linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: Alasdair Kergon <agk@redhat.com>
Cc: Kees Cook <keescook@chromium.org>, Will Drewry <wad@chromium.org>,
	Mike Snitzer <snitzer@redhat.com>,
	dm-devel@redhat.com, Jonathan Corbet <corbet@lwn.net>,
	Shaohua Li <shli@kernel.org>,
	Dan Ehrenberg <dehrenberg@chromium.org>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Chen Yu <yu.c.chen@intel.com>,
	Vishnu Pratap Singh <vishnu.ps@samsung.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Yaowei Bai <baiyaowei@cmss.chinamobile.com>,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-raid@vger.kernel.org, David Zeuthen <zeuthen@google.com>
Subject: [PATCH v5 1/3] dm: export a table+mapped device to the ioctl interface
Date: Sat, 20 Feb 2016 10:13:50 -0800	[thread overview]
Message-ID: <1455992032-14594-2-git-send-email-keescook@chromium.org> (raw)
In-Reply-To: <1455992032-14594-1-git-send-email-keescook@chromium.org>

From: Will Drewry <wad@chromium.org>

If a mapped device and table is configured without traversing the dm-ioctl
interface (dm-fs-style), then it will not be bound to a name or uuid. This
means that it will be inaccessible for userspace management and udev
will be unhappy with the lack of a name or uuid.

The function added in this change performs the required association to
transition to being managed by the ioctl interface.

Signed-off-by: Will Drewry <wad@chromium.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
---
v5: resurrection
v4: https://patchwork.kernel.org/patch/104860/
---
 drivers/md/dm-ioctl.c         | 35 +++++++++++++++++++++++++++++++++++
 include/linux/device-mapper.h |  6 ++++++
 2 files changed, 41 insertions(+)

diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index 80a439543259..e0efc6844b3a 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -1923,6 +1923,41 @@ 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)
+		return -ENXIO;
+
+	/* 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));
+		return -ENXIO;
+	}
+
+	r = dm_hash_insert(name, uuid, md);
+	if (r) {
+		DMERR("%s: could not bind to '%s'", dm_device_name(md), name);
+		return r;
+	}
+
+	/* Let udev know we've changed. */
+	dm_kobject_uevent(md, KOBJ_CHANGE, dm_get_event_nr(md));
+	return r;
+}
 /**
  * dm_copy_name_and_uuid - Copy mapped device name & uuid into supplied buffers
  * @md: Pointer to mapped_device
diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h
index ec1c61c87d89..87afa0552398 100644
--- a/include/linux/device-mapper.h
+++ b/include/linux/device-mapper.h
@@ -381,6 +381,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);
-- 
2.6.3

  reply	other threads:[~2016-02-20 18:14 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-20 18:13 [PATCH v5 0/3] init: add support to directly boot to a mapped device Kees Cook
2016-02-20 18:13 ` Kees Cook [this message]
2016-02-20 18:13 ` [PATCH v5 2/3] dm: make mapped_device locking functions available Kees Cook
2016-02-20 18:13 ` [PATCH v5 3/3] init: add support to directly boot to a mapped device Kees Cook
2016-02-21 22:08 ` [PATCH v5 0/3] " Alasdair G Kergon
2016-02-22 18:55   ` Kees Cook
2016-02-26 16:53     ` Mike Snitzer
2016-02-26 18:52       ` Kees Cook
2016-02-26 19:21         ` Mike Snitzer
2016-02-26 19:59           ` Kees Cook
2016-02-26 20:47             ` Mike Snitzer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1455992032-14594-2-git-send-email-keescook@chromium.org \
    --to=keescook@chromium.org \
    --cc=agk@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=baiyaowei@cmss.chinamobile.com \
    --cc=corbet@lwn.net \
    --cc=dehrenberg@chromium.org \
    --cc=dm-devel@redhat.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=shli@kernel.org \
    --cc=snitzer@redhat.com \
    --cc=vishnu.ps@samsung.com \
    --cc=wad@chromium.org \
    --cc=yu.c.chen@intel.com \
    --cc=zeuthen@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).