From: Peter Rajnoha <prajnoha@redhat.com>
To: lvm-devel@redhat.com
Subject: [PATCH 3/7][retry remove] Add new "dm_set_sysfs_dir" fn to libdm to set the sysfs directory used in the system
Date: Tue, 20 Sep 2011 14:56:42 +0200 [thread overview]
Message-ID: <4E788D8A.30008@redhat.com> (raw)
libdm/libdevmapper.h | 6 ++++++
libdm/libdm-common.c | 33 +++++++++++++++++++++++++--------
2 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h
index 628d7da..ae39262 100644
--- a/libdm/libdevmapper.h
+++ b/libdm/libdevmapper.h
@@ -256,6 +256,12 @@ int dm_set_dev_dir(const char *dir);
const char *dm_dir(void);
/*
+ * Configure sysfs directory
+ */
+int dm_set_sysfs_dir(const char *dir);
+const char *dm_sysfs_dir(void);
+
+/*
* Determine whether a major number belongs to device-mapper or not.
*/
int dm_is_dm_major(uint32_t major);
diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c
index 0aacd1f..7517fb1 100644
--- a/libdm/libdm-common.c
+++ b/libdm/libdm-common.c
@@ -58,6 +58,7 @@ union semun
#endif
static char _dm_dir[PATH_MAX] = DEV_DIR DM_DIR;
+static char _sysfs_dir[PATH_MAX] = "";
static int _verbose = 0;
static int _suspended_dev_counter = 0;
@@ -1008,32 +1009,48 @@ void update_devs(void)
_pop_node_ops();
}
-int dm_set_dev_dir(const char *dev_dir)
+static int _canonicalize_and_set_dir(const char *src, const char *suffix, size_t max_len, char *dir)
{
size_t len;
const char *slash;
- if (*dev_dir != '/') {
- log_debug("Invalid dev_dir value, %s: "
- "not an absolute name.", dev_dir);
+
+ if (*src != '/') {
+ log_debug("Invalid directory value, %s: "
+ "not an absolute name.", src);
return 0;
}
- len = strlen(dev_dir);
- slash = dev_dir[len-1] == '/' ? "" : "/";
+ len = strlen(src);
+ slash = src[len-1] == '/' ? "" : "/";
- if (dm_snprintf(_dm_dir, sizeof _dm_dir, "%s%s%s", dev_dir, slash, DM_DIR) < 0) {
- log_debug("Invalid dev_dir value, %s: name too long.", dev_dir);
+ if (dm_snprintf(dir, max_len, "%s%s%s", src, slash, suffix ? suffix : "") < 0) {
+ log_debug("Invalid directory value, %s: name too long.", src);
return 0;
}
return 1;
}
+int dm_set_dev_dir(const char *dev_dir)
+{
+ return _canonicalize_and_set_dir(dev_dir, DM_DIR, sizeof _dm_dir, _dm_dir);
+}
+
const char *dm_dir(void)
{
return _dm_dir;
}
+int dm_set_sysfs_dir(const char *sysfs_dir)
+{
+ return _canonicalize_and_set_dir(sysfs_dir, NULL, sizeof _sysfs_dir, _sysfs_dir);
+}
+
+const char *dm_sysfs_dir(void)
+{
+ return _sysfs_dir;
+}
+
int dm_mknodes(const char *name)
{
struct dm_task *dmt;
reply other threads:[~2011-09-20 12:56 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=4E788D8A.30008@redhat.com \
--to=prajnoha@redhat.com \
--cc=lvm-devel@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.