Skip to contentSkip to conversation

qmp/hmp interfaces for internal snapshot info

PATCH Superseded Wenchao Xia 5 participants 47 messages Mar 11, 2013 – Mar 18, 2013 Block layer

v9 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

v9 cover qmp/hmp interfaces for internal snapshot info

In the use of snapshot a way to retrieve related info at runtime is needed,
so this serial of patches will merge some code for qemu and qemu-img, and add following interfaces for qemu:

1) qmp: query-images, show image info for a block device Example:
-> { "execute": "query-images" }

<- {
      "return":[
         {
            "device":"ide0-hd0",
            "image":{
               "filename":"disks/test1.img",
               "format":"qcow2",
               "virtual-size":2048000,
               "snapshots":[
                  {
                     "id": "1",
                     "name": "snapshot1",
                     "vm-state-size": 0,
                     "date-sec": 10000200,
                     "date-nsec": 12,
                     "vm-clock-sec": 206,
                     "vm-clock-nsec": 30
                  }
               ]
            }
         }
      ]

}

2) qmp: query-snapshots, show avaiable vm snapshot info which can be used in loadvm.
Example:
-> { "execute": "query-snapshots" }

<- {
      "return":[
         {
            "id": "1",
            "name": "snapshot1",
            "vm-state-size": 0,
            "date-sec": 10000200,
            "date-nsec": 12,
            "vm-clock-sec": 206,
            "vm-clock-nsec": 30
         }
      ]
    }

3) hmp: info images, show what got in qmp query-images in monitor

These patches follows the rule that use qmp to retieve information,
hmp layer just do a translation from qmp object it got.
To make code graceful, snapshot and image info retrieving code in
qemu and qemu-img are merged into block layer, and some function name was adjusted to make it tips better. For the part touch by the serial, it works as:

qemu qemu-img

dump_monitor dump_stdout

     |--------------| 
            |

block/qapi.c

v2:
Rename and adjusted qmp interface according to comments from Eric. Spelling fix.
Information retrieving function in block layer goes to seperated patch. Free qmp object after usage in hmp.
Added counterpart in qmp-commands.hx.
Better tips in qmp-schema.json.

v3:
Spelling fix in commit message, patch 03/11.
Spelling fix in code, patch 06/11.
Add comments that vm-state-size is in bytes, and change size of it in
example to a reasonable number, patch 08/11.

v4:
02/13: in bdrv_get_filename(), add const to parameter *bs. 03/13: new added, in which the function correct the behavior in info
retrieving.
04/13: in bdrv_query_snapshot_infolist(), remove NULL check before call
err_setg(), added TODO comments that let block layer function set error instead of this layer to tip better for errors, Split out patch about image info to patch 05/13.
05/13: new splitted, and it checks *bs by calling bdrv_can_read_snapshot()
before collect internal snasphot info to avoid *err is set unexpectly now.
06/13: check if error happens after calling bdrv_query_image_info(). 08/13: rename info to image in DeviceImageInfo and make it optional,
when device is not inserted it will be empty, added error handling code when met error in calling block layer API.
09/13: distinguish *id and *name in bdrv_find_snapshots(), caller
can choose what to search with. id_wellformed() should be called in new snapshot creation interface above this function in the future.
10/13: now this interface have addtional parameter *device, which
enable showing internal snapshots on a single device. Also use bdrv_can_read_snapshot() instead of bdrv_can_snapshot() now.
11/13: this function goes to hmp.c so hmp_handler_error is not exported
any more, split out patch that switch snapshot info function to patch 12/13.
12/13: new splitted.
13/13: use qmp API instead of directly calling block layer API, now
all hmp function have correspond qmp funtion in this serial.

v5:
04/13: spelling fix in commit message, better comments and better
tips of error, after calling bdrv_snapshot_list().

v6:
==Address Kevin's comments==:
04/14: seperate patch for code moving,
05/14: use strerror() for error tipping after call of bdrv_snapshot_list(),
use "switch" instead of "if else" for error checking, replace info_list->value->* by info->*.
06/14: access bs->backing_file directly instead of calling of
bdrv_get_backing_filename in collect_image_info. Function switch patch of last version is merged into this patch.
08/14: API change, add optional parameter of "device" and "backing",
which allow showing all image info in the backing file chain of block device, add related implemention.
09/14: seperate patch for code moving.
10/14: seperate patch for function change, return what got from
bdrv_snapshot_list() instead of -ENOENT.

==Address Eric's comments==:
02/14: return bool instead of int for this new function. 03/14: return bool instead of int for old function bdrv_can_snapshot().

V7:
==Address Eric's comments==:
6/14: discard of static function bdrv_get_filename().
8/14: better doc and comments, trailing '.' is removed.
11/14: QMP API change: removed parameter *device, it only returns VM snapshot
now. Block device's internal snapshot info can be accessed by query-images.
12/14: related caller code change for query-snapshots. Seperate internal
static function for VM snapshot info.
14/14: HMP API change: added support of query internal snapshots of one image
in the backing file chain of a block device. use query-images instead of query-snapshots. Seperate internal static mirror function for block snapshot info.

v8:
General change:
discard bdrv_can_read_snapshot() for that return value can tip error. add
block/snapshot.c and block/qapi.c and function are moved there. Patches 17-20 are for clean and moved to tail.

Address Markus's comments:
3/20: function was moved to block/snapshot.c instead of block.c. 7/20: better commit message. Remove comments for the return value of
bdrv_snapshot_list(), remove period suffix in error message, better error message, remove the filter callback of it. remove comments for *bs must be open. It return negative value for error check.
8/20: add a flag parameter to filter out inconsistent vm snapshots instead
of a call back function.
9/20: function reorganized to return negative error value, and qmp object
will be got only on success.
10/20: better documents and remove suffix period.
11/20: better documents and remove suffix period, explain optional member
in qmp-commands.hx.

Address Stefan's comments:
6/20: add prefix 'bdrv_' to the moved functions.
7/20: remove the filter call back function. remove bdrv_can_reand_snapshot()
call in qemu-img. It return negative value for error check.
8/20: add a flag parameter to filter out inconsistent vm snapshots instead
of a call back function.
9/20: small trivial static function was removed.

Address Eric's comments:
6/20: add prefix 'bdrv_' to the moved functions. Added message in commit
about the patch's purpose.

Other:
14/20 - 16/20: new interface info image which show all image info
including internal snapshots for each device, share the dump code with qemu-img.
18/20: new clean up patch for block/snapshot.c.
19/20: new clean up patch for block/qapi.c.

V9:
General change:
Drop 4 cleaning patches in the tail in laster version, to make the serial
shorter, which can be submitted later.

Address Eric's comments:
1/14: Merge the patch with file adding patch, add copyright note in the
header file, fix the argument number issue in last version.
3/14: Better commit message.
4/14: Merge the patch with file adding patch, add copyright note in the
header file.
6/14: Better document and comments, rename snapshot_filter_vm() to
snapshot_valid_for_vm() and return bool now.
7/14: Better commit message.
8/14: Remove the free of *list on fail calling
bdrv_query_snapshot_info_list(), better commit message and documents.
9/14: Better documents.

Wenchao Xia (14):
1 block: move bdrv_snapshot_find() to block/snapshot.c
2 block: distinguish id and name in bdrv_find_snapshot()
3 qemu-img: remove unused parameter in collect_image_info()
4 block: move collect_snapshots() and collect_image_info() to block/qapi.c 5 block: add snapshot info query function bdrv_query_snapshot_info_list() 6 block: add check for VM snapshot in bdrv_query_snapshot_info_list() 7 block: add image info query function bdrv_query_image_info() 8 qmp: add interface query-snapshots
9 qmp: add interface query-images
10 hmp: add function hmp_info_snapshots()
11 hmp: switch snapshot info function to qmp based one
12 block: move dump_human_image_info() to block/qapi.c
13 block: dump to buffer for bdrv_image_info_dump()
14 hmp: add command info images

 block/Makefile.objs      |    1 +
 block/qapi.c             |  382 ++++++++++++++++++++++++++++++++++++++++++++++
 block/snapshot.c         |   67 ++++++++
 hmp.c                    |   80 ++++++++++
 hmp.h                    |    2 +
 include/block/qapi.h     |   28 ++++
 include/block/snapshot.h |   26 +++
 monitor.c                |    9 +-
 qapi-schema.json         |   47 ++++++
 qemu-img.c               |  162 +------------------
 qmp-commands.hx          |  145 ++++++++++++++++++
 savevm.c                 |   95 +-----------
 12 files changed, 800 insertions(+), 244 deletions(-)
 create mode 100644 block/qapi.c
 create mode 100644 block/snapshot.c
 create mode 100644 include/block/qapi.h
 create mode 100644 include/block/snapshot.h
#1 lore raw

PATCH v9 1/14 block: move bdrv_snapshot_find() to block/snapshot.c

This patch adds block/snapshot.c and then moves the function
there. It also fixes small code style errors reported by check script.

---
 block/Makefile.objs      |    1 +
 block/snapshot.c         |   37 +++++++++++++++++++++++++++++++++++++
 include/block/snapshot.h |   26 ++++++++++++++++++++++++++
 savevm.c                 |   23 +----------------------
 4 files changed, 65 insertions(+), 22 deletions(-)
 create mode 100644 block/snapshot.c
 create mode 100644 include/block/snapshot.h
block/Makefile.objs +1 -0
index c067f38..60a4cd2 100644
@@ -3,6 +3,7 @@ block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-c
 block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
 block-obj-y += qed-check.o
 block-obj-y += parallels.o blkdebug.o blkverify.o
+block-obj-y += snapshot.o
 block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o
 block-obj-$(CONFIG_POSIX) += raw-posix.o
 block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
block/snapshot.c new file +37 -0
new file mode 100644
index 0000000..8de73b4
@@ -0,0 +1,37 @@
+/*
+ * Snapshot related functions.
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Wenchao Xia   <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#include "block/snapshot.h"
+
+int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
+                       const char *name)
+{
+    QEMUSnapshotInfo *sn_tab, *sn;
+    int nb_sns, i, ret;
+
+    ret = -ENOENT;
+    nb_sns = bdrv_snapshot_list(bs, &sn_tab);
+    if (nb_sns < 0) {
+        return ret;
+    }
+    for (i = 0; i < nb_sns; i++) {
+        sn = &sn_tab[i];
+        if (!strcmp(sn->id_str, name) || !strcmp(sn->name, name)) {
+            *sn_info = *sn;
+            ret = 0;
+            break;
+        }
+    }
+    g_free(sn_tab);
+    return ret;
+}
include/block/snapshot.h new file +26 -0
new file mode 100644
index 0000000..86891d1
@@ -0,0 +1,26 @@
+/*
+ * Snapshot related functions.
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Wenchao Xia   <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#ifndef SNAPSHOT_H
+#define SNAPSHOT_H
+
+#include "qemu-common.h"
+/*
+ * block.h is needed for QEMUSnapshotInfo, it can be removed when define is
+ * moved here.
+ */
+#include "block.h"
+
+int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
+                       const char *name);
+#endif
savevm.c +1 -22
index a8a53ef..95f19ca 100644
@@ -39,6 +39,7 @@
 #include "qmp-commands.h"
 #include "trace.h"
 #include "qemu/bitops.h"
+#include "block/snapshot.h"
 
 #define SELF_ANNOUNCE_ROUNDS 5
 
@@ -2060,28 +2061,6 @@ out:
     return ret;
 }
 
-static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
-                              const char *name)
-{
-    QEMUSnapshotInfo *sn_tab, *sn;
-    int nb_sns, i, ret;
-
-    ret = -ENOENT;
-    nb_sns = bdrv_snapshot_list(bs, &sn_tab);
-    if (nb_sns < 0)
-        return ret;
-    for(i = 0; i < nb_sns; i++) {
-        sn = &sn_tab[i];
-        if (!strcmp(sn->id_str, name) || !strcmp(sn->name, name)) {
-            *sn_info = *sn;
-            ret = 0;
-            break;
-        }
-    }
-    g_free(sn_tab);
-    return ret;
-}
-
 /*
  * Deletes snapshots of a given name in all opened images.
  */
Signature · 1 line
1.7.1
#2 lore raw

Re: [Qemu-devel] [PATCH V9 01/14] block: move bdrv_snapshot_find() to block/snapshot.c

Quoted 15 lines · Wenchao Xia

This patch adds block/snapshot.c and then moves the function
there. It also fixes small code style errors reported by check script.

---
 block/Makefile.objs      |    1 +
 block/snapshot.c         |   37 +++++++++++++++++++++++++++++++++++++
 include/block/snapshot.h |   26 ++++++++++++++++++++++++++
 savevm.c                 |   23 +----------------------
 4 files changed, 65 insertions(+), 22 deletions(-)
 create mode 100644 block/snapshot.c
 create mode 100644 include/block/snapshot.h

+++ b/block/snapshot.c

block/snapshot.c line 4

