diff options
Diffstat (limited to 'lib/label/hints.c')
-rw-r--r-- | lib/label/hints.c | 55 |
1 files changed, 52 insertions, 3 deletions
diff --git a/lib/label/hints.c b/lib/label/hints.c index 9546f4880..d681c5184 100644 --- a/lib/label/hints.c +++ b/lib/label/hints.c @@ -145,6 +145,7 @@ #include "lib/activate/activate.h" #include "lib/label/hints.h" #include "lib/device/dev-type.h" +#include "lib/device/device_id.h" #include <sys/stat.h> #include <fcntl.h> @@ -166,8 +167,10 @@ static const char *_newhints_file = DEFAULT_RUN_DIR "/newhints"; * than they were built with. Increase the minor number * when adding features that older lvm versions can just * ignore while continuing to use the other content. + * + * MAJOR 2: add devices_file */ -#define HINTS_VERSION_MAJOR 1 +#define HINTS_VERSION_MAJOR 2 #define HINTS_VERSION_MINOR 1 #define HINT_LINE_LEN (PATH_MAX + NAME_LEN + ID_LEN + 64) @@ -701,8 +704,9 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int * break; } - if (hv_major > HINTS_VERSION_MAJOR) { - log_debug("ignore hints with newer major version %d.%d", hv_major, hv_minor); + if (hv_major != HINTS_VERSION_MAJOR) { + log_debug("ignore hints with version %d.%d current %d.%d", + hv_major, hv_minor, HINTS_VERSION_MAJOR, HINTS_VERSION_MINOR); *needs_refresh = 1; break; } @@ -747,6 +751,25 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int * continue; } + keylen = strlen("devices_file:"); + if (!strncmp(_hint_line, "devices_file:", keylen)) { + const char *df_hint = _hint_line + keylen; + const char *df_config = find_config_tree_str(cmd, devices_devicesfile_CFG, NULL); + /* when a devices file is not used, hints should have devices_file:. */ + if (!cmd->enable_devices_file || !df_hint || !df_config) { + if (df_hint[0] != '.') { + log_debug("ignore hints with different devices_file: not enabled vs %s", df_hint); + *needs_refresh = 1; + break; + } + } else if (strcmp(df_hint, df_config)) { + log_debug("ignore hints with different devices_file: %s vs %s", df_hint, df_config); + *needs_refresh = 1; + break; + } + continue; + } + keylen = strlen("devs_hash:"); if (!strncmp(_hint_line, "devs_hash:", keylen)) { if (sscanf(_hint_line + keylen, "%u %u", &read_hash, &read_count) != 2) { @@ -818,8 +841,12 @@ static int _read_hint_file(struct cmd_context *cmd, struct dm_list *hints, int * if (!(iter = dev_iter_create(NULL, 0))) return 0; while ((dev = dev_iter_get(cmd, iter))) { + if (cmd->enable_devices_file && !get_uid_for_dev(cmd, dev)) + continue; + if (!_dev_in_hint_hash(cmd, dev)) continue; + memset(devpath, 0, sizeof(devpath)); strncpy(devpath, dev_name(dev), PATH_MAX); calc_hash = calc_crc(calc_hash, (const uint8_t *)devpath, strlen(devpath)); @@ -879,6 +906,7 @@ int write_hint_file(struct cmd_context *cmd, int newhints) struct device *dev; const char *vgname; char *filter_str = NULL; + const char *config_devices_file = NULL; uint32_t hash = INITIAL_CRC; uint32_t count = 0; time_t t; @@ -939,6 +967,19 @@ int write_hint_file(struct cmd_context *cmd, int newhints) fprintf(fp, "scan_lvs:%d\n", cmd->scan_lvs); + /* + * Only associate hints with the default/system devices file. + * If no default/system devices file is used, "." is set. + * If we are using a devices file other than the config setting + * (from --devicesfile), then we should not be using hints and + * shouldn't get here. + */ + config_devices_file = find_config_tree_str(cmd, devices_devicesfile_CFG, NULL); + if (cmd->enable_devices_file && !cmd->devicesfile && config_devices_file) + fprintf(fp, "devices_file:%s\n", config_devices_file); + else + fprintf(fp, "devices_file:.\n"); + /* * iterate through all devs and write a line for each * dev flagged DEV_SCAN_FOUND_LABEL @@ -956,6 +997,14 @@ int write_hint_file(struct cmd_context *cmd, int newhints) * 2. add PVs to the hint file */ while ((dev = dev_iter_get(cmd, iter))) { + if (cmd->enable_devices_file && !get_uid_for_dev(cmd, dev)) { + if (dev->flags & DEV_SCAN_FOUND_LABEL) { + /* should never happen */ + log_error("skip hint hash no uid but found label %s", dev_name(dev)); + } + continue; + } + if (!_dev_in_hint_hash(cmd, dev)) { if (dev->flags & DEV_SCAN_FOUND_LABEL) { /* should never happen */ |