Skip to contentSkip to conversation

LVM2 ./WHATS_NEW daemons/dmeventd/plugins/mirr ...

PATCH [email protected] 1 participant 1 message Dec 22, 2011

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: zkabelac at sourceware.org 2011-12-22 16:37:03

Modified files:
. : WHATS_NEW
daemons/dmeventd/plugins/mirror: dmeventd_mirror.c daemons/dmeventd/plugins/raid: dmeventd_raid.c daemons/dmeventd/plugins/snapshot: dmeventd_snapshot.c

Log message:
Use new dmeventd_lvm2_command function in dmeventd plugins.

For snapshot, prepare whole command in front into private buffer. Add also some missing '\n' for syslog messages.
For raid and mirror only convert creation of command line string. This should avoid any unbound growth of mempool for dm_split_names.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.2215&r2=1.2216
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c.diff?cvsroot=lvm2&r1=1.37&r2=1.38
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/dmeventd/plugins/raid/dmeventd_raid.c.diff?cvsroot=lvm2&r1=1.2&r2=1.3
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c.diff?cvsroot=lvm2&r1=1.17&r2=1.18

WHATS_NEW +1 -0
@@ -1,5 +1,6 @@
 Version 2.02.89 - 
 ==================================
+  Use dmeventd_lvm2_command in dmeventd plugins snapshot, raid, mirror.
   Add helper dmeventd_lvm2_command() into libdevmapper-event-lvm2 library.
   Updated documentation for dmeventd.
   Drop extra stat call before opening device.
daemons/dmeventd/plugins/mirror/dmeventd_mirror.c +11 -24
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2010 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2005-2011 Red Hat, Inc. All rights reserved.
  *
  * This file is part of LVM2.
  *
@@ -133,32 +133,15 @@
 	int r;
 #define CMD_SIZE 256	/* FIXME Use system restriction */
 	char cmd_str[CMD_SIZE];
-	char *vg = NULL, *lv = NULL, *layer = NULL;
 
-	if (strlen(device) > 200)  /* FIXME Use real restriction */
-		return -ENAMETOOLONG;	/* FIXME These return code distinctions are not used so remove them! */
-
-	if (!dm_split_lvm_name(dmeventd_lvm2_pool(), device, &vg, &lv, &layer)) {
-		syslog(LOG_ERR, "Unable to determine VG name from %s.",
-		       device);
-		return -ENOMEM;	/* FIXME Replace with generic error return - reason for failure has already got logged */
-	}
-
-	/* strip off the mirror component designations */
-	layer = strstr(lv, "_mlog");
-	if (layer)
-		*layer = '\0';
-
-	/* FIXME Is any sanity-checking required on %s? */
-	if (CMD_SIZE <= snprintf(cmd_str, CMD_SIZE, "lvconvert --config devices{ignore_suspended_devices=1} --repair --use-policies %s/%s", vg, lv)) {
-		/* this error should be caught above, but doesn't hurt to check again */
-		syslog(LOG_ERR, "Unable to form LVM command: Device name too long.");
+	if (!dmeventd_lvm2_command(dmeventd_lvm2_pool(), cmd_str, sizeof(cmd_str),
+				  "lvconvert --config devices{ignore_suspended_devices=1} "
+				  "--repair --use-policies", device))
 		return -ENAMETOOLONG; /* FIXME Replace with generic error return - reason for failure has already got logged */
-	}
 
 	r = dmeventd_lvm2_run(cmd_str);
 
-	syslog(LOG_INFO, "Repair of mirrored LV %s/%s %s.", vg, lv,
+	syslog(LOG_INFO, "Repair of mirrored device %s %s.", device,
 	       (r == ECMD_PROCESSED) ? "finished successfully" : "failed");
 
 	return (r == ECMD_PROCESSED) ? 0 : -1;
@@ -227,9 +210,12 @@
 		    int minor __attribute__((unused)),
 		    void **unused __attribute__((unused)))
 {
-	int r = dmeventd_lvm2_init();
+	if (!dmeventd_lvm2_init())
+		return 0;
+
 	syslog(LOG_INFO, "Monitoring mirror device %s for events.", device);
-	return r;
+
+	return 1;
 }
 
 int unregister_device(const char *device,
@@ -241,5 +227,6 @@
 	syslog(LOG_INFO, "No longer monitoring mirror device %s for events.",
 	       device);
 	dmeventd_lvm2_exit();
+
 	return 1;
 }
daemons/dmeventd/plugins/raid/dmeventd_raid.c +10 -18
@@ -33,28 +33,16 @@
 	int r;
 #define CMD_SIZE 256	/* FIXME Use system restriction */
 	char cmd_str[CMD_SIZE];
-	char *vg = NULL, *lv = NULL, *layer = NULL;
 
-	if (strlen(device) > 200)  /* FIXME Use real restriction */
+	if (!dmeventd_lvm2_command(dmeventd_lvm2_pool(), cmd_str, sizeof(cmd_str),
+				  "lvconvert --config devices{ignore_suspended_devices=1} "
+				  "--repair --use-policies", device))
 		return -1;
 
-	if (!dm_split_lvm_name(dmeventd_lvm2_pool(), device, &vg, &lv, &layer)) {
-		syslog(LOG_ERR, "Unable to determine VG name from %s.",
-		       device);
-		return -1;
-	}
-
-	/* FIXME Is any sanity-checking required on %s? */
-	if (CMD_SIZE <= snprintf(cmd_str, CMD_SIZE, "lvconvert --config devices{ignore_suspended_devices=1} --repair --use-policies %s/%s", vg, lv)) {
-		/* this error should be caught above, but doesn't hurt to check again */
-		syslog(LOG_ERR, "Unable to form LVM command: Device name too long.");
-		return -1;
-	}
-
 	r = dmeventd_lvm2_run(cmd_str);
 
 	if (r != ECMD_PROCESSED)
-		syslog(LOG_INFO, "Repair of RAID LV %s/%s failed.", vg, lv);
+		syslog(LOG_INFO, "Repair of RAID device %s failed.", device);
 
 	return (r == ECMD_PROCESSED) ? 0 : -1;
 }
@@ -162,9 +150,12 @@
 		    int minor __attribute__((unused)),
 		    void **unused __attribute__((unused)))
 {
-	int r = dmeventd_lvm2_init();
+	if (!dmeventd_lvm2_init())
+		return 0;
+
 	syslog(LOG_INFO, "Monitoring RAID device %s for events.", device);
-	return r;
+
+	return 1;
 }
 
 int unregister_device(const char *device,
@@ -176,5 +167,6 @@
 	syslog(LOG_INFO, "No longer monitoring RAID device %s for events.",
 	       device);
 	dmeventd_lvm2_exit();
+
 	return 1;
 }
daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c +33 -29

110 lines not on this page · raw message