From patchwork Sat Jan 5 12:05:10 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kusanagi Kouichi X-Patchwork-Id: 209666 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id C8FA42C0090 for ; Sat, 5 Jan 2013 23:05:33 +1100 (EST) Received: from localhost ([::1]:59721 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrSVH-0007oY-Ft for incoming@patchwork.ozlabs.org; Sat, 05 Jan 2013 07:05:31 -0500 Received: from eggs.gnu.org ([208.118.235.92]:42744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrSVA-0007nc-6A for qemu-devel@nongnu.org; Sat, 05 Jan 2013 07:05:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TrSV8-0001l3-EO for qemu-devel@nongnu.org; Sat, 05 Jan 2013 07:05:24 -0500 Received: from msa101.auone-net.jp ([61.117.18.161]:33772) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TrSV7-0001ia-UC for qemu-devel@nongnu.org; Sat, 05 Jan 2013 07:05:22 -0500 Received: from ppp.dion.ne.jp (ZR168023.ppp.dion.ne.jp [222.14.168.23]) by msa101.auone-net.jp (au one net msa) with ESMTP id 388913E403B; Sat, 5 Jan 2013 21:05:10 +0900 (JST) Date: Sat, 5 Jan 2013 21:05:10 +0900 From: Kusanagi Kouichi To: qemu-devel@nongnu.org MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Message-Id: <20130105120511.388913E403B@msa101.auone-net.jp> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 61.117.18.161 Cc: Kevin Wolf , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH] raw-posix: Support discard on more filesystems 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 Linux 2.6.38 introduced the filesystem independent interface to deallocate part of a file. As of Linux 3.7, btrfs, ext4, ocfs2, tmpfs and xfs support it. Signed-off-by: Kusanagi Kouichi --- block/raw-posix.c | 22 ++++++++++++++++++++-- configure | 19 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index 87d888e..66ba0b5 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -59,6 +59,9 @@ #ifdef CONFIG_FIEMAP #include #endif +#ifdef CONFIG_FALLOCATE_PUNCH_HOLE +#include +#endif #if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) #include #include @@ -1098,15 +1101,30 @@ static int xfs_discard(BDRVRawState *s, int64_t sector_num, int nb_sectors) static coroutine_fn int raw_co_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) { -#ifdef CONFIG_XFS +#if defined(CONFIG_FALLOCATE_PUNCH_HOLE) || defined(CONFIG_XFS) BDRVRawState *s = bs->opaque; +#endif + int ret = 0; +#ifdef CONFIG_FALLOCATE_PUNCH_HOLE + do { + if (fallocate(s->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + sector_num << BDRV_SECTOR_BITS, + nb_sectors << BDRV_SECTOR_BITS) == 0) { + return 0; + } + } while (errno == EINTR); + + ret = -errno; +#endif + +#ifdef CONFIG_XFS if (s->is_xfs) { return xfs_discard(s, sector_num, nb_sectors); } #endif - return 0; + return ret; } static QEMUOptionParameter raw_create_options[] = { diff --git a/configure b/configure index 837a84a..ff2e373 100755 --- a/configure +++ b/configure @@ -2576,6 +2576,22 @@ if compile_prog "" "" ; then fallocate=yes fi +# check for fallocate hole punching +fallocate_punch_hole=no +cat > $TMPC << EOF +#include +#include + +int main(void) +{ + fallocate(0, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, 0, 0); + return 0; +} +EOF +if compile_prog "" "" ; then + fallocate_punch_hole=yes +fi + # check for sync_file_range sync_file_range=no cat > $TMPC << EOF @@ -3485,6 +3501,9 @@ fi if test "$fallocate" = "yes" ; then echo "CONFIG_FALLOCATE=y" >> $config_host_mak fi +if test "$fallocate_punch_hole" = "yes" ; then + echo "CONFIG_FALLOCATE_PUNCH_HOLE=y" >> $config_host_mak +fi if test "$sync_file_range" = "yes" ; then echo "CONFIG_SYNC_FILE_RANGE=y" >> $config_host_mak fi