From patchwork Mon Oct 22 11:09:17 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Thomas X-Patchwork-Id: 193230 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6AAFA2C00F3 for ; Tue, 23 Oct 2012 03:51:26 +1100 (EST) Received: from localhost ([::1]:36654 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQJzl-0006xq-I9 for incoming@patchwork.ozlabs.org; Mon, 22 Oct 2012 11:32:49 -0400 Received: from eggs.gnu.org ([208.118.235.92]:41457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQG0H-0006tW-F7 for qemu-devel@nongnu.org; Mon, 22 Oct 2012 07:17:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TQG0B-0004sF-Ao for qemu-devel@nongnu.org; Mon, 22 Oct 2012 07:17:05 -0400 Received: from bacon.sh.bytemark.co.uk ([212.110.161.169]:35623) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TQG0B-0004qx-4d for qemu-devel@nongnu.org; Mon, 22 Oct 2012 07:16:59 -0400 Received: from bytemail.bytemark.co.uk ([212.110.161.227]) by bacon.sh.bytemark.co.uk with esmtp (Exim 4.72) (envelope-from ) id 1TQG00-0007EX-Qo; Mon, 22 Oct 2012 12:16:48 +0100 Received: from eboracum.office.bytemark.co.uk ([89.16.168.152] helo=eboracum.bytemark.co.uk) by bytemail.bytemark.co.uk with esmtp (Exim 4.72) (envelope-from ) id 1TQG00-0004L2-Az; Mon, 22 Oct 2012 12:16:48 +0100 From: nick@bytemark.co.uk To: qemu-devel@nongnu.org Date: Mon, 22 Oct 2012 12:09:17 +0100 Message-Id: X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: In-Reply-To: References: To: qemu-devel@nongnu.org MIME-Version: 1.0 Organization: Bytemark Computer Consulting Ltd. The Raylor Centre, James Street, York YO10 3DW, UK. Company registered in England and Wales no. 4484629. VAT registration no. GB 135 6159 13. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 212.110.161.169 X-Mailman-Approved-At: Mon, 22 Oct 2012 11:31:25 -0400 Cc: pbonzini@redhat.com, Nick Thomas Subject: [Qemu-devel] [PATCH 1/3] nbd: Only try to send flush/discard commands if connected to the NBD server 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 This is unlikely to come up now, but is a necessary prerequisite for reconnection behaviour. Signed-off-by: Nick Thomas --- block/nbd.c | 13 +++++++++++-- 1 files changed, 11 insertions(+), 2 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index 2bce47b..9536408 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -71,6 +71,11 @@ typedef struct BDRVNBDState { char *host_spec; } BDRVNBDState; +static bool nbd_is_connected(BDRVNBDState *s) +{ + return s->sock >= 0; +} + static int nbd_config(BDRVNBDState *s, const char *filename, int flags) { char *file; @@ -309,6 +314,7 @@ static void nbd_teardown_connection(BlockDriverState *bs) qemu_aio_set_fd_handler(s->sock, NULL, NULL, NULL, NULL); closesocket(s->sock); + s->sock = -1; } static int nbd_open(BlockDriverState *bs, const char* filename, int flags) @@ -316,6 +322,8 @@ static int nbd_open(BlockDriverState *bs, const char* filename, int flags) BDRVNBDState *s = bs->opaque; int result; + s->sock = -1; + qemu_co_mutex_init(&s->send_mutex); qemu_co_mutex_init(&s->free_sema); @@ -431,7 +439,7 @@ static int nbd_co_flush(BlockDriverState *bs) struct nbd_reply reply; ssize_t ret; - if (!(s->nbdflags & NBD_FLAG_SEND_FLUSH)) { + if (!nbd_is_connected(s) || !(s->nbdflags & NBD_FLAG_SEND_FLUSH)) { return 0; } @@ -462,7 +470,7 @@ static int nbd_co_discard(BlockDriverState *bs, int64_t sector_num, struct nbd_reply reply; ssize_t ret; - if (!(s->nbdflags & NBD_FLAG_SEND_TRIM)) { + if (!nbd_is_connected(s) || !(s->nbdflags & NBD_FLAG_SEND_TRIM)) { return 0; } request.type = NBD_CMD_TRIM; @@ -515,3 +523,4 @@ static void bdrv_nbd_init(void) } block_init(bdrv_nbd_init); +