From patchwork Mon Nov 12 14:22:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 198396 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 D54E52C0089 for ; Tue, 13 Nov 2012 01:23:13 +1100 (EST) Received: from localhost ([::1]:33826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TXuus-0005cV-4J for incoming@patchwork.ozlabs.org; Mon, 12 Nov 2012 09:23:10 -0500 Received: from eggs.gnu.org ([208.118.235.92]:51122) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TXuuG-0004F4-21 for qemu-devel@nongnu.org; Mon, 12 Nov 2012 09:22:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TXuuC-0003ni-Vi for qemu-devel@nongnu.org; Mon, 12 Nov 2012 09:22:31 -0500 Received: from mail-pb0-f45.google.com ([209.85.160.45]:34045) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TXuuC-0003mp-P3 for qemu-devel@nongnu.org; Mon, 12 Nov 2012 09:22:28 -0500 Received: by mail-pb0-f45.google.com with SMTP id mc8so1688260pbc.4 for ; Mon, 12 Nov 2012 06:22:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=MBQPylXGve++Wg0rdQf8ZuM2FBmMLfidDKI3AbF7mkk=; b=geCpmXud1TNRE1nQliDsQ+NzFNdTvEGtZJ7fX8UAk9WpFlpHL9383qt6h1hHyW1HUh JA9NAP3uTwU3RWVnpea69Qq5zMpJEotkUgr+wQQvUjwwXy/PYfVl60fiE7Cpr1jIaRAb k7klyiLnqRLa49AdLOIFDLjB15R656N82QtMlPyMn/aFSLLbeC7zkSBc6qu3CfD0EJJ3 J967GzMp6W9Ob+oD7BLlt3yI6Bfe5EiPD8sKDsKT7fqMzQyoyjpXZaKt9WHRf08RQKfp gXh6+6tNCv2XLJ4CVcrd40q1dtuvRPeNA71W5PnAlidR0A1UhQghajMacMYq13u6KnTA CIbw== Received: by 10.68.202.72 with SMTP id kg8mr14980312pbc.134.1352730148466; Mon, 12 Nov 2012 06:22:28 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-169-1.ip50.fastwebnet.it. [93.34.169.1]) by mx.google.com with ESMTPS id vo8sm4271417pbc.16.2012.11.12.06.22.25 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 12 Nov 2012 06:22:27 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 12 Nov 2012 15:22:02 +0100 Message-Id: <1352730127-32685-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.12.1 In-Reply-To: <1352730127-32685-1-git-send-email-pbonzini@redhat.com> References: <1352730127-32685-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.160.45 Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 2/7] nbd: accept relative path to Unix socket 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 Adding the "is_unix" member now will simplify the parsing of NBD URIs. Signed-off-by: Paolo Bonzini --- block/nbd.c | 17 +++++++---------- 1 file modificato, 7 inserzioni(+), 10 rimozioni(-) diff --git a/block/nbd.c b/block/nbd.c index 2bce47b..48bbeca 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -55,7 +55,6 @@ typedef struct BDRVNBDState { uint32_t nbdflags; off_t size; size_t blocksize; - char *export_name; /* An NBD server may export several devices */ CoMutex send_mutex; CoMutex free_sema; @@ -65,13 +64,12 @@ typedef struct BDRVNBDState { Coroutine *recv_coroutine[MAX_NBD_REQUESTS]; struct nbd_reply reply; - /* If it begins with '/', this is a UNIX domain socket. Otherwise, - * it's a string of the form :port - */ + int is_unix; char *host_spec; + char *export_name; /* An NBD server may export several devices */ } BDRVNBDState; -static int nbd_config(BDRVNBDState *s, const char *filename, int flags) +static int nbd_config(BDRVNBDState *s, const char *filename) { char *file; char *export_name; @@ -98,11 +96,10 @@ static int nbd_config(BDRVNBDState *s, const char *filename, int flags) /* are we a UNIX or TCP socket? */ if (strstart(host_spec, "unix:", &unixpath)) { - if (unixpath[0] != '/') { /* We demand an absolute path*/ - goto out; - } + s->is_unix = true; s->host_spec = g_strdup(unixpath); } else { + s->is_unix = false; s->host_spec = g_strdup(host_spec); } @@ -262,7 +259,7 @@ static int nbd_establish_connection(BlockDriverState *bs) off_t size; size_t blocksize; - if (s->host_spec[0] == '/') { + if (s->is_unix) { sock = unix_socket_outgoing(s->host_spec); } else { sock = tcp_socket_outgoing_spec(s->host_spec); @@ -320,7 +317,7 @@ static int nbd_open(BlockDriverState *bs, const char* filename, int flags) qemu_co_mutex_init(&s->free_sema); /* Pop the config into our state object. Exit if invalid. */ - result = nbd_config(s, filename, flags); + result = nbd_config(s, filename); if (result != 0) { return result; }