zdump/ngdump: Add error messages and debug trace logs

Add debug trace logs for ngdump_read_meta_from_device().

Signed-off-by: Mikhail Zaslonko <zaslonko@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Mikhail Zaslonko
2025-07-15 18:07:02 +02:00
committed by Jan Höppner
parent 650265e296
commit 6547d1ae4c
2 changed files with 22 additions and 4 deletions

View File

@@ -36,8 +36,10 @@ static int open_dump_file(void)
mount_point = util_strdup("/tmp/zdump-ngdump-XXXXXX");
/* Create a mount point directory */
if (mkdtemp(mount_point) == NULL)
if (mkdtemp(mount_point) == NULL) {
warnx("Could not create directory \"%s\"", mount_point);
goto fail_free;
}
if (mount(l.device, mount_point, NGDUMP_FSTYPE, MS_RDONLY, NULL)) {
warnx("Could not mount \"%s\" (%s)", l.device, strerror(errno));

View File

@@ -42,11 +42,19 @@ static int read_meta_from_file(const char *filename, struct ngdump_meta *meta)
FILE *fp = NULL;
char *line = NULL;
util_log_print(UTIL_LOG_TRACE,
"%s: Reading meta file \"%s\"\n",
__func__, filename);
memset(meta, 0, sizeof(*meta));
fp = fopen(filename, "r");
if (!fp)
if (!fp) {
util_log_print(UTIL_LOG_TRACE,
"%s: Could not open \"%s\" (%s)\n",
__func__, filename, strerror(errno));
return -1;
}
while (fscanf(fp, "%m[^\n]\n", &line) == 1) {
char *ptr, *param = NULL, *value = NULL;
@@ -154,8 +162,11 @@ static int validate_meta(const char *mount_point, struct ngdump_meta *meta)
* that the given partition is a valid NGDump partition but with no
* dump present.
*/
if (!meta->file)
if (!meta->file) {
util_log_print(UTIL_LOG_TRACE,
"%s: No dump file present\n", __func__);
return 0;
}
if (!meta->sha256sum) {
warnx("Invalid NGDump SHA256 checksum");
return -1;
@@ -189,13 +200,18 @@ int ngdump_read_meta_from_device(const char *device, struct ngdump_meta *meta)
/* Create a mount point directory */
if (mkdtemp(mount_point) == NULL) {
warnx("Could not create directory \"%s\"", mount_point);
rc = -1;
goto out;
}
rc = mount(device, mount_point, NGDUMP_FSTYPE, MS_RDONLY, NULL);
if (rc)
if (rc) {
util_log_print(UTIL_LOG_TRACE,
"%s: Could not mount \"%s\" (%s)\n",
__func__, device, strerror(errno));
goto out_rmdir;
}
util_asprintf(&filename, "%s/%s", mount_point, NGDUMP_META_FILENAME);