This is the mail archive of the cluster-cvs@sourceware.org mailing list for the cluster.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

cluster: STABLE2 - Fix check_mount to correctly test if device ismounted/busy.


Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=c726c539fd6bb920095e83779ab7c1e15a1f86cc
Commit:        c726c539fd6bb920095e83779ab7c1e15a1f86cc
Parent:        4787e11dc7831f42228b89ba7726fd6f6901a1e3
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:31:38 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 7aeb3af..d884f53 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -296,31 +296,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;
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]