main - label: cache dm device list
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=04fbffb116eaf5fb1b1...
Commit: 04fbffb116eaf5fb1b10785df92966d0083b270f
Parent: 0d67bc96fd15b9f3110bdc824749805c8392b04a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Dec 15 11:45:22 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Dec 20 16:13:28 2021 +0100
label: cache dm device list
Since we check for present DM devices - cache result for
futher use of checking presence of such device.
lvm2 uses cache result for label scan, but also when
it tries to activate or deactivate LV - however only simple
target 'striped' is reasonably supported.
Use disable_dm_devs to be able to control when lv_info()
get cache or uncached results.
TODO: support more type, however this is getting very complicated.
---
WHATS_NEW | 1 +
lib/activate/activate.c | 6 ++++++
lib/activate/dev_manager.c | 29 +++++++++++++++++++++++++++++
lib/commands/toolcontext.c | 1 +
lib/commands/toolcontext.h | 3 +++
lib/label/label.c | 35 +++++++++++++++++++++++++++++++++++
lib/label/label.h | 1 +
lib/locking/locking.c | 1 +
tools/toollib.c | 3 +--
9 files changed, 78 insertions(+), 2 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 0b206f067..e2f6e166b 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.03.15 -
===================================
+ Use cache or active DM device when available with new kernels.
Introduce function to utilize UUIDs from DM_DEVICE_LIST.
Increase some hash table size to better support large device sets.
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index ffb7f4b29..db5f08b11 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -2391,6 +2391,7 @@ int lv_deactivate(struct cmd_context *cmd, const char *lvid_s, const struct logi
static const struct lv_activate_opts laopts = { .skip_in_use = 1 };
struct dm_list *snh;
int r = 0;
+ unsigned tmp_state;
if (!activation())
return 1;
@@ -2463,12 +2464,17 @@ int lv_deactivate(struct cmd_context *cmd, const char *lvid_s, const struct logi
}
critical_section_dec(cmd, "deactivated");
+ tmp_state = cmd->disable_dm_devs;
+ cmd->disable_dm_devs = 1;
+
if (!lv_info(cmd, lv, 0, &info, 0, 0) || info.exists) {
/* Turn into log_error, but we do not log error */
log_debug_activation("Deactivated volume is still %s present.",
display_lvname(lv));
r = 0;
}
+
+ cmd->disable_dm_devs = tmp_state;
out:
return r;
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index 16c66a341..6cf4c718c 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -964,6 +964,16 @@ int dev_manager_info(struct cmd_context *cmd,
if (!(dlid = build_dm_uuid(cmd->mem, lv, layer)))
goto_out;
+ if (!cmd->disable_dm_devs &&
+ cmd->cache_dm_devs &&
+ !dm_device_list_find_by_uuid(cmd->cache_dm_devs, dlid, NULL)) {
+ log_debug("Cached as inactive %s.", name);
+ if (dminfo)
+ memset(dminfo, 0, sizeof(*dminfo));
+ r = 1;
+ goto out;
+ }
+
if (!(r = _info(cmd, name, dlid,
with_open_count, with_read_ahead, with_name_check,
dminfo, read_ahead, seg_status)))
@@ -2245,6 +2255,13 @@ static int _add_dev_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
if (!(dlid = build_dm_uuid(dm->track_pending_delete ? dm->cmd->pending_delete_mem : dm->mem, lv, layer)))
return_0;
+ if (!dm->cmd->disable_dm_devs &&
+ dm->cmd->cache_dm_devs &&
+ !dm_device_list_find_by_uuid(dm->cmd->cache_dm_devs, dlid, NULL)) {
+ log_debug("Cached as not present %s.", name);
+ return 1;
+ }
+
if (!_info(dm->cmd, name, dlid, 1, 0, 0, &info, NULL, NULL))
return_0;
@@ -2390,6 +2407,9 @@ static int _pool_callback(struct dm_tree_node *node,
return 0;
}
}
+
+ dm_device_list_destroy(&cmd->cache_dm_devs); /* Cache no longer valid */
+
log_debug("Running check command on %s", mpath);
if (data->skip_zero) {
@@ -3777,6 +3797,7 @@ static int _tree_action(struct dev_manager *dm, const struct logical_volume *lv,
struct dm_tree_node *root;
char *dlid;
int r = 0;
+ unsigned tmp_state;
if (action < DM_ARRAY_SIZE(_action_names))
log_debug_activation("Creating %s%s tree for %s.",
@@ -3796,9 +3817,17 @@ static int _tree_action(struct dev_manager *dm, const struct logical_volume *lv,
dm->suspend = (action == SUSPEND_WITH_LOCKFS) || (action == SUSPEND);
dm->track_external_lv_deps = 1;
+ /* ATM do not use caching for anything else then striped target.
+ * And also skip for CLEAN action */
+ tmp_state = dm->cmd->disable_dm_devs;
+ if (!seg_is_striped_target(first_seg(lv)) || (action == CLEAN))
+ dm->cmd->disable_dm_devs = 1;
+
if (!(dtree = _create_partial_dtree(dm, lv, laopts->origin_only)))
return_0;
+ dm->cmd->disable_dm_devs = tmp_state;
+
if (!(root = dm_tree_find_node(dtree, 0, 0))) {
log_error("Lost dependency tree root node.");
goto out_no_root;
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index c772dc6b1..301596482 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -2052,6 +2052,7 @@ void destroy_toolcontext(struct cmd_context *cmd)
if (cmd->cft_def_hash)
dm_hash_destroy(cmd->cft_def_hash);
+ dm_device_list_destroy(&cmd->cache_dm_devs);
#ifndef VALGRIND_POOL
if (cmd->linebuffer) {
/* Reset stream buffering to defaults */
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index 4d7d4630d..f16322d4e 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -203,6 +203,7 @@ struct cmd_context {
unsigned event_activation:1; /* whether event_activation is set */
unsigned udevoutput:1;
unsigned online_vg_file_removed:1;
+ unsigned disable_dm_devs:1; /* temporarily disable use of dm devs cache */
/*
* Devices and filtering.
@@ -214,6 +215,8 @@ struct cmd_context {
const char *devicesfile; /* from --devicesfile option */
struct dm_list deviceslist; /* from --devices option, struct dm_str_list */
+ struct dm_list *cache_dm_devs; /* cache with UUIDs from DM_DEVICE_LIST (when available) */
+
/*
* Configuration.
*/
diff --git a/lib/label/label.c b/lib/label/label.c
index 5c77a6923..8676b9e4a 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -1719,6 +1719,41 @@ void label_scan_invalidate_lv(struct cmd_context *cmd, struct logical_volume *lv
}
}
+void label_scan_invalidate_lvs(struct cmd_context *cmd, struct dm_list *lvs)
+{
+ struct dm_list *devs;
+ struct dm_active_device *dm_dev;
+ unsigned devs_features = 0;
+ struct device *dev;
+ struct lv_list *lvl;
+ dev_t devt;
+
+ if (get_device_list(NULL, &devs, &devs_features)) {
+ if (devs_features & DM_DEVICE_LIST_HAS_UUID) {
+ dm_list_iterate_items(dm_dev, devs)
+ if (dm_dev->uuid &&
+ strncmp(dm_dev->uuid, UUID_PREFIX, sizeof(UUID_PREFIX) - 1) == 0) {
+ devt = MKDEV(dm_dev->major, dm_dev->minor);
+ if ((dev = dev_cache_get_by_devt(cmd, devt, NULL, NULL)))
+ label_scan_invalidate(dev);
+ }
+ /* ATM no further caching for any lvconvert command
+ * TODO: any other command to be skipped ??
+ */
+ if (strcmp(cmd->name, "lvconvert")) {
+ dm_device_list_destroy(&cmd->cache_dm_devs);
+ cmd->cache_dm_devs = devs; /* cache to avoid unneeded checks */
+ devs = NULL;
+ }
+ }
+ dm_device_list_destroy(&devs);
+ }
+
+ if (!(devs_features & DM_DEVICE_LIST_HAS_UUID))
+ dm_list_iterate_items(lvl, lvs)
+ label_scan_invalidate_lv(cmd, lvl->lv);
+}
+
/*
* Empty the bcache of all blocks and close all open fds,
* but keep the bcache set up.
diff --git a/lib/label/label.h b/lib/label/label.h
index 3cda1818c..26784c3e8 100644
--- a/lib/label/label.h
+++ b/lib/label/label.h
@@ -110,6 +110,7 @@ int label_scan_devs_excl(struct cmd_context *cmd, struct dev_filter *f, struct d
int label_scan_dev(struct cmd_context *cmd, struct device *dev);
void label_scan_invalidate(struct device *dev);
void label_scan_invalidate_lv(struct cmd_context *cmd, struct logical_volume *lv);
+void label_scan_invalidate_lvs(struct cmd_context *cmd, struct dm_list *lvs);
void label_scan_drop(struct cmd_context *cmd);
void label_scan_destroy(struct cmd_context *cmd);
int label_scan_setup_bcache(void);
diff --git a/lib/locking/locking.c b/lib/locking/locking.c
index c69f08c09..a8153a693 100644
--- a/lib/locking/locking.c
+++ b/lib/locking/locking.c
@@ -330,6 +330,7 @@ int vg_write_lock_held(void)
int sync_local_dev_names(struct cmd_context* cmd)
{
+ dm_device_list_destroy(&cmd->cache_dm_devs);
memlock_unlock(cmd);
fs_unlock();
return 1;
diff --git a/tools/toollib.c b/tools/toollib.c
index 3b3a20689..f95c98f51 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -3122,8 +3122,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
* in bcache, and needs to be closed so the open fd doesn't
* interfere with processing the LV.
*/
- dm_list_iterate_items(lvl, &final_lvs)
- label_scan_invalidate_lv(cmd, lvl->lv);
+ label_scan_invalidate_lvs(cmd, &final_lvs);
dm_list_iterate_items(lvl, &final_lvs) {
lv_uuid[0] = '\0';
2 years, 4 months
main - activate: add get_device_list
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=0d67bc96fd15b9f3110...
Commit: 0d67bc96fd15b9f3110bdc824749805c8392b04a
Parent: 988ea0e94c79a496f2619eab878fd9db6168711d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Dec 15 11:24:31 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Dec 20 16:13:28 2021 +0100
activate: add get_device_list
Add funtion get_device_list() to get list of active DM devices.
Handled through new dm_task_get_device_list().
---
lib/activate/activate.c | 9 +++++++++
lib/activate/activate.h | 4 ++++
lib/activate/dev_manager.c | 29 ++++++++++++++++++++++++++++-
lib/activate/dev_manager.h | 2 ++
4 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index 9d1fe8ebe..ffb7f4b29 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -624,6 +624,15 @@ int target_present(struct cmd_context *cmd, const char *target_name,
&maj, &min, &patchlevel);
}
+int get_device_list(const struct volume_group *vg, struct dm_list **devs,
+ unsigned *devs_features)
+{
+ if (!activation())
+ return 0;
+
+ return dev_manager_get_device_list(NULL, devs, devs_features);
+}
+
/*
* When '*info' is NULL, returns 1 only when LV is active.
* When '*info' != NULL, returns 1 when info structure is populated.
diff --git a/lib/activate/activate.h b/lib/activate/activate.h
index 6133e6d97..a276b48a7 100644
--- a/lib/activate/activate.h
+++ b/lib/activate/activate.h
@@ -106,6 +106,10 @@ int target_present(struct cmd_context *cmd, const char *target_name,
int use_modprobe);
int target_version(const char *target_name, uint32_t *maj,
uint32_t *min, uint32_t *patchlevel);
+
+int get_device_list(const struct volume_group *vg, struct dm_list **devs,
+ unsigned *devs_features);
+
int raid4_is_supported(struct cmd_context *cmd, const struct segment_type *segtype);
int lvm_dm_prefix_check(int major, int minor, const char *prefix);
int list_segment_modules(struct dm_pool *mem, const struct lv_segment *seg,
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index 56575fa85..16c66a341 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -138,8 +138,16 @@ static struct dm_task *_setup_task_run(int task, struct dm_info *info,
if (!with_flush && !dm_task_no_flush(dmt))
log_warn("WARNING: Failed to set no_flush.");
- if (task == DM_DEVICE_TARGET_MSG)
+ switch (task) {
+ case DM_DEVICE_TARGET_MSG:
return dmt; /* TARGET_MSG needs more local tweaking before task_run() */
+ case DM_DEVICE_LIST:
+ if (!dm_task_set_newuuid(dmt, " ")) // new uuid has no meaning here
+ log_warn("WARNING: Failed to query uuid with LIST.");
+ break;
+ default:
+ break;
+ }
if (!dm_task_run(dmt))
goto_out;
@@ -922,6 +930,25 @@ int dev_manager_check_prefix_dm_major_minor(uint32_t major, uint32_t minor, cons
return r;
}
+int dev_manager_get_device_list(const char *prefix, struct dm_list **devs, unsigned *devs_features)
+{
+ struct dm_task *dmt;
+ int r = 1;
+
+ if (!(dmt = _setup_task_run(DM_DEVICE_LIST, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0)))
+ return_0;
+
+ if (!dm_task_get_device_list(dmt, devs, devs_features)) {
+ r = 0;
+ goto_out;
+ }
+
+ out:
+ dm_task_destroy(dmt);
+
+ return r;
+}
+
int dev_manager_info(struct cmd_context *cmd,
const struct logical_volume *lv, const char *layer,
int with_open_count, int with_read_ahead, int with_name_check,
diff --git a/lib/activate/dev_manager.h b/lib/activate/dev_manager.h
index 27092f2b9..9980e1647 100644
--- a/lib/activate/dev_manager.h
+++ b/lib/activate/dev_manager.h
@@ -103,5 +103,7 @@ int dev_manager_device_uses_vg(struct device *dev,
int dev_manager_remove_dm_major_minor(uint32_t major, uint32_t minor);
int dev_manager_check_prefix_dm_major_minor(uint32_t major, uint32_t minor, const char *prefix);
+int dev_manager_get_device_list(const char *prefix, struct dm_list **devs,
+ unsigned *devs_features);
#endif
2 years, 4 months
main - devicemapper: add dm_task_get_device_list
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=988ea0e94c79a496f26...
Commit: 988ea0e94c79a496f2619eab878fd9db6168711d
Parent: 90da953fd22437a8abfff02eb590a621efcc007c
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Dec 15 11:34:50 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
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(+)
diff --git a/WHATS_NEW b/WHATS_NEW
index fc327dffd..0b206f067 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -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
diff --git a/device_mapper/all.h b/device_mapper/all.h
index 17f78d989..c8f040b80 100644
--- a/device_mapper/all.h
+++ b/device_mapper/all.h
@@ -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);
diff --git a/device_mapper/ioctl/libdm-iface.c b/device_mapper/ioctl/libdm-iface.c
index acc0f557c..738807f8f 100644
--- a/device_mapper/ioctl/libdm-iface.c
+++ b/device_mapper/ioctl/libdm-iface.c
@@ -779,6 +779,134 @@ static int _check_has_event_nr(void) {
return _has_event_nr;
}
+struct dm_device_list {
+ struct dm_list list;
+ unsigned count;
+ unsigned features;
+ struct dm_hash_table *uuids;
+};
+
+int dm_task_get_device_list(struct dm_task *dmt, struct dm_list **devs_list,
+ unsigned *devs_features)
+{
+ struct dm_names *names, *names1;
+ struct dm_active_device *dm_dev, *dm_new_dev;
+ struct dm_device_list *devs;
+ unsigned next = 0;
+ uint32_t *event_nr;
+ char *uuid_ptr;
+ size_t len;
+ int cnt = 0;
+
+ *devs_list = 0;
+ *devs_features = 0;
+
+ if ((names = dm_task_get_names(dmt)) && names->dev) {
+ names1 = names;
+ if (!names->name[0])
+ cnt = -1; /* -> cnt == 0 when no device is really present */
+ do {
+ names1 = (struct dm_names *)((char *) names1 + next);
+ next = names1->next;
+ ++cnt;
+ } while (next);
+ }
+
+ if (!(devs = malloc(sizeof(*devs) + (cnt ? cnt * sizeof(*dm_dev) + (char*)names1 - (char*)names + 256 : 0))))
+ return_0;
+
+ dm_list_init(&devs->list);
+ devs->count = cnt;
+ devs->uuids = NULL;
+
+ if (!cnt) {
+ /* nothing in the list -> mark all features present */
+ *devs_features |= (DM_DEVICE_LIST_HAS_EVENT_NR | DM_DEVICE_LIST_HAS_UUID);
+ goto out; /* nothing else to do */
+ }
+
+ dm_dev = (struct dm_active_device *) (devs + 1);
+
+ do {
+ names = (struct dm_names *)((char *) names + next);
+
+ dm_dev->major = MAJOR(names->dev);
+ dm_dev->minor = MINOR(names->dev);
+ dm_dev->name = (char*)(dm_dev + 1);
+ dm_dev->event_nr = 0;
+ dm_dev->uuid = NULL;
+
+ strcpy(dm_dev->name, names->name);
+ len = strlen(names->name) + 1;
+
+ dm_new_dev = _align_ptr((char*)(dm_dev + 1) + len);
+ if (_check_has_event_nr()) {
+ /* Hash for UUIDs with some more bits to reduce colision count */
+ if (!devs->uuids && !(devs->uuids = dm_hash_create(cnt * 8))) {
+ free(devs);
+ return_0;
+ }
+
+ *devs_features |= DM_DEVICE_LIST_HAS_EVENT_NR;
+ event_nr = _align_ptr(names->name + len);
+ dm_dev->event_nr = event_nr[0];
+
+ if ((event_nr[1] & DM_NAME_LIST_FLAG_HAS_UUID)) {
+ *devs_features |= DM_DEVICE_LIST_HAS_UUID;
+ uuid_ptr = _align_ptr(event_nr + 2);
+ dm_dev->uuid = (char*) dm_new_dev;
+ dm_new_dev = _align_ptr((char*)dm_new_dev + strlen(uuid_ptr) + 1);
+ strcpy(dm_dev->uuid, uuid_ptr);
+ if (!dm_hash_insert(devs->uuids, dm_dev->uuid, dm_dev))
+ return_0; // FIXME
+#if 0
+ log_debug("Active %s (%s) %d:%d event:%u",
+ dm_dev->name, dm_dev->uuid,
+ dm_dev->major, dm_dev->minor, dm_dev->event_nr);
+#endif
+ }
+ }
+
+ dm_list_add(&devs->list, &dm_dev->list);
+ dm_dev = dm_new_dev;
+ next = names->next;
+ } while (next);
+
+ out:
+ *devs_list = (struct dm_list *)devs;
+
+ return 1;
+}
+
+int dm_device_list_find_by_uuid(struct dm_list *devs_list, const char *uuid,
+ const struct dm_active_device **dev)
+{
+ struct dm_device_list *devs = (struct dm_device_list *) devs_list;
+ struct dm_active_device *dm_dev;
+
+ if (devs->uuids &&
+ (dm_dev = dm_hash_lookup(devs->uuids, uuid))) {
+ if (dev)
+ *dev = dm_dev;
+ return 1;
+ }
+
+ return 0;
+}
+
+void dm_device_list_destroy(struct dm_list **devs_list)
+{
+ struct dm_device_list *devs = (struct dm_device_list *) *devs_list;
+
+ if (devs) {
+ if (devs->uuids)
+ dm_hash_destroy(devs->uuids);
+
+ free(devs);
+ *devs_list = NULL;
+ }
+}
+
struct dm_names *dm_task_get_names(struct dm_task *dmt)
{
return (struct dm_names *) (((char *) dmt->dmi.v4) +
2 years, 4 months
main - libdm: unmangling UUID for DM_DEVICE_LIST
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=90da953fd22437a8abf...
Commit: 90da953fd22437a8abfff02eb590a621efcc007c
Parent: 65236ee7226930bcbabac0d2dc1979a90bcf2d19
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Dec 8 10:45:13 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Dec 20 16:13:28 2021 +0100
libdm: unmangling UUID for DM_DEVICE_LIST
Properly unmangle UUID if they are provided as result
of DM_DEVICE_LIST ioctl on newer linux kernels.
---
WHATS_NEW_DM | 1 +
device_mapper/ioctl/libdm-iface.c | 52 +++++++++++++++++++++++++++++++++------
libdm/ioctl/libdm-iface.c | 51 ++++++++++++++++++++++++++++++++------
3 files changed, 88 insertions(+), 16 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 8e06ee9b9..dfb075dcc 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.183 -
====================================
+ Unmangle UUIDs for DM_DEVICE_LIST ioctl.
Version 1.02.181 - 20th October 2021
====================================
diff --git a/device_mapper/ioctl/libdm-iface.c b/device_mapper/ioctl/libdm-iface.c
index 925f18c6b..acc0f557c 100644
--- a/device_mapper/ioctl/libdm-iface.c
+++ b/device_mapper/ioctl/libdm-iface.c
@@ -754,6 +754,31 @@ struct dm_deps *dm_task_get_deps(struct dm_task *dmt)
dmt->dmi.v4->data_start);
}
+
+/*
+ * Round up the ptr to an 8-byte boundary.
+ * Follow kernel pattern.
+ */
+#define ALIGN_MASK 7
+static size_t _align_val(size_t val)
+{
+ return (val + ALIGN_MASK) & ~ALIGN_MASK;
+}
+static void *_align_ptr(void *ptr)
+{
+ return (void *)_align_val((size_t)ptr);
+}
+
+static int _check_has_event_nr(void) {
+ static int _has_event_nr = -1;
+
+ if (_has_event_nr < 0)
+ _has_event_nr = dm_check_version() &&
+ ((_dm_version == 4) ? _dm_version_minor >= 38 : _dm_version > 4);
+
+ return _has_event_nr;
+}
+
struct dm_names *dm_task_get_names(struct dm_task *dmt)
{
return (struct dm_names *) (((char *) dmt->dmi.v4) +
@@ -1806,23 +1831,34 @@ static int _do_dm_ioctl_unmangle_string(char *str, const char *str_name,
static int _dm_ioctl_unmangle_names(int type, struct dm_ioctl *dmi)
{
char buf[DM_NAME_LEN];
- struct dm_names *names;
+ char buf_uuid[DM_UUID_LEN];
+ struct dm_name_list *names;
unsigned next = 0;
char *name;
int r = 1;
+ uint32_t *event_nr;
+ char *uuid_ptr;
+ dm_string_mangling_t mangling_mode = dm_get_name_mangling_mode();
if ((name = dmi->name))
- r = _do_dm_ioctl_unmangle_string(name, "name", buf, sizeof(buf),
- dm_get_name_mangling_mode());
+ r &= _do_dm_ioctl_unmangle_string(name, "name", buf, sizeof(buf),
+ mangling_mode);
if (type == DM_DEVICE_LIST &&
- ((names = ((struct dm_names *) ((char *)dmi + dmi->data_start)))) &&
+ ((names = ((struct dm_name_list *) ((char *)dmi + dmi->data_start)))) &&
names->dev) {
do {
- names = (struct dm_names *)((char *) names + next);
- r = _do_dm_ioctl_unmangle_string(names->name, "name",
- buf, sizeof(buf),
- dm_get_name_mangling_mode());
+ names = (struct dm_name_list *)((char *) names + next);
+ event_nr = _align_ptr(names->name + strlen(names->name) + 1);
+ r &= _do_dm_ioctl_unmangle_string(names->name, "name",
+ buf, sizeof(buf), mangling_mode);
+ /* Unmangle also UUID within same loop */
+ if (_check_has_event_nr() &&
+ (event_nr[1] & DM_NAME_LIST_FLAG_HAS_UUID)) {
+ uuid_ptr = _align_ptr(event_nr + 2);
+ r &= _do_dm_ioctl_unmangle_string(uuid_ptr, "UUID", buf_uuid,
+ sizeof(buf_uuid), mangling_mode);
+ }
next = names->next;
} while (next);
}
diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c
index a3a1bdc66..0fba79ce4 100644
--- a/libdm/ioctl/libdm-iface.c
+++ b/libdm/ioctl/libdm-iface.c
@@ -762,6 +762,30 @@ struct dm_deps *dm_task_get_deps(struct dm_task *dmt)
dmt->dmi.v4->data_start);
}
+/*
+ * Round up the ptr to an 8-byte boundary.
+ * Follow kernel pattern.
+ */
+#define ALIGN_MASK 7
+static size_t _align_val(size_t val)
+{
+ return (val + ALIGN_MASK) & ~ALIGN_MASK;
+}
+static void *_align_ptr(void *ptr)
+{
+ return (void *)_align_val((size_t)ptr);
+}
+
+static int _check_has_event_nr(void) {
+ static int _has_event_nr = -1;
+
+ if (_has_event_nr < 0)
+ _has_event_nr = dm_check_version() &&
+ ((_dm_version == 4) ? _dm_version_minor >= 38 : _dm_version > 4);
+
+ return _has_event_nr;
+}
+
struct dm_names *dm_task_get_names(struct dm_task *dmt)
{
return (struct dm_names *) (((char *) dmt->dmi.v4) +
@@ -1782,23 +1806,34 @@ static int _do_dm_ioctl_unmangle_string(char *str, const char *str_name,
static int _dm_ioctl_unmangle_names(int type, struct dm_ioctl *dmi)
{
char buf[DM_NAME_LEN];
- struct dm_names *names;
+ char buf_uuid[DM_UUID_LEN];
+ struct dm_name_list *names;
unsigned next = 0;
char *name;
int r = 1;
+ uint32_t *event_nr;
+ char *uuid_ptr;
+ dm_string_mangling_t mangling_mode = dm_get_name_mangling_mode();
if ((name = dmi->name))
- r = _do_dm_ioctl_unmangle_string(name, "name", buf, sizeof(buf),
- dm_get_name_mangling_mode());
+ r &= _do_dm_ioctl_unmangle_string(name, "name", buf, sizeof(buf),
+ mangling_mode);
if (type == DM_DEVICE_LIST &&
- ((names = ((struct dm_names *) ((char *)dmi + dmi->data_start)))) &&
+ ((names = ((struct dm_name_list *) ((char *)dmi + dmi->data_start)))) &&
names->dev) {
do {
- names = (struct dm_names *)((char *) names + next);
- r = _do_dm_ioctl_unmangle_string(names->name, "name",
- buf, sizeof(buf),
- dm_get_name_mangling_mode());
+ names = (struct dm_name_list *)((char *) names + next);
+ event_nr = _align_ptr(names->name + strlen(names->name) + 1);
+ r &= _do_dm_ioctl_unmangle_string(names->name, "name",
+ buf, sizeof(buf), mangling_mode);
+ /* Unmangle also UUID within same loop */
+ if (_check_has_event_nr() &&
+ (event_nr[1] & DM_NAME_LIST_FLAG_HAS_UUID)) {
+ uuid_ptr = _align_ptr(event_nr + 2);
+ r &= _do_dm_ioctl_unmangle_string(uuid_ptr, "UUID", buf_uuid,
+ sizeof(buf_uuid), mangling_mode);
+ }
next = names->next;
} while (next);
}
2 years, 4 months
main - activate: device_is_usable
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=65236ee7226930bcbab...
Commit: 65236ee7226930bcbabac0d2dc1979a90bcf2d19
Parent: 5a78979b68c4ae822c3f9bcc7ba662c7aa727b40
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Dec 15 11:26:21 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Dec 20 16:13:28 2021 +0100
activate: device_is_usable
Move checking of usable uuid into separate function
and pass in also cmd context.
---
lib/activate/activate.c | 2 +-
lib/activate/activate.h | 2 +-
lib/activate/dev_manager.c | 113 ++++++++++++++++++++++++--------------------
lib/filters/filter-usable.c | 2 +-
4 files changed, 66 insertions(+), 53 deletions(-)
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index 52ec02e2c..9d1fe8ebe 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -413,7 +413,7 @@ int add_areas_line(struct dev_manager *dm, struct lv_segment *seg,
{
return 0;
}
-int device_is_usable(struct device *dev, struct dev_usable_check_params check, int *is_lv)
+int device_is_usable(struct cmd_context *cmd, struct device *dev, struct dev_usable_check_params check, int *is_lv)
{
return 0;
}
diff --git a/lib/activate/activate.h b/lib/activate/activate.h
index edd385aef..6133e6d97 100644
--- a/lib/activate/activate.h
+++ b/lib/activate/activate.h
@@ -254,7 +254,7 @@ struct dev_usable_check_params {
* Returns 1 if mapped device is not suspended, blocked or
* is using a reserved name.
*/
-int device_is_usable(struct device *dev, struct dev_usable_check_params check, int *is_lv);
+int device_is_usable(struct cmd_context *cmd, struct device *dev, struct dev_usable_check_params check, int *is_lv);
/*
* Declaration moved here from fs.h to keep header fs.h hidden
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index a73a556b2..56575fa85 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -359,7 +359,8 @@ static int _info_run(const char *dlid, struct dm_info *dminfo,
*
* Returns: 1 if mirror should be ignored, 0 if safe to use
*/
-static int _ignore_blocked_mirror_devices(struct device *dev,
+static int _ignore_blocked_mirror_devices(struct cmd_context *cmd,
+ struct device *dev,
uint64_t start, uint64_t length,
char *mirror_status_str)
{
@@ -402,7 +403,7 @@ static int _ignore_blocked_mirror_devices(struct device *dev,
goto_out;
tmp_dev->dev = MKDEV(sm->logs[0].major, sm->logs[0].minor);
- if (device_is_usable(tmp_dev, (struct dev_usable_check_params)
+ if (device_is_usable(cmd, tmp_dev, (struct dev_usable_check_params)
{ .check_empty = 1,
.check_blocked = 1,
.check_suspended = ignore_suspended_devices(),
@@ -606,6 +607,60 @@ static int _ignore_frozen_raid(struct device *dev, const char *params)
return r;
}
+static int _is_usable_uuid(const struct device *dev, const char *name, const char *uuid, int check_reserved, int check_lv, int *is_lv)
+{
+ char *vgname, *lvname, *layer;
+ char vg_name[NAME_LEN];
+
+ if (!check_reserved && !check_lv)
+ return 1;
+
+ if (!strncmp(uuid, UUID_PREFIX, sizeof(UUID_PREFIX) - 1)) { /* with LVM- prefix */
+ if (check_reserved) {
+ /* Check internal lvm devices */
+ if (strlen(uuid) > (sizeof(UUID_PREFIX) + 2 * ID_LEN)) { /* 68 with suffix */
+ log_debug_activation("%s: Reserved uuid %s on internal LV device %s not usable.",
+ dev_name(dev), uuid, name);
+ return 0;
+ }
+
+ /* Recognize some older reserved LVs just from the LV name (snapshot, pvmove...) */
+ vgname = vg_name;
+ if (!dm_strncpy(vg_name, name, sizeof(vg_name)) ||
+ !dm_split_lvm_name(NULL, NULL, &vgname, &lvname, &layer))
+ return_0;
+
+ /* FIXME: fails to handle dev aliases i.e. /dev/dm-5, replace with UUID suffix */
+ if (lvname && (is_reserved_lvname(lvname) || *layer)) {
+ log_debug_activation("%s: Reserved internal LV device %s/%s%s%s not usable.",
+ dev_name(dev), vgname, lvname, *layer ? "-" : "", layer);
+ return 0;
+ }
+ }
+
+ if (check_lv) {
+ /* Skip LVs */
+ if (is_lv)
+ *is_lv = 1;
+ return 0;
+ }
+ }
+
+ if (check_reserved &&
+ (!strncmp(uuid, CRYPT_TEMP, sizeof(CRYPT_TEMP) - 1) ||
+ !strncmp(uuid, CRYPT_SUBDEV, sizeof(CRYPT_SUBDEV) - 1) ||
+ !strncmp(uuid, STRATIS, sizeof(STRATIS) - 1))) {
+ /* Skip private crypto devices */
+ log_debug_activation("%s: Reserved uuid %s on %s device %s not usable.",
+ dev_name(dev), uuid,
+ uuid[0] == 'C' ? "crypto" : "stratis",
+ name);
+ return 0;
+ }
+
+ return 1;
+}
+
/*
* device_is_usable
* @dev
@@ -622,15 +677,14 @@ static int _ignore_frozen_raid(struct device *dev, const char *params)
*
* Returns: 1 if usable, 0 otherwise
*/
-int device_is_usable(struct device *dev, struct dev_usable_check_params check, int *is_lv)
+int device_is_usable(struct cmd_context *cmd, struct device *dev, struct dev_usable_check_params check, int *is_lv)
{
struct dm_task *dmt;
struct dm_info info;
const char *name, *uuid;
uint64_t start, length;
char *target_type = NULL;
- char *params, *vgname, *lvname, *layer;
- char vg_name[NAME_LEN];
+ char *params;
void *next = NULL;
int only_error_or_zero_target = 1;
int r = 0;
@@ -655,50 +709,9 @@ int device_is_usable(struct device *dev, struct dev_usable_check_params check, i
goto out;
}
- if (uuid && (check.check_reserved || check.check_lv)) {
- if (!strncmp(uuid, UUID_PREFIX, sizeof(UUID_PREFIX) - 1)) { /* with LVM- prefix */
- if (check.check_reserved) {
- /* Check internal lvm devices */
- if (strlen(uuid) > (sizeof(UUID_PREFIX) + 2 * ID_LEN)) { /* 68 with suffix */
- log_debug_activation("%s: Reserved uuid %s on internal LV device %s not usable.",
- dev_name(dev), uuid, name);
- goto out;
- }
-
- /* Recognize some older reserved LVs just from the LV name (snapshot, pvmove...) */
- vgname = vg_name;
- if (!dm_strncpy(vg_name, name, sizeof(vg_name)) ||
- !dm_split_lvm_name(NULL, NULL, &vgname, &lvname, &layer))
- goto_out;
-
- /* FIXME: fails to handle dev aliases i.e. /dev/dm-5, replace with UUID suffix */
- if (lvname && (is_reserved_lvname(lvname) || *layer)) {
- log_debug_activation("%s: Reserved internal LV device %s/%s%s%s not usable.",
- dev_name(dev), vgname, lvname, *layer ? "-" : "", layer);
- goto out;
- }
- }
-
- if (check.check_lv) {
- /* Skip LVs */
- if (is_lv)
- *is_lv = 1;
- goto out;
- }
- }
-
- if (check.check_reserved &&
- (!strncmp(uuid, CRYPT_TEMP, sizeof(CRYPT_TEMP) - 1) ||
- !strncmp(uuid, CRYPT_SUBDEV, sizeof(CRYPT_SUBDEV) - 1) ||
- !strncmp(uuid, STRATIS, sizeof(STRATIS) - 1))) {
- /* Skip private crypto devices */
- log_debug_activation("%s: Reserved uuid %s on %s device %s not usable.",
- dev_name(dev), uuid,
- uuid[0] == 'C' ? "crypto" : "stratis",
- name);
- goto out;
- }
- }
+ if (uuid &&
+ !_is_usable_uuid(dev, name, uuid, check.check_reserved, check.check_lv, is_lv))
+ goto out;
/* FIXME Also check for mpath no paths */
do {
@@ -713,7 +726,7 @@ int device_is_usable(struct device *dev, struct dev_usable_check_params check, i
log_debug_activation("%s: Scanning mirror devices is disabled.", dev_name(dev));
goto out;
}
- if (!_ignore_blocked_mirror_devices(dev, start,
+ if (!_ignore_blocked_mirror_devices(cmd, dev, start,
length, params)) {
log_debug_activation("%s: Mirror device %s not usable.",
dev_name(dev), name);
diff --git a/lib/filters/filter-usable.c b/lib/filters/filter-usable.c
index 062fb6c74..d7bdf115e 100644
--- a/lib/filters/filter-usable.c
+++ b/lib/filters/filter-usable.c
@@ -87,7 +87,7 @@ static int _passes_usable_filter(struct cmd_context *cmd, struct dev_filter *f,
break;
}
- if (!(r = device_is_usable(dev, ucp, &is_lv))) {
+ if (!(r = device_is_usable(cmd, dev, ucp, &is_lv))) {
if (is_lv)
dev->filtered_flags |= DEV_FILTERED_IS_LV;
else
2 years, 4 months
main - lvmcmdline: comment reset of configuration settings
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=5a78979b68c4ae822c3...
Commit: 5a78979b68c4ae822c3f9bcc7ba662c7aa727b40
Parent: 39a121ddbcf83314c5a75e23671acbc6600292ce
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Dec 17 16:41:54 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Dec 20 16:13:28 2021 +0100
lvmcmdline: comment reset of configuration settings
We used to reset 'settings' to their defaults after command is finished.
This however has a drawback we lose all the logging after this point.
So this patch disables this 'reset' to observe for side-effects.
lvm shell should be getting reset when next command is run -
so this might or might not have some 'hidden' effects.
ATM it looks like nothing really bad should happen - we just should be
able to get more logs - at least from normal commands.
---
tools/lvmcmdline.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 7e3afc241..241c6df18 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -3335,8 +3335,8 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
* ignore everything supplied on the command line of the
* completed command.
*/
- _reset_current_settings_to_default(cmd);
- _apply_current_settings(cmd);
+ //_reset_current_settings_to_default(cmd);
+ //_apply_current_settings(cmd);
/*
* free off any memory the command used.
2 years, 4 months
main - libdm: correct version check
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=39a121ddbcf83314c5a...
Commit: 39a121ddbcf83314c5a75e23671acbc6600292ce
Parent: 47ac2659d5f8544dcd53aeef13a42b3256f2fd6f
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Dec 8 10:56:21 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Dec 20 16:13:28 2021 +0100
libdm: correct version check
If there ever would be API version 5,
these check would give incorrect results.
---
device_mapper/ioctl/libdm-iface.c | 6 ++----
libdm/ioctl/libdm-iface.c | 6 ++----
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/device_mapper/ioctl/libdm-iface.c b/device_mapper/ioctl/libdm-iface.c
index 533bb9eea..925f18c6b 100644
--- a/device_mapper/ioctl/libdm-iface.c
+++ b/device_mapper/ioctl/libdm-iface.c
@@ -616,8 +616,7 @@ int dm_check_version(void)
int dm_cookie_supported(void)
{
return (dm_check_version() &&
- _dm_version >= 4 &&
- _dm_version_minor >= 15);
+ ((_dm_version == 4) ? _dm_version_minor >= 15 : _dm_version > 4));
}
static int _dm_inactive_supported(void)
@@ -1441,8 +1440,7 @@ static int _udev_complete(struct dm_task *dmt)
static int _check_uevent_generated(struct dm_ioctl *dmi)
{
if (!dm_check_version() ||
- _dm_version < 4 ||
- _dm_version_minor < 17)
+ ((_dm_version == 4) ? _dm_version_minor < 17 : _dm_version < 4))
/* can't check, assume uevent is generated */
return 1;
diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c
index 28589a15c..a3a1bdc66 100644
--- a/libdm/ioctl/libdm-iface.c
+++ b/libdm/ioctl/libdm-iface.c
@@ -609,8 +609,7 @@ int dm_check_version(void)
int dm_cookie_supported(void)
{
return (dm_check_version() &&
- _dm_version >= 4 &&
- _dm_version_minor >= 15);
+ ((_dm_version == 4) ? _dm_version_minor >= 15 : _dm_version > 4));
}
static int _dm_inactive_supported(void)
@@ -1436,8 +1435,7 @@ static int _udev_complete(struct dm_task *dmt)
static int _check_uevent_generated(struct dm_ioctl *dmi)
{
if (!dm_check_version() ||
- _dm_version < 4 ||
- _dm_version_minor < 17)
+ ((_dm_version == 4) ? _dm_version_minor < 17 : _dm_version < 4))
/* can't check, assume uevent is generated */
return 1;
2 years, 4 months
main - activate: cache driver_version result
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=47ac2659d5f8544dcd5...
Commit: 47ac2659d5f8544dcd53aeef13a42b3256f2fd6f
Parent: 26e6580dfb00912823282f7028ab542501c449ef
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed Dec 8 10:25:02 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Dec 20 16:13:28 2021 +0100
activate: cache driver_version result
---
lib/activate/activate.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index 727bd2386..52ec02e2c 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -486,12 +486,20 @@ int library_version(char *version, size_t size)
int driver_version(char *version, size_t size)
{
+ static char _vsn[80] = { 0 };
+
if (!activation())
return 0;
log_very_verbose("Getting driver version");
- return dm_driver_version(version, size);
+ if (!_vsn[0] &&
+ !dm_driver_version(_vsn, sizeof(_vsn)))
+ return_0;
+
+ (void) dm_strncpy(version, _vsn, size);
+
+ return 1;
}
int target_version(const char *target_name, uint32_t *maj,
2 years, 4 months
main - toolcontext: reuse destroy_config_context
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=26e6580dfb009128232...
Commit: 26e6580dfb00912823282f7028ab542501c449ef
Parent: 09a4b56895b959f46a9b7e7af11732d8e1bbf945
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Dec 10 20:51:46 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Dec 20 16:13:28 2021 +0100
toolcontext: reuse destroy_config_context
Call existing destroy_config_context() to destroy
some parts of cmd_context.
---
lib/commands/toolcontext.c | 10 +---------
1 file changed, 1 insertion(+), 9 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index a0c78ddd6..c772dc6b1 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -2041,8 +2041,6 @@ void destroy_toolcontext(struct cmd_context *cmd)
_destroy_segtypes(&cmd->segtypes);
_destroy_formats(cmd, &cmd->formats);
_destroy_filters(cmd);
- if (cmd->mem)
- dm_pool_destroy(cmd->mem);
devices_file_exit(cmd);
dev_cache_exit();
_destroy_dev_types(cmd);
@@ -2050,16 +2048,10 @@ void destroy_toolcontext(struct cmd_context *cmd)
if ((cft_cmdline = remove_config_tree_by_source(cmd, CONFIG_STRING)))
config_destroy(cft_cmdline);
- _destroy_config(cmd);
if (cmd->cft_def_hash)
dm_hash_destroy(cmd->cft_def_hash);
- if (cmd->libmem)
- dm_pool_destroy(cmd->libmem);
-
- if (cmd->pending_delete_mem)
- dm_pool_destroy(cmd->pending_delete_mem);
#ifndef VALGRIND_POOL
if (cmd->linebuffer) {
/* Reset stream buffering to defaults */
@@ -2084,7 +2076,7 @@ void destroy_toolcontext(struct cmd_context *cmd)
free(cmd->linebuffer);
}
#endif
- free(cmd);
+ destroy_config_context(cmd);
lvmpolld_disconnect();
2 years, 4 months
main - hash: raise hash table size
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=09a4b56895b959f46a9...
Commit: 09a4b56895b959f46a9b7e7af11732d8e1bbf945
Parent: ed1651d11f42ea7157b7b0aebf498b97e56b98aa
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Dec 17 16:36:36 2021 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Dec 20 16:13:28 2021 +0100
hash: raise hash table size
With slightly bigger hash tables, there is considerable
less hash collisions.
---
WHATS_NEW | 1 +
lib/config/config.c | 2 +-
lib/device/dev-cache.c | 2 +-
lib/filters/filter-persistent.c | 2 +-
4 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index b0720cd10..fc327dffd 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.03.15 -
===================================
+ Increase some hash table size to better support large device sets.
Version 2.03.14 - 20th October 2021
===================================
diff --git a/lib/config/config.c b/lib/config/config.c
index 0cb0da121..c8dab5683 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -1167,7 +1167,7 @@ int config_def_check(struct cft_check_handle *handle)
*vp = 0;
*rp = 0;
if (!handle->cmd->cft_def_hash) {
- if (!(handle->cmd->cft_def_hash = dm_hash_create(60))) {
+ if (!(handle->cmd->cft_def_hash = dm_hash_create(500))) {
log_error("Failed to create configuration definition hash.");
r = 0; goto out;
}
diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index 825e348b4..d3fae4948 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -1246,7 +1246,7 @@ int dev_cache_init(struct cmd_context *cmd)
if (!(_cache.mem = dm_pool_create("dev_cache", 10 * 1024)))
return_0;
- if (!(_cache.names = dm_hash_create(120)) ||
+ if (!(_cache.names = dm_hash_create(1020)) ||
!(_cache.vgid_index = dm_hash_create(30)) ||
!(_cache.lvid_index = dm_hash_create(29))) {
dm_pool_destroy(_cache.mem);
diff --git a/lib/filters/filter-persistent.c b/lib/filters/filter-persistent.c
index 494a38ece..c164c4a99 100644
--- a/lib/filters/filter-persistent.c
+++ b/lib/filters/filter-persistent.c
@@ -58,7 +58,7 @@ static int _init_hash(struct pfilter *pf)
if (pf->devices)
dm_hash_destroy(pf->devices);
- if (!(pf->devices = dm_hash_create(111)))
+ if (!(pf->devices = dm_hash_create(511)))
return_0;
return 1;
2 years, 4 months