Skip to content

Commit dd3932e

Browse files
Christoph HellwigJens Axboe
authored andcommitted
block: remove BLKDEV_IFL_WAIT
All the blkdev_issue_* helpers can only sanely be used for synchronous caller. To issue cache flushes or barriers asynchronously the caller needs to set up a bio by itself with a completion callback to move the asynchronous state machine ahead. So drop the BLKDEV_IFL_WAIT flag that is always specified when calling blkdev_issue_* and also remove the now unused flags argument to blkdev_issue_flush and blkdev_issue_zeroout. For blkdev_issue_discard we need to keep it for the secure discard flag, which gains a more descriptive name and loses the bitops vs flag confusion. Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 8786fb7 commit dd3932e

File tree

19 files changed

+47
-71
lines changed

19 files changed

+47
-71
lines changed

block/blk-flush.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ static void bio_end_flush(struct bio *bio, int err)
205205
* @bdev: blockdev to issue flush for
206206
* @gfp_mask: memory allocation flags (for bio_alloc)
207207
* @error_sector: error sector
208-
* @flags: BLKDEV_IFL_* flags to control behaviour
209208
*
210209
* Description:
211210
* Issue a flush for the block device in question. Caller can supply
@@ -214,7 +213,7 @@ static void bio_end_flush(struct bio *bio, int err)
214213
* request was pushed in some internal queue for later handling.
215214
*/
216215
int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
217-
sector_t *error_sector, unsigned long flags)
216+
sector_t *error_sector)
218217
{
219218
DECLARE_COMPLETION_ONSTACK(wait);
220219
struct request_queue *q;
@@ -240,21 +239,19 @@ int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask,
240239
bio = bio_alloc(gfp_mask, 0);
241240
bio->bi_end_io = bio_end_flush;
242241
bio->bi_bdev = bdev;
243-
if (test_bit(BLKDEV_WAIT, &flags))
244-
bio->bi_private = &wait;
242+
bio->bi_private = &wait;
245243

246244
bio_get(bio);
247245
submit_bio(WRITE_FLUSH, bio);
248-
if (test_bit(BLKDEV_WAIT, &flags)) {
249-
wait_for_completion(&wait);
250-
/*
251-
* The driver must store the error location in ->bi_sector, if
252-
* it supports it. For non-stacked drivers, this should be
253-
* copied from blk_rq_pos(rq).
254-
*/
255-
if (error_sector)
256-
*error_sector = bio->bi_sector;
257-
}
246+
wait_for_completion(&wait);
247+
248+
/*
249+
* The driver must store the error location in ->bi_sector, if
250+
* it supports it. For non-stacked drivers, this should be
251+
* copied from blk_rq_pos(rq).
252+
*/
253+
if (error_sector)
254+
*error_sector = bio->bi_sector;
258255

259256
if (!bio_flagged(bio, BIO_UPTODATE))
260257
ret = -EIO;

block/blk-lib.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
6161
max_discard_sectors &= ~(disc_sects - 1);
6262
}
6363