Quoted 4 lines
block/snapshot.c new file +4 -0
@@ -0,0 +1,37 @@
+/*
+ * Snapshot related functions.
+ *
+ * Copyright IBM, Corp. 2013

Technically, since you are moving code from savevm.c, you should also preserve the copyright on that moved code:

* Copyright (c) 2003-2008 Fabrice Bellard

block/snapshot.c line 9

Quoted 5 lines
block/snapshot.c new file +5 -0
+ *
+ * Authors:
+ *  Wenchao Xia   <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.

Furthermore, the code you are moving was under BSD license, so by moving the code, you have changed its license to something more restrictive. Personally, I like LGPL better than BSD, but as I'm not the copyright holder of the original code, and neither are you, I'm not sure that either of us is qualified to make that change. Therefore, I'm unwilling to add my Reviewed-by, even though the code motion itself is correct, without a maintainer chiming in on whether your licensing is appropriate or needs an adjustment.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw

Re: [Qemu-devel] [PATCH V9 01/14] block: move bdrv_snapshot_find() to block/snapshot.c

Quoted 32 lines · Eric Blake
Quoted 15 lines · Wenchao Xia

This patch adds block/snapshot.c and then moves the function
there. It also fixes small code style errors reported by check script.

---
  block/Makefile.objs      |    1 +
  block/snapshot.c         |   37 +++++++++++++++++++++++++++++++++++++
  include/block/snapshot.h |   26 ++++++++++++++++++++++++++
  savevm.c                 |   23 +----------------------
  4 files changed, 65 insertions(+), 22 deletions(-)

create mode 100644 block/snapshot.c
create mode 100644 include/block/snapshot.h

+++ b/block/snapshot.c

block/snapshot.c line 4

Quoted 4 lines
block/snapshot.c new file +4 -0
@@ -0,0 +1,37 @@
+/*
+ * Snapshot related functions.
+ *
+ * Copyright IBM, Corp. 2013

Technically, since you are moving code from savevm.c, you should also preserve the copyright on that moved code:

* Copyright (c) 2003-2008 Fabrice Bellard

block/snapshot.c line 9

Quoted 5 lines
block/snapshot.c new file +5 -0
+ *
+ * Authors:
+ *  Wenchao Xia   <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
Quoted 9 lines

Furthermore, the code you are moving was under BSD license, so by moving the code, you have changed its license to something more restrictive. Personally, I like LGPL better than BSD, but as I'm not the copyright holder of the original code, and neither are you, I'm not sure that either of us is qualified to make that change. Therefore, I'm unwilling to add my Reviewed-by, even though the code motion itself is correct, without a maintainer chiming in on whether your licensing is appropriate or needs an adjustment.

Oops, Since it belongs to block layer I hope it can be LGPL2. Do you
know how to contact Fabrice Bellard to ask for a change?

Signature · 3 lines
Best Regards

Wenchao Xia
#4 lore raw

Re: [Qemu-devel] [PATCH V9 01/14] block: move bdrv_snapshot_find() to block/snapshot.c

Quoted 18 lines · Wenchao Xia
Quoted 8 lines · Eric Blake
Quoted 6 lines · Wenchao Xia

This patch adds block/snapshot.c and then moves the function
there. It also fixes small code style errors reported by check script.

+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.

Quoted 9 lines

Furthermore, the code you are moving was under BSD license, so by moving the code, you have changed its license to something more restrictive. Personally, I like LGPL better than BSD, but as I'm not the copyright holder of the original code, and neither are you, I'm not sure that either of us is qualified to make that change. Therefore, I'm unwilling to add my Reviewed-by, even though the code motion itself is correct, without a maintainer chiming in on whether your licensing is appropriate or needs an adjustment.

Quoted 2 lines

Oops, Since it belongs to block layer I hope it can be LGPL2. Do you
know how to contact Fabrice Bellard to ask for a change?

As far as I can tell, there is nothing wrong with leaving the file as BSD licensed instead of trying to insist that it be LGPL. The block layer will still be [L]GPL because of other files linked together, but there is nothing inherently wrong with linking a BSD file into an [L]GPL product. In other words, if you are okay with keeping the existing looser BSD license on this file only, it still won't change the license of the overall block layer, and it would save you the hassle of tracking down earlier authors to ask for a relicense.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#5 lore raw

Re: [Qemu-devel] [PATCH V9 01/14] block: move bdrv_snapshot_find() to block/snapshot.c

Quoted 8 lines · Eric Blake

As far as I can tell, there is nothing wrong with leaving the file as BSD licensed instead of trying to insist that it be LGPL. The block layer will still be [L]GPL because of other files linked together, but there is nothing inherently wrong with linking a BSD file into an [L]GPL product. In other words, if you are okay with keeping the existing looser BSD license on this file only, it still won't change the license of the overall block layer, and it would save you the hassle of tracking down earlier authors to ask for a relicense.

Another alternative is to have two licenses covering appropriate portions of the file. For example, aio-win32.c has two licenses: a GPL2-only license for older history, and a GPLv2+ license for all new changes. In your case, you might be able to write a license that states that contents of code copied from other files is BSD, but all new contributions are LGPLv2+.

But again, this is something where I suggest you get an official answer from a maintainer, and not just opinions from a random reviewer, regarding what approach you should take to licensing your code motion.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#6 lore raw

Re: [Qemu-devel] [PATCH V9 01/14] block: move bdrv_snapshot_find() to block/snapshot.c

Quoted 17 lines · Eric Blake
Quoted 8 lines · Eric Blake

As far as I can tell, there is nothing wrong with leaving the file as BSD licensed instead of trying to insist that it be LGPL. The block layer will still be [L]GPL because of other files linked together, but there is nothing inherently wrong with linking a BSD file into an [L]GPL product. In other words, if you are okay with keeping the existing looser BSD license on this file only, it still won't change the license of the overall block layer, and it would save you the hassle of tracking down earlier authors to ask for a relicense.

Another alternative is to have two licenses covering appropriate portions of the file. For example, aio-win32.c has two licenses: a GPL2-only license for older history, and a GPLv2+ license for all new changes. In your case, you might be able to write a license that states that contents of code copied from other files is BSD, but all new contributions are LGPLv2+.

Quoted 4 lines

But again, this is something where I suggest you get an official answer from a maintainer, and not just opinions from a random reviewer, regarding what approach you should take to licensing your code motion.

Thanks for your comments, I am ignorant about licenses.
Dual license seems good to me. Paolo, can I have your opinion on this?

Signature · 3 lines
Best Regards

Wenchao Xia
#7 lore raw

Re: [Qemu-devel] [PATCH V9 01/14] block: move bdrv_snapshot_find() to block/snapshot.c

In reply to Wenchao Xia

Am 12.03.2013 um 06:01 hat Wenchao Xia geschrieben:

Quoted 42 lines
Quoted 32 lines · Eric Blake
Quoted 15 lines · Wenchao Xia

This patch adds block/snapshot.c and then moves the function
there. It also fixes small code style errors reported by check script.

---
 block/Makefile.objs      |    1 +
 block/snapshot.c         |   37 +++++++++++++++++++++++++++++++++++++
 include/block/snapshot.h |   26 ++++++++++++++++++++++++++
 savevm.c                 |   23 +----------------------
 4 files changed, 65 insertions(+), 22 deletions(-)
 create mode 100644 block/snapshot.c
 create mode 100644 include/block/snapshot.h

+++ b/block/snapshot.c

block/snapshot.c line 4

Quoted 4 lines
block/snapshot.c new file +4 -0
@@ -0,0 +1,37 @@
+/*
+ * Snapshot related functions.
+ *
+ * Copyright IBM, Corp. 2013

Technically, since you are moving code from savevm.c, you should also preserve the copyright on that moved code:

* Copyright (c) 2003-2008 Fabrice Bellard

block/snapshot.c line 9

Quoted 5 lines
block/snapshot.c new file +5 -0
+ *
+ * Authors:
+ *  Wenchao Xia   <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
Quoted 9 lines

Furthermore, the code you are moving was under BSD license, so by moving the code, you have changed its license to something more restrictive. Personally, I like LGPL better than BSD, but as I'm not the copyright holder of the original code, and neither are you, I'm not sure that either of us is qualified to make that change. Therefore, I'm unwilling to add my Reviewed-by, even though the code motion itself is correct, without a maintainer chiming in on whether your licensing is appropriate or needs an adjustment.

Quoted 2 lines

Oops, Since it belongs to block layer I hope it can be LGPL2. Do you
know how to contact Fabrice Bellard to ask for a change?

Fabrice is not the only copyright owner of this file.

Just copy the license as it is, changing licenses is always a nasty thing and as I'm not a lawyer I prefer to stay on the safe side. The MIT license works well enough, there's no real reason to change it.

Kevin

#8 lore raw

Re: [Qemu-devel] [PATCH V9 01/14] block: move bdrv_snapshot_find() to block/snapshot.c

Quoted 9 lines · Kevin Wolf

Am 12.03.2013 um 06:01 hat Wenchao Xia geschrieben:

Quoted 2 lines

Oops, Since it belongs to block layer I hope it can be LGPL2. Do you
know how to contact Fabrice Bellard to ask for a change?

Fabrice is not the only copyright owner of this file.

Just copy the license as it is, changing licenses is always a nasty thing and as I'm not a lawyer I prefer to stay on the safe side. The MIT license works well enough, there's no real reason to change it.

*Relicensing* a file is indeed "nasty" in the sense that it's a huge
hassle: you have to track down all copyright holders and get their permission.

But this isn't relicensing. This is exercising your *right* to incorporate permissively-licensed stuff into work covered by a compatible, stronger license. That right was irrevocably granted to you by the copyright holders. You don't have to ask anyone to exercise it.

Of course, the stronger license still has to be compatible with GPLv2, so we can accept the result into QEMU.

If a subsystem has additional requirements on licenses, its maintainers will explain them to you. For what it's worth, substantial parts of the block layer are already GPLv2+.

You don't *have* to switch to a stronger license, of course. It's your choice. Myself, I prefer to protect any substantial work I do with a strong copyleft license such as GPLv2+.

Reviewed-by
#9 lore raw

Re: [Qemu-devel] [PATCH V9 01/14] block: move bdrv_snapshot_find() to block/snapshot.c

Quoted 4 lines · Markus Armbruster

But this isn't relicensing. This is exercising your *right* to incorporate permissively-licensed stuff into work covered by a compatible, stronger license. That right was irrevocably granted to you by the copyright holders. You don't have to ask anyone to exercise it.

Cool - I like that explanation. In that case, my concern has been answered, and you are free to add:

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#10 lore raw

Re: [Qemu-devel] [PATCH V9 01/14] block: move bdrv_snapshot_find() to block/snapshot.c

In reply to Markus Armbruster

Am 13.03.2013 um 19:19 hat Markus Armbruster geschrieben:

Quoted 12 lines
Quoted 9 lines · Kevin Wolf

Am 12.03.2013 um 06:01 hat Wenchao Xia geschrieben:

Quoted 2 lines

Oops, Since it belongs to block layer I hope it can be LGPL2. Do you
know how to contact Fabrice Bellard to ask for a change?

Fabrice is not the only copyright owner of this file.

Just copy the license as it is, changing licenses is always a nasty thing and as I'm not a lawyer I prefer to stay on the safe side. The MIT license works well enough, there's no real reason to change it.

Quoted 8 lines

*Relicensing* a file is indeed "nasty" in the sense that it's a huge
hassle: you have to track down all copyright holders and get their permission.

But this isn't relicensing. This is exercising your *right* to incorporate permissively-licensed stuff into work covered by a compatible, stronger license. That right was irrevocably granted to you by the copyright holders. You don't have to ask anyone to exercise it.

But you have to do it right. This specific patch would introduce a copyright violation. It's really not that hard to conform to the terms of the MIT license, but that doesn't mean that you can ignore it. There is exactly one requirement and it reads like this:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

(I'm still waiting for a patch to blockdev.c, for which you did it wrong, by the way)

Quoted 6 lines

Of course, the stronger license still has to be compatible with GPLv2, so we can accept the result into QEMU.

If a subsystem has additional requirements on licenses, its maintainers will explain them to you. For what it's worth, substantial parts of the block layer are already GPLv2+.

What parts exactly? As long as there are plans for a libqblock and as long as it doesn't seem completely impossible to have it under LGPL, I will ask to use either MIT or LGPL for block layer code (this doesn't apply to qemu-only code that isn't used in the tools - in this sense, things like blockdev.c are not part of the block layer)

Quoted 3 lines

You don't *have* to switch to a stronger license, of course. It's your choice. Myself, I prefer to protect any substantial work I do with a strong copyleft license such as GPLv2+.

And it's my choice if I accept a patch that does nothing except moving code and switching to a stronger license. It feels wrong to do this, even though it may be legal. If you want to change the license for whatever reason, you should at least add substantial code of your own to justify this.

Kevin

#11 lore raw

Re: [Qemu-devel] [PATCH V9 01/14] block: move bdrv_snapshot_find() to block/snapshot.c

Quoted 22 lines · Kevin Wolf

Am 13.03.2013 um 19:19 hat Markus Armbruster geschrieben:

Quoted 12 lines
Quoted 9 lines · Kevin Wolf

Am 12.03.2013 um 06:01 hat Wenchao Xia geschrieben:

Quoted 2 lines

Oops, Since it belongs to block layer I hope it can be LGPL2. Do you
know how to contact Fabrice Bellard to ask for a change?

Fabrice is not the only copyright owner of this file.

Just copy the license as it is, changing licenses is always a nasty thing and as I'm not a lawyer I prefer to stay on the safe side. The MIT license works well enough, there's no real reason to change it.

Quoted 8 lines

*Relicensing* a file is indeed "nasty" in the sense that it's a huge
hassle: you have to track down all copyright holders and get their permission.

But this isn't relicensing. This is exercising your *right* to incorporate permissively-licensed stuff into work covered by a compatible, stronger license. That right was irrevocably granted to you by the copyright holders. You don't have to ask anyone to exercise it.

Quoted 7 lines

But you have to do it right. This specific patch would introduce a copyright violation. It's really not that hard to conform to the terms of the MIT license, but that doesn't mean that you can ignore it. There is exactly one requirement and it reads like this:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

That's why I pointed to resources and examples on how to do it properly.

Quoted 2 lines

(I'm still waiting for a patch to blockdev.c, for which you did it wrong, by the way)

Oops, that one fell through the cracks. Patch coming.

Quoted 7 lines
Quoted 6 lines

Of course, the stronger license still has to be compatible with GPLv2, so we can accept the result into QEMU.

If a subsystem has additional requirements on licenses, its maintainers will explain them to you. For what it's worth, substantial parts of the block layer are already GPLv2+.

Quoted 5 lines

What parts exactly? As long as there are plans for a libqblock and as long as it doesn't seem completely impossible to have it under LGPL, I will ask to use either MIT or LGPL for block layer code (this doesn't apply to qemu-only code that isn't used in the tools - in this sense, things like blockdev.c are not part of the block layer)

$ git-grep -lw GPL block block*
block-migration.c
block/blkverify.c
block/gluster.c
block/linux-aio.c
block/raw-aio.h
block/rbd.c
block/sheepdog.c
blockdev-nbd.c
blockdev.c
Quoted 9 lines
Quoted 3 lines

You don't *have* to switch to a stronger license, of course. It's your choice. Myself, I prefer to protect any substantial work I do with a strong copyleft license such as GPLv2+.

And it's my choice if I accept a patch that does nothing except moving code and switching to a stronger license. It feels wrong to do this, even though it may be legal. If you want to change the license for whatever reason, you should at least add substantial code of your own to justify this.

I wouldn't submit such a patch. Not everything that's legal is proper.

#12 lore raw

Re: [Qemu-devel] [PATCH V9 01/14] block: move bdrv_snapshot_find() to block/snapshot.c

Am 14.03.2013 um 13:10 hat Markus Armbruster geschrieben:

Quoted 9 lines
Quoted 7 lines · Kevin Wolf

But you have to do it right. This specific patch would introduce a copyright violation. It's really not that hard to conform to the terms of the MIT license, but that doesn't mean that you can ignore it. There is exactly one requirement and it reads like this:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Quoted 6 lines

That's why I pointed to resources and examples on how to do it properly.

Quoted 2 lines

(I'm still waiting for a patch to blockdev.c, for which you did it wrong, by the way)

Oops, that one fell through the cracks. Patch coming.

Thanks.

Quoted 13 lines
Quoted 7 lines
Quoted 6 lines

Of course, the stronger license still has to be compatible with GPLv2, so we can accept the result into QEMU.

If a subsystem has additional requirements on licenses, its maintainers will explain them to you. For what it's worth, substantial parts of the block layer are already GPLv2+.

Quoted 5 lines

What parts exactly? As long as there are plans for a libqblock and as long as it doesn't seem completely impossible to have it under LGPL, I will ask to use either MIT or LGPL for block layer code (this doesn't apply to qemu-only code that isn't used in the tools - in this sense, things like blockdev.c are not part of the block layer)

Quoted 10 lines
$ git-grep -lw GPL block block*
block-migration.c
block/blkverify.c
block/gluster.c
block/linux-aio.c
block/raw-aio.h
block/rbd.c
block/sheepdog.c
blockdev-nbd.c
blockdev.c

Luckily, none of these are really critical for a libqblock library, even though they would be nice to have.

If we can't license such a library as LGPL, we would lose the most important potential user, which is libvirt. In which case I probably wouldn't want to bother with providing a library at all.

Kevin

#13 lore raw

Re: [Qemu-devel] [PATCH V9 01/14] block: move bdrv_snapshot_find() to block/snapshot.c

Quoted 43 lines · Kevin Wolf

Am 14.03.2013 um 13:10 hat Markus Armbruster geschrieben:

Quoted 9 lines
Quoted 7 lines · Kevin Wolf

But you have to do it right. This specific patch would introduce a copyright violation. It's really not that hard to conform to the terms of the MIT license, but that doesn't mean that you can ignore it. There is exactly one requirement and it reads like this:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Quoted 6 lines

That's why I pointed to resources and examples on how to do it properly.

Quoted 2 lines

(I'm still waiting for a patch to blockdev.c, for which you did it wrong, by the way)

Oops, that one fell through the cracks. Patch coming.

Thanks.

Quoted 13 lines
Quoted 7 lines
Quoted 6 lines

Of course, the stronger license still has to be compatible with GPLv2, so we can accept the result into QEMU.

If a subsystem has additional requirements on licenses, its maintainers will explain them to you. For what it's worth, substantial parts of the block layer are already GPLv2+.

Quoted 5 lines

What parts exactly? As long as there are plans for a libqblock and as long as it doesn't seem completely impossible to have it under LGPL, I will ask to use either MIT or LGPL for block layer code (this doesn't apply to qemu-only code that isn't used in the tools - in this sense, things like blockdev.c are not part of the block layer)

Quoted 10 lines
$ git-grep -lw GPL block block*
block-migration.c
block/blkverify.c
block/gluster.c
block/linux-aio.c
block/raw-aio.h
block/rbd.c
block/sheepdog.c
blockdev-nbd.c
blockdev.c
Quoted 9 lines

Luckily, none of these are really critical for a libqblock library, even though they would be nice to have.

If we can't license such a library as LGPL, we would lose the most important potential user, which is libvirt. In which case I probably wouldn't want to bother with providing a library at all.

Kevin

As the discuss, I feel a direct copy of the license is the
easiest way, the original one is a good enough MIT license, if my understanding is correct.
One more question: should the date be changed to 2003-2013 in
new file?

/*
* QEMU System Emulator
*
* Copyright (c) 2003-2008 Fabrice Bellard
.....

Signature · 3 lines
Best Regards

Wenchao Xia
#14 lore raw

Re: [Qemu-devel] [PATCH V9 01/14] block: move bdrv_snapshot_find() to block/snapshot.c

Am 15.03.2013 um 07:23 hat Wenchao Xia geschrieben:

Quoted 59 lines
Quoted 43 lines · Kevin Wolf

Am 14.03.2013 um 13:10 hat Markus Armbruster geschrieben:

Quoted 9 lines
Quoted 7 lines · Kevin Wolf

But you have to do it right. This specific patch would introduce a copyright violation. It's really not that hard to conform to the terms of the MIT license, but that doesn't mean that you can ignore it. There is exactly one requirement and it reads like this:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Quoted 6 lines

That's why I pointed to resources and examples on how to do it properly.

Quoted 2 lines

(I'm still waiting for a patch to blockdev.c, for which you did it wrong, by the way)

Oops, that one fell through the cracks. Patch coming.

Thanks.

Quoted 13 lines
Quoted 7 lines
Quoted 6 lines

Of course, the stronger license still has to be compatible with GPLv2, so we can accept the result into QEMU.

If a subsystem has additional requirements on licenses, its maintainers will explain them to you. For what it's worth, substantial parts of the block layer are already GPLv2+.

Quoted 5 lines

What parts exactly? As long as there are plans for a libqblock and as long as it doesn't seem completely impossible to have it under LGPL, I will ask to use either MIT or LGPL for block layer code (this doesn't apply to qemu-only code that isn't used in the tools - in this sense, things like blockdev.c are not part of the block layer)

Quoted 10 lines
$ git-grep -lw GPL block block*
block-migration.c
block/blkverify.c
block/gluster.c
block/linux-aio.c
block/raw-aio.h
block/rbd.c
block/sheepdog.c
blockdev-nbd.c
blockdev.c
Quoted 9 lines

Luckily, none of these are really critical for a libqblock library, even though they would be nice to have.

If we can't license such a library as LGPL, we would lose the most important potential user, which is libvirt. In which case I probably wouldn't want to bother with providing a library at all.

Kevin

As the discuss, I feel a direct copy of the license is the
easiest way, the original one is a good enough MIT license, if my understanding is correct.
One more question: should the date be changed to 2003-2013 in
new file?

Quoted 5 lines

/*
* QEMU System Emulator
*
* Copyright (c) 2003-2008 Fabrice Bellard
.....

Probably not that important, but I would leave it as it is.

Kevin

#15 lore raw

Re: [Qemu-devel] [PATCH V9 01/14] block: move bdrv_snapshot_find() to block/snapshot.c

In reply to Eric Blake
Quoted 32 lines · Eric Blake
Quoted 15 lines · Wenchao Xia

This patch adds block/snapshot.c and then moves the function
there. It also fixes small code style errors reported by check script.

---
 block/Makefile.objs      |    1 +
 block/snapshot.c         |   37 +++++++++++++++++++++++++++++++++++++
 include/block/snapshot.h |   26 ++++++++++++++++++++++++++
 savevm.c                 |   23 +----------------------
 4 files changed, 65 insertions(+), 22 deletions(-)
 create mode 100644 block/snapshot.c
 create mode 100644 include/block/snapshot.h

+++ b/block/snapshot.c

block/snapshot.c line 4

Quoted 4 lines
block/snapshot.c new file +4 -0
@@ -0,0 +1,37 @@
+/*
+ * Snapshot related functions.
+ *
+ * Copyright IBM, Corp. 2013

Technically, since you are moving code from savevm.c, you should also preserve the copyright on that moved code:

* Copyright (c) 2003-2008 Fabrice Bellard

block/snapshot.c line 9

Quoted 5 lines
block/snapshot.c new file +5 -0
+ *
+ * Authors:
+ *  Wenchao Xia   <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
Quoted 8 lines

Furthermore, the code you are moving was under BSD license, so by moving the code, you have changed its license to something more restrictive. Personally, I like LGPL better than BSD, but as I'm not the copyright holder of the original code, and neither are you, I'm not sure that either of us is qualified to make that change. Therefore, I'm unwilling to add my Reviewed-by, even though the code motion itself is correct, without a maintainer chiming in on whether your licensing is appropriate or needs an adjustment.

Code motion from a single file to a new file is the simplest case. You can't go wrong by preserving the license notice exactly then.

Things get a bit messy when you move code to an existing file that already has a different license notice. Whether that's even possible depends on the licenses.

An important special case is adding copyrightable GPL'ed modifications to a permissively-licensed file. This need not be just code motion, it could also happen when you start with a bit of code moved out of a permissively- licensed file, then add copyrightable code of your own, which you want protected by the GPL.

For how to do that properly, check out the Software Freedom Law Center's white paper "Maintaining Permissive-Licensed Files in a GPL-Licensed
Project: Guidelines for Developers"[*] section 2.2 "Adding GPL’d modifications to permissive-licensed files".

An in-tree example is hw/hd-geometry.c, which I rewrote substantially after moving it out of block.c,

[*] https://www.softwarefreedom.org/resources/2007/gpl-non-gpl-collaboration.html

#16 lore raw

PATCH v9 2/14 block: distinguish id and name in bdrv_find_snapshot()

In reply to Wenchao Xia

To make it clear about id and name in searching, the API is changed
a bit to distinguish them, and caller can choose to search by id or name. Searching will be done with higher priority of id. This function also returns negative value from bdrv_snapshot_list() instead of -ENOENT on error now.

---
 block/snapshot.c         |   46 ++++++++++++++++++++++++++++++++++++++--------
 include/block/snapshot.h |    2 +-
 savevm.c                 |   10 +++++-----
 3 files changed, 44 insertions(+), 14 deletions(-)
block/snapshot.c +38 -8
index 8de73b4..1449b3d 100644
@@ -13,8 +13,20 @@
 
 #include "block/snapshot.h"
 
+/*
+ * Try find an internal snapshot with @id or @name, @id have higher priority
+ * in searching.
+ *
+ * @bs: block device to search on, must not be NULL.
+ * @sn_info: snapshot information to be filled in, must not be NULL.
+ * @id: snapshot id to search with, can be NULL.
+ * @name: snapshot name to search with, can be NULL.
+ *
+ * returns 0 and @sn_info is filled with related information if found,
+ * otherwise it returns negative value.
+ */
 int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
