Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LwP8A-0002AR-P2 for qemu-devel@nongnu.org; Tue, 21 Apr 2009 19:11:58 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LwP89-00029f-Hp for qemu-devel@nongnu.org; Tue, 21 Apr 2009 19:11:58 -0400 Received: from [199.232.76.173] (port=36404 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LwP89-00029R-7T for qemu-devel@nongnu.org; Tue, 21 Apr 2009 19:11:57 -0400 Received: from savannah.gnu.org ([199.232.41.3]:43498 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LwP88-00036x-8I for qemu-devel@nongnu.org; Tue, 21 Apr 2009 19:11:56 -0400 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1LwP87-00019U-KW for qemu-devel@nongnu.org; Tue, 21 Apr 2009 23:11:55 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.69) (envelope-from ) id 1LwP86-00019N-7K for qemu-devel@nongnu.org; Tue, 21 Apr 2009 23:11:55 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Tue, 21 Apr 2009 23:11:54 +0000 Subject: [Qemu-devel] [7215] Introduce qemu-img check subcommand (Kevin Wolf) List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 7215 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=7215 Author: aliguori Date: 2009-04-21 23:11:53 +0000 (Tue, 21 Apr 2009) Log Message: ----------- Introduce qemu-img check subcommand (Kevin Wolf) From: Kevin Wolf Now that block drivers can provide check functions, expose them through qemu-img. Signed-off-by: Kevin Wolf Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/qemu-img.c Modified: trunk/qemu-img.c =================================================================== --- trunk/qemu-img.c 2009-04-21 23:11:50 UTC (rev 7214) +++ trunk/qemu-img.c 2009-04-21 23:11:53 UTC (rev 7215) @@ -58,6 +58,7 @@ "QEMU disk image utility\n" "\n" "Command syntax:\n" + " check [-f fmt] filename\n" " create [-e] [-6] [-F fmt] [-b base_image] [-f fmt] filename [size]\n" " commit [-f fmt] filename\n" " convert [-c] [-e] [-6] [-f fmt] [-O output_fmt] [-B output_base_image] filename [filename2 [...]] output_filename\n" @@ -315,6 +316,65 @@ return 0; } +static int img_check(int argc, char **argv) +{ + int c, ret; + const char *filename, *fmt; + BlockDriver *drv; + BlockDriverState *bs; + + fmt = NULL; + for(;;) { + c = getopt(argc, argv, "f:h"); + if (c == -1) + break; + switch(c) { + case 'h': + help(); + break; + case 'f': + fmt = optarg; + break; + } + } + if (optind >= argc) + help(); + filename = argv[optind++]; + + bs = bdrv_new(""); + if (!bs) + error("Not enough memory"); + if (fmt) { + drv = bdrv_find_format(fmt); + if (!drv) + error("Unknown file format '%s'", fmt); + } else { + drv = NULL; + } + if (bdrv_open2(bs, filename, BRDV_O_FLAGS, drv) < 0) { + error("Could not open '%s'", filename); + } + ret = bdrv_check(bs); + switch(ret) { + case 0: + printf("No errors were found on the image.\n"); + break; + case -ENOTSUP: + error("This image format does not support checks"); + break; + default: + if (ret < 0) { + error("An error occurred during the check"); + } else { + printf("%d errors were found on the image.\n", ret); + } + break; + } + + bdrv_delete(bs); + return 0; +} + static int img_commit(int argc, char **argv) { int c, ret; @@ -888,6 +948,8 @@ argc--; argv++; if (!strcmp(cmd, "create")) { img_create(argc, argv); + } else if (!strcmp(cmd, "check")) { + img_check(argc, argv); } else if (!strcmp(cmd, "commit")) { img_commit(argc, argv); } else if (!strcmp(cmd, "convert")) {