64-
if (flags & BLKDEV_IFL_SECURE) {
64+
if (flags & BLKDEV_DISCARD_SECURE) {
6565
if (!blk_queue_secdiscard(q))
6666
return -EOPNOTSUPP;
6767
type |= REQ_SECURE;
@@ -77,8 +77,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
7777
bio->bi_sector = sector;
7878
bio->bi_end_io = blkdev_discard_end_io;
7979
bio->bi_bdev = bdev;
80-
if (flags & BLKDEV_IFL_WAIT)
81-
bio->bi_private = &wait;
80+
bio->bi_private = &wait;
8281

8382
if (nr_sects > max_discard_sectors) {
8483
bio->bi_size = max_discard_sectors << 9;
@@ -92,8 +91,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
9291
bio_get(bio);
9392
submit_bio(type, bio);
9493

95-
if (flags & BLKDEV_IFL_WAIT)
96-
wait_for_completion(&wait);
94+
wait_for_completion(&wait);
9795

9896
if (bio_flagged(bio, BIO_EOPNOTSUPP))
9997
ret = -EOPNOTSUPP;
@@ -139,7 +137,6 @@ static void bio_batch_end_io(struct bio *bio, int err)
139137
* @sector: start sector
140138
* @nr_sects: number of sectors to write
141139
* @gfp_mask: memory allocation flags (for bio_alloc)
142-
* @flags: BLKDEV_IFL_* flags to control behaviour
143140
*
144141
* Description:
145142
* Generate and issue number of bios with zerofiled pages.
@@ -148,7 +145,7 @@ static void bio_batch_end_io(struct bio *bio, int err)
148145
*/
149146

150147
int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
151-
sector_t nr_sects, gfp_t gfp_mask, unsigned long flags)
148+
sector_t nr_sects, gfp_t gfp_mask)
152149
{
153150
int ret;
154151
struct bio *bio;
@@ -174,8 +171,7 @@ int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
174171
bio->bi_sector = sector;
175172
bio->bi_bdev = bdev;
176173
bio->bi_end_io = bio_batch_end_io;
177-
if (flags & BLKDEV_IFL_WAIT)
178-
bio->bi_private = &bb;
174+
bio->bi_private = &bb;
179175

180176
while (nr_sects != 0) {
181177
sz = min((sector_t) PAGE_SIZE >> 9 , nr_sects);
@@ -193,10 +189,9 @@ int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
193189
submit_bio(WRITE, bio);
194190
}
195191

196-
if (flags & BLKDEV_IFL_WAIT)
197-
/* Wait for bios in-flight */
198-
while ( issued != atomic_read(&bb.done))
199-
wait_for_completion(&wait);
192+
/* Wait for bios in-flight */
193+
while (issued != atomic_read(&bb.done))
194+
wait_for_completion(&wait);
200195

201196
if (!test_bit(BIO_UPTODATE, &bb.flags))
202197
/* One of bios in the batch was completed with error.*/

block/ioctl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static int blkdev_reread_part(struct block_device *bdev)
116116
static int blk_ioctl_discard(struct block_device *bdev, uint64_t start,
117117
uint64_t len, int secure)
118118
{
119-
unsigned long flags = BLKDEV_IFL_WAIT;
119+
unsigned long flags = 0;
120120

121121
if (start & 511)
122122
return -EINVAL;
@@ -128,7 +128,7 @@ static int blk_ioctl_discard(struct block_device *bdev, uint64_t start,
128128
if (start + len > (bdev->bd_inode->i_size >> 9))
129129
return -EINVAL;
130130
if (secure)
131-
flags |= BLKDEV_IFL_SECURE;
131+
flags |= BLKDEV_DISCARD_SECURE;
132132
return blkdev_issue_discard(bdev, start, len, GFP_KERNEL, flags);
133133
}
134134

drivers/block/drbd/drbd_int.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,8 +2321,7 @@ static inline void drbd_md_flush(struct drbd_conf *mdev)
23212321
if (test_bit(MD_NO_BARRIER, &mdev->flags))
23222322
return;
23232323

2324-
r = blkdev_issue_flush(mdev->ldev->md_bdev, GFP_KERNEL, NULL,
2325-
BLKDEV_IFL_WAIT);
2324+
r = blkdev_issue_flush(mdev->ldev->md_bdev, GFP_KERNEL, NULL);
23262325
if (r) {
23272326
set_bit(MD_NO_BARRIER, &mdev->flags);
23282327
dev_err(DEV, "meta data flush failed with status %d, disabling md-flushes\n", r);

drivers/block/drbd/drbd_receiver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ static enum finish_epoch drbd_flush_after_epoch(struct drbd_conf *mdev, struct d
975975

976976
if (mdev->write_ordering >= WO_bdev_flush && get_ldev(mdev)) {
977977
rv = blkdev_issue_flush(mdev->ldev->backing_bdev, GFP_KERNEL,
978-
NULL, BLKDEV_IFL_WAIT);
978+
NULL);
979979
if (rv) {
980980
dev_err(DEV, "local disk flush failed with status %d\n", rv);
981981
/* would rather check on EOPNOTSUPP, but that is not reliable.

fs/block_dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ int blkdev_fsync(struct file *filp, int datasync)
370370
*/
371371
mutex_unlock(&bd_inode->i_mutex);
372372

373-
error = blkdev_issue_flush(bdev, GFP_KERNEL, NULL, BLKDEV_IFL_WAIT);
373+
error = blkdev_issue_flush(bdev, GFP_KERNEL, NULL);
374374
if (error == -EOPNOTSUPP)
375375
error = 0;
376376

fs/btrfs/extent-tree.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,8 +1695,7 @@ static int remove_extent_backref(struct btrfs_trans_handle *trans,
16951695
static void btrfs_issue_discard(struct block_device *bdev,
16961696
u64 start, u64 len)
16971697
{
1698-
blkdev_issue_discard(bdev, start >> 9, len >> 9, GFP_KERNEL,
1699-
BLKDEV_IFL_WAIT);
1698+
blkdev_issue_discard(bdev, start >> 9, len >> 9, GFP_KERNEL, 0);
17001699
}
17011700

17021701
static int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr,

fs/ext3/fsync.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ int ext3_sync_file(struct file *file, int datasync)
9090
* storage
9191
*/
9292
if (needs_barrier)
93-
blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL,
94-
BLKDEV_IFL_WAIT);
93+
blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
9594
return ret;
9695
}

fs/ext4/fsync.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,9 @@ int ext4_sync_file(struct file *file, int datasync)
128128
(journal->j_fs_dev != journal->j_dev) &&
129129
(journal->j_flags & JBD2_BARRIER))
130130
blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL,
131-
NULL, BLKDEV_IFL_WAIT);
131+
NULL);
132132
ret = jbd2_log_wait_commit(journal, commit_tid);
133133
} else if (journal->j_flags & JBD2_BARRIER)
134-
blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL,
135-
BLKDEV_IFL_WAIT);
134+
blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
136135
return ret;
137136
}

