master - tests: try unfreezeing raids
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=90512910e5ecf1a4b15...
Commit: 90512910e5ecf1a4b1538d9d9165cb0f44e2c291
Parent: b1ace8ce195046bddbbcdba08d87b7e9a741cdbc
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Mar 8 17:32:47 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Mar 13 12:58:57 2018 +0100
tests: try unfreezeing raids
With problematic kernels raid devices can be occasionaly left with
'frozen' status - try to 'unfreeze' them with idle message on teardown.
Also replace couple greps with 'built-in' dmsetup --select feature.
Note: dmsetup --select currently reports 'No devices found' on stdout
and return success - looks like a bug to fix.
---
test/lib/aux.sh | 55 +++++++++++++++++++++++++++++++---------------------
test/lib/utils.sh | 4 +++
2 files changed, 37 insertions(+), 22 deletions(-)
diff --git a/test/lib/aux.sh b/test/lib/aux.sh
index fbba84b..9f8c8d7 100644
--- a/test/lib/aux.sh
+++ b/test/lib/aux.sh
@@ -396,15 +396,23 @@ teardown_devs_prefixed() {
local prefix=$1
local stray=${2:-0}
local IFS=$IFS_NL
+ local once=1
local dm
rm -rf "$TESTDIR/dev/$prefix*"
+ # Send idle message to frozen raids (with hope to unfreeze them)
+ for dm in $(dm_status | egrep "$prefix.*raid.*frozen"); do
+ echo "## unfreezing: dmsetup message \"${dm%:*}\""
+ dmsetup message "${dm%:*}" 0 "idle" &
+ done
+
# Resume suspended devices first
- for dm in $(dm_info suspended,name | grep "^Suspended:.*$prefix"); do
- echo "dmsetup resume \"${dm#Suspended:}\""
- dmsetup clear "${dm#Suspended:}"
- dmsetup resume "${dm#Suspended:}" &
+ for dm in $(dm_info name -S "name=~$PREFIX&&suspended=Suspended"); do
+ test "$dm" != "No devices found" || break
+ echo "## resuming: dmsetup resume \"$dm\""
+ dmsetup clear "$dm"
+ dmsetup resume "$dm" &
done
wait
@@ -425,37 +433,40 @@ teardown_devs_prefixed() {
# 2nd. loop is trying --force removal which can possibly 'unstuck' some bloked operations
for i in 0 1; do
- local num_remaining_devs=999999
- local num_devs=0
test "$i" = 1 && test "$stray" = 0 && break # no stray device removal
while :; do
- local cnt
local sortby="name"
- local need_udev_wait=0
+ local num_devs=0
# HACK: sort also by minors - so we try to close 'possibly later' created device first
test "$i" = 0 || sortby="-minor"
- # when nothing left for removal, escape both loops...
- dm_info name,open --separator ' ' --sort open,"$sortby" | grep "$prefix" > out || break 2
- num_devs=$(wc -l < out)
- test "$num_devs" -lt "$num_remaining_devs" || break # not managed to reduce table size anymore
- test "$i" = 0 || echo "## removing $num_devs stray mapped devices with names beginning with $prefix: "
- while IFS=' ' read -r dm cnt; do
+ for dm in $(dm_info name,open --separator ';' --nameprefixes --sort open,"$sortby" -S "name=~$prefix") ; do
+ test "$dm" != "No devices found" || break 2
+ eval "$dm"
+
if test "$i" = 0; then
- test "$cnt" -eq 0 || break # stop loop with 1st. opened device
- dmsetup remove "$dm" &>/dev/null || touch REMOVE_FAILED &
+ if test "$once" = 1 ; then
+ once=0
+ echo "## removing stray mapped devices with names beginning with $prefix: "
+ fi
+ test "$DM_OPEN" = 0 || break # stop loop with 1st. opened device
+ dmsetup remove "$DM_NAME" &>/dev/null || touch REMOVE_FAILED &
else
- dmsetup remove -f "$dm" || true
+ dmsetup remove -f "$DM_NAME" || true
fi
- need_udev_wait=1
- done < out
- test "$need_udev_wait" -eq 1 || break
+
+ num_devs=$(( num_devs + 1 ))
+ done
+
+ test "$i" = 0 || break
+
+ test "$num_devs" -gt 0 || break
+
udev_wait
wait
- num_remaining_devs=$num_devs
- done # looping till there are some removed devicess
+ done # looping till there are some removed devices
done
}
diff --git a/test/lib/utils.sh b/test/lib/utils.sh
index bf472a4..a1f7a01 100644
--- a/test/lib/utils.sh
+++ b/test/lib/utils.sh
@@ -228,6 +228,10 @@ dm_info() {
should dmsetup info --noheadings -c -o "$@"
}
+dm_status() {
+ should dmsetup status --noheadings "$@"
+}
+
dm_table() {
should dmsetup table "$@"
}
6 years, 1 month
master - dmsetup: indent
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=b1ace8ce195046bddbb...
Commit: b1ace8ce195046bddbbcdba08d87b7e9a741cdbc
Parent: e9cadbe105b7a449d98598a9329a170bce2d689e
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Mar 12 11:58:04 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Mar 13 12:58:57 2018 +0100
dmsetup: indent
---
tools/dmsetup.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 0d5b713..eac3bb6 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -2473,7 +2473,7 @@ static int _status(CMD_ARGS)
printf("%s: ", name);
} else if (!matched) {
/*
- * Before first target of device in concise output,
+ * Before first target of device in concise output,
* print basic device information in the appropriate format.
* Separate devices by a semi-colon.
*/
6 years, 1 month
master - cleanup: matching signess
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e9cadbe105b7a449d98...
Commit: e9cadbe105b7a449d98598a9329a170bce2d689e
Parent: 49a8c786d5fdbf79ac60f2720d4e1433146d14f4
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sun Mar 11 21:08:07 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Mar 13 12:58:57 2018 +0100
cleanup: matching signess
---
lib/cache/lvmetad.c | 2 +-
tools/command.c | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/cache/lvmetad.c b/lib/cache/lvmetad.c
index b266152..589b48e 100644
--- a/lib/cache/lvmetad.c
+++ b/lib/cache/lvmetad.c
@@ -1677,7 +1677,7 @@ int lvmetad_pv_found(struct cmd_context *cmd, const struct id *pvid, struct devi
if (vg && result) {
seqno_after = daemon_reply_int(reply, "seqno_after", -1);
- if ((seqno_after != vg->seqno) ||
+ if ((seqno_after != (int) vg->seqno) ||
(seqno_after != daemon_reply_int(reply, "seqno_before", -1)))
log_warn("WARNING: Inconsistent metadata found for VG %s", vg->name);
}
diff --git a/tools/command.c b/tools/command.c
index 10efedb..fafbaa9 100644
--- a/tools/command.c
+++ b/tools/command.c
@@ -2927,7 +2927,8 @@ static void _print_man_option_desc(struct command_name *cname, int opt_enum)
char buf[DESC_LINE];
int started_cname = 0;
int line_count = 0;
- int di, bi = 0;
+ int bi = 0;
+ unsigned di;
if (desc[0] != '#') {
printf("%s", desc);
@@ -3246,7 +3247,7 @@ static void _print_man_all_positions_desc(struct command_name *cname)
static void _print_desc_man(const char *desc)
{
char buf[DESC_LINE] = {0};
- int di = 0;
+ unsigned di;
int bi = 0;
for (di = 0; di < strlen(desc); di++) {
6 years, 1 month
master - dmsetup: report close as debug
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=49a8c786d5fdbf79ac6...
Commit: 49a8c786d5fdbf79ac60f2720d4e1433146d14f4
Parent: 06c1f71897273558b5ffe607ceaee6d51576b861
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Mar 12 23:01:52 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Mar 13 12:58:57 2018 +0100
dmsetup: report close as debug
Since close() failures are not causing command errors,
issue error via debug log stream only.
---
tools/dmsetup.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index c866cd6..0d5b713 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -5437,7 +5437,7 @@ static int _stats_create_file(CMD_ARGS)
}
if (close(fd))
- log_error("Error closing %s.", abspath);
+ log_sys_debug("close", abspath);
fd = -1;
@@ -5466,7 +5466,7 @@ bad:
dm_free(bounds);
if ((fd > -1) && close(fd))
- log_error("Error closing %s", path);
+ log_sys_debug("close", path);
if (dms)
dm_stats_destroy(dms);
@@ -6065,7 +6065,7 @@ static int _stats_update_file(CMD_ARGS)
out:
if (close(fd))
- log_error("Error closing %s", abspath);
+ log_sys_debug("close", abspath);
dm_free(regions);
dm_free(abspath);
@@ -6076,7 +6076,7 @@ bad:
dm_free(abspath);
if ((fd > -1) && close(fd))
- log_error("Error closing %s", path);
+ log_sys_debug("close", path);
dm_stats_destroy(dms);
@@ -6614,7 +6614,7 @@ bad:
if (fd > -1 && close(fd))
log_sys_error("close", file);
- return_0;
+ return 0;
}
static int _process_losetup_switches(const char *base, int *argcp, char ***argvp,
6 years, 1 month
master - dmsetup: use dm_snprintf
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=06c1f71897273558b5f...
Commit: 06c1f71897273558b5ffe607ceaee6d51576b861
Parent: 3f351466f7d2789b1f480cd0e370f978df8eb09b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Mar 12 11:57:31 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Mar 13 12:58:57 2018 +0100
dmsetup: use dm_snprintf
---
tools/dmsetup.c | 4 +---
1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 88fb044..c866cd6 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -2297,7 +2297,6 @@ static int _mknodes(CMD_ARGS)
static int _exec_command(const char *name)
{
- int n;
static char path[PATH_MAX];
static char *args[ARGS_MAX + 1];
static int argc = 0;
@@ -2310,8 +2309,7 @@ static int _exec_command(const char *name)
if (!dm_mknodes(name))
return_0;
- n = snprintf(path, sizeof(path), "%s/%s", dm_dir(), name);
- if (n < 0 || n > (int) sizeof(path) - 1)
+ if (dm_snprintf(path, sizeof(path), "%s/%s", dm_dir(), name) < 0)
return_0;
if (!argc) {
6 years, 1 month
master - dmsetup: update _display_info
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=3f351466f7d2789b1f4...
Commit: 3f351466f7d2789b1f480cd0e370f978df8eb09b
Parent: 7ac7cc0ac858462522ef129db4359de69bc6e90d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Mar 12 11:56:54 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Mar 13 12:58:57 2018 +0100
dmsetup: update _display_info
Handle error code.
---
tools/dmsetup.c | 21 ++++++++-------------
1 files changed, 8 insertions(+), 13 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 06eba19..88fb044 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -863,11 +863,6 @@ static int _display_info_cols(struct dm_task *dmt, struct dm_info *info)
int selected;
char *device_name;
- if (!info->exists) {
- fprintf(stderr, "Device does not exist.\n");
- return 0;
- }
-
obj.task = dmt;
obj.info = info;
obj.deps_task = NULL;
@@ -971,11 +966,6 @@ static void _display_info_long(struct dm_task *dmt, struct dm_info *info)
const char *uuid;
uint32_t read_ahead;
- if (!info->exists) {
- fprintf(stderr, "Device does not exist.\n");
- return;
- }
-
printf("Name: %s\n", dm_task_get_name(dmt));
printf("State: %s%s%s\n",
@@ -1013,17 +1003,22 @@ static void _display_info_long(struct dm_task *dmt, struct dm_info *info)
static int _display_info(struct dm_task *dmt)
{
struct dm_info info;
+ int r = 1;
if (!dm_task_get_info(dmt, &info))
return_0;
+ if (!info.exists) {
+ log_error("Device does not exist.");
+ return 0;
+ }
+
if (!_switches[COLS_ARG])
_display_info_long(dmt, &info);
else
- /* FIXME return code */
- _display_info_cols(dmt, &info);
+ r = _display_info_cols(dmt, &info);
- return info.exists ? 1 : 0;
+ return r;
}
static int _set_task_device(struct dm_task *dmt, const char *name, int optional)
6 years, 1 month
master - dmsetup: update messages
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=7ac7cc0ac858462522e...
Commit: 7ac7cc0ac858462522ef129db4359de69bc6e90d
Parent: 9476cf8cdc8ead9dde4b5f768df878f41091c50c
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Mar 12 11:56:25 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Mar 13 12:58:57 2018 +0100
dmsetup: update messages
---
tools/dmsetup.c | 29 ++++++++++++++---------------
1 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index df148e4..06eba19 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -636,14 +636,13 @@ static int _do_timerfd_wait(void)
if (bytes < 0) {
/* EBADF from invalid timerfd or EINVAL from too small buffer. */
- log_error("Interval timer wait failed: %s",
- strerror(errno));
+ log_error("Interval timer wait failed: %s.", strerror(errno));
return 0;
}
/* read(2) on a timerfd descriptor is guaranteed to return 8 bytes. */
if (bytes != 8)
- log_error("Unexpected byte count on timerfd read: " FMTssize_t, bytes);
+ log_error("Unexpected byte count on timerfd read: " FMTssize_t ".", bytes);
/* FIXME: attempt to rebase clock? */
if (expired > 1)
@@ -708,7 +707,7 @@ static int _do_usleep_wait(void)
} else {
dm_timestamp_get(_now);
delta_t = dm_timestamp_delta(_now, _start_timestamp);
- log_debug("Interval timer drift: "FMTd64,
+ log_debug("Interval timer drift: "FMTd64".",
(delta_t % _interval));
/* FIXME: usleep timer drift over large counts. */
@@ -816,12 +815,12 @@ static int _update_interval_times(void)
delta_t = _interval;
/* start the first cycle */
- log_debug("Beginning first interval");
+ log_debug("Beginning first interval.");
_new_interval = 1;
}
- log_debug("Interval #%-4"PRIu64" time delta: %12"
- PRIu64"ns", interval_num, delta_t);
+ log_debug("Interval #%-4"PRIu64" time delta: %12"PRIu64"ns.",
+ interval_num, delta_t);
if (_new_interval) {
/* Update timestamp and interval and clear _new_interval */
@@ -832,9 +831,9 @@ static int _update_interval_times(void)
/*
* Log interval duration and current error.
*/
- log_debug("Interval #%-5"PRIu64" current err: %12"PRIi64"ns",
+ log_debug("Interval #%-5"PRIu64" current err: %12"PRIi64"ns.",
interval_num, ((int64_t)_last_interval - (int64_t)_interval));
- log_debug("End interval #%-9"PRIu64" duration: %12"PRIu64"ns",
+ log_debug("End interval #%-9"PRIu64" duration: %12"PRIu64"ns.",
interval_num, _last_interval);
}
@@ -924,7 +923,7 @@ static int _display_info_cols(struct dm_task *dmt, struct dm_info *info)
/* Update timestamps and handle end-of-interval accounting. */
_update_interval_times();
- log_debug("Adjusted sample interval duration: %12"PRIu64"ns", _last_interval);
+ log_debug("Adjusted sample interval duration: %12"PRIu64"ns.", _last_interval);
/* use measured approximation for calculations */
dm_stats_set_sampling_interval_ns(obj.stats, _last_interval);
} else if (!obj.stats && (_report_type & DR_STATS_META)
@@ -1907,7 +1906,7 @@ static int _udevcomplete_all(CMD_ARGS)
if (semctl(sid, 0, IPC_RMID, 0) < 0) {
log_error("Could not cleanup notification semaphore "
"with semid %d and cookie value "
- FMTu32 " (0x" FMTx32 ")", sid,
+ FMTu32 " (0x" FMTx32 ").", sid,
sdata.sem_perm.__key, sdata.sem_perm.__key);
continue;
}
@@ -5153,7 +5152,7 @@ static int _stats_group_segments(struct dm_stats *dms, uint64_t *region_ids,
regions, group_id, (alias) ? " with alias " : "",
(alias) ? : "");
else
- log_error("Failed to create group for regions %s", regions);
+ log_error("Failed to create group for regions %s.", regions);
bad:
dm_free(regions);
@@ -5434,7 +5433,7 @@ static int _stats_create_file(CMD_ARGS)
bounds, alias);
if (!regions) {
- log_error("Could not create regions from file %s", abspath);
+ log_error("Could not create regions from file %s.", abspath);
goto bad;
}
@@ -5445,7 +5444,7 @@ static int _stats_create_file(CMD_ARGS)
}
if (close(fd))
- log_error("Error closing %s", abspath);
+ log_error("Error closing %s.", abspath);
fd = -1;
@@ -7141,7 +7140,7 @@ static int _process_switches(int *argcp, char ***argvp, const char *dev_dir)
else if (!strcasecmp(optarg, "hex"))
_int_args[MANGLENAME_ARG] = DM_STRING_MANGLING_HEX;
else {
- log_error("Unknown name mangling mode");
+ log_error("Unknown name mangling mode.");
return 0;
}
dm_set_name_mangling_mode((dm_string_mangling_t) _int_args[MANGLENAME_ARG]);
6 years, 1 month
master - dmsetup: join large fprintf
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9476cf8cdc8ead9dde4...
Commit: 9476cf8cdc8ead9dde4b5f768df878f41091c50c
Parent: 5f5db7cf41203a12ab5a5973459e1a621e4df17b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Mar 12 11:41:12 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Mar 13 12:58:57 2018 +0100
dmsetup: join large fprintf
Concatenate strings and make binary slightly smaller.
---
tools/dmsetup.c | 66 +++++++++++++++++++++++++++---------------------------
1 files changed, 33 insertions(+), 33 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index 336d4c0..df148e4 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -6257,32 +6257,32 @@ static void _stats_usage(FILE *out)
{
int i;
- fprintf(out, "Usage:\n\n");
- fprintf(out, "%s\n", _base_commands[_base_command].name);
- fprintf(out, " [-h|--help]\n");
- fprintf(out, " [-v|--verbose [-v|--verbose ...]]\n");
- fprintf(out, " [--areas <nr_areas>] [--areasize <size>]\n");
- fprintf(out, " [--userdata <data>] [--clear]\n");
- fprintf(out, " [--count <count>] [--interval <seconds>]\n");
- fprintf(out, " [-o <fields>] [-O|--sort <sort_fields>]\n");
- fprintf(out, " [--programid <id>]\n");
- fprintf(out, " [--start <start>] [--length <length>]\n");
- fprintf(out, " [--segments] [--units <units>]\n\n");
+ fprintf(out, "Usage:\n\n"
+ "%s\n"
+ " [-h|--help]\n"
+ " [-v|--verbose [-v|--verbose ...]]\n"
+ " [--areas <nr_areas>] [--areasize <size>]\n"
+ " [--userdata <data>] [--clear]\n"
+ " [--count <count>] [--interval <seconds>]\n"
+ " [-o <fields>] [-O|--sort <sort_fields>]\n"
+ " [--programid <id>]\n"
+ " [--start <start>] [--length <length>]\n"
+ " [--segments] [--units <units>]\n\n",
+ _base_commands[_base_command].name);
for (i = 0; _stats_subcommands[i].name; i++)
fprintf(out, "\t%s %s\n", _stats_subcommands[i].name, _stats_subcommands[i].help);
- fprintf(out, "\n<device> may be device name or (if only one) -u <uuid> or -j <major> -m <minor>\n");
- fprintf(out, "<fields> are comma-separated. Use 'help -c' for list.\n");
- putc('\n', out);
+ fprintf(out, "\n<device> may be device name or (if only one) -u <uuid> or -j <major> -m <minor>\n"
+ "<fields> are comma-separated. Use 'help -c' for list.\n\n");
}
static void _dmsetup_usage(FILE *out)
{
int i;
- fprintf(out, "Usage:\n\n");
- fprintf(out, "%s\n"
+ fprintf(out, "Usage:\n\n"
+ "%s\n"
" [--version] [-h|--help [-c|-C|--columns]]\n"
" [-v|--verbose [-v|--verbose ...]] [-f|--force]\n"
" [--checks] [--manglename {none|hex|auto}]\n"
@@ -6298,27 +6298,27 @@ static void _dmsetup_usage(FILE *out)
fprintf(out, "\t%s %s\n", _dmsetup_commands[i].name, _dmsetup_commands[i].help);
fprintf(out, "\n<device> may be device name or (if only one) -u <uuid> or "
- "-j <major> -m <minor>\n");
- fprintf(out, "<mangling_mode> is one of 'none', 'auto' and 'hex'.\n");
- fprintf(out, "<fields> are comma-separated. Use 'help -c' for list.\n");
- fprintf(out, "<concise_device_specification> has single-device entries separated by semi-colons:\n"
- " <name>,<uuid>,<minor>,<flags>,<table>\n"
- " where <flags> is 'ro' or 'rw' (the default) and any of <uuid>, <minor>\n"
- " and <flags> may be empty. Separate extra table lines with commas.\n"
- " E.g.: dev1,,,,0 100 linear 253:1 0,100 100 error;dev2,,,ro,0 1 error\n");
- fprintf(out, "Table_file contents may be supplied on stdin.\n");
- fprintf(out, "Options are: devno, devname, blkdevname.\n");
- fprintf(out, "Tree specific options are: ascii, utf, vt100; compact, inverted, notrunc;\n"
- " blkdevname, [no]device, active, open, rw and uuid.\n");
- putc('\n', out);
+ "-j <major> -m <minor>\n"
+ "<mangling_mode> is one of 'none', 'auto' and 'hex'.\n"
+ "<fields> are comma-separated. Use 'help -c' for list.\n"
+ "<concise_device_specification> has single-device entries separated by semi-colons:\n"
+ " <name>,<uuid>,<minor>,<flags>,<table>\n"
+ " where <flags> is 'ro' or 'rw' (the default) and any of <uuid>, <minor>\n"
+ " and <flags> may be empty. Separate extra table lines with commas.\n"
+ " E.g.: dev1,,,,0 100 linear 253:1 0,100 100 error;dev2,,,ro,0 1 error\n"
+ "Table_file contents may be supplied on stdin.\n"
+ "Options are: devno, devname, blkdevname.\n"
+ "Tree specific options are: ascii, utf, vt100; compact, inverted, notrunc;\n"
+ " blkdevname, [no]device, active, open, rw and uuid.\n\n");
}
static void _losetup_usage(FILE *out)
{
- fprintf(out, "Usage:\n\n");
- fprintf(out, "%s [-d|-a] [-e encryption] "
- "[-o offset] [-f|loop_device] [file]\n\n",
- _base_commands[_base_command].name);
+ fprintf(out,
+ "Usage:\n\n"
+ "%s [-d|-a] [-e encryption] "
+ "[-o offset] [-f|loop_device] [file]\n\n",
+ _base_commands[_base_command].name);
}
static void _usage(FILE *out)
6 years, 1 month
master - dmsetup: stderr to log_error
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=5f5db7cf41203a12ab5...
Commit: 5f5db7cf41203a12ab5a5973459e1a621e4df17b
Parent: f203d4e20601f4fb840df5e3f4f9ea93025a1060
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Mar 12 11:40:30 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Mar 13 12:58:57 2018 +0100
dmsetup: stderr to log_error
---
tools/dmsetup.c | 68 ++++++++++++++++++++++++++----------------------------
1 files changed, 33 insertions(+), 35 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index f7df581..336d4c0 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -420,7 +420,7 @@ out:
free(buffer);
#endif
if (file && fclose(fp))
- fprintf(stderr, "%s: fclose failed: %s", file, strerror(errno));
+ log_sys_debug("fclose", file);
return r;
}
@@ -2283,7 +2283,7 @@ static int _remove_all(CMD_ARGS)
if (!_num_devices)
return r;
- fprintf(stderr, "Unable to remove %d device(s).\n", _num_devices);
+ log_error("Unable to remove %d device(s).", _num_devices);
return r;
}
@@ -6505,7 +6505,7 @@ static int _process_tree_options(const char *options)
else if (!strncmp(s, "notrunc", len))
_tree_switches[TR_TRUNCATE] = 0;
else {
- fprintf(stderr, "Tree options not recognised: %s\n", s);
+ log_error("Tree options not recognised: %s.", s);
return 0;
}
if (!*end)
@@ -6594,9 +6594,9 @@ static int _loop_table(char *table, size_t tlen, char *file,
sectors = size >> SECTOR_SHIFT;
if (_switches[VERBOSE_ARG])
- fprintf(stderr, LOSETUP_CMD_NAME ": set loop size to %llukB "
- "(%llu sectors)\n", (long long unsigned) sectors >> 1,
- (long long unsigned) sectors);
+ log_error(LOSETUP_CMD_NAME ": set loop size to %llukB (%llu sectors).",
+ (long long unsigned) sectors >> 1,
+ (long long unsigned) sectors);
#ifdef HAVE_SYS_STATVFS_H
if (fstatvfs(fd, &fsbuf))
@@ -6607,14 +6607,14 @@ static int _loop_table(char *table, size_t tlen, char *file,
#endif
if (close(fd))
- log_sys_error("close", file);
+ log_sys_debug("close", file);
if (dm_snprintf(table, tlen, "%llu %llu loop %s %llu\n", 0ULL,
(long long unsigned)sectors, file, (long long unsigned)off) < 0)
return_0;
if (_switches[VERBOSE_ARG] > 1)
- fprintf(stderr, "Table: %s\n", table);
+ log_error("Table: %s", table);
return 1;
@@ -6664,33 +6664,32 @@ static int _process_losetup_switches(const char *base, int *argcp, char ***argvp
*argcp -= optind ;
if (encrypt_loop){
- fprintf(stderr, "%s: Sorry, cryptoloop is not yet implemented "
- "in this version.\n", base);
+ log_error("%s: Sorry, cryptoloop is not yet implemented "
+ "in this version.", base);
return 0;
}
if (show_all) {
- fprintf(stderr, "%s: Sorry, show all is not yet implemented "
- "in this version.\n", base);
+ log_error("%s: Sorry, show all is not yet implemented "
+ "in this version.", base);
return 0;
}
if (find) {
- fprintf(stderr, "%s: Sorry, find is not yet implemented "
- "in this version.\n", base);
+ log_error("%s: Sorry, find is not yet implemented "
+ "in this version.", base);
if (!*argcp)
return 0;
}
if (!*argcp) {
- fprintf(stderr, "%s: Please specify loop_device.\n", base);
+ log_error("%s: Please specify loop_device.", base);
_usage(stderr);
return 0;
}
if (!(device_name = _parse_loop_device_name((*argvp)[0], dev_dir))) {
- fprintf(stderr, "%s: Could not parse loop_device %s\n",
- base, (*argvp)[0]);
+ log_error("%s: Could not parse loop_device %s", base, (*argvp)[0]);
_usage(stderr);
return 0;
}
@@ -6705,7 +6704,7 @@ static int _process_losetup_switches(const char *base, int *argcp, char ***argvp
}
if (*argcp != 2) {
- fprintf(stderr, "%s: Too few arguments\n", base);
+ log_error("%s: Too few arguments.", base);
_usage(stderr);
dm_free(device_name);
return 0;
@@ -6713,8 +6712,8 @@ static int _process_losetup_switches(const char *base, int *argcp, char ***argvp
/* FIXME move these to make them available to native dmsetup */
if (!(loop_file = _get_abspath((*argvp)[(find) ? 0 : 1]))) {
- fprintf(stderr, "%s: Could not parse loop file name %s\n",
- base, (*argvp)[1]);
+ log_error("%s: Could not parse loop file name %s.",
+ base, (*argvp)[1]);
_usage(stderr);
dm_free(device_name);
return 0;
@@ -6723,7 +6722,7 @@ static int _process_losetup_switches(const char *base, int *argcp, char ***argvp
_table = dm_malloc(LOOP_TABLE_SIZE);
if (!_table ||
!_loop_table(_table, (size_t) LOOP_TABLE_SIZE, loop_file, device_name, offset)) {
- fprintf(stderr, "Could not build device-mapper table for %s\n", (*argvp)[0]);
+ log_error("Could not build device-mapper table for %s.", (*argvp)[0]);
dm_free(device_name);
return 0;
}
@@ -6768,7 +6767,7 @@ static int _process_options(const char *options)
else if (!strncmp(s, "devname", len))
_dev_name_type = DN_MAP;
else {
- fprintf(stderr, "Option not recognised: %s\n", s);
+ log_error("Option not recognised: %s.", s);
return 0;
}
@@ -6881,7 +6880,7 @@ static int _process_switches(int *argcp, char ***argvp, const char *dev_dir)
_read_ahead_flags = 0;
if (!(namebase = strdup((*argvp)[0]))) {
- fprintf(stderr, "Failed to duplicate name.\n");
+ log_error("Failed to duplicate name.");
return 0;
}
@@ -7216,18 +7215,17 @@ static int _process_switches(int *argcp, char ***argvp, const char *dev_dir)
if ((_switches[MAJOR_ARG] && !_switches[MINOR_ARG]) ||
(!_switches[MAJOR_ARG] && _switches[MINOR_ARG])) {
- fprintf(stderr, "Please specify both major number and "
- "minor number.\n");
+ log_error("Please specify both major number and minor number.");
return 0;
}
if (_switches[TABLE_ARG] && _switches[NOTABLE_ARG]) {
- fprintf(stderr, "--table and --notable are incompatible.\n");
+ log_error("--table and --notable are incompatible.");
return 0;
}
if (_switches[ADD_NODE_ON_RESUME_ARG] && _switches[ADD_NODE_ON_CREATE_ARG]) {
- fprintf(stderr, "--addnodeonresume and --addnodeoncreate are incompatible.\n");
+ log_error("--addnodeonresume and --addnodeoncreate are incompatible.");
return 0;
}
@@ -7257,7 +7255,7 @@ static int _perform_command_for_all_repeatable_args(CMD_ARGS)
{
do {
if (!cmd->fn(cmd, subcommand, argc, argv++, NULL, multiple_devices)) {
- fprintf(stderr, "Command failed\n");
+ log_error("Command failed.");
return 0;
}
} while (cmd->repeatable_cmd && argc-- > 1);
@@ -7280,17 +7278,17 @@ int main(int argc, char **argv)
(void) setlocale(LC_ALL, "");
- dev_dir = getenv (DM_DEV_DIR_ENV_VAR_NAME);
+ dev_dir = getenv(DM_DEV_DIR_ENV_VAR_NAME);
if (dev_dir && *dev_dir) {
if (!dm_set_dev_dir(dev_dir)) {
- fprintf(stderr, "Invalid DM_DEV_DIR environment variable value.\n");
+ log_error("Invalid DM_DEV_DIR environment variable value.");
goto out;
}
} else
dev_dir = DEFAULT_DM_DEV_DIR;
if (!_process_switches(&argc, &argv, dev_dir)) {
- fprintf(stderr, "Couldn't process command line.\n");
+ log_error("Couldn't process command line.");
goto out;
}
@@ -7327,14 +7325,14 @@ int main(int argc, char **argv)
if (!(cmd = _find_dmsetup_command(_command))) {
unknown:
- fprintf(stderr, "Unknown command\n");
+ log_error("Unknown command.");
_usage(stderr);
goto out;
}
if (argc < cmd->min_args ||
(cmd->max_args >= 0 && argc > cmd->max_args)) {
- fprintf(stderr, "Incorrect number of arguments\n");
+ log_error("Incorrect number of arguments.");
_usage(stderr);
goto out;
}
@@ -7354,7 +7352,7 @@ unknown:
dm_set_name_mangling_mode(DM_STRING_MANGLING_NONE);
if (!_process_options(_string_args[OPTIONS_ARG])) {
- fprintf(stderr, "Couldn't process command line.\n");
+ log_error("Couldn't process command line.");
goto out;
}
@@ -7380,7 +7378,7 @@ unknown:
_selection_cmd = cmd;
_switches[COLS_ARG] = 1;
if (!(cmd = _find_dmsetup_command("info"))) {
- fprintf(stderr, "Internal error finding dmsetup info command struct.\n");
+ log_error(INTERNAL_ERROR "finding dmsetup info command struct.");
goto out;
}
}
6 years, 1 month
master - dmsetup: cleanup err usage
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=f203d4e20601f4fb840...
Commit: f203d4e20601f4fb840df5e3f4f9ea93025a1060
Parent: 3b7834af17ba17f4c478937ac5cb022045bb782b
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Mar 9 20:50:43 2018 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Mar 13 12:58:57 2018 +0100
dmsetup: cleanup err usage
Macro err() add '\n'.
---
tools/dmsetup.c | 62 ++++++++++++++++++++++++++----------------------------
1 files changed, 30 insertions(+), 32 deletions(-)
diff --git a/tools/dmsetup.c b/tools/dmsetup.c
index a394c3f..f7df581 100644
--- a/tools/dmsetup.c
+++ b/tools/dmsetup.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
- * Copyright (C) 2004-2015 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2018 Red Hat, Inc. All rights reserved.
* Copyright (C) 2005-2007 NEC Corporation
*
* This file is part of the device-mapper userspace tools.
@@ -103,8 +103,6 @@ extern char *optarg;
/* FIXME Should be elsewhere */
#define SECTOR_SHIFT 9L
-#define err(msg, x...) fprintf(stderr, msg "\n", ##x)
-
/* program_id used for dmstats-managed statistics regions */
#define DM_STATS_PROGRAM_ID "dmstats"
@@ -347,7 +345,7 @@ static int _parse_line(struct dm_task *dmt, char *buffer, const char *file,
if (sscanf(ptr, "%llu %llu %s %n",
&start, &size, ttype, &n) < 3) {
- err("Invalid format on line %d of table %s", line, file);
+ log_error("Invalid format on line %d of table %s.", line, file);
return 0;
}
@@ -392,7 +390,7 @@ static int _parse_file(struct dm_task *dmt, const char *file)
/* OK for empty stdin */
if (file) {
if (!(fp = fopen(file, "r"))) {
- err("Couldn't open '%s' for reading", file);
+ log_error("Couldn't open '%s' for reading.", file);
return 0;
}
} else
@@ -401,7 +399,7 @@ static int _parse_file(struct dm_task *dmt, const char *file)
#ifndef HAVE_GETLINE
buffer_size = LINE_SIZE;
if (!(buffer = dm_malloc(buffer_size))) {
- err("Failed to malloc line buffer.");
+ log_error("Failed to malloc line buffer.");
return 0;
}
@@ -1042,7 +1040,7 @@ static int _set_task_device(struct dm_task *dmt, const char *name, int optional)
!dm_task_set_minor(dmt, _int_args[MINOR_ARG]))
return_0;
} else if (!optional) {
- fprintf(stderr, "No device specified.\n");
+ log_error("No device specified.");
return 0;
}
@@ -1073,20 +1071,20 @@ static int _load(CMD_ARGS)
const char *name = NULL;
if (_switches[NOTABLE_ARG]) {
- err("--notable only available when creating new device\n");
+ log_error("--notable only available when creating new device.");
return 0;
}
if (!_switches[UUID_ARG] && !_switches[MAJOR_ARG]) {
if (!argc) {
- err("Please specify device.\n");
+ log_error("Please specify device.");
return 0;
}
name = argv[0];
argc--;
argv++;
} else if (argc > 1) {
- err("Too many command line arguments.\n");
+ log_error("Too many command line arguments.");
return 0;
}
@@ -1516,7 +1514,7 @@ static int _message(CMD_ARGS)
errno = 0;
sector = strtoull(argv[0], &endptr, 10);
if (errno || *endptr || endptr == argv[0]) {
- err("invalid sector");
+ log_error("Invalid sector.");
goto out;
}
if (!dm_task_set_sector(dmt, sector))
@@ -1526,13 +1524,13 @@ static int _message(CMD_ARGS)
argv++;
if (argc <= 0)
- err("No message supplied.\n");
+ log_error("No message supplied.");
for (i = 0; i < argc; i++)
sz += strlen(argv[i]) + 1;
if (!(str = dm_zalloc(sz))) {
- err("message string allocation failed");
+ log_error("Message string allocation failed.");
goto out;
}
@@ -1642,7 +1640,7 @@ static uint32_t _get_cookie_value(const char *str_value)
value = strtoul(str_value, &p, 0);
if (errno || !value || (*p) || (value > UINT32_MAX)) {
- err("Incorrect cookie value");
+ log_error("Incorrect cookie value.");
return 0;
}
@@ -2087,7 +2085,7 @@ static int _wait(CMD_ARGS)
if (!_switches[UUID_ARG] && !_switches[MAJOR_ARG]) {
if (!argc) {
- err("No device specified.");
+ log_error("No device specified.");
return 0;
}
name = argv[0];
@@ -2191,8 +2189,8 @@ static int _error_device(CMD_ARGS)
name = names ? names->name : argv[0];
if (!name || !*name) {
- err("No device specified.");
- return_0;
+ log_error("No device specified.");
+ return 0;
}
size = _get_device_size(name);
@@ -2342,7 +2340,7 @@ static int _exec_command(const char *name)
}
if (argc == ARGS_MAX) {
- err("Too many args to --exec\n");
+ log_error("Too many args to --exec.");
argc = -1;
return 0;
}
@@ -2453,8 +2451,8 @@ static int _status(CMD_ARGS)
goto_out;
if (!info.exists) {
- fprintf(stderr, "Device does not exist.\n");
- goto_out;
+ log_error("Device does not exist.");
+ goto out;
}
if (!name)
@@ -4777,7 +4775,7 @@ static int _report_init(const struct command *cmd, const char *subcommand)
opt_fields = _string_args[OPTIONS_ARG] + 1;
len = strlen(options) + strlen(opt_fields) + 2;
if (!(tmpopts = dm_malloc(len))) {
- err("Failed to allocate option string.");
+ log_error("Failed to allocate option string.");
return 0;
}
if (dm_snprintf(tmpopts, len, "%s,%s",
@@ -4793,7 +4791,7 @@ static int _report_init(const struct command *cmd, const char *subcommand)
keys = _string_args[SORT_ARG];
buffered = 1;
if (cmd && (!strcmp(cmd->name, "status") || !strcmp(cmd->name, "table"))) {
- err("--sort is not yet supported with status and table");
+ log_error("--sort is not yet supported with status and table.");
goto out;
}
}
@@ -4834,7 +4832,7 @@ static int _report_init(const struct command *cmd, const char *subcommand)
if ((_report_type & DR_TREE) && cmd) {
r = _build_whole_deptree(cmd);
if (!_dtree) {
- err("Internal device dependency tree creation failed.");
+ log_error("Internal device dependency tree creation failed.");
goto out;
}
}
@@ -5027,7 +5025,7 @@ static int _stats_clear(CMD_ARGS)
}
if (!_switches[REGION_ID_ARG] && !_switches[ALL_REGIONS_ARG]) {
- err("Please specify a --regionid or use --allregions.");
+ log_error("Please specify a --regionid or use --allregions.");
return 0;
}
@@ -5350,7 +5348,7 @@ static int _stats_create_file(CMD_ARGS)
dm_filemapd_mode_t mode;
if (names) {
- err("Device names are not compatibile with --filemap.");
+ log_error("Device names are not compatibile with --filemap.");
return 0;
}
@@ -5626,12 +5624,12 @@ static int _stats_delete(CMD_ARGS)
}
if (_switches[REGION_ID_ARG] && _switches[GROUP_ID_ARG]) {
- err("Please use one of --regionid and --groupid.");
+ log_error("Please use one of --regionid and --groupid.");
return 0;
}
if (!_switches[REGION_ID_ARG] && !allregions && !_switches[GROUP_ID_ARG]) {
- err("Please specify a --regionid or --groupid, or use --allregions.");
+ log_error("Please specify a --regionid or --groupid, or use --allregions.");
return 0;
}
@@ -5737,7 +5735,7 @@ static int _stats_print(CMD_ARGS)
}
if (!_switches[REGION_ID_ARG] && !allregions) {
- err("Please specify a --regionid or use --allregions.");
+ log_error("Please specify a --regionid or use --allregions.");
return 0;
}
@@ -5867,7 +5865,7 @@ static int _stats_group(CMD_ARGS)
}
if (!_switches[REGIONS_ARG]) {
- err("Group requires --regions.");
+ log_error("Group requires --regions.");
return 0;
}
@@ -5928,7 +5926,7 @@ static int _stats_ungroup(CMD_ARGS)
}
if (!_switches[GROUP_ID_ARG]) {
- err("Please specify group id.");
+ log_error("Please specify group id.");
return 0;
}
@@ -5981,7 +5979,7 @@ static int _stats_update_file(CMD_ARGS)
if (names) {
- err("Device names are not compatibile with update_filemap.");
+ log_error("Device names are not compatibile with update_filemap.");
return 0;
}
@@ -5995,7 +5993,7 @@ static int _stats_update_file(CMD_ARGS)
}
if (!_switches[GROUP_ID_ARG]) {
- err("--groupid is required to update a filemap group.");
+ log_error("--groupid is required to update a filemap group.");
return 0;
}
6 years, 1 month