From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5gwG-00045o-W1 for qemu-devel@nongnu.org; Thu, 08 Mar 2012 12:15:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S5gwA-0004nu-JQ for qemu-devel@nongnu.org; Thu, 08 Mar 2012 12:15:40 -0500 Received: from mail-iy0-f173.google.com ([209.85.210.173]:47906) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S5gwA-0004n5-CP for qemu-devel@nongnu.org; Thu, 08 Mar 2012 12:15:34 -0500 Received: by mail-iy0-f173.google.com with SMTP id j26so1015616iaf.4 for ; Thu, 08 Mar 2012 09:15:33 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 8 Mar 2012 18:15:03 +0100 Message-Id: <1331226917-6658-4-git-send-email-pbonzini@redhat.com> In-Reply-To: <1331226917-6658-1-git-send-email-pbonzini@redhat.com> References: <1331226917-6658-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [RFC PATCH 03/17] block: add discard properties to BlockDriverInfo List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- 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; } 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; } -- 1.7.7.6