From 0466760ec11548d0451337c5d9e08ef5b9a56fe2 Mon Sep 17 00:00:00 2001 From: Alexander Egorenkov Date: Thu, 5 Aug 2021 11:33:20 +0200 Subject: [PATCH] zdump: Implement DT interface for NGDump MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The NGDump DT interface enables zgetdump to display various meta information contained within a dump partition prepared for NGDump stand-alone dump. Usage example: -------------- No dump yet made ---------------- $ zgetdump -d /dev/nvme0n1 Dump device info: Dump tool.........: Next Generation (NGDump) dump tool Version...........: 1 Architecture......: s390x (64 bit) Partition info: Partition number..: 1 Dump present ------------ $ zgetdump -d /dev/nvme0n1 Dump device info: Dump tool.........: Next Generation (NGDump) dump tool Version...........: 1 Architecture......: s390x (64 bit) Partition info: Partition number..: 1 Meta info: File..............: dump.elf Alternative disk path --------------------- $ zgetdump -d /dev/disk/by-id/nvme-eui.01000000010000005cd2e4c5bc845051 Dump device info: Dump tool.........: Next Generation (NGDump) dump tool Version...........: 1 Architecture......: s390x (64 bit) Partition info: Partition number..: 1 Meta info: File..............: dump.elf Signed-off-by: Alexander Egorenkov Reviewed-by: Alexander Gordeev Reviewed-by: Mikhail Zaslonko Tested-by: Mikhail Zaslonko Signed-off-by: Jan Höppner --- zdump/Makefile | 2 +- zdump/dt.c | 5 ++-- zdump/dt.h | 1 + zdump/dt_ngdump.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 zdump/dt_ngdump.c diff --git a/zdump/Makefile b/zdump/Makefile index 2232126c..6757d65e 100644 --- a/zdump/Makefile +++ b/zdump/Makefile @@ -54,7 +54,7 @@ OBJECTS = zgetdump.o opts.o zg.o zg_error.o zg_print.o \ dt.o dt_s390sv.o dt_s390sv_ext.o \ dt_s390mv.o dt_s390mv_ext.o \ dt_scsi.o output.o \ - ngdump.o + ngdump.o dt_ngdump.o ifeq ("$(HAVE_FUSE)","0") FUSE_CFLAGS = -DHAVE_FUSE=0 -D_FILE_OFFSET_BITS=64 diff --git a/zdump/dt.c b/zdump/dt.c index a0ccae40..192b0bfa 100644 --- a/zdump/dt.c +++ b/zdump/dt.c @@ -22,6 +22,7 @@ static struct dt *dt_vec[] = { &dt_s390sv_ext, &dt_s390sv, &dt_scsi, + &dt_ngdump, NULL, }; @@ -55,8 +56,8 @@ void dt_init(void) while ((dt = dt_vec[i])) { g.fh = zg_open(g.opts.device, O_RDONLY, ZG_CHECK); if (!S_ISBLK(g.fh->sb.st_mode)) - ERR_EXIT("Please specify DASD or SCSI device node" - "(e.g. /dev/dasdd or /dev/sda )"); + ERR_EXIT("Please specify DASD, SCSI or NVMe device node" + "(e.g. /dev/dasdd, /dev/sda or /dev/nvme0n1 )"); if (dt->init() == 0) { l.dt = dt; return; diff --git a/zdump/dt.h b/zdump/dt.h index 0c0d97f3..adcc929e 100644 --- a/zdump/dt.h +++ b/zdump/dt.h @@ -41,5 +41,6 @@ extern struct dt dt_s390mv_ext; extern struct dt dt_s390sv; extern struct dt dt_s390sv_ext; extern struct dt dt_scsi; +extern struct dt dt_ngdump; #endif diff --git a/zdump/dt_ngdump.c b/zdump/dt_ngdump.c new file mode 100644 index 00000000..a1fbe2a1 --- /dev/null +++ b/zdump/dt_ngdump.c @@ -0,0 +1,63 @@ +/* + * zgetdump - Tool for copying and converting System z dumps + * + * NGDump dump tool + * + * Copyright IBM Corp. 2021 + * + * s390-tools is free software; you can redistribute it and/or modify + * it under the terms of the MIT license. See LICENSE for details. + */ + +#include "zgetdump.h" +#include "zg.h" +#include "dt.h" +#include "ngdump.h" + +/* + * File local static data + */ +static struct { + int part_num; + struct ngdump_meta meta; +} l; + +static int dt_ngdump_init(void) +{ + char *part_path = NULL; + int rc; + + l.part_num = ngdump_get_dump_part(g.fh); + if (l.part_num <= 0) + return -1; + if (ngdump_get_disk_part_path(g.fh->path, l.part_num, &part_path) < 0) + return -1; + rc = ngdump_read_meta_from_device(part_path, &l.meta); + free(part_path); + if (rc) + return -1; + + dt_arch_set(DFI_ARCH_64); + dt_version_set(l.meta.version); + + return 0; +} + +static void dt_ngdump_info(void) +{ + STDERR("Partition info:\n"); + STDERR(" Partition number..: %d\n", l.part_num); + if (!l.meta.file) + return; + STDERR("Meta info:\n"); + STDERR(" File..............: %s\n", l.meta.file); +} + +/* + * NGDump DT operations + */ +struct dt dt_ngdump = { + .desc = "Next Generation (NGDump) dump tool", + .init = dt_ngdump_init, + .info = dt_ngdump_info, +};