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=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=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
}