Revision 39a5235c qemu-nbd.c

b/qemu-nbd.c
33 33
#include <libgen.h>
34 34
#include <pthread.h>
35 35

  
36
#define SOCKET_PATH    "/var/lock/qemu-nbd-%s"
36
#define SOCKET_PATH         "/var/lock/qemu-nbd-%s"
37
#define QEMU_NBD_OPT_CACHE  1
38
#define QEMU_NBD_OPT_AIO    2
37 39

  
38 40
static NBDExport *exp;
39 41
static int verbose;
......
77 79
"  -r, --read-only      export read-only\n"
78 80
"  -s, --snapshot       use snapshot file\n"
79 81
"  -n, --nocache        disable host cache\n"
82
"      --cache=MODE     set cache mode (none, writeback, ...)\n"
83
#ifdef CONFIG_LINUX_AIO
84
"      --aio=MODE       set AIO mode (native or threads)\n"
85
#endif
80 86
"\n"
81 87
"Report bugs to <qemu-devel@nongnu.org>\n"
82 88
    , name, NBD_DEFAULT_PORT, "DEVICE");
......
306 312
        { "disconnect", 0, NULL, 'd' },
307 313
        { "snapshot", 0, NULL, 's' },
308 314
        { "nocache", 0, NULL, 'n' },
315
        { "cache", 1, NULL, QEMU_NBD_OPT_CACHE },
316
#ifdef CONFIG_LINUX_AIO
317
        { "aio", 1, NULL, QEMU_NBD_OPT_AIO },
318
#endif
309 319
        { "shared", 1, NULL, 'e' },
310 320
        { "persistent", 0, NULL, 't' },
311 321
        { "verbose", 0, NULL, 'v' },
......
320 330
    int ret;
321 331
    int fd;
322 332
    int persistent = 0;
333
    bool seen_cache = false;
334
#ifdef CONFIG_LINUX_AIO
335
    bool seen_aio = false;
336
#endif
323 337
    pthread_t client_thread;
324 338

  
325 339
    /* The client thread uses SIGTERM to interrupt the server.  A signal
......
336 350
            flags |= BDRV_O_SNAPSHOT;
337 351
            break;
338 352
        case 'n':
339
            flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB;
353
            optarg = (char *) "none";
354
            /* fallthrough */
355
        case QEMU_NBD_OPT_CACHE:
356
            if (seen_cache) {
357
                errx(EXIT_FAILURE, "-n and --cache can only be specified once");
358
            }
359
            seen_cache = true;
360
            if (bdrv_parse_cache_flags(optarg, &flags) == -1) {
361
                errx(EXIT_FAILURE, "Invalid cache mode `%s'", optarg);
362
            }
340 363
            break;
364
#ifdef CONFIG_LINUX_AIO
365
        case QEMU_NBD_OPT_AIO:
366
            if (seen_aio) {
367
                errx(EXIT_FAILURE, "--aio can only be specified once");
368
            }
369
            seen_aio = true;
370
            if (!strcmp(optarg, "native")) {
371
                flags |= BDRV_O_NATIVE_AIO;
372
            } else if (!strcmp(optarg, "threads")) {
373
                /* this is the default */
374
            } else {
375
               errx(EXIT_FAILURE, "invalid aio mode `%s'", optarg);
376
            }
377
            break;
378
#endif
341 379
        case 'b':
342 380
            bindto = optarg;
343 381
            break;

Also available in: Unified diff