From patchwork Thu Mar 17 14:30:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 8617591 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id F1D9C9F54C for ; Fri, 18 Mar 2016 10:01:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1BAB420361 for ; Fri, 18 Mar 2016 10:01:56 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2AABF2034B for ; Fri, 18 Mar 2016 10:01:55 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u2I9wsjd001449; Fri, 18 Mar 2016 05:58:55 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u2HEUd5h022705 for ; Thu, 17 Mar 2016 10:30:39 -0400 Received: from bfoster.bfoster (dhcp-41-24.bos.redhat.com [10.18.41.24]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2HEUdb0003136; Thu, 17 Mar 2016 10:30:39 -0400 Received: by bfoster.bfoster (Postfix, from userid 1000) id CE5EA125E70; Thu, 17 Mar 2016 10:30:37 -0400 (EDT) From: Brian Foster To: xfs@oss.sgi.com Date: Thu, 17 Mar 2016 10:30:35 -0400 Message-Id: <1458225037-24155-8-git-send-email-bfoster@redhat.com> In-Reply-To: <1458225037-24155-1-git-send-email-bfoster@redhat.com> References: <1458225037-24155-1-git-send-email-bfoster@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Fri, 18 Mar 2016 05:58:54 -0400 Cc: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@redhat.com Subject: [dm-devel] [RFC PATCH 7/9] dm thin: add method to provision space X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a hacky interface added to support the filesystem experiment for reserving blocks out of thin pools. The XFS POC uses this method provision space in the pool when blocks are allocated. The number of actual blocks allocated is returned, which is used to update the filesystem accounting. Signed-off-by: Brian Foster --- drivers/md/dm-thin.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c index ac770d89..00b7322 100644 --- a/drivers/md/dm-thin.c +++ b/drivers/md/dm-thin.c @@ -4389,6 +4389,52 @@ static int thin_get_reserved_space(struct dm_target *ti, sector_t *nr_sects) return 0; } +static int thin_provision_space(struct dm_target *ti, sector_t offset, sector_t len) +{ + struct thin_c *tc = ti->private; + struct pool *pool = tc->pool; + sector_t end; + dm_block_t pblock; + dm_block_t vblock; + int error; + struct dm_thin_lookup_result lookup; + sector_t count; + + if (!is_factor(offset, pool->sectors_per_block)) + return -EINVAL; + + if (!len || !is_factor(len, pool->sectors_per_block)) + return -EINVAL; + + end = offset + len; + + count = 0; + while (offset < end) { + vblock = offset / pool->sectors_per_block; + + error = dm_thin_find_block(tc->td, vblock, true, &lookup); + if (error == 0) + goto next; + if (error != -ENODATA) + return error; + + error = alloc_data_block(tc, &pblock); + if (error) + return error; + + error = dm_thin_insert_block(tc->td, vblock, pblock); + if (error) + return error; + + count += pool->sectors_per_block; +next: + offset += pool->sectors_per_block; + } + + /* XXX: int -> sector_t ! */ + return count; +} + static struct target_type thin_target = { .name = "thin", .version = {1, 18, 0}, @@ -4405,6 +4451,7 @@ static struct target_type thin_target = { .io_hints = thin_io_hints, .reserve_space = thin_reserve_space, .get_reserved_space = thin_get_reserved_space, + .provision_space = thin_provision_space, }; /*----------------------------------------------------------------*/