master - coverity: fix warnings about missing return value check for sscanf
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3d333e5a296eba...
Commit: 3d333e5a296eba8ba2858ca007699fe70ec8083e
Parent: 48877e215d882f89294396d79f5d8d71395e427d
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue May 31 10:06:19 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue May 31 10:06:25 2016 +0200
coverity: fix warnings about missing return value check for sscanf
All the variables for sscanf in lvmlockctl.c and lvmlockd-sanlock.c are
zeroed before sscanf call so the failure is detected by seeing the zero
value instead of proper one in subsequent code - so use (void) for
sscanf calls to ignore return value here.
---
daemons/lvmlockd/lvmlockctl.c | 12 ++++++------
daemons/lvmlockd/lvmlockd-sanlock.c | 4 ++--
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/daemons/lvmlockd/lvmlockctl.c b/daemons/lvmlockd/lvmlockctl.c
index 4f559cf..7d4e072 100644
--- a/daemons/lvmlockd/lvmlockctl.c
+++ b/daemons/lvmlockd/lvmlockctl.c
@@ -77,7 +77,7 @@ static void save_client_info(char *line)
uint32_t client_id = 0;
char name[MAX_NAME+1] = { 0 };
- sscanf(line, "info=client pid=%u fd=%d pi=%d id=%u name=%s",
+ (void) sscanf(line, "info=client pid=%u fd=%d pi=%d id=%u name=%s",
&pid, &fd, &pi, &client_id, name);
clients[num_clients].client_id = client_id;
@@ -110,7 +110,7 @@ static void format_info_ls(char *line)
char lock_args[MAX_ARGS+1] = { 0 };
char lock_type[MAX_NAME+1] = { 0 };
- sscanf(line, "info=ls ls_name=%s vg_name=%s vg_uuid=%s vg_sysid=%s vg_args=%s lm_type=%s",
+ (void) sscanf(line, "info=ls ls_name=%s vg_name=%s vg_uuid=%s vg_sysid=%s vg_args=%s lm_type=%s",
ls_name, vg_name, vg_uuid, vg_sysid, lock_args, lock_type);
if (!first_ls)
@@ -131,7 +131,7 @@ static void format_info_ls_action(char *line)
uint32_t pid = 0;
char cl_name[MAX_NAME+1] = { 0 };
- sscanf(line, "info=ls_action client_id=%u %s %s op=%s",
+ (void) sscanf(line, "info=ls_action client_id=%u %s %s op=%s",
&client_id, flags, version, op);
find_client_info(client_id, &pid, cl_name);
@@ -147,7 +147,7 @@ static void format_info_r(char *line, char *r_name_out, char *r_type_out)
char sh_count[MAX_NAME+1] = { 0 };
uint32_t ver = 0;
- sscanf(line, "info=r name=%s type=%s mode=%s %s version=%u",
+ (void) sscanf(line, "info=r name=%s type=%s mode=%s %s version=%u",
r_name, r_type, mode, sh_count, &ver);
strcpy(r_name_out, r_name);
@@ -185,7 +185,7 @@ static void format_info_lk(char *line, char *r_name, char *r_type)
return;
}
- sscanf(line, "info=lk mode=%s version=%u %s client_id=%u",
+ (void) sscanf(line, "info=lk mode=%s version=%u %s client_id=%u",
mode, &ver, flags, &client_id);
find_client_info(client_id, &pid, cl_name);
@@ -221,7 +221,7 @@ static void format_info_r_action(char *line, char *r_name, char *r_type)
return;
}
- sscanf(line, "info=r_action client_id=%u %s %s op=%s rt=%s mode=%s %s %s %s",
+ (void) sscanf(line, "info=r_action client_id=%u %s %s op=%s rt=%s mode=%s %s %s %s",
&client_id, flags, version, op, rt, mode, lm, result, lm_rv);
find_client_info(client_id, &pid, cl_name);
diff --git a/daemons/lvmlockd/lvmlockd-sanlock.c b/daemons/lvmlockd/lvmlockd-sanlock.c
index b47c7f0..e344cb1 100644
--- a/daemons/lvmlockd/lvmlockd-sanlock.c
+++ b/daemons/lvmlockd/lvmlockd-sanlock.c
@@ -276,8 +276,8 @@ static int read_host_id_file(void)
*sep = '\0';
memset(key_str, 0, sizeof(key_str));
memset(val_str, 0, sizeof(val_str));
- sscanf(key, "%s", key_str);
- sscanf(val, "%s", val_str);
+ (void) sscanf(key, "%s", key_str);
+ (void) sscanf(val, "%s", val_str);
if (!strcmp(key_str, "host_id")) {
host_id = atoi(val_str);
7 years, 6 months
master - coverity: missing check for id_write_format return value
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=48877e215d882f...
Commit: 48877e215d882f89294396d79f5d8d71395e427d
Parent: 5b3a4a95956fe467a2c5fe1cce3925e67366d4fe
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue May 31 09:56:10 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue May 31 09:56:10 2016 +0200
coverity: missing check for id_write_format return value
---
daemons/lvmetad/testclient.c | 5 ++++-
lib/cache/lvmcache.c | 6 ++++--
lib/format_pool/disk_rep.c | 9 ++++++---
lib/uuid/uuid.c | 2 ++
tools/toollib.c | 11 ++++++-----
5 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/daemons/lvmetad/testclient.c b/daemons/lvmetad/testclient.c
index 56940d9..c9efbe6 100644
--- a/daemons/lvmetad/testclient.c
+++ b/daemons/lvmetad/testclient.c
@@ -75,7 +75,10 @@ int scan(daemon_handle h, char *fn) {
}
char uuid[64];
- id_write_format(dev->pvid, uuid, 64);
+ if (!id_write_format(dev->pvid, uuid, 64)) {
+ fprintf(stderr, "[C] Failed to format PV UUID for %s", dev_name(dev));
+ return;
+ }
fprintf(stderr, "[C] found PV: %s\n", uuid);
struct lvmcache_info *info = (struct lvmcache_info *) label->info;
struct physical_volume pv = { 0, };
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index 0934b20..9e232f6 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -995,7 +995,8 @@ next:
alt = devl;
}
- id_write_format((const struct id *)dev1->pvid, uuid, sizeof(uuid));
+ if (!id_write_format((const struct id *)dev1->pvid, uuid, sizeof(uuid)))
+ stack;
log_warn("WARNING: PV %s prefers device %s because %s.", uuid, dev_name(dev1), reason);
}
@@ -2066,7 +2067,8 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller,
strncpy(pvid_s, pvid, sizeof(pvid_s) - 1);
pvid_s[sizeof(pvid_s) - 1] = '\0';
- id_write_format((const struct id *)&pvid_s, uuid, sizeof(uuid));
+ if (!id_write_format((const struct id *)&pvid_s, uuid, sizeof(uuid)))
+ stack;
/*
* Find existing info struct in _pvid_hash or create a new one.
diff --git a/lib/format_pool/disk_rep.c b/lib/format_pool/disk_rep.c
index fd11380..0462eb4 100644
--- a/lib/format_pool/disk_rep.c
+++ b/lib/format_pool/disk_rep.c
@@ -60,7 +60,8 @@ static void _add_pl_to_list(struct cmd_context *cmd, struct dm_list *head, struc
if (id_equal(&data->pv_uuid, &pl->pv_uuid)) {
char uuid[ID_LEN + 7] __attribute__((aligned(8)));
- id_write_format(&pl->pv_uuid, uuid, ID_LEN + 7);
+ if (!id_write_format(&pl->pv_uuid, uuid, ID_LEN + 7))
+ stack;
if (!dev_subsystem_part_major(cmd->dev_types, data->dev)) {
log_very_verbose("Ignoring duplicate PV %s on "
@@ -90,11 +91,13 @@ int read_pool_label(struct pool_list *pl, struct labeller *l,
pool_label_in(pd, buf);
get_pool_pv_uuid(&pvid, pd);
- id_write_format(&pvid, uuid, ID_LEN + 7);
+ if (!id_write_format(&pvid, uuid, ID_LEN + 7))
+ stack;
log_debug_metadata("Calculated uuid %s for %s", uuid, dev_name(dev));
get_pool_vg_uuid(&vgid, pd);
- id_write_format(&vgid, uuid, ID_LEN + 7);
+ if (!id_write_format(&vgid, uuid, ID_LEN + 7))
+ stack;
log_debug_metadata("Calculated uuid %s for %s", uuid, pd->pl_pool_name);
if (!(info = lvmcache_add(l, (char *) &pvid, dev, pd->pl_pool_name,
diff --git a/lib/uuid/uuid.c b/lib/uuid/uuid.c
index d52353f..aa44dc4 100644
--- a/lib/uuid/uuid.c
+++ b/lib/uuid/uuid.c
@@ -171,6 +171,8 @@ int id_write_format(const struct id *id, char *buffer, size_t size)
/* split into groups separated by dashes */
if (size < (32 + 6 + 1)) {
+ if (size > 0)
+ buffer[0] = '\0';
log_error("Couldn't write uuid, buffer too small.");
return 0;
}
diff --git a/tools/toollib.c b/tools/toollib.c
index b41db0f..0de6ee8 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1858,8 +1858,8 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
skip = 0;
notfound = 0;
- if (vg_uuid)
- id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid));
+ if (vg_uuid && !id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid)))
+ stack;
log_very_verbose("Processing VG %s %s", vg_name, vg_uuid ? uuid : "");
@@ -1954,7 +1954,8 @@ static int _resolve_duplicate_vgnames(struct cmd_context *cmd,
* name/vgid and checks system_id in the metadata.
*/
if (lvmcache_vg_is_foreign(cmd, vgnl->vg_name, vgnl->vgid)) {
- id_write_format((const struct id*)vgnl->vgid, uuid, sizeof(uuid));
+ if (!id_write_format((const struct id*)vgnl->vgid, uuid, sizeof(uuid)))
+ stack;
log_warn("WARNING: Ignoring foreign VG with matching name %s UUID %s.",
vgnl->vg_name, uuid);
dm_list_del(&vgnl->list);
@@ -2659,8 +2660,8 @@ static int _process_lv_vgnameid_list(struct cmd_context *cmd, uint32_t read_flag
}
}
- if (vg_uuid)
- id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid));
+ if (vg_uuid && !id_write_format((const struct id*)vg_uuid, uuid, sizeof(uuid)))
+ stack;
log_very_verbose("Processing VG %s %s", vg_name, vg_uuid ? uuid : "");
7 years, 6 months
master - coverity: blkdeactivate: separate format and args for printf and declare and assign separately to avoid masking return values
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=5b3a4a95956fe4...
Commit: 5b3a4a95956fe467a2c5fe1cce3925e67366d4fe
Parent: 02d67848eb994c19c6ff2050196585fb763c83cb
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue May 31 09:39:06 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue May 31 09:39:06 2016 +0200
coverity: blkdeactivate: separate format and args for printf and declare and assign separately to avoid masking return values
---
scripts/blkdeactivate.sh.in | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/scripts/blkdeactivate.sh.in b/scripts/blkdeactivate.sh.in
index 39b0f2c..2a48b3e 100644
--- a/scripts/blkdeactivate.sh.in
+++ b/scripts/blkdeactivate.sh.in
@@ -147,7 +147,7 @@ device_umount_one() {
if test -z "${SKIP_UMOUNT_LIST["$mnt"]}" -a "$DO_UMOUNT" -eq "1"; then
echo -n " [UMOUNT]: unmounting $name ($kname) mounted on $mnt... "
- if eval $UMOUNT $UMOUNT_OPTS "$(printf $mnt)" $OUT $ERR; then
+ if eval $UMOUNT $UMOUNT_OPTS "$(printf "%s" "$mnt")" $OUT $ERR; then
echo "done"
else
echo "skipping"
@@ -193,7 +193,8 @@ deactivate_holders () {
}
deactivate_dm () {
- local name=$(printf $name)
+ local name
+ name=$(printf "%s" "$name")
test -b "$DEV_DIR/mapper/$name" || return 0
test -z ${SKIP_DEVICE_LIST["$kname"]} || return 1
@@ -262,7 +263,8 @@ deactivate_lvm () {
}
deactivate_md () {
- local name=$(printf $name)
+ local name
+ name=$(printf "%s" "$name")
test -b "$DEV_DIR/$name" || return 0
test -z ${SKIP_DEVICE_LIST["$kname"]} || return 1
7 years, 6 months
master - coverity: fix possible resource leak of descendants_buffer in _print_historical_lv fn
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=02d67848eb994c...
Commit: 02d67848eb994c19c6ff2050196585fb763c83cb
Parent: cfe7d2368cfaf9744e4fc82d781b3815b5c57155
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue May 31 09:36:40 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue May 31 09:36:58 2016 +0200
coverity: fix possible resource leak of descendants_buffer in _print_historical_lv fn
---
lib/format_text/export.c | 2 +-
lib/format_text/text_export.h | 1 +
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/lib/format_text/export.c b/lib/format_text/export.c
index a762c74..810c932 100644
--- a/lib/format_text/export.c
+++ b/lib/format_text/export.c
@@ -858,7 +858,7 @@ static int _print_historical_lv(struct formatter *f, struct historical_logical_v
if (!_alloc_printed_indirect_descendants(&hlv->indirect_glvs, &descendants_buffer))
goto_out;
- outnl(f);
+ outnlgo(f);
outfgo(f, "%s {", hlv->name);
_inc_indent(f);
diff --git a/lib/format_text/text_export.h b/lib/format_text/text_export.h
index 377ee93..c20c234 100644
--- a/lib/format_text/text_export.h
+++ b/lib/format_text/text_export.h
@@ -22,6 +22,7 @@
#define outf(args...) do {if (!out_text(args)) return_0;} while (0)
#define outfgo(args...) do {if (!out_text(args)) goto_out;} while (0)
#define outnl(f) do {if (!out_newline(f)) return_0;} while (0)
+#define outnlgo(f) do {if (!out_newline(f)) goto_out;} while (0)
struct formatter;
struct lv_segment;
7 years, 6 months
master - tests: add dmstats to CLEAN_TARGETS for make clean
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=cfe7d2368cfaf9...
Commit: cfe7d2368cfaf9744e4fc82d781b3815b5c57155
Parent: 4fb224a5532defa08d48b28add98606803035b9d
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue May 31 09:14:23 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue May 31 09:14:23 2016 +0200
tests: add dmstats to CLEAN_TARGETS for make clean
---
test/Makefile.in | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/test/Makefile.in b/test/Makefile.in
index 0903b90..59fcc96 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -332,7 +332,7 @@ CLEAN_TARGETS += $(RUN_BASE) $(addprefix lib/,$(LIB_LVMLOCKD_CONF))
endif
CLEAN_TARGETS += .lib-dir-stamp .tests-stamp $(LIB) $(addprefix lib/,\
- $(CMDS) clvmd dmeventd dmsetup lvmetad lvmpolld \
+ $(CMDS) clvmd dmeventd dmsetup dmstats lvmetad lvmpolld \
harness thin-performance.profile fsadm vgimportclone \
dm-version-expected version-expected \
paths-installed paths-installed-t paths-common paths-common-t)
7 years, 6 months
master - toollib: properly reset selection handle on selection failure in select_match_{pv, vg, lv}
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=4fb224a5532def...
Commit: 4fb224a5532defa08d48b28add98606803035b9d
Parent: e4ec6bcdd38505c6c229d578aa3eca006441b035
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Tue May 31 09:08:59 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Tue May 31 09:08:59 2016 +0200
toollib: properly reset selection handle on selection failure in select_match_{pv,vg,lv}
---
tools/toollib.c | 24 ++++++++++++------------
1 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/tools/toollib.c b/tools/toollib.c
index b86b8ff..b41db0f 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1766,49 +1766,49 @@ void destroy_processing_handle(struct cmd_context *cmd, struct processing_handle
int select_match_vg(struct cmd_context *cmd, struct processing_handle *handle,
struct volume_group *vg)
{
+ int r;
+
if (!handle->internal_report_for_select)
return 1;
handle->selection_handle->orig_report_type = VGS;
- if (!report_for_selection(cmd, handle, NULL, vg, NULL)) {
+ if (!(r = report_for_selection(cmd, handle, NULL, vg, NULL)))
log_error("Selection failed for VG %s.", vg->name);
- return 0;
- }
handle->selection_handle->orig_report_type = 0;
- return 1;
+ return r;
}
int select_match_lv(struct cmd_context *cmd, struct processing_handle *handle,
struct volume_group *vg, struct logical_volume *lv)
{
+ int r;
+
if (!handle->internal_report_for_select)
return 1;
handle->selection_handle->orig_report_type = LVS;
- if (!report_for_selection(cmd, handle, NULL, vg, lv)) {
+ if (!(r = report_for_selection(cmd, handle, NULL, vg, lv)))
log_error("Selection failed for LV %s.", lv->name);
- return 0;
- }
handle->selection_handle->orig_report_type = 0;
- return 1;
+ return r;
}
int select_match_pv(struct cmd_context *cmd, struct processing_handle *handle,
struct volume_group *vg, struct physical_volume *pv)
{
+ int r;
+
if (!handle->internal_report_for_select)
return 1;
handle->selection_handle->orig_report_type = PVS;
- if (!report_for_selection(cmd, handle, pv, vg, NULL)) {
+ if (!(r = report_for_selection(cmd, handle, pv, vg, NULL)))
log_error("Selection failed for PV %s.", dev_name(pv->dev));
- return 0;
- }
handle->selection_handle->orig_report_type = 0;
- return 1;
+ return r;
}
static int _select_matches(struct processing_handle *handle)
7 years, 6 months
master - report: fix lvm devtypes internal error if -S is used with field name from pvs/vgs/lvs
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e4ec6bcdd38505...
Commit: e4ec6bcdd38505c6c229d578aa3eca006441b035
Parent: 815f1ee26d5ee5c64493f83a78f8c074fc8c82d8
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon May 30 16:37:05 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon May 30 16:46:18 2016 +0200
report: fix lvm devtypes internal error if -S is used with field name from pvs/vgs/lvs
Before this fix, when reporting 'lvm devtypes', the report was
initialized with incorrect reserved values - the ones used for
pvs/vgs/lvs report were used instead of NULL value (because devtypes
doesn't have any reserved values).
For example, trying to (incorrectly) use lv_name for the -S|--select
with lvm devtypes which doesn't have this field at all:
Before this patch (internal error issued):
$ lvm devtypes -S 'lv_name=lvol0'
Internal error: _check_reserved_values_supported: field-specific reserved value of type 0x0 for field not supported
Internal error: dm_report_init_with_selection: trying to register unsupported reserved value type, skipping report selection
DevType MaxParts Description
aoe 16 ATA over Ethernet
ataraid 16 ATA Raid
bcache 1 bcache block device cache
...
With this patch applied (correct error displayed about
unrecognized selection field):
$ lvm devtypes -S 'lv_name=lvol0'
Device Types Fields
-------------------
devtype_name - Name of Device Type exactly as it appears in /proc/devices. [string]
devtype_max_partitions - Maximum number of partitions. (How many device minor numbers get reserved for each device.) [number]
devtype_description - Description of Device Type. [string]
Special Fields
--------------
selected - Set if item passes selection criteria. [number]
help - Show help. [unselectable number]
? - Show help. [unselectable number]
Unrecognised selection field: lv_name
Selection syntax error at 'lv_name=lvol0'.
Use 'help' for selection to get more help.
---
WHATS_NEW | 1 +
lib/report/report.c | 20 +++++++++++++++-----
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 7eac3a7..1bad12a 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.155 -
================================
+ Fix lvm devtypes internal error if -S used with field name from pvs/vgs/lvs.
When reporting Data%,Snap%,Meta%,Cpy%Sync use single ioctl per LV.
Add lvseg_percent_with_info_and_seg_status() for percent retrieval.
Enhance internal seg_status handling to understand snapshots better.
diff --git a/lib/report/report.c b/lib/report/report.c
index 56c6f5b..8e08c75 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -3689,7 +3689,9 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
int quoted, int columns_as_rows, const char *selection)
{
uint32_t report_flags = 0;
- int devtypes_report = *report_type & DEVTYPES ? 1 : 0;
+ const struct dm_report_object_type *types;
+ const struct dm_report_field_type *fields;
+ const struct dm_report_reserved_value *reserved_values;
void *rh;
if (aligned)
@@ -3710,11 +3712,19 @@ void *report_init(struct cmd_context *cmd, const char *format, const char *keys,
if (columns_as_rows)
report_flags |= DM_REPORT_OUTPUT_COLUMNS_AS_ROWS;
- rh = dm_report_init_with_selection(report_type,
- devtypes_report ? _devtypes_report_types : _report_types,
- devtypes_report ? _devtypes_fields : _fields,
+ if (*report_type & DEVTYPES) {
+ types = _devtypes_report_types;
+ fields = _devtypes_fields;
+ reserved_values = NULL;
+ } else {
+ types = _report_types;
+ fields = _fields;
+ reserved_values = _report_reserved_values;
+ }
+
+ rh = dm_report_init_with_selection(report_type, types, fields,
format, separator, report_flags, keys,
- selection, _report_reserved_values, cmd);
+ selection, reserved_values, cmd);
if (rh && field_prefixes)
dm_report_set_output_field_name_prefix(rh, "lvm2_");
7 years, 6 months
master - toollib: simplify internal selection calls for non-reporting tools
by Peter Rajnoha
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=815f1ee26d5ee5...
Commit: 815f1ee26d5ee5c64493f83a78f8c074fc8c82d8
Parent: 7d4d0ff606a78909041c0b734a3ceacc94a47fa0
Author: Peter Rajnoha <prajnoha(a)redhat.com>
AuthorDate: Mon May 30 16:28:47 2016 +0200
Committer: Peter Rajnoha <prajnoha(a)redhat.com>
CommitterDate: Mon May 30 16:44:18 2016 +0200
toollib: simplify internal selection calls for non-reporting tools
Some of the variables were set superfluously - we can just use existing
"struct processing_handle" which includes "struct selection_handle".
---
lib/report/report.h | 3 +-
tools/reporter.c | 3 +-
tools/toollib.c | 70 +++++++++++++++++++-------------------------------
tools/toollib.h | 6 ++--
4 files changed, 34 insertions(+), 48 deletions(-)
diff --git a/lib/report/report.h b/lib/report/report.h
index 088a1ca..8db84e0 100644
--- a/lib/report/report.h
+++ b/lib/report/report.h
@@ -60,6 +60,7 @@ struct selection_handle {
struct field;
struct report_handle;
+struct processing_handle;
typedef int (*field_report_fn) (struct report_handle * dh, struct field * field,
const void *data);
@@ -72,7 +73,7 @@ void *report_init_for_selection(struct cmd_context *cmd, report_type_t *report_t
const char *selection);
const char *report_get_field_prefix(report_type_t report_type);
int report_for_selection(struct cmd_context *cmd,
- struct selection_handle *sh,
+ struct processing_handle *parent_handle,
struct physical_volume *pv,
struct volume_group *vg,
struct logical_volume *lv);
diff --git a/tools/reporter.c b/tools/reporter.c
index bd77513..f572d31 100644
--- a/tools/reporter.c
+++ b/tools/reporter.c
@@ -549,11 +549,12 @@ static int _report_all_in_pv(struct cmd_context *cmd, struct processing_handle *
}
int report_for_selection(struct cmd_context *cmd,
- struct selection_handle *sh,
+ struct processing_handle *parent_handle,
struct physical_volume *pv,
struct volume_group *vg,
struct logical_volume *lv)
{
+ struct selection_handle *sh = parent_handle->selection_handle;
int args_are_pvs = sh->orig_report_type == PVS;
int do_lv_info, do_lv_seg_status;
struct processing_handle *handle;
diff --git a/tools/toollib.c b/tools/toollib.c
index 2f03a91..b86b8ff 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1764,74 +1764,61 @@ void destroy_processing_handle(struct cmd_context *cmd, struct processing_handle
int select_match_vg(struct cmd_context *cmd, struct processing_handle *handle,
- struct volume_group *vg, int *selected)
+ struct volume_group *vg)
{
- struct selection_handle *sh = handle->selection_handle;
-
- if (!handle->internal_report_for_select) {
- *selected = 1;
+ if (!handle->internal_report_for_select)
return 1;
- }
- sh->orig_report_type = VGS;
-
- if (!report_for_selection(cmd, sh, NULL, vg, NULL)) {
+ handle->selection_handle->orig_report_type = VGS;
+ if (!report_for_selection(cmd, handle, NULL, vg, NULL)) {
log_error("Selection failed for VG %s.", vg->name);
return 0;
}
-
- sh->orig_report_type = 0;
- *selected = sh->selected;
+ handle->selection_handle->orig_report_type = 0;
return 1;
}
int select_match_lv(struct cmd_context *cmd, struct processing_handle *handle,
- struct volume_group *vg, struct logical_volume *lv, int *selected)
+ struct volume_group *vg, struct logical_volume *lv)
{
- struct selection_handle *sh = handle->selection_handle;
-
- if (!handle->internal_report_for_select) {
- *selected = 1;
+ if (!handle->internal_report_for_select)
return 1;
- }
- sh->orig_report_type = LVS;
-
- if (!report_for_selection(cmd, sh, NULL, vg, lv)) {
+ handle->selection_handle->orig_report_type = LVS;
+ if (!report_for_selection(cmd, handle, NULL, vg, lv)) {
log_error("Selection failed for LV %s.", lv->name);
return 0;
}
-
- sh->orig_report_type = 0;
- *selected = sh->selected;
+ handle->selection_handle->orig_report_type = 0;
return 1;
}
int select_match_pv(struct cmd_context *cmd, struct processing_handle *handle,
- struct volume_group *vg, struct physical_volume *pv, int *selected)
+ struct volume_group *vg, struct physical_volume *pv)
{
- struct selection_handle *sh = handle->selection_handle;
-
- if (!handle->internal_report_for_select) {
- *selected = 1;
+ if (!handle->internal_report_for_select)
return 1;
- }
- sh->orig_report_type = PVS;
-
- if (!report_for_selection(cmd, sh, pv, vg, NULL)) {
+ handle->selection_handle->orig_report_type = PVS;
+ if (!report_for_selection(cmd, handle, pv, vg, NULL)) {
log_error("Selection failed for PV %s.", dev_name(pv->dev));
return 0;
}
-
- sh->orig_report_type = 0;
- *selected = sh->selected;
+ handle->selection_handle->orig_report_type = 0;
return 1;
}
+static int _select_matches(struct processing_handle *handle)
+{
+ if (!handle->internal_report_for_select)
+ return 1;
+
+ return handle->selection_handle->selected;
+}
+
static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
struct dm_list *vgnameids_to_process,
struct dm_list *arg_vgnames,
@@ -1845,7 +1832,6 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
const char *vg_name;
const char *vg_uuid;
uint32_t lockd_state = 0;
- int selected;
int whole_selected = 0;
int ret_max = ECMD_PROCESSED;
int ret;
@@ -1897,7 +1883,7 @@ static int _process_vgnameid_list(struct cmd_context *cmd, uint32_t read_flags,
if ((process_all ||
(!dm_list_empty(arg_vgnames) && str_list_match_item(arg_vgnames, vg_name)) ||
(!dm_list_empty(arg_tags) && str_list_match_list(arg_tags, &vg->tags, NULL))) &&
- select_match_vg(cmd, handle, vg, &selected) && selected) {
+ select_match_vg(cmd, handle, vg) && _select_matches(handle)) {
log_very_verbose("Process single VG %s", vg_name);
@@ -2264,7 +2250,6 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
{
int ret_max = ECMD_PROCESSED;
int ret = 0;
- int selected;
int whole_selected = 0;
int handle_supplied = handle != NULL;
unsigned process_lv;
@@ -2369,7 +2354,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
if (!process_lv && tags_supplied && str_list_match_list(tags_in, &lvl->lv->tags, NULL))
process_lv = 1;
- process_lv = process_lv && select_match_lv(cmd, handle, vg, lvl->lv, &selected) && selected;
+ process_lv = process_lv && select_match_lv(cmd, handle, vg, lvl->lv) && _select_matches(handle);
if (sigint_caught()) {
ret_max = ECMD_FAILED;
@@ -2432,7 +2417,7 @@ int process_each_lv_in_vg(struct cmd_context *cmd, struct volume_group *vg,
process_lv = 1;
}
- process_lv = process_lv && select_match_lv(cmd, handle, vg, lvl->lv, &selected) && selected;
+ process_lv = process_lv && select_match_lv(cmd, handle, vg, lvl->lv) && _select_matches(handle);
if (sigint_caught()) {
ret_max = ECMD_FAILED;
@@ -3164,7 +3149,6 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
struct pv_list *pvl;
struct device_id_list *dil;
const char *pv_name;
- int selected;
int process_pv;
int ret_max = ECMD_PROCESSED;
int ret = 0;
@@ -3203,7 +3187,7 @@ static int _process_pvs_in_vg(struct cmd_context *cmd,
str_list_match_list(arg_tags, &pv->tags, NULL))
process_pv = 1;
- process_pv = process_pv && select_match_pv(cmd, handle, vg, pv, &selected) && selected;
+ process_pv = process_pv && select_match_pv(cmd, handle, vg, pv) && _select_matches(handle);
if (process_pv) {
if (skip)
diff --git a/tools/toollib.h b/tools/toollib.h
index a366e68..06d0ef9 100644
--- a/tools/toollib.h
+++ b/tools/toollib.h
@@ -147,11 +147,11 @@ int init_selection_handle(struct cmd_context *cmd, struct processing_handle *han
void destroy_processing_handle(struct cmd_context *cmd, struct processing_handle *handle);
int select_match_vg(struct cmd_context *cmd, struct processing_handle *handle,
- struct volume_group *vg, int *selected);
+ struct volume_group *vg);
int select_match_lv(struct cmd_context *cmd, struct processing_handle *handle,
- struct volume_group *vg, struct logical_volume *lv, int *selected);
+ struct volume_group *vg, struct logical_volume *lv);
int select_match_pv(struct cmd_context *cmd, struct processing_handle *handle,
- struct volume_group *vg, struct physical_volume *pv, int *selected);
+ struct volume_group *vg, struct physical_volume *pv);
const char *extract_vgname(struct cmd_context *cmd, const char *lv_name);
const char *skip_dev_dir(struct cmd_context *cmd, const char *vg_name,
7 years, 6 months
master - tests: check thin is not flushed for status
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=7d4d0ff606a789...
Commit: 7d4d0ff606a78909041c0b734a3ceacc94a47fa0
Parent: 88eeb004e9d34635221d45619723518a71ac2ccc
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri May 27 17:24:18 2016 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri May 27 17:25:52 2016 +0200
tests: check thin is not flushed for status
We finally approach a moment where we generally avoid
flushing thin-pool with every lvs command...
---
test/shell/thin-flags.sh | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/test/shell/thin-flags.sh b/test/shell/thin-flags.sh
index 966752a..3fcafb2 100644
--- a/test/shell/thin-flags.sh
+++ b/test/shell/thin-flags.sh
@@ -52,6 +52,10 @@ lvcreate -T -L1M --errorwhenfull y $vg/pool
lvcreate -V2 -n $lv2 $vg/pool
aux error_dev "$dev2" 2054:2
+# Check our 'lvs' is not flushing pool - should be still OK
+check lv_attr_bit health $vg/pool "-"
+# Enforce flush on thin pool device to notice error device.
+dmsetup status $vg-pool-tpool
check lv_attr_bit health $vg/pool "F"
check lv_attr_bit health $vg/$lv2 "F"
aux enable_dev "$dev2"
7 years, 6 months
master - snapshot: for invalid snapshot show 100%
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=88eeb004e9d346...
Commit: 88eeb004e9d34635221d45619723518a71ac2ccc
Parent: 43dfc2011c8955550e9e7b2fe0de78b452921326
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri May 27 17:16:14 2016 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Fri May 27 17:25:37 2016 +0200
snapshot: for invalid snapshot show 100%
Recent commit 92eba53a797a011d1ce6fbd7bef88eab41af2072 started to report
empty "" data usage of invalid snapshot, restore 100% to be shown.
---
lib/metadata/lv.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/lib/metadata/lv.c b/lib/metadata/lv.c
index d67caa2..06f47f4 100644
--- a/lib/metadata/lv.c
+++ b/lib/metadata/lv.c
@@ -380,8 +380,10 @@ dm_percent_t lvseg_percent_with_info_and_seg_status(const struct lv_with_info_an
}
break;
case SEG_STATUS_SNAPSHOT:
- if (s->snapshot->invalid || s->snapshot->merge_failed)
+ if (s->snapshot->merge_failed)
p = DM_PERCENT_INVALID;
+ else if (s->snapshot->invalid)
+ p = DM_PERCENT_100; /* Shown as 100% full */
else if (s->snapshot->has_metadata_sectors &&
(s->snapshot->used_sectors == s->snapshot->metadata_sectors))
p = DM_PERCENT_0;
7 years, 6 months