Change error codes for invalid DISCARDs

This commit is contained in:
toninov 2025-09-04 19:57:43 +02:00
parent 0405514560
commit 110c0c27be
No known key found for this signature in database
3 changed files with 7 additions and 11 deletions

View file

@ -46,8 +46,8 @@ void sflite_discard_work_fn(struct work_struct *work)
/* Check if the slice is mapped */
if (psi == SFLITE_PSI_INVALID) {
/* Attempted to discard an unmapped slice; fail silently, otherwise errors
will be reported under normal operation and confuse the userspace tools. */
/* Fail silent: returning a specific error code would break
plausible deniability */
goto unlock;
}
@ -63,6 +63,7 @@ unlock:
/* WARNING: it is crucial that the original bio is terminated here and never
reaches the block device, otherwise the effect of a TRIM on the block device
would be obvious, and likely to break plausible deniability */
orig_bio->bi_status = BLK_STS_OK;
bio_endio(orig_bio);
return;
}

View file

@ -48,10 +48,9 @@ static int sflite_map(struct dm_target *ti, struct bio *bio)
if (unlikely(bio_op(bio) == REQ_OP_DISCARD)) {
/* Ensure the discard request falls within a single slice */
if (unlikely(bio->bi_iter.bi_size != SFLITE_BLOCK_SIZE * SFLITE_SLICE_SCALE)) {
DMWARN("Wrong discard bio size: %u", bio->bi_iter.bi_size);
/* We have to fail silently, otherwise the filesystem will abort the entire
TRIM operation, even if there are valid 1 MiB slices to be discarded. */
DMINFO("Wrong discard bio size: %u", bio->bi_iter.bi_size);
// TODO investigate where these are coming from
bio->bi_status = BLK_STS_INVAL;
bio_endio(bio);
return DM_MAPIO_SUBMITTED;
}
@ -59,8 +58,7 @@ static int sflite_map(struct dm_target *ti, struct bio *bio)
/* Ensure the logical block number is aligned with the beginning of a slice */
if (unlikely(lblk_num % SFLITE_SLICE_SCALE != 0)) {
DMWARN("Unaligned discard bio!");
/* Same reason as above, fail silently */
bio->bi_status = BLK_STS_INVAL;
bio_endio(bio);
return DM_MAPIO_SUBMITTED;
}

View file

@ -148,9 +148,6 @@ struct sflc_volume_base *sflite_vol_ctr(struct sflc_device_base *sd_base,
ti->per_io_data_size = sizeof(struct sflite_io);
ti->private = svol;
/* Used for testing */
// DMWARN("%u MiB mapped, %u MiB free", svol->posmap.nr_mapped_slices, sdev->nr_free_slices);
return &svol->sv_base;