From: Peter Rajnoha <prajnoha@redhat.com>
To: lvm-devel@redhat.com
Subject: [PATCH 4/7][retry remove] Add new "dm_device_has_holders" fn to libdm
Date: Tue, 20 Sep 2011 14:57:09 +0200 [thread overview]
Message-ID: <4E788DA5.8010304@redhat.com> (raw)
This is a helper function used both in libdevmapper and in LVM
to test whether there are any devices that make use of certain
device given as parameter (this will partially replace "open_count"
check, see the following patch...).
Peter
---
libdm/libdevmapper.h | 6 ++++++
libdm/libdm-common.c | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/libdm/libdevmapper.h b/libdm/libdevmapper.h
index ae39262..9df34bb 100644
--- a/libdm/libdevmapper.h
+++ b/libdm/libdevmapper.h
@@ -267,6 +267,12 @@ const char *dm_sysfs_dir(void);
int dm_is_dm_major(uint32_t major);
/*
+ * Determine whether a device has holders.
+ * (this requires sysfs directory to be configured via dm_set_sysfs_dir)
+ */
+int dm_device_has_holders(uint32_t major, uint32_t minor);
+
+/*
* Release library resources
*/
void dm_lib_release(void);
diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c
index 7517fb1..7ea78af 100644
--- a/libdm/libdm-common.c
+++ b/libdm/libdm-common.c
@@ -1051,6 +1051,42 @@ const char *dm_sysfs_dir(void)
return _sysfs_dir;
}
+static int _is_empty_dir(const char *dir)
+{
+ struct dirent *dirent;
+ DIR *d;
+
+ if (!(d = opendir(dir))) {
+ log_sys_error("opendir", dir);
+ return 0;
+ }
+
+ while ((dirent = readdir(d)))
+ if (strcmp(dirent->d_name, ".") && strcmp(dirent->d_name, ".."))
+ break;
+
+ if (closedir(d))
+ log_sys_error("closedir", dir);
+
+ return dirent ? 0 : 1;
+}
+
+int dm_device_has_holders(uint32_t major, uint32_t minor)
+{
+ char sysfs_path[PATH_MAX];
+
+ if (!*_sysfs_dir)
+ return 0;
+
+ if (dm_snprintf(sysfs_path, PATH_MAX, "%sdev/block/%" PRIu32
+ ":%" PRIu32 "/holders", _sysfs_dir, major, minor) < 0) {
+ log_error("sysfs_path dm_snprintf failed");
+ return 0;
+ }
+
+ return !_is_empty_dir(sysfs_path);
+}
+
int dm_mknodes(const char *name)
{
struct dm_task *dmt;
next reply other threads:[~2011-09-20 12:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-20 12:57 Peter Rajnoha [this message]
2011-09-20 13:10 ` [PATCH 4/7][retry remove] Add new "dm_device_has_holders" fn to libdm Zdenek Kabelac
2011-09-21 11:23 ` Peter Rajnoha
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=4E788DA5.8010304@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.