master - make: fix subdir order for distclean
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=967b5eb1f3a255...
Commit: 967b5eb1f3a25572448974f882e3bc8ba5d3fb9a
Parent: 847e2856a29c41756cc5bbaf70eb87ea030826f4
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Aug 27 15:39:08 2012 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Aug 27 15:39:08 2012 +0200
make: fix subdir order for distclean
The 'test' subdir needs to be processed before 'tools' subdir
for distclean as all the cmd names are read from 'tools/.commands'
file. Otherwise we'd end up with dangling symlinks in 'tools' subdir.
---
Makefile.in | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/Makefile.in b/Makefile.in
index d957e26..4316190 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -40,9 +40,9 @@ SUBDIRS += scripts
# FIXME Should use intermediate Makefiles here!
ifeq ($(MAKECMDGOALS),distclean)
- SUBDIRS = doc include man scripts \
+ SUBDIRS = doc include man test scripts \
libdaemon lib tools daemons libdm \
- udev po liblvm test \
+ udev po liblvm \
unit-tests/datastruct unit-tests/mm unit-tests/regex
endif
DISTCLEAN_DIRS += lcov_reports*
11 years, 3 months
master - config: require dm_config_create_value for dm_config_node's value
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=847e2856a29c41...
Commit: 847e2856a29c41756cc5bbaf70eb87ea030826f4
Parent: 2a70e98b05603bf8fc59929fd2709fb5d2b859e6
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Aug 27 14:19:30 2012 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Aug 27 14:33:54 2012 +0200
config: require dm_config_create_value for dm_config_node's value
If we were defining a section (which is a node without a value) and
the value was created automatically on dm_config_create_node call,
we were wasting resources as the next step after creating the config
node itself was assigning NULL for the node's value.
The dm_config_node_create + dm_config_create_value sequence should be
used instead for settings and dm_config_node_create alone for sections.
The majority of the code already used the correct sequence. Though
with dm_config_node_create fn creating the value as well, the pool
memory was being trashed this way.
This patch removes the node value initialization on dm_config_create_node
fn call and keeps it for the direct dm_config_create_value fn call.
---
WHATS_NEW_DM | 1 +
daemons/lvmetad/lvmetad-core.c | 7 +++++++
libdm/libdm-config.c | 9 ++-------
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index d0e8f7d..c46db61 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.77 -
=================================
+ Don't create value for dm_config_node and require dm_config_create_value call.
Check for existing new_name for dmsetup rename.
Fix memory leak in dmsetup _get_split_name() error path.
diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c
index 3ca3fd5..146ee69 100644
--- a/daemons/lvmetad/lvmetad-core.c
+++ b/daemons/lvmetad/lvmetad-core.c
@@ -520,12 +520,19 @@ static response vg_lookup(lvmetad_state *s, request r)
if (!(res.cft->root = n = dm_config_create_node(res.cft, "response")))
goto bad;
+ if (!(n->v = dm_config_create_value(cft)))
+ goto bad;
+
n->parent = res.cft->root;
n->v->type = DM_CFG_STRING;
n->v->v.str = "OK";
if (!(n = n->sib = dm_config_create_node(res.cft, "name")))
goto bad;
+
+ if (!(n->v = dm_config_create_value(res.cft)))
+ goto bad;
+
n->parent = res.cft->root;
n->v->type = DM_CFG_STRING;
n->v->v.str = name;
diff --git a/libdm/libdm-config.c b/libdm/libdm-config.c
index f8c0954..c19f51d 100644
--- a/libdm/libdm-config.c
+++ b/libdm/libdm-config.c
@@ -1169,14 +1169,9 @@ struct dm_config_node *dm_config_create_node(struct dm_config_tree *cft, const c
log_error("Failed to create config node's key.");
return NULL;
}
- if (!(cn->v = _create_value(cft->mem))) {
- log_error("Failed to create config node's value.");
- return NULL;
- }
cn->parent = NULL;
- cn->v->type = DM_CFG_INT;
- cn->v->v.i = 0;
- cn->v->next = NULL;
+ cn->v = NULL;
+
return cn;
}
11 years, 3 months
master - test: snapshot_extend_threshold -> snapshot_autoextend_threshold
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=2a70e98b05603b...
Commit: 2a70e98b05603bf8fc59929fd2709fb5d2b859e6
Parent: c68c15757384e6cebd7667139661ab643eebbfbe
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Aug 27 14:04:21 2012 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Aug 27 14:04:21 2012 +0200
test: snapshot_extend_threshold -> snapshot_autoextend_threshold
Missing the "auto" prefix in the config key name. The unknown
setting is silently ignored otherwise.
---
test/shell/lvextend-snapshot-dmeventd.sh | 2 +-
test/shell/lvextend-snapshot-policy.sh | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/test/shell/lvextend-snapshot-dmeventd.sh b/test/shell/lvextend-snapshot-dmeventd.sh
index fc3e30a..98bec19 100644
--- a/test/shell/lvextend-snapshot-dmeventd.sh
+++ b/test/shell/lvextend-snapshot-dmeventd.sh
@@ -12,7 +12,7 @@
. lib/test
extend() {
- lvextend --use-policies --config "activation { snapshot_extend_threshold = $1 }" $vg/snap
+ lvextend --use-policies --config "activation { snapshot_autoextend_threshold = $1 }" $vg/snap
}
write_() {
diff --git a/test/shell/lvextend-snapshot-policy.sh b/test/shell/lvextend-snapshot-policy.sh
index f5fdcbe..2f5d84b 100644
--- a/test/shell/lvextend-snapshot-policy.sh
+++ b/test/shell/lvextend-snapshot-policy.sh
@@ -14,7 +14,7 @@
which mkfs.ext2 || skip
extend() {
- lvextend --use-policies --config "activation { snapshot_extend_threshold = $1 }" $vg/snap
+ lvextend --use-policies --config "activation { snapshot_autoextend_threshold = $1 }" $vg/snap
}
write() {
11 years, 3 months
master - setvbuf: reopen only valid fd
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c68c15757384e6...
Commit: c68c15757384e6cebd7667139661ab643eebbfbe
Parent: 5a3c597fd599c21a0bb0c551c92393518d3e70b8
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Aug 27 13:07:07 2012 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Aug 27 13:07:07 2012 +0200
setvbuf: reopen only valid fd
We should check whether the fd is opened before trying to reopen it.
For example, the stdin is closed in test/lib/harness.c causing the
test suite to fail.
---
lib/commands/toolcontext.c | 54 +++++++++++++++++++++++++------------------
lib/misc/lvm-file.h | 2 +
tools/lvmcmdline.c | 2 +-
3 files changed, 34 insertions(+), 24 deletions(-)
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 0ede104..9c2404f 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -1326,21 +1326,25 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
goto out;
}
- if (!_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream))
- goto_out;
- stdin = new_stream;
- if (setvbuf(stdin, cmd->linebuffer, _IOLBF, linebuffer_size)) {
- log_sys_error("setvbuf", "");
- goto out;
+ if (is_valid_fd(STDIN_FILENO)) {
+ if (!_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream))
+ goto_out;
+ stdin = new_stream;
+ if (setvbuf(stdin, cmd->linebuffer, _IOLBF, linebuffer_size)) {
+ log_sys_error("setvbuf", "");
+ goto out;
+ }
}
- if (!_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream))
- goto_out;
- stdout = new_stream;
- if (setvbuf(stdout, cmd->linebuffer + linebuffer_size,
- _IOLBF, linebuffer_size)) {
- log_sys_error("setvbuf", "");
- goto out;
+ if (is_valid_fd(STDOUT_FILENO)) {
+ if (!_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream))
+ goto_out;
+ stdout = new_stream;
+ if (setvbuf(stdout, cmd->linebuffer + linebuffer_size,
+ _IOLBF, linebuffer_size)) {
+ log_sys_error("setvbuf", "");
+ goto out;
+ }
}
/* Buffers are used for lines without '\n' */
} else
@@ -1614,17 +1618,21 @@ void destroy_toolcontext(struct cmd_context *cmd)
if (cmd->linebuffer) {
/* Reset stream buffering to defaults */
- if (_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream)) {
- stdin = new_stream;
- setlinebuf(stdin);
- } else
- cmd->linebuffer = NULL; /* Leave buffer in place (deliberate leak) */
+ if (is_valid_fd(STDIN_FILENO)) {
+ if (_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream)) {
+ stdin = new_stream;
+ setlinebuf(stdin);
+ } else
+ cmd->linebuffer = NULL; /* Leave buffer in place (deliberate leak) */
+ }
- if (_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream)) {
- stdout = new_stream;
- setlinebuf(stdout);
- } else
- cmd->linebuffer = NULL; /* Leave buffer in place (deliberate leak) */
+ if (is_valid_fd(STDOUT_FILENO)) {
+ if (_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream)) {
+ stdout = new_stream;
+ setlinebuf(stdout);
+ } else
+ cmd->linebuffer = NULL; /* Leave buffer in place (deliberate leak) */
+ }
dm_free(cmd->linebuffer);
}
diff --git a/lib/misc/lvm-file.h b/lib/misc/lvm-file.h
index 07327c3..c23d8ad 100644
--- a/lib/misc/lvm-file.h
+++ b/lib/misc/lvm-file.h
@@ -51,6 +51,8 @@ void fcntl_unlock_file(int lockfd);
((buf1).st_ino == (buf2).st_ino && \
(buf1).st_dev == (buf2).st_dev)
+#define is_valid_fd(fd) (!(fcntl(fd, F_GETFD) == -1 && errno == EBADF))
+
/*
* Close the specified stream, taking care to detect and diagnose any write
* error. If there is an error, use the supplied file name in a diagnostic
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index f3704d6..c5341df 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -1230,7 +1230,7 @@ static void _close_descriptor(int fd, unsigned suppress_warnings,
const char *filename;
/* Ignore bad file descriptors */
- if (fcntl(fd, F_GETFD) == -1 && errno == EBADF)
+ if (!is_valid_fd(fd))
return;
if (!suppress_warnings)
11 years, 3 months
master - tests: testing lvm_lv_rename
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5a3c597fd599c2...
Commit: 5a3c597fd599c21a0bb0c551c92393518d3e70b8
Parent: e52d3167518f5ebbb0296b117a1266874978612f
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Jan 27 23:43:14 2011 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Aug 27 13:03:15 2012 +0200
tests: testing lvm_lv_rename
Test stacking of rename operation within one udev transaction.
---
test/api/Makefile.in | 4 +-
test/api/lvtest.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++
test/api/lvtest.sh | 21 ++++++++++++++++
3 files changed, 87 insertions(+), 2 deletions(-)
diff --git a/test/api/Makefile.in b/test/api/Makefile.in
index 324d00b..58d0a23 100644
--- a/test/api/Makefile.in
+++ b/test/api/Makefile.in
@@ -20,8 +20,8 @@ ifeq ("@APPLIB@", "yes")
TARGETS += test
SOURCES = test.c
-TARGETS += vgtest.t percent.t pe_start.t
-SOURCES2 = vgtest.c percent.c pe_start.c
+TARGETS += vgtest.t percent.t pe_start.t lvtest.t
+SOURCES2 = vgtest.c percent.c pe_start.c lvtest.c
endif
include $(top_builddir)/make.tmpl
diff --git a/test/api/lvtest.c b/test/api/lvtest.c
new file mode 100644
index 0000000..c0fee65
--- /dev/null
+++ b/test/api/lvtest.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
+ *
+ * This file is part of LVM2.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License v.2.1.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#undef NDEBUG
+
+#include "lvm2app.h"
+#include "assert.h"
+
+#define err(args...) \
+ do { fprintf(stderr, args); goto bad; } while (0)
+
+int main(int argc, char *argv[])
+{
+ lvm_t handle;
+ vg_t vg;
+ lv_t lv;
+ int r = -1;
+
+ if (!(handle = lvm_init(NULL)))
+ return -1;
+
+ if (!(vg = lvm_vg_open(handle, argv[1], "w", 0)))
+ err("VG open %s failed.\n", argv[1]);
+
+ if (!(lv = lvm_lv_from_name(vg, "test")))
+ err("LV test not found.\n");
+
+ if (lvm_lv_deactivate(lv))
+ err("LV test deactivation failed.\n");
+
+ if (lvm_lv_activate(lv))
+ err("LV test activation failed.\n");
+
+ if (lvm_lv_activate(lv))
+ err("LV test repeated activation failed.\n");
+
+ if (lvm_lv_rename(lv, "test1"))
+ err("LV test rename to test1 failed.\n");
+
+ if (lvm_lv_rename(lv, "test2"))
+ err("LV test1 rename to test2 failed.\n");
+
+ if (lvm_lv_rename(lv, "test"))
+ err("LV test2 rename to test failed.\n");
+
+ if (lvm_vg_close(vg))
+ err("VG close failed.\n");
+
+ r = 0;
+bad:
+ lvm_quit(handle);
+ return r;
+}
diff --git a/test/api/lvtest.sh b/test/api/lvtest.sh
new file mode 100644
index 0000000..0b7684a
--- /dev/null
+++ b/test/api/lvtest.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+# Copyright (C) 2011 Red Hat, Inc. All rights reserved.
+#
+# This file is part of LVM2.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions
+# of the GNU General Public License v.2.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+. lib/test
+
+aux prepare_vg 1
+
+lvcreate -n test -l 5 $vg
+aux apitest lvtest $vg
+
+check lv_field $vg/test lv_name test
11 years, 3 months
master - lvm2api: extend lvm2api with lvm_lv_rename
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e52d3167518f5e...
Commit: e52d3167518f5ebbb0296b117a1266874978612f
Parent: 92330ba9c8e21451f8406377ae4839f397f369a2
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Jan 27 23:41:32 2011 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Aug 27 13:02:42 2012 +0200
lvm2api: extend lvm2api with lvm_lv_rename
Add support for LV rename.
---
WHATS_NEW | 1 +
liblvm/lvm2app.h | 16 ++++++++++++++++
liblvm/lvm_lv.c | 10 ++++++++++
3 files changed, 27 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 85f8663..28d1908 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.98 -
=================================
+ Add lvm_lv_rename() to lvm2api.
Fix setvbuf code by closing and reopening stream before changing buffer.
Disable private buffering when using liblvm.
When private stdin/stdout buffering is not used always use silent mode.
diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h
index 72c0d79..b758945 100644
--- a/liblvm/lvm2app.h
+++ b/liblvm/lvm2app.h
@@ -1343,6 +1343,22 @@ int lvm_lv_remove_tag(lv_t lv, const char *tag);
*/
struct dm_list *lvm_lv_get_tags(const lv_t lv);
+/**
+ * Rename logical volume to new_name.
+ *
+ * \memberof lv_t
+ *
+ * \param lv
+ * Logical volume handle.
+ *
+ * \param new_name
+ * New name of logical volume.
+ *
+ * \return
+ * 0 (success) or -1 (failure).
+ *
+ */
+int lvm_lv_rename(lv_t lv, const char *new_name);
/**
* Resize logical volume to new_size bytes.
diff --git a/liblvm/lvm_lv.c b/liblvm/lvm_lv.c
index 2d4dc02..d47a857 100644
--- a/liblvm/lvm_lv.c
+++ b/liblvm/lvm_lv.c
@@ -292,6 +292,16 @@ lv_t lvm_lv_from_uuid(vg_t vg, const char *uuid)
}
return NULL;
}
+
+int lvm_lv_rename(lv_t lv, const char *new_name)
+{
+ if (!lv_rename(lv->vg->cmd, lv, new_name)) {
+ log_verbose("LV Rename failed.");
+ return -1;
+ }
+ return 0;
+}
+
int lvm_lv_resize(const lv_t lv, uint64_t new_size)
{
/* FIXME: add lv resize code here */
11 years, 3 months
master - setvbuf: close and reopen stream before change
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=92330ba9c8e214...
Commit: 92330ba9c8e21451f8406377ae4839f397f369a2
Parent: 3acc85caa8d313b8c21e4bef7f84601731e74b2b
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Sun Aug 26 00:19:52 2012 +0100
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Sun Aug 26 00:19:52 2012 +0100
setvbuf: close and reopen stream before change
Fix setvbuf code by closing and reopening stream before changing buffer.
But we need to review what this code is doing embedded inside a library
function rather than the simpler original form being run independently
at the top of main() by tools that need it.
---
WHATS_NEW | 1 +
lib/commands/toolcontext.c | 65 +++++++++++++++++++++++++++++++++++++++----
2 files changed, 60 insertions(+), 6 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index acb158b..85f8663 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.98 -
=================================
+ Fix setvbuf code by closing and reopening stream before changing buffer.
Disable private buffering when using liblvm.
When private stdin/stdout buffering is not used always use silent mode.
Add log/silent to lvm.conf equivalent to -qq.
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 4230624..0ede104 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -1245,6 +1245,37 @@ static void _init_globals(struct cmd_context *cmd)
init_mirror_in_sync(0);
}
+/*
+ * Close and reopen stream on file descriptor fd.
+ */
+static int _reopen_stream(FILE *stream, int fd, const char *mode, const char *name, FILE **new_stream)
+{
+ int fd_copy, new_fd;
+
+ if ((fd_copy = dup(fd)) < 0) {
+ log_sys_error("dup", name);
+ return 0;
+ }
+
+ if (fclose(stream))
+ log_sys_error("fclose", name);
+
+ if ((new_fd = dup2(fd_copy, fd)) < 0)
+ log_sys_error("dup2", name);
+ else if (new_fd != fd)
+ log_error("dup2(%d, %d) returned %d", fd_copy, fd, new_fd);
+
+ if (close(fd_copy) < 0)
+ log_sys_error("close", name);
+
+ if (!(*new_stream = fdopen(fd, mode))) {
+ log_sys_error("fdopen", name);
+ return 0;
+ }
+
+ return 1;
+}
+
/* Entry point */
struct cmd_context *create_toolcontext(unsigned is_long_lived,
const char *system_dir,
@@ -1252,6 +1283,7 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
unsigned threaded)
{
struct cmd_context *cmd;
+ FILE *new_stream;
#ifdef M_MMAP_MAX
mallopt(M_MMAP_MAX, 0);
@@ -1293,9 +1325,20 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
log_error("Failed to allocate line buffer.");
goto out;
}
- if ((setvbuf(stdin, cmd->linebuffer, _IOLBF, linebuffer_size) ||
- setvbuf(stdout, cmd->linebuffer + linebuffer_size,
- _IOLBF, linebuffer_size))) {
+
+ if (!_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream))
+ goto_out;
+ stdin = new_stream;
+ if (setvbuf(stdin, cmd->linebuffer, _IOLBF, linebuffer_size)) {
+ log_sys_error("setvbuf", "");
+ goto out;
+ }
+
+ if (!_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream))
+ goto_out;
+ stdout = new_stream;
+ if (setvbuf(stdout, cmd->linebuffer + linebuffer_size,
+ _IOLBF, linebuffer_size)) {
log_sys_error("setvbuf", "");
goto out;
}
@@ -1546,6 +1589,7 @@ int refresh_toolcontext(struct cmd_context *cmd)
void destroy_toolcontext(struct cmd_context *cmd)
{
struct dm_config_tree *cft_cmdline;
+ FILE *new_stream;
if (cmd->dump_filter)
persistent_filter_dump(cmd->filter, 1);
@@ -1570,9 +1614,18 @@ void destroy_toolcontext(struct cmd_context *cmd)
if (cmd->linebuffer) {
/* Reset stream buffering to defaults */
- setlinebuf(stdin);
- fflush(stdout);
- setlinebuf(stdout);
+ if (_reopen_stream(stdin, STDIN_FILENO, "r", "stdin", &new_stream)) {
+ stdin = new_stream;
+ setlinebuf(stdin);
+ } else
+ cmd->linebuffer = NULL; /* Leave buffer in place (deliberate leak) */
+
+ if (_reopen_stream(stdout, STDOUT_FILENO, "w", "stdout", &new_stream)) {
+ stdout = new_stream;
+ setlinebuf(stdout);
+ } else
+ cmd->linebuffer = NULL; /* Leave buffer in place (deliberate leak) */
+
dm_free(cmd->linebuffer);
}
11 years, 3 months
master - buffering: use unbuffered silent mode for liblvm
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3acc85caa8d313...
Commit: 3acc85caa8d313b8c21e4bef7f84601731e74b2b
Parent: 438e0050dfed1f8f2d74670a5f7c5e8c8819c777
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Sun Aug 26 00:15:45 2012 +0100
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Sun Aug 26 00:15:45 2012 +0100
buffering: use unbuffered silent mode for liblvm
Disable private buffering when using liblvm.
When private stdin/stdout buffering is not used always use silent
mode.
---
WHATS_NEW | 2 ++
doc/example.conf.in | 2 ++
lib/commands/toolcontext.c | 12 +++++++++---
lib/display/display.c | 9 ++++++++-
lib/metadata/lv_manip.c | 1 +
liblvm/lvm_base.c | 2 +-
6 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 7d070f9..acb158b 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,7 @@
Version 2.02.98 -
=================================
+ Disable private buffering when using liblvm.
+ When private stdin/stdout buffering is not used always use silent mode.
Add log/silent to lvm.conf equivalent to -qq.
Suppress non-essential stdout with -qq.
Switch non-essential log_print messages to log_print_unless_silent.
diff --git a/doc/example.conf.in b/doc/example.conf.in
index 479b74b..8cec63c 100644
--- a/doc/example.conf.in
+++ b/doc/example.conf.in
@@ -241,6 +241,8 @@ log {
# pvs, version, vgcfgrestore -l, vgdisplay, vgs.
# Non-essential messages are shifted from log level 4 to log level 5
# for syslog and lvm2_log_fn purposes.
+ # Any 'yes' or 'no' questions not overridden by other arguments
+ # are suppressed and default to 'no'.
silent = 0
# Should we send log messages through syslog?
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 57667b6..4230624 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -144,8 +144,12 @@ static void _init_logging(struct cmd_context *cmd)
find_config_tree_int(cmd, "log/level", DEFAULT_LOGLEVEL);
init_debug(cmd->default_settings.debug);
- /* Suppress all non-essential stdout? */
- cmd->default_settings.silent =
+ /*
+ * Suppress all non-essential stdout?
+ * -qq can override the default of 0 to 1 later.
+ * Once set to 1, there is no facility to change it back to 0.
+ */
+ cmd->default_settings.silent = silent_mode() ? :
find_config_tree_int(cmd, "log/silent", DEFAULT_SILENT);
init_silent(cmd->default_settings.silent);
@@ -1296,7 +1300,9 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
goto out;
}
/* Buffers are used for lines without '\n' */
- }
+ } else
+ /* Without buffering, must not use stdin/stdout */
+ init_silent(1);
/*
* Environment variable LVM_SYSTEM_DIR overrides this below.
diff --git a/lib/display/display.c b/lib/display/display.c
index 2422b51..b15ff71 100644
--- a/lib/display/display.c
+++ b/lib/display/display.c
@@ -902,11 +902,19 @@ void display_segtypes(const struct cmd_context *cmd)
}
}
+/*
+ * Prompt for y or n from stdin.
+ * Defaults to 'no' in silent mode.
+ * All callers should support --yes and/or --force to override this.
+ */
char yes_no_prompt(const char *prompt, ...)
{
int c = 0, ret = 0;
va_list ap;
+ if (silent_mode())
+ return 'n';
+
sigint_allow();
do {
if (c == '\n' || !c) {
@@ -939,4 +947,3 @@ char yes_no_prompt(const char *prompt, ...)
return ret;
}
-
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index d591b7b..617d4b7 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -2741,6 +2741,7 @@ int lv_extend(struct logical_volume *lv,
log_error("%s/%s is not active."
" Unable to get sync percent.",
lv->vg->name, lv->name);
+ /* FIXME Support --force */
if (yes_no_prompt("Do full resync of extended "
"portion of %s/%s? [y/n]: ",
lv->vg->name, lv->name) == 'y')
diff --git a/liblvm/lvm_base.c b/liblvm/lvm_base.c
index 2f39b46..815151e 100644
--- a/liblvm/lvm_base.c
+++ b/liblvm/lvm_base.c
@@ -37,7 +37,7 @@ lvm_t lvm_init(const char *system_dir)
/* create context */
/* FIXME: split create_toolcontext */
/* FIXME: make all globals configurable */
- cmd = create_toolcontext(0, system_dir, 1, 0);
+ cmd = create_toolcontext(0, system_dir, 0, 0);
if (!cmd)
return NULL;
11 years, 3 months
master - config: add silent mode
by Alasdair Kergon
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=438e0050dfed1f...
Commit: 438e0050dfed1f8f2d74670a5f7c5e8c8819c777
Parent: 4047e4dfb16175daec348bf44032c02181bd4c70
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Sat Aug 25 20:35:48 2012 +0100
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Sat Aug 25 20:35:48 2012 +0100
config: add silent mode
Accept -q as the short form of --quiet.
Suppress non-essential standard output if -q is given twice.
Treat log/silent in lvm.conf as equivalent to -qq.
Review all log_print messages and change some to
log_print_unless_silent.
When silent, the following commands still produce output:
dumpconfig, lvdisplay, lvmdiskscan, lvs, pvck, pvdisplay,
pvs, version, vgcfgrestore -l, vgdisplay, vgs.
[Needs checking.]
Non-essential messages are shifted from log level 4 to log level 5
for syslog and lvm2_log_fn purposes.
---
WHATS_NEW | 6 ++++-
doc/example.conf.in | 9 +++++++
lib/cache/lvmetad.c | 2 +-
lib/commands/toolcontext.c | 5 ++++
lib/commands/toolcontext.h | 1 +
lib/config/defaults.h | 1 +
lib/display/display.c | 2 +-
lib/log/log.h | 1 +
lib/metadata/lv_manip.c | 14 +++++-----
lib/metadata/metadata.c | 10 ++++----
lib/metadata/mirror.c | 4 +-
lib/metadata/raid_manip.c | 13 ++++-----
lib/misc/lvm-globals.c | 13 +++++++++-
lib/misc/lvm-globals.h | 2 +
man/lvm.8.in | 2 +-
man/lvm.conf.5.in | 6 ++++
tools/args.h | 2 +-
tools/lvchange.c | 2 +-
tools/lvconvert.c | 30 +++++++++++-----------
tools/lvcreate.c | 6 ++--
tools/lvm.c | 1 +
tools/lvmcmdline.c | 6 ++++-
tools/lvrename.c | 4 +-
tools/lvresize.c | 40 +++++++++++++++---------------
tools/lvscan.c | 8 +++---
tools/polldaemon.c | 8 +++---
tools/pvchange.c | 10 ++++----
tools/pvmove.c | 16 ++++++------
tools/pvremove.c | 4 +-
tools/pvresize.c | 6 ++--
tools/pvscan.c | 58 +++++++++++++++++++------------------------
tools/toollib.c | 4 +-
tools/vgcfgbackup.c | 2 +-
tools/vgcfgrestore.c | 2 +-
tools/vgchange.c | 18 +++++++-------
tools/vgconvert.c | 2 +-
tools/vgcreate.c | 4 +-
tools/vgexport.c | 2 +-
tools/vgextend.c | 2 +-
tools/vgimport.c | 2 +-
tools/vgmerge.c | 4 +-
tools/vgreduce.c | 6 ++--
tools/vgrename.c | 4 +-
tools/vgscan.c | 8 +++---
tools/vgsplit.c | 6 ++--
45 files changed, 198 insertions(+), 160 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index c7d5f54..7d070f9 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,9 @@
-Version 2.02.98
+Version 2.02.98 -
=================================
+ Add log/silent to lvm.conf equivalent to -qq.
+ Suppress non-essential stdout with -qq.
+ Switch non-essential log_print messages to log_print_unless_silent.
+ Use -q as short form of --quiet.
Add RAID10 support.
Reuse _reload_lv() in more lvconvert functions.
Fix dereference of NULL in lvmetad error path logging.
diff --git a/doc/example.conf.in b/doc/example.conf.in
index 576397b..479b74b 100644
--- a/doc/example.conf.in
+++ b/doc/example.conf.in
@@ -234,6 +234,15 @@ log {
# There are three levels of verbosity, 3 being the most verbose.
verbose = 0
+ # Set to 1 to suppress all non-essential messages from stdout.
+ # This has the same effect as -qq.
+ # When this is set, the following commands still produce output:
+ # dumpconfig, lvdisplay, lvmdiskscan, lvs, pvck, pvdisplay,
+ # pvs, version, vgcfgrestore -l, vgdisplay, vgs.
+ # Non-essential messages are shifted from log level 4 to log level 5
+ # for syslog and lvm2_log_fn purposes.
+ silent = 0
+
# Should we send log messages through syslog?
# 1 is yes; 0 is no.
syslog = 1
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c
index 6e1759b..feab361 100644
--- a/lib/cache/lvmetad.c
+++ b/lib/cache/lvmetad.c
@@ -710,7 +710,7 @@ int pvscan_lvmetad_single(struct cmd_context *cmd, struct device *dev,
}
if (!label_read(dev, &label, 0)) {
- log_print("No PV label found on %s.", dev_name(dev));
+ log_print_unless_silent("No PV label found on %s.", dev_name(dev));
if (!lvmetad_pv_gone_by_dev(dev, handler))
goto_bad;
return 1;
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 529bd51..57667b6 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -144,6 +144,11 @@ static void _init_logging(struct cmd_context *cmd)
find_config_tree_int(cmd, "log/level", DEFAULT_LOGLEVEL);
init_debug(cmd->default_settings.debug);
+ /* Suppress all non-essential stdout? */
+ cmd->default_settings.silent =
+ find_config_tree_int(cmd, "log/silent", DEFAULT_SILENT);
+ init_silent(cmd->default_settings.silent);
+
/* Verbose level for tty output */
cmd->default_settings.verbose =
find_config_tree_int(cmd, "log/verbose", DEFAULT_VERBOSE);
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index 6fba686..e0ef041 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -27,6 +27,7 @@
struct config_info {
int debug;
int verbose;
+ int silent;
int test;
int syslog;
int activation;
diff --git a/lib/config/defaults.h b/lib/config/defaults.h
index bee3d56..9730a2d 100644
--- a/lib/config/defaults.h
+++ b/lib/config/defaults.h
@@ -111,6 +111,7 @@
#define DEFAULT_SYSLOG 1
#define DEFAULT_VERBOSE 0
+#define DEFAULT_SILENT 0
#define DEFAULT_LOGLEVEL 0
#define DEFAULT_INDENT 1
#define DEFAULT_ABORT_ON_INTERNAL_ERRORS 0
diff --git a/lib/display/display.c b/lib/display/display.c
index 8ceb449..2422b51 100644
--- a/lib/display/display.c
+++ b/lib/display/display.c
@@ -935,7 +935,7 @@ char yes_no_prompt(const char *prompt, ...)
sigint_restore();
if (c != '\n')
- printf("\n");
+ fprintf(stderr, "\n");
return ret;
}
diff --git a/lib/log/log.h b/lib/log/log.h
index 0071a33..f0da64f 100644
--- a/lib/log/log.h
+++ b/lib/log/log.h
@@ -68,6 +68,7 @@
#define log_very_verbose(args...) log_info(args)
#define log_verbose(args...) log_notice(args)
#define log_print(args...) LOG_LINE(_LOG_WARN, args)
+#define log_print_unless_silent(args...) LOG_LINE(silent_mode() ? _LOG_NOTICE : _LOG_WARN, args)
#define log_error(args...) log_err(args)
#define log_error_suppress(s, args...) log_err_suppress(s, args)
#define log_error_once(args...) log_err_once(args)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 59e1429..d591b7b 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -2152,8 +2152,8 @@ int lv_add_virtual_segment(struct logical_volume *lv, uint64_t status,
size = ((uint64_t)lv->vg->extent_size * extents + size - 1) /
size * size / lv->vg->extent_size;
if (size != extents) {
- log_print("Rounding size (%d extents) up to chunk boundary "
- "size (%d extents).", extents, size);
+ log_print_unless_silent("Rounding size (%d extents) up to chunk boundary "
+ "size (%d extents).", extents, size);
extents = size;
}
}
@@ -2738,7 +2738,7 @@ int lv_extend(struct logical_volume *lv,
percent_t sync_percent = PERCENT_INVALID;
if (!lv_is_active(lv)) {
- log_print("%s/%s is not active."
+ log_error("%s/%s is not active."
" Unable to get sync percent.",
lv->vg->name, lv->name);
if (yes_no_prompt("Do full resync of extended "
@@ -3378,7 +3378,7 @@ int lv_remove_single(struct cmd_context *cmd, struct logical_volume *lv,
backup(vg);
if (visible)
- log_print("Logical volume \"%s\" successfully removed", lv->name);
+ log_print_unless_silent("Logical volume \"%s\" successfully removed", lv->name);
return 1;
}
@@ -4207,8 +4207,8 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg, struct l
}
if ((size_rest = lp->extents % lp->stripes)) {
- log_print("Rounding size (%d extents) up to stripe boundary "
- "size (%d extents)", lp->extents,
+ log_print_unless_silent("Rounding size (%d extents) up to stripe boundary "
+ "size (%d extents)", lp->extents,
lp->extents - size_rest + lp->stripes);
lp->extents = lp->extents - size_rest + lp->stripes;
}
@@ -4650,7 +4650,7 @@ int lv_create_single(struct volume_group *vg,
return_0;
out:
- log_print("Logical volume \"%s\" created", lv->name);
+ log_print_unless_silent("Logical volume \"%s\" created", lv->name);
return 1;
}
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 205f77e..220e0c1 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -623,7 +623,7 @@ int vg_remove(struct volume_group *vg)
stack;
if (ret)
- log_print("Volume group \"%s\" successfully removed", vg->name);
+ log_print_unless_silent("Volume group \"%s\" successfully removed", vg->name);
else
log_error("Volume group \"%s\" not properly removed", vg->name);
@@ -988,8 +988,8 @@ uint64_t extents_from_size(struct cmd_context *cmd, uint64_t size,
{
if (size % extent_size) {
size += extent_size - size % extent_size;
- log_print("Rounding up size to full physical extent %s",
- display_size(cmd, size));
+ log_print_unless_silent("Rounding up size to full physical extent %s",
+ display_size(cmd, size));
}
if (size > (uint64_t) MAX_EXTENT_COUNT * extent_size) {
@@ -1305,7 +1305,7 @@ static int _wipe_sb(struct device *dev, const char *type, const char *name,
return 0;
}
- log_print("Wiping %s on %s.", type, name);
+ log_print_unless_silent("Wiping %s on %s.", type, name);
if (!dev_set(dev, superblock, wipe_len, 0)) {
log_error("Failed to wipe %s on %s.", type, name);
return 0;
@@ -1477,7 +1477,7 @@ static int _pvcreate_write(struct cmd_context *cmd, struct pv_to_create *pvc)
return 0;
}
- log_print("Physical volume \"%s\" successfully created", pv_name);
+ log_print_unless_silent("Physical volume \"%s\" successfully created", pv_name);
return 1;
}
diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c
index e3662c1..c4683df 100644
--- a/lib/metadata/mirror.c
+++ b/lib/metadata/mirror.c
@@ -168,8 +168,8 @@ uint32_t adjusted_mirror_region_size(uint32_t extent_size, uint32_t extents,
if (region_max < UINT32_MAX && region_size > region_max) {
region_size = (uint32_t) region_max;
- log_print("Using reduced mirror region size of %" PRIu32
- " sectors", region_size);
+ log_print_unless_silent("Using reduced mirror region size of %" PRIu32
+ " sectors", region_size);
}
return region_size;
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index 0d4640f..1188891 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -1311,8 +1311,8 @@ int lv_raid_split_and_track(struct logical_volume *lv,
return 0;
}
- log_print("%s split from %s for read-only purposes.",
- seg_lv(seg, s)->name, lv->name);
+ log_print_unless_silent("%s split from %s for read-only purposes.",
+ seg_lv(seg, s)->name, lv->name);
/* Resume original LV */
if (!resume_lv(lv->vg->cmd, lv)) {
@@ -1325,8 +1325,8 @@ int lv_raid_split_and_track(struct logical_volume *lv,
if (!_activate_sublv_preserving_excl(lv, seg_lv(seg, s)))
return 0;
- log_print("Use 'lvconvert --merge %s/%s' to merge back into %s",
- lv->vg->name, seg_lv(seg, s)->name, lv->name);
+ log_print_unless_silent("Use 'lvconvert --merge %s/%s' to merge back into %s",
+ lv->vg->name, seg_lv(seg, s)->name, lv->name);
return 1;
}
@@ -1410,9 +1410,8 @@ int lv_raid_merge(struct logical_volume *image_lv)
return 0;
}
- log_print("%s/%s successfully merged back into %s/%s",
- vg->name, image_lv->name,
- vg->name, lv->name);
+ log_print_unless_silent("%s/%s successfully merged back into %s/%s",
+ vg->name, image_lv->name, vg->name, lv->name);
return 1;
}
diff --git a/lib/misc/lvm-globals.c b/lib/misc/lvm-globals.c
index 1c72f85..fe38008 100644
--- a/lib/misc/lvm-globals.c
+++ b/lib/misc/lvm-globals.c
@@ -23,6 +23,7 @@
#include <stdarg.h>
static int _verbose_level = VERBOSE_BASE_LEVEL;
+static int _silent = 0;
static int _test = 0;
static int _md_filtering = 0;
static int _pvmove = 0;
@@ -54,10 +55,15 @@ void init_verbose(int level)
_verbose_level = level;
}
+void init_silent(int silent)
+{
+ _silent = silent;
+}
+
void init_test(int level)
{
if (!_test && level)
- log_print("Test mode: Metadata will NOT be updated and volumes will not be (de)activated.");
+ log_warn("TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.");
_test = level;
}
@@ -267,6 +273,11 @@ int debug_level(void)
return _debug_level;
}
+int silent_mode(void)
+{
+ return _silent;
+}
+
unsigned is_static(void)
{
return _is_static;
diff --git a/lib/misc/lvm-globals.h b/lib/misc/lvm-globals.h
index 3ffdec4..7fe3288 100644
--- a/lib/misc/lvm-globals.h
+++ b/lib/misc/lvm-globals.h
@@ -21,6 +21,7 @@
#define PV_MIN_SIZE_KB 512
void init_verbose(int level);
+void init_silent(int silent);
void init_test(int level);
void init_md_filtering(int level);
void init_pvmove(int level);
@@ -55,6 +56,7 @@ int full_scan_done(void);
int obtain_device_list_from_udev(void);
int trust_cache(void);
int verbose_level(void);
+int silent_mode(void);
int debug_level(void);
int ignorelockingfailure(void);
int lockingfailed(void);
diff --git a/man/lvm.8.in b/man/lvm.8.in
index a2108ed..2ce0065 100644
--- a/man/lvm.8.in
+++ b/man/lvm.8.in
@@ -165,7 +165,7 @@ Set debug level. Repeat from 1 to 6 times to increase the detail of
messages sent to the log file and/or syslog (if configured).
Overrides config file setting.
.TP
-.B \-\-quiet
+.BR \-q ", " \-\-quiet
Suppress output and log messages.
Overrides \fB\-d\fP and \fB\-v\fP.
.TP
diff --git a/man/lvm.conf.5.in b/man/lvm.conf.5.in
index 47ee9f1..79044fc 100644
--- a/man/lvm.conf.5.in
+++ b/man/lvm.conf.5.in
@@ -226,6 +226,12 @@ is invoked. By default tools append messages to the log file.
\fBverbose\fP \(em Default level (0-3) of messages sent to stdout or stderr.
3 is the most verbose; 0 should produce the least output.
.IP
+\fBsilent\fP \(em Set to 1 to suppress all non-essential tool output.
+When set, display and reporting tools will still write the requested
+device properties to standard output, but messages confirming that
+something was or wasn't changed will be reduced to the 'verbose' level
+and not appear unless -v is supplied.
+.IP
\fBsyslog\fP \(em Set to 1 (the default) to send log messages through syslog.
Turn off by setting to 0. If you set to an integer greater than one,
this is used - unvalidated - as the facility. The default is LOG_USER.
diff --git a/tools/args.h b/tools/args.h
index 796fc51..d436db4 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -18,7 +18,6 @@
*/
/* *INDENT-OFF* */
arg(version_ARG, '\0', "version", NULL, 0)
-arg(quiet_ARG, '\0', "quiet", NULL, 0)
arg(physicalvolumesize_ARG, '\0', "setphysicalvolumesize", size_mb_arg, 0)
arg(ignorelockingfailure_ARG, '\0', "ignorelockingfailure", NULL, 0)
arg(nolocking_ARG, '\0', "nolocking", NULL, 0)
@@ -131,6 +130,7 @@ arg(permission_ARG, 'p', "permission", permission_arg, 0)
arg(maxphysicalvolumes_ARG, 'p', "maxphysicalvolumes", int_arg, 0)
arg(partial_ARG, 'P', "partial", NULL, 0)
arg(physicalvolume_ARG, 'P', "physicalvolume", NULL, 0)
+arg(quiet_ARG, 'q', "quiet", NULL, ARG_COUNTABLE)
arg(readahead_ARG, 'r', "readahead", readahead_arg, 0)
arg(resizefs_ARG, 'r', "resizefs", NULL, 0)
arg(reset_ARG, 'R', "reset", NULL, 0)
diff --git a/tools/lvchange.c b/tools/lvchange.c
index 73a37fd..1f32d5c 100644
--- a/tools/lvchange.c
+++ b/tools/lvchange.c
@@ -784,7 +784,7 @@ static int lvchange_single(struct cmd_context *cmd, struct logical_volume *lv,
}
if (doit)
- log_print("Logical volume \"%s\" changed", lv->name);
+ log_print_unless_silent("Logical volume \"%s\" changed", lv->name);
if (arg_count(cmd, resync_ARG))
if (!lvchange_resync(cmd, lv)) {
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 2bfde24..ddda2f1 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -548,7 +548,7 @@ static int _finish_lvconvert_mirror(struct cmd_context *cmd,
if (!(_reload_lv(cmd, vg, lv)))
return_0;
- log_print("Logical volume %s converted.", lv->name);
+ log_print_unless_silent("Logical volume %s converted.", lv->name);
return 1;
}
@@ -564,7 +564,7 @@ static int _finish_lvconvert_merge(struct cmd_context *cmd,
return 0;
}
- log_print("Merge of snapshot into logical volume %s has finished.", lv->name);
+ log_print_unless_silent("Merge of snapshot into logical volume %s has finished.", lv->name);
if (!lv_remove_single(cmd, snap_seg->cow, DONT_PROMPT)) {
log_error("Could not remove snapshot %s merged into %s.",
snap_seg->cow->name, lv->name);
@@ -593,8 +593,8 @@ static progress_t _poll_merge_progress(struct cmd_context *cmd,
}
if (parms->progress_display)
- log_print("%s: %s: %.1f%%", lv->name, parms->progress_title,
- 100.0 - percent_to_float(percent));
+ log_print_unless_silent("%s: %s: %.1f%%", lv->name, parms->progress_title,
+ 100.0 - percent_to_float(percent));
else
log_verbose("%s: %s: %.1f%%", lv->name, parms->progress_title,
100.0 - percent_to_float(percent));
@@ -1511,7 +1511,7 @@ static int _lvconvert_mirrors(struct cmd_context *cmd,
return 0;
if (!lp->need_polling)
- log_print("Logical volume %s converted.", lv->name);
+ log_print_unless_silent("Logical volume %s converted.", lv->name);
backup(lv->vg);
return 1;
@@ -1638,8 +1638,8 @@ static int lvconvert_raid(struct logical_volume *lv, struct lvconvert_params *lp
return 0;
}
- log_print("Faulty devices in %s/%s successfully"
- " replaced.", lv->vg->name, lv->name);
+ log_print_unless_silent("Faulty devices in %s/%s successfully"
+ " replaced.", lv->vg->name, lv->name);
return 1;
}
@@ -1703,7 +1703,7 @@ static int lvconvert_snapshot(struct cmd_context *cmd,
if (!_reload_lv(cmd, lv->vg, lv))
return_0;
- log_print("Logical volume %s converted to snapshot.", lv->name);
+ log_print_unless_silent("Logical volume %s converted to snapshot.", lv->name);
return 1;
}
@@ -1747,7 +1747,7 @@ static int lvconvert_merge(struct cmd_context *cmd,
}
if (lv_info(cmd, lv, 0, &info, 1, 0)) {
if (info.open_count) {
- log_print("Can't merge when snapshot is open");
+ log_print_unless_silent("Can't merge when snapshot is open");
merge_on_activate = 1;
}
}
@@ -1763,8 +1763,8 @@ static int lvconvert_merge(struct cmd_context *cmd,
if (!vg_commit(lv->vg))
return_0;
r = 1;
- log_print("Merging of snapshot %s will start "
- "next activation.", lv->name);
+ log_print_unless_silent("Merging of snapshot %s will start "
+ "next activation.", lv->name);
goto out;
}
@@ -1790,7 +1790,7 @@ static int lvconvert_merge(struct cmd_context *cmd,
lp->lv_to_poll = origin;
r = 1;
- log_print("Merging of volume %s started.", lv->name);
+ log_print_unless_silent("Merging of volume %s started.", lv->name);
out:
backup(lv->vg);
return r;
@@ -1892,8 +1892,8 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
if (!vg_write(pool_lv->vg) || !vg_commit(pool_lv->vg))
return_0;
- log_print("Converted %s/%s to thin pool.",
- pool_lv->vg->name, pool_lv->name);
+ log_print_unless_silent("Converted %s/%s to thin pool.",
+ pool_lv->vg->name, pool_lv->name);
if (was_active && !activate_lv(cmd, pool_lv)) {
log_error("Failed to activate pool logical volume %s/%s.",
pool_lv->vg->name, pool_lv->name);
@@ -2065,7 +2065,7 @@ static int poll_logical_volume(struct cmd_context *cmd, struct logical_volume *l
struct lvinfo info;
if (!lv_info(cmd, lv, 0, &info, 0, 0) || !info.exists) {
- log_print("Conversion starts after activation.");
+ log_print_unless_silent("Conversion starts after activation.");
return ECMD_PROCESSED;
}
return lvconvert_poll(cmd, lv, wait_completion ? 0 : 1U);
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index aac8c22..45a117f 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -301,8 +301,8 @@ static int _update_extents_params(struct volume_group *vg,
if ((lcp->percent != PERCENT_NONE) && lp->stripes &&
(size_rest = lp->extents % (lp->stripes * stripesize_extents)) &&
(vg->free_count < lp->extents - size_rest + (lp->stripes * stripesize_extents))) {
- log_print("Rounding size (%d extents) down to stripe boundary "
- "size (%d extents)", lp->extents,
+ log_print_unless_silent("Rounding size (%d extents) down to stripe boundary "
+ "size (%d extents)", lp->extents,
lp->extents - size_rest);
lp->extents = lp->extents - size_rest;
}
@@ -750,7 +750,7 @@ static int _lvcreate_params(struct lvcreate_params *lp,
log_error("--mirrors must be at least 1 with segment type %s.", lp->segtype->name);
return 0;
}
- log_print("Redundant mirrors argument: default is 0");
+ log_print_unless_silent("Redundant mirrors argument: default is 0");
}
if ((lp->mirrors > 2) && !strcmp(lp->segtype->name, "raid10")) {
diff --git a/tools/lvm.c b/tools/lvm.c
index e002a76..425549a 100644
--- a/tools/lvm.c
+++ b/tools/lvm.c
@@ -199,6 +199,7 @@ int lvm_shell(struct cmd_context *cmd, struct cmdline_context *cmdline)
/* EOF */
if (!input) {
+ /* readline sends prompt to stdout */
printf("\n");
break;
}
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index eea874e..f3704d6 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -847,6 +847,9 @@ static int _get_settings(struct cmd_context *cmd)
cmd->current_settings.verbose = 0;
}
+ if (arg_count(cmd, quiet_ARG) > 1)
+ cmd->current_settings.silent = 1;
+
if (arg_count(cmd, test_ARG))
cmd->current_settings.test = arg_count(cmd, test_ARG);
@@ -863,7 +866,7 @@ static int _get_settings(struct cmd_context *cmd)
if (arg_count(cmd, partial_ARG)) {
cmd->partial_activation = 1;
- log_print("Partial mode. Incomplete logical volumes will be processed.");
+ log_warn("PARTIAL MODE. Incomplete logical volumes will be processed.");
}
if (arg_count(cmd, ignorelockingfailure_ARG) || arg_count(cmd, sysinit_ARG))
@@ -966,6 +969,7 @@ static void _apply_settings(struct cmd_context *cmd)
{
init_debug(cmd->current_settings.debug);
init_verbose(cmd->current_settings.verbose + VERBOSE_BASE_LEVEL);
+ init_silent(cmd->current_settings.silent);
init_test(cmd->current_settings.test);
init_full_scan_done(0);
init_mirror_in_sync(0);
diff --git a/tools/lvrename.c b/tools/lvrename.c
index ef67682..3dc21dc 100644
--- a/tools/lvrename.c
+++ b/tools/lvrename.c
@@ -133,8 +133,8 @@ int lvrename(struct cmd_context *cmd, int argc, char **argv)
if (!lv_rename(cmd, lvl->lv, lv_name_new))
goto error;
- log_print("Renamed \"%s\" to \"%s\" in volume group \"%s\"",
- lv_name_old, lv_name_new, vg_name);
+ log_print_unless_silent("Renamed \"%s\" to \"%s\" in volume group \"%s\"",
+ lv_name_old, lv_name_new, vg_name);
r = ECMD_PROCESSED;
error:
diff --git a/tools/lvresize.c b/tools/lvresize.c
index 05041af..5052bfb 100644
--- a/tools/lvresize.c
+++ b/tools/lvresize.c
@@ -466,8 +466,8 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
lp->size += vg->extent_size -
(lp->size % vg->extent_size);
- log_print("Rounding size to boundary between physical extents: %s",
- display_size(cmd, lp->size));
+ log_print_unless_silent("Rounding size to boundary between physical extents: %s",
+ display_size(cmd, lp->size));
}
lp->extents = lp->size / vg->extent_size;
@@ -580,8 +580,8 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
}
if (!arg_count(cmd, mirrors_ARG) && seg_mirrors) {
- log_print("Extending %" PRIu32 " mirror images.",
- seg_mirrors);
+ log_print_unless_silent("Extending %" PRIu32 " mirror images.",
+ seg_mirrors);
lp->mirrors = seg_mirrors;
}
if ((arg_count(cmd, mirrors_ARG) || seg_mirrors) &&
@@ -636,16 +636,16 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
if (!lp->stripe_size && lp->stripes > 1) {
if (seg_stripesize) {
- log_print("Using stripesize of last segment %s",
- display_size(cmd, (uint64_t) seg_stripesize));
+ log_print_unless_silent("Using stripesize of last segment %s",
+ display_size(cmd, (uint64_t) seg_stripesize));
lp->stripe_size = seg_stripesize;
} else {
lp->stripe_size =
find_config_tree_int(cmd,
"metadata/stripesize",
DEFAULT_STRIPESIZE) * 2;
- log_print("Using default stripesize %s",
- display_size(cmd, (uint64_t) lp->stripe_size));
+ log_print_unless_silent("Using default stripesize %s",
+ display_size(cmd, (uint64_t) lp->stripe_size));
}
}
}
@@ -703,16 +703,16 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
!lp->percent ||
(vg->free_count >= (lp->extents - lv->le_count - size_rest +
(lp->stripes * stripesize_extents))))) {
- log_print("Rounding size (%d extents) up to stripe "
- "boundary size for segment (%d extents)",
- lp->extents, lp->extents - size_rest +
- (lp->stripes * stripesize_extents));
+ log_print_unless_silent("Rounding size (%d extents) up to stripe "
+ "boundary size for segment (%d extents)",
+ lp->extents, lp->extents - size_rest +
+ (lp->stripes * stripesize_extents));
lp->extents = lp->extents - size_rest +
(lp->stripes * stripesize_extents);
} else if (size_rest) {
- log_print("Rounding size (%d extents) down to stripe "
- "boundary size for segment (%d extents)",
- lp->extents, lp->extents - size_rest);
+ log_print_unless_silent("Rounding size (%d extents) down to stripe "
+ "boundary size for segment (%d extents)",
+ lp->extents, lp->extents - size_rest);
lp->extents = lp->extents - size_rest;
}
}
@@ -802,10 +802,10 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
return ECMD_FAILED;
}
- log_print("%sing logical volume %s to %s",
- (lp->resize == LV_REDUCE) ? "Reduc" : "Extend",
- lp->lv_name,
- display_size(cmd, (uint64_t) lp->extents * vg->extent_size));
+ log_print_unless_silent("%sing logical volume %s to %s",
+ (lp->resize == LV_REDUCE) ? "Reduc" : "Extend",
+ lp->lv_name,
+ display_size(cmd, (uint64_t) lp->extents * vg->extent_size));
if (lp->resize == LV_REDUCE) {
if (!lv_reduce(lv, lv->le_count - lp->extents)) {
@@ -871,7 +871,7 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
return ECMD_FAILED;
}
- log_print("Logical volume %s successfully resized", lp->lv_name);
+ log_print_unless_silent("Logical volume %s successfully resized", lp->lv_name);
if (lp->resizefs && (lp->resize == LV_EXTEND) &&
!_fsadm_cmd(cmd, vg, lp, FSADM_CMD_RESIZE, NULL)) {
diff --git a/tools/lvscan.c b/tools/lvscan.c
index 753b00d..636ac45 100644
--- a/tools/lvscan.c
+++ b/tools/lvscan.c
@@ -59,10 +59,10 @@ static int lvscan_single(struct cmd_context *cmd, struct logical_volume *lv,
else
snapshot_str = " ";
- log_print("%s%s '%s%s/%s' [%s] %s", active_str, snapshot_str,
- cmd->dev_dir, lv->vg->name, lv->name,
- display_size(cmd, lv->size),
- get_alloc_string(lv->alloc));
+ log_print_unless_silent("%s%s '%s%s/%s' [%s] %s", active_str, snapshot_str,
+ cmd->dev_dir, lv->vg->name, lv->name,
+ display_size(cmd, lv->size),
+ get_alloc_string(lv->alloc));
return ECMD_PROCESSED;
}
diff --git a/tools/polldaemon.c b/tools/polldaemon.c
index f57484e..a9138a1 100644
--- a/tools/polldaemon.c
+++ b/tools/polldaemon.c
@@ -108,8 +108,8 @@ progress_t poll_mirror_progress(struct cmd_context *cmd,
overall_percent = copy_percent(lv);
if (parms->progress_display)
- log_print("%s: %s: %.1f%%", name, parms->progress_title,
- percent_to_float(overall_percent));
+ log_print_unless_silent("%s: %s: %.1f%%", name, parms->progress_title,
+ percent_to_float(overall_percent));
else
log_verbose("%s: %s: %.1f%%", name, parms->progress_title,
percent_to_float(overall_percent));
@@ -213,8 +213,8 @@ static int _wait_for_single_lv(struct cmd_context *cmd, const char *name, const
lv = parms->poll_fns->get_copy_lv(cmd, vg, name, uuid, parms->lv_type);
if (!lv && parms->lv_type == PVMOVE) {
- log_print("%s: no pvmove in progress - already finished or aborted.",
- name);
+ log_print_unless_silent("%s: no pvmove in progress - already finished or aborted.",
+ name);
unlock_and_release_vg(cmd, vg, vg->name);
return 1;
}
diff --git a/tools/pvchange.c b/tools/pvchange.c
index f6d1abd..70f1e62 100644
--- a/tools/pvchange.c
+++ b/tools/pvchange.c
@@ -168,7 +168,7 @@ static int _pvchange_single(struct cmd_context *cmd, struct volume_group *vg,
return 0;
}
- log_print("Physical volume \"%s\" changed", pv_name);
+ log_print_unless_silent("Physical volume \"%s\" changed", pv_name);
return 1;
}
@@ -269,10 +269,10 @@ int pvchange(struct cmd_context *cmd, int argc, char **argv)
unlock_vg(cmd, VG_GLOBAL);
}
- log_print("%d physical volume%s changed / %d physical volume%s "
- "not changed",
- done, done == 1 ? "" : "s",
- total - done, (total - done) == 1 ? "" : "s");
+ log_print_unless_silent("%d physical volume%s changed / %d physical volume%s "
+ "not changed",
+ done, done == 1 ? "" : "s",
+ total - done, (total - done) == 1 ? "" : "s");
return (total == done) ? ECMD_PROCESSED : ECMD_FAILED;
}
diff --git a/tools/pvmove.c b/tools/pvmove.c
index 05ef33c..9649f11 100644
--- a/tools/pvmove.c
+++ b/tools/pvmove.c
@@ -215,35 +215,35 @@ static struct logical_volume *_set_up_pvmove_lv(struct cmd_context *cmd,
}
if (lv_is_origin(lv) || lv_is_cow(lv)) {
lv_skipped = 1;
- log_print("Skipping snapshot-related LV %s", lv->name);
+ log_print_unless_silent("Skipping snapshot-related LV %s", lv->name);
continue;
}
if (lv->status & MIRRORED) {
lv_skipped = 1;
- log_print("Skipping mirror LV %s", lv->name);
+ log_print_unless_silent("Skipping mirror LV %s", lv->name);
continue;
}
if (lv->status & MIRROR_LOG) {
lv_skipped = 1;
- log_print("Skipping mirror log LV %s", lv->name);
+ log_print_unless_silent("Skipping mirror log LV %s", lv->name);
continue;
}
if (lv->status & MIRROR_IMAGE) {
lv_skipped = 1;
- log_print("Skipping mirror image LV %s", lv->name);
+ log_print_unless_silent("Skipping mirror image LV %s", lv->name);
continue;
}
if (lv->status & LOCKED) {
lv_skipped = 1;
- log_print("Skipping locked LV %s", lv->name);
+ log_print_unless_silent("Skipping locked LV %s", lv->name);
continue;
}
if (vg_is_clustered(vg) &&
lv_is_active_exclusive_remotely(lv)) {
lv_skipped = 1;
- log_print("Skipping LV %s which is activated "
- "exclusively on remote node.", lv->name);
+ log_print_unless_silent("Skipping LV %s which is activated "
+ "exclusively on remote node.", lv->name);
continue;
}
@@ -512,7 +512,7 @@ static int _set_up_pvmove(struct cmd_context *cmd, const char *pv_name,
exclusive = _pvmove_is_exclusive(cmd, vg);
if ((lv_mirr = find_pvmove_lv(vg, pv_dev(pv), PVMOVE))) {
- log_print("Detected pvmove in progress for %s", pv_name);
+ log_print_unless_silent("Detected pvmove in progress for %s", pv_name);
if (argc || lv_name)
log_error("Ignoring remaining command line arguments");
diff --git a/tools/pvremove.c b/tools/pvremove.c
index 7d05758..823c069 100644
--- a/tools/pvremove.c
+++ b/tools/pvremove.c
@@ -131,8 +131,8 @@ static int pvremove_single(struct cmd_context *cmd, const char *pv_name,
if (!lvmetad_pv_gone_by_dev(dev, NULL))
goto_out;
- log_print("Labels on physical volume \"%s\" successfully wiped",
- pv_name);
+ log_print_unless_silent("Labels on physical volume \"%s\" successfully wiped",
+ pv_name);
ret = ECMD_PROCESSED;
diff --git a/tools/pvresize.c b/tools/pvresize.c
index ff19811..2f0693a 100644
--- a/tools/pvresize.c
+++ b/tools/pvresize.c
@@ -118,7 +118,7 @@ static int _pv_resize_single(struct cmd_context *cmd,
backup(vg);
}
- log_print("Physical volume \"%s\" changed", pv_name);
+ log_print_unless_silent("Physical volume \"%s\" changed", pv_name);
r = 1;
out:
@@ -176,8 +176,8 @@ int pvresize(struct cmd_context *cmd, int argc, char **argv)
ret = process_each_pv(cmd, argc, argv, NULL, READ_FOR_UPDATE, 0, ¶ms,
_pvresize_single);
- log_print("%d physical volume(s) resized / %d physical volume(s) "
- "not resized", params.done, params.total - params.done);
+ log_print_unless_silent("%d physical volume(s) resized / %d physical volume(s) "
+ "not resized", params.done, params.total - params.done);
return ret;
}
diff --git a/tools/pvscan.c b/tools/pvscan.c
index 6c634e3..9287388 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -34,7 +34,7 @@ static void _pvscan_display_single(struct cmd_context *cmd,
/* short listing? */
if (arg_count(cmd, short_ARG) > 0) {
- log_print("%s", pv_dev_name(pv));
+ log_print_unless_silent("%s", pv_dev_name(pv));
return;
}
@@ -64,37 +64,31 @@ static void _pvscan_display_single(struct cmd_context *cmd,
}
if (is_orphan(pv)) {
- log_print("PV %-*s %-*s %s [%s]",
- pv_max_name_len, pv_tmp_name,
- vg_max_name_len, " ",
- pv->fmt ? pv->fmt->name : " ",
- display_size(cmd, pv_size(pv)));
+ log_print_unless_silent("PV %-*s %-*s %s [%s]",
+ pv_max_name_len, pv_tmp_name,
+ vg_max_name_len, " ",
+ pv->fmt ? pv->fmt->name : " ",
+ display_size(cmd, pv_size(pv)));
return;
}
if (pv_status(pv) & EXPORTED_VG) {
strncpy(vg_name_this, pv_vg_name(pv), vg_name_len);
- log_print("PV %-*s is in exported VG %s "
- "[%s / %s free]",
- pv_max_name_len, pv_tmp_name,
- vg_name_this,
- display_size(cmd, (uint64_t) pv_pe_count(pv) *
- pv_pe_size(pv)),
- display_size(cmd, (uint64_t) (pv_pe_count(pv) -
- pv_pe_alloc_count(pv))
- * pv_pe_size(pv)));
+ log_print_unless_silent("PV %-*s is in exported VG %s "
+ "[%s / %s free]",
+ pv_max_name_len, pv_tmp_name,
+ vg_name_this,
+ display_size(cmd, (uint64_t) pv_pe_count(pv) * pv_pe_size(pv)),
+ display_size(cmd, (uint64_t) (pv_pe_count(pv) - pv_pe_alloc_count(pv)) * pv_pe_size(pv)));
return;
}
sprintf(vg_tmp_name, "%s", pv_vg_name(pv));
- log_print("PV %-*s VG %-*s %s [%s / %s free]", pv_max_name_len,
- pv_tmp_name, vg_max_name_len, vg_tmp_name,
- pv->fmt ? pv->fmt->name : " ",
- display_size(cmd, (uint64_t) pv_pe_count(pv) *
- pv_pe_size(pv)),
- display_size(cmd, (uint64_t) (pv_pe_count(pv) -
- pv_pe_alloc_count(pv)) *
- pv_pe_size(pv)));
+ log_print_unless_silent("PV %-*s VG %-*s %s [%s / %s free]", pv_max_name_len,
+ pv_tmp_name, vg_max_name_len, vg_tmp_name,
+ pv->fmt ? pv->fmt->name : " ",
+ display_size(cmd, (uint64_t) pv_pe_count(pv) * pv_pe_size(pv)),
+ display_size(cmd, (uint64_t) (pv_pe_count(pv) - pv_pe_alloc_count(pv)) * pv_pe_size(pv)));
}
static int _auto_activation_handler(struct volume_group *vg, int partial,
@@ -223,8 +217,8 @@ static int _pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
break;
}
- log_print("Device %s not found. "
- "Cleared from lvmetad cache.", buf ? : "");
+ log_print_unless_silent("Device %s not found. "
+ "Cleared from lvmetad cache.", buf ? : "");
if (buf)
dm_free(buf);
continue;
@@ -355,17 +349,17 @@ int pvscan(struct cmd_context *cmd, int argc, char **argv)
}
if (!pvs_found) {
- log_print("No matching physical volumes found");
+ log_print_unless_silent("No matching physical volumes found");
unlock_vg(cmd, VG_GLOBAL);
return ECMD_PROCESSED;
}
- log_print("Total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]",
- pvs_found,
- display_size(cmd, size_total),
- pvs_found - new_pvs_found,
- display_size(cmd, (size_total - size_new)),
- new_pvs_found, display_size(cmd, size_new));
+ log_print_unless_silent("Total: %d [%s] / in use: %d [%s] / in no VG: %d [%s]",
+ pvs_found,
+ display_size(cmd, size_total),
+ pvs_found - new_pvs_found,
+ display_size(cmd, (size_total - size_new)),
+ new_pvs_found, display_size(cmd, size_new));
unlock_vg(cmd, VG_GLOBAL);
diff --git a/tools/toollib.c b/tools/toollib.c
index d6fc951..1916bfd 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1527,13 +1527,13 @@ static int _validate_stripe_params(struct cmd_context *cmd, uint32_t *stripes,
uint32_t *stripe_size)
{
if (*stripes == 1 && *stripe_size) {
- log_print("Ignoring stripesize argument with single stripe");
+ log_print_unless_silent("Ignoring stripesize argument with single stripe");
*stripe_size = 0;
}
if (*stripes > 1 && !*stripe_size) {
*stripe_size = find_config_tree_int(cmd, "metadata/stripesize", DEFAULT_STRIPESIZE) * 2;
- log_print("Using default stripesize %s",
+ log_print_unless_silent("Using default stripesize %s",
display_size(cmd, (uint64_t) *stripe_size));
}
diff --git a/tools/vgcfgbackup.c b/tools/vgcfgbackup.c
index c5d712f..32948d8 100644
--- a/tools/vgcfgbackup.c
+++ b/tools/vgcfgbackup.c
@@ -81,7 +81,7 @@ static int vg_backup_single(struct cmd_context *cmd, const char *vg_name,
}
}
- log_print("Volume group \"%s\" successfully backed up.", vg_name);
+ log_print_unless_silent("Volume group \"%s\" successfully backed up.", vg_name);
return ECMD_PROCESSED;
}
diff --git a/tools/vgcfgrestore.c b/tools/vgcfgrestore.c
index 9715c93..d62df99 100644
--- a/tools/vgcfgrestore.c
+++ b/tools/vgcfgrestore.c
@@ -70,7 +70,7 @@ int vgcfgrestore(struct cmd_context *cmd, int argc, char **argv)
return ECMD_FAILED;
}
- log_print("Restored volume group %s", vg_name);
+ log_print_unless_silent("Restored volume group %s", vg_name);
unlock_vg(cmd, VG_ORPHANS);
unlock_vg(cmd, vg_name);
diff --git a/tools/vgchange.c b/tools/vgchange.c
index c59d58e..34f6167 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -194,9 +194,9 @@ static int _vgchange_monitoring(struct cmd_context *cmd, struct volume_group *vg
dmeventd_monitor_mode() != DMEVENTD_MONITOR_IGNORE) {
if (!_monitor_lvs_in_vg(cmd, vg, dmeventd_monitor_mode(), &monitored))
r = 0;
- log_print("%d logical volume(s) in volume group "
- "\"%s\" %smonitored",
- monitored, vg->name, (dmeventd_monitor_mode()) ? "" : "un");
+ log_print_unless_silent("%d logical volume(s) in volume group "
+ "\"%s\" %smonitored",
+ monitored, vg->name, (dmeventd_monitor_mode()) ? "" : "un");
}
return r;
@@ -209,9 +209,9 @@ static int _vgchange_background_polling(struct cmd_context *cmd, struct volume_g
if (lvs_in_vg_activated(vg) && background_polling()) {
polled = _poll_lvs_in_vg(cmd, vg);
if (polled)
- log_print("Background polling started for %d logical volume(s) "
- "in volume group \"%s\"",
- polled, vg->name);
+ log_print_unless_silent("Background polling started for %d logical volume(s) "
+ "in volume group \"%s\"",
+ polled, vg->name);
}
return 1;
@@ -260,8 +260,8 @@ int vgchange_activate(struct cmd_context *cmd, struct volume_group *vg,
/* Print message only if there was not found a missing VG */
if (!vg->cmd_missing_vgs)
- log_print("%d logical volume(s) in volume group \"%s\" now active",
- lvs_in_vg_activated(vg), vg->name);
+ log_print_unless_silent("%d logical volume(s) in volume group \"%s\" now active",
+ lvs_in_vg_activated(vg), vg->name);
return r;
}
@@ -508,7 +508,7 @@ static int vgchange_single(struct cmd_context *cmd, const char *vg_name,
backup(vg);
- log_print("Volume group \"%s\" successfully changed", vg->name);
+ log_print_unless_silent("Volume group \"%s\" successfully changed", vg->name);
}
if (arg_count(cmd, activate_ARG)) {
diff --git a/tools/vgconvert.c b/tools/vgconvert.c
index 1106724..2ba4095 100644
--- a/tools/vgconvert.c
+++ b/tools/vgconvert.c
@@ -186,7 +186,7 @@ static int vgconvert_single(struct cmd_context *cmd, const char *vg_name,
"archived metadata.");
return ECMD_FAILED;
}
- log_print("Volume group %s successfully converted", vg_name);
+ log_print_unless_silent("Volume group %s successfully converted", vg_name);
backup(vg);
diff --git a/tools/vgcreate.c b/tools/vgcreate.c
index dcce544..2b9fb2f 100644
--- a/tools/vgcreate.c
+++ b/tools/vgcreate.c
@@ -119,8 +119,8 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
backup(vg);
- log_print("%s%colume group \"%s\" successfully created",
- clustered_message, *clustered_message ? 'v' : 'V', vg->name);
+ log_print_unless_silent("%s%colume group \"%s\" successfully created",
+ clustered_message, *clustered_message ? 'v' : 'V', vg->name);
release_vg(vg);
return ECMD_PROCESSED;
diff --git a/tools/vgexport.c b/tools/vgexport.c
index a1043d2..c573619 100644
--- a/tools/vgexport.c
+++ b/tools/vgexport.c
@@ -44,7 +44,7 @@ static int vgexport_single(struct cmd_context *cmd __attribute__((unused)),
backup(vg);
- log_print("Volume group \"%s\" successfully exported", vg->name);
+ log_print_unless_silent("Volume group \"%s\" successfully exported", vg->name);
return ECMD_PROCESSED;
diff --git a/tools/vgextend.c b/tools/vgextend.c
index 161796c..2ce7edb 100644
--- a/tools/vgextend.c
+++ b/tools/vgextend.c
@@ -134,7 +134,7 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
goto_bad;
backup(vg);
- log_print("Volume group \"%s\" successfully extended", vg_name);
+ log_print_unless_silent("Volume group \"%s\" successfully extended", vg_name);
r = ECMD_PROCESSED;
bad:
diff --git a/tools/vgimport.c b/tools/vgimport.c
index 284f536..5badcb5 100644
--- a/tools/vgimport.c
+++ b/tools/vgimport.c
@@ -48,7 +48,7 @@ static int vgimport_single(struct cmd_context *cmd __attribute__((unused)),
backup(vg);
- log_print("Volume group \"%s\" successfully imported", vg->name);
+ log_print_unless_silent("Volume group \"%s\" successfully imported", vg->name);
return ECMD_PROCESSED;
diff --git a/tools/vgmerge.c b/tools/vgmerge.c
index 7b2183f..2cecb05 100644
--- a/tools/vgmerge.c
+++ b/tools/vgmerge.c
@@ -148,8 +148,8 @@ static int _vgmerge_single(struct cmd_context *cmd, const char *vg_name_to,
/* FIXME Remove /dev/vgfrom */
backup(vg_to);
- log_print("Volume group \"%s\" successfully merged into \"%s\"",
- vg_from->name, vg_to->name);
+ log_print_unless_silent("Volume group \"%s\" successfully merged into \"%s\"",
+ vg_from->name, vg_to->name);
r = ECMD_PROCESSED;
bad:
/*
diff --git a/tools/vgreduce.c b/tools/vgreduce.c
index 975b9ea..1b04a49 100644
--- a/tools/vgreduce.c
+++ b/tools/vgreduce.c
@@ -193,7 +193,7 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
backup(vg);
- log_print("Removed \"%s\" from volume group \"%s\"", name, vg->name);
+ log_print_unless_silent("Removed \"%s\" from volume group \"%s\"", name, vg->name);
r = ECMD_PROCESSED;
bad:
if (pvl)
@@ -304,8 +304,8 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv)
backup(vg);
if (fixed) {
- log_print("Wrote out consistent volume group %s",
- vg_name);
+ log_print_unless_silent("Wrote out consistent volume group %s",
+ vg_name);
ret = ECMD_PROCESSED;
} else
ret = ECMD_FAILED;
diff --git a/tools/vgrename.c b/tools/vgrename.c
index 56031ec..451d085 100644
--- a/tools/vgrename.c
+++ b/tools/vgrename.c
@@ -177,8 +177,8 @@ static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path,
unlock_vg(cmd, vg_name_new);
unlock_and_release_vg(cmd, vg, vg_name_old);
- log_print("Volume group \"%s\" successfully renamed to \"%s\"",
- vg_name_old, vg_name_new);
+ log_print_unless_silent("Volume group \"%s\" successfully renamed to \"%s\"",
+ vg_name_old, vg_name_new);
/* FIXME lvmcache corruption - vginfo duplicated instead of renamed */
persistent_filter_wipe(cmd->filter);
diff --git a/tools/vgscan.c b/tools/vgscan.c
index f82c71f..a34f3ba 100644
--- a/tools/vgscan.c
+++ b/tools/vgscan.c
@@ -21,9 +21,9 @@ static int vgscan_single(struct cmd_context *cmd, const char *vg_name,
struct volume_group *vg,
void *handle __attribute__((unused)))
{
- log_print("Found %svolume group \"%s\" using metadata type %s",
- vg_is_exported(vg) ? "exported " : "", vg_name,
- vg->fid->fmt->name);
+ log_print_unless_silent("Found %svolume group \"%s\" using metadata type %s",
+ vg_is_exported(vg) ? "exported " : "", vg_name,
+ vg->fid->fmt->name);
check_current_backup(vg);
@@ -64,7 +64,7 @@ int vgscan(struct cmd_context *cmd, int argc, char **argv)
}
}
- log_print("Reading all physical volumes. This may take a while...");
+ log_print_unless_silent("Reading all physical volumes. This may take a while...");
maxret = process_each_vg(cmd, argc, argv, 0, NULL,
&vgscan_single);
diff --git a/tools/vgsplit.c b/tools/vgsplit.c
index 73f94a8..3bbb9fa 100644
--- a/tools/vgsplit.c
+++ b/tools/vgsplit.c
@@ -493,9 +493,9 @@ int vgsplit(struct cmd_context *cmd, int argc, char **argv)
backup(vg_to);
- log_print("%s volume group \"%s\" successfully split from \"%s\"",
- existing_vg ? "Existing" : "New",
- vg_to->name, vg_from->name);
+ log_print_unless_silent("%s volume group \"%s\" successfully split from \"%s\"",
+ existing_vg ? "Existing" : "New",
+ vg_to->name, vg_from->name);
r = ECMD_PROCESSED;
11 years, 3 months
master - RAID: Add support for RAID10
by Jonathan Brassow
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=4047e4dfb16175...
Commit: 4047e4dfb16175daec348bf44032c02181bd4c70
Parent: 99d1e264a87eb256debe2eaa02d9fc4e2b08c815
Author: Jonathan Brassow <jbrassow(a)redhat.com>
AuthorDate: Fri Aug 24 15:34:19 2012 -0500
Committer: Jonathan Brassow <jbrassow(a)redhat.com>
CommitterDate: Fri Aug 24 15:34:19 2012 -0500
RAID: Add support for RAID10
This patch adds support for RAID10. It is not the default at this
stage. The user needs to specify '--type raid10' if they would like
RAID10 instead of stacked mirror over stripe.
---
WHATS_NEW | 1 +
lib/metadata/lv.c | 4 +-
lib/metadata/lv_manip.c | 8 +++
lib/metadata/mirror.c | 4 ++
lib/metadata/raid_manip.c | 18 +++++++
lib/raid/raid.c | 15 ++++++
libdm/libdm-deptree.c | 4 ++
test/shell/lvconvert-raid.sh | 109 +++++++++++++++++++++++++++++++++++++++++-
test/shell/lvcreate-raid.sh | 21 ++++++++-
tools/lvcreate.c | 28 ++++++++++-
tools/lvresize.c | 13 ++++-
11 files changed, 218 insertions(+), 7 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 9bd1739..c7d5f54 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.98
=================================
+ Add RAID10 support.
Reuse _reload_lv() in more lvconvert functions.
Fix dereference of NULL in lvmetad error path logging.
Fix buffer memory leak in lvmetad logging.
diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c
index bb6043d..003e18d 100644
--- a/lib/metadata/lv.c
+++ b/lib/metadata/lv.c
@@ -476,10 +476,10 @@ char *lv_attr_dup(struct dm_pool *mem, const struct logical_volume *lv)
if (lv_is_thin_type(lv))
repstr[6] = 't';
- else if (lv_is_mirror_type(lv))
- repstr[6] = 'm';
else if (lv_is_raid_type(lv))
repstr[6] = 'r';
+ else if (lv_is_mirror_type(lv))
+ repstr[6] = 'm';
else if (lv_is_cow(lv) || lv_is_origin(lv))
repstr[6] = 's';
else if (lv_has_unknown_segments(lv))
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 51abae0..59e1429 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -710,6 +710,14 @@ static uint32_t _calc_area_multiple(const struct segment_type *segtype,
return area_count - segtype->parity_devs;
}
+ /* RAID10 - only has 2-way mirror right now */
+ if (!strcmp(segtype->name, "raid10")) {
+ // FIXME: I'd like the 'stripes' arg always given
+ if (!stripes)
+ return area_count / 2;
+ return stripes;
+ }
+
/* Mirrored stripes */
if (stripes)
return stripes;
diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c
index ac885d6..e3662c1 100644
--- a/lib/metadata/mirror.c
+++ b/lib/metadata/mirror.c
@@ -114,6 +114,10 @@ uint32_t lv_mirror_count(const struct logical_volume *lv)
seg = first_seg(lv);
+ /* FIXME: RAID10 only supports 2 copies right now */
+ if (!strcmp(seg->segtype->name, "raid10"))
+ return 2;
+
if (lv->status & PVMOVE)
return seg->area_count;
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index c86bb9a..0d4640f 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -1620,6 +1620,24 @@ int lv_raid_replace(struct logical_volume *lv,
raid_seg->segtype->parity_devs,
raid_seg->segtype->name, lv->vg->name, lv->name);
return 0;
+ } else if (!strcmp(raid_seg->segtype->name, "raid10")) {
+ uint32_t i, rebuilds_per_group = 0;
+ /* FIXME: We only support 2-way mirrors in RAID10 currently */
+ uint32_t copies = 2;
+
+ for (i = 0; i < raid_seg->area_count * copies; i++) {
+ s = i % raid_seg->area_count;
+ if (!(i % copies))
+ rebuilds_per_group = 0;
+ if (_lv_is_on_pvs(seg_lv(raid_seg, s), remove_pvs) ||
+ _lv_is_on_pvs(seg_metalv(raid_seg, s), remove_pvs))
+ rebuilds_per_group++;
+ if (rebuilds_per_group >= copies) {
+ log_error("Unable to replace all the devices "
+ "in a RAID10 mirror group.");
+ return 0;
+ }
+ }
}
/*
diff --git a/lib/raid/raid.c b/lib/raid/raid.c
index 097d36f..78fe074 100644
--- a/lib/raid/raid.c
+++ b/lib/raid/raid.c
@@ -379,6 +379,20 @@ static struct segment_type *_init_raid1_segtype(struct cmd_context *cmd)
return segtype;
}
+static struct segment_type *_init_raid10_segtype(struct cmd_context *cmd)
+{
+ struct segment_type *segtype;
+
+ segtype = _init_raid_segtype(cmd, "raid10");
+ if (!segtype)
+ return NULL;
+
+ segtype->flags |= SEG_AREAS_MIRRORED;
+ segtype->parity_devs = 0;
+
+ return segtype;
+}
+
static struct segment_type *_init_raid4_segtype(struct cmd_context *cmd)
{
return _init_raid_segtype(cmd, "raid4");
@@ -441,6 +455,7 @@ int init_multiple_segtypes(struct cmd_context *cmd, struct segtype_library *segl
unsigned i = 0;
struct segment_type *(*raid_segtype_fn[])(struct cmd_context *) = {
_init_raid1_segtype,
+ _init_raid10_segtype,
_init_raid4_segtype,
_init_raid5_segtype,
_init_raid5_la_segtype,
diff --git a/libdm/libdm-deptree.c b/libdm/libdm-deptree.c
index 28d1153..f675d0d 100644
--- a/libdm/libdm-deptree.c
+++ b/libdm/libdm-deptree.c
@@ -41,6 +41,7 @@ enum {
SEG_THIN_POOL,
SEG_THIN,
SEG_RAID1,
+ SEG_RAID10,
SEG_RAID4,
SEG_RAID5_LA,
SEG_RAID5_RA,
@@ -72,6 +73,7 @@ struct {
{ SEG_THIN_POOL, "thin-pool"},
{ SEG_THIN, "thin"},
{ SEG_RAID1, "raid1"},
+ { SEG_RAID10, "raid10"},
{ SEG_RAID4, "raid4"},
{ SEG_RAID5_LA, "raid5_la"},
{ SEG_RAID5_RA, "raid5_ra"},
@@ -1912,6 +1914,7 @@ static int _emit_areas_line(struct dm_task *dmt __attribute__((unused)),
}
break;
case SEG_RAID1:
+ case SEG_RAID10:
case SEG_RAID4:
case SEG_RAID5_LA:
case SEG_RAID5_RA:
@@ -2265,6 +2268,7 @@ static int _emit_segment_line(struct dm_task *dmt, uint32_t major,
seg->iv_offset : *seg_start);
break;
case SEG_RAID1:
+ case SEG_RAID10:
case SEG_RAID4:
case SEG_RAID5_LA:
case SEG_RAID5_RA:
diff --git a/test/shell/lvconvert-raid.sh b/test/shell/lvconvert-raid.sh
index c63c141..c62aee5 100644
--- a/test/shell/lvconvert-raid.sh
+++ b/test/shell/lvconvert-raid.sh
@@ -11,12 +11,23 @@
. lib/test
+get_image_pvs() {
+ local d
+ local images=""
+
+ for d in `ls /dev/mapper/${1}-${2}_?image_*`; do
+ images="$images `basename $d | sed s:-:/:`"
+ done
+ lvs --noheadings -a -o devices $images | sed s/\(.\)//
+}
+
########################################################
# MAIN
########################################################
aux target_at_least dm-raid 1 1 0 || skip
-aux prepare_pvs 5 80
+# 9 PVs needed for RAID10 testing (3-stripes/2-mirror - replacing 3 devs)
+aux prepare_pvs 9 80
vgcreate -c n -s 256k $vg $(cat DEVICES)
###########################################
@@ -132,3 +143,99 @@ for i in 1 2 3 ; do
lvconvert --type raid1 $vg/$lv1
lvremove -ff $vg
done
+
+###########################################
+# Device Replacement Testing
+###########################################
+# RAID1: Replace up to n-1 devices - trying different combinations
+# Test for 2-way to 4-way RAID1 LVs
+for i in {1..3}; do
+ lvcreate --type raid1 -m $i -l 2 -n $lv1 $vg
+
+ for j in $(seq $(($i + 1))); do # The number of devs to replace at once
+ for o in $(seq 0 $i); do # The offset into the device list
+ replace=""
+
+ devices=( $(get_image_pvs $vg $lv1) )
+
+ for k in $(seq $j); do
+ index=$((($k + $o) % ($i + 1)))
+ replace="$replace --replace ${devices[$index]}"
+ done
+ aux wait_for_sync $vg $lv1
+
+ if [ $j -ge $((i + 1)) ]; then
+ # Can't replace all at once.
+ not lvconvert $replace $vg/$lv1
+ else
+ lvconvert $replace $vg/$lv1
+ fi
+ done
+ done
+
+ lvremove -ff $vg
+done
+
+# RAID 4/5/6 (can replace up to 'parity' devices)
+for i in 4 5 6; do
+ lvcreate --type raid$i -i 3 -l 3 -n $lv1 $vg
+
+ if [ $i -eq 6 ]; then
+ dev_cnt=5
+ limit=2
+ else
+ dev_cnt=4
+ limit=1
+ fi
+
+ for j in {1..3}; do
+ for o in $(seq 0 $i); do
+ replace=""
+
+ devices=( $(get_image_pvs $vg $lv1) )
+
+ for k in $(seq $j); do
+ index=$((($k + $o) % $dev_cnt))
+ replace="$replace --replace ${devices[$index]}"
+ done
+ aux wait_for_sync $vg $lv1
+
+ if [ $j -gt $limit ]; then
+ not lvconvert $replace $vg/$lv1
+ else
+ lvconvert $replace $vg/$lv1
+ fi
+ done
+ done
+
+ lvremove -ff $vg
+done
+
+# RAID10: Can replace 'copies - 1' devices from each stripe
+# Tests are run on 2-way mirror, 3-way stripe RAID10
+aux target_at_least dm-raid 1 3 1 || skip
+
+lvcreate --type raid10 -m 1 -i 3 -l 3 -n $lv1 $vg
+aux wait_for_sync $vg $lv1
+
+# Can replace any single device
+for i in $(get_image_pvs $vg $lv1); do
+ lvconvert --replace $i $vg/$lv1
+ aux wait_for_sync $vg $lv1
+done
+
+# Can't replace adjacent devices
+devices=( $(get_image_pvs $vg $lv1) )
+not lvconvert --replace ${devices[0]} --replace ${devices[1]} $vg/$lv1
+not lvconvert --replace ${devices[2]} --replace ${devices[3]} $vg/$lv1
+not lvconvert --replace ${devices[4]} --replace ${devices[5]} $vg/$lv1
+
+# Can replace non-adjacent devices
+for i in 0 1; do
+ lvconvert \
+ --replace ${devices[$i]} \
+ --replace ${devices[$(($i + 2))]} \
+ --replace ${devices[$(($i + 4))]} \
+ $vg/$lv1
+ aux wait_for_sync $vg $lv1
+done
diff --git a/test/shell/lvcreate-raid.sh b/test/shell/lvcreate-raid.sh
index c26f694..81e5a5d 100644
--- a/test/shell/lvcreate-raid.sh
+++ b/test/shell/lvcreate-raid.sh
@@ -16,7 +16,7 @@
########################################################
aux target_at_least dm-raid 1 1 0 || skip
-aux prepare_pvs 5 20
+aux prepare_pvs 6 20 # 6 devices for RAID10 (2-mirror,3-stripe) test
vgcreate -c n -s 512k $vg $(cat DEVICES)
###########################################
@@ -49,5 +49,24 @@ for i in raid4 \
done
#
+# Create RAID10:
+#
+
+aux target_at_least dm-raid 1 3 0 || skip
+
+# Should not allow more than 2-way mirror
+not lvcreate --type raid10 -m 2 -i 2 -l 2 -n $lv1 $vg
+
+# 2-way mirror, 2-stripes
+lvcreate --type raid10 -m 1 -i 2 -l 2 -n $lv1 $vg
+aux wait_for_sync $vg $lv1
+lvremove -ff $vg
+
+# 2-way mirror, 3-stripes
+lvcreate --type raid10 -m 1 -i 3 -l 3 -n $lv1 $vg
+aux wait_for_sync $vg $lv1
+lvremove -ff $vg
+
+#
# FIXME: Add tests that specify particular PVs to use for creation
#
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 2cb6ac0..aac8c22 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -702,6 +702,10 @@ static int _lvcreate_params(struct lvcreate_params *lp,
/* Set default segtype */
if (arg_count(cmd, mirrors_ARG))
+ /*
+ * FIXME: Add default setting for when -i and -m arguments
+ * are both given. We should default to "raid10".
+ */
segtype_str = find_config_tree_str(cmd, "global/mirror_segtype_default", DEFAULT_MIRROR_SEGTYPE);
else if (arg_count(cmd, thin_ARG) || arg_count(cmd, thinpool_ARG))
segtype_str = "thin";
@@ -735,7 +739,7 @@ static int _lvcreate_params(struct lvcreate_params *lp,
lp->mirrors = 1;
- /* Default to 2 mirrored areas if '--type mirror|raid1' */
+ /* Default to 2 mirrored areas if '--type mirror|raid1|raid10' */
if (segtype_is_mirrored(lp->segtype))
lp->mirrors = 2;
@@ -748,6 +752,18 @@ static int _lvcreate_params(struct lvcreate_params *lp,
}
log_print("Redundant mirrors argument: default is 0");
}
+
+ if ((lp->mirrors > 2) && !strcmp(lp->segtype->name, "raid10")) {
+ /*
+ * FIXME: When RAID10 is no longer limited to
+ * 2-way mirror, 'lv_mirror_count()'
+ * must also change for RAID10.
+ */
+ log_error("RAID10 currently supports "
+ "only 2-way mirroring (i.e. '-m 1')");
+ return 0;
+ }
+
if (arg_sign_value(cmd, mirrors_ARG, SIGN_NONE) == SIGN_MINUS) {
log_error("Mirrors argument may not be negative");
return 0;
@@ -787,6 +803,16 @@ static int _lvcreate_params(struct lvcreate_params *lp,
log_error("%s: Required device-mapper target(s) not "
"detected in your kernel", lp->segtype->name);
return 0;
+ } else if (!strcmp(lp->segtype->name, "raid10")) {
+ uint32_t maj, min, patchlevel;
+ if (!target_version("raid", &maj, &min, &patchlevel)) {
+ log_error("Failed to determine version of RAID kernel module");
+ return 0;
+ }
+ if ((maj != 1) || (min < 3)) {
+ log_error("RAID module does not support RAID10");
+ return 0;
+ }
}
if (!_lvcreate_name_params(lp, cmd, &argc, &argv) ||
diff --git a/tools/lvresize.c b/tools/lvresize.c
index 64474e0..05041af 100644
--- a/tools/lvresize.c
+++ b/tools/lvresize.c
@@ -578,6 +578,7 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
seg_mirrors = 0;
break;
}
+
if (!arg_count(cmd, mirrors_ARG) && seg_mirrors) {
log_print("Extending %" PRIu32 " mirror images.",
seg_mirrors);
@@ -588,18 +589,26 @@ static int _lvresize(struct cmd_context *cmd, struct volume_group *vg,
log_error("Cannot vary number of mirrors in LV yet.");
return EINVALID_CMD_LINE;
}
+
+ if (seg_mirrors && !strcmp(mirr_seg->segtype->name, "raid10")) {
+ lp->stripes = mirr_seg->area_count / seg_mirrors;
+ lp->stripe_size = mirr_seg->stripe_size;
+ }
}
/* If extending, find stripes, stripesize & size of last segment */
if ((lp->extents > lv->le_count) &&
- !(lp->stripes == 1 || (lp->stripes > 1 && lp->stripe_size))) {
+ !(lp->stripes == 1 || (lp->stripes > 1 && lp->stripe_size)) &&
+ strcmp(mirr_seg->segtype->name, "raid10")) {
/* FIXME Don't assume mirror seg will always be AREA_LV */
/* FIXME We will need to support resize for metadata LV as well,
* and data LV could be any type (i.e. mirror)) */
dm_list_iterate_items(seg, seg_mirrors ? &seg_lv(mirr_seg, 0)->segments :
lv_is_thin_pool(lv) ? &seg_lv(first_seg(lv), 0)->segments : &lv->segments) {
+ /* Allow through "striped" and RAID 4/5/6/10 */
if (!seg_is_striped(seg) &&
- (!seg_is_raid(seg) || seg_is_mirrored(seg)))
+ (!seg_is_raid(seg) || seg_is_mirrored(seg)) &&
+ strcmp(seg->segtype->name, "raid10"))
continue;
sz = seg->stripe_size;
11 years, 3 months