From patchwork Wed Jan 28 18:38:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 433912 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A702F140161 for ; Thu, 29 Jan 2015 05:40:44 +1100 (AEDT) Received: from localhost ([::1]:55386 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGXXe-0001fK-M6 for incoming@patchwork.ozlabs.org; Wed, 28 Jan 2015 13:40:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGXWp-00009M-F3 for qemu-devel@nongnu.org; Wed, 28 Jan 2015 13:39:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGXWo-0008SP-OY for qemu-devel@nongnu.org; Wed, 28 Jan 2015 13:39:51 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:11078 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGXWo-0008K7-Cn for qemu-devel@nongnu.org; Wed, 28 Jan 2015 13:39:50 -0500 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id t0SIcvLA017996; Wed, 28 Jan 2015 21:39:04 +0300 (MSK) From: "Denis V. Lunev" To: Date: Wed, 28 Jan 2015 21:38:53 +0300 Message-Id: <1422470338-20465-3-git-send-email-den@openvz.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422470338-20465-1-git-send-email-den@openvz.org> References: <1422470338-20465-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Cc: Kevin Wolf , Fam Zheng , Peter Lieven , qemu-devel@nongnu.org, Stefan Hajnoczi , "Denis V. Lunev" Subject: [Qemu-devel] [PATCH 2/7] block/raw-posix: create do_fallocate helper 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 The pattern do { if (fallocate(s->fd, mode, offset, len) == 0) { return 0; } } while (errno == EINTR); ret = translate_err(-errno); will be commonly useful in next patches. Create helper for it. Signed-off-by: Denis V. Lunev Reviewed-by: Max Reitz CC: Kevin Wolf CC: Stefan Hajnoczi CC: Peter Lieven CC: Fam Zheng --- block/raw-posix.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index 24300d0..2aa268a 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -902,6 +902,18 @@ static int translate_err(int err) return err; } +#if defined(CONFIG_FALLOCATE_PUNCH_HOLE) +static int do_fallocate(int fd, int mode, off_t offset, off_t len) +{ + do { + if (fallocate(fd, mode, offset, len) == 0) { + return 0; + } + } while (errno == EINTR); + return translate_err(-errno); +} +#endif + static ssize_t handle_aiocb_write_zeroes(RawPosixAIOData *aiocb) { int ret = -EOPNOTSUPP; @@ -965,14 +977,8 @@ static ssize_t handle_aiocb_discard(RawPosixAIOData *aiocb) #endif #ifdef CONFIG_FALLOCATE_PUNCH_HOLE - do { - if (fallocate(s->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, - aiocb->aio_offset, aiocb->aio_nbytes) == 0) { - return 0; - } - } while (errno == EINTR); - - ret = -errno; + ret = do_fallocate(s->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + aiocb->aio_offset, aiocb->aio_nbytes); #endif }