Received: from eggs.gnu.org ([140.186.70.92]:40383) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQjD2-00048W-E2 for qemu-devel@nongnu.org; Wed, 16 Nov 2011 12:23:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RQjD1-00044O-8X for qemu-devel@nongnu.org; Wed, 16 Nov 2011 12:23:40 -0500 Received: from smtp.ctxuk.citrix.com ([62.200.22.115]:28458 helo=SMTP.EU.CITRIX.COM) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RQjD1-00044H-44 for qemu-devel@nongnu.org; Wed, 16 Nov 2011 12:23:39 -0500 From: Ian Campbell Date: Wed, 16 Nov 2011 17:23:35 +0000 In-Reply-To: References: <1321426669-7337-1-git-send-email-cyliu@suse.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Message-ID: <1321464215.3664.218.camel@zakaz.uk.xensource.com> MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] Add -f option to qemu-nbd List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Hajnoczi Cc: Chunyan Liu , qemu-devel@nongnu.org On Wed, 2011-11-16 at 10:34 +0000, Stefan Hajnoczi wrote: > On Wed, Nov 16, 2011 at 6:57 AM, Chunyan Liu wrote: > > Currently qemu-nbd does not support finding free nbd device for users like > > "losetup -f" and issuing "qemu-nbd -c /dev/nbdX disk.img" won't report error > > message when /dev/nbd is already in use. It makes things a little confusing. > > This patch adds "-f" option to qemu-nbd to support finding a free nbd device > > for users. Please review and share your comments. Thanks. > > > > Signed-off-by: Chunyan Liu > > --- > > qemu-nbd.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- > > 1 files changed, 64 insertions(+), 1 deletions(-) > > This patch finds a free device but does not immediately attach to it > and use it. Interfaces like this are prone to race conditions, I > think it would make more sense to combine the -f option with running > the actual NBD server. > > I suggest: > qemu-nbd -f disk.img > > That way it is safe to execute multiple qemu-nbd -f at the same time > without race conditions. I agree, but you'd also need some locking inside qemu-nbd wouldn't you? Or have it just keep trying devices until one works perhaps. > Plus it probably makes the user's life > easier than having to say qemu-nbd -c $(qemu-nbd -f) disk.img. Absolutely. Ian.