Skip to content

Commit 3a5e02c

Browse files
Mike Christieaxboe
authored andcommitted
block, drivers: add REQ_OP_FLUSH operation
This adds a REQ_OP_FLUSH operation that is sent to request_fn based drivers by the block layer's flush code, instead of sending requests with the request->cmd_flags REQ_FLUSH bit set. Signed-off-by: Mike Christie <mchristi@redhat.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Hannes Reinecke <hare@suse.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 4e1b2d5 commit 3a5e02c

20 files changed

Lines changed: 40 additions & 31 deletions

File tree

‎Documentation/block/writeback_cache_control.txt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ doing:
7373

7474
blk_queue_write_cache(sdkp->disk->queue, true, false);
7575

76-
and handle empty REQ_FLUSH requests in its prep_fn/request_fn. Note that
76+
and handle empty REQ_OP_FLUSH requests in its prep_fn/request_fn. Note that
7777
REQ_FLUSH requests with a payload are automatically turned into a sequence
78-
of an empty REQ_FLUSH request followed by the actual write by the block
78+
of an empty REQ_OP_FLUSH request followed by the actual write by the block
7979
layer. For devices that also support the FUA bit the block layer needs
8080
to be told to pass through the REQ_FUA bit using:
8181

8282
blk_queue_write_cache(sdkp->disk->queue, true, true);
8383

8484
and the driver must handle write requests that have the REQ_FUA bit set
8585
in prep_fn/request_fn. If the FUA bit is not natively supported the block
86-
layer turns it into an empty REQ_FLUSH request after the actual write.
86+
layer turns it into an empty REQ_OP_FLUSH request after the actual write.

‎arch/um/drivers/ubd_kern.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ static void do_ubd_request(struct request_queue *q)
12861286

12871287
req = dev->request;
12881288

