From nobody Sun May 5 19:46:47 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 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=1571737076; cv=none; d=zoho.com; s=zohoarc; b=hHcqpsWnPs3O8F7+Al1BaJY7AXSjdN6bNs3/nB29vTEkmSSMrDZrirnHqDrFOabWCHBZNUGfMIBXbUCm0JCt4IuKpRwjGUlp6X292tmDncePqJ6d//YOjVO4imBGAuxCw9sAymHjzogEb7PoDT8mAe45WY2a+niwYbFIoNyv1j8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571737076; 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; bh=6EHz1Kjz12PLX4YVuJUwaMVJzegZfu9NZ7/p4vs13DU=; b=Krg9iFXLbiM8HHL1n8N05SnZTD+ltBM4CEO2xUcj9rWyutXgIZKYwVFCtfGO+iUySqJHtEjukHRLn7odPSMlVjUacnON+IOmjkKHf8twns1UDCY7Ro4Z1zOr4PpPN8A1aSIjstHJNuvjRf1lricZ3b2Khh5yZVxzxKTFDcfMvNk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 157173707649261.527233613928615; Tue, 22 Oct 2019 02:37:56 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-219-OSC7gBPOMRCiBo2moz5_8g-1; Tue, 22 Oct 2019 05:37:52 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 957E31005516; Tue, 22 Oct 2019 09:37:47 +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 706075C57A; Tue, 22 Oct 2019 09:37:47 +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 310351A518; Tue, 22 Oct 2019 09:37:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x9LJtx0R006875 for ; Mon, 21 Oct 2019 15:55:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 50B331001DE4; Mon, 21 Oct 2019 19:55:59 +0000 (UTC) Received: from mx1.redhat.com (ext-mx21.extmail.prod.ext.phx2.redhat.com [10.5.110.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4B5301001DD7 for ; Mon, 21 Oct 2019 19:55:55 +0000 (UTC) Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) (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 3428118C426D for ; Mon, 21 Oct 2019 19:55:54 +0000 (UTC) Received: by mail-lf1-f65.google.com with SMTP id y6so4838138lfj.2 for ; Mon, 21 Oct 2019 12:55:54 -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 q27sm3349974lfn.96.2019.10.21.12.55.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 12:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571737075; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=6EHz1Kjz12PLX4YVuJUwaMVJzegZfu9NZ7/p4vs13DU=; b=PPix8l40R+W3wOWSDKzIXFY4bj1x5j3wvwV73N6EmhNvrEmZjJAKDI9AHGobWg8bFX4noF y/eAM/y1gpG4ybXsbcrQPLPLq3mYoKZd9SuGds4i7qhfBKA23Upp2fTnx+X9E0oSJbe3Zs ZfSs61ugYyXBqaJ4yJHPOWw6oYcWUDA= 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=uxg97djw3mmbUwEAtX4et2V9v1+3ondrVYOe6JQpYno=; b=qh/Mai6Ik0C0z2+1Tg7Rn28mCjll+GODatH68o9bjGuEgunP3oW5wt8wXDk+0TMopb URo+ZtmAJITPsHT5SvLni+PLwLGbiEWqGkuIFOuTHabJ8G+y/XMLVtc3KaiKlbetXYnI LS7OVx4nWf66hyyzUxOaBw0Cuh4/EPBOjK/m1kwig/V+KsbdYJUUa2SFepTWmbV+hpTe hS5cKVXffigJSOzu9RhWq4mzYbJnvMeyr04zYmoR+syr2aZRJSavqTGLBCWcvIOX9HYT PacyV0CkLezB5oZ865hi+Ucr3fdbup+UBQHlcla7wFBaENJpIzXK9csotJtKj/JzGOrC 0G4Q== X-Gm-Message-State: APjAAAU2j9gL/QuGN6kkHmGSEQxrwTO5lRNgec89pdizNERY0zs10aS2 yYHqxlVL2zjkIC0xhsWHXJki8vca X-Google-Smtp-Source: APXvYqySkmgbaAmj/6DMb+kzMvB4EKkx+58VWNfJtq/vWiSiuVEkBKSCZygkeIoKYYjXt+0vvg/YpQ== X-Received: by 2002:a19:ac01:: with SMTP id g1mr16297455lfc.141.1571687752285; Mon, 21 Oct 2019 12:55:52 -0700 (PDT) From: martinsson.patrik@gmail.com To: libvir-list@redhat.com Date: Mon, 21 Oct 2019 21:55:39 +0200 Message-Id: <20191021195539.1623177-2-martinsson.patrik@gmail.com> In-Reply-To: <20191021195539.1623177-1-martinsson.patrik@gmail.com> References: <20191021195539.1623177-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.62]); Mon, 21 Oct 2019 19:55:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Mon, 21 Oct 2019 19:55:54 +0000 (UTC) for IP:'209.85.167.65' DOMAIN:'mail-lf1-f65.google.com' HELO:'mail-lf1-f65.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.65 mail-lf1-f65.google.com 209.85.167.65 mail-lf1-f65.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.62 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-Mailman-Approved-At: Tue, 22 Oct 2019 03:54:42 -0400 Cc: Patrik Martinsson Subject: [libvirt] [PATCHv2 1/1] Add --force flag to virsh blockresize 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-MC-Unique: OSC7gBPOMRCiBo2moz5_8g-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Patrik Martinsson This commit simply adds the '--force' flag to the blockresize command to prevent accidental shrinking of a block device. Similar behaviour is already present on the vol-resize command and it makes sense to mimic it. Implemented in virsh and not in the API. This is to prevent existing applications using the BlockResize-API from 'breaking'. Signed-off-by: Patrik Martinsson --- docs/news.xml | 13 +++++++++++++ tools/virsh-domain.c | 34 +++++++++++++++++++++++++++++++--- tools/virsh.pod | 6 +++++- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/docs/news.xml b/docs/news.xml index c8d55e357b..595d63137a 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -61,6 +61,19 @@
+ + + virsh: Add --force to the blockresize command + + + To prevent accidental shrinking of a block device the --force fl= ag + is introduced for the blockresize command, similar to the --shri= nk + flag for the vol-resize command. If you intend to shrink a block + device with virsh blockresize, you must now include + --force, otherwise the command will fail with an error. This cha= nge + is only in virsh, not in the API. + +
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 2f3ac2d430..412b7e4028 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 "force", + .type =3D VSH_OT_BOOL, + .help =3D N_("Allow the resize to shrink the blockdevice") + }, {.name =3D NULL} }; =20 @@ -2927,10 +2931,12 @@ static bool cmdBlockresize(vshControl *ctl, const vshCmd *cmd) { virDomainPtr dom; + virDomainBlockInfo info; const char *path =3D NULL; unsigned long long size =3D 0; unsigned int flags =3D 0; bool ret =3D false; + bool force =3D vshCommandOptBool(cmd, "force"); =20 if (vshCommandOptStringReq(ctl, cmd, "path", (const char **) &path) < = 0) return false; @@ -2938,24 +2944,46 @@ cmdBlockresize(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptScaledInt(ctl, cmd, "size", &size, 1024, ULLONG_MAX) = < 0) return false; =20 + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (virDomainGetBlockInfo(dom, path, &info, 0) < 0) + goto cleanup; + + /* Make sure to not shrink device if it's already given size */ + if (size =3D=3D info.capacity) { + vshPrintExtra(ctl, _("Given size (%llu bytes) is the same as the " + "current capacity of '%s', not doing anything= "), + size, path); + goto cleanup; + } + + /* Make sure to only allow shrink of device if --force is specified */ + if (size < info.capacity && !force) { + vshError(ctl, _("Can't shrink the size of '%s' below current capac= ity, " + "unless --force is explicity specified"), path); + goto cleanup; + } + /* Prefer the older interface of KiB. */ if (size % 1024 =3D=3D 0) size /=3D 1024; else flags |=3D VIR_DOMAIN_BLOCK_RESIZE_BYTES; =20 - if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) - return false; - if (virDomainBlockResize(dom, path, size, flags) < 0) { vshError(ctl, _("Failed to resize block device '%s'"), path); + goto cleanup; } else { vshPrintExtra(ctl, _("Block device '%s' is resized"), path); ret =3D true; + goto cleanup; } =20 + cleanup: virshDomainFree(dom); return ret; + } =20 #ifndef WIN32 diff --git a/tools/virsh.pod b/tools/virsh.pod index cf2798e71a..dc34a2a263 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 [I<--force>] =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,10 @@ 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 +The I<--force> flag is needed when specified I is less than the curr= ent +capacity of the device, ie. when shrinking a device. Always exercise cauti= on +when shrinking a block device. + =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