thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
0a122b
From 5fcb6627be0a9a6744546adab5e638d4a265d2b7 Mon Sep 17 00:00:00 2001
0a122b
From: Max Reitz <mreitz@redhat.com>
0a122b
Date: Tue, 7 Jan 2014 21:57:09 +0100
0a122b
Subject: [PATCH 04/14] block: Image file option amendment
0a122b
0a122b
RH-Author: Max Reitz <mreitz@redhat.com>
0a122b
Message-id: <1389131839-12920-5-git-send-email-mreitz@redhat.com>
0a122b
Patchwork-id: 56540
0a122b
O-Subject: [RHEL-7.0 qemu-kvm PATCH v2 04/14] block: Image file option amendment
0a122b
Bugzilla: 1033490
0a122b
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
0a122b
RH-Acked-by: Fam Zheng <famz@redhat.com>
0a122b
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
0a122b
0a122b
BZ: 1033490
0a122b
0a122b
This patch adds the "amend" option to qemu-img which allows changing
0a122b
image options on existing image files. It also adds the generic bdrv
0a122b
implementation which is basically just a wrapper for the image format
0a122b
specific function.
0a122b
0a122b
Signed-off-by: Max Reitz <mreitz@redhat.com>
0a122b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
0a122b
(cherry picked from commit 6f176b48f9f98820ed192a1355cc1c7c08ddf46b)
0a122b
0a122b
Signed-off-by: Max Reitz <mreitz@redhat.com>
0a122b
0a122b
Conflicts:
0a122b
	block.c
0a122b
	qemu-img.c
0a122b
0a122b
Conflicts because d616b224745b2c522f965cf8de7da17b553b959a has not yet
0a122b
been backported. This is a single additional function which is missing
0a122b
from the context in this case, therefore later backporting of that
0a122b
commit would be trivial and obvious to resolve.
0a122b
0a122b
Conflicts in qemu-img.c, because it is bdrv_delete() downstream for now,
0a122b
rather than bdrv_unref().
0a122b
---
0a122b
 block.c                   |  8 +++++
0a122b
 include/block/block.h     |  2 ++
0a122b
 include/block/block_int.h |  3 ++
0a122b
 qemu-img-cmds.hx          |  6 ++++
0a122b
 qemu-img.c                | 84 +++++++++++++++++++++++++++++++++++++++++++++++
0a122b
 qemu-img.texi             |  5 +++
0a122b
 6 files changed, 108 insertions(+)
0a122b
0a122b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
0a122b
---
0a122b
 block.c                   |    8 ++++
0a122b
 include/block/block.h     |    2 +
0a122b
 include/block/block_int.h |    3 ++
0a122b
 qemu-img-cmds.hx          |    6 +++
0a122b
 qemu-img.c                |   84 +++++++++++++++++++++++++++++++++++++++++++++
0a122b
 qemu-img.texi             |    5 +++
0a122b
 6 files changed, 108 insertions(+), 0 deletions(-)
0a122b
0a122b
diff --git a/block.c b/block.c
0a122b
index 1ac1ab3..cc7afd4 100644
0a122b
--- a/block.c
0a122b
+++ b/block.c
0a122b
@@ -4980,3 +4980,11 @@ AioContext *bdrv_get_aio_context(BlockDriverState *bs)
0a122b
     /* Currently BlockDriverState always uses the main loop AioContext */
0a122b
     return qemu_get_aio_context();
0a122b
 }
0a122b
+
0a122b
+int bdrv_amend_options(BlockDriverState *bs, QEMUOptionParameter *options)
0a122b
+{
0a122b
+    if (bs->drv->bdrv_amend_options == NULL) {
0a122b
+        return -ENOTSUP;
0a122b
+    }
0a122b
+    return bs->drv->bdrv_amend_options(bs, options);
0a122b
+}
0a122b
diff --git a/include/block/block.h b/include/block/block.h
0a122b
index bcf71e2..e7f718c 100644
0a122b
--- a/include/block/block.h
0a122b
+++ b/include/block/block.h
0a122b
@@ -280,6 +280,8 @@ typedef enum {
0a122b
 
0a122b
 int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix);
0a122b
 
0a122b
+int bdrv_amend_options(BlockDriverState *bs_new, QEMUOptionParameter *options);
0a122b
+
0a122b
 /* async block I/O */
0a122b
 typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sector,
0a122b
                                      int sector_num);
