Changeset
block.c                   | 27 ++++++++++++++++-----
block/file-posix.c        | 14 ++++-------
block/file-win32.c        |  8 +++----
block/gluster.c           |  8 +++----
block/nfs.c               |  8 +++----
block/qapi.c              |  4 ++--
block/qcow2-refcount.c    | 61 +++++++++++++++++++++++++++++++++++++++++++++++
block/qcow2.c             |  2 ++
block/qcow2.h             |  2 ++
block/sheepdog.c          |  8 +++----
block/vmdk.c              |  8 +++----
include/block/block.h     |  3 ++-
include/block/block_int.h |  3 ++-
include/qemu-common.h     |  2 ++
qapi/block-core.json      |  3 ++-
qemu-img.c                | 24 +++++++++++++++++++
16 files changed, 144 insertions(+), 41 deletions(-)
Git apply log
Switched to a new branch '20170525152628.37628-1-vsementsov@virtuozzo.com'
Applying: block: fix comment for bdrv_get_allocated_file_size()
Applying: block: add bdrv_get_format_allocated_size format interface
Applying: qcow2: add .bdrv_get_format_allocated_size
Applying: common: make get_human_readable_size public
Applying: qemu-img check: add format unallocated size
Applying: qemu-img check: add file-size
Applying: block: rename _get_allocated_file_size() to _get_fs_allocated_size()
To https://github.com/patchew-project/qemu
 * [new tag]         patchew/20170525152628.37628-1-vsementsov@virtuozzo.com -> patchew/20170525152628.37628-1-vsementsov@virtuozzo.com
Test passed: s390x

loading

Test passed: docker

loading

Test passed: checkpatch

loading

[Qemu-devel] [PATCH 0/7] qemu-img check: unallocated size
Posted by Vladimir Sementsov-Ogievskiy, 59 weeks ago
Hi all!

These small series is about "Format unallocated size" section for
qemu-img check. It is needed to know, how many holes we have in qcow2,
when underlying raw file is on non-sparse file-system. In this case
actual-size from qemu-img info will not take holes into account.
Also, qemu-img check 'allocated' stat is not appropriate too, as it
is about guest clusters, so metadata and snapshots are not accounted.

Qemu-img check is chosen instead of qemu-img info, to not slow down
qemu-img info by loading all L2 tables (Kevin)

Vladimir Sementsov-Ogievskiy (7):
  block: fix comment for bdrv_get_allocated_file_size()
  block: add bdrv_get_format_allocated_size format interface
  qcow2: add .bdrv_get_format_allocated_size
  common: make get_human_readable_size public
  qemu-img check: add format unallocated size
  qemu-img check: add file-size
  block: rename _get_allocated_file_size() to _get_fs_allocated_size()

 block.c                   | 27 ++++++++++++++++-----
 block/file-posix.c        | 14 ++++-------
 block/file-win32.c        |  8 +++----
 block/gluster.c           |  8 +++----
 block/nfs.c               |  8 +++----
 block/qapi.c              |  4 ++--
 block/qcow2-refcount.c    | 61 +++++++++++++++++++++++++++++++++++++++++++++++
 block/qcow2.c             |  2 ++
 block/qcow2.h             |  2 ++
 block/sheepdog.c          |  8 +++----
 block/vmdk.c              |  8 +++----
 include/block/block.h     |  3 ++-
 include/block/block_int.h |  3 ++-
 include/qemu-common.h     |  2 ++
 qapi/block-core.json      |  3 ++-
 qemu-img.c                | 24 +++++++++++++++++++
 16 files changed, 144 insertions(+), 41 deletions(-)

-- 
2.11.1


[Qemu-devel] [PATCH 1/7] block: fix comment for bdrv_get_allocated_file_size()
Posted by Vladimir Sementsov-Ogievskiy, 59 weeks ago
Current comment is not clear enough: which sparseness is meant, coming
from sparse image format or from sparse file system?

