From nobody Mon Oct 27 14:05:23 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1761309113; cv=none; d=zohomail.com; s=zohoarc; b=WK5myayXN2cBQKRiWlULqFf6JUYZbctAunh3+V0imSUZbSnzTekL7bksiIoFM6ysceTnogXsesh0dIMU1Ot3hauXEcuNy/5pr7mKUxxlC2y3UUZSZxfUHkcjN5emmocKfy/HhLG75JVVhCWMLma6UrUFPYd0Aipkdz6hmfz+FnI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761309113; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=9B7wu+SfNVhC5TFZoBPOUdxmzu1rq3LIlO+WXANdseE=; b=HeazMiaM/QD73sSEFBG7A3RS/9Gd9mlvr39IqZHLbeSq71M5LpaxaSOFBWoOfLopwtSDtxv3ltWAVB7aSKXMUzUyDJpD1dd6Xih8HD5nYpySoJu6M0Ia1/eUXkI80/gcMmYuqktq50A4Jik63jFMx8ZYbc2a52Ioj5hS1Jz1RR4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1761309113528231.11825654343477; Fri, 24 Oct 2025 05:31:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vCGwq-00063c-Gf; Fri, 24 Oct 2025 08:31:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vCGwn-00061o-B0 for qemu-devel@nongnu.org; Fri, 24 Oct 2025 08:31:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vCGwk-00068i-Pr for qemu-devel@nongnu.org; Fri, 24 Oct 2025 08:31:08 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-507-_BHOcyI6Nli5qCUX2RnpdA-1; Fri, 24 Oct 2025 08:31:04 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8C0E81955F2E; Fri, 24 Oct 2025 12:31:03 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.45.225.249]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 80DDD19540EB; Fri, 24 Oct 2025 12:31:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761309065; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9B7wu+SfNVhC5TFZoBPOUdxmzu1rq3LIlO+WXANdseE=; b=dU2E9hE4RLLHKRf9C7mPH+DU8N0ctLVSsaGrnfqPYmi02RqDL+huN4TpKd9hFIRIOxl07M vtRk1M3CvsLbzY1S6Owznp3VtdaX1ni/kkw4s9MHOzgfLiv7WcZbmXZ86VvBTMTJa++Sde 5aFthvvQ9i1+Qe5FpsGiiKfuNF+bdIY= X-MC-Unique: _BHOcyI6Nli5qCUX2RnpdA-1 X-Mimecast-MFC-AGG-ID: _BHOcyI6Nli5qCUX2RnpdA_1761309063 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, eblake@redhat.com, armbru@redhat.com, qemu-devel@nongnu.org, hreitz@redhat.com Subject: [PATCH v2 4/4] qemu-img info: Add cache mode option Date: Fri, 24 Oct 2025 14:30:41 +0200 Message-ID: <20251024123041.51254-6-kwolf@redhat.com> In-Reply-To: <20251024123041.51254-1-kwolf@redhat.com> References: <20251024123041.51254-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1761309120893158500 Content-Type: text/plain; charset="utf-8" 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 --- 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: =20 The size syntax is similar to :manpage:`dd(1)`'s size syntax. =20 -.. option:: info [--object OBJECTDEF] [--image-opts] [-f FMT] [--output=3D= OFMT] [--backing-chain] [--limits] [-U] FILENAME +.. option:: info [--object OBJECTDEF] [--image-opts] [-f FMT] [--output=3D= OFMT] [--backing-chain] [--limits] [-t CACHE] [-U] FILENAME =20 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, gcons= tpointer 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(b= ool image_opts, BlockGraphInfoList **tail =3D &head; GHashTable *filenames; Error *err =3D NULL; + int cache_flags =3D 0; + bool writethrough =3D false; + int ret; + + ret =3D bdrv_parse_cache_mode(cache, &cache_flags, &writethrough); + if (ret < 0) { + error_report("Invalid cache option: %s", cache); + return NULL; + } =20 filenames =3D g_hash_table_new_full(g_str_hash, str_equal_func, NULL, = NULL); =20 @@ -3026,8 +3036,8 @@ static BlockGraphInfoList *collect_image_info_list(bo= ol image_opts, g_hash_table_insert(filenames, (gpointer)filename, NULL); =20 blk =3D 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 =3D OFORMAT_HUMAN; bool chain =3D false; const char *filename, *fmt; + const char *cache =3D BDRV_DEFAULT_CACHE; BlockGraphInfoList *list; bool image_opts =3D false; bool force_share =3D 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 =3D getopt_long(argc, argv, "hf:U", long_options, NULL); + c =3D getopt_long(argc, argv, "hf:t:U", long_options, NULL); if (c =3D=3D -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 overla= ys\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 =3D true; break; + case 't': + cache =3D optarg; + break; case 'U': force_share =3D true; break; @@ -3164,7 +3181,7 @@ static int img_info(const img_cmd_t *ccmd, int argc, = char **argv) } filename =3D argv[optind++]; =20 - list =3D collect_image_info_list(image_opts, filename, fmt, chain, + list =3D collect_image_info_list(image_opts, filename, fmt, cache, cha= in, 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 =20 DEF("info", img_info, - "info [--object objectdef] [--image-opts] [-f fmt] [--output=3Dofmt] [= --backing-chain] [--limits] [-U] filename") + "info [--object objectdef] [--image-opts] [-f fmt] [--output=3Dofmt] [= --backing-chain] [--limits] [-t CACHE] [-U] filename") SRST -.. option:: info [--object OBJECTDEF] [--image-opts] [-f FMT] [--output=3D= OFMT] [--backing-chain] [--limits] [-U] FILENAME +.. option:: info [--object OBJECTDEF] [--image-opts] [-f FMT] [--output=3D= OFMT] [--backing-chain] [--limits] [-t CACHE] [-U] FILENAME ERST =20 DEF("map", img_map, --=20 2.51.0