]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Pass virshStreamCallbackDataPtr to virshStreamSink() and virshStreamSkip()
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 2 Jul 2020 06:42:44 +0000 (08:42 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 24 Aug 2020 11:32:53 +0000 (13:32 +0200)
These callback will need to know more that the FD they are
working on. Pass the structure that is passed to other stream
callbacks (e.g. virshStreamSource() or virshStreamSourceSkip())
instead of inventing a new one.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
tools/virsh-util.c
tools/virsh-volume.c

index 932d6d0849936953760425bd2174ea5e1df759ea..89f15efd0862ec1b91676f02ab5b71cbd2d2fd93 100644 (file)
@@ -146,9 +146,9 @@ virshStreamSink(virStreamPtr st G_GNUC_UNUSED,
                 size_t nbytes,
                 void *opaque)
 {
-    int *fd = opaque;
+    virshStreamCallbackDataPtr cbData = opaque;
 
-    return safewrite(*fd, bytes, nbytes);
+    return safewrite(cbData->fd, bytes, nbytes);
 }
 
 
@@ -186,13 +186,13 @@ virshStreamSkip(virStreamPtr st G_GNUC_UNUSED,
                 long long offset,
                 void *opaque)
 {
-    int *fd = opaque;
+    virshStreamCallbackDataPtr cbData = opaque;
     off_t cur;
 
-    if ((cur = lseek(*fd, offset, SEEK_CUR)) == (off_t) -1)
+    if ((cur = lseek(cbData->fd, offset, SEEK_CUR)) == (off_t) -1)
         return -1;
 
-    if (ftruncate(*fd, cur) < 0)
+    if (ftruncate(cbData->fd, cur) < 0)
         return -1;
 
     return 0;
index e04e2db09624b506a2db3e58badf60298c379611..d29db6c38dd8778f816a145e51907c9b52dd753b 100644 (file)
@@ -790,6 +790,7 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd)
     unsigned long long offset = 0, length = 0;
     bool created = false;
     virshControlPtr priv = ctl->privData;
+    virshStreamCallbackData cbData;
     unsigned int flags = 0;
 
     if (vshCommandOptULongLong(ctl, cmd, "offset", &offset) < 0)
@@ -817,6 +818,9 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd)
         created = true;
     }
 
+    cbData.ctl = ctl;
+    cbData.fd = fd;
+
     if (!(st = virStreamNew(priv->conn, 0))) {
         vshError(ctl, _("cannot create a new stream"));
         goto cleanup;
@@ -827,7 +831,7 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
-    if (virStreamSparseRecvAll(st, virshStreamSink, virshStreamSkip, &fd) < 0) {
+    if (virStreamSparseRecvAll(st, virshStreamSink, virshStreamSkip, &cbData) < 0) {
         vshError(ctl, _("cannot receive data from volume %s"), name);
         goto cleanup;
     }