For example, if we have qcow2 above raw file on non-sparse file system,
this function will say nothing about unallocated (by qcow2 layer)
clusters.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 block.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index 50ba264143..ba22fc0dfb 100644
--- a/block.c
+++ b/block.c
@@ -3388,8 +3388,8 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp)
 }
 
 /**
- * Length of a allocated file in bytes. Sparse files are counted by actual
- * allocated space. Return < 0 if error or unknown.
+ * Size of allocated in underlying file system area. Sparseness is taken into
+ * account for sparse file systems. Return < 0 if error or unknown.
  */
 int64_t bdrv_get_allocated_file_size(BlockDriverState *bs)
 {
-- 
2.11.1


Re: [Qemu-devel] [PATCH 1/7] block: fix comment for bdrv_get_allocated_file_size()
Posted by Eric Blake, 59 weeks ago
On 05/25/2017 10:26 AM, Vladimir Sementsov-Ogievskiy wrote:
> Current comment is not clear enough: which sparseness is meant, coming
> from sparse image format or from sparse file system?
> 
> For example, if we have qcow2 above raw file on non-sparse file system,
> this function will say nothing about unallocated (by qcow2 layer)
> clusters.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  block.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 50ba264143..ba22fc0dfb 100644
> --- a/block.c
> +++ b/block.c
> @@ -3388,8 +3388,8 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp)
>  }
>  
>  /**
> - * Length of a allocated file in bytes. Sparse files are counted by actual

Yay for getting rid of bad grammar (s/a /an /)

> - * allocated space. Return < 0 if error or unknown.
> + * Size of allocated in underlying file system area. Sparseness is taken into

Doesn't read well.  Maybe: s/Size of allocated/Allocation size/ ?

> + * account for sparse file systems. Return < 0 if error or unknown.

I still don't get what we are trying to present.

If we have the following 6 qcow2 file clusters backed by the underlying
lseek(SEEK_DATA/HOLE) file system contents:

BDRV_BLOCK_UNALLOCATED   N/A
BDRV_BLOCK_ZERO_PLAIN    N/A
BDRV_BLOCK_ZERO_ALLOC    hole
BDRV_BLOCK_ZERO_ALLOC    data
BDRV_BLOCK_DATA          hole
BDRV_BLOCK_DATA          data

Then is our answer the size of all qcow2 allocations regardless of
underlying status (4, due to clusters 3-6), or the size of only the
clusters that read from the backing file (2, due to clusters 5-6), or
the size of only the clusters that currently occupy space in the file
system (2, due to clusters 4 and 6), or the size of clusters that are
not provably read-as-zero (1, due to cluster 6)?

Does the answer change if you can have underlying holes happen at a
smaller granularity than clusters?

What happens for compressed clusters?

I think we still need to do a better job at writing a precise comment.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Re: [Qemu-devel] [PATCH 1/7] block: fix comment for bdrv_get_allocated_file_size()
Posted by Eric Blake, 59 weeks ago
On 05/25/2017 11:32 AM, Eric Blake wrote:
> If we have the following 6 qcow2 file clusters backed by the underlying
> lseek(SEEK_DATA/HOLE) file system contents:
> 
> BDRV_BLOCK_UNALLOCATED   N/A
> BDRV_BLOCK_ZERO_PLAIN    N/A
> BDRV_BLOCK_ZERO_ALLOC    hole
> BDRV_BLOCK_ZERO_ALLOC    data
> BDRV_BLOCK_DATA          hole
> BDRV_BLOCK_DATA          data

Sorry, these should all be s/BDRV_BLOCK/QCOW2_CLUSTER/ and
s/DATA/NORMAL/ - as I was referring to the qcow2 cluster status given by
qcow2_get_cluster_type() (as of commit fdfab37 or later).

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Re: [Qemu-devel] [PATCH 1/7] block: fix comment for bdrv_get_allocated_file_size()
Posted by Vladimir Sementsov-Ogievskiy, 59 weeks ago
25.05.2017 19:32, Eric Blake wrote:
> On 05/25/2017 10:26 AM, Vladimir Sementsov-Ogievskiy wrote:
>> Current comment is not clear enough: which sparseness is meant, coming
>> from sparse image format or from sparse file system?
>>
>> For example, if we have qcow2 above raw file on non-sparse file system,
>> this function will say nothing about unallocated (by qcow2 layer)
>> clusters.
>>
>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>> ---
>>   block.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/block.c b/block.c
>> index 50ba264143..ba22fc0dfb 100644
>> --- a/block.c
>> +++ b/block.c
>> @@ -3388,8 +3388,8 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp)
>>   }
>>   
>>   /**
>> - * Length of a allocated file in bytes. Sparse files are counted by actual
> Yay for getting rid of bad grammar (s/a /an /)
>
>> - * allocated space. Return < 0 if error or unknown.
>> + * Size of allocated in underlying file system area. Sparseness is taken into
> Doesn't read well.  Maybe: s/Size of allocated/Allocation size/ ?
>
>> + * account for sparse file systems. Return < 0 if error or unknown.
> I still don't get what we are trying to present.
>
> If we have the following 6 qcow2 file clusters backed by the underlying
> lseek(SEEK_DATA/HOLE) file system contents:
>
> BDRV_BLOCK_UNALLOCATED   N/A
> BDRV_BLOCK_ZERO_PLAIN    N/A
> BDRV_BLOCK_ZERO_ALLOC    hole
> BDRV_BLOCK_ZERO_ALLOC    data
> BDRV_BLOCK_DATA          hole
> BDRV_BLOCK_DATA          data
>
> Then is our answer the size of all qcow2 allocations regardless of
> underlying status (4, due to clusters 3-6), or the size of only the
> clusters that read from the backing file (2, due to clusters 5-6), or
> the size of only the clusters that currently occupy space in the file
> system (2, due to clusters 4 and 6), or the size of clusters that are
> not provably read-as-zero (1, due to cluster 6)?
>
> Does the answer change if you can have underlying holes happen at a
> smaller granularity than clusters?
>
> What happens for compressed clusters?
>
> I think we still need to do a better job at writing a precise comment.
>

bdrv_get_allocated_file_size is not related to qcow2, as qcow2 doesn't 
support it. So, it is finally just raw_get_allocated_file_size, which 
returns st.st_blocks * 512 after fstat(s->fd).

It will correspond to qcow2 sparseness if qcow2 discarded corresponding 
clusters in bs->file and if underlying fs is sparse.



-- 
Best regards,
Vladimir


Re: [Qemu-devel] [PATCH 1/7] block: fix comment for bdrv_get_allocated_file_size()
Posted by Eric Blake, 59 weeks ago
On 05/25/2017 12:03 PM, Vladimir Sementsov-Ogievskiy wrote:
> 25.05.2017 19:32, Eric Blake wrote:
>> On 05/25/2017 10:26 AM, Vladimir Sementsov-Ogievskiy wrote:
>>> Current comment is not clear enough: which sparseness is meant, coming
>>> from sparse image format or from sparse file system?
>>>
>>> For example, if we have qcow2 above raw file on non-sparse file system,
>>> this function will say nothing about unallocated (by qcow2 layer)
>>> clusters.
>>>

>>> + * Size of allocated in underlying file system area. Sparseness is
>>> taken into
>> Doesn't read well.  Maybe: s/Size of allocated/Allocation size/ ?
>>
>>> + * account for sparse file systems. Return < 0 if error or unknown.
>> I still don't get what we are trying to present.
>>

>>
>> I think we still need to do a better job at writing a precise comment.
>>
> 
> bdrv_get_allocated_file_size is not related to qcow2, as qcow2 doesn't
> support it. So, it is finally just raw_get_allocated_file_size, which
> returns st.st_blocks * 512 after fstat(s->fd).
> 
> It will correspond to qcow2 sparseness if qcow2 discarded corresponding
> clusters in bs->file and if underlying fs is sparse.

Okay, that helps.  How about this wording:

Allocation size of the underlying file system area.  Sparseness is taken
into account (holes do not contribute to this size).  Return < 0 if
error or unknown.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Re: [Qemu-devel] [PATCH 1/7] block: fix comment for bdrv_get_allocated_file_size()
Posted by Vladimir Sementsov-Ogievskiy, 59 weeks ago
25.05.2017 20:46, Eric Blake wrote:
> On 05/25/2017 12:03 PM, Vladimir Sementsov-Ogievskiy wrote:
>> 25.05.2017 19:32, Eric Blake wrote:
>>> On 05/25/2017 10:26 AM, Vladimir Sementsov-Ogievskiy wrote:
>>>> Current comment is not clear enough: which sparseness is meant, coming
>>>> from sparse image format or from sparse file system?
>>>>
>>>> For example, if we have qcow2 above raw file on non-sparse file system,
>>>> this function will say nothing about unallocated (by qcow2 layer)
>>>> clusters.
>>>>
>>>> + * Size of allocated in underlying file system area. Sparseness is
>>>> taken into
>>> Doesn't read well.  Maybe: s/Size of allocated/Allocation size/ ?
>>>
>>>> + * account for sparse file systems. Return < 0 if error or unknown.
>>> I still don't get what we are trying to present.
>>>
>>> I think we still need to do a better job at writing a precise comment.
>>>
>> bdrv_get_allocated_file_size is not related to qcow2, as qcow2 doesn't
>> support it. So, it is finally just raw_get_allocated_file_size, which
>> returns st.st_blocks * 512 after fstat(s->fd).
>>
>> It will correspond to qcow2 sparseness if qcow2 discarded corresponding
>> clusters in bs->file and if underlying fs is sparse.
> Okay, that helps.  How about this wording:
>
> Allocation size of the underlying file system area.  Sparseness is taken
> into account (holes do not contribute to this size).  Return < 0 if
> error or unknown.
>
OK for me, thank you. Will use your wording if no other comments on this.



-- 
Best regards,
Vladimir


[Qemu-devel] [PATCH 2/7] block: add bdrv_get_format_allocated_size format interface
Posted by Vladimir Sementsov-Ogievskiy, 59 weeks ago
The function should return actually used by top-level format driver
space (in it's .file). It differs from bdrv_get_allocated_file_size,
which returns allocated on fs file size.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 block.c                   | 15 +++++++++++++++
 include/block/block.h     |  1 +
 include/block/block_int.h |  1 +
 3 files changed, 17 insertions(+)

diff --git a/block.c b/block.c
index ba22fc0dfb..6e1a435490 100644
--- a/block.c
+++ b/block.c
@@ -3407,6 +3407,21 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs)
 }
 
 /**
+ * Actually used by top-level format driver space (in it's .file) in bytes
+ */
+int64_t bdrv_get_format_allocated_size(BlockDriverState *bs)
+{
+    BlockDriver *drv = bs->drv;
+    if (!drv) {
+        return -ENOMEDIUM;
+    }
+    if (drv->bdrv_get_format_allocated_size) {
+        return drv->bdrv_get_format_allocated_size(bs);
+    }
+    return -ENOTSUP;
+}
+
+/**
  * Return number of sectors on success, -errno on error.
  */
 int64_t bdrv_nb_sectors(BlockDriverState *bs)