1289-
if (req->cmd_flags & REQ_FLUSH) {
1289+
if (req_op(req) == REQ_OP_FLUSH) {
12901290
io_req = kmalloc(sizeof(struct io_thread_req),
12911291
GFP_ATOMIC);
12921292
if (io_req == NULL) {

‎block/blk-flush.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* The actual execution of flush is double buffered. Whenever a request
3030
* needs to execute PRE or POSTFLUSH, it queues at
3131
* fq->flush_queue[fq->flush_pending_idx]. Once certain criteria are met, a
32-
* flush is issued and the pending_idx is toggled. When the flush
32+
* REQ_OP_FLUSH is issued and the pending_idx is toggled. When the flush
3333
* completes, all the requests which were pending are proceeded to the next
3434
* step. This allows arbitrary merging of different types of FLUSH/FUA
3535
* requests.
@@ -330,7 +330,7 @@ static bool blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq)
330330
}
331331

332332
flush_rq->cmd_type = REQ_TYPE_FS;
333-
flush_rq->cmd_flags = WRITE_FLUSH | REQ_FLUSH_SEQ;
333+
req_set_op_attrs(flush_rq, REQ_OP_FLUSH, WRITE_FLUSH | REQ_FLUSH_SEQ);
334334
flush_rq->rq_disk = first_rq->rq_disk;
335335
flush_rq->end_io = flush_end_io;
336336

‎drivers/block/loop.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ static int do_req_filebacked(struct loop_device *lo, struct request *rq)
542542
pos = ((loff_t) blk_rq_pos(rq) << 9) + lo->lo_offset;
543543

544544
if (op_is_write(req_op(rq))) {
545-
if (rq->cmd_flags & REQ_FLUSH)
545+
if (req_op(rq) == REQ_OP_FLUSH)
546546
ret = lo_req_flush(lo, rq);
547547
else if (req_op(rq) == REQ_OP_DISCARD)
548548
ret = lo_discard(lo, rq, pos);
@@ -1659,7 +1659,7 @@ static int loop_queue_rq(struct blk_mq_hw_ctx *hctx,
16591659
if (lo->lo_state != Lo_bound)
16601660
return -EIO;
16611661

1662-
if (lo->use_dio && (!(cmd->rq->cmd_flags & REQ_FLUSH) ||
1662+
if (lo->use_dio && (req_op(cmd->rq) != REQ_OP_FLUSH ||
16631663
req_op(cmd->rq) == REQ_OP_DISCARD))
16641664
cmd->use_aio = true;
16651665
else

‎drivers/block/nbd.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static int nbd_send_req(struct nbd_device *nbd, struct request *req)
284284
type = NBD_CMD_DISC;
285285
else if (req_op(req) == REQ_OP_DISCARD)
286286
type = NBD_CMD_TRIM;
287-
else if (req->cmd_flags & REQ_FLUSH)
287+
else if (req_op(req) == REQ_OP_FLUSH)
288288
type = NBD_CMD_FLUSH;
289289
else if (rq_data_dir(req) == WRITE)
290290
type = NBD_CMD_WRITE;

‎drivers/block/osdblk.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static void osdblk_rq_fn(struct request_queue *q)
321321
* driver-specific, etc.
322322
*/
323323

324-
do_flush = rq->cmd_flags & REQ_FLUSH;
324+
do_flush = (req_op(rq) == REQ_OP_FLUSH);
325325
do_write = (rq_data_dir(rq) == WRITE);
326326

327327
if (!do_flush) { /* osd_flush does not use a bio */

‎drivers/block/ps3disk.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static void ps3disk_do_request(struct ps3_storage_device *dev,
196196
dev_dbg(&dev->sbd.core, "%s:%u\n", __func__, __LINE__);
197197

198198
while ((req = blk_fetch_request(q))) {
199-
if (req->cmd_flags & REQ_FLUSH) {
199+
if (req_op(req) == REQ_OP_FLUSH) {
200200
if (ps3disk_submit_flush_request(dev, req))
201201
break;
202202
} else if (req->cmd_type == REQ_TYPE_FS) {
@@ -256,7 +256,7 @@ static irqreturn_t ps3disk_interrupt(int irq, void *data)
256256
return IRQ_HANDLED;
257257
}
258258

259-
if (req->cmd_flags & REQ_FLUSH) {
259+
if (req_op(req) == REQ_OP_FLUSH) {
260260
read = 0;
261261
op = "flush";
262262
} else {

‎drivers/block/skd_main.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ static void skd_request_fn(struct request_queue *q)
597597
data_dir = rq_data_dir(req);
598598
io_flags = req->cmd_flags;
599599

600-
if (io_flags & REQ_FLUSH)
600+
if (req_op(req) == REQ_OP_FLUSH)
601601
flush++;
602602

603603
if (io_flags & REQ_FUA)

‎drivers/block/virtio_blk.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static int virtio_queue_rq(struct blk_mq_hw_ctx *hctx,
172172
BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems);
173173

174174
vbr->req = req;
175-
if (req->cmd_flags & REQ_FLUSH) {
175+
if (req_op(req) == REQ_OP_FLUSH) {
176176
vbr->out_hdr.type = cpu_to_virtio32(vblk->vdev, VIRTIO_BLK_T_FLUSH);
177177
vbr->out_hdr.sector = 0;
178178
vbr->out_hdr.ioprio = cpu_to_virtio32(vblk->vdev, req_get_ioprio(vbr->req));

‎drivers/block/xen-blkfront.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
743743
* The indirect operation can only be a BLKIF_OP_READ or
744744
* BLKIF_OP_WRITE
745745
*/
746-
BUG_ON(req->cmd_flags & (REQ_FLUSH | REQ_FUA));
746+
BUG_ON(req_op(req) == REQ_OP_FLUSH || req->cmd_flags & REQ_FUA);
747747
ring_req->operation = BLKIF_OP_INDIRECT;
748748
ring_req->u.indirect.indirect_op = rq_data_dir(req) ?
749749
BLKIF_OP_WRITE : BLKIF_OP_READ;
@@ -755,7 +755,7 @@ static int blkif_queue_rw_req(struct request *req, struct blkfront_ring_info *ri
755755
ring_req->u.rw.handle = info->handle;
756756
ring_req->operation = rq_data_dir(req) ?
757757
BLKIF_OP_WRITE : BLKIF_OP_READ;
758-
if (req->cmd_flags & (REQ_FLUSH | REQ_FUA)) {
758+
if (req_op(req) == REQ_OP_FLUSH || req->cmd_flags & REQ_FUA) {
759759
/*
760760
* Ideally we can do an unordered flush-to-disk.
761761
* In case the backend onlysupports barriers, use that.
@@ -865,7 +865,7 @@ static inline bool blkif_request_flush_invalid(struct request *req,
865865
struct blkfront_info *info)
866866
{
867867
return ((req->cmd_type != REQ_TYPE_FS) ||
868-
((req->cmd_flags & REQ_FLUSH) &&
868+
((req_op(req) == REQ_OP_FLUSH) &&
869869
!(info->feature_flush & REQ_FLUSH)) ||
870870
((req->cmd_flags & REQ_FUA) &&
871871
!(info->feature_flush & REQ_FUA)));
@@ -2055,7 +2055,7 @@ static int blkif_recover(struct blkfront_info *info)
20552055
/*
20562056
* Get the bios in the request so we can re-queue them.
20572057
*/
2058-
if (copy[i].request->cmd_flags & REQ_FLUSH ||
2058+
if (req_op(copy[i].request) == REQ_OP_FLUSH ||
20592059
req_op(copy[i].request) == REQ_OP_DISCARD ||
20602060
copy[i].request->cmd_flags & (REQ_FUA | REQ_SECURE)) {
20612061
/*

0 commit comments

Comments
 (0)