From patchwork Fri May 14 01:39:40 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Drewry X-Patchwork-Id: 99513 X-Patchwork-Delegate: agk@redhat.com Received: from mx02.colomx.prod.int.phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4E1gSRl032656 for ; Fri, 14 May 2010 01:43:04 GMT Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx02.colomx.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4E1e7FM008224; Thu, 13 May 2010 21:40:08 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4E1e5D7014128 for ; Thu, 13 May 2010 21:40:05 -0400 Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.11]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4E1dxJs010624; Thu, 13 May 2010 21:40:00 -0400 Received: from mail-gy0-f174.google.com (mail-gy0-f174.google.com [209.85.160.174]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4E1dn8J000781; Thu, 13 May 2010 21:39:50 -0400 Received: by gyg13 with SMTP id 13so931588gyg.33 for ; Thu, 13 May 2010 18:39:49 -0700 (PDT) Received: by 10.151.28.14 with SMTP id f14mr1110495ybj.398.1273801189614; Thu, 13 May 2010 18:39:49 -0700 (PDT) Received: from z600 (208-191-153-215.lightspeed.austtx.sbcglobal.net [208.191.153.215]) by mx.google.com with ESMTPS id k30sm13697048ybb.7.2010.05.13.18.39.48 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 13 May 2010 18:39:48 -0700 (PDT) Date: Thu, 13 May 2010 20:39:40 -0500 From: Will Drewry To: dm-devel@redhat.com Message-ID: <20100514013940.GA3523@z600> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-RedHat-Spam-Score: -0.001 (SPF_PASS) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-Scanned-By: MIMEDefang 2.67 on 10.5.110.11 X-loop: dm-devel@redhat.com Cc: agk@redhat.com Subject: [dm-devel] [RFC PATCH] dm: allow a dm-fs-style device to be shared via dm-ioctl X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 14 May 2010 01:43:04 +0000 (UTC) diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c index d7500e1..8dc5fd8 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c @@ -1112,28 +1112,9 @@ static int populate_table(struct dm_table *table, next = spec->next; } - r = dm_table_set_type(table); - if (r) { - DMWARN("unable to set table type"); - return r; - } - return dm_table_complete(table); } -static int table_prealloc_integrity(struct dm_table *t, - struct mapped_device *md) -{ - struct list_head *devices = dm_table_get_devices(t); - struct dm_dev_internal *dd; - - list_for_each_entry(dd, devices, list) - if (bdev_get_integrity(dd->dm_dev.bdev)) - return blk_integrity_register(dm_disk(md), NULL); - - return 0; -} - static int table_load(struct dm_ioctl *param, size_t param_size) { int r; @@ -1155,7 +1136,7 @@ static int table_load(struct dm_ioctl *param, size_t param_size) goto out; } - r = table_prealloc_integrity(t, md); + r = dm_table_prealloc_integrity(t, md); if (r) { DMERR("%s: could not register integrity profile.", dm_device_name(md)); @@ -1163,13 +1144,6 @@ static int table_load(struct dm_ioctl *param, size_t param_size) goto out; } - r = dm_table_alloc_md_mempools(t); - if (r) { - DMWARN("unable to allocate mempools for this table"); - dm_table_destroy(t); - goto out; - } - down_write(&_hash_lock); hc = dm_get_mdptr(md); if (!hc || hc->md != md) { @@ -1637,6 +1611,44 @@ void dm_interface_exit(void) dm_hash_exit(); } + +/** + * dm_ioctl_export - Permanently export a mapped device via the ioctl interface + * @md: Pointer to mapped_device + * @name: Buffer (size DM_NAME_LEN) for name + * @uuid: Buffer (size DM_UUID_LEN) for uuid or NULL if not desired + */ +int dm_ioctl_export(struct mapped_device *md, const char *name, const char *uuid) +{ + int r = 0; + struct hash_cell *hc; + + if (!md) { + r = -ENXIO; + goto out; + } + + /* The name and uuid can only be set once. */ + mutex_lock(&dm_hash_cells_mutex); + hc = dm_get_mdptr(md); + mutex_unlock(&dm_hash_cells_mutex); + if (hc) { + DMERR("%s: already exported", dm_device_name(md)); + r = -ENXIO; + goto out; + } + + r = dm_hash_insert(name, uuid, md); + if (r) { + DMERR("%s: could not export as '%s'", dm_device_name(md), name); + goto out; + } + + /* Let udev know we've changed. */ + dm_kobject_uevent(md, KOBJ_CHANGE, dm_get_event_nr(md)); +out: + return r; +} /** * dm_copy_name_and_uuid - Copy mapped device name & uuid into supplied buffers * @md: Pointer to mapped_device diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 9924ea2..66726d1 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -900,7 +900,7 @@ static int setup_indexes(struct dm_table *t) /* * Builds the btree to index the map. */ -int dm_table_complete(struct dm_table *t) +int dm_table_build_index(struct dm_table *t) { int r = 0; unsigned int leaf_nodes; @@ -919,6 +919,48 @@ int dm_table_complete(struct dm_table *t) return r; } + +/* + * Prepares the table for use by building the indices, + * setting the type, and allocating mempools. + */ +int dm_table_complete(struct dm_table *t) +{ + int r = 0; + + r = dm_table_build_index(t); + if (r) { + DMWARN("unable to build btrees"); + return r; + } + r = dm_table_set_type(t); + if (r) { + DMWARN("unable to set table type"); + return r; + } + r = dm_table_alloc_md_mempools(t); + if (r) + DMWARN("unable to allocate mempools"); + + return r; +} + +/* + * Register the mapped device for blk_integrity support if + * the underlying devices support it. + */ +int dm_table_prealloc_integrity(struct dm_table *t, struct mapped_device *md) +{ + struct list_head *devices = dm_table_get_devices(t); + struct dm_dev_internal *dd; + + list_for_each_entry(dd, devices, list) + if (bdev_get_integrity(dd->dm_dev.bdev)) + return blk_integrity_register(dm_disk(md), NULL); + + return 0; +} + static DEFINE_MUTEX(_event_lock); void dm_table_event_callback(struct dm_table *t, void (*fn)(void *), void *context) diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index 1381cd9..95fea4c 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -215,6 +215,18 @@ void dm_set_mdptr(struct mapped_device *md, void *ptr); void *dm_get_mdptr(struct mapped_device *md); /* + * Export the device via the ioctl interface + */ +int dm_ioctl_export(struct mapped_device *md, const char *name, + const char *uuid); + +/* + * Suspend feature flags + */ +#define DM_SUSPEND_LOCKFS_FLAG (1 << 0) +#define DM_SUSPEND_NOFLUSH_FLAG (1 << 1) + +/* * A device can still be used while suspended, but I/O is deferred. */ int dm_suspend(struct mapped_device *md, unsigned suspend_flags); @@ -268,6 +280,11 @@ int dm_table_add_target(struct dm_table *t, const char *type, int dm_table_complete(struct dm_table *t); /* + * Optionally add support for block integrity. + */ +int dm_table_prealloc_integrity(struct dm_table *t, struct mapped_device *md); + +/* * Unplug all devices in a table. */ void dm_table_unplug_all(struct dm_table *t);