diff --git a/include/block/block.h b/include/block/block.h
index 9b355e92d8..c36b9ccae4 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -304,6 +304,7 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp);
 int64_t bdrv_nb_sectors(BlockDriverState *bs);
 int64_t bdrv_getlength(BlockDriverState *bs);
 int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
+int64_t bdrv_get_format_allocated_size(BlockDriverState *bs);
 void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
 void bdrv_refresh_limits(BlockDriverState *bs, Error **errp);
 int bdrv_commit(BlockDriverState *bs);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 8d3724cce6..e562fa7a5a 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -208,6 +208,7 @@ struct BlockDriver {
     int64_t (*bdrv_getlength)(BlockDriverState *bs);
     bool has_variable_length;
     int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs);
+    int64_t (*bdrv_get_format_allocated_size)(BlockDriverState *bs);
 
     int coroutine_fn (*bdrv_co_pwritev_compressed)(BlockDriverState *bs,
         uint64_t offset, uint64_t bytes, QEMUIOVector *qiov);
-- 
2.11.1


Re: [Qemu-devel] [PATCH 2/7] block: add bdrv_get_format_allocated_size format interface
Posted by Eric Blake, 59 weeks ago
On 05/25/2017 10:26 AM, Vladimir Sementsov-Ogievskiy wrote:
> The function should return actually used by top-level format driver

s/actually/the allocation actually/

> space (in it's .file). It differs from bdrv_get_allocated_file_size,

s/it's/its/ (remember, "it's" is only appropriate if "it is" can be used
in its place)

> which returns allocated on fs file size.

s/allocated on fs file size/the disk usage of the underlying file/

So this is a measure of how many clusters a qcow2 image is currently
using (including metadata clusters, and regardless of whether those
clusters happen to point to a hole in the underlying protocol layer)?

> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  block.c                   | 15 +++++++++++++++
>  include/block/block.h     |  1 +
>  include/block/block_int.h |  1 +
>  3 files changed, 17 insertions(+)
> 
> diff --git a/block.c b/block.c
> index ba22fc0dfb..6e1a435490 100644
> --- a/block.c
> +++ b/block.c
> @@ -3407,6 +3407,21 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs)
>  }
>  
>  /**
> + * Actually used by top-level format driver space (in it's .file) in bytes

s/it's/its/

I think we can do better.  How about:

Return the amount of space allocated by the format driver (including
metadata) in bytes, even if some of that space currently maps to holes
in the underlying protocol file.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

Re: [Qemu-devel] [PATCH 2/7] block: add bdrv_get_format_allocated_size format interface
Posted by Vladimir Sementsov-Ogievskiy, 59 weeks ago
25.05.2017 20:54, Eric Blake wrote:
> On 05/25/2017 10:26 AM, Vladimir Sementsov-Ogievskiy wrote:
>> The function should return actually used by top-level format driver
> s/actually/the allocation actually/
>
>> space (in it's .file). It differs from bdrv_get_allocated_file_size,
> s/it's/its/ (remember, "it's" is only appropriate if "it is" can be used
> in its place)
>
>> which returns allocated on fs file size.
> s/allocated on fs file size/the disk usage of the underlying file/
>
> So this is a measure of how many clusters a qcow2 image is currently
> using (including metadata clusters, and regardless of whether those
> clusters happen to point to a hole in the underlying protocol layer)?

Hmm, interesting remark. Now it is realized exactly as you write.. But 
this leads to the situation, when qcow2 allocates data amount > 
bdrv_getlength(bs->file->bs) and we will have negative size of 
unallocated area =). Denis what do you think? (Actually, we needed this 
feature for non-sparce file system and this question was not considered).

>
>> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
>> ---
>>   block.c                   | 15 +++++++++++++++
>>   include/block/block.h     |  1 +
>>   include/block/block_int.h |  1 +
>>   3 files changed, 17 insertions(+)
>>
>> diff --git a/block.c b/block.c
>> index ba22fc0dfb..6e1a435490 100644
>> --- a/block.c
>> +++ b/block.c
>> @@ -3407,6 +3407,21 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs)
>>   }
>>   
>>   /**
>> + * Actually used by top-level format driver space (in it's .file) in bytes
> s/it's/its/
>
> I think we can do better.  How about:
>
> Return the amount of space allocated by the format driver (including
> metadata) in bytes, even if some of that space currently maps to holes
> in the underlying protocol file.
>

-- 
Best regards,
Vladimir

Re: [Qemu-devel] [PATCH 2/7] block: add bdrv_get_format_allocated_size format interface
Posted by Vladimir Sementsov-Ogievskiy, 59 weeks ago
25.05.2017 21:07, Vladimir Sementsov-Ogievskiy wrote:
> 25.05.2017 20:54, Eric Blake wrote:
>> On 05/25/2017 10:26 AM, Vladimir Sementsov-Ogievskiy wrote:
>>> The function should return actually used by top-level format driver
>> s/actually/the allocation actually/
>>
>>> space (in it's .file). It differs from bdrv_get_allocated_file_size,
>> s/it's/its/ (remember, "it's" is only appropriate if "it is" can be used
>> in its place)
>>
>>> which returns allocated on fs file size.
>> s/allocated on fs file size/the disk usage of the underlying file/
>>
>> So this is a measure of how many clusters a qcow2 image is currently
>> using (including metadata clusters, and regardless of whether those
>> clusters happen to point to a hole in the underlying protocol layer)?
>
> Hmm, interesting remark. Now it is realized exactly as you write.. But 
> this leads to the situation, when qcow2 allocates data amount > 
> bdrv_getlength(bs->file->bs) and we will have negative size of 
> unallocated area =). Denis what do you think? (Actually, we needed 
> this feature for non-sparce file system and this question was not 
> considered).

No, it will not be negative, all OK. I've mistaken. length of 
bs->file->bs will be positive anyway.

Actually, current approach is the following:

a. clusters allocated in qcow2 and after the end of bs->file: unallocated
b. clusters allocated in qcow2 and which are holes bs->file: allocated

(a) look inconsistent with b and with commit message and other things. 
But if I just account (a) clusters, it will lead to negative size of 
unallocated and will spoil the whole stat.. Something should be 
adjusted, at least at comment/commit-message level.


>
>>> Signed-off-by: Vladimir Sementsov-Ogievskiy<vsementsov@virtuozzo.com>
>>> ---
>>>   block.c                   | 15 +++++++++++++++
>>>   include/block/block.h     |  1 +
>>>   include/block/block_int.h |  1 +
>>>   3 files changed, 17 insertions(+)
>>>
>>> diff --git a/block.c b/block.c
>>> index ba22fc0dfb..6e1a435490 100644
>>> --- a/block.c
>>> +++ b/block.c
>>> @@ -3407,6 +3407,21 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState *bs)
>>>   }
>>>   
>>>   /**
>>> + * Actually used by top-level format driver space (in it's .file) in bytes
>> s/it's/its/
>>
>> I think we can do better.  How about:
>>
>> Return the amount of space allocated by the format driver (including
>> metadata) in bytes, even if some of that space currently maps to holes
>> in the underlying protocol file.
>>
>
> -- 
> Best regards,
> Vladimir


-- 
Best regards,
Vladimir

Re: [Qemu-devel] [PATCH 2/7] block: add bdrv_get_format_allocated_size format interface
Posted by Eric Blake, 59 weeks ago
On 05/25/2017 01:19 PM, Vladimir Sementsov-Ogievskiy wrote:

> No, it will not be negative, all OK. I've mistaken. length of
> bs->file->bs will be positive anyway.
> 
> Actually, current approach is the following:
> 
> a. clusters allocated in qcow2 and after the end of bs->file: unallocated

How often do we actually end up in this situation? I know there are a
few cases where it makes sense (for example, if your image is large
enough to have L1 occupy two clusters, but the guest hasn't written
anything in the second half of the guest-visible area, then the second
cluster of the L1 table can be all zeroes - and depending on allocation
patterns, it is feasible that the L1 table can occupy the end of the
image, where the second cluster of the L1 table thus points beyond
end-of-file of the underlying image while still being a well-formed
qcow2 image).  It may also be a common transitory state in how we expand
a qcow2 image; if the expansion is interrupted in the middle, we could
easily have the refcount table saying a cluster has been allocated while
we have not yet actually written to the host file.

> b. clusters allocated in qcow2 and which are holes bs->file: allocated

This may be more common; a typical example is if we have a cluster
marked QCOW2_CLUSTER_NORMAL but which maps to a hole (and therefore
bdrv_get_block_status will report it as BDRV_BLOCK_DATA|BDRV_BLOCK_ZERO).

> 
> (a) look inconsistent with b and with commit message and other things.
> But if I just account (a) clusters, it will lead to negative size of
> unallocated and will spoil the whole stat.. Something should be
> adjusted, at least at comment/commit-message level.

Exposing the stat as a difference may not make as much sense as
reporting actual numbers (this image requires an allocation of this many
bytes to fully represent current guest- and meta-data, even if some of
the allocation is currently pointing to holes or beyond the end of the
underlying file).

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

[Qemu-devel] [PATCH 3/7] qcow2: add .bdrv_get_format_allocated_size
Posted by Vladimir Sementsov-Ogievskiy, 59 weeks ago
Realize .bdrv_get_format_allocated_size interface.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 block/qcow2-refcount.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++
 block/qcow2.c          |  2 ++
 block/qcow2.h          |  2 ++
 3 files changed, 65 insertions(+)

diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c
index 7c06061aae..45adf6bd1d 100644
--- a/block/qcow2-refcount.c
+++ b/block/qcow2-refcount.c
@@ -2931,3 +2931,64 @@ done:
     qemu_vfree(new_refblock);
     return ret;
 }
+
+typedef struct NbAllocatedClustersCo {
+    BlockDriverState *bs;
+    int64_t ret;
+} NbAllocatedClustersCo;
+
+static void coroutine_fn qcow2_get_format_allocated_size_co_entry(void *opaque)
+{
+    NbAllocatedClustersCo *nbco = opaque;
+    BlockDriverState *bs = nbco->bs;
+    BDRVQcow2State *s = bs->opaque;
+    int64_t size, nb_clusters, nb_allocated = 0, i;
+    int ret = 0;
+
+    size = bdrv_getlength(bs->file->bs);
+    if (size < 0) {
+        nbco->ret = size;
+        return;
+    }
+
+    nb_clusters = size_to_clusters(s, size);
+
+    qemu_co_mutex_lock(&s->lock);
+
+    for (i = 0; i < nb_clusters; ++i) {
+        uint64_t refcount;
+        ret = qcow2_get_refcount(bs, i, &refcount);
+        if (ret < 0) {
+            nbco->ret = ret;
+            qemu_co_mutex_unlock(&s->lock);
+            return;
+        }
+        if (refcount > 0) {
+            nb_allocated++;
+        }
+    }
+
+    qemu_co_mutex_unlock(&s->lock);
+
+    nbco->ret = nb_allocated << s->cluster_bits;
+}
+
+int64_t qcow2_get_format_allocated_size(BlockDriverState *bs)
+{
+    NbAllocatedClustersCo nbco = {
+        .bs = bs,
+        .ret = -EINPROGRESS
+    };
+
+    if (qemu_in_coroutine()) {
+        qcow2_get_format_allocated_size_co_entry(&nbco);
+    } else {
+        Coroutine *co =
+            qemu_coroutine_create(qcow2_get_format_allocated_size_co_entry,
+                                  &nbco);
+        qemu_coroutine_enter(co);
+        BDRV_POLL_WHILE(bs, nbco.ret == -EINPROGRESS);
+    }
+
+    return nbco.ret;
+}
diff --git a/block/qcow2.c b/block/qcow2.c
index a8d61f0981..274f213d16 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3469,6 +3469,8 @@ BlockDriver bdrv_qcow2 = {
 
     .bdrv_detach_aio_context  = qcow2_detach_aio_context,
     .bdrv_attach_aio_context  = qcow2_attach_aio_context,
+
+    .bdrv_get_format_allocated_size = qcow2_get_format_allocated_size,
 };
 
 static void bdrv_qcow2_init(void)
diff --git a/block/qcow2.h b/block/qcow2.h
index 1801dc30dc..8cc63d9e0e 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -532,6 +532,8 @@ int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order,
                                 BlockDriverAmendStatusCB *status_cb,
                                 void *cb_opaque, Error **errp);
 
+int64_t qcow2_get_format_allocated_size(BlockDriverState *bs);
+
 /* qcow2-cluster.c functions */
 int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
                         bool exact_size);
