From patchwork Tue Jun 8 03:25:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Drewry X-Patchwork-Id: 104860 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 o583Sjig010524 for ; Tue, 8 Jun 2010 03:29:21 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 o583QGq4014598; Mon, 7 Jun 2010 23:26:17 -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 o583QCt6021654 for ; Mon, 7 Jun 2010 23:26:12 -0400 Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.8]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o583Q7PA011401; Mon, 7 Jun 2010 23:26:07 -0400 Received: from mail-iw0-f174.google.com (mail-iw0-f174.google.com [209.85.214.174]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o583PvAG021812; Mon, 7 Jun 2010 23:25:58 -0400 Received: by iwn37 with SMTP id 37so5217068iwn.33 for ; Mon, 07 Jun 2010 20:25:57 -0700 (PDT) Received: by 10.231.141.27 with SMTP id k27mr5548998ibu.152.1275967557477; Mon, 07 Jun 2010 20:25:57 -0700 (PDT) Received: from localhost.localdomain (208-191-153-102.lightspeed.austtx.sbcglobal.net [208.191.153.102]) by mx.google.com with ESMTPS id d9sm23685924ibl.10.2010.06.07.20.25.54 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 07 Jun 2010 20:25:56 -0700 (PDT) From: Will Drewry To: dm-devel@redhat.com Date: Mon, 7 Jun 2010 22:25:23 -0500 Message-Id: <1275967524-24166-2-git-send-email-wad@chromium.org> In-Reply-To: <1274294304-30606-1-git-send-email-wad@chromium.org> References: <1274294304-30606-1-git-send-email-wad@chromium.org> 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.8 X-loop: dm-devel@redhat.com Cc: Michal Marek , Len Brown , Will Drewry , Mike Snitzer , Kiyoshi Ueda , Nikanth Karthikesan , Greg Kroah-Hartman , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, Tejun Heo , Randy Dunlap , Mikulas Patocka , Vegard Nossum , "Jun'ichi Nomura" , Ingo Molnar , Jan Blunck , Sam Ravnborg , Alasdair G Kergon Subject: [dm-devel] [PATCH v4 2/3] dm: export a table+mapped device to the ioctl interface 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: , MIME-Version: 1.0 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]); Tue, 08 Jun 2010 03:29:21 +0000 (UTC) diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c index dfde391..8c73b20 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c @@ -1604,6 +1604,44 @@ void dm_interface_exit(void) } /** + * 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 bind to '%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 * @name: Buffer (size DM_NAME_LEN) for name diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h index 1381cd9..0792cf3 100644 --- a/include/linux/device-mapper.h +++ b/include/linux/device-mapper.h @@ -215,6 +215,12 @@ 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 (uses mdptr). + */ +int dm_ioctl_export(struct mapped_device *md, const char *name, + const char *uuid); + +/* * A device can still be used while suspended, but I/O is deferred. */ int dm_suspend(struct mapped_device *md, unsigned suspend_flags);