Skip to content

Commit 48920ff

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: remove the discard_zeroes_data flag
Now that we use the proper REQ_OP_WRITE_ZEROES operation everywhere we can kill this hack. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 45c2179 commit 48920ff

File tree

23 files changed

+27
-124
lines changed

23 files changed

+27
-124
lines changed

Documentation/ABI/testing/sysfs-block

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,8 @@ What: /sys/block/<disk>/queue/discard_zeroes_data
213213
Date: May 2011
214214
Contact: Martin K. Petersen <[email protected]>
215215
Description:
216-
Devices that support discard functionality may return
217-
stale or random data when a previously discarded block
218-
is read back. This can cause problems if the filesystem
219-
expects discarded blocks to be explicitly cleared. If a
220-
device reports that it deterministically returns zeroes
221-
when a discarded area is read the discard_zeroes_data
222-
parameter will be set to one. Otherwise it will be 0 and
223-
the result of reading a discarded area is undefined.
216+
Will always return 0. Don't rely on any specific behavior
217+
for discards, and don't read this file.
224218

225219
What: /sys/block/<disk>/queue/write_same_max_bytes
226220
Date: January 2012

Documentation/block/queue-sysfs.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ large discards are issued, setting this value lower will make Linux issue
4343
smaller discards and potentially help reduce latencies induced by large
4444
discard operations.
4545

46-
discard_zeroes_data (RO)
47-
------------------------
48-
When read, this file will show if the discarded block are zeroed by the
49-
device or not. If its value is '1' the blocks are zeroed otherwise not.
50-
5146
hw_sector_size (RO)
5247
-------------------
5348
This is the hardware sector size of the device, in bytes.

block/blk-lib.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,12 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
3737
return -ENXIO;
3838

3939
if (flags & BLKDEV_DISCARD_SECURE) {
40-
if (flags & BLKDEV_DISCARD_ZERO)
41-
return -EOPNOTSUPP;
4240
if (!blk_queue_secure_erase(q))
4341
return -EOPNOTSUPP;
4442
op = REQ_OP_SECURE_ERASE;
4543
} else {
4644
if (!blk_queue_discard(q))
4745
return -EOPNOTSUPP;
48-
if ((flags & BLKDEV_DISCARD_ZERO) &&
49-
!q->limits.discard_zeroes_data)
50-
return -EOPNOTSUPP;
5146
op = REQ_OP_DISCARD;
5247
}
5348

@@ -126,7 +121,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
126121
&bio);
127122
if (!ret && bio) {
128123
ret = submit_bio_wait(bio);
129-
if (ret == -EOPNOTSUPP && !(flags & BLKDEV_DISCARD_ZERO))
124+
if (ret == -EOPNOTSUPP)
130125
ret = 0;
131126
bio_put(bio);
132127
}

block/blk-settings.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ void blk_set_default_limits(struct queue_limits *lim)
103103
lim->discard_granularity = 0;
104104
lim->discard_alignment = 0;
105105
lim->discard_misaligned = 0;
106-
lim->discard_zeroes_data = 0;
107106
lim->logical_block_size = lim->physical_block_size = lim->io_min = 512;
108107
lim->bounce_pfn = (unsigned long)(BLK_BOUNCE_ANY >> PAGE_SHIFT);
109108
lim->alignment_offset = 0;
@@ -127,7 +126,6 @@ void blk_set_stacking_limits(struct queue_limits *lim)
127126
blk_set_default_limits(lim);
128127

129128
/* Inherit limits from component devices */
130-
lim->discard_zeroes_data = 1;
131129
lim->max_segments = USHRT_MAX;
132130
lim->max_discard_segments = 1;
133131
lim->max_hw_sectors = UINT_MAX;
@@ -609,7 +607,6 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
609607
t->io_opt = lcm_not_zero(t->io_opt, b->io_opt);
610608

611609
t->cluster &= b->cluster;
612-
t->discard_zeroes_data &= b->discard_zeroes_data;
613610

