Revision e6b63677

b/qemu-nbd.c
306 306
int main(int argc, char **argv)
307 307
{
308 308
    BlockDriverState *bs;
309
    BlockDriver *drv;
309 310
    off_t dev_offset = 0;
310 311
    uint32_t nbdflags = 0;
311 312
    bool disconnect = false;
......
313 314
    char *device = NULL;
314 315
    int port = NBD_DEFAULT_PORT;
315 316
    off_t fd_size;
316
    const char *sopt = "hVb:o:p:rsnP:c:dvk:e:t";
317
    const char *sopt = "hVb:o:p:rsnP:c:dvk:e:f:t";
317 318
    struct option lopt[] = {
318 319
        { "help", 0, NULL, 'h' },
319 320
        { "version", 0, NULL, 'V' },
......
333 334
#endif
334 335
        { "discard", 1, NULL, QEMU_NBD_OPT_DISCARD },
335 336
        { "shared", 1, NULL, 'e' },
337
        { "format", 1, NULL, 'f' },
336 338
        { "persistent", 0, NULL, 't' },
337 339
        { "verbose", 0, NULL, 'v' },
338 340
        { NULL, 0, NULL, 0 }
......
351 353
    bool seen_aio = false;
352 354
#endif
353 355
    pthread_t client_thread;
356
    const char *fmt = NULL;
354 357

  
355 358
    /* The client thread uses SIGTERM to interrupt the server.  A signal
356 359
     * handler ensures that "qemu-nbd -v -c" exits with a nice status code.
......
454 457
                errx(EXIT_FAILURE, "Shared device number must be greater than 0\n");
455 458
            }
456 459
            break;
460
        case 'f':
461
            fmt = optarg;
462
            break;
457 463
	case 't':
458 464
	    persistent = 1;
459 465
	    break;
......
555 561
    bdrv_init();
556 562
    atexit(bdrv_close_all);
557 563

  
564
    if (fmt) {
565
        drv = bdrv_find_format(fmt);
566
        if (!drv) {
567
            errx(EXIT_FAILURE, "Unknown file format '%s'", fmt);
568
        }
569
    } else {
570
        drv = NULL;
571
    }
572

  
558 573
    bs = bdrv_new("hda");
559 574
    srcpath = argv[optind];
560
    if ((ret = bdrv_open(bs, srcpath, NULL, flags, NULL)) < 0) {
575
    ret = bdrv_open(bs, srcpath, NULL, flags, drv);
576
    if (ret < 0) {
561 577
        errno = -ret;
562 578
        err(EXIT_FAILURE, "Failed to bdrv_open '%s'", argv[optind]);
563 579
    }
b/qemu-nbd.texi
45 45
  disconnect the specified device
46 46
@item -e, --shared=@var{num}
47 47
  device can be shared by @var{num} clients (default @samp{1})
48
@item -f, --format=@var{fmt}
49
  force block driver for format @var{fmt} instead of auto-detecting
48 50
@item -t, --persistent
49 51
  don't exit on the last connection
50 52
@item -v, --verbose

Also available in: Unified diff