main - rename pvscan_cache_single to expect_missing_vg_device in cmd
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=594f6ca97024fa23dfa...
Commit: 594f6ca97024fa23dfa852b6cc9da272877e1ced
Parent: 726dd25969e9e6a3de285a22cea45e9f5f53520f
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Nov 3 09:50:11 2021 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Nov 4 11:08:38 2021 -0500
rename pvscan_cache_single to expect_missing_vg_device in cmd
---
lib/commands/toolcontext.h | 2 +-
lib/device/device_id.c | 5 ++---
lib/metadata/metadata.c | 4 ++--
tools/pvscan.c | 2 +-
4 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index e864932f2..0ae45ccc0 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -174,7 +174,7 @@ struct cmd_context {
unsigned activate_component:1; /* command activates component LV */
unsigned process_component_lvs:1; /* command processes also component LVs */
unsigned mirror_warn_printed:1; /* command already printed warning about non-monitored mirrors */
- unsigned pvscan_cache_single:1;
+ unsigned expect_missing_vg_device:1; /* when reading a vg it's expected that a dev for a pv isn't found */
unsigned can_use_one_scan:1;
unsigned is_clvmd:1;
unsigned md_component_detection:1;
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
index 167bf661b..18669630c 100644
--- a/lib/device/device_id.c
+++ b/lib/device/device_id.c
@@ -778,9 +778,8 @@ static void _device_ids_update_try(struct cmd_context *cmd)
{
int held = 0;
- /* Defer updates to non-pvscan-cache commands. */
- if (cmd->pvscan_cache_single) {
- log_print("pvscan[%d] skip updating devices file.", getpid());
+ if (cmd->expect_missing_vg_device) {
+ log_print("skip updating devices file.");
return;
}
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index c4f65366b..f01a0bea6 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -3558,7 +3558,7 @@ static void _set_pv_device(struct format_instance *fid,
if (!id_write_format(&pv->id, buffer, sizeof(buffer)))
buffer[0] = '\0';
- if (cmd && !cmd->pvscan_cache_single &&
+ if (cmd && !cmd->expect_missing_vg_device &&
(!vg_is_foreign(vg) && !cmd->include_foreign_vgs))
log_warn("WARNING: Couldn't find device with uuid %s.", buffer);
else
@@ -5084,7 +5084,7 @@ struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name, const
if (!pvl->pv->dev) {
/* The obvious and common case of a missing device. */
- if (vg_is_foreign(vg) && !cmd->include_foreign_vgs)
+ if ((vg_is_foreign(vg) && !cmd->include_foreign_vgs) || cmd->expect_missing_vg_device)
log_debug("VG %s is missing PV %s (last written to %s)", vg_name, uuidstr, pvl->pv->device_hint ?: "na");
else if (pvl->pv->device_hint)
log_warn("WARNING: VG %s is missing PV %s (last written to %s).", vg_name, uuidstr, pvl->pv->device_hint);
diff --git a/tools/pvscan.c b/tools/pvscan.c
index 01f57af0c..4f97e211c 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -1679,7 +1679,7 @@ static int _pvscan_cache_args(struct cmd_context *cmd, int argc, char **argv,
dm_list_init(&pvscan_args);
dm_list_init(&pvscan_devs);
- cmd->pvscan_cache_single = 1;
+ cmd->expect_missing_vg_device = 1;
/*
* Special pvscan-specific setup steps to avoid looking
2 years, 5 months
main - add hints interface to the pvs_online file information
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=726dd25969e9e6a3de2...
Commit: 726dd25969e9e6a3de285a22cea45e9f5f53520f
Parent: 6ea8d975b23758e6e099bf51cf7334f27f9fd096
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Jul 15 16:33:50 2021 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Nov 4 10:58:16 2021 -0500
add hints interface to the pvs_online file information
The information in /run/lvm/pvs_online/<pvid> files can
be used to build a list of devices for a given VG.
The pvscan -aay command has long used this information to
activate a VG while scanning only devices in that VG, which
is an important optimization for autoactivation.
This patch implements the same thing through the existing
device hints interface, so that the optimization can be
applied elsewhere. A future patch will take advantage of
this optimization in vgchange -aay, which is now used in
place of pvscan -aay for event activation.
---
lib/commands/toolcontext.h | 1 +
lib/config/defaults.h | 4 ++
lib/label/hints.c | 121 ++++++++++++++++++++++++++++++++++++++++++++-
lib/label/label.c | 3 ++
tools/lvmcmdline.c | 2 +
tools/pvscan.c | 12 +++--
6 files changed, 137 insertions(+), 6 deletions(-)
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index 356c79f8a..e864932f2 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -183,6 +183,7 @@ struct cmd_context {
unsigned enable_hints:1; /* hints are enabled for cmds in general */
unsigned use_hints:1; /* if hints are enabled this cmd can use them */
unsigned pvscan_recreate_hints:1; /* enable special case hint handling for pvscan --cache */
+ unsigned hints_pvs_online:1; /* hints="pvs_online" */
unsigned scan_lvs:1;
unsigned wipe_outdated_pvs:1;
unsigned enable_devices_list:1; /* command is using --devices option */
diff --git a/lib/config/defaults.h b/lib/config/defaults.h
index 1b1568a7b..3308b1ea6 100644
--- a/lib/config/defaults.h
+++ b/lib/config/defaults.h
@@ -328,4 +328,8 @@
#define DEFAULT_WWIDS_FILE "/etc/multipath/wwids"
+#define PVS_ONLINE_DIR DEFAULT_RUN_DIR "/pvs_online"
+#define VGS_ONLINE_DIR DEFAULT_RUN_DIR "/vgs_online"
+#define PVS_LOOKUP_DIR DEFAULT_RUN_DIR "/pvs_lookup"
+
#endif /* _LVM_DEFAULTS_H */
diff --git a/lib/label/hints.c b/lib/label/hints.c
index e444a0c82..c84bd1f1c 100644
--- a/lib/label/hints.c
+++ b/lib/label/hints.c
@@ -150,11 +150,14 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
+#include <dirent.h>
#include <time.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/sysmacros.h>
+int online_pvid_file_read(char *path, int *major, int *minor, char *vgname);
+
static const char *_hints_file = DEFAULT_RUN_DIR "/hints";
static const char *_nohints_file = DEFAULT_RUN_DIR "/nohints";
static const char *_newhints_file = DEFAULT_RUN_DIR "/newhints";
@@ -1278,6 +1281,109 @@ check:
free(name);
}
+static int _get_hints_from_pvs_online(struct cmd_context *cmd, struct dm_list *hints_out,
+ struct dm_list *devs_in, struct dm_list *devs_out)
+{
+ char path[PATH_MAX];
+ char file_vgname[NAME_LEN];
+ struct dm_list hints_list;
+ struct hint file_hint;
+ struct hint *alloc_hint;
+ struct hint *hint, *hint2;
+ struct device_list *devl, *devl2;
+ int file_major, file_minor;
+ int found = 0;
+ DIR *dir;
+ struct dirent *de;
+ char *vgname = NULL;
+ char *pvid;
+
+ dm_list_init(&hints_list);
+
+ if (!(dir = opendir(PVS_ONLINE_DIR)))
+ return 0;
+
+ while ((de = readdir(dir))) {
+ if (de->d_name[0] == '.')
+ continue;
+
+ pvid = de->d_name;
+
+ if (strlen(pvid) != ID_LEN) /* 32 */
+ continue;
+
+ memset(path, 0, sizeof(path));
+ snprintf(path, sizeof(path), "%s/%s", PVS_ONLINE_DIR, pvid);
+
+ memset(&file_hint, 0, sizeof(file_hint));
+ memset(file_vgname, 0, sizeof(file_vgname));
+ file_major = 0;
+ file_minor = 0;
+
+ if (!online_pvid_file_read(path, &file_major, &file_minor, file_vgname))
+ continue;
+
+ if (!dm_strncpy(file_hint.pvid, pvid, sizeof(file_hint.pvid)))
+ continue;
+
+ file_hint.devt = makedev(file_major, file_minor);
+
+ if (file_vgname[0] && validate_name(file_vgname)) {
+ if (!dm_strncpy(file_hint.vgname, file_vgname, sizeof(file_hint.vgname)))
+ continue;
+ }
+
+ if (!(alloc_hint = malloc(sizeof(struct hint))))
+ continue;
+
+ memcpy(alloc_hint, &file_hint, sizeof(struct hint));
+
+ log_debug("add hint %s %d:%d %s from pvs_online", file_hint.pvid, file_major, file_minor, file_vgname);
+ dm_list_add(&hints_list, &alloc_hint->list);
+ found++;
+ }
+
+ if (closedir(dir))
+ stack;
+
+ log_debug("accept hints found %d from pvs_online", found);
+
+ _get_single_vgname_cmd_arg(cmd, &hints_list, &vgname);
+
+ /*
+ * apply_hints equivalent, move devs from devs_in to devs_out if
+ * their devno matches the devno of a hint (and if the hint matches
+ * the vgname when a vgname is present.)
+ */
+ dm_list_iterate_items_safe(devl, devl2, devs_in) {
+ dm_list_iterate_items_safe(hint, hint2, &hints_list) {
+ if ((MAJOR(devl->dev->dev) == MAJOR(hint->devt)) &&
+ (MINOR(devl->dev->dev) == MINOR(hint->devt))) {
+
+ if (vgname && hint->vgname[0] && strcmp(vgname, hint->vgname))
+ goto next_dev;
+
+ snprintf(hint->name, sizeof(hint->name), "%s", dev_name(devl->dev));
+ hint->chosen = 1;
+
+ dm_list_del(&devl->list);
+ dm_list_add(devs_out, &devl->list);
+ }
+ }
+ next_dev:
+ ;
+ }
+
+ log_debug("applied hints using %d other %d vgname %s from pvs_online",
+ dm_list_size(devs_out), dm_list_size(devs_in), vgname ?: "");
+
+ dm_list_splice(hints_out, &hints_list);
+
+ free(vgname);
+
+ return 1;
+}
+
/*
* Returns 0: no hints are used.
* . newhints is set if this command should create new hints after scan
@@ -1299,7 +1405,7 @@ int get_hints(struct cmd_context *cmd, struct dm_list *hints_out, int *newhints,
*newhints = NEWHINTS_NONE;
/* No commands are using hints. */
- if (!cmd->enable_hints)
+ if (!cmd->enable_hints && !cmd->hints_pvs_online)
return 0;
/*
@@ -1319,6 +1425,19 @@ int get_hints(struct cmd_context *cmd, struct dm_list *hints_out, int *newhints,
if (!cmd->use_hints)
return 0;
+ /*
+ * enable_hints is 0 for the special hints=pvs_online
+ * and by lvm.conf hints="none" does not disable hints=pvs_online.
+ * hints=pvs_online can be disabled with --nohints.
+ */
+ if (cmd->hints_pvs_online) {
+ if (!_get_hints_from_pvs_online(cmd, &hints_list, devs_in, devs_out)) {
+ log_debug("get_hints: pvs_online failed");
+ return 0;
+ }
+ return 1;
+ }
+
/*
* Check if another command created the nohints file to prevent us from
* using hints.
diff --git a/lib/label/label.c b/lib/label/label.c
index 9fac3e464..f9ab9a1f1 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -1130,6 +1130,9 @@ int label_scan(struct cmd_context *cmd)
}
}
}
+
+ log_debug_devs("Filtering devices to scan done (nodata)");
+
cmd->filter_nodata_only = 0;
dm_list_iterate_items(devl, &all_devs)
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 1e12bedca..9cbeab91d 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -2540,6 +2540,8 @@ static int _get_current_settings(struct cmd_context *cmd)
if (!strcmp(hint_mode, "none")) {
cmd->enable_hints = 0;
cmd->use_hints = 0;
+ } else if (!strcmp(hint_mode, "pvs_online")) {
+ cmd->hints_pvs_online = 1;
}
}
diff --git a/tools/pvscan.c b/tools/pvscan.c
index 7d84e45d4..01f57af0c 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -21,6 +21,8 @@
#include <dirent.h>
+int online_pvid_file_read(char *path, int *major, int *minor, char *vgname);
+
struct pvscan_params {
int new_pvs_found;
int pvs_found;
@@ -225,7 +227,7 @@ static char *_vgname_in_pvid_file_buf(char *buf)
#define MAX_PVID_FILE_SIZE 512
-static int _online_pvid_file_read(char *path, int *major, int *minor, char *vgname)
+int online_pvid_file_read(char *path, int *major, int *minor, char *vgname)
{
char buf[MAX_PVID_FILE_SIZE] = { 0 };
char *name;
@@ -328,7 +330,7 @@ static void _online_pvid_file_remove_devno(int major, int minor)
file_minor = 0;
memset(file_vgname, 0, sizeof(file_vgname));
- _online_pvid_file_read(path, &file_major, &file_minor, file_vgname);
+ online_pvid_file_read(path, &file_major, &file_minor, file_vgname);
if ((file_major == major) && (file_minor == minor)) {
log_debug("Unlink pv online %s", path);
@@ -447,7 +449,7 @@ check_duplicate:
memset(file_vgname, 0, sizeof(file_vgname));
- _online_pvid_file_read(path, &file_major, &file_minor, file_vgname);
+ online_pvid_file_read(path, &file_major, &file_minor, file_vgname);
if ((file_major == major) && (file_minor == minor)) {
log_debug("Existing online file for %d:%d", major, minor);
@@ -847,7 +849,7 @@ static int _get_devs_from_saved_vg(struct cmd_context *cmd, const char *vgname,
file_minor = 0;
memset(file_vgname, 0, sizeof(file_vgname));
- _online_pvid_file_read(path, &file_major, &file_minor, file_vgname);
+ online_pvid_file_read(path, &file_major, &file_minor, file_vgname);
if (file_vgname[0] && strcmp(vgname, file_vgname)) {
log_error_pvscan(cmd, "Wrong VG found for %d:%d PVID %s: %s vs %s",
@@ -1254,7 +1256,7 @@ static void _set_pv_devices_online(struct cmd_context *cmd, struct volume_group
minor = 0;
file_vgname[0] = '\0';
- _online_pvid_file_read(path, &major, &minor, file_vgname);
+ online_pvid_file_read(path, &major, &minor, file_vgname);
if (file_vgname[0] && strcmp(vg->name, file_vgname)) {
log_warn("WARNING: VG %s PV %s wrong vgname in online file %s",
2 years, 5 months
main - lvmdevices: increase open file limit
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=6ea8d975b23758e6e09...
Commit: 6ea8d975b23758e6e099bf51cf7334f27f9fd096
Parent: b5b0369e4decbd7e2b4a160ba8ebad4e8f8a4094
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri Oct 29 14:49:36 2021 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Nov 3 08:50:57 2021 -0500
lvmdevices: increase open file limit
---
lib/label/label.c | 4 ++--
lib/label/label.h | 2 ++
tools/lvmdevices.c | 3 +++
3 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/lib/label/label.c b/lib/label/label.c
index 479a5037a..9fac3e464 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -891,7 +891,7 @@ static int _setup_bcache(void)
#define BASE_FD_COUNT 32 /* Number of open files we want apart from devs */
-static void _prepare_open_file_limit(struct cmd_context *cmd, unsigned int num_devs)
+void prepare_open_file_limit(struct cmd_context *cmd, unsigned int num_devs)
{
#ifdef HAVE_PRLIMIT
struct rlimit old = { 0 }, new;
@@ -1165,7 +1165,7 @@ int label_scan(struct cmd_context *cmd)
* which we want to keep open) is higher than the current
* soft limit.
*/
- _prepare_open_file_limit(cmd, dm_list_size(&scan_devs));
+ prepare_open_file_limit(cmd, dm_list_size(&scan_devs));
/*
* Do the main scan.
diff --git a/lib/label/label.h b/lib/label/label.h
index 8b510eb79..34563efd0 100644
--- a/lib/label/label.h
+++ b/lib/label/label.h
@@ -134,4 +134,6 @@ void dev_invalidate(struct device *dev);
void dev_set_last_byte(struct device *dev, uint64_t offset);
void dev_unset_last_byte(struct device *dev);
+void prepare_open_file_limit(struct cmd_context *cmd, unsigned int num_devs);
+
#endif
diff --git a/tools/lvmdevices.c b/tools/lvmdevices.c
index 8d9634848..3f104f7de 100644
--- a/tools/lvmdevices.c
+++ b/tools/lvmdevices.c
@@ -176,6 +176,9 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
log_error("Failed to read the devices file.");
return ECMD_FAILED;
}
+
+ prepare_open_file_limit(cmd, dm_list_size(&cmd->use_devices));
+
dev_cache_scan(cmd);
device_ids_match(cmd);
2 years, 5 months
main - filter-sysfs: skip when device id is set
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b5b0369e4decbd7e2b4...
Commit: b5b0369e4decbd7e2b4a160ba8ebad4e8f8a4094
Parent: 5d0964d127ea62da480cafc91fefe403dda86870
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Nov 2 15:42:26 2021 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Nov 2 16:54:53 2021 -0500
filter-sysfs: skip when device id is set
When a device id is set for a device, using an idtype other
than devname, it means that sysfs has been used with the device
to match the device id. So, checking for a sysfs entry for the
device in filter-sysfs is redundant. For any other cases not
covered by this (e.g. devname ids), have filter-sysfs simply
stat /sys/dev/block/major:minor to test if the device exists
in sysfs.
The extensive processing done by filter-sysfs init is removed.
It was taking an immense amount of time with many devices, e.g.
. 1024 PVs in 520 VGs
. 520 concurrent vgchange -ay <vgname> commands
. vgchange scans only PVs in the named VG (based on pvs_online
files from a pending patch)
A large number of the vgchange commands were taking over 1 min,
and nearly half of that time was used by filter-sysfs init.
With this patch, the vgchange commands take about half the time.
---
lib/commands/toolcontext.c | 24 ++--
lib/filters/filter-sysfs.c | 296 ++++-----------------------------------------
2 files changed, 32 insertions(+), 288 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 1b7170de1..a0c78ddd6 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -1143,19 +1143,6 @@ static struct dev_filter *_init_filter_chain(struct cmd_context *cmd)
* Update MAX_FILTERS definition above when adding new filters.
*/
- /*
- * sysfs filter. Only available on 2.6 kernels. Non-critical.
- * Listed first because it's very efficient at eliminating
- * unavailable devices.
- *
- * TODO: I suspect that using the lvm_type and device_id
- * filters before this one may be more efficient.
- */
- if (find_config_tree_bool(cmd, devices_sysfs_scan_CFG, NULL)) {
- if ((filters[nr_filt] = sysfs_filter_create()))
- nr_filt++;
- }
-
/* internal filter used by command processing. */
if (!(filters[nr_filt] = internal_filter_create())) {
log_error("Failed to create internal device filter");
@@ -1195,6 +1182,17 @@ static struct dev_filter *_init_filter_chain(struct cmd_context *cmd)
}
nr_filt++;
+ /*
+ * sysfs filter. Only available on 2.6 kernels. Non-critical.
+ * Eliminates unavailable devices.
+ * TODO: this may be unnecessary now with device ids
+ * (currently not used for devs match to device id using syfs)
+ */
+ if (find_config_tree_bool(cmd, devices_sysfs_scan_CFG, NULL)) {
+ if ((filters[nr_filt] = sysfs_filter_create()))
+ nr_filt++;
+ }
+
/* usable device filter. Required. */
if (!(filters[nr_filt] = usable_filter_create(cmd, cmd->dev_types, FILTER_MODE_NO_LVMETAD))) {
log_error("Failed to create usabled device filter");
diff --git a/lib/filters/filter-sysfs.c b/lib/filters/filter-sysfs.c
index 32ac324dd..672211057 100644
--- a/lib/filters/filter-sysfs.c
+++ b/lib/filters/filter-sysfs.c
@@ -17,288 +17,49 @@
#ifdef __linux__
-#include <sys/sysmacros.h>
-#include <dirent.h>
-
-static int _locate_sysfs_blocks(const char *sysfs_dir, char *path, size_t len,
- unsigned *sysfs_depth)
+static int _accept_p(struct cmd_context *cmd, struct dev_filter *f, struct device *dev, const char *use_filter_name)
{
+ char path[PATH_MAX];
+ const char *sysfs_dir;
struct stat info;
- unsigned i;
- static const struct dir_class {
- const char path[32];
- int depth;
- } classes[] = {
- /*
- * unified classification directory for all kernel subsystems
- *
- * /sys/subsystem/block/devices
- * |-- sda -> ../../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
- * |-- sda1 -> ../../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1
- * `-- sr0 -> ../../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0
- *
- */
- { "subsystem/block/devices", 0 },
-
- /*
- * block subsystem as a class
- *
- * /sys/class/block
- * |-- sda -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
- * |-- sda1 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1
- * `-- sr0 -> ../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0
- *
- */
- { "class/block", 0 },
-
- /*
- * old block subsystem layout with nested directories
- *
- * /sys/block/
- * |-- sda
- * | |-- capability
- * | |-- dev
- * ...
- * | |-- sda1
- * | | |-- dev
- * ...
- * |
- * `-- sr0
- * |-- capability
- * |-- dev
- * ...
- *
- */
-
- { "block", 1 }
- };
-
- for (i = 0; i < DM_ARRAY_SIZE(classes); ++i)
- if ((dm_snprintf(path, len, "%s%s", sysfs_dir, classes[i].path) >= 0) &&
- (stat(path, &info) == 0)) {
- *sysfs_depth = classes[i].depth;
- return 1;
- }
-
- return 0;
-}
-
-/*----------------------------------------------------------------
- * We need to store a set of dev_t.
- *--------------------------------------------------------------*/
-struct entry {
- struct entry *next;
- dev_t dev;
-};
-
-#define SET_BUCKETS 64
-struct dev_set {
- struct dm_pool *mem;
- const char *sys_block;
- unsigned sysfs_depth;
- int initialised;
- struct entry *slots[SET_BUCKETS];
-};
-
-static struct dev_set *_dev_set_create(struct dm_pool *mem,
- const char *sys_block,
- unsigned sysfs_depth)
-{
- struct dev_set *ds;
-
- if (!(ds = dm_pool_zalloc(mem, sizeof(*ds))))
- return NULL;
-
- ds->mem = mem;
- if (!(ds->sys_block = dm_pool_strdup(mem, sys_block)))
- return NULL;
-
- ds->sysfs_depth = sysfs_depth;
- ds->initialised = 0;
-
- return ds;
-}
-
-static unsigned _hash_dev(dev_t dev)
-{
- return (major(dev) ^ minor(dev)) & (SET_BUCKETS - 1);
-}
-/*
- * Doesn't check that the set already contains dev.
- */
-static int _set_insert(struct dev_set *ds, dev_t dev)
-{
- struct entry *e;
- unsigned h = _hash_dev(dev);
-
- if (!(e = dm_pool_alloc(ds->mem, sizeof(*e))))
- return 0;
-
- e->next = ds->slots[h];
- e->dev = dev;
- ds->slots[h] = e;
-
- return 1;
-}
+ dev->filtered_flags &= ~DEV_FILTERED_SYSFS;
-static int _set_lookup(struct dev_set *ds, dev_t dev)
-{
- unsigned h = _hash_dev(dev);
- struct entry *e;
+ /*
+ * Any kind of device id other than devname has been set
+ * using sysfs so we know that sysfs info exists for dev.
+ */
+ if (dev->id && dev->id->idtype && (dev->id->idtype != DEV_ID_TYPE_DEVNAME))
+ return 1;
- for (e = ds->slots[h]; e; e = e->next)
- if (e->dev == dev)
+ sysfs_dir = dm_sysfs_dir();
+ if (sysfs_dir && *sysfs_dir) {
+ if (dm_snprintf(path, sizeof(path), "%sdev/block/%d:%d",
+ sysfs_dir, (int)MAJOR(dev->dev), (int)MINOR(dev->dev)) < 0) {
+ log_debug("failed to create sysfs path");
return 1;
-
- return 0;
-}
-
-/*----------------------------------------------------------------
- * filter methods
- *--------------------------------------------------------------*/
-static int _parse_dev(const char *file, FILE *fp, dev_t *result)
-{
- unsigned major, minor;
- char buffer[64];
-
- if (!fgets(buffer, sizeof(buffer), fp)) {
- log_error("Empty sysfs device file: %s", file);
- return 0;
- }
-
- if (sscanf(buffer, "%u:%u", &major, &minor) != 2) {
- log_error("Incorrect format for sysfs device file: %s.", file);
- return 0;
- }
-
- *result = makedev(major, minor);
- return 1;
-}
-
-static int _read_dev(const char *file, dev_t *result)
-{
- int r;
- FILE *fp;
-
- if (!(fp = fopen(file, "r"))) {
- log_sys_error("fopen", file);
- return 0;
- }
-
- r = _parse_dev(file, fp, result);
-
- if (fclose(fp))
- log_sys_error("fclose", file);
-
- return r;
-}
-
-/*
- * Recurse through sysfs directories, inserting any devs found.
- */
-static int _read_devs(struct dev_set *ds, const char *dir, unsigned sysfs_depth)
-{
- struct dirent *d;
- DIR *dr;
- struct stat info;
- char path[PATH_MAX];
- char file[PATH_MAX];
- dev_t dev = { 0 };
- int r = 1;
-
- if (!(dr = opendir(dir))) {
- log_sys_error("opendir", dir);
- return 0;
- }
-
- while ((d = readdir(dr))) {
- if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
- continue;
-
- if (dm_snprintf(path, sizeof(path), "%s/%s", dir,
- d->d_name) < 0) {
- log_warn("WARNING: sysfs path name too long: %s in %s.",
- d->d_name, dir);
- continue;
}
- /* devices have a "dev" file */
- if (dm_snprintf(file, sizeof(file), "%s/dev", path) < 0) {
- log_warn("WARNING: sysfs path name too long: %s in %s.",
- d->d_name, dir);
- continue;
- }
-
- if (!stat(file, &info)) {
- /* recurse if we found a device and expect subdirs */
- if (sysfs_depth)
- _read_devs(ds, path, sysfs_depth - 1);
-
- /* add the device we have found */
- if (_read_dev(file, &dev))
- _set_insert(ds, dev);
+ if (lstat(path, &info)) {
+ log_debug_devs("%s: Skipping (sysfs)", dev_name(dev));
+ dev->filtered_flags |= DEV_FILTERED_SYSFS;
+ return 0;
}
}
- if (closedir(dr))
- log_sys_debug("closedir", dir);
-
- return r;
-}
-
-static int _init_devs(struct dev_set *ds)
-{
- if (!_read_devs(ds, ds->sys_block, ds->sysfs_depth)) {
- ds->initialised = -1;
- return 0;
- }
-
- ds->initialised = 1;
-
- return 1;
-}
-
-
-static int _accept_p(struct cmd_context *cmd, struct dev_filter *f, struct device *dev, const char *use_filter_name)
-{
- struct dev_set *ds = (struct dev_set *) f->private;
-
- dev->filtered_flags &= ~DEV_FILTERED_SYSFS;
-
- if (!ds->initialised)
- _init_devs(ds);
-
- /* Pass through if initialisation failed */
- if (ds->initialised != 1)
- return 1;
-
- if (!_set_lookup(ds, dev->dev)) {
- log_debug_devs("%s: Skipping (sysfs)", dev_name(dev));
- dev->filtered_flags |= DEV_FILTERED_SYSFS;
- return 0;
- }
-
return 1;
}
static void _destroy(struct dev_filter *f)
{
- struct dev_set *ds = (struct dev_set *) f->private;
-
if (f->use_count)
log_error(INTERNAL_ERROR "Destroying sysfs filter while in use %u times.", f->use_count);
-
- dm_pool_destroy(ds->mem);
+ free(f);
}
struct dev_filter *sysfs_filter_create(void)
{
const char *sysfs_dir = dm_sysfs_dir();
- char sys_block[PATH_MAX];
- unsigned sysfs_depth;
- struct dm_pool *mem;
- struct dev_set *ds;
struct dev_filter *f;
if (!*sysfs_dir) {
@@ -306,26 +67,12 @@ struct dev_filter *sysfs_filter_create(void)
return NULL;
}
- if (!_locate_sysfs_blocks(sysfs_dir, sys_block, sizeof(sys_block), &sysfs_depth))
- return NULL;
-
- if (!(mem = dm_pool_create("sysfs", 256))) {
- log_error("sysfs pool creation failed");
- return NULL;
- }
-
- if (!(ds = _dev_set_create(mem, sys_block, sysfs_depth))) {
- log_error("sysfs dev_set creation failed");
- goto bad;
- }
-
- if (!(f = dm_pool_zalloc(mem, sizeof(*f))))
+ if (!(f = zalloc(sizeof(*f))))
goto_bad;
f->passes_filter = _accept_p;
f->destroy = _destroy;
f->use_count = 0;
- f->private = ds;
f->name = "sysfs";
log_debug_devs("Sysfs filter initialised.");
@@ -333,7 +80,6 @@ struct dev_filter *sysfs_filter_create(void)
return f;
bad:
- dm_pool_destroy(mem);
return NULL;
}
2 years, 5 months
main - hints: remove the cmd hints list
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=5d0964d127ea62da480...
Commit: 5d0964d127ea62da480cafc91fefe403dda86870
Parent: b65a2c3f3a76739fb75a4a3a868cc9f143740052
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Nov 1 16:01:09 2021 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Mon Nov 1 16:01:45 2021 -0500
hints: remove the cmd hints list
which is no longer used after commit
"toollib: remove all devices list from process_each_pv"
---
lib/commands/toolcontext.c | 2 --
lib/commands/toolcontext.h | 1 -
lib/label/hints.c | 1 -
lib/label/label.c | 8 ++------
4 files changed, 2 insertions(+), 10 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 105aecd5d..1b7170de1 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -1605,7 +1605,6 @@ struct cmd_context *create_config_context(void)
dm_list_init(&cmd->config_files);
dm_list_init(&cmd->tags);
- dm_list_init(&cmd->hints);
if (!_init_lvm_conf(cmd))
goto_out;
@@ -1670,7 +1669,6 @@ struct cmd_context *create_toolcontext(unsigned is_clvmd,
dm_list_init(&cmd->formats);
dm_list_init(&cmd->segtypes);
dm_list_init(&cmd->tags);
- dm_list_init(&cmd->hints);
dm_list_init(&cmd->config_files);
label_init();
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index 701b7a739..356c79f8a 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -206,7 +206,6 @@ struct cmd_context {
* Devices and filtering.
*/
struct dev_filter *filter;
- struct dm_list hints;
struct dm_list use_devices; /* struct dev_use for each entry in devices file */
const char *md_component_checks;
const char *search_for_devnames; /* config file setting */
diff --git a/lib/label/hints.c b/lib/label/hints.c
index 3dba9f8ec..e444a0c82 100644
--- a/lib/label/hints.c
+++ b/lib/label/hints.c
@@ -365,7 +365,6 @@ static void _unlock_hints(struct cmd_context *cmd)
void hints_exit(struct cmd_context *cmd)
{
- free_hints(&cmd->hints);
if (_hints_fd == -1)
return;
_unlock_hints(cmd);
diff --git a/lib/label/label.c b/lib/label/label.c
index 3cd912270..479a5037a 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -1207,8 +1207,6 @@ int label_scan(struct cmd_context *cmd)
(unsigned long long)want_size_kb);
}
- dm_list_init(&cmd->hints);
-
/*
* If we're using hints to limit which devs we scanned, verify
* that those hints were valid, and if not we need to scan the
@@ -1220,18 +1218,16 @@ int label_scan(struct cmd_context *cmd)
_scan_list(cmd, cmd->filter, &all_devs, 0, NULL);
/* scan_devs are the devs that have been scanned */
dm_list_splice(&scan_devs, &all_devs);
- free_hints(&hints_list);
using_hints = 0;
create_hints = 0;
/* invalid hints means a new dev probably appeared and
we should search for any missing pvids again. */
unlink_searched_devnames(cmd);
- } else {
- /* The hints may be used by another device iteration. */
- dm_list_splice(&cmd->hints, &hints_list);
}
}
+ free_hints(&hints_list);
+
/*
* Check if the devices_file content is up to date and
* if not update it.
2 years, 5 months