0a122b
diff --git a/include/block/block_int.h b/include/block/block_int.h
0a122b
index 71c8b53..d49a317 100644
0a122b
--- a/include/block/block_int.h
0a122b
+++ b/include/block/block_int.h
0a122b
@@ -202,6 +202,9 @@ struct BlockDriver {
0a122b
     int (*bdrv_check)(BlockDriverState* bs, BdrvCheckResult *result,
0a122b
         BdrvCheckMode fix);
0a122b
 
0a122b
+    int (*bdrv_amend_options)(BlockDriverState *bs,
0a122b
+        QEMUOptionParameter *options);
0a122b
+
0a122b
     void (*bdrv_debug_event)(BlockDriverState *bs, BlkDebugEvent event);
0a122b
 
0a122b
     /* TODO Better pass a option string/QDict/QemuOpts to add any rule? */
0a122b
diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
0a122b
index 0c36e59..da1d965 100644
0a122b
--- a/qemu-img-cmds.hx
0a122b
+++ b/qemu-img-cmds.hx
0a122b
@@ -67,5 +67,11 @@ DEF("resize", img_resize,
0a122b
     "resize [-q] filename [+ | -]size")
0a122b
 STEXI
0a122b
 @item resize [-q] @var{filename} [+ | -]@var{size}
0a122b
+ETEXI
0a122b
+
0a122b
+DEF("amend", img_amend,
0a122b
+    "amend [-q] [-f fmt] -o options filename")
0a122b
+STEXI
0a122b
+@item amend [-q] [-f @var{fmt}] -o @var{options} @var{filename}
0a122b
 @end table
0a122b
 ETEXI
0a122b
diff --git a/qemu-img.c b/qemu-img.c
0a122b
index 1fe175b..f0f70e4 100644
0a122b
--- a/qemu-img.c
0a122b
+++ b/qemu-img.c
0a122b
@@ -2566,6 +2566,90 @@ out:
0a122b
     return 0;
0a122b
 }
0a122b
 
0a122b
+static int img_amend(int argc, char **argv)
0a122b
+{
0a122b
+    int c, ret = 0;
0a122b
+    char *options = NULL;
0a122b
+    QEMUOptionParameter *create_options = NULL, *options_param = NULL;
0a122b
+    const char *fmt = NULL, *filename;
0a122b
+    bool quiet = false;
0a122b
+    BlockDriverState *bs = NULL;
0a122b
+
0a122b
+    for (;;) {
0a122b
+        c = getopt(argc, argv, "hqf:o:");
0a122b
+        if (c == -1) {
0a122b
+            break;
0a122b
+        }
0a122b
+
0a122b
+        switch (c) {
0a122b
+            case 'h':
0a122b
+            case '?':
0a122b
+                help();
0a122b
+                break;
0a122b
+            case 'o':
0a122b
+                options = optarg;
0a122b
+                break;
0a122b
+            case 'f':
0a122b
+                fmt = optarg;
0a122b
+                break;
0a122b
+            case 'q':
0a122b
+                quiet = true;
0a122b
+                break;
0a122b
+        }
0a122b
+    }
0a122b
+
0a122b
+    if (optind != argc - 1) {
0a122b
+        help();
0a122b
+    }
0a122b
+
0a122b
+    if (!options) {
0a122b
+        help();
0a122b
+    }
0a122b
+
0a122b
+    filename = argv[argc - 1];
0a122b
+
0a122b
+    bs = bdrv_new_open(filename, fmt, BDRV_O_FLAGS | BDRV_O_RDWR, true, quiet);
0a122b
+    if (!bs) {
0a122b
+        error_report("Could not open image '%s'", filename);
0a122b
+        ret = -1;
0a122b
+        goto out;
0a122b
+    }
0a122b
+
0a122b
+    fmt = bs->drv->format_name;
0a122b
+
0a122b
+    if (is_help_option(options)) {
0a122b
+        ret = print_block_option_help(filename, fmt);
0a122b
+        goto out;
0a122b
+    }
0a122b
+
0a122b
+    create_options = append_option_parameters(create_options,
0a122b
+            bs->drv->create_options);
0a122b
+    options_param = parse_option_parameters(options, create_options,
0a122b
+            options_param);
0a122b
+    if (options_param == NULL) {
0a122b
+        error_report("Invalid options for file format '%s'", fmt);
0a122b
+        ret = -1;
0a122b
+        goto out;
0a122b
+    }
0a122b
+
0a122b
+    ret = bdrv_amend_options(bs, options_param);
0a122b
+    if (ret < 0) {
0a122b
+        error_report("Error while amending options: %s", strerror(-ret));
0a122b
+        goto out;
0a122b
+    }
0a122b
+
0a122b
+out:
0a122b
+    if (bs) {
0a122b
+        bdrv_delete(bs);
0a122b
+    }
0a122b
+    free_option_parameters(create_options);
0a122b
+    free_option_parameters(options_param);
0a122b
+    if (ret) {
0a122b
+        return 1;
0a122b
+    }
0a122b
+    return 0;
0a122b
+}
0a122b
+
0a122b
 static const img_cmd_t img_cmds[] = {
0a122b
 #define DEF(option, callback, arg_string)        \
0a122b
     { option, callback },
0a122b
diff --git a/qemu-img.texi b/qemu-img.texi
0a122b
index dc578bb..da36975 100644
0a122b
--- a/qemu-img.texi
0a122b
+++ b/qemu-img.texi
0a122b
@@ -356,6 +356,11 @@ sizes accordingly.  Failure to do so will result in data loss!
0a122b
 After using this command to grow a disk image, you must use file system and
0a122b
 partitioning tools inside the VM to actually begin using the new space on the
0a122b
 device.
0a122b
+
0a122b
+@item amend [-f @var{fmt}] -o @var{options} @var{filename}
0a122b
+
0a122b
+Amends the image format specific @var{options} for the image file
0a122b
+@var{filename}. Not all file formats support this operation.
0a122b
 @end table
0a122b
 @c man end
0a122b
 
0a122b
-- 
0a122b
1.7.1
0a122b