[PATCH v7 15/19] s390/dasd: Stamp a format label into newly formatted volumes
Stefan Haberland <[email protected]> Sat, 1 Aug 2026 20:00:29 +0200
| Newsgroups | org.kernel.vger.linux-s390 |
|---|---|
| Message-ID | <[email protected]> |
When a CDL volume is formatted, write a small on-disk label so the format can later be recognised by the kernel. The next patch will use this for ESE detection. The label records a magic, a version, whether the volume is ESE, and whether it was formatted quick (space released, thin) or full. It lives in track 0, head 0, record 4 (the first non-special CDL record). R4 is written by the same channel program that formats track 0 - its WRITE_CKD transfers count + the label data instead of count-only - so label and track format reach the disk atomically; a valid magic then marks a completed format without a separate, racy write. Quick vs full is derived from a full space release (RAS) preceding the format: dasd_eckd_release_space_full() sets a per-device flag the next format consumes. Non-ESE volumes and formats without a preceding full release are recorded as full. struct dasd_format_label is exactly 512 bytes (the smallest block size) so it fits one record; larger blocks zero-pad the rest. Reviewed-by: Jan Höppner <[email protected]> Signed-off-by: Stefan Haberland <[email protected]> --- drivers/s390/block/dasd_eckd.c | 81 +++++++++++++++++++++++++++++++--- drivers/s390/block/dasd_eckd.h | 38 ++++++++++++++++ 2 files changed, 114 insertions(+), 5 deletions(-) diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c index abd35afdeb22..3b560846fa79 100644 --- a/drivers/s390/block/dasd_eckd.c +++ b/drivers/s390/block/dasd_eckd.c @@ -19,6 +19,7 @@ #include <linux/init.h> #include <linux/seq_file.h> #include <linux/uaccess.h> +#include <linux/utsname.h> #include <linux/io.h> #include <asm/css_chars.h> @@ -2722,6 +2723,28 @@ dasd_eckd_build_check(struct dasd_device *base, struct format_data_t *fdata, return cqr; } +/* Fill the format label into a R4 record buffer, zero-padded to blksize. */ +static void dasd_eckd_fill_format_label(struct dasd_device *device, void *data, + unsigned int blksize) +{ + struct dasd_eckd_private *private = device->private; + struct dasd_format_label *label = data; + + memset(label, 0, blksize); + label->magic = DASD_ESE_LABEL_MAGIC; + label->version = DASD_ESE_LABEL_VERSION; + if (dasd_eckd_is_ese(device)) + label->flags |= DASD_ESE_LABEL_F_ESE; + if (private->ese_format_quick) + label->flags |= DASD_ESE_LABEL_F_QUICK; + else + label->flags |= DASD_ESE_LABEL_F_FULL; + label->blksize = blksize; + label->format_tod = get_tod_clock(); + strscpy(label->kernel_version, init_utsname()->release, + sizeof(label->kernel_version)); +} + static struct dasd_ccw_req * dasd_eckd_build_format(struct dasd_device *base, struct dasd_device *startdev, struct format_data_t *fdata, int enable_pav) @@ -2740,6 +2763,7 @@ dasd_eckd_build_format(struct dasd_device *base, struct dasd_device *startdev, int r0_perm; int nr_tracks; int use_prefix; + int write_label; if (enable_pav) startdev = dasd_alias_get_start_dev(base); @@ -2773,6 +2797,15 @@ dasd_eckd_build_format(struct dasd_device *base, struct dasd_device *startdev, use_prefix = base_priv->features.feature[8] & 0x01; + /* + * Stamp the format label into R4 of the very first track. Only for CDL + * (R4 is the first non-special record there), only when this request + * covers track 0, only for the record-writing format intensities (not + * track invalidation), and only if the track actually has an R4. + */ + write_label = (intensity & 0x08) && !((intensity & ~0x08) & 0x04) && + fdata->start_unit == 0 && rpt > 3; + switch (intensity) { case 0x00: /* Normal format */ case 0x08: /* Normal format, use cdl. */ @@ -2819,6 +2852,10 @@ dasd_eckd_build_format(struct dasd_device *base, struct dasd_device *startdev, return ERR_PTR(-EINVAL); } + /* room for the label data that R4 carries in addition to its count */ + if (write_label) + datasize += fdata->blksize; + fcp = dasd_fmalloc_request(DASD_ECKD_MAGIC, cplength, datasize, startdev); if (IS_ERR(fcp)) return fcp; @@ -2963,7 +3000,21 @@ dasd_eckd_build_format(struct dasd_device *base, struct dasd_device *startdev, ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD_MT; ccw->flags = CCW_FLAG_SLI; - ccw->count = 8; + if (write_label && address.cyl == 0 && + address.head == 0 && i == 3) { + /* + * R4 carries the label as its record + * data; it follows ect contiguously so + * the CCW transfers count + data. + */ + dasd_eckd_fill_format_label(base, + data, + fdata->blksize); + data += fdata->blksize; + ccw->count = 8 + fdata->blksize; + } else { + ccw->count = 8; + } ccw->cda = virt_to_dma32(ect); ccw++; } @@ -3173,6 +3224,9 @@ static int dasd_eckd_format_process_data(struct dasd_device *base, static int dasd_eckd_format_device(struct dasd_device *base, struct format_data_t *fdata, int enable_pav) { + struct dasd_eckd_private *private = base->private; + int rc; + /* * A full format (start_unit == 0) returns the device to a fully sparse * state, so restart the heuristic from ft1 without an offline cycle. @@ -3180,8 +3234,18 @@ static int dasd_eckd_format_device(struct dasd_device *base, if (fdata->start_unit == 0) dasd_ft_bias_apply(base); - return dasd_eckd_format_process_data(base, fdata, enable_pav, 0, NULL, - 0, NULL); + rc = dasd_eckd_format_process_data(base, fdata, enable_pav, 0, NULL, + 0, NULL); + + /* + * The quick-format indicator was consumed by the label stamped into + * track 0; clear it so a later format that is not preceded by a full + * space release is recorded as a full format. + */ + if (fdata->start_unit == 0) + private->ese_format_quick = 0; + + return rc; } static bool test_and_set_format_track(sector_t start, sector_t end, @@ -4082,6 +4146,7 @@ dasd_eckd_dso_ras(struct dasd_device *device, struct dasd_block *block, static int dasd_eckd_release_space_full(struct dasd_device *device) { + struct dasd_eckd_private *private; struct dasd_ccw_req *cqr; int rc; @@ -4093,10 +4158,16 @@ static int dasd_eckd_release_space_full(struct dasd_device *device) if (!rc) { /* - * Releasing all space (RAS) wipes every track and the device is fully - * sparse again, so restart the heuristic from ft1. + * Releasing all space (RAS) wipes every track and the device is + * fully sparse again, so restart the heuristic from ft1. */ dasd_ft_bias_apply(device); + /* + * A full release is what makes a subsequent format a quick + * (thin) one; remember it so the format label records that. + */ + private = device->private; + private->ese_format_quick = 1; } dasd_sfree_request(cqr, cqr->memdev); diff --git a/drivers/s390/block/dasd_eckd.h b/drivers/s390/block/dasd_eckd.h index 0fdb92fdddc8..92fd8ac92b79 100644 --- a/drivers/s390/block/dasd_eckd.h +++ b/drivers/s390/block/dasd_eckd.h @@ -159,6 +159,39 @@ struct eckd_r0 { #define DASD_EAV_CYL_HI_SHIFT 16 /* cylinder bits beyond the 16-bit cyl field */ #define DASD_EAV_HEAD_HI_SHIFT 4 /* head occupies the low-order 4 bits of head */ +/* + * On-disk DASD format label. + * + * Written into track 0, head 0, record 4 (R4 - the first non-special CDL + * record) as part of the same channel program that formats track 0, so it is + * stored atomically with the track: either both the track format and the label + * make it to disk or neither does. Its presence with a valid magic therefore + * marks a completed format and can be used for format detection. + * + * The structure is exactly the smallest supported block size (512 bytes) so it + * always fits into a single record. + * For larger block sizes the rest of the record is zero padded. + * The magic together with the version is used to recognise a valid label. + */ +#define DASD_ESE_LABEL_MAGIC 0xC4C1E2C4C6D4E3F1ULL /* EBCDIC "DASDFMT1" */ +#define DASD_ESE_LABEL_VERSION 1 + +/* dasd_format_label.flags */ +#define DASD_ESE_LABEL_F_ESE 0x00000001 /* volume is extent space efficient */ +#define DASD_ESE_LABEL_F_QUICK 0x00000002 /* quick (space released) format */ +#define DASD_ESE_LABEL_F_FULL 0x00000004 /* full format */ + +struct dasd_format_label { + __u64 magic; /* DASD_ESE_LABEL_MAGIC */ + __u32 version; /* DASD_ESE_LABEL_VERSION */ + __u32 flags; /* DASD_ESE_LABEL_F_* */ + __u32 blksize; /* block size the volume was formatted with */ + __u32 reserved0; + __u64 format_tod; /* TOD clock at format time */ + __u8 kernel_version[64]; /* NUL terminated kernel release (uname -r) */ + __u8 reserved[416]; /* pad the struct to 512 bytes */ +} __packed; + struct ch_t { __u16 cyl; __u16 head; @@ -709,6 +742,11 @@ struct dasd_eckd_private { u32 fcx_max_data; char suc_reason; + /* + * Set when the whole volume's space was released (full RAS); consumed by + * the next format to mark the on-disk label as a quick (vs full) format. + */ + int ese_format_quick; }; -- 2.53.0