ed5979
From 4af86458d6bea2a6e15fd57d4d4bbe88e35f7e72 Mon Sep 17 00:00:00 2001
ed5979
From: Hanna Reitz <hreitz@redhat.com>
ed5979
Date: Mon, 20 Jun 2022 18:26:54 +0200
ed5979
Subject: [PATCH 07/20] block/file: Add file-specific image info
ed5979
ed5979
RH-Author: Hanna Czenczek <hreitz@redhat.com>
ed5979
RH-MergeRequest: 145: Show protocol-level information in qemu-img info
ed5979
RH-Bugzilla: 1860292
ed5979
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
ed5979
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
ed5979
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
ed5979
RH-Commit: [2/12] d8cc351d6c16c41b2000e41dc555f13093a9edce (hreitz/qemu-kvm-c-9-s)
ed5979
ed5979
Add some (optional) information that the file driver can provide for
ed5979
image files, namely the extent size hint.
ed5979
ed5979
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
ed5979
Message-Id: <20220620162704.80987-3-hreitz@redhat.com>
ed5979
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
ed5979
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
ed5979
(cherry picked from commit 7f36a50ab4e7d39369cac67be4ba9d6ee4081dc0)
ed5979
Signed-off-by: Hanna Czenczek <hreitz@redhat.com>
ed5979
---
ed5979
 block/file-posix.c   | 30 ++++++++++++++++++++++++++++++
ed5979
 qapi/block-core.json | 26 ++++++++++++++++++++++++--
ed5979
 2 files changed, 54 insertions(+), 2 deletions(-)
ed5979
ed5979
diff --git a/block/file-posix.c b/block/file-posix.c
ed5979
index b9647c5ffc..df3da79aed 100644
ed5979
--- a/block/file-posix.c
ed5979
+++ b/block/file-posix.c
ed5979
@@ -3095,6 +3095,34 @@ static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
ed5979
     return 0;
ed5979
 }
ed5979
 
ed5979
+static ImageInfoSpecific *raw_get_specific_info(BlockDriverState *bs,
ed5979
+                                                Error **errp)
ed5979
+{
ed5979
+    ImageInfoSpecificFile *file_info = g_new0(ImageInfoSpecificFile, 1);
ed5979
+    ImageInfoSpecific *spec_info = g_new(ImageInfoSpecific, 1);
ed5979
+
ed5979
+    *spec_info = (ImageInfoSpecific){
ed5979
+        .type = IMAGE_INFO_SPECIFIC_KIND_FILE,
ed5979
+        .u.file.data = file_info,
ed5979
+    };
ed5979
+
ed5979
+#ifdef FS_IOC_FSGETXATTR
ed5979
+    {
ed5979
+        BDRVRawState *s = bs->opaque;
ed5979
+        struct fsxattr attr;
ed5979
+        int ret;
ed5979
+
ed5979
+        ret = ioctl(s->fd, FS_IOC_FSGETXATTR, &attr);
ed5979
+        if (!ret && attr.fsx_extsize != 0) {
ed5979
+            file_info->has_extent_size_hint = true;
ed5979
+            file_info->extent_size_hint = attr.fsx_extsize;
ed5979
+        }
ed5979
+    }
ed5979
+#endif
ed5979
+
ed5979
+    return spec_info;
ed5979
+}
ed5979
+
ed5979
 static BlockStatsSpecificFile get_blockstats_specific_file(BlockDriverState *bs)
ed5979
 {
ed5979
     BDRVRawState *s = bs->opaque;
ed5979
@@ -3328,6 +3356,7 @@ BlockDriver bdrv_file = {
ed5979
     .bdrv_co_truncate = raw_co_truncate,
ed5979
     .bdrv_getlength = raw_getlength,
ed5979
     .bdrv_get_info = raw_get_info,
ed5979
+    .bdrv_get_specific_info             = raw_get_specific_info,
ed5979
     .bdrv_get_allocated_file_size
ed5979
                         = raw_get_allocated_file_size,
ed5979
     .bdrv_get_specific_stats = raw_get_specific_stats,
ed5979
@@ -3700,6 +3729,7 @@ static BlockDriver bdrv_host_device = {
ed5979
     .bdrv_co_truncate       = raw_co_truncate,
ed5979
     .bdrv_getlength	= raw_getlength,
ed5979
     .bdrv_get_info = raw_get_info,
ed5979
+    .bdrv_get_specific_info             = raw_get_specific_info,
ed5979
     .bdrv_get_allocated_file_size
ed5979
                         = raw_get_allocated_file_size,
ed5979
     .bdrv_get_specific_stats = hdev_get_specific_stats,
ed5979
diff --git a/qapi/block-core.json b/qapi/block-core.json
ed5979
index 95ac4fa634..f5d822cbd6 100644
ed5979
--- a/qapi/block-core.json
ed5979
+++ b/qapi/block-core.json
ed5979
@@ -139,16 +139,29 @@
ed5979
       '*encryption-format': 'RbdImageEncryptionFormat'
ed5979
   } }
ed5979
 
ed5979
+##
ed5979
+# @ImageInfoSpecificFile:
ed5979
+#
ed5979
+# @extent-size-hint: Extent size hint (if available)
ed5979
+#
ed5979
+# Since: 8.0
ed5979
+##
ed5979
+{ 'struct': 'ImageInfoSpecificFile',
ed5979
+  'data': {
ed5979
+      '*extent-size-hint': 'size'
ed5979
+  } }
ed5979
+
ed5979
 ##
ed5979
 # @ImageInfoSpecificKind:
ed5979
 #
ed5979
 # @luks: Since 2.7
ed5979
 # @rbd: Since 6.1
ed5979
+# @file: Since 8.0
ed5979
 #
ed5979
 # Since: 1.7
ed5979
 ##
ed5979
 { 'enum': 'ImageInfoSpecificKind',
ed5979
-  'data': [ 'qcow2', 'vmdk', 'luks', 'rbd' ] }
ed5979
+  'data': [ 'qcow2', 'vmdk', 'luks', 'rbd', 'file' ] }
ed5979
 
ed5979
 ##
ed5979
 # @ImageInfoSpecificQCow2Wrapper:
ed5979
@@ -185,6 +198,14 @@
ed5979
 { 'struct': 'ImageInfoSpecificRbdWrapper',
ed5979
   'data': { 'data': 'ImageInfoSpecificRbd' } }
ed5979
 
ed5979
+##
ed5979
+# @ImageInfoSpecificFileWrapper:
ed5979
+#
ed5979
+# Since: 8.0
ed5979
+##
ed5979
+{ 'struct': 'ImageInfoSpecificFileWrapper',
ed5979
+  'data': { 'data': 'ImageInfoSpecificFile' } }
ed5979
+
ed5979
 ##
ed5979
 # @ImageInfoSpecific:
ed5979
 #
ed5979
@@ -199,7 +220,8 @@
ed5979
       'qcow2': 'ImageInfoSpecificQCow2Wrapper',
ed5979
       'vmdk': 'ImageInfoSpecificVmdkWrapper',
ed5979
       'luks': 'ImageInfoSpecificLUKSWrapper',
ed5979
-      'rbd': 'ImageInfoSpecificRbdWrapper'
ed5979
+      'rbd': 'ImageInfoSpecificRbdWrapper',
ed5979
+      'file': 'ImageInfoSpecificFileWrapper'
ed5979
   } }
ed5979
 
ed5979
 ##
ed5979
-- 
ed5979
2.31.1
ed5979