]> git.proxmox.com Git - pve-qemu.git/blame - debian/patches/extra/0039-nbd-make-nbd_drop-public.patch
bump version to 2.9.1-9
[pve-qemu.git] / debian / patches / extra / 0039-nbd-make-nbd_drop-public.patch
CommitLineData
b45e13fe
AD
1From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2From: Eric Blake <eblake@redhat.com>
3Date: Wed, 19 Jul 2017 18:02:01 +0200
4Subject: [PATCH] nbd: make nbd_drop public
5
6RH-Author: Eric Blake <eblake@redhat.com>
7Message-id: <20170719180202.23329-4-eblake@redhat.com>
8Patchwork-id: 75814
9O-Subject: [RHEV-7.4.z qemu-kvm-rhev PATCH 3/4] nbd: make nbd_drop public
10Bugzilla: 1467509
11RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
12RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
13RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
14
15From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
16
17Following commit will reuse it for nbd server too.
18
19Reviewed-by: Eric Blake <eblake@redhat.com>
20Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
21Message-Id: <20170602150150.258222-3-vsementsov@virtuozzo.com>
22Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
23(cherry picked from commit 44298024d30ad36439707b89715a76333f58791b)
24
25 Conflicts:
26 nbd/client.c, nbd/nbd_internal.h, nbd/common.c - missing errp
27 addition (e44ed99) and bulk rename (d1fdf25)
28
29Signed-off-by: Eric Blake <eblake@redhat.com>
30Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
31---
32 nbd/client.c | 32 +++-----------------------------
33 nbd/common.c | 26 ++++++++++++++++++++++++++
34 nbd/nbd-internal.h | 2 ++
35 3 files changed, 31 insertions(+), 29 deletions(-)
36
37diff --git a/nbd/client.c b/nbd/client.c
507c6de3 38index 6b74a628f1..1652f28e9f 100644
b45e13fe
AD
39--- a/nbd/client.c
40+++ b/nbd/client.c
41@@ -86,32 +86,6 @@ static QTAILQ_HEAD(, NBDExport) exports = QTAILQ_HEAD_INITIALIZER(exports);
42
43 */
44
45-/* Discard length bytes from channel. Return -errno on failure and 0 on
46- * success*/
47-static int drop_sync(QIOChannel *ioc, size_t size)
48-{
49- ssize_t ret = 0;
50- char small[1024];
51- char *buffer;
52-
53- buffer = sizeof(small) >= size ? small : g_malloc(MIN(65536, size));
54- while (size > 0) {
55- ssize_t count = MIN(65536, size);
56- ret = read_sync(ioc, buffer, MIN(65536, size));
57-
58- if (ret < 0) {
59- goto cleanup;
60- }
61- size -= count;
62- }
63-
64- cleanup:
65- if (buffer != small) {
66- g_free(buffer);
67- }
68- return ret;
69-}
70-
71 /* Send an option request.
72 *
73 * The request is for option @opt, with @data containing @len bytes of
74@@ -333,7 +307,7 @@ static int nbd_receive_list(QIOChannel *ioc, const char *want, bool *match,
75 return -1;
76 }
77 if (namelen != strlen(want)) {
78- if (drop_sync(ioc, len) < 0) {
79+ if (nbd_drop(ioc, len) < 0) {
80 error_setg(errp, "failed to skip export name with wrong length");
81 nbd_send_opt_abort(ioc);
82 return -1;
83@@ -349,7 +323,7 @@ static int nbd_receive_list(QIOChannel *ioc, const char *want, bool *match,
84 }
85 name[namelen] = '\0';
86 len -= namelen;
87- if (drop_sync(ioc, len) < 0) {
88+ if (nbd_drop(ioc, len) < 0) {
89 error_setg(errp, "failed to read export description");
90 nbd_send_opt_abort(ioc);
91 return -1;
92@@ -616,7 +590,7 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint16_t *flags,
93 }
94
95 TRACE("Size is %" PRIu64 ", export flags %" PRIx16, *size, *flags);
96- if (zeroes && drop_sync(ioc, 124) < 0) {
97+ if (zeroes && nbd_drop(ioc, 124) < 0) {
98 error_setg(errp, "Failed to read reserved block");
99 goto fail;
100 }
101diff --git a/nbd/common.c b/nbd/common.c
507c6de3 102index 4db45b3ede..9a54010c25 100644
b45e13fe
AD
103--- a/nbd/common.c
104+++ b/nbd/common.c
105@@ -71,6 +71,32 @@ ssize_t nbd_wr_syncv(QIOChannel *ioc,
106 return done;
107 }
108
109+/* Discard length bytes from channel. Return -errno on failure and 0 on
110+ * success */
111+int nbd_drop(QIOChannel *ioc, size_t size)
112+{
113+ ssize_t ret = 0;
114+ char small[1024];
115+ char *buffer;
116+
117+ buffer = sizeof(small) >= size ? small : g_malloc(MIN(65536, size));
118+ while (size > 0) {
119+ ssize_t count = MIN(65536, size);
120+ ret = read_sync(ioc, buffer, MIN(65536, size));
121+
122+ if (ret < 0) {
123+ goto cleanup;
124+ }
125+ size -= count;
126+ }
127+
128+ cleanup:
129+ if (buffer != small) {
130+ g_free(buffer);
131+ }
132+ return ret;
133+}
134+
135
136 void nbd_tls_handshake(QIOTask *task,
137 void *opaque)
138diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h
507c6de3 139index e6bbc7c4b4..c02378c553 100644
b45e13fe
AD
140--- a/nbd/nbd-internal.h
141+++ b/nbd/nbd-internal.h
142@@ -149,4 +149,6 @@ struct NBDTLSHandshakeData {
143 void nbd_tls_handshake(QIOTask *task,
144 void *opaque);
145
146+int nbd_drop(QIOChannel *ioc, size_t size);
147+
148 #endif
149--
507c6de3 1502.11.0
b45e13fe 151