From patchwork Mon May 24 16:33:28 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Drewry X-Patchwork-Id: 101906 X-Patchwork-Delegate: agk@redhat.com Received: from mx01.colomx.prod.int.phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4OGwn5P029437 for ; Mon, 24 May 2010 16:59:27 GMT Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx01.colomx.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4OGv3sk012652; Mon, 24 May 2010 12:57:03 -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 o4OGv1qN021432 for ; Mon, 24 May 2010 12:57:01 -0400 Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.6]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4OGusAb006928; Mon, 24 May 2010 12:56:55 -0400 Received: from mail-vw0-f46.google.com (mail-vw0-f46.google.com [209.85.212.46]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4OGuiTZ002319; Mon, 24 May 2010 12:56:45 -0400 Received: by vws9 with SMTP id 9so2661079vws.33 for ; Mon, 24 May 2010 09:56:44 -0700 (PDT) Received: by 10.224.109.8 with SMTP id h8mr3131439qap.60.1274718844557; Mon, 24 May 2010 09:34:04 -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 6sm10462727qwd.33.2010.05.24.09.34.03 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 24 May 2010 09:34:04 -0700 (PDT) From: Will Drewry To: dm-devel@redhat.com Date: Mon, 24 May 2010 11:33:28 -0500 Message-Id: <1274718808-11194-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.011 (RCVD_IN_DNSWL_NONE,SPF_PASS) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-Scanned-By: MIMEDefang 2.67 on 10.5.110.6 X-loop: dm-devel@redhat.com Cc: Will Drewry , snitzer@redhat.com, agk@redhat.com, linux-kernel@vger.kernel.org Subject: [dm-devel] [PATCH 2/2] 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]); Mon, 24 May 2010 16:59:27 +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);