summaryrefslogtreecommitdiff
path: root/qemu-img.c
diff options
context:
space:
mode:
authoraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-04-21 23:11:53 +0000
committeraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-04-21 23:11:53 +0000
commit984be72451b43db9f15a15e7f12c38e6f802958f (patch)
tree4e5ffde4ac5f223f8edc23180026f97af1228792 /qemu-img.c
parent62cd72fa2656f9893c9f7792f90896e5fa1676fc (diff)
downloadqemu-984be72451b43db9f15a15e7f12c38e6f802958f.tar.gz
qemu-984be72451b43db9f15a15e7f12c38e6f802958f.tar.bz2
qemu-984be72451b43db9f15a15e7f12c38e6f802958f.zip
Introduce qemu-img check subcommand (Kevin Wolf)
From: Kevin Wolf <kwolf@redhat.com> Now that block drivers can provide check functions, expose them through qemu-img. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7215 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'qemu-img.c')
-rw-r--r--qemu-img.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/qemu-img.c b/qemu-img.c
index ccf4a6f9fd..29149a23c8 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -58,6 +58,7 @@ static void help(void)
"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 @@ static int img_create(int argc, char **argv)
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 @@ int main(int argc, char **argv)
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")) {