Skip to contentSkip to conversation

main - devicemapper: add dm_task_get_device_list

PATCH Zdenek Kabelac 1 participant 1 message Dec 20, 2021

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=988ea0e94c79a496f2619eab878fd9db6168711d
Commit:        988ea0e94c79a496f2619eab878fd9db6168711d
Parent:        90da953fd22437a8abfff02eb590a621efcc007c
Author:        Zdenek Kabelac <[email protected]>
AuthorDate:    Wed Dec 15 11:34:50 2021 +0100
Committer:     Zdenek Kabelac <[email protected]>
CommitterDate: Mon Dec 20 16:13:28 2021 +0100

devicemapper: add dm_task_get_device_list

New API extension (internal ATM) for getting a list of active DM device with extra features like i.e. uuid.

To easily lookout for existing UUID in device list, there is: dm_device_list_find_by_uuid()

Once the returned structure is no longer usable call:
dm_device_list_destroy()

Struct dm_active_device {} holds all the info, but is always allocated and destroyed within library.

TODO: once it's stable, copy to libdm

---
 WHATS_NEW                         |   1 +
 device_mapper/all.h               |  29 +++++++++
 device_mapper/ioctl/libdm-iface.c | 128 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 158 insertions(+)
WHATS_NEW +1 -0
index fc327dffd..0b206f067 100644
@@ -1,5 +1,6 @@
 Version 2.03.15 - 
 ===================================
+  Introduce function to utilize UUIDs from DM_DEVICE_LIST.
   Increase some hash table size to better support large device sets.
 
 Version 2.03.14 - 20th October 2021
device_mapper/all.h +29 -0
index 17f78d989..c8f040b80 100644
@@ -173,6 +173,16 @@ struct dm_names {
 	char name[];
 };
 
+struct dm_active_device {
+	struct dm_list list;
+	int major;
+	int minor;
+	char *name;	/* device name */
+
+	uint32_t event_nr; /* valid when DM_DEVICE_LIST_HAS_EVENT_NR is set */
+	char *uuid;	/* valid uuid when DM_DEVICE_LIST_HAS_UUID is set */
+};
+
 struct dm_versions {
 	uint32_t next;		/* Offset to next struct from start of this struct */
 	uint32_t version[3];
@@ -210,6 +220,25 @@ const char *dm_task_get_message_response(struct dm_task *dmt);
  */
 const char *dm_task_get_name(const struct dm_task *dmt);
 struct dm_names *dm_task_get_names(struct dm_task *dmt);
+/*
+ * Retrieve the list of devices and put them into easily accessible
+ * struct dm_active_device list elements.
+ * devs_features provides flag-set with used features so it's easy to check
+ * whether the kernel provides i.e. UUID info together with DM names
+ */
+#define DM_DEVICE_LIST_HAS_EVENT_NR	1
+#define DM_DEVICE_LIST_HAS_UUID		2
+int dm_task_get_device_list(struct dm_task *dmt, struct dm_list **devs_list,
+			    unsigned *devs_features);
+/*
+ * -1: no idea about uuid (not provided by DM_DEVICE_LIST ioctl)
+ *  0: uuid not present
+ *  1: listed and dm_active_device will be set for not NULL pointer
+ */
+int dm_device_list_find_by_uuid(struct dm_list *devs_list, const char *uuid,
+				const struct dm_active_device **dev);
+/* Release all associated memory with list of active DM devices */
+void dm_device_list_destroy(struct dm_list **devs_list);
 
 int dm_task_set_ro(struct dm_task *dmt);
 int dm_task_set_newname(struct dm_task *dmt, const char *newname);
device_mapper/ioctl/libdm-iface.c +128 -0

134 lines not on this page · raw message