[DRBD-cvs] r1685 - trunk/user

svn at svn.drbd.org svn at svn.drbd.org
Wed Dec 22 11:15:18 CET 2004


Author: phil
Date: 2004-12-22 11:15:02 +0100 (Wed, 22 Dec 2004)
New Revision: 1685

Modified:
   trunk/user/drbdmeta.c
Log:
Now drbdmeta uses /proc/drbd to find out if a device is configured...


Modified: trunk/user/drbdmeta.c
===================================================================
--- trunk/user/drbdmeta.c	2004-12-21 17:08:50 UTC (rev 1684)
+++ trunk/user/drbdmeta.c	2004-12-22 10:15:02 UTC (rev 1685)
@@ -1484,6 +1484,28 @@
 	return cfg->ops->parse(cfg, argv + 1, argc - 1, ai);
 }
 
+int is_configured(int minor)
+{
+	FILE *pr;
+	char line[120], tok[40];
+	int m,rv=0;
+
+	pr = fopen("/proc/drbd","r");
+	if(!pr) return rv;
+	
+	while(fgets(line,120,pr)) {
+		if(sscanf(line,"%2d: %s",&m,tok)) {
+			if( m == minor ) {
+				rv = strcmp(tok,"Unconfigured");
+				break;
+			}			
+		}
+	}
+	fclose(pr);
+
+	return rv;
+}
+
 int main(int argc, char **argv)
 {
 	struct meta_cmd *command = NULL;
@@ -1506,19 +1528,7 @@
 	cfg->drbd_dev_name = argv[1];
 	cfg->drbd_fd = dt_lock_open_drbd(cfg->drbd_dev_name, &cfg->lock_fd, 1);
 	if (cfg->drbd_fd > -1) {
-		/* Try to avoid DRBD specific ioctls here...
-		 * If the device is _not_ configured, block device ioctls
-		 * should fail. So if we _can_ determine whether it is readonly,
-		 * it is configured; and we better not touch its meta data.
-		 * 
-		 * Unfortunately this is not true... as soon as the
-		 * driver is loaded, this works, no regard wheter it
-		 * is configured or not.... probabely need to use
-		 * a drbd IOCTL... or look at /proc/drbd ...
-		 * uggly as well!
-		 */
-		int dummy_is_ro;
-		if (ioctl(cfg->drbd_fd, BLKROGET, &dummy_is_ro) == 0) {
+		if (is_configured(dt_minor_of_dev(cfg->drbd_dev_name))) {
 			fprintf(stderr, "Device '%s' is configured!\n",
 				cfg->drbd_dev_name);
 			exit(20);



More information about the drbd-cvs mailing list