From nobody Sun Apr 28 23:22:57 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1516578688841102.59048010008166; Sun, 21 Jan 2018 15:51:28 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id 9CA89C057F83; Sun, 21 Jan 2018 23:51:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 871105F71D; Sun, 21 Jan 2018 23:51:24 +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 B1C6218033D9; Sun, 21 Jan 2018 23:51:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0LNpIpQ027316 for ; Sun, 21 Jan 2018 18:51:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id A33662CFB5; Sun, 21 Jan 2018 23:51:18 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9AF70608F2 for ; Sun, 21 Jan 2018 23:51:16 +0000 (UTC) Received: from mail-qt0-f196.google.com (mail-qt0-f196.google.com [209.85.216.196]) (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 185F45D68B for ; Sun, 21 Jan 2018 23:51:15 +0000 (UTC) Received: by mail-qt0-f196.google.com with SMTP id s3so16756673qtb.10 for ; Sun, 21 Jan 2018 15:51:15 -0800 (PST) Received: from localhost.localdomain ([187.183.59.59]) by smtp.googlemail.com with ESMTPSA id p103sm10098513qkp.74.2018.01.21.15.51.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 21 Jan 2018 15:51:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=bGM8koOqsIF+APt54t8KqKDVZmIwdP+95reWkwkcWVg=; b=eAjrlrUxqYYcpt1bx60xmwlA/OEOgbR1b5lLsdtYoag5tMJGAE60oDKNW/XlKapdDM JlcvJkRz9+zDfj7vrVW/BvVBn73zkZeiTjiHvgrPow6ws6LIjnM2B26QE59FSCfcTzYU CYHWIByKO63zP9Ryn9Jj1uW9PHTTiVqBNrh/CEFAE9x+LOpUXDPSFi6M/aH9S1lN0rIo /0gQAZWUWlOWSBcuZphypA0vDf8kamBNSrDWGd6Sbz+2v0m4wWOu9+6IHr9khtGIkhns A8r3/8VX90YvzRmngI4RC3nGBMKNMdQwC7DwNxxx+cE1xW0u4afA/i/2GfUCFfKSEETH t6Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=bGM8koOqsIF+APt54t8KqKDVZmIwdP+95reWkwkcWVg=; b=Qep8lkYj2ASxYTzl+N+fgX2XUswJZgAgo3WZihYB1805COQC7qYM0sj3dyeWNAtgD+ AuP+HM9XNx4rNXkJDePJcZ9T9/oKlSmVqVfHouyvAnjx7Uc3t84UXvt817FaWsPuUnvE +lh22WfUtPP86WkdChwMyqHI0IsFdAc/x02zRXMSCwK4GMeV2hxSTX7cHe8loUvXfqhm ZklxV9iV5kma6J+Au2aV7v0A7N1LD3SJg4w9q3JWW0GAj/nkgRoISRSHtpBWpQbmNsdI yms/twQoFa3qR8W/813RYbnCnko62+uasl/wQfFOZu+Q1187X54HI1VV2+N/j16JRAZS FcHA== X-Gm-Message-State: AKwxytcrUvNv6MTvgvl0IwrIA+JcnKM1nCpwHSxqJw++9xJoAh22YRlo 7n2Dax2kyXTUZy07XTatVcepxA== X-Google-Smtp-Source: AH8x22739xF8m8L8rg7+3XNJWpOq1TckoXkiD8LZO4NYR5s/fRR8+Hhgt69Idbg6lSeRRIfBO4aqoA== X-Received: by 10.237.39.103 with SMTP id n94mr8334736qtd.323.1516578674064; Sun, 21 Jan 2018 15:51:14 -0800 (PST) From: Julio Faracco To: libvir-list@redhat.com Date: Sun, 21 Jan 2018 21:51:05 -0200 Message-Id: <1516578665-13379-1-git-send-email-jcfaracco@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sun, 21 Jan 2018 23:51:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sun, 21 Jan 2018 23:51:15 +0000 (UTC) for IP:'209.85.216.196' DOMAIN:'mail-qt0-f196.google.com' HELO:'mail-qt0-f196.google.com' FROM:'jcfaracco@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.216.196 mail-qt0-f196.google.com 209.85.216.196 mail-qt0-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2] virsh: Checking the volume capacity before uploading a new file. 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: , MIME-Version: 1.0 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sun, 21 Jan 2018 23:51:27 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The current command 'vol-upload' is not checking if the volume accepts a file bigger than its capacity. It can cause an interrupt of the upload stream. This commit adds a check that fails before starting to send new file to volume if the file is bigger. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1529059 Signed-off-by: Julio Faracco --- tools/virsh-volume.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 8265a39..04e480c 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -672,6 +672,7 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) { const char *file =3D NULL; virStorageVolPtr vol =3D NULL; + virStorageVolInfo volumeInfo; bool ret =3D false; int fd =3D -1; virStreamPtr st =3D NULL; @@ -679,6 +680,7 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) unsigned long long offset =3D 0, length =3D 0; virshControlPtr priv =3D ctl->privData; unsigned int flags =3D 0; + off_t fileLen =3D -1; virshStreamCallbackData cbData; =20 if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0) @@ -701,6 +703,29 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) cbData.ctl =3D ctl; cbData.fd =3D fd; =20 + if (virStorageVolGetInfo(vol, &volumeInfo) < 0) + goto cleanup; + + if ((fileLen =3D virFileLength(file, fd)) < 0) { + vshError(ctl, _("cannot get the file %s length"), file); + goto cleanup; + } + + if (length < fileLen) { + vshError(ctl, _("length parameter is smaller than file size")); + goto cleanup; + } + + if (volumeInfo.capacity < length) { + vshError(ctl, _("lenth parameter is bigger than volume %s capacity= "), name); + goto cleanup; + } + + if (volumeInfo.capacity < fileLen + offset) { + vshError(ctl, _("file is bigger than volume %s capacity"), name); + goto cleanup; + } + if (vshCommandOptBool(cmd, "sparse")) flags |=3D VIR_STORAGE_VOL_UPLOAD_SPARSE_STREAM; =20 --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list