diff mbox series

[4/4] block/file: Add file-specific image info

Message ID 20220503145529.37070-5-hreitz@redhat.com
State New
Headers show
Series block/file: Show extent size in qemu-img info | expand

Commit Message

Hanna Czenczek May 3, 2022, 2:55 p.m. UTC
Add some (optional) information that the file driver can provide for
image files, namely the extent size.

Signed-off-by: Hanna Reitz <hreitz@redhat.com>
---
 qapi/block-core.json | 26 ++++++++++++++++++++++++--
 block/file-posix.c   | 30 ++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 2 deletions(-)

Comments

Hanna Czenczek May 4, 2022, 7:10 a.m. UTC | #1
On 03.05.22 20:50, Eric Blake wrote:
> On Tue, May 03, 2022 at 04:55:29PM +0200, Hanna Reitz wrote:
>> Add some (optional) information that the file driver can provide for
>> image files, namely the extent size.
>>
>> Signed-off-by: Hanna Reitz <hreitz@redhat.com>
>> ---
>>   qapi/block-core.json | 26 ++++++++++++++++++++++++--
>>   block/file-posix.c   | 30 ++++++++++++++++++++++++++++++
>>   2 files changed, 54 insertions(+), 2 deletions(-)
>>
>> +++ b/block/file-posix.c
>> @@ -3068,6 +3068,34 @@ static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
>>       return 0;
>>   }
>>   
>> +static ImageInfoSpecific *raw_get_specific_info(BlockDriverState *bs,
>> +                                                Error **errp)
>> +{
>> +    BDRVRawState *s = bs->opaque;
>> +    ImageInfoSpecificFile *file_info = g_new0(ImageInfoSpecificFile, 1);
>> +    ImageInfoSpecific *spec_info = g_new(ImageInfoSpecific, 1);
>> +
>> +    *spec_info = (ImageInfoSpecific){
>> +        .type = IMAGE_INFO_SPECIFIC_KIND_FILE,
>> +        .u.file.data = file_info,
>> +    };
>> +
>> +#ifdef FS_IOC_FSGETXATTR
>> +    {
>> +        struct fsxattr attr;
>> +        int ret;
>> +
>> +        ret = ioctl(s->fd, FS_IOC_FSGETXATTR, &attr);
>> +        if (!ret && attr.fsx_extsize != 0) {
>> +            file_info->has_extent_size = true;
>> +            file_info->extent_size = attr.fsx_extsize;
>> +        }
>> +    }
>> +#endif
> Can/should we fall back to stat's st_blksize when the ioctl produces
> nothing?

I don’t think so, that’s a different value.  For example, by default, we 
use an extent-size-hint of 1 MB for new images (which is applied at 
least on XFS), but that doesn’t change st_blksize (which is 4096 here).  
So I’d only report the extent-size for filesystems that actually 
differentiate between the two.

Hanna
Kevin Wolf May 4, 2022, 8:46 a.m. UTC | #2
Am 03.05.2022 um 16:55 hat Hanna Reitz geschrieben:
> Add some (optional) information that the file driver can provide for
> image files, namely the extent size.
> 
> Signed-off-by: Hanna Reitz <hreitz@redhat.com>
> ---
>  qapi/block-core.json | 26 ++++++++++++++++++++++++--
>  block/file-posix.c   | 30 ++++++++++++++++++++++++++++++
>  2 files changed, 54 insertions(+), 2 deletions(-)
> 
> diff --git a/qapi/block-core.json b/qapi/block-core.json
> index e7d6c2e0cc..728da051ae 100644
> --- a/qapi/block-core.json
> +++ b/qapi/block-core.json
> @@ -139,16 +139,29 @@
>        '*encryption-format': 'RbdImageEncryptionFormat'
>    } }
>  
> +##
> +# @ImageInfoSpecificFile:
> +#
> +# @extent-size: Extent size (if available)
> +#
> +# Since: 7.1
> +##
> +{ 'struct': 'ImageInfoSpecificFile',
> +  'data': {
> +      '*extent-size': 'size'
> +  } }

It's not "the extent size" (the whole point of extents is that they
don't have a fixed size like blocks), but an extent size *hint* that
tells the filesystem the minimum size to allocate for an extent. The
xfs_io man page calls it the preferred extent size for allocatino, which
works for the documentation if you prefer, but BlockdevCreateOptionsFile
has 'extent-size-hint', so I'd prefer consistency on the wire at least.

