From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42754) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9jDh-0004zM-B3 for qemu-devel@nongnu.org; Thu, 17 Dec 2015 19:48:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a9jDe-0007s5-4y for qemu-devel@nongnu.org; Thu, 17 Dec 2015 19:48:29 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49873) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a9jDd-0007rt-Tx for qemu-devel@nongnu.org; Thu, 17 Dec 2015 19:48:26 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 7E8ACC00126A for ; Fri, 18 Dec 2015 00:48:24 +0000 (UTC) Date: Fri, 18 Dec 2015 08:48:21 +0800 From: Fam Zheng Message-ID: <20151218004821.GB25529@ad.usersys.redhat.com> References: <1450371004-26866-1-git-send-email-armbru@redhat.com> <1450371004-26866-18-git-send-email-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1450371004-26866-18-git-send-email-armbru@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 17/23] vmdk: Clean up control flow in vmdk_parse_extents() a bit List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-devel@nongnu.org On Thu, 12/17 17:49, Markus Armbruster wrote: > Cc: Fam Zheng > Signed-off-by: Markus Armbruster > --- > block/vmdk.c | 28 +++++++++++++++------------- > 1 file changed, 15 insertions(+), 13 deletions(-) > > diff --git a/block/vmdk.c b/block/vmdk.c > index b4a224e..08fa3f3 100644 > --- a/block/vmdk.c > +++ b/block/vmdk.c > @@ -760,6 +760,17 @@ static int vmdk_open_sparse(BlockDriverState *bs, BdrvChild *file, int flags, > } > } > > +static const char *next_line(const char *s) > +{ > + while (*s) { > + if (*s == '\n') { > + return s + 1; > + } > + s++; > + } > + return s; > +} > + > static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, > const char *desc_file_path, QDict *options, > Error **errp) > @@ -769,7 +780,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, > char access[11]; > char type[11]; > char fname[512]; > - const char *p = desc; > + const char *p; > int64_t sectors = 0; > int64_t flat_offset; > char *extent_path; > @@ -779,7 +790,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, > char extent_opt_prefix[32]; > Error *local_err = NULL; > > - while (*p) { > + for (p = desc; *p; p = next_line(p)) { > /* parse extent line in one of below formats: > * > * RW [size in sectors] FLAT "file-name.vmdk" OFFSET > @@ -791,7 +802,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, > matches = sscanf(p, "%10s %" SCNd64 " %10s \"%511[^\n\r\"]\" %" SCNd64, > access, §ors, type, fname, &flat_offset); > if (matches < 4 || strcmp(access, "RW")) { > - goto next_line; > + continue; > } else if (!strcmp(type, "FLAT")) { > if (matches != 5 || flat_offset < 0) { > error_setg(errp, "Invalid extent lines: \n%s", p); > @@ -813,7 +824,7 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, > (strcmp(type, "FLAT") && strcmp(type, "SPARSE") && > strcmp(type, "VMFS") && strcmp(type, "VMFSSPARSE")) || > (strcmp(access, "RW"))) { > - goto next_line; > + continue; > } > > if (!path_is_absolute(fname) && !path_has_protocol(fname) && > @@ -870,15 +881,6 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, > return -ENOTSUP; > } > extent->type = g_strdup(type); > -next_line: > - /* move to next line */ > - while (*p) { > - if (*p == '\n') { > - p++; > - break; > - } > - p++; > - } > } > return 0; > } > -- > 2.4.3 > Reviewed-by: Fam Zheng