This is the mail archive of the
cluster-cvs@sourceware.org
mailing list for the cluster.
cluster: master - Fix check_mount to correctly test if device ismounted/busy.
- From: "Ryan O'Hara" <rohara at fedoraproject dot org>
- To: cluster-cvs-relay at redhat dot com
- Date: Mon, 24 Nov 2008 17:30:35 +0000 (UTC)
- Subject: cluster: master - Fix check_mount to correctly test if device ismounted/busy.
Gitweb: http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=b0db0bad3e6a8996fcaecbb93bfe9f8de97b7508
Commit: b0db0bad3e6a8996fcaecbb93bfe9f8de97b7508
Parent: 1aa4232e1c0f6f5a127b78bb38851cde5e044479
Author: Ryan O'Hara <rohara@redhat.com>
AuthorDate: Mon Nov 24 11:03:26 2008 -0600
Committer: Ryan O'Hara <rohara@redhat.com>
CommitterDate: Mon Nov 24 11:29:53 2008 -0600
Fix check_mount to correctly test if device is mounted/busy.
Attempt to open the device with O_EXCL flag. If errno is EBUSY,
the device is busy/mounted. (BZ 240584)
---
gfs2/mkfs/main_mkfs.c | 30 +++++++++++++++---------------
1 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 9b57f5a..1619ed2 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -298,31 +298,31 @@ static void are_you_sure(struct gfs2_sbd *sdp)
}
/**
- * check_mount - check to see if device is mounted
+ * check_mount - check to see if device is mounted/busy
* @device: the device to create the filesystem on
*
*/
void check_mount(char *device)
{
- struct mntent *mnt;
- FILE *fp;
+ struct stat st_buf;
+ int fd;
- if ((fp = setmntent("/proc/mounts", "r")) == NULL) {
- die("error opening /proc/mounts");
- }
+ if (stat(device, &st_buf) < 0)
+ die("could not stat device %s\n", device);
+ if (!S_ISBLK(st_buf.st_mode))
+ die("%s is not a block device\n", device);
- while ((mnt = getmntent(fp)) != NULL) {
- if (strcmp(device, mnt->mnt_fsname) == 0) {
- printf("cannot create filesystem: ");
- printf("%s appears to be mounted\n", device);
- endmntent(fp);
- exit(EXIT_FAILURE);
- break;
+ fd = open(device, O_RDONLY | O_NONBLOCK | O_EXCL);
+
+ if (fd < 0) {
+ if (errno == EBUSY) {
+ die("device %s is busy\n", device);
}
}
-
- endmntent(fp);
+ else {
+ close(fd);
+ }
return;
}