mirror of
git://sourceware.org/git/lvm2.git
synced 2025-12-25 20:23:49 +03:00
Compare commits
66 Commits
dm_v1_02_0
...
dm_v1_02_0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8339f3ceb3 | ||
|
|
c0c9f3cc19 | ||
|
|
81f4813c29 | ||
|
|
94f57745b9 | ||
|
|
54fb2ebbe0 | ||
|
|
02d122b65b | ||
|
|
df0a5561a1 | ||
|
|
f7c55da7d0 | ||
|
|
b385f701ce | ||
|
|
05dd42f443 | ||
|
|
36d816d5cb | ||
|
|
92a6746e70 | ||
|
|
1728848a39 | ||
|
|
f9eb4e7487 | ||
|
|
d0b9f33aeb | ||
|
|
718583b241 | ||
|
|
6737127e9a | ||
|
|
19a7b4479b | ||
|
|
c340647502 | ||
|
|
0f987d2982 | ||
|
|
52bcaed169 | ||
|
|
177bd565ac | ||
|
|
c801c32fc5 | ||
|
|
d090cf3058 | ||
|
|
1e4b82cc94 | ||
|
|
3426f31184 | ||
|
|
b4fb7af1df | ||
|
|
b36647598b | ||
|
|
fd6b94f20e | ||
|
|
296dc0ed8a | ||
|
|
4f869e14d6 | ||
|
|
5704270e9d | ||
|
|
505b381e85 | ||
|
|
da6cb15393 | ||
|
|
16843f6cc8 | ||
|
|
64f3ad1fd4 | ||
|
|
ff4c4f99b3 | ||
|
|
f5d2e09569 | ||
|
|
f2bdbe0d4d | ||
|
|
c51a13caa6 | ||
|
|
7840c78a23 | ||
|
|
c706f3246b | ||
|
|
608eedf88d | ||
|
|
a564ca82be | ||
|
|
c868b1fee2 | ||
|
|
22374f718f | ||
|
|
abe3cfcf41 | ||
|
|
59db4b50cd | ||
|
|
bdae38765d | ||
|
|
66d3ceeb61 | ||
|
|
445dd17db3 | ||
|
|
cff78a2577 | ||
|
|
6a09e64195 | ||
|
|
22eabe5eab | ||
|
|
b69ba36c2d | ||
|
|
5240aad22b | ||
|
|
2897eb3cb3 | ||
|
|
d3f2f00c25 | ||
|
|
bacfb913a0 | ||
|
|
c99d0236a0 | ||
|
|
aac2b655f7 | ||
|
|
126c41e73a | ||
|
|
359ee54f0d | ||
|
|
28ab560907 | ||
|
|
ead252fee4 | ||
|
|
abf67914c4 |
@@ -38,6 +38,7 @@ ifeq ($(MAKECMDGOALS),distclean)
|
||||
lib/snapshot \
|
||||
po \
|
||||
test/mm test/device test/format1 test/regex test/filters
|
||||
DISTCLEAN_TARGETS += lib/misc/configure.h
|
||||
endif
|
||||
|
||||
include make.tmpl
|
||||
|
||||
52
WHATS_NEW
52
WHATS_NEW
@@ -1,5 +1,53 @@
|
||||
Version 2.02.06 -
|
||||
=================================
|
||||
Version 2.02.08 -
|
||||
================================
|
||||
Add checks for duplicate LV name, lvid and PV id before writing metadata.
|
||||
Report all sanity check failures, not just the first.
|
||||
Fix missing lockfs on first snapshot creation.
|
||||
Add unreliable --trustcache option to reporting commands.
|
||||
Fix locking for mimage removal.
|
||||
Fix clvmd_init_rhel4 'status' exit code.
|
||||
|
||||
Version 2.02.07 - 17th July 2006
|
||||
================================
|
||||
Fix activation logic in lvchange --persistent.
|
||||
Don't ignore persistent minor numbers when activating.
|
||||
Use RTLD_GLOBAL when loading shared libraries.
|
||||
Add some forgotten memlock checks to _vg_read to protect against full scans.
|
||||
Add mutex to dmeventd_mirror to avoid concurrent execution.
|
||||
Fix vgreduce --removemissing to return success if VG is already consistent.
|
||||
Fix return code if VG specified on command line is not found.
|
||||
Fix PV tools to include orphaned PVs in default output again.
|
||||
Fixed unaligned access when using clvm.
|
||||
Fix an extra dev_close in a label_read error path.
|
||||
Append patches to commit emails.
|
||||
Fix target_register_events args.
|
||||
Prevent snapshots of mirrors.
|
||||
Add DISTCLEAN_TARGETS to make template for configure.h.
|
||||
More fixes to error paths.
|
||||
Fix lvcreate corelog validation.
|
||||
Add --config for overriding most config file settings from cmdline.
|
||||
Quote arguments when printing command line.
|
||||
Remove linefeed from 'initialising logging' message.
|
||||
Add 'Completed' debug message.
|
||||
Don't attempt library exit after reloading config files.
|
||||
Always compile with libdevmapper, even if device-mapper is disabled.
|
||||
|
||||
Version 2.02.06 - 12th May 2006
|
||||
===============================
|
||||
Propagate --monitor around cluster.
|
||||
Add --monitor to vgcreate and lvcreate to control dmeventd registration.
|
||||
Filter LCK_NONBLOCK in clvmd lock_vg.
|
||||
Add --nosync to lvcreate with LV flag NOTSYNCED.
|
||||
Use mirror's uuid for a core log.
|
||||
Add mirror log fault-handling policy.
|
||||
Improve mirror warning messages and tidy dmeventd syslog output.
|
||||
Propagate nosync flag around cluster.
|
||||
Allow vgreduce to handle mirror log failures.
|
||||
Add --corelog to lvcreate and lvconvert.
|
||||
Create a log header for replacement in-sync mirror log.
|
||||
Use set_lv() and dev_set() to wipe sections of devices.
|
||||
Add mirror_in_sync() flag to avoid unnecessary resync on activation.
|
||||
Add mirror_library description to example.conf.
|
||||
Fix uuid_from_num() buffer overrun.
|
||||
Make SIZE_SHORT the default for display_size().
|
||||
Fix some memory leaks in error paths found by coverity.
|
||||
|
||||
22
WHATS_NEW_DM
22
WHATS_NEW_DM
@@ -1,3 +1,25 @@
|
||||
Version 1.02.09 - 15 Aug 2006
|
||||
==============================
|
||||
Add --table argument to dmsetup for a one-line table.
|
||||
Abort if errors are found during cmdline option processing.
|
||||
Add lockfs indicator to debug output.
|
||||
|
||||
Version 1.02.08 - 17 July 2006
|
||||
==============================
|
||||
Append full patch to check in emails.
|
||||
Avoid duplicate dmeventd subdir with 'make distclean'.
|
||||
Update dmsetup man page.
|
||||
Add --force to dmsetup remove* to load error target.
|
||||
dmsetup remove_all also performs mknodes.
|
||||
Don't suppress identical table reloads if permission changes.
|
||||
Fix corelog segment line.
|
||||
Suppress some compiler warnings.
|
||||
|
||||
Version 1.02.07 - 11 May 2006
|
||||
=============================
|
||||
Add DM_CORELOG flag to dm_tree_node_add_mirror_target().
|
||||
Avoid a dmeventd compiler warning.
|
||||
|
||||
Version 1.02.06 - 10 May 2006
|
||||
=============================
|
||||
Move DEFS into configure.h.
|
||||
|
||||
41
configure
vendored
41
configure
vendored
@@ -10699,7 +10699,6 @@ done
|
||||
|
||||
fi
|
||||
|
||||
if test x$DEVMAPPER = xyes; then
|
||||
|
||||
for ac_header in libdevmapper.h
|
||||
do
|
||||
@@ -10854,7 +10853,6 @@ fi
|
||||
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
if test x$HAVE_SELINUX = xyes; then
|
||||
|
||||
@@ -11053,45 +11051,6 @@ else
|
||||
echo "${ECHO_T}no" >&6
|
||||
fi
|
||||
|
||||
# Extract the first word of "ifconfig", so it can be a program name with args.
|
||||
set dummy ifconfig; ac_word=$2
|
||||
echo "$as_me:$LINENO: checking for $ac_word" >&5
|
||||
echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
|
||||
if test "${ac_cv_path_MODPROBE_CMD+set}" = set; then
|
||||
echo $ECHO_N "(cached) $ECHO_C" >&6
|
||||
else
|
||||
case $MODPROBE_CMD in
|
||||
[\\/]* | ?:[\\/]*)
|
||||
ac_cv_path_MODPROBE_CMD="$MODPROBE_CMD" # Let the user override the test with a path.
|
||||
;;
|
||||
*)
|
||||
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
|
||||
for as_dir in $PATH
|
||||
do
|
||||
IFS=$as_save_IFS
|
||||
test -z "$as_dir" && as_dir=.
|
||||
for ac_exec_ext in '' $ac_executable_extensions; do
|
||||
if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
|
||||
ac_cv_path_MODPROBE_CMD="$as_dir/$ac_word$ac_exec_ext"
|
||||
echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
|
||||
break 2
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
MODPROBE_CMD=$ac_cv_path_MODPROBE_CMD
|
||||
|
||||
if test -n "$MODPROBE_CMD"; then
|
||||
echo "$as_me:$LINENO: result: $MODPROBE_CMD" >&5
|
||||
echo "${ECHO_T}$MODPROBE_CMD" >&6
|
||||
else
|
||||
echo "$as_me:$LINENO: result: no" >&5
|
||||
echo "${ECHO_T}no" >&6
|
||||
fi
|
||||
|
||||
|
||||
if test x$MODPROBE_CMD != x; then
|
||||
|
||||
|
||||
@@ -538,9 +538,7 @@ if test x$INTL = xyes; then
|
||||
AC_CHECK_HEADERS(libintl.h,,AC_MSG_ERROR(bailing out))
|
||||
fi
|
||||
|
||||
if test x$DEVMAPPER = xyes; then
|
||||
AC_CHECK_HEADERS(libdevmapper.h,,AC_MSG_ERROR(bailing out))
|
||||
fi
|
||||
AC_CHECK_HEADERS(libdevmapper.h,,AC_MSG_ERROR(bailing out))
|
||||
|
||||
if test x$HAVE_SELINUX = xyes; then
|
||||
AC_CHECK_HEADERS(selinux/selinux.h,,AC_MSG_ERROR(bailing out))
|
||||
|
||||
@@ -59,9 +59,7 @@ ifeq ("@DMEVENTD@", "yes")
|
||||
LVMLIBS += -ldevmapper-event
|
||||
endif
|
||||
|
||||
ifeq ("@DEVMAPPER@", "yes")
|
||||
LVMLIBS += -ldevmapper
|
||||
endif
|
||||
LVMLIBS += -ldevmapper
|
||||
|
||||
DEFS += -D_REENTRANT
|
||||
CFLAGS += -fno-strict-aliasing
|
||||
|
||||
@@ -180,7 +180,7 @@ static int lock_vg(struct local_client *client)
|
||||
}
|
||||
else {
|
||||
|
||||
status = sync_lock(lockname, (int)lock_cmd, (int)lock_flags, &lkid);
|
||||
status = sync_lock(lockname, (int)lock_cmd, (lock_flags & LCK_NONBLOCK) ? LKF_NOQUEUE : 0, &lkid);
|
||||
if (status)
|
||||
status = errno;
|
||||
else
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "log.h"
|
||||
#include "activate.h"
|
||||
#include "locking.h"
|
||||
#include "defaults.h"
|
||||
|
||||
static struct cmd_context *cmd = NULL;
|
||||
static struct dm_hash_table *lv_hash = NULL;
|
||||
@@ -306,6 +307,12 @@ int do_lock_lv(unsigned char command, unsigned char lock_flags, char *resource)
|
||||
if (lock_flags & LCK_PARTIAL_MODE)
|
||||
init_partial(1);
|
||||
|
||||
if (lock_flags & LCK_MIRROR_NOSYNC_MODE)
|
||||
init_mirror_in_sync(1);
|
||||
|
||||
if (!(lock_flags & LCK_DMEVENTD_REGISTER_MODE))
|
||||
init_dmeventd_register(0);
|
||||
|
||||
switch (command) {
|
||||
case LCK_LV_EXCLUSIVE:
|
||||
status = do_activate_lv(resource, lock_flags, LKM_EXMODE);
|
||||
@@ -337,6 +344,12 @@ int do_lock_lv(unsigned char command, unsigned char lock_flags, char *resource)
|
||||
if (lock_flags & LCK_PARTIAL_MODE)
|
||||
init_partial(0);
|
||||
|
||||
if (lock_flags & LCK_MIRROR_NOSYNC_MODE)
|
||||
init_mirror_in_sync(0);
|
||||
|
||||
if (!(lock_flags & LCK_DMEVENTD_REGISTER_MODE))
|
||||
init_dmeventd_register(DEFAULT_DMEVENTD_MONITOR);
|
||||
|
||||
/* clean the pool for another command */
|
||||
dm_pool_empty(cmd->mem);
|
||||
|
||||
@@ -497,7 +510,7 @@ static void check_config()
|
||||
{
|
||||
int locking_type;
|
||||
|
||||
locking_type = find_config_int(cmd->cft->root, "global/locking_type", 1);
|
||||
locking_type = find_config_tree_int(cmd, "global/locking_type", 1);
|
||||
|
||||
if (locking_type == 3) /* compiled-in cluster support */
|
||||
return;
|
||||
@@ -505,7 +518,7 @@ static void check_config()
|
||||
if (locking_type == 2) { /* External library, check name */
|
||||
const char *libname;
|
||||
|
||||
libname = find_config_str(cmd->cft->root, "global/locking_library",
|
||||
libname = find_config_tree_str(cmd, "global/locking_library",
|
||||
"");
|
||||
if (strstr(libname, "liblvm2clusterlock.so"))
|
||||
return;
|
||||
|
||||
@@ -1213,14 +1213,14 @@ static void sig_alarm(int signum)
|
||||
/* Init thread signal handling. */
|
||||
static void init_thread_signals(void)
|
||||
{
|
||||
sigset_t sigset;
|
||||
sigset_t my_sigset;
|
||||
struct sigaction act;
|
||||
|
||||
memset(&act, 0, sizeof(act));
|
||||
act.sa_handler = sig_alarm;
|
||||
sigaction(SIGALRM, &act, NULL);
|
||||
sigfillset(&sigset);
|
||||
pthread_sigmask(SIG_BLOCK, &sigset, NULL);
|
||||
sigfillset(&my_sigset);
|
||||
pthread_sigmask(SIG_BLOCK, &my_sigset, NULL);
|
||||
}
|
||||
|
||||
static int daemonize(void)
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#define ME_INSYNC 1
|
||||
#define ME_FAILURE 2
|
||||
|
||||
static pthread_mutex_t _lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* FIXME: We may need to lock around operations to these */
|
||||
static int register_count = 0;
|
||||
static struct dm_pool *mem_pool = NULL;
|
||||
@@ -99,10 +101,13 @@ static int _get_mirror_event(char *params)
|
||||
return rtn;
|
||||
}
|
||||
|
||||
static void _temporary_log_fn(int level, const char *file, int line, const char *format)
|
||||
static void _temporary_log_fn(int level, const char *file,
|
||||
int line, const char *format)
|
||||
{
|
||||
return;
|
||||
syslog(LOG_DEBUG, "%s", format);
|
||||
if (!strncmp(format, "WARNING: ", 9) && (level < 5))
|
||||
syslog(LOG_CRIT, "%s", format);
|
||||
else
|
||||
syslog(LOG_DEBUG, "%s", format);
|
||||
}
|
||||
|
||||
static int _remove_failed_devices(const char *device)
|
||||
@@ -147,6 +152,10 @@ void process_event(const char *device, enum dm_event_type event)
|
||||
char *target_type = NULL;
|
||||
char *params;
|
||||
|
||||
if (pthread_mutex_trylock(&_lock)) {
|
||||
syslog(LOG_NOTICE, "Another thread is handling an event. Waiting...");
|
||||
pthread_mutex_lock(&_lock);
|
||||
}
|
||||
/* FIXME Move inside libdevmapper */
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_STATUS))) {
|
||||
syslog(LOG_ERR, "Unable to create dm_task.\n");
|
||||
@@ -201,11 +210,12 @@ void process_event(const char *device, enum dm_event_type event)
|
||||
fail:
|
||||
if (dmt)
|
||||
dm_task_destroy(dmt);
|
||||
pthread_mutex_unlock(&_lock);
|
||||
}
|
||||
|
||||
int register_device(const char *device)
|
||||
{
|
||||
syslog(LOG_INFO, "Monitoring %s for events\n", device);
|
||||
syslog(LOG_INFO, "Monitoring mirror device, %s for events\n", device);
|
||||
|
||||
/*
|
||||
* Need some space for allocations. 1024 should be more
|
||||
@@ -224,8 +234,6 @@ int register_device(const char *device)
|
||||
|
||||
int unregister_device(const char *device)
|
||||
{
|
||||
syslog(LOG_INFO, "Stopped monitoring %s for events\n", device);
|
||||
|
||||
if (!(--register_count)) {
|
||||
dm_pool_destroy(mem_pool);
|
||||
mem_pool = NULL;
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#define ME_INSYNC 1
|
||||
#define ME_FAILURE 2
|
||||
|
||||
static pthread_mutex_t _lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
/* FIXME: We may need to lock around operations to these */
|
||||
static int register_count = 0;
|
||||
static struct dm_pool *mem_pool = NULL;
|
||||
@@ -99,10 +101,13 @@ static int _get_mirror_event(char *params)
|
||||
return rtn;
|
||||
}
|
||||
|
||||
static void _temporary_log_fn(int level, const char *file, int line, const char *format)
|
||||
static void _temporary_log_fn(int level, const char *file,
|
||||
int line, const char *format)
|
||||
{
|
||||
return;
|
||||
syslog(LOG_DEBUG, "%s", format);
|
||||
if (!strncmp(format, "WARNING: ", 9) && (level < 5))
|
||||
syslog(LOG_CRIT, "%s", format);
|
||||
else
|
||||
syslog(LOG_DEBUG, "%s", format);
|
||||
}
|
||||
|
||||
static int _remove_failed_devices(const char *device)
|
||||
@@ -147,6 +152,10 @@ void process_event(const char *device, enum dm_event_type event)
|
||||
char *target_type = NULL;
|
||||
char *params;
|
||||
|
||||
if (pthread_mutex_trylock(&_lock)) {
|
||||
syslog(LOG_NOTICE, "Another thread is handling an event. Waiting...");
|
||||
pthread_mutex_lock(&_lock);
|
||||
}
|
||||
/* FIXME Move inside libdevmapper */
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_STATUS))) {
|
||||
syslog(LOG_ERR, "Unable to create dm_task.\n");
|
||||
@@ -201,11 +210,12 @@ void process_event(const char *device, enum dm_event_type event)
|
||||
fail:
|
||||
if (dmt)
|
||||
dm_task_destroy(dmt);
|
||||
pthread_mutex_unlock(&_lock);
|
||||
}
|
||||
|
||||
int register_device(const char *device)
|
||||
{
|
||||
syslog(LOG_INFO, "Monitoring %s for events\n", device);
|
||||
syslog(LOG_INFO, "Monitoring mirror device, %s for events\n", device);
|
||||
|
||||
/*
|
||||
* Need some space for allocations. 1024 should be more
|
||||
@@ -224,8 +234,6 @@ int register_device(const char *device)
|
||||
|
||||
int unregister_device(const char *device)
|
||||
{
|
||||
syslog(LOG_INFO, "Stopped monitoring %s for events\n", device);
|
||||
|
||||
if (!(--register_count)) {
|
||||
dm_pool_destroy(mem_pool);
|
||||
mem_pool = NULL;
|
||||
|
||||
@@ -232,9 +232,6 @@ activation {
|
||||
# target or make it return zeros.
|
||||
missing_stripe_filler = "/dev/ioerror"
|
||||
|
||||
# Size (in KB) of each copy operation when mirroring
|
||||
mirror_region_size = 512
|
||||
|
||||
# How much stack (in KB) to reserve for use while devices suspended
|
||||
reserved_stack = 256
|
||||
|
||||
@@ -251,6 +248,54 @@ activation {
|
||||
# "@*" matches if any tag defined on the host is also set in the LV or VG
|
||||
#
|
||||
# volume_list = [ "vg1", "vg2/lvol1", "@tag1", "@*" ]
|
||||
|
||||
# Size (in KB) of each copy operation when mirroring
|
||||
mirror_region_size = 512
|
||||
|
||||
# 'mirror_image_fault_policy' and 'mirror_log_fault_policy' define
|
||||
# how a device failure affecting a mirror is handled.
|
||||
# A mirror is composed of mirror images (copies) and a log.
|
||||
# A disk log ensures that a mirror does not need to be re-synced
|
||||
# (all copies made the same) every time a machine reboots or crashes.
|
||||
#
|
||||
# In the event of a failure, the specified policy will be used to
|
||||
# determine what happens:
|
||||
#
|
||||
# "remove" - Simply remove the faulty device and run without it. If
|
||||
# the log device fails, the mirror would convert to using
|
||||
# an in-memory log. This means the mirror will not
|
||||
# remember its sync status across crashes/reboots and
|
||||
# the entire mirror will be re-synced. If a
|
||||
# mirror image fails, the mirror will convert to a
|
||||
# non-mirrored device if there is only one remaining good
|
||||
# copy.
|
||||
#
|
||||
# "allocate" - Remove the faulty device and try to allocate space on
|
||||
# a new device to be a replacement for the failed device.
|
||||
# Using this policy for the log is fast and maintains the
|
||||
# ability to remember sync state through crashes/reboots.
|
||||
# Using this policy for a mirror device is slow, as it
|
||||
# requires the mirror to resynchronize the devices, but it
|
||||
# will preserve the mirror characteristic of the device.
|
||||
# This policy acts like "remove" if no suitable device and
|
||||
# space can be allocated for the replacement.
|
||||
# Currently this is not implemented properly and behaves
|
||||
# similarly to:
|
||||
#
|
||||
# "allocate_anywhere" - Operates like "allocate", but it does not
|
||||
# require that the new space being allocated be on a
|
||||
# device is not part of the mirror. For a log device
|
||||
# failure, this could mean that the log is allocated on
|
||||
# the same device as a mirror device. For a mirror
|
||||
# device, this could mean that the mirror device is
|
||||
# allocated on the same device as another mirror device.
|
||||
# This policy would not be wise for mirror devices
|
||||
# because it would break the redundant nature of the
|
||||
# mirror. This policy acts like "remove" if no suitable
|
||||
# device and space can be allocated for the replacement.
|
||||
|
||||
mirror_log_fault_policy = "allocate"
|
||||
mirror_device_fault_policy = "remove"
|
||||
}
|
||||
|
||||
|
||||
@@ -291,7 +336,13 @@ activation {
|
||||
|
||||
# Event daemon
|
||||
#
|
||||
#dmeventd {
|
||||
# dmeventd {
|
||||
# mirror_library is the library used when monitoring a mirror device.
|
||||
#
|
||||
# "libdevmapper-event-lvm2mirror.so" attempts to recover from failures.
|
||||
# It removes failed devices from a volume group and reconfigures a
|
||||
# mirror as necessary.
|
||||
#
|
||||
# mirror_library = "libdevmapper-event-lvm2mirror.so"
|
||||
#}
|
||||
|
||||
|
||||
@@ -152,11 +152,16 @@ int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv)
|
||||
}
|
||||
|
||||
int pv_uses_vg(struct cmd_context *cmd, struct physical_volume *pv,
|
||||
struct volume_group *vg)
|
||||
struct volume_group *vg)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void activation_release(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void activation_exit(void)
|
||||
{
|
||||
return;
|
||||
@@ -193,7 +198,7 @@ static int _passes_activation_filter(struct cmd_context *cmd,
|
||||
char *str;
|
||||
char path[PATH_MAX];
|
||||
|
||||
if (!(cn = find_config_node(cmd->cft->root, "activation/volume_list"))) {
|
||||
if (!(cn = find_config_tree_node(cmd, "activation/volume_list"))) {
|
||||
/* If no host tags defined, activate */
|
||||
if (list_empty(&cmd->tags))
|
||||
return 1;
|
||||
@@ -523,7 +528,7 @@ static int _lv_deactivate(struct logical_volume *lv)
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _lv_suspend_lv(struct logical_volume *lv)
|
||||
static int _lv_suspend_lv(struct logical_volume *lv, int lockfs)
|
||||
{
|
||||
int r;
|
||||
struct dev_manager *dm;
|
||||
@@ -531,7 +536,7 @@ static int _lv_suspend_lv(struct logical_volume *lv)
|
||||
if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name)))
|
||||
return_0;
|
||||
|
||||
if (!(r = dev_manager_suspend(dm, lv)))
|
||||
if (!(r = dev_manager_suspend(dm, lv, lockfs)))
|
||||
stack;
|
||||
|
||||
dev_manager_destroy(dm);
|
||||
@@ -574,14 +579,29 @@ int lvs_in_vg_opened(struct volume_group *vg)
|
||||
return count;
|
||||
}
|
||||
|
||||
static int _register_dev_for_events(struct cmd_context *cmd,
|
||||
struct logical_volume *lv, int do_reg)
|
||||
/*
|
||||
* register_dev_for_events
|
||||
*
|
||||
* This function uses proper error codes (but breaks convention)
|
||||
* to return:
|
||||
* -1 on error
|
||||
* 0 if the lv's targets don't do event [un]registration
|
||||
* 0 if the lv is already [un]registered -- FIXME: not implemented
|
||||
* 1 if the lv had a segment which was [un]registered
|
||||
*
|
||||
* Returns: -1 on error
|
||||
*/
|
||||
int register_dev_for_events(struct cmd_context *cmd,
|
||||
struct logical_volume *lv, int do_reg)
|
||||
{
|
||||
#ifdef DMEVENTD
|
||||
int r = 0;
|
||||
struct list *tmp;
|
||||
struct lv_segment *seg;
|
||||
int (*reg) (struct dm_pool *mem, struct lv_segment *,
|
||||
struct config_tree *cft, int events);
|
||||
int (*reg) (struct lv_segment *, int events);
|
||||
|
||||
if (do_reg && !dmeventd_register_mode())
|
||||
return 1;
|
||||
|
||||
list_iterate(tmp, &lv->segments) {
|
||||
seg = list_item(tmp, struct lv_segment);
|
||||
@@ -595,17 +615,21 @@ static int _register_dev_for_events(struct cmd_context *cmd,
|
||||
reg = seg->segtype->ops->target_unregister_events;
|
||||
|
||||
if (!reg)
|
||||
return_0;
|
||||
continue;
|
||||
|
||||
/* FIXME specify events */
|
||||
if (!reg(cmd->mem, seg, cmd->cft, 0)) {
|
||||
/* FIXME specify events */
|
||||
if (!reg(seg, 0)) {
|
||||
stack;
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
r = 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
return r;
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s,
|
||||
@@ -613,6 +637,7 @@ static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s,
|
||||
{
|
||||
struct logical_volume *lv, *lv_pre;
|
||||
struct lvinfo info;
|
||||
int lockfs = 0;
|
||||
|
||||
if (!activation())
|
||||
return 1;
|
||||
@@ -643,12 +668,16 @@ static int _lv_suspend(struct cmd_context *cmd, const char *lvid_s,
|
||||
}
|
||||
}
|
||||
|
||||
if (!_register_dev_for_events(cmd, lv, 0))
|
||||
if (register_dev_for_events(cmd, lv, 0) != 1)
|
||||
/* FIXME Consider aborting here */
|
||||
stack;
|
||||
|
||||
memlock_inc();
|
||||
if (!_lv_suspend_lv(lv)) {
|
||||
|
||||
if (lv_is_origin(lv_pre) || lv_is_cow(lv_pre))
|
||||
lockfs = 1;
|
||||
|
||||
if (!_lv_suspend_lv(lv, lockfs)) {
|
||||
memlock_dec();
|
||||
fs_unlock();
|
||||
return 0;
|
||||
@@ -697,7 +726,7 @@ static int _lv_resume(struct cmd_context *cmd, const char *lvid_s,
|
||||
memlock_dec();
|
||||
fs_unlock();
|
||||
|
||||
if (!_register_dev_for_events(cmd, lv, 1))
|
||||
if (register_dev_for_events(cmd, lv, 1) != 1)
|
||||
stack;
|
||||
|
||||
return 1;
|
||||
@@ -743,7 +772,7 @@ int lv_deactivate(struct cmd_context *cmd, const char *lvid_s)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_register_dev_for_events(cmd, lv, 0))
|
||||
if (register_dev_for_events(cmd, lv, 0) != 1)
|
||||
stack;
|
||||
|
||||
memlock_inc();
|
||||
@@ -816,7 +845,7 @@ static int _lv_activate(struct cmd_context *cmd, const char *lvid_s,
|
||||
memlock_dec();
|
||||
fs_unlock();
|
||||
|
||||
if (!_register_dev_for_events(cmd, lv, 1))
|
||||
if (!register_dev_for_events(cmd, lv, 1) != 1)
|
||||
stack;
|
||||
|
||||
return r;
|
||||
@@ -862,28 +891,21 @@ int lv_mknodes(struct cmd_context *cmd, const struct logical_volume *lv)
|
||||
* Does PV use VG somewhere in its construction?
|
||||
* Returns 1 on failure.
|
||||
*/
|
||||
int pv_uses_vg(struct cmd_context *cmd, struct physical_volume *pv,
|
||||
struct volume_group *vg)
|
||||
int pv_uses_vg(struct physical_volume *pv,
|
||||
struct volume_group *vg)
|
||||
{
|
||||
struct dev_manager *dm;
|
||||
int r;
|
||||
|
||||
if (!activation())
|
||||
return 0;
|
||||
|
||||
if (!dm_is_dm_major(MAJOR(pv->dev->dev)))
|
||||
return 0;
|
||||
|
||||
if (!(dm = dev_manager_create(cmd, vg->name))) {
|
||||
stack;
|
||||
return 1;
|
||||
}
|
||||
return dev_manager_device_uses_vg(pv->dev, vg);
|
||||
}
|
||||
|
||||
r = dev_manager_device_uses_vg(dm, pv->dev, vg);
|
||||
|
||||
dev_manager_destroy(dm);
|
||||
|
||||
return r;
|
||||
void activation_release(void)
|
||||
{
|
||||
dev_manager_release();
|
||||
}
|
||||
|
||||
void activation_exit(void)
|
||||
|
||||
@@ -40,6 +40,7 @@ int target_present(const char *target_name, int use_modprobe);
|
||||
int target_version(const char *target_name, uint32_t *maj,
|
||||
uint32_t *min, uint32_t *patchlevel);
|
||||
|
||||
void activation_release(void);
|
||||
void activation_exit(void);
|
||||
|
||||
int lv_suspend(struct cmd_context *cmd, const char *lvid_s);
|
||||
@@ -80,10 +81,14 @@ int lv_mirror_percent(struct cmd_context *cmd, struct logical_volume *lv,
|
||||
int lvs_in_vg_activated(struct volume_group *vg);
|
||||
int lvs_in_vg_opened(struct volume_group *vg);
|
||||
|
||||
|
||||
int register_dev_for_events(struct cmd_context *cmd,
|
||||
struct logical_volume *lv, int do_reg);
|
||||
|
||||
/*
|
||||
* Returns 1 if PV has a dependency tree that uses anything in VG.
|
||||
*/
|
||||
int pv_uses_vg(struct cmd_context *cmd, struct physical_volume *pv,
|
||||
int pv_uses_vg(struct physical_volume *pv,
|
||||
struct volume_group *vg);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -37,6 +37,7 @@ typedef enum {
|
||||
ACTIVATE,
|
||||
DEACTIVATE,
|
||||
SUSPEND,
|
||||
SUSPEND_WITH_LOCKFS,
|
||||
CLEAN
|
||||
} action_t;
|
||||
|
||||
@@ -329,7 +330,7 @@ static int _percent_run(struct dev_manager *dm, const char *name,
|
||||
|
||||
if (segtype->ops->target_percent &&
|
||||
!segtype->ops->target_percent(&dm->target_state, dm->mem,
|
||||
dm->cmd->cft, seg, params,
|
||||
dm->cmd, seg, params,
|
||||
&total_numerator,
|
||||
&total_denominator,
|
||||
percent))
|
||||
@@ -401,7 +402,7 @@ struct dev_manager *dev_manager_create(struct cmd_context *cmd,
|
||||
dm->mem = mem;
|
||||
|
||||
if (!stripe_filler) {
|
||||
stripe_filler = find_config_str(cmd->cft->root,
|
||||
stripe_filler = find_config_tree_str(cmd,
|
||||
"activation/missing_stripe_filler",
|
||||
DEFAULT_STRIPE_FILLER);
|
||||
}
|
||||
@@ -426,6 +427,11 @@ void dev_manager_destroy(struct dev_manager *dm)
|
||||
dm_pool_destroy(dm->mem);
|
||||
}
|
||||
|
||||
void dev_manager_release(void)
|
||||
{
|
||||
dm_lib_release();
|
||||
}
|
||||
|
||||
void dev_manager_exit(void)
|
||||
{
|
||||
dm_lib_exit();
|
||||
@@ -679,7 +685,7 @@ int add_areas_line(struct dev_manager *dm, struct lv_segment *seg,
|
||||
(seg_type(seg, s) == AREA_LV && !seg_lv(seg, s)))
|
||||
dm_tree_node_add_target_area(node,
|
||||
dm->stripe_filler,
|
||||
NULL, 0);
|
||||
NULL, UINT64_C(0));
|
||||
else if (seg_type(seg, s) == AREA_PV)
|
||||
dm_tree_node_add_target_area(node,
|
||||
dev_name(seg_dev(seg, s)),
|
||||
@@ -704,7 +710,6 @@ int add_areas_line(struct dev_manager *dm, struct lv_segment *seg,
|
||||
}
|
||||
|
||||
static int _add_origin_target_to_dtree(struct dev_manager *dm,
|
||||
struct dm_tree *dtree,
|
||||
struct dm_tree_node *dnode,
|
||||
struct logical_volume *lv)
|
||||
{
|
||||
@@ -720,7 +725,6 @@ static int _add_origin_target_to_dtree(struct dev_manager *dm,
|
||||
}
|
||||
|
||||
static int _add_snapshot_target_to_dtree(struct dev_manager *dm,
|
||||
struct dm_tree *dtree,
|
||||
struct dm_tree_node *dnode,
|
||||
struct logical_volume *lv)
|
||||
{
|
||||
@@ -749,7 +753,6 @@ static int _add_snapshot_target_to_dtree(struct dev_manager *dm,
|
||||
}
|
||||
|
||||
static int _add_target_to_dtree(struct dev_manager *dm,
|
||||
struct dm_tree *dtree,
|
||||
struct dm_tree_node *dnode,
|
||||
struct lv_segment *seg)
|
||||
{
|
||||
@@ -761,7 +764,7 @@ static int _add_target_to_dtree(struct dev_manager *dm,
|
||||
return 0;
|
||||
}
|
||||
|
||||
return seg->segtype->ops->add_target_line(dm, dm->mem, dm->cmd->cft,
|
||||
return seg->segtype->ops->add_target_line(dm, dm->mem, dm->cmd,
|
||||
&dm->target_state, seg,
|
||||
dnode,
|
||||
extent_size * seg->len,
|
||||
@@ -814,12 +817,12 @@ static int _add_segment_to_dtree(struct dev_manager *dm,
|
||||
|
||||
/* Now we've added its dependencies, we can add the target itself */
|
||||
if (lv_is_origin(seg->lv) && !layer) {
|
||||
if (!_add_origin_target_to_dtree(dm, dtree, dnode, seg->lv))
|
||||
if (!_add_origin_target_to_dtree(dm, dnode, seg->lv))
|
||||
return_0;
|
||||
} else if (lv_is_cow(seg->lv) && !layer) {
|
||||
if (!_add_snapshot_target_to_dtree(dm, dtree, dnode, seg->lv))
|
||||
if (!_add_snapshot_target_to_dtree(dm, dnode, seg->lv))
|
||||
return_0;
|
||||
} else if (!_add_target_to_dtree(dm, dtree, dnode, seg))
|
||||
} else if (!_add_target_to_dtree(dm, dnode, seg))
|
||||
return_0;
|
||||
|
||||
if (lv_is_origin(seg->lv) && !layer)
|
||||
@@ -864,10 +867,10 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
|
||||
* Major/minor settings only apply to the visible layer.
|
||||
*/
|
||||
if (!(dnode = dm_tree_add_new_dev(dtree, name, dlid,
|
||||
layer ? lv->major : 0,
|
||||
layer ? lv->minor : 0,
|
||||
layer ? UINT32_C(0) : (uint32_t) lv->major,
|
||||
layer ? UINT32_C(0) : (uint32_t) lv->minor,
|
||||
_read_only_lv(lv),
|
||||
lv->vg->status & PRECOMMITTED,
|
||||
(lv->vg->status & PRECOMMITTED) ? 1 : 0,
|
||||
lvlayer)))
|
||||
return_0;
|
||||
|
||||
@@ -921,7 +924,7 @@ static int _create_lv_symlinks(struct dev_manager *dm, struct dm_tree_node *root
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _clean_tree(struct dev_manager *dm, struct logical_volume *lv, struct dm_tree_node *root)
|
||||
static int _clean_tree(struct dev_manager *dm, struct dm_tree_node *root)
|
||||
{
|
||||
void *handle = NULL;
|
||||
struct dm_tree_node *child;
|
||||
@@ -973,7 +976,7 @@ static int _tree_action(struct dev_manager *dm, struct logical_volume *lv, actio
|
||||
switch(action) {
|
||||
case CLEAN:
|
||||
/* Deactivate any unused non-toplevel nodes */
|
||||
if (!_clean_tree(dm, lv, root))
|
||||
if (!_clean_tree(dm, root))
|
||||
goto_out;
|
||||
break;
|
||||
case DEACTIVATE:
|
||||
@@ -982,8 +985,8 @@ static int _tree_action(struct dev_manager *dm, struct logical_volume *lv, actio
|
||||
goto_out;
|
||||
break;
|
||||
case SUSPEND:
|
||||
if (!lv_is_origin(lv) && !lv_is_cow(lv))
|
||||
dm_tree_skip_lockfs(root);
|
||||
dm_tree_skip_lockfs(root);
|
||||
case SUSPEND_WITH_LOCKFS:
|
||||
if (!dm_tree_suspend_children(root, dlid, ID_LEN + sizeof(UUID_PREFIX) - 1))
|
||||
goto_out;
|
||||
break;
|
||||
@@ -1047,16 +1050,17 @@ int dev_manager_deactivate(struct dev_manager *dm, struct logical_volume *lv)
|
||||
return r;
|
||||
}
|
||||
|
||||
int dev_manager_suspend(struct dev_manager *dm, struct logical_volume *lv)
|
||||
int dev_manager_suspend(struct dev_manager *dm, struct logical_volume *lv,
|
||||
int lockfs)
|
||||
{
|
||||
return _tree_action(dm, lv, SUSPEND);
|
||||
return _tree_action(dm, lv, lockfs ? SUSPEND_WITH_LOCKFS : SUSPEND);
|
||||
}
|
||||
|
||||
/*
|
||||
* Does device use VG somewhere in its construction?
|
||||
* Returns 1 if uncertain.
|
||||
*/
|
||||
int dev_manager_device_uses_vg(struct dev_manager *dm, struct device *dev,
|
||||
int dev_manager_device_uses_vg(struct device *dev,
|
||||
struct volume_group *vg)
|
||||
{
|
||||
struct dm_tree *dtree;
|
||||
@@ -1069,7 +1073,7 @@ int dev_manager_device_uses_vg(struct dev_manager *dm, struct device *dev,
|
||||
return r;
|
||||
}
|
||||
|
||||
if (!dm_tree_add_dev(dtree, MAJOR(dev->dev), MINOR(dev->dev))) {
|
||||
if (!dm_tree_add_dev(dtree, (uint32_t) MAJOR(dev->dev), (uint32_t) MINOR(dev->dev))) {
|
||||
log_error("Failed to add device %s (%" PRIu32 ":%" PRIu32") to dtree",
|
||||
dev_name(dev), (uint32_t) MAJOR(dev->dev), (uint32_t) MINOR(dev->dev));
|
||||
goto out;
|
||||
|
||||
@@ -29,6 +29,7 @@ struct device;
|
||||
struct dev_manager *dev_manager_create(struct cmd_context *cmd,
|
||||
const char *vg_name);
|
||||
void dev_manager_destroy(struct dev_manager *dm);
|
||||
void dev_manager_release(void);
|
||||
void dev_manager_exit(void);
|
||||
|
||||
/*
|
||||
@@ -46,7 +47,8 @@ int dev_manager_snapshot_percent(struct dev_manager *dm,
|
||||
int dev_manager_mirror_percent(struct dev_manager *dm,
|
||||
struct logical_volume *lv, int wait,
|
||||
float *percent, uint32_t *event_nr);
|
||||
int dev_manager_suspend(struct dev_manager *dm, struct logical_volume *lv);
|
||||
int dev_manager_suspend(struct dev_manager *dm, struct logical_volume *lv,
|
||||
int lockfs);
|
||||
int dev_manager_activate(struct dev_manager *dm, struct logical_volume *lv);
|
||||
int dev_manager_preload(struct dev_manager *dm, struct logical_volume *lv);
|
||||
int dev_manager_deactivate(struct dev_manager *dm, struct logical_volume *lv);
|
||||
@@ -59,7 +61,7 @@ int dev_manager_lv_rmnodes(const struct logical_volume *lv);
|
||||
*/
|
||||
int dev_manager_execute(struct dev_manager *dm);
|
||||
|
||||
int dev_manager_device_uses_vg(struct dev_manager *dm, struct device *dev,
|
||||
int dev_manager_device_uses_vg(struct device *dev,
|
||||
struct volume_group *vg);
|
||||
|
||||
#endif
|
||||
|
||||
22
lib/cache/lvmcache.c
vendored
22
lib/cache/lvmcache.c
vendored
@@ -50,7 +50,7 @@ int lvmcache_init(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void lvmcache_lock_vgname(const char *vgname, int read_only)
|
||||
void lvmcache_lock_vgname(const char *vgname, int read_only __attribute((unused)))
|
||||
{
|
||||
if (!_lock_hash && !lvmcache_init()) {
|
||||
log_error("Internal cache initialisation failed");
|
||||
@@ -169,14 +169,18 @@ struct lvmcache_vginfo *vginfo_from_vgid(const char *vgid)
|
||||
const char *vgname_from_vgid(struct dm_pool *mem, const char *vgid)
|
||||
{
|
||||
struct lvmcache_vginfo *vginfo;
|
||||
const char *vgname = NULL;
|
||||
|
||||
if ((vginfo = vginfo_from_vgid(vgid))) {
|
||||
if (mem)
|
||||
return dm_pool_strdup(mem, vginfo->vgname);
|
||||
return vginfo->vgname;
|
||||
}
|
||||
if (!*vgid)
|
||||
vgname = ORPHAN;
|
||||
|
||||
return NULL;
|
||||
if ((vginfo = vginfo_from_vgid(vgid)))
|
||||
vgname = vginfo->vgname;
|
||||
|
||||
if (mem && vgname)
|
||||
return dm_pool_strdup(mem, vgname);
|
||||
|
||||
return vgname;
|
||||
}
|
||||
|
||||
struct lvmcache_info *info_from_pvid(const char *pvid)
|
||||
@@ -237,7 +241,7 @@ int lvmcache_label_scan(struct cmd_context *cmd, int full_scan)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!(iter = dev_iter_create(cmd->filter, (full_scan == 2) ? 1: 0))) {
|
||||
if (!(iter = dev_iter_create(cmd->filter, (full_scan == 2) ? 1 : 0))) {
|
||||
log_error("dev_iter creation failed");
|
||||
goto out;
|
||||
}
|
||||
@@ -857,7 +861,7 @@ static void _lvmcache_destroy_vgnamelist(struct lvmcache_vginfo *vginfo)
|
||||
} while ((vginfo = next));
|
||||
}
|
||||
|
||||
static void _lvmcache_destroy_lockname(int present)
|
||||
static void _lvmcache_destroy_lockname(int present __attribute((unused)))
|
||||
{
|
||||
/* Nothing to do */
|
||||
}
|
||||
|
||||
@@ -84,10 +84,11 @@ static void _init_logging(struct cmd_context *cmd)
|
||||
time_t t;
|
||||
|
||||
const char *log_file;
|
||||
char timebuf[26];
|
||||
|
||||
/* Syslog */
|
||||
cmd->default_settings.syslog =
|
||||
find_config_int(cmd->cft->root, "log/syslog", DEFAULT_SYSLOG);
|
||||
find_config_tree_int(cmd, "log/syslog", DEFAULT_SYSLOG);
|
||||
if (cmd->default_settings.syslog != 1)
|
||||
fin_syslog();
|
||||
|
||||
@@ -96,37 +97,37 @@ static void _init_logging(struct cmd_context *cmd)
|
||||
|
||||
/* Debug level for log file output */
|
||||
cmd->default_settings.debug =
|
||||
find_config_int(cmd->cft->root, "log/level", DEFAULT_LOGLEVEL);
|
||||
find_config_tree_int(cmd, "log/level", DEFAULT_LOGLEVEL);
|
||||
init_debug(cmd->default_settings.debug);
|
||||
|
||||
/* Verbose level for tty output */
|
||||
cmd->default_settings.verbose =
|
||||
find_config_int(cmd->cft->root, "log/verbose", DEFAULT_VERBOSE);
|
||||
find_config_tree_int(cmd, "log/verbose", DEFAULT_VERBOSE);
|
||||
init_verbose(cmd->default_settings.verbose + VERBOSE_BASE_LEVEL);
|
||||
|
||||
/* Log message formatting */
|
||||
init_indent(find_config_int(cmd->cft->root, "log/indent",
|
||||
init_indent(find_config_tree_int(cmd, "log/indent",
|
||||
DEFAULT_INDENT));
|
||||
|
||||
cmd->default_settings.msg_prefix = find_config_str(cmd->cft->root,
|
||||
cmd->default_settings.msg_prefix = find_config_tree_str(cmd,
|
||||
"log/prefix",
|
||||
DEFAULT_MSG_PREFIX);
|
||||
init_msg_prefix(cmd->default_settings.msg_prefix);
|
||||
|
||||
cmd->default_settings.cmd_name = find_config_int(cmd->cft->root,
|
||||
cmd->default_settings.cmd_name = find_config_tree_int(cmd,
|
||||
"log/command_names",
|
||||
DEFAULT_CMD_NAME);
|
||||
init_cmd_name(cmd->default_settings.cmd_name);
|
||||
|
||||
/* Test mode */
|
||||
cmd->default_settings.test =
|
||||
find_config_int(cmd->cft->root, "global/test", 0);
|
||||
find_config_tree_int(cmd, "global/test", 0);
|
||||
|
||||
/* Settings for logging to file */
|
||||
if (find_config_int(cmd->cft->root, "log/overwrite", DEFAULT_OVERWRITE))
|
||||
if (find_config_tree_int(cmd, "log/overwrite", DEFAULT_OVERWRITE))
|
||||
append = 0;
|
||||
|
||||
log_file = find_config_str(cmd->cft->root, "log/file", 0);
|
||||
log_file = find_config_tree_str(cmd, "log/file", 0);
|
||||
|
||||
if (log_file) {
|
||||
release_log_memory();
|
||||
@@ -134,15 +135,17 @@ static void _init_logging(struct cmd_context *cmd)
|
||||
init_log_file(log_file, append);
|
||||
}
|
||||
|
||||
log_file = find_config_str(cmd->cft->root, "log/activate_file", 0);
|
||||
log_file = find_config_tree_str(cmd, "log/activate_file", 0);
|
||||
if (log_file)
|
||||
init_log_direct(log_file, append);
|
||||
|
||||
init_log_while_suspended(find_config_int(cmd->cft->root,
|
||||
init_log_while_suspended(find_config_tree_int(cmd,
|
||||
"log/activation", 0));
|
||||
|
||||
t = time(NULL);
|
||||
log_verbose("Logging initialised at %s", ctime(&t));
|
||||
ctime_r(&t, &timebuf[0]);
|
||||
timebuf[24] = '\0';
|
||||
log_verbose("Logging initialised at %s", timebuf);
|
||||
|
||||
/* Tell device-mapper about our logging */
|
||||
#ifdef DEVMAPPER_SUPPORT
|
||||
@@ -155,7 +158,7 @@ static int _process_config(struct cmd_context *cmd)
|
||||
mode_t old_umask;
|
||||
|
||||
/* umask */
|
||||
cmd->default_settings.umask = find_config_int(cmd->cft->root,
|
||||
cmd->default_settings.umask = find_config_tree_int(cmd,
|
||||
"global/umask",
|
||||
DEFAULT_UMASK);
|
||||
|
||||
@@ -165,7 +168,7 @@ static int _process_config(struct cmd_context *cmd)
|
||||
|
||||
/* dev dir */
|
||||
if (lvm_snprintf(cmd->dev_dir, sizeof(cmd->dev_dir), "%s/",
|
||||
find_config_str(cmd->cft->root, "devices/dir",
|
||||
find_config_tree_str(cmd, "devices/dir",
|
||||
DEFAULT_DEV_DIR)) < 0) {
|
||||
log_error("Device directory given in config file too long");
|
||||
return 0;
|
||||
@@ -176,7 +179,7 @@ static int _process_config(struct cmd_context *cmd)
|
||||
|
||||
/* proc dir */
|
||||
if (lvm_snprintf(cmd->proc_dir, sizeof(cmd->proc_dir), "%s",
|
||||
find_config_str(cmd->cft->root, "global/proc",
|
||||
find_config_tree_str(cmd, "global/proc",
|
||||
DEFAULT_PROC_DIR)) < 0) {
|
||||
log_error("Device directory given in config file too long");
|
||||
return 0;
|
||||
@@ -189,17 +192,17 @@ static int _process_config(struct cmd_context *cmd)
|
||||
}
|
||||
|
||||
/* activation? */
|
||||
cmd->default_settings.activation = find_config_int(cmd->cft->root,
|
||||
cmd->default_settings.activation = find_config_tree_int(cmd,
|
||||
"global/activation",
|
||||
DEFAULT_ACTIVATION);
|
||||
set_activation(cmd->default_settings.activation);
|
||||
|
||||
cmd->default_settings.suffix = find_config_int(cmd->cft->root,
|
||||
cmd->default_settings.suffix = find_config_tree_int(cmd,
|
||||
"global/suffix",
|
||||
DEFAULT_SUFFIX);
|
||||
|
||||
if (!(cmd->default_settings.unit_factor =
|
||||
units_to_bytes(find_config_str(cmd->cft->root,
|
||||
units_to_bytes(find_config_tree_str(cmd,
|
||||
"global/units",
|
||||
DEFAULT_UNITS),
|
||||
&cmd->default_settings.unit_type))) {
|
||||
@@ -469,7 +472,7 @@ static int _init_dev_cache(struct cmd_context *cmd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(cn = find_config_node(cmd->cft->root, "devices/scan"))) {
|
||||
if (!(cn = find_config_tree_node(cmd, "devices/scan"))) {
|
||||
if (!dev_cache_add_dir("/dev")) {
|
||||
log_error("Failed to add /dev to internal "
|
||||
"device cache");
|
||||
@@ -494,7 +497,7 @@ static int _init_dev_cache(struct cmd_context *cmd)
|
||||
}
|
||||
}
|
||||
|
||||
if (!(cn = find_config_node(cmd->cft->root, "devices/loopfiles")))
|
||||
if (!(cn = find_config_tree_node(cmd, "devices/loopfiles")))
|
||||
return 1;
|
||||
|
||||
for (cv = cn->v; cv; cv = cv->next) {
|
||||
@@ -536,14 +539,14 @@ static struct dev_filter *_init_filter_components(struct cmd_context *cmd)
|
||||
* Listed first because it's very efficient at eliminating
|
||||
* unavailable devices.
|
||||
*/
|
||||
if (find_config_bool(cmd->cft->root, "devices/sysfs_scan",
|
||||
if (find_config_tree_bool(cmd, "devices/sysfs_scan",
|
||||
DEFAULT_SYSFS_SCAN)) {
|
||||
if ((filters[nr_filt] = sysfs_filter_create(cmd->proc_dir)))
|
||||
nr_filt++;
|
||||
}
|
||||
|
||||
/* regex filter. Optional. */
|
||||
if (!(cn = find_config_node(cmd->cft->root, "devices/filter")))
|
||||
if (!(cn = find_config_tree_node(cmd, "devices/filter")))
|
||||
log_very_verbose("devices/filter not found in config file: "
|
||||
"no regex filter installed");
|
||||
|
||||
@@ -553,14 +556,14 @@ static struct dev_filter *_init_filter_components(struct cmd_context *cmd)
|
||||
}
|
||||
|
||||
/* device type filter. Required. */
|
||||
cn = find_config_node(cmd->cft->root, "devices/types");
|
||||
cn = find_config_tree_node(cmd, "devices/types");
|
||||
if (!(filters[nr_filt++] = lvm_type_filter_create(cmd->proc_dir, cn))) {
|
||||
log_error("Failed to create lvm type filter");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* md component filter. Optional, non-critical. */
|
||||
if (find_config_bool(cmd->cft->root, "devices/md_component_detection",
|
||||
if (find_config_tree_bool(cmd, "devices/md_component_detection",
|
||||
DEFAULT_MD_COMPONENT_DETECTION)) {
|
||||
init_md_filtering(1);
|
||||
if ((filters[nr_filt] = md_filter_create()))
|
||||
@@ -591,7 +594,7 @@ static int _init_filters(struct cmd_context *cmd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
dev_cache = find_config_str(cmd->cft->root, "devices/cache",
|
||||
dev_cache = find_config_tree_str(cmd, "devices/cache",
|
||||
cache_file);
|
||||
if (!(f4 = persistent_filter_create(f3, dev_cache))) {
|
||||
log_error("Failed to create persistent device filter");
|
||||
@@ -599,7 +602,7 @@ static int _init_filters(struct cmd_context *cmd)
|
||||
}
|
||||
|
||||
/* Should we ever dump persistent filter state? */
|
||||
if (find_config_int(cmd->cft->root, "devices/write_cache_state", 1))
|
||||
if (find_config_tree_int(cmd, "devices/write_cache_state", 1))
|
||||
cmd->dump_filter = 1;
|
||||
|
||||
if (!*cmd->sys_dir)
|
||||
@@ -644,7 +647,7 @@ static int _init_formats(struct cmd_context *cmd)
|
||||
|
||||
#ifdef HAVE_LIBDL
|
||||
/* Load any formats in shared libs */
|
||||
if ((cn = find_config_node(cmd->cft->root, "global/format_libraries"))) {
|
||||
if ((cn = find_config_tree_node(cmd, "global/format_libraries"))) {
|
||||
|
||||
struct config_value *cv;
|
||||
struct format_type *(*init_format_fn) (struct cmd_context *);
|
||||
@@ -656,7 +659,7 @@ static int _init_formats(struct cmd_context *cmd)
|
||||
"global/format_libraries");
|
||||
return 0;
|
||||
}
|
||||
if (!(lib = load_shared_library(cmd->cft, cv->v.str,
|
||||
if (!(lib = load_shared_library(cmd, cv->v.str,
|
||||
"format", 0))) {
|
||||
stack;
|
||||
return 0;
|
||||
@@ -684,7 +687,7 @@ static int _init_formats(struct cmd_context *cmd)
|
||||
|
||||
cmd->fmt_backup = fmt;
|
||||
|
||||
format = find_config_str(cmd->cft->root, "global/format",
|
||||
format = find_config_tree_str(cmd, "global/format",
|
||||
DEFAULT_FORMAT);
|
||||
|
||||
list_iterate_items(fmt, &cmd->formats) {
|
||||
@@ -738,7 +741,7 @@ static int _init_segtypes(struct cmd_context *cmd)
|
||||
|
||||
#ifdef HAVE_LIBDL
|
||||
/* Load any formats in shared libs */
|
||||
if ((cn = find_config_node(cmd->cft->root, "global/segment_libraries"))) {
|
||||
if ((cn = find_config_tree_node(cmd, "global/segment_libraries"))) {
|
||||
|
||||
struct config_value *cv;
|
||||
struct segment_type *(*init_segtype_fn) (struct cmd_context *);
|
||||
@@ -752,7 +755,7 @@ static int _init_segtypes(struct cmd_context *cmd)
|
||||
"global/segment_libraries");
|
||||
return 0;
|
||||
}
|
||||
if (!(lib = load_shared_library(cmd->cft, cv->v.str,
|
||||
if (!(lib = load_shared_library(cmd, cv->v.str,
|
||||
"segment type", 0))) {
|
||||
stack;
|
||||
return 0;
|
||||
@@ -827,13 +830,13 @@ static int _init_backup(struct cmd_context *cmd)
|
||||
|
||||
/* set up archiving */
|
||||
cmd->default_settings.archive =
|
||||
find_config_bool(cmd->cft->root, "backup/archive",
|
||||
find_config_tree_bool(cmd, "backup/archive",
|
||||
DEFAULT_ARCHIVE_ENABLED);
|
||||
|
||||
days = (uint32_t) find_config_int(cmd->cft->root, "backup/retain_days",
|
||||
days = (uint32_t) find_config_tree_int(cmd, "backup/retain_days",
|
||||
DEFAULT_ARCHIVE_DAYS);
|
||||
|
||||
min = (uint32_t) find_config_int(cmd->cft->root, "backup/retain_min",
|
||||
min = (uint32_t) find_config_tree_int(cmd, "backup/retain_min",
|
||||
DEFAULT_ARCHIVE_NUMBER);
|
||||
|
||||
if (lvm_snprintf
|
||||
@@ -844,7 +847,7 @@ static int _init_backup(struct cmd_context *cmd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
dir = find_config_str(cmd->cft->root, "backup/archive_dir",
|
||||
dir = find_config_tree_str(cmd, "backup/archive_dir",
|
||||
default_dir);
|
||||
|
||||
if (!archive_init(cmd, dir, days, min)) {
|
||||
@@ -854,7 +857,7 @@ static int _init_backup(struct cmd_context *cmd)
|
||||
|
||||
/* set up the backup */
|
||||
cmd->default_settings.backup =
|
||||
find_config_bool(cmd->cft->root, "backup/backup",
|
||||
find_config_tree_bool(cmd, "backup/backup",
|
||||
DEFAULT_BACKUP_ENABLED);
|
||||
|
||||
if (lvm_snprintf
|
||||
@@ -865,7 +868,7 @@ static int _init_backup(struct cmd_context *cmd)
|
||||
return 0;
|
||||
}
|
||||
|
||||
dir = find_config_str(cmd->cft->root, "backup/backup_dir", default_dir);
|
||||
dir = find_config_tree_str(cmd, "backup/backup_dir", default_dir);
|
||||
|
||||
if (!backup_init(cmd, dir)) {
|
||||
log_debug("backup_init failed.");
|
||||
@@ -921,7 +924,7 @@ struct cmd_context *create_toolcontext(struct arg *the_args)
|
||||
|
||||
if (!(cmd->libmem = dm_pool_create("library", 4 * 1024))) {
|
||||
log_error("Library memory pool creation failed");
|
||||
return 0;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!_init_lvm_conf(cmd))
|
||||
@@ -1021,7 +1024,7 @@ int refresh_toolcontext(struct cmd_context *cmd)
|
||||
persistent_filter_dump(cmd->filter);
|
||||
}
|
||||
|
||||
activation_exit();
|
||||
activation_release();
|
||||
lvmcache_destroy();
|
||||
label_exit();
|
||||
_destroy_segtypes(&cmd->segtypes);
|
||||
|
||||
@@ -71,6 +71,7 @@ struct cmd_context {
|
||||
struct list config_files;
|
||||
int config_valid;
|
||||
struct config_tree *cft;
|
||||
struct config_tree *cft_override;
|
||||
struct config_info default_settings;
|
||||
struct config_info current_settings;
|
||||
|
||||
|
||||
@@ -41,10 +41,10 @@ enum {
|
||||
};
|
||||
|
||||
struct parser {
|
||||
char *fb, *fe; /* file limits */
|
||||
const char *fb, *fe; /* file limits */
|
||||
|
||||
int t; /* token limits and type */
|
||||
char *tb, *te;
|
||||
const char *tb, *te;
|
||||
|
||||
int fd; /* descriptor for file being parsed */
|
||||
int line; /* line number we are on */
|
||||
@@ -77,7 +77,7 @@ static const int sep = '/';
|
||||
|
||||
#define match(t) do {\
|
||||
if (!_match_aux(p, (t))) {\
|
||||
log_error("Parse error at line %d: unexpected token", p->line); \
|
||||
log_error("Parse error at byte %d (line %d): unexpected token", p->tb - p->fb + 1, p->line); \
|
||||
return 0;\
|
||||
} \
|
||||
} while(0);
|
||||
@@ -101,12 +101,12 @@ struct config_tree *create_config_tree(const char *filename)
|
||||
struct dm_pool *mem = dm_pool_create("config", 10 * 1024);
|
||||
|
||||
if (!mem) {
|
||||
stack;
|
||||
log_error("Failed to allocate config pool.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(c = dm_pool_zalloc(mem, sizeof(*c)))) {
|
||||
stack;
|
||||
log_error("Failed to allocate config tree.");
|
||||
dm_pool_destroy(mem);
|
||||
return 0;
|
||||
}
|
||||
@@ -125,6 +125,46 @@ void destroy_config_tree(struct config_tree *cft)
|
||||
dm_pool_destroy(((struct cs *) cft)->mem);
|
||||
}
|
||||
|
||||
static int _parse_config_file(struct parser *p, struct config_tree *cft)
|
||||
{
|
||||
p->tb = p->te = p->fb;
|
||||
p->line = 1;
|
||||
_get_token(p, TOK_SECTION_E);
|
||||
if (!(cft->root = _file(p)))
|
||||
return_0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
struct config_tree *create_config_tree_from_string(struct cmd_context *cmd,
|
||||
const char *config_settings)
|
||||
{
|
||||
struct cs *c;
|
||||
struct config_tree *cft;
|
||||
struct parser *p;
|
||||
|
||||
if (!(cft = create_config_tree(NULL)))
|
||||
return_NULL;
|
||||
|
||||
c = (struct cs *) cft;
|
||||
if (!(p = dm_pool_alloc(c->mem, sizeof(*p)))) {
|
||||
log_error("Failed to allocate config tree parser.");
|
||||
destroy_config_tree(cft);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
p->mem = c->mem;
|
||||
p->fb = config_settings;
|
||||
p->fe = config_settings + strlen(config_settings);
|
||||
|
||||
if (!_parse_config_file(p, cft)) {
|
||||
destroy_config_tree(cft);
|
||||
return_NULL;
|
||||
}
|
||||
|
||||
return cft;
|
||||
}
|
||||
|
||||
int read_config_fd(struct config_tree *cft, struct device *dev,
|
||||
off_t offset, size_t size, off_t offset2, size_t size2,
|
||||
checksum_fn_t checksum_fn, uint32_t checksum)
|
||||
@@ -134,6 +174,7 @@ int read_config_fd(struct config_tree *cft, struct device *dev,
|
||||
int r = 0;
|
||||
int use_mmap = 1;
|
||||
off_t mmap_offset = 0;
|
||||
char *buf;
|
||||
|
||||
if (!(p = dm_pool_alloc(c->mem, sizeof(*p)))) {
|
||||
stack;
|
||||
@@ -156,22 +197,23 @@ int read_config_fd(struct config_tree *cft, struct device *dev,
|
||||
}
|
||||
p->fb = p->fb + mmap_offset;
|
||||
} else {
|
||||
if (!(p->fb = dm_malloc(size + size2))) {
|
||||
if (!(buf = dm_malloc(size + size2))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
if (!dev_read(dev, (uint64_t) offset, size, p->fb)) {
|
||||
if (!dev_read(dev, (uint64_t) offset, size, buf)) {
|
||||
log_error("Read from %s failed", dev_name(dev));
|
||||
goto out;
|
||||
}
|
||||
if (size2) {
|
||||
if (!dev_read(dev, (uint64_t) offset2, size2,
|
||||
p->fb + size)) {
|
||||
buf + size)) {
|
||||
log_error("Circular read from %s failed",
|
||||
dev_name(dev));
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
p->fb = buf;
|
||||
}
|
||||
|
||||
if (checksum_fn && checksum !=
|
||||
@@ -183,11 +225,7 @@ int read_config_fd(struct config_tree *cft, struct device *dev,
|
||||
|
||||
p->fe = p->fb + size + size2;
|
||||
|
||||
/* parse */
|
||||
p->tb = p->te = p->fb;
|
||||
p->line = 1;
|
||||
_get_token(p, TOK_SECTION_E);
|
||||
if (!(cft->root = _file(p))) {
|
||||
if (!_parse_config_file(p, cft)) {
|
||||
stack;
|
||||
goto out;
|
||||
}
|
||||
@@ -196,7 +234,7 @@ int read_config_fd(struct config_tree *cft, struct device *dev,
|
||||
|
||||
out:
|
||||
if (!use_mmap)
|
||||
dm_free(p->fb);
|
||||
dm_free(buf);
|
||||
else {
|
||||
/* unmap the file */
|
||||
if (munmap((char *) (p->fb - mmap_offset), size + mmap_offset)) {
|
||||
@@ -529,7 +567,7 @@ static struct config_value *_type(struct parser *p)
|
||||
break;
|
||||
|
||||
default:
|
||||
log_error("Parse error at line %d: expected a value", p->line);
|
||||
log_error("Parse error at byte %d (line %d): expected a value", p->tb - p->fb + 1, p->line);
|
||||
return 0;
|
||||
}
|
||||
return v;
|
||||
@@ -721,8 +759,8 @@ static char *_dup_tok(struct parser *p)
|
||||
/*
|
||||
* utility functions
|
||||
*/
|
||||
struct config_node *find_config_node(const struct config_node *cn,
|
||||
const char *path)
|
||||
static struct config_node *_find_config_node(const struct config_node *cn,
|
||||
const char *path)
|
||||
{
|
||||
const char *e;
|
||||
|
||||
@@ -753,10 +791,32 @@ struct config_node *find_config_node(const struct config_node *cn,
|
||||
return (struct config_node *) cn;
|
||||
}
|
||||
|
||||
const char *find_config_str(const struct config_node *cn,
|
||||
const char *path, const char *fail)
|
||||
static struct config_node *_find_first_config_node(const struct config_node *cn1,
|
||||
const struct config_node *cn2,
|
||||
const char *path)
|
||||
{
|
||||
const struct config_node *n = find_config_node(cn, path);
|
||||
struct config_node *cn;
|
||||
|
||||
if (cn1 && (cn = _find_config_node(cn1, path)))
|
||||
return cn;
|
||||
|
||||
if (cn2 && (cn = _find_config_node(cn2, path)))
|
||||
return cn;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct config_node *find_config_node(const struct config_node *cn,
|
||||
const char *path)
|
||||
{
|
||||
return _find_config_node(cn, path);
|
||||
}
|
||||
|
||||
static const char *_find_config_str(const struct config_node *cn1,
|
||||
const struct config_node *cn2,
|
||||
const char *path, const char *fail)
|
||||
{
|
||||
const struct config_node *n = _find_first_config_node(cn1, cn2, path);
|
||||
|
||||
/* Empty strings are ignored */
|
||||
if ((n && n->v->type == CFG_STRING) && (*n->v->v.str)) {
|
||||
@@ -770,9 +830,17 @@ const char *find_config_str(const struct config_node *cn,
|
||||
return fail;
|
||||
}
|
||||
|
||||
int find_config_int(const struct config_node *cn, const char *path, int fail)
|
||||
const char *find_config_str(const struct config_node *cn,
|
||||
const char *path, const char *fail)
|
||||
{
|
||||
const struct config_node *n = find_config_node(cn, path);
|
||||
return _find_config_str(cn, NULL, path, fail);
|
||||
}
|
||||
|
||||
static int _find_config_int(const struct config_node *cn1,
|
||||
const struct config_node *cn2,
|
||||
const char *path, int fail)
|
||||
{
|
||||
const struct config_node *n = _find_first_config_node(cn1, cn2, path);
|
||||
|
||||
if (n && n->v->type == CFG_INT) {
|
||||
log_very_verbose("Setting %s to %d", path, n->v->v.i);
|
||||
@@ -784,10 +852,16 @@ int find_config_int(const struct config_node *cn, const char *path, int fail)
|
||||
return fail;
|
||||
}
|
||||
|
||||
float find_config_float(const struct config_node *cn, const char *path,
|
||||
float fail)
|
||||
int find_config_int(const struct config_node *cn, const char *path, int fail)
|
||||
{
|
||||
const struct config_node *n = find_config_node(cn, path);
|
||||
return _find_config_int(cn, NULL, path, fail);
|
||||
}
|
||||
|
||||
static float _find_config_float(const struct config_node *cn1,
|
||||
const struct config_node *cn2,
|
||||
const char *path, float fail)
|
||||
{
|
||||
const struct config_node *n = _find_first_config_node(cn1, cn2, path);
|
||||
|
||||
if (n && n->v->type == CFG_FLOAT) {
|
||||
log_very_verbose("Setting %s to %f", path, n->v->v.r);
|
||||
@@ -801,6 +875,36 @@ float find_config_float(const struct config_node *cn, const char *path,
|
||||
|
||||
}
|
||||
|
||||
float find_config_float(const struct config_node *cn, const char *path,
|
||||
float fail)
|
||||
{
|
||||
return _find_config_float(cn, NULL, path, fail);
|
||||
}
|
||||
|
||||
struct config_node *find_config_tree_node(struct cmd_context *cmd,
|
||||
const char *path)
|
||||
{
|
||||
return _find_first_config_node(cmd->cft_override ? cmd->cft_override->root : NULL, cmd->cft->root, path);
|
||||
}
|
||||
|
||||
const char *find_config_tree_str(struct cmd_context *cmd,
|
||||
const char *path, const char *fail)
|
||||
{
|
||||
return _find_config_str(cmd->cft_override ? cmd->cft_override->root : NULL, cmd->cft->root, path, fail);
|
||||
}
|
||||
|
||||
int find_config_tree_int(struct cmd_context *cmd, const char *path,
|
||||
int fail)
|
||||
{
|
||||
return _find_config_int(cmd->cft_override ? cmd->cft_override->root : NULL, cmd->cft->root, path, fail);
|
||||
}
|
||||
|
||||
float find_config_tree_float(struct cmd_context *cmd, const char *path,
|
||||
float fail)
|
||||
{
|
||||
return _find_config_float(cmd->cft_override ? cmd->cft_override->root : NULL, cmd->cft->root, path, fail);
|
||||
}
|
||||
|
||||
static int _str_in_array(const char *str, const char *values[])
|
||||
{
|
||||
int i;
|
||||
@@ -827,9 +931,11 @@ static int _str_to_bool(const char *str, int fail)
|
||||
return fail;
|
||||
}
|
||||
|
||||
int find_config_bool(const struct config_node *cn, const char *path, int fail)
|
||||
static int _find_config_bool(const struct config_node *cn1,
|
||||
const struct config_node *cn2,
|
||||
const char *path, int fail)
|
||||
{
|
||||
const struct config_node *n = find_config_node(cn, path);
|
||||
const struct config_node *n = _find_first_config_node(cn1, cn2, path);
|
||||
struct config_value *v;
|
||||
|
||||
if (!n)
|
||||
@@ -848,6 +954,16 @@ int find_config_bool(const struct config_node *cn, const char *path, int fail)
|
||||
return fail;
|
||||
}
|
||||
|
||||
int find_config_bool(const struct config_node *cn, const char *path, int fail)
|
||||
{
|
||||
return _find_config_bool(cn, NULL, path, fail);
|
||||
}
|
||||
|
||||
int find_config_tree_bool(struct cmd_context *cmd, const char *path, int fail)
|
||||
{
|
||||
return _find_config_bool(cmd->cft_override ? cmd->cft_override->root : NULL, cmd->cft->root, path, fail);
|
||||
}
|
||||
|
||||
int get_config_uint32(const struct config_node *cn, const char *path,
|
||||
uint32_t *result)
|
||||
{
|
||||
|
||||
@@ -54,9 +54,11 @@ struct config_tree_list {
|
||||
};
|
||||
|
||||
struct config_tree *create_config_tree(const char *filename);
|
||||
struct config_tree *create_config_tree_from_string(struct cmd_context *cmd,
|
||||
const char *config_settings);
|
||||
void destroy_config_tree(struct config_tree *cft);
|
||||
|
||||
typedef uint32_t (*checksum_fn_t) (uint32_t initial, void *buf, uint32_t size);
|
||||
typedef uint32_t (*checksum_fn_t) (uint32_t initial, const void *buf, uint32_t size);
|
||||
|
||||
int read_config_fd(struct config_tree *cft, struct device *dev,
|
||||
off_t offset, size_t size, off_t offset2, size_t size2,
|
||||
@@ -71,20 +73,30 @@ int merge_config_tree(struct cmd_context *cmd, struct config_tree *cft,
|
||||
|
||||
struct config_node *find_config_node(const struct config_node *cn,
|
||||
const char *path);
|
||||
|
||||
const char *find_config_str(const struct config_node *cn, const char *path,
|
||||
const char *fail);
|
||||
|
||||
int find_config_int(const struct config_node *cn, const char *path, int fail);
|
||||
|
||||
float find_config_float(const struct config_node *cn, const char *path,
|
||||
float fail);
|
||||
|
||||
/*
|
||||
* These versions check an override tree, if present, first.
|
||||
*/
|
||||
struct config_node *find_config_tree_node(struct cmd_context *cmd,
|
||||
const char *path);
|
||||
const char *find_config_tree_str(struct cmd_context *cmd,
|
||||
const char *path, const char *fail);
|
||||
int find_config_tree_int(struct cmd_context *cmd, const char *path,
|
||||
int fail);
|
||||
float find_config_tree_float(struct cmd_context *cmd, const char *path,
|
||||
float fail);
|
||||
|
||||
/*
|
||||
* Understands (0, ~0), (y, n), (yes, no), (on,
|
||||
* off), (true, false).
|
||||
*/
|
||||
int find_config_bool(const struct config_node *cn, const char *path, int fail);
|
||||
int find_config_tree_bool(struct cmd_context *cmd, const char *path, int fail);
|
||||
|
||||
int get_config_uint32(const struct config_node *cn, const char *path,
|
||||
uint32_t *result);
|
||||
|
||||
@@ -34,7 +34,10 @@
|
||||
#define DEFAULT_LOCK_DIR "/var/lock/lvm"
|
||||
#define DEFAULT_LOCKING_LIB "lvm2_locking.so"
|
||||
|
||||
#define DEFAULT_MIRROR_LOG_FAULT_POLICY "allocate"
|
||||
#define DEFAULT_MIRROR_DEV_FAULT_POLICY "remove"
|
||||
#define DEFAULT_DMEVENTD_MIRROR_LIB "libdevmapper-event-lvm2mirror.so"
|
||||
#define DEFAULT_DMEVENTD_MONITOR 1
|
||||
|
||||
#define DEFAULT_UMASK 0077
|
||||
|
||||
|
||||
@@ -645,8 +645,7 @@ struct dev_iter *dev_iter_create(struct dev_filter *f, int dev_scan)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (dev_scan) {
|
||||
if (dev_scan && !trust_cache()) {
|
||||
/* Flag gets reset between each command */
|
||||
if (!full_scan_done())
|
||||
persistent_filter_wipe(f); /* Calls _full_scan(1) */
|
||||
|
||||
@@ -602,7 +602,7 @@ int dev_write(struct device *dev, uint64_t offset, size_t len, void *buffer)
|
||||
return _aligned_io(&where, buffer, 1);
|
||||
}
|
||||
|
||||
int dev_zero(struct device *dev, uint64_t offset, size_t len)
|
||||
int dev_set(struct device *dev, uint64_t offset, size_t len, int value)
|
||||
{
|
||||
size_t s;
|
||||
char buffer[4096];
|
||||
@@ -620,7 +620,7 @@ int dev_zero(struct device *dev, uint64_t offset, size_t len)
|
||||
" sectors", dev_name(dev), offset >> SECTOR_SHIFT,
|
||||
len >> SECTOR_SHIFT);
|
||||
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
memset(buffer, value, sizeof(buffer));
|
||||
while (1) {
|
||||
s = len > sizeof(buffer) ? sizeof(buffer) : len;
|
||||
if (!dev_write(dev, offset, s, buffer))
|
||||
|
||||
@@ -62,7 +62,7 @@ static int _has_partition_table(struct device *dev)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!dev_read(dev, 0, sizeof(buf), &buf)) {
|
||||
if (!dev_read(dev, UINT64_C(0), sizeof(buf), &buf)) {
|
||||
stack;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ const char *dev_name(const struct device *dev);
|
||||
int dev_read(struct device *dev, uint64_t offset, size_t len, void *buffer);
|
||||
int dev_write(struct device *dev, uint64_t offset, size_t len, void *buffer);
|
||||
int dev_append(struct device *dev, size_t len, void *buffer);
|
||||
int dev_zero(struct device *dev, uint64_t offset, size_t len);
|
||||
int dev_set(struct device *dev, uint64_t offset, size_t len, int value);
|
||||
void dev_flush(struct device *dev);
|
||||
|
||||
struct device *dev_create_file(const char *filename, struct device *dev,
|
||||
|
||||
@@ -38,11 +38,13 @@ static int _errseg_merge_segments(struct lv_segment *seg1, struct lv_segment *se
|
||||
}
|
||||
|
||||
#ifdef DEVMAPPER_SUPPORT
|
||||
static int _errseg_add_target_line(struct dev_manager *dm, struct dm_pool *mem,
|
||||
struct config_tree *cft, void **target_state,
|
||||
struct lv_segment *seg,
|
||||
static int _errseg_add_target_line(struct dev_manager *dm __attribute((unused)),
|
||||
struct dm_pool *mem __attribute((unused)),
|
||||
struct cmd_context *cmd __attribute((unused)),
|
||||
void **target_state __attribute((unused)),
|
||||
struct lv_segment *seg __attribute((unused)),
|
||||
struct dm_tree_node *node, uint64_t len,
|
||||
uint32_t *pvmove_mirror_count)
|
||||
uint32_t *pvmove_mirror_count __attribute((unused)))
|
||||
{
|
||||
return dm_tree_node_add_error_target(node, len);
|
||||
}
|
||||
@@ -64,7 +66,7 @@ static int _errseg_target_present(void)
|
||||
|
||||
static void _errseg_destroy(const struct segment_type *segtype)
|
||||
{
|
||||
dm_free((void *) segtype);
|
||||
dm_free((void *)segtype);
|
||||
}
|
||||
|
||||
static struct segtype_handler _error_ops = {
|
||||
|
||||
@@ -458,7 +458,7 @@ static void _add_pv_to_list(struct list *head, struct disk_list *data)
|
||||
|
||||
/*
|
||||
* Build a list of pv_d's structures, allocated from mem.
|
||||
* We keep track of the first object allocated form the pool
|
||||
* We keep track of the first object allocated from the pool
|
||||
* so we can free off all the memory if something goes wrong.
|
||||
*/
|
||||
int read_pvs_in_vg(const struct format_type *fmt, const char *vg_name,
|
||||
@@ -576,7 +576,7 @@ static int _write_lvs(struct disk_list *data)
|
||||
|
||||
pos = data->pvd.lv_on_disk.base;
|
||||
|
||||
if (!dev_zero(data->dev, pos, data->pvd.lv_on_disk.size)) {
|
||||
if (!dev_set(data->dev, pos, data->pvd.lv_on_disk.size, 0)) {
|
||||
log_error("Couldn't zero lv area on device '%s'",
|
||||
dev_name(data->dev));
|
||||
return 0;
|
||||
|
||||
@@ -183,7 +183,8 @@ static int _out_with_comment_file(struct formatter *f, const char *comment,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _out_with_comment_raw(struct formatter *f, const char *comment,
|
||||
static int _out_with_comment_raw(struct formatter *f,
|
||||
const char *comment __attribute((unused)),
|
||||
const char *fmt, va_list ap)
|
||||
{
|
||||
int n;
|
||||
@@ -281,7 +282,7 @@ int out_text(struct formatter *f, const char *fmt, ...)
|
||||
}
|
||||
|
||||
static int _print_header(struct formatter *f,
|
||||
struct volume_group *vg, const char *desc)
|
||||
const char *desc)
|
||||
{
|
||||
time_t t;
|
||||
|
||||
@@ -612,46 +613,27 @@ static int _build_pv_names(struct formatter *f, struct volume_group *vg)
|
||||
struct physical_volume *pv;
|
||||
char buffer[32], *name;
|
||||
|
||||
if (!(f->mem = dm_pool_create("text pv_names", 512))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
if (!(f->mem = dm_pool_create("text pv_names", 512)))
|
||||
return_0;
|
||||
|
||||
if (!(f->pv_names = dm_hash_create(128))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
if (!(f->pv_names = dm_hash_create(128)))
|
||||
return_0;
|
||||
|
||||
list_iterate_items(pvl, &vg->pvs) {
|
||||
pv = pvl->pv;
|
||||
|
||||
/* FIXME But skip if there's already an LV called pv%d ! */
|
||||
if (lvm_snprintf(buffer, sizeof(buffer), "pv%d", count++) < 0) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
if (lvm_snprintf(buffer, sizeof(buffer), "pv%d", count++) < 0)
|
||||
return_0;
|
||||
|
||||
if (!(name = dm_pool_strdup(f->mem, buffer))) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
if (!(name = dm_pool_strdup(f->mem, buffer)))
|
||||
return_0;
|
||||
|
||||
if (!dm_hash_insert(f->pv_names, dev_name(pv->dev), name)) {
|
||||
stack;
|
||||
goto bad;
|
||||
}
|
||||
if (!dm_hash_insert(f->pv_names, dev_name(pv->dev), name))
|
||||
return_0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
bad:
|
||||
if (f->mem)
|
||||
dm_pool_destroy(f->mem);
|
||||
|
||||
if (f->pv_names)
|
||||
dm_hash_destroy(f->pv_names);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _text_vg_export(struct formatter *f,
|
||||
@@ -663,35 +645,33 @@ static int _text_vg_export(struct formatter *f,
|
||||
stack;
|
||||
goto out;
|
||||
}
|
||||
#define fail do {stack; goto out;} while(0)
|
||||
|
||||
if (f->header && !_print_header(f, vg, desc))
|
||||
fail;
|
||||
if (f->header && !_print_header(f, desc))
|
||||
goto_out;
|
||||
|
||||
if (!out_text(f, "%s {", vg->name))
|
||||
fail;
|
||||
goto_out;
|
||||
|
||||
_inc_indent(f);
|
||||
|
||||
if (!_print_vg(f, vg))
|
||||
fail;
|
||||
goto_out;
|
||||
|
||||
outnl(f);
|
||||
if (!_print_pvs(f, vg))
|
||||
fail;
|
||||
goto_out;
|
||||
|
||||
outnl(f);
|
||||
if (!_print_lvs(f, vg))
|
||||
fail;
|
||||
goto_out;
|
||||
|
||||
_dec_indent(f);
|
||||
if (!out_text(f, "}"))
|
||||
fail;
|
||||
goto_out;
|
||||
|
||||
if (!f->header && !_print_header(f, vg, desc))
|
||||
fail;
|
||||
if (!f->header && !_print_header(f, desc))
|
||||
goto_out;
|
||||
|
||||
#undef fail
|
||||
r = 1;
|
||||
|
||||
out:
|
||||
|
||||
@@ -53,6 +53,7 @@ static struct flag _lv_flags[] = {
|
||||
{VISIBLE_LV, "VISIBLE"},
|
||||
{PVMOVE, "PVMOVE"},
|
||||
{LOCKED, "LOCKED"},
|
||||
{MIRROR_NOTSYNCED, "NOTSYNCED"},
|
||||
{MIRROR_IMAGE, NULL},
|
||||
{MIRROR_LOG, NULL},
|
||||
{MIRRORED, NULL},
|
||||
|
||||
@@ -69,7 +69,8 @@ struct text_context {
|
||||
* NOTE: Currently there can be only one vg per text file.
|
||||
*/
|
||||
|
||||
static int _text_vg_setup(struct format_instance *fid, struct volume_group *vg)
|
||||
static int _text_vg_setup(struct format_instance *fid __attribute((unused)),
|
||||
struct volume_group *vg)
|
||||
{
|
||||
if (vg->extent_size & (vg->extent_size - 1)) {
|
||||
log_error("Extent size must be power of 2");
|
||||
@@ -79,7 +80,8 @@ static int _text_vg_setup(struct format_instance *fid, struct volume_group *vg)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _text_lv_setup(struct format_instance *fid, struct logical_volume *lv)
|
||||
static int _text_lv_setup(struct format_instance *fid __attribute((unused)),
|
||||
struct logical_volume *lv)
|
||||
{
|
||||
/******** FIXME Any LV size restriction?
|
||||
uint64_t max_size = UINT_MAX;
|
||||
@@ -1071,9 +1073,9 @@ static int _mda_setup(const struct format_type *fmt,
|
||||
if (!add_mda(fmt, fmt->cmd->mem, mdas, pv->dev, start1,
|
||||
mda_size1)) return 0;
|
||||
|
||||
if (!dev_zero((struct device *) pv->dev, start1,
|
||||
(size_t) (mda_size1 >
|
||||
wipe_size ? : mda_size1))) {
|
||||
if (!dev_set((struct device *) pv->dev, start1,
|
||||
(size_t) (mda_size1 >
|
||||
wipe_size ? : mda_size1), 0)) {
|
||||
log_error("Failed to wipe new metadata area");
|
||||
return 0;
|
||||
}
|
||||
@@ -1117,9 +1119,9 @@ static int _mda_setup(const struct format_type *fmt,
|
||||
if (mda_size2) {
|
||||
if (!add_mda(fmt, fmt->cmd->mem, mdas, pv->dev, start2,
|
||||
mda_size2)) return 0;
|
||||
if (!dev_zero(pv->dev, start2,
|
||||
(size_t) (mda_size1 >
|
||||
wipe_size ? : mda_size1))) {
|
||||
if (!dev_set(pv->dev, start2,
|
||||
(size_t) (mda_size1 >
|
||||
wipe_size ? : mda_size1), 0)) {
|
||||
log_error("Failed to wipe new metadata area");
|
||||
return 0;
|
||||
}
|
||||
@@ -1202,7 +1204,7 @@ static int _text_pv_write(const struct format_type *fmt, struct physical_volume
|
||||
}
|
||||
}
|
||||
if (!add_da
|
||||
(fmt, NULL, &info->das, pv->pe_start << SECTOR_SHIFT, UINT64_C(0))) {
|
||||
(NULL, &info->das, pv->pe_start << SECTOR_SHIFT, UINT64_C(0))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
@@ -1339,7 +1341,7 @@ static int _text_pv_read(const struct format_type *fmt, const char *pv_name,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void _text_destroy_instance(struct format_instance *fid)
|
||||
static void _text_destroy_instance(struct format_instance *fid __attribute((unused)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -1372,7 +1374,7 @@ static void _text_destroy(const struct format_type *fmt)
|
||||
dm_free(fmt->private);
|
||||
}
|
||||
|
||||
dm_free((void *) fmt);
|
||||
dm_free((void *)fmt);
|
||||
}
|
||||
|
||||
static struct metadata_area_ops _metadata_text_file_ops = {
|
||||
@@ -1781,7 +1783,7 @@ struct format_type *create_text_format(struct cmd_context *cmd)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((cn = find_config_node(cmd->cft->root, "metadata/dirs"))) {
|
||||
if ((cn = find_config_tree_node(cmd, "metadata/dirs"))) {
|
||||
for (cv = cn->v; cv; cv = cv->next) {
|
||||
if (cv->type != CFG_STRING) {
|
||||
log_error("Invalid string in config file: "
|
||||
@@ -1797,7 +1799,7 @@ struct format_type *create_text_format(struct cmd_context *cmd)
|
||||
}
|
||||
}
|
||||
|
||||
if ((cn = find_config_node(cmd->cft->root, "metadata/disk_areas"))) {
|
||||
if ((cn = find_config_tree_node(cmd, "metadata/disk_areas"))) {
|
||||
for (cn = cn->child; cn; cn = cn->sib) {
|
||||
if (!_get_config_disk_area(cmd, cn, &mda_lists->raws))
|
||||
goto err;
|
||||
|
||||
@@ -46,7 +46,7 @@ struct labeller *text_labeller_create(const struct format_type *fmt);
|
||||
|
||||
int pvhdr_read(struct device *dev, char *buf);
|
||||
|
||||
int add_da(const struct format_type *fmt, struct dm_pool *mem, struct list *das,
|
||||
int add_da(struct dm_pool *mem, struct list *das,
|
||||
uint64_t start, uint64_t size);
|
||||
void del_das(struct list *das);
|
||||
|
||||
|
||||
@@ -129,6 +129,6 @@ struct volume_group *text_vg_import_file(struct format_instance *fid,
|
||||
const char *file,
|
||||
time_t *when, char **desc)
|
||||
{
|
||||
return text_vg_import_fd(fid, file, NULL, 0, 0, 0, 0, NULL, 0,
|
||||
return text_vg_import_fd(fid, file, NULL, (off_t)0, 0, (off_t)0, 0, NULL, 0,
|
||||
when, desc);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
static int _text_can_handle(struct labeller *l, char *buf, uint64_t sector)
|
||||
static int _text_can_handle(struct labeller *l __attribute((unused)),
|
||||
char *buf,
|
||||
uint64_t sector __attribute((unused)))
|
||||
{
|
||||
struct label_header *lh = (struct label_header *) buf;
|
||||
|
||||
@@ -86,7 +88,7 @@ static int _text_write(struct label *label, char *buf)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int add_da(const struct format_type *fmt, struct dm_pool *mem, struct list *das,
|
||||
int add_da(struct dm_pool *mem, struct list *das,
|
||||
uint64_t start, uint64_t size)
|
||||
{
|
||||
struct data_area_list *dal;
|
||||
@@ -179,7 +181,8 @@ void del_mdas(struct list *mdas)
|
||||
}
|
||||
}
|
||||
|
||||
static int _text_initialise_label(struct labeller *l, struct label *label)
|
||||
static int _text_initialise_label(struct labeller *l __attribute((unused)),
|
||||
struct label *label)
|
||||
{
|
||||
strncpy(label->type, LVM2_LABEL, sizeof(label->type));
|
||||
|
||||
@@ -220,7 +223,7 @@ static int _text_read(struct labeller *l, struct device *dev, char *buf,
|
||||
/* Data areas holding the PEs */
|
||||
dlocn_xl = pvhdr->disk_areas_xl;
|
||||
while ((offset = xlate64(dlocn_xl->offset))) {
|
||||
add_da(info->fmt, NULL, &info->das, offset,
|
||||
add_da(NULL, &info->das, offset,
|
||||
xlate64(dlocn_xl->size));
|
||||
dlocn_xl++;
|
||||
}
|
||||
@@ -248,7 +251,8 @@ static int _text_read(struct labeller *l, struct device *dev, char *buf,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void _text_destroy_label(struct labeller *l, struct label *label)
|
||||
static void _text_destroy_label(struct labeller *l __attribute((unused)),
|
||||
struct label *label)
|
||||
{
|
||||
struct lvmcache_info *info = (struct lvmcache_info *) label->info;
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ int label_read(struct device *dev, struct label **result)
|
||||
lvmcache_update_vgname_and_id(info, ORPHAN, ORPHAN,
|
||||
0, NULL);
|
||||
|
||||
goto out;
|
||||
return r;
|
||||
}
|
||||
|
||||
if (!(l = _find_labeller(dev, buf, §or)))
|
||||
|
||||
@@ -256,7 +256,7 @@ static int _cluster_request(char cmd, const char *node, void *data, int len,
|
||||
strcpy(rarray[i].node, inptr);
|
||||
inptr += strlen(inptr) + 1;
|
||||
|
||||
rarray[i].status = *(int *) inptr;
|
||||
memcpy(&rarray[i].status, inptr, sizeof(int));
|
||||
inptr += sizeof(int);
|
||||
|
||||
rarray[i].response = dm_malloc(strlen(inptr) + 1);
|
||||
@@ -333,6 +333,12 @@ static int _lock_for_cluster(unsigned char cmd, unsigned int flags, char *name)
|
||||
if (partial_mode())
|
||||
args[1] |= LCK_PARTIAL_MODE;
|
||||
|
||||
if (mirror_in_sync())
|
||||
args[1] |= LCK_MIRROR_NOSYNC_MODE;
|
||||
|
||||
if (dmeventd_register_mode())
|
||||
args[1] |= LCK_DMEVENTD_REGISTER_MODE;
|
||||
|
||||
/*
|
||||
* VG locks are just that: locks, and have no side effects
|
||||
* so we only need to do them on the local node because all
|
||||
@@ -446,7 +452,7 @@ void reset_locking(void)
|
||||
}
|
||||
|
||||
#ifdef CLUSTER_LOCKING_INTERNAL
|
||||
int init_cluster_locking(struct locking_type *locking, struct config_tree *cft)
|
||||
int init_cluster_locking(struct locking_type *locking, struct cmd_context *cmd)
|
||||
{
|
||||
locking->lock_resource = _lock_resource;
|
||||
locking->fin_locking = _locking_end;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "locking_types.h"
|
||||
#include "defaults.h"
|
||||
#include "sharedlib.h"
|
||||
#include "toolcontext.h"
|
||||
|
||||
static void *_locking_lib = NULL;
|
||||
static void (*_reset_fn) (void) = NULL;
|
||||
@@ -55,7 +56,7 @@ static void _reset_external_locking(void)
|
||||
_reset_fn();
|
||||
}
|
||||
|
||||
int init_external_locking(struct locking_type *locking, struct config_tree *cft)
|
||||
int init_external_locking(struct locking_type *locking, struct cmd_context *cmd)
|
||||
{
|
||||
const char *libname;
|
||||
|
||||
@@ -69,10 +70,10 @@ int init_external_locking(struct locking_type *locking, struct config_tree *cft)
|
||||
locking->reset_locking = _reset_external_locking;
|
||||
locking->flags = 0;
|
||||
|
||||
libname = find_config_str(cft->root, "global/locking_library",
|
||||
DEFAULT_LOCKING_LIB);
|
||||
libname = find_config_tree_str(cmd, "global/locking_library",
|
||||
DEFAULT_LOCKING_LIB);
|
||||
|
||||
if (!(_locking_lib = load_shared_library(cft, libname, "locking", 1))) {
|
||||
if (!(_locking_lib = load_shared_library(cmd, libname, "locking", 1))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
@@ -90,5 +91,5 @@ int init_external_locking(struct locking_type *locking, struct config_tree *cft)
|
||||
}
|
||||
|
||||
log_verbose("Loaded external locking library %s", libname);
|
||||
return _init_fn(2, cft, &locking->flags);
|
||||
return _init_fn(2, cmd->cft, &locking->flags);
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ static void _remove_ctrl_c_handler()
|
||||
log_sys_error("signal", "_remove_ctrl_c_handler");
|
||||
}
|
||||
|
||||
static void _trap_ctrl_c(int sig)
|
||||
static void _trap_ctrl_c(int sig __attribute((unused)))
|
||||
{
|
||||
_remove_ctrl_c_handler();
|
||||
log_error("CTRL-c detected: giving up waiting for lock");
|
||||
@@ -271,7 +271,7 @@ static int _file_lock_resource(struct cmd_context *cmd, const char *resource,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int init_file_locking(struct locking_type *locking, struct config_tree *cft)
|
||||
int init_file_locking(struct locking_type *locking, struct cmd_context *cmd)
|
||||
{
|
||||
locking->lock_resource = _file_lock_resource;
|
||||
locking->reset_locking = _reset_file_locking;
|
||||
@@ -279,8 +279,8 @@ int init_file_locking(struct locking_type *locking, struct config_tree *cft)
|
||||
locking->flags = 0;
|
||||
|
||||
/* Get lockfile directory from config file */
|
||||
strncpy(_lock_dir, find_config_str(cft->root, "global/locking_dir",
|
||||
DEFAULT_LOCK_DIR),
|
||||
strncpy(_lock_dir, find_config_tree_str(cmd, "global/locking_dir",
|
||||
DEFAULT_LOCK_DIR),
|
||||
sizeof(_lock_dir));
|
||||
|
||||
if (!create_dir(_lock_dir))
|
||||
|
||||
@@ -33,7 +33,7 @@ static int _vg_lock_count = 0; /* Number of locks held */
|
||||
static int _vg_write_lock_held = 0; /* VG write lock held? */
|
||||
static int _signals_blocked = 0;
|
||||
|
||||
static void _block_signals(int flags)
|
||||
static void _block_signals(int flags __attribute((unused)))
|
||||
{
|
||||
sigset_t set;
|
||||
|
||||
@@ -122,26 +122,26 @@ static void _update_vg_lock_count(int flags)
|
||||
/*
|
||||
* Select a locking type
|
||||
*/
|
||||
int init_locking(int type, struct config_tree *cft)
|
||||
int init_locking(int type, struct cmd_context *cmd)
|
||||
{
|
||||
init_lockingfailed(0);
|
||||
|
||||
switch (type) {
|
||||
case 0:
|
||||
init_no_locking(&_locking, cft);
|
||||
init_no_locking(&_locking, cmd);
|
||||
log_print("WARNING: Locking disabled. Be careful! "
|
||||
"This could corrupt your metadata.");
|
||||
return 1;
|
||||
|
||||
case 1:
|
||||
if (!init_file_locking(&_locking, cft))
|
||||
if (!init_file_locking(&_locking, cmd))
|
||||
break;
|
||||
log_very_verbose("File-based locking enabled.");
|
||||
return 1;
|
||||
|
||||
#ifdef HAVE_LIBDL
|
||||
case 2:
|
||||
if (!init_external_locking(&_locking, cft))
|
||||
if (!init_external_locking(&_locking, cmd))
|
||||
break;
|
||||
log_very_verbose("External locking enabled.");
|
||||
return 1;
|
||||
@@ -149,7 +149,7 @@ int init_locking(int type, struct config_tree *cft)
|
||||
|
||||
#ifdef CLUSTER_LOCKING_INTERNAL
|
||||
case 3:
|
||||
if (!init_cluster_locking(&_locking, cft))
|
||||
if (!init_cluster_locking(&_locking, cmd))
|
||||
break;
|
||||
log_very_verbose("Cluster locking enabled.");
|
||||
return 1;
|
||||
@@ -166,7 +166,7 @@ int init_locking(int type, struct config_tree *cft)
|
||||
/* FIXME Ensure only read ops are permitted */
|
||||
log_verbose("Locking disabled - only read operations permitted.");
|
||||
|
||||
init_no_locking(&_locking, cft);
|
||||
init_no_locking(&_locking, cmd);
|
||||
init_lockingfailed(1);
|
||||
|
||||
return 1;
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "uuid.h"
|
||||
#include "config.h"
|
||||
|
||||
int init_locking(int type, struct config_tree *cf);
|
||||
int init_locking(int type, struct cmd_context *cmd);
|
||||
void fin_locking(void);
|
||||
void reset_locking(void);
|
||||
int vg_write_lock_held(void);
|
||||
@@ -74,6 +74,9 @@ int check_lvm1_vg_inactive(struct cmd_context *cmd, const char *vgname);
|
||||
* Additional lock bits for cluster communication
|
||||
*/
|
||||
#define LCK_PARTIAL_MODE 0x00000001 /* Running in partial mode */
|
||||
#define LCK_MIRROR_NOSYNC_MODE 0x00000002 /* Mirrors don't require sync */
|
||||
#define LCK_DMEVENTD_REGISTER_MODE 0x00000004 /* Register with dmeventd */
|
||||
|
||||
|
||||
/*
|
||||
* Common combinations
|
||||
|
||||
@@ -36,10 +36,10 @@ struct locking_type {
|
||||
/*
|
||||
* Locking types
|
||||
*/
|
||||
int init_no_locking(struct locking_type *locking, struct config_tree *cf);
|
||||
int init_no_locking(struct locking_type *locking, struct cmd_context *cmd);
|
||||
|
||||
int init_file_locking(struct locking_type *locking, struct config_tree *cf);
|
||||
int init_file_locking(struct locking_type *locking, struct cmd_context *cmd);
|
||||
|
||||
int init_external_locking(struct locking_type *locking, struct config_tree *cf);
|
||||
int init_external_locking(struct locking_type *locking, struct cmd_context *cmd);
|
||||
|
||||
int init_cluster_locking(struct locking_type *locking, struct config_tree *cf);
|
||||
int init_cluster_locking(struct locking_type *locking, struct cmd_context *cmd);
|
||||
|
||||
@@ -76,7 +76,7 @@ static int _no_lock_resource(struct cmd_context *cmd, const char *resource,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int init_no_locking(struct locking_type *locking, struct config_tree *cft)
|
||||
int init_no_locking(struct locking_type *locking, struct cmd_context *cmd)
|
||||
{
|
||||
locking->lock_resource = _no_lock_resource;
|
||||
locking->reset_locking = _no_reset_locking;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "device.h"
|
||||
#include "memlock.h"
|
||||
#include "lvm-string.h"
|
||||
#include "defaults.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <syslog.h>
|
||||
@@ -31,6 +32,7 @@ static int _partial = 0;
|
||||
static int _md_filtering = 0;
|
||||
static int _pvmove = 0;
|
||||
static int _full_scan_done = 0; /* Restrict to one full scan during each cmd */
|
||||
static int _trust_cache = 0; /* Don't scan when incomplete VGs encountered */
|
||||
static int _debug_level = 0;
|
||||
static int _syslog = 0;
|
||||
static int _log_to_file = 0;
|
||||
@@ -45,6 +47,8 @@ static int _security_level = SECURITY_LEVEL;
|
||||
static char _cmd_name[30] = "";
|
||||
static char _msg_prefix[30] = " ";
|
||||
static int _already_logging = 0;
|
||||
static int _mirror_in_sync = 0;
|
||||
static int _dmeventd_register = DEFAULT_DMEVENTD_MONITOR;
|
||||
|
||||
static lvm2_log_fn_t _lvm2_log_fn = NULL;
|
||||
|
||||
@@ -160,6 +164,11 @@ void init_full_scan_done(int level)
|
||||
_full_scan_done = level;
|
||||
}
|
||||
|
||||
void init_trust_cache(int trustcache)
|
||||
{
|
||||
_trust_cache = trustcache;
|
||||
}
|
||||
|
||||
void init_ignorelockingfailure(int level)
|
||||
{
|
||||
_ignorelockingfailure = level;
|
||||
@@ -175,6 +184,16 @@ void init_security_level(int level)
|
||||
_security_level = level;
|
||||
}
|
||||
|
||||
void init_mirror_in_sync(int in_sync)
|
||||
{
|
||||
_mirror_in_sync = in_sync;
|
||||
}
|
||||
|
||||
void init_dmeventd_register(int reg)
|
||||
{
|
||||
_dmeventd_register = reg;
|
||||
}
|
||||
|
||||
void init_cmd_name(int status)
|
||||
{
|
||||
_log_cmd_name = status;
|
||||
@@ -224,6 +243,11 @@ int full_scan_done()
|
||||
return _full_scan_done;
|
||||
}
|
||||
|
||||
int trust_cache()
|
||||
{
|
||||
return _trust_cache;
|
||||
}
|
||||
|
||||
int lockingfailed()
|
||||
{
|
||||
return _lockingfailed;
|
||||
@@ -239,6 +263,16 @@ int security_level()
|
||||
return _security_level;
|
||||
}
|
||||
|
||||
int mirror_in_sync(void)
|
||||
{
|
||||
return _mirror_in_sync;
|
||||
}
|
||||
|
||||
int dmeventd_register_mode(void)
|
||||
{
|
||||
return _dmeventd_register;
|
||||
}
|
||||
|
||||
void init_debug(int level)
|
||||
{
|
||||
_debug_level = level;
|
||||
|
||||
@@ -66,6 +66,7 @@ void init_partial(int level);
|
||||
void init_md_filtering(int level);
|
||||
void init_pvmove(int level);
|
||||
void init_full_scan_done(int level);
|
||||
void init_trust_cache(int trustcache);
|
||||
void init_debug(int level);
|
||||
void init_cmd_name(int status);
|
||||
void init_msg_prefix(const char *prefix);
|
||||
@@ -73,6 +74,8 @@ void init_indent(int indent);
|
||||
void init_ignorelockingfailure(int level);
|
||||
void init_lockingfailed(int level);
|
||||
void init_security_level(int level);
|
||||
void init_mirror_in_sync(int in_sync);
|
||||
void init_dmeventd_register(int reg);
|
||||
|
||||
void set_cmd_name(const char *cmd_name);
|
||||
|
||||
@@ -81,10 +84,13 @@ int partial_mode(void);
|
||||
int md_filtering(void);
|
||||
int pvmove_mode(void);
|
||||
int full_scan_done(void);
|
||||
int trust_cache(void);
|
||||
int debug_level(void);
|
||||
int ignorelockingfailure(void);
|
||||
int lockingfailed(void);
|
||||
int security_level(void);
|
||||
int mirror_in_sync(void);
|
||||
int dmeventd_register_mode(void);
|
||||
|
||||
/* Suppress messages to stdout/stderr (1) or everywhere (2) */
|
||||
/* Returns previous setting */
|
||||
|
||||
@@ -498,7 +498,7 @@ static int _setup_alloced_segment(struct logical_volume *lv, uint32_t status,
|
||||
struct physical_volume *mirrored_pv,
|
||||
uint32_t mirrored_pe,
|
||||
uint32_t region_size,
|
||||
struct logical_volume *log_lv)
|
||||
struct logical_volume *log_lv __attribute((unused)))
|
||||
{
|
||||
uint32_t s, extents, area_multiple, extra_areas = 0;
|
||||
struct lv_segment *seg;
|
||||
@@ -1102,7 +1102,7 @@ int lv_add_mirror_segment(struct alloc_handle *ah,
|
||||
struct lv_segment *seg;
|
||||
uint32_t m;
|
||||
|
||||
if (list_empty(&log_lv->segments)) {
|
||||
if (log_lv && list_empty(&log_lv->segments)) {
|
||||
log_error("Log LV %s is empty.", log_lv->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ static int _add_pv_to_vg(struct format_instance *fid, struct volume_group *vg,
|
||||
}
|
||||
|
||||
/* Ensure PV doesn't depend on another PV already in the VG */
|
||||
if (pv_uses_vg(fid->fmt->cmd, pv, vg)) {
|
||||
if (pv_uses_vg(pv, vg)) {
|
||||
log_error("Physical volume %s might be constructed from same "
|
||||
"volume group %s", pv_name, vg->name);
|
||||
return 0;
|
||||
@@ -722,23 +722,68 @@ int vg_remove(struct volume_group *vg)
|
||||
|
||||
int vg_validate(struct volume_group *vg)
|
||||
{
|
||||
struct lv_list *lvl;
|
||||
struct pv_list *pvl, *pvl2;
|
||||
struct lv_list *lvl, *lvl2;
|
||||
char uuid[64];
|
||||
int r = 1;
|
||||
|
||||
list_iterate_items(pvl, &vg->pvs) {
|
||||
list_iterate_items(pvl2, &vg->pvs) {
|
||||
if (pvl == pvl2)
|
||||
break;
|
||||
if (id_equal(&pvl->pv->id,
|
||||
&pvl2->pv->id)) {
|
||||
if (!id_write_format(&pvl->pv->id, uuid,
|
||||
sizeof(uuid)))
|
||||
stack;
|
||||
log_error("Internal error: Duplicate PV id "
|
||||
"%s detected for %s in %s.",
|
||||
uuid, dev_name(pvl->pv->dev),
|
||||
vg->name);
|
||||
r = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!check_pv_segments(vg)) {
|
||||
log_error("Internal error: PV segments corrupted in %s.",
|
||||
vg->name);
|
||||
return 0;
|
||||
r = 0;
|
||||
}
|
||||
|
||||
list_iterate_items(lvl, &vg->lvs) {
|
||||
list_iterate_items(lvl2, &vg->lvs) {
|
||||
if (lvl == lvl2)
|
||||
break;
|
||||
if (!strcmp(lvl->lv->name, lvl2->lv->name)) {
|
||||
log_error("Internal error: Duplicate LV name "
|
||||
"%s detected in %s.", lvl->lv->name,
|
||||
vg->name);
|
||||
r = 0;
|
||||
}
|
||||
if (id_equal(&lvl->lv->lvid.id[1],
|
||||
&lvl2->lv->lvid.id[1])) {
|
||||
if (!id_write_format(&lvl->lv->lvid.id[1], uuid,
|
||||
sizeof(uuid)))
|
||||
stack;
|
||||
log_error("Internal error: Duplicate LV id "
|
||||
"%s detected for %s and %s in %s.",
|
||||
uuid, lvl->lv->name, lvl2->lv->name,
|
||||
vg->name);
|
||||
r = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
list_iterate_items(lvl, &vg->lvs) {
|
||||
if (!check_lv_segments(lvl->lv, 1)) {
|
||||
log_error("Internal error: LV segments corrupted in %s.",
|
||||
lvl->lv->name);
|
||||
return 0;
|
||||
r = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -993,7 +1038,11 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
|
||||
if (list_size(&correct_vg->pvs) != list_size(pvids)) {
|
||||
log_debug("Cached VG %s had incorrect PV list",
|
||||
vg->name);
|
||||
correct_vg = NULL;
|
||||
|
||||
if (memlock())
|
||||
inconsistent = 1;
|
||||
else
|
||||
correct_vg = NULL;
|
||||
} else list_iterate_items(pvl, &correct_vg->pvs) {
|
||||
if (!str_list_match_item(pvids, pvl->pv->dev->pvid)) {
|
||||
log_debug("Cached VG %s had incorrect PV list",
|
||||
@@ -1008,6 +1057,10 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
|
||||
if (!correct_vg) {
|
||||
inconsistent = 0;
|
||||
|
||||
if (memlock()) {
|
||||
stack;
|
||||
return NULL;
|
||||
}
|
||||
lvmcache_label_scan(cmd, 2);
|
||||
if (!(fmt = fmt_from_vgname(vgname, vgid))) {
|
||||
stack;
|
||||
@@ -1149,7 +1202,8 @@ static struct volume_group *_vg_read_by_vgid(struct cmd_context *cmd,
|
||||
if (!consistent) {
|
||||
log_error("Volume group %s metadata is "
|
||||
"inconsistent", vginfo->vgname);
|
||||
return NULL;
|
||||
if (!partial_mode())
|
||||
return NULL;
|
||||
}
|
||||
return vg;
|
||||
}
|
||||
@@ -1342,7 +1396,7 @@ struct list *get_pvs(struct cmd_context *cmd)
|
||||
return results;
|
||||
}
|
||||
|
||||
int pv_write(struct cmd_context *cmd, struct physical_volume *pv,
|
||||
int pv_write(struct cmd_context *cmd __attribute((unused)), struct physical_volume *pv,
|
||||
struct list *mdas, int64_t label_sector)
|
||||
{
|
||||
if (!pv->fmt->ops->pv_write) {
|
||||
|
||||
@@ -58,8 +58,9 @@
|
||||
#define VIRTUAL 0x00010000U /* LV - internal use only */
|
||||
#define MIRROR_LOG 0x00020000U /* LV */
|
||||
#define MIRROR_IMAGE 0x00040000U /* LV */
|
||||
#define ACTIVATE_EXCL 0x00080000U /* LV - internal use only */
|
||||
#define PRECOMMITTED 0x00100000U /* VG - internal use only */
|
||||
#define MIRROR_NOTSYNCED 0x00080000U /* LV */
|
||||
#define ACTIVATE_EXCL 0x00100000U /* LV - internal use only */
|
||||
#define PRECOMMITTED 0x00200000U /* VG - internal use only */
|
||||
|
||||
#define LVM_READ 0x00000100U /* LV VG */
|
||||
#define LVM_WRITE 0x00000200U /* LV VG */
|
||||
@@ -580,6 +581,8 @@ int add_mirror_layers(struct alloc_handle *ah,
|
||||
|
||||
int remove_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
|
||||
struct list *removable_pvs, int remove_log);
|
||||
int reconfigure_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
|
||||
struct list *removable_pvs, int remove_log);
|
||||
/*
|
||||
* Given mirror image or mirror log segment, find corresponding mirror segment
|
||||
*/
|
||||
|
||||
@@ -23,6 +23,13 @@
|
||||
#include "lvm-string.h"
|
||||
#include "locking.h" /* FIXME Should not be used in this file */
|
||||
|
||||
#include "defaults.h" /* FIXME: should this be defaults.h? */
|
||||
|
||||
/* These are the flags that represent the mirror failure restoration policies */
|
||||
#define MIRROR_REMOVE 0
|
||||
#define MIRROR_ALLOCATE 1
|
||||
#define MIRROR_ALLOCATE_ANYWHERE 2
|
||||
|
||||
struct lv_segment *find_mirror_seg(struct lv_segment *seg)
|
||||
{
|
||||
return seg->mirror_seg;
|
||||
@@ -192,6 +199,12 @@ int remove_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
|
||||
|
||||
/* Delete the 'orphan' LVs */
|
||||
for (m = num_mirrors; m < old_area_count; m++) {
|
||||
/* LV is now independent of the mirror so must acquire lock. */
|
||||
if (!activate_lv(mirrored_seg->lv->vg->cmd, seg_lv(mirrored_seg, m))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!deactivate_lv(mirrored_seg->lv->vg->cmd, seg_lv(mirrored_seg, m))) {
|
||||
stack;
|
||||
return 0;
|
||||
@@ -204,6 +217,11 @@ int remove_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
|
||||
}
|
||||
|
||||
if (lv1) {
|
||||
if (!activate_lv(mirrored_seg->lv->vg->cmd, lv1)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!deactivate_lv(mirrored_seg->lv->vg->cmd, lv1)) {
|
||||
stack;
|
||||
return 0;
|
||||
@@ -216,6 +234,11 @@ int remove_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
|
||||
}
|
||||
|
||||
if (log_lv) {
|
||||
if (!activate_lv(mirrored_seg->lv->vg->cmd, log_lv)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!deactivate_lv(mirrored_seg->lv->vg->cmd, log_lv)) {
|
||||
stack;
|
||||
return 0;
|
||||
@@ -230,6 +253,163 @@ int remove_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int get_mirror_fault_policy(struct cmd_context *cmd, int log_policy)
|
||||
{
|
||||
const char *policy;
|
||||
|
||||
if (log_policy)
|
||||
policy = find_config_str(NULL, "activation/mirror_log_fault_policy",
|
||||
DEFAULT_MIRROR_LOG_FAULT_POLICY);
|
||||
else
|
||||
policy = find_config_str(NULL, "activation/mirror_device_fault_policy",
|
||||
DEFAULT_MIRROR_DEV_FAULT_POLICY);
|
||||
|
||||
if (!strcmp(policy, "remove"))
|
||||
return MIRROR_REMOVE;
|
||||
else if (!strcmp(policy, "allocate"))
|
||||
return MIRROR_ALLOCATE;
|
||||
else if (!strcmp(policy, "allocate_anywhere"))
|
||||
return MIRROR_ALLOCATE_ANYWHERE;
|
||||
|
||||
if (log_policy)
|
||||
log_error("Bad activation/mirror_log_fault_policy");
|
||||
else
|
||||
log_error("Bad activation/mirror_device_fault_policy");
|
||||
|
||||
return MIRROR_REMOVE;
|
||||
}
|
||||
|
||||
static int get_mirror_log_fault_policy(struct cmd_context *cmd)
|
||||
{
|
||||
return get_mirror_fault_policy(cmd, 1);
|
||||
}
|
||||
|
||||
static int get_mirror_device_fault_policy(struct cmd_context *cmd)
|
||||
{
|
||||
return get_mirror_fault_policy(cmd, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* replace_mirror_images
|
||||
* @mirrored_seg: segment (which may be linear now) to restore
|
||||
* @num_mirrors: number of copies we should end up with
|
||||
* @replace_log: replace log if not present
|
||||
* @in_sync: was the original mirror in-sync?
|
||||
*
|
||||
* in_sync will be set to 0 if new mirror devices are being added
|
||||
* In other words, it is only useful if the log (and only the log)
|
||||
* is being restored.
|
||||
*
|
||||
* Returns: 0 on failure, 1 on reconfig, -1 if no reconfig done
|
||||
*/
|
||||
static int replace_mirror_images(struct lv_segment *mirrored_seg,
|
||||
uint32_t num_mirrors,
|
||||
int log_policy, int in_sync)
|
||||
{
|
||||
int r = -1;
|
||||
struct logical_volume *lv = mirrored_seg->lv;
|
||||
|
||||
/* FIXME: Use lvconvert rather than duplicating its code */
|
||||
|
||||
if (mirrored_seg->area_count < num_mirrors) {
|
||||
log_error("WARNING: Failed to replace mirror device in %s/%s",
|
||||
mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
|
||||
|
||||
if ((mirrored_seg->area_count > 1) && !mirrored_seg->log_lv)
|
||||
log_error("WARNING: Use 'lvconvert -m %d %s/%s --corelog' to replace failed devices",
|
||||
num_mirrors - 1, lv->vg->name, lv->name);
|
||||
else
|
||||
log_error("WARNING: Use 'lvconvert -m %d %s/%s' to replace failed devices",
|
||||
num_mirrors - 1, lv->vg->name, lv->name);
|
||||
r = 0;
|
||||
|
||||
/* REMEMBER/FIXME: set in_sync to 0 if a new mirror device was added */
|
||||
in_sync = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* FIXME: right now, we ignore the allocation policy specified to
|
||||
* allocate the new log.
|
||||
*/
|
||||
if ((mirrored_seg->area_count > 1) && !mirrored_seg->log_lv &&
|
||||
(log_policy != MIRROR_REMOVE)) {
|
||||
log_error("WARNING: Failed to replace mirror log device in %s/%s",
|
||||
lv->vg->name, lv->name);
|
||||
|
||||
log_error("WARNING: Use 'lvconvert -m %d %s/%s' to replace failed devices",
|
||||
mirrored_seg->area_count - 1 , lv->vg->name, lv->name);
|
||||
r = 0;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
int reconfigure_mirror_images(struct lv_segment *mirrored_seg, uint32_t num_mirrors,
|
||||
struct list *removable_pvs, int remove_log)
|
||||
{
|
||||
int r;
|
||||
int insync = 0;
|
||||
int log_policy, dev_policy;
|
||||
uint32_t old_num_mirrors = mirrored_seg->area_count;
|
||||
int had_log = (mirrored_seg->log_lv) ? 1 : 0;
|
||||
float sync_percent = 0;
|
||||
|
||||
/* was the mirror in-sync before problems? */
|
||||
if (!lv_mirror_percent(mirrored_seg->lv->vg->cmd,
|
||||
mirrored_seg->lv, 0, &sync_percent, NULL))
|
||||
log_error("WARNING: Unable to determine mirror sync status of %s/%s.",
|
||||
mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
|
||||
else if (sync_percent >= 100.0)
|
||||
insync = 1;
|
||||
|
||||
/*
|
||||
* While we are only removing devices, we can have sync set.
|
||||
* Setting this is only useful if we are moving to core log
|
||||
* otherwise the disk log will contain the sync information
|
||||
*/
|
||||
init_mirror_in_sync(insync);
|
||||
|
||||
r = remove_mirror_images(mirrored_seg, num_mirrors,
|
||||
removable_pvs, remove_log);
|
||||
if (!r)
|
||||
/* Unable to remove bad devices */
|
||||
return 0;
|
||||
|
||||
log_print("WARNING: Bad device removed from mirror volume, %s/%s",
|
||||
mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
|
||||
|
||||
log_policy = get_mirror_log_fault_policy(mirrored_seg->lv->vg->cmd);
|
||||
dev_policy = get_mirror_device_fault_policy(mirrored_seg->lv->vg->cmd);
|
||||
|
||||
r = replace_mirror_images(mirrored_seg,
|
||||
(dev_policy != MIRROR_REMOVE) ?
|
||||
old_num_mirrors : num_mirrors,
|
||||
log_policy, insync);
|
||||
|
||||
if (!r)
|
||||
/* Failed to replace device(s) */
|
||||
log_error("WARNING: Unable to find substitute device for mirror volume, %s/%s",
|
||||
mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
|
||||
else if (r > 0)
|
||||
/* Success in replacing device(s) */
|
||||
log_print("WARNING: Mirror volume, %s/%s restored - substitute for failed device found.",
|
||||
mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
|
||||
else
|
||||
/* Bad device removed, but not replaced because of policy */
|
||||
if (mirrored_seg->area_count == 1) {
|
||||
log_print("WARNING: Mirror volume, %s/%s converted to linear due to device failure.",
|
||||
mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
|
||||
} else if (had_log && !mirrored_seg->log_lv) {
|
||||
log_print("WARNING: Mirror volume, %s/%s disk log removed due to device failure.",
|
||||
mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
|
||||
}
|
||||
/*
|
||||
* If we made it here, we at least removed the bad device.
|
||||
* Consider this success.
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _create_layers_for_mirror(struct alloc_handle *ah,
|
||||
uint32_t first_area,
|
||||
uint32_t num_mirrors,
|
||||
|
||||
@@ -67,23 +67,19 @@ struct segtype_handler {
|
||||
int (*merge_segments) (struct lv_segment * seg1,
|
||||
struct lv_segment * seg2);
|
||||
int (*add_target_line) (struct dev_manager *dm, struct dm_pool *mem,
|
||||
struct config_tree *cft, void **target_state,
|
||||
struct cmd_context *cmd, void **target_state,
|
||||
struct lv_segment *seg,
|
||||
struct dm_tree_node *node, uint64_t len,
|
||||
uint32_t *pvmove_mirror_count);
|
||||
int (*target_percent) (void **target_state, struct dm_pool * mem,
|
||||
struct config_tree * cft,
|
||||
struct lv_segment * seg, char *params,
|
||||
struct cmd_context *cmd,
|
||||
struct lv_segment *seg, char *params,
|
||||
uint64_t *total_numerator,
|
||||
uint64_t *total_denominator, float *percent);
|
||||
int (*target_present) (void);
|
||||
void (*destroy) (const struct segment_type * segtype);
|
||||
int (*target_register_events) (struct dm_pool *mem,
|
||||
struct lv_segment *seg,
|
||||
struct config_tree *cft, int events);
|
||||
int (*target_unregister_events) (struct dm_pool *mem,
|
||||
struct lv_segment *seg,
|
||||
struct config_tree *cft, int events);
|
||||
int (*target_register_events) (struct lv_segment *seg, int events);
|
||||
int (*target_unregister_events) (struct lv_segment *seg, int events);
|
||||
};
|
||||
|
||||
struct segment_type *get_segtype_from_string(struct cmd_context *cmd,
|
||||
|
||||
@@ -154,7 +154,7 @@ static int _mirrored_text_export(const struct lv_segment *seg, struct formatter
|
||||
|
||||
#ifdef DEVMAPPER_SUPPORT
|
||||
static struct mirror_state *_mirrored_init_target(struct dm_pool *mem,
|
||||
struct config_tree *cft)
|
||||
struct cmd_context *cmd)
|
||||
{
|
||||
struct mirror_state *mirr_state;
|
||||
|
||||
@@ -164,7 +164,7 @@ static struct mirror_state *_mirrored_init_target(struct dm_pool *mem,
|
||||
}
|
||||
|
||||
mirr_state->default_region_size = 2 *
|
||||
find_config_int(cft->root,
|
||||
find_config_tree_int(cmd,
|
||||
"activation/mirror_region_size",
|
||||
DEFAULT_MIRROR_REGION_SIZE);
|
||||
|
||||
@@ -172,9 +172,10 @@ static struct mirror_state *_mirrored_init_target(struct dm_pool *mem,
|
||||
}
|
||||
|
||||
static int _mirrored_target_percent(void **target_state, struct dm_pool *mem,
|
||||
struct config_tree *cft, struct lv_segment *seg,
|
||||
struct cmd_context *cmd, struct lv_segment *seg,
|
||||
char *params, uint64_t *total_numerator,
|
||||
uint64_t *total_denominator, float *percent)
|
||||
uint64_t *total_denominator,
|
||||
float *percent __attribute((unused)))
|
||||
{
|
||||
struct mirror_state *mirr_state;
|
||||
uint64_t numerator, denominator;
|
||||
@@ -183,7 +184,7 @@ static int _mirrored_target_percent(void **target_state, struct dm_pool *mem,
|
||||
char *pos = params;
|
||||
|
||||
if (!*target_state)
|
||||
*target_state = _mirrored_init_target(mem, cft);
|
||||
*target_state = _mirrored_init_target(mem, cmd);
|
||||
|
||||
mirr_state = *target_state;
|
||||
|
||||
@@ -237,13 +238,26 @@ static int _add_log(struct dev_manager *dm, struct lv_segment *seg,
|
||||
(seg->lv->vg->status & CLUSTERED)))
|
||||
clustered = 1;
|
||||
|
||||
if (seg->log_lv &&
|
||||
!(log_dlid = build_dlid(dm, seg->log_lv->lvid.s, NULL))) {
|
||||
log_error("Failed to build uuid for log LV %s.",
|
||||
seg->log_lv->name);
|
||||
return 0;
|
||||
if (seg->log_lv) {
|
||||
/* If disk log, use its UUID */
|
||||
if (!(log_dlid = build_dlid(dm, seg->log_lv->lvid.s, NULL))) {
|
||||
log_error("Failed to build uuid for log LV %s.",
|
||||
seg->log_lv->name);
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
/* If core log, use mirror's UUID and set DM_CORELOG flag */
|
||||
if (!(log_dlid = build_dlid(dm, seg->lv->lvid.s, NULL))) {
|
||||
log_error("Failed to build uuid for mirror LV %s.",
|
||||
seg->lv->name);
|
||||
return 0;
|
||||
}
|
||||
log_flags |= DM_CORELOG;
|
||||
}
|
||||
|
||||
if (mirror_in_sync() && !(seg->status & PVMOVE))
|
||||
log_flags |= DM_NOSYNC;
|
||||
|
||||
if (_block_on_error_available && !(seg->status & PVMOVE))
|
||||
log_flags |= DM_BLOCK_ON_ERROR;
|
||||
|
||||
@@ -251,7 +265,7 @@ static int _add_log(struct dev_manager *dm, struct lv_segment *seg,
|
||||
}
|
||||
|
||||
static int _mirrored_add_target_line(struct dev_manager *dm, struct dm_pool *mem,
|
||||
struct config_tree *cft, void **target_state,
|
||||
struct cmd_context *cmd, void **target_state,
|
||||
struct lv_segment *seg,
|
||||
struct dm_tree_node *node, uint64_t len,
|
||||
uint32_t *pvmove_mirror_count)
|
||||
@@ -264,7 +278,7 @@ static int _mirrored_add_target_line(struct dev_manager *dm, struct dm_pool *mem
|
||||
int r;
|
||||
|
||||
if (!*target_state)
|
||||
*target_state = _mirrored_init_target(mem, cft);
|
||||
*target_state = _mirrored_init_target(mem, cmd);
|
||||
|
||||
mirr_state = *target_state;
|
||||
|
||||
@@ -353,7 +367,7 @@ static int _mirrored_target_present(void)
|
||||
}
|
||||
|
||||
#ifdef DMEVENTD
|
||||
static int _setup_registration(struct dm_pool *mem, struct config_tree *cft,
|
||||
static int _setup_registration(struct dm_pool *mem, struct cmd_context *cmd,
|
||||
char **dso)
|
||||
{
|
||||
char *path;
|
||||
@@ -364,10 +378,10 @@ static int _setup_registration(struct dm_pool *mem, struct config_tree *cft,
|
||||
return 0;
|
||||
}
|
||||
|
||||
libpath = find_config_str(cft->root, "dmeventd/mirror_library",
|
||||
DEFAULT_DMEVENTD_MIRROR_LIB);
|
||||
libpath = find_config_tree_str(cmd, "dmeventd/mirror_library",
|
||||
DEFAULT_DMEVENTD_MIRROR_LIB);
|
||||
|
||||
get_shared_library_path(cft, libpath, path, PATH_MAX);
|
||||
get_shared_library_path(cmd, libpath, path, PATH_MAX);
|
||||
|
||||
*dso = path;
|
||||
|
||||
@@ -376,9 +390,8 @@ static int _setup_registration(struct dm_pool *mem, struct config_tree *cft,
|
||||
|
||||
/* FIXME This gets run while suspended and performs banned operations. */
|
||||
/* FIXME Merge these two functions */
|
||||
static int _target_register_events(struct dm_pool *mem,
|
||||
struct lv_segment *seg,
|
||||
struct config_tree *cft, int events)
|
||||
static int _target_register_events(struct lv_segment *seg,
|
||||
int events)
|
||||
{
|
||||
char *dso, *name;
|
||||
struct logical_volume *lv;
|
||||
@@ -387,12 +400,12 @@ static int _target_register_events(struct dm_pool *mem,
|
||||
lv = seg->lv;
|
||||
vg = lv->vg;
|
||||
|
||||
if (!_setup_registration(mem, cft, &dso)) {
|
||||
if (!_setup_registration(vg->cmd->mem, vg->cmd, &dso)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(name = build_dm_name(mem, vg->name, lv->name, NULL)))
|
||||
if (!(name = build_dm_name(vg->cmd->mem, vg->name, lv->name, NULL)))
|
||||
return_0;
|
||||
|
||||
/* FIXME Save a returned handle here so we can unregister it later */
|
||||
@@ -404,9 +417,8 @@ static int _target_register_events(struct dm_pool *mem,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _target_unregister_events(struct dm_pool *mem,
|
||||
struct lv_segment *seg,
|
||||
struct config_tree *cft, int events)
|
||||
static int _target_unregister_events(struct lv_segment *seg,
|
||||
int events)
|
||||
{
|
||||
char *dso;
|
||||
char *name;
|
||||
@@ -417,10 +429,10 @@ static int _target_unregister_events(struct dm_pool *mem,
|
||||
vg = lv->vg;
|
||||
|
||||
/* FIXME Remove this and use handle to avoid config file race */
|
||||
if (!_setup_registration(mem, cft, &dso))
|
||||
if (!_setup_registration(vg->cmd->mem, vg->cmd, &dso))
|
||||
return_0;
|
||||
|
||||
if (!(name = build_dm_name(mem, vg->name, lv->name, NULL)))
|
||||
if (!(name = build_dm_name(vg->cmd->mem, vg->name, lv->name, NULL)))
|
||||
return_0;
|
||||
|
||||
/* FIXME Use handle returned by registration function instead of dso */
|
||||
|
||||
@@ -1,430 +0,0 @@
|
||||
/* lib/misc/configure.h. Generated by configure. */
|
||||
/* lib/misc/configure.h.in. Generated from configure.in by autoheader. */
|
||||
|
||||
/* Define to 1 if the `closedir' function returns void instead of `int'. */
|
||||
/* #undef CLOSEDIR_VOID */
|
||||
|
||||
/* Define to 1 to include built-in support for clustered LVM locking. */
|
||||
/* #undef CLUSTER_LOCKING_INTERNAL */
|
||||
|
||||
/* Define to 1 to build the shared command library. */
|
||||
/* #undef CMDLIB */
|
||||
|
||||
/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
|
||||
systems. This function is required for `alloca.c' support on those systems.
|
||||
*/
|
||||
/* #undef CRAY_STACKSEG_END */
|
||||
|
||||
/* Define to 1 if using `alloca.c'. */
|
||||
/* #undef C_ALLOCA */
|
||||
|
||||
/* Define to 1 to enable device-mapper interaction. */
|
||||
#define DEVMAPPER_SUPPORT 1
|
||||
|
||||
/* Define to 1 to enable the device-mapper event daemon. */
|
||||
/* #undef DMEVENTD */
|
||||
|
||||
/* Define to 1 if you have `alloca', as a function or macro. */
|
||||
#define HAVE_ALLOCA 1
|
||||
|
||||
/* Define to 1 if you have <alloca.h> and it should be used (not on Ultrix).
|
||||
*/
|
||||
#define HAVE_ALLOCA_H 1
|
||||
|
||||
/* Define to 1 if you have the <asm/byteorder.h> header file. */
|
||||
/* #undef HAVE_ASM_BYTEORDER_H */
|
||||
|
||||
/* Define to 1 if you have the <assert.h> header file. */
|
||||
#define HAVE_ASSERT_H 1
|
||||
|
||||
/* Define to 1 if you have the <ctype.h> header file. */
|
||||
#define HAVE_CTYPE_H 1
|
||||
|
||||
/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#define HAVE_DIRENT_H 1
|
||||
|
||||
/* Define to 1 if you have the <dlfcn.h> header file. */
|
||||
#define HAVE_DLFCN_H 1
|
||||
|
||||
/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
|
||||
/* #undef HAVE_DOPRNT */
|
||||
|
||||
/* Define to 1 if you have the `dup2' function. */
|
||||
/* #undef HAVE_DUP2 */
|
||||
|
||||
/* Define to 1 if you have the <fcntl.h> header file. */
|
||||
#define HAVE_FCNTL_H 1
|
||||
|
||||
/* Define to 1 if you have the `fork' function. */
|
||||
#define HAVE_FORK 1
|
||||
|
||||
/* Define to 1 if you have the <fstab.h> header file. */
|
||||
/* #undef HAVE_FSTAB_H */
|
||||
|
||||
/* Define to 1 if you have the `gethostname' function. */
|
||||
#define HAVE_GETHOSTNAME 1
|
||||
|
||||
/* Define to 1 if you have the `getmntent' function. */
|
||||
/* #undef HAVE_GETMNTENT */
|
||||
|
||||
/* Define to 1 to if getopt_long is available. */
|
||||
#define HAVE_GETOPTLONG 1
|
||||
|
||||
/* Define to 1 if you have the <getopt.h> header file. */
|
||||
#define HAVE_GETOPT_H 1
|
||||
|
||||
/* Define to 1 if you have the `getpagesize' function. */
|
||||
#define HAVE_GETPAGESIZE 1
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#define HAVE_INTTYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <libdevmapper.h> header file. */
|
||||
#define HAVE_LIBDEVMAPPER_H 1
|
||||
|
||||
/* Define to 1 if dynamic libraries are available. */
|
||||
#define HAVE_LIBDL 1
|
||||
|
||||
/* Define to 1 if you have the <libgen.h> header file. */
|
||||
#define HAVE_LIBGEN_H 1
|
||||
|
||||
/* Define to 1 if you have the <libintl.h> header file. */
|
||||
/* #undef HAVE_LIBINTL_H */
|
||||
|
||||
/* Define to 1 if you have the `readline' library (-lreadline). */
|
||||
/* #undef HAVE_LIBREADLINE */
|
||||
|
||||
/* Define to 1 if you have the <limits.h> header file. */
|
||||
#define HAVE_LIMITS_H 1
|
||||
|
||||
/* Define to 1 if you have the <linux/fs.h> header file. */
|
||||
/* #undef HAVE_LINUX_FS_H */
|
||||
|
||||
/* Define to 1 if you have the <locale.h> header file. */
|
||||
#define HAVE_LOCALE_H 1
|
||||
|
||||
/* Define to 1 if `lstat' has the bug that it succeeds when given the
|
||||
zero-length file name argument. */
|
||||
/* #undef HAVE_LSTAT_EMPTY_STRING_BUG */
|
||||
|
||||
/* Define to 1 if you have the <machine/endian.h> header file. */
|
||||
#define HAVE_MACHINE_ENDIAN_H 1
|
||||
|
||||
/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
|
||||
to 0 otherwise. */
|
||||
#define HAVE_MALLOC 1
|
||||
|
||||
/* Define to 1 if you have the <malloc.h> header file. */
|
||||
/* #undef HAVE_MALLOC_H */
|
||||
|
||||
/* Define to 1 if you have the `memmove' function. */
|
||||
/* #undef HAVE_MEMMOVE */
|
||||
|
||||
/* Define to 1 if you have the <memory.h> header file. */
|
||||
#define HAVE_MEMORY_H 1
|
||||
|
||||
/* Define to 1 if you have the `memset' function. */
|
||||
#define HAVE_MEMSET 1
|
||||
|
||||
/* Define to 1 if you have the `mkdir' function. */
|
||||
#define HAVE_MKDIR 1
|
||||
|
||||
/* Define to 1 if you have a working `mmap' system call. */
|
||||
#define HAVE_MMAP 1
|
||||
|
||||
/* Define to 1 if you have the <mntent.h> header file. */
|
||||
/* #undef HAVE_MNTENT_H */
|
||||
|
||||
/* Define to 1 if you have the `munmap' function. */
|
||||
#define HAVE_MUNMAP 1
|
||||
|
||||
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
|
||||
/* #undef HAVE_NDIR_H */
|
||||
|
||||
/* Define to 1 if you have the <netdb.h> header file. */
|
||||
/* #undef HAVE_NETDB_H */
|
||||
|
||||
/* Define to 1 if you have the <netinet/in.h> header file. */
|
||||
/* #undef HAVE_NETINET_IN_H */
|
||||
|
||||
/* Define to 1 if you have the <pthread.h> header file. */
|
||||
/* #undef HAVE_PTHREAD_H */
|
||||
|
||||
/* Define to 1 if you have the <readline/history.h> header file. */
|
||||
/* #undef HAVE_READLINE_HISTORY_H */
|
||||
|
||||
/* Define to 1 if you have the <readline/readline.h> header file. */
|
||||
/* #undef HAVE_READLINE_READLINE_H */
|
||||
|
||||
/* Define to 1 if rl_completion_matches() is available. */
|
||||
/* #undef HAVE_RL_COMPLETION_MATCHES */
|
||||
|
||||
/* Define to 1 if you have the `rmdir' function. */
|
||||
#define HAVE_RMDIR 1
|
||||
|
||||
/* Define to 1 if you have the <search.h> header file. */
|
||||
/* #undef HAVE_SEARCH_H */
|
||||
|
||||
/* Define to 1 if you have the `select' function. */
|
||||
/* #undef HAVE_SELECT */
|
||||
|
||||
/* Define to 1 to include support for selinux. */
|
||||
/* #undef HAVE_SELINUX */
|
||||
|
||||
/* Define to 1 if you have the <selinux/selinux.h> header file. */
|
||||
/* #undef HAVE_SELINUX_SELINUX_H */
|
||||
|
||||
/* Define to 1 if you have the `setlocale' function. */
|
||||
#define HAVE_SETLOCALE 1
|
||||
|
||||
/* Define to 1 if you have the <signal.h> header file. */
|
||||
#define HAVE_SIGNAL_H 1
|
||||
|
||||
/* Define to 1 if you have the `socket' function. */
|
||||
/* #undef HAVE_SOCKET */
|
||||
|
||||
/* Define to 1 if `stat' has the bug that it succeeds when given the
|
||||
zero-length file name argument. */
|
||||
/* #undef HAVE_STAT_EMPTY_STRING_BUG */
|
||||
|
||||
/* Define to 1 if you have the <stddef.h> header file. */
|
||||
#define HAVE_STDDEF_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdint.h> header file. */
|
||||
#define HAVE_STDINT_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdio.h> header file. */
|
||||
#define HAVE_STDIO_H 1
|
||||
|
||||
/* Define to 1 if you have the <stdlib.h> header file. */
|
||||
#define HAVE_STDLIB_H 1
|
||||
|
||||
/* Define to 1 if you have the `strcasecmp' function. */
|
||||
#define HAVE_STRCASECMP 1
|
||||
|
||||
/* Define to 1 if you have the `strchr' function. */
|
||||
#define HAVE_STRCHR 1
|
||||
|
||||
/* Define to 1 if you have the `strdup' function. */
|
||||
#define HAVE_STRDUP 1
|
||||
|
||||
/* Define to 1 if you have the `strerror' function. */
|
||||
#define HAVE_STRERROR 1
|
||||
|
||||
/* Define to 1 if you have the <strings.h> header file. */
|
||||
#define HAVE_STRINGS_H 1
|
||||
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#define HAVE_STRING_H 1
|
||||
|
||||
/* Define to 1 if you have the `strncasecmp' function. */
|
||||
#define HAVE_STRNCASECMP 1
|
||||
|
||||
/* Define to 1 if you have the `strrchr' function. */
|
||||
#define HAVE_STRRCHR 1
|
||||
|
||||
/* Define to 1 if you have the `strstr' function. */
|
||||
#define HAVE_STRSTR 1
|
||||
|
||||
/* Define to 1 if you have the `strtol' function. */
|
||||
#define HAVE_STRTOL 1
|
||||
|
||||
/* Define to 1 if you have the `strtoul' function. */
|
||||
#define HAVE_STRTOUL 1
|
||||
|
||||
/* Define to 1 if `st_rdev' is member of `struct stat'. */
|
||||
#define HAVE_STRUCT_STAT_ST_RDEV 1
|
||||
|
||||
/* Define to 1 if your `struct stat' has `st_rdev'. Deprecated, use
|
||||
`HAVE_STRUCT_STAT_ST_RDEV' instead. */
|
||||
#define HAVE_ST_RDEV 1
|
||||
|
||||
/* Define to 1 if you have the <syslog.h> header file. */
|
||||
#define HAVE_SYSLOG_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
/* #undef HAVE_SYS_DIR_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/disk.h> header file. */
|
||||
#define HAVE_SYS_DISK_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/file.h> header file. */
|
||||
#define HAVE_SYS_FILE_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/ioctl.h> header file. */
|
||||
#define HAVE_SYS_IOCTL_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/mman.h> header file. */
|
||||
#define HAVE_SYS_MMAN_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/mount.h> header file. */
|
||||
/* #undef HAVE_SYS_MOUNT_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
/* #undef HAVE_SYS_NDIR_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/param.h> header file. */
|
||||
#define HAVE_SYS_PARAM_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/resource.h> header file. */
|
||||
#define HAVE_SYS_RESOURCE_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/select.h> header file. */
|
||||
/* #undef HAVE_SYS_SELECT_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/socket.h> header file. */
|
||||
/* #undef HAVE_SYS_SOCKET_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/stat.h> header file. */
|
||||
#define HAVE_SYS_STAT_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/time.h> header file. */
|
||||
#define HAVE_SYS_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/types.h> header file. */
|
||||
#define HAVE_SYS_TYPES_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/uio.h> header file. */
|
||||
/* #undef HAVE_SYS_UIO_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/un.h> header file. */
|
||||
/* #undef HAVE_SYS_UN_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/utsname.h> header file. */
|
||||
#define HAVE_SYS_UTSNAME_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/vfs.h> header file. */
|
||||
/* #undef HAVE_SYS_VFS_H */
|
||||
|
||||
/* Define to 1 if you have the <sys/wait.h> header file. */
|
||||
#define HAVE_SYS_WAIT_H 1
|
||||
|
||||
/* Define to 1 if you have the <time.h> header file. */
|
||||
#define HAVE_TIME_H 1
|
||||
|
||||
/* Define to 1 if you have the `uname' function. */
|
||||
#define HAVE_UNAME 1
|
||||
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#define HAVE_UNISTD_H 1
|
||||
|
||||
/* Define to 1 if you have the <utmpx.h> header file. */
|
||||
/* #undef HAVE_UTMPX_H */
|
||||
|
||||
/* Define to 1 if you have the `vfork' function. */
|
||||
#define HAVE_VFORK 1
|
||||
|
||||
/* Define to 1 if you have the <vfork.h> header file. */
|
||||
/* #undef HAVE_VFORK_H */
|
||||
|
||||
/* Define to 1 if you have the `vprintf' function. */
|
||||
#define HAVE_VPRINTF 1
|
||||
|
||||
/* Define to 1 if `fork' works. */
|
||||
#define HAVE_WORKING_FORK 1
|
||||
|
||||
/* Define to 1 if `vfork' works. */
|
||||
#define HAVE_WORKING_VFORK 1
|
||||
|
||||
/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
|
||||
slash. */
|
||||
/* #undef LSTAT_FOLLOWS_SLASHED_SYMLINK */
|
||||
|
||||
/* Define to 1 if 'lvm' should fall back to using LVM1 binaries if
|
||||
device-mapper is missing from the kernel */
|
||||
/* #undef LVM1_FALLBACK */
|
||||
|
||||
/* Define to 1 to include built-in support for LVM1 metadata. */
|
||||
#define LVM1_INTERNAL 1
|
||||
|
||||
/* Define to 1 to include built-in support for mirrors. */
|
||||
#define MIRRORED_INTERNAL 1
|
||||
|
||||
/* The path to 'modprobe', if available. */
|
||||
#define MODPROBE_CMD "/sbin/ifconfig"
|
||||
|
||||
/* Define to 1 to enable O_DIRECT support. */
|
||||
/* #undef O_DIRECT_SUPPORT */
|
||||
|
||||
/* Define to the address where bug reports for this package should be sent. */
|
||||
#define PACKAGE_BUGREPORT ""
|
||||
|
||||
/* Define to the full name of this package. */
|
||||
#define PACKAGE_NAME ""
|
||||
|
||||
/* Define to the full name and version of this package. */
|
||||
#define PACKAGE_STRING ""
|
||||
|
||||
/* Define to the one symbol short name of this package. */
|
||||
#define PACKAGE_TARNAME ""
|
||||
|
||||
/* Define to the version of this package. */
|
||||
#define PACKAGE_VERSION ""
|
||||
|
||||
/* Define to 1 to include built-in support for GFS pool metadata. */
|
||||
#define POOL_INTERNAL 1
|
||||
|
||||
/* Define to 1 to include the LVM readline shell. */
|
||||
/* #undef READLINE_SUPPORT */
|
||||
|
||||
/* Define as the return type of signal handlers (`int' or `void'). */
|
||||
#define RETSIGTYPE void
|
||||
|
||||
/* Define to the type of arg 1 for `select'. */
|
||||
/* #undef SELECT_TYPE_ARG1 */
|
||||
|
||||
/* Define to the type of args 2, 3 and 4 for `select'. */
|
||||
/* #undef SELECT_TYPE_ARG234 */
|
||||
|
||||
/* Define to the type of arg 5 for `select'. */
|
||||
/* #undef SELECT_TYPE_ARG5 */
|
||||
|
||||
/* Define to 1 to include built-in support for snapshots. */
|
||||
#define SNAPSHOT_INTERNAL 1
|
||||
|
||||
/* If using the C implementation of alloca, define if you know the
|
||||
direction of stack growth for your system; otherwise it will be
|
||||
automatically deduced at run-time.
|
||||
STACK_DIRECTION > 0 => grows toward higher addresses
|
||||
STACK_DIRECTION < 0 => grows toward lower addresses
|
||||
STACK_DIRECTION = 0 => direction of growth unknown */
|
||||
/* #undef STACK_DIRECTION */
|
||||
|
||||
/* Define to 1 if you have the ANSI C header files. */
|
||||
#define STDC_HEADERS 1
|
||||
|
||||
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. */
|
||||
#define TIME_WITH_SYS_TIME 1
|
||||
|
||||
/* Define to 1 if your <sys/time.h> declares `struct tm'. */
|
||||
/* #undef TM_IN_SYS_TIME */
|
||||
|
||||
/* Define to empty if `const' does not conform to ANSI C. */
|
||||
/* #undef const */
|
||||
|
||||
/* Define to `__inline__' or `__inline' if that's what the C compiler
|
||||
calls it, or to nothing if 'inline' is not supported under any name. */
|
||||
#ifndef __cplusplus
|
||||
/* #undef inline */
|
||||
#endif
|
||||
|
||||
/* Define to rpl_malloc if the replacement function should be used. */
|
||||
/* #undef malloc */
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
/* #undef mode_t */
|
||||
|
||||
/* Define to `long' if <sys/types.h> does not define. */
|
||||
/* #undef off_t */
|
||||
|
||||
/* Define to `int' if <sys/types.h> does not define. */
|
||||
/* #undef pid_t */
|
||||
|
||||
/* Define to `unsigned' if <sys/types.h> does not define. */
|
||||
/* #undef size_t */
|
||||
|
||||
/* Define as `fork' if `vfork' does not work. */
|
||||
/* #undef vfork */
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "crc.h"
|
||||
|
||||
/* Calculate an endian-independent CRC of supplied buffer */
|
||||
uint32_t calc_crc(uint32_t initial, void *buf, uint32_t size)
|
||||
uint32_t calc_crc(uint32_t initial, const void *buf, uint32_t size)
|
||||
{
|
||||
static const uint32_t crctab[] = {
|
||||
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
|
||||
@@ -27,7 +27,7 @@ uint32_t calc_crc(uint32_t initial, void *buf, uint32_t size)
|
||||
0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
|
||||
};
|
||||
uint32_t i, crc = initial;
|
||||
uint8_t *data = (uint8_t *) buf;
|
||||
const uint8_t *data = (const uint8_t *) buf;
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
crc ^= *data++;
|
||||
|
||||
@@ -18,6 +18,6 @@
|
||||
|
||||
#define INITIAL_CRC 0xf597a6cf
|
||||
|
||||
uint32_t calc_crc(uint32_t initial, void *buf, uint32_t size);
|
||||
uint32_t calc_crc(uint32_t initial, const void *buf, uint32_t size);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
void get_shared_library_path(struct config_tree *cft, const char *libname,
|
||||
void get_shared_library_path(struct cmd_context *cmd, const char *libname,
|
||||
char *path, size_t path_len)
|
||||
{
|
||||
struct stat info;
|
||||
@@ -31,29 +31,29 @@ void get_shared_library_path(struct config_tree *cft, const char *libname,
|
||||
/* If libname doesn't begin with '/' then use lib_dir/libname,
|
||||
* if present */
|
||||
if (libname[0] == '/' ||
|
||||
!(lib_dir = find_config_str(cft->root, "global/library_dir", 0)) ||
|
||||
!(lib_dir = find_config_tree_str(cmd, "global/library_dir", 0)) ||
|
||||
(lvm_snprintf(path, path_len, "%s/%s", lib_dir,
|
||||
libname) == -1) || stat(path, &info) == -1)
|
||||
strncpy(path, libname, path_len);
|
||||
}
|
||||
|
||||
void *load_shared_library(struct config_tree *cft, const char *libname,
|
||||
void *load_shared_library(struct cmd_context *cmd, const char *libname,
|
||||
const char *desc, int silent)
|
||||
{
|
||||
char path[PATH_MAX];
|
||||
void *library;
|
||||
|
||||
get_shared_library_path(cft, libname, path, sizeof(path));
|
||||
get_shared_library_path(cmd, libname, path, sizeof(path));
|
||||
|
||||
log_very_verbose("Opening shared %s library %s", desc, path);
|
||||
|
||||
if (!(library = dlopen(path, RTLD_LAZY))) {
|
||||
if (!(library = dlopen(path, RTLD_LAZY | RTLD_GLOBAL))) {
|
||||
if (silent && ignorelockingfailure())
|
||||
log_verbose("Unable to open external %s library %s",
|
||||
desc, path);
|
||||
log_verbose("Unable to open external %s library %s: %s",
|
||||
desc, path, dlerror());
|
||||
else
|
||||
log_error("Unable to open external %s library %s",
|
||||
desc, path);
|
||||
log_error("Unable to open external %s library %s: %s",
|
||||
desc, path, dlerror());
|
||||
}
|
||||
|
||||
return library;
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
#include "config.h"
|
||||
#include <dlfcn.h>
|
||||
|
||||
void get_shared_library_path(struct config_tree *cft, const char *libname,
|
||||
void get_shared_library_path(struct cmd_context *cmd, const char *libname,
|
||||
char *path, size_t path_len);
|
||||
void *load_shared_library(struct config_tree *cf, const char *libname,
|
||||
void *load_shared_library(struct cmd_context *cmd, const char *libname,
|
||||
const char *what, int silent);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -144,13 +144,13 @@ int memlock(void)
|
||||
|
||||
void memlock_init(struct cmd_context *cmd)
|
||||
{
|
||||
_size_stack = find_config_int(cmd->cft->root,
|
||||
_size_stack = find_config_tree_int(cmd,
|
||||
"activation/reserved_stack",
|
||||
DEFAULT_RESERVED_STACK) * 1024;
|
||||
_size_malloc_tmp = find_config_int(cmd->cft->root,
|
||||
_size_malloc_tmp = find_config_tree_int(cmd,
|
||||
"activation/reserved_memory",
|
||||
DEFAULT_RESERVED_MEMORY) * 1024;
|
||||
_default_priority = find_config_int(cmd->cft->root,
|
||||
_default_priority = find_config_tree_int(cmd,
|
||||
"activation/process_priority",
|
||||
DEFAULT_PROCESS_PRIORITY);
|
||||
}
|
||||
|
||||
@@ -333,9 +333,12 @@ static int _lvstatus_disp(struct report_handle *rh, struct field *field,
|
||||
|
||||
if (lv->status & PVMOVE)
|
||||
repstr[0] = 'p';
|
||||
else if (lv->status & MIRRORED)
|
||||
repstr[0] = 'm';
|
||||
else if (lv->status & MIRROR_IMAGE)
|
||||
else if (lv->status & MIRRORED) {
|
||||
if (lv->status & MIRROR_NOTSYNCED)
|
||||
repstr[0] = 'M';
|
||||
else
|
||||
repstr[0] = 'm';
|
||||
}else if (lv->status & MIRROR_IMAGE)
|
||||
repstr[0] = 'i';
|
||||
else if (lv->status & MIRROR_LOG)
|
||||
repstr[0] = 'l';
|
||||
@@ -472,7 +475,8 @@ static int _vgstatus_disp(struct report_handle *rh, struct field *field,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _segtype_disp(struct report_handle *rh, struct field *field,
|
||||
static int _segtype_disp(struct report_handle *rh __attribute((unused)),
|
||||
struct field *field,
|
||||
const void *data)
|
||||
{
|
||||
const struct lv_segment *seg = (const struct lv_segment *) data;
|
||||
|
||||
@@ -27,7 +27,7 @@ static const char *_snap_name(const struct lv_segment *seg)
|
||||
}
|
||||
|
||||
static int _snap_text_import(struct lv_segment *seg, const struct config_node *sn,
|
||||
struct dm_hash_table *pv_hash)
|
||||
struct dm_hash_table *pv_hash __attribute((unused)))
|
||||
{
|
||||
uint32_t chunk_size;
|
||||
const char *org_name, *cow_name;
|
||||
@@ -87,8 +87,10 @@ static int _snap_text_export(const struct lv_segment *seg, struct formatter *f)
|
||||
}
|
||||
|
||||
#ifdef DEVMAPPER_SUPPORT
|
||||
static int _snap_target_percent(void **target_state, struct dm_pool *mem,
|
||||
struct config_tree *cft, struct lv_segment *seg,
|
||||
static int _snap_target_percent(void **target_state __attribute((unused)),
|
||||
struct dm_pool *mem __attribute((unused)),
|
||||
struct cmd_context *cmd __attribute((unused)),
|
||||
struct lv_segment *seg __attribute((unused)),
|
||||
char *params, uint64_t *total_numerator,
|
||||
uint64_t *total_denominator, float *percent)
|
||||
{
|
||||
@@ -126,7 +128,7 @@ static int _snap_target_present(void)
|
||||
|
||||
static void _snap_destroy(const struct segment_type *segtype)
|
||||
{
|
||||
dm_free((void *) segtype);
|
||||
dm_free((void *)segtype);
|
||||
}
|
||||
|
||||
static struct segtype_handler _snapshot_ops = {
|
||||
|
||||
@@ -151,11 +151,13 @@ static int _striped_merge_segments(struct lv_segment *seg1, struct lv_segment *s
|
||||
}
|
||||
|
||||
#ifdef DEVMAPPER_SUPPORT
|
||||
static int _striped_add_target_line(struct dev_manager *dm, struct dm_pool *mem,
|
||||
struct config_tree *cft, void **target_state,
|
||||
static int _striped_add_target_line(struct dev_manager *dm,
|
||||
struct dm_pool *mem __attribute((unused)),
|
||||
struct cmd_context *cmd __attribute((unused)),
|
||||
void **target_state __attribute((unused)),
|
||||
struct lv_segment *seg,
|
||||
struct dm_tree_node *node, uint64_t len,
|
||||
uint32_t *pvmove_mirror_count)
|
||||
uint32_t *pvmove_mirror_count __attribute((unused)))
|
||||
{
|
||||
if (!seg->area_count) {
|
||||
log_error("Internal error: striped add_target_line called "
|
||||
@@ -189,7 +191,7 @@ static int _striped_target_present(void)
|
||||
|
||||
static void _striped_destroy(const struct segment_type *segtype)
|
||||
{
|
||||
dm_free((void *) segtype);
|
||||
dm_free((void *)segtype);
|
||||
}
|
||||
|
||||
static struct segtype_handler _striped_ops = {
|
||||
|
||||
@@ -40,7 +40,7 @@ static int _zero_merge_segments(struct lv_segment *seg1, struct lv_segment *seg2
|
||||
#ifdef DEVMAPPER_SUPPORT
|
||||
static int _zero_add_target_line(struct dev_manager *dm __attribute((unused)),
|
||||
struct dm_pool *mem __attribute((unused)),
|
||||
struct config_tree *cft __attribute((unused)),
|
||||
struct cmd_context *cmd __attribute((unused)),
|
||||
void **target_state __attribute((unused)),
|
||||
struct lv_segment *seg __attribute((unused)),
|
||||
struct dm_tree_node *node,uint64_t len,
|
||||
|
||||
@@ -1461,7 +1461,6 @@ static int _reload_with_suppression_v4(struct dm_task *dmt)
|
||||
{
|
||||
struct dm_task *task;
|
||||
struct target *t1, *t2;
|
||||
int matches = 1;
|
||||
int r;
|
||||
|
||||
/* New task to get existing table information */
|
||||
@@ -1491,6 +1490,9 @@ static int _reload_with_suppression_v4(struct dm_task *dmt)
|
||||
return r;
|
||||
}
|
||||
|
||||
if ((task->dmi.v4->flags & DM_READONLY_FLAG) ? 1 : 0 != dmt->read_only)
|
||||
goto no_match;
|
||||
|
||||
t1 = dmt->head;
|
||||
t2 = task->head;
|
||||
|
||||
@@ -1498,21 +1500,20 @@ static int _reload_with_suppression_v4(struct dm_task *dmt)
|
||||
if ((t1->start != t2->start) ||
|
||||
(t1->length != t2->length) ||
|
||||
(strcmp(t1->type, t2->type)) ||
|
||||
(strcmp(t1->params, t2->params))) {
|
||||
matches = 0;
|
||||
break;
|
||||
}
|
||||
(strcmp(t1->params, t2->params)))
|
||||
goto no_match;
|
||||
t1 = t1->next;
|
||||
t2 = t2->next;
|
||||
}
|
||||
|
||||
if (matches && !t1 && !t2) {
|
||||
if (!t1 && !t2) {
|
||||
dmt->dmi.v4 = task->dmi.v4;
|
||||
task->dmi.v4 = NULL;
|
||||
dm_task_destroy(task);
|
||||
return 1;
|
||||
}
|
||||
|
||||
no_match:
|
||||
dm_task_destroy(task);
|
||||
|
||||
/* Now do the original reload */
|
||||
@@ -1542,7 +1543,7 @@ static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command,
|
||||
dmi->flags |= DM_SKIP_BDGET_FLAG;
|
||||
|
||||
log_debug("dm %s %s %s%s%s %s%.0d%s%.0d%s"
|
||||
"%s%c %.0llu %s [%u]",
|
||||
"%s%c%s %.0llu %s [%u]",
|
||||
_cmd_data_v4[dmt->type].name,
|
||||
dmi->name, dmi->uuid, dmt->newname ? " " : "",
|
||||
dmt->newname ? dmt->newname : "",
|
||||
@@ -1553,6 +1554,7 @@ static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command,
|
||||
dmt->major > 0 && dmt->minor == 0 ? "0" : "",
|
||||
dmt->major > 0 ? ") " : "",
|
||||
dmt->no_open_count ? 'N' : 'O',
|
||||
dmt->skip_lockfs ? "S " : "",
|
||||
dmt->sector, dmt->message ? dmt->message : "",
|
||||
dmi->data_size);
|
||||
#ifdef DM_IOCTLS
|
||||
|
||||
@@ -350,6 +350,7 @@ int dm_tree_node_add_mirror_target(struct dm_tree_node *node,
|
||||
#define DM_NOSYNC 0x00000001 /* Known already in sync */
|
||||
#define DM_FORCESYNC 0x00000002 /* Force resync */
|
||||
#define DM_BLOCK_ON_ERROR 0x00000004 /* On error, suspend I/O */
|
||||
#define DM_CORELOG 0x00000008 /* In-memory log */
|
||||
|
||||
int dm_tree_node_add_mirror_target_log(struct dm_tree_node *node,
|
||||
uint32_t region_size,
|
||||
|
||||
@@ -1242,9 +1242,12 @@ static int _emit_segment_line(struct dm_task *dmt, struct load_segment *seg, uin
|
||||
log_parm_count = 1; /* Region size */
|
||||
log_parm_count += hweight32(seg->flags); /* [no]sync, block_on_error etc. */
|
||||
|
||||
if (seg->flags & DM_CORELOG)
|
||||
log_parm_count--; /* DM_CORELOG does not count in the param list */
|
||||
|
||||
if (seg->clustered) {
|
||||
if (seg->uuid)
|
||||
log_parm_count++; /* uuid */
|
||||
log_parm_count++;
|
||||
if ((tw = _dm_snprintf(params + pos, paramsize - pos, "clustered_")) < 0) {
|
||||
stack; /* Out of space */
|
||||
return -1;
|
||||
@@ -1701,18 +1704,19 @@ int dm_tree_node_add_mirror_target_log(struct dm_tree_node *node,
|
||||
seg = list_item(list_last(&node->props.segs), struct load_segment);
|
||||
|
||||
if (log_uuid) {
|
||||
if (!(log_node = dm_tree_find_node_by_uuid(node->dtree, log_uuid))) {
|
||||
log_error("Couldn't find mirror log uuid %s.", log_uuid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_link_tree_nodes(node, log_node))
|
||||
return_0;
|
||||
|
||||
if (!(seg->uuid = dm_pool_strdup(node->dtree->mem, log_uuid))) {
|
||||
log_error("log uuid pool_strdup failed");
|
||||
return 0;
|
||||
}
|
||||
if (!(flags & DM_CORELOG)) {
|
||||
if (!(log_node = dm_tree_find_node_by_uuid(node->dtree, log_uuid))) {
|
||||
log_error("Couldn't find mirror log uuid %s.", log_uuid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!_link_tree_nodes(node, log_node))
|
||||
return_0;
|
||||
}
|
||||
}
|
||||
|
||||
seg->log = log_node;
|
||||
|
||||
@@ -195,8 +195,8 @@ clean: $(SUBDIRS.clean)
|
||||
$(SOURCES:%.c=%.pot) $(LDDEPS)
|
||||
|
||||
distclean: $(SUBDIRS.distclean)
|
||||
$(RM) $(OBJECTS) $(TARGETS) $(CLEAN_TARGETS) $(SOURCES:%.c=%.d) \
|
||||
$(SOURCES:%.c=%.pot) $(LDDEPS) \
|
||||
$(RM) $(OBJECTS) $(TARGETS) $(CLEAN_TARGETS) $(DISTCLEAN_TARGETS) \
|
||||
$(SOURCES:%.c=%.d) $(SOURCES:%.c=%.pot) $(LDDEPS) \
|
||||
config.cache config.log config.status \
|
||||
Makefile make.tmpl core \
|
||||
version.h lvm2.po
|
||||
|
||||
@@ -4,12 +4,13 @@ dmsetup \- low level logical volume management
|
||||
.SH SYNOPSIS
|
||||
.ad l
|
||||
.B dmsetup create
|
||||
.I device_name [-u uuid] [--notable] [table_file]
|
||||
.I device_name [-u uuid] [--notable | --table <table> | table_file]
|
||||
.br
|
||||
.B dmsetup remove
|
||||
.I device_name
|
||||
.I [-f|--force] device_name
|
||||
.br
|
||||
.B dmsetup remove_all
|
||||
.I [-f|--force]
|
||||
.br
|
||||
.B dmsetup suspend
|
||||
.I [--nolockfs] device_name
|
||||
@@ -18,13 +19,13 @@ dmsetup \- low level logical volume management
|
||||
.I device_name
|
||||
.br
|
||||
.B dmsetup load
|
||||
.I device_name [table_file]
|
||||
.I device_name [--table <table> | table_file]
|
||||
.br
|
||||
.B dmsetup clear
|
||||
.I device_name
|
||||
.br
|
||||
.B dmsetup reload
|
||||
.I device_name [table_file]
|
||||
.I device_name [--table <table> | table_file]
|
||||
.br
|
||||
.B dmsetup rename
|
||||
.I device_name new_name
|
||||
@@ -100,10 +101,13 @@ Specify which fields to display. Only \fB-o\ name\fP is supported.
|
||||
.IP \fB-r|--readonly
|
||||
.br
|
||||
Set the table being loaded read-only.
|
||||
.IP \fB--table\ <table>
|
||||
.br
|
||||
Specify a one-line table directly on the command line.
|
||||
.IP \fB-u|--uuid
|
||||
.br
|
||||
Specify the uuid.
|
||||
.IP \fB-v|--verbose [-v|--verbose]
|
||||
.IP \fB-v|--verbose\ [-v|--verbose]
|
||||
.br
|
||||
Produce additional output.
|
||||
.IP \fB--version
|
||||
@@ -111,10 +115,10 @@ Produce additional output.
|
||||
Display the library and kernel driver version.
|
||||
.SH COMMANDS
|
||||
.IP \fBcreate
|
||||
.I device_name [-u uuid] [--notable] [table_file]
|
||||
.I device_name [-u uuid] [--notable | --table <table> | table_file]
|
||||
.br
|
||||
Creates a device with the given name.
|
||||
If table_file is supplied, the table is loaded and made live.
|
||||
If table_file or <table> is supplied, the table is loaded and made live.
|
||||
Otherwise a table is read from standard input unless --notable is used.
|
||||
The optional uuid can be used in place of
|
||||
device_name in subsequent dmsetup commands.
|
||||
@@ -159,19 +163,38 @@ device/nodevice; active, open, rw, uuid.
|
||||
Others specify how the tree is displayed:
|
||||
ascii, utf, vt100; compact, inverted, notrunc.
|
||||
.IP \fBload|reload
|
||||
.I device_name [table_file]
|
||||
.I device_name [--table <table> | table_file]
|
||||
.br
|
||||
Loads table_file into the inactive table slot for device_name.
|
||||
If table_file is not supplied, reads a table from standard input.
|
||||
Loads <table> or table_file into the inactive table slot for device_name.
|
||||
If neither is supplied, reads a table from standard input.
|
||||
.IP \fBmknodes
|
||||
.I [device_name]
|
||||
.br
|
||||
Ensure that the node in /dev/mapper for device_name is correct.
|
||||
If no device_name is supplied, ensure that all nodes in /dev/mapper
|
||||
correspond to mapped devices currently loaded by the device-mapper kernel
|
||||
driver, adding, changing or removing nodes as necessary.
|
||||
.IP \fBremove
|
||||
.I device_name
|
||||
.I [-f|--force] device_name
|
||||
.br
|
||||
Removes a device. It will no longer be visible to dmsetup and
|
||||
will be deleted when its open_count is zero.
|
||||
Removes a device. It will no longer be visible to dmsetup.
|
||||
Open devices cannot be removed except with older kernels
|
||||
that contain a version of device-mapper prior to 4.8.0.
|
||||
In this case the device will be deleted when its open_count
|
||||
drops to zero. From version 4.8.0 onwards, if a device can't
|
||||
be removed because an uninterruptible process is waiting for
|
||||
I/O to return from it, adding --force will replace the table
|
||||
with one that fails all I/O, which might allow the
|
||||
process to be killed.
|
||||
.IP \fBremove_all
|
||||
.I [-f|--force]
|
||||
.br
|
||||
Attempts to remove all device definitions i.e. reset the driver.
|
||||
Use with care!
|
||||
Use with care! From version 4.8.0 onwards, if devices can't
|
||||
be removed because uninterruptible processess are waiting for
|
||||
I/O to return from them, adding --force will replace the table
|
||||
with one that fails all I/O, which might allow the
|
||||
process to be killed. This also runs \fBmknodes\fP afterwards.
|
||||
.IP \fBrename
|
||||
.I device_name new_name
|
||||
.br
|
||||
|
||||
@@ -44,7 +44,7 @@ can also be chosen.
|
||||
The lv_attr bits are:
|
||||
.RS
|
||||
.IP 1 3
|
||||
Volume type: (m)irrored, (o)rigin, (p)vmove, (s)napshot,
|
||||
Volume type: (m)irrored, (M)irrored without initial sync, (o)rigin, (p)vmove, (s)napshot,
|
||||
invalid (S)napshot, (v)irtual
|
||||
.IP 2 3
|
||||
Permissions: (w)riteable, (r)ead-only
|
||||
|
||||
@@ -119,9 +119,9 @@ case "$1" in
|
||||
|
||||
status)
|
||||
status clvmd
|
||||
rtrn=$?
|
||||
vols=$( $LVDISPLAY -C --nohead 2> /dev/null | awk '($3 ~ /....a./) {print $1}' )
|
||||
echo active volumes: ${vols:-"(none)"}
|
||||
rtrn=0
|
||||
;;
|
||||
|
||||
*)
|
||||
|
||||
@@ -16,4 +16,3 @@ CMDS=`./pvscan -u | sed -ne "s/.*PV \(.*\) with UUID \(.*\) VG $1 .*/.\/pvcreate
|
||||
sh -x -c "$CMDS" || exit 1
|
||||
|
||||
./vgcfgrestore --file lvmbackup -M lvm2 $1 || exit 1
|
||||
|
||||
|
||||
@@ -91,9 +91,7 @@ ifeq ("@DMEVENTD@", "yes")
|
||||
LVMLIBS += -ldevmapper-event -lpthread
|
||||
endif
|
||||
|
||||
ifeq ("@DEVMAPPER@", "yes")
|
||||
LVMLIBS += -ldevmapper
|
||||
endif
|
||||
LVMLIBS += -ldevmapper
|
||||
|
||||
DEFS += -DLVM_SHARED_PATH=\"$(exec_prefix)/sbin/lvm\"
|
||||
|
||||
|
||||
@@ -45,6 +45,11 @@ arg(type_ARG, '\0', "type", segtype_arg)
|
||||
arg(alloc_ARG, '\0', "alloc", alloc_arg)
|
||||
arg(separator_ARG, '\0', "separator", string_arg)
|
||||
arg(mirrorsonly_ARG, '\0', "mirrorsonly", NULL)
|
||||
arg(nosync_ARG, '\0', "nosync", NULL)
|
||||
arg(corelog_ARG, '\0', "corelog", NULL)
|
||||
arg(monitor_ARG, '\0', "monitor", yes_no_arg)
|
||||
arg(config_ARG, '\0', "config", string_arg)
|
||||
arg(trustcache_ARG, '\0', "trustcache", NULL)
|
||||
|
||||
/* Allow some variations */
|
||||
arg(resizable_ARG, '\0', "resizable", yes_no_arg)
|
||||
|
||||
@@ -63,6 +63,7 @@ xx(lvchange,
|
||||
"\t[-f|--force]\n"
|
||||
"\t[-h|--help]\n"
|
||||
"\t[--ignorelockingfailure]\n"
|
||||
"\t[--monitor {y|n}]\n"
|
||||
"\t[-M|--persistent y|n] [--major major] [--minor minor]\n"
|
||||
"\t[-P|--partial] " "\n"
|
||||
"\t[-p|--permission r|rw]\n"
|
||||
@@ -74,14 +75,14 @@ xx(lvchange,
|
||||
"\tLogicalVolume[Path] [LogicalVolume[Path]...]\n",
|
||||
|
||||
alloc_ARG, autobackup_ARG, available_ARG, contiguous_ARG, force_ARG,
|
||||
ignorelockingfailure_ARG, major_ARG, minor_ARG, partial_ARG, permission_ARG,
|
||||
persistent_ARG, readahead_ARG, refresh_ARG, addtag_ARG, deltag_ARG,
|
||||
test_ARG)
|
||||
ignorelockingfailure_ARG, major_ARG, minor_ARG, monitor_ARG,
|
||||
partial_ARG, permission_ARG, persistent_ARG, readahead_ARG,
|
||||
refresh_ARG, addtag_ARG, deltag_ARG, test_ARG)
|
||||
|
||||
xx(lvconvert,
|
||||
"Change logical volume layout",
|
||||
"lvconvert "
|
||||
"[-m|--mirrors Mirrors]\n"
|
||||
"[-m|--mirrors Mirrors [--corelog]]\n"
|
||||
"\t[--alloc AllocationPolicy]\n"
|
||||
"\t[-d|--debug]\n"
|
||||
"\t[-h|-?|--help]\n"
|
||||
@@ -99,7 +100,8 @@ xx(lvconvert,
|
||||
"\t[--version]" "\n"
|
||||
"\tOriginalLogicalVolume[Path] SnapshotLogicalVolume[Path]\n",
|
||||
|
||||
alloc_ARG, chunksize_ARG, mirrors_ARG, snapshot_ARG, test_ARG, zero_ARG)
|
||||
alloc_ARG, chunksize_ARG, mirrors_ARG, corelog_ARG,
|
||||
snapshot_ARG, test_ARG, zero_ARG)
|
||||
|
||||
xx(lvcreate,
|
||||
"Create a logical volume",
|
||||
@@ -114,7 +116,7 @@ xx(lvcreate,
|
||||
"\t{-l|--extents LogicalExtentsNumber |\n"
|
||||
"\t -L|--size LogicalVolumeSize[kKmMgGtT]}\n"
|
||||
"\t[-M|--persistent {y|n}] [--major major] [--minor minor]\n"
|
||||
"\t[-m|--mirrors Mirrors]\n"
|
||||
"\t[-m|--mirrors Mirrors [--nosync] [--corelog]]\n"
|
||||
"\t[-n|--name LogicalVolumeName]\n"
|
||||
"\t[-p|--permission {r|rw}]\n"
|
||||
"\t[-r|--readahead ReadAheadSectors]\n"
|
||||
@@ -147,9 +149,10 @@ xx(lvcreate,
|
||||
"\tOriginalLogicalVolume[Path] [PhysicalVolumePath...]\n\n",
|
||||
|
||||
addtag_ARG, alloc_ARG, autobackup_ARG, chunksize_ARG, contiguous_ARG,
|
||||
extents_ARG, major_ARG, minor_ARG, mirrors_ARG, name_ARG, permission_ARG,
|
||||
persistent_ARG, readahead_ARG, regionsize_ARG, size_ARG, snapshot_ARG,
|
||||
stripes_ARG, stripesize_ARG, test_ARG, type_ARG, zero_ARG)
|
||||
corelog_ARG, extents_ARG, major_ARG, minor_ARG, mirrors_ARG, name_ARG,
|
||||
nosync_ARG, permission_ARG, persistent_ARG, readahead_ARG, regionsize_ARG,
|
||||
size_ARG, snapshot_ARG, stripes_ARG, stripesize_ARG, test_ARG, type_ARG,
|
||||
zero_ARG)
|
||||
|
||||
xx(lvdisplay,
|
||||
"Display information about a logical volume",
|
||||
@@ -340,15 +343,16 @@ xx(lvs,
|
||||
"\t[-P|--partial] " "\n"
|
||||
"\t[--segments]\n"
|
||||
"\t[--separator Separator]\n"
|
||||
"\t[--trustcache]\n"
|
||||
"\t[--unbuffered]\n"
|
||||
"\t[--units hsbkmgtHKMGT]\n"
|
||||
"\t[-v|--verbose]\n"
|
||||
"\t[--version]" "\n"
|
||||
"\t[LogicalVolume[Path] [LogicalVolume[Path]...]]\n",
|
||||
|
||||
|
||||
aligned_ARG, all_ARG, ignorelockingfailure_ARG, noheadings_ARG,
|
||||
nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, segments_ARG,
|
||||
separator_ARG, sort_ARG, unbuffered_ARG, units_ARG)
|
||||
separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG)
|
||||
|
||||
xx(lvscan,
|
||||
"List all logical volumes in all volume groups",
|
||||
@@ -492,7 +496,7 @@ xx(pvmove,
|
||||
"\tSourcePhysicalVolume[:PhysicalExtent[-PhysicalExtent]...]}\n"
|
||||
"\t[DestinationPhysicalVolume[:PhysicalExtent[-PhysicalExtent]...]...]\n",
|
||||
|
||||
abort_ARG, alloc_ARG, autobackup_ARG, background_ARG,
|
||||
abort_ARG, alloc_ARG, autobackup_ARG, background_ARG,
|
||||
interval_ARG, name_ARG, test_ARG)
|
||||
|
||||
xx(pvremove,
|
||||
@@ -524,15 +528,16 @@ xx(pvs,
|
||||
"\t[-P|--partial] " "\n"
|
||||
"\t[--segments]\n"
|
||||
"\t[--separator Separator]\n"
|
||||
"\t[--trustcache]\n"
|
||||
"\t[--unbuffered]\n"
|
||||
"\t[--units hsbkmgtHKMGT]\n"
|
||||
"\t[-v|--verbose]\n"
|
||||
"\t[--version]\n"
|
||||
"\t[PhysicalVolume [PhysicalVolume...]]\n",
|
||||
|
||||
|
||||
aligned_ARG, all_ARG, ignorelockingfailure_ARG, noheadings_ARG,
|
||||
nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, segments_ARG,
|
||||
separator_ARG, sort_ARG, unbuffered_ARG, units_ARG)
|
||||
separator_ARG, sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG)
|
||||
|
||||
xx(pvscan,
|
||||
"List all physical volumes",
|
||||
@@ -593,6 +598,7 @@ xx(vgchange,
|
||||
"\t[-d|--debug] " "\n"
|
||||
"\t[-h|--help] " "\n"
|
||||
"\t[--ignorelockingfailure]\n"
|
||||
"\t[--monitor {y|n}]\n"
|
||||
"\t[-t|--test]" "\n"
|
||||
"\t[-u|--uuid] " "\n"
|
||||
"\t[-v|--verbose] " "\n"
|
||||
@@ -608,8 +614,8 @@ xx(vgchange,
|
||||
|
||||
addtag_ARG, alloc_ARG, allocation_ARG, autobackup_ARG, available_ARG,
|
||||
clustered_ARG, deltag_ARG, ignorelockingfailure_ARG, logicalvolume_ARG,
|
||||
partial_ARG, physicalextentsize_ARG, resizeable_ARG, resizable_ARG,
|
||||
test_ARG, uuid_ARG)
|
||||
monitor_ARG, partial_ARG, physicalextentsize_ARG, resizeable_ARG,
|
||||
resizable_ARG, test_ARG, uuid_ARG)
|
||||
|
||||
xx(vgck,
|
||||
"Check the consistency of volume group(s)",
|
||||
@@ -815,15 +821,16 @@ xx(vgs,
|
||||
"\t[-O|--sort [+|-]key1[,[+|-]key2[,...]]]\n"
|
||||
"\t[-P|--partial] " "\n"
|
||||
"\t[--separator Separator]\n"
|
||||
"\t[--trustcache]\n"
|
||||
"\t[--unbuffered]\n"
|
||||
"\t[--units hsbkmgtHKMGT]\n"
|
||||
"\t[-v|--verbose]\n"
|
||||
"\t[--version]\n"
|
||||
"\t[VolumeGroupName [VolumeGroupName...]]\n",
|
||||
|
||||
|
||||
aligned_ARG, all_ARG, ignorelockingfailure_ARG, noheadings_ARG,
|
||||
nolocking_ARG, nosuffix_ARG, options_ARG, partial_ARG, separator_ARG,
|
||||
sort_ARG, unbuffered_ARG, units_ARG)
|
||||
sort_ARG, trustcache_ARG, unbuffered_ARG, units_ARG)
|
||||
|
||||
xx(vgscan,
|
||||
"Search for all volume groups",
|
||||
@@ -833,7 +840,7 @@ xx(vgscan,
|
||||
"\t[--ignorelockingfailure]\n"
|
||||
"\t[--mknodes]\n"
|
||||
"\t[-P|--partial] " "\n"
|
||||
"\t[-v|--verbose]\n"
|
||||
"\t[-v|--verbose]\n"
|
||||
"\t[--version]" "\n",
|
||||
|
||||
ignorelockingfailure_ARG, mknodes_ARG, partial_ARG)
|
||||
|
||||
315
tools/dmsetup.c
315
tools/dmsetup.c
@@ -88,6 +88,7 @@ enum {
|
||||
READ_ONLY = 0,
|
||||
COLS_ARG,
|
||||
EXEC_ARG,
|
||||
FORCE_ARG,
|
||||
GID_ARG,
|
||||
MAJOR_ARG,
|
||||
MINOR_ARG,
|
||||
@@ -97,6 +98,7 @@ enum {
|
||||
NOOPENCOUNT_ARG,
|
||||
NOTABLE_ARG,
|
||||
OPTIONS_ARG,
|
||||
TABLE_ARG,
|
||||
TARGET_ARG,
|
||||
TREE_ARG,
|
||||
UID_ARG,
|
||||
@@ -108,8 +110,10 @@ enum {
|
||||
|
||||
static int _switches[NUM_SWITCHES];
|
||||
static int _values[NUM_SWITCHES];
|
||||
static int _num_devices;
|
||||
static char *_uuid;
|
||||
static char *_fields;
|
||||
static char *_table;
|
||||
static char *_target;
|
||||
static char *_command;
|
||||
static struct dm_tree *_dtree;
|
||||
@@ -117,17 +121,55 @@ static struct dm_tree *_dtree;
|
||||
/*
|
||||
* Commands
|
||||
*/
|
||||
static int _parse_line(struct dm_task *dmt, char *buffer, const char *file,
|
||||
int line)
|
||||
{
|
||||
char ttype[LINE_SIZE], *ptr, *comment;
|
||||
unsigned long long start, size;
|
||||
int n;
|
||||
|
||||
/* trim trailing space */
|
||||
for (ptr = buffer + strlen(buffer) - 1; ptr >= buffer; ptr--)
|
||||
if (!isspace((int) *ptr))
|
||||
break;
|
||||
ptr++;
|
||||
*ptr = '\0';
|
||||
|
||||
/* trim leading space */
|
||||
for (ptr = buffer; *ptr && isspace((int) *ptr); ptr++)
|
||||
;
|
||||
|
||||
if (!*ptr || *ptr == '#')
|
||||
return 1;
|
||||
|
||||
if (sscanf(ptr, "%llu %llu %s %n",
|
||||
&start, &size, ttype, &n) < 3) {
|
||||
err("Invalid format on line %d of table %s", line, file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ptr += n;
|
||||
if ((comment = strchr(ptr, (int) '#')))
|
||||
*comment = '\0';
|
||||
|
||||
if (!dm_task_add_target(dmt, start, size, ttype, ptr))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _parse_file(struct dm_task *dmt, const char *file)
|
||||
{
|
||||
char *buffer = NULL;
|
||||
size_t buffer_size = 0;
|
||||
char ttype[LINE_SIZE], *ptr, *comment;
|
||||
FILE *fp;
|
||||
unsigned long long start, size;
|
||||
int r = 0, n, line = 0;
|
||||
int r = 0, line = 0;
|
||||
|
||||
/* one-line table on cmdline */
|
||||
if (_table)
|
||||
return _parse_line(dmt, _table, "", ++line);
|
||||
|
||||
/* OK for empty stdin */
|
||||
|
||||
if (file) {
|
||||
if (!(fp = fopen(file, "r"))) {
|
||||
err("Couldn't open '%s' for reading", file);
|
||||
@@ -143,38 +185,13 @@ static int _parse_file(struct dm_task *dmt, const char *file)
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (fgets(buffer, buffer_size, fp)) {
|
||||
while (fgets(buffer, (int) buffer_size, fp))
|
||||
#else
|
||||
while (getline(&buffer, &buffer_size, fp) > 0) {
|
||||
while (getline(&buffer, &buffer_size, fp) > 0)
|
||||
#endif
|
||||
line++;
|
||||
|
||||
/* trim trailing space */
|
||||
for (ptr = buffer + strlen(buffer) - 1; ptr >= buffer; ptr--)
|
||||
if (!isspace((int) *ptr))
|
||||
break;
|
||||
ptr++;
|
||||
*ptr = '\0';
|
||||
|
||||
/* trim leading space */
|
||||
for (ptr = buffer; *ptr && isspace((int) *ptr); ptr++) ;
|
||||
|
||||
if (!*ptr || *ptr == '#')
|
||||
continue;
|
||||
|
||||
if (sscanf(ptr, "%llu %llu %s %n",
|
||||
&start, &size, ttype, &n) < 3) {
|
||||
err("%s:%d Invalid format", file, line);
|
||||
if (!_parse_line(dmt, buffer, file ? : "on stdin", ++line))
|
||||
goto out;
|
||||
}
|
||||
|
||||
ptr += n;
|
||||
if ((comment = strchr(ptr, (int) '#')))
|
||||
*comment = '\0';
|
||||
|
||||
if (!dm_task_add_target(dmt, start, size, ttype, ptr))
|
||||
goto out;
|
||||
}
|
||||
r = 1;
|
||||
|
||||
out:
|
||||
@@ -321,7 +338,7 @@ static int _set_task_device(struct dm_task *dmt, const char *name, int optional)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _load(int argc, char **argv, void *data)
|
||||
static int _load(int argc, char **argv, void *data __attribute((unused)))
|
||||
{
|
||||
int r = 0;
|
||||
struct dm_task *dmt;
|
||||
@@ -378,7 +395,7 @@ static int _load(int argc, char **argv, void *data)
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _create(int argc, char **argv, void *data)
|
||||
static int _create(int argc, char **argv, void *data __attribute((unused)))
|
||||
{
|
||||
int r = 0;
|
||||
struct dm_task *dmt;
|
||||
@@ -386,7 +403,7 @@ static int _create(int argc, char **argv, void *data)
|
||||
|
||||
if (argc == 3)
|
||||
file = argv[2];
|
||||
|
||||
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_CREATE)))
|
||||
return 0;
|
||||
|
||||
@@ -434,7 +451,7 @@ static int _create(int argc, char **argv, void *data)
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _rename(int argc, char **argv, void *data)
|
||||
static int _rename(int argc, char **argv, void *data __attribute((unused)))
|
||||
{
|
||||
int r = 0;
|
||||
struct dm_task *dmt;
|
||||
@@ -463,7 +480,7 @@ static int _rename(int argc, char **argv, void *data)
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _message(int argc, char **argv, void *data)
|
||||
static int _message(int argc, char **argv, void *data __attribute((unused)))
|
||||
{
|
||||
int r = 0, i;
|
||||
size_t sz = 1;
|
||||
@@ -523,7 +540,7 @@ static int _message(int argc, char **argv, void *data)
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _setgeometry(int argc, char **argv, void *data)
|
||||
static int _setgeometry(int argc, char **argv, void *data __attribute((unused)))
|
||||
{
|
||||
int r = 0;
|
||||
struct dm_task *dmt;
|
||||
@@ -556,7 +573,7 @@ static int _setgeometry(int argc, char **argv, void *data)
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _version(int argc, char **argv, void *data)
|
||||
static int _version(int argc __attribute((unused)), char **argv __attribute((unused)), void *data __attribute((unused)))
|
||||
{
|
||||
char version[80];
|
||||
|
||||
@@ -602,32 +619,22 @@ static int _simple(int task, const char *name, uint32_t event_nr, int display)
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _remove_all(int argc, char **argv, void *data)
|
||||
{
|
||||
return _simple(DM_DEVICE_REMOVE_ALL, "", 0, 0);
|
||||
}
|
||||
|
||||
static int _remove(int argc, char **argv, void *data)
|
||||
{
|
||||
return _simple(DM_DEVICE_REMOVE, argc > 1 ? argv[1] : NULL, 0, 0);
|
||||
}
|
||||
|
||||
static int _suspend(int argc, char **argv, void *data)
|
||||
static int _suspend(int argc, char **argv, void *data __attribute((unused)))
|
||||
{
|
||||
return _simple(DM_DEVICE_SUSPEND, argc > 1 ? argv[1] : NULL, 0, 1);
|
||||
}
|
||||
|
||||
static int _resume(int argc, char **argv, void *data)
|
||||
static int _resume(int argc, char **argv, void *data __attribute((unused)))
|
||||
{
|
||||
return _simple(DM_DEVICE_RESUME, argc > 1 ? argv[1] : NULL, 0, 1);
|
||||
}
|
||||
|
||||
static int _clear(int argc, char **argv, void *data)
|
||||
static int _clear(int argc, char **argv, void *data __attribute((unused)))
|
||||
{
|
||||
return _simple(DM_DEVICE_CLEAR, argc > 1 ? argv[1] : NULL, 0, 1);
|
||||
}
|
||||
|
||||
static int _wait(int argc, char **argv, void *data)
|
||||
static int _wait(int argc, char **argv, void *data __attribute((unused)))
|
||||
{
|
||||
const char *name = NULL;
|
||||
|
||||
@@ -644,7 +651,7 @@ static int _wait(int argc, char **argv, void *data)
|
||||
(argc > 1) ? (uint32_t) atoi(argv[argc - 1]) : 0, 1);
|
||||
}
|
||||
|
||||
static int _process_all(int argc, char **argv,
|
||||
static int _process_all(int argc, char **argv, int silent,
|
||||
int (*fn) (int argc, char **argv, void *data))
|
||||
{
|
||||
int r = 1;
|
||||
@@ -667,7 +674,8 @@ static int _process_all(int argc, char **argv,
|
||||
}
|
||||
|
||||
if (!names->dev) {
|
||||
printf("No devices found\n");
|
||||
if (!silent)
|
||||
printf("No devices found\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -683,6 +691,132 @@ static int _process_all(int argc, char **argv,
|
||||
return r;
|
||||
}
|
||||
|
||||
static uint64_t _get_device_size(const char *name)
|
||||
{
|
||||
uint64_t start, length, size = UINT64_C(0);
|
||||
struct dm_info info;
|
||||
char *target_type, *params;
|
||||
struct dm_task *dmt;
|
||||
void *next = NULL;
|
||||
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
|
||||
return 0;
|
||||
|
||||
if (!_set_task_device(dmt, name, 0))
|
||||
goto out;
|
||||
|
||||
if (_switches[NOOPENCOUNT_ARG] && !dm_task_no_open_count(dmt))
|
||||
goto out;
|
||||
|
||||
if (!dm_task_run(dmt))
|
||||
goto out;
|
||||
|
||||
if (!dm_task_get_info(dmt, &info) || !info.exists)
|
||||
goto out;
|
||||
|
||||
do {
|
||||
next = dm_get_next_target(dmt, next, &start, &length,
|
||||
&target_type, ¶ms);
|
||||
size += length;
|
||||
} while (next);
|
||||
|
||||
out:
|
||||
dm_task_destroy(dmt);
|
||||
return size;
|
||||
}
|
||||
|
||||
static int _error_device(int argc __attribute((unused)), char **argv __attribute((unused)), void *data)
|
||||
{
|
||||
struct dm_names *names = (struct dm_names *) data;
|
||||
struct dm_task *dmt;
|
||||
const char *name;
|
||||
uint64_t size;
|
||||
int r = 0;
|
||||
|
||||
if (data)
|
||||
name = names->name;
|
||||
else
|
||||
name = argv[1];
|
||||
|
||||
size = _get_device_size(name);
|
||||
|
||||
if (!(dmt = dm_task_create(DM_DEVICE_RELOAD)))
|
||||
return 0;
|
||||
|
||||
if (!_set_task_device(dmt, name, 0))
|
||||
goto err;
|
||||
|
||||
if (!dm_task_add_target(dmt, 0, size, "error", ""))
|
||||
goto err;
|
||||
|
||||
if (_switches[READ_ONLY] && !dm_task_set_ro(dmt))
|
||||
goto err;
|
||||
|
||||
if (_switches[NOOPENCOUNT_ARG] && !dm_task_no_open_count(dmt))
|
||||
goto err;
|
||||
|
||||
if (!dm_task_run(dmt))
|
||||
goto err;
|
||||
|
||||
if (!_simple(DM_DEVICE_RESUME, name, 0, 0)) {
|
||||
_simple(DM_DEVICE_CLEAR, name, 0, 0);
|
||||
goto err;
|
||||
}
|
||||
|
||||
r = 1;
|
||||
|
||||
err:
|
||||
dm_task_destroy(dmt);
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _remove(int argc, char **argv, void *data __attribute((unused)))
|
||||
{
|
||||
int r;
|
||||
|
||||
if (_switches[FORCE_ARG] && argc > 1)
|
||||
r = _error_device(argc, argv, NULL);
|
||||
|
||||
return _simple(DM_DEVICE_REMOVE, argc > 1 ? argv[1] : NULL, 0, 0);
|
||||
}
|
||||
|
||||
static int _count_devices(int argc __attribute((unused)), char **argv __attribute((unused)), void *data __attribute((unused)))
|
||||
{
|
||||
_num_devices++;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _remove_all(int argc __attribute((unused)), char **argv __attribute((unused)), void *data __attribute((unused)))
|
||||
{
|
||||
int r;
|
||||
|
||||
/* Remove all closed devices */
|
||||
r = _simple(DM_DEVICE_REMOVE_ALL, "", 0, 0) | dm_mknodes(NULL);
|
||||
|
||||
if (!_switches[FORCE_ARG])
|
||||
return r;
|
||||
|
||||
_num_devices = 0;
|
||||
r |= _process_all(argc, argv, 1, _count_devices);
|
||||
|
||||
/* No devices left? */
|
||||
if (!_num_devices)
|
||||
return r;
|
||||
|
||||
r |= _process_all(argc, argv, 1, _error_device);
|
||||
r |= _simple(DM_DEVICE_REMOVE_ALL, "", 0, 0) | dm_mknodes(NULL);
|
||||
|
||||
_num_devices = 0;
|
||||
r |= _process_all(argc, argv, 1, _count_devices);
|
||||
if (!_num_devices)
|
||||
return r;
|
||||
|
||||
fprintf(stderr, "Unable to remove %d device(s).\n", _num_devices);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static void _display_dev(struct dm_task *dmt, const char *name)
|
||||
{
|
||||
struct dm_info info;
|
||||
@@ -691,7 +825,7 @@ static void _display_dev(struct dm_task *dmt, const char *name)
|
||||
printf("%s\t(%u, %u)\n", name, info.major, info.minor);
|
||||
}
|
||||
|
||||
static int _mknodes(int argc, char **argv, void *data)
|
||||
static int _mknodes(int argc, char **argv, void *data __attribute((unused)))
|
||||
{
|
||||
return dm_mknodes(argc > 1 ? argv[1] : NULL);
|
||||
}
|
||||
@@ -774,7 +908,7 @@ static int _status(int argc, char **argv, void *data)
|
||||
name = names->name;
|
||||
else {
|
||||
if (argc == 1 && !_switches[UUID_ARG] && !_switches[MAJOR_ARG])
|
||||
return _process_all(argc, argv, _status);
|
||||
return _process_all(argc, argv, 0, _status);
|
||||
if (argc == 2)
|
||||
name = argv[1];
|
||||
}
|
||||
@@ -847,7 +981,7 @@ static int _status(int argc, char **argv, void *data)
|
||||
}
|
||||
|
||||
/* Show target names and their version numbers */
|
||||
static int _targets(int argc, char **argv, void *data)
|
||||
static int _targets(int argc __attribute((unused)), char **argv __attribute((unused)), void *data __attribute((unused)))
|
||||
{
|
||||
int r = 0;
|
||||
struct dm_task *dmt;
|
||||
@@ -877,7 +1011,6 @@ static int _targets(int argc, char **argv, void *data)
|
||||
out:
|
||||
dm_task_destroy(dmt);
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
static int _info(int argc, char **argv, void *data)
|
||||
@@ -892,7 +1025,7 @@ static int _info(int argc, char **argv, void *data)
|
||||
name = names->name;
|
||||
else {
|
||||
if (argc == 1 && !_switches[UUID_ARG] && !_switches[MAJOR_ARG])
|
||||
return _process_all(argc, argv, _info);
|
||||
return _process_all(argc, argv, 0, _info);
|
||||
if (argc == 2)
|
||||
name = argv[1];
|
||||
}
|
||||
@@ -930,7 +1063,7 @@ static int _deps(int argc, char **argv, void *data)
|
||||
name = names->name;
|
||||
else {
|
||||
if (argc == 1 && !_switches[UUID_ARG] && !_switches[MAJOR_ARG])
|
||||
return _process_all(argc, argv, _deps);
|
||||
return _process_all(argc, argv, 0, _deps);
|
||||
if (argc == 2)
|
||||
name = argv[1];
|
||||
}
|
||||
@@ -982,7 +1115,7 @@ static int _deps(int argc, char **argv, void *data)
|
||||
return r;
|
||||
}
|
||||
|
||||
static int _display_name(int argc, char **argv, void *data)
|
||||
static int _display_name(int argc __attribute((unused)), char **argv __attribute((unused)), void *data)
|
||||
{
|
||||
struct dm_names *names = (struct dm_names *) data;
|
||||
|
||||
@@ -1088,19 +1221,19 @@ static int _termwidth = 80; /* Maximum output width */
|
||||
static int _cur_x = 1; /* Current horizontal output position */
|
||||
static char _last_char = 0;
|
||||
|
||||
static void _out_char(char c)
|
||||
static void _out_char(const unsigned c)
|
||||
{
|
||||
/* Only first UTF-8 char counts */
|
||||
_cur_x += ((c & 0xc0) != 0x80);
|
||||
|
||||
if (!_tree_switches[TR_TRUNCATE]) {
|
||||
putchar(c);
|
||||
putchar((int) c);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Truncation? */
|
||||
if (_cur_x <= _termwidth)
|
||||
putchar(c);
|
||||
putchar((int) c);
|
||||
|
||||
if (_cur_x == _termwidth + 1 && ((c & 0xc0) != 0x80)) {
|
||||
if (_last_char || (c & 0x80)) {
|
||||
@@ -1114,7 +1247,7 @@ static void _out_char(char c)
|
||||
}
|
||||
}
|
||||
|
||||
static void _out_string(const char *str)
|
||||
static void _out_string(const unsigned char *str)
|
||||
{
|
||||
while (*str)
|
||||
_out_char(*str++);
|
||||
@@ -1150,9 +1283,9 @@ static void _out_newline(void)
|
||||
_cur_x = 1;
|
||||
}
|
||||
|
||||
static void _out_prefix(int depth)
|
||||
static void _out_prefix(unsigned depth)
|
||||
{
|
||||
int x, d;
|
||||
unsigned x, d;
|
||||
|
||||
for (d = 0; d < depth; d++) {
|
||||
for (x = _tree_width[d] + 1; x > 0; x--)
|
||||
@@ -1192,7 +1325,7 @@ static void _display_tree_attributes(struct dm_tree_node *node)
|
||||
|
||||
if (_tree_switches[TR_OPENCOUNT]) {
|
||||
_out_string(attr++ ? ", " : " [");
|
||||
(void) _out_int(info->open_count);
|
||||
(void) _out_int((unsigned) info->open_count);
|
||||
}
|
||||
|
||||
if (_tree_switches[TR_UUID]) {
|
||||
@@ -1205,8 +1338,8 @@ static void _display_tree_attributes(struct dm_tree_node *node)
|
||||
}
|
||||
|
||||
static void _display_tree_node(struct dm_tree_node *node, unsigned depth,
|
||||
unsigned first_child, unsigned last_child,
|
||||
unsigned has_children)
|
||||
unsigned first_child __attribute((unused)),
|
||||
unsigned last_child, unsigned has_children)
|
||||
{
|
||||
int offset;
|
||||
const char *name;
|
||||
@@ -1287,7 +1420,7 @@ static void _tree_walk_children(struct dm_tree_node *node, unsigned depth)
|
||||
dm_tree_node_num_children(child, inverted) ? 1 : 0;
|
||||
|
||||
_display_tree_node(child, depth, first_child,
|
||||
next_child ? 0 : 1, has_children);
|
||||
next_child ? 0U : 1U, has_children);
|
||||
|
||||
if (has_children)
|
||||
_tree_walk_children(child, depth + 1);
|
||||
@@ -1296,11 +1429,11 @@ static void _tree_walk_children(struct dm_tree_node *node, unsigned depth)
|
||||
}
|
||||
}
|
||||
|
||||
static int _add_dep(int argc, char **argv, void *data)
|
||||
static int _add_dep(int argc __attribute((unused)), char **argv __attribute((unused)), void *data)
|
||||
{
|
||||
struct dm_names *names = (struct dm_names *) data;
|
||||
|
||||
if (!dm_tree_add_dev(_dtree, MAJOR(names->dev), MINOR(names->dev)))
|
||||
if (!dm_tree_add_dev(_dtree, (unsigned) MAJOR(names->dev), (unsigned) MINOR(names->dev)))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
@@ -1309,12 +1442,12 @@ static int _add_dep(int argc, char **argv, void *data)
|
||||
/*
|
||||
* Create and walk dependency tree
|
||||
*/
|
||||
static int _tree(int argc, char **argv, void *data)
|
||||
static int _tree(int argc, char **argv, void *data __attribute((unused)))
|
||||
{
|
||||
if (!(_dtree = dm_tree_create()))
|
||||
return 0;
|
||||
|
||||
if (!_process_all(argc, argv, _add_dep))
|
||||
if (!_process_all(argc, argv, 0, _add_dep))
|
||||
return 0;
|
||||
|
||||
_tree_walk_children(dm_tree_find_node(_dtree, 0, 0), 0);
|
||||
@@ -1335,7 +1468,7 @@ static int _ls(int argc, char **argv, void *data)
|
||||
else if ((_switches[TREE_ARG]))
|
||||
return _tree(argc, argv, data);
|
||||
else
|
||||
return _process_all(argc, argv, _display_name);
|
||||
return _process_all(argc, argv, 0, _display_name);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1354,10 +1487,11 @@ struct command {
|
||||
static struct command _commands[] = {
|
||||
{"create", "<dev_name> [-j|--major <major> -m|--minor <minor>]\n"
|
||||
"\t [-U|--uid <uid>] [-G|--gid <gid>] [-M|--mode <octal_mode>]\n"
|
||||
"\t [-u|uuid <uuid>] [--notable] [<table_file>]",
|
||||
"\t [-u|uuid <uuid>]"
|
||||
"\t [--notable | --table <table> | <table_file>]",
|
||||
1, 2, _create},
|
||||
{"remove", "<device>", 0, 1, _remove},
|
||||
{"remove_all", "", 0, 0, _remove_all},
|
||||
{"remove", "[-f|--force] <device>", 0, 1, _remove},
|
||||
{"remove_all", "[-f|--force]", 0, 0, _remove_all},
|
||||
{"suspend", "<device>", 0, 1, _suspend},
|
||||
{"resume", "<device>", 0, 1, _resume},
|
||||
{"load", "<device> [<table_file>]", 0, 2, _load},
|
||||
@@ -1483,6 +1617,7 @@ static int _process_switches(int *argc, char ***argv)
|
||||
{"readonly", 0, &ind, READ_ONLY},
|
||||
{"columns", 0, &ind, COLS_ARG},
|
||||
{"exec", 1, &ind, EXEC_ARG},
|
||||
{"force", 0, &ind, FORCE_ARG},
|
||||
{"gid", 1, &ind, GID_ARG},
|
||||
{"major", 1, &ind, MAJOR_ARG},
|
||||
{"minor", 1, &ind, MINOR_ARG},
|
||||
@@ -1492,6 +1627,7 @@ static int _process_switches(int *argc, char ***argv)
|
||||
{"noopencount", 0, &ind, NOOPENCOUNT_ARG},
|
||||
{"notable", 0, &ind, NOTABLE_ARG},
|
||||
{"options", 1, &ind, OPTIONS_ARG},
|
||||
{"table", 1, &ind, TABLE_ARG},
|
||||
{"target", 1, &ind, TARGET_ARG},
|
||||
{"tree", 0, &ind, TREE_ARG},
|
||||
{"uid", 1, &ind, UID_ARG},
|
||||
@@ -1527,7 +1663,7 @@ static int _process_switches(int *argc, char ***argv)
|
||||
_values[MINOR_ARG] = atoi((*argv)[2]);
|
||||
*argc -= 2;
|
||||
*argv += 2;
|
||||
} else if ((*argc == 2) &&
|
||||
} else if ((*argc == 2) &&
|
||||
(2 == sscanf((*argv)[1], "%i:%i",
|
||||
&_values[MAJOR_ARG],
|
||||
&_values[MINOR_ARG]))) {
|
||||
@@ -1546,10 +1682,14 @@ static int _process_switches(int *argc, char ***argv)
|
||||
|
||||
optarg = 0;
|
||||
optind = OPTIND_INIT;
|
||||
while ((ind = -1, c = GETOPTLONG_FN(*argc, *argv, "cCGj:m:Mno:ru:Uv",
|
||||
while ((ind = -1, c = GETOPTLONG_FN(*argc, *argv, "cCfGj:m:Mno:ru:Uv",
|
||||
long_options, NULL)) != -1) {
|
||||
if (c == ':' || c == '?')
|
||||
return 0;
|
||||
if (c == 'c' || c == 'C' || ind == COLS_ARG)
|
||||
_switches[COLS_ARG]++;
|
||||
if (c == 'f' || ind == FORCE_ARG)
|
||||
_switches[FORCE_ARG]++;
|
||||
if (c == 'r' || ind == READ_ONLY)
|
||||
_switches[READ_ONLY]++;
|
||||
if (c == 'j' || ind == MAJOR_ARG) {
|
||||
@@ -1599,6 +1739,10 @@ static int _process_switches(int *argc, char ***argv)
|
||||
_switches[NOLOCKFS_ARG]++;
|
||||
if ((ind == NOOPENCOUNT_ARG))
|
||||
_switches[NOOPENCOUNT_ARG]++;
|
||||
if ((ind == TABLE_ARG)) {
|
||||
_switches[TABLE_ARG]++;
|
||||
_table = optarg;
|
||||
}
|
||||
if ((ind == TREE_ARG))
|
||||
_switches[TREE_ARG]++;
|
||||
if ((ind == VERSION_ARG))
|
||||
@@ -1624,6 +1768,11 @@ static int _process_switches(int *argc, char ***argv)
|
||||
if (_switches[TREE_ARG] && !_process_tree_options(_fields))
|
||||
return 0;
|
||||
|
||||
if (_switches[TABLE_ARG] && _switches[NOTABLE_ARG]) {
|
||||
fprintf(stderr, "--table and --notable are incompatible.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
*argv += optind;
|
||||
*argc -= optind;
|
||||
return 1;
|
||||
@@ -1634,7 +1783,7 @@ int main(int argc, char **argv)
|
||||
struct command *c;
|
||||
int r = 1;
|
||||
|
||||
(void) setlocale(LC_ALL, "");
|
||||
(void) setlocale(LC_ALL, "");
|
||||
|
||||
if (!_process_switches(&argc, &argv)) {
|
||||
fprintf(stderr, "Couldn't process command line.\n");
|
||||
|
||||
@@ -72,6 +72,38 @@ static int lvchange_permission(struct cmd_context *cmd,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lvchange_registration(struct cmd_context *cmd,
|
||||
struct logical_volume *lv)
|
||||
{
|
||||
int r;
|
||||
struct lvinfo info;
|
||||
|
||||
if (!lv_info(cmd, lv, &info, 0) || !info.exists) {
|
||||
log_error("Logical volume, %s, is not active", lv->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* do not register pvmove lv's */
|
||||
if (lv->status & PVMOVE)
|
||||
return 1;
|
||||
|
||||
log_verbose("%smonitoring logical volume \"%s\"",
|
||||
(dmeventd_register_mode()) ? "" : "Not ", lv->name);
|
||||
r = register_dev_for_events(cmd, lv, dmeventd_register_mode());
|
||||
|
||||
if (r < 0) {
|
||||
log_error("Unable to %smonitor logical volume, %s",
|
||||
(dmeventd_register_mode()) ? "" : "un", lv->name);
|
||||
r = 0;
|
||||
} else if (!r) {
|
||||
log_verbose("Logical volume %s needs no monitoring.",
|
||||
lv->name);
|
||||
r = 1;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static int lvchange_availability(struct cmd_context *cmd,
|
||||
struct logical_volume *lv)
|
||||
{
|
||||
@@ -283,14 +315,7 @@ static int lvchange_persistent(struct cmd_context *cmd,
|
||||
lv->major = arg_int_value(cmd, major_ARG, lv->major);
|
||||
log_verbose("Setting persistent device number to (%d, %d) "
|
||||
"for \"%s\"", lv->major, lv->minor, lv->name);
|
||||
if (active) {
|
||||
log_verbose("Re-activating logical volume \"%s\"",
|
||||
lv->name);
|
||||
if (!activate_lv(cmd, lv)) {
|
||||
log_error("%s: reactivation failed", lv->name);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
log_very_verbose("Updating logical volume \"%s\" on disk(s)", lv->name);
|
||||
@@ -301,21 +326,17 @@ static int lvchange_persistent(struct cmd_context *cmd,
|
||||
|
||||
backup(lv->vg);
|
||||
|
||||
if (!suspend_lv(cmd, lv)) {
|
||||
log_error("Failed to lock %s", lv->name);
|
||||
vg_revert(lv->vg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!vg_commit(lv->vg)) {
|
||||
resume_lv(cmd, lv);
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_very_verbose("Updating permissions for \"%s\" in kernel", lv->name);
|
||||
if (!resume_lv(cmd, lv)) {
|
||||
log_error("Problem reactivating %s", lv->name);
|
||||
return 0;
|
||||
if (active) {
|
||||
log_verbose("Re-activating logical volume \"%s\"", lv->name);
|
||||
if (!activate_lv(cmd, lv)) {
|
||||
log_error("%s: reactivation failed", lv->name);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -422,6 +443,8 @@ static int lvchange_single(struct cmd_context *cmd, struct logical_volume *lv,
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
init_dmeventd_register(arg_int_value(cmd, monitor_ARG, DEFAULT_DMEVENTD_MONITOR));
|
||||
|
||||
/* access permission change */
|
||||
if (arg_count(cmd, permission_ARG)) {
|
||||
if (!archive(lv->vg))
|
||||
@@ -474,14 +497,22 @@ static int lvchange_single(struct cmd_context *cmd, struct logical_volume *lv,
|
||||
log_print("Logical volume \"%s\" changed", lv->name);
|
||||
|
||||
/* availability change */
|
||||
if (arg_count(cmd, available_ARG))
|
||||
if (arg_count(cmd, available_ARG)) {
|
||||
if (!lvchange_availability(cmd, lv))
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (arg_count(cmd, refresh_ARG))
|
||||
if (!lvchange_refresh(cmd, lv))
|
||||
return ECMD_FAILED;
|
||||
|
||||
if (!arg_count(cmd, available_ARG) &&
|
||||
!arg_count(cmd, refresh_ARG) &&
|
||||
arg_count(cmd, monitor_ARG)) {
|
||||
if (!lvchange_registration(cmd, lv))
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
return ECMD_PROCESSED;
|
||||
}
|
||||
|
||||
@@ -492,9 +523,10 @@ int lvchange(struct cmd_context *cmd, int argc, char **argv)
|
||||
&& !arg_count(cmd, minor_ARG) && !arg_count(cmd, major_ARG)
|
||||
&& !arg_count(cmd, persistent_ARG) && !arg_count(cmd, addtag_ARG)
|
||||
&& !arg_count(cmd, deltag_ARG) && !arg_count(cmd, refresh_ARG)
|
||||
&& !arg_count(cmd, alloc_ARG)) {
|
||||
log_error("One or more of -a, -C, -j, -m, -M, -p, -r, "
|
||||
"--refresh, --alloc, --addtag or --deltag required");
|
||||
&& !arg_count(cmd, alloc_ARG) && !arg_count(cmd, monitor_ARG)) {
|
||||
log_error("Need 1 or more of -a, -C, -j, -m, -M, -p, -r, "
|
||||
"--refresh, --alloc, --addtag, --deltag "
|
||||
"or --monitor");
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ static int _read_params(struct lvconvert_params *lp, struct cmd_context *cmd,
|
||||
lp->region_size = 2 * arg_uint_value(cmd,
|
||||
regionsize_ARG, 0);
|
||||
} else {
|
||||
region_size = 2 * find_config_int(cmd->cft->root,
|
||||
region_size = 2 * find_config_tree_int(cmd,
|
||||
"activation/mirror_region_size",
|
||||
DEFAULT_MIRROR_REGION_SIZE);
|
||||
if (region_size < 0) {
|
||||
@@ -235,6 +235,8 @@ static int lvconvert_mirrors(struct cmd_context * cmd, struct logical_volume * l
|
||||
struct alloc_handle *ah = NULL;
|
||||
struct logical_volume *log_lv;
|
||||
struct list *parallel_areas;
|
||||
struct segment_type *segtype; /* FIXME: could I just use lp->segtype */
|
||||
float sync_percent;
|
||||
|
||||
seg = first_seg(lv);
|
||||
existing_mirrors = seg->area_count;
|
||||
@@ -277,10 +279,71 @@ static int lvconvert_mirrors(struct cmd_context * cmd, struct logical_volume * l
|
||||
return 0;
|
||||
}
|
||||
if (lp->mirrors == existing_mirrors) {
|
||||
log_error("Logical volume %s already has %"
|
||||
PRIu32 " mirror(s).", lv->name,
|
||||
lp->mirrors - 1);
|
||||
return 1;
|
||||
if (!seg->log_lv && !arg_count(cmd, corelog_ARG)) {
|
||||
/* No disk log present, add one. */
|
||||
/* FIXME: Why doesn't this work? Without
|
||||
it, we will probably put the log on the
|
||||
same device as a mirror leg.
|
||||
if (!(parallel_areas = build_parallel_areas_from_lv(cmd, lv))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
parallel_areas = NULL;
|
||||
if (!lv_mirror_percent(cmd, lv, 0, &sync_percent, NULL)) {
|
||||
log_error("Unable to determine mirror sync status.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
segtype = get_segtype_from_string(cmd, "striped");
|
||||
|
||||
if (!(ah = allocate_extents(lv->vg, NULL, segtype, 1,
|
||||
0, 1, 0,
|
||||
NULL, 0, 0, lp->pvh,
|
||||
lp->alloc,
|
||||
parallel_areas))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sync_percent >= 100.0)
|
||||
init_mirror_in_sync(1);
|
||||
else
|
||||
init_mirror_in_sync(0);
|
||||
|
||||
if (!(log_lv = create_mirror_log(cmd, lv->vg, ah,
|
||||
lp->alloc, lv->name,
|
||||
(sync_percent >= 100.0) ?
|
||||
1 : 0))) {
|
||||
log_error("Failed to create mirror log.");
|
||||
return 0;
|
||||
}
|
||||
seg->log_lv = log_lv;
|
||||
log_lv->status |= MIRROR_LOG;
|
||||
first_seg(log_lv)->mirror_seg = seg;
|
||||
} else if (seg->log_lv && arg_count(cmd, corelog_ARG)) {
|
||||
/* Had disk log, switch to core. */
|
||||
if (!lv_mirror_percent(cmd, lv, 0, &sync_percent, NULL)) {
|
||||
log_error("Unable to determine mirror sync status.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sync_percent >= 100.0)
|
||||
init_mirror_in_sync(1);
|
||||
else
|
||||
init_mirror_in_sync(0);
|
||||
|
||||
if (!remove_mirror_images(seg, lp->mirrors,
|
||||
lp->pv_count ?
|
||||
lp->pvh : NULL, 1))
|
||||
return_0;
|
||||
} else {
|
||||
/* No change */
|
||||
log_error("Logical volume %s already has %"
|
||||
PRIu32 " mirror(s).", lv->name,
|
||||
lp->mirrors - 1);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (lp->mirrors > existing_mirrors) {
|
||||
/* FIXME Unless anywhere, remove PV of log_lv
|
||||
@@ -314,7 +377,8 @@ static int lvconvert_mirrors(struct cmd_context * cmd, struct logical_volume * l
|
||||
return_0;
|
||||
|
||||
if (!(ah = allocate_extents(lv->vg, NULL, lp->segtype,
|
||||
1, lp->mirrors - 1, 1,
|
||||
1, lp->mirrors - 1,
|
||||
arg_count(cmd, corelog_ARG) ? 0 : 1,
|
||||
lv->le_count * (lp->mirrors - 1),
|
||||
NULL, 0, 0, lp->pvh,
|
||||
lp->alloc,
|
||||
@@ -325,9 +389,11 @@ static int lvconvert_mirrors(struct cmd_context * cmd, struct logical_volume * l
|
||||
lv->le_count,
|
||||
lp->region_size);
|
||||
|
||||
if (!(log_lv = create_mirror_log(cmd, lv->vg, ah,
|
||||
log_lv = NULL;
|
||||
if (!arg_count(cmd, corelog_ARG) &&
|
||||
!(log_lv = create_mirror_log(cmd, lv->vg, ah,
|
||||
lp->alloc,
|
||||
lv->name))) {
|
||||
lv->name, 0))) {
|
||||
log_error("Failed to create mirror log.");
|
||||
return 0;
|
||||
}
|
||||
@@ -390,7 +456,7 @@ static int lvconvert_snapshot(struct cmd_context *cmd,
|
||||
|
||||
if (!lp->zero)
|
||||
log_error("WARNING: \"%s\" not zeroed", lv->name);
|
||||
else if (!zero_lv(cmd, lv)) {
|
||||
else if (!set_lv(cmd, lv, 0)) {
|
||||
log_error("Aborting. Failed to wipe snapshot "
|
||||
"exception store.");
|
||||
return 0;
|
||||
|
||||
@@ -24,6 +24,8 @@ struct lvcreate_params {
|
||||
int zero;
|
||||
int major;
|
||||
int minor;
|
||||
int corelog;
|
||||
int nosync;
|
||||
|
||||
char *origin;
|
||||
const char *vg_name;
|
||||
@@ -211,7 +213,7 @@ static int _read_stripe_params(struct lvcreate_params *lp,
|
||||
}
|
||||
|
||||
if (lp->stripes > 1 && !lp->stripe_size) {
|
||||
lp->stripe_size = find_config_int(cmd->cft->root,
|
||||
lp->stripe_size = find_config_tree_int(cmd,
|
||||
"metadata/stripesize",
|
||||
DEFAULT_STRIPESIZE) * 2;
|
||||
log_print("Using default stripesize %s",
|
||||
@@ -262,7 +264,7 @@ static int _read_mirror_params(struct lvcreate_params *lp,
|
||||
}
|
||||
lp->region_size = 2 * arg_uint_value(cmd, regionsize_ARG, 0);
|
||||
} else {
|
||||
region_size = 2 * find_config_int(cmd->cft->root,
|
||||
region_size = 2 * find_config_tree_int(cmd,
|
||||
"activation/mirror_region_size",
|
||||
DEFAULT_MIRROR_REGION_SIZE);
|
||||
if (region_size < 0) {
|
||||
@@ -291,6 +293,9 @@ static int _read_mirror_params(struct lvcreate_params *lp,
|
||||
return 0;
|
||||
}
|
||||
|
||||
lp->corelog = arg_count(cmd, corelog_ARG) ? 1 : 0;
|
||||
lp->nosync = arg_count(cmd, nosync_ARG) ? 1 : 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -377,6 +382,16 @@ static int _lvcreate_params(struct lvcreate_params *lp, struct cmd_context *cmd,
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (arg_count(cmd, corelog_ARG)) {
|
||||
log_error("--corelog is only available with mirrors");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (arg_count(cmd, nosync_ARG)) {
|
||||
log_error("--nosync is only available with mirrors");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (activation() && lp->segtype->ops->target_present &&
|
||||
@@ -580,6 +595,13 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
|
||||
"supported yet");
|
||||
return 0;
|
||||
}
|
||||
if (org->status & MIRROR_IMAGE ||
|
||||
org->status & MIRROR_LOG ||
|
||||
org->status & MIRRORED) {
|
||||
log_error("Snapshots and mirrors may not yet be mixed.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Must zero cow */
|
||||
status |= LVM_WRITE;
|
||||
}
|
||||
@@ -634,9 +656,9 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
|
||||
/* FIXME Calculate how many extents needed for the log */
|
||||
|
||||
if (!(ah = allocate_extents(vg, NULL, lp->segtype, lp->stripes,
|
||||
lp->mirrors, 1, lp->extents,
|
||||
NULL, 0, 0, pvh, lp->alloc,
|
||||
NULL))) {
|
||||
lp->mirrors, lp->corelog ? 0 : 1,
|
||||
lp->extents, NULL, 0, 0,
|
||||
pvh, lp->alloc, NULL))) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
@@ -645,8 +667,17 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
|
||||
lp->extents,
|
||||
lp->region_size);
|
||||
|
||||
if (!(log_lv = create_mirror_log(cmd, vg, ah, lp->alloc,
|
||||
lv_name))) {
|
||||
init_mirror_in_sync(lp->nosync);
|
||||
|
||||
if (lp->nosync) {
|
||||
log_print("WARNING: New mirror won't be synchronised. "
|
||||
"Don't read what you didn't write!");
|
||||
status |= MIRROR_NOTSYNCED;
|
||||
}
|
||||
|
||||
if (!lp->corelog &&
|
||||
!(log_lv = create_mirror_log(cmd, vg, ah, lp->alloc,
|
||||
lv_name, lp->nosync))) {
|
||||
log_error("Failed to create mirror log.");
|
||||
return 0;
|
||||
}
|
||||
@@ -730,7 +761,7 @@ static int _lvcreate(struct cmd_context *cmd, struct lvcreate_params *lp)
|
||||
}
|
||||
|
||||
if ((lp->zero || lp->snapshot) && activation()) {
|
||||
if (!zero_lv(cmd, lv) && lp->snapshot) {
|
||||
if (!set_lv(cmd, lv, 0) && lp->snapshot) {
|
||||
/* FIXME Remove the failed lv we just added */
|
||||
log_error("Aborting. Failed to wipe snapshot "
|
||||
"exception store. Remove new LV and retry.");
|
||||
|
||||
@@ -449,7 +449,7 @@ static void _register_commands()
|
||||
driverloaded_ARG, \
|
||||
debug_ARG, help_ARG, help2_ARG, \
|
||||
version_ARG, verbose_ARG, \
|
||||
quiet_ARG, -1);
|
||||
quiet_ARG, config_ARG, -1);
|
||||
#include "commands.h"
|
||||
#undef xx
|
||||
}
|
||||
@@ -707,6 +707,17 @@ static int _get_settings(struct cmd_context *cmd)
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
|
||||
if (arg_count(cmd, trustcache_ARG)) {
|
||||
if (arg_count(cmd, all_ARG)) {
|
||||
log_error("--trustcache is incompatible with --all");
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
init_trust_cache(1);
|
||||
log_print("WARNING: Cache file of PVs will be trusted. "
|
||||
"New devices holding PVs may get ignored.");
|
||||
} else
|
||||
init_trust_cache(0);
|
||||
|
||||
/* Handle synonyms */
|
||||
if (!_merge_synonym(cmd, resizable_ARG, resizeable_ARG) ||
|
||||
!_merge_synonym(cmd, allocation_ARG, allocatable_ARG) ||
|
||||
@@ -760,12 +771,23 @@ int help(struct cmd_context *cmd __attribute((unused)), int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _override_settings(struct cmd_context *cmd)
|
||||
{
|
||||
if (!(cmd->cft_override = create_config_tree_from_string(cmd, arg_str_value(cmd, config_ARG, "")))) {
|
||||
log_error("Failed to set overridden configuration entries.");
|
||||
return EINVALID_CMD_LINE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _apply_settings(struct cmd_context *cmd)
|
||||
{
|
||||
init_debug(cmd->current_settings.debug);
|
||||
init_verbose(cmd->current_settings.verbose + VERBOSE_BASE_LEVEL);
|
||||
init_test(cmd->current_settings.test);
|
||||
init_full_scan_done(0);
|
||||
init_mirror_in_sync(0);
|
||||
|
||||
init_msg_prefix(cmd->default_settings.msg_prefix);
|
||||
init_cmd_name(cmd->default_settings.cmd_name);
|
||||
@@ -781,7 +803,7 @@ static void _apply_settings(struct cmd_context *cmd)
|
||||
|
||||
static char *_copy_command_line(struct cmd_context *cmd, int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int i, space;
|
||||
|
||||
/*
|
||||
* Build up the complete command line, used as a
|
||||
@@ -791,9 +813,17 @@ static char *_copy_command_line(struct cmd_context *cmd, int argc, char **argv)
|
||||
goto bad;
|
||||
|
||||
for (i = 0; i < argc; i++) {
|
||||
space = strchr(argv[i], ' ') ? 1 : 0;
|
||||
|
||||
if (space && !dm_pool_grow_object(cmd->mem, "'", 1))
|
||||
goto bad;
|
||||
|
||||
if (!dm_pool_grow_object(cmd->mem, argv[i], strlen(argv[i])))
|
||||
goto bad;
|
||||
|
||||
if (space && !dm_pool_grow_object(cmd->mem, "'", 1))
|
||||
goto bad;
|
||||
|
||||
if (i < (argc - 1))
|
||||
if (!dm_pool_grow_object(cmd->mem, " ", 1))
|
||||
goto bad;
|
||||
@@ -833,7 +863,11 @@ static int _run_command(struct cmd_context *cmd, int argc, char **argv)
|
||||
|
||||
set_cmd_name(cmd->command->name);
|
||||
|
||||
if (!cmd->config_valid || config_files_changed(cmd)) {
|
||||
if (arg_count(cmd, config_ARG))
|
||||
if ((ret = _override_settings(cmd)))
|
||||
goto_out;
|
||||
|
||||
if (arg_count(cmd, config_ARG) || !cmd->config_valid || config_files_changed(cmd)) {
|
||||
/* Reinitialise various settings inc. logging, filters */
|
||||
if (!refresh_toolcontext(cmd)) {
|
||||
log_error("Updated config file invalid. Aborting.");
|
||||
@@ -842,7 +876,7 @@ static int _run_command(struct cmd_context *cmd, int argc, char **argv)
|
||||
}
|
||||
|
||||
if ((ret = _get_settings(cmd)))
|
||||
goto out;
|
||||
goto_out;
|
||||
_apply_settings(cmd);
|
||||
|
||||
log_debug("Processing: %s", cmd->cmd_line);
|
||||
@@ -852,15 +886,15 @@ static int _run_command(struct cmd_context *cmd, int argc, char **argv)
|
||||
#endif
|
||||
|
||||
if ((ret = _process_common_commands(cmd)))
|
||||
goto out;
|
||||
goto_out;
|
||||
|
||||
if (arg_count(cmd, nolocking_ARG))
|
||||
locking_type = 0;
|
||||
else
|
||||
locking_type = find_config_int(cmd->cft->root,
|
||||
locking_type = find_config_tree_int(cmd,
|
||||
"global/locking_type", 1);
|
||||
|
||||
if (!init_locking(locking_type, cmd->cft)) {
|
||||
if (!init_locking(locking_type, cmd)) {
|
||||
log_error("Locking type %d initialisation failed.",
|
||||
locking_type);
|
||||
ret = ECMD_FAILED;
|
||||
@@ -877,6 +911,15 @@ static int _run_command(struct cmd_context *cmd, int argc, char **argv)
|
||||
lvmcache_destroy();
|
||||
}
|
||||
|
||||
if (cmd->cft_override) {
|
||||
destroy_config_tree(cmd->cft_override);
|
||||
cmd->cft_override = NULL;
|
||||
/* Move this? */
|
||||
if (!refresh_toolcontext(cmd))
|
||||
stack;
|
||||
}
|
||||
|
||||
/* FIXME Move this? */
|
||||
cmd->current_settings = cmd->default_settings;
|
||||
_apply_settings(cmd);
|
||||
|
||||
@@ -888,6 +931,8 @@ static int _run_command(struct cmd_context *cmd, int argc, char **argv)
|
||||
if (ret == EINVALID_CMD_LINE && !_interactive)
|
||||
_usage(cmd->command->name);
|
||||
|
||||
log_debug("Completed: %s", cmd->cmd_line);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1161,7 +1206,7 @@ static void _read_history(struct cmd_context *cmd)
|
||||
if (read_history(hist_file))
|
||||
log_very_verbose("Couldn't read history from %s.", hist_file);
|
||||
|
||||
stifle_history(find_config_int(cmd->cft->root, "shell/history_size",
|
||||
stifle_history(find_config_tree_int(cmd, "shell/history_size",
|
||||
DEFAULT_MAX_HISTORY));
|
||||
|
||||
}
|
||||
@@ -1333,7 +1378,7 @@ static int _lvm1_fallback(struct cmd_context *cmd)
|
||||
char vsn[80];
|
||||
int dm_present;
|
||||
|
||||
if (!find_config_int(cmd->cft->root, "global/fallback_to_lvm1",
|
||||
if (!find_config_tree_int(cmd, "global/fallback_to_lvm1",
|
||||
DEFAULT_FALLBACK_TO_LVM1) ||
|
||||
strncmp(cmd->kernel_vsn, "2.4.", 4))
|
||||
return 0;
|
||||
|
||||
@@ -301,7 +301,7 @@ static int _lvresize(struct cmd_context *cmd, struct lvresize_params *lp)
|
||||
lp->stripe_size = seg_stripesize;
|
||||
} else {
|
||||
lp->stripe_size =
|
||||
find_config_int(cmd->cft->root,
|
||||
find_config_tree_int(cmd,
|
||||
"metadata/stripesize",
|
||||
DEFAULT_STRIPESIZE) * 2;
|
||||
log_print("Using default stripesize %s",
|
||||
|
||||
@@ -96,7 +96,7 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name)
|
||||
(yes_no_prompt("Software RAID md superblock "
|
||||
"detected on %s. Wipe it? [y/n] ", name) == 'y'))) {
|
||||
log_print("Wiping software RAID md superblock on %s", name);
|
||||
if (!dev_zero(dev, md_superblock, 4)) {
|
||||
if (!dev_set(dev, md_superblock, 4, 0)) {
|
||||
log_error("Failed to wipe RAID md superblock on %s",
|
||||
name);
|
||||
return 0;
|
||||
@@ -185,13 +185,13 @@ static int pvcreate_single(struct cmd_context *cmd, const char *pv_name,
|
||||
pvmetadatasize = arg_uint64_value(cmd, metadatasize_ARG, UINT64_C(0))
|
||||
* 2;
|
||||
if (!pvmetadatasize)
|
||||
pvmetadatasize = find_config_int(cmd->cft->root,
|
||||
pvmetadatasize = find_config_tree_int(cmd,
|
||||
"metadata/pvmetadatasize",
|
||||
DEFAULT_PVMETADATASIZE);
|
||||
|
||||
pvmetadatacopies = arg_int_value(cmd, metadatacopies_ARG, -1);
|
||||
if (pvmetadatacopies < 0)
|
||||
pvmetadatacopies = find_config_int(cmd->cft->root,
|
||||
pvmetadatacopies = find_config_tree_int(cmd,
|
||||
"metadata/pvmetadatacopies",
|
||||
DEFAULT_PVMETADATACOPIES);
|
||||
|
||||
@@ -225,7 +225,7 @@ static int pvcreate_single(struct cmd_context *cmd, const char *pv_name,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!dev_zero(dev, UINT64_C(0), (size_t) 2048)) {
|
||||
if (!dev_set(dev, UINT64_C(0), (size_t) 2048, 0)) {
|
||||
log_error("%s not wiped: aborting", pv_name);
|
||||
dev_close(dev);
|
||||
goto error;
|
||||
|
||||
@@ -134,73 +134,73 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
|
||||
|
||||
int aligned, buffered, headings;
|
||||
|
||||
aligned = find_config_int(cmd->cft->root, "report/aligned",
|
||||
aligned = find_config_tree_int(cmd, "report/aligned",
|
||||
DEFAULT_REP_ALIGNED);
|
||||
buffered = find_config_int(cmd->cft->root, "report/buffered",
|
||||
buffered = find_config_tree_int(cmd, "report/buffered",
|
||||
DEFAULT_REP_BUFFERED);
|
||||
headings = find_config_int(cmd->cft->root, "report/headings",
|
||||
headings = find_config_tree_int(cmd, "report/headings",
|
||||
DEFAULT_REP_HEADINGS);
|
||||
separator = find_config_str(cmd->cft->root, "report/separator",
|
||||
separator = find_config_tree_str(cmd, "report/separator",
|
||||
DEFAULT_REP_SEPARATOR);
|
||||
|
||||
switch (report_type) {
|
||||
case LVS:
|
||||
keys = find_config_str(cmd->cft->root, "report/lvs_sort",
|
||||
keys = find_config_tree_str(cmd, "report/lvs_sort",
|
||||
DEFAULT_LVS_SORT);
|
||||
if (!arg_count(cmd, verbose_ARG))
|
||||
options = find_config_str(cmd->cft->root,
|
||||
options = find_config_tree_str(cmd,
|
||||
"report/lvs_cols",
|
||||
DEFAULT_LVS_COLS);
|
||||
else
|
||||
options = find_config_str(cmd->cft->root,
|
||||
options = find_config_tree_str(cmd,
|
||||
"report/lvs_cols_verbose",
|
||||
DEFAULT_LVS_COLS_VERB);
|
||||
break;
|
||||
case VGS:
|
||||
keys = find_config_str(cmd->cft->root, "report/vgs_sort",
|
||||
keys = find_config_tree_str(cmd, "report/vgs_sort",
|
||||
DEFAULT_VGS_SORT);
|
||||
if (!arg_count(cmd, verbose_ARG))
|
||||
options = find_config_str(cmd->cft->root,
|
||||
options = find_config_tree_str(cmd,
|
||||
"report/vgs_cols",
|
||||
DEFAULT_VGS_COLS);
|
||||
else
|
||||
options = find_config_str(cmd->cft->root,
|
||||
options = find_config_tree_str(cmd,
|
||||
"report/vgs_cols_verbose",
|
||||
DEFAULT_VGS_COLS_VERB);
|
||||
break;
|
||||
case PVS:
|
||||
keys = find_config_str(cmd->cft->root, "report/pvs_sort",
|
||||
keys = find_config_tree_str(cmd, "report/pvs_sort",
|
||||
DEFAULT_PVS_SORT);
|
||||
if (!arg_count(cmd, verbose_ARG))
|
||||
options = find_config_str(cmd->cft->root,
|
||||
options = find_config_tree_str(cmd,
|
||||
"report/pvs_cols",
|
||||
DEFAULT_PVS_COLS);
|
||||
else
|
||||
options = find_config_str(cmd->cft->root,
|
||||
options = find_config_tree_str(cmd,
|
||||
"report/pvs_cols_verbose",
|
||||
DEFAULT_PVS_COLS_VERB);
|
||||
break;
|
||||
case SEGS:
|
||||
keys = find_config_str(cmd->cft->root, "report/segs_sort",
|
||||
keys = find_config_tree_str(cmd, "report/segs_sort",
|
||||
DEFAULT_SEGS_SORT);
|
||||
if (!arg_count(cmd, verbose_ARG))
|
||||
options = find_config_str(cmd->cft->root,
|
||||
options = find_config_tree_str(cmd,
|
||||
"report/segs_cols",
|
||||
DEFAULT_SEGS_COLS);
|
||||
else
|
||||
options = find_config_str(cmd->cft->root,
|
||||
options = find_config_tree_str(cmd,
|
||||
"report/segs_cols_verbose",
|
||||
DEFAULT_SEGS_COLS_VERB);
|
||||
break;
|
||||
case PVSEGS:
|
||||
keys = find_config_str(cmd->cft->root, "report/pvsegs_sort",
|
||||
keys = find_config_tree_str(cmd, "report/pvsegs_sort",
|
||||
DEFAULT_PVSEGS_SORT);
|
||||
if (!arg_count(cmd, verbose_ARG))
|
||||
options = find_config_str(cmd->cft->root,
|
||||
options = find_config_tree_str(cmd,
|
||||
"report/pvsegs_cols",
|
||||
DEFAULT_PVSEGS_COLS);
|
||||
else
|
||||
options = find_config_str(cmd->cft->root,
|
||||
options = find_config_tree_str(cmd,
|
||||
"report/pvsegs_cols_verbose",
|
||||
DEFAULT_PVSEGS_COLS_VERB);
|
||||
break;
|
||||
|
||||
@@ -15,10 +15,15 @@
|
||||
|
||||
#include "tools.h"
|
||||
#include "lv_alloc.h"
|
||||
#include "xlate.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
/* From linux/drivers/md/dm-log.c */
|
||||
#define MIRROR_MAGIC 0x4D695272
|
||||
#define MIRROR_DISK_VERSION 2
|
||||
|
||||
/* Command line args */
|
||||
unsigned arg_count(struct cmd_context *cmd, int a)
|
||||
{
|
||||
@@ -408,7 +413,7 @@ static int _process_one_vg(struct cmd_context *cmd, const char *vg_name,
|
||||
if (!(vg = vg_read(cmd, vg_name, vgid, &consistent))) {
|
||||
log_error("Volume group \"%s\" not found", vg_name);
|
||||
unlock_vg(cmd, vg_name);
|
||||
return ret_max;
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
if (!list_empty(tags)) {
|
||||
@@ -1111,9 +1116,9 @@ int generate_log_name_format(struct volume_group *vg __attribute((unused)),
|
||||
}
|
||||
|
||||
/*
|
||||
* Volumes may be zeroed to remove old application data.
|
||||
* Initialize the LV with 'value'.
|
||||
*/
|
||||
int zero_lv(struct cmd_context *cmd, struct logical_volume *lv)
|
||||
int set_lv(struct cmd_context *cmd, struct logical_volume *lv, int value)
|
||||
{
|
||||
struct device *dev;
|
||||
char *name;
|
||||
@@ -1126,27 +1131,80 @@ int zero_lv(struct cmd_context *cmd, struct logical_volume *lv)
|
||||
* (I know the device is at least 4k, but not 32k)
|
||||
*/
|
||||
if (!(name = dm_pool_alloc(cmd->mem, PATH_MAX))) {
|
||||
log_error("Name allocation failed - device not zeroed");
|
||||
log_error("Name allocation failed - device not cleared");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lvm_snprintf(name, PATH_MAX, "%s%s/%s", cmd->dev_dir,
|
||||
lv->vg->name, lv->name) < 0) {
|
||||
log_error("Name too long - device not zeroed (%s)", lv->name);
|
||||
log_error("Name too long - device not cleared (%s)", lv->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_verbose("Zeroing start of logical volume \"%s\"", lv->name);
|
||||
log_verbose("Clearing start of logical volume \"%s\"", lv->name);
|
||||
|
||||
if (!(dev = dev_cache_get(name, NULL))) {
|
||||
log_error("%s: not found: device not zeroed", name);
|
||||
log_error("%s: not found: device not cleared", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!dev_open_quiet(dev))
|
||||
return 0;
|
||||
|
||||
dev_zero(dev, UINT64_C(0), (size_t) 4096);
|
||||
dev_set(dev, UINT64_C(0), (size_t) 4096, value);
|
||||
dev_close_immediate(dev);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This function writes a new header to the mirror log header to the lv
|
||||
*
|
||||
* Returns: 1 on success, 0 on failure
|
||||
*/
|
||||
static int _write_log_header(struct cmd_context *cmd, struct logical_volume *lv)
|
||||
{
|
||||
struct device *dev;
|
||||
char *name;
|
||||
struct { /* The mirror log header */
|
||||
uint32_t magic;
|
||||
uint32_t version;
|
||||
uint64_t nr_regions;
|
||||
} log_header;
|
||||
|
||||
log_header.magic = xlate32(MIRROR_MAGIC);
|
||||
log_header.version = xlate32(MIRROR_DISK_VERSION);
|
||||
log_header.nr_regions = xlate64((uint64_t)-1);
|
||||
|
||||
if (!(name = dm_pool_alloc(cmd->mem, PATH_MAX))) {
|
||||
log_error("Name allocation failed - log header not written (%s)",
|
||||
lv->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (lvm_snprintf(name, PATH_MAX, "%s%s/%s", cmd->dev_dir,
|
||||
lv->vg->name, lv->name) < 0) {
|
||||
log_error("Name too long - log header not written (%s)", lv->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
log_verbose("Writing log header to device, %s", lv->name);
|
||||
|
||||
if (!(dev = dev_cache_get(name, NULL))) {
|
||||
log_error("%s: not found: log header not written", name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!dev_open_quiet(dev))
|
||||
return 0;
|
||||
|
||||
if (!dev_write(dev, UINT64_C(0), sizeof(log_header), &log_header)) {
|
||||
log_error("Failed to write log header to %s", name);
|
||||
dev_close_immediate(dev);
|
||||
return 0;
|
||||
}
|
||||
|
||||
dev_close_immediate(dev);
|
||||
|
||||
return 1;
|
||||
@@ -1156,7 +1214,8 @@ struct logical_volume *create_mirror_log(struct cmd_context *cmd,
|
||||
struct volume_group *vg,
|
||||
struct alloc_handle *ah,
|
||||
alloc_policy_t alloc,
|
||||
const char *lv_name)
|
||||
const char *lv_name,
|
||||
int in_sync)
|
||||
{
|
||||
struct logical_volume *log_lv;
|
||||
char *log_name;
|
||||
@@ -1201,12 +1260,18 @@ struct logical_volume *create_mirror_log(struct cmd_context *cmd,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (activation() && !zero_lv(cmd, log_lv)) {
|
||||
if (activation() && !set_lv(cmd, log_lv, in_sync)) {
|
||||
log_error("Aborting. Failed to wipe mirror log. "
|
||||
"Remove new LV and retry.");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!_write_log_header(cmd, log_lv)) {
|
||||
log_error("Aborting. Failed to write mirror log header. "
|
||||
"Remove new LV and retry.");
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!deactivate_lv(cmd, log_lv)) {
|
||||
log_error("Aborting. Failed to deactivate mirror log. "
|
||||
"Remove new LV and retry.");
|
||||
|
||||
@@ -97,8 +97,9 @@ struct logical_volume *create_mirror_log(struct cmd_context *cmd,
|
||||
struct volume_group *vg,
|
||||
struct alloc_handle *ah,
|
||||
alloc_policy_t alloc,
|
||||
const char *lv_name);
|
||||
const char *lv_name,
|
||||
int in_sync);
|
||||
|
||||
int zero_lv(struct cmd_context *cmd, struct logical_volume *lv);
|
||||
int set_lv(struct cmd_context *cmd, struct logical_volume *lv, int value);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -15,6 +15,51 @@
|
||||
|
||||
#include "tools.h"
|
||||
|
||||
static int _register_lvs_in_vg(struct cmd_context *cmd,
|
||||
struct volume_group *vg, int reg)
|
||||
{
|
||||
struct lv_list *lvl;
|
||||
struct logical_volume *lv;
|
||||
struct lvinfo info;
|
||||
int lv_active;
|
||||
int count = 0;
|
||||
int r;
|
||||
|
||||
list_iterate_items(lvl, &vg->lvs) {
|
||||
lv = lvl->lv;
|
||||
|
||||
if (!lv_info(cmd, lv, &info, 0))
|
||||
lv_active = 0;
|
||||
else
|
||||
lv_active = info.exists;
|
||||
|
||||
/*
|
||||
* FIXME: Need to consider all cases... PVMOVE, etc
|
||||
*/
|
||||
if ((lv->status & PVMOVE) || !lv_active)
|
||||
continue;
|
||||
|
||||
r = register_dev_for_events(cmd, lv, reg);
|
||||
|
||||
if (r < 0) {
|
||||
log_error("Failed to %s logical volume, %s",
|
||||
(reg) ? "register" : "unregister",
|
||||
lv->name);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (r)
|
||||
count++;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns the number of monitored devices, not the number
|
||||
* of _new_ monitored devices
|
||||
*/
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
static int _activate_lvs_in_vg(struct cmd_context *cmd,
|
||||
struct volume_group *vg, int activate)
|
||||
{
|
||||
@@ -65,9 +110,23 @@ static int _activate_lvs_in_vg(struct cmd_context *cmd,
|
||||
return count;
|
||||
}
|
||||
|
||||
static int _vgchange_monitoring(struct cmd_context *cmd, struct volume_group *vg)
|
||||
{
|
||||
int active, monitored;
|
||||
|
||||
if ((active = lvs_in_vg_activated(vg))) {
|
||||
monitored = _register_lvs_in_vg(cmd, vg, dmeventd_register_mode());
|
||||
log_print("%d logical volume(s) in volume group "
|
||||
"\"%s\" now %smonitored",
|
||||
monitored, vg->name, (dmeventd_register_mode()) ? "" : "un");
|
||||
}
|
||||
|
||||
return ECMD_PROCESSED;
|
||||
}
|
||||
|
||||
static int _vgchange_available(struct cmd_context *cmd, struct volume_group *vg)
|
||||
{
|
||||
int lv_open, active;
|
||||
int lv_open, active, monitored;
|
||||
int available;
|
||||
int activate = 1;
|
||||
|
||||
@@ -93,9 +152,15 @@ static int _vgchange_available(struct cmd_context *cmd, struct volume_group *vg)
|
||||
if (activate && !lockingfailed())
|
||||
check_current_backup(vg);
|
||||
|
||||
if (activate && (active = lvs_in_vg_activated(vg)))
|
||||
if (activate && (active = lvs_in_vg_activated(vg))) {
|
||||
log_verbose("%d logical volume(s) in volume group \"%s\" "
|
||||
"already active", active, vg->name);
|
||||
monitored = _register_lvs_in_vg(cmd, vg, dmeventd_register_mode());
|
||||
log_verbose("%d existing logical volume(s) in volume "
|
||||
"group \"%s\" now %smonitored",
|
||||
monitored, vg->name,
|
||||
dmeventd_register_mode() ? "" : "un");
|
||||
}
|
||||
|
||||
if (activate && _activate_lvs_in_vg(cmd, vg, available))
|
||||
log_verbose("Activated logical volumes in "
|
||||
@@ -429,9 +494,14 @@ static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
|
||||
return ECMD_FAILED;
|
||||
}
|
||||
|
||||
init_dmeventd_register(arg_int_value(cmd, monitor_ARG, DEFAULT_DMEVENTD_MONITOR));
|
||||
|
||||
if (arg_count(cmd, available_ARG))
|
||||
r = _vgchange_available(cmd, vg);
|
||||
|
||||
else if (arg_count(cmd, monitor_ARG))
|
||||
r = _vgchange_monitoring(cmd, vg);
|
||||
|
||||
else if (arg_count(cmd, resizeable_ARG))
|
||||
r = _vgchange_resizeable(cmd, vg);
|
||||
|
||||
@@ -466,7 +536,8 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)
|
||||
arg_count(cmd, resizeable_ARG) + arg_count(cmd, deltag_ARG) +
|
||||
arg_count(cmd, addtag_ARG) + arg_count(cmd, uuid_ARG) +
|
||||
arg_count(cmd, physicalextentsize_ARG) +
|
||||
arg_count(cmd, clustered_ARG) + arg_count(cmd, alloc_ARG))) {
|
||||
arg_count(cmd, clustered_ARG) + arg_count(cmd, alloc_ARG) +
|
||||
arg_count(cmd, monitor_ARG))) {
|
||||
log_error("One of -a, -c, -l, -s, -x, --uuid, --alloc, --addtag or "
|
||||
"--deltag required");
|
||||
return EINVALID_CMD_LINE;
|
||||
|
||||
@@ -71,14 +71,14 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,
|
||||
UINT64_C(0)) * 2;
|
||||
if (!pvmetadatasize)
|
||||
pvmetadatasize =
|
||||
find_config_int(cmd->cft->root,
|
||||
find_config_tree_int(cmd,
|
||||
"metadata/pvmetadatasize",
|
||||
DEFAULT_PVMETADATASIZE);
|
||||
|
||||
pvmetadatacopies = arg_int_value(cmd, metadatacopies_ARG, -1);
|
||||
if (pvmetadatacopies < 0)
|
||||
pvmetadatacopies =
|
||||
find_config_int(cmd->cft->root,
|
||||
find_config_tree_int(cmd,
|
||||
"metadata/pvmetadatacopies",
|
||||
DEFAULT_PVMETADATACOPIES);
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
|
||||
|
||||
/* Check no PVs are constructed from either VG */
|
||||
list_iterate_items(pvl, &vg_to->pvs) {
|
||||
if (pv_uses_vg(cmd, pvl->pv, vg_from)) {
|
||||
if (pv_uses_vg(pvl->pv, vg_from)) {
|
||||
log_error("Physical volume %s might be constructed "
|
||||
"from same volume group %s.",
|
||||
dev_name(pvl->pv->dev), vg_from->name);
|
||||
@@ -134,7 +134,7 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
|
||||
}
|
||||
|
||||
list_iterate_items(pvl, &vg_from->pvs) {
|
||||
if (pv_uses_vg(cmd, pvl->pv, vg_to)) {
|
||||
if (pv_uses_vg(pvl->pv, vg_to)) {
|
||||
log_error("Physical volume %s might be constructed "
|
||||
"from same volume group %s.",
|
||||
dev_name(pvl->pv->dev), vg_to->name);
|
||||
|
||||
@@ -111,7 +111,13 @@ static int _remove_lv(struct cmd_context *cmd, struct logical_volume *lv,
|
||||
* and add to list of LVs to be removed later.
|
||||
* Doesn't apply to snapshots/origins yet - they're already deactivated.
|
||||
*/
|
||||
if (lv_info(cmd, lv, &info, 0) && info.exists) {
|
||||
/*
|
||||
* If the LV is a part of mirror segment,
|
||||
* the mirrored LV also should be cleaned up.
|
||||
* Clean-up is currently done by caller (_make_vg_consistent()).
|
||||
*/
|
||||
if ((lv_info(cmd, lv, &info, 0) && info.exists)
|
||||
|| first_seg(lv)->mirror_seg) {
|
||||
extents = lv->le_count;
|
||||
mirror_seg = first_seg(lv)->mirror_seg;
|
||||
if (!lv_empty(lv)) {
|
||||
@@ -158,7 +164,7 @@ static int _make_vg_consistent(struct cmd_context *cmd, struct volume_group *vg)
|
||||
struct lv_segment *seg, *mirrored_seg;
|
||||
struct lv_segment_area area;
|
||||
unsigned s;
|
||||
uint32_t mimages;
|
||||
uint32_t mimages, remove_log;
|
||||
int list_unsafe, only_mirror_images_found;
|
||||
LIST_INIT(lvs_changed);
|
||||
only_mirror_images_found = 1;
|
||||
@@ -259,7 +265,10 @@ static int _make_vg_consistent(struct cmd_context *cmd, struct volume_group *vg)
|
||||
mirrored_seg = first_seg(lvl->lv);
|
||||
if (!seg_is_mirrored(mirrored_seg))
|
||||
continue;
|
||||
|
||||
mimages = mirrored_seg->area_count;
|
||||
remove_log = 0;
|
||||
|
||||
for (s = 0; s < mirrored_seg->area_count; s++) {
|
||||
list_iterate_items_safe(lvl2, lvlt, &lvs_changed) {
|
||||
if (seg_type(mirrored_seg, s) != AREA_LV ||
|
||||
@@ -272,8 +281,29 @@ static int _make_vg_consistent(struct cmd_context *cmd, struct volume_group *vg)
|
||||
mimages--; /* FIXME Assumes uniqueness */
|
||||
}
|
||||
}
|
||||
if (mimages != mirrored_seg->area_count) {
|
||||
if (!remove_mirror_images(mirrored_seg, mimages, NULL, 0)) {
|
||||
|
||||
if (mirrored_seg->log_lv) {
|
||||
list_iterate_items(seg, &mirrored_seg->log_lv->segments) {
|
||||
/* FIXME: The second test shouldn't be required */
|
||||
if ((seg->segtype ==
|
||||
get_segtype_from_string(vg->cmd, "error"))) {
|
||||
log_print("The log device for %s/%s has failed.",
|
||||
vg->name, mirrored_seg->lv->name);
|
||||
remove_log = 1;
|
||||
break;
|
||||
}
|
||||
if (!strcmp(seg->segtype->name, "error")) {
|
||||
log_print("Log device for %s/%s has failed.",
|
||||
vg->name, mirrored_seg->lv->name);
|
||||
remove_log = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((mimages != mirrored_seg->area_count) || (remove_log)){
|
||||
if (!reconfigure_mirror_images(mirrored_seg, mimages,
|
||||
NULL, remove_log)) {
|
||||
stack;
|
||||
return 0;
|
||||
}
|
||||
@@ -295,14 +325,20 @@ static int _make_vg_consistent(struct cmd_context *cmd, struct volume_group *vg)
|
||||
|
||||
/* Deactivate error LVs */
|
||||
if (!test_mode()) {
|
||||
list_iterate_items(lvl, &lvs_changed) {
|
||||
list_iterate_items_safe(lvl, lvlt, &lvs_changed) {
|
||||
log_verbose("Deactivating (if active) logical volume %s",
|
||||
lvl->lv->name);
|
||||
|
||||
if (!deactivate_lv(cmd, lvl->lv)) {
|
||||
log_error("Failed to deactivate LV %s",
|
||||
lvl->lv->name);
|
||||
return 0;
|
||||
/*
|
||||
* We failed to deactivate.
|
||||
* Probably because this was a mirror log.
|
||||
* Don't try to lv_remove it.
|
||||
* Continue work on others.
|
||||
*/
|
||||
list_del(&lvl->list);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -445,7 +481,7 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv)
|
||||
log_error("Volume group \"%s\" is already consistent",
|
||||
vg_name);
|
||||
unlock_vg(cmd, vg_name);
|
||||
return ECMD_FAILED;
|
||||
return ECMD_PROCESSED;
|
||||
}
|
||||
|
||||
init_partial(1);
|
||||
|
||||
Reference in New Issue
Block a user