[Ocfs2-tools-commits] manish commits r967 - in trunk/libocfs2: . include

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Tue Jun 21 16:03:02 CDT 2005


Author: manish
Date: 2005-06-21 16:03:00 -0500 (Tue, 21 Jun 2005)
New Revision: 967

Modified:
   trunk/libocfs2/checkhb.c
   trunk/libocfs2/include/ocfs2.h
   trunk/libocfs2/ismounted.c
Log:
Sync with upstream ismounted code, which detects busy devices now


Modified: trunk/libocfs2/checkhb.c
===================================================================
--- trunk/libocfs2/checkhb.c	2005-06-20 18:36:54 UTC (rev 966)
+++ trunk/libocfs2/checkhb.c	2005-06-21 21:03:00 UTC (rev 967)
@@ -83,6 +83,7 @@
  * 	OCFS2_MF_ISROOT
  * 	OCFS2_MF_READONLY
  * 	OCFS2_MF_SWAP
+ * 	OCFS2_MF_BUSY
  * 	OCFS2_MF_MOUNTED_CLUSTER	if mounted on cluster
  */
 errcode_t ocfs2_check_heartbeats(struct list_head *dev_list)

Modified: trunk/libocfs2/include/ocfs2.h
===================================================================
--- trunk/libocfs2/include/ocfs2.h	2005-06-20 18:36:54 UTC (rev 966)
+++ trunk/libocfs2/include/ocfs2.h	2005-06-21 21:03:00 UTC (rev 967)
@@ -150,11 +150,12 @@
 #define OCFS2_DIR_SCAN_FLAG_EXCLUDE_DOTS	0x01
 
 /* Check if mounted flags */
-#define OCFS2_MF_MOUNTED         0x01
-#define OCFS2_MF_ISROOT          0x02
-#define OCFS2_MF_READONLY        0x04
-#define OCFS2_MF_SWAP            0x08
-#define OCFS2_MF_MOUNTED_CLUSTER 0x16
+#define OCFS2_MF_MOUNTED		1
+#define OCFS2_MF_ISROOT			2
+#define OCFS2_MF_READONLY		4
+#define OCFS2_MF_SWAP			8
+#define OCFS2_MF_BUSY			16
+#define OCFS2_MF_MOUNTED_CLUSTER	32
 
 /* check_heartbeats progress states */
 #define OCFS2_CHB_START		1

Modified: trunk/libocfs2/ismounted.c
===================================================================
--- trunk/libocfs2/ismounted.c	2005-06-20 18:36:54 UTC (rev 966)
+++ trunk/libocfs2/ismounted.c	2005-06-21 21:03:00 UTC (rev 967)
@@ -284,10 +284,12 @@
 
 
 /*
- * ocfs2_check_mount_point() returns 1 if the device is mounted, 0
- * otherwise.  If mtpt is non-NULL, the directory where the device is
- * mounted is copied to where mtpt is pointing, up to mtlen
- * characters.
+ * ocfs2_check_mount_point() fills determines if the device is
+ * mounted or otherwise busy, and fills in mount_flags with one or
+ * more of the following flags: OCFS2_MF_MOUNTED, OCFS2_MF_ISROOT,
+ * OCFS2_MF_READONLY, OCFS2_MF_SWAP, and OCFS2_MF_BUSY.  If mtpt is
+ * non-NULL, the directory where the device is mounted is copied to
+ * where mtpt is pointing, up to mtlen characters.
  */
 #ifdef __TURBOC__
  #pragma argsused
@@ -295,24 +297,43 @@
 errcode_t ocfs2_check_mount_point(const char *device, int *mount_flags,
 				  char *mtpt, int mtlen)
 {
+	struct stat	st_buf;
+	errcode_t	retval = 0;
+	int		fd;
+
 	if (is_swap_device(device)) {
 		*mount_flags = OCFS2_MF_MOUNTED | OCFS2_MF_SWAP;
 		strncpy(mtpt, "<swap>", mtlen);
-		return 0;
-	}
+	} else {
 #ifdef HAVE_MNTENT_H
-	return check_mntent(device, mount_flags, mtpt, mtlen);
+		retval = check_mntent(device, mount_flags, mtpt, mtlen);
 #else 
 #ifdef HAVE_GETMNTINFO
-	return check_getmntinfo(device, mount_flags, mtpt, mtlen);
+		retval = check_getmntinfo(device, mount_flags, mtpt, mtlen);
 #else
 #ifdef __GNUC__
  #warning "Can't use getmntent or getmntinfo to check for mounted filesystems!"
 #endif
-	*mount_flags = 0;
-	return 0;
+		*mount_flags = 0;
 #endif /* HAVE_GETMNTINFO */
 #endif /* HAVE_MNTENT_H */
+	}
+	if (retval)
+		return retval;
+
+#ifdef __linux__ /* This only works on Linux 2.6+ systems */
+	if ((stat(device, &st_buf) != 0) ||
+	    !S_ISBLK(st_buf.st_mode))
+		return 0;
+	fd = open(device, O_RDONLY | O_EXCL);
+	if (fd < 0) {
+		if (errno == EBUSY)
+			*mount_flags |= OCFS2_MF_BUSY;
+	} else
+		close(fd);
+
+	return 0;
+#endif
 }
 
 /*
@@ -345,20 +366,18 @@
 		exit(1);
 	}
 	printf("Device %s reports flags %02x\n", argv[1], mount_flags);
+	if (mount_flags & OCFS2_MF_BUSY)
+		printf("\t%s is apparently in use.\n", argv[1]);
 	if (mount_flags & OCFS2_MF_MOUNTED)
 		printf("\t%s is mounted.\n", argv[1]);
-
 	if (mount_flags & OCFS2_MF_SWAP)
 		printf("\t%s is a swap device.\n", argv[1]);
-
 	if (mount_flags & OCFS2_MF_READONLY)
 		printf("\t%s is read-only.\n", argv[1]);
-	
 	if (mount_flags & OCFS2_MF_ISROOT)
 		printf("\t%s is the root filesystem.\n", argv[1]);
 	if (mntpt[0])
 		printf("\t%s is mounted on %s.\n", argv[1], mntpt);
-	
 	exit(0);
 }
-#endif /* DEBUG */
+#endif /* DEBUG_EXE */



More information about the Ocfs2-tools-commits mailing list