From patchwork Mon Jan 14 15:26:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 211811 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 D90CE2C0098 for ; Tue, 15 Jan 2013 02:39:45 +1100 (EST) Received: from localhost ([::1]:59409 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tulxf-0006yn-V6 for incoming@patchwork.ozlabs.org; Mon, 14 Jan 2013 10:28:31 -0500 Received: from eggs.gnu.org ([208.118.235.92]:32920) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TulwU-000401-FO for qemu-devel@nongnu.org; Mon, 14 Jan 2013 10:27:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TulwO-0002mS-0Z for qemu-devel@nongnu.org; Mon, 14 Jan 2013 10:27:18 -0500 Received: from mail-qa0-f42.google.com ([209.85.216.42]:36209) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TulwN-0002mK-TA for qemu-devel@nongnu.org; Mon, 14 Jan 2013 10:27:11 -0500 Received: by mail-qa0-f42.google.com with SMTP id hg5so1528802qab.1 for ; Mon, 14 Jan 2013 07:27:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=5G3aNIZj46H4Cd48VMdBiyFk5xKzC/8FrYcToj94mL0=; b=GfTVwtrgTKjC/lBIs67UjxvQpjUT4sfnZ9iWsoEyGQY0Y7yw/VhnieenfYT674irG0 xprdCkrrkwmVsDY/B34RFYVXLy+a2WdQVHGf8mgKYQj/qxCKeJigs61cF1KjxdJWWp2Y TusWYP/EFRMUYi0f2CsGJysCUZD1/FUdQalLlV6RIF35O+57YuZFk+ZL5yUeBQznfl0L EScwEQQGqY5FDtMKdUi8eN3ehCBSAoVP0OJ4w62gpQpVjCWqZlFsDuaK1Qts4cOv84Pp adPHzWLTZdPTnE5az/QmY+tzHLjGlphMosPTBpiaZlrXq44qzaGx4Gi0uiseFXsPiSLc gjKw== X-Received: by 10.224.195.138 with SMTP id ec10mr71858144qab.3.1358177231535; Mon, 14 Jan 2013 07:27:11 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-179-137.ip50.fastwebnet.it. [93.34.179.137]) by mx.google.com with ESMTPS id t2sm6157728qav.1.2013.01.14.07.27.09 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 14 Jan 2013 07:27:10 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 14 Jan 2013 16:26:54 +0100 Message-Id: <1358177218-16802-4-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1358177218-16802-1-git-send-email-pbonzini@redhat.com> References: <1358177218-16802-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.216.42 Cc: kwolf@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH 3/7] raw: support discard on block devices 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 Block devices use a ioctl instead of fallocate, so add a separate implementation. Signed-off-by: Paolo Bonzini --- block/raw-posix.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/block/raw-posix.c b/block/raw-posix.c index b647cfb..1d32139 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1345,6 +1345,40 @@ static BlockDriverAIOCB *hdev_aio_ioctl(BlockDriverState *bs, return thread_pool_submit_aio(aio_worker, acb, cb, opaque); } +static coroutine_fn int hdev_co_discard(BlockDriverState *bs, + int64_t sector_num, int nb_sectors) +{ + BDRVRawState *s = bs->opaque; + int ret; + + if (s->has_discard == 0) { + return 0; + } + ret = fd_open(bs); + if (ret < 0) { + return ret; + } + + ret = -EOPNOTSUPP; +#ifdef BLKDISCARD + do { + uint64_t range[2] = { sector_num * 512, (uint64_t)nb_sectors * 512 }; + if (ioctl(s->fd, BLKDISCARD, range) == 0) { + return 0; + } + } while (errno == EINTR); + + ret = -errno; +#endif + if (ret == -ENODEV || ret == -ENOSYS || ret == -EOPNOTSUPP || + ret == -ENOTTY) { + s->has_discard = 0; + ret = 0; + } + return ret; + +} + #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) static int fd_open(BlockDriverState *bs) { @@ -1413,6 +1447,8 @@ static BlockDriver bdrv_host_device = { .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, .bdrv_aio_flush = raw_aio_flush,