qemu-nbd: Use blk_new_open() in main()

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-id: 1423162705-32065-11-git-send-email-mreitz@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Max Reitz 2015-02-05 13:58:19 -05:00 committed by Stefan Hajnoczi
parent f1d3cd792b
commit 4fbec260ae
1 changed files with 9 additions and 16 deletions

View File

@ -391,7 +391,6 @@ int main(int argc, char **argv)
{ {
BlockBackend *blk; BlockBackend *blk;
BlockDriverState *bs; BlockDriverState *bs;
BlockDriver *drv;
off_t dev_offset = 0; off_t dev_offset = 0;
uint32_t nbdflags = 0; uint32_t nbdflags = 0;
bool disconnect = false; bool disconnect = false;
@ -434,7 +433,7 @@ int main(int argc, char **argv)
char *end; char *end;
int flags = BDRV_O_RDWR; int flags = BDRV_O_RDWR;
int partition = -1; int partition = -1;
int ret; int ret = 0;
int fd; int fd;
bool seen_cache = false; bool seen_cache = false;
bool seen_discard = false; bool seen_discard = false;
@ -445,6 +444,7 @@ int main(int argc, char **argv)
const char *fmt = NULL; const char *fmt = NULL;
Error *local_err = NULL; Error *local_err = NULL;
BlockdevDetectZeroesOptions detect_zeroes = BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF; BlockdevDetectZeroesOptions detect_zeroes = BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF;
QDict *options = NULL;
/* The client thread uses SIGTERM to interrupt the server. A signal /* The client thread uses SIGTERM to interrupt the server. A signal
* handler ensures that "qemu-nbd -v -c" exits with a nice status code. * 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); atexit(bdrv_close_all);
if (fmt) { if (fmt) {
drv = bdrv_find_format(fmt); options = qdict_new();
if (!drv) { qdict_put(options, "driver", qstring_from_str(fmt));
errx(EXIT_FAILURE, "Unknown file format '%s'", fmt);
}
} else {
drv = NULL;
} }
blk = blk_new_with_bs("hda", &error_abort);
bs = blk_bs(blk);
srcpath = argv[optind]; srcpath = argv[optind];
ret = bdrv_open(&bs, srcpath, NULL, NULL, flags, drv, &local_err); blk = blk_new_open("hda", srcpath, NULL, options, flags, &local_err);
if (ret < 0) { if (!blk) {
errno = -ret; errx(EXIT_FAILURE, "Failed to blk_new_open '%s': %s", argv[optind],
err(EXIT_FAILURE, "Failed to bdrv_open '%s': %s", argv[optind], error_get_pretty(local_err));
error_get_pretty(local_err));
} }
bs = blk_bs(blk);
if (sn_opts) { if (sn_opts) {
ret = bdrv_snapshot_load_tmp(bs, ret = bdrv_snapshot_load_tmp(bs,