From: Andrew Price Date: Tue, 5 Apr 2016 15:03:29 +0100 Subject: [Cluster-devel] [PATCH 2/2] mkfs.gfs2: Open the target device with O_EXCL In-Reply-To: <1459865009-14109-1-git-send-email-anprice@redhat.com> References: <1459865009-14109-1-git-send-email-anprice@redhat.com> Message-ID: <1459865009-14109-2-git-send-email-anprice@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit O_EXCL will let local mounters know that the device is busy while mkfs.gfs2 is running so that they don't try to access it. Before: # mount /dev/vdc /mnt/test mount: /dev/vdc: can't read superblock With O_EXCL: # mount /dev/vdc /mnt/test mount: /dev/vdc is already mounted or /mnt/test busy Signed-off-by: Andrew Price --- gfs2/mkfs/main_mkfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c index 107d3cc..4436f93 100644 --- a/gfs2/mkfs/main_mkfs.c +++ b/gfs2/mkfs/main_mkfs.c @@ -854,7 +854,7 @@ static void open_dev(struct mkfs_dev *dev) { int error; - dev->fd = open(dev->path, O_RDWR | O_CLOEXEC); + dev->fd = open(dev->path, O_RDWR|O_CLOEXEC|O_EXCL); if (dev->fd < 0) { perror(dev->path); exit(1); -- 2.4.11