Skip to contentSkip to conversation

master - cleanup: simplier _lv_passes_volumes_filter

PATCH Zdenek Kabelac 1 participant 1 message Sep 24, 2014

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=bc0a3e23553f8d622a7218ded55ac1fdaa75286c
Commit:        bc0a3e23553f8d622a7218ded55ac1fdaa75286c
Parent:        a1213401393ac6e6a9a9e168379574469eb715c8
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Sun Sep 21 01:08:43 2014 +0200
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Wed Sep 24 10:54:47 2014 +0200

cleanup: simplier _lv_passes_volumes_filter

Don't recreate string and just check components directly.

---
 lib/activate/activate.c |   23 +++++++----------------
 1 files changed, 7 insertions(+), 16 deletions(-)
lib/activate/activate.c +7 -16
index 3f9d1a2..2a94ea6 100644
@@ -114,7 +114,7 @@ static int _lv_passes_volumes_filter(struct cmd_context *cmd, const struct logic
 	const struct dm_config_value *cv;
 	const char *str;
 	static char config_path[PATH_MAX];
-	static char path[PATH_MAX];
+	size_t len = strlen(lv->vg->name);
 
 	config_def_get_path(config_path, sizeof(config_path), cfg_id);
 	log_verbose("%s configuration setting defined: "
@@ -161,21 +161,12 @@ static int _lv_passes_volumes_filter(struct cmd_context *cmd, const struct logic
 			else
 				continue;
 		}
-		if (!strchr(str, '/')) {
-			/* vgname supplied */
-			if (!strcmp(str, lv->vg->name))
-				return 1;
-			else
-				continue;
-		}
-		/* vgname/lvname */
-		if (dm_snprintf(path, sizeof(path), "%s/%s", lv->vg->name,
-				 lv->name) < 0) {
-			log_error("dm_snprintf error from %s/%s", lv->vg->name,
-				  lv->name);
-			continue;
-		}
-		if (!strcmp(path, str))
+
+		/* If supplied name is vgname[/lvname] */
+		if ((strncmp(str, lv->vg->name, len) == 0) &&
+		    (!str[len] ||
+		     ((str[len] == '/') &&
+		      !strcmp(str + len + 1, lv->name))))
 			return 1;
 	}