From patchwork Fri Nov 11 20:56:00 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: e-t172 X-Patchwork-Id: 125298 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CD1E71007D8 for ; Sat, 12 Nov 2011 07:56:18 +1100 (EST) Received: from localhost ([::1]:36681 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROy90-0003HK-Cb for incoming@patchwork.ozlabs.org; Fri, 11 Nov 2011 15:56:14 -0500 Received: from eggs.gnu.org ([140.186.70.92]:51294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROy8v-0003Go-5Q for qemu-devel@nongnu.org; Fri, 11 Nov 2011 15:56:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ROy8t-0003uI-JB for qemu-devel@nongnu.org; Fri, 11 Nov 2011 15:56:09 -0500 Received: from phys.kobol.akegroup.org ([94.23.8.80]:47964) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ROy8t-0003uE-A8 for qemu-devel@nongnu.org; Fri, 11 Nov 2011 15:56:07 -0500 Received: from [192.168.0.3] (110.131.31.93.rev.sfr.net [93.31.131.110]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "e-t172", Issuer "AKE Group" (verified OK)) (Authenticated sender: e-t172) by kobol.akegroup.org (AKE Group Mail server) with ESMTPSA id 42C1E18B3AB; Fri, 11 Nov 2011 21:56:06 +0100 (CET) Message-ID: <4EBD8BE0.50908@akegroup.org> Date: Fri, 11 Nov 2011 21:56:00 +0100 From: e-t172 Organization: AKE Group User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: qemu-devel@nongnu.org X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 94.23.8.80 Cc: kwolf@redhat.com Subject: [Qemu-devel] [PATCH] block/raw-posix.c: add BLKDISCARD support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This adds ioctl(BLKDISCARD) (a.k.a "discard", "TRIM", "UNMAP", "hole punching") support for host devices. This is especially useful if the raw device is a SSD or some kind of thin-provisioned device. Cc: Kevin Wolf Signed-off-by: Etienne Dechamps --- block/raw-posix.c | 20 ++++++++++++++++++++ 1 files changed, 20 insertions(+), 0 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index a3de373..d6eac66 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -104,6 +104,10 @@ #define O_DIRECT O_DSYNC #endif +#ifndef BLKDISCARD +#define BLKDISCARD _IO(0x12, 119) +#endif + #define FTYPE_FILE 0 #define FTYPE_CD 1 #define FTYPE_FD 2 @@ -892,6 +896,21 @@ static int hdev_has_zero_init(BlockDriverState *bs) return 0; } +static int hdev_co_discard(BlockDriverState *bs, int64_t sector_num, + int nb_sectors) +{ + BDRVRawState *s = bs->opaque; + int fd = s->fd; + uint64_t range[2]; + + range[0] = sector_num << 9; + range[1] = nb_sectors << 9; + if (ioctl(fd, BLKDISCARD, &range)) { + return -errno; + } + return 0; +} + static BlockDriver bdrv_host_device = { .format_name = "host_device", .protocol_name = "host_device", @@ -902,6 +921,7 @@ static BlockDriver bdrv_host_device = { .bdrv_create = hdev_create, .create_options = raw_create_options, .bdrv_has_zero_init = hdev_has_zero_init, + .bdrv_co_discard = hdev_co_discard, .bdrv_aio_readv = raw_aio_readv, .bdrv_aio_writev = raw_aio_writev,