From patchwork Wed Dec 10 10:33:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 419545 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4567814009B for ; Wed, 10 Dec 2014 21:49:39 +1100 (AEDT) Received: from localhost ([::1]:44581 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xyept-0007wi-EH for incoming@patchwork.ozlabs.org; Wed, 10 Dec 2014 05:49:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58971) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xyec1-0000IJ-J0 for qemu-devel@nongnu.org; Wed, 10 Dec 2014 05:35:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xyebs-00081R-TB for qemu-devel@nongnu.org; Wed, 10 Dec 2014 05:35:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34536) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xyebs-00080y-LK for qemu-devel@nongnu.org; Wed, 10 Dec 2014 05:35:08 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBAAZ8xM005143 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 10 Dec 2014 05:35:08 -0500 Received: from noname.str.redhat.com (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id sBAAYeS8016328; Wed, 10 Dec 2014 05:35:07 -0500 From: Kevin Wolf To: qemu-devel@nongnu.org Date: Wed, 10 Dec 2014 11:33:53 +0100 Message-Id: <1418207679-32260-28-git-send-email-kwolf@redhat.com> In-Reply-To: <1418207679-32260-1-git-send-email-kwolf@redhat.com> References: <1418207679-32260-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com Subject: [Qemu-devel] [PULL 27/73] qemu-nbd: Use BlockBackend where reasonable 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: Max Reitz Because qemu-nbd creates the BlockBackend by itself, it should create the according BlockDriverState tree by itself as well; that means, it has call bdrv_open() on its own. This is one of the places where qemu-nbd still needs to use a BlockDriverState directly (the root BDS below the BB); other places are the configuration of zero detection (which may be lifted into the BB eventually, but is not yet) and temporarily loading a snapshot. Everywhere else, though, qemu-nbd can and thus should use BlockBackend. Suggested-by: Paolo Bonzini Signed-off-by: Max Reitz Reviewed-by: Paolo Bonzini Message-id: 1416309679-333-7-git-send-email-mreitz@redhat.com Signed-off-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- qemu-nbd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 60ce50f..d222512 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -146,7 +146,7 @@ static void read_partition(uint8_t *p, struct partition_record *r) r->nb_sectors_abs = p[12] | p[13] << 8 | p[14] << 16 | p[15] << 24; } -static int find_partition(BlockDriverState *bs, int partition, +static int find_partition(BlockBackend *blk, int partition, off_t *offset, off_t *size) { struct partition_record mbr[4]; @@ -155,7 +155,7 @@ static int find_partition(BlockDriverState *bs, int partition, int ext_partnum = 4; int ret; - if ((ret = bdrv_read(bs, 0, data, 1)) < 0) { + if ((ret = blk_read(blk, 0, data, 1)) < 0) { errno = -ret; err(EXIT_FAILURE, "error while reading"); } @@ -175,7 +175,7 @@ static int find_partition(BlockDriverState *bs, int partition, uint8_t data1[512]; int j; - if ((ret = bdrv_read(bs, mbr[i].start_sector_abs, data1, 1)) < 0) { + if ((ret = blk_read(blk, mbr[i].start_sector_abs, data1, 1)) < 0) { errno = -ret; err(EXIT_FAILURE, "error while reading"); } @@ -720,10 +720,10 @@ int main(int argc, char **argv) } bs->detect_zeroes = detect_zeroes; - fd_size = bdrv_getlength(bs); + fd_size = blk_getlength(blk); if (partition != -1) { - ret = find_partition(bs, partition, &dev_offset, &fd_size); + ret = find_partition(blk, partition, &dev_offset, &fd_size); if (ret < 0) { errno = -ret; err(EXIT_FAILURE, "Could not find partition %d", partition);