From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [PULL 18/18] qemu-img info: Add cache mode option
Date: Wed, 29 Oct 2025 13:06:34 +0100 [thread overview]
Message-ID: <20251029120634.288467-19-kwolf@redhat.com> (raw)
In-Reply-To: <20251029120634.288467-1-kwolf@redhat.com>
When querying block limits, different cache modes (in particular
O_DIRECT or not) can result in different limits. Add an option to
'qemu-img info' that allows the user to specify a cache mode, so that
they can get the block limits for the cache mode they intend to use with
their VM.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-ID: <20251024123041.51254-5-kwolf@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
docs/tools/qemu-img.rst | 2 +-
qemu-img.c | 25 +++++++++++++++++++++----
qemu-img-cmds.hx | 4 ++--
3 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/docs/tools/qemu-img.rst b/docs/tools/qemu-img.rst
index fdc9ea9cf2..558b0eb84d 100644
--- a/docs/tools/qemu-img.rst
+++ b/docs/tools/qemu-img.rst
@@ -503,7 +503,7 @@ Command description:
The size syntax is similar to :manpage:`dd(1)`'s size syntax.
-.. option:: info [--object OBJECTDEF] [--image-opts] [-f FMT] [--output=OFMT] [--backing-chain] [--limits] [-U] FILENAME
+.. option:: info [--object OBJECTDEF] [--image-opts] [-f FMT] [--output=OFMT] [--backing-chain] [--limits] [-t CACHE] [-U] FILENAME
Give information about the disk image *FILENAME*. Use it in
particular to know the size reserved on disk which can be different
diff --git a/qemu-img.c b/qemu-img.c
index 5cdbeda969..a7791896c1 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -3003,6 +3003,7 @@ static gboolean str_equal_func(gconstpointer a, gconstpointer b)
static BlockGraphInfoList *collect_image_info_list(bool image_opts,
const char *filename,
const char *fmt,
+ const char *cache,
bool chain, bool limits,
bool force_share)
{
@@ -3010,6 +3011,15 @@ static BlockGraphInfoList *collect_image_info_list(bool image_opts,
BlockGraphInfoList **tail = &head;
GHashTable *filenames;
Error *err = NULL;
+ int cache_flags = 0;
+ bool writethrough = false;
+ int ret;
+
+ ret = bdrv_parse_cache_mode(cache, &cache_flags, &writethrough);
+ if (ret < 0) {
+ error_report("Invalid cache option: %s", cache);
+ return NULL;
+ }
filenames = g_hash_table_new_full(g_str_hash, str_equal_func, NULL, NULL);
@@ -3026,8 +3036,8 @@ static BlockGraphInfoList *collect_image_info_list(bool image_opts,
g_hash_table_insert(filenames, (gpointer)filename, NULL);
blk = img_open(image_opts, filename, fmt,
- BDRV_O_NO_BACKING | BDRV_O_NO_IO, false, false,
- force_share);
+ BDRV_O_NO_BACKING | BDRV_O_NO_IO | cache_flags,
+ writethrough, false, force_share);
if (!blk) {
goto err;
}
@@ -3087,6 +3097,7 @@ static int img_info(const img_cmd_t *ccmd, int argc, char **argv)
OutputFormat output_format = OFORMAT_HUMAN;
bool chain = false;
const char *filename, *fmt;
+ const char *cache = BDRV_DEFAULT_CACHE;
BlockGraphInfoList *list;
bool image_opts = false;
bool force_share = false;
@@ -3099,13 +3110,14 @@ static int img_info(const img_cmd_t *ccmd, int argc, char **argv)
{"format", required_argument, 0, 'f'},
{"image-opts", no_argument, 0, OPTION_IMAGE_OPTS},
{"backing-chain", no_argument, 0, OPTION_BACKING_CHAIN},
+ {"cache", required_argument, 0, 't'},
{"force-share", no_argument, 0, 'U'},
{"limits", no_argument, 0, OPTION_LIMITS},
{"output", required_argument, 0, OPTION_OUTPUT},
{"object", required_argument, 0, OPTION_OBJECT},
{0, 0, 0, 0}
};
- c = getopt_long(argc, argv, "hf:U", long_options, NULL);
+ c = getopt_long(argc, argv, "hf:t:U", long_options, NULL);
if (c == -1) {
break;
}
@@ -3121,6 +3133,8 @@ static int img_info(const img_cmd_t *ccmd, int argc, char **argv)
" (incompatible with -f|--format)\n"
" --backing-chain\n"
" display information about the backing chain for copy-on-write overlays\n"
+" -t, --cache CACHE\n"
+" cache mode for FILE (default: " BDRV_DEFAULT_CACHE ")\n"
" -U, --force-share\n"
" open image in shared mode for concurrent access\n"
" --limits\n"
@@ -3143,6 +3157,9 @@ static int img_info(const img_cmd_t *ccmd, int argc, char **argv)
case OPTION_BACKING_CHAIN:
chain = true;
break;
+ case 't':
+ cache = optarg;
+ break;
case 'U':
force_share = true;
break;
@@ -3164,7 +3181,7 @@ static int img_info(const img_cmd_t *ccmd, int argc, char **argv)
}
filename = argv[optind++];
- list = collect_image_info_list(image_opts, filename, fmt, chain,
+ list = collect_image_info_list(image_opts, filename, fmt, cache, chain,
limits, force_share);
if (!list) {
return 1;
diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index 74b66f9d42..6bc8265cfb 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -66,9 +66,9 @@ SRST
ERST
DEF("info", img_info,
- "info [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [--backing-chain] [--limits] [-U] filename")
+ "info [--object objectdef] [--image-opts] [-f fmt] [--output=ofmt] [--backing-chain] [--limits] [-t CACHE] [-U] filename")
SRST
-.. option:: info [--object OBJECTDEF] [--image-opts] [-f FMT] [--output=OFMT] [--backing-chain] [--limits] [-U] FILENAME
+.. option:: info [--object OBJECTDEF] [--image-opts] [-f FMT] [--output=OFMT] [--backing-chain] [--limits] [-t CACHE] [-U] FILENAME
ERST
DEF("map", img_map,
--
2.51.0
next prev parent reply other threads:[~2025-10-29 12:11 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-29 12:06 [PULL 00/18] Block layer patches Kevin Wolf
2025-10-29 12:06 ` [PULL 01/18] tests/qemu-iotests: Mark the 'inactive-node-nbd' as unsupported with -luks Kevin Wolf
2025-10-29 12:06 ` [PULL 02/18] block: remove 'detached-header' option from opts after use Kevin Wolf
2025-10-29 12:06 ` [PULL 03/18] block: fix luks 'amend' when run in coroutine Kevin Wolf
2025-10-31 10:18 ` Michael Tokarev
2025-10-31 11:05 ` Daniel P. Berrangé
2025-10-29 12:06 ` [PULL 04/18] block/monitor: Use hmp_handle_error to report error Kevin Wolf
2025-10-29 12:06 ` [PULL 05/18] block/curl.c: Fix CURLOPT_VERBOSE parameter type Kevin Wolf
2025-10-29 12:06 ` [PULL 06/18] iotests: Adjust nbd expected outputs to match current behavior Kevin Wolf
2025-10-29 12:06 ` [PULL 07/18] iotests: Adjust fuse-allow-other expected output Kevin Wolf
2025-10-29 12:06 ` [PULL 08/18] block: enable stats-intervals for storage devices Kevin Wolf
2025-10-29 12:06 ` [PULL 09/18] MAINTAINERS: Mark VHDX block driver as "Odd Fixes" Kevin Wolf
2025-10-29 12:06 ` [PULL 10/18] include/block/block_int-common: document when resize callback is used Kevin Wolf
2025-10-29 12:06 ` [PULL 11/18] block: make bdrv_co_parent_cb_resize() a proper IO API function Kevin Wolf
2025-10-29 12:06 ` [PULL 12/18] block: implement 'resize' callback for child_of_bds class Kevin Wolf
2025-10-29 12:06 ` [PULL 13/18] iotests: add test for resizing a node below filters Kevin Wolf
2025-10-29 12:06 ` [PULL 14/18] iotests: add test for resizing a 'file' node below a 'raw' node Kevin Wolf
2025-10-29 12:06 ` [PULL 15/18] block: Improve comments in BlockLimits Kevin Wolf
2025-10-29 12:06 ` [PULL 16/18] block: Expose block limits for images in QMP Kevin Wolf
2025-10-29 12:06 ` [PULL 17/18] qemu-img info: Optionally show block limits Kevin Wolf
2025-10-29 12:06 ` Kevin Wolf [this message]
2025-10-31 9:25 ` [PULL 00/18] Block layer patches Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251029120634.288467-19-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).