From patchwork Fri Feb 13 16:24:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 439594 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 BA86B1402C2 for ; Sat, 14 Feb 2015 04:04:55 +1100 (AEDT) Received: from localhost ([::1]:56549 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMJfh-0000kI-BO for incoming@patchwork.ozlabs.org; Fri, 13 Feb 2015 12:04:53 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48607) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMJDR-0003QL-Cn for qemu-devel@nongnu.org; Fri, 13 Feb 2015 11:35:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YMJDL-0003Ly-J3 for qemu-devel@nongnu.org; Fri, 13 Feb 2015 11:35:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:53302) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YMJDL-0003La-BG for qemu-devel@nongnu.org; Fri, 13 Feb 2015 11:35:35 -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 t1DGZXgT007135 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 13 Feb 2015 11:35:33 -0500 Received: from localhost (ovpn-112-21.ams2.redhat.com [10.36.112.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t1DGZWOW005486; Fri, 13 Feb 2015 11:35:32 -0500 From: Stefan Hajnoczi To: Date: Fri, 13 Feb 2015 16:24:55 +0000 Message-Id: <1423844701-21041-60-git-send-email-stefanha@redhat.com> In-Reply-To: <1423844701-21041-1-git-send-email-stefanha@redhat.com> References: <1423844701-21041-1-git-send-email-stefanha@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: Peter Maydell , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PULL 59/65] qemu-nbd: Use blk_new_open() in main() 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 Signed-off-by: Max Reitz Reviewed-by: Kevin Wolf Message-id: 1423162705-32065-11-git-send-email-mreitz@redhat.com Signed-off-by: Stefan Hajnoczi --- qemu-nbd.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 4d8df08..ac1e5d6 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -391,7 +391,6 @@ int main(int argc, char **argv) { BlockBackend *blk; BlockDriverState *bs; - BlockDriver *drv; off_t dev_offset = 0; uint32_t nbdflags = 0; bool disconnect = false; @@ -434,7 +433,7 @@ int main(int argc, char **argv) char *end; int flags = BDRV_O_RDWR; int partition = -1; - int ret; + int ret = 0; int fd; bool seen_cache = false; bool seen_discard = false; @@ -445,6 +444,7 @@ int main(int argc, char **argv) const char *fmt = NULL; Error *local_err = NULL; BlockdevDetectZeroesOptions detect_zeroes = BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF; + QDict *options = NULL; /* The client thread uses SIGTERM to interrupt the server. A signal * handler ensures that "qemu-nbd -v -c" exits with a nice status code. @@ -689,24 +689,17 @@ int main(int argc, char **argv) atexit(bdrv_close_all); if (fmt) { - drv = bdrv_find_format(fmt); - if (!drv) { - errx(EXIT_FAILURE, "Unknown file format '%s'", fmt); - } - } else { - drv = NULL; + options = qdict_new(); + qdict_put(options, "driver", qstring_from_str(fmt)); } - blk = blk_new_with_bs("hda", &error_abort); - bs = blk_bs(blk); - srcpath = argv[optind]; - ret = bdrv_open(&bs, srcpath, NULL, NULL, flags, drv, &local_err); - if (ret < 0) { - errno = -ret; - err(EXIT_FAILURE, "Failed to bdrv_open '%s': %s", argv[optind], - error_get_pretty(local_err)); + blk = blk_new_open("hda", srcpath, NULL, options, flags, &local_err); + if (!blk) { + errx(EXIT_FAILURE, "Failed to blk_new_open '%s': %s", argv[optind], + error_get_pretty(local_err)); } + bs = blk_bs(blk); if (sn_opts) { ret = bdrv_snapshot_load_tmp(bs,