fs/ext4/mballoc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2566,8 +2566,7 @@ static inline void ext4_issue_discard(struct super_block *sb,
25662566
discard_block = block + ext4_group_first_block_no(sb, block_group);
25672567
trace_ext4_discard_blocks(sb,
25682568
(unsigned long long) discard_block, count);
2569-
ret = sb_issue_discard(sb, discard_block, count, GFP_NOFS,
2570-
BLKDEV_IFL_WAIT);
2569+
ret = sb_issue_discard(sb, discard_block, count, GFP_NOFS, 0);
25712570
if (ret == EOPNOTSUPP) {
25722571
ext4_warning(sb, "discard not supported, disabling");
25732572
clear_opt(EXT4_SB(sb)->s_mount_opt, DISCARD);

fs/fat/fatent.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,7 @@ int fat_free_clusters(struct inode *inode, int cluster)
578578
sb_issue_discard(sb,
579579
fat_clus_to_blknr(sbi, first_cl),
580580
nr_clus * sbi->sec_per_clus,
581-
GFP_NOFS,
582-
BLKDEV_IFL_WAIT);
581+
GFP_NOFS, 0);
583582

584583
first_cl = cluster;
585584
}

fs/gfs2/rgrp.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,7 @@ static void gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset,
854854
if ((start + nr_sects) != blk) {
855855
rv = blkdev_issue_discard(bdev, start,
856856
nr_sects, GFP_NOFS,
857-
BLKDEV_IFL_WAIT);
857+
0);
858858
if (rv)
859859
goto fail;
860860
nr_sects = 0;
@@ -868,8 +868,7 @@ static void gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset,
868868
}
869869
}
870870
if (nr_sects) {
871-
rv = blkdev_issue_discard(bdev, start, nr_sects, GFP_NOFS,
872-
BLKDEV_IFL_WAIT);
871+
rv = blkdev_issue_discard(bdev, start, nr_sects, GFP_NOFS, 0);
873872
if (rv)
874873
goto fail;
875874
}

fs/jbd2/checkpoint.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,8 +532,7 @@ int jbd2_cleanup_journal_tail(journal_t *journal)
532532
*/
533533
if ((journal->j_fs_dev != journal->j_dev) &&
534534
(journal->j_flags & JBD2_BARRIER))
535-
blkdev_issue_flush(journal->j_fs_dev, GFP_KERNEL, NULL,
536-
BLKDEV_IFL_WAIT);
535+
blkdev_issue_flush(journal->j_fs_dev, GFP_KERNEL, NULL);
537536
if (!(journal->j_flags & JBD2_ABORT))
538537
jbd2_journal_update_superblock(journal, 1);
539538
return 0;

fs/jbd2/commit.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
684684
if (commit_transaction->t_flushed_data_blocks &&
685685
(journal->j_fs_dev != journal->j_dev) &&
686686
(journal->j_flags & JBD2_BARRIER))
687-
blkdev_issue_flush(journal->j_fs_dev, GFP_KERNEL, NULL,
688-
BLKDEV_IFL_WAIT);
687+
blkdev_issue_flush(journal->j_fs_dev, GFP_KERNEL, NULL);
689688