Kevin
Hanna Czenczek May 4, 2022, 11:26 a.m. UTC | #3
On 04.05.22 10:46, Kevin Wolf wrote:
> Am 03.05.2022 um 16:55 hat Hanna Reitz geschrieben:
>> Add some (optional) information that the file driver can provide for
>> image files, namely the extent size.
>>
>> Signed-off-by: Hanna Reitz <hreitz@redhat.com>
>> ---
>>   qapi/block-core.json | 26 ++++++++++++++++++++++++--
>>   block/file-posix.c   | 30 ++++++++++++++++++++++++++++++
>>   2 files changed, 54 insertions(+), 2 deletions(-)
>>
>> diff --git a/qapi/block-core.json b/qapi/block-core.json
>> index e7d6c2e0cc..728da051ae 100644
>> --- a/qapi/block-core.json
>> +++ b/qapi/block-core.json
>> @@ -139,16 +139,29 @@
>>         '*encryption-format': 'RbdImageEncryptionFormat'
>>     } }
>>   
>> +##
>> +# @ImageInfoSpecificFile:
>> +#
>> +# @extent-size: Extent size (if available)
>> +#
>> +# Since: 7.1
>> +##
>> +{ 'struct': 'ImageInfoSpecificFile',
>> +  'data': {
>> +      '*extent-size': 'size'
>> +  } }
> It's not "the extent size" (the whole point of extents is that they
> don't have a fixed size like blocks), but an extent size *hint* that
> tells the filesystem the minimum size to allocate for an extent. The
> xfs_io man page calls it the preferred extent size for allocatino, which
> works for the documentation if you prefer, but BlockdevCreateOptionsFile
> has 'extent-size-hint', so I'd prefer consistency on the wire at least.

Got it.
diff mbox series

Patch

diff --git a/qapi/block-core.json b/qapi/block-core.json
index e7d6c2e0cc..728da051ae 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -139,16 +139,29 @@ 
       '*encryption-format': 'RbdImageEncryptionFormat'
   } }
 
+##
+# @ImageInfoSpecificFile:
+#
+# @extent-size: Extent size (if available)
+#
+# Since: 7.1
+##
+{ 'struct': 'ImageInfoSpecificFile',
+  'data': {
+      '*extent-size': 'size'
+  } }
+
 ##
 # @ImageInfoSpecificKind:
 #
 # @luks: Since 2.7
 # @rbd: Since 6.1
+# @file: Since 7.1
 #
 # Since: 1.7
 ##
 { 'enum': 'ImageInfoSpecificKind',
-  'data': [ 'qcow2', 'vmdk', 'luks', 'rbd' ] }
+  'data': [ 'qcow2', 'vmdk', 'luks', 'rbd', 'file' ] }
 
 ##
 # @ImageInfoSpecificQCow2Wrapper:
@@ -185,6 +198,14 @@ 
 { 'struct': 'ImageInfoSpecificRbdWrapper',
   'data': { 'data': 'ImageInfoSpecificRbd' } }
 
+##
+# @ImageInfoSpecificFileWrapper:
+#
+# Since: 7.1
+##
+{ 'struct': 'ImageInfoSpecificFileWrapper',
+  'data': { 'data': 'ImageInfoSpecificFile' } }
+
 ##
 # @ImageInfoSpecific:
 #
@@ -199,7 +220,8 @@ 
       'qcow2': 'ImageInfoSpecificQCow2Wrapper',
       'vmdk': 'ImageInfoSpecificVmdkWrapper',
       'luks': 'ImageInfoSpecificLUKSWrapper',
-      'rbd': 'ImageInfoSpecificRbdWrapper'
+      'rbd': 'ImageInfoSpecificRbdWrapper',
+      'file': 'ImageInfoSpecificFileWrapper'
   } }
 
 ##
diff --git a/block/file-posix.c b/block/file-posix.c
index bfd9b21111..4323345c99 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -3068,6 +3068,34 @@  static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
     return 0;
 }
 
+static ImageInfoSpecific *raw_get_specific_info(BlockDriverState *bs,
+                                                Error **errp)
+{
+    BDRVRawState *s = bs->opaque;
+    ImageInfoSpecificFile *file_info = g_new0(ImageInfoSpecificFile, 1);
+    ImageInfoSpecific *spec_info = g_new(ImageInfoSpecific, 1);
+
+    *spec_info = (ImageInfoSpecific){
+        .type = IMAGE_INFO_SPECIFIC_KIND_FILE,
+        .u.file.data = file_info,
+    };
+
+#ifdef FS_IOC_FSGETXATTR
+    {
+        struct fsxattr attr;
+        int ret;
+
+        ret = ioctl(s->fd, FS_IOC_FSGETXATTR, &attr);
+        if (!ret && attr.fsx_extsize != 0) {
+            file_info->has_extent_size = true;
+            file_info->extent_size = attr.fsx_extsize;
+        }
+    }
+#endif
+
+    return spec_info;
+}
+
 static BlockStatsSpecificFile get_blockstats_specific_file(BlockDriverState *bs)
 {
     BDRVRawState *s = bs->opaque;
@@ -3301,6 +3329,7 @@  BlockDriver bdrv_file = {
     .bdrv_co_truncate = raw_co_truncate,
     .bdrv_getlength = raw_getlength,
     .bdrv_get_info = raw_get_info,
+    .bdrv_get_specific_info = raw_get_specific_info,
     .bdrv_get_allocated_file_size
                         = raw_get_allocated_file_size,
     .bdrv_get_specific_stats = raw_get_specific_stats,
@@ -3673,6 +3702,7 @@  static BlockDriver bdrv_host_device = {
     .bdrv_co_truncate       = raw_co_truncate,
     .bdrv_getlength	= raw_getlength,
     .bdrv_get_info = raw_get_info,
+    .bdrv_get_specific_info = raw_get_specific_info,
     .bdrv_get_allocated_file_size
                         = raw_get_allocated_file_size,
     .bdrv_get_specific_stats = hdev_get_specific_stats,