Skip to content

Commit

Permalink
nbd: make nbd_drop public
Browse files Browse the repository at this point in the history
Following commit will reuse it for nbd server too.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20170602150150.258222-3-vsementsov@virtuozzo.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
Vladimir Sementsov-Ogievskiy authored and bonzini committed Jun 15, 2017
1 parent d1fdf25 commit 4429802
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
26 changes: 0 additions & 26 deletions nbd/client.c
Expand Up @@ -86,32 +86,6 @@ static QTAILQ_HEAD(, NBDExport) exports = QTAILQ_HEAD_INITIALIZER(exports);
*/

/* Discard length bytes from channel. Return -errno on failure and 0 on
* success*/
static int nbd_drop(QIOChannel *ioc, size_t size, Error **errp)
{
ssize_t ret = 0;
char small[1024];
char *buffer;

buffer = sizeof(small) >= size ? small : g_malloc(MIN(65536, size));
while (size > 0) {
ssize_t count = MIN(65536, size);
ret = nbd_read(ioc, buffer, MIN(65536, size), errp);

if (ret < 0) {
goto cleanup;
}
size -= count;
}

cleanup:
if (buffer != small) {
g_free(buffer);
}
return ret;
}

/* Send an option request.
*
* The request is for option @opt, with @data containing @len bytes of
Expand Down
26 changes: 26 additions & 0 deletions nbd/common.c
Expand Up @@ -65,6 +65,32 @@ ssize_t nbd_rwv(QIOChannel *ioc, struct iovec *iov, size_t niov, size_t length,
return done;
}

/* Discard length bytes from channel. Return -errno on failure and 0 on
* success */
int nbd_drop(QIOChannel *ioc, size_t size, Error **errp)
{
ssize_t ret = 0;
char small[1024];
char *buffer;

buffer = sizeof(small) >= size ? small : g_malloc(MIN(65536, size));
while (size > 0) {
ssize_t count = MIN(65536, size);
ret = nbd_read(ioc, buffer, MIN(65536, size), errp);

if (ret < 0) {
goto cleanup;
}
size -= count;
}

cleanup:
if (buffer != small) {
g_free(buffer);
}
return ret;
}


void nbd_tls_handshake(QIOTask *task,
void *opaque)
Expand Down
2 changes: 2 additions & 0 deletions nbd/nbd-internal.h
Expand Up @@ -153,4 +153,6 @@ struct NBDTLSHandshakeData {
void nbd_tls_handshake(QIOTask *task,
void *opaque);

int nbd_drop(QIOChannel *ioc, size_t size, Error **errp);

#endif

0 comments on commit 4429802

Please sign in to comment.