-- 
2.11.1


[Qemu-devel] [PATCH 4/7] common: make get_human_readable_size public
Posted by Vladimir Sementsov-Ogievskiy, 59 weeks ago
To be reused from qemu-img check.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 block/qapi.c          | 2 +-
 include/qemu-common.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/block/qapi.c b/block/qapi.c
index a40922ea26..d249d97142 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -524,7 +524,7 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes,
 
 #define NB_SUFFIXES 4
 
-static char *get_human_readable_size(char *buf, int buf_size, int64_t size)
+char *get_human_readable_size(char *buf, int buf_size, int64_t size)
 {
     static const char suffixes[NB_SUFFIXES] = {'K', 'M', 'G', 'T'};
     int64_t base;
diff --git a/include/qemu-common.h b/include/qemu-common.h
index 387ef520bf..7102ad8dbd 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -152,4 +152,6 @@ void page_size_init(void);
  * returned. */
 bool dump_in_progress(void);
 
+char *get_human_readable_size(char *buf, int buf_size, int64_t size);
+
 #endif
-- 
2.11.1


Re: [Qemu-devel] [PATCH 4/7] common: make get_human_readable_size public
Posted by Eric Blake, 59 weeks ago
On 05/25/2017 10:26 AM, Vladimir Sementsov-Ogievskiy wrote:
> To be reused from qemu-img check.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  block/qapi.c          | 2 +-
>  include/qemu-common.h | 2 ++
>  2 files changed, 3 insertions(+), 1 deletion(-)

Would it be better to use size_to_str() added in commit 22951aa?

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

[Qemu-devel] [PATCH 5/7] qemu-img check: add format unallocated size
Posted by Vladimir Sementsov-Ogievskiy, 59 weeks ago
Shows format 'sparseness' of the image top level.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 qapi/block-core.json |  3 ++-
 qemu-img.c           | 19 +++++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index ea0b3e8b13..c7ed5dc970 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -185,7 +185,8 @@
            '*image-end-offset': 'int', '*corruptions': 'int', '*leaks': 'int',
            '*corruptions-fixed': 'int', '*leaks-fixed': 'int',
            '*total-clusters': 'int', '*allocated-clusters': 'int',
-           '*fragmented-clusters': 'int', '*compressed-clusters': 'int' } }
+           '*fragmented-clusters': 'int', '*compressed-clusters': 'int',
+           '*format-unallocated-size': 'uint64'} }
 
 ##
 # @MapEntry:
diff --git a/qemu-img.c b/qemu-img.c
index b506839ef0..cbd09148d2 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -601,6 +601,13 @@ static void dump_human_image_check(ImageCheck *check, bool quiet)
         qprintf(quiet,
                 "Image end offset: %" PRId64 "\n", check->image_end_offset);
     }
+
+    if (check->has_format_unallocated_size) {
+        char u_buf[128];
+        qprintf(quiet, "Format unallocated size: %s\n",
+                get_human_readable_size(u_buf, sizeof(u_buf),
+                                        check->format_unallocated_size));
+    }
 }
 
 static int collect_image_check(BlockDriverState *bs,
@@ -639,6 +646,18 @@ static int collect_image_check(BlockDriverState *bs,
     check->compressed_clusters      = result.bfi.compressed_clusters;
     check->has_compressed_clusters  = result.bfi.compressed_clusters != 0;
 
+    if (bs->file) {
+        int64_t file_size = bdrv_getlength(bs->file->bs);
+        if (file_size >= 0) {
+            int64_t format_allocated_size = bdrv_get_format_allocated_size(bs);
+            if (format_allocated_size >= 0) {
+                check->format_unallocated_size =
+                    file_size - format_allocated_size;
+                check->has_format_unallocated_size = true;
+            }
+        }
+    }
+
     return 0;
 }
 
-- 
2.11.1


Re: [Qemu-devel] [PATCH 5/7] qemu-img check: add format unallocated size
Posted by Eric Blake, 59 weeks ago
On 05/25/2017 10:26 AM, Vladimir Sementsov-Ogievskiy wrote:
> Shows format 'sparseness' of the image top level.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  qapi/block-core.json |  3 ++-
>  qemu-img.c           | 19 +++++++++++++++++++
>  2 files changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/qapi/block-core.json b/qapi/block-core.json
> index ea0b3e8b13..c7ed5dc970 100644
> --- a/qapi/block-core.json
> +++ b/qapi/block-core.json
> @@ -185,7 +185,8 @@
>             '*image-end-offset': 'int', '*corruptions': 'int', '*leaks': 'int',
>             '*corruptions-fixed': 'int', '*leaks-fixed': 'int',
>             '*total-clusters': 'int', '*allocated-clusters': 'int',
> -           '*fragmented-clusters': 'int', '*compressed-clusters': 'int' } }
> +           '*fragmented-clusters': 'int', '*compressed-clusters': 'int',
> +           '*format-unallocated-size': 'uint64'} }

Missing documentation (including a since 2.10 blurb).

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

