Skip to contentSkip to conversation

Don't allow snapshots if the overlay has parent nodes

PATCH In review Alberto Garcia 2 participants 4 messages Oct 29, 2015 – Oct 30, 2015

lore
Share & tools
lore
#0 lore raw

cover Don't allow snapshots if the overlay has parent nodes

There are several sanity checks for the 'blockdev-snapshot' command, but none covers the use of a file BDS as the overlay node.

      { 'execute': 'blockdev-add', 'arguments':
        { 'options': { 'driver': 'qcow2',
                       'node-name': 'new0',
                       'file': { 'driver': 'file',
                                 'filename': 'new.qcow2',
                                 'node-name': 'file0' } } } }

      { 'execute': 'blockdev-snapshot', 'arguments':
        { 'node': 'virtio0',
          'overlay': 'file0' } }

This series fixes that and adds a new test case. This of course depends on the 'blockdev-snapshot' series:

https://lists.gnu.org/archive/html/qemu-block/2015-10/msg00974.html

I anyway wonder if it wouldn't be a good idea to have regular op blockers in all file BDSs?

Regards,

Berto

Alberto Garcia (2):
block: Don't allow snapshots if the overlay has parent nodes
block: test 'blockdev-snapshot' using a file BDS as the overlay

 blockdev.c                 |  5 +++++
 tests/qemu-iotests/085     | 12 +++++++++++-
 tests/qemu-iotests/085.out |  4 ++++
 3 files changed, 20 insertions(+), 1 deletion(-)
Signature · 1 line
2.6.1
#1 lore raw

PATCH 1/2 block: Don't allow snapshots if the overlay has parent nodes

This addresses scenarios where the overlay node of the 'blockdev-snapshot' parameter is a child of an existing node, such as this one:

{ 'execute': 'blockdev-add', 'arguments':

    { 'options': { 'driver': 'qcow2',
                   'node-name': 'new0',
                   'file': { 'driver': 'file',
                             'filename': 'new.qcow2',
                             'node-name': 'file0' } } } }

{ 'execute': 'blockdev-snapshot', 'arguments':

    { 'node': 'virtio0',
      'overlay': 'file0' } }
---
 blockdev.c | 5 +++++
 1 file changed, 5 insertions(+)
blockdev.c +5 -0
index a567a05..fcddb07 100644
@@ -1667,6 +1667,11 @@ static void external_snapshot_prepare(BlkTransactionState *common,
 
     if (state->new_bs->backing != NULL) {
         error_setg(errp, "The snapshot already has a backing image");
+        return;
+    }
+
+    if (!QLIST_EMPTY(&state->new_bs->parents)) {
+        error_setg(errp, "The snapshot is already being used");
     }
 }
 
Signature · 1 line
2.6.1
#2 lore raw

PATCH 2/2 block: test 'blockdev-snapshot' using a file BDS as the overlay

In reply to Alberto Garcia
---
 tests/qemu-iotests/085     | 12 +++++++++++-
 tests/qemu-iotests/085.out |  4 ++++
 2 files changed, 15 insertions(+), 1 deletion(-)
tests/qemu-iotests/085 +11 -1
index 9484117..ccde2ae 100755
@@ -103,7 +103,8 @@ function add_snapshot_image()
            { 'options':
              { 'driver': 'qcow2', 'node-name': 'snap_"${1}"', "${extra_params}"
                'file':
-               { 'driver': 'file', 'filename': '"${snapshot_file}"' } } } }"
+               { 'driver': 'file', 'filename': '"${snapshot_file}"',
+                 'node-name': 'file_"${1}"' } } } }"
     _send_qemu_cmd $h "${cmd}" "return"
 }
 
@@ -187,6 +188,15 @@ add_snapshot_image ${SNAPSHOTS}
 blockdev_snapshot ${SNAPSHOTS}
 
 echo
+echo === Invalid command - cannot create a snapshot using a file BDS ===
+echo
+
+_send_qemu_cmd $h "{ 'execute': 'blockdev-snapshot',
+                     'arguments': { 'node':'virtio0',
+                                    'overlay':'file_"${SNAPSHOTS}"' }
+                   }" "error"
+
+echo
 echo === Invalid command - snapshot node used as active layer ===
 echo
 
tests/qemu-iotests/085.out +4 -0
index 52292ea..65395d3 100644
@@ -62,6 +62,10 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file=TEST_DIR/
 {"return": {}}
 {"return": {}}
 
+=== Invalid command - cannot create a snapshot using a file BDS ===
+
+{"error": {"class": "GenericError", "desc": "The snapshot is already being used"}}
+
 === Invalid command - snapshot node used as active layer ===
 
 {"error": {"class": "GenericError", "desc": "The snapshot is already in use by virtio0"}}
Signature · 1 line
2.6.1
#3 lore raw
In reply to Alberto Garcia
Quoted 13 lines · Alberto Garcia

There are several sanity checks for the 'blockdev-snapshot' command, but none covers the use of a file BDS as the overlay node.

      { 'execute': 'blockdev-add', 'arguments':
        { 'options': { 'driver': 'qcow2',
                       'node-name': 'new0',
                       'file': { 'driver': 'file',
                                 'filename': 'new.qcow2',
                                 'node-name': 'file0' } } } }

      { 'execute': 'blockdev-snapshot', 'arguments':
        { 'node': 'virtio0',
          'overlay': 'file0' } }

Well, I don't think the problem here is that file0 has a parent. For instance, you might want to use a qcow2 child node of a quorum BDS as the new overlay; or in the future, you may want to use a snapshot node which has some filters on top of it.

To me, the problem is that file0 is driven by the driver "file" which does not support backing files. I think that's what should be fixed.

Max

Quoted 21 lines

This series fixes that and adds a new test case. This of course depends on the 'blockdev-snapshot' series:

   https://lists.gnu.org/archive/html/qemu-block/2015-10/msg00974.html

I anyway wonder if it wouldn't be a good idea to have regular op blockers in all file BDSs?

Regards,

Berto

Alberto Garcia (2):
block: Don't allow snapshots if the overlay has parent nodes
block: test 'blockdev-snapshot' using a file BDS as the overlay

 blockdev.c                 |  5 +++++
 tests/qemu-iotests/085     | 12 +++++++++++-
 tests/qemu-iotests/085.out |  4 ++++
 3 files changed, 20 insertions(+), 1 deletion(-)