export internal snapshot by qemu-nbd
v4 cover export internal snapshot by qemu-nbd
This series allow user to read internal snapshot's contents without qemu-img convert.
V2:
Address Stefan's comments:
02: add 'fall through' comments in the case statement.
03: add doc about the difference of internal snapshot and backing chain
snapshot, which is used in previous '--snapshot' parameter.
Other:
01,04: rebased on upstream with conflict resolved.
v3:
Address Paolo's comments:
02: add parameter "-l snapshot_id_or_name", rename options
snapshot-load to load-snapshot, use QemuOpts.
03: rename snapshot-load to load-snapshot.
04: related change to test both -l and -L case. 05-07: add similar parameter for qemu-img convert. Other:
01: foldered original snapshot logic into functionbdrv_snapshot_load_tmp_by_id_or_name(), since multiple caller present in this version. Refined error message from ", reason: %s" to ": %s".
02: Refined error message from ", reason: %s" to ": %s". 03: Rename PARAM to SNAPSHOT_PARAM.
v4:
Address Eric's comments:
01: typo fix.
02: squashed patch. Use only one option -l and distiguish
the cases by the starting string.
03: remove 'eval', remove '_supported_os Linux', remove the
comments that have typo.
04: squashed patch. Add only one option -l and distiguish
the cases by the starting string.
05: remove indentation.
Address Paolo's comments:
02: Use only one option -l and distiguish the cases by
the starting string.
04: Use only one option -l and distiguish the cases by
the starting string, mark old -s as deprecated, added doc for them.
Wenchao Xia (5):
1 snapshot: distinguish id and name in load_tmp
2 qemu-nbd: support internal snapshot export
3 qemu-iotests: add 058 internal snapshot export with qemu-nbd case 4 qemu-img: add -l for snapshot in convert
5 qemu-iotests: add test for snapshot in qemu-img convert
block/qcow2-snapshot.c | 16 +++++- block/qcow2.h | 5 ++- block/snapshot.c | 78 +++++++++++++++++++++++++++- include/block/block_int.h | 4 +- include/block/snapshot.h | 15 +++++- qemu-img-cmds.hx | 2 +- qemu-img.c | 45 ++++++++++++++--- qemu-img.texi | 12 +++-- qemu-nbd.c | 47 +++++++++++++++++- qemu-nbd.texi | 8 +++- tests/qemu-iotests/058 | 119 ++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/058.out | 44 ++++++++++++++++ tests/qemu-iotests/check | 1 + tests/qemu-iotests/group | 1 + 14 files changed, 374 insertions(+), 23 deletions(-) create mode 100755 tests/qemu-iotests/058 create mode 100644 tests/qemu-iotests/058.out
PATCH v4 1/5 snapshot: distinguish id and name in load_tmp
Since later this function will be used so improve it. The only caller of it now is qemu-img, and it is not impacted by introduce function bdrv_snapshot_load_tmp_by_id_or_name() that call bdrv_snapshot_load_tmp() twice to keep old search logic. bdrv_snapshot_load_tmp_by_id_or_name() return int to let caller know the errno, and errno will be used later. Also fix a typo in comments of bdrv_snapshot_delete().
--- block/qcow2-snapshot.c | 16 ++++++++++- block/qcow2.h | 5 +++- block/snapshot.c | 60 ++++++++++++++++++++++++++++++++++++++++++-- include/block/block_int.h | 4 ++- include/block/snapshot.h | 7 ++++- qemu-img.c | 8 ++++- 6 files changed, 90 insertions(+), 10 deletions(-)
block/qcow2-snapshot.c +14 -2
@@ -669,7 +669,10 @@ int qcow2_snapshot_list(BlockDriverState *bs, QEMUSnapshotInfo **psn_tab)return s->nb_snapshots; } -int qcow2_snapshot_load_tmp (BlockDriverState *bs,const char *snapshot_name) +int qcow2_snapshot_load_tmp (BlockDriverState *bs, +const char *snapshot_id, +const char *name, +Error **errp) {int i, snapshot_index;BDRVQcowState *s = bs->opaque;
@@ -677,12 +680,17 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name)uint64_t *new_l1_table;int new_l1_bytes;int ret; +const char *device =bdrv_get_device_name (bs);assert (bs->read_only);/* Search the snapshot */ - snapshot_index =find_snapshot_by_id_or_name (bs, snapshot_name); + snapshot_index =find_snapshot_by_id_and_name (bs, snapshot_id, name);if (snapshot_index <0 ) { +error_setg (errp, +"Can't find a snapshot with ID '%s' and name '%s' " +"on device '%s'" , +STR_OR_NULL (snapshot_id),STR_OR_NULL (name), device);return -ENOENT ; } sn = &s->snapshots[snapshot_index];
@@ -693,6 +701,10 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs, const char *snapshot_name) ret =bdrv_pread (bs->file, sn->l1_table_offset, new_l1_table, new_l1_bytes);if (ret <0 ) { +error_setg (errp, +"Failed to read l1 table for snapshot with ID '%s' and name " +"'%s' on device '%s'" , + sn->id_str, sn->name, device);g_free (new_l1_table);return ret; }
block/qcow2.h +4 -1
@@ -472,7 +472,10 @@ int qcow2_snapshot_delete(BlockDriverState *bs,const char *name, Error **errp);int qcow2_snapshot_list (BlockDriverState *bs,QEMUSnapshotInfo **psn_tab); -int qcow2_snapshot_load_tmp (BlockDriverState *bs,const char *snapshot_name); +int qcow2_snapshot_load_tmp (BlockDriverState *bs, +const char *snapshot_id, +const char *name, +Error **errp);void qcow2_free_snapshots (BlockDriverState *bs);int qcow2_read_snapshots (BlockDriverState *bs);
block/snapshot.c +57 -3
82 lines not on this page · raw message
include/block/block_int.h +3 -1
@@ -166,7 +166,9 @@ struct BlockDriver {int (*bdrv_snapshot_list)(BlockDriverState *bs,QEMUSnapshotInfo **psn_info);int (*bdrv_snapshot_load_tmp)(BlockDriverState *bs, -const char *snapshot_name); +const char *snapshot_id, +const char *name, +Error **errp);int (*bdrv_get_info)(BlockDriverState *bs,BlockDriverInfo *bdi); int (*bdrv_save_vmstate)(BlockDriverState *bs, QEMUIOVector *qiov,
include/block/snapshot.h +6 -1
@@ -61,5 +61,10 @@ void bdrv_snapshot_delete_by_id_or_name(BlockDriverState *bs,int bdrv_snapshot_list (BlockDriverState *bs,QEMUSnapshotInfo **psn_info);int bdrv_snapshot_load_tmp (BlockDriverState *bs, -const char *snapshot_name); +const char *snapshot_id, +const char *name, +Error **errp); +int bdrv_snapshot_load_tmp_by_id_or_name (BlockDriverState *bs, +const char *id_or_name, +Error **errp);#endif
qemu-img.c +6 -2
@@ -1260,8 +1260,12 @@ static int img_convert(int argc, char **argv) ret =-1 ; goto out; } -if (bdrv_snapshot_load_tmp (bs[0 ], snapshot_name) <0 ) { -error_report ("Failed to load snapshot" ); + +bdrv_snapshot_load_tmp_by_id_or_name (bs[0 ], snapshot_name, &local_err); +if (error_is_set (&local_err)) { +error_report ("Failed to load snapshot: %s" , +error_get_pretty (local_err)); +error_free (local_err); ret =-1 ; goto out; }
Signature · 1 line
1.7.1
PATCH v4 2/5 qemu-nbd: support internal snapshot export
In reply to Wenchao XiaNow it is possible to directly export an internal snapshot, which can be used to probe the snapshot's contents without qemu-img convert.
--- block/snapshot.c | 18 +++++++++++++++++ include/block/snapshot.h | 8 +++++++ qemu-nbd.c | 47 ++++++++++++++++++++++++++++++++++++++++++++- qemu-nbd.texi | 8 ++++++- 4 files changed, 78 insertions(+), 3 deletions(-)
block/snapshot.c +18 -0
@@ -25,6 +25,24 @@#include "block/snapshot.h" #include "block/block_int.h" +QemuOptsList internal_snapshot_opts = { + .name ="snapshot" , + .head =QTAILQ_HEAD_INITIALIZER (internal_snapshot_opts.head), + .desc = { + { + .name =SNAPSHOT_OPT_ID , + .type =QEMU_OPT_STRING , + .help ="snapshot id" + },{ + .name =SNAPSHOT_OPT_NAME , + .type =QEMU_OPT_STRING , + .help ="snapshot name" + },{ +/* end of list */ + } + }, +}; +int bdrv_snapshot_find (BlockDriverState *bs,QEMUSnapshotInfo *sn_info,const char *name) {
include/block/snapshot.h +8 -0
@@ -27,6 +27,14 @@#include "qemu-common.h" #include "qapi/error.h" +#include "qemu/option.h" + + +#define SNAPSHOT_OPT_BASE "snapshot." +#define SNAPSHOT_OPT_ID "snapshot.id" +#define SNAPSHOT_OPT_NAME "snapshot.name" + +extern QemuOptsList internal_snapshot_opts; typedef struct QEMUSnapshotInfo { char id_str[128]; /* unique snapshot id */
qemu-nbd.c +45 -2
89 lines not on this page · raw message
qemu-nbd.texi +7 -1
@@ -27,7 +27,13 @@ Export QEMU disk image using NBD protocol. @item -P, --partition=@var{num} only expose partition @var{num} @item -s, --snapshot - use snapshot file + use @var{filename} as an external snapshot, create a temporary + file with backing_file=@var{filename}, redirect the write to + the temporary one +@item -l, --load-snapshot=@var{snapshot_param} + load an internal snapshot inside @var{filename} and export it + as an read-only device, @var{snapshot_param} format is + 'snapshot.id=[ID],snapshot.name=[NAME]' or '[ID_OR_NAME]' @item -n, --nocache @itemx --cache=@var{cache} set cache mode to be used with the file. See the documentation of
Signature · 1 line
1.7.1
PATCH v4 3/5 qemu-iotests: add 058 internal snapshot export with qemu-nbd case
In reply to Wenchao Xia--- tests/qemu-iotests/058 | 102 ++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/058.out | 32 ++++++++++++++ tests/qemu-iotests/check | 1 + tests/qemu-iotests/group | 1 + 4 files changed, 136 insertions(+), 0 deletions(-) create mode 100755 tests/qemu-iotests/058 create mode 100644 tests/qemu-iotests/058.out
tests/qemu-iotests/058 new file +102 -0
@@ -0,0 +1,102 @@ +#!/bin/bash +# +# Test export internal snapshot by qemu-nbd. +# +# Copyright (C) 2013 IBM, Inc. +# +# Based on 029. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq=`basename $0` +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! + +nbd_snapshot_port=10850 +nbd_snapshot_img="nbd:127.0.0.1:$nbd_snapshot_port" + +_export_nbd_snapshot() +{ + $QEMU_NBD -v -t -b 127.0.0.1 -p $nbd_snapshot_port "$TEST_IMG" -l $1 & + NBD_SNAPSHOT_PID=$! + sleep 1 +} + +_export_nbd_snapshot1() +{ + $QEMU_NBD -v -t -b 127.0.0.1 -p $nbd_snapshot_port $TEST_IMG -l snapshot.name=$1 & + NBD_SNAPSHOT_PID=$! + sleep 1 +} + +_cleanup() +{ + if [ -n "$NBD_SNAPSHOT_PID" ]; then + kill $NBD_SNAPSHOT_PID + fi + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.pattern + +_supported_fmt qcow2 +_supported_proto generic + +echo +echo "== preparing image ==" +_make_test_img 64M +$QEMU_IO -c 'write -P 0xa 0x1000 0x1000' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'write -P 0xb 0x2000 0x1000' $TEST_IMG | _filter_qemu_io +$QEMU_IMG snapshot -c sn1 $TEST_IMG +$QEMU_IO -c 'write -P 0xc 0x1000 0x1000' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'write -P 0xd 0x2000 0x1000' $TEST_IMG | _filter_qemu_io +_check_test_img + +echo +echo "== verifying the image file with patterns ==" +$QEMU_IO -c 'read -P 0xc 0x1000 0x1000' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'read -P 0xd 0x2000 0x1000' $TEST_IMG | _filter_qemu_io + +_export_nbd_snapshot sn1 + +echo +echo "== verifying the exported snapshot with patterns ==" +$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' $nbd_snapshot_img | _filter_qemu_io +$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' $nbd_snapshot_img | _filter_qemu_io + +kill $NBD_SNAPSHOT_PID +sleep 1 + +_export_nbd_snapshot1 sn1 + +echo +echo "== verifying the exported snapshot with patterns ==" +$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' $nbd_snapshot_img | _filter_qemu_io +$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' $nbd_snapshot_img | _filter_qemu_io + +# success, all done +echo "*** done" +rm -f $seq.full +status=0
tests/qemu-iotests/058.out new file +32 -0
@@ -0,0 +1,32 @@ +QA output created by 058 + +== preparing image == +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 +wrote 4096/4096 bytes at offset 4096 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 4096/4096 bytes at offset 8192 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 4096/4096 bytes at offset 4096 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 4096/4096 bytes at offset 8192 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +No errors were found on the image. + +== verifying the image file with patterns == +read 4096/4096 bytes at offset 4096 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 4096/4096 bytes at offset 8192 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== verifying the exported snapshot with patterns == +read 4096/4096 bytes at offset 4096 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 4096/4096 bytes at offset 8192 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== verifying the exported snapshot with patterns == +read 4096/4096 bytes at offset 4096 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 4096/4096 bytes at offset 8192 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +*** done
tests/qemu-iotests/check +1 -0
@@ -161,6 +161,7 @@ cat <<EOF QEMU -- $QEMU QEMU_IMG -- $QEMU_IMG QEMU_IO -- $QEMU_IO +QEMU_NBD -- $QEMU_NBD IMGFMT -- $FULL_IMGFMT_DETAILS IMGPROTO -- $FULL_IMGPROTO_DETAILS PLATFORM -- $FULL_HOST_DETAILS
tests/qemu-iotests/group +1 -0
@@ -64,6 +64,7 @@ 055 rw auto 056 rw auto backing 057 rw auto +058 rw auto 059 rw auto 060 rw auto 061 rw auto
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH V4 3/5] qemu-iotests: add 058 internal snapshot export with qemu-nbd case
Quoted 51 lines · Wenchao Xia
Signed-off-by Wenchao Xia <[email protected]>--- tests/qemu-iotests/058 | 102 ++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/058.out | 32 ++++++++++++++ tests/qemu-iotests/check | 1 + tests/qemu-iotests/group | 1 + 4 files changed, 136 insertions(+), 0 deletions(-) create mode 100755 tests/qemu-iotests/058 create mode 100644 tests/qemu-iotests/058.outtests/qemu-iotests/058 new file +35
-0@@ -0,0 +1,102 @@ +#!/bin/bash +# +# Test export internal snapshot by qemu-nbd. +# +# Copyright (C) 2013 IBM, Inc. +# +# Based on 029. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq=`basename $0` +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! + +nbd_snapshot_port=10850 +nbd_snapshot_img="nbd:127.0.0.1:$nbd_snapshot_port" +
tests/qemu-iotests/058 line 45
Quoted 10 lines
tests/qemu-iotests/058 new file +10
-0+_export_nbd_snapshot() +{ + $QEMU_NBD -v -t -b 127.0.0.1 -p $nbd_snapshot_port "$TEST_IMG" -l $1 & + NBD_SNAPSHOT_PID=$! + sleep 1 +} + +_export_nbd_snapshot1() +{ + $QEMU_NBD -v -t -b 127.0.0.1 -p $nbd_snapshot_port $TEST_IMG -l snapshot.name=$1 &
Please quote $TEST_IMG, so that it works with spaced pathnames.
Quoted 25 lines
tests/qemu-iotests/058 new file +25
-0+ NBD_SNAPSHOT_PID=$! + sleep 1 +} + +_cleanup() +{ + if [ -n "$NBD_SNAPSHOT_PID" ]; then + kill $NBD_SNAPSHOT_PID + fi + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter +. ./common.pattern + +_supported_fmt qcow2 +_supported_proto generic + +echo +echo "== preparing image ==" +_make_test_img 64M +$QEMU_IO -c 'write -P 0xa 0x1000 0x1000' $TEST_IMG | _filter_qemu_io
tests/qemu-iotests/058 line 80
Quoted 10 lines
tests/qemu-iotests/058 new file +10
-0+$QEMU_IO -c 'write -P 0xb 0x2000 0x1000' $TEST_IMG | _filter_qemu_io +$QEMU_IMG snapshot -c sn1 $TEST_IMG +$QEMU_IO -c 'write -P 0xc 0x1000 0x1000' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'write -P 0xd 0x2000 0x1000' $TEST_IMG | _filter_qemu_io +_check_test_img + +echo +echo "== verifying the image file with patterns ==" +$QEMU_IO -c 'read -P 0xc 0x1000 0x1000' $TEST_IMG | _filter_qemu_io +$QEMU_IO -c 'read -P 0xd 0x2000 0x1000' $TEST_IMG | _filter_qemu_io
More quoting needing ($TEST_IMG again)
Quoted 88 lines
tests/qemu-iotests/058 new file +22
-0+ +_export_nbd_snapshot sn1 + +echo +echo "== verifying the exported snapshot with patterns ==" +$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' $nbd_snapshot_img | _filter_qemu_io +$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' $nbd_snapshot_img | _filter_qemu_io + +kill $NBD_SNAPSHOT_PID +sleep 1 + +_export_nbd_snapshot1 sn1 + +echo +echo "== verifying the exported snapshot with patterns ==" +$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' $nbd_snapshot_img | _filter_qemu_io +$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' $nbd_snapshot_img | _filter_qemu_io + +# success, all done +echo "*** done" +rm -f $seq.full +status=0tests/qemu-iotests/058.out new file +32
-0@@ -0,0 +1,32 @@ +QA output created by 058 + +== preparing image == +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 +wrote 4096/4096 bytes at offset 4096 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 4096/4096 bytes at offset 8192 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 4096/4096 bytes at offset 4096 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 4096/4096 bytes at offset 8192 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +No errors were found on the image. + +== verifying the image file with patterns == +read 4096/4096 bytes at offset 4096 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 4096/4096 bytes at offset 8192 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== verifying the exported snapshot with patterns == +read 4096/4096 bytes at offset 4096 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 4096/4096 bytes at offset 8192 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== verifying the exported snapshot with patterns == +read 4096/4096 bytes at offset 4096 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 4096/4096 bytes at offset 8192 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +*** donetests/qemu-iotests/check +1
-0@@ -161,6 +161,7 @@ cat <<EOF QEMU -- $QEMU QEMU_IMG -- $QEMU_IMG QEMU_IO -- $QEMU_IO +QEMU_NBD -- $QEMU_NBD IMGFMT -- $FULL_IMGFMT_DETAILS IMGPROTO -- $FULL_IMGPROTO_DETAILS PLATFORM -- $FULL_HOST_DETAILStests/qemu-iotests/group +1
-0@@ -64,6 +64,7 @@ 055 rw auto 056 rw auto backing 057 rw auto +058 rw auto 059 rw auto 060 rw auto 061 rw autoSignature · 1 line
1.7.1
PATCH v4 4/5 qemu-img: add -l for snapshot in convert
In reply to Wenchao XiaNow qemu-img convert have similar options as qemu-nbd for internal snapshot.
--- qemu-img-cmds.hx | 2 +- qemu-img.c | 45 ++++++++++++++++++++++++++++++++++++--------- qemu-img.texi | 12 ++++++++---- 3 files changed, 45 insertions(+), 14 deletions(-)
qemu-img-cmds.hx +1 -1
@@ -34,7 +34,7 @@ STEXI ETEXI DEF("convert", img_convert, - "convert [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_name] [-S sparse_size] filename [filename2 [...]] output_filename") + "convert [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-O output_fmt] [-o options] [-s snapshot_id_or_name] [-l snapshot_param] [-S sparse_size] filename [filename2 [...]] output_filename") STEXI @item convert [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} ETEXI
qemu-img.c +36 -9
87 lines not on this page · raw message
qemu-img.texi +8 -4
@@ -46,7 +46,11 @@ is the destination disk image filename is a comma separated list of format specific options in a name=value format. Use @code{-o ?} for an overview of the options supported by the used format or see the format descriptions below for details. - +@item snapshot_param +is param used for internal snapshot, format is +'snapshot.id=[ID],snapshot.name=[NAME]' or '[ID_OR_NAME]' +@item snapshot_id_or_name +is deprecated, use snapshot_param instead @item -c indicates that target image must be compressed (qcow format only)
@@ -179,10 +183,10 @@ Error on reading data @end table -@item convert [-c] [-p] [-n] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} +@item convert [-c] [-p] [-n] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename} -Convert the disk image @var{filename} or a snapshot @var{snapshot_name} to disk image @var{output_filename} -using format @var{output_fmt}. It can be optionally compressed (@code{-c} +Convert the disk image @var{filename} or a snapshot @var{snapshot_param}(@var{snapshot_id_or_name} is deprecated) +to disk image @var{output_filename} using format @var{output_fmt}. It can be optionally compressed (@code{-c} option) or use any format specific options like encryption (@code{-o} option). Only the formats @code{qcow} and @code{qcow2} support compression. The
Signature · 1 line
1.7.1
PATCH v4 5/5 qemu-iotests: add test for snapshot in qemu-img convert
In reply to Wenchao Xia--- tests/qemu-iotests/058 | 19 ++++++++++++++++++- tests/qemu-iotests/058.out | 12 ++++++++++++ 2 files changed, 30 insertions(+), 1 deletions(-)
tests/qemu-iotests/058 +18 -1
@@ -1,6 +1,6 @@ #!/bin/bash # -# Test export internal snapshot by qemu-nbd. +# Test export internal snapshot by qemu-nbd, convert it by qemu-img. # # Copyright (C) 2013 IBM, Inc. #
@@ -33,6 +33,8 @@ status=1 # failure is the default! nbd_snapshot_port=10850 nbd_snapshot_img="nbd:127.0.0.1:$nbd_snapshot_port" +converted_image=$TEST_IMG.converted + _export_nbd_snapshot() { $QEMU_NBD -v -t -b 127.0.0.1 -p $nbd_snapshot_port "$TEST_IMG" -l $1 &
@@ -53,6 +55,7 @@ _cleanup() kill $NBD_SNAPSHOT_PID fi _cleanup_test_img + rm -f $converted_image } trap "_cleanup; exit \$status" 0 1 2 3 15
@@ -96,6 +99,20 @@ echo "== verifying the exported snapshot with patterns ==" $QEMU_IO -c 'read -P 0xa 0x1000 0x1000' $nbd_snapshot_img | _filter_qemu_io $QEMU_IO -c 'read -P 0xb 0x2000 0x1000' $nbd_snapshot_img | _filter_qemu_io +$QEMU_IMG convert $TEST_IMG -l sn1 -O qcow2 $converted_image + +echo +echo "== verifying the converted snapshot with patterns ==" +$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' $converted_image | _filter_qemu_io +$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' $converted_image | _filter_qemu_io + +$QEMU_IMG convert $TEST_IMG -l snapshot.name=sn1 -O qcow2 $converted_image + +echo +echo "== verifying the converted snapshot with patterns ==" +$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' $converted_image | _filter_qemu_io +$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' $converted_image | _filter_qemu_io + # success, all done echo "*** done" rm -f $seq.full
tests/qemu-iotests/058.out +12 -0
@@ -29,4 +29,16 @@ read 4096/4096 bytes at offset 4096 4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 4096/4096 bytes at offset 8192 4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== verifying the converted snapshot with patterns == +read 4096/4096 bytes at offset 4096 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 4096/4096 bytes at offset 8192 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== verifying the converted snapshot with patterns == +read 4096/4096 bytes at offset 4096 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 4096/4096 bytes at offset 8192 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) *** done
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH V4 5/5] qemu-iotests: add test for snapshot in qemu-img convert
Quoted 28 lines · Wenchao Xia
Signed-off-by Wenchao Xia <[email protected]>--- tests/qemu-iotests/058 | 19 ++++++++++++++++++- tests/qemu-iotests/058.out | 12 ++++++++++++ 2 files changed, 30 insertions(+), 1 deletions(-)tests/qemu-iotests/058 +3
-1@@ -1,6 +1,6 @@ #!/bin/bash # -# Test export internal snapshot by qemu-nbd. +# Test export internal snapshot by qemu-nbd, convert it by qemu-img. # # Copyright (C) 2013 IBM, Inc. #@@ -33,6 +33,8 @@ status=1 # failure is the default! nbd_snapshot_port=10850 nbd_snapshot_img="nbd:127.0.0.1:$nbd_snapshot_port" +converted_image=$TEST_IMG.converted + _export_nbd_snapshot() { $QEMU_NBD -v -t -b 127.0.0.1 -p $nbd_snapshot_port "$TEST_IMG" -l $1 &
tests/qemu-iotests/058 _cleanup() · line 58
Quoted 4 lines
tests/qemu-iotests/058 +1
-0@@ -53,6 +55,7 @@ _cleanup() kill $NBD_SNAPSHOT_PID fi _cleanup_test_img + rm -f $converted_image
Please quote $converted_image (especially with rm -f) - it is also used unquoted later on in this file, as well.
tests/qemu-iotests/058 echo "== verifying the exported snapshot with patterns ==" · line 102
Quoted 8 lines
tests/qemu-iotests/058 +1
-0} trap "_cleanup; exit \$status" 0 1 2 3 15@@ -96,6 +99,20 @@ echo "== verifying the exported snapshot with patterns ==" $QEMU_IO -c 'read -P 0xa 0x1000 0x1000' $nbd_snapshot_img | _filter_qemu_io $QEMU_IO -c 'read -P 0xb 0x2000 0x1000' $nbd_snapshot_img | _filter_qemu_io +$QEMU_IMG convert $TEST_IMG -l sn1 -O qcow2 $converted_image
$TEST_IMG needs quoting here, and again below
Quoted 41 lines
tests/qemu-iotests/058 +13
-0+ +echo +echo "== verifying the converted snapshot with patterns ==" +$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' $converted_image | _filter_qemu_io +$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' $converted_image | _filter_qemu_io + +$QEMU_IMG convert $TEST_IMG -l snapshot.name=sn1 -O qcow2 $converted_image + +echo +echo "== verifying the converted snapshot with patterns ==" +$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' $converted_image | _filter_qemu_io +$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' $converted_image | _filter_qemu_io + # success, all done echo "*** done" rm -f $seq.fulltests/qemu-iotests/058.out +12
-0@@ -29,4 +29,16 @@ read 4096/4096 bytes at offset 4096 4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 4096/4096 bytes at offset 8192 4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== verifying the converted snapshot with patterns == +read 4096/4096 bytes at offset 4096 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 4096/4096 bytes at offset 8192 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== verifying the converted snapshot with patterns == +read 4096/4096 bytes at offset 4096 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 4096/4096 bytes at offset 8192 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) *** doneSignature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH V4 5/5] qemu-iotests: add test for snapshot in qemu-img convert
Quoted 40 lines · Jeff Cody
Quoted 28 lines · Wenchao Xia
Signed-off-by Wenchao Xia <[email protected]>--- tests/qemu-iotests/058 | 19 ++++++++++++++++++- tests/qemu-iotests/058.out | 12 ++++++++++++ 2 files changed, 30 insertions(+), 1 deletions(-)tests/qemu-iotests/058 +3
-1@@ -1,6 +1,6 @@ #!/bin/bash # -# Test export internal snapshot by qemu-nbd. +# Test export internal snapshot by qemu-nbd, convert it by qemu-img. # # Copyright (C) 2013 IBM, Inc. #@@ -33,6 +33,8 @@ status=1 # failure is the default! nbd_snapshot_port=10850 nbd_snapshot_img="nbd:127.0.0.1:$nbd_snapshot_port" +converted_image=$TEST_IMG.converted + _export_nbd_snapshot() { $QEMU_NBD -v -t -b 127.0.0.1 -p $nbd_snapshot_port "$TEST_IMG" -l $1 &tests/qemu-iotests/058 _cleanup() · line 58
Quoted 4 lines
tests/qemu-iotests/058 +1
-0@@ -53,6 +55,7 @@ _cleanup() kill $NBD_SNAPSHOT_PID fi _cleanup_test_img + rm -f $converted_imagePlease quote $converted_image (especially with rm -f) - it is also used unquoted later on in this file, as well.
Quoted 3 lines
tests/qemu-iotests/058 +0
-0} trap "_cleanup; exit \$status" 0 1 2 3 15
Quoted 8 lines
tests/qemu-iotests/058 echo "== verifying the exported snapshot with patterns ==" · line 102
Quoted 5 lines
tests/qemu-iotests/058 +1
-0@@ -96,6 +99,20 @@ echo "== verifying the exported snapshot with patterns ==" $QEMU_IO -c 'read -P 0xa 0x1000 0x1000' $nbd_snapshot_img | _filter_qemu_io $QEMU_IO -c 'read -P 0xb 0x2000 0x1000' $nbd_snapshot_img | _filter_qemu_io +$QEMU_IMG convert $TEST_IMG -l sn1 -O qcow2 $converted_image$TEST_IMG needs quoting here, and again below
Thanks for reviewing, will rebase with the quote issue fixed.
Quoted 42 lines
Quoted 41 lines
tests/qemu-iotests/058 +13
-0+ +echo +echo "== verifying the converted snapshot with patterns ==" +$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' $converted_image | _filter_qemu_io +$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' $converted_image | _filter_qemu_io + +$QEMU_IMG convert $TEST_IMG -l snapshot.name=sn1 -O qcow2 $converted_image + +echo +echo "== verifying the converted snapshot with patterns ==" +$QEMU_IO -c 'read -P 0xa 0x1000 0x1000' $converted_image | _filter_qemu_io +$QEMU_IO -c 'read -P 0xb 0x2000 0x1000' $converted_image | _filter_qemu_io + # success, all done echo "*** done" rm -f $seq.fulltests/qemu-iotests/058.out +12
-1@@ -29,4 +29,16 @@ read 4096/4096 bytes at offset 4096 4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 4096/4096 bytes at offset 8192 4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== verifying the converted snapshot with patterns == +read 4096/4096 bytes at offset 4096 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 4096/4096 bytes at offset 8192 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== verifying the converted snapshot with patterns == +read 4096/4096 bytes at offset 4096 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 4096/4096 bytes at offset 8192 +4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) *** done --1.7.1
Quoted 65 lines · Wenchao Xia
This series allow user to read internal snapshot's contents without qemu-img convert.
V2:
Address Stefan's comments:
02: add 'fall through' comments in the case statement.
03: add doc about the difference of internal snapshot and backing chain
snapshot, which is used in previous '--snapshot' parameter.
Other:
01,04: rebased on upstream with conflict resolved.v3:
Address Paolo's comments:
02: add parameter "-lsnapshot_id_or_name", rename options
snapshot-load to load-snapshot, use QemuOpts.
03: rename snapshot-load to load-snapshot.
04: related change to test both -l and -L case. 05-07: add similar parameter for qemu-img convert. Other:
01: foldered original snapshot logic into functionbdrv_snapshot_load_tmp_by_id_or_name(), since multiple caller present in this version. Refined error message from ", reason: %s" to ": %s".
02: Refined error message from ", reason: %s" to ": %s". 03: Rename PARAM toSNAPSHOT_PARAM.v4:
Address Eric's comments:
01: typo fix.
02: squashed patch. Use only one option -l and distiguish
the cases by the starting string.
03: remove 'eval', remove '_supported_osLinux', remove the
comments that have typo.
04: squashed patch. Add only one option -l and distiguish
the cases by the starting string.
05: remove indentation.
Address Paolo's comments:
02: Use only one option -l and distiguish the cases by
the starting string.
04: Use only one option -l and distiguish the cases by
the starting string, mark old -s as deprecated, added doc for them.Wenchao Xia (5):
1 snapshot: distinguish id and name inload_tmp
2 qemu-nbd: support internal snapshot export
3 qemu-iotests: add 058 internal snapshot export with qemu-nbd case 4 qemu-img: add -l for snapshot in convert
5 qemu-iotests: add test for snapshot in qemu-img convertblock/qcow2-snapshot.c | 16 +++++- block/qcow2.h | 5 ++- block/snapshot.c | 78 +++++++++++++++++++++++++++- include/block/block_int.h | 4 +- include/block/snapshot.h | 15 +++++- qemu-img-cmds.hx | 2 +- qemu-img.c | 45 ++++++++++++++--- qemu-img.texi | 12 +++-- qemu-nbd.c | 47 +++++++++++++++++- qemu-nbd.texi | 8 +++- tests/qemu-iotests/058 | 119 ++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/058.out | 44 ++++++++++++++++ tests/qemu-iotests/check | 1 + tests/qemu-iotests/group | 1 + 14 files changed, 374 insertions(+), 23 deletions(-)
Quoted 3 lines
create mode 100755 tests/qemu-iotests/058
create mode 100644 tests/qemu-iotests/058.out
ping?
Hello, rebase on upstream?