614611
/* Physical block size a multiple of the logical block size? */
615612
if (t->physical_block_size & (t->logical_block_size - 1)) {

block/blk-sysfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static ssize_t queue_discard_max_store(struct request_queue *q,
208208

209209
static ssize_t queue_discard_zeroes_data_show(struct request_queue *q, char *page)
210210
{
211-
return queue_var_show(queue_discard_zeroes_data(q), page);
211+
return queue_var_show(0, page);
212212
}
213213

214214
static ssize_t queue_write_same_max_show(struct request_queue *q, char *page)

block/compat_ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
685685
case BLKALIGNOFF:
686686
return compat_put_int(arg, bdev_alignment_offset(bdev));
687687
case BLKDISCARDZEROES:
688-
return compat_put_uint(arg, bdev_discard_zeroes_data(bdev));
688+
return compat_put_uint(arg, 0);
689689
case BLKFLSBUF:
690690
case BLKROSET:
691691
case BLKDISCARD:

block/ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
547547
case BLKALIGNOFF:
548548
return put_int(arg, bdev_alignment_offset(bdev));
549549
case BLKDISCARDZEROES:
550-
return put_uint(arg, bdev_discard_zeroes_data(bdev));
550+
return put_uint(arg, 0);
551551
case BLKSECTGET:
552552
max_sectors = min_t(unsigned int, USHRT_MAX,
553553
queue_max_sectors(bdev_get_queue(bdev)));

drivers/block/drbd/drbd_main.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,6 @@ void assign_p_sizes_qlim(struct drbd_device *device, struct p_sizes *p, struct r
931931
p->qlim->io_min = cpu_to_be32(queue_io_min(q));
932932
p->qlim->io_opt = cpu_to_be32(queue_io_opt(q));
933933
p->qlim->discard_enabled = blk_queue_discard(q);
934-
p->qlim->discard_zeroes_data = queue_discard_zeroes_data(q);
935934
p->qlim->write_same_capable = !!q->limits.max_write_same_sectors;
936935
} else {
937936
q = device->rq_queue;
@@ -941,7 +940,6 @@ void assign_p_sizes_qlim(struct drbd_device *device, struct p_sizes *p, struct r
941940
p->qlim->io_min = cpu_to_be32(queue_io_min(q));
942941
p->qlim->io_opt = cpu_to_be32(queue_io_opt(q));
943942
p->qlim->discard_enabled = 0;
944-
p->qlim->discard_zeroes_data = 0;
945943
p->qlim->write_same_capable = 0;
946944
}
947945
}

drivers/block/drbd/drbd_nl.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,10 +1199,6 @@ static void decide_on_discard_support(struct drbd_device *device,
11991199
struct drbd_connection *connection = first_peer_device(device)->connection;
12001200
bool can_do = b ? blk_queue_discard(b) : true;
12011201

1202-
if (can_do && b && !b->limits.discard_zeroes_data && !discard_zeroes_if_aligned) {
1203-
can_do = false;
1204-
drbd_info(device, "discard_zeroes_data=0 and discard_zeroes_if_aligned=no: disabling discards\n");
1205-
}
12061202
if (can_do && connection->cstate >= C_CONNECTED && !(connection->agreed_features & DRBD_FF_TRIM)) {
12071203
can_do = false;
12081204
drbd_info(connection, "peer DRBD too old, does not support TRIM: disabling discards\n");
@@ -1484,8 +1480,7 @@ static void sanitize_disk_conf(struct drbd_device *device, struct disk_conf *dis
14841480
if (disk_conf->al_extents > drbd_al_extents_max(nbc))
14851481
disk_conf->al_extents = drbd_al_extents_max(nbc);
14861482

1487-
if (!blk_queue_discard(q)
1488-
|| (!q->limits.discard_zeroes_data && !disk_conf->discard_zeroes_if_aligned)) {
1483+
if (!blk_queue_discard(q)) {
14891484
if (disk_conf->rs_discard_granularity) {
14901485
disk_conf->rs_discard_granularity = 0; /* disable feature */
14911486
drbd_info(device, "rs_discard_granularity feature disabled\n");

drivers/block/loop.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,6 @@ static void loop_config_discard(struct loop_device *lo)
828828
q->limits.discard_alignment = 0;
829829
blk_queue_max_discard_sectors(q, 0);
830830
blk_queue_max_write_zeroes_sectors(q, 0);
831-
q->limits.discard_zeroes_data = 0;
832831
queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, q);
833832
return;
834833
}
@@ -837,7 +836,6 @@ static void loop_config_discard(struct loop_device *lo)
837836
q->limits.discard_alignment = 0;
838837
blk_queue_max_discard_sectors(q, UINT_MAX >> 9);
839838
blk_queue_max_write_zeroes_sectors(q, UINT_MAX >> 9);
840-
q->limits.discard_zeroes_data = 1;
841839
queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
842840
}
843841

drivers/block/mtip32xx/mtip32xx.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4025,7 +4025,6 @@ static int mtip_block_initialize(struct driver_data *dd)
40254025
dd->queue->limits.discard_granularity = 4096;
40264026
blk_queue_max_discard_sectors(dd->queue,
40274027
MTIP_MAX_TRIM_ENTRY_LEN * MTIP_MAX_TRIM_ENTRIES);
4028-
dd->queue->limits.discard_zeroes_data = 0;
40294028
}
40304029

40314030
/* Set the capacity of the device in 512 byte sectors. */

drivers/block/nbd.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,6 @@ static int nbd_dev_add(int index)
11101110
queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, disk->queue);
11111111
disk->queue->limits.discard_granularity = 512;
11121112
blk_queue_max_discard_sectors(disk->queue, UINT_MAX);
1113-
disk->queue->limits.discard_zeroes_data = 0;
11141113
blk_queue_max_hw_sectors(disk->queue, 65536);
11151114
disk->queue->limits.max_sectors = 256;
11161115

drivers/md/dm-cache-target.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2773,7 +2773,6 @@ static int cache_create(struct cache_args *ca, struct cache **result)
27732773

27742774
ti->num_discard_bios = 1;
27752775
ti->discards_supported = true;
2776-
ti->discard_zeroes_data_unsupported = true;
27772776
ti->split_discard_bios = false;
27782777

27792778
cache->features = ca->features;

drivers/md/dm-crypt.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,6 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
20302030
wake_up_process(cc->write_thread);
20312031

20322032
ti->num_flush_bios = 1;
2033-
ti->discard_zeroes_data_unsupported = true;
20342033

20352034
return 0;
20362035

drivers/md/dm-raid.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2813,7 +2813,9 @@ static void configure_discard_support(struct raid_set *rs)
28132813
/* Assume discards not supported until after checks below. */
28142814
ti->discards_supported = false;
28152815

2816-
/* RAID level 4,5,6 require discard_zeroes_data for data integrity! */
2816+
/*
2817+
* XXX: RAID level 4,5,6 require zeroing for safety.
2818+
*/
28172819
raid456 = (rs->md.level == 4 || rs->md.level == 5 || rs->md.level == 6);
28182820

28192821
for (i = 0; i < rs->raid_disks; i++) {
@@ -2827,8 +2829,6 @@ static void configure_discard_support(struct raid_set *rs)
28272829
return;
28282830

28292831
if (raid456) {
2830-
if (!q->limits.discard_zeroes_data)
2831-
return;
28322832
if (!devices_handle_discard_safely) {
28332833
DMERR("raid456 discard support disabled due to discard_zeroes_data uncertainty.");
28342834
DMERR("Set dm-raid.devices_handle_discard_safely=Y to override.");

drivers/md/dm-raid1.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,6 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
11241124
ti->num_flush_bios = 1;
11251125
ti->num_discard_bios = 1;
11261126
ti->per_io_data_size = sizeof(struct dm_raid1_bio_record);
1127-
ti->discard_zeroes_data_unsupported = true;
11281127

11291128
ms->kmirrord_wq = alloc_workqueue("kmirrord", WQ_MEM_RECLAIM, 0);
11301129
if (!ms->kmirrord_wq) {

drivers/md/dm-table.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,22 +1449,6 @@ static bool dm_table_supports_flush(struct dm_table *t, unsigned long flush)
14491449
return false;
14501450
}
14511451

1452-
static bool dm_table_discard_zeroes_data(struct dm_table *t)
1453-
{
1454-
struct dm_target *ti;
1455-
unsigned i = 0;
1456-
1457-
/* Ensure that all targets supports discard_zeroes_data. */
1458-
while (i < dm_table_get_num_targets(t)) {
1459-
ti = dm_table_get_target(t, i++);
1460-
1461-
if (ti->discard_zeroes_data_unsupported)
1462-
return false;
1463-
}
1464-
1465-
return true;
1466-
}
1467-
14681452
static int device_is_nonrot(struct dm_target *ti, struct dm_dev *dev,
14691453
sector_t start, sector_t len, void *data)
14701454
{
@@ -1620,9 +1604,6 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
16201604
}
16211605
blk_queue_write_cache(q, wc, fua);
16221606

1623-
if (!dm_table_discard_zeroes_data(t))
1624-
q->limits.discard_zeroes_data = 0;
1625-
16261607
/* Ensure that all underlying devices are non-rotational. */
16271608
if (dm_table_all_devices_attribute(t, device_is_nonrot))
16281609
queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);

drivers/md/dm-thin.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3263,7 +3263,6 @@ static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
32633263
* them down to the data device. The thin device's discard
32643264
* processing will cause mappings to be removed from the btree.
32653265
*/
3266-
ti->discard_zeroes_data_unsupported = true;
32673266
if (pf.discard_enabled && pf.discard_passdown) {
32683267
ti->num_discard_bios = 1;
32693268

@@ -4119,7 +4118,6 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
41194118
ti->per_io_data_size = sizeof(struct dm_thin_endio_hook);
41204119

41214120
/* In case the pool supports discards, pass them on. */
4122-
ti->discard_zeroes_data_unsupported = true;
41234121
if (tc->pool->pf.discard_enabled) {
41244122
ti->discards_supported = true;
41254123
ti->num_discard_bios = 1;

drivers/md/raid5.c

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7227,7 +7227,6 @@ static int raid5_run(struct mddev *mddev)
72277227

72287228
if (mddev->queue) {
72297229
int chunk_size;
7230-
bool discard_supported = true;
72317230
/* read-ahead size must cover two whole stripes, which
72327231
* is 2 * (datadisks) * chunksize where 'n' is the
72337232
* number of raid devices
@@ -7263,12 +7262,6 @@ static int raid5_run(struct mddev *mddev)
72637262
blk_queue_max_discard_sectors(mddev->queue,
72647263
0xfffe * STRIPE_SECTORS);
72657264

7266-
/*
7267-
* unaligned part of discard request will be ignored, so can't
7268-
* guarantee discard_zeroes_data
7269-
*/
7270-
mddev->queue->limits.discard_zeroes_data = 0;
7271-
72727265
blk_queue_max_write_same_sectors(mddev->queue, 0);
72737266
blk_queue_max_write_zeroes_sectors(mddev->queue, 0);
72747267

@@ -7277,35 +7270,24 @@ static int raid5_run(struct mddev *mddev)
72777270
rdev->data_offset << 9);
72787271
disk_stack_limits(mddev->gendisk, rdev->bdev,
72797272
rdev->new_data_offset << 9);
7280-
/*
7281-
* discard_zeroes_data is required, otherwise data
7282-
* could be lost. Consider a scenario: discard a stripe
7283-
* (the stripe could be inconsistent if
7284-
* discard_zeroes_data is 0); write one disk of the
7285-
* stripe (the stripe could be inconsistent again
7286-
* depending on which disks are used to calculate
7287-
* parity); the disk is broken; The stripe data of this
7288-
* disk is lost.
7289-
*/
7290-
if (!blk_queue_discard(bdev_get_queue(rdev->bdev)) ||
7291-
!bdev_get_queue(rdev->bdev)->
7292-
limits.discard_zeroes_data)
7293-
discard_supported = false;
7294-
/* Unfortunately, discard_zeroes_data is not currently
7295-
* a guarantee - just a hint. So we only allow DISCARD
7296-
* if the sysadmin has confirmed that only safe devices
7297-
* are in use by setting a module parameter.
7298-
*/
7299-
if (!devices_handle_discard_safely) {
7300-
if (discard_supported) {
7301-
pr_info("md/raid456: discard support disabled due to uncertainty.\n");
7302-
pr_info("Set raid456.devices_handle_discard_safely=Y to override.\n");
7303-
}
7304-
discard_supported = false;
7305-
}
73067273
}
73077274

7308-
if (discard_supported &&
7275+
/*
7276+
* zeroing is required, otherwise data
7277+
* could be lost. Consider a scenario: discard a stripe
7278+
* (the stripe could be inconsistent if
7279+
* discard_zeroes_data is 0); write one disk of the
7280+
* stripe (the stripe could be inconsistent again
7281+
* depending on which disks are used to calculate
7282+
* parity); the disk is broken; The stripe data of this
7283+
* disk is lost.
7284+
*
7285+
* We only allow DISCARD if the sysadmin has confirmed that
7286+
* only safe devices are in use by setting a module parameter.
7287+
* A better idea might be to turn DISCARD into WRITE_ZEROES
7288+
* requests, as that is required to be safe.
7289+
*/
7290+
if (devices_handle_discard_safely &&
73097291
mddev->queue->limits.max_discard_sectors >= (stripe >> 9) &&
73107292
mddev->queue->limits.discard_granularity >= stripe)
73117293
queue_flag_set_unlocked(QUEUE_FLAG_DISCARD,

drivers/scsi/sd.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,6 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)
644644
unsigned int logical_block_size = sdkp->device->sector_size;
645645
unsigned int max_blocks = 0;
646646

647-
q->limits.discard_zeroes_data = 0;
648-
649647
/*
650648
* When LBPRZ is reported, discard alignment and granularity
651649
* must be fixed to the logical block size. Otherwise the block
@@ -681,19 +679,16 @@ static void sd_config_discard(struct scsi_disk *sdkp, unsigned int mode)
681679
case SD_LBP_WS16:
682680
max_blocks = min_not_zero(sdkp->max_ws_blocks,
683681
(u32)SD_MAX_WS16_BLOCKS);
684-
q->limits.discard_zeroes_data = sdkp->lbprz;
685682
break;
686683

687684
case SD_LBP_WS10:
688685
max_blocks = min_not_zero(sdkp->max_ws_blocks,
689686
(u32)SD_MAX_WS10_BLOCKS);
690-
q->limits.discard_zeroes_data = sdkp->lbprz;
691687
break;
692688

693689
case SD_LBP_ZERO:
694690
max_blocks = min_not_zero(sdkp->max_ws_blocks,
695691
(u32)SD_MAX_WS10_BLOCKS);
696-
q->limits.discard_zeroes_data = 1;
697692
break;
698693
}
699694

drivers/target/target_core_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ bool target_configure_unmap_from_queue(struct se_dev_attrib *attrib,
851851
attrib->unmap_granularity = q->limits.discard_granularity / block_size;
852852
attrib->unmap_granularity_alignment = q->limits.discard_alignment /
853853
block_size;
854-
attrib->unmap_zeroes_data = q->limits.discard_zeroes_data;
854+
attrib->unmap_zeroes_data = 0;
855855
return true;
856856
}
857857
EXPORT_SYMBOL(target_configure_unmap_from_queue);

0 commit comments

Comments
 (0)