From patchwork Thu Mar 17 14:30:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 8617611 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6F9FFC0553 for ; Fri, 18 Mar 2016 10:02:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8060F20374 for ; Fri, 18 Mar 2016 10:02:08 +0000 (UTC) Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com [209.132.183.37]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7E3AE2034B for ; Fri, 18 Mar 2016 10:02:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2I9wsGv050314; Fri, 18 Mar 2016 05:58:55 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u2HEUc3G022680 for ; Thu, 17 Mar 2016 10:30:38 -0400 Received: from bfoster.bfoster (dhcp-41-24.bos.redhat.com [10.18.41.24]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2HEUcWM012254; Thu, 17 Mar 2016 10:30:38 -0400 Received: by bfoster.bfoster (Postfix, from userid 1000) id 5A2901201F4; Thu, 17 Mar 2016 10:30:37 -0400 (EDT) From: Brian Foster To: xfs@oss.sgi.com Date: Thu, 17 Mar 2016 10:30:30 -0400 Message-Id: <1458225037-24155-3-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.27 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 2/9] dm: add methods to set and get reserved 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=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 From: Mike Snitzer Signed-off-by: Mike Snitzer --- drivers/md/dm.c | 75 +++++++++++++++++++++++++++++++++++++++++++ include/linux/device-mapper.h | 5 +++ 2 files changed, 80 insertions(+) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index be49057..4da5d3e 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -664,6 +664,79 @@ out: return r; } +/* + * FIXME: factor out common helper that can be used by + * multiple block_device_operations -> target methods + * (including dm_blk_ioctl above) + */ + +static int dm_blk_reserve_space(struct block_device *bdev, sector_t nr_sects) +{ + struct mapped_device *md = bdev->bd_disk->private_data; + int srcu_idx; + struct dm_table *map; + struct dm_target *tgt; + int r = -EINVAL; + + map = dm_get_live_table(md, &srcu_idx); + + if (!map || !dm_table_get_size(map)) + goto out; + + /* We only support devices that have a single target */ + if (dm_table_get_num_targets(map) != 1) + goto out; + + tgt = dm_table_get_target(map, 0); + if (!tgt->type->reserve_space) + goto out; + + if (dm_suspended_md(md)) { + r = -EAGAIN; + goto out; + } + + r = tgt->type->reserve_space(tgt, nr_sects); +out: + dm_put_live_table(md, srcu_idx); + + return r; +} + +static int dm_blk_get_reserved_space(struct block_device *bdev, + sector_t *nr_sects) +{ + struct mapped_device *md = bdev->bd_disk->private_data; + int srcu_idx; + struct dm_table *map; + struct dm_target *tgt; + int r = -EINVAL; + + map = dm_get_live_table(md, &srcu_idx); + + if (!map || !dm_table_get_size(map)) + goto out; + + /* We only support devices that have a single target */ + if (dm_table_get_num_targets(map) != 1) + goto out; + + tgt = dm_table_get_target(map, 0); + if (!tgt->type->get_reserved_space) + goto out; + + if (dm_suspended_md(md)) { + r = -EAGAIN; + goto out; + } + + r = tgt->type->get_reserved_space(tgt, nr_sects); +out: + dm_put_live_table(md, srcu_idx); + + return r; +} + static struct dm_io *alloc_io(struct mapped_device *md) { return mempool_alloc(md->io_pool, GFP_NOIO); @@ -3723,6 +3796,8 @@ static const struct block_device_operations dm_blk_dops = { .ioctl = dm_blk_ioctl, .getgeo = dm_blk_getgeo, .pr_ops = &dm_pr_ops, + .reserve_space = dm_blk_reserve_space, + .get_reserved_space = dm_blk_get_reserved_space, .owner = THIS_MODULE }; diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index 0830c9e..540c772 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -116,6 +116,9 @@ typedef void (*dm_io_hints_fn) (struct dm_target *ti, */ typedef int (*dm_busy_fn) (struct dm_target *ti); +typedef int (*dm_reserve_space_fn) (struct dm_target *ti, sector_t nr_sects); +typedef int (*dm_get_reserved_space_fn) (struct dm_target *ti, sector_t *nr_sects); + void dm_error(const char *message); struct dm_dev { @@ -162,6 +165,8 @@ struct target_type { dm_busy_fn busy; dm_iterate_devices_fn iterate_devices; dm_io_hints_fn io_hints; + dm_reserve_space_fn reserve_space; + dm_get_reserved_space_fn get_reserved_space; /* For internal device-mapper use. */ struct list_head list;