nbd: make client request fixed new style if advertised
If the server advertises support for the fixed new style negotiation, the client should in turn enable new style. This will allow the client to negotiate further NBD options besides the export name. Signed-off-by: Daniel P. Berrange <berrange@redhat.com> Message-Id: <1455129674-17255-10-git-send-email-berrange@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
26afa868db
commit
e2a9d9a39d
27
nbd/client.c
27
nbd/client.c
@ -76,7 +76,6 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint32_t *flags,
|
|||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
uint64_t magic, s;
|
uint64_t magic, s;
|
||||||
uint16_t tmp;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
TRACE("Receiving negotiation.");
|
TRACE("Receiving negotiation.");
|
||||||
@ -117,19 +116,26 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint32_t *flags,
|
|||||||
TRACE("Magic is 0x%" PRIx64, magic);
|
TRACE("Magic is 0x%" PRIx64, magic);
|
||||||
|
|
||||||
if (magic == NBD_OPTS_MAGIC) {
|
if (magic == NBD_OPTS_MAGIC) {
|
||||||
uint32_t reserved = 0;
|
uint32_t clientflags = 0;
|
||||||
uint32_t opt;
|
uint32_t opt;
|
||||||
uint32_t namesize;
|
uint32_t namesize;
|
||||||
|
uint16_t globalflags;
|
||||||
|
uint16_t exportflags;
|
||||||
|
|
||||||
if (read_sync(ioc, &tmp, sizeof(tmp)) != sizeof(tmp)) {
|
if (read_sync(ioc, &globalflags, sizeof(globalflags)) !=
|
||||||
|
sizeof(globalflags)) {
|
||||||
error_setg(errp, "Failed to read server flags");
|
error_setg(errp, "Failed to read server flags");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
*flags = be16_to_cpu(tmp) << 16;
|
*flags = be16_to_cpu(globalflags) << 16;
|
||||||
/* reserved for future use */
|
if (globalflags & NBD_FLAG_FIXED_NEWSTYLE) {
|
||||||
if (write_sync(ioc, &reserved, sizeof(reserved)) !=
|
TRACE("Server supports fixed new style");
|
||||||
sizeof(reserved)) {
|
clientflags |= NBD_FLAG_C_FIXED_NEWSTYLE;
|
||||||
error_setg(errp, "Failed to read reserved field");
|
}
|
||||||
|
/* client requested flags */
|
||||||
|
if (write_sync(ioc, &clientflags, sizeof(clientflags)) !=
|
||||||
|
sizeof(clientflags)) {
|
||||||
|
error_setg(errp, "Failed to send clientflags field");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
/* write the export name */
|
/* write the export name */
|
||||||
@ -165,11 +171,12 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint32_t *flags,
|
|||||||
*size = be64_to_cpu(s);
|
*size = be64_to_cpu(s);
|
||||||
TRACE("Size is %" PRIu64, *size);
|
TRACE("Size is %" PRIu64, *size);
|
||||||
|
|
||||||
if (read_sync(ioc, &tmp, sizeof(tmp)) != sizeof(tmp)) {
|
if (read_sync(ioc, &exportflags, sizeof(exportflags)) !=
|
||||||
|
sizeof(exportflags)) {
|
||||||
error_setg(errp, "Failed to read export flags");
|
error_setg(errp, "Failed to read export flags");
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
*flags |= be16_to_cpu(tmp);
|
*flags |= be16_to_cpu(exportflags);
|
||||||
} else if (magic == NBD_CLIENT_MAGIC) {
|
} else if (magic == NBD_CLIENT_MAGIC) {
|
||||||
if (name) {
|
if (name) {
|
||||||
error_setg(errp, "Server does not support export names");
|
error_setg(errp, "Server does not support export names");
|
||||||
|
Loading…
Reference in New Issue
Block a user