thebeanogamer / rpms / qemu-kvm

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