File s390-tools-sles11sp2-zfcpdump-hsa-attribute.patch of Package s390-tools
Subject: [PATCH] [BZ 88199] zfcpdump: Release HSA early if Linux kernel supports it
From: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Description: zfcpdump: Release HSA early if Linux kernel supports it
Symptom: Under LPAR the zfcpdump HSA is a shared resource. Up to now
the HSA memory is released when the zcore file is closed.
Problem: Dump programs that know that they do not need the HSA memory
any more (e.g. because they already dumped it) could release
it earlier. This would allow other LPARs to use it again.
Solution: With this patch zfcpdump releases the HSA after the area has
been dumped if the Linux kernel has support (hsa file) for
that operation.
Reproduction: Trigger two parallel zfcpdumps on two LPARs on the same CEC.
Upstream-ID: -
Problem-ID: 88199
Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
---
zfcpdump_v2/zfcpdump.c | 34 ++++++++++++++++++++++++++++++++--
zfcpdump_v2/zfcpdump.h | 1 +
2 files changed, 33 insertions(+), 2 deletions(-)
--- a/zfcpdump_v2/zfcpdump.c
+++ b/zfcpdump_v2/zfcpdump.c
@@ -222,6 +222,7 @@ static int write_to_file(const char *fil
static int read_file(const char *file, char *buf, int size)
{
+ ssize_t count;
int fh;
PRINT_TRACE("Read: %s:\n", file);
@@ -230,11 +231,13 @@ static int read_file(const char *file, c
PRINT_PERR("open %s failed\n", file);
return -1;
}
- if (read(fh, buf, size) < 0) {
+ count = read(fh, buf, size - 1);
+ if (count < 0) {
PRINT_PERR("read %s failed\n", file);
close(fh);
return -1;
}
+ buf[count] = 0;
if (buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = 0; /* strip newline */
close(fh);
@@ -244,6 +247,26 @@ static int read_file(const char *file, c
}
/*
+ * Get HSA size
+ */
+static __u64 get_hsa_size(void)
+{
+ char buf[128];
+
+ if (read_file(DEV_ZCORE_HSA, buf, sizeof(buf)))
+ return 0;
+ return strtoul(buf, NULL, 16);
+}
+
+/*
+ * Release HSA
+ */
+static void release_hsa(void)
+{
+ write_to_file(DEV_ZCORE_HSA, "0");
+}
+
+/*
* Enable the scsi disk for dumping
* Return: 0 - ok
* != 0 - error
@@ -708,7 +731,7 @@ static int create_dump(void)
struct dump_page dp;
char buf[PAGE_SIZE], dpcpage[PAGE_SIZE];
char dump_name[1024];
- __u64 mem_loc, mem_count;
+ __u64 mem_loc, mem_count, hsa_size;
__u32 buf_loc = 0, dp_size, dp_flags;
int size, fin, fout, fmap, rc = 0;
char c_info[CHUNK_INFO_SIZE];
@@ -796,6 +819,9 @@ static int create_dump(void)
} while (1);
}
+ hsa_size = get_hsa_size();
+ PRINT_TRACE("hsa size: %llx\n", (unsigned long long) hsa_size);
+
/* try to open the source device */
fin = open(DEV_ZCORE, O_RDONLY, 0);
if (fin == -1) {
@@ -894,6 +920,10 @@ static int create_dump(void)
goto failed_close_fout;
}
}
+ if (hsa_size && mem_loc >= hsa_size) {
+ release_hsa();
+ hsa_size = 0;
+ }
if (read(fin, buf, PAGE_SIZE) != PAGE_SIZE) {
if (errno == EFAULT) {
/* probably memory hole. Skip page */
--- a/zfcpdump_v2/zfcpdump.h
+++ b/zfcpdump_v2/zfcpdump.h
@@ -78,6 +78,7 @@ struct globals {
#define DEV_ZCORE "/sys/kernel/debug/zcore/mem"
#define DEV_ZCORE_MAP "/sys/kernel/debug/zcore/memmap"
#define DEV_ZCORE_REIPL "/sys/kernel/debug/zcore/reipl"
+#define DEV_ZCORE_HSA "/sys/kernel/debug/zcore/hsa"
#define REIPL "1"
#define DEV_SCSI "/dev/sda"
#define DUMP_DIR "/mnt"