File diskdump-Always-allocate-a-flattened-offset-map.patch of Package libkdumpfile.36085
From: Petr Tesarik <petr@tesarici.cz>
Date: Thu, 26 Sep 2024 11:51:20 +0200
Subject: diskdump: Always allocate a flattened offset map
References: bsc#1223399
Upstream: merged
Git-commit: ddd6ddfdc91993eaa39fcd62c2bc568ac8ac01f0
Prepare to support a mix of flattened and rearranged files in a file set by
checking individual files in the set with flatmap_isflattened() instead of
the flatmap pointer.
This change also simplifies initialization, but the disk dump private data
is now always allocated (and freed), even if the dump file turns out to be
a different format. That should be a very minor regression, though.
Signed-off-by: Petr Tesarik <ptesarik@suse.com>
---
src/kdumpfile/diskdump.c | 32 +++++++++++++-------------------
src/kdumpfile/kdumpfile-priv.h | 10 ++++++++++
2 files changed, 23 insertions(+), 19 deletions(-)
--- a/src/kdumpfile/diskdump.c
+++ b/src/kdumpfile/diskdump.c
@@ -216,7 +216,7 @@ diskdump_pread(kdump_ctx_t *ctx, void *b
{
struct disk_dump_priv *ddp = ctx->shared->fmtdata;
- return ddp->flatmap
+ return flatmap_isflattened(ddp->flatmap)
? flatmap_pread(ddp->flatmap, buf, len, pos)
: fcache_pread(ctx->shared->fcache, buf, len, pos);
}
@@ -237,7 +237,7 @@ diskdump_get_chunk(kdump_ctx_t *ctx, str
{
struct disk_dump_priv *ddp = ctx->shared->fmtdata;
- return ddp->flatmap
+ return flatmap_isflattened(ddp->flatmap)
? flatmap_get_chunk(ddp->flatmap, fch, len, pos)
: fcache_get_chunk(ctx->shared->fcache, fch, len, pos);
}
@@ -899,8 +899,14 @@ init_private(kdump_ctx_t *ctx)
if (!ddp)
return set_error(ctx, KDUMP_ERR_SYSTEM,
"Cannot allocate diskdump private data");
-
ctx->shared->fmtdata = ddp;
+
+ ddp->flatmap = flatmap_alloc();
+ if (!ddp->flatmap)
+ return set_error(ctx, KDUMP_ERR_SYSTEM,
+ "Cannot allocate %s",
+ "flattened dump maps");
+
return KDUMP_OK;
}
@@ -977,6 +983,10 @@ diskdump_probe(kdump_ctx_t *ctx)
if (status != KDUMP_OK)
return set_error(ctx, status, "Cannot read dump header");
+ status = init_private(ctx);
+ if (status != KDUMP_OK)
+ return status;
+
if (!memcmp(hdr, magic_flattened, sizeof magic_flattened)) {
struct makedumpfile_header *flathdr =
(struct makedumpfile_header*) hdr;
@@ -991,17 +1001,7 @@ diskdump_probe(kdump_ctx_t *ctx)
"Unknown flattened %s: %" PRId64 "\n",
"version", be64toh(flathdr->version));
- status = init_private(ctx);
- if (status != KDUMP_OK)
- return status;
-
ddp = ctx->shared->fmtdata;
- ddp->flatmap = flatmap_alloc();
- if (!ddp->flatmap)
- return set_error(ctx, KDUMP_ERR_SYSTEM,
- "Cannot allocate %s",
- "flattened dump maps");
-
status = flatmap_init(ddp->flatmap, ctx);
if (status != KDUMP_OK)
return status;
@@ -1023,12 +1023,6 @@ diskdump_probe(kdump_ctx_t *ctx)
set_file_description(ctx, desc);
- if (!ctx->shared->fmtdata) {
- status = init_private(ctx);
- if (status != KDUMP_OK)
- return status;
- }
-
return open_common(ctx, hdr);
}
--- a/src/kdumpfile/kdumpfile-priv.h
+++ b/src/kdumpfile/kdumpfile-priv.h
@@ -1538,6 +1538,16 @@ INTERNAL_DECL(kdump_status, flatmap_get_
(struct flattened_map *map, struct fcache_chunk *fch,
size_t len, off_t pos));
+/** Check whether a given file in a set is flattened.
+ * @param map Flattened offset map.
+ * @returns @c true if file is flattened, @c false otherwise.
+ */
+static inline bool
+flatmap_isflattened(struct flattened_map *map)
+{
+ return map->fmap.map;
+}
+
/** Check if a character is a POSIX white space.
* @param c Character to check.
*