Skip to contentSkip to conversation

dm log userspace, fix table status output

PATCH New Jonathan Brassow 1 participant 1 message Jul 28, 2009 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm log userspace, fix table status output

This patch fixes up the arguments that get printed when a STATUSTYPE_TABLE request is issued.

We keep a copy of the arguments passed to userspace for creating a log, just in case we need to resend them. These are the same arguments that are desired in the STATUSTYPE_TABLE request, except for one. When creating the userspace log, the userspace daemon must know the size of the mirror, so that is appended onto the arguments given in the constructor table. We were printing this extra argument out as well, which is a mistake.

drivers/md/dm-log-userspace-base.c +20 -2
Index: linux-2.6/drivers/md/dm-log-userspace-base.c
===================================================================
@@ -561,6 +561,7 @@ static int userspace_status(struct dm_di
 			    char *result, unsigned maxlen)
 {
 	int r = 0;
+	char *index;
 	size_t sz = (size_t)maxlen;
 	struct log_c *lc = log->context;
 
@@ -577,8 +578,25 @@ static int userspace_status(struct dm_di
 		break;
 	case STATUSTYPE_TABLE:
 		sz = 0;
-		DMEMIT("%s %u %s %s ", log->type->name, lc->usr_argc + 1,
-		       lc->uuid, lc->usr_argv_str);
+		DMEMIT("%s %u %s ", log->type->name, lc->usr_argc, lc->uuid);
+
+		/*
+		 * The usr_argv that we keep has an extra 'mirror device
+		 * length' field appended to the original given arguments.
+		 * We should not include that field in our output.
+		 */
+		index = strrchr(lc->usr_argv_str, ' ');
+		BUG_ON(!index); /* There will always be a ' ' */
+		index += 2;  /* I want the space and 1 more for NULL */
+
+		/*
+		 * Make DMEMIT behave the way we want.  Only allow
+		 * the amount of the string we need plus what has
+		 * already been written (if there is sufficient space).
+		 */
+		if (maxlen > (index - lc->usr_argv_str + sz))
+			maxlen = index - lc->usr_argv_str + sz;
+		DMEMIT("%s ", lc->usr_argv_str);
 		break;
 	}
 	return (r) ? 0 : (int)sz;