From 41108c98aa639f8c70a5012584a9146a7fdbffa4 Mon Sep 17 00:00:00 2001 From: Sven Schnelle Date: Tue, 17 Jan 2023 16:04:58 +0000 Subject: [PATCH] zipl: move mkfs to ngdump prepare script The current code first assembles the ngdump init ramdisk, and creates the filesystem on the dump disk afterwards. ngdump uses uuids to mount the dump device. Because the filesystem uuid is changing with the final mkfs, ngdump has to use the partuuid of the device. This does work for nvme, but not for dasds. Another problem is that dryrun likely wouldn't work if there's no partition table on the dump device. To fix these issues, move the mkfs to the ngdump helper script so we can use the filesystem uuid. When --dryrun is specified the script passes /dev/null as ngdump device to make mkinitramfs happy. As the initramdisk is never used in this case, this shouldn't be a problem. Signed-off-by: Sven Schnelle Acked-by: Stefan Haberland Signed-off-by: Steffen Eiden --- zipl/dracut/zipl_helper.prepare-ngdump | 26 ++++++++++++----- .../zipl_helper.prepare-ngdump | 29 ++++++++++++------- zipl/src/bootmap.c | 17 ----------- zipl/src/job.c | 2 +- 4 files changed, 38 insertions(+), 36 deletions(-) diff --git a/zipl/dracut/zipl_helper.prepare-ngdump b/zipl/dracut/zipl_helper.prepare-ngdump index 7f774876..f078480c 100755 --- a/zipl/dracut/zipl_helper.prepare-ngdump +++ b/zipl/dracut/zipl_helper.prepare-ngdump @@ -16,14 +16,21 @@ DRACUT_OMIT_MODULES=( systemd-timedated systemd-timesyncd systemd-networkd systemd-network-manager systemd-coredump) -[ $# -gt 0 ] || { echo "Usage: $0 " >&2; exit 1; } +function create_dumpfs() +{ + [ "$dryrun" -eq 1 ] && { echo "/dev/null"; return 0; } + mkfs -F "$device" >/dev/null || { echo "Couldn't create filesystem on $1." >&2; return 1; } + local disk_path=/dev/disk/by-uuid/$(blkid -o value -s UUID "$device") + for i in $(seq 0 30) + do + [ -e "$disk_path" ] && break; + sleep 1 + done + + [ -e "$disk_path" ] || { echo "Filesystem device link missing." >&2; return 1; } + echo "$disk_path" +} -# -# Retrieve partition UUID -# -# We use PARTUUID because zipl re-formats the given partition after -# calling us, therefore, a UUID will change. -# device=$(readlink -f $1) disk_path=/dev/disk/by-partuuid/$(blkid -o value -s PARTUUID "$device") @@ -69,6 +76,11 @@ function create_initrd() --kver "$kver" -f "$initrd" 2>&1 } +[ $# -gt 1 ] || { echo "Usage: $0 " >&2; exit 1; } + +device=$(readlink -f $1) +dryrun=$2 +disk_path=$(create_dumpfs $device) kernel_version=$(get_kernel_version) kernel=$(get_kernel_image "$kernel_version") [ -e "$kernel" ] || { echo "Couldn't find kernel image." >&2; exit 1; } diff --git a/zipl/initramfs-tools/zipl_helper.prepare-ngdump b/zipl/initramfs-tools/zipl_helper.prepare-ngdump index 5727474b..6dd4ce73 100755 --- a/zipl/initramfs-tools/zipl_helper.prepare-ngdump +++ b/zipl/initramfs-tools/zipl_helper.prepare-ngdump @@ -6,18 +6,20 @@ # it under the terms of the MIT license. See LICENSE for details. # -[ $# -gt 0 ] || { echo "Usage: $0 " >&2; exit 1; } +function create_dumpfs() +{ + [ "$dryrun" -eq 1 ] && { echo "/dev/null"; return 0; } + mkfs -F "$device" >/dev/null || { echo "Couldn't create filesystem on $1." >&2; return 1; } + local disk_path=/dev/disk/by-uuid/$(blkid -o value -s UUID "$device") + for i in $(seq 0 30) + do + [ -e "$disk_path" ] && break; + sleep 1 + done -# -# Retrieve partition UUID -# -# We use PARTUUID because zipl re-formats the given partition after -# calling us, therefore, a UUID will change. -# -device=$(readlink -f $1) -disk_path=/dev/disk/by-partuuid/$(blkid -o value -s PARTUUID "$device") - -[ -e "$disk_path" ] || { echo "Couldn't find disk by PARTUUID." >&2; exit 1; } + [ -e "$disk_path" ] || { echo "Filesystem device link missing." >&2; return 1; } + echo "$disk_path" +} function get_kernel_version() { @@ -49,6 +51,11 @@ function create_initrd() NGDUMP=y NGDUMP_DEVICE="$disk" mkinitramfs -o "$initrd" "$kver" 2>&1 } +[ $# -gt 1 ] || { echo "Usage: $0 " >&2; exit 1; } + +device=$(readlink -f $1) +dryrun=$2 +disk_path=$(create_dumpfs $device) kernel_version=$(get_kernel_version) kernel=$(get_kernel_image "$kernel_version") [ -e "$kernel" ] || { echo "Couldn't find kernel image." >&2; exit 1; } diff --git a/zipl/src/bootmap.c b/zipl/src/bootmap.c index 9e13639a..7770b062 100644 --- a/zipl/src/bootmap.c +++ b/zipl/src/bootmap.c @@ -1667,7 +1667,6 @@ static int prepare_bootloader_ngdump(struct job_data *job, { struct disk_info *info; char *bootmap_dir; - int rc; /* Retrieve target device information */ if (disk_get_info(job->data.dump.device, &job->target, &info)) @@ -1693,22 +1692,6 @@ static int prepare_bootloader_ngdump(struct job_data *job, return -1; } bis->dump_tmp_dir_created = 1; - if (!dry_run) { - char *cmd = NULL; - util_asprintf(&cmd, "mkfs.%s -qF %s >/dev/null", - NGDUMP_FSTYPE, job->data.dump.device); - if (verbose) - printf("Formatting partition '%s'\n", - job->data.dump.device); - rc = system(cmd); - free(cmd); - if (rc) { - error_reason(strerror(errno)); - error_text("Could not format partition '%s':", - job->data.dump.device); - return -1; - } - } /* * Mount partition where bootmap file and also a dump file will * be stored. diff --git a/zipl/src/job.c b/zipl/src/job.c index 41e674b7..53c1a4e6 100644 --- a/zipl/src/job.c +++ b/zipl/src/job.c @@ -919,7 +919,7 @@ check_job_images_ngdump(struct job_dump_data* dump, char *name) FILE *fp; int rc; - misc_asprintf(&ppn_cmd, "%s %s", helper, dump->device); + misc_asprintf(&ppn_cmd, "%s %s %d", helper, dump->device, dry_run); printf("Run %s\n", ppn_cmd); fp = popen(ppn_cmd, "r");