master - tests: aux.sh check for already present config
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=d426d7e7099b23d169e...
Commit: d426d7e7099b23d169e396292a25ab97cbfc2000
Parent: 32c0dc35493c36b1f4d79264af1ad09a6150b198
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Jul 7 23:03:08 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 10 14:23:53 2017 +0200
tests: aux.sh check for already present config
'aux lvmconf' detects if new config needs to be regenerated.
---
test/lib/aux.sh | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index 3f54dbb..13be7c5 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -1226,6 +1226,18 @@ EOF
lvmconf() {
unset profile_name
+ test $# -eq 0 || {
+ # Compare if passed args aren't already all in generated lvm.conf
+ local needed=0
+ for i in "$@"; do
+ val=$(grep "${i%%[={ ]*}" CONFIG_VALUES 2>/dev/null | tail -1) || { needed=1; break; }
+ test "$val" = "$i" || { needed=1; break; }
+ done
+ test "$needed" -eq 0 && {
+ echo "## LVMCONF: values are already there, skipping."
+ return 0 # not needed
+ }
+ }
generate_config "$@"
mv -f CONFIG "$LVM_SYSTEM_DIR/lvm.conf"
}
6 years, 9 months
master - tests: aux.sh double quote
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=32c0dc35493c36b1f4d...
Commit: 32c0dc35493c36b1f4d79264af1ad09a6150b198
Parent: 84e83ac37e652baa686648f1bfb4215e2c0dd206
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Jul 6 23:58:28 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 10 14:23:53 2017 +0200
tests: aux.sh double quote
---
test/lib/aux.sh | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index e31c4d7..3f54dbb 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -351,7 +351,7 @@ prepare_lvmdbusd() {
echo "Failed to start lvmdbusd daemon"
return 1
fi
- echo $pid > LOCAL_LVMDBUSD
+ echo "$pid" > LOCAL_LVMDBUSD
echo ok
}
@@ -384,7 +384,7 @@ teardown_devs_prefixed() {
local IFS=$IFS_NL
local dm
- rm -rf "$TESTDIR/dev/$prefix"*
+ rm -rf "$TESTDIR/dev/$prefix*"
# Resume suspended devices first
for dm in $(dm_info suspended,name | grep "^Suspended:.*$prefix"); do
@@ -642,7 +642,7 @@ prepare_loop() {
done
fi
test -n "$LOOP" # confirm or fail
- BACKING_DEV="$LOOP"
+ BACKING_DEV=$LOOP
echo "$LOOP" > LOOP
echo "$LOOP" > BACKING_DEV
echo "ok ($LOOP)"
@@ -1040,7 +1040,7 @@ backup_dev() {
local dev
for dev in "$@"; do
- dd if="$dev" of="$dev.backup" bs=1024
+ dd if="$dev" of="${dev}.backup" bs=1024
done
}
@@ -1048,9 +1048,9 @@ restore_dev() {
local dev
for dev in "$@"; do
- test -e "$dev.backup" || \
+ test -e "${dev}.backup" || \
die "Internal error: $dev not backed up, can't restore!"
- dd of="$dev" if="$dev.backup" bs=1024
+ dd of="$dev" if="${dev}.backup" bs=1024
done
}
@@ -1232,7 +1232,7 @@ lvmconf() {
profileconf() {
local pdir="$LVM_SYSTEM_DIR/profile"
- profile_name="$1"
+ local profile_name=$1
shift
generate_config "$@"
mkdir -p "$pdir"
@@ -1598,7 +1598,7 @@ test -z "$LVM_TEST_AUX_TRACE" || set -x
test -f DEVICES && devs=$(< DEVICES)
-if test "$1" = dmsetup; then
+if test "$1" = "dmsetup" ; then
shift
dmsetup_wrapped "$@"
else
6 years, 9 months
master - tests: aux.sh replace sed call
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=84e83ac37e652baa686...
Commit: 84e83ac37e652baa686648f1bfb4215e2c0dd206
Parent: 928a49a7c8f78dff4add340107ecc46e6a1b8587
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Jul 6 19:11:46 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 10 14:23:53 2017 +0200
tests: aux.sh replace sed call
Use internal shell vars manips
---
test/lib/aux.sh | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index 6ac57d4..e31c4d7 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -960,8 +960,7 @@ disable_dev() {
done
test -n "$silent" || for num in $notify; do
- notify_lvmetad --major "$(echo "$num" | sed -e "s,:.*,,")" \
- --minor "$(echo "$num" | sed -e "s,.*:,,")"
+ notify_lvmetad --major "${num%%:*}" --minor "${num##*:}"
done
}
6 years, 9 months
master - tests: aux.sh use grep -E
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=928a49a7c8f78dff4ad...
Commit: 928a49a7c8f78dff4add340107ecc46e6a1b8587
Parent: 5bd09cb79dc66eac7515b93b8991eded8ac25afd
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Jul 1 09:41:14 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 10 14:23:53 2017 +0200
tests: aux.sh use grep -E
egrep is nonstandard.
---
test/lib/aux.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index 21c94ac..6ac57d4 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -545,7 +545,7 @@ teardown() {
kill_sleep_kill_ LOCAL_LVMETAD "${LVM_VALGRIND_LVMETAD:-0}"
- dm_table | not egrep -q "$vg|$vg1|$vg2|$vg3|$vg4" || {
+ dm_table | not grep -E -q "$vg|$vg1|$vg2|$vg3|$vg4" || {
# Avoid activation of dmeventd if there is no pid
cfg=$(test -s LOCAL_DMEVENTD || echo "--config activation{monitoring=0}")
if dm_info suspended,name | grep -q "^Suspended:.*$prefix" ; then
6 years, 9 months
master - tests: aux.sh drop useless echo
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=5bd09cb79dc66eac751...
Commit: 5bd09cb79dc66eac7515b93b8991eded8ac25afd
Parent: 6be61bf04408855da89f2117d268f1dbe1b98279
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Jul 1 09:28:06 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 10 14:23:53 2017 +0200
tests: aux.sh drop useless echo
Simply trim on space.
---
test/lib/aux.sh | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index c5944c2..21c94ac 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -548,7 +548,7 @@ teardown() {
dm_table | not egrep -q "$vg|$vg1|$vg2|$vg3|$vg4" || {
# Avoid activation of dmeventd if there is no pid
cfg=$(test -s LOCAL_DMEVENTD || echo "--config activation{monitoring=0}")
- if echo "$(dm_info suspended,name)" | grep -q "^Suspended:.*$prefix" ; then
+ if dm_info suspended,name | grep -q "^Suspended:.*$prefix" ; then
echo "Skipping vgremove, suspended devices detected."
else
vgremove -ff "$cfg" \
@@ -1207,8 +1207,7 @@ EOF
# read sequential list and put into associative array
while IFS=$IFS_NL read -r v; do
- # trim white-space-chars via echo when inserting
- CONF["$(echo ${v%%[={]*})"]=${v#*/}
+ CONF["${v%%[={ ]*}"]=${v#*/}
done < "$config_values"
# sort by section and iterate through them
6 years, 9 months
master - tests: aux.sh check cd result
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=6be61bf04408855da89...
Commit: 6be61bf04408855da89f2117d268f1dbe1b98279
Parent: c87e1afa0327c60621075f581bffb30b33735442
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Jul 1 09:27:19 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 10 14:23:53 2017 +0200
tests: aux.sh check cd result
Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
---
test/lib/aux.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index 2eeb67f..c5944c2 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -585,7 +585,7 @@ teardown() {
}
test -n "$TESTDIR" && {
- cd "$TESTOLDPWD"
+ cd "$TESTOLDPWD" || die "Failed to enter $TESTOLDPWD"
rm -rf "$TESTDIR" || echo BLA
}
6 years, 9 months
master - tests: export many shell vars with 1 command
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=c87e1afa0327c606210...
Commit: c87e1afa0327c60621075f581bffb30b33735442
Parent: c48149cf80c6582c2369bc7f8a33d794021d9dae
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Jul 10 13:33:55 2017 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Mon Jul 10 14:23:53 2017 +0200
tests: export many shell vars with 1 command
---
test/Makefile.in | 36 ++++++++++++++++++++----------------
test/lib/inittest.sh | 7 ++++---
2 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/test/Makefile.in b/test/Makefile.in
index c399596..eee9bf2 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -273,22 +273,26 @@ lib/flavour-%: $(srcdir)/lib/flavour-%.sh .lib-dir-stamp
cp $< $@
lib/paths-common: $(srcdir)/Makefile.in .lib-dir-stamp Makefile
- echo 'export DM_UDEV_SYNCHRONISATION=$(dm_udev_synchronisation)' >> $@-t
- echo 'export THIN=@THIN@' >> $@-t
- echo 'export RAID=@RAID@' >> $@-t
- echo 'export CACHE=@CACHE@' >> $@-t
- echo 'export LVMETAD_PIDFILE="@LVMETAD_PIDFILE@"' >> $@-t
- echo 'export LVMPOLLD_PIDFILE="@LVMPOLLD_PIDFILE@"' >> $@-t
- echo 'export DMEVENTD_PIDFILE="@DMEVENTD_PIDFILE@"' >> $@-t
- echo 'export CLVMD_PIDFILE="@CLVMD_PIDFILE@"' >> $@-t
- echo 'export LVM_TEST_THIN_CHECK_CMD=$${LVM_TEST_THIN_CHECK_CMD-@THIN_CHECK_CMD@}' >> $@-t
- echo 'export LVM_TEST_THIN_DUMP_CMD=$${LVM_TEST_THIN_DUMP_CMD-@THIN_DUMP_CMD@}' >> $@-t
- echo 'export LVM_TEST_THIN_REPAIR_CMD=$${LVM_TEST_THIN_REPAIR_CMD-@THIN_REPAIR_CMD@}' >> $@-t
- echo 'export LVM_TEST_THIN_RESTORE_CMD=$${LVM_TEST_THIN_RESTORE_CMD-@THIN_RESTORE_CMD@}' >> $@-t
- echo 'export LVM_TEST_CACHE_CHECK_CMD=$${LVM_TEST_CACHE_CHECK_CMD-@CACHE_CHECK_CMD@}' >> $@-t
- echo 'export LVM_TEST_CACHE_DUMP_CMD=$${LVM_TEST_CACHE_DUMP_CMD-@CACHE_DUMP_CMD@}' >> $@-t
- echo 'export LVM_TEST_CACHE_REPAIR_CMD=$${LVM_TEST_CACHE_REPAIR_CMD-@CACHE_REPAIR_CMD@}' >> $@-t
- echo 'export LVM_TEST_CACHE_RESTORE_CMD=$${LVM_TEST_CACHE_RESTORE_CMD-@CACHE_RESTORE_CMD@}' >> $@-t
+ echo 'DM_UDEV_SYNCHRONISATION=$(dm_udev_synchronisation)' >> $@-t
+ echo 'THIN=@THIN@' >> $@-t
+ echo 'RAID=@RAID@' >> $@-t
+ echo 'CACHE=@CACHE@' >> $@-t
+ echo 'LVMETAD_PIDFILE="@LVMETAD_PIDFILE@"' >> $@-t
+ echo 'LVMPOLLD_PIDFILE="@LVMPOLLD_PIDFILE@"' >> $@-t
+ echo 'DMEVENTD_PIDFILE="@DMEVENTD_PIDFILE@"' >> $@-t
+ echo 'CLVMD_PIDFILE="@CLVMD_PIDFILE@"' >> $@-t
+ echo 'LVM_TEST_THIN_CHECK_CMD=$${LVM_TEST_THIN_CHECK_CMD-@THIN_CHECK_CMD@}' >> $@-t
+ echo 'LVM_TEST_THIN_DUMP_CMD=$${LVM_TEST_THIN_DUMP_CMD-@THIN_DUMP_CMD@}' >> $@-t
+ echo 'LVM_TEST_THIN_REPAIR_CMD=$${LVM_TEST_THIN_REPAIR_CMD-@THIN_REPAIR_CMD@}' >> $@-t
+ echo 'LVM_TEST_THIN_RESTORE_CMD=$${LVM_TEST_THIN_RESTORE_CMD-@THIN_RESTORE_CMD@}' >> $@-t
+ echo 'LVM_TEST_CACHE_CHECK_CMD=$${LVM_TEST_CACHE_CHECK_CMD-@CACHE_CHECK_CMD@}' >> $@-t
+ echo 'LVM_TEST_CACHE_DUMP_CMD=$${LVM_TEST_CACHE_DUMP_CMD-@CACHE_DUMP_CMD@}' >> $@-t
+ echo 'LVM_TEST_CACHE_REPAIR_CMD=$${LVM_TEST_CACHE_REPAIR_CMD-@CACHE_REPAIR_CMD@}' >> $@-t
+ echo 'LVM_TEST_CACHE_RESTORE_CMD=$${LVM_TEST_CACHE_RESTORE_CMD-@CACHE_RESTORE_CMD@}' >> $@-t
+ echo 'export DM_UDEV_SYNCHRONISATION THIN RAID CACHE\' >> $@-t
+ echo ' LVMETAD_PIDFILE LVMPOLLD_PIDFILE DMEVENTD_PIDFILE CLVMD_PIDFILE\' >> $@-t
+ echo ' LVM_TEST_THIN_CHECK_CMD LVM_TEST_THIN_DUMP_CMD LVM_TEST_THIN_REPAIR_CMD LVM_TEST_THIN_RESTORE_CMD\' >> $@-t
+ echo ' LVM_TEST_CACHE_CHECK_CMD LVM_TEST_CACHE_DUMP_CMD LVM_TEST_CACHE_REPAIR_CMD LVM_TEST_CACHE_RESTORE_CMD' >> $@-t
mv $@-t $@
lib/paths-installed: lib/paths-common
diff --git a/test/lib/inittest.sh b/test/lib/inittest.sh
index f959b71..d3844b4 100644
--- a/test/lib/inittest.sh
+++ b/test/lib/inittest.sh
@@ -57,9 +57,10 @@ TESTDIR=$(mkdtemp "${LVM_TEST_DIR:-/tmp}" "$PREFIX.XXXXXXXXXX") || \
RUNNING_DMEVENTD=$(pgrep dmeventd || true)
export TESTOLDPWD TESTDIR COMMON_PREFIX PREFIX RUNNING_DMEVENTD
-export LVM_LOG_FILE_EPOCH=DEBUG
-export LVM_LOG_FILE_MAX_LINES=100000
-export LVM_EXPECTED_EXIT_STATUS=1
+LVM_LOG_FILE_EPOCH=DEBUG
+LVM_LOG_FILE_MAX_LINES=100000
+LVM_EXPECTED_EXIT_STATUS=1
+export LVM_LOG_FILE_EPOCH LVM_LOG_FILE_MAX_LINES LVM_EXPECTED_EXIT_STATUS
test -n "$BASH" && trap 'set +vx; STACKTRACE; set -vx' ERR
trap 'aux teardown' EXIT # don't forget to clean up
6 years, 9 months
master - udev: also create /dev/disk/by-part{label, uuid} and gpt-auto-root symlinks
by Peter Rajnoha
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=c48149cf80c6582c236...
Commit: c48149cf80c6582c2369bc7f8a33d794021d9dae
Parent: cf3a6bbbe881d9a4ba6d108304f0c07ee6cd8d1a
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon Jul 10 12:35:53 2017 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon Jul 10 12:36:39 2017 +0200
udev: also create /dev/disk/by-part{label,uuid} and gpt-auto-root symlinks
The blkid we call in 13-dm-disk.rules also returns identifiers for
partitions based on which the /dev/disk/by-part{uuid,label} and
gpt-auto-root symlinks should be created in the same manner as we
already create symlinks for filesystem labels and uuids.
This is because we handle blkid calls and symlink creation under
/dev/disk ourselves in our 13-dm-disk.rules for device-mapper devices
for us to have more control over this process.
See also https://lists.freedesktop.org/archives/systemd-devel/2017-July/039220.html
and original report http://tracker.ceph.com/issues/19489 for
the exact case where these symlinks were missing.
---
WHATS_NEW_DM | 1 +
udev/13-dm-disk.rules.in | 3 +++
2 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 923f25d..40fb4f4 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.142 -
=================================
+ Create /dev/disk/by-part{uuid,label} and gpt-auto-root symlinks with udev.
Version 1.02.141 - 28th June 2017
=================================
diff --git a/udev/13-dm-disk.rules.in b/udev/13-dm-disk.rules.in
index 4b64dd6..5355810 100644
--- a/udev/13-dm-disk.rules.in
+++ b/udev/13-dm-disk.rules.in
@@ -24,6 +24,9 @@ ENV{DM_NOSCAN}=="1", GOTO="dm_watch"
ENV{DM_UDEV_LOW_PRIORITY_FLAG}=="1", OPTIONS="link_priority=-100"
ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}"
ENV{ID_FS_USAGE}=="filesystem|other", ENV{ID_FS_LABEL_ENC}=="?*", SYMLINK+="disk/by-label/$env{ID_FS_LABEL_ENC}"
+ENV{ID_PART_ENTRY_UUID}=="?*", SYMLINK+="disk/by-partuuid/$env{ID_PART_ENTRY_UUID}"
+ENV{ID_PART_ENTRY_SCHEME}=="gpt", ENV{ID_PART_ENTRY_NAME}=="?*", SYMLINK+="disk/by-partlabel/$env{ID_PART_ENTRY_NAME}"
+ENV{ID_PART_ENTRY_SCHEME}=="gpt", ENV{ID_PART_GPT_AUTO_ROOT}=="1", SYMLINK+="gpt-auto-root"
# Add inotify watch to track changes on this device.
# Using the watch rule is not optimal - it generates a lot of spurious
6 years, 9 months
master - commands: fix handing of ENO_SUCH_CMD in script
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=cf3a6bbbe881d9a4ba6...
Commit: cf3a6bbbe881d9a4ba6d108304f0c07ee6cd8d1a
Parent: 85f1814e9dc574c271cfdae91adfe2628ff62fa9
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon May 8 10:50:27 2017 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Jul 7 15:34:27 2017 -0500
commands: fix handing of ENO_SUCH_CMD in script
Fix the error messages when an unrecognized command is
run from a script. We shouldn't attempt to parse options
for an unrecognized command name, which causes misleading
errors about bad options, but rather exit right when we
know the command name is not valid. Also don't complain
about exiting without an error message when running a
script if no command didn't exist.
---
tools/lvmcmdline.c | 16 ++++++++++------
1 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 2e71abf..1b7940f 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -2748,7 +2748,8 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
return_ECMD_FAILED;
/* Look up command - will be NULL if not recognised */
- cmd->cname = find_command_name(cmd->name);
+ if (!(cmd->cname = find_command_name(cmd->name)))
+ return ENO_SUCH_CMD;
if (!_process_command_line(cmd, &argc, &argv)) {
log_error("Error during parsing of command line.");
@@ -2765,10 +2766,6 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
log_debug("Parsing: %s", cmd->cmd_line);
- /* Having validated cmdline args, return if we didn't recognised the command */
- if (!cmd->cname)
- return ENO_SUCH_CMD;
-
if (!(cmd->command = _find_command(cmd, cmd->name, &argc, argv)))
return EINVALID_CMD_LINE;
@@ -3293,7 +3290,7 @@ static int _run_script(struct cmd_context *cmd, int argc, char **argv)
{
FILE *script;
char buffer[CMD_LEN];
- int ret = 0;
+ int ret = ENO_SUCH_CMD;
int magic_number = 0;
char *script_file = argv[0];
@@ -3328,6 +3325,13 @@ static int _run_script(struct cmd_context *cmd, int argc, char **argv)
if (!strcmp(argv[0], "quit") || !strcmp(argv[0], "exit"))
break;
ret = lvm_run_command(cmd, argc, argv);
+ /*
+ * FIXME: handling scripts with invalid or failing commands
+ * could use some cleaning up, e.g. error_message_produced
+ * check and error are repeated again in the caller.
+ */
+ if (ret == ENO_SUCH_CMD)
+ break;
if (ret != ECMD_PROCESSED) {
if (!error_message_produced()) {
log_debug(INTERNAL_ERROR "Failed command did not use log_error");
6 years, 10 months
master - commands: centralize shell vs script vs command decision
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=85f1814e9dc574c271c...
Commit: 85f1814e9dc574c271cfdae91adfe2628ff62fa9
Parent: c995e40b6333fb83fc1eda7be0cc4ef43f1eb88e
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon May 8 10:31:30 2017 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Jul 7 15:33:44 2017 -0500
commands: centralize shell vs script vs command decision
This clarifies the point where lvm decides if it is
running an lvm shell, command or a script.
---
tools/lvmcmdline.c | 39 ++++++++++++++++++++++++++++++---------
1 files changed, 30 insertions(+), 9 deletions(-)
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 964e295..2e71abf 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -3292,7 +3292,6 @@ void lvm_fin(struct cmd_context *cmd)
static int _run_script(struct cmd_context *cmd, int argc, char **argv)
{
FILE *script;
-
char buffer[CMD_LEN];
int ret = 0;
int magic_number = 0;
@@ -3391,7 +3390,10 @@ int lvm2_main(int argc, char **argv)
int ret, alias = 0;
struct custom_fds custom_fds;
struct cmd_context *cmd;
+ int run_shell = 0;
+ int run_script = 0;
const char *run_name;
+ const char *run_command_name = NULL;
if (!argv)
return -1;
@@ -3461,16 +3463,30 @@ int lvm2_main(int argc, char **argv)
goto_out;
}
- /* Can be the name of a script file. */
- if (run_name && !find_command_name(run_name))
- run_name = NULL;
+ /*
+ * Decide if we are running a shell or a command or a script. When
+ * there is no run_name, it's a shell, when run_name is a recognized
+ * lvm command it's that command, when run_name is not a recognized
+ * command name, try it as an lvm script.
+ */
+ if (!run_name)
+ run_shell = 1;
+ else if (!find_command_name(run_name))
+ run_script = 1;
+ else
+ run_command_name = run_name;
- if (!lvm_register_commands(cmd, run_name)) {
+ /*
+ * NULL run_command_name means register all command defs because
+ * a script or shell needs to access any command name, while a
+ * single command needs to access only defs for the named command.
+ */
+ if (!lvm_register_commands(cmd, run_command_name)) {
ret = ECMD_FAILED;
goto out;
}
- if (!alias && !argc) {
+ if (run_shell) {
#ifdef READLINE_SUPPORT
_nonroot_warning();
if (!_prepare_profiles(cmd)) {
@@ -3488,11 +3504,16 @@ int lvm2_main(int argc, char **argv)
}
_nonroot_warning();
- ret = lvm_run_command(cmd, argc, argv);
- if ((ret == ENO_SUCH_CMD) && (!alias))
+
+ if (run_script)
ret = _run_script(cmd, argc, argv);
- if (ret == ENO_SUCH_CMD)
+ else
+ ret = lvm_run_command(cmd, argc, argv);
+
+ if (ret == ENO_SUCH_CMD) {
log_error("No such command. Try 'help'.");
+ goto out;
+ }
if ((ret != ECMD_PROCESSED) && !error_message_produced()) {
log_debug(INTERNAL_ERROR "Failed command did not use log_error");
6 years, 10 months