From nobody Fri Mar 29 16:02:14 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1570459404; cv=none; d=zoho.com; s=zohoarc; b=TbgNIg4UpduqaRSKtW/6yPJLMm1G+mYlBP/MVWMq2/onuOvuNz7Qtde4O1B1r9QnE2zWxBr66ATGIwQ8q4/S16YlhwD+C3YZ3XSgp+uifHH5VFHaprNwstCEq+BoeueDHOCv/QkLwHKlxHdu3/mfSZONAADgMwu4QMOoSUt4tVg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570459404; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=7VZ2hhRoXZU2MMy6zxC3TYq5qs9VAsblsNmG9RnzZxE=; b=FiLIY0hZ+oGeNUqvBC7NjrtS4eAqSi8TpGjtJy9lZ4FIPuR52Nq9GNJbdZYhzZiCJoyso7cbP9URB4zk6MtKei1JsAs5p7QTyMpvHlwgmRqh00MaVmJu5N4MYv0unDxVki1A9M4WUn3MXD2/+gHKAk1BIwHoGG1LvlnN5NDmWe4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570459404319877.9274753328586; Mon, 7 Oct 2019 07:43:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 954CF307CDD1; Mon, 7 Oct 2019 14:43:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7A4195D70D; Mon, 7 Oct 2019 14:43:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BB38D4EDA6; Mon, 7 Oct 2019 14:43:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x95Iuh1V001717 for ; Sat, 5 Oct 2019 14:56:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 15D37600D1; Sat, 5 Oct 2019 18:56:43 +0000 (UTC) Received: from mx1.redhat.com (ext-mx24.extmail.prod.ext.phx2.redhat.com [10.5.110.65]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 10794600CC for ; Sat, 5 Oct 2019 18:56:40 +0000 (UTC) Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AFB9E10CC1E0 for ; Sat, 5 Oct 2019 18:56:38 +0000 (UTC) Received: by mail-lf1-f68.google.com with SMTP id x80so6668765lff.3 for ; Sat, 05 Oct 2019 11:56:38 -0700 (PDT) Received: from nimbus.bredbandsbolaget.se (c-f25fe655.046-303-73746f39.bbcust.telenor.se. [85.230.95.242]) by smtp.gmail.com with ESMTPSA id q14sm2017258ljc.7.2019.10.05.11.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2019 11:56:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/Vu28JU5nh392j4pZpBcuw/N1B+TAz2jFfm4IrIKQA8=; b=fbeUVoWgZgtWhU5418PUOC8kOnV1W263kLuib6vZRTQgyQNxtzYEACGBcf0eTsD9N9 VsiSLNsTX4rq4oP1GM68xaMdNQE++Q73D8D3SbwoP/rDwEuhnzVOEtAujUGNDugiz1gL SVkdgmcLCbD2Ijfoe8ocyzfrulr+haH3ZcfV2uswKnKMO35TpZmUNXRitJLx8jLU/VOx HTTzxn0OIRfMe+ad0Re3if7b/+w1CiaK5Hol9iG03Gy8F+hUHEzUpAYQEUzEhMjkSUXv CMicvdJnCfkOPSBN4zgGwXgUvx0wCcPFprMIv622m6IAXd1fdZNOwfpGcl4j1fQ1vnOf AhTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/Vu28JU5nh392j4pZpBcuw/N1B+TAz2jFfm4IrIKQA8=; b=Qf7V23kgiPDdYzKjci89ZEFvaDUSDnBeUItnyeH1ELSml9b1kx0EA8WrbxqxHO3AcL 2IqBMq1iqrJ4NyDfK2yMJlFnEoFHFSE91bLCk+qNnBqIbpkpYZuu1MMVqUC5OO9KwKCK JuLSjuULEwxbqW9f/F9Se8gdF1ZRkVSJM8GbEU1FdqWFrT4ZAk9U2c3vz+4A+Jl7csDI ei5SF+YixVtd/jwxU7p/QHocAtsrEa9pJCdWlzffjCwUvZ86d8YjJCk0ogJ9rS1VFjn/ 5UVRf+8CabcNW3Ljh3lWk3o1LUU3re/gZYCCsknykDpaFrjh4a3k8IvGjM1/Yre9zyFG ZnwA== X-Gm-Message-State: APjAAAXWjC7xUboL10ijrqIo//m3W3kZqMEplRCj4+7TIt24J7nWTvg/ nR8zsdF74qJ/F4kkCkTxXQox1AWT X-Google-Smtp-Source: APXvYqxLDGAbusu+VDd5Zy5bLKSPORkkcaHMjVo7nmyRJmjAmKBWiSnpW7tz3Fb+GPqFePumOIj2ig== X-Received: by 2002:a19:495b:: with SMTP id l27mr11464787lfj.45.1570301796820; Sat, 05 Oct 2019 11:56:36 -0700 (PDT) From: martinsson.patrik@gmail.com To: libvir-list@redhat.com Date: Sat, 5 Oct 2019 20:56:21 +0200 Message-Id: <20191005185621.1517545-2-martinsson.patrik@gmail.com> In-Reply-To: <20191005185621.1517545-1-martinsson.patrik@gmail.com> References: <20191005185621.1517545-1-martinsson.patrik@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Sat, 05 Oct 2019 18:56:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Sat, 05 Oct 2019 18:56:39 +0000 (UTC) for IP:'209.85.167.68' DOMAIN:'mail-lf1-f68.google.com' HELO:'mail-lf1-f68.google.com' FROM:'martinsson.patrik@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.1 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS) 209.85.167.68 mail-lf1-f68.google.com 209.85.167.68 mail-lf1-f68.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.65 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Mon, 07 Oct 2019 10:35:27 -0400 Cc: patchon Subject: [libvirt] [PATCH 1/1] Add shrink flag to blockresize command X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 07 Oct 2019 14:43:23 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: patchon These commits simply adds the '--shrink' flag to the blockresize command to prevent accidental shrinking of a block device. This behaviour is already present on the vol-resize command and it makes sense to mimic that behaviour. Only implemented in the qemu-driver atm. Signed-off-by: Patrik Martinsson --- src/qemu/qemu_driver.c | 15 ++++++++++++++- tools/virsh-domain.c | 7 +++++++ tools/virsh.pod | 9 ++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 95fe844c34..4e34eec796 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11265,8 +11265,10 @@ qemuDomainBlockResize(virDomainPtr dom, char *device =3D NULL; const char *nodename =3D NULL; virDomainDiskDefPtr disk =3D NULL; + virDomainBlockInfo info; =20 - virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES, -1); + virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES | + VIR_STORAGE_VOL_RESIZE_SHRINK, -1); =20 /* We prefer operating on bytes. */ if ((flags & VIR_DOMAIN_BLOCK_RESIZE_BYTES) =3D=3D 0) { @@ -11279,6 +11281,9 @@ qemuDomainBlockResize(virDomainPtr dom, size *=3D 1024; } =20 + if (virDomainGetBlockInfo(dom, path, &info, 0) < 0) + goto cleanup; + if (!(vm =3D qemuDomainObjFromDomain(dom))) goto cleanup; =20 @@ -11299,6 +11304,14 @@ qemuDomainBlockResize(virDomainPtr dom, goto endjob; } =20 + if (size < info.capacity && + !(flags & VIR_STORAGE_VOL_RESIZE_SHRINK)) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("Can't shrink capacity below current " + "capacity unless shrink flag explicitly specified= ")); + goto endjob; + } + /* qcow2 and qed must be sized on 512 byte blocks/sectors, * so adjust size if necessary to round up. */ diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index fbfdc09c0d..a67ee35428 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2920,6 +2920,10 @@ static const vshCmdOptDef opts_blockresize[] =3D { .flags =3D VSH_OFLAG_REQ, .help =3D N_("New size of the block device, as scaled integer (defaul= t KiB)") }, + {.name =3D "shrink", + .type =3D VSH_OT_BOOL, + .help =3D N_("allow the resize to shrink the volume") + }, {.name =3D NULL} }; =20 @@ -2938,6 +2942,9 @@ cmdBlockresize(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptScaledInt(ctl, cmd, "size", &size, 1024, ULLONG_MAX) = < 0) return false; =20 + if (vshCommandOptBool(cmd, "shrink")) + flags |=3D VIR_STORAGE_VOL_RESIZE_SHRINK; + /* Prefer the older interface of KiB. */ if (size % 1024 =3D=3D 0) size /=3D 1024; diff --git a/tools/virsh.pod b/tools/virsh.pod index cf2798e71a..96387127d6 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1027,7 +1027,7 @@ I specifies copying bandwidth limit in MiB= /s. For further information on the I argument see the corresponding section for the B command. =20 -=3Ditem B I I I +=3Ditem B I I I<--size> I<--shrink> =20 Resize a block device of domain while the domain is running, I specifies the absolute path of the block device; it corresponds @@ -1040,6 +1040,13 @@ I is a scaled integer (see B above) whi= ch defaults to KiB "B" to get bytes (note that for historical reasons, this differs from B which defaults to bytes without a suffix). =20 +Attempts to shrink the block device will fail unless I<--shrink> is presen= t. +The I cannot be negative since the given capacity is the absolute +size of the block device. Always exercise caution when shrinking a block d= evice. +B that it is up to the driver to implement the check if shrinki= ng +should be allowed or not depending on if I<--shrink> is set. So far only t= he +qemu-driver does this. + =3Ditem B I [I] [I<--safe>] [I<--force>] =20 Connect the virtual serial console for the guest. The optional --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list