diff mbox

[RFC,03/17] block: add discard properties to BlockDriverInfo

Message ID 1331226917-6658-4-git-send-email-pbonzini@redhat.com
State New
Headers show

Commit Message

Paolo Bonzini March 8, 2012, 5:15 p.m. UTC
In the next patches we will declare the guest's semantics for discard
to be "always zero the data".  We need to know whether the operation
need to be emulated or can be passed down.  For this purpose we need
to know the semantics of the operation and its granularity.

The granularity may not be related to the cluster size (for example
"raw" does not have a cluster size), so add it separately.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 block.h       |    4 ++++
 block/qcow2.c |    2 ++
 qemu-io.c     |    5 ++++-
 3 files changed, 10 insertions(+), 1 deletions(-)

Comments

Kevin Wolf March 9, 2012, 4:47 p.m. UTC | #1
Am 08.03.2012 18:15, schrieb Paolo Bonzini:
> In the next patches we will declare the guest's semantics for discard
> to be "always zero the data".  We need to know whether the operation
> need to be emulated or can be passed down.  For this purpose we need
> to know the semantics of the operation and its granularity.
> 
> The granularity may not be related to the cluster size (for example
> "raw" does not have a cluster size), so add it separately.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  block.h       |    4 ++++
>  block/qcow2.c |    2 ++
>  qemu-io.c     |    5 ++++-
>  3 files changed, 10 insertions(+), 1 deletions(-)
> 
> diff --git a/block.h b/block.h
> index 48d0bf3..7feda73 100644
> --- a/block.h
> +++ b/block.h
> @@ -15,6 +15,10 @@ typedef struct BlockDriverInfo {
>      int cluster_size;
>      /* offset at which the VM state can be saved (0 if not possible) */
>      int64_t vm_state_offset;
> +    /* whether discard is guaranteed to zero bytes */
> +    bool discard_zeroes_data;
> +    /* discard granularity in sectors */
> +    int discard_granularity;

Why not in bytes? The arbitrary 512 byte units used in the block layer
were probably not the best idea ever and we shouldn't spread it further.

Kevin
diff mbox

Patch

diff --git a/block.h b/block.h
index 48d0bf3..7feda73 100644
--- a/block.h
+++ b/block.h
@@ -15,6 +15,10 @@  typedef struct BlockDriverInfo {
     int cluster_size;
     /* offset at which the VM state can be saved (0 if not possible) */
     int64_t vm_state_offset;
+    /* whether discard is guaranteed to zero bytes */
+    bool discard_zeroes_data;
+    /* discard granularity in sectors */
+    int discard_granularity;
 } BlockDriverInfo;
 
 typedef struct QEMUSnapshotInfo {
diff --git a/block/qcow2.c b/block/qcow2.c
index eb5ea48..2908484 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1256,6 +1256,8 @@  static int qcow2_get_info(BlockDriverState *bs, BlockDriverInfo *bdi)
     BDRVQcowState *s = bs->opaque;
     bdi->cluster_size = s->cluster_size;
     bdi->vm_state_offset = qcow2_vm_state_offset(s);
+    bdi->discard_zeroes_data = (bs->backing_hd == NULL);
+    bdi->discard_granularity = s->cluster_size / BDRV_SECTOR_SIZE;
     return 0;
 }
 
diff --git a/qemu-io.c b/qemu-io.c
index 3189530..8f28b6a 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -1437,7 +1437,7 @@  static const cmdinfo_t length_cmd = {
 static int info_f(int argc, char **argv)
 {
     BlockDriverInfo bdi;
-    char s1[64], s2[64];
+    char s1[64], s2[64], s3[64];
     int ret;
 
     if (bs->drv && bs->drv->format_name) {
@@ -1454,9 +1454,12 @@  static int info_f(int argc, char **argv)
 
     cvtstr(bdi.cluster_size, s1, sizeof(s1));
     cvtstr(bdi.vm_state_offset, s2, sizeof(s2));
+    cvtstr(bdi.discard_granularity * BDRV_SECTOR_SIZE, s3, sizeof(s3));
 
     printf("cluster size: %s\n", s1);
     printf("vm state offset: %s\n", s2);
+    printf("discard zeroes: %s\n", bdi.discard_zeroes_data ? "yes" : "no");
+    printf("discard granularity: %s\n", s3);
 
     return 0;
 }