690689
/* Done it all: now write the commit record asynchronously. */
691690
if (JBD2_HAS_INCOMPAT_FEATURE(journal,
@@ -810,8 +809,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
810809
if (JBD2_HAS_INCOMPAT_FEATURE(journal,
811810
JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT) &&
812811
journal->j_flags & JBD2_BARRIER) {
813-
blkdev_issue_flush(journal->j_dev, GFP_KERNEL, NULL,
814-
BLKDEV_IFL_WAIT);
812+
blkdev_issue_flush(journal->j_dev, GFP_KERNEL, NULL);
815813
}
816814

817815
if (err)

fs/nilfs2/the_nilfs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ int nilfs_discard_segments(struct the_nilfs *nilfs, __u64 *segnump,
774774
ret = blkdev_issue_discard(nilfs->ns_bdev,
775775
start * sects_per_block,
776776
nblocks * sects_per_block,
777-
GFP_NOFS, BLKDEV_IFL_WAIT);
777+
GFP_NOFS, 0);
778778
if (ret < 0)
779779
return ret;
780780
nblocks = 0;
@@ -784,7 +784,7 @@ int nilfs_discard_segments(struct the_nilfs *nilfs, __u64 *segnump,
784784
ret = blkdev_issue_discard(nilfs->ns_bdev,
785785
start * sects_per_block,
786786
nblocks * sects_per_block,
787-
GFP_NOFS, BLKDEV_IFL_WAIT);
787+
GFP_NOFS, 0);
788788
return ret;
789789
}
790790

fs/reiserfs/file.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ static int reiserfs_sync_file(struct file *filp, int datasync)
152152
barrier_done = reiserfs_commit_for_inode(inode);
153153
reiserfs_write_unlock(inode->i_sb);
154154
if (barrier_done != 1 && reiserfs_barrier_flush(inode->i_sb))
155-
blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL,
156-
BLKDEV_IFL_WAIT);
155+
blkdev_issue_flush(inode->i_sb->s_bdev, GFP_KERNEL, NULL);
157156
if (barrier_done < 0)
158157
return barrier_done;
159158
return (err < 0) ? -EIO : 0;

fs/xfs/linux-2.6/xfs_super.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,7 @@ void
693693
xfs_blkdev_issue_flush(
694694
xfs_buftarg_t *buftarg)
695695
{
696-
blkdev_issue_flush(buftarg->bt_bdev, GFP_KERNEL, NULL,
697-
BLKDEV_IFL_WAIT);
696+
blkdev_issue_flush(buftarg->bt_bdev, GFP_KERNEL, NULL);
698697
}
699698

700699
STATIC void

include/linux/blkdev.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -867,18 +867,14 @@ static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt,
867867
return NULL;
868868
return bqt->tag_index[tag];
869869
}
870-
enum{
871-
BLKDEV_WAIT, /* wait for completion */
872-
BLKDEV_SECURE, /* secure discard */
873-
};
874-
#define BLKDEV_IFL_WAIT (1 << BLKDEV_WAIT)
875-
#define BLKDEV_IFL_SECURE (1 << BLKDEV_SECURE)
876-
extern int blkdev_issue_flush(struct block_device *, gfp_t, sector_t *,
877-
unsigned long);
870+
871+
#define BLKDEV_DISCARD_SECURE 0x01 /* secure discard */
872+
873+
extern int blkdev_issue_flush(struct block_device *, gfp_t, sector_t *);
878874
extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector,
879875
sector_t nr_sects, gfp_t gfp_mask, unsigned long flags);
880876
extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
881-
sector_t nr_sects, gfp_t gfp_mask, unsigned long flags);
877+
sector_t nr_sects, gfp_t gfp_mask);
882878
static inline int sb_issue_discard(struct super_block *sb, sector_t block,
883879
sector_t nr_blocks, gfp_t gfp_mask, unsigned long flags)
884880
{

mm/swapfile.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static int discard_swap(struct swap_info_struct *si)
141141
nr_blocks = ((sector_t)se->nr_pages - 1) << (PAGE_SHIFT - 9);
142142
if (nr_blocks) {
143143
err = blkdev_issue_discard(si->bdev, start_block,
144-
nr_blocks, GFP_KERNEL, BLKDEV_IFL_WAIT);
144+
nr_blocks, GFP_KERNEL, 0);
145145
if (err)
146146
return err;
147147
cond_resched();
@@ -152,7 +152,7 @@ static int discard_swap(struct swap_info_struct *si)
152152
nr_blocks = (sector_t)se->nr_pages << (PAGE_SHIFT - 9);
153153

154154
err = blkdev_issue_discard(si->bdev, start_block,
155-
nr_blocks, GFP_KERNEL, BLKDEV_IFL_WAIT);
155+
nr_blocks, GFP_KERNEL, 0);
156156
if (err)
157157
break;
158158

@@ -191,7 +191,7 @@ static void discard_swap_cluster(struct swap_info_struct *si,
191191
start_block <<= PAGE_SHIFT - 9;
192192
nr_blocks <<= PAGE_SHIFT - 9;
193193
if (blkdev_issue_discard(si->bdev, start_block,
194-
nr_blocks, GFP_NOIO, BLKDEV_IFL_WAIT))
194+
nr_blocks, GFP_NOIO, 0))
195195
break;
196196
}
197197

0 commit comments

Comments
 (0)