From: Jonthan Brassow <[email-masked]>

The output of 'dmsetup table' includes an internal
field that should not be there.  This patch removes it.

We keep a copy of the arguments passed to userspace for
creating a log 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.

Signed-off-by: Jonathan Brassow <[email-masked]>

---
 drivers/md/dm-log-userspace-base.c |   22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

Index: linux-2.6.31-rc8/drivers/md/dm-log-userspace-base.c
===================================================================
--- linux-2.6.31-rc8.orig/drivers/md/dm-log-userspace-base.c
+++ linux-2.6.31-rc8/drivers/md/dm-log-userspace-base.c
@@ -566,6 +566,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;
 
@@ -582,8 +583,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;