[libvirt] [PATCH v2] virsh: Checking the volume capacity before uploading a new file.
Peter Krempa
pkrempa at redhat.com
Mon Jan 22 14:44:52 UTC 2018
On Sun, Jan 21, 2018 at 21:51:05 -0200, Julio Faracco wrote:
> 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=1529059
>
> Signed-off-by: Julio Faracco <jcfaracco at gmail.com>
> ---
> 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 = NULL;
> virStorageVolPtr vol = NULL;
> + virStorageVolInfo volumeInfo;
> bool ret = false;
> int fd = -1;
> virStreamPtr st = NULL;
> @@ -679,6 +680,7 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
> unsigned long long offset = 0, length = 0;
> virshControlPtr priv = ctl->privData;
> unsigned int flags = 0;
> + off_t fileLen = -1;
> virshStreamCallbackData cbData;
>
> if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0)
> @@ -701,6 +703,29 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
> cbData.ctl = ctl;
> cbData.fd = fd;
>
> + if (virStorageVolGetInfo(vol, &volumeInfo) < 0)
> + goto cleanup;
> +
> + if ((fileLen = virFileLength(file, fd)) < 0) {
> + vshError(ctl, _("cannot get the file %s length"), file);
This is wrong since you might want to upload contents of a block device,
in which case you'd report this error.
> + goto cleanup;
> + }
> +
> + if (length < fileLen) {
I think this is wrong. The 'length' parameter was designed to allow
upload of a partial file. Adding this would break it.
> + vshError(ctl, _("length parameter is smaller than file size"));
> + goto cleanup;
> + }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20180122/96826833/attachment-0001.sig>
More information about the libvir-list
mailing list