From patchwork Sat Sep 11 14:04:55 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 64514 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 58F11B70A2 for ; Sun, 12 Sep 2010 00:08:28 +1000 (EST) Received: from localhost ([127.0.0.1]:58284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OuQkj-00041b-DE for incoming@patchwork.ozlabs.org; Sat, 11 Sep 2010 10:08:25 -0400 Received: from [140.186.70.92] (port=36799 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OuQhU-0002Oy-9t for qemu-devel@nongnu.org; Sat, 11 Sep 2010 10:05:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OuQhR-0004yB-PW for qemu-devel@nongnu.org; Sat, 11 Sep 2010 10:05:04 -0400 Received: from e6.ny.us.ibm.com ([32.97.182.146]:55882) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OuQhR-0004xr-NE for qemu-devel@nongnu.org; Sat, 11 Sep 2010 10:05:01 -0400 Received: from d01relay01.pok.ibm.com (d01relay01.pok.ibm.com [9.56.227.233]) by e6.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id o8BE4vsM031635 for ; Sat, 11 Sep 2010 10:04:57 -0400 Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o8BE51Yj335938 for ; Sat, 11 Sep 2010 10:05:01 -0400 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o8BE51Jm017063 for ; Sat, 11 Sep 2010 10:05:01 -0400 Received: from localhost.localdomain (sig-9-65-48-245.mts.ibm.com [9.65.48.245]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o8BE4ulp016945; Sat, 11 Sep 2010 10:05:00 -0400 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Sat, 11 Sep 2010 09:04:55 -0500 Message-Id: <1284213896-12705-3-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1284213896-12705-1-git-send-email-aliguori@us.ibm.com> References: <1284213896-12705-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Kevin Wolf , Anthony Liguori , Stefan Hajnoczi , Juan Quintela Subject: [Qemu-devel] [PATCH 2/3] block-nbd: fix use of protocols in backing files and nbd probing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The use of protocols in backing_files is currently broken because of some checks for adjusting relative pathnames. Additionally, there's a spurious read when using an nbd protocol that can be quite destructive when using copy-on-read. Potentially, this can lead to probing an image file over top of NBD but this is completely wrong as NBD devices are not growable. Signed-off-by: Anthony Liguori --- NB: this is absolutely not ideal. A more elegant suggestion would be appreciated. I don't think NBD cleanly fits the model of a protocol as it stands today. diff --git a/block.c b/block.c index cd2ee31..a32d5dd 100644 --- a/block.c +++ b/block.c @@ -344,6 +344,12 @@ static int find_image_format(const char *filename, BlockDriver **pdrv) return ret; } + if (strcmp(bs->drv->protocol_name, "nbd") == 0) { + drv = bs->drv; + bdrv_delete(bs); + goto out; + } + /* Return the raw BlockDriver * to scsi-generic devices or empty drives */ if (bs->sg || !bdrv_is_inserted(bs)) { bdrv_delete(bs); @@ -373,6 +379,7 @@ static int find_image_format(const char *filename, BlockDriver **pdrv) } } } +out: if (!drv) { ret = -ENOENT; } @@ -603,10 +610,16 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, BlockDriver *back_drv = NULL; bs->backing_hd = bdrv_new(""); - path_combine(backing_filename, sizeof(backing_filename), - filename, bs->backing_file); - if (bs->backing_format[0] != '\0') - back_drv = bdrv_find_format(bs->backing_format); + back_drv = bdrv_find_protocol(bs->backing_file); + if (!back_drv) { + path_combine(backing_filename, sizeof(backing_filename), + filename, bs->backing_file); + if (bs->backing_format[0] != '\0') + back_drv = bdrv_find_format(bs->backing_format); + } else { + pstrcpy(backing_filename, sizeof(backing_filename), + bs->backing_file); + } /* backing files always opened read-only */ back_flags =