static char _devices_file_version[VERSION_LINE_MAX];
static const char *_searched_file = DEFAULT_RUN_DIR "/searched_devnames";
+/* Only for displaying in lvmdevices command output. */
+char devices_file_hostname_orig[PATH_MAX];
+char devices_file_product_uuid_orig[PATH_MAX];
+
char *devices_file_version(void)
{
return _devices_file_version;
return 1;
/*
- * The use_devices list should rarely if ever be non-empty at this
- * point, it means device_ids_read has been called twice.
- * If we wanted to redo reading the file, we'd need to
- * free_dus(&cmd->use_devices) and clear the MATCHED_USE_ID flag in all
- * dev->flags.
+ * Note: lvmdevices calls device_ids_read() a second
+ * time to get the original entries to compare with
+ * updated entries. Prior to calling it again, it
+ * moves the cmd->use_devices entries out of the way.
+ * Otherwise, device_ids_read() should only be called
+ * once at the start of a command.
*/
if (!dm_list_empty(&cmd->use_devices)) {
+ /* shouldn't happen */
log_debug("device_ids_read already done");
return 1;
}
continue;
if (!strncmp(line, "HOSTNAME", 8)) {
+ _copy_idline_str(line, check_id, sizeof(check_id));
+ log_debug("read devices file hostname %s", check_id);
+
+ /* Save original for lvmdevices output. */
+ if (!strcmp(cmd->name, "lvmdevices"))
+ strncpy(devices_file_hostname_orig, check_id, PATH_MAX-1);
+
if (!cmd->device_ids_check_hostname)
continue;
+
hostname_found = 1;
- _copy_idline_str(line, check_id, sizeof(check_id));
- log_debug("read devices file hostname %s", check_id);
if (cmd->hostname && strcmp(cmd->hostname, check_id)) {
log_debug("Devices file hostname %s vs local %s.",
check_id[0] ? check_id : "none", cmd->hostname ?: "none");
}
if (!strncmp(line, "PRODUCT_UUID", 12)) {
+ _copy_idline_str(line, check_id, sizeof(check_id));
+ log_debug("read devices file product_uuid %s", check_id);
+
+ /* Save original for lvmdevices output. */
+ if (!strcmp(cmd->name, "lvmdevices"))
+ strncpy(devices_file_product_uuid_orig, check_id, PATH_MAX-1);
+
if (!cmd->device_ids_check_product_uuid)
continue;
+
product_uuid_found = 1;
- _copy_idline_str(line, check_id, sizeof(check_id));
- log_debug("read devices file product_uuid %s", check_id);
if ((!cmd->product_uuid && check_id[0]) ||
(cmd->product_uuid && strcmp(cmd->product_uuid, check_id))) {
log_debug("Devices file product_uuid %s vs local %s.",
}
if (fclose(fp))
stack;
-
- if (!product_uuid_found && !hostname_found &&
- (cmd->device_ids_check_product_uuid || cmd->device_ids_check_hostname)) {
+
+ if (!product_uuid_found && cmd->device_ids_check_product_uuid) {
+ cmd->device_ids_refresh_trigger = 1;
+ log_debug("Devices file refresh: missing product_uuid");
+ } else if ((!product_uuid_found && !hostname_found) &&
+ (cmd->device_ids_check_product_uuid || cmd->device_ids_check_hostname)) {
cmd->device_ids_refresh_trigger = 1;
- log_debug("Devices file refresh due to no product_uuid or hostname.");
+ log_debug("Devices file refresh: missing product_uuid and hostname");
}
-
+
return ret;
}
fprintf(fp, "# LVM uses devices listed in this file.\n");
fprintf(fp, "# Created by LVM command %s pid %d at %s", cmd->name, getpid(), ctime(&t));
+ /* if product_uuid is included, then hostname is unnecessary */
if (cmd->product_uuid && cmd->device_ids_check_product_uuid)
fprintf(fp, "PRODUCT_UUID=%s\n", cmd->product_uuid);
- if (cmd->hostname && cmd->device_ids_check_hostname)
+ else if (cmd->hostname && cmd->device_ids_check_hostname)
fprintf(fp, "HOSTNAME=%s\n", cmd->hostname);
if (dm_snprintf(version_buf, VERSION_LINE_MAX, "VERSION=%u.%u.%u", DEVICES_FILE_MAJOR, DEVICES_FILE_MINOR, df_counter+1) < 0)
/* coverity[unnecessary_header] needed for MuslC */
#include <sys/file.h>
+extern char devices_file_hostname_orig[PATH_MAX];
+extern char devices_file_product_uuid_orig[PATH_MAX];
+
static void _search_devs_for_pvids(struct cmd_context *cmd, struct dm_list *search_pvids, struct dm_list *found_devs)
{
struct dev_iter *iter;
dm_list_init(&done_old);
dm_list_init(&done_new);
+ /*
+ * Move the entries that have been processed out of the way so
+ * original entries can be added to use_devices by device_ids_read().
+ * The processed entries are moved back to cmd->use_devices at the
+ * end of this function.
+ */
dm_list_splice(&use_new, &cmd->use_devices);
device_ids_read(cmd);
dm_list_splice(&use_old, &cmd->use_devices);
dm_list_init(&cmd->use_devices);
+ /*
+ * Check if system identifier is changed.
+ */
+
+ if (cmd->device_ids_refresh_trigger) {
+ int include_product_uuid = 0;
+ int include_hostname = 0;
+
+ if (cmd->product_uuid && cmd->device_ids_check_product_uuid) {
+ include_product_uuid = 1;
+ if (devices_file_product_uuid_orig[0] &&
+ strcmp(cmd->product_uuid, devices_file_product_uuid_orig))
+ log_print_unless_silent("PRODUCT_UUID=%s (old %s): update",
+ cmd->product_uuid, devices_file_product_uuid_orig);
+ else if (!devices_file_product_uuid_orig[0])
+ log_print_unless_silent("PRODUCT_UUID=%s: add", cmd->product_uuid);
+ }
+ if (!include_product_uuid && devices_file_product_uuid_orig[0])
+ log_print_unless_silent("PRODUCT_UUID=%s: remove", devices_file_product_uuid_orig);
+
+ /* hostname is only updated or added if product_uuid is not included */
+ if (cmd->hostname && cmd->device_ids_check_hostname && !include_product_uuid) {
+ include_hostname = 1;
+ if (devices_file_hostname_orig[0] &&
+ strcmp(cmd->hostname, devices_file_hostname_orig))
+ log_print_unless_silent("HOSTNAME=%s (old %s): update",
+ cmd->hostname, devices_file_hostname_orig);
+ else if (!devices_file_hostname_orig[0])
+ log_print_unless_silent("HOSTNAME=%s: add", cmd->hostname);
+ }
+ if (!include_hostname && devices_file_hostname_orig[0])
+ log_print_unless_silent("HOSTNAME=%s: remove", devices_file_hostname_orig);
+ }
+
/*
* Check entries with proper id types.
*/