master - remove unused io functions
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=3ed9256985bd9fadcbb...
Commit: 3ed9256985bd9fadcbbb8f419b8d44bf22e93ef2
Parent: fb83719d7f6ca0b2da0a56e5ce7ac1a9d1ebc7e1
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Feb 28 10:48:30 2019 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Feb 28 10:58:00 2019 -0600
remove unused io functions
---
lib/device/dev-io.c | 328 ---------------------------------------------------
lib/device/device.h | 8 --
2 files changed, 0 insertions(+), 336 deletions(-)
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index 4460e55..3fe2647 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -53,95 +53,6 @@
static unsigned _dev_size_seqno = 1;
-static const char *_reasons[] = {
- "dev signatures",
- "PV labels",
- "VG metadata header",
- "VG metadata content",
- "extra VG metadata header",
- "extra VG metadata content",
- "LVM1 metadata",
- "pool metadata",
- "LV content",
- "logging",
-};
-
-static const char *_reason_text(dev_io_reason_t reason)
-{
- return _reasons[(unsigned) reason];
-}
-
-/*-----------------------------------------------------------------
- * The standard io loop that keeps submitting an io until it's
- * all gone.
- *---------------------------------------------------------------*/
-static int _io(struct device_area *where, char *buffer, int should_write, dev_io_reason_t reason)
-{
- int fd = dev_fd(where->dev);
- ssize_t n = 0;
- size_t total = 0;
-
- if (fd < 0) {
- log_error("Attempt to read an unopened device (%s).",
- dev_name(where->dev));
- return 0;
- }
-
- log_debug_io("%s %s:%8" PRIu64 " bytes (sync) at %" PRIu64 "%s (for %s)",
- should_write ? "Write" : "Read ", dev_name(where->dev),
- where->size, (uint64_t) where->start,
- (should_write && test_mode()) ? " (test mode - suppressed)" : "", _reason_text(reason));
-
- /*
- * Skip all writes in test mode.
- */
- if (should_write && test_mode())
- return 1;
-
- if (where->size > SSIZE_MAX) {
- log_error("Read size too large: %" PRIu64, where->size);
- return 0;
- }
-
- if (lseek(fd, (off_t) where->start, SEEK_SET) == (off_t) -1) {
- log_error("%s: lseek %" PRIu64 " failed: %s",
- dev_name(where->dev), (uint64_t) where->start,
- strerror(errno));
- return 0;
- }
-
- while (total < (size_t) where->size) {
- do
- n = should_write ?
- write(fd, buffer, (size_t) where->size - total) :
- read(fd, buffer, (size_t) where->size - total);
- while ((n < 0) && ((errno == EINTR) || (errno == EAGAIN)));
-
- if (n < 0)
- log_error_once("%s: %s failed after %" PRIu64 " of %" PRIu64
- " at %" PRIu64 ": %s", dev_name(where->dev),
- should_write ? "write" : "read",
- (uint64_t) total,
- (uint64_t) where->size,
- (uint64_t) where->start, strerror(errno));
-
- if (n <= 0)
- break;
-
- total += n;
- buffer += n;
- }
-
- return (total == (size_t) where->size);
-}
-
-/*-----------------------------------------------------------------
- * LVM2 uses O_DIRECT when performing metadata io, which requires
- * block size aligned accesses. If any io is not aligned we have
- * to perform the io via a bounce buffer, obviously this is quite
- * inefficient.
- *---------------------------------------------------------------*/
-
/*
* Get the physical and logical block size for a device.
*/
@@ -213,101 +124,6 @@ out:
return r;
}
-/*
- * Widens a region to be an aligned region.
- */
-static void _widen_region(unsigned int block_size, struct device_area *region,
- struct device_area *result)
-{
- uint64_t mask = block_size - 1, delta;
- memcpy(result, region, sizeof(*result));
-
- /* adjust the start */
- delta = result->start & mask;
- if (delta) {
- result->start -= delta;
- result->size += delta;
- }
-
- /* adjust the end */
- delta = (result->start + result->size) & mask;
- if (delta)
- result->size += block_size - delta;
-}
-
-static int _aligned_io(struct device_area *where, char *buffer,
- int should_write, dev_io_reason_t reason)
-{
- char *bounce, *bounce_buf;
- unsigned int physical_block_size = 0;
- unsigned int block_size = 0;
- unsigned buffer_was_widened = 0;
- uintptr_t mask;
- struct device_area widened;
- int r = 0;
-
- if (!(where->dev->flags & DEV_REGULAR) &&
- !dev_get_block_size(where->dev, &physical_block_size, &block_size))
- return_0;
-
- if (!block_size)
- block_size = lvm_getpagesize();
- mask = block_size - 1;
-
- _widen_region(block_size, where, &widened);
-
- /* Did we widen the buffer? When writing, this means means read-modify-write. */
- if (where->size != widened.size || where->start != widened.start) {
- buffer_was_widened = 1;
- log_debug_io("Widening request for %" PRIu64 " bytes at %" PRIu64 " to %" PRIu64 " bytes at %" PRIu64 " on %s (for %s)",
- where->size, (uint64_t) where->start, widened.size, (uint64_t) widened.start, dev_name(where->dev), _reason_text(reason));
- } else if (!((uintptr_t) buffer & mask))
- /* Perform the I/O directly. */
- return _io(where, buffer, should_write, reason);
-
- /* Allocate a bounce buffer with an extra block */
- if (!(bounce_buf = bounce = malloc((size_t) widened.size + block_size))) {
- log_error("Bounce buffer malloc failed");
- return 0;
- }
-
- /*
- * Realign start of bounce buffer (using the extra sector)
- */
- if (((uintptr_t) bounce) & mask)
- bounce = (char *) ((((uintptr_t) bounce) + mask) & ~mask);
-
- /* Do we need to read into the bounce buffer? */
- if ((!should_write || buffer_was_widened) &&
- !_io(&widened, bounce, 0, reason)) {
- if (!should_write)
- goto_out;
- /* FIXME Handle errors properly! */
- /* FIXME pre-extend the file */
- memset(bounce, '\n', widened.size);
- }
-
- if (should_write) {
- memcpy(bounce + (where->start - widened.start), buffer,
- (size_t) where->size);
-
- /* ... then we write */
- if (!(r = _io(&widened, bounce, 1, reason)))
- stack;
-
- goto out;
- }
-
- memcpy(buffer, bounce + (where->start - widened.start),
- (size_t) where->size);
-
- r = 1;
-
-out:
- free(bounce_buf);
- return r;
-}
-
static int _dev_get_size_file(struct device *dev, uint64_t *size)
{
const char *name = dev_name(dev);
@@ -581,7 +397,6 @@ int dev_open_flags(struct device *dev, int flags, int direct, int quiet)
dev->flags |= DEV_O_DIRECT_TESTED;
#endif
dev->open_count++;
- dev->flags &= ~DEV_ACCESSED_W;
if (need_rw)
dev->flags |= DEV_OPENED_RW;
@@ -643,16 +458,6 @@ int dev_open_readonly_quiet(struct device *dev)
return dev_open_flags(dev, O_RDONLY, 1, 1);
}
-int dev_test_excl(struct device *dev)
-{
- int flags = 0;
-
- flags |= O_EXCL;
- flags |= O_RDWR;
-
- return dev_open_flags(dev, flags, 1, 1);
-}
-
static void _close(struct device *dev)
{
if (close(dev->fd))
@@ -675,11 +480,6 @@ static int _dev_close(struct device *dev, int immediate)
return 0;
}
-#ifndef O_DIRECT_SUPPORT
- if (dev->flags & DEV_ACCESSED_W)
- dev_flush(dev);
-#endif
-
if (dev->open_count > 0)
dev->open_count--;
@@ -702,131 +502,3 @@ int dev_close_immediate(struct device *dev)
{
return _dev_close(dev, 1);
}
-
-int dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *buffer)
-{
- struct device_area where;
- int ret;
-
- if (!dev->open_count)
- return_0;
-
- where.dev = dev;
- where.start = offset;
- where.size = len;
-
- ret = _aligned_io(&where, buffer, 0, reason);
-
- return ret;
-}
-
-/*
- * Read from 'dev' into 'buf', possibly in 2 distinct regions, denoted
- * by (offset,len) and (offset2,len2). Thus, the total size of
- * 'buf' should be len+len2.
- */
-int dev_read_circular(struct device *dev, uint64_t offset, size_t len,
- uint64_t offset2, size_t len2, dev_io_reason_t reason, char *buf)
-{
- if (!dev_read(dev, offset, len, reason, buf)) {
- log_error("Read from %s failed", dev_name(dev));
- return 0;
- }
-
- /*
- * The second region is optional, and allows for
- * a circular buffer on the device.
- */
- if (!len2)
- return 1;
-
- if (!dev_read(dev, offset2, len2, reason, buf + len)) {
- log_error("Circular read from %s failed",
- dev_name(dev));
- return 0;
- }
-
- return 1;
-}
-
-/* FIXME If O_DIRECT can't extend file, dev_extend first; dev_truncate after.
- * But fails if concurrent processes writing
- */
-
-/* FIXME pre-extend the file */
-int dev_append(struct device *dev, size_t len, dev_io_reason_t reason, char *buffer)
-{
- int r;
-
- if (!dev->open_count)
- return_0;
-
- r = dev_write(dev, dev->end, len, reason, buffer);
- dev->end += (uint64_t) len;
-
-#ifndef O_DIRECT_SUPPORT
- dev_flush(dev);
-#endif
- return r;
-}
-
-int dev_write(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *buffer)
-{
- struct device_area where;
- int ret;
-
- if (!dev->open_count)
- return_0;
-
- if (!len) {
- log_error(INTERNAL_ERROR "Attempted to write 0 bytes to %s at " FMTu64, dev_name(dev), offset);
- return 0;
- }
-
- where.dev = dev;
- where.start = offset;
- where.size = len;
-
- dev->flags |= DEV_ACCESSED_W;
-
- ret = _aligned_io(&where, buffer, 1, reason);
-
- return ret;
-}
-
-int dev_set(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, int value)
-{
- size_t s;
- char buffer[4096] __attribute__((aligned(8)));
-
- if (!dev_open(dev))
- return_0;
-
- if ((offset % SECTOR_SIZE) || (len % SECTOR_SIZE))
- log_debug_devs("Wiping %s at %" PRIu64 " length %" PRIsize_t,
- dev_name(dev), offset, len);
- else
- log_debug_devs("Wiping %s at sector %" PRIu64 " length %" PRIsize_t
- " sectors", dev_name(dev), offset >> SECTOR_SHIFT,
- len >> SECTOR_SHIFT);
-
- memset(buffer, value, sizeof(buffer));
- while (1) {
- s = len > sizeof(buffer) ? sizeof(buffer) : len;
- if (!dev_write(dev, offset, s, reason, buffer))
- break;
-
- len -= s;
- if (!len)
- break;
-
- offset += s;
- }
-
- dev->flags |= DEV_ACCESSED_W;
-
- if (!dev_close(dev))
- stack;
-
- return (len == 0);
-}
diff --git a/lib/device/device.h b/lib/device/device.h
index fa7e738..afeee7f 100644
--- a/lib/device/device.h
+++ b/lib/device/device.h
@@ -20,7 +20,6 @@
#include <fcntl.h>
-#define DEV_ACCESSED_W 0x00000001 /* Device written to? */
#define DEV_REGULAR 0x00000002 /* Regular file? */
#define DEV_ALLOCED 0x00000004 /* malloc used */
#define DEV_OPENED_RW 0x00000008 /* Opened RW */
@@ -144,17 +143,10 @@ int dev_open_readonly_buffered(struct device *dev);
int dev_open_readonly_quiet(struct device *dev);
int dev_close(struct device *dev);
int dev_close_immediate(struct device *dev);
-int dev_test_excl(struct device *dev);
int dev_fd(struct device *dev);
const char *dev_name(const struct device *dev);
-int dev_read(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *buffer);
-int dev_read_circular(struct device *dev, uint64_t offset, size_t len,
- uint64_t offset2, size_t len2, dev_io_reason_t reason, char *buf);
-int dev_write(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, void *buffer);
-int dev_append(struct device *dev, size_t len, dev_io_reason_t reason, char *buffer);
-int dev_set(struct device *dev, uint64_t offset, size_t len, dev_io_reason_t reason, int value);
void dev_flush(struct device *dev);
struct device *dev_create_file(const char *filename, struct device *dev,
4 years, 9 months
master - logging: remove unused code
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=fb83719d7f6ca0b2da0...
Commit: fb83719d7f6ca0b2da0a56e5ce7ac1a9d1ebc7e1
Parent: ce79b62bc2fcaddf65e090ec3fef75926cddf82c
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Feb 28 10:30:54 2019 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Feb 28 10:30:54 2019 -0600
logging: remove unused code
Incomplete bits of original code that's unused.
---
lib/commands/toolcontext.c | 6 ----
lib/log/log.c | 61 +-------------------------------------------
lib/log/lvm-logging.h | 2 -
3 files changed, 1 insertions(+), 68 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 29c1bd8..0b88dca 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -374,15 +374,10 @@ static void _init_logging(struct cmd_context *cmd)
log_file = find_config_tree_str(cmd, log_file_CFG, NULL);
if (log_file) {
- release_log_memory();
fin_log();
init_log_file(log_file, append);
}
- log_file = find_config_tree_str(cmd, log_activate_file_CFG, NULL);
- if (log_file)
- init_log_direct(log_file, append);
-
init_log_while_suspended(find_config_tree_bool(cmd, log_activation_CFG, NULL));
cmd->default_settings.debug_classes = _parse_debug_classes(cmd);
@@ -1995,7 +1990,6 @@ void destroy_toolcontext(struct cmd_context *cmd)
lvmpolld_disconnect();
- release_log_memory();
activation_exit();
reset_log_duplicated();
fin_log();
diff --git a/lib/log/log.c b/lib/log/log.c
index cb850dc..ebf26b4 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -28,19 +28,15 @@
static FILE *_log_file;
static char _log_file_path[PATH_MAX];
-static struct device _log_dev;
-static struct dm_str_list _log_dev_alias;
static int _syslog = 0;
static int _log_to_file = 0;
static uint64_t _log_file_max_lines = 0;
static uint64_t _log_file_lines = 0;
-static int _log_direct = 0;
static int _log_while_suspended = 0;
static int _indent = 0;
static int _log_suppress = 0;
static char _msg_prefix[30] = " ";
-static int _already_logging = 0;
static int _abort_on_internal_errors_config = 0;
static uint32_t _debug_file_fields;
static uint32_t _debug_output_fields;
@@ -309,17 +305,6 @@ void unlink_log_file(int ret)
}
}
-void init_log_direct(const char *log_file, int append)
-{
- int open_flags = append ? 0 : O_TRUNC;
-
- dev_create_file(log_file, &_log_dev, &_log_dev_alias, 1);
- if (!dev_open_flags(&_log_dev, O_RDWR | O_CREAT | open_flags, 1, 0))
- return;
-
- _log_direct = 1;
-}
-
void init_log_while_suspended(int log_while_suspended)
{
_log_while_suspended = log_while_suspended;
@@ -343,22 +328,8 @@ int log_suppress(int suppress)
return old_suppress;
}
-void release_log_memory(void)
-{
- if (!_log_direct)
- return;
-
- free((char *) _log_dev_alias.str);
- _log_dev_alias.str = "activate_log file";
-}
-
void fin_log(void)
{
- if (_log_direct) {
- (void) dev_close(&_log_dev);
- _log_direct = 0;
- }
-
if (_log_to_file) {
if (dm_fclose(_log_file)) {
if (errno)
@@ -519,7 +490,7 @@ static void _vprint_log(int level, const char *file, int line, int dm_errno_or_c
char buf[1024], message[4096];
char time_prefix[32] = "";
const char *command_prefix = NULL;
- int bufused, n;
+ int n;
const char *trformat; /* Translated format string */
char *newbuf;
int use_stderr = log_stderr(level);
@@ -749,36 +720,6 @@ static void _vprint_log(int level, const char *file, int line, int dm_errno_or_c
if (fatal_internal_error)
abort();
-
- /* FIXME This code is unfinished - pre-extend & condense. */
- if (!_already_logging && _log_direct && critical_section()) {
- _already_logging = 1;
- memset(&buf, ' ', sizeof(buf));
- bufused = 0;
- if ((n = dm_snprintf(buf, sizeof(buf), "%s:%s %s:%d %s",
- time_prefix, log_command_file(), file, line, _msg_prefix)) == -1)
- goto done;
-
- bufused += n; /* n does not include '\0' */
-
- va_copy(ap, orig_ap);
- n = vsnprintf(buf + bufused, sizeof(buf) - bufused,
- trformat, ap);
- va_end(ap);
-
- if (n < 0)
- goto done;
-
- bufused += n;
- if (n >= (int) sizeof(buf))
- bufused = sizeof(buf) - 1;
- done:
- buf[bufused] = '\n';
- buf[sizeof(buf) - 1] = '\n';
- /* FIXME real size bufused */
- dev_append(&_log_dev, sizeof(buf), DEV_IO_LOG, buf);
- _already_logging = 0;
- }
}
void print_log(int level, const char *file, int line, int dm_errno_or_class,
diff --git a/lib/log/lvm-logging.h b/lib/log/lvm-logging.h
index 8a0c0e5..39108fc 100644
--- a/lib/log/lvm-logging.h
+++ b/lib/log/lvm-logging.h
@@ -53,12 +53,10 @@ void init_debug_output_fields(uint32_t debug_fields);
void init_log_file(const char *log_file, int append);
void unlink_log_file(int ret);
-void init_log_direct(const char *log_file, int append);
void init_log_while_suspended(int log_while_suspended);
void init_abort_on_internal_errors(int fatal);
void fin_log(void);
-void release_log_memory(void);
void reset_log_duplicated(void);
void init_syslog(int facility);
4 years, 9 months
stable-2.02 - pvscan.service.in: Move StartLimitInterval to Service section
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=675b94a11b6e76b241b...
Commit: 675b94a11b6e76b241bf84db2c4e318a9658c394
Parent: 850e95f24a86c4487363c6cf43b10c15a86b0c26
Author: Marcos Paulo de Souza <mpdesouza(a)suse.de>
AuthorDate: Thu Feb 28 09:35:40 2019 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Feb 28 09:38:34 2019 -0600
pvscan.service.in: Move StartLimitInterval to Service section
Without this patch, pvscan service file contains StartLimitInterval at
the Unit section, which trigger an error:
Unknown lvalue 'StartLimitInterval' in section 'Unit'
Moving StartLimitInterval to Service section fixes the issue.
Signed-off-by: Marcos Paulo de Souza <mpdesouza(a)suse.de>
---
scripts/lvm2_pvscan_systemd_red_hat@.service.in | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/scripts/lvm2_pvscan_systemd_red_hat@.service.in b/scripts/lvm2_pvscan_systemd_red_hat@.service.in
index 839bfd1..f0bbd46 100644
--- a/scripts/lvm2_pvscan_systemd_red_hat@.service.in
+++ b/scripts/lvm2_pvscan_systemd_red_hat@.service.in
@@ -2,7 +2,6 @@
Description=LVM2 PV scan on device %i
Documentation=man:pvscan(8)
DefaultDependencies=no
-StartLimitInterval=0
BindsTo=dev-block-%i.device
Requires=lvm2-lvmetad.socket
After=lvm2-lvmetad.socket lvm2-lvmetad.service
@@ -14,3 +13,4 @@ Type=oneshot
RemainAfterExit=yes
ExecStart=@SBINDIR@/lvm pvscan --cache --activate ay %i
ExecStop=@SBINDIR@/lvm pvscan --cache %i
+StartLimitInterval=0
4 years, 9 months
master - pvscan service: use StartLimitIntervalSec
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ce79b62bc2fcaddf65e...
Commit: ce79b62bc2fcaddf65e090ec3fef75926cddf82c
Parent: a9eaab6bebe1919b476ec3a4d094a4d6c512920e
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Feb 28 08:50:37 2019 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Thu Feb 28 08:50:37 2019 -0600
pvscan service: use StartLimitIntervalSec
systemd changed the name
---
scripts/lvm2-pvscan.service.in | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/scripts/lvm2-pvscan.service.in b/scripts/lvm2-pvscan.service.in
index 93fe062..09753e8 100644
--- a/scripts/lvm2-pvscan.service.in
+++ b/scripts/lvm2-pvscan.service.in
@@ -2,7 +2,7 @@
Description=LVM event activation on device %i
Documentation=man:pvscan(8)
DefaultDependencies=no
-StartLimitInterval=0
+StartLimitIntervalSec=0
BindsTo=dev-block-%i.device
Before=shutdown.target
Conflicts=shutdown.target
4 years, 9 months
master - Use "cachevol" to refer to cache on a single LV
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=a9eaab6bebe1919b476...
Commit: a9eaab6bebe1919b476ec3a4d094a4d6c512920e
Parent: c8fc18e8bfbf6e81fc26c7cde780711db748f112
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Wed Jan 30 09:55:34 2019 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Wed Feb 27 08:52:34 2019 -0600
Use "cachevol" to refer to cache on a single LV
and "cachepool" to refer to a cache on a cache pool object.
The problem was that the --cachepool option was being used
to refer to both a cache pool object, and to a standard LV
used for caching. This could be somewhat confusing, and it
made it less clear when each kind would be used. By
separating them, it's clear when a cachepool or a cachevol
should be used.
Previously:
- lvm would use the cache pool approach when the user passed
a cache-pool LV to the --cachepool option.
- lvm would use the cache vol approach when the user passed
a standard LV in the --cachepool option.
Now:
- lvm will always use the cache pool approach when the user
uses the --cachepool option.
- lvm will always use the cache vol approach when the user
uses the --cachevol option.
---
lib/activate/dev_manager.c | 14 ++--
lib/activate/dev_manager.h | 4 +-
lib/cache_segtype/cache.c | 10 +-
lib/format_text/flags.c | 2 +-
lib/locking/lvmlockd.c | 2 +-
lib/metadata/cache_manip.c | 32 ++++----
lib/metadata/lv.c | 6 +-
lib/metadata/lv_manip.c | 8 +-
lib/metadata/merge.c | 6 +-
lib/metadata/metadata-exported.h | 10 +-
lib/report/report.c | 8 +-
man/lvmcache.7_main | 83 ++++++++++++++++---
test/shell/cache-single-options.sh | 26 +++---
test/shell/cache-single-thin.sh | 2 +-
test/shell/cache-single-types.sh | 2 +-
test/shell/cache-single-usage.sh | 4 +-
test/shell/writecache.sh | 4 +-
tools/args.h | 5 +-
tools/command-lines.in | 20 +++--
tools/lvchange.c | 2 +-
tools/lvconvert.c | 153 ++++++++++++++++++++++++------------
tools/lvmcmdline.c | 5 +-
tools/tools.h | 5 +-
tools/vgsplit.c | 2 +-
24 files changed, 270 insertions(+), 145 deletions(-)
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index dc570c7..37ce2bf 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -833,7 +833,7 @@ static int _info(struct cmd_context *cmd,
/* FIXME: could we just use dev_manager_info instead of this? */
-int get_cache_single_meta_data(struct cmd_context *cmd,
+int get_cache_vol_meta_data(struct cmd_context *cmd,
struct logical_volume *lv,
struct logical_volume *pool_lv,
struct dm_info *info_meta, struct dm_info *info_data)
@@ -876,7 +876,7 @@ int get_cache_single_meta_data(struct cmd_context *cmd,
* devs?
*/
-int remove_cache_single_meta_data(struct cmd_context *cmd,
+int remove_cache_vol_meta_data(struct cmd_context *cmd,
struct dm_info *info_meta, struct dm_info *info_data)
{
struct dm_tree *dtree;
@@ -2375,7 +2375,7 @@ static int _pool_register_callback(struct dev_manager *dm,
#endif
/* Skip for single-device cache pool */
- if (lv_is_cache(lv) && lv_is_cache_single(first_seg(lv)->pool_lv))
+ if (lv_is_cache(lv) && lv_is_cache_vol(first_seg(lv)->pool_lv))
return 1;
if (!(data = dm_pool_zalloc(dm->mem, sizeof(*data)))) {
@@ -2445,7 +2445,7 @@ static int _add_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
/* Unused cache pool is activated as metadata */
}
- if (lv_is_cache(lv) && lv_is_cache_single(first_seg(lv)->pool_lv) && dm->activation) {
+ if (lv_is_cache(lv) && lv_is_cache_vol(first_seg(lv)->pool_lv) && dm->activation) {
struct logical_volume *pool_lv = first_seg(lv)->pool_lv;
struct lv_segment *lvseg = first_seg(lv);
struct dm_info info_meta;
@@ -2637,7 +2637,7 @@ static int _add_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
return_0;
}
if (seg->pool_lv &&
- (lv_is_cache_pool(seg->pool_lv) || lv_is_cache_single(seg->pool_lv) || dm->track_external_lv_deps) &&
+ (lv_is_cache_pool(seg->pool_lv) || lv_is_cache_vol(seg->pool_lv) || dm->track_external_lv_deps) &&
/* When activating and not origin_only detect linear 'overlay' over pool */
!_add_lv_to_dtree(dm, dtree, seg->pool_lv, dm->activation ? origin_only : 1))
return_0;
@@ -3163,7 +3163,7 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
return 1;
}
- if (lv_is_cache(lv) && lv_is_cache_single(first_seg(lv)->pool_lv)) {
+ if (lv_is_cache(lv) && lv_is_cache_vol(first_seg(lv)->pool_lv)) {
struct logical_volume *pool_lv = first_seg(lv)->pool_lv;
struct lv_segment *lvseg = first_seg(lv);
struct volume_group *vg = lv->vg;
@@ -3414,7 +3414,7 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
!_pool_register_callback(dm, dnode, lv))
return_0;
- if (lv_is_cache(lv) && !lv_is_cache_single(first_seg(lv)->pool_lv) &&
+ if (lv_is_cache(lv) && !lv_is_cache_vol(first_seg(lv)->pool_lv) &&
/* Register callback only for layer activation or non-layered cache LV */
(layer || !lv_layer(lv)) &&
/* Register callback when metadata LV is NOT already active */
diff --git a/lib/activate/dev_manager.h b/lib/activate/dev_manager.h
index 6456991..e8e8ae3 100644
--- a/lib/activate/dev_manager.h
+++ b/lib/activate/dev_manager.h
@@ -107,12 +107,12 @@ int dev_manager_device_uses_vg(struct device *dev,
int dev_manager_remove_dm_major_minor(uint32_t major, uint32_t minor);
-int get_cache_single_meta_data(struct cmd_context *cmd,
+int get_cache_vol_meta_data(struct cmd_context *cmd,
struct logical_volume *lv,
struct logical_volume *pool_lv,
struct dm_info *info_meta, struct dm_info *info_data);
-int remove_cache_single_meta_data(struct cmd_context *cmd,
+int remove_cache_vol_meta_data(struct cmd_context *cmd,
struct dm_info *info_meta, struct dm_info *info_data);
#endif
diff --git a/lib/cache_segtype/cache.c b/lib/cache_segtype/cache.c
index 8a97b30..20a4261 100644
--- a/lib/cache_segtype/cache.c
+++ b/lib/cache_segtype/cache.c
@@ -49,7 +49,7 @@ static void _cache_display(const struct lv_segment *seg)
const struct dm_config_node *n;
const struct lv_segment *setting_seg = NULL;
- if (seg_is_cache(seg) && lv_is_cache_single(seg->pool_lv))
+ if (seg_is_cache(seg) && lv_is_cache_vol(seg->pool_lv))
setting_seg = seg;
else if (seg_is_cache_pool(seg))
@@ -540,7 +540,7 @@ static int _cache_text_import(struct lv_segment *seg,
if (!id_read_format(&seg->data_id, uuid))
return SEG_LOG_ERROR("Couldn't format data_id in");
} else {
- /* Do not call this when LV is cache_single. */
+ /* Do not call this when LV is cache_vol. */
/* load order is unknown, could be cache origin or pool LV, so check for both */
if (!dm_list_empty(&pool_lv->segments))
_fix_missing_defaults(first_seg(pool_lv));
@@ -570,7 +570,7 @@ static int _cache_text_export(const struct lv_segment *seg, struct formatter *f)
if (seg->cleaner_policy)
outf(f, "cleaner = 1");
- if (lv_is_cache_single(seg->pool_lv)) {
+ if (lv_is_cache_vol(seg->pool_lv)) {
outf(f, "metadata_format = " FMTu32, seg->cache_metadata_format);
if (!_settings_text_export(seg, f))
@@ -620,7 +620,7 @@ static int _cache_add_target_line(struct dev_manager *dm,
cache_pool_seg = first_seg(seg->pool_lv);
- if (lv_is_cache_single(seg->pool_lv))
+ if (lv_is_cache_vol(seg->pool_lv))
setting_seg = seg;
else
setting_seg = cache_pool_seg;
@@ -668,7 +668,7 @@ static int _cache_add_target_line(struct dev_manager *dm,
if (!(origin_uuid = build_dm_uuid(mem, seg_lv(seg, 0), NULL)))
return_0;
- if (!lv_is_cache_single(seg->pool_lv)) {
+ if (!lv_is_cache_vol(seg->pool_lv)) {
/* We don't use start/len when using separate data/meta devices. */
if (seg->metadata_len || seg->data_len) {
log_error(INTERNAL_ERROR "LV %s using unsupported ranges with cache pool.",
diff --git a/lib/format_text/flags.c b/lib/format_text/flags.c
index cf5be00..1ae64a2 100644
--- a/lib/format_text/flags.c
+++ b/lib/format_text/flags.c
@@ -72,7 +72,7 @@ static const struct flag _lv_flags[] = {
{LV_ACTIVATION_SKIP, "ACTIVATION_SKIP", COMPATIBLE_FLAG},
{LV_ERROR_WHEN_FULL, "ERROR_WHEN_FULL", COMPATIBLE_FLAG},
{LV_METADATA_FORMAT, "METADATA_FORMAT", SEGTYPE_FLAG},
- {LV_CACHE_SINGLE, "CACHE_SINGLE", STATUS_FLAG},
+ {LV_CACHE_VOL, "CACHE_VOL", STATUS_FLAG},
{LV_NOSCAN, NULL, 0},
{LV_TEMPORARY, NULL, 0},
{POOL_METADATA_SPARE, NULL, 0},
diff --git a/lib/locking/lvmlockd.c b/lib/locking/lvmlockd.c
index 9b2d050..5ecdc64 100644
--- a/lib/locking/lvmlockd.c
+++ b/lib/locking/lvmlockd.c
@@ -2780,7 +2780,7 @@ int lockd_lv_uses_lock(struct logical_volume *lv)
if (lv_is_pool_metadata_spare(lv))
return 0;
- if (lv_is_cache_single(lv))
+ if (lv_is_cache_vol(lv))
return 0;
if (lv_is_cache_pool(lv))
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c
index ee2a5c5..20deda3 100644
--- a/lib/metadata/cache_manip.c
+++ b/lib/metadata/cache_manip.c
@@ -61,7 +61,7 @@ const char *display_cache_mode(const struct lv_segment *seg)
{
const struct lv_segment *setting_seg = NULL;
- if (seg_is_cache(seg) && lv_is_cache_single(seg->pool_lv))
+ if (seg_is_cache(seg) && lv_is_cache_vol(seg->pool_lv))
setting_seg = seg;
else if (seg_is_cache_pool(seg))
@@ -131,7 +131,7 @@ int cache_set_cache_mode(struct lv_segment *seg, cache_mode_t mode)
if (seg_is_cache_pool(seg) && (mode == CACHE_MODE_UNSELECTED))
return 1;
- if (seg_is_cache(seg) && lv_is_cache_single(seg->pool_lv))
+ if (seg_is_cache(seg) && lv_is_cache_vol(seg->pool_lv))
setting_seg = seg;
else if (seg_is_cache_pool(seg))
@@ -337,7 +337,7 @@ int validate_lv_cache_create_pool(const struct logical_volume *pool_lv)
{
struct lv_segment *seg;
- if (!lv_is_cache_pool(pool_lv) && !lv_is_cache_single(pool_lv)) {
+ if (!lv_is_cache_pool(pool_lv) && !lv_is_cache_vol(pool_lv)) {
log_error("Logical volume %s is not a cache pool.",
display_lvname(pool_lv));
return 0;
@@ -559,7 +559,7 @@ int lv_cache_wait_for_clean(struct logical_volume *cache_lv, int *is_clean)
return 1;
}
-static int _lv_detach_cache_single_while_active(struct cmd_context *cmd, struct logical_volume *cache_lv)
+static int _lv_detach_cache_vol_while_active(struct cmd_context *cmd, struct logical_volume *cache_lv)
{
struct lv_segment *cache_seg = first_seg(cache_lv);
struct logical_volume *corigin_lv;
@@ -582,7 +582,7 @@ static int _lv_detach_cache_single_while_active(struct cmd_context *cmd, struct
/*
* This info is needed to remove the cmeta/cdata devs at the end.
*/
- if (!get_cache_single_meta_data(cmd, cache_lv, cache_pool_lv, &info_meta, &info_data)) {
+ if (!get_cache_vol_meta_data(cmd, cache_lv, cache_pool_lv, &info_meta, &info_data)) {
log_error("Failed to get info about cdata/cmeta for %s", display_lvname(cache_pool_lv));
return 0;
}
@@ -604,7 +604,7 @@ static int _lv_detach_cache_single_while_active(struct cmd_context *cmd, struct
return_0;
}
- cache_pool_lv->status &= ~LV_CACHE_SINGLE;
+ cache_pool_lv->status &= ~LV_CACHE_VOL;
if (!remove_layer_from_lv(cache_lv, corigin_lv)) {
log_error("Failed to remove cache layer from %s", display_lvname(cache_lv));
@@ -623,7 +623,7 @@ static int _lv_detach_cache_single_while_active(struct cmd_context *cmd, struct
*/
/* These cmeta/cdata dm devs need to be removed since they are using cache_pool_lv. */
- if (!remove_cache_single_meta_data(cmd, &info_meta, &info_data))
+ if (!remove_cache_vol_meta_data(cmd, &info_meta, &info_data))
log_error("Failed to remove cdata/cmeta devs for %s", display_lvname(cache_pool_lv));
if (!deactivate_lv(cmd, cache_pool_lv))
@@ -652,7 +652,7 @@ static int _lv_detach_cache_single_while_active(struct cmd_context *cmd, struct
return 1;
}
-static int _lv_detach_cache_single_while_inactive(struct cmd_context *cmd, struct logical_volume *cache_lv)
+static int _lv_detach_cache_vol_while_inactive(struct cmd_context *cmd, struct logical_volume *cache_lv)
{
struct lv_segment *cache_seg = first_seg(cache_lv);
struct logical_volume *corigin_lv;
@@ -707,7 +707,7 @@ static int _lv_detach_cache_single_while_inactive(struct cmd_context *cmd, struc
return_0;
}
- cache_pool_lv->status &= ~LV_CACHE_SINGLE;
+ cache_pool_lv->status &= ~LV_CACHE_VOL;
if (!remove_layer_from_lv(cache_lv, corigin_lv)) {
log_error("Failed to remove cache layer from %s", display_lvname(cache_lv));
@@ -724,7 +724,7 @@ static int _lv_detach_cache_single_while_inactive(struct cmd_context *cmd, struc
return 1;
}
-int lv_detach_cache_single(struct logical_volume *cache_lv)
+int lv_detach_cache_vol(struct logical_volume *cache_lv)
{
struct cmd_context *cmd = cache_lv->vg->cmd;
@@ -734,9 +734,9 @@ int lv_detach_cache_single(struct logical_volume *cache_lv)
}
if (lv_is_active(cache_lv))
- return _lv_detach_cache_single_while_active(cmd, cache_lv);
+ return _lv_detach_cache_vol_while_active(cmd, cache_lv);
else
- return _lv_detach_cache_single_while_inactive(cmd, cache_lv);
+ return _lv_detach_cache_vol_while_inactive(cmd, cache_lv);
}
/*
@@ -763,7 +763,7 @@ int lv_cache_remove(struct logical_volume *cache_lv)
return 0;
}
- if (lv_is_cache_single(cache_seg->pool_lv)) {
+ if (lv_is_cache_vol(cache_seg->pool_lv)) {
log_error(INTERNAL_ERROR "Incorrect remove for cache single");
return 0;
}
@@ -952,7 +952,7 @@ int cache_set_policy(struct lv_segment *lvseg, const char *name,
return 1; /* Policy and settings can be selected later when caching LV */
}
- if (seg_is_cache(lvseg) && lv_is_cache_single(lvseg->pool_lv))
+ if (seg_is_cache(lvseg) && lv_is_cache_vol(lvseg->pool_lv))
seg = lvseg;
else if (seg_is_cache_pool(lvseg))
@@ -1128,7 +1128,7 @@ int cache_set_metadata_format(struct lv_segment *seg, cache_metadata_format_t fo
#define ONE_MB_S 2048 /* 1MB in sectors */
#define ONE_GB_S 2097152 /* 1GB in sectors */
-int cache_single_set_params(struct cmd_context *cmd,
+int cache_vol_set_params(struct cmd_context *cmd,
struct logical_volume *cache_lv,
struct logical_volume *pool_lv,
uint64_t poolmetadatasize,
@@ -1428,7 +1428,7 @@ int wipe_cache_pool(struct logical_volume *cache_pool_lv)
int r;
/* Only unused cache-pool could be activated and wiped */
- if ((!lv_is_cache_pool(cache_pool_lv) && !lv_is_cache_single(cache_pool_lv)) ||
+ if ((!lv_is_cache_pool(cache_pool_lv) && !lv_is_cache_vol(cache_pool_lv)) ||
!dm_list_empty(&cache_pool_lv->segs_using_this_lv)) {
log_error(INTERNAL_ERROR "Failed to wipe cache pool for volume %s.",
display_lvname(cache_pool_lv));
diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c
index 0e54323..e8f1fab 100644
--- a/lib/metadata/lv.c
+++ b/lib/metadata/lv.c
@@ -333,7 +333,7 @@ uint64_t lvseg_chunksize(const struct lv_segment *seg)
if (lv_is_cow(seg->lv))
size = (uint64_t) find_snapshot(seg->lv)->chunk_size;
- else if (seg_is_cache(seg) && lv_is_cache_single(seg->pool_lv))
+ else if (seg_is_cache(seg) && lv_is_cache_vol(seg->pool_lv))
size = (uint64_t) seg->chunk_size;
else if (seg_is_pool(seg))
size = (uint64_t) seg->chunk_size;
@@ -941,7 +941,7 @@ uint64_t lv_metadata_size(const struct logical_volume *lv)
if (!(seg = first_seg(lv)))
return 0;
- if (seg_is_cache(seg) && lv_is_cache_single(seg->pool_lv))
+ if (seg_is_cache(seg) && lv_is_cache_vol(seg->pool_lv))
return seg->metadata_len;
if (lv_is_thin_pool(lv) || lv_is_cache_pool(lv))
@@ -1309,7 +1309,7 @@ char *lv_attr_dup_with_info_and_seg_status(struct dm_pool *mem, const struct lv_
if (lv_is_thin_pool(lv) || lv_is_thin_volume(lv))
repstr[6] = 't';
- else if (lv_is_cache_pool(lv) || lv_is_cache_single(lv) || lv_is_cache(lv) || lv_is_cache_origin(lv))
+ else if (lv_is_cache_pool(lv) || lv_is_cache_vol(lv) || lv_is_cache(lv) || lv_is_cache_origin(lv))
repstr[6] = 'C';
else if (lv_is_raid_type(lv))
repstr[6] = 'r';
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 3b08d05..6360241 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -422,7 +422,7 @@ static int _lv_layout_and_role_cache(struct dm_pool *mem,
if (lv_is_cache(lv) &&
!str_list_add_no_dup_check(mem, layout, _lv_type_names[LV_TYPE_CACHE]))
goto_bad;
- else if (lv_is_cache_pool(lv) || lv_is_cache_single(lv)) {
+ else if (lv_is_cache_pool(lv) || lv_is_cache_vol(lv)) {
if (!str_list_add_no_dup_check(mem, layout, _lv_type_names[LV_TYPE_CACHE]) ||
!str_list_add_no_dup_check(mem, layout, _lv_type_names[LV_TYPE_POOL]))
goto_bad;
@@ -4453,7 +4453,7 @@ static int _rename_skip_pools_externals_cb(struct logical_volume *lv, void *data
{
if (lv_is_pool(lv) ||
lv_is_vdo_pool(lv) ||
- lv_is_cache_single(lv) ||
+ lv_is_cache_vol(lv) ||
lv_is_external_origin(lv))
return -1; /* and skip subLVs */
@@ -6225,8 +6225,8 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
if (!lockd_lv(cmd, lock_lv, "ex", LDLV_PERSISTENT))
return_0;
- if (lv_is_cache(lv) && lv_is_cache_single(first_seg(lv)->pool_lv)) {
- if (!lv_detach_cache_single(lv)) {
+ if (lv_is_cache(lv) && lv_is_cache_vol(first_seg(lv)->pool_lv)) {
+ if (!lv_detach_cache_vol(lv)) {
log_error("Failed to detach cache from %s", display_lvname(lv));
return 0;
}
diff --git a/lib/metadata/merge.c b/lib/metadata/merge.c
index d3d1d95..08f8fbe 100644
--- a/lib/metadata/merge.c
+++ b/lib/metadata/merge.c
@@ -364,14 +364,14 @@ static void _check_lv_segment(struct logical_volume *lv, struct lv_segment *seg,
if (!seg->pool_lv) {
seg_error("is missing cache pool LV");
- } else if (!lv_is_cache_pool(seg->pool_lv) && !lv_is_cache_single(seg->pool_lv))
+ } else if (!lv_is_cache_pool(seg->pool_lv) && !lv_is_cache_vol(seg->pool_lv))
seg_error("is not referencing cache pool LV");
} else { /* !cache */
if (seg->cleaner_policy)
seg_error("sets cleaner_policy");
}
- if (lv_is_cache(lv) && seg->pool_lv && lv_is_cache_single(seg->pool_lv)) {
+ if (lv_is_cache(lv) && seg->pool_lv && lv_is_cache_vol(seg->pool_lv)) {
cache_setting_seg = seg;
no_metadata_format = 1;
}
@@ -805,7 +805,7 @@ int check_lv_segments(struct logical_volume *lv, int complete_vg)
if ((seg_count != 1) &&
(lv_is_cache(lv) ||
lv_is_cache_pool(lv) ||
- lv_is_cache_single(lv) ||
+ lv_is_cache_vol(lv) ||
lv_is_raid(lv) ||
lv_is_snapshot(lv) ||
lv_is_thin_pool(lv) ||
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index c76e644..f451140 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -152,7 +152,7 @@
#define LV_VDO_POOL UINT64_C(0x0000000040000000) /* LV - Internal user only */
#define LV_VDO_POOL_DATA UINT64_C(0x8000000000000000) /* LV - Internal user only */
-#define LV_CACHE_SINGLE UINT64_C(0x0010000000000000) /* LV - also a PV flag */
+#define LV_CACHE_VOL UINT64_C(0x0010000000000000) /* LV - also a PV flag */
/* Format features flags */
@@ -248,11 +248,11 @@
#define lv_is_cache(lv) (((lv)->status & CACHE) ? 1 : 0)
#define lv_is_cache_pool(lv) (((lv)->status & CACHE_POOL) ? 1 : 0)
-#define lv_is_cache_single(lv) (((lv)->status & LV_CACHE_SINGLE) ? 1 : 0)
+#define lv_is_cache_vol(lv) (((lv)->status & LV_CACHE_VOL) ? 1 : 0)
#define lv_is_used_cache_pool(lv) (lv_is_cache_pool(lv) && !dm_list_empty(&(lv)->segs_using_this_lv))
#define lv_is_cache_pool_data(lv) (((lv)->status & CACHE_POOL_DATA) ? 1 : 0)
#define lv_is_cache_pool_metadata(lv) (((lv)->status & CACHE_POOL_METADATA) ? 1 : 0)
-#define lv_is_cache_type(lv) (((lv)->status & (CACHE | CACHE_POOL | LV_CACHE_SINGLE | CACHE_POOL_DATA | CACHE_POOL_METADATA)) ? 1 : 0)
+#define lv_is_cache_type(lv) (((lv)->status & (CACHE | CACHE_POOL | LV_CACHE_VOL | CACHE_POOL_DATA | CACHE_POOL_METADATA)) ? 1 : 0)
#define lv_is_pool(lv) (((lv)->status & (CACHE_POOL | THIN_POOL)) ? 1 : 0)
#define lv_is_pool_data(lv) (((lv)->status & (CACHE_POOL_DATA | THIN_POOL_DATA)) ? 1 : 0)
@@ -1254,7 +1254,7 @@ int cache_set_params(struct lv_segment *seg,
cache_mode_t mode,
const char *policy_name,
const struct dm_config_tree *policy_settings);
-int cache_single_set_params(struct cmd_context *cmd,
+int cache_vol_set_params(struct cmd_context *cmd,
struct logical_volume *cache_lv,
struct logical_volume *pool_lv,
uint64_t poolmetadatasize,
@@ -1279,7 +1279,7 @@ struct logical_volume *lv_cache_create(struct logical_volume *pool_lv,
struct logical_volume *origin_lv);
int lv_cache_wait_for_clean(struct logical_volume *cache_lv, int *is_clean);
int lv_cache_remove(struct logical_volume *cache_lv);
-int lv_detach_cache_single(struct logical_volume *cache_lv);
+int lv_detach_cache_vol(struct logical_volume *cache_lv);
int wipe_cache_pool(struct logical_volume *cache_pool_lv);
/* -- metadata/cache_manip.c */
diff --git a/lib/report/report.c b/lib/report/report.c
index ecec0a3..e1150f6 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -1430,7 +1430,7 @@ static int _cache_settings_disp(struct dm_report *rh, struct dm_pool *mem,
struct _str_list_append_baton baton;
struct dm_list dummy_list; /* dummy list to display "nothing" */
- if (seg_is_cache(seg) && lv_is_cache_single(seg->pool_lv))
+ if (seg_is_cache(seg) && lv_is_cache_vol(seg->pool_lv))
setting_seg = seg;
else if (seg_is_cache_pool(seg))
@@ -1568,7 +1568,7 @@ static int _cache_policy_disp(struct dm_report *rh, struct dm_pool *mem,
const struct lv_segment *seg = (const struct lv_segment *) data;
const struct lv_segment *setting_seg = NULL;
- if (seg_is_cache(seg) && lv_is_cache_single(seg->pool_lv))
+ if (seg_is_cache(seg) && lv_is_cache_vol(seg->pool_lv))
setting_seg = seg;
else if (seg_is_cache_pool(seg))
@@ -2753,7 +2753,7 @@ static int _cachemetadataformat_disp(struct dm_report *rh, struct dm_pool *mem,
const struct lv_segment *setting_seg = NULL;
const uint64_t *fmt;
- if (seg_is_cache(seg) && lv_is_cache_single(seg->pool_lv))
+ if (seg_is_cache(seg) && lv_is_cache_vol(seg->pool_lv))
setting_seg = seg;
else if (seg_is_cache_pool(seg))
@@ -3231,7 +3231,7 @@ static int _lvmetadatasize_disp(struct dm_report *rh, struct dm_pool *mem,
const struct logical_volume *lv = (const struct logical_volume *) data;
uint64_t size;
- if (lv_is_cache(lv) && lv_is_cache_single(first_seg(lv)->pool_lv)) {
+ if (lv_is_cache(lv) && lv_is_cache_vol(first_seg(lv)->pool_lv)) {
size = lv_metadata_size(lv);
return _size64_disp(rh, mem, field, &size, private);
}
diff --git a/man/lvmcache.7_main b/man/lvmcache.7_main
index 89a1943..9f3e526 100644
--- a/man/lvmcache.7_main
+++ b/man/lvmcache.7_main
@@ -58,11 +58,15 @@ desired caching type, and specify the fast LV to use:
.nf
using dm-cache:
- $ lvconvert --type cache --cachepool fast vg/main
+ $ lvconvert --type cache --cachevol fast vg/main
-or dm-writecache:
+using dm-writecache:
- $ lvconvert --type writecache --cachepool fast vg/main
+ $ lvconvert --type writecache --cachevol fast vg/main
+
+using dm-cache with a cache pool:
+
+ $ lvconvert --type cache --cachepool fastpool vg/main
.fi
.B 4. Display LVs
@@ -82,7 +86,7 @@ using dm-cache:
main vg Cwi-a-C--- [main_corig] cache main_corig(0)
[main_corig] vg owi-aoC--- linear /dev/slow(0)
-or dm-writecache:
+using dm-writecache:
$ lvs -a -o name,vgname,lvattr,origin,segtype,devices vg
LV VG Attr Origin Type Devices
@@ -110,6 +114,32 @@ attached.
\&
+.SS option args
+
+\&
+
+.B --cachevol
+.I LV
+.br
+
+Pass this option a standard LV. With a cache vol, cache data and metadata
+are contained within the single LV. This is used with dm-writecache or
+dm-cache.
+
+.B --cachepool
+.IR CachePoolLV | LV
+.br
+
+Pass this option a cache pool object. With a cache pool, lvm places cache
+data and cache metadata on different LVs. The two LVs together are called
+a cache pool. This permits specific placement of data and metadata. A
+cache pool is represented as a special type of LV that cannot be used
+directly. (If a standard LV is passed to this option, lvm will first
+convert it to a cache pool by combining it with another LV to use for
+metadata.) This can be used with dm-cache.
+
+\&
+
.SS dm-writecache block size
\&
@@ -145,7 +175,7 @@ Tunable parameters can be passed to the dm-writecache kernel module using
the --cachesettings option when caching is started, e.g.
.nf
-$ lvconvert --type writecache --cachepool fast \\
+$ lvconvert --type writecache --cachevol fast \\
--cachesettings 'high_watermark=N writeback_jobs=N' vg/main
.fi
@@ -201,10 +231,10 @@ Applicable only to persistent memory.
\&
When using dm-cache, the cache metadata and cache data can be stored on
-separate LVs. To do this, a "cache-pool LV" is created, which is a
-special LV that references two sub LVs, one for data and one for metadata.
+separate LVs. To do this, a "cache pool" is created, which is a special
+LV that references two sub LVs, one for data and one for metadata.
-To create a cache-pool LV from two separate LVs:
+To create a cache pool from two separate LVs:
.nf
$ lvcreate -n fastpool -L DataSize vg /dev/fast1
@@ -212,17 +242,17 @@ $ lvcreate -n fastpoolmeta -L MetadataSize vg /dev/fast2
$ lvconvert --type cache-pool --poolmetadata fastpoolmeta vg/fastpool
.fi
-Then use the cache-pool LV to start caching the main LV:
+Then use the cache pool LV to start caching the main LV:
.nf
$ lvconvert --type cache --cachepool fastpool vg/main
.fi
-A variation of the same procedure automatically creates a cache-pool when
+A variation of the same procedure automatically creates a cache pool when
caching is started. To do this, use a standard LV as the --cachepool
(this will hold cache data), and use another standard LV as the
--poolmetadata (this will hold cache metadata). LVM will create a
-cache-pool LV from the two specified LVs, and use the cache-pool to start
+cache pool LV from the two specified LVs, and use the cache pool to start
caching the main LV.
.nf
@@ -257,7 +287,7 @@ mode can be displayed with the cache_mode reporting option:
defines the default cache mode.
.nf
-$ lvconvert --type cache --cachepool fast \\
+$ lvconvert --type cache --cachevol fast \\
--cachemode writethrough vg/main
.nf
@@ -360,9 +390,36 @@ and metadata LVs, each of the sub-LVs can use raid1.)
.nf
$ lvcreate -n main -L Size vg /dev/slow
$ lvcreate --type raid1 -m 1 -n fast -L Size vg /dev/fast1 /dev/fast2
-$ lvconvert --type cache --cachepool fast vg/main
+$ lvconvert --type cache --cachevol fast vg/main
.fi
+.SS dm-cache command shortcut
+
+\&
+
+A single command can be used to create a cache pool and attach that new
+cache pool to a main LV:
+
+.nf
+$ lvcreate --type cache --name Name --size Size VG/LV [PV]
+.fi
+
+In this command, the specified LV already exists, and is the main LV to be
+cached. The command creates a new cache pool with the given name and
+size, using the optionally specified PV (typically an ssd). Then it
+attaches the new cache pool to the existing main LV to begin caching.
+
+(Note: ensure that the specified main LV is a standard LV. If a cache
+pool LV is mistakenly specified, then the command does something
+different.)
+
+(Note: the type option is interpreted differently by this command than by
+normal lvcreate commands in which --type specifies the type of the newly
+created LV. In this case, an LV with type cache-pool is being created,
+and the existing main LV is being converted to type cache.)
+
+\&
+
.SH SEE ALSO
.BR lvm.conf (5),
.BR lvchange (8),
diff --git a/test/shell/cache-single-options.sh b/test/shell/cache-single-options.sh
index d33bc2e..da9cbba 100644
--- a/test/shell/cache-single-options.sh
+++ b/test/shell/cache-single-options.sh
@@ -69,13 +69,13 @@ mount_umount()
#
# 1 shouldn't be used any longer
-not lvconvert --cachemetadataformat 1 -y --type cache --cachepool $lv2 $vg/$lv1
+not lvconvert --cachemetadataformat 1 -y --type cache --cachevol $lv2 $vg/$lv1
# 3 doesn't exist
-not lvconvert --cachemetadataformat 3 -y --type cache --cachepool $lv2 $vg/$lv1
+not lvconvert --cachemetadataformat 3 -y --type cache --cachevol $lv2 $vg/$lv1
# 2 is used by default
-lvconvert -y --type cache --cachepool $lv2 $vg/$lv1
+lvconvert -y --type cache --cachevol $lv2 $vg/$lv1
check lv_field $vg/$lv1 cachemetadataformat "2"
@@ -84,14 +84,14 @@ check lv_field $vg/$lv1 segtype linear
check lv_field $vg/$lv2 segtype linear
# 2 can be set explicitly
-lvconvert --cachemetadataformat 2 -y --type cache --cachepool $lv2 $vg/$lv1
+lvconvert --cachemetadataformat 2 -y --type cache --cachevol $lv2 $vg/$lv1
check lv_field $vg/$lv1 cachemetadataformat "2"
lvconvert --splitcache $vg/$lv1
# "auto" means 2
-lvconvert --cachemetadataformat auto -y --type cache --cachepool $lv2 $vg/$lv1
+lvconvert --cachemetadataformat auto -y --type cache --cachevol $lv2 $vg/$lv1
check lv_field $vg/$lv1 cachemetadataformat "2"
@@ -107,7 +107,7 @@ mount_umount $lv1
# Test --poolmetadatasize
#
-lvconvert -y --type cache --cachepool $lv2 --poolmetadatasize 4m $vg/$lv1
+lvconvert -y --type cache --cachevol $lv2 --poolmetadatasize 4m $vg/$lv1
check lv_field $vg/$lv1 lv_metadata_size "4.00m"
@@ -123,7 +123,7 @@ mount_umount $lv1
# Test --chunksize
#
-lvconvert -y --type cache --cachepool $lv2 --chunksize 32k $vg/$lv1
+lvconvert -y --type cache --cachevol $lv2 --chunksize 32k $vg/$lv1
check lv_field $vg/$lv1 chunksize "32.00k"
@@ -139,7 +139,7 @@ mount_umount $lv1
# Test --cachemode
#
-lvconvert -y --type cache --cachepool $lv2 --cachemode writethrough $vg/$lv1
+lvconvert -y --type cache --cachevol $lv2 --cachemode writethrough $vg/$lv1
check lv_field $vg/$lv1 cachemode "writethrough"
@@ -152,7 +152,7 @@ mount_umount $lv1
# FIXME: kernel errors for other cache modes
-#lvconvert -y --type cache --cachepool $lv2 --cachemode passthrough $vg/$lv1
+#lvconvert -y --type cache --cachevol $lv2 --cachemode passthrough $vg/$lv1
#check lv_field $vg/$lv1 cachemode "passthrough"
@@ -164,7 +164,7 @@ mount_umount $lv1
#mount_umount $lv1
-lvconvert -y --type cache --cachepool $lv2 --cachemode writeback $vg/$lv1
+lvconvert -y --type cache --cachevol $lv2 --cachemode writeback $vg/$lv1
check lv_field $vg/$lv1 cachemode "writeback"
@@ -180,7 +180,7 @@ mount_umount $lv1
# Test --cachepolicy
#
-lvconvert -y --type cache --cachepool $lv2 --cachepolicy smq $vg/$lv1
+lvconvert -y --type cache --cachevol $lv2 --cachepolicy smq $vg/$lv1
check lv_field $vg/$lv1 cachepolicy "smq"
@@ -202,7 +202,7 @@ mount_umount $lv1
# (only for mq policy, no settings for smq)
#
-lvconvert -y --type cache --cachepool $lv2 --cachemode writethrough --cachepolicy mq --cachesettings 'migration_threshold = 233 sequential_threshold=13 random_threshold =1' $vg/$lv1
+lvconvert -y --type cache --cachevol $lv2 --cachemode writethrough --cachepolicy mq --cachesettings 'migration_threshold = 233 sequential_threshold=13 random_threshold =1' $vg/$lv1
check lv_field $vg/$lv1 cachemode "writethrough"
check lv_field $vg/$lv1 cachepolicy "mq"
@@ -224,7 +224,7 @@ mount_umount $lv1
# Test lvchange of --cachemode, --cachepolicy, --cachesettings
#
-lvconvert -y --type cache --cachepool $lv2 $vg/$lv1
+lvconvert -y --type cache --cachevol $lv2 $vg/$lv1
lvchange -ay $vg/$lv1
diff --git a/test/shell/cache-single-thin.sh b/test/shell/cache-single-thin.sh
index 33097ca..2547502 100644
--- a/test/shell/cache-single-thin.sh
+++ b/test/shell/cache-single-thin.sh
@@ -30,7 +30,7 @@ vgcreate $SHARED $vg "$dev1" "$dev2" "$dev3" "$dev4" "$dev5"
lvcreate -L10 -an -n $lv1 $vg "$dev1"
lvcreate -L10 -an -n $lv2 $vg "$dev2"
-lvconvert -y --type cache --cachepool $lv2 $vg/$lv1
+lvconvert -y --type cache --cachevol $lv2 $vg/$lv1
lvconvert -y --type thin-pool $vg/$lv1
lvcreate --type thin -V10 -n lvthin --thinpool $vg/$lv1
diff --git a/test/shell/cache-single-types.sh b/test/shell/cache-single-types.sh
index e7c58e2..a973679 100644
--- a/test/shell/cache-single-types.sh
+++ b/test/shell/cache-single-types.sh
@@ -45,7 +45,7 @@ cp pattern1 "$mount_dir/pattern1"
umount "$mount_dir"
lvchange -an $vg/$lv1
-lvconvert -y --type cache --cachepool $lv2 $vg/$lv1
+lvconvert -y --type cache --cachevol $lv2 $vg/$lv1
check lv_field $vg/$lv1 segtype cache
diff --git a/test/shell/cache-single-usage.sh b/test/shell/cache-single-usage.sh
index 63be718..09d5b10 100644
--- a/test/shell/cache-single-usage.sh
+++ b/test/shell/cache-single-usage.sh
@@ -48,7 +48,7 @@ cp pattern1 "$mount_dir/pattern1"
umount "$mount_dir"
lvchange -an $vg/$lv1
-lvconvert -y --type cache --cachepool $lv2 $vg/$lv1
+lvconvert -y --type cache --cachevol $lv2 $vg/$lv1
check lv_field $vg/$lv1 segtype cache
@@ -90,7 +90,7 @@ lvchange -an $vg/$lv2
# test2: create fs on LV after cache is attached
-lvconvert -y --type cache --cachepool $lv2 $vg/$lv1
+lvconvert -y --type cache --cachevol $lv2 $vg/$lv1
check lv_field $vg/$lv1 segtype cache
diff --git a/test/shell/writecache.sh b/test/shell/writecache.sh
index 42c864a..94fa459 100644
--- a/test/shell/writecache.sh
+++ b/test/shell/writecache.sh
@@ -48,7 +48,7 @@ cp pattern1 $mount_dir/pattern1
umount $mount_dir
lvchange -an $vg/$lv1
-lvconvert --yes --type writecache --cachepool $lv2 $vg/$lv1
+lvconvert --yes --type writecache --cachevol $lv2 $vg/$lv1
check lv_field $vg/$lv1 segtype writecache
@@ -90,7 +90,7 @@ lvchange -an $vg/$lv2
# test2: create fs on LV after writecache is attached
-lvconvert --yes --type writecache --cachepool $lv2 $vg/$lv1
+lvconvert --yes --type writecache --cachevol $lv2 $vg/$lv1
check lv_field $vg/$lv1 segtype writecache
diff --git a/tools/args.h b/tools/args.h
index b3ba99e..3d72e8a 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -121,7 +121,10 @@ arg(cachemode_ARG, '\0', "cachemode", cachemode_VAL, 0, 0,
"block invalidates. See \\fBlvmcache\\fP(7) for more information.\n")
arg(cachepool_ARG, '\0', "cachepool", lv_VAL, 0, 0,
- "The name of a cache pool LV.\n")
+ "The name of a cache pool.\n")
+
+arg(cachevol_ARG, '\0', "cachevol", lv_VAL, 0, 0,
+ "The name of a cache volume.\n")
arg(commandprofile_ARG, '\0', "commandprofile", string_VAL, 0, 0,
"The command profile to use for command configuration.\n"
diff --git a/tools/command-lines.in b/tools/command-lines.in
index eaa71ea..bf9d7df 100644
--- a/tools/command-lines.in
+++ b/tools/command-lines.in
@@ -453,30 +453,38 @@ RULE: --poolmetadata not --readahead --stripesize --stripes_long
lvconvert --type cache --cachepool LV LV_linear_striped_raid_thinpool
OO: --cache, OO_LVCONVERT_CACHE, OO_LVCONVERT_POOL, OO_LVCONVERT
-ID: lvconvert_to_cache_vol
-DESC: Attach a cache to an LV, converts the LV to type cache.
+ID: lvconvert_to_cache_with_cachepool
+DESC: Attach a cache pool to an LV, converts the LV to type cache.
RULE: all and lv_is_visible
RULE: --poolmetadata not --readahead --stripesize --stripes_long
# alternate form of lvconvert --type cache
lvconvert --cache --cachepool LV LV_linear_striped_raid_thinpool
OO: --type cache, OO_LVCONVERT_CACHE, OO_LVCONVERT_POOL, OO_LVCONVERT
-ID: lvconvert_to_cache_vol
-DESC: Attach a cache to an LV (infers --type cache).
+ID: lvconvert_to_cache_with_cachepool
+DESC: Attach a cache pool to an LV (infers --type cache).
RULE: all and lv_is_visible
RULE: --poolmetadata not --readahead --stripesize --stripes_long
FLAGS: SECONDARY_SYNTAX
---
-lvconvert --type writecache --cachepool LV LV_linear_striped_raid
+lvconvert --type writecache --cachevol LV LV_linear_striped_raid
OO: OO_LVCONVERT, --cachesettings String
-ID: lvconvert_to_writecache_vol
+ID: lvconvert_to_writecache
DESC: Attach a writecache to an LV, converts the LV to type writecache.
RULE: all and lv_is_visible
---
+lvconvert --type cache --cachevol LV LV_linear_striped_raid_thinpool
+OO: --cache, OO_LVCONVERT_CACHE, OO_LVCONVERT, --poolmetadatasize SizeMB, --chunksize SizeKB
+ID: lvconvert_to_cache_with_cachevol
+DESC: Attach a cache to an LV, converts the LV to type cache.
+RULE: all and lv_is_visible
+
+---
+
lvconvert --type thin-pool LV_linear_striped_raid_cache
OO: --stripes_long Number, --stripesize SizeKB,
--discards Discards, OO_LVCONVERT_POOL, OO_LVCONVERT
diff --git a/tools/lvchange.c b/tools/lvchange.c
index 975e24f..a40bfcf 100644
--- a/tools/lvchange.c
+++ b/tools/lvchange.c
@@ -621,7 +621,7 @@ static int _lvchange_cache(struct cmd_context *cmd,
seg = first_seg(lv);
- if (seg_is_cache(seg) && lv_is_cache_single(seg->pool_lv))
+ if (seg_is_cache(seg) && lv_is_cache_vol(seg->pool_lv))
setting_seg = seg;
else if (seg_is_cache_pool(seg))
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 9fa87c0..cd640ab 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -1847,8 +1847,8 @@ static int _lvconvert_split_and_keep_cache(struct cmd_context *cmd,
if (!archive(lv->vg))
return_0;
- if (lv_is_cache_single(cache_seg->pool_lv)) {
- if (!lv_detach_cache_single(lv))
+ if (lv_is_cache_vol(cache_seg->pool_lv)) {
+ if (!lv_detach_cache_vol(lv))
return_0;
} else {
if (!lv_cache_remove(lv))
@@ -2421,7 +2421,7 @@ static int _lvconvert_cache_repair(struct cmd_context *cmd,
struct logical_volume *pmslv;
struct logical_volume *mlv;
- if (lv_is_cache(cache_lv) && lv_is_cache_single(first_seg(cache_lv)->pool_lv)) {
+ if (lv_is_cache(cache_lv) && lv_is_cache_vol(first_seg(cache_lv)->pool_lv)) {
log_error("Manual repair required.");
return 0;
}
@@ -3354,7 +3354,7 @@ revert_new_lv:
#endif
}
-static int _cache_single_attach(struct cmd_context *cmd,
+static int _cache_vol_attach(struct cmd_context *cmd,
struct logical_volume *lv,
struct logical_volume *lv_fast)
{
@@ -3398,7 +3398,7 @@ static int _cache_single_attach(struct cmd_context *cmd,
if (arg_is_set(cmd, poolmetadatasize_ARG))
poolmetadatasize = arg_uint64_value(cmd, poolmetadatasize_ARG, 0);
- if (!cache_single_set_params(cmd, cache_lv, lv_fast, poolmetadatasize, chunk_size, cache_metadata_format, cache_mode, policy_name, policy_settings))
+ if (!cache_vol_set_params(cmd, cache_lv, lv_fast, poolmetadatasize, chunk_size, cache_metadata_format, cache_mode, policy_name, policy_settings))
goto_out;
/*
@@ -4104,7 +4104,72 @@ int lvconvert_to_pool_cmd(struct cmd_context *cmd, int argc, char **argv)
NULL, NULL, &_lvconvert_to_pool_single);
}
-static int _lvconvert_cache_attach_single(struct cmd_context *cmd,
+static int _lvconvert_cachevol_attach_single(struct cmd_context *cmd,
+ struct logical_volume *lv,
+ struct processing_handle *handle)
+{
+ struct volume_group *vg = lv->vg;
+ struct logical_volume *cachevol_lv;
+ const char *cachevol_name;
+
+ if (!(cachevol_name = arg_str_value(cmd, cachevol_ARG, NULL)))
+ goto_out;
+
+ if (!validate_lvname_param(cmd, &vg->name, &cachevol_name))
+ goto_out;
+
+ if (!(cachevol_lv = find_lv(vg, cachevol_name))) {
+ log_error("Cache single %s not found.", cachevol_name);
+ goto out;
+ }
+
+ /* Ensure the LV is not active elsewhere. */
+ if (!lockd_lv(cmd, lv, "ex", 0))
+ goto_out;
+
+ if (!dm_list_empty(&cachevol_lv->segs_using_this_lv)) {
+ log_error("LV %s is already in use.", display_lvname(cachevol_lv));
+ goto out;
+ }
+
+ if (!arg_is_set(cmd, yes_ARG) &&
+ yes_no_prompt("Erase all existing data on %s? [y/n]: ", display_lvname(cachevol_lv)) == 'n') {
+ log_error("Conversion aborted.");
+ goto out;
+ }
+
+ /* Ensure the LV is not active elsewhere. */
+ if (!lockd_lv(cmd, cachevol_lv, "ex", LDLV_PERSISTENT))
+ goto_out;
+
+ cachevol_lv->status |= LV_CACHE_VOL;
+
+ if (!wipe_cache_pool(cachevol_lv))
+ goto_out;
+
+ /* When the lv arg is a thinpool, redirect command to data sub lv. */
+
+ if (lv_is_thin_pool(lv)) {
+ lv = seg_lv(first_seg(lv), 0);
+ log_verbose("Redirecting operation to data sub LV %s.", display_lvname(lv));
+ }
+
+ if (_raid_split_image_conversion(lv))
+ goto_out;
+
+ /* Attach the cache to the main LV. */
+
+ if (!_cache_vol_attach(cmd, lv, cachevol_lv))
+ goto_out;
+
+ log_print_unless_silent("Logical volume %s is now cached.", display_lvname(lv));
+
+ return ECMD_PROCESSED;
+ out:
+ return ECMD_FAILED;
+}
+
+static int _lvconvert_cachepool_attach_single(struct cmd_context *cmd,
struct logical_volume *lv,
struct processing_handle *handle)
{
@@ -4132,7 +4197,7 @@ static int _lvconvert_cache_attach_single(struct cmd_context *cmd,
* If using an existing cache pool, wipe it.
*/
- if (!lv_is_cache_pool(cachepool_lv) && arg_is_set(cmd, poolmetadata_ARG)) {
+ if (!lv_is_cache_pool(cachepool_lv)) {
int lvt_enum = get_lvt_enum(cachepool_lv);
struct lv_type *lvtype = get_lv_type(lvt_enum);
@@ -4163,28 +4228,6 @@ static int _lvconvert_cache_attach_single(struct cmd_context *cmd,
log_error("LV %s is not a cache pool.", display_lvname(cachepool_lv));
goto out;
}
-
- } else if (!lv_is_cache_pool(cachepool_lv)) {
-
- if (!dm_list_empty(&cachepool_lv->segs_using_this_lv)) {
- log_error("LV %s is already in use.", display_lvname(cachepool_lv));
- goto out;
- }
-
- if (!arg_is_set(cmd, yes_ARG) &&
- yes_no_prompt("Erase all existing data on %s? [y/n]: ", display_lvname(cachepool_lv)) == 'n') {
- log_error("Conversion aborted.");
- goto out;
- }
-
- /* Ensure the LV is not active elsewhere. */
- if (!lockd_lv(cmd, cachepool_lv, "ex", LDLV_PERSISTENT))
- goto_out;
-
- cachepool_lv->status |= LV_CACHE_SINGLE;
-
- if (!wipe_cache_pool(cachepool_lv))
- goto_out;
} else {
if (!dm_list_empty(&cachepool_lv->segs_using_this_lv)) {
log_error("Cache pool %s is already in use.", cachepool_name);
@@ -4225,31 +4268,20 @@ static int _lvconvert_cache_attach_single(struct cmd_context *cmd,
/* Attach the cache to the main LV. */
- if (lv_is_cache_single(cachepool_lv)) {
- if (!_cache_single_attach(cmd, lv, cachepool_lv))
- goto_out;
-
- } else if (lv_is_cache_pool(cachepool_lv)) {
- if (!_cache_pool_attach(cmd, lv, cachepool_lv))
- goto_out;
-
- } else {
- log_error(INTERNAL_ERROR "Invalid cache pool state for %s", cachepool_lv->name);
- goto out;
- }
+ if (!_cache_pool_attach(cmd, lv, cachepool_lv))
+ goto_out;
log_print_unless_silent("Logical volume %s is now cached.", display_lvname(lv));
return ECMD_PROCESSED;
-
out:
return ECMD_FAILED;
}
-int lvconvert_to_cache_vol_cmd(struct cmd_context *cmd, int argc, char **argv)
+int lvconvert_to_cache_with_cachepool_cmd(struct cmd_context *cmd, int argc, char **argv)
{
return process_each_lv(cmd, 1, cmd->position_argv, NULL, NULL, READ_FOR_UPDATE,
- NULL, NULL, &_lvconvert_cache_attach_single);
+ NULL, NULL, &_lvconvert_cachepool_attach_single);
}
static int _lvconvert_to_thin_with_external_single(struct cmd_context *cmd,
@@ -4510,7 +4542,7 @@ static int _lvconvert_detach_writecache(struct cmd_context *cmd,
struct logical_volume *lv,
struct logical_volume *lv_fast);
-static int _lvconvert_split_cache_single(struct cmd_context *cmd,
+static int _lvconvert_split_cache_vol(struct cmd_context *cmd,
struct logical_volume *lv,
struct processing_handle *handle)
{
@@ -4565,7 +4597,7 @@ static int _lvconvert_split_cache_single(struct cmd_context *cmd,
} else if (lv_is_cache(lv_main)) {
if ((cmd->command->command_enum == lvconvert_split_and_remove_cache_CMD) &&
- lv_is_cache_single(lv_fast)) {
+ lv_is_cache_vol(lv_fast)) {
log_error("Detach cache from %s with --splitcache.", display_lvname(lv));
log_error("The cache %s may then be removed with lvremove.", display_lvname(lv_fast));
return 0;
@@ -4600,7 +4632,7 @@ int lvconvert_split_cache_cmd(struct cmd_context *cmd, int argc, char **argv)
}
return process_each_lv(cmd, 1, cmd->position_argv, NULL, NULL, READ_FOR_UPDATE,
- NULL, NULL, &_lvconvert_split_cache_single);
+ NULL, NULL, &_lvconvert_split_cache_vol);
}
static int _lvconvert_raid_types_single(struct cmd_context *cmd, struct logical_volume *lv,
@@ -5453,7 +5485,7 @@ static int _lvconvert_writecache_attach_single(struct cmd_context *cmd,
char *lockd_fast_name = NULL;
struct id lockd_fast_id;
- fast_name = arg_str_value(cmd, cachepool_ARG, "");
+ fast_name = arg_str_value(cmd, cachevol_ARG, "");
if (!(lv_fast = find_lv(vg, fast_name))) {
log_error("LV %s not found.", fast_name);
@@ -5559,7 +5591,7 @@ bad:
}
-int lvconvert_to_writecache_vol_cmd(struct cmd_context *cmd, int argc, char **argv)
+int lvconvert_to_writecache_cmd(struct cmd_context *cmd, int argc, char **argv)
{
struct processing_handle *handle;
struct lvconvert_result lr = { 0 };
@@ -5582,6 +5614,29 @@ int lvconvert_to_writecache_vol_cmd(struct cmd_context *cmd, int argc, char **ar
return ret;
}
+int lvconvert_to_cache_with_cachevol_cmd(struct cmd_context *cmd, int argc, char **argv)
+{
+ struct processing_handle *handle;
+ struct lvconvert_result lr = { 0 };
+ int ret;
+
+ if (!(handle = init_processing_handle(cmd, NULL))) {
+ log_error("Failed to initialize processing handle.");
+ return ECMD_FAILED;
+ }
+
+ handle->custom_handle = &lr;
+
+ cmd->cname->flags &= ~GET_VGNAME_FROM_OPTIONS;
+
+ ret = process_each_lv(cmd, cmd->position_argc, cmd->position_argv, NULL, NULL, READ_FOR_UPDATE, handle, NULL,
+ &_lvconvert_cachevol_attach_single);
+
+ destroy_processing_handle(cmd, handle);
+
+ return ret;
+}
+
/*
* All lvconvert command defs have their own function,
* so the generic function name is unused.
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index b2fb00d..44b7724 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -123,8 +123,9 @@ static const struct command_function _command_functions[CMD_COUNT] = {
{ lvconvert_to_thinpool_CMD, lvconvert_to_pool_cmd },
{ lvconvert_to_cachepool_CMD, lvconvert_to_pool_cmd },
{ lvconvert_to_thin_with_external_CMD, lvconvert_to_thin_with_external_cmd },
- { lvconvert_to_cache_vol_CMD, lvconvert_to_cache_vol_cmd },
- { lvconvert_to_writecache_vol_CMD, lvconvert_to_writecache_vol_cmd },
+ { lvconvert_to_cache_with_cachevol_CMD, lvconvert_to_cache_with_cachevol_cmd },
+ { lvconvert_to_cache_with_cachepool_CMD, lvconvert_to_cache_with_cachepool_cmd },
+ { lvconvert_to_writecache_CMD, lvconvert_to_writecache_cmd },
{ lvconvert_swap_pool_metadata_CMD, lvconvert_swap_pool_metadata_cmd },
{ lvconvert_to_thinpool_or_swap_metadata_CMD, lvconvert_to_pool_or_swap_metadata_cmd },
{ lvconvert_to_cachepool_or_swap_metadata_CMD, lvconvert_to_pool_or_swap_metadata_cmd },
diff --git a/tools/tools.h b/tools/tools.h
index ab9503e..69132a5 100644
--- a/tools/tools.h
+++ b/tools/tools.h
@@ -250,8 +250,9 @@ int lvconvert_combine_split_snapshot_cmd(struct cmd_context *cmd, int argc, char
int lvconvert_start_poll_cmd(struct cmd_context *cmd, int argc, char **argv);
int lvconvert_to_pool_cmd(struct cmd_context *cmd, int argc, char **argv);
-int lvconvert_to_cache_vol_cmd(struct cmd_context *cmd, int argc, char **argv);
-int lvconvert_to_writecache_vol_cmd(struct cmd_context *cmd, int argc, char **argv);
+int lvconvert_to_cache_with_cachevol_cmd(struct cmd_context *cmd, int argc, char **argv);
+int lvconvert_to_cache_with_cachepool_cmd(struct cmd_context *cmd, int argc, char **argv);
+int lvconvert_to_writecache_cmd(struct cmd_context *cmd, int argc, char **argv);
int lvconvert_to_thin_with_external_cmd(struct cmd_context *cmd, int argc, char **argv);
int lvconvert_swap_pool_metadata_cmd(struct cmd_context *cmd, int argc, char **argv);
int lvconvert_to_pool_or_swap_metadata_cmd(struct cmd_context *cmd, int argc, char **argv);
diff --git a/tools/vgsplit.c b/tools/vgsplit.c
index 87f48df..7150570 100644
--- a/tools/vgsplit.c
+++ b/tools/vgsplit.c
@@ -402,7 +402,7 @@ static int _move_cache(struct volume_group *vg_from,
/* NOTREACHED */
- if (lv_is_cache(lv) && lv_is_cache_single(seg->pool_lv)) {
+ if (lv_is_cache(lv) && lv_is_cache_vol(seg->pool_lv)) {
log_error("Cannot split while LV %s has cache attached.", display_lvname(lv));
return 0;
} else if (lv_is_cache(lv)) {
4 years, 9 months
master - config: make hints setting commented
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=c8fc18e8bfbf6e81fc2...
Commit: c8fc18e8bfbf6e81fc26c7cde780711db748f112
Parent: 90149c303e3c0d2d09b14d218924d0bc6c91469d
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Feb 26 15:54:30 2019 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Feb 26 15:54:30 2019 -0600
config: make hints setting commented
---
lib/config/config_settings.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
index c8e629f..fc66117 100644
--- a/lib/config/config_settings.h
+++ b/lib/config/config_settings.h
@@ -255,7 +255,7 @@ cfg(devices_external_device_info_source_CFG, "external_device_info_source", devi
" compiled with udev support.\n"
"#\n")
-cfg(devices_hints_CFG, "hints", devices_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_HINTS, vsn(2, 3, 2), NULL, 0, NULL,
+cfg(devices_hints_CFG, "hints", devices_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_TYPE_STRING, DEFAULT_HINTS, vsn(2, 3, 2), NULL, 0, NULL,
"Use a local file to remember which devices have PVs on them.\n"
"Some commands will use this as an optimization to reduce device\n"
"scanning, and will only scan the listed PVs. Removing the hint file\n"
4 years, 9 months
master - logging: new config settings to specify debug fields
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=90149c303e3c0d2d09b...
Commit: 90149c303e3c0d2d09b14d218924d0bc6c91469d
Parent: 74460f70efca7c8ed76e5980b300668a1a328cc4
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Feb 26 14:31:44 2019 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Feb 26 14:42:16 2019 -0600
logging: new config settings to specify debug fields
For users who do not want all of the fields included
in debug lines, let them specify in lvm.conf which
fields to include. timestamp, command[pid], and
file:line fields can all be disabled.
---
lib/commands/toolcontext.c | 42 +++++++++++++++++++++++++++++++++
lib/config/config_settings.h | 8 ++++++
lib/log/log.c | 52 ++++++++++++++++++++++++++++++++++++-----
lib/log/log.h | 7 +++++
lib/log/lvm-logging.h | 3 ++
5 files changed, 105 insertions(+), 7 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 8abe0df..29c1bd8 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -232,6 +232,45 @@ static void _get_sysfs_dir(struct cmd_context *cmd, char *buf, size_t buf_size)
strncpy(buf, sys_mnt, buf_size);
}
+static uint32_t _parse_debug_fields(struct cmd_context *cmd, int cfg, const char *cfgname)
+{
+ const struct dm_config_node *cn;
+ const struct dm_config_value *cv;
+ uint32_t debug_fields = 0;
+
+ if (!(cn = find_config_tree_array(cmd, cfg, NULL))) {
+ log_error(INTERNAL_ERROR "Unable to find configuration for log/%s.", cfgname);
+ return 0;
+ }
+
+ for (cv = cn->v; cv; cv = cv->next) {
+ if (cv->type != DM_CFG_STRING) {
+ log_verbose("log/%s contains a value which is not a string. Ignoring.", cfgname);
+ continue;
+ }
+
+ if (!strcasecmp(cv->v.str, "all"))
+ return 0;
+
+ if (!strcasecmp(cv->v.str, "time"))
+ debug_fields |= LOG_DEBUG_FIELD_TIME;
+
+ else if (!strcasecmp(cv->v.str, "command"))
+ debug_fields |= LOG_DEBUG_FIELD_COMMAND;
+
+ else if (!strcasecmp(cv->v.str, "fileline"))
+ debug_fields |= LOG_DEBUG_FIELD_FILELINE;
+
+ else if (!strcasecmp(cv->v.str, "message"))
+ debug_fields |= LOG_DEBUG_FIELD_MESSAGE;
+
+ else
+ log_verbose("Unrecognised value for log/%s: %s", cfgname, cv->v.str);
+ }
+
+ return debug_fields;
+}
+
static int _parse_debug_classes(struct cmd_context *cmd)
{
const struct dm_config_node *cn;
@@ -350,6 +389,9 @@ static void _init_logging(struct cmd_context *cmd)
log_debug("Setting log debug classes to %d", cmd->default_settings.debug_classes);
init_debug_classes_logged(cmd->default_settings.debug_classes);
+ init_debug_file_fields(_parse_debug_fields(cmd, log_debug_file_fields_CFG, "debug_file_fields"));
+ init_debug_output_fields(_parse_debug_fields(cmd, log_debug_output_fields_CFG, "debug_output_fields"));
+
t = time(NULL);
ctime_r(&t, &timebuf[0]);
timebuf[24] = '\0';
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
index 0e305e4..c8e629f 100644
--- a/lib/config/config_settings.h
+++ b/lib/config/config_settings.h
@@ -838,6 +838,14 @@ cfg_array(log_debug_classes_CFG, "debug_classes", log_CFG_SECTION, CFG_ALLOW_EMP
"available: memory, devices, io, activation, allocation,\n"
"metadata, cache, locking, lvmpolld. Use \"all\" to see everything.\n")
+cfg_array(log_debug_file_fields_CFG, "debug_file_fields", log_CFG_SECTION, CFG_DEFAULT_COMMENTED | CFG_ADVANCED, CFG_TYPE_STRING, "#Stime#Scommand#Sfileline#Smessage", vsn(2, 3, 2), NULL, 0, NULL,
+ "The fields included in debug output written to log file.\n"
+ "Use \"all\" to include everything (the default).\n")
+
+cfg_array(log_debug_output_fields_CFG, "debug_output_fields", log_CFG_SECTION, CFG_DEFAULT_COMMENTED | CFG_ADVANCED, CFG_TYPE_STRING, "#Stime#Scommand#Sfileline#Smessage", vsn(2, 3, 2), NULL, 0, NULL,
+ "The fields included in debug output written to stderr.\n"
+ "Use \"all\" to include everything (the default).\n")
+
cfg(backup_backup_CFG, "backup", backup_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_BACKUP_ENABLED, vsn(1, 0, 0), NULL, 0, NULL,
"Maintain a backup of the current metadata configuration.\n"
"Think very hard before turning this off!\n")
diff --git a/lib/log/log.c b/lib/log/log.c
index 8cea402..cb850dc 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -42,6 +42,8 @@ static int _log_suppress = 0;
static char _msg_prefix[30] = " ";
static int _already_logging = 0;
static int _abort_on_internal_errors_config = 0;
+static uint32_t _debug_file_fields;
+static uint32_t _debug_output_fields;
static lvm2_log_fn_t _lvm2_log_fn = NULL;
@@ -472,6 +474,16 @@ const char *log_get_report_object_type_name(log_report_object_type_t object_type
return log_object_type_names[object_type];
}
+void init_debug_file_fields(uint32_t debug_fields)
+{
+ _debug_file_fields = debug_fields;
+}
+
+void init_debug_output_fields(uint32_t debug_fields)
+{
+ _debug_output_fields = debug_fields;
+}
+
static void _set_time_prefix(char *prefix, int buflen)
{
@@ -506,6 +518,7 @@ static void _vprint_log(int level, const char *file, int line, int dm_errno_or_c
va_list ap;
char buf[1024], message[4096];
char time_prefix[32] = "";
+ const char *command_prefix = NULL;
int bufused, n;
const char *trformat; /* Translated format string */
char *newbuf;
@@ -629,12 +642,24 @@ static void _vprint_log(int level, const char *file, int line, int dm_errno_or_c
if (verbose_level() > _LOG_DEBUG) {
memset(buf, 0, sizeof(buf));
- if (!time_prefix[0])
- _set_time_prefix(time_prefix, sizeof(time_prefix));
+ if (!_debug_output_fields || (_debug_output_fields & LOG_DEBUG_FIELD_TIME)) {
+ if (!time_prefix[0])
+ _set_time_prefix(time_prefix, sizeof(time_prefix));
+ else
+ time_prefix[0] = '\0';
+ }
- (void) dm_snprintf(buf, sizeof(buf), "%s%s %s:%d",
- time_prefix, log_command_file(), file, line);
+ if (!_debug_output_fields || (_debug_output_fields & LOG_DEBUG_FIELD_COMMAND))
+ command_prefix = log_command_file();
+ else
+ command_prefix = NULL;
+ if (!_debug_output_fields || (_debug_output_fields & LOG_DEBUG_FIELD_FILELINE))
+ (void) dm_snprintf(buf, sizeof(buf), "%s%s %s:%d",
+ time_prefix, command_prefix ?: "", file, line);
+ else
+ (void) dm_snprintf(buf, sizeof(buf), "%s%s",
+ time_prefix, command_prefix ?: "");
} else {
memset(buf, 0, sizeof(buf));
@@ -682,10 +707,23 @@ static void _vprint_log(int level, const char *file, int line, int dm_errno_or_c
}
if (_log_to_file && (_log_while_suspended || !critical_section())) {
- if (!time_prefix[0])
- _set_time_prefix(time_prefix, sizeof(time_prefix));
- fprintf(_log_file, "%s%s %s:%d%s", time_prefix, log_command_file(), file, line, _msg_prefix);
+ if (!_debug_file_fields || (_debug_file_fields & LOG_DEBUG_FIELD_TIME)) {
+ if (!time_prefix[0])
+ _set_time_prefix(time_prefix, sizeof(time_prefix));
+ else
+ time_prefix[0] = '\0';
+ }
+
+ if (!_debug_file_fields || (_debug_file_fields & LOG_DEBUG_FIELD_COMMAND))
+ command_prefix = log_command_file();
+ else
+ command_prefix = NULL;
+
+ if (!_debug_file_fields || (_debug_file_fields & LOG_DEBUG_FIELD_FILELINE))
+ fprintf(_log_file, "%s%s %s:%d%s", time_prefix, command_prefix ?: "", file, line, _msg_prefix);
+ else
+ fprintf(_log_file, "%s%s %s", time_prefix, command_prefix ?: "", _msg_prefix);
va_copy(ap, orig_ap);
vfprintf(_log_file, trformat, ap);
diff --git a/lib/log/log.h b/lib/log/log.h
index 256fed0..d3848a4 100644
--- a/lib/log/log.h
+++ b/lib/log/log.h
@@ -57,6 +57,13 @@
#define INTERNAL_ERROR "Internal error: "
+#define LOG_DEBUG_FIELD_ALL 0x0000
+#define LOG_DEBUG_FIELD_TIME 0x0001
+#define LOG_DEBUG_FIELD_COMMAND 0x0002
+#define LOG_DEBUG_FIELD_FILELINE 0x0004
+#define LOG_DEBUG_FIELD_MESSAGE 0x0008
+
+
/*
* Classes available for debug log messages.
* These are also listed in doc/example.conf
diff --git a/lib/log/lvm-logging.h b/lib/log/lvm-logging.h
index ca93ff4..8a0c0e5 100644
--- a/lib/log/lvm-logging.h
+++ b/lib/log/lvm-logging.h
@@ -48,6 +48,9 @@ void init_log_fn(lvm2_log_fn_t log_fn);
void init_indent(int indent);
void init_msg_prefix(const char *prefix);
+void init_debug_file_fields(uint32_t debug_fields);
+void init_debug_output_fields(uint32_t debug_fields);
+
void init_log_file(const char *log_file, int append);
void unlink_log_file(int ret);
void init_log_direct(const char *log_file, int append);
4 years, 9 months
master - pvscan: fix hint recreation
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=74460f70efca7c8ed76...
Commit: 74460f70efca7c8ed76e5980b300668a1a328cc4
Parent: 9aea6ae956543995b30282c984af5fdad2347f07
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue Feb 26 10:30:11 2019 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Feb 26 10:30:11 2019 -0600
pvscan: fix hint recreation
Restore part of the fix from f0089472e7 that was lost
in the process of backporting 74a388cca1.
---
tools/pvscan.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/tools/pvscan.c b/tools/pvscan.c
index c6f2902..389aafa 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -891,6 +891,9 @@ int pvscan_cache_cmd(struct cmd_context *cmd, int argc, char **argv)
_online_files_remove(_vgs_online_dir);
_online_pvscan_all_devs(cmd, complete_vgnames, NULL);
_unlock_online();
+
+ cmd->pvscan_recreate_hints = 0;
+ cmd->use_hints = 0;
goto activate;
}
4 years, 9 months
master - logging: add command[pid] and timestamp to file and verbose output
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9aea6ae956543995b30...
Commit: 9aea6ae956543995b30282c984af5fdad2347f07
Parent: ccfbd505fea2f259f7c89dc23b020b838363a611
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri Feb 22 12:01:20 2019 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Tue Feb 26 10:03:44 2019 -0600
logging: add command[pid] and timestamp to file and verbose output
Without this, the output from different commands in a single
log file could not be separated.
Change the default "indent" setting to 0 so that the default
debug output does not include variable spaces in the middle
of debug lines.
---
lib/commands/toolcontext.c | 4 +-
lib/commands/toolcontext.h | 1 -
lib/config/config_settings.h | 2 +-
lib/config/defaults.h | 2 +-
lib/log/log.c | 66 +++++++++++++++++++++++++++++++++--------
lib/misc/lvm-globals.c | 44 +++++++++++++++++++++++-----
lib/misc/lvm-globals.h | 4 ++-
tools/lvmcmdline.c | 7 ++--
8 files changed, 100 insertions(+), 30 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 62e21f7..8abe0df 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -320,8 +320,8 @@ static void _init_logging(struct cmd_context *cmd)
cmd->default_settings.msg_prefix = find_config_tree_str_allow_empty(cmd, log_prefix_CFG, NULL);
init_msg_prefix(cmd->default_settings.msg_prefix);
- cmd->default_settings.cmd_name = find_config_tree_bool(cmd, log_command_names_CFG, NULL);
- init_cmd_name(cmd->default_settings.cmd_name);
+ /* so that file and verbose output have a command prefix */
+ init_log_command(0, 0);
/* Test mode */
cmd->default_settings.test =
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index e8ce312..959c153 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -44,7 +44,6 @@ struct config_info {
const char *fmt_name;
const char *dmeventd_executable;
uint64_t unit_factor;
- int cmd_name; /* Show command name? */
mode_t umask;
char unit_type;
char _padding[1];
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
index e15494d..0e305e4 100644
--- a/lib/config/config_settings.h
+++ b/lib/config/config_settings.h
@@ -812,7 +812,7 @@ cfg(log_level_CFG, "level", log_CFG_SECTION, 0, CFG_TYPE_INT, DEFAULT_LOGLEVEL,
"There are 6 syslog-like log levels currently in use: 2 to 7 inclusive.\n"
"7 is the most verbose (LOG_DEBUG).\n")
-cfg(log_indent_CFG, "indent", log_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_INDENT, vsn(1, 0, 0), NULL, 0, NULL,
+cfg(log_indent_CFG, "indent", log_CFG_SECTION, CFG_DEFAULT_COMMENTED, CFG_TYPE_BOOL, DEFAULT_INDENT, vsn(1, 0, 0), NULL, 0, NULL,
"Indent messages according to their severity.\n")
cfg(log_command_names_CFG, "command_names", log_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_CMD_NAME, vsn(1, 0, 0), NULL, 0, NULL,
diff --git a/lib/config/defaults.h b/lib/config/defaults.h
index cb013c6..affb4c9 100644
--- a/lib/config/defaults.h
+++ b/lib/config/defaults.h
@@ -221,7 +221,7 @@
#define DEFAULT_VERBOSE 0
#define DEFAULT_SILENT 0
#define DEFAULT_LOGLEVEL 0
-#define DEFAULT_INDENT 1
+#define DEFAULT_INDENT 0
#define DEFAULT_ABORT_ON_INTERNAL_ERRORS 0
#define DEFAULT_UNITS "r"
#define DEFAULT_SUFFIX 1
diff --git a/lib/log/log.c b/lib/log/log.c
index f6aaa04..8cea402 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -24,6 +24,7 @@
#include <stdarg.h>
#include <syslog.h>
#include <ctype.h>
+#include <time.h>
static FILE *_log_file;
static char _log_file_path[PATH_MAX];
@@ -36,7 +37,7 @@ static uint64_t _log_file_max_lines = 0;
static uint64_t _log_file_lines = 0;
static int _log_direct = 0;
static int _log_while_suspended = 0;
-static int _indent = 1;
+static int _indent = 0;
static int _log_suppress = 0;
static char _msg_prefix[30] = " ";
static int _already_logging = 0;
@@ -471,12 +472,40 @@ const char *log_get_report_object_type_name(log_report_object_type_t object_type
return log_object_type_names[object_type];
}
+static void _set_time_prefix(char *prefix, int buflen)
+{
+
+ struct timespec ts;
+ struct tm time_info;
+ int len;
+
+ if (clock_gettime(CLOCK_REALTIME, &ts) < 0)
+ goto fail;
+
+ if (!localtime_r(&ts.tv_sec, &time_info))
+ goto fail;
+
+ len = strftime(prefix, buflen, "%H:%M:%S", &time_info);
+ if (!len)
+ goto fail;
+
+ len = dm_snprintf(prefix + len, buflen - len, ".%ld ", ts.tv_nsec/1000);
+ if (len < 0)
+ goto fail;
+
+ return;
+
+fail:
+ *prefix = '\0';
+}
+
__attribute__ ((format(printf, 5, 0)))
static void _vprint_log(int level, const char *file, int line, int dm_errno_or_class,
const char *format, va_list orig_ap)
{
va_list ap;
char buf[1024], message[4096];
+ char time_prefix[32] = "";
int bufused, n;
const char *trformat; /* Translated format string */
char *newbuf;
@@ -598,10 +627,21 @@ static void _vprint_log(int level, const char *file, int line, int dm_errno_or_c
log_it:
if (!logged_via_report && ((verbose_level() >= level) && !_log_suppress)) {
if (verbose_level() > _LOG_DEBUG) {
- (void) dm_snprintf(buf, sizeof(buf), "#%s:%-5d ",
- file, line);
- } else
- buf[0] = '\0';
+ memset(buf, 0, sizeof(buf));
+
+ if (!time_prefix[0])
+ _set_time_prefix(time_prefix, sizeof(time_prefix));
+
+ (void) dm_snprintf(buf, sizeof(buf), "%s%s %s:%d",
+ time_prefix, log_command_file(), file, line);
+
+ } else {
+ memset(buf, 0, sizeof(buf));
+
+ /* without -vvvv, command[pid] is controlled by config settings */
+
+ (void) dm_snprintf(buf, sizeof(buf), "%s", log_command_info());
+ }
if (_indent)
switch (level) {
@@ -627,8 +667,7 @@ static void _vprint_log(int level, const char *file, int line, int dm_errno_or_c
stream = (use_stderr || (level != _LOG_WARN)) ? err_stream : out_stream;
if (stream == err_stream)
fflush(out_stream);
- fprintf(stream, "%s%s%s%s", buf, log_command_name(),
- _msg_prefix, indent_spaces);
+ fprintf(stream, "%s%s%s", buf, _msg_prefix, indent_spaces);
vfprintf(stream, trformat, ap);
fputc('\n', stream);
}
@@ -643,15 +682,17 @@ static void _vprint_log(int level, const char *file, int line, int dm_errno_or_c
}
if (_log_to_file && (_log_while_suspended || !critical_section())) {
- fprintf(_log_file, "%s:%-5d %s%s", file, line, log_command_name(),
- _msg_prefix);
+ if (!time_prefix[0])
+ _set_time_prefix(time_prefix, sizeof(time_prefix));
+
+ fprintf(_log_file, "%s%s %s:%d%s", time_prefix, log_command_file(), file, line, _msg_prefix);
va_copy(ap, orig_ap);
vfprintf(_log_file, trformat, ap);
va_end(ap);
if (_log_file_max_lines && ++_log_file_lines >= _log_file_max_lines) {
- fprintf(_log_file, "\n%s:%-5d %sAborting. Command has reached limit "
+ fprintf(_log_file, "\n%s:%d %sAborting. Command has reached limit "
"for logged lines (LVM_LOG_FILE_MAX_LINES=" FMTu64 ").",
file, line, _msg_prefix,
_log_file_max_lines);
@@ -676,9 +717,8 @@ static void _vprint_log(int level, const char *file, int line, int dm_errno_or_c
_already_logging = 1;
memset(&buf, ' ', sizeof(buf));
bufused = 0;
- if ((n = dm_snprintf(buf, sizeof(buf),
- "%s:%-5d %s%s", file, line, log_command_name(),
- _msg_prefix)) == -1)
+ if ((n = dm_snprintf(buf, sizeof(buf), "%s:%s %s:%d %s",
+ time_prefix, log_command_file(), file, line, _msg_prefix)) == -1)
goto done;
bufused += n; /* n does not include '\0' */
diff --git a/lib/misc/lvm-globals.c b/lib/misc/lvm-globals.c
index 9d169e7..1ddd2fb 100644
--- a/lib/misc/lvm-globals.c
+++ b/lib/misc/lvm-globals.c
@@ -34,9 +34,10 @@ static enum dev_ext_e _external_device_info_source = DEV_EXT_NONE;
static int _trust_cache = 0; /* Don't scan when incomplete VGs encountered */
static int _debug_level = 0;
static int _debug_classes_logged = 0;
-static int _log_cmd_name = 0;
static int _security_level = SECURITY_LEVEL;
-static char _cmd_name[30] = "";
+static char _log_command_info[40] = "";
+static char _log_command_file[40] = "";
+static char _cmd_name[30] = "none";
static int _mirror_in_sync = 0;
static int _dmeventd_monitor = DEFAULT_DMEVENTD_MONITOR;
/* When set, disables update of _dmeventd_monitor & _ignore_suspended_devices */
@@ -147,9 +148,34 @@ void init_ignore_lvm_mirrors(int scan)
_ignore_lvm_mirrors = scan;
}
-void init_cmd_name(int status)
+void init_log_command(int log_name, int log_pid)
{
- _log_cmd_name = status;
+ memset(_log_command_info, 0, sizeof(_log_command_info));
+ memset(_log_command_file, 0, sizeof(_log_command_file));
+
+ /*
+ * Always include command name and pid in file and verbose output.
+ */
+
+ (void) dm_snprintf(_log_command_file, sizeof(_log_command_file), "%s[%d]",
+ _cmd_name, getpid());
+
+ /*
+ * This is the prefix that can be configured for each line of stdout.
+ */
+
+ if (!log_name && !log_pid)
+ return;
+
+ else if (log_name && !log_pid)
+ (void) dm_strncpy(_log_command_info, _cmd_name, sizeof(_log_command_info));
+
+ else if (!log_name && log_pid)
+ (void) dm_snprintf(_log_command_info, sizeof(_log_command_info), "%d", getpid());
+
+ else
+ (void) dm_snprintf(_log_command_info, sizeof(_log_command_info), "%s[%d]",
+ _cmd_name, getpid());
}
void init_is_static(unsigned value)
@@ -198,12 +224,14 @@ void set_sysfs_dir_path(const char *path)
(void) dm_strncpy(_sysfs_dir_path, path, sizeof(_sysfs_dir_path));
}
-const char *log_command_name(void)
+const char *log_command_info(void)
{
- if (!_log_cmd_name)
- return "";
+ return _log_command_info;
+}
- return _cmd_name;
+const char *log_command_file(void)
+{
+ return _log_command_file;
}
void init_error_message_produced(int value)
diff --git a/lib/misc/lvm-globals.h b/lib/misc/lvm-globals.h
index 793beca..c69b99a 100644
--- a/lib/misc/lvm-globals.h
+++ b/lib/misc/lvm-globals.h
@@ -36,6 +36,7 @@ void init_trust_cache(int trustcache);
void init_debug(int level);
void init_debug_classes_logged(int classes);
void init_cmd_name(int status);
+void init_log_command(int log_name, int log_pid);
void init_security_level(int level);
void init_mirror_in_sync(int in_sync);
void init_dmeventd_monitor(int reg);
@@ -73,7 +74,8 @@ int mirror_in_sync(void);
int background_polling(void);
int ignore_suspended_devices(void);
int ignore_lvm_mirrors(void);
-const char *log_command_name(void);
+const char *log_command_info(void);
+const char *log_command_file(void);
unsigned is_static(void);
int udev_checking(void);
const char *sysfs_dir_path(void);
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 49a6038..b2fb00d 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -2492,7 +2492,6 @@ static void _apply_current_settings(struct cmd_context *cmd)
init_dmeventd_monitor(DEFAULT_DMEVENTD_MONITOR);
init_msg_prefix(cmd->default_settings.msg_prefix);
- init_cmd_name(cmd->default_settings.cmd_name);
archive_enable(cmd, cmd->current_settings.archive);
backup_enable(cmd, cmd->current_settings.backup);
@@ -2788,6 +2787,10 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
return ECMD_FAILED;
}
+ set_cmd_name(cmd->name);
+
+ init_log_command(find_config_tree_bool(cmd, log_command_names_CFG, NULL), 0);
+
configure_command_option_values(cmd->name);
/* eliminate '-' from all options starting with -- */
@@ -2855,8 +2858,6 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
cmd->position_argc = argc;
cmd->position_argv = argv;
- set_cmd_name(cmd->name);
-
if (arg_is_set(cmd, config_ARG))
if (!override_config_tree_from_string(cmd, arg_str_value(cmd, config_ARG, ""))) {
ret = EINVALID_CMD_LINE;
4 years, 9 months
master - dmsetup: Fix multi-line concise table parsing
by Alasdair Kergon
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ccfbd505fea2f259f7c...
Commit: ccfbd505fea2f259f7c89dc23b020b838363a611
Parent: eff33684f774bb732e66898a65c52163d0987b70
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Mon Feb 25 13:41:51 2019 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Mon Feb 25 13:41:51 2019 +0000
dmsetup: Fix multi-line concise table parsing
Use the correct loop variable within the loop, instead of reusing the
initial value. Table lines after the first don't get terminated in
the right place.
Signed-off-by: Kurt Garloff <kurt(a)garloff.de>
---
libdm/dm-tools/dmsetup.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/libdm/dm-tools/dmsetup.c b/libdm/dm-tools/dmsetup.c
index 2feb419..928b599 100644
--- a/libdm/dm-tools/dmsetup.c
+++ b/libdm/dm-tools/dmsetup.c
@@ -368,7 +368,7 @@ static int _parse_table_lines(struct dm_task *dmt)
do {
/* Identify and terminate each line */
- if ((next_pos = strchr(_table, '\n')))
+ if ((next_pos = strchr(pos, '\n')))
*next_pos++ = '\0';
if (!_parse_line(dmt, pos, "", ++line))
return_0;
4 years, 9 months