From patchwork Mon Nov 18 12:25:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 292059 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5A3392C00B3 for ; Mon, 18 Nov 2013 23:32:33 +1100 (EST) Received: from localhost ([::1]:42720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ViO0E-0003l2-LW for incoming@patchwork.ozlabs.org; Mon, 18 Nov 2013 07:32:30 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50817) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ViNv7-0005Kk-NN for qemu-devel@nongnu.org; Mon, 18 Nov 2013 07:27:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ViNuz-0006nW-9H for qemu-devel@nongnu.org; Mon, 18 Nov 2013 07:27:13 -0500 Received: from mail-wg0-x233.google.com ([2a00:1450:400c:c00::233]:45389) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ViNuy-0006nK-MR for qemu-devel@nongnu.org; Mon, 18 Nov 2013 07:27:04 -0500 Received: by mail-wg0-f51.google.com with SMTP id m15so6000081wgh.6 for ; Mon, 18 Nov 2013 04:27:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=U+VdtvXL+Er0T+YVLqxURY+AnKMMVqrDLmhDrYJe32M=; b=Aex7q5QOW7AY0V/CS6QfsPFmDCjwprMnu96UQMWPcGMD7nB7v4c37Dotbq8jTKM9tI zRcOsenqlIcbZGijtUq380uohwIT7UKBc/TjIREhKKrVA1sQDJzzf4SsAdKcwVQulHFJ Rm2mlAr1d3kaxfGvFbF3zDwTuu28EwYI2r8+YLSgsShQpEaNAgma3oAMqHFwpECd7scT dMRfsmSWcJxwi85gsJguWjYj47ChxRY+g3n14hKzLzcVHa5CoOdX85ykl4UeWTgScliP OFfzsQO8an3h0eHXUxnCE5ZG9Q/XYrlljJbJW3zuJlxi3eyuWnTH+BR0KUfTfY737ymI GxdQ== X-Received: by 10.180.86.102 with SMTP id o6mr16748633wiz.30.1384777623817; Mon, 18 Nov 2013 04:27:03 -0800 (PST) Received: from localhost (nat-pool-cdg-t.redhat.com. [209.132.186.20]) by mx.google.com with ESMTPSA id hv5sm23681779wib.2.2013.11.18.04.27.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Nov 2013 04:27:02 -0800 (PST) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Mon, 18 Nov 2013 13:25:18 +0100 Message-Id: <1384777531-14635-9-git-send-email-marcandre.lureau@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1384777531-14635-1-git-send-email-marcandre.lureau@gmail.com> References: <1384777531-14635-1-git-send-email-marcandre.lureau@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c00::233 Cc: kwolf@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , jcody@redhat.com, kraxel@redhat.com, spice-devel@freedesktop.org Subject: [Qemu-devel] [PATCH 08/21] nbd: pass export name as init argument X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Marc-André Lureau There is no need to keep the export name around, and it seems a better fit as an argument in the init() call. Signed-off-by: Marc-André Lureau --- block/nbd-client.c | 10 ++++------ block/nbd-client.h | 5 ++--- block/nbd.c | 13 ++++++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index 1abfc6a..e29227b 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -338,17 +338,15 @@ static void nbd_teardown_connection(NbdClientSession *client) void nbd_client_session_close(NbdClientSession *client) { nbd_teardown_connection(client); - g_free(client->export_name); - client->export_name = NULL; } -int nbd_client_session_init(NbdClientSession *client, - BlockDriverState *bs, int sock) +int nbd_client_session_init(NbdClientSession *client, BlockDriverState *bs, + int sock, const char *export) { int ret; - /* NBD handshake */ - ret = nbd_receive_negotiate(sock, client->export_name, + logout("session init %s\n", export); + ret = nbd_receive_negotiate(sock, export, &client->nbdflags, &client->size, &client->blocksize); if (ret < 0) { diff --git a/block/nbd-client.h b/block/nbd-client.h index c271236..f2a6337 100644 --- a/block/nbd-client.h +++ b/block/nbd-client.h @@ -30,14 +30,13 @@ typedef struct NbdClientSession { Coroutine *recv_coroutine[MAX_NBD_REQUESTS]; struct nbd_reply reply; - char *export_name; /* An NBD server may export several devices */ bool is_unix; BlockDriverState *bs; } NbdClientSession; -int nbd_client_session_init(NbdClientSession *client, - BlockDriverState *bs, int sock); +int nbd_client_session_init(NbdClientSession *client, BlockDriverState *bs, + int sock, const char *export_name); void nbd_client_session_close(NbdClientSession *client); int nbd_client_session_co_discard(NbdClientSession *client, int64_t sector_num, diff --git a/block/nbd.c b/block/nbd.c index be75ba0..4455a13 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -188,7 +188,7 @@ out: g_free(file); } -static int nbd_config(BDRVNBDState *s, QDict *options) +static int nbd_config(BDRVNBDState *s, QDict *options, char **export) { Error *local_err = NULL; @@ -218,8 +218,8 @@ static int nbd_config(BDRVNBDState *s, QDict *options) qemu_opt_set_number(s->socket_opts, "port", NBD_DEFAULT_PORT); } - s->client.export_name = g_strdup(qdict_get_try_str(options, "export")); - if (s->client.export_name) { + *export = g_strdup(qdict_get_try_str(options, "export")); + if (*export) { qdict_del(options, "export"); } @@ -253,10 +253,11 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVNBDState *s = bs->opaque; + char *export = NULL; int result, sock; /* Pop the config into our state object. Exit if invalid. */ - result = nbd_config(s, options); + result = nbd_config(s, options, &export); if (result != 0) { return result; } @@ -270,7 +271,9 @@ static int nbd_open(BlockDriverState *bs, QDict *options, int flags, } /* NBD handshake */ - return nbd_client_session_init(&s->client, bs, sock); + result = nbd_client_session_init(&s->client, bs, sock, export); + g_free(export); + return result; } static int nbd_co_readv(BlockDriverState *bs, int64_t sector_num,