From nobody Mon Feb 9 17:24:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1644510172613801.4800635285088; Thu, 10 Feb 2022 08:22:52 -0800 (PST) Received: from localhost ([::1]:51612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nICDa-0001U0-1Q for importer@patchew.org; Thu, 10 Feb 2022 11:22:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:45530) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nI9Y0-0003iw-NK; Thu, 10 Feb 2022 08:31:44 -0500 Received: from proxmox-new.maurer-it.com ([94.136.29.106]:8677) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nI9Xx-0004mf-N6; Thu, 10 Feb 2022 08:31:44 -0500 Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 3D04046DCB; Thu, 10 Feb 2022 14:31:31 +0100 (CET) From: Fabian Ebner To: qemu-devel@nongnu.org Subject: [PATCH 4/4] qemu-img: dd: add -l option for loading a snapshot Date: Thu, 10 Feb 2022 14:31:23 +0100 Message-Id: <20220210133123.347350-5-f.ebner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220210133123.347350-1-f.ebner@proxmox.com> References: <20220210133123.347350-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=94.136.29.106; envelope-from=f.ebner@proxmox.com; helo=proxmox-new.maurer-it.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, w.bumiller@proxmox.com, qemu-block@nongnu.org, aderumier@odiso.com, hreitz@redhat.com, t.lamprecht@proxmox.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1644510173512100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Fabian Ebner --- docs/tools/qemu-img.rst | 7 ++++--- qemu-img-cmds.hx | 4 ++-- qemu-img.c | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst index 9b022d9363..b2333d7b04 100644 --- a/docs/tools/qemu-img.rst +++ b/docs/tools/qemu-img.rst @@ -500,10 +500,11 @@ Command description: it doesn't need to be specified separately in this case. =20 =20 -.. option:: dd [--image-opts] [-U] [-f FMT] [-O OUTPUT_FMT] [-n] [bs=3DBLO= CK_SIZE] [count=3DBLOCKS] [skip=3DBLOCKS] [isize=3DINPUT_SIZE] [osize=3DOUT= PUT_SIZE] [if=3DINPUT] [of=3DOUTPUT] +.. option:: dd [--image-opts] [-U] [-f FMT] [-O OUTPUT_FMT] [-n] [-l SNAPS= HOT_PARAM] [bs=3DBLOCK_SIZE] [count=3DBLOCKS] [skip=3DBLOCKS] [isize=3DINPU= T_SIZE] [osize=3DOUTPUT_SIZE] [if=3DINPUT] [of=3DOUTPUT] =20 - dd copies from *INPUT* file (default: STDIN) to *OUTPUT* file (default: - STDOUT) converting it from *FMT* format to *OUTPUT_FMT* format. + dd copies from *INPUT* file (default: STDIN) or snapshot *SNAPSHOT_PARAM= * to + *OUTPUT* file (default: STDOUT) converting it from *FMT* format to + *OUTPUT_FMT* format. =20 The data is by default read and written using blocks of 512 bytes but ca= n be modified by specifying *BLOCK_SIZE*. If count=3D\ *BLOCKS* is specified diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index 97e750623f..2f527306b0 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -58,9 +58,9 @@ SRST ERST =20 DEF("dd", img_dd, - "dd [--image-opts] [-U] [-f fmt] [-O output_fmt] [-n] [bs=3Dblock_size= ] [count=3Dblocks] [skip=3Dblocks] [isize=3Dinput_size] [osize=3Doutput_siz= e] [if=3Dinput] [of=3Doutput]") + "dd [--image-opts] [-U] [-f fmt] [-O output_fmt] [-n] [-l snapshot_par= am] [bs=3Dblock_size] [count=3Dblocks] [skip=3Dblocks] [isize=3Dinput_size]= [osize=3Doutput_size] [if=3Dinput] [of=3Doutput]") SRST -.. option:: dd [--image-opts] [-U] [-f FMT] [-O OUTPUT_FMT] [-n] [bs=3DBLO= CK_SIZE] [count=3DBLOCKS] [skip=3DBLOCKS] [isize=3DINPUT_SIZE] [osize=3DOUT= PUT_SIZE] [if=3DINPUT] [of=3DOUTPUT] +.. option:: dd [--image-opts] [-U] [-f FMT] [-O OUTPUT_FMT] [-n] [-l SNAPS= HOT_PARAM] [bs=3DBLOCK_SIZE] [count=3DBLOCKS] [skip=3DBLOCKS] [isize=3DINPU= T_SIZE] [osize=3DOUTPUT_SIZE] [if=3DINPUT] [of=3DOUTPUT] ERST =20 DEF("info", img_info, diff --git a/qemu-img.c b/qemu-img.c index 89bf6fd087..28b6430800 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -4936,6 +4936,7 @@ static int img_dd(int argc, char **argv) BlockDriver *drv =3D NULL, *proto_drv =3D NULL; BlockBackend *blk1 =3D NULL, *blk2 =3D NULL; QemuOpts *opts =3D NULL; + QemuOpts *sn_opts =3D NULL; QemuOptsList *create_opts =3D NULL; Error *local_err =3D NULL; bool image_opts =3D false; @@ -4945,6 +4946,7 @@ static int img_dd(int argc, char **argv) int64_t size =3D 0, readsize =3D 0; int64_t block_count =3D 0, out_pos, in_pos; bool force_share =3D false, skip_create =3D false; + const char *snapshot_name =3D NULL; struct DdInfo dd =3D { .flags =3D 0, .count =3D 0, @@ -4982,7 +4984,7 @@ static int img_dd(int argc, char **argv) { 0, 0, 0, 0 } }; =20 - while ((c =3D getopt_long(argc, argv, ":hf:O:Un", long_options, NULL))= ) { + while ((c =3D getopt_long(argc, argv, ":hf:O:l:Un", long_options, NULL= ))) { if (c =3D=3D EOF) { break; } @@ -5005,6 +5007,19 @@ static int img_dd(int argc, char **argv) case 'n': skip_create =3D true; break; + case 'l': + if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) { + sn_opts =3D qemu_opts_parse_noisily(&internal_snapshot_opt= s, + optarg, false); + if (!sn_opts) { + error_report("Failed in parsing snapshot param '%s'", + optarg); + goto out; + } + } else { + snapshot_name =3D optarg; + } + break; case 'U': force_share =3D true; break; @@ -5074,11 +5089,24 @@ static int img_dd(int argc, char **argv) if (dd.flags & C_IF) { blk1 =3D img_open(image_opts, in.filename, fmt, 0, false, false, force_share); - if (!blk1) { ret =3D -1; goto out; } + if (sn_opts) { + bdrv_snapshot_load_tmp(blk_bs(blk1), + qemu_opt_get(sn_opts, SNAPSHOT_OPT_ID), + qemu_opt_get(sn_opts, SNAPSHOT_OPT_NAME= ), + &local_err); + } else if (snapshot_name !=3D NULL) { + bdrv_snapshot_load_tmp_by_id_or_name(blk_bs(blk1), snapshot_na= me, + &local_err); + } + if (local_err) { + error_reportf_err(local_err, "Failed to load snapshot: "); + ret =3D -1; + goto out; + } } =20 if (dd.flags & C_ISIZE && dd.isize > 0) { @@ -5233,6 +5261,7 @@ static int img_dd(int argc, char **argv) out: g_free(arg); qemu_opts_del(opts); + qemu_opts_del(sn_opts); qemu_opts_free(create_opts); blk_unref(blk1); blk_unref(blk2); --=20 2.30.2