mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 03:35:32 -04:00
s390/dasd: Add range-based format-track collision detection
Replace the single per-device format_entry slot with an array of 16 slots so multiple format requests can be in flight at once, and extend struct dasd_format_entry with a start_trk/end_trk/cqr range (replacing the single track field). Rewrite test_and_set_format_track() to scan the array for range overlaps instead of a trkcount snapshot, honour the early-collision flag, and return the allocated slot to the caller. Add dasd_req_conflict() and extend dasd_return_cqr_cb() to mark in-flight data CQRs that overlap a just-completed format range, so the next test_and_set_format_track() detects the conflict early. Remove the now-obsolete trkcount snapshot in dasd_start_IO(). The detection added here only becomes active together with the WRITE_FULL_TRACK ESE format handler later in the series: that patch routes the format request through dasd_return_cqr_cb() (so completion runs the overlap hook with cqr->format set) and records each request's start_trk/end_trk range. Until then the array and the conflict check are in place but dormant. Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com> Signed-off-by: Stefan Haberland <sth@linux.ibm.com> Link: https://patch.msgid.link/20260805111612.1285190-10-sth@linux.ibm.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
committed by
Jens Axboe
parent
9cebfced13
commit
0569784929
@@ -1401,13 +1401,6 @@ int dasd_start_IO(struct dasd_ccw_req *cqr)
|
||||
if (!cqr->lpm)
|
||||
cqr->lpm = dasd_path_get_opm(device);
|
||||
}
|
||||
/*
|
||||
* remember the amount of formatted tracks to prevent double format on
|
||||
* ESE devices
|
||||
*/
|
||||
if (cqr->block)
|
||||
cqr->trkcount = atomic_read(&cqr->block->trkcount);
|
||||
|
||||
if (cqr->cpmode == 1) {
|
||||
rc = ccw_device_tm_start(device->cdev, cqr->cpaddr,
|
||||
(long) cqr, cqr->lpm);
|
||||
@@ -2868,6 +2861,28 @@ static void __dasd_process_block_ccw_queue(struct dasd_block *block,
|
||||
|
||||
static void dasd_return_cqr_cb(struct dasd_ccw_req *cqr, void *data)
|
||||
{
|
||||
struct dasd_ccw_req *temp_cqr;
|
||||
struct dasd_block *block;
|
||||
|
||||
/* only format CQRs are candidates */
|
||||
if (!cqr->block || unlikely(!cqr->format))
|
||||
goto out;
|
||||
|
||||
block = cqr->block;
|
||||
/*
|
||||
* Mark in-flight (IN_IO) CQRs that overlap this just-completed format
|
||||
* range so they re-check in test_and_set_format on completion; FILLED
|
||||
* or QUEUED CQRs re-check the format_list on their next round anyway.
|
||||
*/
|
||||
list_for_each_entry(temp_cqr, &block->ccw_queue, blocklist) {
|
||||
if (temp_cqr != cqr &&
|
||||
temp_cqr->status != DASD_CQR_FILLED &&
|
||||
temp_cqr->status != DASD_CQR_QUEUED &&
|
||||
dasd_req_conflict(cqr, temp_cqr)) {
|
||||
WRITE_ONCE(temp_cqr->collision, true);
|
||||
}
|
||||
}
|
||||
out:
|
||||
dasd_schedule_block_bh(cqr->block);
|
||||
}
|
||||
|
||||
|
||||
@@ -3150,32 +3150,44 @@ static int dasd_eckd_format_device(struct dasd_device *base,
|
||||
0, NULL);
|
||||
}
|
||||
|
||||
static bool test_and_set_format_track(struct dasd_format_entry *to_format,
|
||||
struct dasd_ccw_req *cqr)
|
||||
static bool test_and_set_format_track(sector_t start, sector_t end,
|
||||
struct dasd_ccw_req *cqr,
|
||||
struct dasd_block *block,
|
||||
struct dasd_device *device,
|
||||
struct dasd_format_entry **entry)
|
||||
{
|
||||
struct dasd_block *block = cqr->block;
|
||||
struct dasd_format_entry *format;
|
||||
struct dasd_format_entry *to_format, *format;
|
||||
unsigned long flags;
|
||||
bool rc = false;
|
||||
int i = 0;
|
||||
|
||||
/* marked as a collision by dasd_return_cqr_cb last round: retry */
|
||||
if (cqr && READ_ONCE(cqr->collision)) {
|
||||
WRITE_ONCE(cqr->collision, false);
|
||||
return true;
|
||||
}
|
||||
spin_lock_irqsave(&block->format_lock, flags);
|
||||
if (cqr->trkcount != atomic_read(&block->trkcount)) {
|
||||
/*
|
||||
* The number of formatted tracks has changed after request
|
||||
* start and we can not tell if the current track was involved.
|
||||
* To avoid data corruption treat it as if the current track is
|
||||
* involved
|
||||
*/
|
||||
while (i < DASD_NR_FORMAT_ENTRIES &&
|
||||
READ_ONCE(device->format_entry[i].cqr))
|
||||
i++;
|
||||
|
||||
if (i >= DASD_NR_FORMAT_ENTRIES) {
|
||||
rc = true;
|
||||
goto out;
|
||||
}
|
||||
|
||||
list_for_each_entry(format, &block->format_list, list) {
|
||||
if (format->track == to_format->track) {
|
||||
if (!(end < format->start_trk || format->end_trk < start)) {
|
||||
rc = true;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
to_format = &device->format_entry[i];
|
||||
to_format->start_trk = start;
|
||||
to_format->end_trk = end;
|
||||
to_format->cqr = cqr;
|
||||
list_add_tail(&to_format->list, &block->format_list);
|
||||
*entry = to_format;
|
||||
|
||||
out:
|
||||
spin_unlock_irqrestore(&block->format_lock, flags);
|
||||
@@ -3183,13 +3195,13 @@ static bool test_and_set_format_track(struct dasd_format_entry *to_format,
|
||||
}
|
||||
|
||||
static void clear_format_track(struct dasd_format_entry *format,
|
||||
struct dasd_block *block)
|
||||
struct dasd_block *block)
|
||||
{
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&block->format_lock, flags);
|
||||
atomic_inc(&block->trkcount);
|
||||
list_del_init(&format->list);
|
||||
format->cqr = NULL;
|
||||
spin_unlock_irqrestore(&block->format_lock, flags);
|
||||
}
|
||||
|
||||
@@ -3211,8 +3223,8 @@ static struct dasd_ccw_req *
|
||||
dasd_eckd_ese_format(struct dasd_device *startdev, struct dasd_ccw_req *cqr,
|
||||
struct irb *irb)
|
||||
{
|
||||
struct dasd_format_entry *format = NULL;
|
||||
struct dasd_eckd_private *private;
|
||||
struct dasd_format_entry *format;
|
||||
struct format_data_t fdata;
|
||||
unsigned int recs_per_trk;
|
||||
struct dasd_ccw_req *fcqr;
|
||||
@@ -3231,7 +3243,6 @@ dasd_eckd_ese_format(struct dasd_device *startdev, struct dasd_ccw_req *cqr,
|
||||
private = base->private;
|
||||
blksize = block->bp_block;
|
||||
recs_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
|
||||
format = &startdev->format_entry;
|
||||
|
||||
first_trk = blk_rq_pos(req) >> block->s2b_shift;
|
||||
sector_div(first_trk, recs_per_trk);
|
||||
@@ -3248,9 +3259,9 @@ dasd_eckd_ese_format(struct dasd_device *startdev, struct dasd_ccw_req *cqr,
|
||||
curr_trk, first_trk, last_trk);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
format->track = curr_trk;
|
||||
|
||||
/* test if track is already in formatting by another thread */
|
||||
if (test_and_set_format_track(format, cqr)) {
|
||||
if (test_and_set_format_track(curr_trk, curr_trk, cqr, block, startdev, &format)) {
|
||||
/* this is no real error so do not count down retries */
|
||||
cqr->retries++;
|
||||
return ERR_PTR(-EEXIST);
|
||||
@@ -3262,17 +3273,28 @@ dasd_eckd_ese_format(struct dasd_device *startdev, struct dasd_ccw_req *cqr,
|
||||
fdata.intensity = private->uses_cdl ? DASD_FMT_INT_COMPAT : 0;
|
||||
|
||||
rc = dasd_eckd_format_sanity_checks(base, &fdata);
|
||||
if (rc)
|
||||
if (rc) {
|
||||
if (format)
|
||||
clear_format_track(format, block);
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
/*
|
||||
* We're building the request with PAV disabled as we're reusing
|
||||
* the former startdev.
|
||||
*/
|
||||
fcqr = dasd_eckd_build_format(base, startdev, &fdata, 0);
|
||||
if (IS_ERR(fcqr))
|
||||
if (IS_ERR(fcqr)) {
|
||||
if (format)
|
||||
clear_format_track(format, block);
|
||||
return fcqr;
|
||||
}
|
||||
|
||||
if (format) {
|
||||
/* occupancy marker; the free-slot scan reads it with READ_ONCE */
|
||||
WRITE_ONCE(format->cqr, fcqr);
|
||||
fcqr->format = format;
|
||||
}
|
||||
fcqr->callback = dasd_eckd_ese_format_cb;
|
||||
fcqr->callback_data = (void *) format;
|
||||
|
||||
|
||||
@@ -545,9 +545,17 @@ struct dasd_profile {
|
||||
spinlock_t lock;
|
||||
};
|
||||
|
||||
/*
|
||||
* concurrent ESE format ranges in flight; also caps a WRITE_FULL_TRACK's
|
||||
* track count, which the LRE track bitmask limits to 16
|
||||
*/
|
||||
#define DASD_NR_FORMAT_ENTRIES 16
|
||||
|
||||
struct dasd_format_entry {
|
||||
struct list_head list;
|
||||
sector_t track;
|
||||
struct dasd_ccw_req *cqr;
|
||||
sector_t start_trk;
|
||||
sector_t end_trk;
|
||||
};
|
||||
|
||||
struct dasd_device {
|
||||
@@ -617,7 +625,7 @@ struct dasd_device {
|
||||
struct dentry *debugfs_dentry;
|
||||
struct dentry *hosts_dentry;
|
||||
struct dasd_profile profile;
|
||||
struct dasd_format_entry format_entry;
|
||||
struct dasd_format_entry format_entry[DASD_NR_FORMAT_ENTRIES];
|
||||
struct kset *paths_info;
|
||||
struct dasd_copy_relation *copy;
|
||||
unsigned long aq_mask;
|
||||
@@ -834,6 +842,13 @@ static inline void *dasd_get_callback_data(struct dasd_ccw_req *cqr)
|
||||
return cqr->callback_data;
|
||||
}
|
||||
|
||||
static inline bool dasd_req_conflict(struct dasd_ccw_req *cqr1,
|
||||
struct dasd_ccw_req *cqr2)
|
||||
{
|
||||
return !(cqr1->format->end_trk < cqr2->start_trk ||
|
||||
cqr2->end_trk < cqr1->format->start_trk);
|
||||
}
|
||||
|
||||
/* externals in dasd.c */
|
||||
#define DASD_PROFILE_OFF 0
|
||||
#define DASD_PROFILE_ON 1
|
||||
|
||||
Reference in New Issue
Block a user