[Qemu-devel] [PATCH 6/7] qemu-img check: add file-size
Posted by Vladimir Sementsov-Ogievskiy, 59 weeks ago
Add bdrv_getlength() of underlying bs->file->bs, to improve
'Format unallocated size' section of qemu-img check output.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 qapi/block-core.json |  2 +-
 qemu-img.c           | 11 ++++++++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/qapi/block-core.json b/qapi/block-core.json
index c7ed5dc970..f720a29512 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -186,7 +186,7 @@
            '*corruptions-fixed': 'int', '*leaks-fixed': 'int',
            '*total-clusters': 'int', '*allocated-clusters': 'int',
            '*fragmented-clusters': 'int', '*compressed-clusters': 'int',
-           '*format-unallocated-size': 'uint64'} }
+           '*format-unallocated-size': 'uint64', '*file-size': 'uint64'} }
 
 ##
 # @MapEntry:
diff --git a/qemu-img.c b/qemu-img.c
index cbd09148d2..08a2b5ba54 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -603,10 +603,13 @@ static void dump_human_image_check(ImageCheck *check, bool quiet)
     }
 
     if (check->has_format_unallocated_size) {
-        char u_buf[128];
-        qprintf(quiet, "Format unallocated size: %s\n",
+        char buf[128], u_buf[128];
+        assert(check->has_file_size);
+        qprintf(quiet, "Format unallocated size: %s/%s = %0.2f%%\n",
                 get_human_readable_size(u_buf, sizeof(u_buf),
-                                        check->format_unallocated_size));
+                                        check->format_unallocated_size),
+                get_human_readable_size(buf, sizeof(buf), check->file_size),
+                check->format_unallocated_size * 100.0 / check->file_size);
     }
 }
 
@@ -650,6 +653,8 @@ static int collect_image_check(BlockDriverState *bs,
         int64_t file_size = bdrv_getlength(bs->file->bs);
         if (file_size >= 0) {
             int64_t format_allocated_size = bdrv_get_format_allocated_size(bs);
+            check->file_size = file_size;
+            check->has_file_size = true;
             if (format_allocated_size >= 0) {
                 check->format_unallocated_size =
                     file_size - format_allocated_size;
-- 
2.11.1


Re: [Qemu-devel] [PATCH 6/7] qemu-img check: add file-size
Posted by Eric Blake, 59 weeks ago
On 05/25/2017 10:26 AM, Vladimir Sementsov-Ogievskiy wrote:
> Add bdrv_getlength() of underlying bs->file->bs, to improve
> 'Format unallocated size' section of qemu-img check output.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  qapi/block-core.json |  2 +-
>  qemu-img.c           | 11 ++++++++---
>  2 files changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/qapi/block-core.json b/qapi/block-core.json
> index c7ed5dc970..f720a29512 100644
> --- a/qapi/block-core.json
> +++ b/qapi/block-core.json
> @@ -186,7 +186,7 @@
>             '*corruptions-fixed': 'int', '*leaks-fixed': 'int',
>             '*total-clusters': 'int', '*allocated-clusters': 'int',
>             '*fragmented-clusters': 'int', '*compressed-clusters': 'int',
> -           '*format-unallocated-size': 'uint64'} }
> +           '*format-unallocated-size': 'uint64', '*file-size': 'uint64'} }

Missing documentation, including a since 2.10 blurb.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

[Qemu-devel] [PATCH 7/7] block: rename _get_allocated_file_size() to _get_fs_allocated_size()
Posted by Vladimir Sementsov-Ogievskiy, 59 weeks ago
To be in contrast with _get_format_allocated_size()

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 block.c                   |  8 ++++----
 block/file-posix.c        | 14 +++++---------
 block/file-win32.c        |  8 +++-----
 block/gluster.c           |  8 ++++----
 block/nfs.c               |  8 ++++----
 block/qapi.c              |  2 +-
 block/sheepdog.c          |  8 ++++----
 block/vmdk.c              |  8 ++++----
 include/block/block.h     |  2 +-
 include/block/block_int.h |  2 +-
 10 files changed, 31 insertions(+), 37 deletions(-)

diff --git a/block.c b/block.c
index 6e1a435490..9f4bb37c54 100644
--- a/block.c
+++ b/block.c
@@ -3391,17 +3391,17 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp)
  * Size of allocated in underlying file system area. Sparseness is taken into
  * account for sparse file systems. Return < 0 if error or unknown.
  */
-int64_t bdrv_get_allocated_file_size(BlockDriverState *bs)
+int64_t bdrv_get_fs_allocated_size(BlockDriverState *bs)
 {
     BlockDriver *drv = bs->drv;
     if (!drv) {
         return -ENOMEDIUM;
     }
-    if (drv->bdrv_get_allocated_file_size) {
-        return drv->bdrv_get_allocated_file_size(bs);
+    if (drv->bdrv_get_fs_allocated_size) {
+        return drv->bdrv_get_fs_allocated_size(bs);
     }
     if (bs->file) {
-        return bdrv_get_allocated_file_size(bs->file->bs);
+        return bdrv_get_fs_allocated_size(bs->file->bs);
     }
     return -ENOTSUP;
 }
diff --git a/block/file-posix.c b/block/file-posix.c
index 4354d49642..46ca4728b3 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -1829,7 +1829,7 @@ static int64_t raw_getlength(BlockDriverState *bs)
 }
 #endif
 