-                       const char *name)
+                       const char *id, const char *name)
 {
     QEMUSnapshotInfo *sn_tab, *sn;
     int nb_sns, i, ret;
@@ -22,16 +34,34 @@ int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
     ret = -ENOENT;
     nb_sns = bdrv_snapshot_list(bs, &sn_tab);
     if (nb_sns < 0) {
-        return ret;
+        return nb_sns;
     }
-    for (i = 0; i < nb_sns; i++) {
-        sn = &sn_tab[i];
-        if (!strcmp(sn->id_str, name) || !strcmp(sn->name, name)) {
-            *sn_info = *sn;
-            ret = 0;
-            break;
+
+    /* search by id */
+    if (id) {
+        for (i = 0; i < nb_sns; i++) {
+            sn = &sn_tab[i];
+            if (!strcmp(sn->id_str, id)) {
+                *sn_info = *sn;
+                ret = 0;
+                goto out;
+            }
         }
     }
+
+    /* search by name */
+    if (name) {
+        for (i = 0; i < nb_sns; i++) {
+            sn = &sn_tab[i];
+            if (!strcmp(sn->name, name)) {
+                *sn_info = *sn;
+                ret = 0;
+                goto out;
+            }
+        }
+    }
+
+ out:
     g_free(sn_tab);
     return ret;
 }
include/block/snapshot.h +1 -1
index 86891d1..fc9be7b 100644
@@ -22,5 +22,5 @@
 #include "block.h"
 
 int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
-                       const char *name);
+                       const char *id, const char *name);
 #endif
