Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=2e82a070f3c9224d…
Commit: 2e82a070f3c9224da5c9f383d47e75a1715586cf
Parent: 84394c0219e4fcee719663c710121f1bb731a538
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Fri Nov 29 21:45:37 2013 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Fri Nov 29 21:45:37 2013 +0000
pvcreate: Avoid spurious 'not found' messages.
Replacement of pv_read by find_pv_by_name in commit
651d5093edde3e0ebee9d75be1c9834efc152d91 caused spurious
error messages when running pvcreate or vgextend against an
unformatted device.
Physical volume /dev/loop4 not found
Physical volume "/dev/loop4" successfully created
Physical volume /dev/loop4 not found
Physical volume /dev/loop4 not found
Physical volume "/dev/loop4" successfully created
Volume group "vg1" successfully extended
---
lib/metadata/metadata-exported.h | 2 +-
lib/metadata/metadata.c | 8 ++++----
lib/metadata/mirror.c | 2 +-
tools/pvmove.c | 4 ++--
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index ece5f53..f205a14 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -847,7 +847,7 @@ struct logical_volume *find_lv(const struct volume_group *vg,
const char *lv_name);
struct physical_volume *find_pv_by_name(struct cmd_context *cmd,
const char *pv_name,
- int allow_orphan);
+ int allow_orphan, int allow_unformatted);
const char *find_vgname_from_pvname(struct cmd_context *cmd,
const char *pvname);
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index f075c21..61816e2 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -633,7 +633,7 @@ static int vg_extend_single_pv(struct volume_group *vg, char *pv_name,
{
struct physical_volume *pv;
- if (!(pv = find_pv_by_name(vg->cmd, pv_name, 1)))
+ if (!(pv = find_pv_by_name(vg->cmd, pv_name, 1, 1)))
stack;
if (!pv && !pp) {
log_error("%s not identified as an existing "
@@ -1278,7 +1278,7 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,
/* FIXME Check partition type is LVM unless --force is given */
/* Is there a pv here already? */
- if (!(pv = find_pv_by_name(cmd, name, 1)))
+ if (!(pv = find_pv_by_name(cmd, name, 1, 1)))
stack;
/* Allow partial & exported VGs to be destroyed. */
@@ -1781,7 +1781,7 @@ struct physical_volume *find_pv(struct volume_group *vg, struct device *dev)
/* FIXME: liblvm todo - make into function that returns handle */
struct physical_volume *find_pv_by_name(struct cmd_context *cmd,
const char *pv_name,
- int allow_orphan)
+ int allow_orphan, int allow_unformatted)
{
struct device *dev;
struct pv_list *pvl;
@@ -1804,7 +1804,7 @@ struct physical_volume *find_pv_by_name(struct cmd_context *cmd,
else
free_pv_fid(pvl->pv);
- if (!pv)
+ if (!pv && !allow_unformatted)
log_error("Physical volume %s not found", pv_name);
if (pv && !allow_orphan && is_orphan_vg(pv->vg_name)) {
diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c
index 6fc7674..18917d3 100644
--- a/lib/metadata/mirror.c
+++ b/lib/metadata/mirror.c
@@ -1577,7 +1577,7 @@ struct logical_volume *find_pvmove_lv_from_pvname(struct cmd_context *cmd,
struct physical_volume *pv;
struct logical_volume *lv;
- if (!(pv = find_pv_by_name(cmd, name, 0)))
+ if (!(pv = find_pv_by_name(cmd, name, 0, 0)))
return_NULL;
lv = find_pvmove_lv(vg, pv->dev, lv_type);
diff --git a/tools/pvmove.c b/tools/pvmove.c
index ab2e03b..19e1482 100644
--- a/tools/pvmove.c
+++ b/tools/pvmove.c
@@ -628,7 +628,7 @@ static int _set_up_pvmove(struct cmd_context *cmd, const char *pv_name,
argv++;
/* Find PV (in VG) */
- if (!(pv = find_pv_by_name(cmd, pv_name, 0))) {
+ if (!(pv = find_pv_by_name(cmd, pv_name, 0, 0))) {
stack;
return EINVALID_CMD_LINE;
}
@@ -809,7 +809,7 @@ static struct volume_group *_get_move_vg(struct cmd_context *cmd,
struct volume_group *vg;
/* Reread all metadata in case it got changed */
- if (!(pv = find_pv_by_name(cmd, name, 0))) {
+ if (!(pv = find_pv_by_name(cmd, name, 0, 0))) {
log_error("ABORTING: Can't reread PV %s", name);
/* What more could we do here? */
return NULL;
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=84394c0219e4fcee…
Commit: 84394c0219e4fcee719663c710121f1bb731a538
Parent: d2d5c24a68285a2f056977f877ab1a19e61b992f
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Fri Nov 29 20:56:29 2013 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Fri Nov 29 20:56:29 2013 +0000
lvmetad: extend socket/pid file handling
Make it easier to run a live lvmetad in debugging mode and
to avoid conflicts if multiple test instances need to be run
alongside a live one.
No longer require -s when -f is used: use built-in default.
Add -p to lvmetad to specify the pid file.
No longer disable pidfile if -f used to run in foreground.
If specified socket file appears to be genuine but stale, remove it
before use.
On error, only remove lvmetad socket file if created by the same
process. (Previous code removes socket even while a running instance
is using it!)
---
WHATS_NEW | 3 ++
daemons/lvmetad/lvmetad-core.c | 25 +++++++++++---------
libdaemon/server/daemon-server.c | 46 +++++++++++++++++++++++++++++++++++--
man/lvmetad.8.in | 36 +++++++++++++++++++++--------
test/lib/test.sh | 1 +
5 files changed, 87 insertions(+), 24 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 0101b49..043b7ef 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,8 @@
Version 2.02.105 -
=====================================
+ Add -p and LVM_LVMETAD_PID env var to lvmetad to change pid file.
+ Allow lvmetad to reuse stale socket.
+ Only unlink lvmetad socket on error if created by the same process.
Append missing newline to lvmetad missing socket path error message.
Check for non-zero aligment in _text_pv_add_metadata_area() to not div by 0.
Add allocation/use_blkid_wiping to lvm.conf to enable blkid wiping.
diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c
index 71254f4..2810faf 100644
--- a/daemons/lvmetad/lvmetad-core.c
+++ b/daemons/lvmetad/lvmetad-core.c
@@ -1189,6 +1189,7 @@ static void usage(char *prog, FILE *file)
" -h Show this help information\n"
" -f Don't fork, run in the foreground\n"
" -l Logging message level (-l {all|wire|debug})\n"
+ " -p Set path to the pidfile\n"
" -s Set path to the socket to listen on\n\n", prog);
}
@@ -1196,27 +1197,34 @@ int main(int argc, char *argv[])
{
signed char opt;
lvmetad_state ls;
+ int _pidfile_override = 1;
int _socket_override = 1;
daemon_state s = {
.daemon_fini = fini,
.daemon_init = init,
.handler = handler,
.name = "lvmetad",
- .pidfile = LVMETAD_PIDFILE,
+ .pidfile = getenv("LVM_LVMETAD_PIDFILE"),
.private = &ls,
.protocol = "lvmetad",
.protocol_version = 1,
.socket_path = getenv("LVM_LVMETAD_SOCKET"),
};
+ if (!s.pidfile) {
+ _pidfile_override = 0;
+ s.pidfile = LVMETAD_PIDFILE;
+ }
+
if (!s.socket_path) {
_socket_override = 0;
s.socket_path = LVMETAD_SOCKET;
}
+
ls.log_config = "";
// use getopt_long
- while ((opt = getopt(argc, argv, "?fhVl:s:")) != EOF) {
+ while ((opt = getopt(argc, argv, "?fhVl:p:s:")) != EOF) {
switch (opt) {
case 'h':
usage(argv[0], stdout);
@@ -1230,6 +1238,10 @@ int main(int argc, char *argv[])
case 'l':
ls.log_config = optarg;
break;
+ case 'p':
+ s.pidfile = optarg;
+ _pidfile_override = 1;
+ break;
case 's': // --socket
s.socket_path = optarg;
_socket_override = 1;
@@ -1240,15 +1252,6 @@ int main(int argc, char *argv[])
}
}
- if (s.foreground) {
- if (!_socket_override) {
- fprintf(stderr, "A socket path (-s) is required in foreground mode.\n");
- exit(2);
- }
-
- s.pidfile = NULL;
- }
-
daemon_start(s);
return 0;
}
diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c
index 156925a..914b803 100644
--- a/libdaemon/server/daemon-server.c
+++ b/libdaemon/server/daemon-server.c
@@ -207,7 +207,9 @@ out:
static int _open_socket(daemon_state s)
{
int fd = -1;
+ int file_created = 0;
struct sockaddr_un sockaddr = { .sun_family = AF_UNIX };
+ struct stat buf;
mode_t old_mask;
(void) dm_prepare_selinux_context(s.socket_path, S_IFSOCK);
@@ -233,9 +235,47 @@ static int _open_socket(daemon_state s)
}
if (bind(fd, (struct sockaddr *) &sockaddr, sizeof(sockaddr))) {
- perror("can't bind local socket.");
- goto error;
+ if (errno != EADDRINUSE) {
+ perror("can't bind local socket");
+ goto error;
+ }
+
+ /* Socket already exists. If it's stale, remove it. */
+ if (stat(sockaddr.sun_path, &buf)) {
+ perror("stat failed");
+ goto error;
+ }
+
+ if (S_ISSOCK(buf.st_mode)) {
+ fprintf(stderr, "%s: not a socket\n", sockaddr.sun_path);
+ goto error;
+ }
+
+ if (buf.st_uid || (buf.st_mode & (S_IRWXG | S_IRWXO))) {
+ fprintf(stderr, "%s: unrecognised permissions\n", sockaddr.sun_path);
+ goto error;
+ }
+
+ if (!connect(fd, (struct sockaddr *) &sockaddr, sizeof(sockaddr))) {
+ fprintf(stderr, "Socket %s already in use\n", sockaddr.sun_path);
+ goto error;
+ }
+
+ fprintf(stderr, "removing stale socket %s\n", sockaddr.sun_path);
+
+ if (unlink(sockaddr.sun_path) && (errno != ENOENT)) {
+ perror("unlink failed");
+ goto error;
+ }
+
+ if (bind(fd, (struct sockaddr *) &sockaddr, sizeof(sockaddr))) {
+ perror("local socket bind failed after unlink");
+ goto error;
+ }
}
+
+ file_created = 1;
+
if (listen(fd, 1) != 0) {
perror("listen local");
goto error;
@@ -250,7 +290,7 @@ error:
if (fd >= 0) {
if (close(fd))
perror("close failed");
- if (unlink(s.socket_path))
+ if (file_created && unlink(s.socket_path))
perror("unlink failed");
fd = -1;
}
diff --git a/man/lvmetad.8.in b/man/lvmetad.8.in
index 7110877..4956a3f 100644
--- a/man/lvmetad.8.in
+++ b/man/lvmetad.8.in
@@ -6,8 +6,11 @@ lvmetad \- LVM metadata cache daemon
.RB [ \-l
.RI {all|wire|debug}
.RB ]
+.RB [ \-p
+.RI pidfile_path
+.RB ]
.RB [ \-s
-.RI path
+.RI socket_path
.RB ]
.RB [ \-f ]
.RB [ \-h ]
@@ -21,6 +24,15 @@ consistent image of the volume groups available in the system.
By default, lvmetad, even if running, is not used by LVM. See \fBlvm.conf\fP(5).
.SH OPTIONS
+
+To run the daemon in a test environment both the pidfile_path and the
+socket_path should be changed from the defaults.
+.TP
+.B \-f
+Don't fork, but run in the foreground.
+.TP
+.BR \-h ", " \-?
+Show help information.
.TP
.BR \-l " {" \fIall | \fIwire | \fIdebug }
Select the type of log messages to generate.
@@ -32,23 +44,27 @@ Selecting 'all' supplies both and is equivalent to a comma-separated list
Prior to release 2.02.98, repeating -d from 1 to 3 times, viz. -d, -dd, -ddd,
increased the detail of messages.
.TP
-.B \-f
-Don't fork, run in the foreground.
-.TP
-.BR \-h ", " \-?
-Show help information.
+.B \-p \fIpidfile_path
+Path to the pidfile. This overrides both the built-in default
+(#DEFAULT_PID_DIR#/lvmetad.pid) and the environment variable
+\fBLVM_LVMETAD_PIDFILE\fP. This file is used to prevent more
+than one instance of the daemon running simultaneously.
.TP
-.B \-s \fIpath
-Path to the socket file to use. The option overrides both the built-in default
+.B \-s \fIsocket_path
+Path to the socket file. This overrides both the built-in default
(#DEFAULT_RUN_DIR#/lvmetad.socket) and the environment variable
-\fBLVM_LVMETAD_SOCKET\fP.
+\fBLVM_LVMETAD_SOCKET\fP. To communicate successfully with lvmetad,
+all LVM2 processes should use the same socket path.
.TP
.B \-V
Display the version of lvmetad daemon.
.SH ENVIRONMENT VARIABLES
.TP
+.B LVM_LVMETAD_PIDFILE
+Path for the pid file.
+.TP
.B LVM_LVMETAD_SOCKET
-override path for socket file to use.
+Path for the socket file.
.SH SEE ALSO
.BR lvm (8),
diff --git a/test/lib/test.sh b/test/lib/test.sh
index 563ef59..265d61d 100644
--- a/test/lib/test.sh
+++ b/test/lib/test.sh
@@ -83,6 +83,7 @@ aux prepare_clvmd
test -n "$LVM_TEST_LVMETAD" && {
aux prepare_lvmetad
export LVM_LVMETAD_SOCKET="$TESTDIR/lvmetad.socket"
+ export LVM_LVMETAD_PIDFILE="$TESTDIR/lvmetad.pid"
}
echo "@TESTDIR=$TESTDIR"
echo "@PREFIX=$PREFIX"
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d2d5c24a68285a2f…
Commit: d2d5c24a68285a2f056977f877ab1a19e61b992f
Parent: 75628f341ad38b68aae33eae0b5700be2a6e5769
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri Nov 29 16:37:09 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Fri Nov 29 16:38:53 2013 +0100
configure: require libblkid >= 2.24 for blkid wiping
Some symbols/identifiers were defined even later than 2.22, like BLKID_SUBLKS_BADCSUM.
---
configure | 20 ++++++++++----------
configure.in | 4 ++--
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/configure b/configure
index 5d81dac..564d322 100755
--- a/configure
+++ b/configure
@@ -9211,12 +9211,12 @@ if test -n "$BLKID_CFLAGS"; then
pkg_cv_BLKID_CFLAGS="$BLKID_CFLAGS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"blkid >= 2.22\""; } >&5
- ($PKG_CONFIG --exists --print-errors "blkid >= 2.22") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"blkid >= 2.24\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "blkid >= 2.24") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_BLKID_CFLAGS=`$PKG_CONFIG --cflags "blkid >= 2.22" 2>/dev/null`
+ pkg_cv_BLKID_CFLAGS=`$PKG_CONFIG --cflags "blkid >= 2.24" 2>/dev/null`
else
pkg_failed=yes
fi
@@ -9227,12 +9227,12 @@ if test -n "$BLKID_LIBS"; then
pkg_cv_BLKID_LIBS="$BLKID_LIBS"
elif test -n "$PKG_CONFIG"; then
if test -n "$PKG_CONFIG" && \
- { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"blkid >= 2.22\""; } >&5
- ($PKG_CONFIG --exists --print-errors "blkid >= 2.22") 2>&5
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"blkid >= 2.24\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "blkid >= 2.24") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; then
- pkg_cv_BLKID_LIBS=`$PKG_CONFIG --libs "blkid >= 2.22" 2>/dev/null`
+ pkg_cv_BLKID_LIBS=`$PKG_CONFIG --libs "blkid >= 2.24" 2>/dev/null`
else
pkg_failed=yes
fi
@@ -9252,9 +9252,9 @@ else
_pkg_short_errors_supported=no
fi
if test $_pkg_short_errors_supported = yes; then
- BLKID_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "blkid >= 2.22" 2>&1`
+ BLKID_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "blkid >= 2.24" 2>&1`
else
- BLKID_PKG_ERRORS=`$PKG_CONFIG --print-errors "blkid >= 2.22" 2>&1`
+ BLKID_PKG_ERRORS=`$PKG_CONFIG --print-errors "blkid >= 2.24" 2>&1`
fi
# Put the nasty error message in config.log where it belongs
echo "$BLKID_PKG_ERRORS" >&5
@@ -9262,7 +9262,7 @@ fi
if test x$BLKID_WIPING = xmaybe; then
BLKID_WIPING=no
else
- as_fn_error $? "bailing out... blkid library >= 2.22 is required" "$LINENO" 5
+ as_fn_error $? "bailing out... blkid library >= 2.24 is required" "$LINENO" 5
fi
elif test $pkg_failed = untried; then
@@ -9271,7 +9271,7 @@ $as_echo "no" >&6; }
if test x$BLKID_WIPING = xmaybe; then
BLKID_WIPING=no
else
- as_fn_error $? "bailing out... blkid library >= 2.22 is required" "$LINENO" 5
+ as_fn_error $? "bailing out... blkid library >= 2.24 is required" "$LINENO" 5
fi
else
diff --git a/configure.in b/configure.in
index b4a407a..e4d0014 100644
--- a/configure.in
+++ b/configure.in
@@ -959,14 +959,14 @@ if test x$BLKID_WIPING != xno; then
if test x$PKGCONFIG_INIT != x1; then
pkg_config_init
fi
- PKG_CHECK_MODULES(BLKID, blkid >= 2.22,
+ PKG_CHECK_MODULES(BLKID, blkid >= 2.24,
[if test x$BLKID_WIPING = xmaybe; then
BLKID_WIPING=yes
fi],
[if test x$BLKID_WIPING = xmaybe; then
BLKID_WIPING=no
else
- AC_MSG_ERROR([bailing out... blkid library >= 2.22 is required])
+ AC_MSG_ERROR([bailing out... blkid library >= 2.24 is required])
fi
])
if test x$BLKID_WIPING = xyes; then
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=75628f341ad38b68…
Commit: 75628f341ad38b68aae33eae0b5700be2a6e5769
Parent: b3074560eb36d0b1c8ec61f50e71b0b27dbda982
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri Nov 29 15:27:56 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Fri Nov 29 15:27:56 2013 +0100
configure: enable blkid_wiping by default if the blkid library is present
---
WHATS_NEW | 3 +-
configure | 53 ++++++++++++++++++++--------------------------
configure.in | 29 +++++++++++++++++--------
lib/misc/configure.h.in | 2 +-
4 files changed, 46 insertions(+), 41 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 6aac94a..0101b49 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -3,7 +3,8 @@ Version 2.02.105 -
Append missing newline to lvmetad missing socket path error message.
Check for non-zero aligment in _text_pv_add_metadata_area() to not div by 0.
Add allocation/use_blkid_wiping to lvm.conf to enable blkid wiping.
- Add configure --enable-blkid_wiping to use libblkid to detect signatures.
+ Enable blkid_wiping by default if the blkid library is present.
+ Add configure --disable-blkid_wiping to disable libblkid signature detection.
Add -W/--wipesignatures lvcreate option to support wiping on new LVs.
Add allocation/wipe_signatures_on_new_logical_volumes_when_zeroing to lvm.conf.
Do not fail the whole autoactivation if the VG refresh done before fails.
diff --git a/configure b/configure
index 8247ddd..5d81dac 100755
--- a/configure
+++ b/configure
@@ -1563,7 +1563,8 @@ Optional Features:
--enable-valgrind-pool enable valgrind awareness of pools
--disable-devmapper disable LVM2 device-mapper interaction
--enable-lvmetad enable the LVM Metadata Daemon
- --enable-blkid_wiping use wiping functionality provided by libblkid
+ --disable-blkid_wiping disable libblkid detection of signatures when wiping
+ and use native code instead
--enable-udev-systemd-background-jobs
enable udev-systemd protocol to instantiate a
service for background job
@@ -9185,20 +9186,19 @@ _ACEOF
fi
################################################################################
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use blkid wiping functionality" >&5
-$as_echo_n "checking whether to use blkid wiping functionality... " >&6; }
-# Check whether --enable-blkid-wiping was given.
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable libblkid detection of signatures when wiping" >&5
+$as_echo_n "checking whether to enable libblkid detection of signatures when wiping... " >&6; }
+# Check whether --enable-blkid_wiping was given.
if test "${enable_blkid_wiping+set}" = set; then :
enableval=$enable_blkid_wiping; BLKID_WIPING=$enableval
else
- BLKID_WIPING=no
+ BLKID_WIPING=maybe
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $BLKID_WIPING" >&5
$as_echo "$BLKID_WIPING" >&6; }
-
-if test x$BLKID_WIPING = xyes; then
+if test x$BLKID_WIPING != xno; then
if test x$PKGCONFIG_INIT != x1; then
pkg_config_init
fi
@@ -9259,43 +9259,36 @@ fi
# Put the nasty error message in config.log where it belongs
echo "$BLKID_PKG_ERRORS" >&5
- as_fn_error $? "Package requirements (blkid >= 2.22) were not met:
-
-$BLKID_PKG_ERRORS
-
-Consider adjusting the PKG_CONFIG_PATH environment variable if you
-installed software in a non-standard prefix.
-
-Alternatively, you may set the environment variables BLKID_CFLAGS
-and BLKID_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details." "$LINENO" 5
+ if test x$BLKID_WIPING = xmaybe; then
+ BLKID_WIPING=no
+ else
+ as_fn_error $? "bailing out... blkid library >= 2.22 is required" "$LINENO" 5
+ fi
elif test $pkg_failed = untried; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
- { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it
-is in your PATH or set the PKG_CONFIG environment variable to the full
-path to pkg-config.
-
-Alternatively, you may set the environment variables BLKID_CFLAGS
-and BLKID_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details.
-
-To get pkg-config, see <http://pkg-config.freedesktop.org/ >.
-See \`config.log' for more details" "$LINENO" 5; }
+ if test x$BLKID_WIPING = xmaybe; then
+ BLKID_WIPING=no
+ else
+ as_fn_error $? "bailing out... blkid library >= 2.22 is required" "$LINENO" 5
+ fi
else
BLKID_CFLAGS=$pkg_cv_BLKID_CFLAGS
BLKID_LIBS=$pkg_cv_BLKID_LIBS
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
- BLKID_PC="blkid"
+ if test x$BLKID_WIPING = xmaybe; then
+ BLKID_WIPING=yes
+ fi
fi
+ if test x$BLKID_WIPING = xyes; then
+ BLKID_PC="blkid"
$as_echo "#define BLKID_WIPING_SUPPORT 1" >>confdefs.h
+ fi
fi
################################################################################
diff --git a/configure.in b/configure.in
index ff9bf81..b4a407a 100644
--- a/configure.in
+++ b/configure.in
@@ -947,21 +947,32 @@ fi
################################################################################
dnl -- Enable blkid wiping functionality
-AC_MSG_CHECKING(whether to use blkid wiping functionality)
-AC_ARG_ENABLE(blkid-wiping,
- AC_HELP_STRING([--enable-blkid_wiping],
- [use wiping functionality provided by libblkid]),
- BLKID_WIPING=$enableval, BLKID_WIPING=no)
+AC_MSG_CHECKING(whether to enable libblkid detection of signatures when wiping)
+AC_ARG_ENABLE(blkid_wiping,
+ AC_HELP_STRING([--disable-blkid_wiping],
+ [disable libblkid detection of signatures when wiping and use native code instead]),
+ BLKID_WIPING=$enableval, BLKID_WIPING=maybe)
AC_MSG_RESULT($BLKID_WIPING)
-
-if test x$BLKID_WIPING = xyes; then
+if test x$BLKID_WIPING != xno; then
dnl -- init pkgconfig if required
if test x$PKGCONFIG_INIT != x1; then
pkg_config_init
fi
- PKG_CHECK_MODULES(BLKID, blkid >= 2.22, [BLKID_PC="blkid"])
- AC_DEFINE([BLKID_WIPING_SUPPORT], 1, [Define to 1 to use wiping functionality provided by libblkid.])
+ PKG_CHECK_MODULES(BLKID, blkid >= 2.22,
+ [if test x$BLKID_WIPING = xmaybe; then
+ BLKID_WIPING=yes
+ fi],
+ [if test x$BLKID_WIPING = xmaybe; then
+ BLKID_WIPING=no
+ else
+ AC_MSG_ERROR([bailing out... blkid library >= 2.22 is required])
+ fi
+ ])
+ if test x$BLKID_WIPING = xyes; then
+ BLKID_PC="blkid"
+ AC_DEFINE([BLKID_WIPING_SUPPORT], 1, [Define to 1 to use libblkid detection of signatures when wiping.])
+ fi
fi
################################################################################
diff --git a/lib/misc/configure.h.in b/lib/misc/configure.h.in
index 51db42e..4e9ffd1 100644
--- a/lib/misc/configure.h.in
+++ b/lib/misc/configure.h.in
@@ -1,6 +1,6 @@
/* lib/misc/configure.h.in. Generated from configure.in by autoheader. */
-/* Define to 1 to use wiping functionality provided by libblkid. */
+/* Define to 1 to use libblkid detection of signatures when wiping. */
#undef BLKID_WIPING_SUPPORT
/* Define to 1 if the `closedir' function returns void instead of `int'. */
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b3074560eb36d0b1…
Commit: b3074560eb36d0b1c8ec61f50e71b0b27dbda982
Parent: 3f8083107ea901f9c58ef38ad9bb8084825a2f88
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Thu Nov 28 19:16:25 2013 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Thu Nov 28 19:16:25 2013 +0000
lvmetad: Add newline to missing socket error mesg
---
WHATS_NEW | 1 +
daemons/lvmetad/lvmetad-core.c | 2 +-
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index cd63144..6aac94a 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Append missing newline to lvmetad missing socket path error message.
Check for non-zero aligment in _text_pv_add_metadata_area() to not div by 0.
Add allocation/use_blkid_wiping to lvm.conf to enable blkid wiping.
Add configure --enable-blkid_wiping to use libblkid to detect signatures.
diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c
index 7e64d9d..71254f4 100644
--- a/daemons/lvmetad/lvmetad-core.c
+++ b/daemons/lvmetad/lvmetad-core.c
@@ -1242,7 +1242,7 @@ int main(int argc, char *argv[])
if (s.foreground) {
if (!_socket_override) {
- fprintf(stderr, "A socket path (-s) is required in foreground mode.");
+ fprintf(stderr, "A socket path (-s) is required in foreground mode.\n");
exit(2);
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3f8083107ea901f9…
Commit: 3f8083107ea901f9c58ef38ad9bb8084825a2f88
Parent: 08bab406b5bcae92df340209c1a0902e68aa1a28
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Nov 28 15:47:20 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Thu Nov 28 15:47:20 2013 +0100
tests: add test for lvcreate signature wiping
---
test/shell/lvcreate-signature-wiping.sh | 97 +++++++++++++++++++++++++++++++
1 files changed, 97 insertions(+), 0 deletions(-)
diff --git a/test/shell/lvcreate-signature-wiping.sh b/test/shell/lvcreate-signature-wiping.sh
new file mode 100644
index 0000000..617fed1
--- /dev/null
+++ b/test/shell/lvcreate-signature-wiping.sh
@@ -0,0 +1,97 @@
+#!/bin/sh
+# Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+#
+# 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
+
+# 'Exercise signature wiping during lvcreate'
+
+. lib/test
+
+aux prepare_devs 1
+aux pvcreate -f $dev1
+aux vgcreate $vg $dev1
+
+# lvcreate wipes signatures when found on newly created LV - test this on "swap".
+# Test all combinatios with -Z{y|n} and -W{y|n} and related lvm.conf settings.
+
+lvcreate -l1 -n $lv1 $vg
+mkswap "$DM_DEV_DIR/$vg/$lv1"
+blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" | grep "swap"
+lvremove -f $vg/$lv1
+
+wiping_msg="Wiping swap signature"
+
+aux lvmconf "allocation/wipe_signatures_on_new_logical_volumes_when_zeroing = 0"
+
+lvcreate -y -Zn -l1 -n $lv1 $vg | not grep "$wiping_msg"
+blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" | grep "swap"
+lvremove -f $vg/$lv1
+
+lvcreate -y -Zn -Wn -l1 -n $lv1 $vg | not grep "$wiping_msg"
+blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" | grep "swap"
+lvremove -f $vg/$lv1
+
+lvcreate -y -Zn -Wy -l1 -n $lv1 $vg | grep "$wiping_msg"
+(blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" || true) | not grep "swap"
+mkswap "$DM_DEV_DIR/$vg/$lv1"
+blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" | grep "swap"
+lvremove -f $vg/$lv1
+
+lvcreate -y -Zy -l1 -n $lv1 $vg | not grep "$wiping_msg"
+mkswap "$DM_DEV_DIR/$vg/$lv1"
+blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" | grep "swap"
+lvremove -f $vg/$lv1
+
+lvcreate -y -Zy -Wn -l1 -n $lv1 $vg | not grep "$wiping_msg"
+mkswap "$DM_DEV_DIR/$vg/$lv1"
+blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" | grep "swap"
+lvremove -f $vg/$lv1
+
+lvcreate -y -Zy -Wy -l1 -n $lv1 $vg | grep "$wiping_msg"
+mkswap "$DM_DEV_DIR/$vg/$lv1"
+blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" | grep "swap"
+lvremove -f $vg/$lv1
+
+
+aux lvmconf "allocation/wipe_signatures_on_new_logical_volumes_when_zeroing = 1"
+
+lvcreate -y -Zn -l1 -n $lv1 $vg | not grep "$wiping_msg"
+blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" | grep "swap"
+lvremove -f $vg/$lv1
+
+lvcreate -y -Zn -Wn -l1 -n $lv1 $vg | not grep "$wiping_msg"
+blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" | grep "swap"
+lvremove -f $vg/$lv1
+
+lvcreate -y -Zn -Wy -l1 -n $lv1 $vg | grep "$wiping_msg"
+(blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" || true) | not grep "swap"
+mkswap "$DM_DEV_DIR/$vg/$lv1"
+blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" | grep "swap"
+lvremove -f $vg/$lv1
+
+lvcreate -y -Zy -l1 -n $lv1 $vg | grep "$wiping_msg"
+(blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" || true) | not grep "swap"
+mkswap "$DM_DEV_DIR/$vg/$lv1"
+blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" | grep "swap"
+lvremove -f $vg/$lv1
+
+lvcreate -y -Zy -Wn -l1 -n $lv1 $vg | not grep "$wiping_msg"
+mkswap "$DM_DEV_DIR/$vg/$lv1"
+blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" | grep "swap"
+lvremove -f $vg/$lv1
+
+lvcreate -y -Zy -Wy -l1 -n $lv1 $vg | grep "$wiping_msg"
+(blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" || true) | not grep "swap"
+mkswap "$DM_DEV_DIR/$vg/$lv1"
+blkid -c /dev/null "$DM_DEV_DIR/$vg/$lv1" | grep "swap"
+lvremove -f $vg/$lv1
+
+
+vgremove $vg
+pvremove $dev1
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=08bab406b5bcae92…
Commit: 08bab406b5bcae92df340209c1a0902e68aa1a28
Parent: c24b558c8c3e8f877e7cf216369e3415be8dbc6f
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Nov 28 14:10:55 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Thu Nov 28 14:10:55 2013 +0100
tests: wipe fs signature manually in pvcreate-operation test
So that the next pvcreate that is called does not issue any
warnings/prompts about existing signature (when blkid wiping is used).
---
test/shell/pvcreate-operation.sh | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/test/shell/pvcreate-operation.sh b/test/shell/pvcreate-operation.sh
index ddcf94c..b885ed2 100644
--- a/test/shell/pvcreate-operation.sh
+++ b/test/shell/pvcreate-operation.sh
@@ -23,6 +23,9 @@ do
not pvcreate -M$mdatype "$dev1" 2>err
grep "Can't open "$dev1" exclusively. Mounted filesystem?" err
umount "$dev1"
+ # wipe the filesystem signature for next
+ # pvcreate to not issue any prompts
+ dd if=/dev/zero of=$dev1 bs=1K count=2
fi
# pvcreate (lvm$mdatype) succeeds when run repeatedly (pv not in a vg) (bz178216)
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c24b558c8c3e8f87…
Commit: c24b558c8c3e8f877e7cf216369e3415be8dbc6f
Parent: 6a1957badcb95a5f2815436e64798b48ed85ca0c
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Nov 28 13:23:45 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Thu Nov 28 13:27:52 2013 +0100
tests: initialize signature wiping
Do not use signature wiping for newly created LVs in tests - we're
reusing the devs in tests and such detection could just interfere
inappropriately. We'd need to modify all tests to anwer the prompt
whether any signature found should be removed or not or we'd need
to use "-y" option for all lvcreates in tests. It's better to disable
this feature then and let's do a separate test to test this signature
wiping functionality.
---
test/lib/aux.sh | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index 4ef1132..d1ae524 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -563,6 +563,7 @@ activation/polling_interval = 0
activation/snapshot_autoextend_percent = 50
activation/snapshot_autoextend_threshold = 50
activation/monitoring = 0
+allocation/wipe_signatures_on_new_logical_volumes_when_zeroing = 0
EOF
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6a1957badcb95a5f…
Commit: 6a1957badcb95a5f2815436e64798b48ed85ca0c
Parent: ce8ebda3fc0e8275d15f8cdc7f6f21162c7c1636
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Nov 28 13:14:46 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Thu Nov 28 13:14:46 2013 +0100
pvcreate: do not issue warning about any existing PV
If we're calling pvcreate on a device that already has a PV label,
the blkid detects the existing PV and then we consider it for wiping
before we continue creating the new PV label and we issue a warning
with a prompt whether such old PV label should be removed. We don't
do this with native signature detection code. Let's make it consistent
with old behaviour.
But still keep this "PV" (identified as "LVM1_member" or "LVM2_member"
by blkid) detection when creating new LVs to avoid unexpected PV label
appeareance inside LV.
---
lib/device/dev-type.c | 20 ++++++++++++++------
lib/device/dev-type.h | 3 ++-
lib/metadata/lv_manip.c | 2 +-
lib/metadata/metadata.c | 2 +-
4 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c
index 04b555b..78b093c 100644
--- a/lib/device/dev-type.c
+++ b/lib/device/dev-type.c
@@ -449,8 +449,8 @@ out:
#ifdef BLKID_WIPING_SUPPORT
-static int _blkid_wipe(blkid_probe probe, struct device *dev,
- const char *name, int yes, force_t force)
+static int _blkid_wipe(blkid_probe probe, struct device *dev, const char *name,
+ int exclude_lvm_member, int yes, force_t force)
{
const char *offset = NULL, *type = NULL, *magic = NULL,
*usage = NULL, *label = NULL, *uuid = NULL;
@@ -458,6 +458,9 @@ static int _blkid_wipe(blkid_probe probe, struct device *dev,
size_t len;
if (!blkid_probe_lookup_value(probe, "TYPE", &type, NULL)) {
+ if (exclude_lvm_member &&
+ (!strcmp(type, "LVM1_member") || !strcmp(type, "LVM2_member")))
+ return 1;
if (!blkid_probe_lookup_value(probe, "SBMAGIC_OFFSET", &offset, NULL) &&
blkid_probe_lookup_value(probe, "SBMAGIC", &magic, &len))
return_0;
@@ -495,6 +498,7 @@ static int _blkid_wipe(blkid_probe probe, struct device *dev,
}
static int _wipe_known_signatures_with_blkid(struct device *dev, const char *name,
+ int exclude_lvm_member,
int yes, force_t force)
{
blkid_probe probe = NULL;
@@ -522,7 +526,7 @@ static int _wipe_known_signatures_with_blkid(struct device *dev, const char *nam
while (!blkid_do_probe(probe)) {
found++;
- if (_blkid_wipe(probe, dev, name, yes, force))
+ if (_blkid_wipe(probe, dev, name, exclude_lvm_member, yes, force))
wiped++;
}
@@ -576,6 +580,7 @@ static int _wipe_signature(struct device *dev, const char *type, const char *nam
}
static int _wipe_known_signatures_with_lvm(struct device *dev, const char *name,
+ int exclude_lvm_member,
int yes, force_t force)
{
if (!_wipe_signature(dev, "software RAID md superblock", name, 4, yes, force, dev_is_md) ||
@@ -587,13 +592,16 @@ static int _wipe_known_signatures_with_lvm(struct device *dev, const char *name,
}
int wipe_known_signatures(struct cmd_context *cmd, struct device *dev,
- const char *name, int yes, force_t force)
+ const char *name, int exclude_lvm_member,
+ int yes, force_t force)
{
#ifdef BLKID_WIPING_SUPPORT
if (find_config_tree_bool(cmd, allocation_use_blkid_wiping_CFG, NULL))
- return _wipe_known_signatures_with_blkid(dev, name, yes, force);
+ return _wipe_known_signatures_with_blkid(dev, name,
+ exclude_lvm_member, yes, force);
#endif
- return _wipe_known_signatures_with_lvm(dev, name, yes, force);
+ return _wipe_known_signatures_with_lvm(dev, name,
+ exclude_lvm_member, yes, force);
}
#ifdef __linux__
diff --git a/lib/device/dev-type.h b/lib/device/dev-type.h
index 39d947b..284280e 100644
--- a/lib/device/dev-type.h
+++ b/lib/device/dev-type.h
@@ -60,7 +60,8 @@ int dev_is_swap(struct device *dev, uint64_t *signature);
int dev_is_luks(struct device *dev, uint64_t *signature);
/* Signature wiping. */
-int wipe_known_signatures(struct cmd_context *cmd, struct device *dev, const char *name, int yes, force_t force);
+int wipe_known_signatures(struct cmd_context *cmd, struct device *dev, const char *name,
+ int exclude_lvm_member, int yes, force_t force);
/* Type-specific device properties */
unsigned long dev_md_stripe_width(struct dev_types *dt, struct device *dev);
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index fe9e656..c67dd38 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -5415,7 +5415,7 @@ int wipe_lv(struct logical_volume *lv, struct wipe_params wp)
if (wp.do_wipe_signatures) {
log_verbose("Wiping known signatures on logical volume \"%s/%s\"",
lv->vg->name, lv->name);
- if (!wipe_known_signatures(lv->vg->cmd, dev, name, wp.yes, wp.force))
+ if (!wipe_known_signatures(lv->vg->cmd, dev, name, 0, wp.yes, wp.force))
stack;
}
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index d55dba1..f075c21 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -1328,7 +1328,7 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,
goto bad;
}
- if (!wipe_known_signatures(cmd, dev, name, pp->yes, pp->force)) {
+ if (!wipe_known_signatures(cmd, dev, name, 1, pp->yes, pp->force)) {
log_error("Aborting pvcreate on %s.", name);
goto bad;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ce8ebda3fc0e8275…
Commit: ce8ebda3fc0e8275d15f8cdc7f6f21162c7c1636
Parent: 6bf6430ae94e2a0e8239b198e35b53abbaa3f041
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Nov 28 11:35:53 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:48:01 2013 +0100
cleanup: tab indent
---
lib/metadata/lv_manip.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 1fec9a5..fe9e656 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -4725,7 +4725,7 @@ int lv_remove_with_dependencies(struct cmd_context *cmd, struct logical_volume *
yes_no_prompt("Removing origin %s will also remove %u "
"snapshots(s). Proceed? [y/n]: ",
lv->name, lv->origin_count) == 'n')
- goto no_remove;
+ goto no_remove;
dm_list_iterate_safe(snh, snht, &lv->snapshot_segs)
if (!lv_remove_with_dependencies(cmd, dm_list_struct_base(snh, struct lv_segment,
@@ -4762,7 +4762,7 @@ int lv_remove_with_dependencies(struct cmd_context *cmd, struct logical_volume *
(yes_no_prompt("Removal of pool metadata spare logical volume \"%s\" "
"disables automatic recovery attempts after damage "
"to a thin pool. Proceed? [y/n]: ", lv->name) == 'n'))
- goto no_remove;
+ goto no_remove;
return lv_remove_single(cmd, lv, force);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6bf6430ae94e2a0e…
Commit: 6bf6430ae94e2a0e8239b198e35b53abbaa3f041
Parent: 5bdbaf4ed7a0f8b8e032d4f8d76bb63f8ec071b8
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 25 14:34:34 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:48:01 2013 +0100
cleanup: convert log_error with log_warn
Collapse 2 ifs and replace log_error() with log_warn(), since\
the reported message is not causing tools error.
(and cannot be probably triggered anyway).
---
lib/activate/dev_manager.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index e53273d..bed4d60 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -112,9 +112,9 @@ static int _info_run(const char *name, const char *dlid, struct dm_info *info,
if (!(dmt = _setup_task(mknodes ? name : NULL, dlid, 0, dmtask, major, minor)))
return_0;
- if (!with_open_count)
- if (!dm_task_no_open_count(dmt))
- log_error("Failed to disable open_count");
+ if (!with_open_count &&
+ !dm_task_no_open_count(dmt))
+ log_warn("WARNING: Failed to disable open_count.");
if (!dm_task_run(dmt))
goto_out;
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5bdbaf4ed7a0f8b8…
Commit: 5bdbaf4ed7a0f8b8e032d4f8d76bb63f8ec071b8
Parent: 6c787d9b6ed9c9ef2964431881884dd3879f4dc1
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 25 13:46:34 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:48:01 2013 +0100
cleanup: convert log_sys_error to log_sys_debug
Use debug for those error reports which do not lead to error return
call.
---
daemons/dmeventd/libdevmapper-event.c | 8 ++++----
lib/locking/file_locking.c | 10 +++++-----
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/daemons/dmeventd/libdevmapper-event.c b/daemons/dmeventd/libdevmapper-event.c
index 9e8911e..1b5273d 100644
--- a/daemons/dmeventd/libdevmapper-event.c
+++ b/daemons/dmeventd/libdevmapper-event.c
@@ -425,7 +425,7 @@ static int _start_daemon(char *dmeventd_path, struct dm_event_fifos *fifos)
if (fifos->client >= 0) {
/* server is running and listening */
if (close(fifos->client))
- log_sys_error("close", fifos->client_path);
+ log_sys_debug("close", fifos->client_path);
return 1;
} else if (errno != ENXIO) {
/* problem */
@@ -507,14 +507,14 @@ static int _init_client(char *dmeventd_path, struct dm_event_fifos *fifos)
void fini_fifos(struct dm_event_fifos *fifos)
{
if (fifos->client >= 0 && close(fifos->client))
- log_sys_error("close", fifos->client_path);
+ log_sys_debug("close", fifos->client_path);
if (fifos->server >= 0) {
if (flock(fifos->server, LOCK_UN))
- log_sys_error("flock unlock", fifos->server_path);
+ log_sys_debug("flock unlock", fifos->server_path);
if (close(fifos->server))
- log_sys_error("close", fifos->server_path);
+ log_sys_debug("close", fifos->server_path);
}
}
diff --git a/lib/locking/file_locking.c b/lib/locking/file_locking.c
index 3fa0a2d..1fa23b3 100644
--- a/lib/locking/file_locking.c
+++ b/lib/locking/file_locking.c
@@ -54,10 +54,10 @@ static void _undo_flock(const char *file, int fd)
!fstat(fd, &buf2) &&
is_same_inode(buf1, buf2))
if (unlink(file))
- log_sys_error("unlink", file);
+ log_sys_debug("unlink", file);
if (close(fd) < 0)
- log_sys_error("close", file);
+ log_sys_debug("close", file);
}
static int _release_lock(const char *file, int unlock)
@@ -73,7 +73,7 @@ static int _release_lock(const char *file, int unlock)
if (unlock) {
log_very_verbose("Unlocking %s", ll->res);
if (flock(ll->lf, LOCK_NB | LOCK_UN))
- log_sys_error("flock", ll->res);
+ log_sys_debug("flock", ll->res);
}
_undo_flock(ll->res, ll->lf);
@@ -141,7 +141,7 @@ static int _do_flock(const char *file, int *fd, int operation, uint32_t nonblock
operation == LOCK_EX ? 'W' : 'R', nonblock ? ' ' : 'B');
do {
if ((*fd > -1) && close(*fd))
- log_sys_error("close", file);
+ log_sys_debug("close", file);
if ((*fd = open(file, O_CREAT | O_APPEND | O_RDWR, 0777)) < 0) {
log_sys_error("open", file);
@@ -162,7 +162,7 @@ static int _do_flock(const char *file, int *fd, int operation, uint32_t nonblock
errno = old_errno;
log_sys_error("flock", file);
if (close(*fd))
- log_sys_error("close", file);
+ log_sys_debug("close", file);
*fd = -1;
return 0;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6c787d9b6ed9c9ef…
Commit: 6c787d9b6ed9c9ef2964431881884dd3879f4dc1
Parent: 50e1fad86a5ca85965222d2ba9b8a7076d07cbbc
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 25 13:43:25 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:48:01 2013 +0100
cleanup: move declaration to the front
---
daemons/lvmetad/lvmetad-core.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c
index 87374e8..7e64d9d 100644
--- a/daemons/lvmetad/lvmetad-core.c
+++ b/daemons/lvmetad/lvmetad-core.c
@@ -791,7 +791,7 @@ static response pv_gone(lvmetad_state *s, request r)
const char *pvid = daemon_request_str(r, "uuid", NULL);
int64_t device = daemon_request_int(r, "device", 0);
struct dm_config_tree *pvmeta;
- char *pvid_old;
+ char *pvid_old, *vgid;
DEBUGLOG(s, "pv_gone: %s / %" PRIu64, pvid, device);
@@ -807,7 +807,7 @@ static response pv_gone(lvmetad_state *s, request r)
pvmeta = dm_hash_lookup(s->pvid_to_pvmeta, pvid);
pvid_old = dm_hash_lookup_binary(s->device_to_pvid, &device, sizeof(device));
- char *vgid = dm_hash_lookup(s->pvid_to_vgid, pvid);
+ vgid = dm_hash_lookup(s->pvid_to_vgid, pvid);
if (vgid && !(vgid = dm_strdup(vgid))) {
unlock_pvid_to_pvmeta(s);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=50e1fad86a5ca859…
Commit: 50e1fad86a5ca85965222d2ba9b8a7076d07cbbc
Parent: c6cfd7b2b93645a96db74f90d57bc5031704c298
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 25 13:42:30 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:47:51 2013 +0100
cleanup: use matching signed types
---
daemons/clvmd/clvmd.c | 2 +-
lib/metadata/mirror.c | 2 +-
libdaemon/server/daemon-log.c | 4 ++--
tools/lvconvert.c | 4 ++--
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index d57c0fd..fc8cf6e 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -1095,7 +1095,7 @@ static int verify_message(char *buf, int len)
{
struct clvm_header *h = (struct clvm_header *)buf;
- if (len < sizeof(struct clvm_header)) {
+ if (len < (int)sizeof(struct clvm_header)) {
log_error("verify_message short len %d", len);
return -1;
}
diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c
index a2b2feb..6fc7674 100644
--- a/lib/metadata/mirror.c
+++ b/lib/metadata/mirror.c
@@ -847,7 +847,7 @@ static int _remove_mirror_images(struct logical_volume *lv,
uint32_t new_area_count = mirrored_seg->area_count;
struct lv_list *lvl;
struct dm_list tmp_orphan_lvs;
- int orig_removed = num_removed;
+ uint32_t orig_removed = num_removed;
if (removed)
*removed = 0;
diff --git a/libdaemon/server/daemon-log.c b/libdaemon/server/daemon-log.c
index c9e133c..91900af 100644
--- a/libdaemon/server/daemon-log.c
+++ b/libdaemon/server/daemon-log.c
@@ -51,7 +51,7 @@ struct backend backend[] = {
void daemon_log(log_state *s, int type, const char *message) {
int i = 0;
while ( backend[i].id ) {
- if ( (s->log_config[type] & backend[i].id) == backend[i].id )
+ if ((int)(s->log_config[type] & backend[i].id) == backend[i].id )
backend[i].log( s, &s->backend_state[i], type, message );
++ i;
}
@@ -60,7 +60,7 @@ void daemon_log(log_state *s, int type, const char *message) {
static int _type_interesting(log_state *s, int type) {
int i = 0;
while ( backend[i].id ) {
- if ( (s->log_config[type] & backend[i].id) == backend[i].id )
+ if ((int)(s->log_config[type] & backend[i].id) == backend[i].id )
return 1;
++ i;
}
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 9a542a6..6f81356 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -958,7 +958,7 @@ static void _lvconvert_mirrors_repair_ask(struct cmd_context *cmd,
* 1 = 'disk'
* 2+ = 'mirrored'
*/
-static int _get_log_count(struct logical_volume *lv)
+static uint32_t _get_log_count(struct logical_volume *lv)
{
struct logical_volume *log_lv;
@@ -1434,7 +1434,7 @@ int mirror_remove_missing(struct cmd_context *cmd,
if (!(failed_pvs = _failed_pv_list(lv->vg)))
return_0;
- if (force && _failed_mirrors_count(lv) == lv_mirror_count(lv)) {
+ if (force && _failed_mirrors_count(lv) == (int)lv_mirror_count(lv)) {
log_error("No usable images left in %s.", lv->name);
return lv_remove_with_dependencies(cmd, lv, DONT_PROMPT, 0);
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c6cfd7b2b93645a9…
Commit: c6cfd7b2b93645a96db74f90d57bc5031704c298
Parent: bfcf3edcc69243cfcef6e73e8bbcba0e60366802
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Nov 24 19:03:29 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:45:52 2013 +0100
cleanup: drop extra dm_list_empty
Since dm_list_first has this check already include,
skip extra call in while().
Moreover analyzers are then sure pvl is not NULL.
---
lib/metadata/metadata.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 60be61e..d55dba1 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -2798,8 +2798,7 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd,
baton.warnings = warnings;
baton.vg = vg;
- while (!dm_list_empty(&head.list)) {
- pvl = (struct pv_list *) dm_list_first(&head.list);
+ while ((pvl = (struct pv_list *) dm_list_first(&head.list))) {
dm_list_del(&pvl->list);
add_pvl_to_vgs(vg, pvl);
vg->extent_count += pvl->pv->pe_count;
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=bfcf3edcc69243cf…
Commit: bfcf3edcc69243cfcef6e73e8bbcba0e60366802
Parent: 8c96afd361686647e10f3bf70c03dea62b82bc01
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Nov 24 18:59:46 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:45:52 2013 +0100
cleanup: fold test into printf arg
When arg is folded, compiler is able to check all args.
(better for security)
---
lib/metadata/metadata.c | 6 ++----
1 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 5c87ab6..60be61e 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -43,9 +43,6 @@ static struct physical_volume *_pv_read(struct cmd_context *cmd,
static uint32_t _vg_bad_status_bits(const struct volume_group *vg,
uint64_t status);
-const char _really_init[] =
- "Really INITIALIZE physical volume \"%s\" of volume group \"%s\" [y/n]? ";
-
static int _alignment_overrides_default(unsigned long data_alignment,
unsigned long default_pe_align)
{
@@ -1294,7 +1291,8 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,
/* prompt */
if (pv && !is_orphan(pv) && !pp->yes &&
- yes_no_prompt(_really_init, name, pv_vg_name(pv)) == 'n') {
+ yes_no_prompt("Really INITIALIZE physical volume \"%s\" of volume group \"%s\" [y/n]? ",
+ name, pv_vg_name(pv)) == 'n') {
log_error("%s: physical volume not initialized", name);
goto bad;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=8c96afd361686647…
Commit: 8c96afd361686647e10f3bf70c03dea62b82bc01
Parent: a1eda8ea245ec7af684fb50e7f0abf5229d9bcfb
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Nov 28 11:22:24 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:45:52 2013 +0100
cleanup: use compound literals for wipe_lv
Optimize and cleanup recently introduced new function wipe_lv.
Use compound literals to get nicely initialized wipe_params struct.
Pass in lv as explicit argument for wipe_lv.
Use cmd from lv structure.
Initialize only non-null members so it's easy to see what
is the special arg.
---
lib/metadata/lv_manip.c | 73 ++++++++++++++-----------------------
lib/metadata/metadata-exported.h | 5 +--
lib/metadata/mirror.c | 13 ++-----
lib/metadata/raid_manip.c | 11 +-----
lib/metadata/thin_manip.c | 13 +------
tools/lvchange.c | 13 +------
tools/lvconvert.c | 27 ++------------
7 files changed, 40 insertions(+), 115 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 2480942..1fec9a5 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -2906,17 +2906,8 @@ static int _lv_extend_layered_lv(struct alloc_handle *ah,
* wipe '1' to remove the superblock of any previous
* RAID devices. It is much quicker.
*/
- struct wipe_lv_params wp = {
- .lv = meta_lv,
- .do_zero = 1,
- .zero_sectors = 1,
- .zero_value = 0,
- .do_wipe_signatures = 0,
- .yes = 0,
- .force = PROMPT
- };
-
- if (!wipe_lv(meta_lv->vg->cmd, &wp)) {
+ if (!wipe_lv(meta_lv, (struct wipe_params)
+ { .do_zero = 1, .zero_sectors = 1 })) {
log_error("Failed to zero %s/%s",
meta_lv->vg->name, meta_lv->name);
return 0;
@@ -5382,19 +5373,19 @@ int insert_layer_for_segments_on_pv(struct cmd_context *cmd,
/*
* Initialize the LV with 'value'.
*/
-int wipe_lv(struct cmd_context *cmd, struct wipe_lv_params *wp)
+int wipe_lv(struct logical_volume *lv, struct wipe_params wp)
{
struct device *dev;
- char *name;
+ char name[PATH_MAX];
uint64_t zero_sectors;
- if (!(wp->do_zero || wp->do_wipe_signatures))
+ if (!wp.do_zero && !wp.do_wipe_signatures)
/* nothing to do */
return 1;
- if (!lv_is_active_locally(wp->lv)) {
+ if (!lv_is_active_locally(lv)) {
log_error("Volume \"%s/%s\" is not active locally.",
- wp->lv->vg->name, wp->lv->name);
+ lv->vg->name, lv->name);
return 0;
}
@@ -5405,18 +5396,13 @@ int wipe_lv(struct cmd_context *cmd, struct wipe_lv_params *wp)
* <ejt_> k, I'll drop a fixme to that effect
* (I know the device is at least 4k, but not 32k)
*/
- if (!(name = dm_pool_alloc(cmd->mem, PATH_MAX))) {
- log_error("Name allocation failed - device not cleared");
- return 0;
- }
-
- if (dm_snprintf(name, PATH_MAX, "%s%s/%s", cmd->dev_dir,
- wp->lv->vg->name, wp->lv->name) < 0) {
- log_error("Name too long - device not cleared (%s)", wp->lv->name);
+ if (dm_snprintf(name, sizeof(name), "%s%s/%s", lv->vg->cmd->dev_dir,
+ lv->vg->name, lv->name) < 0) {
+ log_error("Name too long - device not cleared (%s)", lv->name);
return 0;
}
- sync_local_dev_names(cmd); /* Wait until devices are available */
+ sync_local_dev_names(lv->vg->cmd); /* Wait until devices are available */
if (!(dev = dev_cache_get(name, NULL))) {
log_error("%s: not found: device not cleared", name);
@@ -5426,23 +5412,23 @@ int wipe_lv(struct cmd_context *cmd, struct wipe_lv_params *wp)
if (!dev_open_quiet(dev))
return_0;
- if (wp->do_wipe_signatures) {
+ if (wp.do_wipe_signatures) {
log_verbose("Wiping known signatures on logical volume \"%s/%s\"",
- wp->lv->vg->name, wp->lv->name);
- if (!wipe_known_signatures(cmd, dev, name, wp->yes, wp->force))
+ lv->vg->name, lv->name);
+ if (!wipe_known_signatures(lv->vg->cmd, dev, name, wp.yes, wp.force))
stack;
}
- if (wp->do_zero) {
- zero_sectors = wp->zero_sectors ? : UINT64_C(4096) >> SECTOR_SHIFT;
+ if (wp.do_zero) {
+ zero_sectors = wp.zero_sectors ? : UINT64_C(4096) >> SECTOR_SHIFT;
- if (zero_sectors > wp->lv->size)
- zero_sectors = wp->lv->size;
+ if (zero_sectors > lv->size)
+ zero_sectors = lv->size;
log_verbose("Clearing start of logical volume \"%s/%s\"",
- wp->lv->vg->name, wp->lv->name);
+ lv->vg->name, lv->name);
- if (!dev_set(dev, UINT64_C(0), (size_t) zero_sectors << SECTOR_SHIFT, wp->zero_value))
+ if (!dev_set(dev, UINT64_C(0), (size_t) zero_sectors << SECTOR_SHIFT, wp.zero_value))
stack;
}
@@ -5451,7 +5437,7 @@ int wipe_lv(struct cmd_context *cmd, struct wipe_lv_params *wp)
if (!dev_close_immediate(dev))
stack;
- wp->lv->status &= ~LV_NOSCAN;
+ lv->status &= ~LV_NOSCAN;
return 1;
}
@@ -6094,16 +6080,13 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
if ((!seg_is_thin(lp) ||
(lv_is_thin_volume(lv) && !lp->snapshot &&
!first_seg(first_seg(lv)->pool_lv)->zero_new_blocks))) {
- struct wipe_lv_params wp = {
- .lv = lv,
- .do_zero = lp->zero,
- .zero_sectors = 0,
- .zero_value = 0,
- .do_wipe_signatures = lp->wipe_signatures,
- .yes = lp->yes,
- .force = lp->force
- };
- if (!wipe_lv(cmd, &wp)) {
+ if (!wipe_lv(lv, (struct wipe_params)
+ {
+ .do_zero = lp->zero,
+ .do_wipe_signatures = lp->wipe_signatures,
+ .yes = lp->yes,
+ .force = lp->force
+ })) {
log_error("Aborting. Failed to wipe %s.",
lp->snapshot ? "snapshot exception store" :
"start of new LV");
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index c274649..ece5f53 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -622,8 +622,7 @@ struct logical_volume *lv_create_empty(const char *name,
alloc_policy_t alloc,
struct volume_group *vg);
-struct wipe_lv_params {
- struct logical_volume *lv;
+struct wipe_params {
int do_zero; /* should we do zeroing of LV start? */
uint64_t zero_sectors; /* sector count to zero */
int zero_value; /* zero-out with this value */
@@ -633,7 +632,7 @@ struct wipe_lv_params {
};
/* Zero out LV and/or wipe signatures */
-int wipe_lv(struct cmd_context *cmd, struct wipe_lv_params *params);
+int wipe_lv(struct logical_volume *lv, struct wipe_params params);
int lv_change_tag(struct logical_volume *lv, const char *tag, int add_tag);
diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c
index 83ba486..a2b2feb 100644
--- a/lib/metadata/mirror.c
+++ b/lib/metadata/mirror.c
@@ -340,16 +340,9 @@ static int _init_mirror_log(struct cmd_context *cmd,
str_list_del(&log_lv->tags, sl->str);
if (activation()) {
- struct wipe_lv_params wp = {
- .lv = log_lv,
- .do_zero = 1,
- .zero_sectors = log_lv->size,
- .zero_value = in_sync ? -1 : 0,
- .do_wipe_signatures = 0,
- .yes = 0,
- .force = PROMPT
- };
- if (!wipe_lv(cmd, &wp)) {
+ if (!wipe_lv(log_lv, (struct wipe_params)
+ { .do_zero = 1, .zero_sectors = log_lv->size,
+ .zero_value = in_sync ? -1 : 0 })) {
log_error("Aborting. Failed to wipe mirror log.");
goto deactivate_and_revert_new_lv;
}
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index d1bb330..a29ea85 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -170,15 +170,6 @@ static int _raid_remove_top_layer(struct logical_volume *lv,
static int _clear_lv(struct logical_volume *lv)
{
int was_active = lv_is_active_locally(lv);
- struct wipe_lv_params wp = {
- .lv = lv,
- .do_zero = 1,
- .zero_sectors = 1,
- .zero_value = 0,
- .do_wipe_signatures = 0,
- .yes = 0,
- .force = PROMPT
- };
if (test_mode())
return 1;
@@ -196,7 +187,7 @@ static int _clear_lv(struct logical_volume *lv)
* wipe the first sector to remove the superblock of any previous
* RAID devices. It is much quicker.
*/
- if (!wipe_lv(lv->vg->cmd, &wp)) {
+ if (!wipe_lv(lv, (struct wipe_params) { .do_zero = 1, .zero_sectors = 1 })) {
log_error("Failed to zero %s", lv->name);
return 0;
}
diff --git a/lib/metadata/thin_manip.c b/lib/metadata/thin_manip.c
index 4ee4411..b3fedcf 100644
--- a/lib/metadata/thin_manip.c
+++ b/lib/metadata/thin_manip.c
@@ -467,21 +467,10 @@ int create_pool(struct logical_volume *pool_lv, const struct segment_type *segty
*
* FIXME: implement lazy clearing when activation is disabled
*/
-
- struct wipe_lv_params wp = {
- .lv = pool_lv,
- .do_zero = 1,
- .zero_sectors = 0,
- .zero_value = 0,
- .do_wipe_signatures = 0,
- .yes = 0,
- .force = PROMPT
- };
-
/* pool_lv is a new LV so the VG lock protects us */
if (!activate_lv_local(pool_lv->vg->cmd, pool_lv) ||
/* Clear 4KB of metadata device for new thin-pool. */
- !wipe_lv(pool_lv->vg->cmd, &wp)) {
+ !wipe_lv(pool_lv, (struct wipe_params) { .do_zero = 1 })) {
log_error("Aborting. Failed to wipe pool metadata %s.",
pool_lv->name);
goto bad;
diff --git a/tools/lvchange.c b/tools/lvchange.c
index 59a554c..a0e350f 100644
--- a/tools/lvchange.c
+++ b/tools/lvchange.c
@@ -479,17 +479,8 @@ static int lvchange_resync(struct cmd_context *cmd, struct logical_volume *lv)
(seg_is_raid(seg)) ? "metadata" : "log",
lvl->lv->name);
- struct wipe_lv_params wp = {
- .lv = lvl->lv,
- .do_zero = 1,
- .zero_sectors = lvl->lv->size,
- .zero_value = 0,
- .do_wipe_signatures = 0,
- .yes = 0,
- .force = PROMPT
- };
-
- if (!wipe_lv(cmd, &wp)) {
+ if (!wipe_lv(lvl->lv, (struct wipe_params)
+ { .do_zero = 1, .zero_sectors = lvl->lv->size })) {
log_error("Unable to reset sync status for %s",
lv->name);
if (!deactivate_lv(cmd, lvl->lv))
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 34c8de2..9a542a6 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -1847,22 +1847,10 @@ static int lvconvert_snapshot(struct cmd_context *cmd,
if (!lp->zero || !(lv->status & LVM_WRITE))
log_warn("WARNING: \"%s\" not zeroed", lv->name);
- else {
- struct wipe_lv_params wp = {
- .lv = lv,
- .do_zero = 1,
- .zero_sectors = 0,
- .zero_value = 0,
- .do_wipe_signatures = 0,
- .yes = 0,
- .force = PROMPT
- };
-
- if (!wipe_lv(cmd, &wp)) {
+ else if (!wipe_lv(lv, (struct wipe_params) { .do_zero = 1 })) {
log_error("Aborting. Failed to wipe snapshot "
"exception store.");
return 0;
- }
}
if (!deactivate_lv(cmd, lv)) {
@@ -2506,17 +2494,8 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
return 0;
}
- struct wipe_lv_params wp = {
- .lv = metadata_lv,
- .do_zero = 1,
- .zero_sectors = 0,
- .zero_value = 0,
- .do_wipe_signatures = 0,
- .yes = 0,
- .force = PROMPT
- };
- if (!wipe_lv(cmd, &wp)) {
+ if (!wipe_lv(metadata_lv, (struct wipe_params) { .do_zero = 1 })) {
log_error("Aborting. Failed to wipe thin metadata lv.");
return 0;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a1eda8ea245ec7af…
Commit: a1eda8ea245ec7af684fb50e7f0abf5229d9bcfb
Parent: 8724c0fcebcc35df980e6819e5c531f213fe2767
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 22:27:32 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:45:52 2013 +0100
toollib: drop init of ret
Keep the ret uninitialized, so we get compiler warning, when tried
to use this value instead of ret_max as function return value.
---
tools/toollib.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index 90a7cb8..654384d 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -190,7 +190,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd,
process_single_lv_fn_t process_single_lv)
{
int ret_max = ECMD_PROCESSED;
- int ret = 0;
+ int ret;
unsigned process_all = 0;
unsigned process_lv = 0;
unsigned tags_supplied = 0;
@@ -302,7 +302,7 @@ int process_each_lv(struct cmd_context *cmd, int argc, char **argv,
{
int opt = 0;
int ret_max = ECMD_PROCESSED;
- int ret = 0;
+ int ret;
struct dm_list *tags_arg;
struct dm_list *vgnames; /* VGs to process */
@@ -724,7 +724,7 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
process_single_pv_fn_t process_single_pv)
{
int ret_max = ECMD_PROCESSED;
- int ret = 0;
+ int ret;
struct pv_list *pvl;
dm_list_iterate_items(pvl, &vg->pvs) {
@@ -810,7 +810,7 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
{
int opt = 0;
int ret_max = ECMD_PROCESSED;
- int ret = 0;
+ int ret;
int lock_global = !(flags & READ_WITHOUT_LOCK) && !(flags & READ_FOR_UPDATE) && !lvmetad_active();
struct pv_list *pvl;
@@ -1803,7 +1803,7 @@ int process_each_label(struct cmd_context *cmd, int argc, char **argv, void *han
struct device *dev;
int ret_max = ECMD_PROCESSED;
- int ret = 0;
+ int ret;
int opt = 0;
if (argc) {
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=8724c0fcebcc35df…
Commit: 8724c0fcebcc35df980e6819e5c531f213fe2767
Parent: b3679590dfb9839196c36ac74b86377ae2a10f8e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Nov 26 12:09:41 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:45:28 2013 +0100
snapshot: move code of old snapshot merge
Move code for merging old snapshot into its own function.
---
tools/lvconvert.c | 68 ++++++++++++++++++++++++++++------------------------
1 files changed, 37 insertions(+), 31 deletions(-)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 051463b..34c8de2 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -1884,31 +1884,59 @@ static int lvconvert_snapshot(struct cmd_context *cmd,
return 1;
}
-static int lvconvert_merge(struct cmd_context *cmd,
- struct logical_volume *lv,
- struct lvconvert_params *lp)
+static int _lvconvert_merge_old_snapshot(struct cmd_context *cmd,
+ struct logical_volume *lv,
+ struct lvconvert_params *lp)
{
int r = 0;
int merge_on_activate = 0;
struct logical_volume *origin = origin_from_cow(lv);
struct lv_segment *snap_seg = find_snapshot(lv);
struct lvinfo info;
+ percent_t snap_percent;
/* Check if merge is possible */
+ if (!lv_is_cow(lv)) {
+ log_error("\"%s\" is not a mergeable logical volume.",
+ lv->name);
+ return 0;
+ }
+
if (lv_is_merging_cow(lv)) {
- log_error("Snapshot %s is already merging", lv->name);
+ log_error("Snapshot %s is already merging.", lv->name);
return 0;
}
+
if (lv_is_merging_origin(origin)) {
log_error("Snapshot %s is already merging into the origin.",
find_snapshot(origin)->cow->name);
return 0;
}
+
if (lv_is_virtual_origin(origin)) {
log_error("Snapshot %s has virtual origin.", lv->name);
return 0;
}
+ if (lv_is_external_origin(origin_from_cow(lv))) {
+ log_error("Cannot merge snapshot \"%s\" into "
+ "the read-only external origin \"%s\".",
+ lv->name, origin_from_cow(lv)->name);
+ return 0;
+ }
+
+ if (lv_info(lv->vg->cmd, lv, 0, &info, 1, 0)
+ && info.exists && info.live_table &&
+ (!lv_snapshot_percent(lv, &snap_percent) ||
+ snap_percent == PERCENT_INVALID)) {
+ log_error("Unable to merge invalidated snapshot LV \"%s\".",
+ lv->name);
+ return 0;
+ }
+
+ if (!archive(lv->vg))
+ return_0;
+
/*
* Prevent merge with open device(s) as it would likely lead
* to application/filesystem failure. Merge on origin's next
@@ -1955,7 +1983,7 @@ static int lvconvert_merge(struct cmd_context *cmd,
/* Perform merge */
if (!suspend_lv(cmd, origin)) {
- log_error("Failed to suspend origin %s", origin->name);
+ log_error("Failed to suspend origin %s.", origin->name);
vg_revert(lv->vg);
goto out;
}
@@ -1967,7 +1995,7 @@ static int lvconvert_merge(struct cmd_context *cmd,
}
if (!resume_lv(cmd, origin)) {
- log_error("Failed to reactivate origin %s", origin->name);
+ log_error("Failed to reactivate origin %s.", origin->name);
goto out;
}
@@ -1978,6 +2006,7 @@ static int lvconvert_merge(struct cmd_context *cmd,
log_print_unless_silent("Merging of volume %s started.", lv->name);
out:
backup(lv->vg);
+
return r;
}
@@ -2588,8 +2617,6 @@ static int _lvconvert_single(struct cmd_context *cmd, struct logical_volume *lv,
{
struct lvconvert_params *lp = handle;
struct dm_list *failed_pvs;
- struct lvinfo info;
- percent_t snap_percent;
if (lv->status & LOCKED) {
log_error("Cannot convert locked LV %s", lv->name);
@@ -2634,29 +2661,8 @@ static int _lvconvert_single(struct cmd_context *cmd, struct logical_volume *lv,
}
}
if (lp->merge) {
- if (!lv_is_cow(lv)) {
- log_error("\"%s\" is not a mergeable logical volume",
- lv->name);
- return ECMD_FAILED;
- }
- if (lv_is_external_origin(origin_from_cow(lv))) {
- log_error("Cannot merge snapshot \"%s\" into "
- "the read-only external origin \"%s\".",
- lv->name, origin_from_cow(lv)->name);
- return ECMD_FAILED;
- }
- if (lv_info(lv->vg->cmd, lv, 0, &info, 1, 0)
- && info.exists && info.live_table &&
- (!lv_snapshot_percent(lv, &snap_percent) ||
- snap_percent == PERCENT_INVALID)) {
- log_error("Unable to merge invalidated snapshot LV \"%s\"", lv->name);
- return ECMD_FAILED;
- }
- if (!archive(lv->vg))
- return_ECMD_FAILED;
-
- if (!lvconvert_merge(cmd, lv, lp)) {
- log_error("Unable to merge LV \"%s\" into its origin.", lv->name);
+ if (!_lvconvert_merge_old_snapshot(cmd, lv, lp)) {
+ log_print_unless_silent("Unable to merge LV \"%s\" into its origin.", lv->name);
return ECMD_FAILED;
}
} else if (lp->snapshot) {
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b3679590dfb98391…
Commit: b3679590dfb9839196c36ac74b86377ae2a10f8e
Parent: 6dae2373034ce3fc11f226c963d81a670043191a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 25 14:24:25 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:45:02 2013 +0100
dmeventd: simplify error path
Use common 'bad:' label for exit error path where
fifo is closed before exit().
---
WHATS_NEW_DM | 1 +
daemons/dmeventd/dmeventd.c | 21 ++++++++++++---------
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 564419f..1f1cde1 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.84 -
====================================
+ Close fifos before exiting in dmeventd restart() error path.
Move printf format string directly into dm_asprintf args list.
Catch invalid use of string sort values when reporting numerical fields.
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 301c5f5..f2d6671 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -1848,20 +1848,18 @@ static void restart(void)
if (!dm_event_get_version(&fifos, &version)) {
fprintf(stderr, "WARNING: Could not communicate with existing dmeventd.\n");
- fini_fifos(&fifos);
- exit(EXIT_FAILURE);
+ goto bad;
}
if (version < 1) {
fprintf(stderr, "WARNING: The running dmeventd instance is too old.\n"
"Protocol version %d (required: 1). Action cancelled.\n",
version);
- exit(EXIT_FAILURE);
+ goto bad;
}
- if (daemon_talk(&fifos, &msg, DM_EVENT_CMD_GET_STATUS, "-", "-", 0, 0)) {
- exit(EXIT_FAILURE);
- }
+ if (daemon_talk(&fifos, &msg, DM_EVENT_CMD_GET_STATUS, "-", "-", 0, 0))
+ goto bad;
message = msg.data;
message = strchr(message, ' ');
@@ -1876,13 +1874,13 @@ static void restart(void)
if (!(_initial_registrations = dm_malloc(sizeof(char*) * (count + 1)))) {
fprintf(stderr, "Memory allocation registration failed.\n");
- exit(EXIT_FAILURE);
+ goto bad;
}
for (i = 0; i < count; ++i) {
if (!(_initial_registrations[i] = dm_strdup(message))) {
fprintf(stderr, "Memory allocation for message failed.\n");
- exit(EXIT_FAILURE);
+ goto bad;
}
message += strlen(message) + 1;
}
@@ -1890,7 +1888,7 @@ static void restart(void)
if (daemon_talk(&fifos, &msg, DM_EVENT_CMD_DIE, "-", "-", 0, 0)) {
fprintf(stderr, "Old dmeventd refused to die.\n");
- exit(EXIT_FAILURE);
+ goto bad;
}
/*
@@ -1904,6 +1902,11 @@ static void restart(void)
}
fini_fifos(&fifos);
+
+ return;
+bad:
+ fini_fifos(&fifos);
+ exit(EXIT_FAILURE);
}
static void usage(char *prog, FILE *file)
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6dae2373034ce3fc…
Commit: 6dae2373034ce3fc11f226c963d81a670043191a
Parent: fc9d4dd11f2331e056f0b56274877c8a4b4b1570
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Nov 28 12:21:06 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:43:14 2013 +0100
dmeventd: fifo init and close cleanup
Use structure initialization for easier to read code.
Close only descriptors >= 0.
---
daemons/dmeventd/dmeventd.c | 8 +++++-
daemons/dmeventd/libdevmapper-event.c | 48 ++++++++++++++++----------------
2 files changed, 31 insertions(+), 25 deletions(-)
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 189d1b6..301c5f5 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -1826,7 +1826,13 @@ static void _daemonize(void)
static void restart(void)
{
- struct dm_event_fifos fifos = { 0 };
+ struct dm_event_fifos fifos = {
+ .server = -1,
+ .client = -1,
+ /* FIXME Make these either configurable or depend directly on dmeventd_path */
+ .client_path = DM_EVENT_FIFO_CLIENT,
+ .server_path = DM_EVENT_FIFO_SERVER
+ };
struct dm_event_daemon_message msg = { 0 };
int i, count = 0;
char *message;
diff --git a/daemons/dmeventd/libdevmapper-event.c b/daemons/dmeventd/libdevmapper-event.c
index 92e9c1d..9e8911e 100644
--- a/daemons/dmeventd/libdevmapper-event.c
+++ b/daemons/dmeventd/libdevmapper-event.c
@@ -468,10 +468,6 @@ int init_fifos(struct dm_event_fifos *fifos)
/* FIXME? Is fifo the most suitable method? Why not share
comms/daemon code with something else e.g. multipath? */
- /* FIXME Make these either configurable or depend directly on dmeventd_path */
- fifos->client_path = DM_EVENT_FIFO_CLIENT;
- fifos->server_path = DM_EVENT_FIFO_SERVER;
-
/* Open the fifo used to read from the daemon. */
if ((fifos->server = open(fifos->server_path, O_RDWR)) < 0) {
log_sys_error("open", fifos->server_path);
@@ -481,32 +477,27 @@ int init_fifos(struct dm_event_fifos *fifos)
/* Lock out anyone else trying to do communication with the daemon. */
if (flock(fifos->server, LOCK_EX) < 0) {
log_sys_error("flock", fifos->server_path);
- if (close(fifos->server))
- log_sys_error("close", fifos->server_path);
- return 0;
+ goto bad;
}
/* if ((fifos->client = open(fifos->client_path, O_WRONLY | O_NONBLOCK)) < 0) {*/
if ((fifos->client = open(fifos->client_path, O_RDWR | O_NONBLOCK)) < 0) {
log_sys_error("open", fifos->client_path);
- if (close(fifos->server))
- log_sys_error("close", fifos->server_path);
- return 0;
+ goto bad;
}
return 1;
+bad:
+ if (close(fifos->server))
+ log_sys_debug("close", fifos->server_path);
+ fifos->server = -1;
+
+ return 0;
}
/* Initialize client. */
static int _init_client(char *dmeventd_path, struct dm_event_fifos *fifos)
{
- /* init fifos */
- memset(fifos, 0, sizeof(*fifos));
-
- /* FIXME Make these either configurable or depend directly on dmeventd_path */
- fifos->client_path = DM_EVENT_FIFO_CLIENT;
- fifos->server_path = DM_EVENT_FIFO_SERVER;
-
if (!_start_daemon(dmeventd_path, fifos))
return_0;
@@ -515,13 +506,16 @@ static int _init_client(char *dmeventd_path, struct dm_event_fifos *fifos)
void fini_fifos(struct dm_event_fifos *fifos)
{
- if (flock(fifos->server, LOCK_UN))
- log_error("flock unlock %s", fifos->server_path);
-
- if (close(fifos->client))
+ if (fifos->client >= 0 && close(fifos->client))
log_sys_error("close", fifos->client_path);
- if (close(fifos->server))
- log_sys_error("close", fifos->server_path);
+
+ if (fifos->server >= 0) {
+ if (flock(fifos->server, LOCK_UN))
+ log_sys_error("flock unlock", fifos->server_path);
+
+ if (close(fifos->server))
+ log_sys_error("close", fifos->server_path);
+ }
}
/* Get uuid of a device */
@@ -585,7 +579,13 @@ static int _do_event(int cmd, char *dmeventd_path, struct dm_event_daemon_messag
enum dm_event_mask evmask, uint32_t timeout)
{
int ret;
- struct dm_event_fifos fifos;
+ struct dm_event_fifos fifos = {
+ .server = -1,
+ .client = -1,
+ /* FIXME Make these either configurable or depend directly on dmeventd_path */
+ .client_path = DM_EVENT_FIFO_CLIENT,
+ .server_path = DM_EVENT_FIFO_SERVER
+ };
if (!_init_client(dmeventd_path, &fifos)) {
stack;
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fc9d4dd11f2331e0…
Commit: fc9d4dd11f2331e056f0b56274877c8a4b4b1570
Parent: 79991aa7699587b40946d029787b38ae67405336
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 25 13:44:46 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:42:44 2013 +0100
config: use int for type
Since the type is used for 'or' operation of enumerated bit fields,
it doesn't not have type cfg_def_type_t - use proper int type for
bitmask.
---
lib/config/config.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/config/config.h b/lib/config/config.h
index f57757b..0769c40 100644
--- a/lib/config/config.h
+++ b/lib/config/config.h
@@ -88,7 +88,7 @@ typedef struct cfg_def_item {
int id; /* ID of this item */
int parent; /* ID of parent item */
const char *name; /* name of the item in configuration tree */
- cfg_def_type_t type; /* configuration item type */
+ int type; /* configuration item type (bits of cfg_def_type_t) */
cfg_def_value_t default_value; /* default value (only for settings) */
uint16_t flags; /* configuration item definition flags */
uint16_t since_version; /* version this item appeared in */
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=79991aa7699587b4…
Commit: 79991aa7699587b40946d029787b38ae67405336
Parent: 01c438a96c82bf31ccda0721707fc90afa01a07e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Nov 28 11:39:38 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:42:43 2013 +0100
snapshot: drop find_merging_snapshot
Drop find_merging_snapshot() function. Use find_snapshot()
called after check for lv_is_merging_origin() which
is the commonly used code path - so we avoid duplicated
tests and potential risk of derefering NULL point
in unhandled error path.
---
lib/activate/dev_manager.c | 12 ++++++------
lib/metadata/metadata-exported.h | 2 --
lib/metadata/snapshot_manip.c | 11 ++---------
tools/lvconvert.c | 9 +++++----
4 files changed, 13 insertions(+), 21 deletions(-)
diff --git a/lib/activate/dev_manager.c b/lib/activate/dev_manager.c
index f8027d4..e53273d 100644
--- a/lib/activate/dev_manager.c
+++ b/lib/activate/dev_manager.c
@@ -2047,9 +2047,9 @@ static int _add_snapshot_merge_target_to_dtree(struct dev_manager *dm,
struct logical_volume *lv)
{
const char *origin_dlid, *cow_dlid, *merge_dlid;
- struct lv_segment *merging_snap_seg;
+ struct lv_segment *merging_snap_seg = find_snapshot(lv);
- if (!(merging_snap_seg = find_merging_snapshot(lv))) {
+ if (!lv_is_merging_origin(lv)) {
log_error(INTERNAL_ERROR "LV %s is not merging snapshot.", lv->name);
return 0;
}
@@ -2374,7 +2374,8 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
/* FIXME Seek a simpler way to lay out the snapshot-merge tree. */
- if (lv_is_origin(lv) && lv_is_merging_origin(lv) && !layer) {
+ if (!layer && lv_is_merging_origin(lv)) {
+ seg = find_snapshot(lv);
/*
* Clear merge attributes if merge isn't currently possible:
* either origin or merging snapshot are open
@@ -2385,8 +2386,7 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
/* An activating merging origin won't have a node in the tree yet */
if (((dinfo = _cached_info(dm->mem, dtree, lv, NULL)) &&
dinfo->open_count) ||
- ((dinfo = _cached_info(dm->mem, dtree,
- find_merging_snapshot(lv)->cow, NULL)) &&
+ ((dinfo = _cached_info(dm->mem, dtree, seg->cow, NULL)) &&
dinfo->open_count)) {
/* FIXME Is there anything simpler to check for instead? */
if (!lv_has_target_type(dm->mem, lv, NULL, "snapshot-merge"))
@@ -2445,7 +2445,7 @@ static int _add_new_lv_to_dtree(struct dev_manager *dm, struct dm_tree *dtree,
return_0;
if (!laopts->no_merging && lv_is_merging_origin(lv)) {
if (!_add_new_lv_to_dtree(dm, dtree,
- find_merging_snapshot(lv)->cow, laopts, "cow"))
+ find_snapshot(lv)->cow, laopts, "cow"))
return_0;
/*
* Must also add "real" LV for use when
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 41bd1a7..c274649 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -882,8 +882,6 @@ int lv_is_visible(const struct logical_volume *lv);
int pv_is_in_vg(struct volume_group *vg, struct physical_volume *pv);
-struct lv_segment *find_merging_snapshot(const struct logical_volume *origin);
-
/* Given a cow LV, return return the snapshot lv_segment that uses it */
struct lv_segment *find_snapshot(const struct logical_volume *lv);
diff --git a/lib/metadata/snapshot_manip.c b/lib/metadata/snapshot_manip.c
index 3e90f3e..e9a6d87 100644
--- a/lib/metadata/snapshot_manip.c
+++ b/lib/metadata/snapshot_manip.c
@@ -100,14 +100,6 @@ int lv_is_merging_origin(const struct logical_volume *origin)
return (origin->status & MERGING) ? 1 : 0;
}
-struct lv_segment *find_merging_snapshot(const struct logical_volume *origin)
-{
- if (!lv_is_merging_origin(origin))
- return NULL;
-
- return find_snapshot(origin);
-}
-
int lv_is_merging_cow(const struct logical_volume *snapshot)
{
/* checks lv_segment's status to see if cow is merging */
@@ -233,7 +225,8 @@ int vg_remove_snapshot(struct logical_volume *cow)
dm_list_del(&cow->snapshot->origin_list);
origin->origin_count--;
- if (find_merging_snapshot(origin) == find_snapshot(cow)) {
+ if (lv_is_merging_origin(origin) &&
+ (find_snapshot(origin) == find_snapshot(cow))) {
clear_snapshot_merge(origin);
/*
* preload origin IFF "snapshot-merge" target is active
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 31eb232..051463b 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -650,8 +650,9 @@ static int _finish_lvconvert_merge(struct cmd_context *cmd,
struct logical_volume *lv,
struct dm_list *lvs_changed __attribute__((unused)))
{
- struct lv_segment *snap_seg = find_merging_snapshot(lv);
- if (!snap_seg) {
+ struct lv_segment *snap_seg = find_snapshot(lv);
+
+ if (!lv_is_merging_origin(lv)) {
log_error("Logical volume %s has no merging snapshot.", lv->name);
return 0;
}
@@ -1899,8 +1900,8 @@ static int lvconvert_merge(struct cmd_context *cmd,
return 0;
}
if (lv_is_merging_origin(origin)) {
- log_error("Snapshot %s is already merging into the origin",
- find_merging_snapshot(origin)->cow->name);
+ log_error("Snapshot %s is already merging into the origin.",
+ find_snapshot(origin)->cow->name);
return 0;
}
if (lv_is_virtual_origin(origin)) {
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=01c438a96c82bf31…
Commit: 01c438a96c82bf31ccda0721707fc90afa01a07e
Parent: 5a4137c804b0ba579c5f368fe91942c465815f66
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Nov 24 19:00:53 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Thu Nov 28 12:42:39 2013 +0100
format-text: ensure aligment is not 0
Make sure this path of code is not used for alignment == 0,
to prevent division by 0.
---
WHATS_NEW | 1 +
lib/format_text/format-text.c | 2 +-
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 55b17c0..cd63144 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Check for non-zero aligment in _text_pv_add_metadata_area() to not div by 0.
Add allocation/use_blkid_wiping to lvm.conf to enable blkid wiping.
Add configure --enable-blkid_wiping to use libblkid to detect signatures.
Add -W/--wipesignatures lvcreate option to support wiping on new LVs.
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index 275d16f..eb5c9e9 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -2083,7 +2083,7 @@ static int _text_pv_add_metadata_area(const struct format_type *fmt,
* alignment since it would be useless.
* Check first whether we can apply that!
*/
- if (!pe_start_locked &&
+ if (!pe_start_locked && alignment &&
((limit - mda_start) > alignment * 2)) {
mda_size = limit - mda_start - alignment * 2;
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5a4137c804b0ba57…
Commit: 5a4137c804b0ba579c5f368fe91942c465815f66
Parent: 5968f07fd5ccb2b7d4e407cd8fec86b0b1f80f3a
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Nov 27 16:49:12 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 16:49:12 2013 +0100
profile: wipe_signatures_on_new_logical_volumes_when_zeroing not yet profilable
But it might be - needs more testing...
---
conf/default.profile.in | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/conf/default.profile.in b/conf/default.profile.in
index 5a481de..29049ef 100644
--- a/conf/default.profile.in
+++ b/conf/default.profile.in
@@ -9,7 +9,6 @@
# Refer to 'man lvm.conf' for further information about profiles and file layout.
allocation {
- wipe_signatures_on_new_logical_volumes_when_zeroing = 1
thin_pool_chunk_size_policy = "generic"
thin_pool_chunk_size = 64
thin_pool_discards = "passdown"
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5968f07fd5ccb2b7…
Commit: 5968f07fd5ccb2b7d4e407cd8fec86b0b1f80f3a
Parent: eaa23d32732c9bc3dd4f948781b5764cf21d84ba
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Nov 27 15:20:12 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 15:49:15 2013 +0100
man: lvcreate -W/--wipesignatures
---
man/lvcreate.8.in | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/man/lvcreate.8.in b/man/lvcreate.8.in
index 4a29720..a34c4ae 100644
--- a/man/lvcreate.8.in
+++ b/man/lvcreate.8.in
@@ -75,6 +75,7 @@ lvcreate \- create a logical volume in an existing volume group
.RB [ \-\-type
.IR SegmentType ]
.RB [ \-v | \-\-verbose ]
+.RB [ \-W | \-\-wipesignatures ]
.RB [ \-Z | \-\-zero
.RI { y | n }]
.IR VolumeGroup { Name | Path }[/ ThinPoolLogicalVolumeName ]
@@ -135,8 +136,9 @@ If autoactivation option is used (\fB\-a\fIay\fR), the logical volume is
activated only if it matches an item in the
.B activation/auto_activation_volume_list
set in \fBlvm.conf\fP(5).
-For autoactivated logical volumes, \fB\-\-zero\fP \fIn\fP is always assumed
-and it can't be overridden. If the clustered locking is enabled,
+For autoactivated logical volumes, \fB\-\-zero\fP \fIn\fP and
+\fB\-\-wipesignatures\fP \fIn\fP is always assumed and it can't
+be overridden. If the clustered locking is enabled,
\fB\-a\fIey\fR will activate exclusively on one node and
.IR \fB\-a { a | l } y
will activate only on the local node.
@@ -399,6 +401,21 @@ requested size using the zero target. A suffix of _vorigin is used for
this device. Note: using sparse snapshots is not efficient for larger
device sizes (GiB), thin provisioning should be used for this case.
.TP
+.BR \-W ", " \-\-wipesignatures " {" \fIy | \fIn }
+Controls wiping of detected signatures on newly created Logical Volume.
+If this option is not specified, then by default signature wiping is done
+each time the zeroing (\fB\-Z\fP/\fB\-\-zero\fP) is done. This default behaviour
+can be controlled by \fBallocation/wipe_signatures_on_new_logical_volumes_when_zeroing\fP
+setting found in \fBlvm.conf\fP(5).
+.br
+If blkid wiping is used (\fBallocation/use_blkid_wiping setting\fP in \fBlvm.conf\fP(5))
+and LVM2 is compiled with blkid wiping support, then \fBblkid\fP(8) library is used
+to detect the signatures (use \fBblkid -k\fP command to list the signatures that are recognized).
+Otherwise, native LVM2 code is used to detect signatures (MD RAID, swap and LUKS
+signatures are detected only in this case).
+.br
+Logical Volume is not wiped if the read only flag is set.
+.TP
.BR \-Z ", " \-\-zero " {" \fIy | \fIn }
Controls zeroing of the first KiB of data in the new logical volume.
.br
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=eaa23d32732c9bc3…
Commit: eaa23d32732c9bc3dd4f948781b5764cf21d84ba
Parent: ab2f858af7a72448b6c015a5984c73f5cdaf3664
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Fri Nov 15 14:50:02 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 15:49:15 2013 +0100
wiping: add support for blkid wiping
This is actually the wipefs functionailty as a matter of fact
(wipefs uses the same libblkid calls).
libblkid is more rich when it comes to detecting various
signatures, including filesystems and users can better
decide what to erase and what should be kept.
The code is shared for both pvcreate (where wiping is necessary
to complete the pvcreate operation) and lvcreate where it's up
to the user to decide.
The verbose output contains a bit more information about the
signature like LABEL and UUID.
For example:
raw/~ # lvcreate -L16m vg
WARNING: linux_raid_member signature detected on /dev/vg/lvol0 at offset 4096. Wipe it? [y/n]
or more verbose one:
raw/~ # lvcreate -L16m vg -v
...
Found existing signature on /dev/vg/lvol0 at offset 4096: LABEL="raw.virt:0" UUID="da6af139-8403-5d06-b8c4-13f6f24b73b1" TYPE="linux_raid_member" USAGE="raid"
WARNING: linux_raid_member signature detected on /dev/vg/lvol0 at offset 4096. Wipe it? [y/n]
The verbose output is the same output as found in blkid.
---
lib/device/dev-type.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++-
lib/device/dev-type.h | 2 +-
lib/metadata/lv_manip.c | 2 +-
lib/metadata/metadata.c | 2 +-
4 files changed, 115 insertions(+), 4 deletions(-)
diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c
index e42349d..04b555b 100644
--- a/lib/device/dev-type.c
+++ b/lib/device/dev-type.c
@@ -21,6 +21,10 @@
#include <libgen.h>
#include <ctype.h>
+#ifdef BLKID_WIPING_SUPPORT
+#include <blkid/blkid.h>
+#endif
+
#include "device-types.h"
struct dev_types *create_dev_types(const char *proc_dir,
@@ -443,6 +447,102 @@ out:
return ret;
}
+#ifdef BLKID_WIPING_SUPPORT
+
+static int _blkid_wipe(blkid_probe probe, struct device *dev,
+ const char *name, int yes, force_t force)
+{
+ const char *offset = NULL, *type = NULL, *magic = NULL,
+ *usage = NULL, *label = NULL, *uuid = NULL;
+ loff_t offset_value;
+ size_t len;
+
+ if (!blkid_probe_lookup_value(probe, "TYPE", &type, NULL)) {
+ if (!blkid_probe_lookup_value(probe, "SBMAGIC_OFFSET", &offset, NULL) &&
+ blkid_probe_lookup_value(probe, "SBMAGIC", &magic, &len))
+ return_0;
+ } else if (!blkid_probe_lookup_value(probe, "PTTYPE", &type, NULL)) {
+ if (!blkid_probe_lookup_value(probe, "PTMAGIC_OFFSET", &offset, NULL) &&
+ blkid_probe_lookup_value(probe, "PTMAGIC", &magic, &len))
+ return_0;
+ usage = "partition table";
+ } else
+ return_0;
+
+ offset_value = strtoll(offset, NULL, 10);
+
+ if (!usage)
+ blkid_probe_lookup_value(probe, "USAGE", &usage, NULL);
+ blkid_probe_lookup_value(probe, "LABEL", &label, NULL);
+ blkid_probe_lookup_value(probe, "UUID", &uuid, NULL);
+
+ log_verbose("Found existing signature on %s at offset %s: LABEL=\"%s\" "
+ "UUID=\"%s\" TYPE=\"%s\" USAGE=\"%s\"",
+ name, offset, label, uuid, type, usage);
+
+ if (!yes && (force == PROMPT) &&
+ yes_no_prompt("WARNING: %s signature detected on %s at offset %s. "
+ "Wipe it? [y/n] ", type, name, offset) != 'y')
+ return_0;
+
+ log_print_unless_silent("Wiping %s signature on %s.", type, name);
+ if (!dev_set(dev, offset_value, len, 0)) {
+ log_error("Failed to wipe %s signature on %s.", type, name);
+ return 0;
+ }
+
+ return 1;
+}
+
+static int _wipe_known_signatures_with_blkid(struct device *dev, const char *name,
+ int yes, force_t force)
+{
+ blkid_probe probe = NULL;
+ int found = 0, wiped = 0, left = 0;
+ int r = 0;
+
+ /* TODO: Should we check for valid dev - _dev_is_valid(dev)? */
+
+ if (!(probe = blkid_new_probe_from_filename(dev_name(dev)))) {
+ log_error("Failed to create a new blkid probe for device %s.", dev_name(dev));
+ goto out;
+ }
+
+ blkid_probe_enable_partitions(probe, 1);
+ blkid_probe_set_partitions_flags(probe, BLKID_PARTS_MAGIC);
+
+ blkid_probe_enable_superblocks(probe, 1);
+ blkid_probe_set_superblocks_flags(probe, BLKID_SUBLKS_LABEL |
+ BLKID_SUBLKS_UUID |
+ BLKID_SUBLKS_TYPE |
+ BLKID_SUBLKS_USAGE |
+ BLKID_SUBLKS_VERSION |
+ BLKID_SUBLKS_MAGIC |
+ BLKID_SUBLKS_BADCSUM);
+
+ while (!blkid_do_probe(probe)) {
+ found++;
+ if (_blkid_wipe(probe, dev, name, yes, force))
+ wiped++;
+ }
+
+ if (!found)
+ r = 1;
+
+ left = found - wiped;
+ if (!left)
+ r = 1;
+ else
+ log_warn("%d existing signature%s left on the device.",
+ left, left > 1 ? "s" : "");
+out:
+ if (probe)
+ blkid_free_probe(probe);
+ return r;
+}
+
+#endif /* BLKID_WIPING_SUPPORT */
+
static int _wipe_signature(struct device *dev, const char *type, const char *name,
int wipe_len, int yes, force_t force,
int (*signature_detection_fn)(struct device *dev, uint64_t *offset_found))
@@ -475,7 +575,8 @@ static int _wipe_signature(struct device *dev, const char *type, const char *nam
return 1;
}
-int wipe_known_signatures(struct device *dev, const char *name, int yes, force_t force)
+static int _wipe_known_signatures_with_lvm(struct device *dev, const char *name,
+ int yes, force_t force)
{
if (!_wipe_signature(dev, "software RAID md superblock", name, 4, yes, force, dev_is_md) ||
!_wipe_signature(dev, "swap signature", name, 10, yes, force, dev_is_swap) ||
@@ -485,6 +586,16 @@ int wipe_known_signatures(struct device *dev, const char *name, int yes, force_t
return 1;
}
+int wipe_known_signatures(struct cmd_context *cmd, struct device *dev,
+ const char *name, int yes, force_t force)
+{
+#ifdef BLKID_WIPING_SUPPORT
+ if (find_config_tree_bool(cmd, allocation_use_blkid_wiping_CFG, NULL))
+ return _wipe_known_signatures_with_blkid(dev, name, yes, force);
+#endif
+ return _wipe_known_signatures_with_lvm(dev, name, yes, force);
+}
+
#ifdef __linux__
static int _snprintf_attr(char *buf, size_t buf_size, const char *sysfs_dir,
diff --git a/lib/device/dev-type.h b/lib/device/dev-type.h
index 895a172..39d947b 100644
--- a/lib/device/dev-type.h
+++ b/lib/device/dev-type.h
@@ -60,7 +60,7 @@ int dev_is_swap(struct device *dev, uint64_t *signature);
int dev_is_luks(struct device *dev, uint64_t *signature);
/* Signature wiping. */
-int wipe_known_signatures(struct device *dev, const char *name, int yes, force_t force);
+int wipe_known_signatures(struct cmd_context *cmd, struct device *dev, const char *name, int yes, force_t force);
/* Type-specific device properties */
unsigned long dev_md_stripe_width(struct dev_types *dt, struct device *dev);
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 521d058..2480942 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -5429,7 +5429,7 @@ int wipe_lv(struct cmd_context *cmd, struct wipe_lv_params *wp)
if (wp->do_wipe_signatures) {
log_verbose("Wiping known signatures on logical volume \"%s/%s\"",
wp->lv->vg->name, wp->lv->name);
- if (!wipe_known_sbs(dev, name, wp->yes, wp->force))
+ if (!wipe_known_signatures(cmd, dev, name, wp->yes, wp->force))
stack;
}
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index f0230f1..5c87ab6 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -1330,7 +1330,7 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,
goto bad;
}
- if (!wipe_known_signatures(dev, name, pp->yes, pp->force)) {
+ if (!wipe_known_signatures(cmd, dev, name, pp->yes, pp->force)) {
log_error("Aborting pvcreate on %s.", name);
goto bad;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ab2f858af7a72448…
Commit: ab2f858af7a72448b6c015a5984c73f5cdaf3664
Parent: 9bfc0be493192958f5dbffea4eb7dda968062261
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Nov 27 13:52:15 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 15:49:14 2013 +0100
conf: add allocation/use_blkid_wiping
Add allocation/use_blkid_wiping setting to lvm.conf to select between
LVM2 native code to detect signatures to wipe or blkid library code.
---
WHATS_NEW | 1 +
conf/example.conf.in | 15 +++++++++++++++
lib/config/config_settings.h | 1 +
3 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 9823cd1..55b17c0 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Add allocation/use_blkid_wiping to lvm.conf to enable blkid wiping.
Add configure --enable-blkid_wiping to use libblkid to detect signatures.
Add -W/--wipesignatures lvcreate option to support wiping on new LVs.
Add allocation/wipe_signatures_on_new_logical_volumes_when_zeroing to lvm.conf.
diff --git a/conf/example.conf.in b/conf/example.conf.in
index 0ac53ef..b7ad3d1 100644
--- a/conf/example.conf.in
+++ b/conf/example.conf.in
@@ -272,6 +272,21 @@ allocation {
# algorithm.
maximise_cling = 1
+ # Whether to use blkid library instead of native LVM2 code to detect
+ # any existing signatures while creating new Physical Volumes and
+ # Logical Volumes. LVM2 needs to be compiled with blkid wiping support
+ # for this setting to take effect.
+ #
+ # LVM2 native detection code is currently able to recognize these signatures:
+ # - MD device signature
+ # - swap signature
+ # - LUKS signature
+ # To see the list of signatures recognized by blkid, check the output
+ # of 'blkid -k' command. The blkid can recognize more signatures than
+ # LVM2 native detection code, but due to this higher number of signatures
+ # to be recognized, it can take more time to complete the signature scan.
+ use_blkid_wiping = 1
+
# Whether do wipe any signatures found on newly created Logical Volumes
# automatically in addition to zeroing of the first KB on the LV
# (-Z/--zero y option) when running the LVM command without specifying
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
index 7a7e8e5..929e907 100644
--- a/lib/config/config_settings.h
+++ b/lib/config/config_settings.h
@@ -104,6 +104,7 @@ cfg(devices_issue_discards_CFG, "issue_discards", devices_CFG_SECTION, 0, CFG_TY
cfg_array(allocation_cling_tag_list_CFG, "cling_tag_list", allocation_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(2, 2, 77), NULL)
cfg(allocation_maximise_cling_CFG, "maximise_cling", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MAXIMISE_CLING, vsn(2, 2, 85), NULL)
+cfg(allocation_use_blkid_wiping_CFG, "use_blkid_wiping", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, 1, vsn(2, 2, 105), NULL)
cfg(allocation_wipe_signatures_on_new_logical_volumes_when_zeroing_CFG, "wipe_signatures_on_new_logical_volumes_when_zeroing", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, 1, vsn(2, 2, 105), NULL)
cfg(allocation_mirror_logs_require_separate_pvs_CFG, "mirror_logs_require_separate_pvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MIRROR_LOGS_REQUIRE_SEPARATE_PVS, vsn(2, 2, 85), NULL)
cfg(allocation_thin_pool_metadata_require_separate_pvs_CFG, "thin_pool_metadata_require_separate_pvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_THIN_POOL_METADATA_REQUIRE_SEPARATE_PVS, vsn(2, 2, 89), NULL)
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9bfc0be493192958…
Commit: 9bfc0be493192958f5dbffea4eb7dda968062261
Parent: b6dab4e0598df7b6a44a32749fdb846c03aa692d
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Thu Nov 14 14:03:24 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 15:48:16 2013 +0100
configure: add --enable-blkid_wiping
---
WHATS_NEW | 1 +
configure | 128 +++++++++++++++++++++++++++++++++++++++++++++++
configure.in | 22 ++++++++
lib/misc/configure.h.in | 3 +
liblvm/liblvm2app.pc.in | 2 +-
make.tmpl.in | 5 +-
tools/Makefile.in | 2 +-
7 files changed, 159 insertions(+), 4 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index b4d683d..9823cd1 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Add configure --enable-blkid_wiping to use libblkid to detect signatures.
Add -W/--wipesignatures lvcreate option to support wiping on new LVs.
Add allocation/wipe_signatures_on_new_logical_volumes_when_zeroing to lvm.conf.
Do not fail the whole autoactivation if the VG refresh done before fails.
diff --git a/configure b/configure
index 9418d53..8247ddd 100755
--- a/configure
+++ b/configure
@@ -691,6 +691,8 @@ CLDFLAGS
BUILD_LVMETAD
BUILD_DMEVENTD
BUILD_CMIRRORD
+BLKID_WIPING
+BLKID_PC
APPLIB
MODPROBE_CMD
MSGFMT
@@ -700,6 +702,8 @@ LVM2CMD_LIB
LVM2APP_LIB
UDEV_LIBS
UDEV_CFLAGS
+BLKID_LIBS
+BLKID_CFLAGS
VALGRIND_POOL
VALGRIND_LIBS
VALGRIND_CFLAGS
@@ -852,6 +856,7 @@ enable_valgrind_pool
enable_devmapper
enable_lvmetad
with_lvmetad_pidfile
+enable_blkid_wiping
enable_udev_systemd_background_jobs
enable_udev_sync
enable_udev_rules
@@ -926,6 +931,8 @@ CUNIT_CFLAGS
CUNIT_LIBS
VALGRIND_CFLAGS
VALGRIND_LIBS
+BLKID_CFLAGS
+BLKID_LIBS
UDEV_CFLAGS
UDEV_LIBS'
@@ -1556,6 +1563,7 @@ Optional Features:
--enable-valgrind-pool enable valgrind awareness of pools
--disable-devmapper disable LVM2 device-mapper interaction
--enable-lvmetad enable the LVM Metadata Daemon
+ --enable-blkid_wiping use wiping functionality provided by libblkid
--enable-udev-systemd-background-jobs
enable udev-systemd protocol to instantiate a
service for background job
@@ -1716,6 +1724,9 @@ Some influential environment variables:
C compiler flags for VALGRIND, overriding pkg-config
VALGRIND_LIBS
linker flags for VALGRIND, overriding pkg-config
+ BLKID_CFLAGS
+ C compiler flags for BLKID, overriding pkg-config
+ BLKID_LIBS linker flags for BLKID, overriding pkg-config
UDEV_CFLAGS C compiler flags for UDEV, overriding pkg-config
UDEV_LIBS linker flags for UDEV, overriding pkg-config
@@ -9174,6 +9185,120 @@ _ACEOF
fi
################################################################################
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use blkid wiping functionality" >&5
+$as_echo_n "checking whether to use blkid wiping functionality... " >&6; }
+# Check whether --enable-blkid-wiping was given.
+if test "${enable_blkid_wiping+set}" = set; then :
+ enableval=$enable_blkid_wiping; BLKID_WIPING=$enableval
+else
+ BLKID_WIPING=no
+fi
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $BLKID_WIPING" >&5
+$as_echo "$BLKID_WIPING" >&6; }
+
+
+if test x$BLKID_WIPING = xyes; then
+ if test x$PKGCONFIG_INIT != x1; then
+ pkg_config_init
+ fi
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for BLKID" >&5
+$as_echo_n "checking for BLKID... " >&6; }
+
+if test -n "$BLKID_CFLAGS"; then
+ pkg_cv_BLKID_CFLAGS="$BLKID_CFLAGS"
+ elif test -n "$PKG_CONFIG"; then
+ if test -n "$PKG_CONFIG" && \
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"blkid >= 2.22\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "blkid >= 2.22") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; then
+ pkg_cv_BLKID_CFLAGS=`$PKG_CONFIG --cflags "blkid >= 2.22" 2>/dev/null`
+else
+ pkg_failed=yes
+fi
+ else
+ pkg_failed=untried
+fi
+if test -n "$BLKID_LIBS"; then
+ pkg_cv_BLKID_LIBS="$BLKID_LIBS"
+ elif test -n "$PKG_CONFIG"; then
+ if test -n "$PKG_CONFIG" && \
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"blkid >= 2.22\""; } >&5
+ ($PKG_CONFIG --exists --print-errors "blkid >= 2.22") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; then
+ pkg_cv_BLKID_LIBS=`$PKG_CONFIG --libs "blkid >= 2.22" 2>/dev/null`
+else
+ pkg_failed=yes
+fi
+ else
+ pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+ _pkg_short_errors_supported=yes
+else
+ _pkg_short_errors_supported=no
+fi
+ if test $_pkg_short_errors_supported = yes; then
+ BLKID_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "blkid >= 2.22" 2>&1`
+ else
+ BLKID_PKG_ERRORS=`$PKG_CONFIG --print-errors "blkid >= 2.22" 2>&1`
+ fi
+ # Put the nasty error message in config.log where it belongs
+ echo "$BLKID_PKG_ERRORS" >&5
+
+ as_fn_error $? "Package requirements (blkid >= 2.22) were not met:
+
+$BLKID_PKG_ERRORS
+
+Consider adjusting the PKG_CONFIG_PATH environment variable if you
+installed software in a non-standard prefix.
+
+Alternatively, you may set the environment variables BLKID_CFLAGS
+and BLKID_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details." "$LINENO" 5
+
+elif test $pkg_failed = untried; then
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error $? "The pkg-config script could not be found or is too old. Make sure it
+is in your PATH or set the PKG_CONFIG environment variable to the full
+path to pkg-config.
+
+Alternatively, you may set the environment variables BLKID_CFLAGS
+and BLKID_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.
+
+To get pkg-config, see <http://pkg-config.freedesktop.org/ >.
+See \`config.log' for more details" "$LINENO" 5; }
+
+else
+ BLKID_CFLAGS=$pkg_cv_BLKID_CFLAGS
+ BLKID_LIBS=$pkg_cv_BLKID_LIBS
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+ BLKID_PC="blkid"
+fi
+
+$as_echo "#define BLKID_WIPING_SUPPORT 1" >>confdefs.h
+
+fi
+
+################################################################################
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to use udev-systemd protocol for jobs in background" >&5
$as_echo_n "checking whether to use udev-systemd protocol for jobs in background... " >&6; }
# Check whether --enable-udev-systemd-background-jobs was given.
@@ -11029,6 +11154,9 @@ LVM_LIBAPI=`echo "$VER" | $AWK -F '[()]' '{print $2}'`
+
+
+
################################################################################
ac_config_files="$ac_config_files Makefile make.tmpl daemons/Makefile daemons/clvmd/Makefile daemons/cmirrord/Makefile daemons/dmeventd/Makefile daemons/dmeventd/libdevmapper-event.pc daemons/dmeventd/plugins/Makefile daemons/dmeventd/plugins/lvm2/Makefile daemons/dmeventd/plugins/raid/Makefile daemons/dmeventd/plugins/mirror/Makefile daemons/dmeventd/plugins/snapshot/Makefile daemons/dmeventd/plugins/thin/Makefile daemons/lvmetad/Makefile conf/Makefile conf/example.conf conf/default.profile include/.symlinks include/Makefile lib/Makefile lib/format1/Makefile lib/format_pool/Makefile lib/locking/Makefile lib/mirror/Makefile lib/replicator/Makefile lib/misc/lvm-version.h lib/raid/Makefile lib/snapshot/Makefile lib/thin/Makefile libdaemon/Makefile libdaemon/client/Makefile libdaemon/server/Makefile libdm/Makefile libdm/libdevmapper.pc liblvm/Makefile liblvm/liblvm2app.pc man/Makefile po/Makefile python/Makefile python/setup.py scripts/blkdeactivate.sh scripts/blk_availability_
init_red_hat scripts/blk_availability_systemd_red_hat.service scripts/clvmd_init_red_hat scripts/cmirrord_init_red_hat scripts/lvm2_lvmetad_init_red_hat scripts/lvm2_lvmetad_systemd_red_hat.socket scripts/lvm2_lvmetad_systemd_red_hat.service scripts/lvm2_pvscan_systemd_red_hat@.service scripts/lvm2_monitoring_init_red_hat scripts/dm_event_systemd_red_hat.socket scripts/dm_event_systemd_red_hat.service scripts/lvm2_monitoring_systemd_red_hat.service scripts/lvm2_tmpfiles_red_hat.conf scripts/Makefile test/Makefile test/api/Makefile test/unit/Makefile tools/Makefile udev/Makefile unit-tests/datastruct/Makefile unit-tests/regex/Makefile unit-tests/mm/Makefile"
diff --git a/configure.in b/configure.in
index cd80274..ff9bf81 100644
--- a/configure.in
+++ b/configure.in
@@ -946,6 +946,25 @@ if test x$BUILD_LVMETAD = xyes; then
fi
################################################################################
+dnl -- Enable blkid wiping functionality
+AC_MSG_CHECKING(whether to use blkid wiping functionality)
+AC_ARG_ENABLE(blkid-wiping,
+ AC_HELP_STRING([--enable-blkid_wiping],
+ [use wiping functionality provided by libblkid]),
+ BLKID_WIPING=$enableval, BLKID_WIPING=no)
+AC_MSG_RESULT($BLKID_WIPING)
+
+
+if test x$BLKID_WIPING = xyes; then
+ dnl -- init pkgconfig if required
+ if test x$PKGCONFIG_INIT != x1; then
+ pkg_config_init
+ fi
+ PKG_CHECK_MODULES(BLKID, blkid >= 2.22, [BLKID_PC="blkid"])
+ AC_DEFINE([BLKID_WIPING_SUPPORT], 1, [Define to 1 to use wiping functionality provided by libblkid.])
+fi
+
+################################################################################
dnl -- Enable udev-systemd protocol to instantiate a service for background jobs
AC_MSG_CHECKING(whether to use udev-systemd protocol for jobs in background)
AC_ARG_ENABLE(udev-systemd-background-jobs,
@@ -1538,6 +1557,9 @@ LVM_LIBAPI=`echo "$VER" | $AWK -F '[[()]]' '{print $2}'`
################################################################################
AC_SUBST(APPLIB)
AC_SUBST(AWK)
+AC_SUBST(BLKID_LIBS)
+AC_SUBST(BLKID_PC)
+AC_SUBST(BLKID_WIPING)
AC_SUBST(BUILD_CMIRRORD)
AC_SUBST(BUILD_DMEVENTD)
AC_SUBST(BUILD_LVMETAD)
diff --git a/lib/misc/configure.h.in b/lib/misc/configure.h.in
index 13ba882..51db42e 100644
--- a/lib/misc/configure.h.in
+++ b/lib/misc/configure.h.in
@@ -1,5 +1,8 @@
/* lib/misc/configure.h.in. Generated from configure.in by autoheader. */
+/* Define to 1 to use wiping functionality provided by libblkid. */
+#undef BLKID_WIPING_SUPPORT
+
/* Define to 1 if the `closedir' function returns void instead of `int'. */
#undef CLOSEDIR_VOID
diff --git a/liblvm/liblvm2app.pc.in b/liblvm/liblvm2app.pc.in
index 4c71c36..7d7fd3d 100644
--- a/liblvm/liblvm2app.pc.in
+++ b/liblvm/liblvm2app.pc.in
@@ -8,4 +8,4 @@ Description: lvm2 application library
Version: @LVM_MAJOR@.@LVM_LIBAPI@
Cflags: -I${includedir}
Libs: -L${libdir} -llvm2app
-Requires.private: devmapper
+Requires.private: devmapper @BLKID_PC@
diff --git a/make.tmpl.in b/make.tmpl.in
index 3eea85e..35a47be 100644
--- a/make.tmpl.in
+++ b/make.tmpl.in
@@ -43,7 +43,7 @@ PYTHON = @PYTHON@
LIBS = @LIBS@
# Extra libraries always linked with static binaries
-STATIC_LIBS = $(SELINUX_LIBS) $(UDEV_LIBS)
+STATIC_LIBS = $(SELINUX_LIBS) $(UDEV_LIBS) $(BLKID_LIBS)
DEFS += @DEFS@
# FIXME set this only where it's needed, not globally?
CFLAGS += @CFLAGS@ @UDEV_CFLAGS@
@@ -52,12 +52,13 @@ ELDFLAGS += @ELDFLAGS@
LDDEPS += @LDDEPS@
LDFLAGS += @LDFLAGS@
LIB_SUFFIX = @LIB_SUFFIX@
-LVMINTERNAL_LIBS = -llvm-internal $(DAEMON_LIBS) $(UDEV_LIBS) $(DL_LIBS)
+LVMINTERNAL_LIBS = -llvm-internal $(DAEMON_LIBS) $(UDEV_LIBS) $(DL_LIBS) $(BLKID_LIBS)
DL_LIBS = @DL_LIBS@
PTHREAD_LIBS = @PTHREAD_LIBS@
READLINE_LIBS = @READLINE_LIBS@
SELINUX_LIBS = @SELINUX_LIBS@
UDEV_LIBS = @UDEV_LIBS@
+BLKID_LIBS=@BLKID_LIBS@
TESTING = @TESTING@
# Setup directory variables
diff --git a/tools/Makefile.in b/tools/Makefile.in
index f90cfae..f8e4934 100644
--- a/tools/Makefile.in
+++ b/tools/Makefile.in
@@ -117,7 +117,7 @@ CFLOW_TARGET = lvm
include $(top_builddir)/make.tmpl
-LIBS += $(UDEV_LIBS)
+LIBS += $(UDEV_LIBS) $(BLKID_LIBS)
device-mapper: $(TARGETS_DM)
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b6dab4e0598df7b6…
Commit: b6dab4e0598df7b6a44a32749fdb846c03aa692d
Parent: 169b4c15864330e3fe47efee7b0def06581b8f08
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Nov 6 16:16:34 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 15:48:15 2013 +0100
lv_manip: rename set_lv -> wipe_lv and include signature wiping capability
Use common wipe_lv (former set_lv) fn to do zeroing as well as signature
wiping if needed. Provide new struct wipe_lv_params to define the
functionality.
Bind "lvcreate -W/--wipesignatures y" with proper wipe_lv call.
Also, add "yes" and "force" to lvcreate_params so it's possible
to apply them for the prompt: "WARNING: %s detected on %s. Wipe it? [y/n]".
---
lib/metadata/lv_manip.c | 98 ++++++++++++++++++++++++++------------
lib/metadata/metadata-exported.h | 18 ++++++-
lib/metadata/mirror.c | 18 +++++--
lib/metadata/raid_manip.c | 11 ++++-
lib/metadata/thin_manip.c | 12 ++++-
tools/lvchange.c | 13 +++++-
tools/lvconvert.c | 27 ++++++++++-
tools/lvcreate.c | 2 +
8 files changed, 157 insertions(+), 42 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 491accd..521d058 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -2906,7 +2906,17 @@ static int _lv_extend_layered_lv(struct alloc_handle *ah,
* wipe '1' to remove the superblock of any previous
* RAID devices. It is much quicker.
*/
- if (!set_lv(meta_lv->vg->cmd, meta_lv, 1, 0)) {
+ struct wipe_lv_params wp = {
+ .lv = meta_lv,
+ .do_zero = 1,
+ .zero_sectors = 1,
+ .zero_value = 0,
+ .do_wipe_signatures = 0,
+ .yes = 0,
+ .force = PROMPT
+ };
+
+ if (!wipe_lv(meta_lv->vg->cmd, &wp)) {
log_error("Failed to zero %s/%s",
meta_lv->vg->name, meta_lv->name);
return 0;
@@ -5372,15 +5382,19 @@ int insert_layer_for_segments_on_pv(struct cmd_context *cmd,
/*
* Initialize the LV with 'value'.
*/
-int set_lv(struct cmd_context *cmd, struct logical_volume *lv,
- uint64_t sectors, int value)
+int wipe_lv(struct cmd_context *cmd, struct wipe_lv_params *wp)
{
struct device *dev;
char *name;
+ uint64_t zero_sectors;
- if (!lv_is_active_locally(lv)) {
+ if (!(wp->do_zero || wp->do_wipe_signatures))
+ /* nothing to do */
+ return 1;
+
+ if (!lv_is_active_locally(wp->lv)) {
log_error("Volume \"%s/%s\" is not active locally.",
- lv->vg->name, lv->name);
+ wp->lv->vg->name, wp->lv->name);
return 0;
}
@@ -5397,15 +5411,13 @@ int set_lv(struct cmd_context *cmd, struct logical_volume *lv,
}
if (dm_snprintf(name, PATH_MAX, "%s%s/%s", cmd->dev_dir,
- lv->vg->name, lv->name) < 0) {
- log_error("Name too long - device not cleared (%s)", lv->name);
+ wp->lv->vg->name, wp->lv->name) < 0) {
+ log_error("Name too long - device not cleared (%s)", wp->lv->name);
return 0;
}
sync_local_dev_names(cmd); /* Wait until devices are available */
- log_verbose("Clearing start of logical volume \"%s\"", lv->name);
-
if (!(dev = dev_cache_get(name, NULL))) {
log_error("%s: not found: device not cleared", name);
return 0;
@@ -5414,21 +5426,32 @@ int set_lv(struct cmd_context *cmd, struct logical_volume *lv,
if (!dev_open_quiet(dev))
return_0;
- if (!sectors)
- sectors = UINT64_C(4096) >> SECTOR_SHIFT;
+ if (wp->do_wipe_signatures) {
+ log_verbose("Wiping known signatures on logical volume \"%s/%s\"",
+ wp->lv->vg->name, wp->lv->name);
+ if (!wipe_known_sbs(dev, name, wp->yes, wp->force))
+ stack;
+ }
- if (sectors > lv->size)
- sectors = lv->size;
+ if (wp->do_zero) {
+ zero_sectors = wp->zero_sectors ? : UINT64_C(4096) >> SECTOR_SHIFT;
- if (!dev_set(dev, UINT64_C(0), (size_t) sectors << SECTOR_SHIFT, value))
- stack;
+ if (zero_sectors > wp->lv->size)
+ zero_sectors = wp->lv->size;
+
+ log_verbose("Clearing start of logical volume \"%s/%s\"",
+ wp->lv->vg->name, wp->lv->name);
+
+ if (!dev_set(dev, UINT64_C(0), (size_t) zero_sectors << SECTOR_SHIFT, wp->zero_value))
+ stack;
+ }
dev_flush(dev);
if (!dev_close_immediate(dev))
stack;
- lv->status &= ~LV_NOSCAN;
+ wp->lv->status &= ~LV_NOSCAN;
return 1;
}
@@ -5982,12 +6005,12 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
backup(vg);
if (test_mode()) {
- log_verbose("Test mode: Skipping activation and zeroing.");
+ log_verbose("Test mode: Skipping activation, zeroing and signature wiping.");
goto out;
}
- /* Do not scan this LV until properly zeroed. */
- if (lp->zero)
+ /* Do not scan this LV until properly zeroed/wiped. */
+ if (lp->zero | lp->wipe_signatures)
lv->status |= LV_NOSCAN;
if (lp->temporary)
@@ -6056,21 +6079,36 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
}
} else if (!lv_active_change(cmd, lv, lp->activate)) {
log_error("Failed to activate new LV.");
- if (lp->zero)
+ if (lp->zero || lp->wipe_signatures)
goto deactivate_and_revert_new_lv;
return NULL;
}
- if (!seg_is_thin(lp) && !lp->zero && !lp->snapshot)
- log_warn("WARNING: \"%s\" not zeroed", lv->name);
- else if ((!seg_is_thin(lp) ||
- (lv_is_thin_volume(lv) && !lp->snapshot &&
- !first_seg(first_seg(lv)->pool_lv)->zero_new_blocks)) &&
- !set_lv(cmd, lv, UINT64_C(0), 0)) {
- log_error("Aborting. Failed to wipe %s.",
- lp->snapshot ? "snapshot exception store" :
- "start of new LV");
- goto deactivate_and_revert_new_lv;
+ if (!seg_is_thin(lp) && !lp->snapshot) {
+ if (!lp->zero)
+ log_warn("WARNING: \"%s/%s\" not zeroed", lv->vg->name, lv->name);
+ if (!lp->wipe_signatures)
+ log_verbose("Signature wiping on \"%s/%s\" not requested", lv->vg->name, lv->name);
+ }
+
+ if ((!seg_is_thin(lp) ||
+ (lv_is_thin_volume(lv) && !lp->snapshot &&
+ !first_seg(first_seg(lv)->pool_lv)->zero_new_blocks))) {
+ struct wipe_lv_params wp = {
+ .lv = lv,
+ .do_zero = lp->zero,
+ .zero_sectors = 0,
+ .zero_value = 0,
+ .do_wipe_signatures = lp->wipe_signatures,
+ .yes = lp->yes,
+ .force = lp->force
+ };
+ if (!wipe_lv(cmd, &wp)) {
+ log_error("Aborting. Failed to wipe %s.",
+ lp->snapshot ? "snapshot exception store" :
+ "start of new LV");
+ goto deactivate_and_revert_new_lv;
+ }
}
if (lp->snapshot && !seg_is_thin(lp)) {
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 69a0e90..41bd1a7 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -622,9 +622,18 @@ struct logical_volume *lv_create_empty(const char *name,
alloc_policy_t alloc,
struct volume_group *vg);
-/* Write out LV contents */
-int set_lv(struct cmd_context *cmd, struct logical_volume *lv,
- uint64_t sectors, int value);
+struct wipe_lv_params {
+ struct logical_volume *lv;
+ int do_zero; /* should we do zeroing of LV start? */
+ uint64_t zero_sectors; /* sector count to zero */
+ int zero_value; /* zero-out with this value */
+ int do_wipe_signatures; /* should we wipe known signatures found on LV? */
+ int yes; /* answer yes automatically to all questions */
+ force_t force; /* force mode */
+};
+
+/* Zero out LV and/or wipe signatures */
+int wipe_lv(struct cmd_context *cmd, struct wipe_lv_params *params);
int lv_change_tag(struct logical_volume *lv, const char *tag, int add_tag);
@@ -779,6 +788,9 @@ struct lvcreate_params {
alloc_policy_t alloc; /* all */
struct dm_list tags; /* all */
+
+ int yes;
+ force_t force;
};
struct logical_volume *lv_create_single(struct volume_group *vg,
diff --git a/lib/metadata/mirror.c b/lib/metadata/mirror.c
index 24c9786..83ba486 100644
--- a/lib/metadata/mirror.c
+++ b/lib/metadata/mirror.c
@@ -339,10 +339,20 @@ static int _init_mirror_log(struct cmd_context *cmd,
dm_list_iterate_items(sl, tags)
str_list_del(&log_lv->tags, sl->str);
- if (activation() && !set_lv(cmd, log_lv, log_lv->size,
- in_sync ? -1 : 0)) {
- log_error("Aborting. Failed to wipe mirror log.");
- goto deactivate_and_revert_new_lv;
+ if (activation()) {
+ struct wipe_lv_params wp = {
+ .lv = log_lv,
+ .do_zero = 1,
+ .zero_sectors = log_lv->size,
+ .zero_value = in_sync ? -1 : 0,
+ .do_wipe_signatures = 0,
+ .yes = 0,
+ .force = PROMPT
+ };
+ if (!wipe_lv(cmd, &wp)) {
+ log_error("Aborting. Failed to wipe mirror log.");
+ goto deactivate_and_revert_new_lv;
+ }
}
if (activation() && !_write_log_header(cmd, log_lv)) {
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
index 147b478..d1bb330 100644
--- a/lib/metadata/raid_manip.c
+++ b/lib/metadata/raid_manip.c
@@ -170,6 +170,15 @@ static int _raid_remove_top_layer(struct logical_volume *lv,
static int _clear_lv(struct logical_volume *lv)
{
int was_active = lv_is_active_locally(lv);
+ struct wipe_lv_params wp = {
+ .lv = lv,
+ .do_zero = 1,
+ .zero_sectors = 1,
+ .zero_value = 0,
+ .do_wipe_signatures = 0,
+ .yes = 0,
+ .force = PROMPT
+ };
if (test_mode())
return 1;
@@ -187,7 +196,7 @@ static int _clear_lv(struct logical_volume *lv)
* wipe the first sector to remove the superblock of any previous
* RAID devices. It is much quicker.
*/
- if (!set_lv(lv->vg->cmd, lv, 1, 0)) {
+ if (!wipe_lv(lv->vg->cmd, &wp)) {
log_error("Failed to zero %s", lv->name);
return 0;
}
diff --git a/lib/metadata/thin_manip.c b/lib/metadata/thin_manip.c
index bd5b117..4ee4411 100644
--- a/lib/metadata/thin_manip.c
+++ b/lib/metadata/thin_manip.c
@@ -468,10 +468,20 @@ int create_pool(struct logical_volume *pool_lv, const struct segment_type *segty
* FIXME: implement lazy clearing when activation is disabled
*/
+ struct wipe_lv_params wp = {
+ .lv = pool_lv,
+ .do_zero = 1,
+ .zero_sectors = 0,
+ .zero_value = 0,
+ .do_wipe_signatures = 0,
+ .yes = 0,
+ .force = PROMPT
+ };
+
/* pool_lv is a new LV so the VG lock protects us */
if (!activate_lv_local(pool_lv->vg->cmd, pool_lv) ||
/* Clear 4KB of metadata device for new thin-pool. */
- !set_lv(pool_lv->vg->cmd, pool_lv, UINT64_C(0), 0)) {
+ !wipe_lv(pool_lv->vg->cmd, &wp)) {
log_error("Aborting. Failed to wipe pool metadata %s.",
pool_lv->name);
goto bad;
diff --git a/tools/lvchange.c b/tools/lvchange.c
index 897ffb2..59a554c 100644
--- a/tools/lvchange.c
+++ b/tools/lvchange.c
@@ -478,7 +478,18 @@ static int lvchange_resync(struct cmd_context *cmd, struct logical_volume *lv)
log_very_verbose("Clearing %s device %s",
(seg_is_raid(seg)) ? "metadata" : "log",
lvl->lv->name);
- if (!set_lv(cmd, lvl->lv, lvl->lv->size, 0)) {
+
+ struct wipe_lv_params wp = {
+ .lv = lvl->lv,
+ .do_zero = 1,
+ .zero_sectors = lvl->lv->size,
+ .zero_value = 0,
+ .do_wipe_signatures = 0,
+ .yes = 0,
+ .force = PROMPT
+ };
+
+ if (!wipe_lv(cmd, &wp)) {
log_error("Unable to reset sync status for %s",
lv->name);
if (!deactivate_lv(cmd, lvl->lv))
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index a15bd75..31eb232 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -1846,10 +1846,22 @@ static int lvconvert_snapshot(struct cmd_context *cmd,
if (!lp->zero || !(lv->status & LVM_WRITE))
log_warn("WARNING: \"%s\" not zeroed", lv->name);
- else if (!set_lv(cmd, lv, UINT64_C(0), 0)) {
+ else {
+ struct wipe_lv_params wp = {
+ .lv = lv,
+ .do_zero = 1,
+ .zero_sectors = 0,
+ .zero_value = 0,
+ .do_wipe_signatures = 0,
+ .yes = 0,
+ .force = PROMPT
+ };
+
+ if (!wipe_lv(cmd, &wp)) {
log_error("Aborting. Failed to wipe snapshot "
"exception store.");
return 0;
+ }
}
if (!deactivate_lv(cmd, lv)) {
@@ -2463,7 +2475,18 @@ static int _lvconvert_thinpool(struct cmd_context *cmd,
log_error("Aborting. Failed to activate thin metadata lv.");
return 0;
}
- if (!set_lv(cmd, metadata_lv, UINT64_C(0), 0)) {
+
+ struct wipe_lv_params wp = {
+ .lv = metadata_lv,
+ .do_zero = 1,
+ .zero_sectors = 0,
+ .zero_value = 0,
+ .do_wipe_signatures = 0,
+ .yes = 0,
+ .force = PROMPT
+ };
+
+ if (!wipe_lv(cmd, &wp)) {
log_error("Aborting. Failed to wipe thin metadata lv.");
return 0;
}
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 83c12a7..1fe5130 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -710,6 +710,8 @@ static int _read_activation_params(struct lvcreate_params *lp, struct cmd_contex
return 0;
}
+ lp->yes = arg_count(cmd, yes_ARG);
+ lp->force = (force_t) arg_count(cmd, force_ARG);
return 1;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=169b4c15864330e3…
Commit: 169b4c15864330e3fe47efee7b0def06581b8f08
Parent: 5b7e543cae5be52e1dcd79c7f6876acc89138cf1
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Nov 6 16:05:50 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 15:48:15 2013 +0100
lvcreate: recognize --wipesignatures arg
Recognize the new --wipesignatures arg in lvcreate that is supposed
to wipe known signatures if found on newly created LV.
---
WHATS_NEW | 1 +
lib/metadata/metadata-exported.h | 1 +
liblvm/lvm_lv.c | 1 +
tools/args.h | 1 +
tools/commands.h | 4 +++-
tools/lvcreate.c | 28 +++++++++++++++++++++++-----
6 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index af489d6..b4d683d 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Add -W/--wipesignatures lvcreate option to support wiping on new LVs.
Add allocation/wipe_signatures_on_new_logical_volumes_when_zeroing to lvm.conf.
Do not fail the whole autoactivation if the VG refresh done before fails.
Do not connect to lvmetad on vg/lvchange --sysinit -aay and socket absent.
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 33c534f..69a0e90 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -723,6 +723,7 @@ struct lvcreate_params {
int thin; /* thin */
int create_thin_pool; /* thin */
int zero; /* all */
+ int wipe_signatures; /* all */
int major; /* all */
int minor; /* all */
int log_count; /* mirror */
diff --git a/liblvm/lvm_lv.c b/liblvm/lvm_lv.c
index 938a16b..f5c3ab9 100644
--- a/liblvm/lvm_lv.c
+++ b/liblvm/lvm_lv.c
@@ -129,6 +129,7 @@ static void _lv_set_default_params(struct lvcreate_params *lp,
uint64_t extents)
{
lp->zero = 1;
+ lp->wipe_signatures = 0;
lp->major = -1;
lp->minor = -1;
lp->activate = CHANGE_AY;
diff --git a/tools/args.h b/tools/args.h
index 27b97eb..8ca73a3 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -176,6 +176,7 @@ arg(uuidlist_ARG, 'U', "uuidlist", NULL, 0)
arg(verbose_ARG, 'v', "verbose", NULL, ARG_COUNTABLE)
arg(volumegroup_ARG, 'V', "volumegroup", NULL, 0)
arg(virtualsize_ARG, 'V', "virtualsize", size_mb_arg, 0)
+arg(wipesignatures_ARG, 'W', "wipesignatures", yes_no_arg, 0)
arg(allocatable_ARG, 'x', "allocatable", yes_no_arg, 0)
arg(resizeable_ARG, 'x', "resizeable", yes_no_arg, 0)
arg(yes_ARG, 'y', "yes", NULL, 0)
diff --git a/tools/commands.h b/tools/commands.h
index c299276..c54e812 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -248,6 +248,7 @@ xx(lvcreate,
"\t[-t|--test]\n"
"\t[--type VolumeType]\n"
"\t[-v|--verbose]\n"
+ "\t[-W|--wipesignatures {y|n}]\n"
"\t[-Z|--zero {y|n}]\n"
"\t[--version]\n"
"\tVolumeGroupName [PhysicalVolumePath...]\n\n"
@@ -294,7 +295,8 @@ xx(lvcreate,
raidminrecoveryrate_ARG, raidmaxrecoveryrate_ARG, readahead_ARG,
regionsize_ARG, setactivationskip_ARG, size_ARG, snapshot_ARG, stripes_ARG,
stripesize_ARG, test_ARG, thin_ARG, thinpool_ARG,
- type_ARG, virtualoriginsize_ARG, virtualsize_ARG, zero_ARG)
+ type_ARG, virtualoriginsize_ARG, virtualsize_ARG,
+ wipesignatures_ARG, zero_ARG)
xx(lvdisplay,
"Display information about a logical volume",
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 4850872..83c12a7 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -614,8 +614,8 @@ static int _read_activation_params(struct lvcreate_params *lp, struct cmd_contex
return 0;
}
} else if (lp->activate == CHANGE_AAY) {
- if (arg_count(cmd, zero_ARG)) {
- log_error("-Z is incompatible with --activate a");
+ if (arg_count(cmd, zero_ARG) || arg_count(cmd, wipesignatures_ARG)) {
+ log_error("-Z and -W is incompatible with --activate a");
return 0;
}
lp->zero = 0;
@@ -644,9 +644,11 @@ static int _read_activation_params(struct lvcreate_params *lp, struct cmd_contex
lp->permission = arg_uint_value(cmd, permission_ARG,
LVM_READ | LVM_WRITE);
- /* Must not zero read only volume */
- if (!(lp->permission & LVM_WRITE))
+ /* Must not zero/wipe read only volume */
+ if (!(lp->permission & LVM_WRITE)) {
lp->zero = 0;
+ lp->wipe_signatures = 0;
+ }
if (arg_count(cmd, major_ARG) > 1) {
log_error("Option -j/--major may not be repeated.");
@@ -867,11 +869,27 @@ static int _lvcreate_params(struct lvcreate_params *lp,
}
/*
- * Should we zero the lv.
+ * Should we zero/wipe signatures on the lv.
*/
lp->zero = strcmp(arg_str_value(cmd, zero_ARG,
(lp->segtype->flags & SEG_CANNOT_BE_ZEROED) ? "n" : "y"), "n");
+ if (arg_count(cmd, wipesignatures_ARG)) {
+ /* If -W/--wipesignatures is given on command line directly, respect it. */
+ lp->wipe_signatures = strcmp(arg_str_value(cmd, wipesignatures_ARG,
+ (lp->segtype->flags & SEG_CANNOT_BE_ZEROED) ? "n" : "y"), "n");
+ } else {
+ /*
+ * If -W/--wipesignatures is not given on command line,
+ * look at the allocation/wipe_signatures_on_new_logical_volumes_when_zeroing
+ * to decide what should be done exactly.
+ */
+ if (find_config_tree_bool(cmd, allocation_wipe_signatures_on_new_logical_volumes_when_zeroing_CFG, NULL))
+ lp->wipe_signatures = lp->zero;
+ else
+ lp->wipe_signatures = 0;
+ }
+
if (!_lvcreate_name_params(lp, cmd, &argc, &argv) ||
!_read_size_params(lp, lcp, cmd) ||
!get_stripe_params(cmd, &lp->stripes, &lp->stripe_size) ||
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5b7e543cae5be52e…
Commit: 5b7e543cae5be52e1dcd79c7f6876acc89138cf1
Parent: 03c941a4caf411f21045670e205ccdd975be27c7
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Nov 27 12:54:48 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 15:48:06 2013 +0100
conf: add allocation/wipe_signatures_on_new_logical_volumes_when_zeroing
This setting controls whether signature wiping on newly created logical
volumes will follow the state of zeroing (-Z/--zero option).
---
WHATS_NEW | 1 +
conf/default.profile.in | 1 +
conf/example.conf.in | 9 +++++++++
lib/config/config_settings.h | 1 +
4 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 7718b6f..af489d6 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Add allocation/wipe_signatures_on_new_logical_volumes_when_zeroing to lvm.conf.
Do not fail the whole autoactivation if the VG refresh done before fails.
Do not connect to lvmetad on vg/lvchange --sysinit -aay and socket absent.
Use lv_check_not_in_use() when testing device in use before merging.
diff --git a/conf/default.profile.in b/conf/default.profile.in
index 29049ef..5a481de 100644
--- a/conf/default.profile.in
+++ b/conf/default.profile.in
@@ -9,6 +9,7 @@
# Refer to 'man lvm.conf' for further information about profiles and file layout.
allocation {
+ wipe_signatures_on_new_logical_volumes_when_zeroing = 1
thin_pool_chunk_size_policy = "generic"
thin_pool_chunk_size = 64
thin_pool_discards = "passdown"
diff --git a/conf/example.conf.in b/conf/example.conf.in
index 03e1c45..0ac53ef 100644
--- a/conf/example.conf.in
+++ b/conf/example.conf.in
@@ -272,6 +272,15 @@ allocation {
# algorithm.
maximise_cling = 1
+ # Whether do wipe any signatures found on newly created Logical Volumes
+ # automatically in addition to zeroing of the first KB on the LV
+ # (-Z/--zero y option) when running the LVM command without specifying
+ # the -W/--wipesignatures option. If -W/--wipesignatures command line
+ # option is specified, it always takes precedence over this setting.
+ # Default is to wipe signatures when zeroing.
+ #
+ wipe_signatures_on_new_logical_volumes_when_zeroing = 1
+
# Set to 1 to guarantee that mirror logs will always be placed on
# different PVs from the mirror images. This was the default
# until version 2.02.85.
diff --git a/lib/config/config_settings.h b/lib/config/config_settings.h
index 7fdf763..7a7e8e5 100644
--- a/lib/config/config_settings.h
+++ b/lib/config/config_settings.h
@@ -104,6 +104,7 @@ cfg(devices_issue_discards_CFG, "issue_discards", devices_CFG_SECTION, 0, CFG_TY
cfg_array(allocation_cling_tag_list_CFG, "cling_tag_list", allocation_CFG_SECTION, 0, CFG_TYPE_STRING, NULL, vsn(2, 2, 77), NULL)
cfg(allocation_maximise_cling_CFG, "maximise_cling", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MAXIMISE_CLING, vsn(2, 2, 85), NULL)
+cfg(allocation_wipe_signatures_on_new_logical_volumes_when_zeroing_CFG, "wipe_signatures_on_new_logical_volumes_when_zeroing", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, 1, vsn(2, 2, 105), NULL)
cfg(allocation_mirror_logs_require_separate_pvs_CFG, "mirror_logs_require_separate_pvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MIRROR_LOGS_REQUIRE_SEPARATE_PVS, vsn(2, 2, 85), NULL)
cfg(allocation_thin_pool_metadata_require_separate_pvs_CFG, "thin_pool_metadata_require_separate_pvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_THIN_POOL_METADATA_REQUIRE_SEPARATE_PVS, vsn(2, 2, 89), NULL)
cfg(allocation_thin_pool_zero_CFG, "thin_pool_zero", allocation_CFG_SECTION, CFG_PROFILABLE, CFG_TYPE_BOOL, DEFAULT_THIN_POOL_ZERO, vsn(2, 2, 99), NULL)
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=03c941a4caf411f2…
Commit: 03c941a4caf411f21045670e205ccdd975be27c7
Parent: 120df5561088f4a5277716117339d9212b666214
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Nov 6 15:09:29 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 12:56:58 2013 +0100
device: cleanup signature wiping functions
The wipe_known_signatures fn now wraps the _wipe_signature fn that is called
for each known signature (currently md, swap and luks). This patch makes the
code more readable, not repeating the same sequence when used anywhere in the
code. We're going to reuse this code later...
---
lib/device/dev-luks.c | 5 +++--
lib/device/dev-md.c | 6 +++---
lib/device/dev-swap.c | 7 +++----
lib/device/dev-type.c | 42 ++++++++++++++++++++++++++++++++++++++++++
lib/device/dev-type.h | 4 ++++
lib/metadata/metadata.c | 46 ++++------------------------------------------
6 files changed, 59 insertions(+), 51 deletions(-)
diff --git a/lib/device/dev-luks.c b/lib/device/dev-luks.c
index 2671d62..572fd1d 100644
--- a/lib/device/dev-luks.c
+++ b/lib/device/dev-luks.c
@@ -18,7 +18,7 @@
#define LUKS_SIGNATURE "LUKS\xba\xbe"
#define LUKS_SIGNATURE_SIZE 6
-int dev_is_luks(struct device *dev, uint64_t *signature)
+int dev_is_luks(struct device *dev, uint64_t *offset_found)
{
char buf[LUKS_SIGNATURE_SIZE];
int ret = -1;
@@ -28,7 +28,8 @@ int dev_is_luks(struct device *dev, uint64_t *signature)
return -1;
}
- *signature = 0;
+ if (offset_found)
+ *offset_found = 0;
if (!dev_read(dev, 0, LUKS_SIGNATURE_SIZE, buf))
goto_out;
diff --git a/lib/device/dev-md.c b/lib/device/dev-md.c
index 9af8074..d6a7609 100644
--- a/lib/device/dev-md.c
+++ b/lib/device/dev-md.c
@@ -81,7 +81,7 @@ static uint64_t _v1_sb_offset(uint64_t size, md_minor_version_t minor_version)
/*
* Returns -1 on error
*/
-int dev_is_md(struct device *dev, uint64_t *sb)
+int dev_is_md(struct device *dev, uint64_t *offset_found)
{
int ret = 1;
md_minor_version_t minor;
@@ -120,8 +120,8 @@ out:
if (!dev_close(dev))
stack;
- if (ret && sb)
- *sb = sb_offset;
+ if (ret && offset_found)
+ *offset_found = sb_offset;
return ret;
}
diff --git a/lib/device/dev-swap.c b/lib/device/dev-swap.c
index cc44008..f506eda 100644
--- a/lib/device/dev-swap.c
+++ b/lib/device/dev-swap.c
@@ -36,7 +36,7 @@ _swap_detect_signature(const char *buf)
return 0;
}
-int dev_is_swap(struct device *dev, uint64_t *signature)
+int dev_is_swap(struct device *dev, uint64_t *offset_found)
{
char buf[10];
uint64_t size;
@@ -53,8 +53,6 @@ int dev_is_swap(struct device *dev, uint64_t *signature)
return -1;
}
- *signature = 0;
-
for (page = 0x1000; page <= MAX_PAGESIZE; page <<= 1) {
/*
* skip 32k pagesize since this does not seem to be supported
@@ -69,7 +67,8 @@ int dev_is_swap(struct device *dev, uint64_t *signature)
break;
}
if (_swap_detect_signature(buf)) {
- *signature = page - SIGNATURE_SIZE;
+ if (offset_found)
+ *offset_found = page - SIGNATURE_SIZE;
ret = 1;
break;
}
diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c
index f3f29b2..e42349d 100644
--- a/lib/device/dev-type.c
+++ b/lib/device/dev-type.c
@@ -443,6 +443,48 @@ out:
return ret;
}
+static int _wipe_signature(struct device *dev, const char *type, const char *name,
+ int wipe_len, int yes, force_t force,
+ int (*signature_detection_fn)(struct device *dev, uint64_t *offset_found))
+{
+ int wipe;
+ uint64_t offset_found;
+
+ wipe = signature_detection_fn(dev, &offset_found);
+ if (wipe == -1) {
+ log_error("Fatal error while trying to detect %s on %s.",
+ type, name);
+ return 0;
+ }
+
+ if (wipe == 0)
+ return 1;
+
+ /* Specifying --yes => do not ask. */
+ if (!yes && (force == PROMPT) &&
+ yes_no_prompt("WARNING: %s detected on %s. Wipe it? [y/n] ",
+ type, name) != 'y')
+ return_0;
+
+ log_print_unless_silent("Wiping %s on %s.", type, name);
+ if (!dev_set(dev, offset_found, wipe_len, 0)) {
+ log_error("Failed to wipe %s on %s.", type, name);
+ return 0;
+ }
+
+ return 1;
+}
+
+int wipe_known_signatures(struct device *dev, const char *name, int yes, force_t force)
+{
+ if (!_wipe_signature(dev, "software RAID md superblock", name, 4, yes, force, dev_is_md) ||
+ !_wipe_signature(dev, "swap signature", name, 10, yes, force, dev_is_swap) ||
+ !_wipe_signature(dev, "LUKS signature", name, 8, yes, force, dev_is_luks))
+ return 0;
+
+ return 1;
+}
+
#ifdef __linux__
static int _snprintf_attr(char *buf, size_t buf_size, const char *sysfs_dir,
diff --git a/lib/device/dev-type.h b/lib/device/dev-type.h
index 2fa32db..895a172 100644
--- a/lib/device/dev-type.h
+++ b/lib/device/dev-type.h
@@ -16,6 +16,7 @@
#define _LVM_DEV_TYPE_H
#include "device.h"
+#include "display.h"
#define NUMBER_OF_MAJORS 4096
@@ -58,6 +59,9 @@ int dev_is_md(struct device *dev, uint64_t *sb);
int dev_is_swap(struct device *dev, uint64_t *signature);
int dev_is_luks(struct device *dev, uint64_t *signature);
+/* Signature wiping. */
+int wipe_known_signatures(struct device *dev, const char *name, int yes, force_t force);
+
/* Type-specific device properties */
unsigned long dev_md_stripe_width(struct dev_types *dt, struct device *dev);
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index c71ec30..f0230f1 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -1268,40 +1268,6 @@ int vg_split_mdas(struct cmd_context *cmd __attribute__((unused)),
return 1;
}
-static int _wipe_sb(struct device *dev, const char *type, const char *name,
- int wipe_len, struct pvcreate_params *pp,
- int (*func)(struct device *dev, uint64_t *signature))
-{
- int wipe;
- uint64_t superblock;
-
- wipe = func(dev, &superblock);
- if (wipe == -1) {
- log_error("Fatal error while trying to detect %s on %s.",
- type, name);
- return 0;
- }
-
- if (wipe == 0)
- return 1;
-
- /* Specifying --yes => do not ask. */
- if (!pp->yes && (pp->force == PROMPT) &&
- yes_no_prompt("WARNING: %s detected on %s. Wipe it? [y/n] ",
- type, name) != 'y') {
- log_error("Aborting pvcreate on %s.", name);
- return 0;
- }
-
- 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;
- }
-
- return 1;
-}
-
/*
* See if we may pvcreate on this device.
* 0 indicates we may not.
@@ -1364,14 +1330,10 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,
goto bad;
}
- if (!_wipe_sb(dev, "software RAID md superblock", name, 4, pp, dev_is_md))
- goto_bad;
-
- if (!_wipe_sb(dev, "swap signature", name, 10, pp, dev_is_swap))
- goto_bad;
-
- if (!_wipe_sb(dev, "LUKS signature", name, 8, pp, dev_is_luks))
- goto_bad;
+ if (!wipe_known_signatures(dev, name, pp->yes, pp->force)) {
+ log_error("Aborting pvcreate on %s.", name);
+ goto bad;
+ }
if (sigint_caught())
goto_bad;
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=120df5561088f4a5…
Commit: 120df5561088f4a5277716117339d9212b666214
Parent: d6e67b850365864bba91619a40503ff0b0392e2c
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Nov 27 08:53:26 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 08:53:26 2013 +0100
activation: change log_error to log_warn if refresh before autoactivation fails
---
tools/pvscan.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/pvscan.c b/tools/pvscan.c
index 981a9c2..4f99f45 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -148,7 +148,7 @@ static int _auto_activation_handler(struct cmd_context *cmd,
}
if (!refresh_done)
- log_error("%s: refresh before autoactivation failed.", vg->name);
+ log_warn("%s: refresh before autoactivation failed.", vg->name);
if (!vgchange_activate(vg->cmd, vg, activate)) {
log_error("%s: autoactivation failed.", vg->name);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d6e67b850365864b…
Commit: d6e67b850365864bba91619a40503ff0b0392e2c
Parent: 729b104413e11412866a549ef8a6702f56c4acd1
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Nov 27 08:33:02 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 08:33:02 2013 +0100
WHATS_NEW: commit 729b104
---
WHATS_NEW | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 4148754..7718b6f 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Do not fail the whole autoactivation if the VG refresh done before fails.
Do not connect to lvmetad on vg/lvchange --sysinit -aay and socket absent.
Use lv_check_not_in_use() when testing device in use before merging.
Move test for target present from init_snapshot_merge() to lvconvert.
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=729b104413e11412…
Commit: 729b104413e11412866a549ef8a6702f56c4acd1
Parent: 8d5cff5b9bb217942c009dca49d0bffb51e85004
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Nov 27 08:20:02 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 27 08:20:02 2013 +0100
activation: continue with autoactivation if refresh fails
If the refresh fails for any reason before autoactivation, let's not
make this a stopper for autoactivation itself - just log the error
message if it appears.
The reason is that in some rare situations, we can still hit the
problem with the suspend call to fail (as already described in
commit d8085edf65006a50608edb821b3d30947abaa838, also
https://bugzilla.redhat.com/show_bug.cgi?id=1027314 ) The refresh
itself is done for only one reason - to refresh any dm tables
for LVs for which the underlying PVs got unplugged/disconnected
and then plugged/connected back (see also
https://bugzilla.redhat.com/show_bug.cgi?id=954061 for more info).
In this case, the major:minor pair is changed and we need to
update dm tables for LVs accordingly.
Now if refresh fails, the error is still logged, but autoactivation
continues.
---
tools/pvscan.c | 4 +---
1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/tools/pvscan.c b/tools/pvscan.c
index ce8c446..981a9c2 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -147,10 +147,8 @@ static int _auto_activation_handler(struct cmd_context *cmd,
usleep(REFRESH_BEFORE_AUTOACTIVATION_RETRY_USLEEP_DELAY);
}
- if (!refresh_done) {
+ if (!refresh_done)
log_error("%s: refresh before autoactivation failed.", vg->name);
- goto out;
- }
if (!vgchange_activate(vg->cmd, vg, activate)) {
log_error("%s: autoactivation failed.", vg->name);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=8d5cff5b9bb21794…
Commit: 8d5cff5b9bb217942c009dca49d0bffb51e85004
Parent: 47110f7e27ce2a4bf329e860cf6eb339d107fde7
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Nov 26 14:51:23 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Nov 26 14:51:23 2013 +0100
lv/vgchange: do not try to connect to lvmetad if socket absent and --sysinit -aay used
If using lv/vgchange --sysinit -aay and lvmetad is enabled, we'd like to
avoid the direct activation and rely on autoactivation instead so
it fits system initialization scripts.
But if we're calling lv/vgchange --sysinit -aay too early when even
lvmetad service is not started yet, we just need to do the direct
activation instead without printing any error messages (while
trying to connect to lvmetad and not finding its socket).
This patch adds two helper functions - "lvmetad_socket_present" and
"lvmetad_used" which can be used to check for this condition properly
and avoid these lvmetad connections when the socket is not present
(and hence lvmetad is not yet running).
---
WHATS_NEW | 1 +
daemons/lvmetad/lvmetad-client.h | 4 +++-
daemons/lvmetad/lvmetad-core.c | 4 +++-
lib/cache/lvmetad.c | 16 ++++++++++++++++
lib/cache/lvmetad.h | 15 +++++++++++++++
tools/lvchange.c | 30 ++++++++++++++++++++++++++----
tools/vgchange.c | 30 ++++++++++++++++++++++++++----
7 files changed, 90 insertions(+), 10 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 9b18ef0..4148754 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Do not connect to lvmetad on vg/lvchange --sysinit -aay and socket absent.
Use lv_check_not_in_use() when testing device in use before merging.
Move test for target present from init_snapshot_merge() to lvconvert.
Check for failure of lvmcache_add_mda() when writing pv.
diff --git a/daemons/lvmetad/lvmetad-client.h b/daemons/lvmetad/lvmetad-client.h
index fe8eedc..8d6ae0e 100644
--- a/daemons/lvmetad/lvmetad-client.h
+++ b/daemons/lvmetad/lvmetad-client.h
@@ -17,6 +17,8 @@
#include "daemon-client.h"
+#define LVMETAD_SOCKET DEFAULT_RUN_DIR "/lvmetad.socket"
+
struct volume_group;
/* Different types of replies we may get from lvmetad. */
@@ -64,7 +66,7 @@ static inline daemon_handle lvmetad_open(const char *socket)
{
daemon_info lvmetad_info = {
.path = "lvmetad",
- .socket = socket ?: DEFAULT_RUN_DIR "/lvmetad.socket",
+ .socket = socket ?: LVMETAD_SOCKET,
.protocol = "lvmetad",
.protocol_version = 1,
.autostart = 0
diff --git a/daemons/lvmetad/lvmetad-core.c b/daemons/lvmetad/lvmetad-core.c
index 03d89c9..87374e8 100644
--- a/daemons/lvmetad/lvmetad-core.c
+++ b/daemons/lvmetad/lvmetad-core.c
@@ -29,6 +29,8 @@
#include <math.h> /* fabs() */
#include <float.h> /* DBL_EPSILON */
+#define LVMETAD_SOCKET DEFAULT_RUN_DIR "/lvmetad.socket"
+
typedef struct {
log_state *log; /* convenience */
const char *log_config;
@@ -1209,7 +1211,7 @@ int main(int argc, char *argv[])
if (!s.socket_path) {
_socket_override = 0;
- s.socket_path = DEFAULT_RUN_DIR "/lvmetad.socket";
+ s.socket_path = LVMETAD_SOCKET;
}
ls.log_config = "";
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c
index 5119ab1..1ead9f8 100644
--- a/lib/cache/lvmetad.c
+++ b/lib/cache/lvmetad.c
@@ -72,6 +72,22 @@ void lvmetad_connect_or_warn(void)
strerror(_lvmetad.error));
}
+int lvmetad_used(void)
+{
+ return _lvmetad_use;
+}
+
+int lvmetad_socket_present(void)
+{
+ const char *socket = _lvmetad_socket ?: LVMETAD_SOCKET;
+ int r;
+
+ if ((r = access(socket, F_OK)) && errno != ENOENT)
+ log_sys_error("lvmetad_socket_present", "");
+
+ return !r;
+}
+
int lvmetad_active(void)
{
if (!_lvmetad_use)
diff --git a/lib/cache/lvmetad.h b/lib/cache/lvmetad.h
index ff4cd0a..85b71c2 100644
--- a/lib/cache/lvmetad.h
+++ b/lib/cache/lvmetad.h
@@ -44,6 +44,19 @@ void lvmetad_set_active(int);
void lvmetad_set_socket(const char *);
/*
+ * Check whether lvmetad is used.
+ */
+int lvmetad_used(void);
+
+/*
+ * Check if lvmetad socket is present (either the one set by lvmetad_set_socket
+ * or the default one if not set). For example, this may be used before calling
+ * lvmetad_active() check that does connect to the socket - this would produce
+ * various connection errors if the socket is not present.
+ */
+int lvmetad_socket_present(void);
+
+/*
* Check whether lvmetad is active (where active means both that it is running
* and that we have a working connection with it).
*/
@@ -149,6 +162,8 @@ int lvmetad_pvscan_all_devs(struct cmd_context *cmd, activation_handler handler)
# define lvmetad_disconnect() do { } while (0)
# define lvmetad_set_active(a) do { } while (0)
# define lvmetad_set_socket(a) do { } while (0)
+# define lvmetad_used() (0)
+# define lvmetad_socket_present() (0)
# define lvmetad_active() (0)
# define lvmetad_connect_or_warn() do { } while (0)
# define lvmetad_set_token(a) do { } while (0)
diff --git a/tools/lvchange.c b/tools/lvchange.c
index 1931c03..897ffb2 100644
--- a/tools/lvchange.c
+++ b/tools/lvchange.c
@@ -1235,11 +1235,33 @@ int lvchange(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE;
}
- if (arg_count(cmd, sysinit_ARG) && lvmetad_active() &&
+ /*
+ * If --sysinit -aay is used and at the same time lvmetad is used,
+ * we want to rely on autoactivation to take place. Also, we
+ * need to take special care here as lvmetad service does
+ * not neet to be running at this moment yet - it could be
+ * just too early during system initialization time.
+ */
+ if (arg_count(cmd, sysinit_ARG) && lvmetad_used() &&
arg_uint_value(cmd, activate_ARG, 0) == CHANGE_AAY) {
- log_warn("lvmetad is active while using --sysinit -a ay, "
- "skipping manual activation");
- return ECMD_PROCESSED;
+ if (!lvmetad_socket_present()) {
+ /*
+ * If lvmetad socket is not present yet,
+ * the service is just not started. It'll
+ * be started a bit later so we need to do
+ * the activation without lvmetad which means
+ * direct activation instead of autoactivation.
+ */
+ log_warn("lvmetad is not active yet, using direct activation during sysinit");
+ lvmetad_set_active(0);
+ } else if (lvmetad_active()) {
+ /*
+ * If lvmetad is active already, we want
+ * to make use of the autoactivation.
+ */
+ log_warn("lvmetad is active, skipping direct activation during sysinit");
+ return ECMD_PROCESSED;
+ }
}
return process_each_lv(cmd, argc, argv,
diff --git a/tools/vgchange.c b/tools/vgchange.c
index 4087fab..b50b444 100644
--- a/tools/vgchange.c
+++ b/tools/vgchange.c
@@ -616,11 +616,33 @@ int vgchange(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE;
}
- if (arg_count(cmd, sysinit_ARG) && lvmetad_active() &&
+ /*
+ * If --sysinit -aay is used and at the same time lvmetad is used,
+ * we want to rely on autoactivation to take place. Also, we
+ * need to take special care here as lvmetad service does
+ * not neet to be running at this moment yet - it could be
+ * just too early during system initialization time.
+ */
+ if (arg_count(cmd, sysinit_ARG) && lvmetad_used() &&
arg_uint_value(cmd, activate_ARG, 0) == CHANGE_AAY) {
- log_warn("lvmetad is active while using --sysinit -a ay, "
- "skipping manual activation");
- return ECMD_PROCESSED;
+ if (!lvmetad_socket_present()) {
+ /*
+ * If lvmetad socket is not present yet,
+ * the service is just not started. It'll
+ * be started a bit later so we need to do
+ * the activation without lvmetad which means
+ * direct activation instead of autoactivation.
+ */
+ log_warn("lvmetad is not active yet, using direct activation during sysinit");
+ lvmetad_set_active(0);
+ } else if (lvmetad_active()) {
+ /*
+ * If lvmetad is active already, we want
+ * to make use of the autoactivation.
+ */
+ log_warn("lvmetad is active, skipping direct activation during sysinit");
+ return ECMD_PROCESSED;
+ }
}
if (arg_count(cmd, clustered_ARG) && !argc && !arg_count(cmd, yes_ARG) &&
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=47110f7e27ce2a4b…
Commit: 47110f7e27ce2a4bf329e860cf6eb339d107fde7
Parent: b8f72c0f2c41fa76bdd3f4c0d73cf31dc9ce9b88
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Nov 21 10:41:08 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 21:00:56 2013 +0100
tests: add WARNED test to final list
WARNED result should not be forgotten - it's supposed
to be fixed...
keep enum alphabetically sorted
---
test/lib/harness.c | 25 ++++++++++++++-----------
1 files changed, 14 insertions(+), 11 deletions(-)
diff --git a/test/lib/harness.c b/test/lib/harness.c
index 8c9f4a7..dca0198 100644
--- a/test/lib/harness.c
+++ b/test/lib/harness.c
@@ -65,13 +65,13 @@ static struct subst subst[2];
enum {
UNKNOWN,
- PASSED,
- SKIPPED,
FAILED,
- WARNED,
- KNOWNFAIL,
INTERRUPTED,
+ KNOWNFAIL,
+ PASSED,
+ SKIPPED,
TIMEOUT,
+ WARNED,
};
static void handler( int sig ) {
@@ -511,12 +511,12 @@ int main(int argc, char **argv) {
if ((list = fopen(results_list, "w"))) {
for (i = 1; i < argc; ++ i) {
switch (s.status[i]) {
- case PASSED: result = "passed"; break;
case FAILED: result = "failed"; break;
+ case INTERRUPTED: result = "interrupted"; break;
+ case PASSED: result = "passed"; break;
case SKIPPED: result = "skipped"; break;
- case WARNED: result = "warnings"; break;
case TIMEOUT: result = "timeout"; break;
- case INTERRUPTED: result = "interrupted"; break;
+ case WARNED: result = "warnings"; break;
default: result = "unknown"; break;
}
fprintf(list, "%s %s\n", argv[i], result);
@@ -526,24 +526,27 @@ int main(int argc, char **argv) {
perror("fopen result");
/* print out a summary */
- if (s.nfailed || s.nskipped || s.nknownfail || s.ninterrupted) {
+ if (s.nfailed || s.nskipped || s.nknownfail || s.ninterrupted || s.nwarned) {
for (i = 1; i < argc; ++ i) {
switch (s.status[i]) {
case FAILED:
printf("FAILED: %s\n", argv[i]);
break;
+ case INTERRUPTED:
+ printf("INTERRUPTED: %s\n", argv[i]);
+ break;
case KNOWNFAIL:
printf("FAILED (expected): %s\n", argv[i]);
break;
case SKIPPED:
printf("skipped: %s\n", argv[i]);
break;
- case INTERRUPTED:
- printf("INTERRUPTED: %s\n", argv[i]);
- break;
case TIMEOUT:
printf("TIMEOUT: %s\n", argv[i]);
break;
+ case WARNED:
+ printf("WARNED: %s\n", argv[i]);
+ break;
default: /* do nothing */ ;
}
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b8f72c0f2c41fa76…
Commit: b8f72c0f2c41fa76bdd3f4c0d73cf31dc9ce9b88
Parent: 62db5c1e48467ef846432652dd1058eb85c0bcbd
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 20:43:30 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 21:00:56 2013 +0100
cleanup: use const format
---
lib/label/label.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/label/label.h b/lib/label/label.h
index 103e799..253e1e8 100644
--- a/lib/label/label.h
+++ b/lib/label/label.h
@@ -88,7 +88,7 @@ struct label_ops {
struct labeller {
struct label_ops *ops;
- struct format_type *fmt;
+ const struct format_type *fmt;
};
int label_init(void);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=62db5c1e48467ef8…
Commit: 62db5c1e48467ef846432652dd1058eb85c0bcbd
Parent: 6ebbf1982892a819dc14045a8dca0ad512cebdf8
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 20:42:03 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 21:00:56 2013 +0100
cleanup: make gcc happier with initializers
Whole struct will be set to 0, just
if the first member is array, gcc gives warning
we should initialized this element as array,
so pick any later simple type.
---
tools/reporter.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/reporter.c b/tools/reporter.c
index dccd785..bf181e7 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -141,8 +141,8 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
struct volume_group *old_vg = vg;
char uuid[64] __attribute__((aligned(8)));
struct label *label;
- struct label _dummy_label = { 0 };
- struct device _dummy_device = { 0 };
+ struct label _dummy_label = { .dev = 0 };
+ struct device _dummy_device = { .dev = 0 };
if (is_pv(pv) && !is_orphan(pv) && !vg) {
vg_name = pv_vg_name(pv);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6ebbf1982892a819…
Commit: 6ebbf1982892a819dc14045a8dca0ad512cebdf8
Parent: 07d766d270f764e3a8300fee79ac559d18f21e66
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 10:04:13 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 21:00:56 2013 +0100
cleanup: drop unused header
Header is not used here.
---
liblvm/lvm_base.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/liblvm/lvm_base.c b/liblvm/lvm_base.c
index d694173..80a4894 100644
--- a/liblvm/lvm_base.c
+++ b/liblvm/lvm_base.c
@@ -18,7 +18,6 @@
#include "lvm-version.h"
#include "metadata-exported.h"
#include "lvm2app.h"
-#include "lvm-string.h"
const char *lvm_library_get_version(void)
{
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=07d766d270f764e3…
Commit: 07d766d270f764e3a8300fee79ac559d18f21e66
Parent: 3e0fb102dece1a4d476496c3b6291e319b6305be
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 13:24:53 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 21:00:55 2013 +0100
cleanup: use string directly
---
lib/misc/lvm-wrappers.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/lib/misc/lvm-wrappers.c b/lib/misc/lvm-wrappers.c
index a96cd98..46590b9 100644
--- a/lib/misc/lvm-wrappers.c
+++ b/lib/misc/lvm-wrappers.c
@@ -18,7 +18,6 @@
#include <fcntl.h>
#ifdef UDEV_SYNC_SUPPORT
-static const char _no_context_msg[] = "Udev library context not set.";
struct udev *_udev;
int udev_init_library_context(void)
@@ -46,7 +45,7 @@ int udev_is_running(void)
int r;
if (!_udev) {
- log_debug_activation(_no_context_msg);
+ log_debug_activation("Udev library context not set.");
goto bad;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3e0fb102dece1a4d…
Commit: 3e0fb102dece1a4d476496c3b6291e319b6305be
Parent: bea118a87cd6cf7c63ccaa0d75691de1f73602ab
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 13:23:31 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 21:00:55 2013 +0100
cleanup: simplify pv uuid display
Shorter code with explicit type casting.
---
lib/report/report.c | 15 +++++----------
1 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/lib/report/report.c b/lib/report/report.c
index 20eab4f..2d39cb0 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -728,18 +728,13 @@ static int _pvuuid_disp(struct dm_report *rh __attribute__((unused)), struct dm_
const void *data, void *private __attribute__((unused)))
{
const struct label *label = (const struct label *) data;
- char *repstr = NULL;
+ const char *repstr = "";
- if (!label->dev)
- dm_report_field_set_value(field, "", NULL);
- else {
- if (!(repstr = id_format_and_copy(mem, label->dev->pvid)))
- return_0;
-
- dm_report_field_set_value(field, repstr, NULL);
- }
+ if (label->dev &&
+ !(repstr = id_format_and_copy(mem, (const struct id *) label->dev->pvid)))
+ return_0;
- return 1;
+ return _field_set_value(field, repstr, NULL);
}
static int _pvmdas_disp(struct dm_report *rh, struct dm_pool *mem,
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=bea118a87cd6cf7c…
Commit: bea118a87cd6cf7c63ccaa0d75691de1f73602ab
Parent: 19cc92230cd855d08e0a8787687c8dba9cd8d627
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 13:18:02 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 21:00:55 2013 +0100
cleanup: use safe iterator
Simplify code and use dm_list_iterate_items_safe() and avoid
scanning the list mutliple times.
Use dm_list_move().
---
lib/metadata/metadata.c | 16 +++++++---------
1 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 53d7e5e..c71ec30 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -2809,7 +2809,7 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd,
struct lvmcache_vginfo *vginfo;
struct volume_group *vg = NULL;
struct _vg_read_orphan_baton baton;
- struct pv_list *pvl, *pvl_;
+ struct pv_list *pvl, *tpvl;
struct pv_list head;
dm_list_init(&head.list);
@@ -2823,15 +2823,13 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd,
return_NULL;
vg = fmt->orphan_vg;
-restart:
- dm_list_iterate_items(pvl, &vg->pvs) {
- if (pvl->pv->status & UNLABELLED_PV ) {
- dm_list_del(&pvl->list);
- dm_list_add(&head.list, &pvl->list);
- goto restart;
- } else
+
+ dm_list_iterate_items_safe(pvl, tpvl, &vg->pvs)
+ if (pvl->pv->status & UNLABELLED_PV )
+ dm_list_move(&head.list, &pvl->list);
+ else
pv_set_fid(pvl->pv, NULL);
- }
+
dm_list_init(&vg->pvs);
vg->pv_count = 0;
vg->extent_count = 0;
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=19cc92230cd855d0…
Commit: 19cc92230cd855d08e0a8787687c8dba9cd8d627
Parent: 879ea38c53f81ab22225fb368e8787144517d963
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 13:15:47 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 21:00:55 2013 +0100
cleanup: use trigraph
Shorter code...
---
lib/metadata/lv_manip.c | 6 ++----
1 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index e22aaa2..491accd 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -3822,10 +3822,8 @@ static int _lvresize_adjust_extents(struct cmd_context *cmd, struct logical_volu
lv->status |= LV_NOTSYNCED;
dm_list_iterate_back_items(mirr_seg, &lv->segments) {
- if (seg_is_mirrored(mirr_seg))
- seg_mirrors = lv_mirror_count(mirr_seg->lv);
- else
- seg_mirrors = 0;
+ seg_mirrors = seg_is_mirrored(mirr_seg) ?
+ lv_mirror_count(mirr_seg->lv) : 0;
break;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=879ea38c53f81ab2…
Commit: 879ea38c53f81ab22225fb368e8787144517d963
Parent: 1ff53bb7b682a13e32d986e53a40eeb8fb5e47c4
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 10:01:52 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 21:00:55 2013 +0100
dmeventd: drop duplicated code
Do not call pthread_attr_init() twice.
The second call has all proper tests.
---
daemons/dmeventd/dmeventd.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index e9fc59b..189d1b6 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -273,7 +273,6 @@ static int _pthread_create_smallstack(pthread_t *t, void *(*fun)(void *), void *
int r;
pthread_t tmp;
pthread_attr_t attr;
- pthread_attr_init(&attr);
/*
* From pthread_attr_init man page:
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=1ff53bb7b682a13e…
Commit: 1ff53bb7b682a13e32d986e53a40eeb8fb5e47c4
Parent: 30c127eaf8561c9fc4b0aecace2991d3551a5dd3
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 18:19:13 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 21:00:55 2013 +0100
snapshot: code move
Move some code lines in front, they will be shared with thin snapshot
merge later.
---
lib/metadata/snapshot_manip.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/metadata/snapshot_manip.c b/lib/metadata/snapshot_manip.c
index c491918..3e90f3e 100644
--- a/lib/metadata/snapshot_manip.c
+++ b/lib/metadata/snapshot_manip.c
@@ -154,6 +154,10 @@ void init_snapshot_seg(struct lv_segment *seg, struct logical_volume *origin,
void init_snapshot_merge(struct lv_segment *snap_seg,
struct logical_volume *origin)
{
+ snap_seg->status |= MERGING;
+ origin->snapshot = snap_seg;
+ origin->status |= MERGING;
+
/*
* Even though lv_is_visible(snap_seg->lv) returns 0,
* the snap_seg->lv (name: snapshotX) is _not_ hidden;
@@ -165,9 +169,6 @@ void init_snapshot_merge(struct lv_segment *snap_seg,
* merge metadata (snap_seg->lv is now "internal")
*/
snap_seg->lv->status &= ~VISIBLE_LV;
- snap_seg->status |= MERGING;
- origin->snapshot = snap_seg;
- origin->status |= MERGING;
}
void clear_snapshot_merge(struct logical_volume *origin)
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=30c127eaf8561c9f…
Commit: 30c127eaf8561c9fc4b0aecace2991d3551a5dd3
Parent: b4fc397de6a456efb8b8cce1e7d0048d4573f7cc
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 20:44:25 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 21:00:55 2013 +0100
fix missing header
---
lib/metadata/pv_manip.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/lib/metadata/pv_manip.c b/lib/metadata/pv_manip.c
index bee7972..d0c3b44 100644
--- a/lib/metadata/pv_manip.c
+++ b/lib/metadata/pv_manip.c
@@ -19,6 +19,7 @@
#include "toolcontext.h"
#include "locking.h"
#include "defaults.h"
+#include "lvmcache.h"
#include "lvmetad.h"
#include "display.h"
#include "label.h"
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b4fc397de6a456ef…
Commit: b4fc397de6a456efb8b8cce1e7d0048d4573f7cc
Parent: 782a356e7cce8d0d32850677cdb5a9b28996471e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 13:16:12 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 21:00:55 2013 +0100
do_flock: mark descriptor as closed
Keep the structure content valid in error path
and mark descriptor as closed (-1).
---
lib/locking/file_locking.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/lib/locking/file_locking.c b/lib/locking/file_locking.c
index ab3dabd..3fa0a2d 100644
--- a/lib/locking/file_locking.c
+++ b/lib/locking/file_locking.c
@@ -163,6 +163,7 @@ static int _do_flock(const char *file, int *fd, int operation, uint32_t nonblock
log_sys_error("flock", file);
if (close(*fd))
log_sys_error("close", file);
+ *fd = -1;
return 0;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=782a356e7cce8d0d…
Commit: 782a356e7cce8d0d32850677cdb5a9b28996471e
Parent: d079c81ab49648fc5506490e34e16244c20fa45f
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 13:12:35 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 21:00:54 2013 +0100
archiver: add check for dm_pool_strdup
It will likely not fail to duplicate empty string, but
just keep the test of result of this function consistent.
Also on error path restore extent_size if in some
case someone would still use that variable.
---
lib/format_text/archiver.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/lib/format_text/archiver.c b/lib/format_text/archiver.c
index f41bffc..c1fe3f5 100644
--- a/lib/format_text/archiver.c
+++ b/lib/format_text/archiver.c
@@ -334,13 +334,17 @@ int backup_restore_vg(struct cmd_context *cmd, struct volume_group *vg, int drop
* Setting vg->old_name to a blank value will explicitly
* disable any attempt to check VG name in existing metadata.
*/
- vg->old_name = dm_pool_strdup(vg->vgmem, "");
+ if (!(vg->old_name = dm_pool_strdup(vg->vgmem, ""))) {
+ log_error("Failed to duplicate empty name.");
+ return 0;
+ }
/* Add any metadata areas on the PVs */
dm_list_iterate_items(pvl, &vg->pvs) {
tmp = vg->extent_size;
vg->extent_size = 0;
if (!vg->fid->fmt->ops->pv_setup(vg->fid->fmt, pvl->pv, vg)) {
+ vg->extent_size = tmp;
log_error("Format-specific setup for %s failed",
pv_dev_name(pvl->pv));
return 0;
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d079c81ab49648fc…
Commit: d079c81ab49648fc5506490e34e16244c20fa45f
Parent: 6fa95d17ee85ffd77d4dc90b23cdd024f65c279c
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 12:57:35 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 21:00:54 2013 +0100
dev-type: use text format as direct arg for printf
Put common printf() case into a function and use
the string with text format as direct arg to make
the compile time validation of args easier and
code shorter.
Switch log_error() to log_warn(), since 'return 0'
doesn't cause any failure here.
---
lib/device/dev-type.c | 33 +++++++++++++++++++--------------
1 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c
index a98cf45..f3f29b2 100644
--- a/lib/device/dev-type.c
+++ b/lib/device/dev-type.c
@@ -445,13 +445,25 @@ out:
#ifdef __linux__
+static int _snprintf_attr(char *buf, size_t buf_size, const char *sysfs_dir,
+ const char *attribute, dev_t dev)
+{
+ if (dm_snprintf(buf, buf_size, "%s/dev/block/%d:%d/%s", sysfs_dir,
+ (int)MAJOR(dev), (int)MINOR(dev),
+ attribute) < 0) {
+ log_warn("dm_snprintf %s failed.", attribute);
+ return 0;
+ }
+
+ return 1;
+}
+
static unsigned long _dev_topology_attribute(struct dev_types *dt,
const char *attribute,
struct device *dev)
{
const char *sysfs_dir = dm_sysfs_dir();
- static const char sysfs_fmt_str[] = "%s/dev/block/%d:%d/%s";
- char path[PATH_MAX+1], buffer[64];
+ char path[PATH_MAX], buffer[64];
FILE *fp;
struct stat info;
dev_t uninitialized_var(primary);
@@ -463,12 +475,8 @@ static unsigned long _dev_topology_attribute(struct dev_types *dt,
if (!sysfs_dir || !*sysfs_dir)
return_0;
- if (dm_snprintf(path, PATH_MAX, sysfs_fmt_str, sysfs_dir,
- (int)MAJOR(dev->dev), (int)MINOR(dev->dev),
- attribute) < 0) {
- log_error("dm_snprintf %s failed", attribute);
- return 0;
- }
+ if (!_snprintf_attr(path, sizeof(path), sysfs_dir, attribute, dev->dev))
+ return_0;
/*
* check if the desired sysfs attribute exists
@@ -484,12 +492,9 @@ static unsigned long _dev_topology_attribute(struct dev_types *dt,
return 0;
/* get attribute from partition's primary device */
- if (dm_snprintf(path, PATH_MAX, sysfs_fmt_str, sysfs_dir,
- (int)MAJOR(primary), (int)MINOR(primary),
- attribute) < 0) {
- log_error("primary dm_snprintf %s failed", attribute);
- return 0;
- }
+ if (!_snprintf_attr(path, sizeof(path), sysfs_dir, attribute, primary))
+ return_0;
+
if (stat(path, &info) == -1) {
if (errno != ENOENT)
log_sys_error("stat", path);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6fa95d17ee85ffd7…
Commit: 6fa95d17ee85ffd77d4dc90b23cdd024f65c279c
Parent: 069fa6c49d85f677320ccb1965ef2e59b6829303
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 12:54:59 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 21:00:51 2013 +0100
dmeventd: move format text to printf
Instead of passing argument with format string to printf(),
put the string as arg directly.
Also move there remains args to make the code shorter.
---
WHATS_NEW_DM | 1 +
daemons/dmeventd/dmeventd.c | 12 +++++-------
daemons/dmeventd/libdevmapper-event.c | 16 ++++++++--------
3 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 24d53af..564419f 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.84 -
====================================
+ Move printf format string directly into dm_asprintf args list.
Catch invalid use of string sort values when reporting numerical fields.
Version 1.02.83 - 13th November 2013
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index bdaf552..e9fc59b 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -1110,20 +1110,18 @@ static int _unregister_for_event(struct message_data *message_data)
static int _registered_device(struct message_data *message_data,
struct thread_status *thread)
{
- struct dm_event_daemon_message *msg = message_data->msg;
-
- const char *fmt = "%s %s %s %u";
- const char *id = message_data->id;
- const char *dso = thread->dso_data->dso_name;
- const char *dev = thread->device.uuid;
int r;
+ struct dm_event_daemon_message *msg = message_data->msg;
unsigned events = ((thread->status == DM_THREAD_RUNNING) &&
thread->events) ? thread->events :
thread->events | DM_EVENT_REGISTRATION_PENDING;
dm_free(msg->data);
- if ((r = dm_asprintf(&(msg->data), fmt, id, dso, dev, events)) < 0) {
+ if ((r = dm_asprintf(&(msg->data), "%s %s %s %u",
+ message_data->id,
+ thread->dso_data->dso_name,
+ thread->device.uuid, events)) < 0) {
msg->size = 0;
return -ENOMEM;
}
diff --git a/daemons/dmeventd/libdevmapper-event.c b/daemons/dmeventd/libdevmapper-event.c
index 72f0f92..92e9c1d 100644
--- a/daemons/dmeventd/libdevmapper-event.c
+++ b/daemons/dmeventd/libdevmapper-event.c
@@ -345,9 +345,6 @@ int daemon_talk(struct dm_event_fifos *fifos,
const char *dso_name, const char *dev_name,
enum dm_event_mask evmask, uint32_t timeout)
{
- const char *dso = dso_name ? dso_name : "-";
- const char *dev = dev_name ? dev_name : "-";
- const char *fmt = "%d:%d %s %s %u %" PRIu32;
int msg_size;
memset(msg, 0, sizeof(*msg));
@@ -355,14 +352,17 @@ int daemon_talk(struct dm_event_fifos *fifos,
* Set command and pack the arguments
* into ASCII message string.
*/
- msg->cmd = cmd;
- if (cmd == DM_EVENT_CMD_HELLO)
- fmt = "%d:%d HELLO";
- if ((msg_size = dm_asprintf(&(msg->data), fmt, getpid(), _sequence_nr,
- dso, dev, evmask, timeout)) < 0) {
+ if ((msg_size =
+ ((cmd == DM_EVENT_CMD_HELLO) ?
+ dm_asprintf(&(msg->data), "%d:%d HELLO", getpid(), _sequence_nr) :
+ dm_asprintf(&(msg->data), "%d:%d %s %s %u %" PRIu32,
+ getpid(), _sequence_nr,
+ dso_name ? : "-", dev_name ? : "-", evmask, timeout)))
+ < 0) {
log_error("_daemon_talk: message allocation failed");
return -ENOMEM;
}
+ msg->cmd = cmd;
msg->size = msg_size;
/*
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=069fa6c49d85f677…
Commit: 069fa6c49d85f677320ccb1965ef2e59b6829303
Parent: 4a061a35c7523d0a1657a52fc179b520d6bcf4d2
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 10:00:00 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 20:58:13 2013 +0100
activate: modify read_only when dev_manager exists
Change opts only when dm has been successfully created.
So on the error path we leave structure unmodified.
---
lib/activate/activate.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index 0597409..44dfeb6 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -1097,11 +1097,11 @@ static int _lv_preload(struct logical_volume *lv, struct lv_activate_opts *laopt
struct dev_manager *dm;
int old_readonly = laopts->read_only;
- laopts->read_only = _passes_readonly_filter(lv->vg->cmd, lv);
-
if (!(dm = dev_manager_create(lv->vg->cmd, lv->vg->name, (lv->status & PVMOVE) ? 0 : 1)))
goto_out;
+ laopts->read_only = _passes_readonly_filter(lv->vg->cmd, lv);
+
if (!(r = dev_manager_preload(dm, lv, laopts, flush_required)))
stack;
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=4a061a35c7523d0a…
Commit: 4a061a35c7523d0a1657a52fc179b520d6bcf4d2
Parent: 6d196410fc071cfe15638bbde0b3ac8bbbf4be53
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 15:27:47 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 20:58:11 2013 +0100
snapshot: use lv_check_not_in_use
Instead of plain open_count check, try to use 'smarter'
lv_check_not_in_use() function.
---
WHATS_NEW | 1 +
tools/lvconvert.c | 19 ++++++++-----------
2 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 119463b..9b18ef0 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Use lv_check_not_in_use() when testing device in use before merging.
Move test for target present from init_snapshot_merge() to lvconvert.
Check for failure of lvmcache_add_mda() when writing pv.
Check for failure of dev_get_size() when reporting device size.
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 6a7281b..a15bd75 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -1906,17 +1906,14 @@ static int lvconvert_merge(struct cmd_context *cmd,
* constructor and DM should prevent appropriate devices from
* being open.
*/
- if (lv_info(cmd, origin, 0, &info, 1, 0)) {
- if (info.open_count) {
- log_error("Can't merge over open origin volume");
- merge_on_activate = 1;
- }
- }
- if (lv_info(cmd, lv, 0, &info, 1, 0)) {
- if (info.open_count) {
- log_print_unless_silent("Can't merge when snapshot is open");
- merge_on_activate = 1;
- }
+ if (lv_info(cmd, origin, 0, &info, 1, 0) &&
+ !lv_check_not_in_use(cmd, origin, &info)) {
+ log_print_unless_silent("Can't merge over open origin volume.");
+ merge_on_activate = 1;
+ } else if (lv_info(cmd, lv, 0, &info, 1, 0) &&
+ !lv_check_not_in_use(cmd, lv, &info)) {
+ log_print_unless_silent("Can't merge when snapshot is open.");
+ merge_on_activate = 1;
}
init_snapshot_merge(snap_seg, origin);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6d196410fc071cfe…
Commit: 6d196410fc071cfe15638bbde0b3ac8bbbf4be53
Parent: 3d3b8bfd1c7cc22383580b2723415ddcf9fbe7d7
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 14:52:35 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 20:57:30 2013 +0100
snapshot: revert and move check to lvconvert
Revert 4777eb68728859a0b3651e29c628111ed7c99103 which put
target_present check into init_snapshot_merge(). However
this function is also used when parsing metadata. So we would
get this present test performed even when target is not really
needed. So move this target_present test directly into lvconvert.
---
WHATS_NEW | 1 +
lib/metadata/metadata-exported.h | 2 +-
lib/metadata/snapshot_manip.c | 12 ++----------
tools/lvconvert.c | 8 ++++++--
4 files changed, 10 insertions(+), 13 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 41251b8..119463b 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Move test for target present from init_snapshot_merge() to lvconvert.
Check for failure of lvmcache_add_mda() when writing pv.
Check for failure of dev_get_size() when reporting device size.
Drop extra unneeded '/' when scanning sysfs directory.
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index ed1ec8d..33c534f 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -880,7 +880,7 @@ struct logical_volume *origin_from_cow(const struct logical_volume *lv);
void init_snapshot_seg(struct lv_segment *seg, struct logical_volume *origin,
struct logical_volume *cow, uint32_t chunk_size, int merge);
-int init_snapshot_merge(struct lv_segment *snap_seg, struct logical_volume *origin);
+void init_snapshot_merge(struct lv_segment *snap_seg, struct logical_volume *origin);
void clear_snapshot_merge(struct logical_volume *origin);
diff --git a/lib/metadata/snapshot_manip.c b/lib/metadata/snapshot_manip.c
index fc1273e..c491918 100644
--- a/lib/metadata/snapshot_manip.c
+++ b/lib/metadata/snapshot_manip.c
@@ -19,7 +19,6 @@
#include "toolcontext.h"
#include "lv_alloc.h"
#include "activate.h"
-#include "segtype.h"
int lv_is_origin(const struct logical_volume *lv)
{
@@ -152,8 +151,8 @@ void init_snapshot_seg(struct lv_segment *seg, struct logical_volume *origin,
dm_list_add(&origin->snapshot_segs, &seg->origin_list);
}
-int init_snapshot_merge(struct lv_segment *snap_seg,
- struct logical_volume *origin)
+void init_snapshot_merge(struct lv_segment *snap_seg,
+ struct logical_volume *origin)
{
/*
* Even though lv_is_visible(snap_seg->lv) returns 0,
@@ -169,13 +168,6 @@ int init_snapshot_merge(struct lv_segment *snap_seg,
snap_seg->status |= MERGING;
origin->snapshot = snap_seg;
origin->status |= MERGING;
-
- if (snap_seg->segtype->ops->target_present &&
- !snap_seg->segtype->ops->target_present(snap_seg->lv->vg->cmd,
- snap_seg, NULL))
- return 0;
-
- return 1;
}
void clear_snapshot_merge(struct logical_volume *origin)
diff --git a/tools/lvconvert.c b/tools/lvconvert.c
index 92a2022..6a7281b 100644
--- a/tools/lvconvert.c
+++ b/tools/lvconvert.c
@@ -1919,10 +1919,14 @@ static int lvconvert_merge(struct cmd_context *cmd,
}
}
- if (!init_snapshot_merge(snap_seg, origin)) {
+ init_snapshot_merge(snap_seg, origin);
+
+ if (snap_seg->segtype->ops->target_present &&
+ !snap_seg->segtype->ops->target_present(snap_seg->lv->vg->cmd,
+ snap_seg, NULL)) {
log_error("Can't initialize snapshot merge. "
"Missing support in kernel?");
- return_0;
+ return 0;
}
/* store vg on disk(s) */
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3d3b8bfd1c7cc223…
Commit: 3d3b8bfd1c7cc22383580b2723415ddcf9fbe7d7
Parent: a50a297f6e75d650abe9fe084b499a7968cc59ee
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 13:25:27 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 20:55:09 2013 +0100
pv_write: check for lvmcache_add_mda failure
Add missing test of failing lvmcache_add_mda() call.
---
WHATS_NEW | 1 +
lib/format_text/format-text.c | 6 ++++--
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 99f9067..41251b8 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Check for failure of lvmcache_add_mda() when writing pv.
Check for failure of dev_get_size() when reporting device size.
Drop extra unneeded '/' when scanning sysfs directory.
Fix undef value if skipped clustered VG ignored for toollib PV seg. (2.02.103)
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index e67d24d..275d16f 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -1328,8 +1328,10 @@ static int _text_pv_write(const struct format_type *fmt, struct physical_volume
mdac->area.size >> SECTOR_SHIFT);
// if fmt is not the same as info->fmt we are in trouble
- lvmcache_add_mda(info, mdac->area.dev,
- mdac->area.start, mdac->area.size, mda_is_ignored(mda));
+ if (!lvmcache_add_mda(info, mdac->area.dev,
+ mdac->area.start, mdac->area.size,
+ mda_is_ignored(mda)))
+ return_0;
}
if (!lvmcache_update_bas(info, pv))
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a50a297f6e75d650…
Commit: a50a297f6e75d650abe9fe084b499a7968cc59ee
Parent: 08d6d81cc24a3c3b780fe25ed49aefc9a9b61586
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 22 13:21:52 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 20:54:16 2013 +0100
report: detect dev_get_size failure
Since dev_get_size() may fail, detect this failure.
---
WHATS_NEW | 1 +
lib/report/report.c | 7 +++++--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index b7a1e84..99f9067 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Check for failure of dev_get_size() when reporting device size.
Drop extra unneeded '/' when scanning sysfs directory.
Fix undef value if skipped clustered VG ignored for toollib PV seg. (2.02.103)
liblvm/python API Add ability to validate VG/LV names.
diff --git a/lib/report/report.c b/lib/report/report.c
index 9cb2298..20eab4f 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -693,8 +693,11 @@ static int _devsize_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
{
- uint64_t size = 0;
- dev_get_size(*(const struct device **) data, &size);
+ uint64_t size;
+
+ if (!dev_get_size(*(const struct device **) data, &size))
+ return_0;
+
return _size64_disp(rh, mem, field, &size, private);
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=08d6d81cc24a3c3b…
Commit: 08d6d81cc24a3c3b780fe25ed49aefc9a9b61586
Parent: 4c1f281b43175e69a73fcc59a9142fd374e8b70c
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Nov 21 17:50:12 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 22 20:53:31 2013 +0100
filters: drop extra slash from sysfs path
Sysfs filter was using '/sys//class/block' with double '//' inside.
Remove this extra '/'.
Also simplify code around and use loop to try those paths.
---
WHATS_NEW | 1 +
lib/filters/filter-sysfs.c | 109 +++++++++++++++++++++----------------------
2 files changed, 54 insertions(+), 56 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 647c810..b7a1e84 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Drop extra unneeded '/' when scanning sysfs directory.
Fix undef value if skipped clustered VG ignored for toollib PV seg. (2.02.103)
liblvm/python API Add ability to validate VG/LV names.
liblvm/python API Add ability to create PV with arguments.
diff --git a/lib/filters/filter-sysfs.c b/lib/filters/filter-sysfs.c
index af3ed07..ff94810 100644
--- a/lib/filters/filter-sysfs.c
+++ b/lib/filters/filter-sysfs.c
@@ -23,64 +23,61 @@ static int _locate_sysfs_blocks(const char *sysfs_dir, char *path, size_t len,
unsigned *sysfs_depth)
{
struct stat info;
-
- /*
- * unified classification directory for all kernel subsystems
- *
- * /sys/subsystem/block/devices
- * |-- sda -> ../../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
- * |-- sda1 -> ../../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1
- * `-- sr0 -> ../../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0
- *
- */
- if (dm_snprintf(path, len, "%s/%s", sysfs_dir,
- "subsystem/block/devices") >= 0) {
- if (!stat(path, &info)) {
- *sysfs_depth = 0;
- return 1;
- }
- }
-
- /*
- * block subsystem as a class
- *
- * /sys/class/block
- * |-- sda -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
- * |-- sda1 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1
- * `-- sr0 -> ../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0
- *
- */
- if (dm_snprintf(path, len, "%s/%s", sysfs_dir, "class/block") >= 0) {
- if (!stat(path, &info)) {
- *sysfs_depth = 0;
+ unsigned i;
+ static const struct dir_class {
+ const char path[32];
+ int depth;
+ } classes[] = {
+ /*
+ * unified classification directory for all kernel subsystems
+ *
+ * /sys/subsystem/block/devices
+ * |-- sda -> ../../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
+ * |-- sda1 -> ../../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1
+ * `-- sr0 -> ../../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0
+ *
+ */
+ { "subsystem/block/devices", 0 },
+
+ /*
+ * block subsystem as a class
+ *
+ * /sys/class/block
+ * |-- sda -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
+ * |-- sda1 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1
+ * `-- sr0 -> ../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0
+ *
+ */
+ { "class/block", 0 },
+
+ /*
+ * old block subsystem layout with nested directories
+ *
+ * /sys/block/
+ * |-- sda
+ * | |-- capability
+ * | |-- dev
+ * ...
+ * | |-- sda1
+ * | | |-- dev
+ * ...
+ * |
+ * `-- sr0
+ * |-- capability
+ * |-- dev
+ * ...
+ *
+ */
+
+ { "block", 1 }
+ };
+
+ for (i = 0; i < DM_ARRAY_SIZE(classes); ++i)
+ if ((dm_snprintf(path, len, "%s%s", sysfs_dir, classes[i].path) >= 0) &&
+ (stat(path, &info) == 0)) {
+ *sysfs_depth = classes[i].depth;
return 1;
}
- }
-
- /*
- * old block subsystem layout with nested directories
- *
- * /sys/block/
- * |-- sda
- * | |-- capability
- * | |-- dev
- * ...
- * | |-- sda1
- * | | |-- dev
- * ...
- * |
- * `-- sr0
- * |-- capability
- * |-- dev
- * ...
- *
- */
- if (dm_snprintf(path, len, "%s/%s", sysfs_dir, "block") >= 0) {
- if (!stat(path, &info)) {
- *sysfs_depth = 1;
- return 1;
- }
- }
return 0;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=4c1f281b43175e69…
Commit: 4c1f281b43175e69a73fcc59a9142fd374e8b70c
Parent: 7c8abb29df2e8cc22c43f67117486e4e717110dd
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Fri Nov 22 18:11:04 2013 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Fri Nov 22 18:11:04 2013 +0000
toollib: Avoid undefined ignore_vg parameter.
Fix process_each_segment_in_pv to always set ret before calling ignore_vg().
---
WHATS_NEW | 1 +
tools/toollib.c | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index e47f0e5..647c810 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Fix undef value if skipped clustered VG ignored for toollib PV seg. (2.02.103)
liblvm/python API Add ability to validate VG/LV names.
liblvm/python API Add ability to create PV with arguments.
liblvm/python API Fail VG reduce when insufficient metadata copies
diff --git a/tools/toollib.c b/tools/toollib.c
index b3bfd1d..90a7cb8 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -510,10 +510,10 @@ int process_each_segment_in_pv(struct cmd_context *cmd,
vg_name = pv_vg_name(pv);
vg = vg_read(cmd, vg_name, NULL, 0);
- if (ignore_vg(vg, vg_name, 0, &ret)) {
+ if (ignore_vg(vg, vg_name, 0, &ret_max)) {
release_vg(vg);
stack;
- return ret;
+ return ret_max;
}
/*
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7c8abb29df2e8cc2…
Commit: 7c8abb29df2e8cc22c43f67117486e4e717110dd
Parent: 5588a56391dd3ef61d284ea64bcb6da591a3136c
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Nov 19 14:54:18 2013 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Nov 19 14:54:18 2013 -0600
liblvm/python API: Additions & fixes
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
WHATS_NEW | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index bd18c6f..e47f0e5 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,8 @@
Version 2.02.105 -
=====================================
+ liblvm/python API Add ability to validate VG/LV names.
+ liblvm/python API Add ability to create PV with arguments.
+ liblvm/python API Fail VG reduce when insufficient metadata copies
Fix install of conf subdir when not building in srcdir.
Add reporting of thin_id device id for thin volumes.
Fix reporting of empty numerical values.
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5588a56391dd3ef6…
Commit: 5588a56391dd3ef61d284ea64bcb6da591a3136c
Parent: 370520a310a44e6b9a48d9507bf2136748093029
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Mon Nov 18 15:09:09 2013 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Nov 19 14:40:47 2013 -0600
python_lvm_unit.py: Add test for new name validate methods
Test naming validate names for VG and LV names.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
test/api/python_lvm_unit.py | 106 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 106 insertions(+), 0 deletions(-)
diff --git a/test/api/python_lvm_unit.py b/test/api/python_lvm_unit.py
index fc8c198..8208d91 100755
--- a/test/api/python_lvm_unit.py
+++ b/test/api/python_lvm_unit.py
@@ -17,6 +17,7 @@ import random
import string
import lvm
import os
+import itertools
# Set of basic unit tests for the python bindings.
#
@@ -808,5 +809,110 @@ class TestLvm(unittest.TestCase):
for d in device_names:
lvm.pvCreate(d)
+ def test_vg_reduce(self):
+ # Test the case where we try to reduce a vg where the last PV has
+ # no metadata copies. In this case the reduce should fail.
+ vg_name = TestLvm.VG_P + 'reduce_test'
+
+ device_names = TestLvm._get_pv_device_names()
+
+ for d in device_names:
+ lvm.pvRemove(d)
+
+ lvm.pvCreate(device_names[0], 0, 0) # Size all, pvmetadatacopies 0
+ lvm.pvCreate(device_names[1])
+ lvm.pvCreate(device_names[2])
+ lvm.pvCreate(device_names[3])
+
+ vg = lvm.vgCreate(vg_name)
+
+ vg.extend(device_names[3])
+ vg.extend(device_names[2])
+ vg.extend(device_names[1])
+ vg.extend(device_names[0])
+ vg.close()
+
+ vg = None
+
+ vg = lvm.vgOpen(vg_name, 'w')
+
+ vg.reduce(device_names[3])
+ vg.reduce(device_names[2])
+
+ self.assertRaises(lvm.LibLVMError, vg.reduce, device_names[1])
+
+ vg.close()
+ vg = None
+
+ vg = lvm.vgOpen(vg_name, 'w')
+ vg.remove()
+ vg.close()
+
+ @staticmethod
+ def _test_valid_names(method):
+ sample = 'azAZ09._-+'
+
+ method('x' * 127)
+ method('.X')
+ method('..X')
+
+ for i in range(1, 7):
+ tests = (''.join(i) for i in itertools.product(sample, repeat=i))
+ for t in tests:
+ if t == '.' or t == '..':
+ t += 'X'
+ elif t.startswith('-'):
+ t = 'H' + t
+ method(t)
+
+ def _test_bad_names(self, method, dupe_name):
+ # Test for duplicate name
+ self.assertRaises(lvm.LibLVMError, method, dupe_name)
+
+ # Test for too long a name
+ self.assertRaises(lvm.LibLVMError, method, ('x' * 128))
+
+ # Test empty
+ self.assertRaises(lvm.LibLVMError, method, '')
+
+ # Invalid characters
+ self.assertRaises(lvm.LibLVMError, method, '&invalid^char')
+
+ # Cannot start with .. and no following characters
+ self.assertRaises(lvm.LibLVMError, method, '..')
+
+ # Cannot start with . and no following characters
+ self.assertRaises(lvm.LibLVMError, method, '.')
+
+ # Cannot start with a hyphen
+ self.assertRaises(lvm.LibLVMError, method, '-not_good')
+
+ def _lv_reserved_names(self, method):
+ prefixes = ['snapshot', 'pvmove']
+ reserved = ['_mlog', '_mimage', '_pmspare', '_rimage', '_rmeta',
+ '_vorigin', '_tdata', '_tmeta']
+
+ for p in prefixes:
+ self.assertRaises(lvm.LibLVMError, method, p + rs(3))
+
+ for r in reserved:
+ self.assertRaises(lvm.LibLVMError, method, rs(3) + r + rs(1))
+ self.assertRaises(lvm.LibLVMError, method, r + rs(1))
+
+ def test_vg_lv_name_validate(self):
+ lv_name = 'vg_lv_name_validate'
+ TestLvm._create_thin_lv(TestLvm._get_pv_device_names(), lv_name)
+ lv, vg = TestLvm._get_lv(None, lv_name)
+
+ self._test_bad_names(lvm.vgNameValidate, vg.getName())
+ self._test_bad_names(vg.lvNameValidate, lv.getName())
+
+ # Test good values
+ TestLvm._test_valid_names(lvm.vgNameValidate)
+ TestLvm._test_valid_names(vg.lvNameValidate)
+ self._lv_reserved_names(vg.lvNameValidate)
+
+ vg.close()
+
if __name__ == "__main__":
unittest.main()
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=370520a310a44e6b…
Commit: 370520a310a44e6b9a48d9507bf2136748093029
Parent: 12d5e53953f1dacd911190cacc153dc2343878fe
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Mon Nov 18 15:07:32 2013 -0600
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Nov 19 14:40:45 2013 -0600
python_lvm_unit.py: Clean-up method names & scope
Changed naming of methods from camel case to all lower case with
underscores per guidelines. Changed any methods that can be
static methods to static.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
test/api/python_lvm_unit.py | 300 +++++++++++++++++++++++--------------------
1 files changed, 158 insertions(+), 142 deletions(-)
diff --git a/test/api/python_lvm_unit.py b/test/api/python_lvm_unit.py
index 6c13149..fc8c198 100755
--- a/test/api/python_lvm_unit.py
+++ b/test/api/python_lvm_unit.py
@@ -39,11 +39,12 @@ def l(txt):
fh.flush()
-def rs(l=10):
+def rs(rand_len=10):
"""
Generate a random string
"""
- return ''.join(random.choice(string.ascii_uppercase) for x in range(l))
+ return ''.join(random.choice(string.ascii_uppercase)
+ for x in range(rand_len))
def _get_allowed_devices():
@@ -54,9 +55,9 @@ def _get_allowed_devices():
return rc
-def compare_pv(r, l):
- r_name = r.getName()
- l_name = l.getName()
+def compare_pv(right, left):
+ r_name = right.getName()
+ l_name = left.getName()
if r_name > l_name:
return 1
@@ -74,6 +75,7 @@ class AllowedPVS(object):
def __init__(self):
self.handle = None
+ self.pvs_all = None
def __enter__(self):
rc = []
@@ -102,24 +104,27 @@ class TestLvm(unittest.TestCase):
VG_P = 'py_unit_test_'
- def _get_pv_device_names(self):
+ @staticmethod
+ def _get_pv_device_names():
rc = []
with AllowedPVS() as pvs:
for p in pvs:
rc.append(p.getName())
return rc
- def _createThickLV(self, device_list, name):
+ @staticmethod
+ def _create_thick_lv(device_list, name):
vg = lvm.vgCreate(TestLvm.VG_P + "_" + name)
for d in device_list:
vg.extend(d)
- vg.createLvLinear(name, vg.getSize()/2)
+ vg.createLvLinear(name, vg.getSize() / 2)
vg.close()
vg = None
- def _createThinPool(self, device_list, pool_name):
+ @staticmethod
+ def _create_thin_pool(device_list, pool_name):
vg = lvm.vgCreate(TestLvm.VG_P + "_" + pool_name)
for d in device_list:
@@ -129,14 +134,16 @@ class TestLvm(unittest.TestCase):
lvm.THIN_DISCARDS_PASSDOWN, 1)
return vg
- def _createThinLV(self, pv_devices, name):
+ @staticmethod
+ def _create_thin_lv(pv_devices, name):
thin_pool_name = 'thin_vg_pool_' + rs(4)
- vg = self._createThinPool(pv_devices, thin_pool_name)
+ vg = TestLvm._create_thin_pool(pv_devices, thin_pool_name)
vg.createLvThin(thin_pool_name, name, vg.getSize()/8)
vg.close()
vg = None
- def _vg_names(self):
+ @staticmethod
+ def _vg_names():
rc = []
vg_names = lvm.listVgNames()
@@ -146,25 +153,27 @@ class TestLvm(unittest.TestCase):
return rc
- def _get_lv(self, lv_vol_type=None, lv_name=None):
- vg_name_list = self._vg_names()
+ @staticmethod
+ def _get_lv(lv_vol_type=None, lv_name=None):
+ vg_name_list = TestLvm._vg_names()
for vg_name in vg_name_list:
vg = lvm.vgOpen(vg_name, "w")
lvs = vg.listLVs()
- for l in lvs:
- attr = l.getAttr()
+ for lv in lvs:
+ attr = lv.getAttr()
if lv_vol_type or lv_name:
if lv_vol_type is not None and attr[0] == lv_vol_type:
- return l, vg
- elif lv_name is not None and lv_name == l.getName():
- return l, vg
+ return lv, vg
+ elif lv_name is not None and lv_name == lv.getName():
+ return lv, vg
else:
- return l, vg
+ return lv, vg
vg.close()
return None, None
- def _remove_VG(self, vg_name):
+ @staticmethod
+ def _remove_vg(vg_name):
vg = lvm.vgOpen(vg_name, 'w')
pvs = vg.listPVs()
@@ -172,26 +181,26 @@ class TestLvm(unittest.TestCase):
pe_devices = []
#Remove old snapshots first, then lv
- for l in vg.listLVs():
- attr = l.getAttr()
+ for lv in vg.listLVs():
+ attr = lv.getAttr()
if attr[0] == 's':
- l.remove()
+ lv.remove()
lvs = vg.listLVs()
#Now remove any thin lVs
- for l in vg.listLVs():
- attr = l.getAttr()
+ for lv in vg.listLVs():
+ attr = lv.getAttr()
if attr[0] == 'V':
- l.remove()
+ lv.remove()
#now remove the rest
- for l in vg.listLVs():
- name = l.getName()
+ for lv in vg.listLVs():
+ name = lv.getName()
#Don't remove the hidden ones
- if 'tmeta' not in name and 'tdata' not in name:
- l.remove()
+ if '_tmeta' not in name and '_tdata' not in name:
+ lv.remove()
for p in pvs:
pe_devices.append(p.getName())
@@ -202,23 +211,28 @@ class TestLvm(unittest.TestCase):
vg.remove()
vg.close()
- def _clean_up(self):
+ @staticmethod
+ def _clean_up():
#Clear out the testing PVs, but only if they contain stuff
#this unit test created
- for vg_n in self._vg_names():
- self._remove_VG(vg_n)
+ for vg_n in TestLvm._vg_names():
+ TestLvm._remove_vg(vg_n)
+
+ for d in TestLvm._get_pv_device_names():
+ lvm.pvRemove(d)
+ lvm.pvCreate(d)
def setUp(self):
- device_list = self._get_pv_device_names()
+ device_list = TestLvm._get_pv_device_names()
#Make sure we have an adequate number of PVs to use
self.assertTrue(len(device_list) >= 4)
- self._clean_up()
+ TestLvm._clean_up()
def tearDown(self):
- self._clean_up()
+ TestLvm._clean_up()
- def testPVresize(self):
+ def test_pv_resize(self):
with AllowedPVS() as pvs:
pv = pvs[0]
curr_size = pv.getSize()
@@ -231,7 +245,7 @@ class TestLvm(unittest.TestCase):
self.assertTrue(resized_size != curr_size)
pv.resize(dev_size)
- def testPVlifecycle(self):
+ def test_pv_life_cycle(self):
"""
Test removing and re-creating a PV
"""
@@ -256,7 +270,8 @@ class TestLvm(unittest.TestCase):
self.assertTrue(found)
- def testPvMethods(self):
+ @staticmethod
+ def test_pv_methods():
with AllowedPVS() as pvs:
for p in pvs:
p.getName()
@@ -267,13 +282,13 @@ class TestLvm(unittest.TestCase):
p.getFree()
p = None
- def testVersion(self):
+ def test_version(self):
version = lvm.getVersion()
self.assertNotEquals(version, None)
self.assertEquals(type(version), str)
self.assertTrue(len(version) > 0)
- def testPvGetters(self):
+ def test_pv_getters(self):
with AllowedPVS() as pvs:
pv = pvs[0]
self.assertEqual(type(pv.getName()), str)
@@ -301,7 +316,7 @@ class TestLvm(unittest.TestCase):
self.assertEqual(type(result[1]), bool)
self.assertTrue(result[1] == settable)
- def testPvSegs(self):
+ def test_pv_segs(self):
with AllowedPVS() as pvs:
pv = pvs[0]
pv_segs = pv.listPVsegs()
@@ -311,39 +326,39 @@ class TestLvm(unittest.TestCase):
for i in pv_segs:
self._test_prop(i, 'pvseg_start', long, False)
- def testPvProperty(self):
+ def test_pv_property(self):
with AllowedPVS() as pvs:
pv = pvs[0]
self._test_prop(pv, 'pv_mda_count', long, False)
- def testLvProperty(self):
+ def test_lv_property(self):
lv_name = 'lv_test'
- self._createThinLV(self._get_pv_device_names(), lv_name)
- lv, vg = self._get_lv(None, lv_name)
+ TestLvm._create_thin_lv(TestLvm._get_pv_device_names(), lv_name)
+ lv, vg = TestLvm._get_lv(None, lv_name)
self._test_prop(lv, 'seg_count', long, False)
vg.close()
- def testLvTags(self):
+ def test_lv_tags(self):
lv_name = 'lv_test'
- self._createThinLV(self._get_pv_device_names(), lv_name)
- lv, vg = self._get_lv(None, lv_name)
- self._testTags(lv)
+ TestLvm._create_thin_lv(TestLvm._get_pv_device_names(), lv_name)
+ lv, vg = TestLvm._get_lv(None, lv_name)
+ self._test_tags(lv)
vg.close()
- def testLvActiveInactive(self):
+ def test_lv_active_inactive(self):
lv_name = 'lv_test'
- self._createThinLV(self._get_pv_device_names(), lv_name)
- lv, vg = self._get_lv(None, lv_name)
+ TestLvm._create_thin_lv(TestLvm._get_pv_device_names(), lv_name)
+ lv, vg = TestLvm._get_lv(None, lv_name)
lv.deactivate()
self.assertTrue(lv.isActive() is False)
lv.activate()
self.assertTrue(lv.isActive() is True)
vg.close()
- def testLvRename(self):
+ def test_lv_rename(self):
lv_name = 'lv_test'
- self._createThinLV(self._get_pv_device_names(), lv_name)
- lv, vg = self._get_lv(None, lv_name)
+ TestLvm._create_thin_lv(TestLvm._get_pv_device_names(), lv_name)
+ lv, vg = TestLvm._get_lv(None, lv_name)
current_name = lv.getName()
new_name = rs()
@@ -352,29 +367,29 @@ class TestLvm(unittest.TestCase):
lv.rename(current_name)
vg.close()
- def testLvSnapshot(self):
+ def test_lv_snapshot(self):
thin_lv = 'thin_lv'
thick_lv = 'thick_lv'
- device_names = self._get_pv_device_names()
+ device_names = TestLvm._get_pv_device_names()
- self._createThinLV(device_names[0:2], thin_lv)
- self._createThickLV(device_names[2:4], thick_lv)
+ TestLvm._create_thin_lv(device_names[0:2], thin_lv)
+ TestLvm._create_thick_lv(device_names[2:4], thick_lv)
- lv, vg = self._get_lv(None, thick_lv)
+ lv, vg = TestLvm._get_lv(None, thick_lv)
lv.snapshot('thick_snap_shot', 1024*1024)
vg.close()
- thick_ss, vg = self._get_lv(None, 'thick_snap_shot')
+ thick_ss, vg = TestLvm._get_lv(None, 'thick_snap_shot')
self.assertTrue(thick_ss is not None)
vg.close()
- thin_lv, vg = self._get_lv(None, thin_lv)
+ thin_lv, vg = TestLvm._get_lv(None, thin_lv)
thin_lv.snapshot('thin_snap_shot')
vg.close()
- thin_ss, vg = self._get_lv(None, 'thin_snap_shot')
+ thin_ss, vg = TestLvm._get_lv(None, 'thin_snap_shot')
self.assertTrue(thin_ss is not None)
origin = thin_ss.getOrigin()
@@ -382,38 +397,38 @@ class TestLvm(unittest.TestCase):
vg.close()
- def testLvSuspend(self):
+ def test_lv_suspend(self):
lv_name = 'lv_test'
- self._createThinLV(self._get_pv_device_names(), lv_name)
- lv, vg = self._get_lv(None, lv_name)
+ TestLvm._create_thin_lv(TestLvm._get_pv_device_names(), lv_name)
+ lv, vg = TestLvm._get_lv(None, lv_name)
result = lv.isSuspended()
self.assertTrue(type(result) == bool)
vg.close()
- def testLvSize(self):
+ def test_lv_size(self):
lv_name = 'lv_test'
- self._createThinLV(self._get_pv_device_names(), lv_name)
- lv, vg = self._get_lv(None, lv_name)
+ TestLvm._create_thin_lv(TestLvm._get_pv_device_names(), lv_name)
+ lv, vg = TestLvm._get_lv(None, lv_name)
result = lv.getSize()
self.assertTrue(type(result) == int or type(result) == long)
vg.close()
- def testLvResize(self):
+ def test_lv_resize(self):
lv_name = 'lv_test'
- self._createThinLV(self._get_pv_device_names(), lv_name)
- lv, vg = self._get_lv(None, lv_name)
+ TestLvm._create_thin_lv(TestLvm._get_pv_device_names(), lv_name)
+ lv, vg = TestLvm._get_lv(None, lv_name)
curr_size = lv.getSize()
lv.resize(curr_size+(1024*1024))
latest = lv.getSize()
self.assertTrue(curr_size != latest)
- def testLvSeg(self):
+ def test_lv_seg(self):
lv_name = 'lv_test'
- self._createThinLV(self._get_pv_device_names(), lv_name)
- lv, vg = self._get_lv(None, lv_name)
+ TestLvm._create_thin_lv(TestLvm._get_pv_device_names(), lv_name)
+ lv, vg = TestLvm._get_lv(None, lv_name)
lv_segs = lv.listLVsegs()
@@ -424,11 +439,11 @@ class TestLvm(unittest.TestCase):
vg.close()
- def testGetSetExtentSize(self):
+ def test_get_set_extend_size(self):
thick_lv = 'get_set_prop'
- device_names = self._get_pv_device_names()
- self._createThickLV(device_names[0:2], thick_lv)
- lv, vg = self._get_lv(None, thick_lv)
+ device_names = TestLvm._get_pv_device_names()
+ TestLvm._create_thick_lv(device_names[0:2], thick_lv)
+ lv, vg = TestLvm._get_lv(None, thick_lv)
new_extent = 1024 * 1024 * 4
@@ -439,11 +454,11 @@ class TestLvm(unittest.TestCase):
self.assertEqual(vg.getExtentSize(), new_extent)
vg.close()
- def testVGsetGetProp(self):
+ def test_vg_get_set_prop(self):
thick_lv = 'get_set_prop'
- device_names = self._get_pv_device_names()
- self._createThickLV(device_names[0:2], thick_lv)
- lv, vg = self._get_lv(None, thick_lv)
+ device_names = TestLvm._get_pv_device_names()
+ TestLvm._create_thick_lv(device_names[0:2], thick_lv)
+ lv, vg = TestLvm._get_lv(None, thick_lv)
self.assertTrue(vg is not None)
if vg:
@@ -451,14 +466,14 @@ class TestLvm(unittest.TestCase):
vg.setProperty('vg_mda_copies', vg_mda_copies[0])
vg.close()
- def testVGremoveRestore(self):
+ def test_vg_remove_restore(self):
#Store off the list of physical devices
pv_devices = []
thick_lv = 'get_set_prop'
- device_names = self._get_pv_device_names()
- self._createThickLV(device_names[0:2], thick_lv)
- lv, vg = self._get_lv(None, thick_lv)
+ device_names = TestLvm._get_pv_device_names()
+ TestLvm._create_thick_lv(device_names[0:2], thick_lv)
+ lv, vg = TestLvm._get_lv(None, thick_lv)
vg_name = vg.getName()
@@ -467,22 +482,22 @@ class TestLvm(unittest.TestCase):
pv_devices.append(p.getName())
vg.close()
- self._remove_VG(vg_name)
- self._createThickLV(pv_devices, thick_lv)
+ TestLvm._remove_vg(vg_name)
+ self._create_thick_lv(pv_devices, thick_lv)
- def testVgNames(self):
+ def test_vg_names(self):
vg = lvm.listVgNames()
self.assertTrue(isinstance(vg, tuple))
- def testDupeLvCreate(self):
+ def test_dupe_lv_create(self):
"""
Try to create a lv with the same name expecting a failure
Note: This was causing a seg. fault previously
"""
thick_lv = 'dupe_name'
- device_names = self._get_pv_device_names()
- self._createThickLV(device_names[0:2], thick_lv)
- lv, vg = self._get_lv(None, thick_lv)
+ device_names = TestLvm._get_pv_device_names()
+ TestLvm._create_thick_lv(device_names[0:2], thick_lv)
+ lv, vg = TestLvm._get_lv(None, thick_lv)
self.assertTrue(vg is not None)
@@ -496,11 +511,11 @@ class TestLvm(unittest.TestCase):
lv.getSize())
vg.close()
- def testVgUuids(self):
+ def test_vg_uuids(self):
- device_names = self._get_pv_device_names()
- self._createThinLV(device_names[0:2], 'thin')
- self._createThickLV(device_names[2:4], 'thick')
+ device_names = TestLvm._get_pv_device_names()
+ TestLvm._create_thin_lv(device_names[0:2], 'thin')
+ TestLvm._create_thick_lv(device_names[2:4], 'thick')
vgs_uuids = lvm.listVgUuids()
@@ -523,12 +538,12 @@ class TestLvm(unittest.TestCase):
self.assertTrue(len(vgs_uuids) == 0)
- def testPvLookupFromVG(self):
- device_names = self._get_pv_device_names()
- self._createThinLV(device_names[0:2], 'thin')
- self._createThickLV(device_names[2:4], 'thick')
+ def test_pv_lookup_from_vg(self):
+ device_names = TestLvm._get_pv_device_names()
+ TestLvm._create_thin_lv(device_names[0:2], 'thin')
+ TestLvm._create_thick_lv(device_names[2:4], 'thick')
- vg_names = self._vg_names()
+ vg_names = TestLvm._vg_names()
self.assertTrue(len(vg_names) > 0)
@@ -558,31 +573,31 @@ class TestLvm(unittest.TestCase):
pvs = None
vg.close()
- def testPercentToFloat(self):
+ def test_percent_to_float(self):
self.assertEqual(lvm.percentToFloat(0), 0.0)
self.assertEqual(lvm.percentToFloat(1000000), 1.0)
self.assertEqual(lvm.percentToFloat(1000000 / 2), 0.5)
- def testScan(self):
+ def test_scan(self):
self.assertEqual(lvm.scan(), None)
- def testConfigReload(self):
+ def test_config_reload(self):
self.assertEqual(lvm.configReload(), None)
- def testConfig_override(self):
+ def test_config_override(self):
self.assertEquals(lvm.configOverride("global.test = 1"), None)
- def testConfigFindBool(self):
+ def test_config_find_bool(self):
either_or = lvm.configFindBool("global/fallback_to_local_locking")
self.assertTrue(type(either_or) == bool)
self.assertTrue(lvm.configFindBool("global/locking_type"))
- def testVgFromPVLookups(self):
- device_names = self._get_pv_device_names()
- self._createThinLV(device_names[0:2], 'thin')
- self._createThickLV(device_names[2:4], 'thick')
+ def test_vg_from_pv_lookups(self):
+ device_names = TestLvm._get_pv_device_names()
+ TestLvm._create_thin_lv(device_names[0:2], 'thin')
+ TestLvm._create_thick_lv(device_names[2:4], 'thick')
- vgname_list = self._vg_names()
+ vgname_list = TestLvm._vg_names()
self.assertTrue(len(vgname_list) > 0)
@@ -598,12 +613,12 @@ class TestLvm(unittest.TestCase):
self.assertEqual(vg_name, lvm.vgNameFromDevice(pv.getName()))
vg.close()
- def testVgGetName(self):
- device_names = self._get_pv_device_names()
- self._createThinLV(device_names[0:2], 'thin')
- self._createThickLV(device_names[2:4], 'thick')
+ def test_vg_get_name(self):
+ device_names = TestLvm._get_pv_device_names()
+ TestLvm._create_thin_lv(device_names[0:2], 'thin')
+ TestLvm._create_thick_lv(device_names[2:4], 'thick')
- vgname_list = self._vg_names()
+ vgname_list = TestLvm._vg_names()
self.assertTrue(len(vgname_list) > 0)
@@ -612,12 +627,12 @@ class TestLvm(unittest.TestCase):
self.assertEqual(vg.getName(), vg_name)
vg.close()
- def testVgGetUuid(self):
- device_names = self._get_pv_device_names()
- self._createThinLV(device_names[0:2], 'thin')
- self._createThickLV(device_names[2:4], 'thick')
+ def test_vg_get_uuid(self):
+ device_names = TestLvm._get_pv_device_names()
+ TestLvm._create_thin_lv(device_names[0:2], 'thin')
+ TestLvm._create_thick_lv(device_names[2:4], 'thick')
- vgname_list = self._vg_names()
+ vgname_list = TestLvm._vg_names()
self.assertTrue(len(vgname_list) > 0)
@@ -632,12 +647,12 @@ class TestLvm(unittest.TestCase):
"getExtentSize", "getExtentCount", "getFreeExtentCount",
"getPvCount", "getMaxPv", "getMaxLv"]
- def testVgGetters(self):
- device_names = self._get_pv_device_names()
- self._createThinLV(device_names[0:2], 'thin')
- self._createThickLV(device_names[2:4], 'thick')
+ def test_vg_getters(self):
+ device_names = TestLvm._get_pv_device_names()
+ TestLvm._create_thin_lv(device_names[0:2], 'thin')
+ TestLvm._create_thick_lv(device_names[2:4], 'thick')
- vg_name_list = self._vg_names()
+ vg_name_list = TestLvm._vg_names()
self.assertTrue(len(vg_name_list) > 0)
@@ -655,7 +670,7 @@ class TestLvm(unittest.TestCase):
vg.close()
- def _testTags(self, tag_obj):
+ def _test_tags(self, tag_obj):
existing_tags = tag_obj.getTags()
self.assertTrue(type(existing_tags) == tuple)
@@ -688,23 +703,24 @@ class TestLvm(unittest.TestCase):
for e in existing_tags:
self.assertTrue(e in current_tags)
- def testVgTags(self):
- device_names = self._get_pv_device_names()
+ def test_vg_tags(self):
+ device_names = TestLvm._get_pv_device_names()
i = 0
for d in device_names:
if i % 2 == 0:
- self._createThinLV([d], "thin_lv%d" % i)
+ TestLvm._create_thin_lv([d], "thin_lv%d" % i)
else:
- self._createThickLV([d], "thick_lv%d" % i)
+ TestLvm._create_thick_lv([d], "thick_lv%d" % i)
i += 1
- for vg_name in self._vg_names():
+ for vg_name in TestLvm._vg_names():
vg = lvm.vgOpen(vg_name, 'w')
- self._testTags(vg)
+ self._test_tags(vg)
vg.close()
- def testListing(self):
+ @staticmethod
+ def test_listing():
env = os.environ
@@ -719,12 +735,12 @@ class TestLvm(unittest.TestCase):
for v in lvm.listVgNames():
l('vg= %s' % v)
- def testPVemptylisting(self):
+ def test_pv_empty_listing(self):
#We had a bug where we would seg. fault if we had no PVs.
l('testPVemptylisting entry')
- device_names = self._get_pv_device_names()
+ device_names = TestLvm._get_pv_device_names()
for d in device_names:
l("Removing %s" % d)
@@ -742,7 +758,7 @@ class TestLvm(unittest.TestCase):
for d in device_names:
lvm.pvCreate(d)
- def testPVCreate(self):
+ def test_pv_create(self):
size = [0, 1024*1024*4]
pvmeta_copies = [0, 1, 2]
pvmeta_size = [0, 255, 512, 1024]
@@ -750,7 +766,7 @@ class TestLvm(unittest.TestCase):
data_alignment_offset = [1, 1, 1]
zero = [0, 1]
- device_names = self._get_pv_device_names()
+ device_names = TestLvm._get_pv_device_names()
for d in device_names:
lvm.pvRemove(d)
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=12d5e53953f1dacd…
Commit: 12d5e53953f1dacd911190cacc153dc2343878fe
Parent: fe5b538c14c47e2e206d13c17f0225e39470d720
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Thu Oct 3 16:06:05 2013 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Nov 19 14:40:44 2013 -0600
lvm2app: Remove forward declarations.
Remove the forward struct declaration. This isn't needed for
implementing opaque data pointers.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
liblvm/lvm2app.h | 19 ++++++-------------
1 files changed, 6 insertions(+), 13 deletions(-)
diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h
index 0940b6f..a91640a 100644
--- a/liblvm/lvm2app.h
+++ b/liblvm/lvm2app.h
@@ -84,20 +84,13 @@ const char *lvm_library_get_version(void);
/******************************** structures ********************************/
/**
- * Opaque structures - do not use directly. Internal structures may change
- * without notice between releases, whereas this API will be changed much less
- * frequently. Backwards compatibility will normally be preserved in future
- * releases. On any occasion when the developers do decide to break backwards
- * compatibility in any significant way, the LVM_LIBAPI number (included in
- * the library's soname) will be incremented.
- */
-struct lvm;
-struct physical_volume;
-struct volume_group;
-struct logical_volume;
-struct lv_segment;
-struct pv_segment;
-struct lvm_lv_create_params;
+ * Opaque C pointers - Internal structures may change without notice between
+ * releases, whereas this API will be changed much less frequently. Backwards
+ * compatibility will normally be preserved in future releases. On any occasion
+ * when the developers do decide to break backwards compatibility in any
+ * significant way, the LVM_LIBAPI number (included in the library's soname)
+ * will be incremented.
+ */
/**
* \class lvm_t
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fe5b538c14c47e2e…
Commit: fe5b538c14c47e2e206d13c17f0225e39470d720
Parent: 0c7a7d4d8433965313120254b68199525871b6a6
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Thu Sep 26 12:19:18 2013 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Nov 19 14:40:42 2013 -0600
lvm2app: Reset buffer after retrieving error message
The error buffer will stack error messages which is fine. However,
once you retrieve the error messages it doesn't make sense to keep
appending for each additional error message when running in the
context of a library call.
This patch clears and resets the buffer after the user retrieves
the error message.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
lib/log/log.c | 7 +++++++
lib/log/lvm-logging.h | 1 +
liblvm/lvm_base.c | 9 ++++++++-
python/liblvm.c | 5 ++++-
4 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/lib/log/log.c b/lib/log/log.c
index e0c1e73..1af9616 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -170,6 +170,13 @@ const char *stored_errmsg(void)
return _lvm_errmsg ? : "";
}
+const char *stored_errmsg_with_clear(void)
+{
+ const char *rc = strdup(stored_errmsg());
+ reset_lvm_errno(1);
+ return rc;
+}
+
static struct dm_hash_table *_duplicated = NULL;
void reset_log_duplicated(void) {
diff --git a/lib/log/lvm-logging.h b/lib/log/lvm-logging.h
index 52cd895..145e2a1 100644
--- a/lib/log/lvm-logging.h
+++ b/lib/log/lvm-logging.h
@@ -55,6 +55,7 @@ int error_message_produced(void);
void reset_lvm_errno(int store_errmsg);
int stored_errno(void);
const char *stored_errmsg(void);
+const char *stored_errmsg_with_clear(void);
/* Suppress messages to stdout/stderr (1) or everywhere (2) */
/* Returns previous setting */
diff --git a/liblvm/lvm_base.c b/liblvm/lvm_base.c
index 139cc97..d694173 100644
--- a/liblvm/lvm_base.c
+++ b/liblvm/lvm_base.c
@@ -115,7 +115,14 @@ int lvm_errno(lvm_t libh)
const char *lvm_errmsg(lvm_t libh)
{
- return stored_errmsg();
+ const char *rc = NULL;
+ struct cmd_context *cmd = (struct cmd_context *)libh;
+ const char *msg = stored_errmsg_with_clear();
+ if (msg) {
+ rc = dm_pool_strdup(cmd->mem, msg);
+ free((void *)msg);
+ }
+ return rc;
}
const char *lvm_vgname_from_pvid(lvm_t libh, const char *pvid)
diff --git a/python/liblvm.c b/python/liblvm.c
index 330ef14..6abd5ff 100644
--- a/python/liblvm.c
+++ b/python/liblvm.c
@@ -141,6 +141,7 @@ static lvobject *_create_py_lv(vgobject *parent, lv_t lv)
static PyObject *_liblvm_get_last_error(void)
{
PyObject *info;
+ const char *msg = NULL;
LVM_VALID(NULL);
@@ -148,7 +149,9 @@ static PyObject *_liblvm_get_last_error(void)
return NULL;
PyTuple_SetItem(info, 0, PyInt_FromLong((long) lvm_errno(_libh)));
- PyTuple_SetItem(info, 1, PyString_FromString(lvm_errmsg(_libh)));
+ msg = lvm_errmsg(_libh);
+ PyTuple_SetItem(info, 1, ((msg) ? PyString_FromString(msg) :
+ PyString_FromString("Memory error while retrieving error message")));
return info;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0c7a7d4d84339653…
Commit: 0c7a7d4d8433965313120254b68199525871b6a6
Parent: 0dd247502ace2dd20763d1b664edc280a255de06
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Thu Sep 26 11:39:40 2013 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Nov 19 14:40:40 2013 -0600
python-lvm: VG/LV name validation.
Python portion of
https://bugzilla.redhat.com/show_bug.cgi?id=883689
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
python/liblvm.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/python/liblvm.c b/python/liblvm.c
index 033de82..330ef14 100644
--- a/python/liblvm.c
+++ b/python/liblvm.c
@@ -391,6 +391,25 @@ static PyObject *_liblvm_lvm_percent_to_float(PyObject *self, PyObject *arg)
return Py_BuildValue("d", converted);
}
+static PyObject *_liblvm_lvm_vg_name_validate(PyObject *self, PyObject *arg)
+{
+ const char *name;
+
+ LVM_VALID(NULL);
+
+ if (!PyArg_ParseTuple(arg, "s", &name))
+ return NULL;
+
+ if (lvm_vg_name_validate(_libh, name) < 0) {
+ PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
+ return NULL;
+ }
+
+ Py_INCREF(Py_None);
+
+ return Py_None;
+}
+
static PyObject *_liblvm_lvm_vgname_from_pvid(PyObject *self, PyObject *arg)
{
const char *pvid;
@@ -1213,6 +1232,25 @@ static PyObject *_liblvm_lvm_lv_from_uuid(vgobject *self, PyObject *arg)
return _liblvm_lvm_lv_from_N(self, arg, lvm_lv_from_uuid);
}
+static PyObject *_liblvm_lvm_lv_name_validate(vgobject *self, PyObject *args)
+{
+ const char *name;
+
+ VG_VALID(self);
+
+ if (!PyArg_ParseTuple(args, "s", &name))
+ return NULL;
+
+ if (lvm_lv_name_validate(self->vg, name) < 0) {
+ PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
+ return NULL;
+ }
+
+ Py_INCREF(Py_None);
+
+ return Py_None;
+}
+
static PyObject *_liblvm_lvm_pv_from_N(vgobject *self, PyObject *arg, pv_fetch_by_N method)
{
const char *id;
@@ -1771,6 +1809,7 @@ static PyMethodDef _Liblvm_methods[] = {
{ "pvCreate", (PyCFunction)_liblvm_lvm_pv_create, METH_VARARGS },
{ "pvRemove", (PyCFunction)_liblvm_lvm_pv_remove, METH_VARARGS },
{ "percentToFloat", (PyCFunction)_liblvm_lvm_percent_to_float, METH_VARARGS },
+ { "vgNameValidate", (PyCFunction)_liblvm_lvm_vg_name_validate, METH_VARARGS },
{ "vgNameFromPvid", (PyCFunction)_liblvm_lvm_vgname_from_pvid, METH_VARARGS },
{ "vgNameFromDevice", (PyCFunction)_liblvm_lvm_vgname_from_device, METH_VARARGS },
{ NULL, NULL } /* sentinel */
@@ -1805,6 +1844,7 @@ static PyMethodDef _liblvm_vg_methods[] = {
{ "listPVs", (PyCFunction)_liblvm_lvm_vg_list_pvs, METH_NOARGS },
{ "lvFromName", (PyCFunction)_liblvm_lvm_lv_from_name, METH_VARARGS },
{ "lvFromUuid", (PyCFunction)_liblvm_lvm_lv_from_uuid, METH_VARARGS },
+ { "lvNameValidate", (PyCFunction)_liblvm_lvm_lv_name_validate, METH_VARARGS },
{ "pvFromName", (PyCFunction)_liblvm_lvm_pv_from_name, METH_VARARGS },
{ "pvFromUuid", (PyCFunction)_liblvm_lvm_pv_from_uuid, METH_VARARGS },
{ "getTags", (PyCFunction)_liblvm_lvm_vg_get_tags, METH_NOARGS },
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0dd247502ace2dd2…
Commit: 0dd247502ace2dd20763d1b664edc280a255de06
Parent: e54e70dc66a8be0dbc61e1dbc65310d86d35b086
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Thu Sep 26 11:37:40 2013 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Nov 19 14:40:39 2013 -0600
lvm2app: Add VG/LV name validation
C library portion for
https://bugzilla.redhat.com/show_bug.cgi?id=883689
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
lib/display/display.c | 29 ++++++++++++++++++++++++++++
lib/display/display.h | 3 ++
lib/metadata/metadata-exported.h | 1 +
lib/metadata/metadata.c | 12 ++++++----
lib/misc/lvm-string.c | 39 +++++++++++++++++++++++++------------
lib/misc/lvm-string.h | 8 ++++++-
liblvm/lvm2app.h | 32 +++++++++++++++++++++++++++++++
liblvm/lvm_base.c | 1 +
liblvm/lvm_vg.c | 30 +++++++++++++++++++++++++++++
9 files changed, 136 insertions(+), 19 deletions(-)
diff --git a/lib/display/display.c b/lib/display/display.c
index be56f12..2fd37a2 100644
--- a/lib/display/display.c
+++ b/lib/display/display.c
@@ -915,6 +915,35 @@ void display_segtypes(const struct cmd_context *cmd)
}
}
+void display_name_error(name_error_t name_error)
+{
+ if (name_error != NAME_VALID) {
+ switch(name_error) {
+ case NAME_INVALID_EMPTY:
+ log_error("Name is zero length");
+ break;
+ case NAME_INVALID_HYPEN:
+ log_error("Name cannot start with hyphen");
+ break;
+ case NAME_INVALID_DOTS:
+ log_error("Name starts with . or .. and has no "
+ "following character(s)");
+ break;
+ case NAME_INVALID_CHARSET:
+ log_error("Name contains invalid character, valid set includes: "
+ "[a-zA-Z0-9.-_+]");
+ break;
+ case NAME_INVALID_LENGTH:
+ /* Report that name length -1 to accommodate nul*/
+ log_error("Name length exceeds maximum limit of %d", (NAME_LEN -1));
+ break;
+ default:
+ log_error("Unknown error %d on name validation", name_error);
+ break;
+ }
+ }
+}
+
/*
* Prompt for y or n from stdin.
* Defaults to 'no' in silent mode.
diff --git a/lib/display/display.h b/lib/display/display.h
index 8462901..077fff4 100644
--- a/lib/display/display.h
+++ b/lib/display/display.h
@@ -18,6 +18,7 @@
#include "metadata-exported.h"
#include "locking.h"
+#include "lvm-string.h"
#include <stdint.h>
@@ -53,6 +54,8 @@ void vgdisplay_short(const struct volume_group *vg);
void display_formats(const struct cmd_context *cmd);
void display_segtypes(const struct cmd_context *cmd);
+void display_name_error(name_error_t name_error);
+
/*
* Allocation policy display conversion routines.
*/
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 7429241..ed1ec8d 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -581,6 +581,7 @@ int pv_analyze(struct cmd_context *cmd, const char *pv_name,
/* FIXME: move internal to library */
uint32_t pv_list_extents_free(const struct dm_list *pvh);
+int validate_new_vg_name(struct cmd_context *cmd, const char *vg_name);
int vg_validate(struct volume_group *vg);
struct volume_group *vg_create(struct cmd_context *cmd, const char *vg_name);
int vg_remove_mdas(struct volume_group *vg);
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index d80958d..53d7e5e 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -435,13 +435,15 @@ int move_pvs_used_by_lv(struct volume_group *vg_from,
return 1;
}
-static int validate_new_vg_name(struct cmd_context *cmd, const char *vg_name)
+int validate_new_vg_name(struct cmd_context *cmd, const char *vg_name)
{
static char vg_path[PATH_MAX];
+ name_error_t name_error;
- if (!validate_name(vg_name)) {
- log_error("New volume group name \"%s\" is invalid.",
- vg_name);
+ name_error = validate_name_detailed(vg_name);
+ if (NAME_VALID != name_error) {
+ display_name_error(name_error);
+ log_error("New volume group name \"%s\" is invalid.", vg_name);
return 0;
}
@@ -4574,7 +4576,7 @@ void mda_set_ignored(struct metadata_area *mda, unsigned mda_ignored)
else
return; /* No change */
- log_debug_metadata("%s ignored flag for mda %s at offset %" PRIu64 ".",
+ log_debug_metadata("%s ignored flag for mda %s at offset %" PRIu64 ".",
mda_ignored ? "Setting" : "Clearing",
mda->ops->mda_metadata_locn_name ? mda->ops->mda_metadata_locn_name(locn) : "",
mda->ops->mda_metadata_locn_offset ? mda->ops->mda_metadata_locn_offset(locn) : UINT64_C(0));
diff --git a/lib/misc/lvm-string.c b/lib/misc/lvm-string.c
index 8aa1f6c..380fe81 100644
--- a/lib/misc/lvm-string.c
+++ b/lib/misc/lvm-string.c
@@ -63,35 +63,40 @@ int validate_tag(const char *n)
return 1;
}
-/*
- * Device layer names are all of the form <vg>-<lv>-<layer>, any
- * other hyphens that appear in these names are quoted with yet
- * another hyphen. The top layer of any device has no layer
- * name. eg, vg0-lvol0.
- */
-int validate_name(const char *n)
+static int _validate_name(const char *n)
{
register char c;
register int len = 0;
if (!n || !*n)
- return 0;
+ return -1;
/* Hyphen used as VG-LV separator - ambiguity if LV starts with it */
if (*n == '-')
- return 0;
+ return -2;
if ((*n == '.') && (!n[1] || (n[1] == '.' && !n[2]))) /* ".", ".." */
- return 0;
+ return -3;
while ((len++, c = *n++))
if (!isalnum(c) && c != '.' && c != '_' && c != '-' && c != '+')
- return 0;
+ return -4;
if (len > NAME_LEN)
- return 0;
+ return -5;
- return 1;
+ return 0;
+}
+
+/*
+ * Device layer names are all of the form <vg>-<lv>-<layer>, any
+ * other hyphens that appear in these names are quoted with yet
+ * another hyphen. The top layer of any device has no layer
+ * name. eg, vg0-lvol0.
+ */
+int validate_name(const char *n)
+{
+ return (_validate_name(n) < 0 ? 0 : 1);
}
int apply_lvname_restrictions(const char *name)
@@ -136,6 +141,14 @@ int apply_lvname_restrictions(const char *name)
return 1;
}
+/*
+ * Validates name and returns an emunerated reason for name validataion failure.
+ */
+name_error_t validate_name_detailed(const char *name)
+{
+ return _validate_name(name);
+}
+
int is_reserved_lvname(const char *name)
{
int rc, old_suppress;
diff --git a/lib/misc/lvm-string.h b/lib/misc/lvm-string.h
index 6be048d..13aacf8 100644
--- a/lib/misc/lvm-string.h
+++ b/lib/misc/lvm-string.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
+ * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
* Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
@@ -24,6 +24,11 @@
struct pool;
+typedef enum name_error { NAME_VALID = 0, NAME_INVALID_EMPTY = -1,
+ NAME_INVALID_HYPEN = -2, NAME_INVALID_DOTS = -3,
+ NAME_INVALID_CHARSET = -4, NAME_INVALID_LENGTH = -5}
+ name_error_t;
+
int emit_to_buffer(char **buffer, size_t *size, const char *fmt, ...)
__attribute__ ((format(printf, 3, 4)));
@@ -31,6 +36,7 @@ char *build_dm_uuid(struct dm_pool *mem, const char *lvid,
const char *layer);
int validate_name(const char *n);
+name_error_t validate_name_detailed(const char *n);
int validate_tag(const char *n);
int apply_lvname_restrictions(const char *name);
diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h
index afc6793..0940b6f 100644
--- a/liblvm/lvm2app.h
+++ b/liblvm/lvm2app.h
@@ -510,6 +510,21 @@ vg_t lvm_vg_open(lvm_t libh, const char *vgname, const char *mode,
uint32_t flags);
/**
+ * Validate a name to be used for new VG construction.
+ *
+ * This function checks that the name has no invalid characters,
+ * the length doesn't exceed maximum and that the VG name isn't already in use
+ * and that the name adheres to any other limitations.
+ *
+ * \param libh
+ * Valid library handle
+ *
+ * \param name
+ * Name to validate for new VG create.
+ */
+int lvm_vg_name_validate(lvm_t libh, const char *vg_name);
+
+/**
* Create a VG with default parameters.
*
* \memberof lvm_t
@@ -1554,6 +1569,23 @@ int lvm_lv_resize(const lv_t lv, uint64_t new_size);
lv_t lvm_lv_snapshot(const lv_t lv, const char *snap_name, uint64_t max_snap_size);
/**
+ * Validate a name to be used for LV creation.
+ *
+ * Validates that the name does not contain any invalid characters, max length
+ * and that the LV name doesn't already exist for this VG.
+ *
+ * Note: You can have the same LV name in different VGs, thus the reason this
+ * function requires that you specify a VG to check against.
+ *
+ * \param lv
+ * Volume group handle.
+ *
+ * \param name
+ * Name to validate
+ */
+int lvm_lv_name_validate(const vg_t vg, const char *lv_name);
+
+/**
* Thin provisioning discard policies
*/
typedef enum {
diff --git a/liblvm/lvm_base.c b/liblvm/lvm_base.c
index b7603e3..139cc97 100644
--- a/liblvm/lvm_base.c
+++ b/liblvm/lvm_base.c
@@ -18,6 +18,7 @@
#include "lvm-version.h"
#include "metadata-exported.h"
#include "lvm2app.h"
+#include "lvm-string.h"
const char *lvm_library_get_version(void)
{
diff --git a/liblvm/lvm_vg.c b/liblvm/lvm_vg.c
index 214f459..d3c8ae2 100644
--- a/liblvm/lvm_vg.c
+++ b/liblvm/lvm_vg.c
@@ -21,6 +21,7 @@
#include "lvmetad.h"
#include "lvm_misc.h"
#include "lvm2app.h"
+#include "display.h"
int lvm_vg_add_tag(vg_t vg, const char *tag)
{
@@ -385,3 +386,32 @@ int lvm_scan(lvm_t libh)
return -1;
return 0;
}
+
+int lvm_lv_name_validate(const vg_t vg, const char *name)
+{
+ name_error_t name_error;
+
+ name_error = validate_name_detailed(name);
+
+ if (NAME_VALID == name_error) {
+ if (apply_lvname_restrictions(name)) {
+ if (!find_lv_in_vg(vg, name)) {
+ return 0;
+ } else {
+ log_errno(EINVAL, "LV name exists in VG");
+ }
+ }
+ } else {
+ display_name_error(name_error);
+ }
+ return -1;
+}
+
+int lvm_vg_name_validate(lvm_t libh, const char *name)
+{
+ struct cmd_context *cmd = (struct cmd_context *)libh;
+
+ if (validate_new_vg_name(cmd, name))
+ return 0;
+ return -1;
+}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e54e70dc66a8be0d…
Commit: e54e70dc66a8be0dbc61e1dbc65310d86d35b086
Parent: 531d85a0ee3854e49f9b81658dd6d7c60bb4de86
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Sep 11 18:13:18 2013 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Nov 19 14:40:37 2013 -0600
python-lvm: Update and enable unit test case
Added tests for lvm.pvCreate and enable the test suite.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
test/api/pytest.sh | 4 --
test/api/python_lvm_unit.py | 99 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 99 insertions(+), 4 deletions(-)
diff --git a/test/api/pytest.sh b/test/api/pytest.sh
index 791c9dc..67e224c 100644
--- a/test/api/pytest.sh
+++ b/test/api/pytest.sh
@@ -27,8 +27,4 @@ export PYTHONPATH=`dirname $python_lib`:$PYTHONPATH
#Setup which devices the unit test can use.
export PY_UNIT_PVS=$(cat DEVICES)
-
-#We will skip until we can ensure it is correct.
-skip
-
python_lvm_unit.py -v -f
diff --git a/test/api/python_lvm_unit.py b/test/api/python_lvm_unit.py
index eab9575..6c13149 100755
--- a/test/api/python_lvm_unit.py
+++ b/test/api/python_lvm_unit.py
@@ -27,6 +27,17 @@ import os
# production system. Therefore it is strongly advised that this unit test
# not be run on a system that contains data of value.
+fh = None
+
+
+def l(txt):
+ if os.environ.get('PY_UNIT_LOG') is not None:
+ global fh
+ if fh is None:
+ fh = open('/tmp/lvm_py_unit_test_' + rs(10), "a")
+ fh.write(txt + "\n")
+ fh.flush()
+
def rs(l=10):
"""
@@ -693,5 +704,93 @@ class TestLvm(unittest.TestCase):
self._testTags(vg)
vg.close()
+ def testListing(self):
+
+ env = os.environ
+
+ for k, v in env.items():
+ l("%s:%s" % (k, v))
+
+ with lvm.listPvs() as pvs:
+ for p in pvs:
+ l('pv= %s' % p.getName())
+
+ l('Checking for VG')
+ for v in lvm.listVgNames():
+ l('vg= %s' % v)
+
+ def testPVemptylisting(self):
+ #We had a bug where we would seg. fault if we had no PVs.
+
+ l('testPVemptylisting entry')
+
+ device_names = self._get_pv_device_names()
+
+ for d in device_names:
+ l("Removing %s" % d)
+ lvm.pvRemove(d)
+
+ count = 0
+
+ with lvm.listPvs() as pvs:
+ for p in pvs:
+ count += 1
+ l('pv= %s' % p.getName())
+
+ self.assertTrue(count == 0)
+
+ for d in device_names:
+ lvm.pvCreate(d)
+
+ def testPVCreate(self):
+ size = [0, 1024*1024*4]
+ pvmeta_copies = [0, 1, 2]
+ pvmeta_size = [0, 255, 512, 1024]
+ data_alignment = [0, 2048, 4096]
+ data_alignment_offset = [1, 1, 1]
+ zero = [0, 1]
+
+ device_names = self._get_pv_device_names()
+
+ for d in device_names:
+ lvm.pvRemove(d)
+
+ d = device_names[0]
+
+ #Test some error cases
+ self.assertRaises(TypeError, lvm.pvCreate, None)
+ self.assertRaises(lvm.LibLVMError, lvm.pvCreate, '')
+ self.assertRaises(lvm.LibLVMError, lvm.pvCreate, d, 4)
+ self.assertRaises(lvm.LibLVMError, lvm.pvCreate, d, 0, 4)
+ self.assertRaises(lvm.LibLVMError, lvm.pvCreate, d, 0, 0, 0, 2**34)
+ self.assertRaises(lvm.LibLVMError, lvm.pvCreate, d, 0, 0, 0, 4096,
+ 2**34)
+
+ #Try a number of combinations and permutations
+ for s in size:
+ lvm.pvCreate(d, s)
+ lvm.pvRemove(d)
+ for copies in pvmeta_copies:
+ lvm.pvCreate(d, s, copies)
+ lvm.pvRemove(d)
+ for pv_size in pvmeta_size:
+ lvm.pvCreate(d, s, copies, pv_size)
+ lvm.pvRemove(d)
+ for align in data_alignment:
+ lvm.pvCreate(d, s, copies, pv_size, align)
+ lvm.pvRemove(d)
+ for align_offset in data_alignment_offset:
+ lvm.pvCreate(d, s, copies, pv_size, align,
+ align * align_offset)
+ lvm.pvRemove(d)
+ for z in zero:
+ lvm.pvCreate(d, s, copies, pv_size, align,
+ align * align_offset, z)
+ lvm.pvRemove(d)
+
+ #Restore
+ for d in device_names:
+ lvm.pvCreate(d)
+
if __name__ == "__main__":
unittest.main()
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=531d85a0ee3854e4…
Commit: 531d85a0ee3854e49f9b81658dd6d7c60bb4de86
Parent: 04304ba7356c90568dcf32f0772a2023f4684656
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Sep 10 18:05:28 2013 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Nov 19 14:40:36 2013 -0600
python-lvm: Add addl. PV create arguments
Added overloaded PV create arguments with defaults for PV
creation.
Addresses bug: https://bugzilla.redhat.com/show_bug.cgi?id=880395
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
python/liblvm.c | 51 +++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/python/liblvm.c b/python/liblvm.c
index 36b64e4..033de82 100644
--- a/python/liblvm.c
+++ b/python/liblvm.c
@@ -23,6 +23,7 @@
#include <Python.h>
#include "lvm2app.h"
+#include "defaults.h"
static lvm_t _libh;
@@ -317,24 +318,62 @@ static PyObject *_liblvm_lvm_pv_remove(PyObject *self, PyObject *arg)
return Py_None;
}
+static int _set_pv_numeric_prop(pv_create_params_t pv_params, const char *name,
+ unsigned long long value)
+{
+ struct lvm_property_value prop_value;
+ prop_value.is_integer = 1;
+ prop_value.value.integer = value;
+
+ return lvm_pv_params_set_property(pv_params, name, &prop_value);
+}
+
+#define SET_PV_PROP(params, name, value) \
+ do { \
+ if (_set_pv_numeric_prop(params, name, value) == -1) \
+ goto error; \
+ } while(0)\
+
static PyObject *_liblvm_lvm_pv_create(PyObject *self, PyObject *arg)
{
const char *pv_name;
- unsigned long long size;
+ unsigned long long size = 0;
+ unsigned long long pvmetadatacopies = DEFAULT_PVMETADATACOPIES;
+ unsigned long long pvmetadatasize = DEFAULT_PVMETADATASIZE;
+ unsigned long long data_alignment = 0;
+ unsigned long long data_alignment_offset = 0;
+ unsigned long long zero = 1;
+ pv_create_params_t pv_params = NULL;
LVM_VALID(NULL);
- if (!PyArg_ParseTuple(arg, "sK", &pv_name, &size))
+ if (!PyArg_ParseTuple(arg, "s|KKKKKK", &pv_name, &size, &pvmetadatacopies,
+ &pvmetadatasize, &data_alignment,
+ &data_alignment_offset, &zero))
return NULL;
- if (lvm_pv_create(_libh, pv_name, size) == -1) {
- PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
- return NULL;
+ pv_params = lvm_pv_params_create(_libh, pv_name);
+ if (!pv_params) {
+ goto error;
}
- Py_INCREF(Py_None);
+ SET_PV_PROP(pv_params, "size", size);
+ SET_PV_PROP(pv_params, "pvmetadatacopies", pvmetadatacopies);
+ SET_PV_PROP(pv_params, "pvmetadatasize", pvmetadatasize);
+ SET_PV_PROP(pv_params, "data_alignment", data_alignment);
+ SET_PV_PROP(pv_params, "data_alignment_offset", data_alignment_offset);
+ SET_PV_PROP(pv_params, "zero", zero);
+
+ if (lvm_pv_create_adv(pv_params)) {
+ goto error;
+ }
+ Py_INCREF(Py_None);
return Py_None;
+
+error:
+ PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
+ return NULL;
}
static PyObject *_liblvm_lvm_percent_to_float(PyObject *self, PyObject *arg)
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=04304ba7356c9056…
Commit: 04304ba7356c90568dcf32f0772a2023f4684656
Parent: ec7f632ce08014ca5ceb3ac6c92d834fb0b8c93e
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Sep 10 18:01:28 2013 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Nov 19 14:40:34 2013 -0600
lvm2app: Add ability to create PV with args
Add a PV create which takes a paramters object that
has get/set method to configure PV creation.
Current get/set operations include:
- size
- pvmetadatacopies
- pvmetadatasize
- data_alignment
- data_alignment_offset
- zero
Reference: https://bugzilla.redhat.com/show_bug.cgi?id=880395
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
lib/metadata/metadata.c | 28 ++++++++++
liblvm/lvm2app.h | 64 ++++++++++++++++++++++
liblvm/lvm_lv.c | 8 ++--
liblvm/lvm_misc.c | 10 ++++
liblvm/lvm_misc.h | 9 +++-
liblvm/lvm_prop.c | 31 +++++++++++
liblvm/lvm_prop.h | 14 +++++
liblvm/lvm_prop_fields.h | 7 +++
liblvm/lvm_pv.c | 136 +++++++++++++++++++++++++++++++++++++++++-----
liblvm/lvm_vg.c | 4 +-
tools/toollib.c | 6 --
11 files changed, 289 insertions(+), 28 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 7177ff0..d80958d 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -1455,6 +1455,30 @@ static int _pvcreate_write(struct cmd_context *cmd, struct pv_to_create *pvc)
return 1;
}
+static int _verify_pv_create_params(struct pvcreate_params *pp)
+{
+ /*
+ * FIXME: Some of these checks are duplicates in pvcreate_params_validate.
+ */
+ if (pp->pvmetadatacopies > 2) {
+ log_error("Metadatacopies may only be 0, 1 or 2");
+ return 0;
+ }
+
+ if (pp->data_alignment > UINT32_MAX) {
+ log_error("Physical volume data alignment is too big.");
+ return 0;
+ }
+
+ if (pp->data_alignment_offset > UINT32_MAX) {
+ log_error("Physical volume data alignment offset is too big.");
+ return 0;
+ }
+
+ return 1;
+}
+
+
/*
* pvcreate_vol() - initialize a device with PV label and metadata area
*
@@ -1479,6 +1503,10 @@ struct physical_volume *pvcreate_vol(struct cmd_context *cmd, const char *pv_nam
if (!pp)
pp = &default_pp;
+ if (!_verify_pv_create_params(pp)) {
+ goto bad;
+ }
+
if (pp->rp.idp) {
if ((dev = lvmcache_device_from_pvid(cmd, pp->rp.idp, NULL, NULL)) &&
(dev != dev_cache_get(pv_name, cmd->filter))) {
diff --git a/liblvm/lvm2app.h b/liblvm/lvm2app.h
index cb6766c..afc6793 100644
--- a/liblvm/lvm2app.h
+++ b/liblvm/lvm2app.h
@@ -162,6 +162,14 @@ typedef struct pv_segment *pvseg_t;
typedef struct lvm_lv_create_params *lv_create_params_t;
/**
+ * \class pv_create_params
+ *
+ * This pv_create_params represents the plethora of available options when
+ * creating a physical volume
+ */
+typedef struct lvm_pv_create_params *pv_create_params_t;
+
+/**
* Logical Volume object list.
*
* Lists of these structures are returned by lvm_vg_list_lvs().
@@ -582,6 +590,62 @@ int lvm_list_pvs_free(struct dm_list *pvlist);
int lvm_pv_create(lvm_t libh, const char *pv_name, uint64_t size);
/**
+ * Create a physical volume parameter object for PV creation.
+ *
+ * \param libh Library handle
+ * \param pv_name Device name
+ *
+ * \return
+ * NULL on error, else valid parameter object to use.
+ */
+pv_create_params_t lvm_pv_params_create(lvm_t libh, const char *pv_name);
+
+/**
+ * Create a parameter object to use in function lvm_pv_create_adv
+ *
+ * \param params The params object to get property value from
+ * \param name The name of the property to retrieve
+ *
+ * Available properties:
+ *
+ * size zero indicates use detected size of device
+ * (recommended and default)
+ * pvmetadatacopies Number of metadata copies (0,1,2)
+ * pvmetadatasize The approx. size to be to be set aside for metadata
+ * data_alignment Align the start of the data to a multiple of
+ * this number
+ * data_alignment_offset Shift the start of the data area by this addl.
+ * offset
+ * zero Set to 1 to zero out first 2048 bytes of
+ * device, 0 to not (default is 1)
+ *
+ * \return
+ * lvm_property_value
+ */
+struct lvm_property_value lvm_pv_params_get_property(
+ const pv_create_params_t params,
+ const char *name);
+
+/**
+ * Sets a property of a PV parameter create object.
+ *
+ * \param params The parameter object
+ * \param name The name of the property to set (see get prop list)
+ * \param prop The property to set the value on.
+ */
+int lvm_pv_params_set_property(pv_create_params_t params, const char *name,
+ struct lvm_property_value *prop);
+/**
+ * Creates a physical volume using the supplied params object.
+ *
+ * \param params The parameters to use for physical volume creation
+ *
+ * \return
+ * -1 on error, 0 on success.
+ */
+int lvm_pv_create_adv(pv_create_params_t params);
+
+/**
* Remove a physical volume.
* Note: You cannot remove a PV while iterating through the list of PVs as
* locks are held for the PV list.
diff --git a/liblvm/lvm_lv.c b/liblvm/lvm_lv.c
index 46399e4..938a16b 100644
--- a/liblvm/lvm_lv.c
+++ b/liblvm/lvm_lv.c
@@ -71,13 +71,13 @@ const char *lvm_lv_get_origin(const lv_t lv)
struct lvm_property_value lvm_lv_get_property(const lv_t lv, const char *name)
{
- return get_property(NULL, NULL, lv, NULL, NULL, NULL, name);
+ return get_property(NULL, NULL, lv, NULL, NULL, NULL, NULL, name);
}
struct lvm_property_value lvm_lvseg_get_property(const lvseg_t lvseg,
const char *name)
{
- return get_property(NULL, NULL, NULL, lvseg, NULL, NULL, name);
+ return get_property(NULL, NULL, NULL, lvseg, NULL, NULL, NULL, name);
}
uint64_t lvm_lv_is_active(const lv_t lv)
@@ -598,7 +598,7 @@ struct lvm_property_value lvm_lv_params_get_property(
};
if (params && params->magic == LV_CREATE_PARAMS_MAGIC) {
- rc = get_property(NULL, NULL, NULL, NULL, NULL, ¶ms->lvp, name);
+ rc = get_property(NULL, NULL, NULL, NULL, NULL, ¶ms->lvp, NULL, name);
} else {
log_error("Invalid lv_create_params parameter");
}
@@ -612,7 +612,7 @@ int lvm_lv_params_set_property(lv_create_params_t params, const char *name,
int rc = -1;
if (params && params->magic == LV_CREATE_PARAMS_MAGIC) {
- rc = set_property(NULL, NULL, NULL, ¶ms->lvp, name, prop);
+ rc = set_property(NULL, NULL, NULL, ¶ms->lvp, NULL, name, prop);
} else {
log_error("Invalid lv_create_params parameter");
}
diff --git a/liblvm/lvm_misc.c b/liblvm/lvm_misc.c
index c79af8f..ba77010 100644
--- a/liblvm/lvm_misc.c
+++ b/liblvm/lvm_misc.c
@@ -51,6 +51,7 @@ struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
const lvseg_t lvseg,
const pvseg_t pvseg,
const struct lvcreate_params *lvcp,
+ const struct pvcreate_params *pvcp,
const char *name)
{
struct lvm_property_type prop;
@@ -76,6 +77,9 @@ struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
} else if (lvcp) {
if (!lv_create_param_get_property(lvcp, &prop))
return v;
+ } else if (pvcp) {
+ if (!pv_create_param_get_property(pvcp, &prop))
+ return v;
} else {
log_errno(EINVAL, "Invalid NULL handle passed to library function.");
return v;
@@ -95,6 +99,7 @@ struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
int set_property(const pv_t pv, const vg_t vg, const lv_t lv,
struct lvcreate_params *lvcp,
+ struct pvcreate_params *pvcp,
const char *name,
struct lvm_property_value *v)
{
@@ -125,6 +130,11 @@ int set_property(const pv_t pv, const vg_t vg, const lv_t lv,
v->is_valid = 0;
return -1;
}
+ } else if (pvcp) {
+ if (!pv_create_param_set_property(pvcp, &prop)) {
+ v->is_valid = 0;
+ return -1;
+ }
} else {
return -1;
}
diff --git a/liblvm/lvm_misc.h b/liblvm/lvm_misc.h
index a84125a..b187021 100644
--- a/liblvm/lvm_misc.h
+++ b/liblvm/lvm_misc.h
@@ -16,14 +16,19 @@
#include "libdevmapper.h"
#include "lvm2app.h"
+#include "metadata-exported.h"
struct dm_list *tag_list_copy(struct dm_pool *p, struct dm_list *tag_list);
struct lvm_property_value get_property(const pv_t pv, const vg_t vg,
const lv_t lv, const lvseg_t lvseg,
- const pvseg_t pvseg, const struct lvcreate_params *lvcp,
+ const pvseg_t pvseg,
+ const struct lvcreate_params *lvcp,
+ const struct pvcreate_params *pvcp,
const char *name);
int set_property(const pv_t pv, const vg_t vg, const lv_t lv,
- struct lvcreate_params *lvcp, const char *name,
+ struct lvcreate_params *lvcp,
+ struct pvcreate_params *pvcp,
+ const char *name,
struct lvm_property_value *value);
#endif
diff --git a/liblvm/lvm_prop.c b/liblvm/lvm_prop.c
index e25f03b..cbbd6f5 100644
--- a/liblvm/lvm_prop.c
+++ b/liblvm/lvm_prop.c
@@ -21,6 +21,25 @@
GET_LVCREATEPARAMS_NUM_PROPERTY_FN(skip_zero, lvcp->zero)
SET_LVCREATEPARAMS_NUM_PROPERTY_FN(skip_zero, lvcp->zero)
+/* PV create parameters */
+GET_PVCREATEPARAMS_NUM_PROPERTY_FN(size, pvcp->size)
+SET_PVCREATEPARAMS_NUM_PROPERTY_FN(size, pvcp->size)
+
+GET_PVCREATEPARAMS_NUM_PROPERTY_FN(pvmetadatacopies, pvcp->pvmetadatacopies)
+SET_PVCREATEPARAMS_NUM_PROPERTY_FN(pvmetadatacopies, pvcp->pvmetadatacopies)
+
+GET_PVCREATEPARAMS_NUM_PROPERTY_FN(pvmetadatasize, pvcp->pvmetadatasize)
+SET_PVCREATEPARAMS_NUM_PROPERTY_FN(pvmetadatasize, pvcp->pvmetadatasize)
+
+GET_PVCREATEPARAMS_NUM_PROPERTY_FN(data_alignment, pvcp->data_alignment)
+SET_PVCREATEPARAMS_NUM_PROPERTY_FN(data_alignment, pvcp->data_alignment)
+
+GET_PVCREATEPARAMS_NUM_PROPERTY_FN(data_alignment_offset, pvcp->data_alignment_offset)
+SET_PVCREATEPARAMS_NUM_PROPERTY_FN(data_alignment_offset, pvcp->data_alignment_offset)
+
+GET_PVCREATEPARAMS_NUM_PROPERTY_FN(zero, pvcp->zero)
+SET_PVCREATEPARAMS_NUM_PROPERTY_FN(zero, pvcp->zero)
+
struct lvm_property_type _lib_properties[] = {
#include "lvm_prop_fields.h"
{ 0, "", 0, 0, 0, { .integer = 0 }, prop_not_implemented_get,
@@ -42,3 +61,15 @@ int lv_create_param_set_property(struct lvcreate_params *lvcp,
{
return prop_set_property(_lib_properties, lvcp, prop, LV_CREATE_PARAMS);
}
+
+int pv_create_param_get_property(const struct pvcreate_params *pvcp,
+ struct lvm_property_type *prop)
+{
+ return prop_get_property(_lib_properties, pvcp, prop, PV_CREATE_PARAMS);
+}
+
+int pv_create_param_set_property(struct pvcreate_params *pvcp,
+ struct lvm_property_type *prop)
+{
+ return prop_set_property(_lib_properties, pvcp, prop, PV_CREATE_PARAMS);
+}
diff --git a/liblvm/lvm_prop.h b/liblvm/lvm_prop.h
index bedc078..db4cf8a 100644
--- a/liblvm/lvm_prop.h
+++ b/liblvm/lvm_prop.h
@@ -17,8 +17,10 @@
#define _LIB_LVM_PROP_H
typedef struct lvcreate_params type_lvcreate_params;
+typedef struct pvcreate_params type_pvcreate_params;
#define LV_CREATE_PARAMS 1
+#define PV_CREATE_PARAMS 2
#define GET_LVCREATEPARAMS_NUM_PROPERTY_FN(NAME, VALUE)\
GET_NUM_PROPERTY_FN(NAME, VALUE, lvcreate_params, lvcp)
@@ -26,10 +28,22 @@ typedef struct lvcreate_params type_lvcreate_params;
#define SET_LVCREATEPARAMS_NUM_PROPERTY_FN(NAME, VALUE) \
SET_NUM_PROPERTY(NAME, VALUE, lvcreate_params, lvcp)
+#define GET_PVCREATEPARAMS_NUM_PROPERTY_FN(NAME, VALUE)\
+ GET_NUM_PROPERTY_FN(NAME, VALUE, pvcreate_params, pvcp)
+
+#define SET_PVCREATEPARAMS_NUM_PROPERTY_FN(NAME, VALUE) \
+ SET_NUM_PROPERTY(NAME, VALUE, pvcreate_params, pvcp)
+
int lv_create_param_get_property(const struct lvcreate_params *lvcp,
struct lvm_property_type *prop);
int lv_create_param_set_property(struct lvcreate_params *lvcp,
struct lvm_property_type *prop);
+int pv_create_param_get_property(const struct pvcreate_params *pvcp,
+ struct lvm_property_type *prop);
+
+int pv_create_param_set_property(struct pvcreate_params *pvcp,
+ struct lvm_property_type *prop);
+
#endif
diff --git a/liblvm/lvm_prop_fields.h b/liblvm/lvm_prop_fields.h
index 99c322d..ba7dd18 100644
--- a/liblvm/lvm_prop_fields.h
+++ b/liblvm/lvm_prop_fields.h
@@ -13,3 +13,10 @@
*/
FIELD(LV_CREATE_PARAMS, lvcreate_params, NUM, "skip_zero", zero, 2, uint32, skip_zero, "Skip zeroing on lv creation", 1)
+
+FIELD(PV_CREATE_PARAMS, pvcreate_params, NUM, "size", size, 2, uint64_t, size, "PV size", 1)
+FIELD(PV_CREATE_PARAMS, pvcreate_params, NUM, "pvmetadatacopies", pvmetadatacopies, 2, uint64_t, pvmetadatacopies, "PV Metadata copies", 1)
+FIELD(PV_CREATE_PARAMS, pvcreate_params, NUM, "pvmetadatasize", pvmetadatasize, 2, uint64_t, pvmetadatasize, "PV Metadata size", 1)
+FIELD(PV_CREATE_PARAMS, pvcreate_params, NUM, "data_alignment", data_alignment, 2, uint64_t, data_alignment, "Start data to a multiple of value", 1)
+FIELD(PV_CREATE_PARAMS, pvcreate_params, NUM, "data_alignment_offset", data_alignment_offset, 2, uint64_t, data_alignment_offset, "Shift the start of the data area", 1)
+FIELD(PV_CREATE_PARAMS, pvcreate_params, NUM, "zero", zero, 2, uint64_t, zero, "Zero first 2048 bytes of device", 1)
diff --git a/liblvm/lvm_pv.c b/liblvm/lvm_pv.c
index e67e1eb..d540a6c 100644
--- a/liblvm/lvm_pv.c
+++ b/liblvm/lvm_pv.c
@@ -21,6 +21,16 @@
#include "locking.h"
#include "toolcontext.h"
+struct lvm_pv_create_params
+{
+ uint32_t magic;
+ lvm_t libh;
+ const char *pv_name;
+ struct pvcreate_params pv_p;
+};
+
+#define PV_CREATE_PARAMS_MAGIC 0xFEED0002
+
const char *lvm_pv_get_uuid(const pv_t pv)
{
return pv_uuid_dup(pv);
@@ -53,13 +63,13 @@ uint64_t lvm_pv_get_free(const pv_t pv)
struct lvm_property_value lvm_pv_get_property(const pv_t pv, const char *name)
{
- return get_property(pv, NULL, NULL, NULL, NULL, NULL, name);
+ return get_property(pv, NULL, NULL, NULL, NULL, NULL, NULL, name);
}
struct lvm_property_value lvm_pvseg_get_property(const pvseg_t pvseg,
const char *name)
{
- return get_property(NULL, NULL, NULL, NULL, pvseg, NULL, name);
+ return get_property(NULL, NULL, NULL, NULL, pvseg, NULL, NULL, name);
}
struct lvm_list_wrapper
@@ -80,6 +90,8 @@ int lvm_pv_remove(lvm_t libh, const char *pv_name)
return 0;
}
+#define PV_LIST_MAGIC 0xF005BA11
+
struct dm_list *lvm_list_pvs(lvm_t libh)
{
struct lvm_list_wrapper *rc = NULL;
@@ -109,7 +121,7 @@ struct dm_list *lvm_list_pvs(lvm_t libh)
* pointer in the free call.
*/
rc->cmd = cmd;
- rc->magic = 0xF005BA11;
+ rc->magic = PV_LIST_MAGIC;
}
return &rc->pvslist;
@@ -123,7 +135,7 @@ int lvm_list_pvs_free(struct dm_list *pvlist)
if (pvlist) {
to_delete = dm_list_struct_base(pvlist, struct lvm_list_wrapper, pvslist);
- if (to_delete->magic != 0xF005BA11) {
+ if (to_delete->magic != PV_LIST_MAGIC) {
log_errno(EINVAL, "Not a correct pvlist structure");
return -1;
}
@@ -224,26 +236,122 @@ int lvm_pv_resize(const pv_t pv, uint64_t new_size)
return 0;
}
-int lvm_pv_create(lvm_t libh, const char *pv_name, uint64_t size)
+/*
+ * Common internal code to create a parameter passing object
+ */
+static struct lvm_pv_create_params *_lvm_pv_params_create(
+ lvm_t libh,
+ const char *pv_name,
+ struct lvm_pv_create_params *pvcp_in)
{
- struct pvcreate_params pp;
+ struct lvm_pv_create_params *pvcp = NULL;
+ const char *dev = NULL;
struct cmd_context *cmd = (struct cmd_context *)libh;
- uint64_t size_sectors = size;
- pvcreate_params_set_defaults(&pp);
+ if (!pv_name || strlen(pv_name) == 0) {
+ log_error("Invalid pv_name");
+ return NULL;
+ }
+
+ if (!pvcp_in) {
+ pvcp = dm_pool_zalloc(cmd->libmem, sizeof(struct lvm_pv_create_params));
+ } else {
+ pvcp = pvcp_in;
+ }
+
+ if (!pvcp) {
+ return NULL;
+ }
+
+ dev = dm_pool_strdup(cmd->libmem, pv_name);
+ if (!dev) {
+ return NULL;
+ }
+
+ pvcreate_params_set_defaults(&pvcp->pv_p);
+ pvcp->pv_p.yes = 1;
+ pvcp->pv_p.force = DONT_PROMPT;
+ pvcp->pv_name = dev;
+ pvcp->libh = libh;
+ pvcp->magic = PV_CREATE_PARAMS_MAGIC;
+
+ return pvcp;
+}
+
+pv_create_params_t lvm_pv_params_create(lvm_t libh, const char *pv_name)
+{
+ return _lvm_pv_params_create(libh, pv_name, NULL);
+}
- if (size_sectors != 0) {
- if (size_sectors % SECTOR_SIZE) {
+struct lvm_property_value lvm_pv_params_get_property(
+ const pv_create_params_t params,
+ const char *name)
+{
+ struct lvm_property_value rc = {
+ .is_valid = 0
+ };
+
+ if (params && params->magic == PV_CREATE_PARAMS_MAGIC) {
+ rc = get_property(NULL, NULL, NULL, NULL, NULL, NULL, ¶ms->pv_p,
+ name);
+ } else {
+ log_error("Invalid pv_create_params parameter");
+ }
+
+ return rc;
+}
+
+int lvm_pv_params_set_property(pv_create_params_t params, const char *name,
+ struct lvm_property_value *prop)
+{
+ int rc = -1;
+
+ if (params && params->magic == PV_CREATE_PARAMS_MAGIC) {
+ rc = set_property(NULL, NULL, NULL, NULL, ¶ms->pv_p, name, prop);
+ } else {
+ log_error("Invalid pv_create_params parameter");
+ }
+ return rc;
+}
+
+static int _pv_create(pv_create_params_t params)
+{
+ struct cmd_context *cmd = (struct cmd_context *)params->libh;
+
+ if (params->pv_p.size) {
+ if (params->pv_p.size % SECTOR_SIZE) {
log_errno(EINVAL, "Size not a multiple of 512");
return -1;
}
- size_sectors = size_sectors >> SECTOR_SHIFT;
+ params->pv_p.size = params->pv_p.size >> SECTOR_SHIFT;
}
- pp.size = size_sectors;
+ if (!pvcreate_single(cmd, params->pv_name, ¶ms->pv_p))
+ return -1;
+ return 0;
+}
+
+int lvm_pv_create(lvm_t libh, const char *pv_name, uint64_t size)
+{
+ struct lvm_pv_create_params pp;
- if (!pvcreate_single(cmd, pv_name, &pp))
+ if (!_lvm_pv_params_create(libh, pv_name, &pp))
return -1;
- return 0;
+ pp.pv_p.size = size;
+
+ return _pv_create(&pp);
+}
+
+int lvm_pv_create_adv(pv_create_params_t params)
+{
+ int rc = -1;
+
+ if (params && params->magic == PV_CREATE_PARAMS_MAGIC) {
+ rc = _pv_create(params);
+ } else {
+ log_error("Invalid pv_create_params parameter");
+ }
+
+ return rc;
}
diff --git a/liblvm/lvm_vg.c b/liblvm/lvm_vg.c
index 3f4968e..214f459 100644
--- a/liblvm/lvm_vg.c
+++ b/liblvm/lvm_vg.c
@@ -340,7 +340,7 @@ const char *lvm_vg_get_name(const vg_t vg)
struct lvm_property_value lvm_vg_get_property(const vg_t vg, const char *name)
{
- return get_property(NULL, vg, NULL, NULL, NULL, NULL, name);
+ return get_property(NULL, vg, NULL, NULL, NULL, NULL, NULL, name);
}
int lvm_vg_set_property(const vg_t vg, const char *name,
@@ -357,7 +357,7 @@ int lvm_vg_set_property(const vg_t vg, const char *name,
strlen(value->value.string) + 1);
}
- return set_property(NULL, vg, NULL, NULL, name, value);
+ return set_property(NULL, vg, NULL, NULL, NULL, name, value);
}
struct dm_list *lvm_list_vg_names(lvm_t libh)
diff --git a/tools/toollib.c b/tools/toollib.c
index 9a33e55..b3bfd1d 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1541,12 +1541,6 @@ int pvcreate_params_validate(struct cmd_context *cmd,
return 0;
}
- if (arg_count(cmd, pvmetadatacopies_ARG) &&
- arg_int_value(cmd, pvmetadatacopies_ARG, -1) > 2) {
- log_error("Metadatacopies may only be 0, 1 or 2");
- return 0;
- }
-
if (arg_count(cmd, metadataignore_ARG))
pp->metadataignore = arg_int_value(cmd, metadataignore_ARG,
DEFAULT_PVMETADATAIGNORE);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ec7f632ce08014ca…
Commit: ec7f632ce08014ca5ceb3ac6c92d834fb0b8c93e
Parent: 5074dcc896681494309c59830803b54a84429fd0
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Sep 10 17:59:45 2013 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Nov 19 14:40:32 2013 -0600
python-lvm: Test case change for vg.reduce
Fix reduce as newly changed vg reduce fails when you
try to remove the last pv in the vg.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
test/api/python_lvm_unit.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/test/api/python_lvm_unit.py b/test/api/python_lvm_unit.py
index bceb82c..eab9575 100755
--- a/test/api/python_lvm_unit.py
+++ b/test/api/python_lvm_unit.py
@@ -185,7 +185,7 @@ class TestLvm(unittest.TestCase):
for p in pvs:
pe_devices.append(p.getName())
- for pv in pe_devices:
+ for pv in pe_devices[:-1]:
vg.reduce(pv)
vg.remove()
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5074dcc896681494…
Commit: 5074dcc896681494309c59830803b54a84429fd0
Parent: fe474e1452866476b7f17175d92417d6d827ae4c
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Sep 3 18:07:43 2013 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Nov 19 14:40:30 2013 -0600
metadata.c: Call refactored vgreduce_single
Replace the code with the refactored vgreduce_single instead
of calling its own implementation.
Corrects bug: https://bugzilla.redhat.com/show_bug.cgi?id=989174
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
lib/metadata/metadata-exported.h | 2 +-
lib/metadata/metadata.c | 35 ++++++-----------------------------
lib/metadata/vg.c | 37 ++++++++++++++++++++++---------------
tools/vgreduce.c | 2 +-
4 files changed, 30 insertions(+), 46 deletions(-)
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index cac5b3c..7429241 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -594,7 +594,7 @@ int vg_extend(struct volume_group *vg, int pv_count, const char *const *pv_names
int vg_reduce(struct volume_group *vg, const char *pv_name);
int vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
- struct physical_volume *pv);
+ struct physical_volume *pv, int commit);
int vg_change_tag(struct volume_group *vg, const char *tag, int add_tag);
int vg_split_mdas(struct cmd_context *cmd, struct volume_group *vg_from,
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 398def6..7177ff0 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -691,50 +691,27 @@ int vg_extend(struct volume_group *vg, int pv_count, const char *const *pv_names
return 1;
}
-/* FIXME: use this inside vgreduce_single? */
int vg_reduce(struct volume_group *vg, const char *pv_name)
{
struct physical_volume *pv;
struct pv_list *pvl;
- if (_vg_bad_status_bits(vg, RESIZEABLE_VG))
- return 0;
-
- if (!archive(vg))
- goto bad;
-
- /* remove each pv */
if (!(pvl = find_pv_in_vg(vg, pv_name))) {
log_error("Physical volume %s not in volume group %s.",
pv_name, vg->name);
- goto bad;
+ return 0;
}
pv = pvl->pv;
- if (pv_pe_alloc_count(pv)) {
- log_error("Physical volume %s still in use.",
- pv_name);
- goto bad;
- }
-
- if (!dev_get_size(pv_dev(pv), &pv->size)) {
- log_error("%s: Couldn't get size.", pv_name);
- goto bad;
+ if (vgreduce_single(vg->cmd, vg, pv, 0)) {
+ dm_list_add(&vg->removed_pvs, &pvl->list);
+ return 1;
}
- vg->free_count -= pv_pe_count(pv) - pv_pe_alloc_count(pv);
- vg->extent_count -= pv_pe_count(pv);
- del_pvl_from_vgs(vg, pvl);
-
- /* add pv to the remove_pvs list */
- dm_list_add(&vg->removed_pvs, &pvl->list);
-
- return 1;
-
- bad:
log_error("Unable to remove physical volume '%s' from "
- "volume group '%s'.", pv_name, vg->name);
+ "volume group '%s'.", pv_name, vg->name);
+
return 0;
}
diff --git a/lib/metadata/vg.c b/lib/metadata/vg.c
index 20b4b4d..877371e 100644
--- a/lib/metadata/vg.c
+++ b/lib/metadata/vg.c
@@ -576,7 +576,7 @@ char *vg_attr_dup(struct dm_pool *mem, const struct volume_group *vg)
}
int vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
- struct physical_volume *pv)
+ struct physical_volume *pv, int commit)
{
struct pv_list *pvl;
struct volume_group *orphan_vg = NULL;
@@ -637,25 +637,32 @@ int vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
goto bad;
}
- if (!vg_write(vg) || !vg_commit(vg)) {
- log_error("Removal of physical volume \"%s\" from "
- "\"%s\" failed", name, vg->name);
- goto bad;
- }
+ /*
+ * Only write out the needed changes if so requested by caller.
+ */
+ if (commit) {
+ if (!vg_write(vg) || !vg_commit(vg)) {
+ log_error("Removal of physical volume \"%s\" from "
+ "\"%s\" failed", name, vg->name);
+ goto bad;
+ }
- if (!pv_write(cmd, pv, 0)) {
- log_error("Failed to clear metadata from physical "
- "volume \"%s\" "
- "after removal from \"%s\"", name, vg->name);
- goto bad;
- }
+ if (!pv_write(cmd, pv, 0)) {
+ log_error("Failed to clear metadata from physical "
+ "volume \"%s\" "
+ "after removal from \"%s\"", name, vg->name);
+ goto bad;
+ }
- backup(vg);
+ backup(vg);
- log_print_unless_silent("Removed \"%s\" from volume group \"%s\"", name, vg->name);
+ log_print_unless_silent("Removed \"%s\" from volume group \"%s\"",
+ name, vg->name);
+ }
r = 1;
bad:
- if (pvl)
+ /* If we are committing here or we had an error then we will free fid */
+ if (pvl && (commit || r != 1))
free_pv_fid(pvl->pv);
unlock_and_release_vg(cmd, orphan_vg, VG_ORPHANS);
return r;
diff --git a/tools/vgreduce.c b/tools/vgreduce.c
index 534a4fb..0ade4fa 100644
--- a/tools/vgreduce.c
+++ b/tools/vgreduce.c
@@ -125,7 +125,7 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
struct physical_volume *pv,
void *handle __attribute__((unused)))
{
- int r = vgreduce_single(cmd, vg, pv);
+ int r = vgreduce_single(cmd, vg, pv, 1);
if (!r)
return ECMD_FAILED;
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fe474e1452866476…
Commit: fe474e1452866476b7f17175d92417d6d827ae4c
Parent: 20ffb0f721e72fb25905e9ae77689e901babf4ce
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Tue Sep 3 17:31:45 2013 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Nov 19 14:40:28 2013 -0600
vgreduce: Move _vgreduce_single functionality
Moving the core functionality of vgreduce single into
lib/metadata/vg.c so that the command line and lvm2app library
can call the same core functionality. New function is
vgreduce_single.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
lib/metadata/metadata-exported.h | 4 ++
lib/metadata/vg.c | 87 ++++++++++++++++++++++++++++++++++++++
tools/vgreduce.c | 81 ++---------------------------------
3 files changed, 95 insertions(+), 77 deletions(-)
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index 1bf5236..cac5b3c 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -592,6 +592,10 @@ int vg_rename(struct cmd_context *cmd, struct volume_group *vg,
int vg_extend(struct volume_group *vg, int pv_count, const char *const *pv_names,
struct pvcreate_params *pp);
int vg_reduce(struct volume_group *vg, const char *pv_name);
+
+int vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
+ struct physical_volume *pv);
+
int vg_change_tag(struct volume_group *vg, const char *tag, int add_tag);
int vg_split_mdas(struct cmd_context *cmd, struct volume_group *vg_from,
struct volume_group *vg_to);
diff --git a/lib/metadata/vg.c b/lib/metadata/vg.c
index 476292e..20b4b4d 100644
--- a/lib/metadata/vg.c
+++ b/lib/metadata/vg.c
@@ -19,6 +19,7 @@
#include "activate.h"
#include "toolcontext.h"
#include "lvmcache.h"
+#include "archiver.h"
struct volume_group *alloc_vg(const char *pool_name, struct cmd_context *cmd,
const char *vg_name)
@@ -573,3 +574,89 @@ char *vg_attr_dup(struct dm_pool *mem, const struct volume_group *vg)
repstr[5] = (vg_is_clustered(vg)) ? 'c' : '-';
return repstr;
}
+
+int vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
+ struct physical_volume *pv)
+{
+ struct pv_list *pvl;
+ struct volume_group *orphan_vg = NULL;
+ int r = 0;
+ const char *name = pv_dev_name(pv);
+
+ if (!vg) {
+ log_error(INTERNAL_ERROR "VG is NULL.");
+ return r;
+ }
+
+ if (pv_pe_alloc_count(pv)) {
+ log_error("Physical volume \"%s\" still in use", name);
+ return r;
+ }
+
+ if (vg->pv_count == 1) {
+ log_error("Can't remove final physical volume \"%s\" from "
+ "volume group \"%s\"", name, vg->name);
+ return r;
+ }
+
+ if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE, NULL)) {
+ log_error("Can't get lock for orphan PVs");
+ return r;
+ }
+
+ pvl = find_pv_in_vg(vg, name);
+
+ if (!archive(vg))
+ goto_bad;
+
+ log_verbose("Removing \"%s\" from volume group \"%s\"", name, vg->name);
+
+ if (pvl)
+ del_pvl_from_vgs(vg, pvl);
+
+ pv->vg_name = vg->fid->fmt->orphan_vg_name;
+ pv->status = ALLOCATABLE_PV;
+
+ if (!dev_get_size(pv_dev(pv), &pv->size)) {
+ log_error("%s: Couldn't get size.", pv_dev_name(pv));
+ goto bad;
+ }
+
+ vg->free_count -= pv_pe_count(pv) - pv_pe_alloc_count(pv);
+ vg->extent_count -= pv_pe_count(pv);
+
+ orphan_vg = vg_read_for_update(cmd, vg->fid->fmt->orphan_vg_name,
+ NULL, 0);
+
+ if (vg_read_error(orphan_vg))
+ goto bad;
+
+ if (!vg_split_mdas(cmd, vg, orphan_vg) || !vg->pv_count) {
+ log_error("Cannot remove final metadata area on \"%s\" from \"%s\"",
+ name, vg->name);
+ goto bad;
+ }
+
+ if (!vg_write(vg) || !vg_commit(vg)) {
+ log_error("Removal of physical volume \"%s\" from "
+ "\"%s\" failed", name, vg->name);
+ goto bad;
+ }
+
+ if (!pv_write(cmd, pv, 0)) {
+ log_error("Failed to clear metadata from physical "
+ "volume \"%s\" "
+ "after removal from \"%s\"", name, vg->name);
+ goto bad;
+ }
+
+ backup(vg);
+
+ log_print_unless_silent("Removed \"%s\" from volume group \"%s\"", name, vg->name);
+ r = 1;
+bad:
+ if (pvl)
+ free_pv_fid(pvl->pv);
+ unlock_and_release_vg(cmd, orphan_vg, VG_ORPHANS);
+ return r;
+}
diff --git a/tools/vgreduce.c b/tools/vgreduce.c
index 8803899..534a4fb 100644
--- a/tools/vgreduce.c
+++ b/tools/vgreduce.c
@@ -125,88 +125,15 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
struct physical_volume *pv,
void *handle __attribute__((unused)))
{
- struct pv_list *pvl;
- struct volume_group *orphan_vg = NULL;
- int r = ECMD_FAILED;
- const char *name = pv_dev_name(pv);
-
- if (!vg) {
- log_error(INTERNAL_ERROR "VG is NULL.");
- return ECMD_FAILED;
- }
+ int r = vgreduce_single(cmd, vg, pv);
- if (pv_pe_alloc_count(pv)) {
- log_error("Physical volume \"%s\" still in use", name);
- return ECMD_FAILED;
- }
-
- if (vg->pv_count == 1) {
- log_error("Can't remove final physical volume \"%s\" from "
- "volume group \"%s\"", name, vg->name);
+ if (!r)
return ECMD_FAILED;
- }
-
- if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE, NULL)) {
- log_error("Can't get lock for orphan PVs");
- return ECMD_FAILED;
- }
-
- pvl = find_pv_in_vg(vg, name);
-
- if (!archive(vg))
- goto_bad;
-
- log_verbose("Removing \"%s\" from volume group \"%s\"", name, vg->name);
- if (pvl)
- del_pvl_from_vgs(vg, pvl);
-
- pv->vg_name = vg->fid->fmt->orphan_vg_name;
- pv->status = ALLOCATABLE_PV;
-
- if (!dev_get_size(pv_dev(pv), &pv->size)) {
- log_error("%s: Couldn't get size.", pv_dev_name(pv));
- goto bad;
- }
-
- vg->free_count -= pv_pe_count(pv) - pv_pe_alloc_count(pv);
- vg->extent_count -= pv_pe_count(pv);
-
- orphan_vg = vg_read_for_update(cmd, vg->fid->fmt->orphan_vg_name,
- NULL, 0);
-
- if (vg_read_error(orphan_vg))
- goto bad;
-
- if (!vg_split_mdas(cmd, vg, orphan_vg) || !vg->pv_count) {
- log_error("Cannot remove final metadata area on \"%s\" from \"%s\"",
- name, vg->name);
- goto bad;
- }
-
- if (!vg_write(vg) || !vg_commit(vg)) {
- log_error("Removal of physical volume \"%s\" from "
- "\"%s\" failed", name, vg->name);
- goto bad;
- }
-
- if (!pv_write(cmd, pv, 0)) {
- log_error("Failed to clear metadata from physical "
- "volume \"%s\" "
- "after removal from \"%s\"", name, vg->name);
- goto bad;
- }
+ return ECMD_PROCESSED;
+}
- backup(vg);
- log_print_unless_silent("Removed \"%s\" from volume group \"%s\"", name, vg->name);
- r = ECMD_PROCESSED;
-bad:
- if (pvl)
- free_pv_fid(pvl->pv);
- unlock_and_release_vg(cmd, orphan_vg, VG_ORPHANS);
- return r;
-}
int vgreduce(struct cmd_context *cmd, int argc, char **argv)
{
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=20ffb0f721e72fb2…
Commit: 20ffb0f721e72fb25905e9ae77689e901babf4ce
Parent: 1f744733a15fe56404dbd0c4d8e1aab339fef774
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Jul 31 15:16:01 2013 -0500
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Nov 19 14:40:27 2013 -0600
python-lvm: Ensure library handle is correct after python gc() call
In a previous commit we added the ability for the library to do garbage
collection, to free all the memory used by the library handle buffer by closing
and re-opening the library handle. When we introduced this functionality we
also opened up the opportunity that the user of the python bindings to have
an object that references the old library handle. In this case if the user
tried to use the old object a segmentation fault could occur because the
memory had been previously freed.
This patch tries to mitigate this by storing a copy of the library handle that
was used when the object was created so that it can compare the current in
use pointer with what existed when the object was created. In the case where
they match the operation is permitted to continue, otherwise an exception is
throw, thus avoiding a segmentation fault.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
python/liblvm.c | 219 ++++++++++++++++++++++++++-----------------------------
1 files changed, 103 insertions(+), 116 deletions(-)
diff --git a/python/liblvm.c b/python/liblvm.c
index 42a327e..36b64e4 100644
--- a/python/liblvm.c
+++ b/python/liblvm.c
@@ -30,11 +30,13 @@ static lvm_t _libh;
typedef struct {
PyObject_HEAD
vg_t vg; /* vg handle */
+ lvm_t libh_copy;
} vgobject;
typedef struct {
PyObject_HEAD
struct dm_list *pvslist;
+ lvm_t libh_copy;
} pvslistobject;
typedef struct {
@@ -71,9 +73,14 @@ static PyTypeObject _LibLVMpvsegType;
static PyObject *_LibLVMError;
-#define LVM_VALID() \
+#define LVM_VALID(ptr) \
do { \
- if (!_libh) { \
+ if (ptr && _libh) { \
+ if (ptr != _libh) { \
+ PyErr_SetString(PyExc_UnboundLocalError, "LVM handle reference stale"); \
+ return NULL; \
+ } \
+ } else if (!_libh) { \
PyErr_SetString(PyExc_UnboundLocalError, "LVM handle invalid"); \
return NULL; \
} \
@@ -99,17 +106,42 @@ static vgobject *_create_py_vg(void)
{
vgobject *vgobj = PyObject_New(vgobject, &_LibLVMvgType);
- if (vgobj)
+ if (vgobj) {
vgobj->vg = NULL;
+ vgobj->libh_copy = _libh;
+ }
return vgobj;
}
+static pvslistobject *_create_py_pvlist(void)
+{
+ pvslistobject *pvlistobj = PyObject_New(pvslistobject, &_LibLVMpvlistType);
+
+ if (pvlistobj) {
+ pvlistobj->pvslist = NULL;
+ pvlistobj->libh_copy = _libh;
+ }
+
+ return pvlistobj;
+}
+
+static lvobject *_create_py_lv(vgobject *parent, lv_t lv)
+{
+ lvobject * lvobj = PyObject_New(lvobject, &_LibLVMlvType);
+ if (lvobj) {
+ lvobj->parent_vgobj = parent;
+ Py_INCREF(lvobj->parent_vgobj);
+ lvobj->lv = lv;
+ }
+ return lvobj;
+}
+
static PyObject *_liblvm_get_last_error(void)
{
PyObject *info;
- LVM_VALID();
+ LVM_VALID(NULL);
if (!(info = PyTuple_New(2)))
return NULL;
@@ -122,7 +154,7 @@ static PyObject *_liblvm_get_last_error(void)
static PyObject *_liblvm_library_get_version(void)
{
- LVM_VALID();
+ LVM_VALID(NULL);
return Py_BuildValue("s", lvm_library_get_version());
}
@@ -131,7 +163,7 @@ static const char _gc_doc[] = "Garbage collect the C library";
static PyObject *_liblvm_lvm_gc(void)
{
- LVM_VALID();
+ LVM_VALID(NULL);
lvm_quit(_libh);
@@ -152,7 +184,7 @@ static PyObject *_liblvm_lvm_list_vg_names(void)
PyObject * pytuple;
int i = 0;
- LVM_VALID();
+ LVM_VALID(NULL);
if (!(vgnames = lvm_list_vg_names(_libh))) {
PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
@@ -177,7 +209,7 @@ static PyObject *_liblvm_lvm_list_vg_uuids(void)
PyObject * pytuple;
int i = 0;
- LVM_VALID();
+ LVM_VALID(NULL);
if (!(uuids = lvm_list_vg_uuids(_libh))) {
PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
@@ -261,23 +293,16 @@ static PyObject *_liblvm_pvlist_dealloc(pvslistobject *self)
static PyObject *_liblvm_lvm_list_pvs(void)
{
- pvslistobject *pvslistobj;
-
- LVM_VALID();
-
- if (!(pvslistobj = PyObject_New(pvslistobject, &_LibLVMpvlistType)))
- return NULL;
+ LVM_VALID(NULL);
- pvslistobj->pvslist = NULL;
-
- return (PyObject *)pvslistobj;
+ return (PyObject *)_create_py_pvlist();
}
static PyObject *_liblvm_lvm_pv_remove(PyObject *self, PyObject *arg)
{
const char *pv_name;
- LVM_VALID();
+ LVM_VALID(NULL);
if (!PyArg_ParseTuple(arg, "s", &pv_name))
return NULL;
@@ -297,7 +322,7 @@ static PyObject *_liblvm_lvm_pv_create(PyObject *self, PyObject *arg)
const char *pv_name;
unsigned long long size;
- LVM_VALID();
+ LVM_VALID(NULL);
if (!PyArg_ParseTuple(arg, "sK", &pv_name, &size))
return NULL;
@@ -317,7 +342,7 @@ static PyObject *_liblvm_lvm_percent_to_float(PyObject *self, PyObject *arg)
double converted;
int percent;
- LVM_VALID();
+ LVM_VALID(NULL);
if (!PyArg_ParseTuple(arg, "i", &percent))
return NULL;
@@ -332,7 +357,7 @@ static PyObject *_liblvm_lvm_vgname_from_pvid(PyObject *self, PyObject *arg)
const char *pvid;
const char *vgname;
- LVM_VALID();
+ LVM_VALID(NULL);
if (!PyArg_ParseTuple(arg, "s", &pvid))
return NULL;
@@ -350,7 +375,7 @@ static PyObject *_liblvm_lvm_vgname_from_device(PyObject *self, PyObject *arg)
const char *device;
const char *vgname;
- LVM_VALID();
+ LVM_VALID(NULL);
if (!PyArg_ParseTuple(arg, "s", &device))
return NULL;
@@ -370,7 +395,7 @@ static PyObject *_liblvm_lvm_config_find_bool(PyObject *self, PyObject *arg)
int rval;
PyObject *rc;
- LVM_VALID();
+ LVM_VALID(NULL);
if (!PyArg_ParseTuple(arg, "s", &config))
return NULL;
@@ -390,7 +415,7 @@ static PyObject *_liblvm_lvm_config_find_bool(PyObject *self, PyObject *arg)
static PyObject *_liblvm_lvm_config_reload(void)
{
- LVM_VALID();
+ LVM_VALID(NULL);
if (lvm_config_reload(_libh) == -1) {
PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
@@ -405,7 +430,7 @@ static PyObject *_liblvm_lvm_config_reload(void)
static PyObject *_liblvm_lvm_scan(void)
{
- LVM_VALID();
+ LVM_VALID(NULL);
if (lvm_scan(_libh) == -1) {
PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
@@ -421,7 +446,7 @@ static PyObject *_liblvm_lvm_config_override(PyObject *self, PyObject *arg)
{
const char *config;
- LVM_VALID();
+ LVM_VALID(NULL);
if (!PyArg_ParseTuple(arg, "s", &config))
return NULL;
@@ -447,7 +472,7 @@ static PyObject *_liblvm_lvm_vg_open(PyObject *self, PyObject *args)
vgobject *vgobj;
- LVM_VALID();
+ LVM_VALID(NULL);
if (!PyArg_ParseTuple(args, "s|s", &vgname, &mode))
return NULL;
@@ -472,7 +497,7 @@ static PyObject *_liblvm_lvm_vg_create(PyObject *self, PyObject *args)
const char *vgname;
vgobject *vgobj;
- LVM_VALID();
+ LVM_VALID(NULL);
if (!PyArg_ParseTuple(args, "s", &vgname))
return NULL;
@@ -495,6 +520,7 @@ static void liblvm_vg_dealloc(vgobject *self)
if (self->vg != NULL) {
lvm_vg_close(self->vg);
self->vg = NULL;
+ self->libh_copy = NULL;
}
PyObject_Del(self);
@@ -504,20 +530,20 @@ static void liblvm_vg_dealloc(vgobject *self)
#define VG_VALID(vgobject) \
do { \
- LVM_VALID(); \
- if (!vgobject->vg) { \
+ if (!vgobject || !vgobject->vg) { \
PyErr_SetString(PyExc_UnboundLocalError, "VG object invalid"); \
return NULL; \
} \
+ LVM_VALID(vgobject->libh_copy); \
} while (0)
#define PVSLIST_VALID(pvslistobject) \
do { \
- LVM_VALID(); \
- if (!pvslistobject->pvslist) { \
+ if (!pvslistobject || !pvslistobject->pvslist) { \
PyErr_SetString(PyExc_UnboundLocalError, "PVS object invalid"); \
return NULL; \
} \
+ LVM_VALID(pvslistobject->libh_copy); \
} while (0)
static PyObject *_liblvm_lvm_vg_close(vgobject *self)
@@ -526,6 +552,7 @@ static PyObject *_liblvm_lvm_vg_close(vgobject *self)
if (self->vg) {
lvm_vg_close(self->vg);
self->vg = NULL;
+ self->libh_copy = NULL;
}
Py_INCREF(Py_None);
@@ -941,15 +968,11 @@ static PyObject *_liblvm_lvm_vg_list_lvs(vgobject *self)
dm_list_iterate_items(lvl, lvs) {
/* Create and initialize the object */
- if (!(lvobj = PyObject_New(lvobject, &_LibLVMlvType))) {
+ if (!(lvobj = _create_py_lv(self, lvl->lv))) {
Py_DECREF(pytuple);
return NULL;
}
- lvobj->parent_vgobj = self;
- Py_INCREF(lvobj->parent_vgobj);
-
- lvobj->lv = lvl->lv;
PyTuple_SET_ITEM(pytuple, i, (PyObject *) lvobj);
i++;
}
@@ -986,29 +1009,19 @@ static PyObject *_liblvm_lvm_vg_create_lv_linear(vgobject *self, PyObject *args)
{
const char *vgname;
unsigned long long size;
- lvobject *lvobj;
+ lv_t lv;
VG_VALID(self);
if (!PyArg_ParseTuple(args, "sK", &vgname, &size))
return NULL;
- if (!(lvobj = PyObject_New(lvobject, &_LibLVMlvType)))
- return NULL;
-
- /* Initialize the parent ptr in case lv create fails and we dealloc lvobj */
- lvobj->parent_vgobj = NULL;
-
- if (!(lvobj->lv = lvm_vg_create_lv_linear(self->vg, vgname, size))) {
+ if (!(lv = lvm_vg_create_lv_linear(self->vg, vgname, size))) {
PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
- Py_DECREF(lvobj);
return NULL;
}
- lvobj->parent_vgobj = self;
- Py_INCREF(lvobj->parent_vgobj);
-
- return (PyObject *)lvobj;
+ return (PyObject *)_create_py_lv(self, lv);
}
static PyObject *_liblvm_lvm_vg_create_lv_thinpool(vgobject *self, PyObject *args)
@@ -1019,7 +1032,7 @@ static PyObject *_liblvm_lvm_vg_create_lv_thinpool(vgobject *self, PyObject *arg
unsigned long chunk_size = 0;
int skip_zero = 0;
lvm_thin_discards_t discard = LVM_THIN_DISCARDS_PASSDOWN;
- lvobject *lvobj;
+ lv_t lv;
lv_create_params_t lvp = NULL;
struct lvm_property_value prop_value;
@@ -1029,17 +1042,10 @@ static PyObject *_liblvm_lvm_vg_create_lv_thinpool(vgobject *self, PyObject *arg
&meta_size, &discard, &skip_zero))
return NULL;
- if (!(lvobj = PyObject_New(lvobject, &_LibLVMlvType)))
- return NULL;
-
- /* Initialize the parent ptr in case lv create fails and we dealloc lvobj */
- lvobj->parent_vgobj = NULL;
-
if (!(lvp = lvm_lv_params_create_thin_pool(self->vg, pool_name, size, chunk_size,
meta_size, discard))) {
PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
- Py_DECREF(lvobj);
return NULL;
}
@@ -1051,23 +1057,20 @@ static PyObject *_liblvm_lvm_vg_create_lv_thinpool(vgobject *self, PyObject *arg
if (lvm_lv_params_set_property(lvp, "skip_zero",
&prop_value) == -1) {
- PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
- Py_DECREF(lvobj);
- return NULL;
+ goto error;
}
}
}
- if (!(lvobj->lv = lvm_lv_create(lvp))) {
- PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
- Py_DECREF(lvobj);
- return NULL;
+ if (!(lv = lvm_lv_create(lvp))) {
+ goto error;
}
- lvobj->parent_vgobj = self;
- Py_INCREF(lvobj->parent_vgobj);
+ return (PyObject *)_create_py_lv(self, lv);
- return (PyObject *)lvobj;
+error:
+ PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
+ return NULL;
}
static PyObject *_liblvm_lvm_vg_create_lv_thin(vgobject *self, PyObject *args)
@@ -1075,7 +1078,7 @@ static PyObject *_liblvm_lvm_vg_create_lv_thin(vgobject *self, PyObject *args)
const char *pool_name;
const char *lv_name;
unsigned long long size = 0;
- lvobject *lvobj;
+ lv_t lv;
lv_create_params_t lvp = NULL;
VG_VALID(self);
@@ -1083,28 +1086,17 @@ static PyObject *_liblvm_lvm_vg_create_lv_thin(vgobject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "ssK", &pool_name, &lv_name, &size))
return NULL;
- if (!(lvobj = PyObject_New(lvobject, &_LibLVMlvType)))
- return NULL;
-
- /* Initialize the parent ptr in case lv create fails and we dealloc lvobj */
- lvobj->parent_vgobj = NULL;
-
if (!(lvp = lvm_lv_params_create_thin(self->vg, pool_name, lv_name,size))) {
PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
- Py_DECREF(lvobj);
return NULL;
}
- if (!(lvobj->lv = lvm_lv_create(lvp))) {
+ if (!(lv = lvm_lv_create(lvp))) {
PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
- Py_DECREF(lvobj);
return NULL;
}
- lvobj->parent_vgobj = self;
- Py_INCREF(lvobj->parent_vgobj);
-
- return (PyObject *)lvobj;
+ return (PyObject *)_create_py_lv(self, lv);
}
static void liblvm_lv_dealloc(lvobject *self)
@@ -1157,7 +1149,6 @@ typedef pv_t (*pv_fetch_by_N)(vg_t vg, const char *id);
static PyObject *_liblvm_lvm_lv_from_N(vgobject *self, PyObject *arg, lv_fetch_by_N method)
{
const char *id;
- lvobject *lvobj;
lv_t lv = NULL;
VG_VALID(self);
@@ -1170,15 +1161,7 @@ static PyObject *_liblvm_lvm_lv_from_N(vgobject *self, PyObject *arg, lv_fetch_b
return NULL;
}
- if (!(lvobj = PyObject_New(lvobject, &_LibLVMlvType)))
- return NULL;
-
- lvobj->parent_vgobj = self;
- Py_INCREF(lvobj->parent_vgobj);
-
- lvobj->lv = lv;
-
- return (PyObject *)lvobj;
+ return (PyObject *)_create_py_lv(self, lv);
}
static PyObject *_liblvm_lvm_lv_from_name(vgobject *self, PyObject *arg)
@@ -1242,12 +1225,12 @@ static void _liblvm_pv_dealloc(pvobject *self)
/* LV Methods */
#define LV_VALID(lvobject) \
- do { \
- VG_VALID(lvobject->parent_vgobj); \
- if (!lvobject->lv) { \
+ do { \
+ if (!lvobject || !lvobject->lv) { \
PyErr_SetString(PyExc_UnboundLocalError, "LV object invalid"); \
- return NULL; \
- } \
+ return NULL; \
+ }\
+ VG_VALID(lvobject->parent_vgobj); \
} while (0)
static PyObject *_liblvm_lvm_lv_get_attr(lvobject *self)
@@ -1510,7 +1493,7 @@ static PyObject *_liblvm_lvm_lv_snapshot(lvobject *self, PyObject *args)
{
const char *snap_name;
unsigned long long size = 0;
- lvobject *lvobj;
+ lv_t lv;
lv_create_params_t lvp = NULL;
LV_VALID(self);
@@ -1518,43 +1501,33 @@ static PyObject *_liblvm_lvm_lv_snapshot(lvobject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "s|K", &snap_name, &size))
return NULL;
- if (!(lvobj = PyObject_New(lvobject, &_LibLVMlvType)))
- return NULL;
-
- lvobj->parent_vgobj = NULL;
-
if (!(lvp = lvm_lv_params_create_snapshot(self->lv, snap_name, size))) {
PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
- Py_DECREF(lvobj);
return NULL;
}
- if (!(lvobj->lv = lvm_lv_create(lvp))) {
+ if (!(lv = lvm_lv_create(lvp))) {
PyErr_SetObject(_LibLVMError, _liblvm_get_last_error());
- Py_DECREF(lvobj);
return NULL;
}
- lvobj->parent_vgobj = self->parent_vgobj;
- Py_INCREF(lvobj->parent_vgobj);
-
- return (PyObject *)lvobj;
+ return (PyObject *)_create_py_lv(self->parent_vgobj, lv);
}
/* PV Methods */
#define PV_VALID(pvobject) \
do { \
+ if (!pvobject || !pvobject->pv) { \
+ PyErr_SetString(PyExc_UnboundLocalError, "PV object invalid"); \
+ return NULL; \
+ } \
if (pvobject->parent_vgobj) { \
VG_VALID(pvobject->parent_vgobj); \
} \
if (pvobject->parent_pvslistobj) { \
PVSLIST_VALID(pvobject->parent_pvslistobj); \
} \
- if (!pvobject->pv) { \
- PyErr_SetString(PyExc_UnboundLocalError, "PV object invalid"); \
- return NULL; \
- } \
} while (0)
static PyObject *_liblvm_lvm_pv_get_name(pvobject *self)
@@ -1673,7 +1646,14 @@ static PyObject *_liblvm_lvm_pv_list_pvsegs(pvobject *self)
* No way to close/destroy an lvseg, just need to make sure parents are
* still good
*/
-#define LVSEG_VALID(lvsegobject) LV_VALID(lvsegobject->parent_lvobj)
+#define LVSEG_VALID(lvsegobject) \
+ do { \
+ if ( !lvsegobject || !lvsegobject->parent_lvobj ) { \
+ PyErr_SetString(PyExc_UnboundLocalError, "LV segment object invalid"); \
+ return NULL; \
+ } \
+ LV_VALID(lvsegobject->parent_lvobj); \
+ } while(0)
static void _liblvm_lvseg_dealloc(lvsegobject *self)
{
@@ -1702,7 +1682,14 @@ static PyObject *_liblvm_lvm_lvseg_get_property(lvsegobject *self, PyObject *arg
* No way to close/destroy a pvseg, just need to make sure parents are
* still good
*/
-#define PVSEG_VALID(pvsegobject) PV_VALID(pvsegobject->parent_pvobj)
+#define PVSEG_VALID(pvsegobject) \
+ do { \
+ if (!pvsegobject || !pvsegobject->parent_pvobj) { \
+ PyErr_SetString(PyExc_UnboundLocalError, "PV segment object invalid"); \
+ return NULL; \
+ } \
+ PV_VALID(pvsegobject->parent_pvobj); \
+ } while(0)
static void _liblvm_pvseg_dealloc(pvsegobject *self)
{
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=1f744733a15fe564…
Commit: 1f744733a15fe56404dbd0c4d8e1aab339fef774
Parent: b0b061cdbc4856cf6f5b43bd9ae835e678440890
Author: Tony Asleson <tasleson(a)redhat.com>
AuthorDate: Wed Jul 31 12:56:41 2013 -0400
Committer: Tony Asleson <tasleson(a)redhat.com>
CommitterDate: Tue Nov 19 14:40:25 2013 -0600
python-lvm: Correct names
The existing names do not follow accepted guidelines.
Signed-off-by: Tony Asleson <tasleson(a)redhat.com>
---
python/liblvm.c | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/python/liblvm.c b/python/liblvm.c
index a9de817..42a327e 100644
--- a/python/liblvm.c
+++ b/python/liblvm.c
@@ -1846,7 +1846,7 @@ static PyMethodDef _liblvm_pvseg_methods[] = {
static PyTypeObject _LibLVMvgType = {
PyObject_HEAD_INIT(&PyType_Type)
- .tp_name = "liblvm.Liblvm_vg",
+ .tp_name = "lvm.Liblvm_vg",
.tp_basicsize = sizeof(vgobject),
.tp_new = PyType_GenericNew,
.tp_dealloc = (destructor)liblvm_vg_dealloc,
@@ -1857,7 +1857,7 @@ static PyTypeObject _LibLVMvgType = {
static PyTypeObject _LibLVMlvType = {
PyObject_HEAD_INIT(&PyType_Type)
- .tp_name = "liblvm.Liblvm_lv",
+ .tp_name = "lvm.Liblvm_lv",
.tp_basicsize = sizeof(lvobject),
.tp_new = PyType_GenericNew,
.tp_dealloc = (destructor)liblvm_lv_dealloc,
@@ -1868,7 +1868,7 @@ static PyTypeObject _LibLVMlvType = {
static PyTypeObject _LibLVMpvlistType = {
PyObject_HEAD_INIT(&PyType_Type)
- .tp_name = "liblvm.Liblvm_pvlist",
+ .tp_name = "lvm.Liblvm_pvlist",
.tp_basicsize = sizeof(pvslistobject),
.tp_new = PyType_GenericNew,
.tp_dealloc = (destructor)_liblvm_pvlist_dealloc,
@@ -1879,7 +1879,7 @@ static PyTypeObject _LibLVMpvlistType = {
static PyTypeObject _LibLVMpvType = {
PyObject_HEAD_INIT(&PyType_Type)
- .tp_name = "liblvm.Liblvm_pv",
+ .tp_name = "lvm.Liblvm_pv",
.tp_basicsize = sizeof(pvobject),
.tp_new = PyType_GenericNew,
.tp_dealloc = (destructor)_liblvm_pv_dealloc,
@@ -1890,7 +1890,7 @@ static PyTypeObject _LibLVMpvType = {
static PyTypeObject _LibLVMlvsegType = {
PyObject_HEAD_INIT(&PyType_Type)
- .tp_name = "liblvm.Liblvm_lvseg",
+ .tp_name = "lvm.Liblvm_lvseg",
.tp_basicsize = sizeof(lvsegobject),
.tp_new = PyType_GenericNew,
.tp_dealloc = (destructor)_liblvm_lvseg_dealloc,
@@ -1901,7 +1901,7 @@ static PyTypeObject _LibLVMlvsegType = {
static PyTypeObject _LibLVMpvsegType = {
PyObject_HEAD_INIT(&PyType_Type)
- .tp_name = "liblvm.Liblvm_pvseg",
+ .tp_name = "lvm.Liblvm_pvseg",
.tp_basicsize = sizeof(pvsegobject),
.tp_new = PyType_GenericNew,
.tp_dealloc = (destructor)_liblvm_pvseg_dealloc,
@@ -1952,7 +1952,7 @@ PyMODINIT_FUNC initlvm(void)
LVM_THIN_DISCARDS_PASSDOWN) < 0)
return;
- if ((_LibLVMError = PyErr_NewException("Liblvm._LibLVMError", NULL, NULL))) {
+ if ((_LibLVMError = PyErr_NewException("lvm.LibLVMError", NULL, NULL))) {
/* Each call to PyModule_AddObject decrefs it; compensate: */
Py_INCREF(_LibLVMError);
Py_INCREF(_LibLVMError);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b0b061cdbc4856cf…
Commit: b0b061cdbc4856cf6f5b43bd9ae835e678440890
Parent: fe609141a894d33b92a6eb5fb9b5ee62bdc6c4ee
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Nov 19 11:47:28 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Nov 19 11:49:33 2013 +0100
tests: skip raid test on 3.12.0
3.12.0 kernel prevents raid test to be usable,
leaving unremovable devices in table.
This needs to be fixed ASAP, meanwhile disable test to make
test machines at least usable.
---
test/lib/aux.sh | 6 ++++++
test/shell/lvconvert-raid.sh | 5 +----
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index 6f21e8b..4ef1132 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -689,6 +689,12 @@ target_at_least()
dm-*) modprobe "$1" || true ;;
esac
+ if test "$1" = dm-raid; then
+ case "$(uname -r)" in
+ 3.12.0*) return 1 ;;
+ esac
+ fi
+
local version=$(dmsetup targets 2>/dev/null | grep "${1##dm-} " 2>/dev/null)
version=${version##* v}
shift
diff --git a/test/shell/lvconvert-raid.sh b/test/shell/lvconvert-raid.sh
index 680710e..0bdb023 100644
--- a/test/shell/lvconvert-raid.sh
+++ b/test/shell/lvconvert-raid.sh
@@ -22,10 +22,7 @@ get_image_pvs() {
########################################################
# MAIN
########################################################
-if ! aux target_at_least dm-raid 1 2 0; then
- dmsetup targets | grep raid
- skip
-fi
+aux target_at_least dm-raid 1 2 0 || skip
# 9 PVs needed for RAID10 testing (3-stripes/2-mirror - replacing 3 devs)
aux prepare_pvs 9 80
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fe609141a894d33b…
Commit: fe609141a894d33b92a6eb5fb9b5ee62bdc6c4ee
Parent: c697f501c7d9f29b6e0b32225b962d1632654004
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 15 23:47:14 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Nov 19 10:55:14 2013 +0100
tests: on 32bit test with <16T devs
Add 'can_use_16T' to detect systems where we could
safely use 16T devices without causing system deadlocks.
16T size leads on those to endless loops in udevd
- it calls blkid which tries cached read from such device
- this ends in endless loop.
Related problems:
https://bugzilla.redhat.com/show_bug.cgi?id=1015028
---
test/lib/aux.sh | 6 ++++++
test/shell/lvconvert-thin.sh | 9 ++++++++-
test/shell/lvcreate-large-raid.sh | 3 +++
test/shell/lvcreate-large-raid10.sh | 3 +++
test/shell/lvcreate-large.sh | 3 +++
test/shell/snapshot-usage.sh | 11 ++++++++++-
6 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index f51fc0d..6f21e8b 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -670,6 +670,12 @@ wait_for_sync() {
return 1
}
+# Check if tests are running on 64bit architecture
+can_use_16T()
+{
+ test "$(getconf LONG_BIT)" -eq 64
+}
+
#
# Check wheter kernel [dm module] target exist
# at least in expected version
diff --git a/test/shell/lvconvert-thin.sh b/test/shell/lvconvert-thin.sh
index 0081e45..d177f9a 100644
--- a/test/shell/lvconvert-thin.sh
+++ b/test/shell/lvconvert-thin.sh
@@ -28,7 +28,11 @@ aux prepare_pvs 4 64
# build one large PV
vgcreate $vg1 $(cut -d ' ' -f -3 DEVICES)
-lvcreate -s -l 100%FREE -n $lv $vg1 --virtualsize 64T
+# 32bit linux kernels are fragille with device size >= 16T
+# maybe uname -m [ x86_64 | i686 ]
+TSIZE=64T
+aux can_use_16T || TSIZE=15T
+lvcreate -s -l 100%FREE -n $lv $vg1 --virtualsize $TSIZE
aux extend_filter_LVMTEST
pvcreate "$DM_DEV_DIR/$vg1/$lv"
@@ -97,10 +101,13 @@ lvconvert --thinpool $vg/$lv1 --poolmetadata $vg/$lv2 |& tee err
grep "WARNING: Maximum size" err
lvremove -f $vg
+
+if test "$TSIZE" -eq 64T; then
lvcreate -L24T -n $lv1 $vg
# Warning about bigger then needed (24T data and 16G -> 128K chunk)
lvconvert -c 64 --thinpool $vg/$lv1 |& tee err
grep "WARNING: Chunk size is too small" err
+fi
#lvs -a -o+chunk_size,stripe_size,seg_pe_ranges
diff --git a/test/shell/lvcreate-large-raid.sh b/test/shell/lvcreate-large-raid.sh
index a91da05..395cf2b 100644
--- a/test/shell/lvcreate-large-raid.sh
+++ b/test/shell/lvcreate-large-raid.sh
@@ -13,6 +13,9 @@
. lib/test
+# FIXME update test to make something useful on <16T
+aux can_use_16T || skip
+
aux target_at_least dm-raid 1 1 0 || skip
aux prepare_vg 5
diff --git a/test/shell/lvcreate-large-raid10.sh b/test/shell/lvcreate-large-raid10.sh
index d971d74..4f97997 100644
--- a/test/shell/lvcreate-large-raid10.sh
+++ b/test/shell/lvcreate-large-raid10.sh
@@ -13,6 +13,9 @@
. lib/test
+# FIXME update test to make something useful on <16T
+aux can_use_16T || skip
+
aux target_at_least dm-raid 1 3 0 || skip
aux prepare_vg 5
diff --git a/test/shell/lvcreate-large.sh b/test/shell/lvcreate-large.sh
index 63b2b03..c8790f1 100644
--- a/test/shell/lvcreate-large.sh
+++ b/test/shell/lvcreate-large.sh
@@ -13,6 +13,9 @@
. lib/test
+# FIXME update test to make something useful on <16T
+aux can_use_16T || skip
+
aux prepare_vg 4
lvcreate -s -l 100%FREE -n $lv $vg --virtualsize 1024T
diff --git a/test/shell/snapshot-usage.sh b/test/shell/snapshot-usage.sh
index 3d4d308..9e6a14f 100644
--- a/test/shell/snapshot-usage.sh
+++ b/test/shell/snapshot-usage.sh
@@ -27,7 +27,10 @@ cleanup_tail()
aux prepare_pvs 1
vgcreate -s 4M $vg $(cat DEVICES)
-lvcreate -s -l 100%FREE -n $lv $vg --virtualsize 15P
+TSIZE=15P
+aux can_use_16T || TSIZE=15T
+
+lvcreate -s -l 100%FREE -n $lv $vg --virtualsize $TSIZE
aux extend_filter_LVMTEST
aux lvmconf "activation/snapshot_autoextend_percent = 20" \
@@ -106,6 +109,9 @@ check lv_field $vg1/lvol1 size "28.00k"
fill 20K
vgremove -ff $vg1
+# Can't test >= 16T devices on 32bit
+if test "$TSIZE" -eq 15P ; then
+
# Check usability with largest extent size
pvcreate $DM_DEV_DIR/$vg/$lv
vgcreate -s 4G $vg1 $DM_DEV_DIR/$vg/$lv
@@ -119,4 +125,7 @@ lvcreate -aey -V15E -l1 -n $lv1 -s $vg1
check lv_field $vg1/$lv1 origin_size "15.00e"
vgremove -ff $vg1
+
+fi
+
vgremove -ff $vg
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c697f501c7d9f29b…
Commit: c697f501c7d9f29b6e0b32225b962d1632654004
Parent: 3a6f91d7139119bea664050a957cbc21490398bc
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 15 23:44:18 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Nov 19 10:55:11 2013 +0100
Makefile: fix build in non src dir
Fix 'make install' from builddir != srcdir.
---
WHATS_NEW | 1 +
conf/Makefile.in | 2 +-
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 0a4909a..bd18c6f 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Fix install of conf subdir when not building in srcdir.
Add reporting of thin_id device id for thin volumes.
Fix reporting of empty numerical values.
Simplify reporting code.
diff --git a/conf/Makefile.in b/conf/Makefile.in
index 8b5238a..3f66621 100644
--- a/conf/Makefile.in
+++ b/conf/Makefile.in
@@ -19,7 +19,7 @@ CONFSRC=example.conf
CONFDEST=lvm.conf
DEFAULT_PROFILE=default.profile
-PROFILES=$(DEFAULT_PROFILE) thin-performance.profile
+PROFILES=$(DEFAULT_PROFILE) $(srcdir)/thin-performance.profile
include $(top_builddir)/make.tmpl
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3a6f91d7139119be…
Commit: 3a6f91d7139119bea664050a957cbc21490398bc
Parent: 03d3e1d9c17e959dc78a5bfa82cd69878653a9d2
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Nov 18 18:00:49 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Mon Nov 18 18:00:49 2013 +0100
metadata: Make the fid mda routines a little more resilient.
---
lib/metadata/metadata.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index aa5f124..398def6 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -4400,6 +4400,9 @@ int fid_add_mda(struct format_instance *fid, struct metadata_area *mda,
if (!key)
return 1;
+ if (!fid->metadata_areas_index)
+ return_0;
+
/* Add metadata area to index. */
if (!_convert_key_to_string(key, key_len, sub_key,
full_key, sizeof(full_key)))
@@ -4439,10 +4442,13 @@ struct metadata_area *fid_get_mda_indexed(struct format_instance *fid,
static char full_key[PATH_MAX];
struct metadata_area *mda = NULL;
+ if (!fid->metadata_areas_index)
+ return_NULL;
if (!_convert_key_to_string(key, key_len, sub_key,
full_key, sizeof(full_key)))
return_NULL;
+
mda = (struct metadata_area *) dm_hash_lookup(fid->metadata_areas_index,
full_key);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=03d3e1d9c17e959d…
Commit: 03d3e1d9c17e959dc78a5bfa82cd69878653a9d2
Parent: b8a6b8f467fadd5334fdb0c4a149753916e097db
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Nov 18 17:53:45 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Mon Nov 18 17:53:45 2013 +0100
lvmetad: Set up device pointers in synthetic lvmcache_infos.
---
lib/cache/lvmetad.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c
index 8940704..5119ab1 100644
--- a/lib/cache/lvmetad.c
+++ b/lib/cache/lvmetad.c
@@ -277,6 +277,7 @@ static struct lvmcache_info *_pv_populate_lvmcache(
return_NULL;
lvmcache_get_label(info)->sector = label_sector;
+ lvmcache_get_label(info)->dev = dev;
lvmcache_set_device_size(info, devsize);
lvmcache_del_das(info);
lvmcache_del_mdas(info);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b8a6b8f467fadd53…
Commit: b8a6b8f467fadd5334fdb0c4a149753916e097db
Parent: ae337d472eb973bbde80d641da9567acfa7874ff
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Nov 18 17:53:06 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Mon Nov 18 17:53:06 2013 +0100
test: Force label-based reporting in pv-duplicate.sh.
---
test/shell/pv-duplicate.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/test/shell/pv-duplicate.sh b/test/shell/pv-duplicate.sh
index 40d1f68..f315d86 100644
--- a/test/shell/pv-duplicate.sh
+++ b/test/shell/pv-duplicate.sh
@@ -21,5 +21,5 @@ vgcreate --metadatasize 128k $vg1 "$dev1"
dd if="$dev1" of="$dev2" bs=256K count=1
dd if="$dev1" of="$dev3" bs=256K count=1
-pvs "$dev3"
+pvs "$dev3" -o pv_uuid
vgs $vg1
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ae337d472eb973bb…
Commit: ae337d472eb973bbde80d641da9567acfa7874ff
Parent: ecc296311ff2a251aa254353b0a0fb3ee97be97c
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Sun Nov 17 22:36:13 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 22:36:13 2013 +0100
report: Print UUIDs for missing PVs when possible.
---
test/shell/listings.sh | 3 +++
tools/reporter.c | 8 +++++++-
2 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/test/shell/listings.sh b/test/shell/listings.sh
index 0d4c83f..e5a3954 100644
--- a/test/shell/listings.sh
+++ b/test/shell/listings.sh
@@ -69,3 +69,6 @@ vgs -o pv_name,vg_name $vg
pvdisplay $(cat DEVICES) >out
pvdisplay --maps $(cat DEVICES) >out2
not diff out out2
+
+aux disable_dev $dev1
+pvs -o +pv_uuid | grep BADBEE-BAAD-BAAD-BAAD-BAAD-BAAD-BADBEE
diff --git a/tools/reporter.c b/tools/reporter.c
index fb01686..dccd785 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -142,6 +142,7 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
char uuid[64] __attribute__((aligned(8)));
struct label *label;
struct label _dummy_label = { 0 };
+ struct device _dummy_device = { 0 };
if (is_pv(pv) && !is_orphan(pv) && !vg) {
vg_name = pv_vg_name(pv);
@@ -182,7 +183,12 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
/* FIXME workaround for pv_label going through cache; remove once struct
* physical_volume gains a proper "label" pointer */
if (!(label = pv_label(pv))) {
- _dummy_label.dev = pv->dev;
+ if (pv->dev)
+ _dummy_label.dev = pv->dev;
+ else {
+ _dummy_label.dev = &_dummy_device;
+ memcpy(_dummy_device.pvid, &pv->id, ID_LEN);
+ }
label = &_dummy_label;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ecc296311ff2a251…
Commit: ecc296311ff2a251aa254353b0a0fb3ee97be97c
Parent: a5bb1b48eea704c5970a719d2e77577dccd82bb9
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Sun Nov 17 22:35:16 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 22:35:16 2013 +0100
metadata: Do not throw an error in pv_label for missing PVs.
---
lib/metadata/pv.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/metadata/pv.c b/lib/metadata/pv.c
index 1d608f2..349048e 100644
--- a/lib/metadata/pv.c
+++ b/lib/metadata/pv.c
@@ -355,7 +355,7 @@ struct label *pv_label(const struct physical_volume *pv)
struct lvmcache_info *info =
lvmcache_info_from_pvid((const char *)&pv->id.uuid, 0);
if (!info) {
- if (pv->vg) /* process_each_pv will create PVs that are dummy
+ if (pv->vg && pv->dev) /* process_each_pv will create PVs that are dummy
* and that have no label associated */
log_error(INTERNAL_ERROR "PV %s unexpectedly not in cache.",
dev_name(pv->dev));
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a5bb1b48eea704c5…
Commit: a5bb1b48eea704c5970a719d2e77577dccd82bb9
Parent: 71b6565529028fcc075c52595fde380c96065cc9
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Sun Nov 17 22:34:56 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 22:34:56 2013 +0100
dev-cache.c: Make dev_name a little more robust.
---
lib/device/dev-cache.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index 46e5d65..9451314 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -1036,6 +1036,6 @@ int dev_fd(struct device *dev)
const char *dev_name(const struct device *dev)
{
- return (dev) ? dm_list_item(dev->aliases.n, struct str_list)->str :
+ return (dev && dev->aliases.n) ? dm_list_item(dev->aliases.n, struct str_list)->str :
"unknown device";
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=71b6565529028fcc…
Commit: 71b6565529028fcc075c52595fde380c96065cc9
Parent: 14ffc9d4df952346ce4338939b3ed869b8b491b4
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Sun Nov 17 21:04:07 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:43:06 2013 +0100
report: Convert pv_mda_size to a type "label" field.
---
lib/report/columns.h | 2 +-
lib/report/report.c | 5 ++---
test/shell/pvcreate-usage.sh | 1 +
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lib/report/columns.h b/lib/report/columns.h
index 0617605..93b5575 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -71,7 +71,7 @@ FIELD(LABEL, label, STR, "PV UUID", type, 38, pvuuid, pv_uuid, "Unique identifie
FIELD(LABEL, label, NUM, "DevSize", dev, 7, devsize, dev_size, "Size of underlying device in current units.", 0)
FIELD(LABEL, label, STR, "PV", dev, 10, dev_name, pv_name, "Name.", 0)
FIELD(LABEL, label, NUM, "PMdaFree", type, 9, pvmdafree, pv_mda_free, "Free metadata area space on this device in current units.", 0)
-FIELD(LABEL, pv, NUM, "PMdaSize", id, 9, pvmdasize, pv_mda_size, "Size of smallest metadata area on this device in current units.", 0)
+FIELD(LABEL, label, NUM, "PMdaSize", type, 9, pvmdasize, pv_mda_size, "Size of smallest metadata area on this device in current units.", 0)
FIELD(PVS, pv, NUM, "1st PE", pe_start, 7, size64, pe_start, "Offset to the start of data on the underlying device.", 0)
FIELD(PVS, pv, NUM, "PSize", id, 5, pvsize, pv_size, "Size of PV in current units.", 0)
diff --git a/lib/report/report.c b/lib/report/report.c
index e4ad2c3..9cb2298 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -820,9 +820,8 @@ static int _pvmdasize_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
{
- const struct physical_volume *pv =
- (const struct physical_volume *) data;
- uint64_t min_mda_size = pv_mda_size(pv);
+ const struct label *label = (const struct label *) data;
+ uint64_t min_mda_size = lvmcache_smallest_mda_size(label->info);
return _size64_disp(rh, mem, field, &min_mda_size, private);
}
diff --git a/test/shell/pvcreate-usage.sh b/test/shell/pvcreate-usage.sh
index c78e4bd..251746d 100644
--- a/test/shell/pvcreate-usage.sh
+++ b/test/shell/pvcreate-usage.sh
@@ -34,6 +34,7 @@ pvremove "$dev1"
pvcreate --metadatasize 512k "$dev1"
pvcreate --metadatasize 96k "$dev2"
vgcreate $vg "$dev1" "$dev2"
+pvs -o +pv_mda_size
check compare_fields vgs $vg vg_mda_size pvs "$dev2" pv_mda_size
vgremove $vg
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=14ffc9d4df952346…
Commit: 14ffc9d4df952346ce4338939b3ed869b8b491b4
Parent: 22942821841da6e84f3fd6c988ed6a3a37401ba6
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Wed Aug 28 14:11:59 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:43:06 2013 +0100
reporter: Adapt pvseg reporting to label-type fields.
---
lib/report/report.c | 11 ++++++++---
tools/reporter.c | 2 +-
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/lib/report/report.c b/lib/report/report.c
index 9fd75bb..e4ad2c3 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -727,10 +727,15 @@ static int _pvuuid_disp(struct dm_report *rh __attribute__((unused)), struct dm_
const struct label *label = (const struct label *) data;
char *repstr = NULL;
- if (!(repstr = id_format_and_copy(mem, label->dev->pvid)))
- return_0;
+ if (!label->dev)
+ dm_report_field_set_value(field, "", NULL);
+ else {
+ if (!(repstr = id_format_and_copy(mem, label->dev->pvid)))
+ return_0;
+
+ dm_report_field_set_value(field, repstr, NULL);
+ }
- dm_report_field_set_value(field, repstr, NULL);
return 1;
}
diff --git a/tools/reporter.c b/tools/reporter.c
index 28e178c..fb01686 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -107,7 +107,7 @@ static int _pvsegs_sub_single(struct cmd_context *cmd,
dm_list_init(&_free_logical_volume.snapshot_segs);
if (!report_object(handle, vg, seg ? seg->lv : &_free_logical_volume, pvseg->pv,
- seg ? : &_free_lv_segment, pvseg, NULL)) {
+ seg ? : &_free_lv_segment, pvseg, pv_label(pvseg->pv))) {
ret = ECMD_FAILED;
goto_out;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=22942821841da6e8…
Commit: 22942821841da6e84f3fd6c988ed6a3a37401ba6
Parent: d5095222fa4f8cea89b721dcb12adad89176413e
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Wed Aug 28 14:07:26 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:43:06 2013 +0100
reporter: Deal correctly with dummy PVs/labels.
---
lib/report/report.c | 2 +-
tools/reporter.c | 12 +++++++++---
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/lib/report/report.c b/lib/report/report.c
index dee4ea2..9fd75bb 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -184,7 +184,7 @@ static int _pvfmt_disp(struct dm_report *rh, struct dm_pool *mem,
const struct label *l =
(const struct label *) data;
- if (!l->labeller->fmt) {
+ if (!l->labeller || !l->labeller->fmt) {
dm_report_field_set_value(field, "", NULL);
return 1;
}
diff --git a/tools/reporter.c b/tools/reporter.c
index a15f8ef..28e178c 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -141,6 +141,7 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
struct volume_group *old_vg = vg;
char uuid[64] __attribute__((aligned(8)));
struct label *label;
+ struct label _dummy_label = { 0 };
if (is_pv(pv) && !is_orphan(pv) && !vg) {
vg_name = pv_vg_name(pv);
@@ -178,9 +179,14 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
pv = pvl->pv;
}
- if ((!(label = pv_label(pv))) ||
- (!report_object(handle, vg, NULL, pv, NULL, NULL, label)))
- {
+ /* FIXME workaround for pv_label going through cache; remove once struct
+ * physical_volume gains a proper "label" pointer */
+ if (!(label = pv_label(pv))) {
+ _dummy_label.dev = pv->dev;
+ label = &_dummy_label;
+ }
+
+ if (!report_object(handle, vg, NULL, pv, NULL, NULL, label)) {
stack;
ret = ECMD_FAILED;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d5095222fa4f8cea…
Commit: d5095222fa4f8cea89b721dcb12adad89176413e
Parent: 67c563ac2b643f97602686dc07cee4a8bdb5bc34
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Wed Aug 21 01:32:51 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:43:06 2013 +0100
toollib: Report errors on non-PV arguments to process_each_label.
---
tools/toollib.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index 529088c..9a33e55 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1821,8 +1821,12 @@ int process_each_label(struct cmd_context *cmd, int argc, char **argv, void *han
continue;
}
- if (!label_read(dev, &label, 0))
+ if (!label_read(dev, &label, 0)) {
+ log_error("No physical volume label read from %s",
+ argv[opt]);
+ ret_max = ECMD_FAILED;
continue;
+ }
ret = process_single_label(cmd, label, handle);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=67c563ac2b643f97…
Commit: 67c563ac2b643f97602686dc07cee4a8bdb5bc34
Parent: a8aa8d4b5c5722cab871c3243a203d26d6f5ac83
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Wed Aug 21 01:30:38 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:43:06 2013 +0100
pv_label: NULL result is not always an internal error.
---
lib/metadata/pv.c | 5 ++++-
1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/lib/metadata/pv.c b/lib/metadata/pv.c
index 0288f07..1d608f2 100644
--- a/lib/metadata/pv.c
+++ b/lib/metadata/pv.c
@@ -355,7 +355,10 @@ struct label *pv_label(const struct physical_volume *pv)
struct lvmcache_info *info =
lvmcache_info_from_pvid((const char *)&pv->id.uuid, 0);
if (!info) {
- log_error(INTERNAL_ERROR "PV %s unexpectedly not in cache.", dev_name(pv->dev));
+ if (pv->vg) /* process_each_pv will create PVs that are dummy
+ * and that have no label associated */
+ log_error(INTERNAL_ERROR "PV %s unexpectedly not in cache.",
+ dev_name(pv->dev));
return NULL;
}
return lvmcache_get_label(info);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a8aa8d4b5c5722ca…
Commit: a8aa8d4b5c5722cab871c3243a203d26d6f5ac83
Parent: 67a7b7a87da65b2350f975272e581be5f41976e0
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 19:15:31 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:43:06 2013 +0100
report: Make PV UUID into a "label" type field.
---
lib/report/columns.h | 2 +-
lib/report/report.c | 14 ++++++++++++++
test/shell/listings.sh | 4 +++-
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/lib/report/columns.h b/lib/report/columns.h
index 8a87d11..0617605 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -66,8 +66,8 @@ FIELD(LVS, lv, STR, "Time", lvid, 26, lvtime, lv_time, "Creation time of the LV,
FIELD(LVS, lv, STR, "Host", lvid, 10, lvhost, lv_host, "Creation host of the LV, if known.", 0)
FIELD(LVS, lv, STR, "Modules", lvid, 7, modules, lv_modules, "Kernel device-mapper modules required for this LV.", 0)
-FIELD(LABEL, pv, STR, "PV UUID", id, 38, uuid, pv_uuid, "Unique identifier.", 0)
FIELD(LABEL, label, STR, "Fmt", type, 3, pvfmt, pv_fmt, "Type of metadata.", 0)
+FIELD(LABEL, label, STR, "PV UUID", type, 38, pvuuid, pv_uuid, "Unique identifier.", 0)
FIELD(LABEL, label, NUM, "DevSize", dev, 7, devsize, dev_size, "Size of underlying device in current units.", 0)
FIELD(LABEL, label, STR, "PV", dev, 10, dev_name, pv_name, "Name.", 0)
FIELD(LABEL, label, NUM, "PMdaFree", type, 9, pvmdafree, pv_mda_free, "Free metadata area space on this device in current units.", 0)
diff --git a/lib/report/report.c b/lib/report/report.c
index 3f716b5..dee4ea2 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -720,6 +720,20 @@ static int _uuid_disp(struct dm_report *rh __attribute__((unused)), struct dm_po
return _field_set_value(field, repstr, NULL);
}
+static int _pvuuid_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem,
+ struct dm_report_field *field,
+ const void *data, void *private __attribute__((unused)))
+{
+ const struct label *label = (const struct label *) data;
+ char *repstr = NULL;
+
+ if (!(repstr = id_format_and_copy(mem, label->dev->pvid)))
+ return_0;
+
+ dm_report_field_set_value(field, repstr, NULL);
+ return 1;
+}
+
static int _pvmdas_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
diff --git a/test/shell/listings.sh b/test/shell/listings.sh
index 30df79f..0d4c83f 100644
--- a/test/shell/listings.sh
+++ b/test/shell/listings.sh
@@ -17,7 +17,7 @@
aux prepare_devs 5
-pvcreate "$dev1"
+pvcreate --uuid BADBEE-BAAD-BAAD-BAAD-BAAD-BAAD-BADBEE --norestorefile "$dev1"
pvcreate --metadatacopies 0 "$dev2"
pvcreate --metadatacopies 0 "$dev3"
pvcreate "$dev4"
@@ -31,6 +31,8 @@ test $(pvs --noheadings -o seg_all,pv_all,lv_all,vg_all $(cat DEVICES) | wc -l)
vgcreate $vg $(cat DEVICES)
+check pv_field $dev1 pv_uuid BADBEE-BAAD-BAAD-BAAD-BAAD-BAAD-BADBEE
+
#COMM pvs and vgs report mda_count, mda_free (bz202886, bz247444)
pvs -o +pv_mda_count,pv_mda_free $(cat DEVICES)
for I in "$dev2" "$dev3" "$dev5"; do
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=67a7b7a87da65b23…
Commit: 67a7b7a87da65b2350f975272e581be5f41976e0
Parent: 99214c51eb815806c4a4a4711fa3562546479751
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 19:14:51 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:43:06 2013 +0100
report: Iterate over labels instead of PVs for label-only reports.
---
tools/reporter.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/reporter.c b/tools/reporter.c
index 8b2a7c7..a15f8ef 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -391,8 +391,8 @@ static int _report(struct cmd_context *cmd, int argc, char **argv,
report_handle, &_vgs_single);
break;
case LABEL:
- r = process_each_pv(cmd, argc, argv, NULL, READ_WITHOUT_LOCK,
- 1, report_handle, &_label_single);
+ r = process_each_label(cmd, argc, argv,
+ report_handle, &_label_single);
break;
case PVS:
if (args_are_pvs)
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=99214c51eb815806…
Commit: 99214c51eb815806c4a4a4711fa3562546479751
Parent: b07fb3a6415215bf7e6128516a210b07376753dc
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 19:14:10 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:43:06 2013 +0100
report: Make PMdaFree into a "label" field.
---
lib/report/columns.h | 2 +-
lib/report/report.c | 5 ++---
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/lib/report/columns.h b/lib/report/columns.h
index 27f4d7f..8a87d11 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -67,10 +67,10 @@ FIELD(LVS, lv, STR, "Host", lvid, 10, lvhost, lv_host, "Creation host of the LV,
FIELD(LVS, lv, STR, "Modules", lvid, 7, modules, lv_modules, "Kernel device-mapper modules required for this LV.", 0)
FIELD(LABEL, pv, STR, "PV UUID", id, 38, uuid, pv_uuid, "Unique identifier.", 0)
-FIELD(LABEL, pv, NUM, "PMdaFree", id, 9, pvmdafree, pv_mda_free, "Free metadata area space on this device in current units.", 0)
FIELD(LABEL, label, STR, "Fmt", type, 3, pvfmt, pv_fmt, "Type of metadata.", 0)
FIELD(LABEL, label, NUM, "DevSize", dev, 7, devsize, dev_size, "Size of underlying device in current units.", 0)
FIELD(LABEL, label, STR, "PV", dev, 10, dev_name, pv_name, "Name.", 0)
+FIELD(LABEL, label, NUM, "PMdaFree", type, 9, pvmdafree, pv_mda_free, "Free metadata area space on this device in current units.", 0)
FIELD(LABEL, pv, NUM, "PMdaSize", id, 9, pvmdasize, pv_mda_size, "Size of smallest metadata area on this device in current units.", 0)
FIELD(PVS, pv, NUM, "1st PE", pe_start, 7, size64, pe_start, "Offset to the start of data on the underlying device.", 0)
diff --git a/lib/report/report.c b/lib/report/report.c
index 94e5230..3f716b5 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -791,9 +791,8 @@ static int _pvmdafree_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
{
- const struct physical_volume *pv =
- (const struct physical_volume *) data;
- uint64_t freespace = pv_mda_free(pv);
+ const struct label *label = (const struct label *) data;
+ uint64_t freespace = lvmcache_info_mda_free(label->info);
return _size64_disp(rh, mem, field, &freespace, private);
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b07fb3a6415215bf…
Commit: b07fb3a6415215bf7e6128516a210b07376753dc
Parent: 7e33f50cea7a7240d81ffdec3f8b0c6a1976fce3
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 16:00:40 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:43:04 2013 +0100
report: Adapt _pvfmt_disp to label-based reporting.
---
lib/report/columns.h | 2 +-
lib/report/report.c | 12 +++++++-----
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/lib/report/columns.h b/lib/report/columns.h
index 54c46e4..27f4d7f 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -66,9 +66,9 @@ FIELD(LVS, lv, STR, "Time", lvid, 26, lvtime, lv_time, "Creation time of the LV,
FIELD(LVS, lv, STR, "Host", lvid, 10, lvhost, lv_host, "Creation host of the LV, if known.", 0)
FIELD(LVS, lv, STR, "Modules", lvid, 7, modules, lv_modules, "Kernel device-mapper modules required for this LV.", 0)
-FIELD(LABEL, pv, STR, "Fmt", id, 3, pvfmt, pv_fmt, "Type of metadata.", 0)
FIELD(LABEL, pv, STR, "PV UUID", id, 38, uuid, pv_uuid, "Unique identifier.", 0)
FIELD(LABEL, pv, NUM, "PMdaFree", id, 9, pvmdafree, pv_mda_free, "Free metadata area space on this device in current units.", 0)
+FIELD(LABEL, label, STR, "Fmt", type, 3, pvfmt, pv_fmt, "Type of metadata.", 0)
FIELD(LABEL, label, NUM, "DevSize", dev, 7, devsize, dev_size, "Size of underlying device in current units.", 0)
FIELD(LABEL, label, STR, "PV", dev, 10, dev_name, pv_name, "Name.", 0)
FIELD(LABEL, pv, NUM, "PMdaSize", id, 9, pvmdasize, pv_mda_size, "Size of smallest metadata area on this device in current units.", 0)
diff --git a/lib/report/report.c b/lib/report/report.c
index f304157..94e5230 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -181,13 +181,15 @@ static int _pvfmt_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
{
- const struct physical_volume *pv =
- (const struct physical_volume *) data;
+ const struct label *l =
+ (const struct label *) data;
- if (pv->fmt)
- return _string_disp(rh, mem, field, &pv->fmt->name, private);
+ if (!l->labeller->fmt) {
+ dm_report_field_set_value(field, "", NULL);
+ return 1;
+ }
- return _field_set_value(field, "", NULL);
+ return _string_disp(rh, mem, field, &l->labeller->fmt->name, private);
}
static int _lvkmaj_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7e33f50cea7a7240…
Commit: 7e33f50cea7a7240d81ffdec3f8b0c6a1976fce3
Parent: 6b41e916ff8a11e91fade523323db549417f703c
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 19:07:11 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
report: Add a proper "label" field type.
---
lib/report/report.c | 13 +++++++++++--
lib/report/report.h | 4 +++-
tools/reporter.c | 19 +++++++++++--------
3 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/lib/report/report.c b/lib/report/report.c
index 2684392..f304157 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -32,6 +32,7 @@ struct lvm_report_object {
struct physical_volume *pv;
struct lv_segment *seg;
struct pv_segment *pvseg;
+ struct label *label;
};
static const uint64_t _hundred64 = UINT64_C(100);
@@ -1138,6 +1139,11 @@ static void *_obj_get_pv(void *obj)
return ((struct lvm_report_object *)obj)->pv;
}
+static void *_obj_get_label(void *obj)
+{
+ return ((struct lvm_report_object *)obj)->label;
+}
+
static void *_obj_get_seg(void *obj)
{
return ((struct lvm_report_object *)obj)->seg;
@@ -1157,7 +1163,7 @@ static const struct dm_report_object_type _report_types[] = {
{ VGS, "Volume Group", "vg_", _obj_get_vg },
{ LVS, "Logical Volume", "lv_", _obj_get_lv },
{ PVS, "Physical Volume", "pv_", _obj_get_pv },
- { LABEL, "Physical Volume Label", "pv_", _obj_get_pv },
+ { LABEL, "Physical Volume Label", "pv_", _obj_get_label },
{ SEGS, "Logical Volume Segment", "seg_", _obj_get_seg },
{ PVSEGS, "Physical Volume Segment", "pvseg_", _obj_get_pvseg },
{ 0, "", "", NULL },
@@ -1183,6 +1189,7 @@ typedef struct logical_volume type_lv;
typedef struct volume_group type_vg;
typedef struct lv_segment type_seg;
typedef struct pv_segment type_pvseg;
+typedef struct label type_label;
typedef dev_known_type_t type_devtype;
@@ -1242,7 +1249,8 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
*/
int report_object(void *handle, struct volume_group *vg,
struct logical_volume *lv, struct physical_volume *pv,
- struct lv_segment *seg, struct pv_segment *pvseg)
+ struct lv_segment *seg, struct pv_segment *pvseg,
+ struct label *label)
{
struct lvm_report_object obj;
@@ -1255,6 +1263,7 @@ int report_object(void *handle, struct volume_group *vg,
obj.pv = pv;
obj.seg = seg;
obj.pvseg = pvseg;
+ obj.label = label ? label : (pv ? pv_label(pv) : NULL);
return dm_report_object(handle, &obj);
}
diff --git a/lib/report/report.h b/lib/report/report.h
index bda8553..2c093b0 100644
--- a/lib/report/report.h
+++ b/lib/report/report.h
@@ -17,6 +17,7 @@
#define _LVM_REPORT_H
#include "metadata-exported.h"
+#include "label.h"
typedef enum {
LVS = 1,
@@ -41,7 +42,8 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
void report_free(void *handle);
int report_object(void *handle, struct volume_group *vg,
struct logical_volume *lv, struct physical_volume *pv,
- struct lv_segment *seg, struct pv_segment *pvseg);
+ struct lv_segment *seg, struct pv_segment *pvseg,
+ struct label *label);
int report_devtypes(void *handle);
int report_output(void *handle);
diff --git a/tools/reporter.c b/tools/reporter.c
index a967f60..8b2a7c7 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -31,7 +31,7 @@ static int _vgs_single(struct cmd_context *cmd __attribute__((unused)),
const char *vg_name, struct volume_group *vg,
void *handle)
{
- if (!report_object(handle, vg, NULL, NULL, NULL, NULL))
+ if (!report_object(handle, vg, NULL, NULL, NULL, NULL, NULL))
return_ECMD_FAILED;
check_current_backup(vg);
@@ -42,7 +42,7 @@ static int _vgs_single(struct cmd_context *cmd __attribute__((unused)),
static int _lvs_single(struct cmd_context *cmd, struct logical_volume *lv,
void *handle)
{
- if (!report_object(handle, lv->vg, lv, NULL, NULL, NULL))
+ if (!report_object(handle, lv->vg, lv, NULL, NULL, NULL, NULL))
return_ECMD_FAILED;
return ECMD_PROCESSED;
@@ -51,7 +51,7 @@ static int _lvs_single(struct cmd_context *cmd, struct logical_volume *lv,
static int _segs_single(struct cmd_context *cmd __attribute__((unused)),
struct lv_segment *seg, void *handle)
{
- if (!report_object(handle, seg->lv->vg, seg->lv, NULL, seg, NULL))
+ if (!report_object(handle, seg->lv->vg, seg->lv, NULL, seg, NULL, NULL))
return_ECMD_FAILED;
return ECMD_PROCESSED;
@@ -107,7 +107,7 @@ static int _pvsegs_sub_single(struct cmd_context *cmd,
dm_list_init(&_free_logical_volume.snapshot_segs);
if (!report_object(handle, vg, seg ? seg->lv : &_free_logical_volume, pvseg->pv,
- seg ? : &_free_lv_segment, pvseg)) {
+ seg ? : &_free_lv_segment, pvseg, NULL)) {
ret = ECMD_FAILED;
goto_out;
}
@@ -140,6 +140,7 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
const char *vg_name = NULL;
struct volume_group *old_vg = vg;
char uuid[64] __attribute__((aligned(8)));
+ struct label *label;
if (is_pv(pv) && !is_orphan(pv) && !vg) {
vg_name = pv_vg_name(pv);
@@ -177,7 +178,9 @@ static int _pvs_single(struct cmd_context *cmd, struct volume_group *vg,
pv = pvl->pv;
}
- if (!report_object(handle, vg, NULL, pv, NULL, NULL)) {
+ if ((!(label = pv_label(pv))) ||
+ (!report_object(handle, vg, NULL, pv, NULL, NULL, label)))
+ {
stack;
ret = ECMD_FAILED;
}
@@ -192,10 +195,10 @@ out:
return ret;
}
-static int _label_single(struct cmd_context *cmd, struct volume_group *vg,
- struct physical_volume *pv, void *handle)
+static int _label_single(struct cmd_context *cmd, struct label *label,
+ void *handle)
{
- if (!report_object(handle, vg, NULL, pv, NULL, NULL))
+ if (!report_object(handle, NULL, NULL, NULL, NULL, NULL, label))
return_ECMD_FAILED;
return ECMD_PROCESSED;
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6b41e916ff8a11e9…
Commit: 6b41e916ff8a11e91fade523323db549417f703c
Parent: cc633c84cfc82e91e83393271a068a662e7d4678
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 19:05:28 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
report: Make dev_size and dev_name columns' type "label".
---
lib/report/columns.h | 4 ++--
lib/report/report.c | 6 ++----
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/lib/report/columns.h b/lib/report/columns.h
index 88a0266..54c46e4 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -68,9 +68,9 @@ FIELD(LVS, lv, STR, "Modules", lvid, 7, modules, lv_modules, "Kernel device-mapp
FIELD(LABEL, pv, STR, "Fmt", id, 3, pvfmt, pv_fmt, "Type of metadata.", 0)
FIELD(LABEL, pv, STR, "PV UUID", id, 38, uuid, pv_uuid, "Unique identifier.", 0)
-FIELD(LABEL, pv, NUM, "DevSize", id, 7, devsize, dev_size, "Size of underlying device in current units.", 0)
-FIELD(LABEL, pv, STR, "PV", dev, 10, dev_name, pv_name, "Name.", 0)
FIELD(LABEL, pv, NUM, "PMdaFree", id, 9, pvmdafree, pv_mda_free, "Free metadata area space on this device in current units.", 0)
+FIELD(LABEL, label, NUM, "DevSize", dev, 7, devsize, dev_size, "Size of underlying device in current units.", 0)
+FIELD(LABEL, label, STR, "PV", dev, 10, dev_name, pv_name, "Name.", 0)
FIELD(LABEL, pv, NUM, "PMdaSize", id, 9, pvmdasize, pv_mda_size, "Size of smallest metadata area on this device in current units.", 0)
FIELD(PVS, pv, NUM, "1st PE", pe_start, 7, size64, pe_start, "Offset to the start of data on the underlying device.", 0)
diff --git a/lib/report/report.c b/lib/report/report.c
index c780ca4..2684392 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -690,10 +690,8 @@ static int _devsize_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
{
- const struct physical_volume *pv =
- (const struct physical_volume *) data;
- uint64_t size = pv_dev_size(pv);
-
+ uint64_t size = 0;
+ dev_get_size(*(const struct device **) data, &size);
return _size64_disp(rh, mem, field, &size, private);
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=cc633c84cfc82e91…
Commit: cc633c84cfc82e91e83393271a068a662e7d4678
Parent: dc3a0711454938e1a6264b7e3bf24a6dd1ac7e9f
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 19:03:20 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
label: Track a device pointer in struct label.
---
lib/label/label.c | 4 +++-
lib/label/label.h | 1 +
2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/lib/label/label.c b/lib/label/label.c
index cff6464..e083150 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -282,8 +282,10 @@ int label_read(struct device *dev, struct label **result,
if (!(l = _find_labeller(dev, buf, §or, scan_sector)))
goto out;
- if ((r = (l->ops->read)(l, dev, buf, result)) && result && *result)
+ if ((r = (l->ops->read)(l, dev, buf, result)) && result && *result) {
+ (*result)->dev = dev;
(*result)->sector = sector;
+ }
out:
if (!dev_close(dev))
diff --git a/lib/label/label.h b/lib/label/label.h
index 8dc49ff..103e799 100644
--- a/lib/label/label.h
+++ b/lib/label/label.h
@@ -42,6 +42,7 @@ struct label {
char type[8];
uint64_t sector;
struct labeller *labeller;
+ struct device *dev;
void *info;
};
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=dc3a0711454938e1…
Commit: dc3a0711454938e1a6264b7e3bf24a6dd1ac7e9f
Parent: a2034e9a99337ac16ee415f7f2398e0b8e976716
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 18:54:59 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
metadata: Add a pv_label accessor (go from a PV to its label).
---
lib/metadata/pv.c | 10 ++++++++++
lib/metadata/pv.h | 1 +
2 files changed, 11 insertions(+), 0 deletions(-)
diff --git a/lib/metadata/pv.c b/lib/metadata/pv.c
index 5b08998..0288f07 100644
--- a/lib/metadata/pv.c
+++ b/lib/metadata/pv.c
@@ -350,3 +350,13 @@ unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned mda_ignor
return 1;
}
+struct label *pv_label(const struct physical_volume *pv)
+{
+ struct lvmcache_info *info =
+ lvmcache_info_from_pvid((const char *)&pv->id.uuid, 0);
+ if (!info) {
+ log_error(INTERNAL_ERROR "PV %s unexpectedly not in cache.", dev_name(pv->dev));
+ return NULL;
+ }
+ return lvmcache_get_label(info);
+}
diff --git a/lib/metadata/pv.h b/lib/metadata/pv.h
index ff708f8..8fd3061 100644
--- a/lib/metadata/pv.h
+++ b/lib/metadata/pv.h
@@ -95,5 +95,6 @@ unsigned pv_mda_set_ignored(const struct physical_volume *pv, unsigned ignored);
int is_orphan(const struct physical_volume *pv);
int is_missing_pv(const struct physical_volume *pv);
int is_pv(const struct physical_volume *pv);
+struct label *pv_label(const struct physical_volume *pv);
#endif /* _LVM_PV_H */
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a2034e9a99337ac1…
Commit: a2034e9a99337ac16ee415f7f2398e0b8e976716
Parent: 1ef2c3c4ee325dd9ce607b62c1720d782021d399
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 18:52:28 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
metadata: Add lvmcache_info_mda_free as a companion to pv_mda_free.
---
lib/metadata/pv.c | 16 +++++++++++-----
lib/metadata/pv.h | 2 ++
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/lib/metadata/pv.c b/lib/metadata/pv.c
index dad747c..5b08998 100644
--- a/lib/metadata/pv.c
+++ b/lib/metadata/pv.c
@@ -241,14 +241,11 @@ static int _pv_mda_free(struct metadata_area *mda, void *baton) {
return 1;
}
-uint64_t pv_mda_free(const struct physical_volume *pv)
+uint64_t lvmcache_info_mda_free(struct lvmcache_info *info)
{
- struct lvmcache_info *info;
uint64_t freespace = UINT64_MAX;
- const char *pvid = (const char *)&pv->id.uuid;
- if ((info = lvmcache_info_from_pvid(pvid, 0)))
- lvmcache_foreach_mda(info, _pv_mda_free, &freespace);
+ lvmcache_foreach_mda(info, _pv_mda_free, &freespace);
if (freespace == UINT64_MAX)
freespace = UINT64_C(0);
@@ -256,6 +253,15 @@ uint64_t pv_mda_free(const struct physical_volume *pv)
return freespace;
}
+uint64_t pv_mda_free(const struct physical_volume *pv)
+{
+ const char *pvid = (const char *)&pv->id.uuid;
+ struct lvmcache_info *info;
+ if ((info = lvmcache_info_from_pvid(pvid, 0)))
+ return lvmcache_info_mda_free(info);
+ return 0;
+}
+
uint64_t pv_used(const struct physical_volume *pv)
{
uint64_t used;
diff --git a/lib/metadata/pv.h b/lib/metadata/pv.h
index c018f38..ff708f8 100644
--- a/lib/metadata/pv.h
+++ b/lib/metadata/pv.h
@@ -85,6 +85,8 @@ uint64_t pv_ba_size(const struct physical_volume *pv);
uint32_t pv_pe_count(const struct physical_volume *pv);
uint32_t pv_pe_alloc_count(const struct physical_volume *pv);
uint64_t pv_mda_size(const struct physical_volume *pv);
+struct lvmcache_info;
+uint64_t lvmcache_info_mda_free(struct lvmcache_info *info);
uint64_t pv_mda_free(const struct physical_volume *pv);
uint64_t pv_used(const struct physical_volume *pv);
uint32_t pv_mda_count(const struct physical_volume *pv);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=1ef2c3c4ee325dd9…
Commit: 1ef2c3c4ee325dd9ce607b62c1720d782021d399
Parent: 9b91977f4ec21a2080daaa2e261fbdecbe8fbd2c
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 18:51:27 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
toollib: Implement process_each_label.
---
tools/toollib.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
tools/toollib.h | 6 +++++
2 files changed, 64 insertions(+), 0 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index 127dd66..529088c 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1801,3 +1801,61 @@ int change_tag(struct cmd_context *cmd, struct volume_group *vg,
return 1;
}
+int process_each_label(struct cmd_context *cmd, int argc, char **argv, void *handle,
+ process_single_label_fn_t process_single_label)
+{
+ struct label *label;
+ struct dev_iter *iter;
+ struct device *dev;
+
+ int ret_max = ECMD_PROCESSED;
+ int ret = 0;
+ int opt = 0;
+
+ if (argc) {
+ for (; opt < argc; opt++) {
+ if (!(dev = dev_cache_get(argv[opt], cmd->filter))) {
+ log_error("Failed to find device "
+ "\"%s\"", argv[opt]);
+ ret_max = ECMD_FAILED;
+ continue;
+ }
+
+ if (!label_read(dev, &label, 0))
+ continue;
+
+ ret = process_single_label(cmd, label, handle);
+
+ if (ret > ret_max)
+ ret_max = ret;
+
+ if (sigint_caught())
+ break;
+ }
+
+ return ret_max;
+ }
+
+ if (!(iter = dev_iter_create(cmd->filter, 1))) {
+ log_error("dev_iter creation failed");
+ return ECMD_FAILED;
+ }
+
+ while ((dev = dev_iter_get(iter)))
+ {
+ if (!label_read(dev, &label, 0))
+ continue;
+
+ ret = process_single_label(cmd, label, handle);
+
+ if (ret > ret_max)
+ ret_max = ret;
+
+ if (sigint_caught())
+ break;
+ }
+
+ dev_iter_destroy(iter);
+
+ return ret_max;
+}
diff --git a/tools/toollib.h b/tools/toollib.h
index aa6f699..d809123 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -38,6 +38,9 @@ typedef int (*process_single_pv_fn_t) (struct cmd_context *cmd,
struct volume_group *vg,
struct physical_volume *pv,
void *handle);
+typedef int (*process_single_label_fn_t) (struct cmd_context *cmd,
+ struct label *label,
+ void *handle);
typedef int (*process_single_lv_fn_t) (struct cmd_context *cmd,
struct logical_volume *lv,
void *handle);
@@ -58,6 +61,9 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
int scan_label_only, void *handle,
process_single_pv_fn_t process_single_pv);
+int process_each_label(struct cmd_context *cmd, int argc, char **argv,
+ void *handle, process_single_label_fn_t process_single_label);
+
int process_each_segment_in_pv(struct cmd_context *cmd,
struct volume_group *vg,
struct physical_volume *pv,
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9b91977f4ec21a20…
Commit: 9b91977f4ec21a2080daaa2e261fbdecbe8fbd2c
Parent: bead8ef5f03f563064276037eed5d9ca94b67ead
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Mon Jul 29 15:58:18 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
labeller: Make the use of "private" as "fmt" explicit.
All labellers always use the "private" (void *) field as the fmt pointer. Making
this fact explicit in the type of the labeller simplifies the label reporting
code which needs to extract the format. Moreover, it removes a number of
error-prone casts from the code.
---
lib/cache/lvmcache.c | 4 ++--
lib/format1/format1.c | 2 +-
lib/format1/lvm1-label.c | 2 +-
lib/format_pool/format_pool.c | 2 +-
lib/format_pool/pool_label.c | 2 +-
lib/format_text/format-text.c | 2 +-
lib/format_text/text_label.c | 4 ++--
lib/label/label.c | 4 ++--
lib/label/label.h | 4 ++--
9 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index f33565c..770a1b3 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -1450,7 +1450,7 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
const char *vgname, const char *vgid,
uint32_t vgstatus)
{
- const struct format_type *fmt = (const struct format_type *) labeller->private;
+ const struct format_type *fmt = labeller->fmt;
struct dev_types *dt = fmt->cmd->dev_types;
struct label *label;
struct lvmcache_info *existing, *info;
@@ -1540,7 +1540,7 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller, const char *pvid,
label = info->label;
}
- info->fmt = (const struct format_type *) labeller->private;
+ info->fmt = labeller->fmt;
info->status |= CACHE_INVALID;
if (!_lvmcache_update_pvid(info, pvid_s)) {
diff --git a/lib/format1/format1.c b/lib/format1/format1.c
index 7014a35..509167a 100644
--- a/lib/format1/format1.c
+++ b/lib/format1/format1.c
@@ -614,7 +614,7 @@ struct format_type *init_format(struct cmd_context *cmd)
return NULL;
}
- if (!(label_register_handler(FMT_LVM1_NAME, fmt->labeller))) {
+ if (!(label_register_handler(fmt->labeller))) {
log_error("Couldn't register lvm1 label handler.");
fmt->labeller->ops->destroy(fmt->labeller);
dm_free(fmt);
diff --git a/lib/format1/lvm1-label.c b/lib/format1/lvm1-label.c
index 6138a05..c5f9f35 100644
--- a/lib/format1/lvm1-label.c
+++ b/lib/format1/lvm1-label.c
@@ -122,7 +122,7 @@ struct labeller *lvm1_labeller_create(struct format_type *fmt)
}
l->ops = &_lvm1_ops;
- l->private = (const void *) fmt;
+ l->fmt = fmt;
return l;
}
diff --git a/lib/format_pool/format_pool.c b/lib/format_pool/format_pool.c
index 0891524..0f8f3a3 100644
--- a/lib/format_pool/format_pool.c
+++ b/lib/format_pool/format_pool.c
@@ -309,7 +309,7 @@ struct format_type *init_format(struct cmd_context *cmd)
return NULL;
}
- if (!(label_register_handler(FMT_POOL_NAME, fmt->labeller))) {
+ if (!(label_register_handler(fmt->labeller))) {
log_error("Couldn't register pool label handler.");
fmt->labeller->ops->destroy(fmt->labeller);
dm_free(fmt);
diff --git a/lib/format_pool/pool_label.c b/lib/format_pool/pool_label.c
index 7059b98..d453dd9 100644
--- a/lib/format_pool/pool_label.c
+++ b/lib/format_pool/pool_label.c
@@ -99,7 +99,7 @@ struct labeller *pool_labeller_create(struct format_type *fmt)
}
l->ops = &_pool_ops;
- l->private = (const void *) fmt;
+ l->fmt = fmt;
return l;
}
diff --git a/lib/format_text/format-text.c b/lib/format_text/format-text.c
index 950e0d5..e67d24d 100644
--- a/lib/format_text/format-text.c
+++ b/lib/format_text/format-text.c
@@ -2433,7 +2433,7 @@ struct format_type *create_text_format(struct cmd_context *cmd)
goto bad;
}
- if (!(label_register_handler(FMT_TEXT_NAME, fmt->labeller))) {
+ if (!(label_register_handler(fmt->labeller))) {
log_error("Couldn't register text label handler.");
fmt->labeller->ops->destroy(fmt->labeller);
goto bad;
diff --git a/lib/format_text/text_label.c b/lib/format_text/text_label.c
index 3408590..516d694 100644
--- a/lib/format_text/text_label.c
+++ b/lib/format_text/text_label.c
@@ -316,7 +316,7 @@ struct _update_mda_baton {
static int _update_mda(struct metadata_area *mda, void *baton)
{
struct _update_mda_baton *p = baton;
- const struct format_type *fmt = p->label->labeller->private; // Oh dear.
+ const struct format_type *fmt = p->label->labeller->fmt;
struct mda_context *mdac = (struct mda_context *) mda->metadata_locn;
struct mda_header *mdah;
const char *vgname = NULL;
@@ -471,7 +471,7 @@ struct labeller *text_labeller_create(const struct format_type *fmt)
}
l->ops = &_text_ops;
- l->private = (const void *) fmt;
+ l->fmt = fmt;
return l;
}
diff --git a/lib/label/label.c b/lib/label/label.c
index a38ba68..cff6464 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -76,11 +76,11 @@ void label_exit(void)
dm_list_init(&_labellers);
}
-int label_register_handler(const char *name, struct labeller *handler)
+int label_register_handler(struct labeller *handler)
{
struct labeller_i *li;
- if (!(li = _alloc_li(name, handler)))
+ if (!(li = _alloc_li(handler->fmt->name, handler)))
return_0;
dm_list_add(&_labellers, &li->list);
diff --git a/lib/label/label.h b/lib/label/label.h
index f3268bb..8dc49ff 100644
--- a/lib/label/label.h
+++ b/lib/label/label.h
@@ -87,13 +87,13 @@ struct label_ops {
struct labeller {
struct label_ops *ops;
- const void *private;
+ struct format_type *fmt;
};
int label_init(void);
void label_exit(void);
-int label_register_handler(const char *name, struct labeller *handler);
+int label_register_handler(struct labeller *handler);
struct labeller *label_get_handler(const char *name);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=bead8ef5f03f5630…
Commit: bead8ef5f03f563064276037eed5d9ca94b67ead
Parent: ba6d6f002837d0fa2f27ad3660cfde7887870401
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Tue Feb 19 10:57:45 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
metadata: Nuke the exported "pv_read" function.
---
lib/metadata/metadata-exported.h | 3 ---
lib/metadata/metadata.c | 36 ------------------------------------
2 files changed, 0 insertions(+), 39 deletions(-)
diff --git a/lib/metadata/metadata-exported.h b/lib/metadata/metadata-exported.h
index c00e4e5..1bf5236 100644
--- a/lib/metadata/metadata-exported.h
+++ b/lib/metadata/metadata-exported.h
@@ -505,9 +505,6 @@ int vg_commit(struct volume_group *vg);
void vg_revert(struct volume_group *vg);
struct volume_group *vg_read_internal(struct cmd_context *cmd, const char *vg_name,
const char *vgid, int warnings, int *consistent);
-struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name,
- int warnings,
- int scan_label_only);
#define get_pvs( cmd ) get_pvs_internal((cmd), NULL, NULL)
#define get_pvs_perserve_vg( cmd, pv_list, vg_list ) get_pvs_internal((cmd), (pv_list), (vg_list))
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index fa480c8..aa5f124 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -1339,20 +1339,6 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,
if (!(pv = find_pv_by_name(cmd, name, 1)))
stack;
- /*
- * If a PV has no MDAs it may appear to be an orphan until the
- * metadata is read off another PV in the same VG. Detecting
- * this means checking every VG by scanning every PV on the
- * system.
- */
- if (pv && is_orphan(pv) && dm_list_empty(&pv->fid->metadata_areas_in_use)) {
- free_pv_fid(pv);
- if (!scan_vgs_for_pvs(cmd, 0))
- return_0;
- if (!(pv = pv_read(cmd, name, 0, 0)))
- stack;
- }
-
/* Allow partial & exported VGs to be destroyed. */
/* We must have -ff to overwrite a non orphan */
if (pv && !is_orphan(pv) && pp->force != DONT_PROMPT_OVERRIDE) {
@@ -3652,28 +3638,6 @@ const char *find_vgname_from_pvname(struct cmd_context *cmd,
return find_vgname_from_pvid(cmd, pvid);
}
-/**
- * pv_read - read and return a handle to a physical volume
- * @cmd: LVM command initiating the pv_read
- * @pv_name: full device name of the PV, including the path
- * @mdas: list of metadata areas of the PV
- * @label_sector: sector number where the PV label is stored on @pv_name
- * @warnings:
- *
- * Returns:
- * PV handle - valid pv_name and successful read of the PV, or
- * NULL - invalid parameter or error in reading the PV
- *
- * Note:
- * FIXME - liblvm todo - make into function that returns handle
- */
-struct physical_volume *pv_read(struct cmd_context *cmd, const char *pv_name,
- int warnings,
- int scan_label_only)
-{
- return _pv_read(cmd, cmd->mem, pv_name, NULL, warnings, scan_label_only);
-}
-
/* FIXME Use label functions instead of PV functions */
static struct physical_volume *_pv_read(struct cmd_context *cmd,
struct dm_pool *pvmem,
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=ba6d6f002837d0fa…
Commit: ba6d6f002837d0fa2f27ad3660cfde7887870401
Parent: 651d5093edde3e0ebee9d75be1c9834efc152d91
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Tue Feb 19 03:13:59 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
metadata: Fix handling of orphan PV linking & re-linking.
---
lib/metadata/metadata.c | 31 ++++++++++++++++++++++++++++---
1 files changed, 28 insertions(+), 3 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index b67d596..fa480c8 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -269,6 +269,12 @@ int add_pv_to_vg(struct volume_group *vg, const char *pv_name,
vg->extent_count += pv->pe_count;
vg->free_count += pv->pe_count;
+ dm_list_iterate_items(pvl, &fid->fmt->orphan_vg->pvs)
+ if (pv == pvl->pv) { /* unlink from orphan */
+ dm_list_del(&pvl->list);
+ break;
+ }
+
if (pv->status & UNLABELLED_PV) {
if (!(pvc = dm_pool_zalloc(mem, sizeof(*pvc)))) {
log_error("pv_to_create allocation for '%s' failed", pv_name);
@@ -2810,8 +2816,10 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd,
struct lvmcache_vginfo *vginfo;
struct volume_group *vg = NULL;
struct _vg_read_orphan_baton baton;
- struct pv_list *pvl;
+ struct pv_list *pvl, *pvl_;
+ struct pv_list head;
+ dm_list_init(&head.list);
lvmcache_label_scan(cmd, 0);
lvmcache_seed_infos_from_lvmetad(cmd);
@@ -2822,14 +2830,31 @@ static struct volume_group *_vg_read_orphans(struct cmd_context *cmd,
return_NULL;
vg = fmt->orphan_vg;
- dm_list_iterate_items(pvl, &vg->pvs)
- pv_set_fid(pvl->pv, NULL);
+restart:
+ dm_list_iterate_items(pvl, &vg->pvs) {
+ if (pvl->pv->status & UNLABELLED_PV ) {
+ dm_list_del(&pvl->list);
+ dm_list_add(&head.list, &pvl->list);
+ goto restart;
+ } else
+ pv_set_fid(pvl->pv, NULL);
+ }
dm_list_init(&vg->pvs);
vg->pv_count = 0;
+ vg->extent_count = 0;
+ vg->free_count = 0;
baton.warnings = warnings;
baton.vg = vg;
+ while (!dm_list_empty(&head.list)) {
+ pvl = (struct pv_list *) dm_list_first(&head.list);
+ dm_list_del(&pvl->list);
+ add_pvl_to_vgs(vg, pvl);
+ vg->extent_count += pvl->pv->pe_count;
+ vg->free_count += pvl->pv->pe_count;
+ }
+
if (!lvmcache_foreach_pv(vginfo, _vg_read_orphan_pv, &baton))
return_NULL;
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=651d5093edde3e0e…
Commit: 651d5093edde3e0ebee9d75be1c9834efc152d91
Parent: 2f5c12e3a88f6bc028e8355c58b6b2c89da301e7
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Tue Feb 19 02:32:25 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
metadata: Avoid pv_read in find_pv_by_name.
---
lib/metadata/metadata.c | 34 ++++++++++++++++++++--------------
1 files changed, 20 insertions(+), 14 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 869d368..b67d596 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -1330,7 +1330,7 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,
/* FIXME Check partition type is LVM unless --force is given */
/* Is there a pv here already? */
- if (!(pv = pv_read(cmd, name, 0, 0)))
+ if (!(pv = find_pv_by_name(cmd, name, 1)))
stack;
/*
@@ -1824,23 +1824,29 @@ struct physical_volume *find_pv_by_name(struct cmd_context *cmd,
const char *pv_name,
int allow_orphan)
{
- struct physical_volume *pv;
+ struct device *dev;
+ struct pv_list *pvl;
+ struct dm_list *pvslist;
+ struct physical_volume *pv = NULL;
+
+ lvmcache_seed_infos_from_lvmetad(cmd);
- if (!(pv = _pv_read(cmd, cmd->mem, pv_name, NULL, 1, 0))) {
+ if (!(dev = dev_cache_get(pv_name, cmd->filter))) {
log_error("Physical volume %s not found", pv_name);
- goto bad;
+ return_NULL;
}
- if (is_orphan_vg(pv->vg_name) && dm_list_empty(&pv->fid->metadata_areas_in_use)) {
- /* If a PV has no MDAs - need to search all VGs for it */
- if (!scan_vgs_for_pvs(cmd, 1))
- goto_bad;
- free_pv_fid(pv);
- if (!(pv = _pv_read(cmd, cmd->mem, pv_name, NULL, 1, 0))) {
- log_error("Physical volume %s not found", pv_name);
- goto bad;
- }
- }
+ if (!(pvslist = get_pvs(cmd)))
+ return_NULL;
+
+ dm_list_iterate_items(pvl, pvslist)
+ if (pvl->pv->dev == dev)
+ pv = pvl->pv;
+ else
+ free_pv_fid(pvl->pv);
+
+ if (!pv)
+ log_error("Physical volume %s not found", pv_name);
if (pv && !allow_orphan && is_orphan_vg(pv->vg_name)) {
log_error("Physical volume %s not in a volume group", pv_name);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=2f5c12e3a88f6bc0…
Commit: 2f5c12e3a88f6bc028e8355c58b6b2c89da301e7
Parent: fc02f241789824877d604ca40a56ab6487d7212a
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Tue Feb 19 02:14:51 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
pvremove: Avoid using pv_read in favour of scanning.
---
lib/metadata/pv_manip.c | 76 ++++++++++++++++++++++++----------------------
1 files changed, 40 insertions(+), 36 deletions(-)
diff --git a/lib/metadata/pv_manip.c b/lib/metadata/pv_manip.c
index b7a4b43..bee7972 100644
--- a/lib/metadata/pv_manip.c
+++ b/lib/metadata/pv_manip.c
@@ -652,59 +652,63 @@ const char _really_wipe[] =
static int pvremove_check(struct cmd_context *cmd, const char *name,
unsigned force_count, unsigned prompt)
{
- struct physical_volume *pv;
+ struct device *dev;
+ struct label *label;
+ struct pv_list *pvl;
+ struct dm_list *pvslist;
+
+ struct physical_volume *pv = NULL;
+ int r = 0;
/* FIXME Check partition type is LVM unless --force is given */
+ if (!(dev = dev_cache_get(name, cmd->filter))) {
+ log_error("Device %s not found", name);
+ return 0;
+ }
+
/* Is there a pv here already? */
/* If not, this is an error unless you used -f. */
- if (!(pv = pv_read(cmd, name, 1, 0))) {
+ if (!label_read(dev, &label, 0)) {
if (force_count)
return 1;
- log_error("Physical Volume %s not found", name);
+ log_error("No PV label found on %s.", name);
return 0;
}
- /*
- * If a PV has no MDAs it may appear to be an
- * orphan until the metadata is read off
- * another PV in the same VG. Detecting this
- * means checking every VG by scanning every
- * PV on the system.
- */
- if (is_orphan(pv) && dm_list_empty(&pv->fid->metadata_areas_in_use) &&
- dm_list_empty(&pv->fid->metadata_areas_ignored)) {
- if (!scan_vgs_for_pvs(cmd, 0)) {
- log_error("Rescan for PVs without metadata areas "
- "failed.");
- goto bad;
- }
- free_pv_fid(pv);
- if (!(pv = pv_read(cmd, name, 1, 0))) {
- log_error("Failed to read physical volume %s", name);
- goto bad;
- }
+ lvmcache_seed_infos_from_lvmetad(cmd);
+ if (!(pvslist = get_pvs(cmd)))
+ return_0;
+
+ dm_list_iterate_items(pvl, pvslist)
+ if (pvl->pv->dev == dev)
+ pv = pvl->pv;
+
+ if (!pv) {
+ log_error(INTERNAL_ERROR "Physical Volume %s has a label,"
+ " but is neither in a VG nor orphan.", name);
+ goto out; /* better safe than sorry */
}
- /* orphan ? */
if (is_orphan(pv)) {
- free_pv_fid(pv);
- return 1;
+ r = 1;
+ goto out;
}
- /* Allow partial & exported VGs to be destroyed. */
/* we must have -ff to overwrite a non orphan */
if (force_count < 2) {
log_error("PV %s belongs to Volume Group %s so please use vgreduce first.", name, pv_vg_name(pv));
log_error("(If you are certain you need pvremove, then confirm by using --force twice.)");
- goto bad;
+ goto out;
}
/* prompt */
if (!prompt &&
- yes_no_prompt(_really_wipe, name, pv_vg_name(pv)) == 'n') {
+ yes_no_prompt("Really WIPE LABELS from physical volume \"%s\" "
+ "of volume group \"%s\" [y/n]? ",
+ name, pv_vg_name(pv)) == 'n') {
log_error("%s: physical volume label not removed", name);
- goto bad;
+ goto out;
}
if (force_count) {
@@ -715,17 +719,17 @@ static int pvremove_check(struct cmd_context *cmd, const char *name,
!is_orphan(pv) ? "\"" : "");
}
- free_pv_fid(pv);
- return 1;
-
-bad:
- free_pv_fid(pv);
- return 0;
+ r = 1;
+out:
+ if (pvslist)
+ dm_list_iterate_items(pvl, pvslist)
+ free_pv_fid(pvl->pv);
+ return r;
}
int pvremove_single(struct cmd_context *cmd, const char *pv_name,
void *handle __attribute__((unused)), unsigned force_count,
- unsigned prompt)
+ unsigned prompt)
{
struct device *dev;
int r = 0;
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fc02f24178982487…
Commit: fc02f241789824877d604ca40a56ab6487d7212a
Parent: 603b45e0ed1032875f587eda3391c47b6652303c
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Tue Feb 19 01:56:51 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
test: Fix fallout from pv_read changes.
---
test/shell/pv-duplicate.sh | 2 +-
test/shell/pvcreate-operation-md.sh | 35 +++++++++++++++++++++--------------
2 files changed, 22 insertions(+), 15 deletions(-)
diff --git a/test/shell/pv-duplicate.sh b/test/shell/pv-duplicate.sh
index 6b9f309..40d1f68 100644
--- a/test/shell/pv-duplicate.sh
+++ b/test/shell/pv-duplicate.sh
@@ -21,5 +21,5 @@ vgcreate --metadatasize 128k $vg1 "$dev1"
dd if="$dev1" of="$dev2" bs=256K count=1
dd if="$dev1" of="$dev3" bs=256K count=1
-pvs "$dev1"
+pvs "$dev3"
vgs $vg1
diff --git a/test/shell/pvcreate-operation-md.sh b/test/shell/pvcreate-operation-md.sh
index 5e2a28d..9cad745 100644
--- a/test/shell/pvcreate-operation-md.sh
+++ b/test/shell/pvcreate-operation-md.sh
@@ -58,21 +58,24 @@ test -b "$mddev" && skip
mdadm --create --metadata=1.0 "$mddev" --auto=md --level 0 --raid-devices=2 --chunk 64 "$dev1" "$dev2"
trap 'cleanup_md_and_teardown' EXIT # cleanup this MD device at the end of the test
test -b "$mddev" || skip
+cp -LR "$mddev" "$DM_DEV_DIR" # so that LVM/DM can see the device
+lvmdev="$DM_DEV_DIR/md_lvm_test0"
# Test alignment of PV on MD without any MD-aware or topology-aware detection
# - should treat $mddev just like any other block device
pv_align="1.00m"
pvcreate --metadatasize 128k \
--config 'devices {md_chunk_alignment=0 data_alignment_detection=0 data_alignment_offset_detection=0}' \
- "$mddev"
-check pv_field "$mddev" pe_start $pv_align
+ "$lvmdev"
+
+check pv_field "$lvmdev" pe_start $pv_align
# Test md_chunk_alignment independent of topology-aware detection
pv_align="1.00m"
pvcreate --metadatasize 128k \
--config 'devices {data_alignment_detection=0 data_alignment_offset_detection=0}' \
- "$mddev"
-check pv_field "$mddev" pe_start $pv_align
+ "$lvmdev"
+check pv_field "$lvmdev" pe_start $pv_align
# Test newer topology-aware alignment detection
@@ -81,8 +84,8 @@ if kernel_at_least 2 6 33 ; then
pv_align="1.00m"
# optimal_io_size=131072, minimum_io_size=65536
pvcreate --metadatasize 128k \
- --config 'devices { md_chunk_alignment=0 }' "$mddev"
- check pv_field "$mddev" pe_start $pv_align
+ --config 'devices { md_chunk_alignment=0 }' "$lvmdev"
+ check pv_field "$lvmdev" pe_start $pv_align
fi
# partition MD array directly, depends on blkext in Linux >= 2.6.28
@@ -91,9 +94,10 @@ if kernel_at_least 2 6 28 ; then
sfdisk "$mddev" <<EOF
,,83
EOF
+ pvscan
# make sure partition on MD is _not_ removed
# - tests partition -> parent lookup via sysfs paths
- not pvcreate --metadatasize 128k "$mddev"
+ not pvcreate --metadatasize 128k "$lvmdev"
# verify alignment_offset is accounted for in pe_start
# - topology infrastructure is available in Linux >= 2.6.31
@@ -109,6 +113,8 @@ EOF
# wait here for created device node on tmpfs
aux udev_wait "$mddev_p"
test -b "$mddev_p" || skip
+ cp -LR "$mddev_p" "$DM_DEV_DIR"
+ lvmdev_p="$DM_DEV_DIR/$base_mddev_p"
# Checking for 'alignment_offset' in sysfs implies Linux >= 2.6.31
# but reliable alignment_offset support requires kernel.org Linux >= 2.6.33
@@ -120,9 +126,9 @@ EOF
if [ $alignment_offset -gt 0 ]; then
# default alignment is 1M, add alignment_offset
pv_align=$((1048576+$alignment_offset))B
- pvcreate --metadatasize 128k "$mddev_p"
- check pv_field "$mddev_p" pe_start $pv_align --units b
- pvremove "$mddev_p"
+ pvcreate --metadatasize 128k "$lvmdev_p"
+ check pv_field "$lvmdev_p" pe_start $pv_align --units b
+ pvremove "$lvmdev_p"
fi
fi
@@ -140,12 +146,13 @@ if kernel_at_least 2 6 33 ; then
# optimal_io_size=2097152, minimum_io_size=1048576
pv_align="2.00m"
pvcreate --metadatasize 128k \
- --config 'devices { md_chunk_alignment=0 }' "$mddev"
- check pv_field "$mddev" pe_start $pv_align
+ --config 'devices { md_chunk_alignment=0 }' "$lvmdev"
+ pvscan # Something is seriously broken.
+ check pv_field "$lvmdev" pe_start $pv_align
# now verify pe_start alignment override using --dataalignment
pv_align="192.00k"
pvcreate --dataalignment 64k --metadatasize 128k \
- --config 'devices { md_chunk_alignment=0 }' "$mddev"
- check pv_field "$mddev" pe_start $pv_align
+ --config 'devices { md_chunk_alignment=0 }' "$lvmdev"
+ check pv_field "$lvmdev" pe_start $pv_align
fi
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=603b45e0ed103287…
Commit: 603b45e0ed1032875f587eda3391c47b6652303c
Parent: 0a59305c44e992831d66da50f5058f154a795d3a
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Tue Feb 19 01:54:34 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:27 2013 +0100
pvresize: Do not use pv_read (get the PV from orphan VG).
---
lib/metadata/pv_manip.c | 51 ++++++++++++++++------------------------------
1 files changed, 18 insertions(+), 33 deletions(-)
diff --git a/lib/metadata/pv_manip.c b/lib/metadata/pv_manip.c
index fb29ef4..b7a4b43 100644
--- a/lib/metadata/pv_manip.c
+++ b/lib/metadata/pv_manip.c
@@ -549,9 +549,9 @@ static int pv_resize(struct physical_volume *pv,
}
int pv_resize_single(struct cmd_context *cmd,
- struct volume_group *vg,
- struct physical_volume *pv,
- const uint64_t new_size)
+ struct volume_group *vg,
+ struct physical_volume *pv,
+ const uint64_t new_size)
{
struct pv_list *pvl;
uint64_t size = 0;
@@ -561,38 +561,25 @@ int pv_resize_single(struct cmd_context *cmd,
struct volume_group *old_vg = vg;
int vg_needs_pv_write = 0;
- if (is_orphan_vg(vg_name)) {
- if (!lock_vol(cmd, vg_name, LCK_VG_WRITE, NULL)) {
- log_error("Can't get lock for orphans");
- return 0;
- }
-
- if (!(pv = pv_read(cmd, pv_name, 1, 0))) {
- unlock_vg(cmd, vg_name);
- log_error("Unable to read PV \"%s\"", pv_name);
- return 0;
- }
- } else {
- vg = vg_read_for_update(cmd, vg_name, NULL, 0);
+ vg = vg_read_for_update(cmd, vg_name, NULL, 0);
- if (vg_read_error(vg)) {
- release_vg(vg);
- log_error("Unable to read volume group \"%s\".",
- vg_name);
- return 0;
- }
+ if (vg_read_error(vg)) {
+ release_vg(vg);
+ log_error("Unable to read volume group \"%s\".",
+ vg_name);
+ return 0;
+ }
- if (!(pvl = find_pv_in_vg(vg, pv_name))) {
- log_error("Unable to find \"%s\" in volume group \"%s\"",
- pv_name, vg->name);
- goto out;
- }
+ if (!(pvl = find_pv_in_vg(vg, pv_name))) {
+ log_error("Unable to find \"%s\" in volume group \"%s\"",
+ pv_name, vg->name);
+ goto out;
+ }
- pv = pvl->pv;
+ pv = pvl->pv;
- if (!archive(vg))
- goto out;
- }
+ if (!archive(vg))
+ goto out;
if (!(pv->fmt->features & FMT_RESIZE_PV)) {
log_error("Physical volume %s format does not support resizing.",
@@ -650,8 +637,6 @@ out:
log_error("Use pvcreate and vgcfgrestore "
"to repair from archived metadata.");
unlock_vg(cmd, vg_name);
- if (is_orphan_vg(vg_name))
- free_pv_fid(pv);
if (!old_vg)
release_vg(vg);
return r;
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0a59305c44e99283…
Commit: 0a59305c44e992831d66da50f5058f154a795d3a
Parent: 7e685e6c70e5b738e5740b920e6080b9a13c2556
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Tue Jun 11 09:13:39 2013 +0200
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:26 2013 +0100
test: Add a test for the failing pv_read optimisation.
---
test/shell/mda-rollback.sh | 26 ++++++++++++++++++++++++++
1 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/test/shell/mda-rollback.sh b/test/shell/mda-rollback.sh
new file mode 100644
index 0000000..d47eb8a
--- /dev/null
+++ b/test/shell/mda-rollback.sh
@@ -0,0 +1,26 @@
+#!/bin/sh
+# Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+#
+# 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_devs 3
+
+vgcreate --metadatasize 128k $vg1 "$dev1" "$dev2" "$dev3"
+
+vgreduce $vg1 $dev1
+dd if="$dev1" of=badmda bs=256K count=1
+vgextend $vg1 $dev1
+
+dd if=badmda of="$dev1" bs=256K count=1
+
+# dev1 is part of vg1 (as witnessed by metadata on dev2 and dev3), but its mda
+# was corrupt (written over by a backup from time dev1 was an orphan)
+check pv_field $dev1 vg_name $vg1
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7e685e6c70e5b738…
Commit: 7e685e6c70e5b738e5740b920e6080b9a13c2556
Parent: e1a63905d14cc73352b905c70cb4084b7e521e33
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Tue Feb 19 00:12:30 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:26 2013 +0100
toollib: Drop the pv_read optimisation.
Only reading a single PV works correctly only in very limited circumstances.
Moreover, we can't rely on the MDA available on the PV either, since it may be
out of date in some circumstances (until now, we believed that PVs that have an
empty MDA are always orphans, but this is not 100% reliable either).
---
tools/toollib.c | 93 +++++++++++++++++++++++++++----------------------------
1 files changed, 46 insertions(+), 47 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index bc8b33c..127dd66 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -744,6 +744,8 @@ int process_each_pv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
static int _process_all_devs(struct cmd_context *cmd, void *handle,
process_single_pv_fn_t process_single_pv)
{
+ struct pv_list *pvl;
+ struct dm_list *pvslist;
struct physical_volume *pv;
struct physical_volume pv_dummy;
struct dev_iter *iter;
@@ -752,7 +754,8 @@ static int _process_all_devs(struct cmd_context *cmd, void *handle,
int ret_max = ECMD_PROCESSED;
int ret;
- if (!scan_vgs_for_pvs(cmd, 1))
+ lvmcache_seed_infos_from_lvmetad(cmd);
+ if (!(pvslist = get_pvs(cmd)))
return_ECMD_FAILED;
if (!(iter = dev_iter_create(cmd->filter, 1))) {
@@ -760,20 +763,28 @@ static int _process_all_devs(struct cmd_context *cmd, void *handle,
return ECMD_FAILED;
}
- while ((dev = dev_iter_get(iter))) {
+ while ((dev = dev_iter_get(iter)))
+ {
if (sigint_caught()) {
ret_max = ECMD_FAILED;
stack;
break;
}
- if (!(pv = pv_read(cmd, dev_name(dev), 0, 0))) {
- memset(&pv_dummy, 0, sizeof(pv_dummy));
- dm_list_init(&pv_dummy.tags);
- dm_list_init(&pv_dummy.segments);
- pv_dummy.dev = dev;
- pv = &pv_dummy;
- }
+ memset(&pv_dummy, 0, sizeof(pv_dummy));
+ dm_list_init(&pv_dummy.tags);
+ dm_list_init(&pv_dummy.segments);
+ pv_dummy.dev = dev;
+ pv = &pv_dummy;
+
+ /* TODO use a device-indexed hash here */
+ dm_list_iterate_items(pvl, pvslist)
+ if (pvl->pv->dev == dev)
+ pv = pvl->pv;
+
+ ret = process_single_pv(cmd, NULL, pv, handle);
+
+ free_pv_fid(pv);
ret = process_single_pv(cmd, NULL, pv, handle);
if (ret > ret_max)
@@ -804,11 +815,11 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
struct pv_list *pvl;
struct physical_volume *pv;
- struct dm_list *pvslist, *vgnames;
+ struct dm_list *pvslist = NULL, *vgnames;
struct dm_list tags;
struct str_list *sll;
char *at_sign, *tagname;
- int scanned = 0;
+ struct device *dev;
dm_list_init(&tags);
@@ -854,52 +865,36 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
}
pv = pvl->pv;
} else {
- if (!(pv = pv_read(cmd, argv[opt],
- 1, scan_label_only))) {
- log_error("Failed to read physical "
- "volume \"%s\"", argv[opt]);
+ if (!pvslist) {
+ lvmcache_seed_infos_from_lvmetad(cmd);
+ if (!(pvslist = get_pvs(cmd)))
+ goto bad;
+ }
+
+ if (!(dev = dev_cache_get(argv[opt], cmd->filter))) {
+ log_error("Failed to find device "
+ "\"%s\"", argv[opt]);
ret_max = ECMD_FAILED;
continue;
}
- /*
- * If a PV has no MDAs it may appear to be an
- * orphan until the metadata is read off
- * another PV in the same VG. Detecting this
- * means checking every VG by scanning every
- * PV on the system.
- */
- if (!scanned && is_orphan(pv) &&
- dm_list_empty(&pv->fid->metadata_areas_in_use)) {
- if (!scan_label_only &&
- !scan_vgs_for_pvs(cmd, 1)) {
- stack;
- ret_max = ECMD_FAILED;
- continue;
- }
- scanned = 1;
- free_pv_fid(pv);
- if (!(pv = pv_read(cmd, argv[opt],
- 1,
- scan_label_only))) {
- log_error("Failed to read "
- "physical volume "
- "\"%s\"", argv[opt]);
- ret_max = ECMD_FAILED;
- continue;
- }
+ pv = NULL;
+ dm_list_iterate_items(pvl, pvslist)
+ if (pvl->pv->dev == dev)
+ pv = pvl->pv;
+
+ if (!pv) {
+ log_error("Failed to find physical volume "
+ "\"%s\"", argv[opt]);
+ ret_max = ECMD_FAILED;
+ continue;
}
}
ret = process_single_pv(cmd, vg, pv, handle);
+
if (ret > ret_max)
ret_max = ret;
- /*
- * Free PV only if we called pv_read before,
- * otherwise the PV structure is part of the VG.
- */
- if (!vg)
- free_pv_fid(pv);
}
if (!dm_list_empty(&tags) && (vgnames = get_vgnames(cmd, 1)) &&
!dm_list_empty(vgnames)) {
@@ -954,6 +949,10 @@ int process_each_pv(struct cmd_context *cmd, int argc, char **argv,
}
}
out:
+ if (pvslist)
+ dm_list_iterate_items(pvl, pvslist)
+ free_pv_fid(pvl->pv);
+
if (lock_global)
unlock_vg(cmd, VG_GLOBAL);
return ret_max;
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e1a63905d14cc733…
Commit: e1a63905d14cc73352b905c70cb4084b7e521e33
Parent: 803f8ca7146c548c271c04d432a3c68726a0d37d
Author: Petr Rockai <prockai(a)redhat.com>
AuthorDate: Wed Mar 20 14:34:05 2013 +0100
Committer: Petr Rockai <prockai(a)redhat.com>
CommitterDate: Sun Nov 17 21:41:26 2013 +0100
metadata: Do not try to check vg_name of a NULL PV.
---
lib/metadata/metadata.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 8571e0a..869d368 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -1842,7 +1842,7 @@ struct physical_volume *find_pv_by_name(struct cmd_context *cmd,
}
}
- if (!allow_orphan && is_orphan_vg(pv->vg_name)) {
+ if (pv && !allow_orphan && is_orphan_vg(pv->vg_name)) {
log_error("Physical volume %s not in a volume group", pv_name);
goto bad;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=803f8ca7146c548c…
Commit: 803f8ca7146c548c271c04d432a3c68726a0d37d
Parent: 3716e9535455c5fb012511f820d0525e4aa48bc8
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 11 17:19:26 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 15 12:38:37 2013 +0100
tests: used -n for fsck
---
test/shell/lvcreate-thin-snap.sh | 4 ++--
test/shell/lvcreate-thin.sh | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/test/shell/lvcreate-thin-snap.sh b/test/shell/lvcreate-thin-snap.sh
index a223469..b7511e7 100644
--- a/test/shell/lvcreate-thin-snap.sh
+++ b/test/shell/lvcreate-thin-snap.sh
@@ -37,7 +37,7 @@ mkfs.ext4 $DM_DEV_DIR/$vg/$lv1
# create thin snapshot of thin LV
lvcreate -K -s $vg/$lv1 --name snap
# check snapshot filesystem was properly frozen before snapping
-fsck -p $DM_DEV_DIR/$vg/snap
+fsck -n $DM_DEV_DIR/$vg/snap
lvcreate -K -s $vg/$lv1 --name $lv2
lvcreate -K -s $vg/$lv1 --name $vg/$lv3
lvcreate --type snapshot $vg/$lv1
@@ -59,6 +59,6 @@ lvremove -ff $vg
lvcreate -L10M --zero n -T $vg/pool -V10M --name $lv1
mkfs.ext4 $DM_DEV_DIR/$vg/$lv1
lvcreate -K -s $vg/$lv1 --name snap
-fsck -p $DM_DEV_DIR/$vg/snap
+fsck -n $DM_DEV_DIR/$vg/snap
vgremove -ff $vg
diff --git a/test/shell/lvcreate-thin.sh b/test/shell/lvcreate-thin.sh
index d2e3022..98ab7eb 100644
--- a/test/shell/lvcreate-thin.sh
+++ b/test/shell/lvcreate-thin.sh
@@ -138,7 +138,7 @@ check vg_field $vg lv_count 0
lvcreate -L10M -V10M -T $vg/pool --name lv1
mkfs.ext4 $DM_DEV_DIR/$vg/lv1
lvcreate -K -s $vg/lv1 --name snap_lv1
-fsck -p $DM_DEV_DIR/$vg/snap_lv1
+fsck -n $DM_DEV_DIR/$vg/snap_lv1
lvcreate -s $vg/lv1 --name lv2
lvcreate -s $vg/lv1 --name $vg/lv3
lvcreate --type snapshot $vg/lv1 --name lv6
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3716e9535455c5fb…
Commit: 3716e9535455c5fb012511f820d0525e4aa48bc8
Parent: 89a8c7bea6df1d52818837f5a6778d7ae3e9626c
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 4 15:06:55 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 15 12:38:37 2013 +0100
tests: indent
---
test/api/vglist.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/test/api/vglist.c b/test/api/vglist.c
index 3d23369..01f52ec 100644
--- a/test/api/vglist.c
+++ b/test/api/vglist.c
@@ -46,7 +46,7 @@ int main(int argc, char *argv[])
lvm_str_list_t *str;
int i = 0;
struct dm_list *vgnames;
- struct dm_list *vgids;
+ struct dm_list *vgids;
if (argc != 3)
abort();
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=89a8c7bea6df1d52…
Commit: 89a8c7bea6df1d52818837f5a6778d7ae3e9626c
Parent: 3cb9041764005c3a8f59b0b5ede3808b660d001a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Nov 12 15:08:35 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 15 12:38:37 2013 +0100
cleanup: share the nonremoval message
Use common goto label for not remove log error.
---
lib/metadata/lv_manip.c | 23 +++++++++++------------
1 files changed, 11 insertions(+), 12 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 4a224e4..e22aaa2 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -4709,10 +4709,8 @@ int lv_remove_with_dependencies(struct cmd_context *cmd, struct logical_volume *
} else if ((snap_percent == PERCENT_MERGE_FAILED) &&
(force == PROMPT) &&
yes_no_prompt("Removing snapshot \"%s\" that failed to merge may leave origin \"%s\" inconsistent. "
- "Proceed? [y/n]: ", lv->name, origin_from_cow(lv)->name) == 'n') {
- log_error("Logical volume %s not removed.", lv->name);
- return 0;
- }
+ "Proceed? [y/n]: ", lv->name, origin_from_cow(lv)->name) == 'n')
+ goto no_remove;
}
} else if (!level && lv_is_virtual_origin(origin = origin_from_cow(lv)))
/* If this is a sparse device, remove its origin too. */
@@ -4727,10 +4725,8 @@ int lv_remove_with_dependencies(struct cmd_context *cmd, struct logical_volume *
!lv_is_active(lv) &&
yes_no_prompt("Removing origin %s will also remove %u "
"snapshots(s). Proceed? [y/n]: ",
- lv->name, lv->origin_count) == 'n') {
- log_error("Logical volume %s not removed.", lv->name);
- return 0;
- }
+ lv->name, lv->origin_count) == 'n')
+ goto no_remove;
dm_list_iterate_safe(snh, snht, &lv->snapshot_segs)
if (!lv_remove_with_dependencies(cmd, dm_list_struct_base(snh, struct lv_segment,
@@ -4766,12 +4762,15 @@ int lv_remove_with_dependencies(struct cmd_context *cmd, struct logical_volume *
(force == PROMPT) &&
(yes_no_prompt("Removal of pool metadata spare logical volume \"%s\" "
"disables automatic recovery attempts after damage "
- "to a thin pool. Proceed? [y/n]: ", lv->name) == 'n')) {
- log_error("Logical volume \"%s\" not removed.", lv->name);
- return 0;
- }
+ "to a thin pool. Proceed? [y/n]: ", lv->name) == 'n'))
+ goto no_remove;
return lv_remove_single(cmd, lv, force);
+
+no_remove:
+ log_error("Logical volume \"%s\" not removed.", lv->name);
+
+ return 0;
}
/*
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3cb9041764005c3a…
Commit: 3cb9041764005c3a8f59b0b5ede3808b660d001a
Parent: eb4b03768f3ae751518b77b69882539e0c864a90
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Sep 24 14:47:32 2013 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 15 12:38:37 2013 +0100
cleanup: do not pass uninitialized space to selinux.
Just like with dm_prepare_selinux_context rather initialize to NULL.
---
libdm/libdm-common.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c
index febcd0e..5ec5769 100644
--- a/libdm/libdm-common.c
+++ b/libdm/libdm-common.c
@@ -899,7 +899,7 @@ int dm_prepare_selinux_context(const char *path, mode_t mode)
int dm_set_selinux_context(const char *path, mode_t mode)
{
#ifdef HAVE_SELINUX
- security_context_t scontext;
+ security_context_t scontext = NULL;
if (is_selinux_enabled() <= 0)
return 1;
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=eb4b03768f3ae751…
Commit: eb4b03768f3ae751518b77b69882539e0c864a90
Parent: 37b7c6707952b0cca2c583f2a48f997c94576a70
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 15 12:16:50 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 15 12:38:37 2013 +0100
libdm: catch wrongly reported values
Add internal error warning when string value is used
as sort value for numerical field.
Using log_warn since the function itself does not return error,
so we do not confuse log_error() checker.
---
WHATS_NEW_DM | 1 +
libdm/libdm-report.c | 4 ++++
2 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index e3953e4..24d53af 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.84 -
====================================
+ Catch invalid use of string sort values when reporting numerical fields.
Version 1.02.83 - 13th November 2013
====================================
diff --git a/libdm/libdm-report.c b/libdm/libdm-report.c
index 0984416..7e8484e 100644
--- a/libdm/libdm-report.c
+++ b/libdm/libdm-report.c
@@ -240,6 +240,10 @@ void dm_report_field_set_value(struct dm_report_field *field, const void *value,
{
field->report_string = (const char *) value;
field->sort_value = sortvalue ? : value;
+
+ if ((field->sort_value == value) &&
+ (field->props->flags & DM_REPORT_FIELD_TYPE_NUMBER))
+ log_warn(INTERNAL_ERROR "Using string as sort value for numerical field.");
}
/*
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=37b7c6707952b0cc…
Commit: 37b7c6707952b0cca2c583f2a48f997c94576a70
Parent: 6ca832ceafe4ca599e059464faf2ef5760a29b23
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Nov 11 10:05:45 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 15 12:38:37 2013 +0100
thin: report thin device id
Support lvs -o+thin_id to report thin device id.
This device_id is connection between kernel and lvm2 user space thin
metadata.
---
WHATS_NEW | 1 +
lib/display/display.c | 1 +
lib/report/columns.h | 1 +
lib/report/properties.c | 2 ++
lib/report/report.c | 12 ++++++++++++
test/shell/lvcreate-thin.sh | 1 +
6 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index fb3b21a..0a4909a 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Add reporting of thin_id device id for thin volumes.
Fix reporting of empty numerical values.
Simplify reporting code.
diff --git a/lib/display/display.c b/lib/display/display.c
index d3b4d6e..be56f12 100644
--- a/lib/display/display.c
+++ b/lib/display/display.c
@@ -600,6 +600,7 @@ int lvdisplay_full(struct cmd_context *cmd,
if (lv_is_thin_volume(lv)) {
seg = first_seg(lv);
log_print("LV Pool name %s", seg->pool_lv->name);
+ log_print("LV Thin device ID %u", seg->device_id);
if (seg->origin)
log_print("LV Thin origin name %s",
seg->origin->name);
diff --git a/lib/report/columns.h b/lib/report/columns.h
index 6df9771..88a0266 100644
--- a/lib/report/columns.h
+++ b/lib/report/columns.h
@@ -122,6 +122,7 @@ FIELD(SEGS, seg, NUM, "#Thins", list, 4, thincount, thin_count, "For thin pools,
FIELD(SEGS, seg, STR, "Discards", list, 8, discards, discards, "For thin pools, how discards are handled.", 0)
FIELD(SEGS, seg, NUM, "Zero", list, 4, thinzero, zero, "For thin pools, if zeroing is enabled.", 0)
FIELD(SEGS, seg, NUM, "TransId", list, 4, transactionid, transaction_id, "For thin pools, the transaction id.", 0)
+FIELD(SEGS, seg, NUM, "ThId", list, 4, thinid, thin_id, "For thin volume, the thin device id.", 0)
FIELD(SEGS, seg, NUM, "Start", list, 5, segstart, seg_start, "Offset within the LV to the start of the segment in current units.", 0)
FIELD(SEGS, seg, NUM, "Start", list, 5, segstartpe, seg_start_pe, "Offset within the LV to the start of the segment in physical extents.", 0)
FIELD(SEGS, seg, NUM, "SSize", list, 5, segsize, seg_size, "Size of segment in current units.", 0)
diff --git a/lib/report/properties.c b/lib/report/properties.c
index 56200f0..8c48de1 100644
--- a/lib/report/properties.c
+++ b/lib/report/properties.c
@@ -307,6 +307,8 @@ GET_LVSEG_NUM_PROPERTY_FN(zero, lvseg->zero_new_blocks)
#define _zero_set prop_not_implemented_set
GET_LVSEG_NUM_PROPERTY_FN(transaction_id, lvseg->transaction_id)
#define _transaction_id_set prop_not_implemented_set
+GET_LVSEG_NUM_PROPERTY_FN(thin_id, lvseg->device_id)
+#define _thin_id_set prop_not_implemented_set
GET_LVSEG_STR_PROPERTY_FN(discards, lvseg_discards_dup(lvseg->lv->vg->vgmem, lvseg))
#define _discards_set prop_not_implemented_set
GET_LVSEG_NUM_PROPERTY_FN(seg_start, (SECTOR_SIZE * lvseg_start(lvseg)))
diff --git a/lib/report/report.c b/lib/report/report.c
index 1565aec..c780ca4 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -610,6 +610,18 @@ static int _transactionid_disp(struct dm_report *rh, struct dm_pool *mem,
return _field_set_value(field, "", &_minusone64);
}
+static int _thinid_disp(struct dm_report *rh, struct dm_pool *mem,
+ struct dm_report_field *field,
+ const void *data, void *private)
+{
+ const struct lv_segment *seg = (const struct lv_segment *) data;
+
+ if (seg_is_thin_volume(seg))
+ return dm_report_field_uint32(rh, field, &seg->device_id);
+
+ return _field_set_value(field, "", &_minusone64);
+}
+
static int _discards_disp(struct dm_report *rh, struct dm_pool *mem,
struct dm_report_field *field,
const void *data, void *private)
diff --git a/test/shell/lvcreate-thin.sh b/test/shell/lvcreate-thin.sh
index 743da3b..d2e3022 100644
--- a/test/shell/lvcreate-thin.sh
+++ b/test/shell/lvcreate-thin.sh
@@ -129,6 +129,7 @@ lvcreate -V2G --type thin --thinpool pool --name $vg/lv12 $vg
check lv_exists $vg lv1 lv2 lv3 lv4 lv5 lv6 lv7 lv8 lv9 lv10 lv11 lv12
check vg_field $vg lv_count 19
+check lv_field $vg/lv1 thin_id 7
lvremove -ff $vg
check vg_field $vg lv_count 0
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=6ca832ceafe4ca59…
Commit: 6ca832ceafe4ca599e059464faf2ef5760a29b23
Parent: 36d7c639d14e121e839b2117dcf744097e6ebfde
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 23 11:03:02 2013 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 15 11:05:03 2013 +0100
report: use _field_set_percent
Use common routine for displaying percentage.
---
lib/report/report.c | 131 ++++++++++-----------------------------------------
1 files changed, 25 insertions(+), 106 deletions(-)
diff --git a/lib/report/report.c b/lib/report/report.c
index 5caebb2..1565aec 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -34,6 +34,7 @@ struct lvm_report_object {
struct pv_segment *pvseg;
};
+static const uint64_t _hundred64 = UINT64_C(100);
static const uint64_t _minusone64 = UINT64_C(-1);
static const int32_t _minusone32 = INT32_C(-1);
static const uint64_t _zero64 = UINT64_C(0);
@@ -851,56 +852,23 @@ static int _snpercent_disp(struct dm_report *rh __attribute__((unused)), struct
{
const struct logical_volume *lv = (const struct logical_volume *) data;
percent_t snap_percent;
- uint64_t *sortval;
- char *repstr;
-
- /* Suppress snapshot percentage if not using driver */
- if (!activation()) {
- dm_report_field_set_value(field, "", NULL);
- return 1;
- }
-
- if (!(sortval = dm_pool_alloc(mem, sizeof(uint64_t)))) {
- log_error("dm_pool_alloc failed");
- return 0;
- }
- if ((!lv_is_cow(lv) && !lv_is_merging_origin(lv)) ||
- !lv_is_active_locally(lv)) {
- *sortval = UINT64_C(0);
- dm_report_field_set_value(field, "", sortval);
- return 1;
- }
+ if ((lv_is_cow(lv) || lv_is_merging_origin(lv)) &&
+ lv_snapshot_percent(lv, &snap_percent)) {
+ if ((snap_percent != PERCENT_INVALID) &&
+ (snap_percent != PERCENT_MERGE_FAILED))
+ return _field_set_percent(field, mem, snap_percent);
- if (!lv_snapshot_percent(lv, &snap_percent) ||
- (snap_percent == PERCENT_INVALID) || (snap_percent == PERCENT_MERGE_FAILED)) {
- if (!lv_is_merging_origin(lv)) {
- *sortval = UINT64_C(100);
- dm_report_field_set_value(field, "100.00", sortval);
- } else {
- /* onactivate merge that hasn't started yet would
- * otherwise display incorrect snap% in origin
- */
- *sortval = UINT64_C(0);
- dm_report_field_set_value(field, "", sortval);
- }
- return 1;
- }
+ if (!lv_is_merging_origin(lv))
+ return _field_set_value(field, "100.00", &_hundred64);
- if (!(repstr = dm_pool_zalloc(mem, 8))) {
- log_error("dm_pool_alloc failed");
- return 0;
+ /*
+ * on activate merge that hasn't started yet would
+ * otherwise display incorrect snap% in origin
+ */
}
- if (dm_snprintf(repstr, 7, "%.2f", percent_to_float(snap_percent)) < 0) {
- log_error("snapshot percentage too large");
- return 0;
- }
-
- *sortval = (uint64_t)(snap_percent * 1000.f);
- dm_report_field_set_value(field, repstr, sortval);
-
- return 1;
+ return _field_set_value(field, "", &_minusone64);
}
static int _copypercent_disp(struct dm_report *rh __attribute__((unused)),
@@ -910,44 +878,17 @@ static int _copypercent_disp(struct dm_report *rh __attribute__((unused)),
{
const struct logical_volume *lv = (const struct logical_volume *) data;
percent_t percent;
- uint64_t *sortval;
- char *repstr;
-
- if (!(sortval = dm_pool_alloc(mem, sizeof(uint64_t)))) {
- log_error("dm_pool_alloc failed");
- return 0;
- }
-
- if (lv->status & RAID) {
- if (!lv_raid_percent(lv, &percent) ||
- (percent == PERCENT_INVALID))
- goto no_copypercent;
- } else if ((!(lv->status & PVMOVE) && !(lv->status & MIRRORED)) ||
- !lv_mirror_percent(lv->vg->cmd, lv, 0, &percent, NULL) ||
- (percent == PERCENT_INVALID))
- goto no_copypercent;
- percent = copy_percent(lv);
+ if (((lv_is_raid(lv) && lv_raid_percent(lv, &percent)) ||
- if (!(repstr = dm_pool_zalloc(mem, 8))) {
- log_error("dm_pool_alloc failed");
- return 0;
+ ((lv->status & (PVMOVE | MIRRORED)) &&
+ lv_mirror_percent(lv->vg->cmd, lv, 0, &percent, NULL))) &&
+ (percent != PERCENT_INVALID)) {
+ percent = copy_percent(lv);
+ return _field_set_percent(field, mem, percent);
}
- if (dm_snprintf(repstr, 7, "%.2f", percent_to_float(percent)) < 0) {
- log_error("copy percentage too large");
- return 0;
- }
-
- *sortval = (uint64_t)(percent * 1000.f);
- dm_report_field_set_value(field, repstr, sortval);
-
- return 1;
-
-no_copypercent:
- *sortval = UINT64_C(0);
- dm_report_field_set_value(field, "", sortval);
- return 1;
+ return _field_set_value(field, "", &_minusone64);
}
static int _raidsyncaction_disp(struct dm_report *rh __attribute__((unused)),
@@ -1030,21 +971,12 @@ static int _dtpercent_disp(int metadata, struct dm_pool *mem,
const void *data, void *private)
{
const struct logical_volume *lv = (const struct logical_volume *) data;
- struct lvinfo info;
percent_t percent;
- uint64_t *sortval;
- char *repstr;
- /* Suppress data percent if not thin pool/volume or not using driver */
- if (!lv_info(lv->vg->cmd, lv, 1, &info, 0, 0) || !info.exists) {
- dm_report_field_set_value(field, "", NULL);
- return 1;
- }
-
- if (!(sortval = dm_pool_zalloc(mem, sizeof(uint64_t)))) {
- log_error("Failed to allocate sortval.");
- return 0;
- }
+ /* Suppress data percent if not using driver */
+ /* cannot use lv_is_active_locally - need to check for layer -tpool */
+ if (!lv_info(lv->vg->cmd, lv, 1, NULL, 0, 0))
+ return _field_set_value(field, "", &_minusone64);
if (lv_is_thin_pool(lv)) {
if (!lv_thin_pool_percent(lv, metadata, &percent))
@@ -1054,20 +986,7 @@ static int _dtpercent_disp(int metadata, struct dm_pool *mem,
return_0;
}
- if (!(repstr = dm_pool_alloc(mem, 8))) {
- log_error("Failed to allocate report buffer.");
- return 0;
- }
-
- if (dm_snprintf(repstr, 8, "%.2f", percent_to_float(percent)) < 0) {
- log_error("Data percentage too large.");
- return 0;
- }
-
- *sortval = (uint64_t)(percent * 1000.f);
- dm_report_field_set_value(field, repstr, sortval);
-
- return 1;
+ return _field_set_percent(field, mem, percent);
}
static int _datapercent_disp(struct dm_report *rh, struct dm_pool *mem,
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=36d7c639d14e121e…
Commit: 36d7c639d14e121e839b2117dcf744097e6ebfde
Parent: 9eb81b1bf74411bba6cc950a4ebe0a44856c0e74
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 23 10:18:10 2013 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 15 11:05:02 2013 +0100
report: fix dereference of string as uint64_t
Fix buggy usage of "" (empty string) as a numerical string
value used for sorting.
On intel 64b platform this was typically resolve
as 0xffffff0000000000 - which is already 'close' to
UINT64_MAX which is used for _minusone64.
On other platforms it might have been giving
different numbers depends on aligment of strings.
Use proper &_minusone64 for sorting value when the reported
value is NUM.
Note: each numerical value needs to be thought about if it needs
default value &_zero64 or &_minusone64 since for cases, were
value of zero is valid, sorting should not be mixing entries
together.
---
WHATS_NEW | 1 +
lib/report/report.c | 84 ++++++++++++++++++--------------------------------
2 files changed, 31 insertions(+), 54 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index b190ca4..fb3b21a 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Fix reporting of empty numerical values.
Simplify reporting code.
Version 2.02.104 - 13th November 2013
diff --git a/lib/report/report.c b/lib/report/report.c
index 697d642..5caebb2 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -591,13 +591,10 @@ static int _thinzero_disp(struct dm_report *rh, struct dm_pool *mem,
{
const struct lv_segment *seg = (const struct lv_segment *) data;
- /* Suppress thin count if not thin pool */
- if (!seg_is_thin_pool(seg)) {
- dm_report_field_set_value(field, "", NULL);
- return 1;
- }
+ if (seg_is_thin_pool(seg))
+ return _uint32_disp(rh, mem, field, &seg->zero_new_blocks, private);
- return _uint32_disp(rh, mem, field, &seg->zero_new_blocks, private);
+ return _field_set_value(field, "", &_minusone64);
}
static int _transactionid_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -606,13 +603,10 @@ static int _transactionid_disp(struct dm_report *rh, struct dm_pool *mem,
{
const struct lv_segment *seg = (const struct lv_segment *) data;
- /* Suppress thin count if not thin pool */
- if (!seg_is_thin_pool(seg)) {
- dm_report_field_set_value(field, "", NULL);
- return 1;
- }
+ if (seg_is_thin_pool(seg))
+ return dm_report_field_uint64(rh, field, &seg->transaction_id);
- return dm_report_field_uint64(rh, field, &seg->transaction_id);
+ return _field_set_value(field, "", &_minusone64);
}
static int _discards_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -980,13 +974,10 @@ static int _raidmismatchcount_disp(struct dm_report *rh __attribute__((unused)),
const struct logical_volume *lv = (const struct logical_volume *) data;
uint64_t mismatch_count;
- if (!(lv->status & RAID) ||
- !lv_raid_mismatch_count(lv, &mismatch_count)) {
- dm_report_field_set_value(field, "", NULL);
- return 1;
- }
+ if (lv_is_raid(lv) && lv_raid_mismatch_count(lv, &mismatch_count))
+ return dm_report_field_uint64(rh, field, &mismatch_count);
- return dm_report_field_uint64(rh, field, &mismatch_count);
+ return _field_set_value(field, "", &_minusone64);
}
static int _raidwritebehind_disp(struct dm_report *rh __attribute__((unused)),
@@ -997,12 +988,10 @@ static int _raidwritebehind_disp(struct dm_report *rh __attribute__((unused)),
{
const struct logical_volume *lv = (const struct logical_volume *) data;
- if (!lv_is_raid_type(lv) || !first_seg(lv)->writebehind) {
- dm_report_field_set_value(field, "", NULL);
- return 1;
- }
+ if (lv_is_raid_type(lv) && first_seg(lv)->writebehind)
+ return dm_report_field_uint32(rh, field, &first_seg(lv)->writebehind);
- return dm_report_field_uint32(rh, field, &first_seg(lv)->writebehind);
+ return _field_set_value(field, "", &_minusone64);
}
static int _raidminrecoveryrate_disp(struct dm_report *rh __attribute__((unused)),
@@ -1013,13 +1002,11 @@ static int _raidminrecoveryrate_disp(struct dm_report *rh __attribute__((unused)
{
const struct logical_volume *lv = (const struct logical_volume *) data;
- if (!lv_is_raid_type(lv) || !first_seg(lv)->min_recovery_rate) {
- dm_report_field_set_value(field, "", NULL);
- return 1;
- }
+ if (lv_is_raid_type(lv) && first_seg(lv)->min_recovery_rate)
+ return dm_report_field_uint32(rh, field,
+ &first_seg(lv)->min_recovery_rate);
- return dm_report_field_uint32(rh, field,
- &first_seg(lv)->min_recovery_rate);
+ return _field_set_value(field, "", &_minusone64);
}
static int _raidmaxrecoveryrate_disp(struct dm_report *rh __attribute__((unused)),
@@ -1030,13 +1017,11 @@ static int _raidmaxrecoveryrate_disp(struct dm_report *rh __attribute__((unused)
{
const struct logical_volume *lv = (const struct logical_volume *) data;
- if (!lv_is_raid_type(lv) || !first_seg(lv)->max_recovery_rate) {
- dm_report_field_set_value(field, "", NULL);
- return 1;
- }
+ if (lv_is_raid_type(lv) && first_seg(lv)->max_recovery_rate)
+ return dm_report_field_uint32(rh, field,
+ &first_seg(lv)->max_recovery_rate);
- return dm_report_field_uint32(rh, field,
- &first_seg(lv)->max_recovery_rate);
+ return _field_set_value(field, "", &_minusone64);
}
/* Called only with lv_is_thin_pool/volume */
@@ -1097,9 +1082,7 @@ static int _datapercent_disp(struct dm_report *rh, struct dm_pool *mem,
if (lv_is_thin_pool(lv) || lv_is_thin_volume(lv))
return _dtpercent_disp(0, mem, field, data, private);
- dm_report_field_set_value(field, "", NULL);
-
- return 1;
+ return _field_set_value(field, "", &_minusone64);
}
static int _metadatapercent_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -1111,9 +1094,7 @@ static int _metadatapercent_disp(struct dm_report *rh, struct dm_pool *mem,
if (lv_is_thin_pool(lv))
return _dtpercent_disp(1, mem, field, data, private);
- dm_report_field_set_value(field, "", NULL);
-
- return 1;
+ return _field_set_value(field, "", &_minusone64);
}
static int _lvmetadatasize_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -1123,14 +1104,12 @@ 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_thin_pool(lv)) {
- dm_report_field_set_value(field, "", NULL);
- return 1;
+ if (lv_is_thin_pool(lv)) {
+ size = lv_metadata_size(lv);
+ return _size64_disp(rh, mem, field, &size, private);
}
- size = lv_metadata_size(lv);
-
- return _size64_disp(rh, mem, field, &size, private);
+ return _field_set_value(field, "", &_minusone64);
}
static int _thincount_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -1140,15 +1119,12 @@ static int _thincount_disp(struct dm_report *rh, struct dm_pool *mem,
const struct lv_segment *seg = (const struct lv_segment *) data;
uint32_t count;
- /* Suppress thin count if not thin pool */
- if (!seg_is_thin_pool(seg)) {
- dm_report_field_set_value(field, "", NULL);
- return 1;
+ if (seg_is_thin_pool(seg)) {
+ count = dm_list_size(&seg->lv->segs_using_this_lv);
+ return _uint32_disp(rh, mem, field, &count, private);
}
- count = dm_list_size(&seg->lv->segs_using_this_lv);
-
- return _uint32_disp(rh, mem, field, &count, private);
+ return _field_set_value(field, "", &_minusone64);
}
static int _lvtime_disp(struct dm_report *rh, struct dm_pool *mem,
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9eb81b1bf74411bb…
Commit: 9eb81b1bf74411bba6cc950a4ebe0a44856c0e74
Parent: 49ccf44f4505242262bf35f7e226d2791aad9397
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 23 10:17:50 2013 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 15 11:05:02 2013 +0100
report: using _field_set_value
Simple conversion to use _field_set_value() and shorteing
the code.
---
lib/report/report.c | 162 ++++++++++++++++++---------------------------------
1 files changed, 56 insertions(+), 106 deletions(-)
diff --git a/lib/report/report.c b/lib/report/report.c
index 49a6b8a..697d642 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -106,12 +106,11 @@ static int _devices_disp(struct dm_report *rh __attribute__((unused)), struct dm
const void *data, void *private __attribute__((unused)))
{
char *str;
- if (!(str = lvseg_devices(mem, (const struct lv_segment *) data)))
- return 0;
- dm_report_field_set_value(field, str, NULL);
+ if (!(str = lvseg_devices(mem, (const struct lv_segment *) data)))
+ return_0;
- return 1;
+ return _field_set_value(field, str, NULL);
}
static int _peranges_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem,
@@ -119,12 +118,11 @@ static int _peranges_disp(struct dm_report *rh __attribute__((unused)), struct d
const void *data, void *private __attribute__((unused)))
{
char *str;
- if (!(str = lvseg_seg_pe_ranges(mem, (const struct lv_segment *) data)))
- return 0;
- dm_report_field_set_value(field, str, NULL);
+ if (!(str = lvseg_seg_pe_ranges(mem, (const struct lv_segment *) data)))
+ return_0;
- return 1;
+ return _field_set_value(field, str, NULL);
}
static int _tags_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem,
@@ -135,11 +133,9 @@ static int _tags_disp(struct dm_report *rh __attribute__((unused)), struct dm_po
char *tags_str;
if (!(tags_str = tags_format_and_copy(mem, tags)))
- return 0;
-
- dm_report_field_set_value(field, tags_str, NULL);
+ return_0;
- return 1;
+ return _field_set_value(field, tags_str, NULL);
}
static int _modules_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -150,10 +146,9 @@ static int _modules_disp(struct dm_report *rh, struct dm_pool *mem,
char *modules_str;
if (!(modules_str = lv_modules_dup(mem, lv)))
- return 0;
+ return_0;
- dm_report_field_set_value(field, modules_str, NULL);
- return 1;
+ return _field_set_value(field, modules_str, NULL);
}
static int _lvprofile_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -165,8 +160,7 @@ static int _lvprofile_disp(struct dm_report *rh, struct dm_pool *mem,
if (lv->profile)
return dm_report_field_string(rh, field, &lv->profile->name);
- dm_report_field_set_value(field, "", NULL);
- return 1;
+ return _field_set_value(field, "", NULL);
}
static int _vgfmt_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -175,12 +169,10 @@ static int _vgfmt_disp(struct dm_report *rh, struct dm_pool *mem,
{
const struct volume_group *vg = (const struct volume_group *) data;
- if (!vg->fid) {
- dm_report_field_set_value(field, "", NULL);
- return 1;
- }
+ if (vg->fid)
+ return _string_disp(rh, mem, field, &vg->fid->fmt->name, private);
- return _string_disp(rh, mem, field, &vg->fid->fmt->name, private);
+ return _field_set_value(field, "", NULL);
}
static int _pvfmt_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -190,12 +182,10 @@ static int _pvfmt_disp(struct dm_report *rh, struct dm_pool *mem,
const struct physical_volume *pv =
(const struct physical_volume *) data;
- if (!pv->fmt) {
- dm_report_field_set_value(field, "", NULL);
- return 1;
- }
+ if (pv->fmt)
+ return _string_disp(rh, mem, field, &pv->fmt->name, private);
- return _string_disp(rh, mem, field, &pv->fmt->name, private);
+ return _field_set_value(field, "", NULL);
}
static int _lvkmaj_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
@@ -232,10 +222,9 @@ static int _lvstatus_disp(struct dm_report *rh __attribute__((unused)), struct d
char *repstr;
if (!(repstr = lv_attr_dup(mem, lv)))
- return 0;
+ return_0;
- dm_report_field_set_value(field, repstr, NULL);
- return 1;
+ return _field_set_value(field, repstr, NULL);
}
static int _pvstatus_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem,
@@ -247,10 +236,9 @@ static int _pvstatus_disp(struct dm_report *rh __attribute__((unused)), struct d
char *repstr;
if (!(repstr = pv_attr_dup(mem, pv)))
- return 0;
+ return_0;
- dm_report_field_set_value(field, repstr, NULL);
- return 1;
+ return _field_set_value(field, repstr, NULL);
}
static int _vgstatus_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem,
@@ -261,10 +249,9 @@ static int _vgstatus_disp(struct dm_report *rh __attribute__((unused)), struct d
char *repstr;
if (!(repstr = vg_attr_dup(mem, vg)))
- return 0;
+ return_0;
- dm_report_field_set_value(field, repstr, NULL);
- return 1;
+ return _field_set_value(field, repstr, NULL);
}
static int _segtype_disp(struct dm_report *rh __attribute__((unused)),
@@ -280,8 +267,7 @@ static int _segtype_disp(struct dm_report *rh __attribute__((unused)),
return 0;
}
- dm_report_field_set_value(field, name, NULL);
- return 1;
+ return _field_set_value(field, name, NULL);
}
static int _loglv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
@@ -294,8 +280,7 @@ static int _loglv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((
if ((name = lv_mirror_log_dup(mem, lv)))
return dm_report_field_string(rh, field, &name);
- dm_report_field_set_value(field, "", NULL);
- return 1;
+ return _field_set_value(field, "", NULL);
}
static int _lvname_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -325,9 +310,7 @@ static int _lvname_disp(struct dm_report *rh, struct dm_pool *mem,
return 0;
}
- dm_report_field_set_value(field, repstr, lvname);
-
- return 1;
+ return _field_set_value(field, repstr, lvname);
}
static int _datalv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
@@ -340,8 +323,7 @@ static int _datalv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__(
if (seg)
return _lvname_disp(rh, mem, field, seg_lv(seg, 0), private);
- dm_report_field_set_value(field, "", NULL);
- return 1;
+ return _field_set_value(field, "", NULL);
}
static int _metadatalv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
@@ -354,8 +336,7 @@ static int _metadatalv_disp(struct dm_report *rh, struct dm_pool *mem __attribut
if (seg)
return _lvname_disp(rh, mem, field, seg->metadata_lv, private);
- dm_report_field_set_value(field, "", NULL);
- return 1;
+ return _field_set_value(field, "", NULL);
}
static int _poollv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
@@ -368,8 +349,7 @@ static int _poollv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__(
if (seg)
return _lvname_disp(rh, mem, field, seg->pool_lv, private);
- dm_report_field_set_value(field, "", NULL);
- return 1;
+ return _field_set_value(field, "", NULL);
}
static int _lvpath_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -380,11 +360,9 @@ static int _lvpath_disp(struct dm_report *rh, struct dm_pool *mem,
char *repstr;
if (!(repstr = lv_path_dup(mem, lv)))
- return 0;
-
- dm_report_field_set_value(field, repstr, NULL);
+ return_0;
- return 1;
+ return _field_set_value(field, repstr, NULL);
}
static int _origin_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -402,8 +380,7 @@ static int _origin_disp(struct dm_report *rh, struct dm_pool *mem,
if (lv_is_thin_volume(lv) && first_seg(lv)->external_lv)
return _lvname_disp(rh, mem, field, first_seg(lv)->external_lv, private);
- dm_report_field_set_value(field, "", NULL);
- return 1;
+ return _field_set_value(field, "", NULL);
}
static int _movepv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
@@ -413,11 +390,10 @@ static int _movepv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__(
const struct logical_volume *lv = (const struct logical_volume *) data;
const char *name;
- if (!(name = lv_move_pv_dup(mem, lv)))
- dm_report_field_set_value(field, "", NULL);
- else
+ if ((name = lv_move_pv_dup(mem, lv)))
return dm_report_field_string(rh, field, &name);
- return 1;
+
+ return _field_set_value(field, "", NULL);
}
static int _convertlv_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
@@ -425,14 +401,12 @@ static int _convertlv_disp(struct dm_report *rh, struct dm_pool *mem __attribute
const void *data, void *private __attribute__((unused)))
{
const struct logical_volume *lv = (const struct logical_volume *) data;
- const char *name = NULL;
+ const char *name;
- name = lv_convert_lv_dup(mem, lv);
- if (name)
+ if ((name = lv_convert_lv_dup(mem, lv)))
return dm_report_field_string(rh, field, &name);
- dm_report_field_set_value(field, "", NULL);
- return 1;
+ return _field_set_value(field, "", NULL);
}
static int _size32_disp(struct dm_report *rh __attribute__((unused)), struct dm_pool *mem,
@@ -458,9 +432,7 @@ static int _size32_disp(struct dm_report *rh __attribute__((unused)), struct dm_
*sortval = (uint64_t) size;
- dm_report_field_set_value(field, repstr, sortval);
-
- return 1;
+ return _field_set_value(field, repstr, sortval);
}
static int _size64_disp(struct dm_report *rh __attribute__((unused)),
@@ -486,9 +458,8 @@ static int _size64_disp(struct dm_report *rh __attribute__((unused)),
}
*sortval = size;
- dm_report_field_set_value(field, repstr, sortval);
- return 1;
+ return _field_set_value(field, repstr, sortval);
}
static int _uint32_disp(struct dm_report *rh, struct dm_pool *mem __attribute__((unused)),
@@ -520,10 +491,8 @@ static int _lvreadahead_disp(struct dm_report *rh, struct dm_pool *mem,
{
const struct logical_volume *lv = (const struct logical_volume *) data;
- if (lv->read_ahead == DM_READ_AHEAD_AUTO) {
- dm_report_field_set_value(field, "auto", &_minusone64);
- return 1;
- }
+ if (lv->read_ahead == DM_READ_AHEAD_AUTO)
+ return _field_set_value(field, "auto", &_minusone64);
return _size32_disp(rh, mem, field, &lv->read_ahead, private);
}
@@ -561,9 +530,7 @@ static int _segmonitor_disp(struct dm_report *rh, struct dm_pool *mem,
if (!(str = lvseg_monitor_dup(mem, (const struct lv_segment *)data)))
return_0;
- dm_report_field_set_value(field, str, NULL);
-
- return 1;
+ return _field_set_value(field, str, NULL);
}
static int _segstart_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -663,9 +630,7 @@ static int _discards_disp(struct dm_report *rh, struct dm_pool *mem,
return dm_report_field_string(rh, field, &discards_str);
}
- dm_report_field_set_value(field, "", NULL);
-
- return 1;
+ return _field_set_value(field, "", NULL);
}
static int _originsize_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -678,9 +643,7 @@ static int _originsize_disp(struct dm_report *rh, struct dm_pool *mem,
if (size)
return _size64_disp(rh, mem, field, &size, private);
- dm_report_field_set_value(field, "", &_zero64);
-
- return 1;
+ return _field_set_value(field, "", &_zero64);
}
static int _pvused_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -741,13 +704,12 @@ static int _uuid_disp(struct dm_report *rh __attribute__((unused)), struct dm_po
struct dm_report_field *field,
const void *data, void *private __attribute__((unused)))
{
- char *repstr = NULL;
+ char *repstr;
if (!(repstr = id_format_and_copy(mem, data)))
return_0;
- dm_report_field_set_value(field, repstr, NULL);
- return 1;
+ return _field_set_value(field, repstr, NULL);
}
static int _pvmdas_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -799,10 +761,8 @@ static int _vgmdacopies_disp(struct dm_report *rh, struct dm_pool *mem,
const struct volume_group *vg = (const struct volume_group *) data;
uint32_t count = vg_mda_copies(vg);
- if (count == VGMETADATACOPIES_UNMANAGED) {
- dm_report_field_set_value(field, "unmanaged", &_minusone64);
- return 1;
- }
+ if (count == VGMETADATACOPIES_UNMANAGED)
+ return _field_set_value(field, "unmanaged", &_minusone64);
return _uint32_disp(rh, mem, field, &count, private);
}
@@ -816,8 +776,7 @@ static int _vgprofile_disp(struct dm_report *rh, struct dm_pool *mem,
if (vg->profile)
return dm_report_field_string(rh, field, &vg->profile->name);
- dm_report_field_set_value(field, "", NULL);
- return 1;
+ return _field_set_value(field, "", NULL);
}
static int _pvmdafree_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -1006,13 +965,10 @@ static int _raidsyncaction_disp(struct dm_report *rh __attribute__((unused)),
const struct logical_volume *lv = (const struct logical_volume *) data;
char *sync_action;
- if (!(lv->status & RAID) ||
- !lv_raid_sync_action(lv, &sync_action)) {
- dm_report_field_set_value(field, "", NULL);
- return 1;
- }
+ if (lv_is_raid(lv) && lv_raid_sync_action(lv, &sync_action))
+ return _string_disp(rh, mem, field, &sync_action, private);
- return _string_disp(rh, mem, field, &sync_action, private);
+ return _field_set_value(field, "", NULL);
}
static int _raidmismatchcount_disp(struct dm_report *rh __attribute__((unused)),
@@ -1211,9 +1167,7 @@ static int _lvtime_disp(struct dm_report *rh, struct dm_pool *mem,
*sortval = lv->timestamp;
- dm_report_field_set_value(field, repstr, sortval);
-
- return 1;
+ return _field_set_value(field, repstr, sortval);
}
static int _lvhost_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -1228,9 +1182,7 @@ static int _lvhost_disp(struct dm_report *rh, struct dm_pool *mem,
return 0;
}
- dm_report_field_set_value(field, repstr, repstr);
-
- return 1;
+ return _field_set_value(field, repstr, NULL);
}
static int _lvactive_disp(struct dm_report *rh, struct dm_pool *mem,
@@ -1244,9 +1196,7 @@ static int _lvactive_disp(struct dm_report *rh, struct dm_pool *mem,
return 0;
}
- dm_report_field_set_value(field, repstr, NULL);
-
- return 1;
+ return _field_set_value(field, repstr, NULL);
}
/* Report object types */
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=49ccf44f45052422…
Commit: 49ccf44f4505242262bf35f7e226d2791aad9397
Parent: 322e7b3060e79e62708f7936f140386d64704878
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Sep 23 10:02:01 2013 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 15 11:05:00 2013 +0100
report: add wrappers to set values and percents
Add wrapper function for dm_report_field_set_value() which returns void
and return 1, so the code could be shorter.
Add wrapper function for percent display _field_set_percent().
---
WHATS_NEW | 1 +
lib/report/report.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index b6f51e1..b190ca4 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.105 -
=====================================
+ Simplify reporting code.
Version 2.02.104 - 13th November 2013
=====================================
diff --git a/lib/report/report.c b/lib/report/report.c
index 46edf56..49a6b8a 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -38,6 +38,43 @@ static const uint64_t _minusone64 = UINT64_C(-1);
static const int32_t _minusone32 = INT32_C(-1);
static const uint64_t _zero64 = UINT64_C(0);
+static int _field_set_value(struct dm_report_field *field, const void *data, const void *sort)
+{
+ dm_report_field_set_value(field, data, sort);
+
+ return 1;
+}
+
+static int _field_set_percent(struct dm_report_field *field,
+ struct dm_pool *mem,
+ percent_t percent)
+{
+ char *repstr;
+ uint64_t *sortval;
+
+ if (percent == PERCENT_INVALID)
+ // FIXME maybe use here '--'?
+ return _field_set_value(field, "", &_minusone64);
+
+ if (!(repstr = dm_pool_alloc(mem, 8)) ||
+ !(sortval = dm_pool_alloc(mem, sizeof(uint64_t)))) {
+ if (repstr)
+ dm_pool_free(mem, repstr);
+ log_error("dm_pool_alloc failed.");
+ return 0;
+ }
+
+ if (dm_snprintf(repstr, 7, "%.2f", percent_to_float(percent)) < 0) {
+ dm_pool_free(mem, repstr);
+ log_error("Percentage too large.");
+ return 0;
+ }
+
+ *sortval = (uint64_t)(percent * 1000.f);
+
+ return _field_set_value(field, repstr, sortval);
+}
+
/*
* Data-munging functions to prepare each data type for display and sorting
*/
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=322e7b3060e79e62…
Commit: 322e7b3060e79e62708f7936f140386d64704878
Parent: 77a1efeb8eb0fe73c858ade05b578c3cfe3ddd9f
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Wed Nov 13 14:11:11 2013 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Wed Nov 13 14:11:11 2013 +0000
post-release
---
VERSION | 2 +-
VERSION_DM | 2 +-
WHATS_NEW | 3 +++
WHATS_NEW_DM | 3 +++
4 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/VERSION b/VERSION
index 576af30..8594917 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.02.104(2)-git (2013-11-13)
+2.02.105(2)-git (2013-11-13)
diff --git a/VERSION_DM b/VERSION_DM
index 89b02c3..d36b815 100644
--- a/VERSION_DM
+++ b/VERSION_DM
@@ -1 +1 @@
-1.02.83-git (2013-11-13)
+1.02.84-git (2013-11-13)
diff --git a/WHATS_NEW b/WHATS_NEW
index 475794e..b6f51e1 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,3 +1,6 @@
+Version 2.02.105 -
+=====================================
+
Version 2.02.104 - 13th November 2013
=====================================
Workaround VG refresh race during autoactivation by retrying the refresh.
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 1e8bae7..e3953e4 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,3 +1,6 @@
+Version 1.02.84 -
+====================================
+
Version 1.02.83 - 13th November 2013
====================================
Consistently report on stderr when device is not found for dmsetup info.
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=77a1efeb8eb0fe73…
Commit: 77a1efeb8eb0fe73c858ade05b578c3cfe3ddd9f
Parent: 527db4645fdbf10361797c871b9cadf6c5e73405
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Wed Nov 13 14:02:34 2013 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Wed Nov 13 14:02:34 2013 +0000
release 2.02.104
87 files changed, 1207 insertions(+), 294 deletions(-)
---
VERSION | 2 +-
VERSION_DM | 2 +-
WHATS_NEW | 7 +++----
WHATS_NEW_DM | 6 ++++--
4 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/VERSION b/VERSION
index 8e798d0..576af30 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.02.104(2)-git (2013-10-04)
+2.02.104(2)-git (2013-11-13)
diff --git a/VERSION_DM b/VERSION_DM
index 0e6eddb..89b02c3 100644
--- a/VERSION_DM
+++ b/VERSION_DM
@@ -1 +1 @@
-1.02.83-git (2013-10-04)
+1.02.83-git (2013-11-13)
diff --git a/WHATS_NEW b/WHATS_NEW
index ff6041d..475794e 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,5 @@
-Version 2.02.104 -
-===================================
+Version 2.02.104 - 13th November 2013
+=====================================
Workaround VG refresh race during autoactivation by retrying the refresh.
Handle failures in temporary mirror used when adding images to mirrors.
Fix and improve logic for implicitely exclusive activations.
@@ -28,7 +28,6 @@ Version 2.02.104 -
Move code to remove virtual snapshot from tools to lib for lvm2app.
Fix possible race during daemon worker thread creation (lvmetad).
Fix possible deadlock while clearing lvmetad cache for full rescan.
- Fix possible race while creating/destroying memory pools.
Recognise NVM Express devices in filter.
Fix failing metadata repair when lvmetad is used.
Fix incorrect memory handling when reading messages from lvmetad.
@@ -37,7 +36,7 @@ Version 2.02.104 -
Add support for flagging an LV to skip udev scanning during activation.
Improve message when unable to change discards setting on active thin pool.
Run full scan before vgrename operation to avoid any cache name collision.
- Fix lvconvert when converting to a thin pool and thin LV at once.
+ Fix lvconvert when converting to a thin pool and thin LV at once. (2.02.99)
Version 2.02.103 - 4th October 2013
===================================
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 0f905fd..1e8bae7 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,9 +1,11 @@
-Version 1.02.83
-==================================
+Version 1.02.83 - 13th November 2013
+====================================
Consistently report on stderr when device is not found for dmsetup info.
Skip race errors when non-udev dmsetup build runs on udev-enabled system.
Skip error message when holders are not present in sysfs.
Use __linux__ instead of linux define to make libdevmapper.h C compliant.
+ Use mutex to avoid possible race while creating/destroying memory pools.
+ Require libpthread to build now.
Version 1.02.82 - 4th October 2013
==================================
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=527db4645fdbf103…
Commit: 527db4645fdbf10361797c871b9cadf6c5e73405
Parent: d8085edf65006a50608edb821b3d30947abaa838
Author: Alasdair G Kergon <agk(a)redhat.com>
AuthorDate: Wed Nov 13 13:56:29 2013 +0000
Committer: Alasdair G Kergon <agk(a)redhat.com>
CommitterDate: Wed Nov 13 13:56:29 2013 +0000
gcc: replace #ifdef linux with __linux__
---
WHATS_NEW | 1 +
daemons/dmeventd/dmeventd.c | 10 +++++-----
daemons/dmeventd/plugins/thin/dmeventd_thin.c | 2 +-
lib/activate/activate.c | 4 ++--
lib/commands/toolcontext.c | 2 +-
lib/device/dev-io.c | 2 +-
lib/device/dev-md.c | 2 +-
lib/device/dev-swap.c | 2 +-
lib/device/dev-type.c | 2 +-
lib/device/dev-type.h | 2 +-
lib/filters/filter-md.c | 2 +-
lib/filters/filter-mpath.c | 2 +-
lib/filters/filter-sysfs.c | 2 +-
lib/mm/xlate.h | 2 +-
libdaemon/server/daemon-server.c | 8 ++++----
libdm/ioctl/libdm-iface.c | 2 +-
libdm/libdm-common.c | 4 ++--
libdm/misc/dm-ioctl.h | 2 +-
tools/dmsetup.c | 2 +-
19 files changed, 28 insertions(+), 27 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index af1a26a..ff6041d 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -18,6 +18,7 @@ Version 2.02.104 -
Remove 2>/dev/null from three lvm commands executed by vgimportclone.
Add configure --enable-udev-systemd-background-jobs.
Add lvm2-pvscan@.service to run pvscan as a service for lvmetad/autoactivation.
+ Use #ifdef __linux__ instead of linux throughout.
Fix lvconvert swap of poolmetadata volume for active thin pool.
Check for open count with a timeout before removal/deactivation of an LV.
Report RAID images split with tracking as out-of-sync ("I").
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 3754714..bdaf552 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -39,7 +39,7 @@
#include <arpa/inet.h> /* for htonl, ntohl */
#include <fcntl.h> /* for musl libc */
-#ifdef linux
+#ifdef __linux__
/*
* Kernel version 2.6.36 and higher has
* new OOM killer adjustment interface.
@@ -1619,7 +1619,7 @@ static void _exit_handler(int sig __attribute__((unused)))
_exit_now = 1;
}
-#ifdef linux
+#ifdef __linux__
static int _set_oom_adj(const char *oom_adj_path, int val)
{
FILE *fp;
@@ -1810,7 +1810,7 @@ static void _daemonize(void)
fd = rlim.rlim_cur;
for (--fd; fd >= 0; fd--) {
-#ifdef linux
+#ifdef __linux__
/* Do not close fds preloaded by systemd! */
if (_systemd_activation &&
(fd == SD_FD_FIFO_SERVER || fd == SD_FD_FIFO_CLIENT))
@@ -1963,7 +1963,7 @@ int main(int argc, char *argv[])
if (_restart)
restart();
-#ifdef linux
+#ifdef __linux__
_systemd_activation = _systemd_handover(&fifos);
#endif
@@ -1985,7 +1985,7 @@ int main(int argc, char *argv[])
signal(SIGHUP, &_exit_handler);
signal(SIGQUIT, &_exit_handler);
-#ifdef linux
+#ifdef __linux__
/* Systemd has adjusted oom killer for us already */
if (!_systemd_activation && !_protect_against_oom_killer())
syslog(LOG_ERR, "Failed to protect against OOM killer");
diff --git a/daemons/dmeventd/plugins/thin/dmeventd_thin.c b/daemons/dmeventd/plugins/thin/dmeventd_thin.c
index 8b173f1..3126bfa 100644
--- a/daemons/dmeventd/plugins/thin/dmeventd_thin.c
+++ b/daemons/dmeventd/plugins/thin/dmeventd_thin.c
@@ -44,7 +44,7 @@ struct dso_state {
/* TODO - move this mountinfo code into library to be reusable */
-#ifdef linux
+#ifdef __linux__
# include "kdev_t.h"
#else
# define MAJOR(x) major((x))
diff --git a/lib/activate/activate.c b/lib/activate/activate.c
index 7e6a5ac..0597409 100644
--- a/lib/activate/activate.c
+++ b/lib/activate/activate.c
@@ -910,8 +910,8 @@ int lv_raid_message(const struct logical_volume *lv, const char *msg)
if (lv_is_thin_pool(lv) &&
(lv_is_raid(seg_lv(first_seg(lv), 0)) ||
lv_is_raid(first_seg(lv)->metadata_lv))) {
- log_error("Thinpool data or metadata volume"
- " must be specified. (e.g. \"%s/%s_tdata\")",
+ log_error("Thin pool data or metadata volume "
+ "must be specified. (E.g. \"%s/%s_tdata\")",
lv->vg->name, lv->name);
return 0;
}
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
index 3ed359d..d13d8d5 100644
--- a/lib/commands/toolcontext.c
+++ b/lib/commands/toolcontext.c
@@ -49,7 +49,7 @@
#include <syslog.h>
#include <time.h>
-#ifdef linux
+#ifdef __linux__
# include <malloc.h>
#endif
diff --git a/lib/device/dev-io.c b/lib/device/dev-io.c
index 34e3064..6c8613c 100644
--- a/lib/device/dev-io.c
+++ b/lib/device/dev-io.c
@@ -27,7 +27,7 @@
#include <unistd.h>
#include <sys/ioctl.h>
-#ifdef linux
+#ifdef __linux__
# define u64 uint64_t /* Missing without __KERNEL__ */
# undef WNOHANG /* Avoid redefinition */
# undef WUNTRACED /* Avoid redefinition */
diff --git a/lib/device/dev-md.c b/lib/device/dev-md.c
index a8bbe81..9af8074 100644
--- a/lib/device/dev-md.c
+++ b/lib/device/dev-md.c
@@ -18,7 +18,7 @@
#include "metadata.h"
#include "xlate.h"
-#ifdef linux
+#ifdef __linux__
/* Lifted from <linux/raid/md_p.h> because of difficulty including it */
diff --git a/lib/device/dev-swap.c b/lib/device/dev-swap.c
index 6faa810..cc44008 100644
--- a/lib/device/dev-swap.c
+++ b/lib/device/dev-swap.c
@@ -15,7 +15,7 @@
#include "lib.h"
#include "dev-type.h"
-#ifdef linux
+#ifdef __linux__
#define MAX_PAGESIZE (64 * 1024)
#define SIGNATURE_SIZE 10
diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c
index 11f0407..a98cf45 100644
--- a/lib/device/dev-type.c
+++ b/lib/device/dev-type.c
@@ -443,7 +443,7 @@ out:
return ret;
}
-#ifdef linux
+#ifdef __linux__
static unsigned long _dev_topology_attribute(struct dev_types *dt,
const char *attribute,
diff --git a/lib/device/dev-type.h b/lib/device/dev-type.h
index 1227ab0..2fa32db 100644
--- a/lib/device/dev-type.h
+++ b/lib/device/dev-type.h
@@ -19,7 +19,7 @@
#define NUMBER_OF_MAJORS 4096
-#ifdef linux
+#ifdef __linux__
# define MAJOR(dev) ((dev & 0xfff00) >> 8)
# define MINOR(dev) ((dev & 0xff) | ((dev >> 12) & 0xfff00))
# define MKDEV(ma,mi) ((mi & 0xff) | (ma << 8) | ((mi & ~0xff) << 12))
diff --git a/lib/filters/filter-md.c b/lib/filters/filter-md.c
index 0089f93..fe79f3d 100644
--- a/lib/filters/filter-md.c
+++ b/lib/filters/filter-md.c
@@ -16,7 +16,7 @@
#include "lib.h"
#include "filter.h"
-#ifdef linux
+#ifdef __linux__
static int _ignore_md(struct dev_filter *f __attribute__((unused)),
struct device *dev)
diff --git a/lib/filters/filter-mpath.c b/lib/filters/filter-mpath.c
index a9881fd..10106f0 100644
--- a/lib/filters/filter-mpath.c
+++ b/lib/filters/filter-mpath.c
@@ -16,7 +16,7 @@
#include "filter.h"
#include "activate.h"
-#ifdef linux
+#ifdef __linux__
#include <dirent.h>
diff --git a/lib/filters/filter-sysfs.c b/lib/filters/filter-sysfs.c
index e03beca..af3ed07 100644
--- a/lib/filters/filter-sysfs.c
+++ b/lib/filters/filter-sysfs.c
@@ -15,7 +15,7 @@
#include "lib.h"
#include "filter.h"
-#ifdef linux
+#ifdef __linux__
#include <dirent.h>
diff --git a/lib/mm/xlate.h b/lib/mm/xlate.h
index 57d7241..0d243c4 100644
--- a/lib/mm/xlate.h
+++ b/lib/mm/xlate.h
@@ -16,7 +16,7 @@
#ifndef _LVM_XLATE_H
#define _LVM_XLATE_H
-#ifdef linux
+#ifdef __linux__
# include <endian.h>
# include <byteswap.h>
#else
diff --git a/libdaemon/server/daemon-server.c b/libdaemon/server/daemon-server.c
index b114b9f..156925a 100644
--- a/libdaemon/server/daemon-server.c
+++ b/libdaemon/server/daemon-server.c
@@ -54,7 +54,7 @@ static void _exit_handler(int sig __attribute__((unused)))
#define EXIT_ALREADYRUNNING 13
-#ifdef linux
+#ifdef __linux__
#include <stddef.h>
@@ -318,7 +318,7 @@ static void _daemonise(daemon_state s)
fd = rlim.rlim_cur;
for (--fd; fd >= 0; fd--) {
-#ifdef linux
+#ifdef __linux__
/* Do not close fds preloaded by systemd! */
if (_systemd_activation && fd == SD_FD_SOCKET_SERVER)
continue;
@@ -469,7 +469,7 @@ void daemon_start(daemon_state s)
if (setenv("LC_ALL", "C", 1))
perror("Cannot set LC_ALL to C");
-#ifdef linux
+#ifdef __linux__
_systemd_activation = _systemd_handover(&s);
#endif
@@ -504,7 +504,7 @@ void daemon_start(daemon_state s)
signal(SIGALRM, &_exit_handler);
signal(SIGPIPE, SIG_IGN);
-#ifdef linux
+#ifdef __linux__
/* Systemd has adjusted oom killer for us already */
if (s.avoid_oom && !_systemd_activation && !_protect_against_oom_killer())
ERROR(&s, "Failed to protect against OOM killer");
diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c
index c530bb7..7b1fead 100644
--- a/libdm/ioctl/libdm-iface.c
+++ b/libdm/ioctl/libdm-iface.c
@@ -23,7 +23,7 @@
#include <sys/utsname.h>
#include <limits.h>
-#ifdef linux
+#ifdef __linux__
# include "kdev_t.h"
# include <linux/limits.h>
#else
diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c
index 9a52f2e..febcd0e 100644
--- a/libdm/libdm-common.c
+++ b/libdm/libdm-common.c
@@ -32,7 +32,7 @@
# include <libudev.h>
#endif
-#ifdef linux
+#ifdef __linux__
# include <linux/fs.h>
#endif
@@ -1069,7 +1069,7 @@ static int _rename_dev_node(const char *old_name, const char *new_name,
return 1;
}
-#ifdef linux
+#ifdef __linux__
static int _open_dev_node(const char *dev_name)
{
int fd = -1;
diff --git a/libdm/misc/dm-ioctl.h b/libdm/misc/dm-ioctl.h
index dae2bcb..76316b0 100644
--- a/libdm/misc/dm-ioctl.h
+++ b/libdm/misc/dm-ioctl.h
@@ -8,7 +8,7 @@
#ifndef _LINUX_DM_IOCTL_V4_H
#define _LINUX_DM_IOCTL_V4_H
-#ifdef linux
+#ifdef __linux__
# include <linux/types.h>
#endif
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index e25d109..4433571 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -84,7 +84,7 @@ extern char *optarg;
__result; }))
#endif
-#ifdef linux
+#ifdef __linux__
# include "kdev_t.h"
#else
# define MAJOR(x) major((x))
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d8085edf65006a50…
Commit: d8085edf65006a50608edb821b3d30947abaa838
Parent: 7de533ad12972f5a9c5bf2d2b477d8320f7e4a8e
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue Nov 12 10:55:34 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue Nov 12 11:09:45 2013 +0100
pvscan: retry VG refresh before autoactivation if it fails
There's a tiny race when suspending the device which is part
of the refresh because when suspend ioctl is performed, the
dm kernel driver executes (do_suspend and dm_suspend kernel fn):
step 1: a check whether the dev is already suspended and
if yes it returns success immediately as there's
nothing to do
step 2: it grabs the suspend lock
step 3: another check whether the dev is already suspended
and if found suspended, it exits with -EINVAL now
The race can occur in between step 1 and step 2. To prevent
premature autoactivation failure, we're using a simple retry
logic here before we fail completely. For a complete solution,
we need to fix the locking so there's no possibility for suspend
calls to interleave each other to cause this kind of race.
This is just a workaround. Remove it and replace it with proper
locking once we have that in!
---
WHATS_NEW | 1 +
tools/pvscan.c | 34 +++++++++++++++++++++++++++++++++-
2 files changed, 34 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 5eb4abe..af1a26a 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.104 -
===================================
+ Workaround VG refresh race during autoactivation by retrying the refresh.
Handle failures in temporary mirror used when adding images to mirrors.
Fix and improve logic for implicitely exclusive activations.
Return success when LV cannot be activated because of volume_list filter.
diff --git a/tools/pvscan.c b/tools/pvscan.c
index b6a07bd..ce8c446 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -91,10 +91,15 @@ static void _pvscan_display_single(struct cmd_context *cmd,
display_size(cmd, (uint64_t) (pv_pe_count(pv) - pv_pe_alloc_count(pv)) * pv_pe_size(pv)));
}
+#define REFRESH_BEFORE_AUTOACTIVATION_RETRIES 5
+#define REFRESH_BEFORE_AUTOACTIVATION_RETRY_USLEEP_DELAY 100000
+
static int _auto_activation_handler(struct cmd_context *cmd,
const char *vgid, int partial,
activation_change_t activate)
{
+ unsigned int refresh_retries = REFRESH_BEFORE_AUTOACTIVATION_RETRIES;
+ int refresh_done = 0;
struct volume_group *vg;
int consistent = 0;
struct id vgid_raw;
@@ -115,7 +120,34 @@ static int _auto_activation_handler(struct cmd_context *cmd,
r = 1; goto out;
}
- if (!vg_refresh_visible(vg->cmd, vg)) {
+ /* FIXME: There's a tiny race when suspending the device which is part
+ * of the refresh because when suspend ioctl is performed, the dm
+ * kernel driver executes (do_suspend and dm_suspend kernel fn):
+ *
+ * step 1: a check whether the dev is already suspended and
+ * if yes it returns success immediately as there's
+ * nothing to do
+ * step 2: it grabs the suspend lock
+ * step 3: another check whether the dev is already suspended
+ * and if found suspended, it exits with -EINVAL now
+ *
+ * The race can occur in between step 1 and step 2. To prevent premature
+ * autoactivation failure, we're using a simple retry logic here before
+ * we fail completely. For a complete solution, we need to fix the
+ * locking so there's no possibility for suspend calls to interleave
+ * each other to cause this kind of race.
+ *
+ * Remove this workaround with "refresh_retries" once we have proper locking in!
+ */
+ while (refresh_retries--) {
+ if (vg_refresh_visible(vg->cmd, vg)) {
+ refresh_done = 1;
+ break;
+ }
+ usleep(REFRESH_BEFORE_AUTOACTIVATION_RETRY_USLEEP_DELAY);
+ }
+
+ if (!refresh_done) {
log_error("%s: refresh before autoactivation failed.", vg->name);
goto out;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7de533ad12972f5a…
Commit: 7de533ad12972f5a9c5bf2d2b477d8320f7e4a8e
Parent: b6b5299d1e1f6bdddb9bda30c4f37aaccbe3df44
Author: Jonathan Brassow <jbrassow(a)redhat.com>
AuthorDate: Fri Nov 8 09:52:00 2013 -0600
Committer: Jonathan Brassow <jbrassow(a)redhat.com>
CommitterDate: Fri Nov 8 09:52:00 2013 -0600
mirror: Handle failures in tmp mirror used when up-converting.
Failures in the temporary mirror used when up-converting cause dmeventd
to issue 'lvconvert --repair' on the sub-LV, <lv_name>_mimagetmp_?. The
'lvconvert' command refuses to deal with this sub-LV outright - it
expects to be given the name of the top-level LV. So, just like we do
with mirrored logs, we strip-off the portion of the name that is not
the top-level LV and issue the command on the top-level LV instead.
---
WHATS_NEW | 1 +
daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index f0a764b..5eb4abe 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.104 -
===================================
+ Handle failures in temporary mirror used when adding images to mirrors.
Fix and improve logic for implicitely exclusive activations.
Return success when LV cannot be activated because of volume_list filter.
Return proper error state for remote exclusive activation.
diff --git a/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c b/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
index 5d5a46b..6d2c3de 100644
--- a/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
+++ b/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
@@ -159,8 +159,8 @@ int dmeventd_lvm2_command(struct dm_pool *mem, char *buffer, size_t size,
}
/* strip off the mirror component designations */
- layer = strstr(lv, "_mlog");
- if (layer)
+ if ((layer = strstr(lv, "_mimagetmp")) ||
+ (layer = strstr(lv, "_mlog")))
*layer = '\0';
r = dm_snprintf(buffer, size, "%s %s/%s", cmd, vg, lv);
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=b6b5299d1e1f6bdd…
Commit: b6b5299d1e1f6bdddb9bda30c4f37aaccbe3df44
Parent: fc144a3fc5389db11c3c34c9c240a763cc850cc7
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Nov 6 14:55:18 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 6 14:55:18 2013 +0100
corosync: fix some gcc warnings
warning: function declaration isn't a prototype [-Wstrict-prototypes]
warning: old-style function definition [-Wold-style-definition]
---
daemons/clvmd/clvmd-corosync.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/daemons/clvmd/clvmd-corosync.c b/daemons/clvmd/clvmd-corosync.c
index 9092c8a..e68cb73 100644
--- a/daemons/clvmd/clvmd-corosync.c
+++ b/daemons/clvmd/clvmd-corosync.c
@@ -388,7 +388,7 @@ static int _name_from_csid(const char *csid, char *name)
return 0;
}
-static int _get_num_nodes()
+static int _get_num_nodes(void)
{
DEBUGLOG("num_nodes = %d\n", num_nodes);
return num_nodes;
@@ -505,7 +505,7 @@ static int _unlock_resource(const char *resource, int lockid)
return 0;
}
-static int _is_quorate()
+static int _is_quorate(void)
{
int quorate;
if (quorum_getquorate(quorum_handle, &quorate) == CS_OK)
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fc144a3fc5389db1…
Commit: fc144a3fc5389db11c3c34c9c240a763cc850cc7
Parent: 14b852609b20e57c3b2dede0641d31155232b946
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Wed Nov 6 13:29:25 2013 +0100
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Wed Nov 6 13:29:25 2013 +0100
profile: add thin_pool_chunk_size_policy to default.profile
By default, thin_pool_chunk_size_policy is set to "generic".
---
conf/default.profile.in | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/conf/default.profile.in b/conf/default.profile.in
index 6a0b8f1..29049ef 100644
--- a/conf/default.profile.in
+++ b/conf/default.profile.in
@@ -9,6 +9,7 @@
# Refer to 'man lvm.conf' for further information about profiles and file layout.
allocation {
+ thin_pool_chunk_size_policy = "generic"
thin_pool_chunk_size = 64
thin_pool_discards = "passdown"
thin_pool_zero = 1
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=14b852609b20e57c…
Commit: 14b852609b20e57c3b2dede0641d31155232b946
Parent: 52f41baedba31335cd16d7767df26378f43c4626
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 1 12:55:41 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 1 13:05:05 2013 +0100
tests: testing thin lvchange
Test various thin change operation,
including activation logic - which is somewhat
limited with singlenode emulation.
More tests needs to be added.
---
test/shell/lvchange-thin.sh | 131 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 131 insertions(+), 0 deletions(-)
diff --git a/test/shell/lvchange-thin.sh b/test/shell/lvchange-thin.sh
new file mode 100644
index 0000000..0b4c15d
--- /dev/null
+++ b/test/shell/lvchange-thin.sh
@@ -0,0 +1,131 @@
+#!/bin/sh
+# Copyright (C) 2013 Red Hat, Inc. All rights reserved.
+#
+# 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 have_thin 1 0 0 || skip
+
+aux prepare_pvs 3
+
+vgcreate -s 128k $vg "$dev1" "$dev2"
+vgcreate -s 128k $vg2 "$dev3"
+
+lvcreate -V10M -L10M -T $vg/pool -n $lv1
+lvcreate -L10M -n $lv2 $vg
+
+lvchange -an $vg/$lv1
+
+# Test activation
+lvchange -aly $vg/$lv1
+check active $vg $lv1
+
+lvchange -aln $vg/$lv1
+check inactive $vg $lv1
+
+# Test for allowable changes
+#
+# contiguous_ARG
+lvchange -C y $vg/$lv1
+lvchange -C n $vg/$lv1
+
+# permission_ARG
+lvchange -p r $vg/$lv1
+lvchange -p rw $vg/$lv1
+
+# FIXME
+#should lvchange -p r $vg/pool
+#should lvchange -p rw $vg/pool
+
+# readahead_ARG
+lvchange -r none $vg/$lv1
+lvchange -r auto $vg/$lv1
+# FIXME
+# Think about more support
+
+# minor_ARG
+lvchange --yes -M y --minor 234 --major 253 $vg/$lv1
+lvchange -M n $vg/$lv1
+
+lvchange --yes -M y --minor 235 --major 253 $vg/pool
+lvchange -M n $vg/pool
+
+# addtag_ARG
+lvchange --addtag foo $vg/$lv1
+lvchange --addtag foo $vg/pool
+
+# deltag_ARG
+lvchange --deltag foo $vg/$lv1
+lvchange --deltag foo $vg/pool
+
+# discards_ARG
+lvchange --discards nopassdown $vg/pool
+lvchange --discards passdown $vg/pool
+
+# zero_ARG
+lvchange --zero n $vg/pool
+lvchange --zero y $vg/pool
+
+#
+# Test for disallowed metadata changes
+#
+# resync_ARG
+not lvchange --resync $vg/$lv1
+
+# alloc_ARG
+#not lvchange --alloc anywhere $vg/$lv1
+
+# discards_ARG
+not lvchange --discards ignore $vg/$lv1
+
+# zero_ARG
+not lvchange --zero y $vg/$lv1
+
+
+#
+# Ensure that allowed args don't cause disallowed args to get through
+#
+not lvchange --resync -ay $vg/$lv1
+not lvchange --resync --addtag foo $vg/$lv1
+
+#
+# Play with tags and activation
+#
+TAG=$(hostname)
+aux lvmconf 'activation/volume_list = [ "$vg/$lv2", "@mytag", "$vg2" ]'
+
+lvchange -ay $vg/$lv1
+check inactive $vg $lv1
+
+lvchange --addtag mytag $vg/$lv1
+
+lvchange -ay @mytag_fake
+check inactive $vg $lv1
+
+lvchange -ay $vg/$lv1
+# Volume has matching tag
+check active $vg $lv1
+lvchange -an $vg/$lv1
+
+lvchange -ay @mytag
+check active $vg $lv1
+
+# Fails here since it cannot clear device header
+not lvcreate -Zy -L10 -n $lv3 $vg2
+# OK when zeroing is disabled
+lvcreate -Zn -L10 -n $lv3 $vg2
+check inactive $vg2 $lv3
+
+aux lvmconf 'activation/volume_list = [ "$vg2" ]'
+vgchange -an $vg
+vgchange -ay $vg $vg2
+lvs -a -o+lv_active $vg $vg2
+
+vgremove -ff $vg $vg2
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=52f41baedba31335…
Commit: 52f41baedba31335cd16d7767df26378f43c4626
Parent: 9f6209b878fb5b33dae5bc52a7ea47a9de9ff900
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 1 12:40:27 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 1 13:05:03 2013 +0100
dmsetup: report error on stderr
Send error message on stdout, since after _display_info_long()
command return errors.
Patch makes consistent behavior for command:
dmsetup info -c non-existing-dev
&
dmsetup info non-existing-dev
Now both commands report error on stderr when they return error status
for non-existing device.
---
WHATS_NEW_DM | 1 +
tools/dmsetup.c | 2 +-
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 6742ad4..0f905fd 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.83
==================================
+ Consistently report on stderr when device is not found for dmsetup info.
Skip race errors when non-udev dmsetup build runs on udev-enabled system.
Skip error message when holders are not present in sysfs.
Use __linux__ instead of linux define to make libdevmapper.h C compliant.
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index a0ee23e..e25d109 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -461,7 +461,7 @@ static void _display_info_long(struct dm_task *dmt, struct dm_info *info)
uint32_t read_ahead;
if (!info->exists) {
- printf("Device does not exist.\n");
+ fprintf(stderr, "Device does not exist.\n");
return;
}
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9f6209b878fb5b33…
Commit: 9f6209b878fb5b33dae5bc52a7ea47a9de9ff900
Parent: c3e674ad3010d21dc2cbde27b7634f7ea4fe67e3
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Nov 1 10:31:31 2013 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri Nov 1 13:03:50 2013 +0100
activation: improve activation
This patch fixes mostly cluster behavior but also updates
non-cluster reaction where calls like 'lvchange -aln'
lead to incorrect errors for some segment types.
Fix the implicit activation rules where some segment types could
be activated only in exclusive mode in cluster.
lvm2 command was not preserver 'local' property and incorrectly
converted local activations in to plain exclusive, so the local
activation could have activate volumes exclusively, but remotely.
---
WHATS_NEW | 1 +
lib/metadata/lv.c | 63 ++++++++++++++++++++++++++++++++---------------
lib/metadata/lv_manip.c | 10 +++----
3 files changed, 48 insertions(+), 26 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index ff8da1d..f0a764b 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.104 -
===================================
+ Fix and improve logic for implicitely exclusive activations.
Return success when LV cannot be activated because of volume_list filter.
Return proper error state for remote exclusive activation.
Fix missing lvmetad scan for PVs found on MD partitions.
diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c
index e59bd8e..c1f6271 100644
--- a/lib/metadata/lv.c
+++ b/lib/metadata/lv.c
@@ -735,39 +735,62 @@ char *lv_host_dup(struct dm_pool *mem, const struct logical_volume *lv)
return dm_pool_strdup(mem, lv->hostname ? : "");
}
+static int _lv_is_exclusive(struct logical_volume *lv)
+{
+ /* Some devices require exlusivness */
+ return seg_is_raid(first_seg(lv)) ||
+ lv_is_origin(lv) ||
+ lv_is_thin_type(lv);
+}
+
int lv_active_change(struct cmd_context *cmd, struct logical_volume *lv,
enum activation_change activate)
{
- if (activate == CHANGE_AN) {
+ switch (activate) {
+ case CHANGE_AN:
+deactivate:
log_verbose("Deactivating logical volume \"%s\"", lv->name);
if (!deactivate_lv(cmd, lv))
return_0;
- } else if ((activate == CHANGE_AE) ||
- seg_is_raid(first_seg(lv)) ||
- lv_is_origin(lv) ||
- lv_is_thin_type(lv)) {
- if (activate == CHANGE_ALN) {
- /* origin, thin or RAID - all others have _AE */
- /* other types of activation are implicitly exclusive */
- /* Note: the order of tests is mandatory */
- log_error("Cannot deactivate \"%s\" locally.", lv->name);
- return 0;
+ break;
+ case CHANGE_ALN:
+ if (_lv_is_exclusive(lv)) {
+ if (!lv_is_active_locally(lv)) {
+ log_error("Cannot deactivate remotely exclusive device locally.");
+ return 0;
+ }
+ /* Unlock whole exclusive activation */
+ goto deactivate;
}
- log_verbose("Activating logical volume \"%s\" exclusively.",
- lv->name);
- if (!activate_lv_excl(cmd, lv))
- return_0;
- } else if (activate == CHANGE_ALN) {
log_verbose("Deactivating logical volume \"%s\" locally.",
lv->name);
if (!deactivate_lv_local(cmd, lv))
return_0;
- } else if ((activate == CHANGE_ALY) || (activate == CHANGE_AAY)) {
- log_verbose("Activating logical volume \"%s\" locally.",
+ break;
+ case CHANGE_ALY:
+ case CHANGE_AAY:
+ if (_lv_is_exclusive(lv)) {
+ log_verbose("Activating logical volume \"%s\" exclusively locally.",
+ lv->name);
+ if (!activate_lv_excl_local(cmd, lv))
+ return_0;
+ } else {
+ log_verbose("Activating logical volume \"%s\" locally.",
+ lv->name);
+ if (!activate_lv_local(cmd, lv))
+ return_0;
+ }
+ break;
+ case CHANGE_AE:
+exclusive:
+ log_verbose("Activating logical volume \"%s\" exclusively.",
lv->name);
- if (!activate_lv_local(cmd, lv))
+ if (!activate_lv_excl(cmd, lv))
return_0;
- } else { /* CHANGE_AY */
+ break;
+ default: /* CHANGE_AY */
+ if (_lv_is_exclusive(lv))
+ goto exclusive;
log_verbos