master - debug: enhance messages
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=5555765cfc71a87eadc...
Commit: 5555765cfc71a87eadcb1f6ac9bdd41f2e3c9052
Parent: cff16b062badbc65661940b021c06d3b1c423562
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Nov 28 13:19:44 2019 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Dec 10 15:44:16 2019 +0100
debug: enhance messages
Drop 'extra' stack trace where errors are already logged from function.
Add some missing dots in messages.
---
lib/metadata/metadata.c | 40 ++++++++++++++++++++--------------------
1 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 1371b97..5856a92 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -4905,7 +4905,7 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
}
if (found_old_metadata)
- log_warn("WARNING: Inconsistent metadata found for VG %s", vgname);
+ log_warn("WARNING: Inconsistent metadata found for VG %s.", vgname);
vg = NULL;
@@ -4936,13 +4936,13 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
if (!(dev->flags & DEV_IS_MD_COMPONENT))
continue;
- log_debug_metadata("Drop dev for MD component from cache %s", dev_name(dev));
+ log_debug_metadata("Drop dev for MD component from cache %s.", dev_name(dev));
lvmcache_del_dev(dev);
dm_list_iterate_items(mda, &fid->metadata_areas_in_use) {
if (mda_get_device(mda) != dev)
continue;
- log_debug_metadata("Drop mda from MD component from mda list %s", dev_name(dev));
+ log_debug_metadata("Drop mda from MD component from mda list %s.", dev_name(dev));
dm_list_del(&mda->list);
break;
}
@@ -5010,7 +5010,7 @@ struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name, const
int activating = (vg_read_flags & READ_FOR_ACTIVATE);
if (is_orphan_vg(vg_name)) {
- log_very_verbose("Reading orphan VG %s", vg_name);
+ log_very_verbose("Reading orphan VG %s.", vg_name);
vg = vg_read_orphans(cmd, vg_name);
*error_flags = 0;
*error_vg = NULL;
@@ -5020,7 +5020,7 @@ struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name, const
if (!validate_name(vg_name)) {
log_error("Volume group name \"%s\" has invalid characters.", vg_name);
failure |= FAILED_NOTFOUND;
- goto_bad;
+ goto bad;
}
/*
@@ -5035,15 +5035,15 @@ struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name, const
if (!(vg_read_flags & READ_WITHOUT_LOCK) &&
!lock_vol(cmd, vg_name, (writing || activating) ? LCK_VG_WRITE : LCK_VG_READ, NULL)) {
- log_error("Can't get lock for %s", vg_name);
+ log_error("Can't get lock for %s.", vg_name);
failure |= FAILED_LOCKING;
- goto_bad;
+ goto bad;
}
if (!(vg = _vg_read(cmd, vg_name, vgid, 0, writing))) {
/* Some callers don't care if the VG doesn't exist and don't want an error message. */
if (!(vg_read_flags & READ_OK_NOTFOUND))
- log_error("Volume group \"%s\" not found", vg_name);
+ log_error("Volume group \"%s\" not found.", vg_name);
failure |= FAILED_NOTFOUND;
goto_bad;
}
@@ -5114,14 +5114,14 @@ struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name, const
if (!check_pv_segments(vg)) {
log_error(INTERNAL_ERROR "PV segments corrupted in %s.", vg->name);
failure |= FAILED_INTERNAL_ERROR;
- goto_bad;
+ goto bad;
}
dm_list_iterate_items(lvl, &vg->lvs) {
if (!check_lv_segments(lvl->lv, 0)) {
log_error(INTERNAL_ERROR "LV segments corrupted in %s.", lvl->lv->name);
failure |= FAILED_INTERNAL_ERROR;
- goto_bad;
+ goto bad;
}
}
@@ -5130,7 +5130,7 @@ struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name, const
if (!check_lv_segments(lvl->lv, 1)) {
log_error(INTERNAL_ERROR "LV segments corrupted in %s.", lvl->lv->name);
failure |= FAILED_INTERNAL_ERROR;
- goto_bad;
+ goto bad;
}
}
@@ -5166,23 +5166,23 @@ struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name, const
*/
if (writing || activating) {
if (!(vg->status & LVM_WRITE)) {
- log_error("Volume group %s is read-only", vg->name);
+ log_error("Volume group %s is read-only.", vg->name);
failure |= FAILED_READ_ONLY;
- goto_bad;
+ goto bad;
}
if (!cmd->handles_missing_pvs && (missing_pv_dev || missing_pv_flag)) {
log_error("Cannot change VG %s while PVs are missing.", vg->name);
log_error("See vgreduce --removemissing and vgextend --restoremissing.");
failure |= FAILED_NOT_ENABLED;
- goto_bad;
+ goto bad;
}
}
if (writing && !cmd->handles_unknown_segments && vg_has_unknown_segments(vg)) {
log_error("Cannot change VG %s with unknown segments in it!", vg->name);
failure |= FAILED_NOT_ENABLED; /* FIXME new failure code here? */
- goto_bad;
+ goto bad;
}
/*
@@ -5197,31 +5197,31 @@ struct volume_group *vg_read(struct cmd_context *cmd, const char *vg_name, const
if (dm_pool_locked(vg->vgmem)) {
/* FIXME: can this happen? */
- log_warn("WARNING: vg_read no vg copy: pool locked");
+ log_warn("WARNING: vg_read no vg copy: pool locked.");
goto out;
}
if (vg->vg_committed) {
/* FIXME: can this happen? */
- log_warn("WARNING: vg_read no vg copy: copy exists");
+ log_warn("WARNING: vg_read no vg copy: copy exists.");
release_vg(vg->vg_committed);
vg->vg_committed = NULL;
}
if (vg->vg_precommitted) {
/* FIXME: can this happen? */
- log_warn("WARNING: vg_read no vg copy: pre copy exists");
+ log_warn("WARNING: vg_read no vg copy: pre copy exists.");
release_vg(vg->vg_precommitted);
vg->vg_precommitted = NULL;
}
if (!(cft = export_vg_to_config_tree(vg))) {
- log_warn("WARNING: vg_read no vg copy: copy export failed");
+ log_warn("WARNING: vg_read no vg copy: copy export failed.");
goto out;
}
if (!(vg->vg_committed = import_vg_from_config_tree(cmd, vg->fid, cft)))
- log_warn("WARNING: vg_read no vg copy: copy import failed");
+ log_warn("WARNING: vg_read no vg copy: copy import failed.");
dm_config_destroy(cft);
} else {
4 years, 4 months
master - debug: avoid to slashes in debug message
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=cff16b062badbc65661...
Commit: cff16b062badbc65661940b021c06d3b1c423562
Parent: e70d5d470c196f81c125c2705c065302608dbfbe
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Oct 24 16:36:01 2019 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Dec 10 15:44:16 2019 +0100
debug: avoid to slashes in debug message
---
lib/device/dev-cache.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index 3dcfc10..e17b13f 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -1522,7 +1522,7 @@ struct device *dev_cache_get_by_devt(struct cmd_context *cmd, dev_t dev, struct
sysfs_dir = dm_sysfs_dir();
if (sysfs_dir && *sysfs_dir) {
/* First check if dev is sysfs to avoid useless scan */
- if (dm_snprintf(path, sizeof(path), "%s/dev/block/%d:%d",
+ if (dm_snprintf(path, sizeof(path), "%sdev/block/%d:%d",
sysfs_dir, (int)MAJOR(dev), (int)MINOR(dev)) < 0) {
log_error("dm_snprintf partition failed.");
return NULL;
4 years, 4 months
master - debug: print VG name in log messages for segment errors
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e70d5d470c196f81c12...
Commit: e70d5d470c196f81c125c2705c065302608dbfbe
Parent: 4353823306800fda4184a4a4278d036ca345993b
Author: Nikhil Kshirsagar <nkshirsa(a)redhat.com>
AuthorDate: Tue Nov 26 12:36:45 2019 +0530
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Dec 10 15:44:06 2019 +0100
debug: print VG name in log messages for segment errors
Signed-off-by: Nikhil Kshirsagar <nkshirsa(a)redhat.com>
---
lib/metadata/merge.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/metadata/merge.c b/lib/metadata/merge.c
index e482921..11b26b4 100644
--- a/lib/metadata/merge.c
+++ b/lib/metadata/merge.c
@@ -73,7 +73,7 @@ int lv_merge_segments(struct logical_volume *lv)
#define seg_error(msg) do { \
log_error("LV %s, segment %u invalid: %s for %s segment.", \
- seg->lv->name, seg_count, (msg), lvseg_name(seg)); \
+ display_lvname(seg->lv), seg_count, (msg), lvseg_name(seg)); \
if ((*error_count)++ > ERROR_MAX) \
return; \
} while (0)
@@ -86,14 +86,14 @@ int lv_merge_segments(struct logical_volume *lv)
*/
#define raid_seg_error(msg) do { \
log_error("LV %s invalid: %s for %s segment", \
- seg->lv->name, (msg), lvseg_name(seg)); \
+ display_lvname(seg->lv), (msg), lvseg_name(seg)); \
if ((*error_count)++ > ERROR_MAX) \
return; \
} while (0)
#define raid_seg_error_val(msg, val) do { \
log_error("LV %s invalid: %s (is %u) for %s segment", \
- seg->lv->name, (msg), (val), lvseg_name(seg)); \
+ display_lvname(seg->lv), (msg), (val), lvseg_name(seg)); \
if ((*error_count)++ > ERROR_MAX) \
return; \
} while(0)
4 years, 4 months
master - libdm: set maj:min while creating and reloading device
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=4353823306800fda418...
Commit: 4353823306800fda4184a4a4278d036ca345993b
Parent: df0bc5081c1b84c2ae7c8d8dc92305f90f161683
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Dec 10 13:28:44 2019 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Dec 10 15:42:59 2019 +0100
libdm: set maj:min while creating and reloading device
Add maj:min to the task structure for RELOAD - which is now
handled in _flatten() and will just skip passing device name.
---
libdm/ioctl/libdm-iface.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c
index ae44abf..7ad549c 100644
--- a/libdm/ioctl/libdm-iface.c
+++ b/libdm/ioctl/libdm-iface.c
@@ -1429,6 +1429,7 @@ static int _check_uevent_generated(struct dm_ioctl *dmi)
static int _create_and_load_v4(struct dm_task *dmt)
{
+ struct dm_info info;
struct dm_task *task;
int r;
uint32_t cookie;
@@ -1459,6 +1460,9 @@ static int _create_and_load_v4(struct dm_task *dmt)
if (!dm_task_run(task))
goto_bad;
+ if (!dm_task_get_info(task, &info) || !info.exists)
+ goto_bad;
+
dm_task_destroy(task);
/* Next load the table */
@@ -1476,6 +1480,8 @@ static int _create_and_load_v4(struct dm_task *dmt)
goto revert;
}
+ task->major = info.major;
+ task->minor = info.minor;
task->read_only = dmt->read_only;
task->head = dmt->head;
task->tail = dmt->tail;
4 years, 4 months
master - libdm: support device RELOAD with maj:min and devname set
by Zdenek Kabelac
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=df0bc5081c1b84c2ae7...
Commit: df0bc5081c1b84c2ae7c8d8dc92305f90f161683
Parent: 338f4df54ba19244c4cf51c9ad6461ef5613ed5f
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Dec 10 13:28:16 2019 +0100
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Dec 10 15:42:59 2019 +0100
libdm: support device RELOAD with maj:min and devname set
When devices are created - we were not giving meaning error messages
when the failure happened on 'reload' part of creation.
With this patch we are now able to report both name and major:minor.
Enhancment is most visible with 'crypto' devices,
which are using 'secure' memory erase bit.
---
WHATS_NEW_DM | 1 +
libdm/ioctl/libdm-iface.c | 14 ++++++++++----
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index b64a9a2..a1e233e 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.169 -
=====================================
+ Enhance error messages for device creation.
Version 1.02.167 - 30th November 2019
=====================================
diff --git a/libdm/ioctl/libdm-iface.c b/libdm/ioctl/libdm-iface.c
index dd46b67..ae44abf 100644
--- a/libdm/ioctl/libdm-iface.c
+++ b/libdm/ioctl/libdm-iface.c
@@ -1238,8 +1238,12 @@ static struct dm_ioctl *_flatten(struct dm_task *dmt, unsigned repeat_count)
}
/* FIXME Until resume ioctl supplies name, use dev_name for readahead */
- if (DEV_NAME(dmt) && (dmt->type != DM_DEVICE_RESUME || dmt->minor < 0 ||
- dmt->major < 0))
+ if (DEV_NAME(dmt) &&
+ (((dmt->type != DM_DEVICE_RESUME) &&
+ (dmt->type != DM_DEVICE_RELOAD)) ||
+ (dmt->minor < 0) || (dmt->major < 0)))
+ /* When RESUME or RELOAD sets maj:min and dev_name, use just maj:min,
+ * passed dev_name is useful for better error/debug messages */
strncpy(dmi->name, DEV_NAME(dmt), sizeof(dmi->name));
if (DEV_UUID(dmt))
@@ -1904,7 +1908,8 @@ static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command,
log_verbose("device-mapper: %s ioctl on %s %s%s%.0d%s%.0d%s%s "
"failed: %s",
_cmd_data_v4[dmt->type].name,
- dmi->name, dmi->uuid,
+ dmi->name[0] ? dmi->name : DEV_NAME(dmt) ? : "",
+ dmi->uuid[0] ? dmi->uuid : DEV_UUID(dmt) ? : "",
dmt->major > 0 ? "(" : "",
dmt->major > 0 ? dmt->major : 0,
dmt->major > 0 ? ":" : "",
@@ -1916,7 +1921,8 @@ static struct dm_ioctl *_do_dm_ioctl(struct dm_task *dmt, unsigned command,
log_error("device-mapper: %s ioctl on %s %s%s%.0d%s%.0d%s%s "
"failed: %s",
_cmd_data_v4[dmt->type].name,
- dmi->name, dmi->uuid,
+ dmi->name[0] ? dmi->name : DEV_NAME(dmt) ? : "",
+ dmi->uuid[0] ? dmi->uuid : DEV_UUID(dmt) ? : "",
dmt->major > 0 ? "(" : "",
dmt->major > 0 ? dmt->major : 0,
dmt->major > 0 ? ":" : "",
4 years, 4 months
master - man pvck: describe settings
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=338f4df54ba19244c4c...
Commit: 338f4df54ba19244c4cf51c9ad6461ef5613ed5f
Parent: 3f381784f2726edda1ebfe806ba7d0b0dee33cdb
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri Dec 6 16:21:48 2019 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Dec 6 16:24:27 2019 -0600
man pvck: describe settings
---
man/pvck.8_des | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/man/pvck.8_des b/man/pvck.8_des
index 2169d73..8e81493 100644
--- a/man/pvck.8_des
+++ b/man/pvck.8_des
@@ -81,3 +81,49 @@ correct (having been undamaged or already repaired).
Repairs label_header fields, leaving the pv_header (in the same sector)
unchanged. (repairtype pv_header should usually be used instead.)
+.SS Settings
+
+The --settings option controls or overrides certain dump or repair
+behaviors. All offset and size values in settings are in bytes (units are
+not recognized.) These settings are subject to change.
+
+.B mda_num=1|2
+.br
+Select which metadata area should be used. By default the first metadata
+area (1) is used. mda1 is always located at offset 4096. mda2, at the
+end of the device, often does not exist (it's not created by default.) If
+mda1 is erased, mda2, if it exists, will often still have metadata.
+
+\fBmetadata_offset=\fP\fIbytes\fP
+.br
+Select metadata text at this offset. Use with metadata_search to
+print/save one instance of metadata text.
+
+\fBmda_offset=\fP\fIbytes\fP \fBmda_size=\fP\fIbytes\fP
+.br
+Refers to a metadata area (mda) location and size. An mda includes an
+mda_header and circular text buffer. Setting this forces metadata_search
+look for metadata in the given area instead of the normal locations. When
+set to zero with repair, it indicates no metadata areas should exist.
+
+\fBmda2_offset=\fP\fIbytes\fP \fBmda2_size=\fP\fIbytes\fP
+.br
+When repairing a pv_header, this forces a specific offset and size for
+mda2 that should be recorded in the pv_header.
+
+\fBpv_uuid=\fP\fIuuid\fP
+.br
+Specify the PV UUID of the device being repaired. When not specified,
+repair will attempt to determine the correct PV UUID by matching a device
+name in the metadata.
+
+\fBdevice_size=\fP\fIbytes\fP
+.br
+\fBdata_offset=\fP\fIbytes\fP
+.br
+When repairing a pv_header, the device_size, data_offset, and pvid can all
+be specified directly, in which case these values are not taken from a
+metadata file (where they usually come from), and the metadata file can be
+omitted. data_offset is the starting location of the first physical
+extent (data), which follows the first metadata area.
+
4 years, 4 months
master - update option description for settings
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=3f381784f2726edda1e...
Commit: 3f381784f2726edda1ebfe806ba7d0b0dee33cdb
Parent: ec71df6fec481b688a7c4db3171a451c18dbdc52
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri Dec 6 16:21:26 2019 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Dec 6 16:21:26 2019 -0600
update option description for settings
---
tools/args.h | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/tools/args.h b/tools/args.h
index 533cc54..e0bd42a 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -463,7 +463,8 @@ arg(setphysicalvolumesize_ARG, '\0', "setphysicalvolumesize", sizemb_VAL, 0, 0,
arg(settings_ARG, '\0', "settings", string_VAL, ARG_GROUPABLE, 0,
"Specifies command specific settings in \"Key = Value\" form.\n"
- "Repeat this option to specify multiple values.\n")
+ "Combine multiple settings in quotes, or repeat the settings\n"
+ "option for each.\n")
arg(poll_ARG, '\0', "poll", bool_VAL, 0, 0,
"When yes, start the background transformation of an LV.\n"
4 years, 4 months
master - pvck: deal with coverity warnings
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ec71df6fec481b688a7...
Commit: ec71df6fec481b688a7c4db3171a451c18dbdc52
Parent: 91f91b80f1c0879b48b683cc762512c0c980cb7c
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Dec 2 11:16:02 2019 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Mon Dec 2 11:16:02 2019 -0600
pvck: deal with coverity warnings
---
tools/pvck.c | 98 +++++++++++++++++++++++++++++++++------------------------
1 files changed, 57 insertions(+), 41 deletions(-)
diff --git a/tools/pvck.c b/tools/pvck.c
index 4eaf8b4..0266218 100644
--- a/tools/pvck.c
+++ b/tools/pvck.c
@@ -304,7 +304,7 @@ static int _dump_all_text(struct cmd_context *cmd, struct settings *set, const c
char vgname[NAME_LEN+1];
char id_str[ID_STR_SIZE];
char id_first[ID_STR_SIZE];
- char *text_buf;
+ char *text_buf = NULL;
char *p;
uint32_t buf_off; /* offset with buf which begins with mda_header, bytes */
uint32_t buf_off_first = 0;
@@ -1488,7 +1488,8 @@ static int _dump_search(struct cmd_context *cmd, const char *dump, struct settin
mda_offset = dev_bytes - extra_bytes - ONE_MB_IN_BYTES;
mda_size = dev_bytes - mda_offset;
- }
+ } else
+ return_0;
if ((mda_num == 1) && (mda1_offset != mda_offset)) {
log_print("Ignoring mda1_offset %llu mda1_size %llu from pv_header.",
@@ -1999,7 +2000,7 @@ static int _repair_pv_header(struct cmd_context *cmd, const char *repair,
uint64_t pe_start_sectors; /* in sectors, as stored in metadata */
uint64_t data_offset; /* in bytes, as stored in pv_header */
uint32_t head_crc;
- int mda_count;
+ int mda_count = 0;
int found_label = 0;
int di;
@@ -2460,7 +2461,7 @@ static int _backup_file_to_raw_metadata(char *back_buf, uint64_t back_size,
char line[MAX_META_LINE];
char line2[MAX_META_LINE];
char *p, *text_buf;
- uint32_t text_pos, pre_len, back_pos, text_max;
+ uint32_t text_pos, pre_len = 0, back_pos, text_max;
int len, len2, vgnamelen;
text_max = back_size * 2;
@@ -2514,8 +2515,10 @@ static int _backup_file_to_raw_metadata(char *back_buf, uint64_t back_size,
back_pos += len;
/* shouldn't happen */
- if (text_pos + len > text_max)
+ if (text_pos + len > text_max) {
+ free(text_buf);
return_0;
+ }
if (len == 1) {
text_buf[text_pos++] = '\n';
@@ -2529,12 +2532,16 @@ static int _backup_file_to_raw_metadata(char *back_buf, uint64_t back_size,
}
/* shouldn't happen */
- if (text_pos + pre_len + 3 > text_max)
+ if (text_pos + pre_len + 3 > text_max) {
+ free(text_buf);
return_0;
+ }
- /* copy first pre_len bytes of back_buf into text_buf */
- memcpy(text_buf + text_pos, back_buf, pre_len);
- text_pos += pre_len;
+ if (pre_len) {
+ /* copy first pre_len bytes of back_buf into text_buf */
+ memcpy(text_buf + text_pos, back_buf, pre_len);
+ text_pos += pre_len;
+ }
text_pos++; /* null termination */
@@ -2560,7 +2567,7 @@ static int _dump_backup_to_raw(struct cmd_context *cmd, struct settings *set)
struct stat sb;
char *back_buf, *text_buf;
uint64_t back_size, text_size;
- int fd, rv;
+ int fd, rv, ret;
if (arg_is_set(cmd, file_ARG)) {
if (!(tofile = arg_str_value(cmd, file_ARG, NULL)))
@@ -2572,37 +2579,33 @@ static int _dump_backup_to_raw(struct cmd_context *cmd, struct settings *set)
return 0;
}
- if (!(fd = open(input, O_RDONLY))) {
+ if ((fd = open(input, O_RDONLY)) < 0) {
log_error("Cannot open file: %s", input);
return 0;
}
if (fstat(fd, &sb)) {
log_error("Cannot access file: %s", input);
- close(fd);
- return 0;
+ goto fail_close;
}
if (!(back_size = (uint64_t)sb.st_size)) {
log_error("Empty file: %s", input);
- close(fd);
- return 0;
+ goto fail_close;
}
- if (!(back_buf = zalloc(back_size))) {
- close(fd);
- return 0;
- }
+ if (!(back_buf = zalloc(back_size)))
+ goto fail_close;
rv = read(fd, back_buf, back_size);
if (rv != back_size) {
log_error("Cannot read file: %s", input);
- close(fd);
free(back_buf);
- return 0;
+ goto fail_close;
}
- close(fd);
+ if (close(fd))
+ stack;
if (!_is_backup_file(cmd, back_buf, back_size)) {
log_error("File does not appear to contain a metadata backup.");
@@ -2615,8 +2618,6 @@ static int _dump_backup_to_raw(struct cmd_context *cmd, struct settings *set)
return_0;
}
- free(back_buf);
-
if (!tofile) {
log_print("---");
printf("%s\n", text_buf);
@@ -2625,7 +2626,8 @@ static int _dump_backup_to_raw(struct cmd_context *cmd, struct settings *set)
FILE *fp;
if (!(fp = fopen(tofile, "wx"))) {
log_error("Failed to create file %s", tofile);
- return 0;
+ ret = 0;
+ goto out;
}
fprintf(fp, "%s", text_buf);
@@ -2635,8 +2637,16 @@ static int _dump_backup_to_raw(struct cmd_context *cmd, struct settings *set)
if (fclose(fp))
stack;
}
+ ret = 1;
+out:
+ free(back_buf);
+ free(text_buf);
+ return ret;
- return 1;
+fail_close:
+ if (close(fd))
+ stack;
+ return 0;
}
/* all sizes and offsets in bytes */
@@ -2706,51 +2716,52 @@ static int _read_metadata_file(struct cmd_context *cmd, struct metadata_file *mf
uint32_t text_crc;
int fd, rv;
- if (!(fd = open(mf->filename, O_RDONLY))) {
+ if ((fd = open(mf->filename, O_RDONLY)) < 0) {
log_error("Cannot open file: %s", mf->filename);
return 0;
}
if (fstat(fd, &sb)) {
log_error("Cannot access file: %s", mf->filename);
- close(fd);
- return 0;
+ goto out;
}
if (!(text_size = (uint64_t)sb.st_size)) {
log_error("Empty file: %s", mf->filename);
- close(fd);
- return 0;
+ goto out;
}
- if (!(text_buf = zalloc(text_size + 1))) {
- close(fd);
- return 0;
- }
+ if (!(text_buf = zalloc(text_size + 1)))
+ goto_out;
rv = read(fd, text_buf, text_size);
if (rv != text_size) {
log_error("Cannot read file: %s", mf->filename);
- close(fd);
free(text_buf);
- return 0;
+ goto out;
}
text_size += 1; /* null terminating byte */
- close(fd);
+ if (close(fd))
+ stack;
if (_is_backup_file(cmd, text_buf, text_size)) {
char *back_buf = text_buf;
uint64_t back_size = text_size;
text_buf = NULL;
text_size = 0;
- if (!_backup_file_to_raw_metadata(back_buf, back_size, &text_buf, &text_size))
+ if (!_backup_file_to_raw_metadata(back_buf, back_size, &text_buf, &text_size)) {
+ free(back_buf);
return_0;
+ }
+ free(back_buf);
}
- if (!_check_metadata_file(cmd, mf, text_buf, text_size))
+ if (!_check_metadata_file(cmd, mf, text_buf, text_size)) {
+ free(text_buf);
return_0;
+ }
text_crc = calc_crc(INITIAL_CRC, (uint8_t *)text_buf, text_size);
@@ -2758,13 +2769,18 @@ static int _read_metadata_file(struct cmd_context *cmd, struct metadata_file *mf
mf->text_buf = text_buf;
mf->text_crc = text_crc;
return 1;
+
+out:
+ if (close(fd))
+ stack;
+ return 0;
}
int pvck(struct cmd_context *cmd, int argc, char **argv)
{
struct settings set;
struct metadata_file mf;
- struct device *dev;
+ struct device *dev = NULL;
const char *dump, *repair;
const char *pv_name;
uint64_t labelsector = 1;
4 years, 4 months