-static int64_t raw_get_allocated_file_size(BlockDriverState *bs)
+static int64_t raw_get_fs_allocated_size(BlockDriverState *bs)
 {
     struct stat st;
     BDRVRawState *s = bs->opaque;
@@ -2218,8 +2218,7 @@ BlockDriver bdrv_file = {
     .bdrv_truncate = raw_truncate,
     .bdrv_getlength = raw_getlength,
     .bdrv_get_info = raw_get_info,
-    .bdrv_get_allocated_file_size
-                        = raw_get_allocated_file_size,
+    .bdrv_get_fs_allocated_size = raw_get_fs_allocated_size,
     .bdrv_check_perm = raw_check_perm,
     .bdrv_set_perm   = raw_set_perm,
     .bdrv_abort_perm_update = raw_abort_perm_update,
@@ -2679,8 +2678,7 @@ static BlockDriver bdrv_host_device = {
     .bdrv_truncate      = raw_truncate,
     .bdrv_getlength	= raw_getlength,
     .bdrv_get_info = raw_get_info,
-    .bdrv_get_allocated_file_size
-                        = raw_get_allocated_file_size,
+    .bdrv_get_fs_allocated_size = raw_get_fs_allocated_size,
     .bdrv_check_perm = raw_check_perm,
     .bdrv_set_perm   = raw_set_perm,
     .bdrv_abort_perm_update = raw_abort_perm_update,
@@ -2803,8 +2801,7 @@ static BlockDriver bdrv_host_cdrom = {
     .bdrv_truncate      = raw_truncate,
     .bdrv_getlength      = raw_getlength,
     .has_variable_length = true,
-    .bdrv_get_allocated_file_size
-                        = raw_get_allocated_file_size,
+    .bdrv_get_fs_allocated_size = raw_get_fs_allocated_size,
 
     /* removable device support */
     .bdrv_is_inserted   = cdrom_is_inserted,
@@ -2933,8 +2930,7 @@ static BlockDriver bdrv_host_cdrom = {
     .bdrv_truncate      = raw_truncate,
     .bdrv_getlength      = raw_getlength,
     .has_variable_length = true,
-    .bdrv_get_allocated_file_size
-                        = raw_get_allocated_file_size,
+    .bdrv_get_fs_allocated_size = raw_get_fs_allocated_size,
 
     /* removable device support */
     .bdrv_is_inserted   = cdrom_is_inserted,
diff --git a/block/file-win32.c b/block/file-win32.c
index 8f14f0bdcd..e246b8954b 100644
--- a/block/file-win32.c
+++ b/block/file-win32.c
@@ -524,7 +524,7 @@ static int64_t raw_getlength(BlockDriverState *bs)
     return l.QuadPart;
 }
 
-static int64_t raw_get_allocated_file_size(BlockDriverState *bs)
+static int64_t raw_get_fs_allocated_size(BlockDriverState *bs)
 {
     typedef DWORD (WINAPI * get_compressed_t)(const char *filename,
                                               DWORD * high);
@@ -604,8 +604,7 @@ BlockDriver bdrv_file = {
 
     .bdrv_truncate	= raw_truncate,
     .bdrv_getlength	= raw_getlength,
-    .bdrv_get_allocated_file_size
-                        = raw_get_allocated_file_size,
+    .bdrv_get_fs_allocated_size = raw_get_fs_allocated_size,
 
     .create_opts        = &raw_create_opts,
 };
@@ -773,8 +772,7 @@ static BlockDriver bdrv_host_device = {
     .bdrv_getlength      = raw_getlength,
     .has_variable_length = true,
 
-    .bdrv_get_allocated_file_size
-                        = raw_get_allocated_file_size,
+    .bdrv_get_fs_allocated_size = raw_get_fs_allocated_size,
 };
 
 static void bdrv_file_init(void)
diff --git a/block/gluster.c b/block/gluster.c
index 7c76cd0988..4509602d83 100644
--- a/block/gluster.c
+++ b/block/gluster.c
@@ -1407,7 +1407,7 @@ static BlockDriver bdrv_gluster = {
     .bdrv_close                   = qemu_gluster_close,
     .bdrv_create                  = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
-    .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
+    .bdrv_get_fs_allocated_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
     .bdrv_co_readv                = qemu_gluster_co_readv,
     .bdrv_co_writev               = qemu_gluster_co_writev,
@@ -1435,7 +1435,7 @@ static BlockDriver bdrv_gluster_tcp = {
     .bdrv_close                   = qemu_gluster_close,
     .bdrv_create                  = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
-    .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
+    .bdrv_get_fs_allocated_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
     .bdrv_co_readv                = qemu_gluster_co_readv,
     .bdrv_co_writev               = qemu_gluster_co_writev,
@@ -1463,7 +1463,7 @@ static BlockDriver bdrv_gluster_unix = {
     .bdrv_close                   = qemu_gluster_close,
     .bdrv_create                  = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
-    .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
+    .bdrv_get_fs_allocated_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
     .bdrv_co_readv                = qemu_gluster_co_readv,
     .bdrv_co_writev               = qemu_gluster_co_writev,
@@ -1497,7 +1497,7 @@ static BlockDriver bdrv_gluster_rdma = {
     .bdrv_close                   = qemu_gluster_close,
     .bdrv_create                  = qemu_gluster_create,
     .bdrv_getlength               = qemu_gluster_getlength,
-    .bdrv_get_allocated_file_size = qemu_gluster_allocated_file_size,
+    .bdrv_get_fs_allocated_size = qemu_gluster_allocated_file_size,
     .bdrv_truncate                = qemu_gluster_truncate,
     .bdrv_co_readv                = qemu_gluster_co_readv,
     .bdrv_co_writev               = qemu_gluster_co_writev,
diff --git a/block/nfs.c b/block/nfs.c
index 848b2c0bb0..0aa5288a07 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -719,7 +719,7 @@ static int nfs_has_zero_init(BlockDriverState *bs)
 
 /* Called (via nfs_service) with QemuMutex held.  */
 static void
-nfs_get_allocated_file_size_cb(int ret, struct nfs_context *nfs, void *data,
+nfs_get_fs_allocated_size_cb(int ret, struct nfs_context *nfs, void *data,
                                void *private_data)
 {
     NFSRPC *task = private_data;
@@ -734,7 +734,7 @@ nfs_get_allocated_file_size_cb(int ret, struct nfs_context *nfs, void *data,
     bdrv_wakeup(task->bs);
 }
 
-static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)
+static int64_t nfs_get_fs_allocated_size(BlockDriverState *bs)
 {
     NFSClient *client = bs->opaque;
     NFSRPC task = {0};
@@ -747,7 +747,7 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)
 
     task.bs = bs;
     task.st = &st;
-    if (nfs_fstat_async(client->context, client->fh, nfs_get_allocated_file_size_cb,
+    if (nfs_fstat_async(client->context, client->fh, nfs_get_fs_allocated_size_cb,
                         &task) != 0) {
         return -ENOMEM;
     }
@@ -880,7 +880,7 @@ static BlockDriver bdrv_nfs = {
     .create_opts                    = &nfs_create_opts,
 
     .bdrv_has_zero_init             = nfs_has_zero_init,
-    .bdrv_get_allocated_file_size   = nfs_get_allocated_file_size,
+    .bdrv_get_fs_allocated_size   = nfs_get_fs_allocated_size,
     .bdrv_truncate                  = nfs_file_truncate,
 
     .bdrv_file_open                 = nfs_file_open,
diff --git a/block/qapi.c b/block/qapi.c
index d249d97142..6dc3575785 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -246,7 +246,7 @@ void bdrv_query_image_info(BlockDriverState *bs,
     info->filename        = g_strdup(bs->filename);
     info->format          = g_strdup(bdrv_get_format_name(bs));
     info->virtual_size    = size;
-    info->actual_size     = bdrv_get_allocated_file_size(bs);
+    info->actual_size     = bdrv_get_fs_allocated_size(bs);
     info->has_actual_size = info->actual_size >= 0;
     if (bdrv_is_encrypted(bs)) {
         info->encrypted = true;
diff --git a/block/sheepdog.c b/block/sheepdog.c
index a18315a1ca..d6195981d4 100644
--- a/block/sheepdog.c
+++ b/block/sheepdog.c
@@ -3003,7 +3003,7 @@ sd_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
     return ret;
 }
 
-static int64_t sd_get_allocated_file_size(BlockDriverState *bs)
+static int64_t sd_get_fs_allocated_size(BlockDriverState *bs)
 {
     BDRVSheepdogState *s = bs->opaque;
     SheepdogInode *inode = &s->inode;
@@ -3066,7 +3066,7 @@ static BlockDriver bdrv_sheepdog = {
     .bdrv_create    = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
-    .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
+    .bdrv_get_fs_allocated_size = sd_get_fs_allocated_size,
     .bdrv_truncate  = sd_truncate,
 
     .bdrv_co_readv  = sd_co_readv,
@@ -3102,7 +3102,7 @@ static BlockDriver bdrv_sheepdog_tcp = {
     .bdrv_create    = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
-    .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
+    .bdrv_get_fs_allocated_size = sd_get_fs_allocated_size,
     .bdrv_truncate  = sd_truncate,
 
     .bdrv_co_readv  = sd_co_readv,
@@ -3138,7 +3138,7 @@ static BlockDriver bdrv_sheepdog_unix = {
     .bdrv_create    = sd_create,
     .bdrv_has_zero_init = bdrv_has_zero_init_1,
     .bdrv_getlength = sd_getlength,
-    .bdrv_get_allocated_file_size = sd_get_allocated_file_size,
+    .bdrv_get_fs_allocated_size = sd_get_fs_allocated_size,
     .bdrv_truncate  = sd_truncate,
 
     .bdrv_co_readv  = sd_co_readv,
diff --git a/block/vmdk.c b/block/vmdk.c
index 55581b03fe..bfb53204c6 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -2134,14 +2134,14 @@ static coroutine_fn int vmdk_co_flush(BlockDriverState *bs)
     return ret;
 }
 
-static int64_t vmdk_get_allocated_file_size(BlockDriverState *bs)
+static int64_t vmdk_get_fs_allocated_size(BlockDriverState *bs)
 {
     int i;
     int64_t ret = 0;
     int64_t r;
     BDRVVmdkState *s = bs->opaque;
 
-    ret = bdrv_get_allocated_file_size(bs->file->bs);
+    ret = bdrv_get_fs_allocated_size(bs->file->bs);
     if (ret < 0) {
         return ret;
     }
@@ -2149,7 +2149,7 @@ static int64_t vmdk_get_allocated_file_size(BlockDriverState *bs)
         if (s->extents[i].file == bs->file) {
             continue;
         }
-        r = bdrv_get_allocated_file_size(s->extents[i].file->bs);
+        r = bdrv_get_fs_allocated_size(s->extents[i].file->bs);
         if (r < 0) {
             return r;
         }
@@ -2363,7 +2363,7 @@ static BlockDriver bdrv_vmdk = {
     .bdrv_create                  = vmdk_create,
     .bdrv_co_flush_to_disk        = vmdk_co_flush,
     .bdrv_co_get_block_status     = vmdk_co_get_block_status,
-    .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size,
+    .bdrv_get_fs_allocated_size = vmdk_get_fs_allocated_size,
     .bdrv_has_zero_init           = vmdk_has_zero_init,
     .bdrv_get_specific_info       = vmdk_get_specific_info,
     .bdrv_refresh_limits          = vmdk_refresh_limits,
diff --git a/include/block/block.h b/include/block/block.h
index c36b9ccae4..11ec88d18d 100644
--- a/include/block/block.h
+++ b/include/block/block.h
@@ -303,7 +303,7 @@ void bdrv_refresh_filename(BlockDriverState *bs);
 int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp);
 int64_t bdrv_nb_sectors(BlockDriverState *bs);
 int64_t bdrv_getlength(BlockDriverState *bs);
-int64_t bdrv_get_allocated_file_size(BlockDriverState *bs);
+int64_t bdrv_get_fs_allocated_size(BlockDriverState *bs);
 int64_t bdrv_get_format_allocated_size(BlockDriverState *bs);
 void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr);
 void bdrv_refresh_limits(BlockDriverState *bs, Error **errp);
diff --git a/include/block/block_int.h b/include/block/block_int.h
index e562fa7a5a..ab58746148 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -207,7 +207,7 @@ struct BlockDriver {
 
     int64_t (*bdrv_getlength)(BlockDriverState *bs);
     bool has_variable_length;
-    int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs);
+    int64_t (*bdrv_get_fs_allocated_size)(BlockDriverState *bs);
     int64_t (*bdrv_get_format_allocated_size)(BlockDriverState *bs);
 
     int coroutine_fn (*bdrv_co_pwritev_compressed)(BlockDriverState *bs,
-- 
2.11.1


Re: [Qemu-devel] [PATCH 7/7] block: rename _get_allocated_file_size() to _get_fs_allocated_size()
Posted by Vladimir Sementsov-Ogievskiy, 59 weeks ago
25.05.2017 18:26, Vladimir Sementsov-Ogievskiy wrote:
> To be in contrast with _get_format_allocated_size()


Sorry for broken indents in this patch, I'll fix them in the next 
version. Waiting for other comments.


-- 
Best regards,
Vladimir


Re: [Qemu-devel] [PATCH 7/7] block: rename _get_allocated_file_size() to _get_fs_allocated_size()
Posted by Eric Blake, 59 weeks ago
On 05/25/2017 10:26 AM, Vladimir Sementsov-Ogievskiy wrote:
> To be in contrast with _get_format_allocated_size()
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  block.c                   |  8 ++++----
>  block/file-posix.c        | 14 +++++---------
>  block/file-win32.c        |  8 +++-----
>  block/gluster.c           |  8 ++++----
>  block/nfs.c               |  8 ++++----
>  block/qapi.c              |  2 +-
>  block/sheepdog.c          |  8 ++++----
>  block/vmdk.c              |  8 ++++----
>  include/block/block.h     |  2 +-
>  include/block/block_int.h |  2 +-
>  10 files changed, 31 insertions(+), 37 deletions(-)

Bikeshedding: is 'protocol' a better name than 'fs'? Unfortunately, it's
longer.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org