Version 2.02.148 -
==================================
+ Replace hard-coded module and target names with macros.
Add pv_major and pv_minor report fields.
Detect and warn about mismatch between devices used and assumed for an LV.
#include "lib.h"
#include "libdevmapper-event.h"
#include "dmeventd_lvm.h"
+#include "activate.h" /* For TARGET_NAME* */
/* FIXME Reformat to 80 char lines. */
continue;
}
- if (strcmp(target_type, "mirror")) {
+ if (strcmp(target_type, TARGET_NAME_MIRROR)) {
log_info("%s has unmirrored portion.", device);
continue;
}
*/
void fs_unlock(void);
+#define TARGET_NAME_CACHE "cache"
+#define TARGET_NAME_ERROR "error"
+#define TARGET_NAME_ERROR_OLD "erro" /* Truncated in older kernels */
+#define TARGET_NAME_LINEAR "linear"
+#define TARGET_NAME_MIRROR "mirror"
+#define TARGET_NAME_RAID "raid"
+#define TARGET_NAME_SNAPSHOT "snapshot"
+#define TARGET_NAME_SNAPSHOT_MERGE "snapshot-merge"
+#define TARGET_NAME_SNAPSHOT_ORIGIN "snapshot-origin"
+#define TARGET_NAME_STRIPED "striped"
+#define TARGET_NAME_THIN "thin"
+#define TARGET_NAME_THIN_POOL "thin-pool"
+#define TARGET_NAME_ZERO "zero"
+
+#define MODULE_NAME_CLUSTERED_MIRROR "clog"
+#define MODULE_NAME_CACHE TARGET_NAME_CACHE
+#define MODULE_NAME_ERROR TARGET_NAME_ERROR
+#define MODULE_NAME_LOG_CLUSTERED "log-clustered"
+#define MODULE_NAME_LOG_USERSPACE "log-userspace"
+#define MODULE_NAME_MIRROR TARGET_NAME_MIRROR
+#define MODULE_NAME_SNAPSHOT TARGET_NAME_SNAPSHOT
+#define MODULE_NAME_RAID TARGET_NAME_RAID
+#define MODULE_NAME_ZERO TARGET_NAME_ZERO
+
#endif
* linear/striped, old snapshots and raids have proper
* segment selected for status!
*/
- if (strcmp(target_name, "cache") &&
- strcmp(target_name, "thin-pool") &&
- strcmp(target_name, "thin"))
+ if (strcmp(target_name, TARGET_NAME_CACHE) &&
+ strcmp(target_name, TARGET_NAME_THIN_POOL) &&
+ strcmp(target_name, TARGET_NAME_THIN))
return 1;
if (!(segtype = get_segtype_from_string(seg_status->seg->lv->vg->cmd, target_name)))
&target_type, ¶ms);
if ((s == start) && (l == length) &&
target_type && params) {
- if (strcmp(target_type, "mirror"))
+ if (strcmp(target_type, TARGET_NAME_MIRROR))
goto_out;
if (((p = strstr(params, " block_on_error")) &&
do {
next = dm_get_next_target(dmt, next, &start, &length, &target_type, ¶ms);
- if (!target_type || !strcmp(target_type, "snapshot")) {
+ if (!target_type || !strcmp(target_type, TARGET_NAME_SNAPSHOT)) {
if (!params || sscanf(params, "%d:%d %d:%d", &major1, &minor1, &major2, &minor2) != 4) {
log_error("Incorrect snapshot table found");
goto_out;
}
r = r || _device_is_suspended(major1, minor1) || _device_is_suspended(major2, minor2);
- } else if (!strcmp(target_type, "snapshot-origin")) {
+ } else if (!strcmp(target_type, TARGET_NAME_SNAPSHOT_ORIGIN)) {
if (!params || sscanf(params, "%d:%d", &major1, &minor1) != 2) {
log_error("Incorrect snapshot-origin table found");
goto_out;
next = dm_get_next_target(dmt, next, &start, &length,
&target_type, ¶ms);
- if (check.check_blocked && target_type && !strcmp(target_type, "mirror")) {
+ if (check.check_blocked && target_type && !strcmp(target_type, TARGET_NAME_MIRROR)) {
if (ignore_lvm_mirrors()) {
log_debug_activation("%s: Scanning mirror devices is disabled.", dev_name(dev));
goto out;
* in a stack - use proper dm tree to check this instead.
*/
if (check.check_suspended && target_type &&
- (!strcmp(target_type, "snapshot") || !strcmp(target_type, "snapshot-origin")) &&
+ (!strcmp(target_type, TARGET_NAME_SNAPSHOT) || !strcmp(target_type, TARGET_NAME_SNAPSHOT_ORIGIN)) &&
_ignore_suspended_snapshot_component(dev)) {
log_debug_activation("%s: %s device %s not usable.", dev_name(dev), target_type, name);
goto out;
}
/* TODO: extend check struct ? */
- if (target_type && !strcmp(target_type, "thin") &&
+ if (target_type && !strcmp(target_type, TARGET_NAME_THIN) &&
!_ignore_unusable_thins(dev)) {
log_debug_activation("%s: %s device %s not usable.", dev_name(dev), target_type, name);
goto out;
}
- if (target_type && strcmp(target_type, "error"))
+ if (target_type && strcmp(target_type, TARGET_NAME_ERROR))
only_error_target = 0;
} while (next);
/*
* Try and get some info on this device.
*/
- if (!_percent(dm, name, dlid, "snapshot", 0, NULL, percent,
+ if (!_percent(dm, name, dlid, TARGET_NAME_SNAPSHOT, 0, NULL, percent,
NULL, fail_if_percent_unsupported))
return_0;
dm_get_next_target(dmt, NULL, &start, &length, &type, ¶ms);
- if (!type || strcmp(type, "cache")) {
+ if (!type || strcmp(type, TARGET_NAME_CACHE)) {
log_error("Expected cache segment type but got %s instead",
type ? type : "NULL");
goto out;
return_0;
log_debug_activation("Getting device status percentage for %s", name);
- if (!(_percent(dm, name, dlid, "thin-pool", 0,
+ if (!(_percent(dm, name, dlid, TARGET_NAME_THIN_POOL, 0,
(metadata) ? lv : NULL, percent, NULL, 1)))
return_0;
goto out;
}
- if (!target_type || strcmp(target_type, "thin")) {
+ if (!target_type || strcmp(target_type, TARGET_NAME_THIN)) {
log_error("Unexpected target type %s found for thin %s.",
target_type, display_lvname(lv));
goto out;
char *dlid;
uint64_t extent_size = seg->lv->vg->extent_size;
- if (!strcmp(dm->cmd->stripe_filler, "error")) {
+ if (!strcmp(dm->cmd->stripe_filler, TARGET_NAME_ERROR)) {
/*
* FIXME, the tree pointer is first field of dm_tree_node, but
* we don't have the struct definition available.
dinfo->open_count)) {
if (seg_is_thin_volume(seg) ||
/* FIXME Is there anything simpler to check for instead? */
- !lv_has_target_type(dm->mem, lv, NULL, "snapshot-merge"))
+ !lv_has_target_type(dm->mem, lv, NULL, TARGET_NAME_SNAPSHOT_MERGE))
laopts->no_merging = 1;
}
}
if (!_cache_checked) {
_cache_checked = 1;
- if (!(_cache_present = target_present(cmd, "cache", 1)))
+ if (!(_cache_present = target_present(cmd, TARGET_NAME_CACHE, 1)))
return 0;
- if (!target_version("cache", &maj, &min, &patchlevel))
+ if (!target_version(TARGET_NAME_CACHE, &maj, &min, &patchlevel))
return_0;
if ((maj < 1) ||
const struct lv_segment *seg __attribute__((unused)),
struct dm_list *modules)
{
- if (!str_list_add(mem, modules, "cache")) {
+ if (!str_list_add(mem, modules, MODULE_NAME_CACHE)) {
log_error("String list allocation failed for cache module.");
return 0;
}
/* Reported truncated in older kernels */
if (!_errseg_checked) {
_errseg_checked = 1;
- _errseg_present = target_present(cmd, "error", 0) ||
- target_present(cmd, "erro", 0);
+ _errseg_present = target_present(cmd, TARGET_NAME_ERROR, 0) ||
+ target_present(cmd, TARGET_NAME_ERROR_OLD, 0);
}
return _errseg_present;
const struct lv_segment *seg __attribute__((unused)),
struct dm_list *modules)
{
- if (!str_list_add(mem, modules, "error")) {
+ if (!str_list_add(mem, modules, MODULE_NAME_ERROR)) {
log_error("error module string list allocation failed");
return 0;
}
* - IMPORTANT: avoids preload if inactivate merge is pending
*/
if (lv_has_target_type(origin->vg->vgmem, origin, NULL,
- "snapshot-merge")) {
+ TARGET_NAME_SNAPSHOT_MERGE)) {
/*
* preload origin to:
* - allow proper release of -cow
if (!_mirrored_checked) {
_mirrored_checked = 1;
- if (!(_mirrored_present = target_present(cmd, "mirror", 1)))
+ if (!(_mirrored_present = target_present(cmd, TARGET_NAME_MIRROR, 1)))
return 0;
/*
*/
/* FIXME Move this into libdevmapper */
- if (target_version("mirror", &maj, &min, &patchlevel) &&
+ if (target_version(TARGET_NAME_MIRROR, &maj, &min, &patchlevel) &&
maj == 1 &&
((min >= 1) ||
(min == 0 && driver_version(vsn, sizeof(vsn)) &&
if (!uname(&uts) &&
(sscanf(uts.release, "%u.%u.%u", &kmaj, &kmin, &krel) == 3) &&
KERNEL_VERSION(kmaj, kmin, krel) < KERNEL_VERSION(2, 6, 31)) {
- if (module_present(cmd, "log-clustered"))
+ if (module_present(cmd, MODULE_NAME_LOG_CLUSTERED))
_mirror_attributes |= MIRROR_LOG_CLUSTERED;
- } else if (module_present(cmd, "log-userspace"))
+ } else if (module_present(cmd, MODULE_NAME_LOG_USERSPACE))
_mirror_attributes |= MIRROR_LOG_CLUSTERED;
if (!(_mirror_attributes & MIRROR_LOG_CLUSTERED))
return_0;
if (vg_is_clustered(seg->lv->vg) &&
- !str_list_add(mem, modules, "clog")) {
+ !str_list_add(mem, modules, MODULE_NAME_CLUSTERED_MIRROR)) {
log_error("cluster log string list allocation failed");
return 0;
}
- if (!str_list_add(mem, modules, "mirror")) {
+ if (!str_list_add(mem, modules, MODULE_NAME_MIRROR)) {
log_error("mirror string list allocation failed");
return 0;
}
if (!_raid_checked) {
_raid_checked = 1;
- if (!(_raid_present = target_present(cmd, "raid", 1)))
+ if (!(_raid_present = target_present(cmd, TARGET_NAME_RAID, 1)))
return 0;
if (!target_version("raid", &maj, &min, &patchlevel))
const struct lv_segment *seg __attribute__((unused)),
struct dm_list *modules)
{
- if (!str_list_add(mem, modules, "raid")) {
+ if (!str_list_add(mem, modules, MODULE_NAME_RAID)) {
log_error("raid module string list allocation failed");
return 0;
}
const struct lv_activate_opts *laopts)
{
if (!laopts->no_merging && (seg->status & MERGING))
- return "snapshot-merge";
+ return TARGET_NAME_SNAPSHOT_MERGE;
return lvseg_name(seg);
}
#ifdef DEVMAPPER_SUPPORT
static int _snap_target_status_compatible(const char *type)
{
- return (strcmp(type, "snapshot-merge") == 0);
+ return (strcmp(type, TARGET_NAME_SNAPSHOT_MERGE) == 0);
}
static int _snap_target_percent(void **target_state __attribute__((unused)),
if (!_snap_checked) {
_snap_checked = 1;
- if (!(_snap_present = target_present(cmd, "snapshot", 1) &&
- target_present(cmd, "snapshot-origin", 0)))
+ if (!(_snap_present = target_present(cmd, TARGET_NAME_SNAPSHOT, 1) &&
+ target_present(cmd, TARGET_NAME_SNAPSHOT_ORIGIN, 0)))
return 0;
- if (target_version("snapshot", &maj, &min, &patchlevel) &&
+ if (target_version(TARGET_NAME_SNAPSHOT, &maj, &min, &patchlevel) &&
(maj > 1 ||
(maj == 1 && (min >= 12 || (min == 10 && patchlevel >= 2)))))
_snap_attrs |= SNAPSHOT_FEATURE_FIXED_LEAK;
/* TODO: test everything at once */
if (_snap_present && seg && (seg->status & MERGING)) {
if (!_snap_merge_checked) {
- _snap_merge_present = target_present(cmd, "snapshot-merge", 0);
+ _snap_merge_present = target_present(cmd, TARGET_NAME_SNAPSHOT_MERGE, 0);
_snap_merge_checked = 1;
}
return _snap_merge_present;
const struct lv_segment *seg __attribute__((unused)),
struct dm_list *modules)
{
- if (!str_list_add(mem, modules, "snapshot")) {
+ if (!str_list_add(mem, modules, MODULE_NAME_SNAPSHOT)) {
log_error("snapshot string list allocation failed");
return 0;
}
if (!_striped_checked) {
_striped_checked = 1;
- _striped_present = target_present(cmd, "linear", 0) &&
- target_present(cmd, "striped", 0);
+ _striped_present = target_present(cmd, TARGET_NAME_LINEAR, 0) &&
+ target_present(cmd, TARGET_NAME_STRIPED, 0);
}
return _striped_present;
if (!_zero_checked) {
_zero_checked = 1;
- _zero_present = target_present(cmd, "zero", 1);
+ _zero_present = target_present(cmd, TARGET_NAME_ZERO, 1);
}
return _zero_present;
const struct lv_segment *seg __attribute__((unused)),
struct dm_list *modules)
{
- if (!str_list_add(mem, modules, "zero")) {
+ if (!str_list_add(mem, modules, MODULE_NAME_ZERO)) {
log_error("zero module string list allocation failed");
return 0;
}