qemu-io-cmds.c (3cb99f4124faeca3235bd76ba2879ad091b43a50) qemu-io-cmds.c (dc900c35239bc865df2dff5880eabcd25b974f19)
1/*
2 * Command line utility to exercise the QEMU I/O path.
3 *
4 * Copyright (C) 2009-2016 Red Hat, Inc.
5 * Copyright (c) 2003-2005 Silicon Graphics, Inc.
6 *
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
9 */
10
11#include "qemu/osdep.h"
12#include "qapi/error.h"
1/*
2 * Command line utility to exercise the QEMU I/O path.
3 *
4 * Copyright (C) 2009-2016 Red Hat, Inc.
5 * Copyright (c) 2003-2005 Silicon Graphics, Inc.
6 *
7 * This work is licensed under the terms of the GNU GPL, version 2 or later.
8 * See the COPYING file in the top-level directory.
9 */
10
11#include "qemu/osdep.h"
12#include "qapi/error.h"
13#include "qapi/qmp/qdict.h"
13#include "qemu-io.h"
14#include "sysemu/block-backend.h"
15#include "block/block.h"
16#include "block/block_int.h" /* for info_f() */
17#include "block/qapi.h"
18#include "qemu/error-report.h"
19#include "qemu/main-loop.h"
20#include "qemu/option.h"

--- 1952 unchanged lines hidden (view full) ---

1973{
1974 BlockDriverState *bs = blk_bs(blk);
1975 QemuOpts *qopts;
1976 QDict *opts;
1977 int c;
1978 int flags = bs->open_flags;
1979 bool writethrough = !blk_enable_write_cache(blk);
1980 bool has_rw_option = false;
14#include "qemu-io.h"
15#include "sysemu/block-backend.h"
16#include "block/block.h"
17#include "block/block_int.h" /* for info_f() */
18#include "block/qapi.h"
19#include "qemu/error-report.h"
20#include "qemu/main-loop.h"
21#include "qemu/option.h"

--- 1952 unchanged lines hidden (view full) ---

1974{
1975 BlockDriverState *bs = blk_bs(blk);
1976 QemuOpts *qopts;
1977 QDict *opts;
1978 int c;
1979 int flags = bs->open_flags;
1980 bool writethrough = !blk_enable_write_cache(blk);
1981 bool has_rw_option = false;
1982 bool has_cache_option = false;
1981
1982 BlockReopenQueue *brq;
1983 Error *local_err = NULL;
1984
1985 while ((c = getopt(argc, argv, "c:o:rw")) != -1) {
1986 switch (c) {
1987 case 'c':
1988 if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) {
1989 error_report("Invalid cache option: %s", optarg);
1990 return -EINVAL;
1991 }
1983
1984 BlockReopenQueue *brq;
1985 Error *local_err = NULL;
1986
1987 while ((c = getopt(argc, argv, "c:o:rw")) != -1) {
1988 switch (c) {
1989 case 'c':
1990 if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) {
1991 error_report("Invalid cache option: %s", optarg);
1992 return -EINVAL;
1993 }
1994 has_cache_option = true;
1992 break;
1993 case 'o':
1994 if (!qemu_opts_parse_noisily(&reopen_opts, optarg, 0)) {
1995 qemu_opts_reset(&reopen_opts);
1996 return -EINVAL;
1997 }
1998 break;
1999 case 'r':

--- 41 unchanged lines hidden (view full) ---

2041 blk_get_perm(blk, &orig_perm, &orig_shared_perm);
2042 blk_set_perm(blk,
2043 orig_perm & ~(BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED),
2044 orig_shared_perm,
2045 &error_abort);
2046 }
2047
2048 qopts = qemu_opts_find(&reopen_opts, NULL);
1995 break;
1996 case 'o':
1997 if (!qemu_opts_parse_noisily(&reopen_opts, optarg, 0)) {
1998 qemu_opts_reset(&reopen_opts);
1999 return -EINVAL;
2000 }
2001 break;
2002 case 'r':

--- 41 unchanged lines hidden (view full) ---

2044 blk_get_perm(blk, &orig_perm, &orig_shared_perm);
2045 blk_set_perm(blk,
2046 orig_perm & ~(BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED),
2047 orig_shared_perm,
2048 &error_abort);
2049 }
2050
2051 qopts = qemu_opts_find(&reopen_opts, NULL);
2049 opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : NULL;
2052 opts = qopts ? qemu_opts_to_qdict(qopts, NULL) : qdict_new();
2050 qemu_opts_reset(&reopen_opts);
2051
2053 qemu_opts_reset(&reopen_opts);
2054
2055 if (qdict_haskey(opts, BDRV_OPT_READ_ONLY)) {
2056 if (has_rw_option) {
2057 error_report("Cannot set both -r/-w and '" BDRV_OPT_READ_ONLY "'");
2058 qobject_unref(opts);
2059 return -EINVAL;
2060 }
2061 } else {
2062 qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !(flags & BDRV_O_RDWR));
2063 }
2064
2065 if (qdict_haskey(opts, BDRV_OPT_CACHE_DIRECT) ||
2066 qdict_haskey(opts, BDRV_OPT_CACHE_NO_FLUSH)) {
2067 if (has_cache_option) {
2068 error_report("Cannot set both -c and the cache options");
2069 qobject_unref(opts);
2070 return -EINVAL;
2071 }
2072 } else {
2073 qdict_put_bool(opts, BDRV_OPT_CACHE_DIRECT, flags & BDRV_O_NOCACHE);
2074 qdict_put_bool(opts, BDRV_OPT_CACHE_NO_FLUSH, flags & BDRV_O_NO_FLUSH);
2075 }
2076
2052 bdrv_subtree_drained_begin(bs);
2053 brq = bdrv_reopen_queue(NULL, bs, opts, flags);
2054 bdrv_reopen_multiple(bdrv_get_aio_context(bs), brq, &local_err);
2055 bdrv_subtree_drained_end(bs);
2056
2057 if (local_err) {
2058 error_report_err(local_err);
2059 return -EINVAL;

--- 312 unchanged lines hidden ---
2077 bdrv_subtree_drained_begin(bs);
2078 brq = bdrv_reopen_queue(NULL, bs, opts, flags);
2079 bdrv_reopen_multiple(bdrv_get_aio_context(bs), brq, &local_err);
2080 bdrv_subtree_drained_end(bs);
2081
2082 if (local_err) {
2083 error_report_err(local_err);
2084 return -EINVAL;

--- 312 unchanged lines hidden ---