savevm.c +5 -5
index 95f19ca..6557750 100644
@@ -2073,7 +2073,7 @@ static int del_existing_snapshots(Monitor *mon, const char *name)
     bs = NULL;
     while ((bs = bdrv_next(bs))) {
         if (bdrv_can_snapshot(bs) &&
-            bdrv_snapshot_find(bs, snapshot, name) >= 0)
+            bdrv_snapshot_find(bs, snapshot, name, name) >= 0)
         {
             ret = bdrv_snapshot_delete(bs, name);
             if (ret < 0) {
@@ -2133,7 +2133,7 @@ void do_savevm(Monitor *mon, const QDict *qdict)
     sn->vm_clock_nsec = qemu_get_clock_ns(vm_clock);
 
     if (name) {
-        ret = bdrv_snapshot_find(bs, old_sn, name);
+        ret = bdrv_snapshot_find(bs, old_sn, name, name);
         if (ret >= 0) {
             pstrcpy(sn->name, sizeof(sn->name), old_sn->name);
             pstrcpy(sn->id_str, sizeof(sn->id_str), old_sn->id_str);
@@ -2224,7 +2224,7 @@ int load_vmstate(const char *name)
     }
 
     /* Don't even try to load empty VM states */
-    ret = bdrv_snapshot_find(bs_vm_state, &sn, name);
+    ret = bdrv_snapshot_find(bs_vm_state, &sn, name, name);
     if (ret < 0) {
         return ret;
     } else if (sn.vm_state_size == 0) {
@@ -2248,7 +2248,7 @@ int load_vmstate(const char *name)
             return -ENOTSUP;
         }
 
-        ret = bdrv_snapshot_find(bs, &sn, name);
+        ret = bdrv_snapshot_find(bs, &sn, name, name);
         if (ret < 0) {
             error_report("Device '%s' does not have the requested snapshot '%s'",
                            bdrv_get_device_name(bs), name);
@@ -2354,7 +2354,7 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict)
 
         while ((bs1 = bdrv_next(bs1))) {
             if (bdrv_can_snapshot(bs1) && bs1 != bs) {
-                ret = bdrv_snapshot_find(bs1, sn_info, sn->id_str);
+                ret = bdrv_snapshot_find(bs1, sn_info, sn->id_str, NULL);
                 if (ret < 0) {
                     available = 0;
                     break;
Signature · 1 line
1.7.1
#17 lore raw

PATCH v9 3/14 qemu-img: remove unused parameter in collect_image_info()

In reply to Wenchao Xia

Parameter *fmt was not used, so remove it.

---
 qemu-img.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
qemu-img.c +2 -3
index 471de7d..f4e5d90 100644
@@ -1640,8 +1640,7 @@ static void dump_json_image_info(ImageInfo *info)
 
 static void collect_image_info(BlockDriverState *bs,
                    ImageInfo *info,
-                   const char *filename,
-                   const char *fmt)
+                   const char *filename)
 {
     uint64_t total_sectors;
     char backing_filename[1024];
@@ -1815,7 +1814,7 @@ static ImageInfoList *collect_image_info_list(const char *filename,
         }
 
         info = g_new0(ImageInfo, 1);
-        collect_image_info(bs, info, filename, fmt);
+        collect_image_info(bs, info, filename);
         collect_snapshots(bs, info);
 
         elem = g_new0(ImageInfoList, 1);
Signature · 1 line
1.7.1
#18 lore raw

PATCH v9 4/14 block: move collect_snapshots() and collect_image_info() to block/qapi.c

In reply to Wenchao Xia

This patch adds block/qapi.c and moves the functions there. To avoid
conflict and tip better, macro in header file is BLOCK_QAPI_H instead of QAPI_H. The moving is for making review easier, those functions will be modified and renamed later.

---
 block/Makefile.objs  |    2 +-
 block/qapi.c         |   96 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/block/qapi.h |   24 ++++++++++++
 qemu-img.c           |   86 ++-------------------------------------------
 4 files changed, 124 insertions(+), 84 deletions(-)
 create mode 100644 block/qapi.c
 create mode 100644 include/block/qapi.h
block/Makefile.objs +1 -1
index 60a4cd2..fc27bed 100644
@@ -3,7 +3,7 @@ block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-c
 block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
 block-obj-y += qed-check.o
 block-obj-y += parallels.o blkdebug.o blkverify.o
-block-obj-y += snapshot.o
+block-obj-y += snapshot.o qapi.o
 block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o
 block-obj-$(CONFIG_POSIX) += raw-posix.o
 block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
block/qapi.c new file +96 -0

96 lines not on this page · raw message

include/block/qapi.h new file +24 -0
new file mode 100644
index 0000000..ecb5242
@@ -0,0 +1,24 @@
+/*
+ * Block layer qmp related functions
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Wenchao Xia   <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.
+ *
+ */
+
+#ifndef BLOCK_QAPI_H
+#define BLOCK_QAPI_H
+
+#include "qapi-types.h"
+#include "block/block.h"
+
+void bdrv_collect_snapshots(BlockDriverState *bs , ImageInfo *info);
+void bdrv_collect_image_info(BlockDriverState *bs,
+                             ImageInfo *info,
+                             const char *filename);
+#endif
qemu-img.c +3 -83

110 lines not on this page · raw message

Signature · 1 line
1.7.1
#19 lore raw

Re: [Qemu-devel] [PATCH V9 04/14] block: move collect_snapshots() and collect_image_info() to block/qapi.c

Quoted 18 lines · Wenchao Xia

This patch adds block/qapi.c and moves the functions there. To avoid
conflict and tip better, macro in header file is BLOCK_QAPI_H instead of QAPI_H. The moving is for making review easier, those functions will be modified and renamed later.

---
 block/Makefile.objs  |    2 +-
 block/qapi.c         |   96 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/block/qapi.h |   24 ++++++++++++
 qemu-img.c           |   86 ++-------------------------------------------
 4 files changed, 124 insertions(+), 84 deletions(-)
 create mode 100644 block/qapi.c
 create mode 100644 include/block/qapi.h

+++ b/block/qapi.c

block/qapi.c line 10

Quoted 10 lines
block/qapi.c new file +10 -0
@@ -0,0 +1,96 @@
+/*
+ * Block layer qmp related functions
+ *
+ * Copyright IBM, Corp. 2013
+ *
+ * Authors:
+ *  Wenchao Xia   <[email protected]>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2 or later.
+ * See the COPYING.LIB file in the top-level directory.

This is another case of moving code from a BSD file into an LGPLv2+ file; depending on what the resolution is for 1/14, you should do the same thing here.

Everything else looks okay, but I'm reluctant to add reviewed-by without the license issue sorted.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by
#20 lore raw

Re: [Qemu-devel] [PATCH V9 04/14] block: move collect_snapshots() and collect_image_info() to block/qapi.c

Quoted 8 lines · Eric Blake
Quoted 5 lines · Wenchao Xia

This patch adds block/qapi.c and moves the functions there. To avoid
conflict and tip better, macro in header file is BLOCK_QAPI_H instead of QAPI_H. The moving is for making review easier, those functions will be modified and renamed later.

Quoted 6 lines

This is another case of moving code from a BSD file into an LGPLv2+ file; depending on what the resolution is for 1/14, you should do the same thing here.

Everything else looks okay, but I'm reluctant to add reviewed-by without the license issue sorted.

Same argument as for 1/14 - you exercised your right to copy code from a permissive license into a stronger license, which is an acceptable use of open source code. Hence:

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#21 lore raw

PATCH v9 5/14 block: add snapshot info query function bdrv_query_snapshot_info_list()

In reply to Wenchao Xia

This patch adds function bdrv_query_snapshot_info_list(), which will
retrieve snapshot info of an image in qmp object format. The implementation is based on the code moved from qemu-img.c with modification to fit more for qmp based block layer API.

---
 block/qapi.c         |   52 +++++++++++++++++++++++++++++++++++++------------
 include/block/qapi.h |    4 ++-
 qemu-img.c           |    4 ++-
 3 files changed, 45 insertions(+), 15 deletions(-)
block/qapi.c +39 -13
index 51692d3..2da28db 100644
@@ -14,29 +14,53 @@
 #include "block/qapi.h"
 #include "block/block_int.h"
 
-void bdrv_collect_snapshots(BlockDriverState *bs , ImageInfo *info)
+/* return 0 on success, and @p_list will be set only on success. */
+int bdrv_query_snapshot_info_list(BlockDriverState *bs,
+                                  SnapshotInfoList **p_list,
+                                  Error **errp)
 {
     int i, sn_count;
     QEMUSnapshotInfo *sn_tab = NULL;
-    SnapshotInfoList *info_list, *cur_item = NULL;
+    SnapshotInfoList *info_list, *cur_item = NULL, *head = NULL;
+    SnapshotInfo *info;
+
     sn_count = bdrv_snapshot_list(bs, &sn_tab);
+    if (sn_count < 0) {
+        const char *dev = bdrv_get_device_name(bs);
+        switch (sn_count) {
+        case -ENOMEDIUM:
+            error_setg(errp, "Device '%s' is not inserted", dev);
+            break;
+        case -ENOTSUP:
+            error_setg(errp,
+                       "Device '%s' does not support internal snapshots",
+                       dev);
+            break;
+        default:
+            error_setg(errp, "Can't list snapshots of device '%s': %s",
+                       dev, strerror(-sn_count));
+            break;
+        }
+        return sn_count;
+    }
 
     for (i = 0; i < sn_count; i++) {
-        info->has_snapshots = true;
-        info_list = g_new0(SnapshotInfoList, 1);
 
-        info_list->value                = g_new0(SnapshotInfo, 1);
-        info_list->value->id            = g_strdup(sn_tab[i].id_str);
-        info_list->value->name          = g_strdup(sn_tab[i].name);
-        info_list->value->vm_state_size = sn_tab[i].vm_state_size;
-        info_list->value->date_sec      = sn_tab[i].date_sec;
-        info_list->value->date_nsec     = sn_tab[i].date_nsec;
-        info_list->value->vm_clock_sec  = sn_tab[i].vm_clock_nsec / 1000000000;
-        info_list->value->vm_clock_nsec = sn_tab[i].vm_clock_nsec % 1000000000;
+        info = g_new0(SnapshotInfo, 1);
+        info->id            = g_strdup(sn_tab[i].id_str);
+        info->name          = g_strdup(sn_tab[i].name);
+        info->vm_state_size = sn_tab[i].vm_state_size;
+        info->date_sec      = sn_tab[i].date_sec;
+        info->date_nsec     = sn_tab[i].date_nsec;
+        info->vm_clock_sec  = sn_tab[i].vm_clock_nsec / 1000000000;
+        info->vm_clock_nsec = sn_tab[i].vm_clock_nsec % 1000000000;
+
+        info_list = g_new0(SnapshotInfoList, 1);
+        info_list->value = info;
 
         /* XXX: waiting for the qapi to support qemu-queue.h types */
         if (!cur_item) {
-            info->snapshots = cur_item = info_list;
+            head = cur_item = info_list;
         } else {
             cur_item->next = info_list;
             cur_item = info_list;
@@ -45,6 +69,8 @@ void bdrv_collect_snapshots(BlockDriverState *bs , ImageInfo *info)
     }
 
     g_free(sn_tab);
+    *p_list = head;
+    return 0;
 }
 
 void bdrv_collect_image_info(BlockDriverState *bs,
include/block/qapi.h +3 -1
index ecb5242..4b46165 100644
@@ -17,7 +17,9 @@
 #include "qapi-types.h"
 #include "block/block.h"
 
-void bdrv_collect_snapshots(BlockDriverState *bs , ImageInfo *info);
+int bdrv_query_snapshot_info_list(BlockDriverState *bs,
+                                  SnapshotInfoList **p_list,
+                                  Error **errp);
 void bdrv_collect_image_info(BlockDriverState *bs,
                              ImageInfo *info,
                              const char *filename);
qemu-img.c +3 -1
index 2e1698f..cb534c9 100644
@@ -1735,7 +1735,9 @@ static ImageInfoList *collect_image_info_list(const char *filename,
 
         info = g_new0(ImageInfo, 1);
         bdrv_collect_image_info(bs, info, filename);
-        bdrv_collect_snapshots(bs, info);
+        if (!bdrv_query_snapshot_info_list(bs, &info->snapshots, NULL)) {
+            info->has_snapshots = true;
+        }
 
         elem = g_new0(ImageInfoList, 1);
         elem->value = info;
Signature · 1 line
1.7.1
#22 lore raw

PATCH v9 6/14 block: add check for VM snapshot in bdrv_query_snapshot_info_list()

In reply to Wenchao Xia

This patch adds a parameter to tell whether return valid snapshots
for whole VM only.

---
 block/qapi.c         |   42 ++++++++++++++++++++++++++++++++++++++++--
 include/block/qapi.h |    1 +
 qemu-img.c           |    3 ++-
 3 files changed, 43 insertions(+), 3 deletions(-)
block/qapi.c +40 -2
index 2da28db..1d99f5a 100644
@@ -12,11 +12,47 @@
  */
 
 #include "block/qapi.h"
+#include "block/snapshot.h"
 #include "block/block_int.h"
 
-/* return 0 on success, and @p_list will be set only on success. */
+/*
+ * check whether the snapshot is valid for whole vm.
+ *
+ * @sn: snapshot info to be checked.
+ * @bs: where @sn was found.
+ *
+ * return true if the snapshot is consistent for the VM.
+ */
+static bool snapshot_valid_for_vm(const QEMUSnapshotInfo *sn,
+                                  BlockDriverState *bs)
+{
+    BlockDriverState *bs1 = NULL;
+    QEMUSnapshotInfo s, *sn_info = &s;
+    int ret;
+
+    /* Check logic is connected with load_vmstate():
+       Only check the devices that can snapshot, other devices that can't
+       take snapshot, for example, readonly ones, will be ignored in
+       load_vmstate(). */
+    while ((bs1 = bdrv_next(bs1))) {
+        if (bdrv_can_snapshot(bs1) && bs1 != bs) {
+            ret = bdrv_snapshot_find(bs1, sn_info, sn->id_str, NULL);
+            if (ret < 0) {
+                return false;
+            }
+        }
+    }
+    return true;
+}
+
+/*
+ * return 0 on success, and @p_list will be set only on success. If
+ * @vm_snapshot is true, limit the results to snapshots valid for the
+ * whole VM.
+ */
 int bdrv_query_snapshot_info_list(BlockDriverState *bs,
                                   SnapshotInfoList **p_list,
+                                  bool vm_snapshot,
                                   Error **errp)
 {
     int i, sn_count;
@@ -45,7 +81,9 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,
     }
 
     for (i = 0; i < sn_count; i++) {
-
+        if (vm_snapshot && !snapshot_valid_for_vm(&sn_tab[i], bs)) {
+            continue;
+        }
         info = g_new0(SnapshotInfo, 1);
         info->id            = g_strdup(sn_tab[i].id_str);
         info->name          = g_strdup(sn_tab[i].name);
include/block/qapi.h +1 -0
index 4b46165..092ad8c 100644
@@ -19,6 +19,7 @@
 
 int bdrv_query_snapshot_info_list(BlockDriverState *bs,
                                   SnapshotInfoList **p_list,
+                                  bool vm_snapshot,
                                   Error **errp);
 void bdrv_collect_image_info(BlockDriverState *bs,
                              ImageInfo *info,
qemu-img.c +2 -1
index cb534c9..83532b1 100644
@@ -1735,7 +1735,8 @@ static ImageInfoList *collect_image_info_list(const char *filename,
 
         info = g_new0(ImageInfo, 1);
         bdrv_collect_image_info(bs, info, filename);
-        if (!bdrv_query_snapshot_info_list(bs, &info->snapshots, NULL)) {
+        if (!bdrv_query_snapshot_info_list(bs, &info->snapshots,
+                                          false, NULL)) {
             info->has_snapshots = true;
         }
 
Signature · 1 line
1.7.1
Reviewed-by on v9 6/14
#23 lore raw

Re: [Qemu-devel] [PATCH V9 06/14] block: add check for VM snapshot in bdrv_query_snapshot_info_list()

Quoted 10 lines · Wenchao Xia

This patch adds a parameter to tell whether return valid snapshots
for whole VM only.

---
 block/qapi.c         |   42 ++++++++++++++++++++++++++++++++++++++++--
 include/block/qapi.h |    1 +
 qemu-img.c           |    3 ++-
 3 files changed, 43 insertions(+), 3 deletions(-)

block/qapi.c line 38

Quoted 6 lines
block/qapi.c +6 -0
+    /* Check logic is connected with load_vmstate():
+       Only check the devices that can snapshot, other devices that can't
+       take snapshot, for example, readonly ones, will be ignored in
+       load_vmstate(). */
+    while ((bs1 = bdrv_next(bs1))) {
+        if (bdrv_can_snapshot(bs1) && bs1 != bs) {

Minor optimization - you could rearrange the conjunct and check 'bs1 != bs' first, to avoid the overhead of bdrv_can_snapshot on bs. But that doesn't stop me from giving:

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#24 lore raw

PATCH v9 7/14 block: add image info query function bdrv_query_image_info()

In reply to Wenchao Xia

This patch adds function bdrv_query_image_info(), which will
retrieve image info in qmp object format. The implementation is based on the code moved from qemu-img.c, but uses block layer function to get snapshot info.

---
 block/qapi.c         |   39 ++++++++++++++++++++++++++++++++-------
 include/block/qapi.h |    6 +++---
 qemu-img.c           |    7 ++-----
 3 files changed, 37 insertions(+), 15 deletions(-)
block/qapi.c +32 -7
index 1d99f5a..b78ea5c 100644
@@ -111,18 +111,22 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,
     return 0;
 }
 
-void bdrv_collect_image_info(BlockDriverState *bs,
-                             ImageInfo *info,
-                             const char *filename)
+/* return 0 on success, and @p_info will be set only on success. */
+int bdrv_query_image_info(BlockDriverState *bs,
+                          ImageInfo **p_info,
+                          Error **errp)
 {
     uint64_t total_sectors;
-    char backing_filename[1024];
+    const char *backing_filename;
     char backing_filename2[1024];
     BlockDriverInfo bdi;
+    int ret;
+    Error *err = NULL;
+    ImageInfo *info = g_new0(ImageInfo, 1);
 
     bdrv_get_geometry(bs, &total_sectors);
 
-    info->filename        = g_strdup(filename);
+    info->filename        = g_strdup(bs->filename);
     info->format          = g_strdup(bdrv_get_format_name(bs));
     info->virtual_size    = total_sectors * 512;
     info->actual_size     = bdrv_get_allocated_file_size(bs);
@@ -139,8 +143,8 @@ void bdrv_collect_image_info(BlockDriverState *bs,
         info->dirty_flag = bdi.is_dirty;
         info->has_dirty_flag = true;
     }
-    bdrv_get_backing_filename(bs, backing_filename, sizeof(backing_filename));
-    if (backing_filename[0] != '\0') {
+    backing_filename = bs->backing_file;
+    if (backing_filename && backing_filename[0] != '\0') {
         info->backing_filename = g_strdup(backing_filename);
         info->has_backing_filename = true;
         bdrv_get_full_backing_filename(bs, backing_filename2,
@@ -157,4 +161,25 @@ void bdrv_collect_image_info(BlockDriverState *bs,
             info->has_backing_filename_format = true;
         }
     }
+
+    ret = bdrv_query_snapshot_info_list(bs, &info->snapshots, false, &err);
+    switch (ret) {
+    case 0:
+        info->has_snapshots = true;
+        break;
+    /* recoverable error */
+    case -ENOMEDIUM:
+        error_free(err);
+        break;
+    case -ENOTSUP:
+        error_free(err);
+        break;
+    default:
+        error_propagate(errp, err);
+        qapi_free_ImageInfo(info);
+        return ret;
+    }
+
+    *p_info = info;
+    return 0;
 }
include/block/qapi.h +3 -3
index 092ad8c..7ff1f98 100644
@@ -21,7 +21,7 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,
                                   SnapshotInfoList **p_list,
                                   bool vm_snapshot,
                                   Error **errp);
-void bdrv_collect_image_info(BlockDriverState *bs,
-                             ImageInfo *info,
-                             const char *filename);
+int bdrv_query_image_info(BlockDriverState *bs,
+                          ImageInfo **p_info,
+                          Error **errp);
 #endif
qemu-img.c +2 -5
index 83532b1..59d900a 100644
@@ -1733,11 +1733,8 @@ static ImageInfoList *collect_image_info_list(const char *filename,
             goto err;
         }
 
-        info = g_new0(ImageInfo, 1);
-        bdrv_collect_image_info(bs, info, filename);
-        if (!bdrv_query_snapshot_info_list(bs, &info->snapshots,
-                                          false, NULL)) {
-            info->has_snapshots = true;
+        if (bdrv_query_image_info(bs, &info, NULL)) {
+            goto err;
         }
 
         elem = g_new0(ImageInfoList, 1);
Signature · 1 line
1.7.1
#25 lore raw

PATCH v9 8/14 qmp: add interface query-snapshots

In reply to Wenchao Xia

This interface returns info of valid internal snapshots for whole vm.

---
 block/qapi.c     |   18 +++++++++++++++++
 qapi-schema.json |   14 +++++++++++++
 qmp-commands.hx  |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 87 insertions(+), 0 deletions(-)
block/qapi.c +18 -0
index b78ea5c..7bf2581 100644
@@ -14,6 +14,7 @@
 #include "block/qapi.h"
 #include "block/snapshot.h"
 #include "block/block_int.h"
+#include "qmp-commands.h"
 
 /*
  * check whether the snapshot is valid for whole vm.
@@ -183,3 +184,20 @@ int bdrv_query_image_info(BlockDriverState *bs,
     *p_info = info;
     return 0;
 }
+
+SnapshotInfoList *qmp_query_snapshots(Error **errp)
+{
+    BlockDriverState *bs;
+    SnapshotInfoList *list = NULL;
+
+    /* internal snapshot for whole vm */
+    bs = bdrv_snapshots();
+    if (!bs) {
+        error_setg(errp, "No available block device supports snapshots\n");
+        return NULL;
+    }
+
+    bdrv_query_snapshot_info_list(bs, &list, true, errp);
+
+    return list;
+}
qapi-schema.json +14 -0
index 28b070f..014365b 100644
@@ -839,6 +839,20 @@
 { 'command': 'query-block', 'returns': ['BlockInfo'] }
 
 ##
+# @query-snapshots:
+#
+# Get a list of internal snapshots for the whole virtual machine. Only valid
+# internal snapshots will be returned, inconsistent ones will be ignored
+#
+# Returns: a list of @SnapshotInfo describing all consistent virtual machine
+#          snapshots
+#
+# Since: 1.5
+##
+{ 'command': 'query-snapshots',
+  'returns': ['SnapshotInfo'] }
+
+##
 # @BlockDeviceStats:
 #
 # Statistics of a virtual block device or a block backing device.
qmp-commands.hx +55 -0

61 lines not on this page · raw message

Signature · 1 line
1.7.1
Reviewed-by on v9 8/14
#26 lore raw

Re: [Qemu-devel] [PATCH V9 08/14] qmp: add interface query-snapshots

Quoted 8 lines · Wenchao Xia

This interface returns info of valid internal snapshots for whole vm.

---
 block/qapi.c     |   18 +++++++++++++++++
 qapi-schema.json |   14 +++++++++++++
 qmp-commands.hx  |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 87 insertions(+), 0 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#27 lore raw

PATCH v9 9/14 qmp: add interface query-images

In reply to Wenchao Xia

This mirror function will return image info including snapshots,
and if specified backing image's info will also be returned. Now Qemu have both query-images and query-block interfaces.

---
 block/qapi.c     |   83 +++++++++++++++++++++++++++++++++++++++++++++++++
 qapi-schema.json |   33 ++++++++++++++++++++
 qmp-commands.hx  |   90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 206 insertions(+), 0 deletions(-)
block/qapi.c +83 -0
index 7bf2581..0cbbb8c 100644
@@ -201,3 +201,86 @@ SnapshotInfoList *qmp_query_snapshots(Error **errp)
 
     return list;
 }
+
+/* Collect all info for one bs, p_list point to the empty tail to be filled,
+   return the empty tail of the new list. @bs must be the top one. */
+static DeviceImageInfoList **
+collect_device_image_info_list(BlockDriverState *bs,
+                               bool show_backing,
+                               DeviceImageInfoList **p_list,
+                               Error **errp)
+{
+    DeviceImageInfoList **p_next = p_list;
+    char *device_name = bs->device_name;
+
+    while (bs) {
+        DeviceImageInfo *dii = g_malloc0(sizeof(*dii));
+        DeviceImageInfoList *diil = g_malloc0(sizeof(*diil));
+        diil->value = dii;
+        *p_next = diil;
+        p_next = &diil->next;
+
+        dii->device = g_strdup(device_name);
+        if (!bdrv_is_inserted(bs)) {
+            dii->has_image = false;
+            break;
+        }
+        dii->has_image = true;
+        if (bdrv_query_image_info(bs, &dii->image, errp)) {
+            break;
+        }
+
+        if (show_backing && bs->drv && bs->backing_hd) {
+            bs = bs->backing_hd;
+        } else {
+            bs = NULL;
+        }
+    }
+    return p_next;
+}
+
+DeviceImageInfoList *qmp_query_images(bool has_device,
+                                      const char *device,
+                                      bool has_backing,
+                                      bool backing,
+                                      Error **errp)
+{
+    DeviceImageInfoList *head = NULL, **p_next = &head;
+    BlockDriverState *bs = NULL;
+    Error *err = NULL;
+    const char *target_device = NULL;
+    bool show_backing = false;
+
+    if (has_device) {
+        target_device = device;
+    }
+    if (has_backing) {
+        show_backing = backing;
+    }
+
+    if (target_device) {
+        bs = bdrv_find(device);
+        if (!bs) {
+            error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+            return NULL;
+        }
+        collect_device_image_info_list(bs, show_backing, p_next, errp);
+        if (error_is_set(&err)) {
+            goto err;
+        }
+    } else {
+        while ((bs = bdrv_next(bs))) {
+            p_next = collect_device_image_info_list(bs, show_backing,
+                                                    p_next, errp);
+            if (error_is_set(&err)) {
+                goto err;
+            }
+        }
+    }
+
+    return head;
+
+ err:
+    qapi_free_DeviceImageInfoList(head);
+    return NULL;
+}
qapi-schema.json +33 -0
index 014365b..642a10a 100644
@@ -294,6 +294,21 @@
            '*total-clusters': 'int', '*allocated-clusters': 'int',
            '*fragmented-clusters': 'int', '*compressed-clusters': 'int' } }
 
+# @DeviceImageInfo:
+#
+# Information about an image used by a QEMU block device
+#
+# @device: name of the block device
+#
+# @image: #optional info of the image used
+#
+# Since: 1.5
+#
+##
+
+{ 'type': 'DeviceImageInfo',
+  'data': {'device': 'str', '*image': 'ImageInfo' } }
+
 ##
 # @StatusInfo:
 #
@@ -853,6 +868,24 @@
   'returns': ['SnapshotInfo'] }
 
 ##
+# @query-images:
+#
+# Get block device image information
+#
+# @device: #optional the name of the device to get image info from. If not
+#          specified, all block devices will be queried
+# @backing: #optional true to show information on backing images, false or
+#          omitted to show just the top image of a block device
+#
+# Returns: a list of @DeviceImageInfo describing each virtual block device
+#
+# Since: 1.5
+##
+{ 'command': 'query-images',
+  'data': { '*device': 'str', '*backing': 'bool' },
+  'returns': ['DeviceImageInfo'] }
+
+##
 # @BlockDeviceStats:
 #
 # Statistics of a virtual block device or a block backing device.
qmp-commands.hx +90 -0

96 lines not on this page · raw message

Signature · 1 line
1.7.1
#28 lore raw

Re: [Qemu-devel] [PATCH V9 09/14] qmp: add interface query-images

Quoted 3 lines · Wenchao Xia

This mirror function will return image info including snapshots,
and if specified backing image's info will also be returned. Now Qemu have both query-images and query-block interfaces.

In the middle of a sentence, we prefer QEMU or qemu, not Qemu.

Quoted 8 lines
---
 block/qapi.c     |   83 +++++++++++++++++++++++++++++++++++++++++++++++++
 qapi-schema.json |   33 ++++++++++++++++++++
 qmp-commands.hx  |   90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 206 insertions(+), 0 deletions(-)

As pointed out at the top level, why do we need a new command? Could query-devices be enhanced instead to provide this information as additional dictionary members, so that a single query provides entire backing chain and internal snapshot data alongside everything else?

qapi-schema.json line 876

Quoted 7 lines

##

qapi-schema.json +6 -0
+# @query-images:
+#
+# Get block device image information
+#
+# @device: #optional the name of the device to get image info from. If not
+#          specified, all block devices will be queried

Even if we decide to add a new command, I still think this is overkill for QMP. Just return the data on all the devices, all the time.

qapi-schema.json line 878

Quoted 2 lines
qapi-schema.json +2 -0
+# @backing: #optional true to show information on backing images, false or
+#          omitted to show just the top image of a block device

Likewise. Calling apps can filter out what they need, without you having to add filtering into the qmp code. HMP can do filtering, since it is supposed to be human-friendly, but I don't see a reason to make QMP give reduced information.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#29 lore raw

PATCH v9 10/14 hmp: add function hmp_info_snapshots()

In reply to Wenchao Xia

This function will simply call qmp interface qmp_query_snapshots()
added in last commit and then dump information in monitor console.
To get snapshot info, Now qemu and qemu-img both call block layer
function bdrv_query_snapshot_info_list() in their calling path, and then they just translate the qmp object got to strings in stdout or monitor console.

---
 hmp.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 hmp.h |    1 +
 2 files changed, 43 insertions(+), 0 deletions(-)
hmp.c +42 -0
index 2f47a8a..34f0691 100644
@@ -607,6 +607,48 @@ void hmp_info_block_jobs(Monitor *mon, const QDict *qdict)
     }
 }
 
+/* assume list is valid */
+static void monitor_dump_snapshotinfolist(Monitor *mon, SnapshotInfoList *list)
+{
+    SnapshotInfoList *elem;
+    char buf[256];
+
+    monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
+
+    for (elem = list; elem; elem = elem->next) {
+        QEMUSnapshotInfo sn = {
+            .vm_state_size = elem->value->vm_state_size,
+            .date_sec = elem->value->date_sec,
+            .date_nsec = elem->value->date_nsec,
+            .vm_clock_nsec = elem->value->vm_clock_sec * 1000000000ULL +
+                             elem->value->vm_clock_nsec,
+        };
+        pstrcpy(sn.id_str, sizeof(sn.id_str), elem->value->id);
+        pstrcpy(sn.name, sizeof(sn.name), elem->value->name);
+        monitor_printf(mon, "%s\n", bdrv_snapshot_dump(buf, sizeof(buf), &sn));
+    }
+}
+
+void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    SnapshotInfoList *list;
+
+    list = qmp_query_snapshots(&err);
+    if (error_is_set(&err)) {
+        hmp_handle_error(mon, &err);
+        return;
+    }
+
+    if (list == NULL) {
+        monitor_printf(mon, "There is no suitable snapshot available\n");
+        return;
+    }
+
+    monitor_dump_snapshotinfolist(mon, list);
+    qapi_free_SnapshotInfoList(list);
+}
+
 void hmp_quit(Monitor *mon, const QDict *qdict)
 {
     monitor_suspend(mon);
hmp.h +1 -0
index 30b3c20..0b0ae13 100644
@@ -36,6 +36,7 @@ void hmp_info_spice(Monitor *mon, const QDict *qdict);
 void hmp_info_balloon(Monitor *mon, const QDict *qdict);
 void hmp_info_pci(Monitor *mon, const QDict *qdict);
 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict);
+void hmp_info_snapshots(Monitor *mon, const QDict *qdict);
 void hmp_quit(Monitor *mon, const QDict *qdict);
 void hmp_stop(Monitor *mon, const QDict *qdict);
 void hmp_system_reset(Monitor *mon, const QDict *qdict);
Signature · 1 line
1.7.1
#30 lore raw

PATCH v9 11/14 hmp: switch snapshot info function to qmp based one

In reply to Wenchao Xia

This patch using new added function in last commit which retrieve
info from qmp for snapshot info.

---
 monitor.c |    2 +-
 savevm.c  |   64 -------------------------------------------------------------
 2 files changed, 1 insertions(+), 65 deletions(-)
monitor.c +1 -1
index 32a6e74..5112375 100644
@@ -2594,7 +2594,7 @@ static mon_cmd_t info_cmds[] = {
         .args_type  = "",
         .params     = "",
         .help       = "show the currently saved VM snapshots",
-        .mhandler.cmd = do_info_snapshots,
+        .mhandler.cmd = hmp_info_snapshots,
     },
     {
         .name       = "status",
savevm.c +0 -64

70 lines not on this page · raw message

Signature · 1 line
1.7.1
#31 lore raw

PATCH v9 12/14 block: move dump_human_image_info() to block/qapi.c

In reply to Wenchao Xia

This function is needed later in hmp command, it is also renamed to
bdrv_image_info_dump().

---
 block/qapi.c         |   67 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/block/qapi.h |    1 +
 qemu-img.c           |   69 +-------------------------------------------------
 3 files changed, 69 insertions(+), 68 deletions(-)
block/qapi.c +67 -0
index 0cbbb8c..1eb3de1 100644
@@ -284,3 +284,70 @@ DeviceImageInfoList *qmp_query_images(bool has_device,
     qapi_free_DeviceImageInfoList(head);
     return NULL;
 }
+
+void bdrv_image_info_dump(ImageInfo *info)
+{
+    char size_buf[128], dsize_buf[128];
+    if (!info->has_actual_size) {
+        snprintf(dsize_buf, sizeof(dsize_buf), "unavailable");
+    } else {
+        get_human_readable_size(dsize_buf, sizeof(dsize_buf),
+                                info->actual_size);
+    }
+    get_human_readable_size(size_buf, sizeof(size_buf), info->virtual_size);
+    printf("image: %s\n"
+           "file format: %s\n"
+           "virtual size: %s (%" PRId64 " bytes)\n"
+           "disk size: %s\n",
+           info->filename, info->format, size_buf,
+           info->virtual_size,
+           dsize_buf);
+
+    if (info->has_encrypted && info->encrypted) {
+        printf("encrypted: yes\n");
+    }
+
+    if (info->has_cluster_size) {
+        printf("cluster_size: %" PRId64 "\n", info->cluster_size);
+    }
+
+    if (info->has_dirty_flag && info->dirty_flag) {
+        printf("cleanly shut down: no\n");
+    }
+
+    if (info->has_backing_filename) {
+        printf("backing file: %s", info->backing_filename);
+        if (info->has_full_backing_filename) {
+            printf(" (actual path: %s)", info->full_backing_filename);
+        }
+        putchar('\n');
+        if (info->has_backing_filename_format) {
+            printf("backing file format: %s\n", info->backing_filename_format);
+        }
+    }
+
+    if (info->has_snapshots) {
+        SnapshotInfoList *elem;
+        char buf[256];
+
+        printf("Snapshot list:\n");
+        printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
+
+        /* Ideally bdrv_snapshot_dump() would operate on SnapshotInfoList but
+         * we convert to the block layer's native QEMUSnapshotInfo for now.
+         */
+        for (elem = info->snapshots; elem; elem = elem->next) {
+            QEMUSnapshotInfo sn = {
+                .vm_state_size = elem->value->vm_state_size,
+                .date_sec = elem->value->date_sec,
+                .date_nsec = elem->value->date_nsec,
+                .vm_clock_nsec = elem->value->vm_clock_sec * 1000000000ULL +
+                                 elem->value->vm_clock_nsec,
+            };
+
+            pstrcpy(sn.id_str, sizeof(sn.id_str), elem->value->id);
+            pstrcpy(sn.name, sizeof(sn.name), elem->value->name);
+            printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), &sn));
+        }
+    }
+}
include/block/qapi.h +1 -0
index 7ff1f98..cc55bda 100644
@@ -24,4 +24,5 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,
 int bdrv_query_image_info(BlockDriverState *bs,
                           ImageInfo **p_info,
                           Error **errp);
+void bdrv_image_info_dump(ImageInfo *info);
 #endif
qemu-img.c +1 -68

81 lines not on this page · raw message

Signature · 1 line
1.7.1
Reviewed-by on v9 12/14
#32 lore raw

Re: [Qemu-devel] [PATCH V9 12/14] block: move dump_human_image_info() to block/qapi.c

Quoted 9 lines · Wenchao Xia

This function is needed later in hmp command, it is also renamed to
bdrv_image_info_dump().

---
 block/qapi.c         |   67 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/block/qapi.h |    1 +
 qemu-img.c           |   69 +-------------------------------------------------
 3 files changed, 69 insertions(+), 68 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#33 lore raw

PATCH v9 13/14 block: dump to buffer for bdrv_image_info_dump()

In reply to Wenchao Xia

This allow hmp use this function, just like qemu-img.
It also returns a pointer now to make it easy to use.

---
 block/qapi.c         |   67 +++++++++++++++++++++++++++++++++++--------------
 include/block/qapi.h |    2 +-
 qemu-img.c           |    6 +++-
 3 files changed, 54 insertions(+), 21 deletions(-)
block/qapi.c +48 -19
index 1eb3de1..e6a6ec6 100644
@@ -285,9 +285,30 @@ DeviceImageInfoList *qmp_query_images(bool has_device,
     return NULL;
 }
 
-void bdrv_image_info_dump(ImageInfo *info)
+GCC_FMT_ATTR(3, 4)
+static void snprintf_tail(char **p_buf, int *p_size, const char *fmt, ...)
+{
+    int l;
+    if (*p_size < 1) {
+        return;
+    }
+
+    va_list ap;
+    va_start(ap, fmt);
+    l = vsnprintf(*p_buf, *p_size, fmt, ap);
+    va_end(ap);
+    if (l > 0) {
+        *p_buf += l;
+        *p_size -= l;
+    }
+}
+
+/* Use buf instead of asprintf to reduce memory fragility. */
+char *bdrv_image_info_dump(char *buf, int buf_size, ImageInfo *info)
 {
     char size_buf[128], dsize_buf[128];
+    char *buf1 = buf;
+
     if (!info->has_actual_size) {
         snprintf(dsize_buf, sizeof(dsize_buf), "unavailable");
     } else {
@@ -295,43 +316,49 @@ void bdrv_image_info_dump(ImageInfo *info)
                                 info->actual_size);
     }
     get_human_readable_size(size_buf, sizeof(size_buf), info->virtual_size);
-    printf("image: %s\n"
-           "file format: %s\n"
-           "virtual size: %s (%" PRId64 " bytes)\n"
-           "disk size: %s\n",
-           info->filename, info->format, size_buf,
-           info->virtual_size,
-           dsize_buf);
+    snprintf_tail(&buf1, &buf_size,
+                  "image: %s\n"
+                  "file format: %s\n"
+                  "virtual size: %s (%" PRId64 " bytes)\n"
+                  "disk size: %s\n",
+                  info->filename, info->format, size_buf,
+                  info->virtual_size,
+                  dsize_buf);
 
     if (info->has_encrypted && info->encrypted) {
-        printf("encrypted: yes\n");
+        snprintf_tail(&buf1, &buf_size, "encrypted: yes\n");
     }
 
     if (info->has_cluster_size) {
-        printf("cluster_size: %" PRId64 "\n", info->cluster_size);
+        snprintf_tail(&buf1, &buf_size, "cluster_size: %" PRId64 "\n",
+                 info->cluster_size);
     }
 
     if (info->has_dirty_flag && info->dirty_flag) {
-        printf("cleanly shut down: no\n");
+        snprintf_tail(&buf1, &buf_size, "cleanly shut down: no\n");
     }
 
     if (info->has_backing_filename) {
-        printf("backing file: %s", info->backing_filename);
+        snprintf_tail(&buf1, &buf_size, "backing file: %s",
+                      info->backing_filename);
         if (info->has_full_backing_filename) {
-            printf(" (actual path: %s)", info->full_backing_filename);
+            snprintf_tail(&buf1, &buf_size, " (actual path: %s)",
+                          info->full_backing_filename);
         }
-        putchar('\n');
+        snprintf_tail(&buf1, &buf_size, "\n");
         if (info->has_backing_filename_format) {
-            printf("backing file format: %s\n", info->backing_filename_format);
+            snprintf_tail(&buf1, &buf_size, "backing file format: %s\n",
+                          info->backing_filename_format);
         }
     }
 
     if (info->has_snapshots) {
         SnapshotInfoList *elem;
-        char buf[256];
+        char buf_sn[256];
 
-        printf("Snapshot list:\n");
-        printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), NULL));
+        snprintf_tail(&buf1, &buf_size, "Snapshot list:\n");
+        snprintf_tail(&buf1, &buf_size, "%s\n",
+                      bdrv_snapshot_dump(buf_sn, sizeof(buf_sn), NULL));
 
         /* Ideally bdrv_snapshot_dump() would operate on SnapshotInfoList but
          * we convert to the block layer's native QEMUSnapshotInfo for now.
@@ -347,7 +374,9 @@ void bdrv_image_info_dump(ImageInfo *info)
 
             pstrcpy(sn.id_str, sizeof(sn.id_str), elem->value->id);
             pstrcpy(sn.name, sizeof(sn.name), elem->value->name);
-            printf("%s\n", bdrv_snapshot_dump(buf, sizeof(buf), &sn));
+            snprintf_tail(&buf1, &buf_size, "%s\n",
+                          bdrv_snapshot_dump(buf_sn, sizeof(buf_sn), &sn));
         }
     }
+    return buf;
 }
include/block/qapi.h +1 -1
index cc55bda..7962871 100644
@@ -24,5 +24,5 @@ int bdrv_query_snapshot_info_list(BlockDriverState *bs,
 int bdrv_query_image_info(BlockDriverState *bs,
                           ImageInfo **p_info,
                           Error **errp);
-void bdrv_image_info_dump(ImageInfo *info);
+char *bdrv_image_info_dump(char *buf, int buf_size, ImageInfo *info);
 #endif
qemu-img.c +5 -1
index e1d6bac..6db2b38 100644
@@ -1606,10 +1606,12 @@ static void dump_json_image_info(ImageInfo *info)
     QDECREF(str);
 }
 
+#define IMAGE_INFO_BUF_SIZE (2048)
 static void dump_human_image_info_list(ImageInfoList *list)
 {
     ImageInfoList *elem;
     bool delim = false;
+    char *buf = g_malloc0(IMAGE_INFO_BUF_SIZE);
 
     for (elem = list; elem; elem = elem->next) {
         if (delim) {
@@ -1617,8 +1619,10 @@ static void dump_human_image_info_list(ImageInfoList *list)
         }
         delim = true;
 
-        bdrv_image_info_dump(elem->value);
+        printf("%s",
+               bdrv_image_info_dump(buf, IMAGE_INFO_BUF_SIZE, elem->value));
     }
+    g_free(buf);
 }
 
 static gboolean str_equal_func(gconstpointer a, gconstpointer b)
Signature · 1 line
1.7.1
#34 lore raw

PATCH v9 14/14 hmp: add command info images

In reply to Wenchao Xia

This command will show block image's information, including
internal snapshots.

---
 hmp.c     |   38 ++++++++++++++++++++++++++++++++++++++
 hmp.h     |    1 +
 monitor.c |    7 +++++++
 3 files changed, 46 insertions(+), 0 deletions(-)
hmp.c +38 -0
index 34f0691..05d9b3b 100644
@@ -22,6 +22,7 @@
 #include "qemu/sockets.h"
 #include "monitor/monitor.h"
 #include "ui/console.h"
+#include "block/qapi.h"
 
 static void hmp_handle_error(Monitor *mon, Error **errp)
 {
@@ -649,6 +650,43 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict)
     qapi_free_SnapshotInfoList(list);
 }
 
+#define IMAGE_INFO_BUF_SIZE (2048)
+static void mon_dump_device_image_info_list(Monitor *mon,
+                                            DeviceImageInfoList *list)
+{
+    char *buf = g_malloc0(IMAGE_INFO_BUF_SIZE);
+    DeviceImageInfoList *p = list;
+    DeviceImageInfo *dii;
+    while (p) {
+        dii = p->value;
+        monitor_printf(mon, "Device : %s\n", dii->device);
+        if (dii->has_image) {
+            bdrv_image_info_dump(buf, IMAGE_INFO_BUF_SIZE, dii->image);
+            monitor_printf(mon, "%s", buf);
+        }
+        monitor_printf(mon, "\n");
+
+        p = p->next;
+    }
+    g_free(buf);
+}
+
+void hmp_info_images(Monitor *mon, const QDict *qdict)
+{
+    const char *device = qdict_get_try_str(qdict, "device");
+    int backing = qdict_get_try_bool(qdict, "backing", 0);
+    Error *err = NULL;
+    DeviceImageInfoList *list = NULL;
+
+    list = qmp_query_images(!!device, device, true, backing, &err);
+    if (!error_is_set(&err) && list) {
+        mon_dump_device_image_info_list(mon, list);
+    }
+
+    hmp_handle_error(mon, &err);
+    qapi_free_DeviceImageInfoList(list);
+}
+
 void hmp_quit(Monitor *mon, const QDict *qdict)
 {
     monitor_suspend(mon);
hmp.h +1 -0
index 0b0ae13..9d9ada3 100644
@@ -37,6 +37,7 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict);
 void hmp_info_pci(Monitor *mon, const QDict *qdict);
 void hmp_info_block_jobs(Monitor *mon, const QDict *qdict);
 void hmp_info_snapshots(Monitor *mon, const QDict *qdict);
+void hmp_info_images(Monitor *mon, const QDict *qdict);
 void hmp_quit(Monitor *mon, const QDict *qdict);
 void hmp_stop(Monitor *mon, const QDict *qdict);
 void hmp_system_reset(Monitor *mon, const QDict *qdict);
monitor.c +7 -0
index 5112375..b470963 100644
@@ -2597,6 +2597,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.cmd = hmp_info_snapshots,
     },
     {
+        .name       = "images",
+        .args_type  = "backing:-b,device:B?",
+        .params     = "[-b] [device]",
+        .help       = "show the image info",
+        .mhandler.cmd = hmp_info_images,
+    },
+    {
         .name       = "status",
         .args_type  = "",
         .params     = "",
Signature · 1 line
1.7.1
#35 lore raw
In reply to Wenchao Xia
Quoted 29 lines · Wenchao Xia

In the use of snapshot a way to retrieve related info at runtime is needed,
so this serial of patches will merge some code for qemu and qemu-img, and add following interfaces for qemu:

1) qmp: query-images, show image info for a block device Example:
-> { "execute": "query-images" }

<- {
      "return":[
         {
            "device":"ide0-hd0",
            "image":{
               "filename":"disks/test1.img",
               "format":"qcow2",
               "virtual-size":2048000,
               "snapshots":[
                  {
                     "id": "1",
                     "name": "snapshot1",
                     "vm-state-size": 0,
                     "date-sec": 10000200,
                     "date-nsec": 12,
                     "vm-clock-sec": 206,
                     "vm-clock-nsec": 30
                  }
               ]
            }
         }
      ]
Quoted 1 line

}

See my recent RFC patch to add a virtual_size to query-block:
http://permalink.gmane.org/gmane.comp.emulators.qemu/199443

Is there a reason you added the new query-images command instead of extending BlockDeviceInfo with an ImageInfo field? Then query-block, which is already used today, just provides ImageInfo as well.

I suggest this because it makes life easier for clients - they can issue a single command to extract all image information. If we have two commands they may have to invoke both and then match the results together.

Stefan

#36 lore raw
Quoted 6 lines · Stefan Hajnoczi
Quoted 4 lines · Wenchao Xia

In the use of snapshot a way to retrieve related info at runtime is needed,
so this serial of patches will merge some code for qemu and qemu-img, and add following interfaces for qemu:

Quoted 8 lines

Is there a reason you added the new query-images command instead of extending BlockDeviceInfo with an ImageInfo field? Then query-block, which is already used today, just provides ImageInfo as well.

I suggest this because it makes life easier for clients - they can issue a single command to extract all image information. If we have two commands they may have to invoke both and then match the results together.

Indeed, from the libvirt perspective, I would much prefer that a single command gives me everything, instead of having to call two commands to build up the complete picture.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#37 lore raw
Quoted 11 lines · Eric Blake
Quoted 10 lines · Stefan Hajnoczi
Quoted 4 lines · Wenchao Xia

In the use of snapshot a way to retrieve related info at runtime is needed,
so this serial of patches will merge some code for qemu and qemu-img, and add following interfaces for qemu:

Is there a reason you added the new query-images command instead of extending BlockDeviceInfo with an ImageInfo field? Then query-block, which is already used today, just provides ImageInfo as well.

Quoted 9 lines
Quoted 4 lines

I suggest this because it makes life easier for clients - they can issue a single command to extract all image information. If we have two commands they may have to invoke both and then match the results together.

Indeed, from the libvirt perspective, I would much prefer that a single command gives me everything, instead of having to call two commands to build up the complete picture.

I have no special reason for new interface query-images, it just
show up during the work, and I am pretty OK to merge the information into query-block especially when the user of it, Eric hope so. Then the qmp interface need to designed carefully, my idea is adding an item in BlockDeviceInfo:

{ 'type': 'BlockDeviceInfo',
'data': { 'file': 'str', 'ro': 'bool', 'drv': 'str',

            '*backing_file': 'str', 'backing_file_depth': 'int',
            'encrypted': 'bool', 'encryption_key_missing': 'bool',
            'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
            'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
            'images': ['ImageInfo']} }}

In this way, new define of structure is not needed, and no break
of API I guess, but disadvantage is there will be some duplicated info in ImageInfo and other structure in BlockInfo, such as "file, encrypted".

Signature · 3 lines
Best Regards

Wenchao Xia
#38 lore raw
Quoted 36 lines · Wenchao Xia
Quoted 11 lines · Eric Blake
Quoted 10 lines · Stefan Hajnoczi
Quoted 4 lines · Wenchao Xia

In the use of snapshot a way to retrieve related info at runtime is needed,
so this serial of patches will merge some code for qemu and qemu-img, and add following interfaces for qemu:

Is there a reason you added the new query-images command instead of extending BlockDeviceInfo with an ImageInfo field? Then query-block, which is already used today, just provides ImageInfo as well.

Quoted 9 lines
Quoted 4 lines

I suggest this because it makes life easier for clients - they can issue a single command to extract all image information. If we have two commands they may have to invoke both and then match the results together.

Indeed, from the libvirt perspective, I would much prefer that a single command gives me everything, instead of having to call two commands to build up the complete picture.

I have no special reason for new interface query-images, it just
show up during the work, and I am pretty OK to merge the information into query-block especially when the user of it, Eric hope so. Then the qmp interface need to designed carefully, my idea is adding an item in BlockDeviceInfo:

{ 'type': 'BlockDeviceInfo',
'data': { 'file': 'str', 'ro': 'bool', 'drv': 'str',

            '*backing_file': 'str', 'backing_file_depth': 'int',
            'encrypted': 'bool', 'encryption_key_missing': 'bool',
            'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
            'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
            'images': ['ImageInfo']} }}
Quoted 4 lines

In this way, new define of structure is not needed, and no break
of API I guess, but disadvantage is there will be some duplicated info in ImageInfo and other structure in BlockInfo, such as "file, encrypted".

I'm happy with adding a ImageInfo field into BlockDeviceInfo.

Why did you make it an array and what is the array's layout?

Stefan

#39 lore raw
Quoted 9 lines · Stefan Hajnoczi
Quoted 9 lines

{ 'type': 'BlockDeviceInfo',
'data': { 'file': 'str', 'ro': 'bool', 'drv': 'str',

            '*backing_file': 'str', 'backing_file_depth': 'int',
            'encrypted': 'bool', 'encryption_key_missing': 'bool',
            'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
            'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
            'images': ['ImageInfo']} }}
Quoted 8 lines
Quoted 4 lines

In this way, new define of structure is not needed, and no break
of API I guess, but disadvantage is there will be some duplicated info in ImageInfo and other structure in BlockInfo, such as "file, encrypted".

I'm happy with adding a ImageInfo field into BlockDeviceInfo.

Why did you make it an array and what is the array's layout?

I think the point of an array of ImageInfo is to let us return data on an entire backing chain. That is, if I have:

image.raw <- middle.qcow2 (with internal snapshot "a") <- top.qcow2 (with internal snapshots "b", "c")

then I want to see data on image.raw, as well as on snapshots a, b, and c, all in one command. For my example, 'images' would be a three-element array, with element 0 describing top.qcow2 and its two internal snapshots, element 1 describing middle.qcow2 and its snapshot, and element 2 describing image.raw.

However, it's also worth remembering that there has been a proposal for having quorums, where a single block device can have multiple images associated with the top level, and where we would then want a recursive structure rather than an array for representing backing chain information of a given information within the array of multiple images associated with a single quorum device.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#40 lore raw

Am 13.03.2013 um 13:29 hat Eric Blake geschrieben:

Quoted 31 lines · Stefan Hajnoczi
Quoted 9 lines
Quoted 9 lines

{ 'type': 'BlockDeviceInfo',
'data': { 'file': 'str', 'ro': 'bool', 'drv': 'str',

            '*backing_file': 'str', 'backing_file_depth': 'int',
            'encrypted': 'bool', 'encryption_key_missing': 'bool',
            'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
            'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
            'images': ['ImageInfo']} }}
Quoted 8 lines
Quoted 4 lines

In this way, new define of structure is not needed, and no break
of API I guess, but disadvantage is there will be some duplicated info in ImageInfo and other structure in BlockInfo, such as "file, encrypted".

I'm happy with adding a ImageInfo field into BlockDeviceInfo.

Why did you make it an array and what is the array's layout?

I think the point of an array of ImageInfo is to let us return data on an entire backing chain. That is, if I have:

image.raw <- middle.qcow2 (with internal snapshot "a") <- top.qcow2 (with internal snapshots "b", "c")

then I want to see data on image.raw, as well as on snapshots a, b, and c, all in one command. For my example, 'images' would be a three-element array, with element 0 describing top.qcow2 and its two internal snapshots, element 1 describing middle.qcow2 and its snapshot, and element 2 describing image.raw.

Quoted 6 lines

However, it's also worth remembering that there has been a proposal for having quorums, where a single block device can have multiple images associated with the top level, and where we would then want a recursive structure rather than an array for representing backing chain information of a given information within the array of multiple images associated with a single quorum device.

Yes, please go for a recursive structure. You might also want to get information about bs->file like query-blockstats already provides, so you already have a second link today.

I wonder if we could somehow add driver-specific fields to this struct or if QAPI just breaks down when you try to do something like this. It is what Quorum would have to use. But that's a separate problem and shouldn't block this series.

Kevin

#41 lore raw
In reply to Eric Blake
Quoted 31 lines · Eric Blake
Quoted 9 lines · Stefan Hajnoczi
Quoted 9 lines

{ 'type': 'BlockDeviceInfo',
'data': { 'file': 'str', 'ro': 'bool', 'drv': 'str',

            '*backing_file': 'str', 'backing_file_depth': 'int',
            'encrypted': 'bool', 'encryption_key_missing': 'bool',
            'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
            'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
            'images': ['ImageInfo']} }}
Quoted 8 lines
Quoted 4 lines

In this way, new define of structure is not needed, and no break
of API I guess, but disadvantage is there will be some duplicated info in ImageInfo and other structure in BlockInfo, such as "file, encrypted".

I'm happy with adding a ImageInfo field into BlockDeviceInfo.

Why did you make it an array and what is the array's layout?

I think the point of an array of ImageInfo is to let us return data on an entire backing chain. That is, if I have:

image.raw <- middle.qcow2 (with internal snapshot "a") <- top.qcow2 (with internal snapshots "b", "c")

then I want to see data on image.raw, as well as on snapshots a, b, and c, all in one command. For my example, 'images' would be a three-element array, with element 0 describing top.qcow2 and its two internal snapshots, element 1 describing middle.qcow2 and its snapshot, and element 2 describing image.raw.

Quoted 6 lines

However, it's also worth remembering that there has been a proposal for having quorums, where a single block device can have multiple images associated with the top level, and where we would then want a recursive structure rather than an array for representing backing chain information of a given information within the array of multiple images associated with a single quorum device.

The same applies for VMDK where one .vmdk can reference multiple extent files.

This is why I asked about the array. A dict of ImageInfos is needed, they can refer to each other by key.

If we go with an array we're painting ourselves into a corner.

If we go with a dict it's more complicated and may not be used much.

I'd go for the dict but we need a policy for choosing keys (names) for the ImageInfo elements. Perhaps BlockDeviceInfo['file'] is the key for the top-level image and then ImageInfo['backing-filename'] for the backing chain.

Stefan

#42 lore raw
Quoted 39 lines · Stefan Hajnoczi
Quoted 31 lines · Eric Blake
Quoted 9 lines · Stefan Hajnoczi
Quoted 9 lines

{ 'type': 'BlockDeviceInfo',
'data': { 'file': 'str', 'ro': 'bool', 'drv': 'str',

             '*backing_file': 'str', 'backing_file_depth': 'int',
             'encrypted': 'bool', 'encryption_key_missing': 'bool',
             'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
             'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
             'images': ['ImageInfo']} }}
Quoted 8 lines
Quoted 4 lines

In this way, new define of structure is not needed, and no break
of API I guess, but disadvantage is there will be some duplicated info in ImageInfo and other structure in BlockInfo, such as "file, encrypted".

I'm happy with adding a ImageInfo field into BlockDeviceInfo.

Why did you make it an array and what is the array's layout?

I think the point of an array of ImageInfo is to let us return data on an entire backing chain. That is, if I have:

image.raw <- middle.qcow2 (with internal snapshot "a") <- top.qcow2 (with internal snapshots "b", "c")

then I want to see data on image.raw, as well as on snapshots a, b, and c, all in one command. For my example, 'images' would be a three-element array, with element 0 describing top.qcow2 and its two internal snapshots, element 1 describing middle.qcow2 and its snapshot, and element 2 describing image.raw.

Quoted 6 lines

However, it's also worth remembering that there has been a proposal for having quorums, where a single block device can have multiple images associated with the top level, and where we would then want a recursive structure rather than an array for representing backing chain information of a given information within the array of multiple images associated with a single quorum device.

Quoted 3 lines

The same applies for VMDK where one .vmdk can reference multiple extent files.

I'd like to confirm: This means a block device can have multiple
images at top level, but one image can still have only one backing image at most? If my understanding is correct,following should be the case:

1 device hda have two active images: a.qcow2 and b.qcow2(maybe vmdk format now, just an example)
2 a.qcow2 file's backing file will be a_base0.qcow2, never a_base0.qcow2 and a_base1.qcow2.

Quoted 5 lines

This is why I asked about the array. A dict of ImageInfos is needed, they can refer to each other by key.

If we go with an array we're painting ourselves into a corner.

Quoted 9 lines

If we go with a dict it's more complicated and may not be used much.

I'd go for the dict but we need a policy for choosing keys (names) for the ImageInfo elements. Perhaps BlockDeviceInfo['file'] is the key for the top-level image and then ImageInfo['backing-filename'] for the backing chain.

Stefan

Since ImageInfo already have key 'backing-filename', which stands for
the information got in this image, not from the backing image, add a new key 'bakcing-image' for recursive linking:

{ 'type': 'ImageInfo',
'data': {'filename': 'str', 'format': 'str', '*dirty-flag': 'bool',

           '*actual-size': 'int', 'virtual-size': 'int',
           '*cluster-size': 'int', '*encrypted': 'bool',
           '*backing-filename': 'str', '*full-backing-filename': 'str',
           '*backing-filename-format': 'str',
           '*backing-image": 'ImageInfo',
           '*snapshots': ['SnapshotInfo'] } }

Then insert ImageInfo into BlockDeviceInfo, with key 'images', since
'file' is already used which may break compatibility if we change it. 'images' uses an array for the case when multiple images exist in top level, not for backing chain.

{ 'type': 'BlockDeviceInfo',
'data': { 'file': 'str', 'ro': 'bool', 'drv': 'str',

            '*backing_file': 'str', 'backing_file_depth': 'int',
            'encrypted': 'bool', 'encryption_key_missing': 'bool',
            'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
            'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
            'images': ['ImageInfo']} }}
Signature · 3 lines
Best Regards

Wenchao Xia
#43 lore raw

Am 15.03.2013 um 07:07 hat Wenchao Xia geschrieben:

Quoted 9 lines
Quoted 3 lines · Stefan Hajnoczi

The same applies for VMDK where one .vmdk can reference multiple extent files.

I'd like to confirm: This means a block device can have multiple
images at top level, but one image can still have only one backing image at most? If my understanding is correct,following should be the case:

Quoted 4 lines

1 device hda have two active images: a.qcow2 and b.qcow2(maybe vmdk format now, just an example)
2 a.qcow2 file's backing file will be a_base0.qcow2, never a_base0.qcow2 and a_base1.qcow2.

I don't think this describes exactly what happens. Each qemu block device refers to one BlockDriverState, let's say top.vmdk for the top level image. This may refer to a backing file, backing.vmdk for example.

Now top.vmdk nd back.vmdk could both be split images, and the former refers to its extents top_0.vmdk and top_1.vmdk, which contain the actual data of the image, and the latter may refer to backing_0.vmdk, backing_1.vmdk and backing_2.vmdk.

So this can happen in any position in the BlockDriverState graph.

Quoted 18 lines

Since ImageInfo already have key 'backing-filename', which stands for
the information got in this image, not from the backing image, add a new key 'bakcing-image' for recursive linking:

{ 'type': 'ImageInfo',
'data': {'filename': 'str', 'format': 'str', '*dirty-flag': 'bool',

           '*actual-size': 'int', 'virtual-size': 'int',
           '*cluster-size': 'int', '*encrypted': 'bool',
           '*backing-filename': 'str', '*full-backing-filename': 'str',
           '*backing-filename-format': 'str',
           '*backing-image": 'ImageInfo',
           '*snapshots': ['SnapshotInfo'] } }

Then insert ImageInfo into BlockDeviceInfo, with key 'images', since
'file' is already used which may break compatibility if we change it. 'images' uses an array for the case when multiple images exist in top level, not for backing chain.

Quoted 7 lines

{ 'type': 'BlockDeviceInfo',
'data': { 'file': 'str', 'ro': 'bool', 'drv': 'str',

            '*backing_file': 'str', 'backing_file_depth': 'int',
            'encrypted': 'bool', 'encryption_key_missing': 'bool',
            'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
            'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
            'images': ['ImageInfo']} }}

Yes, I think this is what Stefan meant (at least it looks like what I was thinking of).

Kevin

#44 lore raw
Quoted 19 lines · Kevin Wolf

Am 15.03.2013 um 07:07 hat Wenchao Xia geschrieben:

Quoted 9 lines
Quoted 3 lines · Stefan Hajnoczi

The same applies for VMDK where one .vmdk can reference multiple extent files.

I'd like to confirm: This means a block device can have multiple
images at top level, but one image can still have only one backing image at most? If my understanding is correct,following should be the case:

Quoted 4 lines

1 device hda have two active images: a.qcow2 and b.qcow2(maybe vmdk format now, just an example)
2 a.qcow2 file's backing file will be a_base0.qcow2, never a_base0.qcow2 and a_base1.qcow2.

I don't think this describes exactly what happens. Each qemu block device refers to one BlockDriverState, let's say top.vmdk for the top level image. This may refer to a backing file, backing.vmdk for example.

Quoted 7 lines

Now top.vmdk nd back.vmdk could both be split images, and the former refers to its extents top_0.vmdk and top_1.vmdk, which contain the actual data of the image, and the latter may refer to backing_0.vmdk, backing_1.vmdk and backing_2.vmdk.

So this can happen in any position in the BlockDriverState graph.

Thank u for the detailed explaination. Currently BlockDriverState
have only one file name, so if my understanding is correct, the multiple referred disk is actually an internal data struct in VMDK now. Qemu main block layer only saw "main" disk in each layer.

an case:
BlockDriverState:

     |
top.vmdk<-----------------------------------ref_top.vmdk
     |                                            |
backing_top.vmdk<---ref_backing_top.vmdk  backing_ref_top.vmdk

This seems hard to be reflected in the structure I defined before,
and hard to get in currently block.c's API. what I can think is improve ImageInfo:

{ 'type': 'ImageInfo',
'data': {'filename': 'str', 'format': 'str', '*dirty-flag': 'bool',

            '*actual-size': 'int', 'virtual-size': 'int',
            '*cluster-size': 'int', '*encrypted': 'bool',
            '*backing-filename': 'str', '*full-backing-filename': 'str',
            '*backing-filename-format': 'str',
            '*backing-image": 'ImageInfo',
            '*ref-images": '[ImageInfo]',
            '*snapshots': ['SnapshotInfo'] } }

Backing-image reflect that one image can have one main backing file,
and one image can have multiple referenced images. Do you think this structure is good enough?

Quoted 31 lines
Quoted 18 lines

Since ImageInfo already have key 'backing-filename', which stands for
the information got in this image, not from the backing image, add a new key 'bakcing-image' for recursive linking:

{ 'type': 'ImageInfo',
'data': {'filename': 'str', 'format': 'str', '*dirty-flag': 'bool',

            '*actual-size': 'int', 'virtual-size': 'int',
            '*cluster-size': 'int', '*encrypted': 'bool',
            '*backing-filename': 'str', '*full-backing-filename': 'str',
            '*backing-filename-format': 'str',
            '*backing-image": 'ImageInfo',
            '*snapshots': ['SnapshotInfo'] } }

Then insert ImageInfo into BlockDeviceInfo, with key 'images', since
'file' is already used which may break compatibility if we change it. 'images' uses an array for the case when multiple images exist in top level, not for backing chain.

Quoted 7 lines

{ 'type': 'BlockDeviceInfo',
'data': { 'file': 'str', 'ro': 'bool', 'drv': 'str',

             '*backing_file': 'str', 'backing_file_depth': 'int',
             'encrypted': 'bool', 'encryption_key_missing': 'bool',
             'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
             'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
             'images': ['ImageInfo']} }}

Yes, I think this is what Stefan meant (at least it looks like what I was thinking of).

Kevin

Signature · 3 lines
Best Regards

Wenchao Xia
#45 lore raw

Am 18.03.2013 um 11:30 hat Wenchao Xia geschrieben:

Quoted 53 lines
Quoted 19 lines · Kevin Wolf

Am 15.03.2013 um 07:07 hat Wenchao Xia geschrieben:

Quoted 9 lines
Quoted 3 lines · Stefan Hajnoczi

The same applies for VMDK where one .vmdk can reference multiple extent files.

I'd like to confirm: This means a block device can have multiple
images at top level, but one image can still have only one backing image at most? If my understanding is correct,following should be the case:

Quoted 4 lines

1 device hda have two active images: a.qcow2 and b.qcow2(maybe vmdk format now, just an example)
2 a.qcow2 file's backing file will be a_base0.qcow2, never a_base0.qcow2 and a_base1.qcow2.

I don't think this describes exactly what happens. Each qemu block device refers to one BlockDriverState, let's say top.vmdk for the top level image. This may refer to a backing file, backing.vmdk for example.

Quoted 7 lines

Now top.vmdk nd back.vmdk could both be split images, and the former refers to its extents top_0.vmdk and top_1.vmdk, which contain the actual data of the image, and the latter may refer to backing_0.vmdk, backing_1.vmdk and backing_2.vmdk.

So this can happen in any position in the BlockDriverState graph.

Thank u for the detailed explaination. Currently BlockDriverState
have only one file name, so if my understanding is correct, the multiple referred disk is actually an internal data struct in VMDK now. Qemu main block layer only saw "main" disk in each layer.

an case:
BlockDriverState:

     |
top.vmdk<-----------------------------------ref_top.vmdk
     |                                            |
backing_top.vmdk<---ref_backing_top.vmdk  backing_ref_top.vmdk

This seems hard to be reflected in the structure I defined before,
and hard to get in currently block.c's API. what I can think is improve ImageInfo:

{ 'type': 'ImageInfo',
'data': {'filename': 'str', 'format': 'str', '*dirty-flag': 'bool',

            '*actual-size': 'int', 'virtual-size': 'int',
            '*cluster-size': 'int', '*encrypted': 'bool',
            '*backing-filename': 'str', '*full-backing-filename': 'str',
            '*backing-filename-format': 'str',
            '*backing-image": 'ImageInfo',
            '*ref-images": '[ImageInfo]',
            '*snapshots': ['SnapshotInfo'] } }
Quoted 3 lines

Backing-image reflect that one image can have one main backing file,
and one image can have multiple referenced images. Do you think this structure is good enough?

Yes, I think this is fine.

We don't need to introduce ref-images now, it's just good to have the option to do it as soon as we need it. This is why we preferred using a recursive structure instead of an array.

Kevin

#46 lore raw
In reply to Wenchao Xia
Quoted 34 lines · Wenchao Xia
Quoted 5 lines · Stefan Hajnoczi

This is why I asked about the array. A dict of ImageInfos is needed, they can refer to each other by key.

If we go with an array we're painting ourselves into a corner.

Quoted 9 lines

If we go with a dict it's more complicated and may not be used much.

I'd go for the dict but we need a policy for choosing keys (names) for the ImageInfo elements. Perhaps BlockDeviceInfo['file'] is the key for the top-level image and then ImageInfo['backing-filename'] for the backing chain.

Stefan

Since ImageInfo already have key 'backing-filename', which stands for
the information got in this image, not from the backing image, add a new key 'bakcing-image' for recursive linking:

{ 'type': 'ImageInfo',
'data': {'filename': 'str', 'format': 'str', '*dirty-flag': 'bool',

           '*actual-size': 'int', 'virtual-size': 'int',
           '*cluster-size': 'int', '*encrypted': 'bool',
           '*backing-filename': 'str', '*full-backing-filename': 'str',
           '*backing-filename-format': 'str',
           '*backing-image": 'ImageInfo',
           '*snapshots': ['SnapshotInfo'] } }

Then insert ImageInfo into BlockDeviceInfo, with key 'images', since
'file' is already used which may break compatibility if we change it. 'images' uses an array for the case when multiple images exist in top level, not for backing chain.

Quoted 7 lines

{ 'type': 'BlockDeviceInfo',
'data': { 'file': 'str', 'ro': 'bool', 'drv': 'str',

            '*backing_file': 'str', 'backing_file_depth': 'int',
            'encrypted': 'bool', 'encryption_key_missing': 'bool',
            'bps': 'int', 'bps_rd': 'int', 'bps_wr': 'int',
            'iops': 'int', 'iops_rd': 'int', 'iops_wr': 'int',
            'images': ['ImageInfo']} }}

Sounds good.

Stefan