Commit ef295ecf authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

block: better op and flags encoding

Now that we don't need the common flags to overflow outside the range
of a 32-bit type we can encode them the same way for both the bio and
request fields.  This in addition allows us to place the operation
first (and make some room for more ops while we're at it) and to
stop having to shift around the operation values.

In addition this allows passing around only one value in the block layer
instead of two (and eventuall also in the file systems, but we can do
that later) and thus clean up a lot of code.

Last but not least this allows decreasing the size of the cmd_flags
field in struct request to 32-bits.  Various functions passing this
value could also be updated, but I'd like to avoid the churn for now.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent e8064021
...@@ -553,8 +553,8 @@ struct request { ...@@ -553,8 +553,8 @@ struct request {
struct request_list *rl; struct request_list *rl;
} }
See the rq_flag_bits definitions for an explanation of the various flags See the req_ops and req_flag_bits definitions for an explanation of the various
available. Some bits are used by the block layer or i/o scheduler. flags available. Some bits are used by the block layer or i/o scheduler.
The behaviour of the various sector counts are almost the same as before, The behaviour of the various sector counts are almost the same as before,
except that since we have multi-segment bios, current_nr_sectors refers except that since we have multi-segment bios, current_nr_sectors refers
......
...@@ -1056,8 +1056,7 @@ static struct io_context *rq_ioc(struct bio *bio) ...@@ -1056,8 +1056,7 @@ static struct io_context *rq_ioc(struct bio *bio)
/** /**
* __get_request - get a free request * __get_request - get a free request
* @rl: request list to allocate from * @rl: request list to allocate from
* @op: REQ_OP_READ/REQ_OP_WRITE * @op: operation and flags
* @op_flags: rq_flag_bits
* @bio: bio to allocate request for (can be %NULL) * @bio: bio to allocate request for (can be %NULL)
* @gfp_mask: allocation mask * @gfp_mask: allocation mask
* *
...@@ -1068,23 +1067,22 @@ static struct io_context *rq_ioc(struct bio *bio) ...@@ -1068,23 +1067,22 @@ static struct io_context *rq_ioc(struct bio *bio)
* Returns ERR_PTR on failure, with @q->queue_lock held. * Returns ERR_PTR on failure, with @q->queue_lock held.
* Returns request pointer on success, with @q->queue_lock *not held*. * Returns request pointer on success, with @q->queue_lock *not held*.
*/ */
static struct request *__get_request(struct request_list *rl, int op, static struct request *__get_request(struct request_list *rl, unsigned int op,
int op_flags, struct bio *bio, struct bio *bio, gfp_t gfp_mask)
gfp_t gfp_mask)
{ {
struct request_queue *q = rl->q; struct request_queue *q = rl->q;
struct request *rq; struct request *rq;
struct elevator_type *et = q->elevator->type; struct elevator_type *et = q->elevator->type;
struct io_context *ioc = rq_ioc(bio); struct io_context *ioc = rq_ioc(bio);
struct io_cq *icq = NULL; struct io_cq *icq = NULL;
const bool is_sync = rw_is_sync(op, op_flags) != 0; const bool is_sync = op_is_sync(op);
int may_queue; int may_queue;
req_flags_t rq_flags = RQF_ALLOCED; req_flags_t rq_flags = RQF_ALLOCED;
if (unlikely(blk_queue_dying(q))) if (unlikely(blk_queue_dying(q)))
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
may_queue = elv_may_queue(q, op, op_flags); may_queue = elv_may_queue(q, op);
if (may_queue == ELV_MQUEUE_NO) if (may_queue == ELV_MQUEUE_NO)
goto rq_starved; goto rq_starved;
...@@ -1154,7 +1152,7 @@ static struct request *__get_request(struct request_list *rl, int op, ...@@ -1154,7 +1152,7 @@ static struct request *__get_request(struct request_list *rl, int op,
blk_rq_init(q, rq); blk_rq_init(q, rq);
blk_rq_set_rl(rq, rl); blk_rq_set_rl(rq, rl);
req_set_op_attrs(rq, op, op_flags); rq->cmd_flags = op;
rq->rq_flags = rq_flags; rq->rq_flags = rq_flags;
/* init elvpriv */ /* init elvpriv */
...@@ -1232,8 +1230,7 @@ static struct request *__get_request(struct request_list *rl, int op, ...@@ -1232,8 +1230,7 @@ static struct request *__get_request(struct request_list *rl, int op,
/** /**
* get_request - get a free request * get_request - get a free request
* @q: request_queue to allocate request from * @q: request_queue to allocate request from
* @op: REQ_OP_READ/REQ_OP_WRITE * @op: operation and flags
* @op_flags: rq_flag_bits
* @bio: bio to allocate request for (can be %NULL) * @bio: bio to allocate request for (can be %NULL)
* @gfp_mask: allocation mask * @gfp_mask: allocation mask
* *
...@@ -1244,18 +1241,17 @@ static struct request *__get_request(struct request_list *rl, int op, ...@@ -1244,18 +1241,17 @@ static struct request *__get_request(struct request_list *rl, int op,
* Returns ERR_PTR on failure, with @q->queue_lock held. * Returns ERR_PTR on failure, with @q->queue_lock held.
* Returns request pointer on success, with @q->queue_lock *not held*. * Returns request pointer on success, with @q->queue_lock *not held*.
*/ */
static struct request *get_request(struct request_queue *q, int op, static struct request *get_request(struct request_queue *q, unsigned int op,
int op_flags, struct bio *bio, struct bio *bio, gfp_t gfp_mask)
gfp_t gfp_mask)
{ {
const bool is_sync = rw_is_sync(op, op_flags) != 0; const bool is_sync = op_is_sync(op);
DEFINE_WAIT(wait); DEFINE_WAIT(wait);
struct request_list *rl; struct request_list *rl;
struct request *rq; struct request *rq;
rl = blk_get_rl(q, bio); /* transferred to @rq on success */ rl = blk_get_rl(q, bio); /* transferred to @rq on success */
retry: retry:
rq = __get_request(rl, op, op_flags, bio, gfp_mask); rq = __get_request(rl, op, bio, gfp_mask);
if (!IS_ERR(rq)) if (!IS_ERR(rq))
return rq; return rq;
...@@ -1297,7 +1293,7 @@ static struct request *blk_old_get_request(struct request_queue *q, int rw, ...@@ -1297,7 +1293,7 @@ static struct request *blk_old_get_request(struct request_queue *q, int rw,
create_io_context(gfp_mask, q->node); create_io_context(gfp_mask, q->node);
spin_lock_irq(q->queue_lock); spin_lock_irq(q->queue_lock);
rq = get_request(q, rw, 0, NULL, gfp_mask); rq = get_request(q, rw, NULL, gfp_mask);
if (IS_ERR(rq)) { if (IS_ERR(rq)) {
spin_unlock_irq(q->queue_lock); spin_unlock_irq(q->queue_lock);
return rq; return rq;
...@@ -1446,7 +1442,7 @@ void __blk_put_request(struct request_queue *q, struct request *req) ...@@ -1446,7 +1442,7 @@ void __blk_put_request(struct request_queue *q, struct request *req)
*/ */
if (rq_flags & RQF_ALLOCED) { if (rq_flags & RQF_ALLOCED) {
struct request_list *rl = blk_rq_rl(req); struct request_list *rl = blk_rq_rl(req);
bool sync = rw_is_sync(req_op(req), req->cmd_flags); bool sync = op_is_sync(req->cmd_flags);
BUG_ON(!list_empty(&req->queuelist)); BUG_ON(!list_empty(&req->queuelist));
BUG_ON(ELV_ON_HASH(req)); BUG_ON(ELV_ON_HASH(req));
...@@ -1652,8 +1648,6 @@ unsigned int blk_plug_queued_count(struct request_queue *q) ...@@ -1652,8 +1648,6 @@ unsigned int blk_plug_queued_count(struct request_queue *q)
void init_request_from_bio(struct request *req, struct bio *bio) void init_request_from_bio(struct request *req, struct bio *bio)
{ {
req->cmd_type = REQ_TYPE_FS; req->cmd_type = REQ_TYPE_FS;
req->cmd_flags |= bio->bi_opf & REQ_COMMON_MASK;
if (bio->bi_opf & REQ_RAHEAD) if (bio->bi_opf & REQ_RAHEAD)
req->cmd_flags |= REQ_FAILFAST_MASK; req->cmd_flags |= REQ_FAILFAST_MASK;
...@@ -1665,9 +1659,8 @@ void init_request_from_bio(struct request *req, struct bio *bio) ...@@ -1665,9 +1659,8 @@ void init_request_from_bio(struct request *req, struct bio *bio)
static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio) static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio)
{ {
const bool sync = !!(bio->bi_opf & REQ_SYNC);
struct blk_plug *plug; struct blk_plug *plug;
int el_ret, rw_flags = 0, where = ELEVATOR_INSERT_SORT; int el_ret, where = ELEVATOR_INSERT_SORT;
struct request *req; struct request *req;
unsigned int request_count = 0; unsigned int request_count = 0;
...@@ -1722,24 +1715,11 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio) ...@@ -1722,24 +1715,11 @@ static blk_qc_t blk_queue_bio(struct request_queue *q, struct bio *bio)
} }
get_rq: get_rq:
/*
* This sync check and mask will be re-done in init_request_from_bio(),
* but we need to set it earlier to expose the sync flag to the
* rq allocator and io schedulers.
*/
if (sync)
rw_flags |= REQ_SYNC;
/*
* Add in META/PRIO flags, if set, before we get to the IO scheduler
*/
rw_flags |= (bio->bi_opf & (REQ_META | REQ_PRIO));
/* /*
* Grab a free request. This is might sleep but can not fail. * Grab a free request. This is might sleep but can not fail.
* Returns with the queue unlocked. * Returns with the queue unlocked.
*/ */
req = get_request(q, bio_data_dir(bio), rw_flags, bio, GFP_NOIO); req = get_request(q, bio->bi_opf, bio, GFP_NOIO);
if (IS_ERR(req)) { if (IS_ERR(req)) {
bio->bi_error = PTR_ERR(req); bio->bi_error = PTR_ERR(req);
bio_endio(bio); bio_endio(bio);
...@@ -2946,8 +2926,6 @@ EXPORT_SYMBOL_GPL(__blk_end_request_err); ...@@ -2946,8 +2926,6 @@ EXPORT_SYMBOL_GPL(__blk_end_request_err);
void blk_rq_bio_prep(struct request_queue *q, struct request *rq, void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
struct bio *bio) struct bio *bio)
{ {
req_set_op(rq, bio_op(bio));
if (bio_has_data(bio)) if (bio_has_data(bio))
rq->nr_phys_segments = bio_phys_segments(q, bio); rq->nr_phys_segments = bio_phys_segments(q, bio);
...@@ -3031,8 +3009,7 @@ EXPORT_SYMBOL_GPL(blk_rq_unprep_clone); ...@@ -3031,8 +3009,7 @@ EXPORT_SYMBOL_GPL(blk_rq_unprep_clone);
static void __blk_rq_prep_clone(struct request *dst, struct request *src) static void __blk_rq_prep_clone(struct request *dst, struct request *src)
{ {
dst->cpu = src->cpu; dst->cpu = src->cpu;
req_set_op_attrs(dst, req_op(src), dst->cmd_flags = src->cmd_flags | REQ_NOMERGE;
(src->cmd_flags & REQ_CLONE_MASK) | REQ_NOMERGE);
dst->cmd_type = src->cmd_type; dst->cmd_type = src->cmd_type;
dst->__sector = blk_rq_pos(src); dst->__sector = blk_rq_pos(src);
dst->__data_len = blk_rq_bytes(src); dst->__data_len = blk_rq_bytes(src);
...@@ -3537,8 +3514,11 @@ EXPORT_SYMBOL(blk_set_runtime_active); ...@@ -3537,8 +3514,11 @@ EXPORT_SYMBOL(blk_set_runtime_active);
int __init blk_dev_init(void) int __init blk_dev_init(void)
{ {
BUILD_BUG_ON(__REQ_NR_BITS > 8 * BUILD_BUG_ON(REQ_OP_LAST >= (1 << REQ_OP_BITS));
BUILD_BUG_ON(REQ_OP_BITS + REQ_FLAG_BITS > 8 *
FIELD_SIZEOF(struct request, cmd_flags)); FIELD_SIZEOF(struct request, cmd_flags));
BUILD_BUG_ON(REQ_OP_BITS + REQ_FLAG_BITS > 8 *
FIELD_SIZEOF(struct bio, bi_opf));
/* used for unplugging and affects IO latency/throughput - HIGHPRI */ /* used for unplugging and affects IO latency/throughput - HIGHPRI */
kblockd_workqueue = alloc_workqueue("kblockd", kblockd_workqueue = alloc_workqueue("kblockd",
......
...@@ -330,7 +330,7 @@ static bool blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq) ...@@ -330,7 +330,7 @@ static bool blk_kick_flush(struct request_queue *q, struct blk_flush_queue *fq)
} }
flush_rq->cmd_type = REQ_TYPE_FS; flush_rq->cmd_type = REQ_TYPE_FS;
req_set_op_attrs(flush_rq, REQ_OP_FLUSH, WRITE_FLUSH); flush_rq->cmd_flags = REQ_OP_FLUSH | WRITE_FLUSH;
flush_rq->rq_flags |= RQF_FLUSH_SEQ; flush_rq->rq_flags |= RQF_FLUSH_SEQ;
flush_rq->rq_disk = first_rq->rq_disk; flush_rq->rq_disk = first_rq->rq_disk;
flush_rq->end_io = flush_end_io; flush_rq->end_io = flush_end_io;
......
...@@ -29,7 +29,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, ...@@ -29,7 +29,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
struct request_queue *q = bdev_get_queue(bdev); struct request_queue *q = bdev_get_queue(bdev);
struct bio *bio = *biop; struct bio *bio = *biop;
unsigned int granularity; unsigned int granularity;
enum req_op op; unsigned int op;
int alignment; int alignment;
sector_t bs_mask; sector_t bs_mask;
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
int blk_rq_append_bio(struct request *rq, struct bio *bio) int blk_rq_append_bio(struct request *rq, struct bio *bio)
{ {
if (!rq->bio) { if (!rq->bio) {
rq->cmd_flags &= REQ_OP_MASK;
rq->cmd_flags |= (bio->bi_opf & REQ_OP_MASK);
blk_rq_bio_prep(rq->q, rq, bio); blk_rq_bio_prep(rq->q, rq, bio);
} else { } else {
if (!ll_back_merge_fn(rq->q, rq, bio)) if (!ll_back_merge_fn(rq->q, rq, bio))
......
...@@ -139,14 +139,13 @@ bool blk_mq_can_queue(struct blk_mq_hw_ctx *hctx) ...@@ -139,14 +139,13 @@ bool blk_mq_can_queue(struct blk_mq_hw_ctx *hctx)
EXPORT_SYMBOL(blk_mq_can_queue); EXPORT_SYMBOL(blk_mq_can_queue);
static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx, static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx,
struct request *rq, int op, struct request *rq, unsigned int op)
unsigned int op_flags)
{ {
INIT_LIST_HEAD(&rq->queuelist); INIT_LIST_HEAD(&rq->queuelist);
/* csd/requeue_work/fifo_time is initialized before use */ /* csd/requeue_work/fifo_time is initialized before use */
rq->q = q; rq->q = q;
rq->mq_ctx = ctx; rq->mq_ctx = ctx;
req_set_op_attrs(rq, op, op_flags); rq->cmd_flags = op;
if (blk_queue_io_stat(q)) if (blk_queue_io_stat(q))
rq->rq_flags |= RQF_IO_STAT; rq->rq_flags |= RQF_IO_STAT;
/* do not touch atomic flags, it needs atomic ops against the timer */ /* do not touch atomic flags, it needs atomic ops against the timer */
...@@ -183,11 +182,11 @@ static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx, ...@@ -183,11 +182,11 @@ static void blk_mq_rq_ctx_init(struct request_queue *q, struct blk_mq_ctx *ctx,
rq->end_io_data = NULL; rq->end_io_data = NULL;
rq->next_rq = NULL; rq->next_rq = NULL;
ctx->rq_dispatched[rw_is_sync(op, op_flags)]++; ctx->rq_dispatched[op_is_sync(op)]++;
} }
static struct request * static struct request *
__blk_mq_alloc_request(struct blk_mq_alloc_data *data, int op, int op_flags) __blk_mq_alloc_request(struct blk_mq_alloc_data *data, unsigned int op)
{ {
struct request *rq; struct request *rq;
unsigned int tag; unsigned int tag;
...@@ -202,7 +201,7 @@ __blk_mq_alloc_request(struct blk_mq_alloc_data *data, int op, int op_flags) ...@@ -202,7 +201,7 @@ __blk_mq_alloc_request(struct blk_mq_alloc_data *data, int op, int op_flags)
} }
rq->tag = tag; rq->tag = tag;
blk_mq_rq_ctx_init(data->q, data->ctx, rq, op, op_flags); blk_mq_rq_ctx_init(data->q, data->ctx, rq, op);
return rq; return rq;
} }
...@@ -225,7 +224,7 @@ struct request *blk_mq_alloc_request(struct request_queue *q, int rw, ...@@ -225,7 +224,7 @@ struct request *blk_mq_alloc_request(struct request_queue *q, int rw,
ctx = blk_mq_get_ctx(q); ctx = blk_mq_get_ctx(q);
hctx = blk_mq_map_queue(q, ctx->cpu); hctx = blk_mq_map_queue(q, ctx->cpu);
blk_mq_set_alloc_data(&alloc_data, q, flags, ctx, hctx); blk_mq_set_alloc_data(&alloc_data, q, flags, ctx, hctx);
rq = __blk_mq_alloc_request(&alloc_data, rw, 0); rq = __blk_mq_alloc_request(&alloc_data, rw);
blk_mq_put_ctx(ctx); blk_mq_put_ctx(ctx);
if (!rq) { if (!rq) {
...@@ -277,7 +276,7 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q, int rw, ...@@ -277,7 +276,7 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q, int rw,
ctx = __blk_mq_get_ctx(q, cpumask_first(hctx->cpumask)); ctx = __blk_mq_get_ctx(q, cpumask_first(hctx->cpumask));
blk_mq_set_alloc_data(&alloc_data, q, flags, ctx, hctx); blk_mq_set_alloc_data(&alloc_data, q, flags, ctx, hctx);
rq = __blk_mq_alloc_request(&alloc_data, rw, 0); rq = __blk_mq_alloc_request(&alloc_data, rw);
if (!rq) { if (!rq) {
ret = -EWOULDBLOCK; ret = -EWOULDBLOCK;
goto out_queue_exit; goto out_queue_exit;
...@@ -1196,19 +1195,14 @@ static struct request *blk_mq_map_request(struct request_queue *q, ...@@ -1196,19 +1195,14 @@ static struct request *blk_mq_map_request(struct request_queue *q,
struct blk_mq_hw_ctx *hctx; struct blk_mq_hw_ctx *hctx;
struct blk_mq_ctx *ctx; struct blk_mq_ctx *ctx;
struct request *rq; struct request *rq;
int op = bio_data_dir(bio);
int op_flags = 0;
blk_queue_enter_live(q); blk_queue_enter_live(q);
ctx = blk_mq_get_ctx(q); ctx = blk_mq_get_ctx(q);
hctx = blk_mq_map_queue(q, ctx->cpu); hctx = blk_mq_map_queue(q, ctx->cpu);
if (rw_is_sync(bio_op(bio), bio->bi_opf)) trace_block_getrq(q, bio, bio->bi_opf);
op_flags |= REQ_SYNC;
trace_block_getrq(q, bio, op);
blk_mq_set_alloc_data(data, q, 0, ctx, hctx); blk_mq_set_alloc_data(data, q, 0, ctx, hctx);
rq = __blk_mq_alloc_request(data, op, op_flags); rq = __blk_mq_alloc_request(data, bio->bi_opf);
data->hctx->queued++; data->hctx->queued++;
return rq; return rq;
...@@ -1256,7 +1250,7 @@ static int blk_mq_direct_issue_request(struct request *rq, blk_qc_t *cookie) ...@@ -1256,7 +1250,7 @@ static int blk_mq_direct_issue_request(struct request *rq, blk_qc_t *cookie)
*/ */
static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
{ {
const int is_sync = rw_is_sync(bio_op(bio), bio->bi_opf); const int is_sync = op_is_sync(bio->bi_opf);
const int is_flush_fua = bio->bi_opf & (REQ_PREFLUSH | REQ_FUA); const int is_flush_fua = bio->bi_opf & (REQ_PREFLUSH | REQ_FUA);
struct blk_mq_alloc_data data; struct blk_mq_alloc_data data;
struct request *rq; struct request *rq;
...@@ -1350,7 +1344,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio) ...@@ -1350,7 +1344,7 @@ static blk_qc_t blk_mq_make_request(struct request_queue *q, struct bio *bio)
*/ */
static blk_qc_t blk_sq_make_request(struct request_queue *q, struct bio *bio) static blk_qc_t blk_sq_make_request(struct request_queue *q, struct bio *bio)
{ {
const int is_sync = rw_is_sync(bio_op(bio), bio->bi_opf); const int is_sync = op_is_sync(bio->bi_opf);
const int is_flush_fua = bio->bi_opf & (REQ_PREFLUSH | REQ_FUA); const int is_flush_fua = bio->bi_opf & (REQ_PREFLUSH | REQ_FUA);
struct blk_plug *plug; struct blk_plug *plug;
unsigned int request_count = 0; unsigned int request_count = 0;
......
...@@ -667,10 +667,10 @@ static inline void cfqg_put(struct cfq_group *cfqg) ...@@ -667,10 +667,10 @@ static inline void cfqg_put(struct cfq_group *cfqg)
} while (0) } while (0)
static inline void cfqg_stats_update_io_add(struct cfq_group *cfqg, static inline void cfqg_stats_update_io_add(struct cfq_group *cfqg,
struct cfq_group *curr_cfqg, int op, struct cfq_group *curr_cfqg,
int op_flags) unsigned int op)
{ {
blkg_rwstat_add(&cfqg->stats.queued, op, op_flags, 1); blkg_rwstat_add(&cfqg->stats.queued, op, 1);
cfqg_stats_end_empty_time(&cfqg->stats); cfqg_stats_end_empty_time(&cfqg->stats);
cfqg_stats_set_start_group_wait_time(cfqg, curr_cfqg); cfqg_stats_set_start_group_wait_time(cfqg, curr_cfqg);
} }
...@@ -684,30 +684,29 @@ static inline void cfqg_stats_update_timeslice_used(struct cfq_group *cfqg, ...@@ -684,30 +684,29 @@ static inline void cfqg_stats_update_timeslice_used(struct cfq_group *cfqg,
#endif #endif
} }
static inline void cfqg_stats_update_io_remove(struct cfq_group *cfqg, int op, static inline void cfqg_stats_update_io_remove(struct cfq_group *cfqg,
int op_flags) unsigned int op)
{ {
blkg_rwstat_add(&cfqg->stats.queued, op, op_flags, -1); blkg_rwstat_add(&cfqg->stats.queued, op, -1);
} }
static inline void cfqg_stats_update_io_merged(struct cfq_group *cfqg, int op, static inline void cfqg_stats_update_io_merged(struct cfq_group *cfqg,
int op_flags) unsigned int op)
{ {
blkg_rwstat_add(&cfqg->stats.merged, op, op_flags, 1); blkg_rwstat_add(&cfqg->stats.merged, op, 1);
} }
static inline void cfqg_stats_update_completion(struct cfq_group *cfqg, static inline void cfqg_stats_update_completion(struct cfq_group *cfqg,
uint64_t start_time, uint64_t io_start_time, int op, uint64_t start_time, uint64_t io_start_time,
int op_flags) unsigned int op)
{ {
struct cfqg_stats *stats = &cfqg->stats; struct cfqg_stats *stats = &cfqg->stats;
unsigned long long now = sched_clock(); unsigned long long now = sched_clock();
if (time_after64(now, io_start_time)) if (time_after64(now, io_start_time))
blkg_rwstat_add(&stats->service_time, op, op_flags, blkg_rwstat_add(&stats->service_time, op, now - io_start_time);
now - io_start_time);
if (time_after64(io_start_time, start_time)) if (time_after64(io_start_time, start_time))
blkg_rwstat_add(&stats->wait_time, op, op_flags, blkg_rwstat_add(&stats->wait_time, op,
io_start_time - start_time); io_start_time - start_time);
} }
...@@ -786,16 +785,16 @@ static inline void cfqg_put(struct cfq_group *cfqg) { } ...@@ -786,16 +785,16 @@ static inline void cfqg_put(struct cfq_group *cfqg) { }
#define cfq_log_cfqg(cfqd, cfqg, fmt, args...) do {} while (0) #define cfq_log_cfqg(cfqd, cfqg, fmt, args...) do {} while (0)
static inline void cfqg_stats_update_io_add(struct cfq_group *cfqg, static inline void cfqg_stats_update_io_add(struct cfq_group *cfqg,
struct cfq_group *curr_cfqg, int op, int op_flags) { } struct cfq_group *curr_cfqg, unsigned int op) { }
static inline void cfqg_stats_update_timeslice_used(struct cfq_group *cfqg, static inline void cfqg_stats_update_timeslice_used(struct cfq_group *cfqg,
uint64_t time, unsigned long unaccounted_time) { } uint64_t time, unsigned long unaccounted_time) { }
static inline void cfqg_stats_update_io_remove(struct cfq_group *cfqg, int op, static inline void cfqg_stats_update_io_remove(struct cfq_group *cfqg,
int op_flags) { } unsigned int op) { }
static inline void cfqg_stats_update_io_merged(struct cfq_group *cfqg, int op, static inline void cfqg_stats_update_io_merged(struct cfq_group *cfqg,
int op_flags) { } unsigned int op) { }
static inline void cfqg_stats_update_completion(struct cfq_group *cfqg, static inline void cfqg_stats_update_completion(struct cfq_group *cfqg,
uint64_t start_time, uint64_t io_start_time, int op, uint64_t start_time, uint64_t io_start_time,
int op_flags) { } unsigned int op) { }
#endif /* CONFIG_CFQ_GROUP_IOSCHED */ #endif /* CONFIG_CFQ_GROUP_IOSCHED */
...@@ -2474,10 +2473,10 @@ static void cfq_reposition_rq_rb(struct cfq_queue *cfqq, struct request *rq) ...@@ -2474,10 +2473,10 @@ static void cfq_reposition_rq_rb(struct cfq_queue *cfqq, struct request *rq)
{ {
elv_rb_del(&cfqq->sort_list, rq); elv_rb_del(&cfqq->sort_list, rq);
cfqq->queued[rq_is_sync(rq)]--; cfqq->queued[rq_is_sync(rq)]--;
cfqg_stats_update_io_remove(RQ_CFQG(rq), req_op(rq), rq->cmd_flags); cfqg_stats_update_io_remove(RQ_CFQG(rq), rq->cmd_flags);
cfq_add_rq_rb(rq); cfq_add_rq_rb(rq);
cfqg_stats_update_io_add(RQ_CFQG(rq), cfqq->cfqd->serving_group, cfqg_stats_update_io_add(RQ_CFQG(rq), cfqq->cfqd->serving_group,
req_op(rq), rq->cmd_flags); rq->cmd_flags);
} }
static struct request * static struct request *
...@@ -2530,7 +2529,7 @@ static void cfq_remove_request(struct request *rq) ...@@ -2530,7 +2529,7 @@ static void cfq_remove_request(struct request *rq)
cfq_del_rq_rb(rq); cfq_del_rq_rb(rq);
cfqq->cfqd->rq_queued--; cfqq->cfqd->rq_queued--;
cfqg_stats_update_io_remove(RQ_CFQG(rq), req_op(rq), rq->cmd_flags); cfqg_stats_update_io_remove(RQ_CFQG(rq), rq->cmd_flags);
if (rq->cmd_flags & REQ_PRIO) { if (rq->cmd_flags & REQ_PRIO) {
WARN_ON(!cfqq->prio_pending); WARN_ON(!cfqq->prio_pending);
cfqq->prio_pending--; cfqq->prio_pending--;
...@@ -2565,7 +2564,7 @@ static void cfq_merged_request(struct request_queue *q, struct request *req, ...@@ -2565,7 +2564,7 @@ static void cfq_merged_request(struct request_queue *q, struct request *req,
static void cfq_bio_merged(struct request_queue *q, struct request *req, static void cfq_bio_merged(struct request_queue *q, struct request *req,
struct bio *bio) struct bio *bio)
{ {
cfqg_stats_update_io_merged(RQ_CFQG(req), bio_op(bio), bio->bi_opf); cfqg_stats_update_io_merged(RQ_CFQG(req), bio->bi_opf);
} }
static void static void
...@@ -2588,7 +2587,7 @@ cfq_merged_requests(struct request_queue *q, struct request *rq, ...@@ -2588,7 +2587,7 @@ cfq_merged_requests(struct request_queue *q, struct request *rq,
if (cfqq->next_rq == next) if (cfqq->next_rq == next)
cfqq->next_rq = rq; cfqq->next_rq = rq;
cfq_remove_request(next); cfq_remove_request(next);
cfqg_stats_update_io_merged(RQ_CFQG(rq), req_op(next), next->cmd_flags); cfqg_stats_update_io_merged(RQ_CFQG(rq), next->cmd_flags);
cfqq = RQ_CFQQ(next); cfqq = RQ_CFQQ(next);
/* /*
...@@ -4142,7 +4141,7 @@ static void cfq_insert_request(struct request_queue *q, struct request *rq) ...@@ -4142,7 +4141,7 @@ static void cfq_insert_request(struct request_queue *q, struct request *rq)
rq->fifo_time = ktime_get_ns() + cfqd->cfq_fifo_expire[rq_is_sync(rq)]; rq->fifo_time = ktime_get_ns() + cfqd->cfq_fifo_expire[rq_is_sync(rq)];
list_add_tail(&rq->queuelist, &cfqq->fifo); list_add_tail(&rq->queuelist, &cfqq->fifo);
cfq_add_rq_rb(rq); cfq_add_rq_rb(rq);
cfqg_stats_update_io_add(RQ_CFQG(rq), cfqd->serving_group, req_op(rq), cfqg_stats_update_io_add(RQ_CFQG(rq), cfqd->serving_group,
rq->cmd_flags); rq->cmd_flags);
cfq_rq_enqueued(cfqd, cfqq, rq); cfq_rq_enqueued(cfqd, cfqq, rq);
} }
...@@ -4240,8 +4239,7 @@ static void cfq_completed_request(struct request_queue *q, struct request *rq) ...@@ -4240,8 +4239,7 @@ static void cfq_completed_request(struct request_queue *q, struct request *rq)
cfqq->dispatched--; cfqq->dispatched--;
(RQ_CFQG(rq))->dispatched--; (RQ_CFQG(rq))->dispatched--;
cfqg_stats_update_completion(cfqq->cfqg, rq_start_time_ns(rq), cfqg_stats_update_completion(cfqq->cfqg, rq_start_time_ns(rq),
rq_io_start_time_ns(rq), req_op(rq), rq_io_start_time_ns(rq), rq->cmd_flags);
rq->cmd_flags);
cfqd->rq_in_flight[cfq_cfqq_sync(cfqq)]--; cfqd->rq_in_flight[cfq_cfqq_sync(cfqq)]--;
...@@ -4319,14 +4317,14 @@ static void cfq_completed_request(struct request_queue *q, struct request *rq) ...@@ -4319,14 +4317,14 @@ static void cfq_completed_request(struct request_queue *q, struct request *rq)
cfq_schedule_dispatch(cfqd); cfq_schedule_dispatch(cfqd);
} }
static void cfqq_boost_on_prio(struct cfq_queue *cfqq, int op_flags) static void cfqq_boost_on_prio(struct cfq_queue *cfqq, unsigned int op)
{ {
/* /*
* If REQ_PRIO is set, boost class and prio level, if it's below * If REQ_PRIO is set, boost class and prio level, if it's below
* BE/NORM. If prio is not set, restore the potentially boosted * BE/NORM. If prio is not set, restore the potentially boosted
* class/prio level. * class/prio level.
*/ */
if (!(op_flags & REQ_PRIO)) { if (!(op & REQ_PRIO)) {
cfqq->ioprio_class = cfqq->org_ioprio_class; cfqq->ioprio_class = cfqq->org_ioprio_class;
cfqq->ioprio = cfqq->org_ioprio; cfqq->ioprio = cfqq->org_ioprio;
} else { } else {
...@@ -4347,7 +4345,7 @@ static inline int __cfq_may_queue(struct cfq_queue *cfqq) ...@@ -4347,7 +4345,7 @@ static inline int __cfq_may_queue(struct cfq_queue *cfqq)
return ELV_MQUEUE_MAY; return ELV_MQUEUE_MAY;
} }
static int cfq_may_queue(struct request_queue *q, int op, int op_flags) static int cfq_may_queue(struct request_queue *q, unsigned int op)
{ {
struct cfq_data *cfqd = q->elevator->elevator_data; struct cfq_data *cfqd = q->elevator->elevator_data;
struct task_struct *tsk = current; struct task_struct *tsk = current;
...@@ -4364,10 +4362,10 @@ static int cfq_may_queue(struct request_queue *q, int op, int op_flags) ...@@ -4364,10 +4362,10 @@ static int cfq_may_queue(struct request_queue *q, int op, int op_flags)
if (!cic) if (!cic)
return ELV_MQUEUE_MAY; return ELV_MQUEUE_MAY;
cfqq = cic_to_cfqq(cic, rw_is_sync(op, op_flags)); cfqq = cic_to_cfqq(cic, op_is_sync(op));
if (cfqq) { if (cfqq) {
cfq_init_prio_data(cfqq, cic); cfq_init_prio_data(cfqq, cic);
cfqq_boost_on_prio(cfqq, op_flags); cfqq_boost_on_prio(cfqq, op);
return __cfq_may_queue(cfqq); return __cfq_may_queue(cfqq);
} }
......
...@@ -714,12 +714,12 @@ void elv_put_request(struct request_queue *q, struct request *rq) ...@@ -714,12 +714,12 @@ void elv_put_request(struct request_queue *q, struct request *rq)
e->type->ops.elevator_put_req_fn(rq); e->type->ops.elevator_put_req_fn(rq);
} }
int elv_may_queue(struct request_queue *q, int op, int op_flags) int elv_may_queue(struct request_queue *q, unsigned int op)
{ {
struct elevator_queue *e = q->elevator; struct elevator_queue *e = q->elevator;
if (e->type->ops.elevator_may_queue_fn) if (e->type->ops.elevator_may_queue_fn)
return e->type->ops.elevator_may_queue_fn(q, op, op_flags); return e->type->ops.elevator_may_queue_fn(q, op);
return ELV_MQUEUE_MAY; return ELV_MQUEUE_MAY;
} }
......
...@@ -1135,7 +1135,7 @@ static void clone_init(struct dm_crypt_io *io, struct bio *clone) ...@@ -1135,7 +1135,7 @@ static void clone_init(struct dm_crypt_io *io, struct bio *clone)
clone->bi_private = io; clone->bi_private = io;
clone->bi_end_io = crypt_endio; clone->bi_end_io = crypt_endio;
clone->bi_bdev = cc->dev->bdev; clone->bi_bdev = cc->dev->bdev;
bio_set_op_attrs(clone, bio_op(io->base_bio), bio_flags(io->base_bio)); clone->bi_opf = io->base_bio->bi_opf;
} }
static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp) static int kcryptd_io_read(struct dm_crypt_io *io, gfp_t gfp)
......
...@@ -1031,8 +1031,7 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt) ...@@ -1031,8 +1031,7 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt)
} else if (rq_data_dir(rq) == READ) { } else if (rq_data_dir(rq) == READ) {
SCpnt->cmnd[0] = READ_6; SCpnt->cmnd[0] = READ_6;
} else { } else {
scmd_printk(KERN_ERR, SCpnt, "Unknown command %llu,%llx\n", scmd_printk(KERN_ERR, SCpnt, "Unknown command %d\n", req_op(rq));
req_op(rq), (unsigned long long) rq->cmd_flags);
goto out; goto out;
} }
......
...@@ -8427,7 +8427,7 @@ static int btrfs_submit_direct_hook(struct btrfs_dio_private *dip, ...@@ -8427,7 +8427,7 @@ static int btrfs_submit_direct_hook(struct btrfs_dio_private *dip,
if (!bio) if (!bio)
return -ENOMEM; return -ENOMEM;
bio_set_op_attrs(bio, bio_op(orig_bio), bio_flags(orig_bio)); bio->bi_opf = orig_bio->bi_opf;
bio->bi_private = dip; bio->bi_private = dip;
bio->bi_end_io = btrfs_end_dio_bio; bio->bi_end_io = btrfs_end_dio_bio;
btrfs_io_bio(bio)->logical = file_offset; btrfs_io_bio(bio)->logical = file_offset;
...@@ -8465,8 +8465,7 @@ static int btrfs_submit_direct_hook(struct btrfs_dio_private *dip, ...@@ -8465,8 +8465,7 @@ static int btrfs_submit_direct_hook(struct btrfs_dio_private *dip,
start_sector, GFP_NOFS); start_sector, GFP_NOFS);
if (!bio) if (!bio)
goto out_err; goto out_err;
bio_set_op_attrs(bio, bio_op(orig_bio), bio->bi_opf = orig_bio->bi_opf;
bio_flags(orig_bio));
bio->bi_private = dip; bio->bi_private = dip;
bio->bi_end_io = btrfs_end_dio_bio; bio->bi_end_io = btrfs_end_dio_bio;
btrfs_io_bio(bio)->logical = file_offset; btrfs_io_bio(bio)->logical = file_offset;
......
...@@ -3118,7 +3118,7 @@ EXPORT_SYMBOL(submit_bh); ...@@ -3118,7 +3118,7 @@ EXPORT_SYMBOL(submit_bh);
/** /**
* ll_rw_block: low-level access to block devices (DEPRECATED) * ll_rw_block: low-level access to block devices (DEPRECATED)
* @op: whether to %READ or %WRITE * @op: whether to %READ or %WRITE
* @op_flags: rq_flag_bits * @op_flags: req_flag_bits
* @nr: number of &struct buffer_heads in the array * @nr: number of &struct buffer_heads in the array
* @bhs: array of pointers to &struct buffer_head * @bhs: array of pointers to &struct buffer_head
* *
......
...@@ -688,7 +688,7 @@ struct f2fs_io_info { ...@@ -688,7 +688,7 @@ struct f2fs_io_info {
struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */
enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ enum page_type type; /* contains DATA/NODE/META/META_FLUSH */
int op; /* contains REQ_OP_ */ int op; /* contains REQ_OP_ */
int op_flags; /* rq_flag_bits */ int op_flags; /* req_flag_bits */
block_t new_blkaddr; /* new block address to be written */ block_t new_blkaddr; /* new block address to be written */
block_t old_blkaddr; /* old block address before Cow */ block_t old_blkaddr; /* old block address before Cow */
struct page *page; /* page to be written */ struct page *page; /* page to be written */
......
...@@ -231,7 +231,7 @@ static void gfs2_end_log_write(struct bio *bio) ...@@ -231,7 +231,7 @@ static void gfs2_end_log_write(struct bio *bio)
* gfs2_log_flush_bio - Submit any pending log bio * gfs2_log_flush_bio - Submit any pending log bio
* @sdp: The superblock * @sdp: The superblock
* @op: REQ_OP * @op: REQ_OP
* @op_flags: rq_flag_bits * @op_flags: req_flag_bits
* *
* Submit any pending part-built or full bio to the block device. If * Submit any pending part-built or full bio to the block device. If
* there is no pending bio, then this is a no-op. * there is no pending bio, then this is a no-op.
......
...@@ -581,15 +581,14 @@ static inline void blkg_rwstat_exit(struct blkg_rwstat *rwstat) ...@@ -581,15 +581,14 @@ static inline void blkg_rwstat_exit(struct blkg_rwstat *rwstat)
/** /**
* blkg_rwstat_add - add a value to a blkg_rwstat * blkg_rwstat_add - add a value to a blkg_rwstat
* @rwstat: target blkg_rwstat * @rwstat: target blkg_rwstat
* @op: REQ_OP * @op: REQ_OP and flags
* @op_flags: rq_flag_bits
* @val: value to add * @val: value to add
* *
* Add @val to @rwstat. The counters are chosen according to @rw. The * Add @val to @rwstat. The counters are chosen according to @rw. The
* caller is responsible for synchronizing calls to this function. * caller is responsible for synchronizing calls to this function.
*/ */
static inline void blkg_rwstat_add(struct blkg_rwstat *rwstat, static inline void blkg_rwstat_add(struct blkg_rwstat *rwstat,
int op, int op_flags, uint64_t val) unsigned int op, uint64_t val)
{ {
struct percpu_counter *cnt; struct percpu_counter *cnt;
...@@ -600,7 +599,7 @@ static inline void blkg_rwstat_add(struct blkg_rwstat *rwstat, ...@@ -600,7 +599,7 @@ static inline void blkg_rwstat_add(struct blkg_rwstat *rwstat,
__percpu_counter_add(cnt, val, BLKG_STAT_CPU_BATCH); __percpu_counter_add(cnt, val, BLKG_STAT_CPU_BATCH);
if (op_flags & REQ_SYNC) if (op & REQ_SYNC)
cnt = &rwstat->cpu_cnt[BLKG_RWSTAT_SYNC]; cnt = &rwstat->cpu_cnt[BLKG_RWSTAT_SYNC];
else else
cnt = &rwstat->cpu_cnt[BLKG_RWSTAT_ASYNC]; cnt = &rwstat->cpu_cnt[BLKG_RWSTAT_ASYNC];
...@@ -705,9 +704,9 @@ static inline bool blkcg_bio_issue_check(struct request_queue *q, ...@@ -705,9 +704,9 @@ static inline bool blkcg_bio_issue_check(struct request_queue *q,
if (!throtl) { if (!throtl) {
blkg = blkg ?: q->root_blkg; blkg = blkg ?: q->root_blkg;
blkg_rwstat_add(&blkg->stat_bytes, bio_op(bio), bio->bi_opf, blkg_rwstat_add(&blkg->stat_bytes, bio->bi_opf,
bio->bi_iter.bi_size); bio->bi_iter.bi_size);
blkg_rwstat_add(&blkg->stat_ios, bio_op(bio), bio->bi_opf, 1); blkg_rwstat_add(&blkg->stat_ios, bio->bi_opf, 1);
} }
rcu_read_unlock(); rcu_read_unlock();
......
...@@ -88,24 +88,6 @@ struct bio { ...@@ -88,24 +88,6 @@ struct bio {
struct bio_vec bi_inline_vecs[0]; struct bio_vec bi_inline_vecs[0];
}; };
#define BIO_OP_SHIFT (8 * FIELD_SIZEOF(struct bio, bi_opf) - REQ_OP_BITS)
#define bio_flags(bio) ((bio)->bi_opf & ((1 << BIO_OP_SHIFT) - 1))
#define bio_op(bio) ((bio)->bi_opf >> BIO_OP_SHIFT)
#define bio_set_op_attrs(bio, op, op_flags) do { \
if (__builtin_constant_p(op)) \
BUILD_BUG_ON((op) + 0U >= (1U << REQ_OP_BITS)); \
else \
WARN_ON_ONCE((op) + 0U >= (1U << REQ_OP_BITS)); \
if (__builtin_constant_p(op_flags)) \
BUILD_BUG_ON((op_flags) + 0U >= (1U << BIO_OP_SHIFT)); \
else \
WARN_ON_ONCE((op_flags) + 0U >= (1U << BIO_OP_SHIFT)); \
(bio)->bi_opf = bio_flags(bio); \
(bio)->bi_opf |= (((op) + 0U) << BIO_OP_SHIFT); \
(bio)->bi_opf |= (op_flags); \
} while (0)
#define BIO_RESET_BYTES offsetof(struct bio, bi_max_vecs) #define BIO_RESET_BYTES offsetof(struct bio, bi_max_vecs)
/* /*
...@@ -147,26 +129,40 @@ struct bio { ...@@ -147,26 +129,40 @@ struct bio {
#endif /* CONFIG_BLOCK */ #endif /* CONFIG_BLOCK */
/* /*
* Request flags. For use in the cmd_flags field of struct request, and in * Operations and flags common to the bio and request structures.
* bi_opf of struct bio. Note that some flags are only valid in either one. * We use 8 bits for encoding the operation, and the remaining 24 for flags.
*/ */
enum rq_flag_bits { #define REQ_OP_BITS 8
/* common flags */ #define REQ_OP_MASK ((1 << REQ_OP_BITS) - 1)
__REQ_FAILFAST_DEV, /* no driver retries of device errors */ #define REQ_FLAG_BITS 24
enum req_opf {
REQ_OP_READ,
REQ_OP_WRITE,
REQ_OP_DISCARD, /* request to discard sectors */
REQ_OP_SECURE_ERASE, /* request to securely erase sectors */
REQ_OP_WRITE_SAME, /* write same block many times */
REQ_OP_FLUSH, /* request for cache flush */
REQ_OP_ZONE_REPORT, /* Get zone information */
REQ_OP_ZONE_RESET, /* Reset a zone write pointer */
REQ_OP_LAST,
};
enum req_flag_bits {
__REQ_FAILFAST_DEV = /* no driver retries of device errors */
REQ_OP_BITS,
__REQ_FAILFAST_TRANSPORT, /* no driver retries of transport errors */ __REQ_FAILFAST_TRANSPORT, /* no driver retries of transport errors */
__REQ_FAILFAST_DRIVER, /* no driver retries of driver errors */ __REQ_FAILFAST_DRIVER, /* no driver retries of driver errors */
__REQ_SYNC, /* request is sync (sync write or read) */ __REQ_SYNC, /* request is sync (sync write or read) */
__REQ_META, /* metadata io request */ __REQ_META, /* metadata io request */
__REQ_PRIO, /* boost priority in cfq */ __REQ_PRIO, /* boost priority in cfq */
__REQ_NOMERGE, /* don't touch this for merging */ __REQ_NOMERGE, /* don't touch this for merging */
__REQ_NOIDLE, /* don't anticipate more IO after this one */ __REQ_NOIDLE, /* don't anticipate more IO after this one */
__REQ_INTEGRITY, /* I/O includes block integrity payload */ __REQ_INTEGRITY, /* I/O includes block integrity payload */
__REQ_FUA, /* forced unit access */ __REQ_FUA, /* forced unit access */
__REQ_PREFLUSH, /* request for cache flush */ __REQ_PREFLUSH, /* request for cache flush */
__REQ_RAHEAD, /* read ahead, can fail anytime */ __REQ_RAHEAD, /* read ahead, can fail anytime */
__REQ_NR_BITS, /* stops here */ __REQ_NR_BITS, /* stops here */
}; };
...@@ -176,37 +172,32 @@ enum rq_flag_bits { ...@@ -176,37 +172,32 @@ enum rq_flag_bits {
#define REQ_SYNC (1ULL << __REQ_SYNC) #define REQ_SYNC (1ULL << __REQ_SYNC)
#define REQ_META (1ULL << __REQ_META) #define REQ_META (1ULL << __REQ_META)
#define REQ_PRIO (1ULL << __REQ_PRIO) #define REQ_PRIO (1ULL << __REQ_PRIO)
#define REQ_NOMERGE (1ULL << __REQ_NOMERGE)
#define REQ_NOIDLE (1ULL << __REQ_NOIDLE) #define REQ_NOIDLE (1ULL << __REQ_NOIDLE)
#define REQ_INTEGRITY (1ULL << __REQ_INTEGRITY) #define REQ_INTEGRITY (1ULL << __REQ_INTEGRITY)
#define REQ_FUA (1ULL << __REQ_FUA)
#define REQ_PREFLUSH (1ULL << __REQ_PREFLUSH)
#define REQ_RAHEAD (1ULL << __REQ_RAHEAD)
#define REQ_FAILFAST_MASK \ #define REQ_FAILFAST_MASK \
(REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER) (REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER)
#define REQ_COMMON_MASK \
(REQ_FAILFAST_MASK | REQ_SYNC | REQ_META | REQ_PRIO | REQ_NOIDLE | \
REQ_PREFLUSH | REQ_FUA | REQ_INTEGRITY | REQ_NOMERGE | REQ_RAHEAD)
#define REQ_CLONE_MASK REQ_COMMON_MASK
/* This mask is used for both bio and request merge checking */
#define REQ_NOMERGE_FLAGS \ #define REQ_NOMERGE_FLAGS \
(REQ_NOMERGE | REQ_PREFLUSH | REQ_FUA) (REQ_NOMERGE | REQ_PREFLUSH | REQ_FUA)
#define REQ_RAHEAD (1ULL << __REQ_RAHEAD) #define bio_op(bio) \
#define REQ_FUA (1ULL << __REQ_FUA) ((bio)->bi_opf & REQ_OP_MASK)
#define REQ_NOMERGE (1ULL << __REQ_NOMERGE) #define req_op(req) \
#define REQ_PREFLUSH (1ULL << __REQ_PREFLUSH) ((req)->cmd_flags & REQ_OP_MASK)
enum req_op { /* obsolete, don't use in new code */
REQ_OP_READ, #define bio_set_op_attrs(bio, op, op_flags) \
REQ_OP_WRITE, ((bio)->bi_opf |= (op | op_flags))
REQ_OP_DISCARD, /* request to discard sectors */
REQ_OP_SECURE_ERASE, /* request to securely erase sectors */
REQ_OP_WRITE_SAME, /* write same block many times */
REQ_OP_FLUSH, /* request for cache flush */
REQ_OP_ZONE_REPORT, /* Get zone information */
REQ_OP_ZONE_RESET, /* Reset a zone write pointer */
};
#define REQ_OP_BITS 3 static inline bool op_is_sync(unsigned int op)
{
return (op & REQ_OP_MASK) == REQ_OP_READ || (op & REQ_SYNC);
}
typedef unsigned int blk_qc_t; typedef unsigned int blk_qc_t;
#define BLK_QC_T_NONE -1U #define BLK_QC_T_NONE -1U
......
...@@ -142,7 +142,7 @@ struct request { ...@@ -142,7 +142,7 @@ struct request {
int cpu; int cpu;
unsigned cmd_type; unsigned cmd_type;
u64 cmd_flags; unsigned int cmd_flags; /* op and common flags */
req_flags_t rq_flags; req_flags_t rq_flags;
unsigned long atomic_flags; unsigned long atomic_flags;
...@@ -244,20 +244,6 @@ struct request { ...@@ -244,20 +244,6 @@ struct request {
struct request *next_rq; struct request *next_rq;
}; };
#define REQ_OP_SHIFT (8 * sizeof(u64) - REQ_OP_BITS)
#define req_op(req) ((req)->cmd_flags >> REQ_OP_SHIFT)
#define req_set_op(req, op) do { \
WARN_ON(op >= (1 << REQ_OP_BITS)); \
(req)->cmd_flags &= ((1ULL << REQ_OP_SHIFT) - 1); \
(req)->cmd_flags |= ((u64) (op) << REQ_OP_SHIFT); \
} while (0)
#define req_set_op_attrs(req, op, flags) do { \
req_set_op(req, op); \
(req)->cmd_flags |= flags; \
} while (0)
static inline unsigned short req_get_ioprio(struct request *req) static inline unsigned short req_get_ioprio(struct request *req)
{ {
return req->ioprio; return req->ioprio;
...@@ -741,17 +727,9 @@ static inline unsigned int blk_queue_zone_size(struct request_queue *q) ...@@ -741,17 +727,9 @@ static inline unsigned int blk_queue_zone_size(struct request_queue *q)
return blk_queue_is_zoned(q) ? q->limits.chunk_sectors : 0; return blk_queue_is_zoned(q) ? q->limits.chunk_sectors : 0;
} }
/*
* We regard a request as sync, if either a read or a sync write
*/
static inline bool rw_is_sync(int op, unsigned int rw_flags)
{
return op == REQ_OP_READ || (rw_flags & REQ_SYNC);
}
static inline bool rq_is_sync(struct request *rq) static inline bool rq_is_sync(struct request *rq)
{ {
return rw_is_sync(req_op(rq), rq->cmd_flags); return op_is_sync(rq->cmd_flags);
} }
static inline bool blk_rl_full(struct request_list *rl, bool sync) static inline bool blk_rl_full(struct request_list *rl, bool sync)
......
...@@ -118,7 +118,7 @@ static inline int blk_cmd_buf_len(struct request *rq) ...@@ -118,7 +118,7 @@ static inline int blk_cmd_buf_len(struct request *rq)
} }
extern void blk_dump_cmd(char *buf, struct request *rq); extern void blk_dump_cmd(char *buf, struct request *rq);
extern void blk_fill_rwbs(char *rwbs, int op, u32 rw, int bytes); extern void blk_fill_rwbs(char *rwbs, unsigned int op, int bytes);
#endif /* CONFIG_EVENT_TRACING && CONFIG_BLOCK */ #endif /* CONFIG_EVENT_TRACING && CONFIG_BLOCK */
......
...@@ -58,7 +58,7 @@ struct dm_io_notify { ...@@ -58,7 +58,7 @@ struct dm_io_notify {
struct dm_io_client; struct dm_io_client;
struct dm_io_request { struct dm_io_request {
int bi_op; /* REQ_OP */ int bi_op; /* REQ_OP */
int bi_op_flags; /* rq_flag_bits */ int bi_op_flags; /* req_flag_bits */
struct dm_io_memory mem; /* Memory to use for io */ struct dm_io_memory mem; /* Memory to use for io */
struct dm_io_notify notify; /* Synchronous if notify.fn is NULL */ struct dm_io_notify notify; /* Synchronous if notify.fn is NULL */
struct dm_io_client *client; /* Client memory handler */ struct dm_io_client *client; /* Client memory handler */
......
...@@ -30,7 +30,7 @@ typedef int (elevator_dispatch_fn) (struct request_queue *, int); ...@@ -30,7 +30,7 @@ typedef int (elevator_dispatch_fn) (struct request_queue *, int);
typedef void (elevator_add_req_fn) (struct request_queue *, struct request *); typedef void (elevator_add_req_fn) (struct request_queue *, struct request *);
typedef struct request *(elevator_request_list_fn) (struct request_queue *, struct request *); typedef struct request *(elevator_request_list_fn) (struct request_queue *, struct request *);
typedef void (elevator_completed_req_fn) (struct request_queue *, struct request *); typedef void (elevator_completed_req_fn) (struct request_queue *, struct request *);
typedef int (elevator_may_queue_fn) (struct request_queue *, int, int); typedef int (elevator_may_queue_fn) (struct request_queue *, unsigned int);
typedef void (elevator_init_icq_fn) (struct io_cq *); typedef void (elevator_init_icq_fn) (struct io_cq *);
typedef void (elevator_exit_icq_fn) (struct io_cq *); typedef void (elevator_exit_icq_fn) (struct io_cq *);
...@@ -139,7 +139,7 @@ extern struct request *elv_former_request(struct request_queue *, struct request ...@@ -139,7 +139,7 @@ extern struct request *elv_former_request(struct request_queue *, struct request
extern struct request *elv_latter_request(struct request_queue *, struct request *); extern struct request *elv_latter_request(struct request_queue *, struct request *);
extern int elv_register_queue(struct request_queue *q); extern int elv_register_queue(struct request_queue *q);
extern void elv_unregister_queue(struct request_queue *q); extern void elv_unregister_queue(struct request_queue *q);
extern int elv_may_queue(struct request_queue *, int, int); extern int elv_may_queue(struct request_queue *, unsigned int);
extern void elv_completed_request(struct request_queue *, struct request *); extern void elv_completed_request(struct request_queue *, struct request *);
extern int elv_set_request(struct request_queue *q, struct request *rq, extern int elv_set_request(struct request_queue *q, struct request *rq,
struct bio *bio, gfp_t gfp_mask); struct bio *bio, gfp_t gfp_mask);
......
...@@ -27,8 +27,7 @@ DECLARE_EVENT_CLASS(bcache_request, ...@@ -27,8 +27,7 @@ DECLARE_EVENT_CLASS(bcache_request,
__entry->sector = bio->bi_iter.bi_sector; __entry->sector = bio->bi_iter.bi_sector;
__entry->orig_sector = bio->bi_iter.bi_sector - 16; __entry->orig_sector = bio->bi_iter.bi_sector - 16;
__entry->nr_sector = bio->bi_iter.bi_size >> 9; __entry->nr_sector = bio->bi_iter.bi_size >> 9;
blk_fill_rwbs(__entry->rwbs, bio_op(bio), bio->bi_opf, blk_fill_rwbs(__entry->rwbs, bio->bi_opf, bio->bi_iter.bi_size);
bio->bi_iter.bi_size);
), ),
TP_printk("%d,%d %s %llu + %u (from %d,%d @ %llu)", TP_printk("%d,%d %s %llu + %u (from %d,%d @ %llu)",
...@@ -102,8 +101,7 @@ DECLARE_EVENT_CLASS(bcache_bio, ...@@ -102,8 +101,7 @@ DECLARE_EVENT_CLASS(bcache_bio,
__entry->dev = bio->bi_bdev->bd_dev; __entry->dev = bio->bi_bdev->bd_dev;
__entry->sector = bio->bi_iter.bi_sector; __entry->sector = bio->bi_iter.bi_sector;
__entry->nr_sector = bio->bi_iter.bi_size >> 9; __entry->nr_sector = bio->bi_iter.bi_size >> 9;
blk_fill_rwbs(__entry->rwbs, bio_op(bio), bio->bi_opf, blk_fill_rwbs(__entry->rwbs, bio->bi_opf, bio->bi_iter.bi_size);
bio->bi_iter.bi_size);
), ),
TP_printk("%d,%d %s %llu + %u", TP_printk("%d,%d %s %llu + %u",
...@@ -138,8 +136,7 @@ TRACE_EVENT(bcache_read, ...@@ -138,8 +136,7 @@ TRACE_EVENT(bcache_read,
__entry->dev = bio->bi_bdev->bd_dev; __entry->dev = bio->bi_bdev->bd_dev;
__entry->sector = bio->bi_iter.bi_sector; __entry->sector = bio->bi_iter.bi_sector;
__entry->nr_sector = bio->bi_iter.bi_size >> 9; __entry->nr_sector = bio->bi_iter.bi_size >> 9;
blk_fill_rwbs(__entry->rwbs, bio_op(bio), bio->bi_opf, blk_fill_rwbs(__entry->rwbs, bio->bi_opf, bio->bi_iter.bi_size);
bio->bi_iter.bi_size);
__entry->cache_hit = hit; __entry->cache_hit = hit;
__entry->bypass = bypass; __entry->bypass = bypass;
), ),
...@@ -170,8 +167,7 @@ TRACE_EVENT(bcache_write, ...@@ -170,8 +167,7 @@ TRACE_EVENT(bcache_write,
__entry->inode = inode; __entry->inode = inode;
__entry->sector = bio->bi_iter.bi_sector; __entry->sector = bio->bi_iter.bi_sector;
__entry->nr_sector = bio->bi_iter.bi_size >> 9; __entry->nr_sector = bio->bi_iter.bi_size >> 9;
blk_fill_rwbs(__entry->rwbs, bio_op(bio), bio->bi_opf, blk_fill_rwbs(__entry->rwbs, bio->bi_opf, bio->bi_iter.bi_size);
bio->bi_iter.bi_size);
__entry->writeback = writeback; __entry->writeback = writeback;
__entry->bypass = bypass; __entry->bypass = bypass;
), ),
......
...@@ -84,8 +84,7 @@ DECLARE_EVENT_CLASS(block_rq_with_error, ...@@ -84,8 +84,7 @@ DECLARE_EVENT_CLASS(block_rq_with_error,
0 : blk_rq_sectors(rq); 0 : blk_rq_sectors(rq);
__entry->errors = rq->errors; __entry->errors = rq->errors;
blk_fill_rwbs(__entry->rwbs, req_op(rq), rq->cmd_flags, blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, blk_rq_bytes(rq));
blk_rq_bytes(rq));
blk_dump_cmd(__get_str(cmd), rq); blk_dump_cmd(__get_str(cmd), rq);
), ),
...@@ -163,7 +162,7 @@ TRACE_EVENT(block_rq_complete, ...@@ -163,7 +162,7 @@ TRACE_EVENT(block_rq_complete,
__entry->nr_sector = nr_bytes >> 9; __entry->nr_sector = nr_bytes >> 9;
__entry->errors = rq->errors; __entry->errors = rq->errors;
blk_fill_rwbs(__entry->rwbs, req_op(rq), rq->cmd_flags, nr_bytes); blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, nr_bytes);
blk_dump_cmd(__get_str(cmd), rq); blk_dump_cmd(__get_str(cmd), rq);
), ),
...@@ -199,8 +198,7 @@ DECLARE_EVENT_CLASS(block_rq, ...@@ -199,8 +198,7 @@ DECLARE_EVENT_CLASS(block_rq,
__entry->bytes = (rq->cmd_type == REQ_TYPE_BLOCK_PC) ? __entry->bytes = (rq->cmd_type == REQ_TYPE_BLOCK_PC) ?
blk_rq_bytes(rq) : 0; blk_rq_bytes(rq) : 0;
blk_fill_rwbs(__entry->rwbs, req_op(rq), rq->cmd_flags, blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, blk_rq_bytes(rq));
blk_rq_bytes(rq));
blk_dump_cmd(__get_str(cmd), rq); blk_dump_cmd(__get_str(cmd), rq);
memcpy(__entry->comm, current->comm, TASK_COMM_LEN); memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
), ),
...@@ -274,8 +272,7 @@ TRACE_EVENT(block_bio_bounce, ...@@ -274,8 +272,7 @@ TRACE_EVENT(block_bio_bounce,
bio->bi_bdev->bd_dev : 0; bio->bi_bdev->bd_dev : 0;
__entry->sector = bio->bi_iter.bi_sector; __entry->sector = bio->bi_iter.bi_sector;
__entry->nr_sector = bio_sectors(bio); __entry->nr_sector = bio_sectors(bio);
blk_fill_rwbs(__entry->rwbs, bio_op(bio), bio->bi_opf, blk_fill_rwbs(__entry->rwbs, bio->bi_opf, bio->bi_iter.bi_size);
bio->bi_iter.bi_size);
memcpy(__entry->comm, current->comm, TASK_COMM_LEN); memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
), ),
...@@ -313,8 +310,7 @@ TRACE_EVENT(block_bio_complete, ...@@ -313,8 +310,7 @@ TRACE_EVENT(block_bio_complete,
__entry->sector = bio->bi_iter.bi_sector; __entry->sector = bio->bi_iter.bi_sector;
__entry->nr_sector = bio_sectors(bio); __entry->nr_sector = bio_sectors(bio);
__entry->error = error; __entry->error = error;
blk_fill_rwbs(__entry->rwbs, bio_op(bio), bio->bi_opf, blk_fill_rwbs(__entry->rwbs, bio->bi_opf, bio->bi_iter.bi_size);
bio->bi_iter.bi_size);
), ),
TP_printk("%d,%d %s %llu + %u [%d]", TP_printk("%d,%d %s %llu + %u [%d]",
...@@ -341,8 +337,7 @@ DECLARE_EVENT_CLASS(block_bio_merge, ...@@ -341,8 +337,7 @@ DECLARE_EVENT_CLASS(block_bio_merge,
__entry->dev = bio->bi_bdev->bd_dev; __entry->dev = bio->bi_bdev->bd_dev;
__entry->sector = bio->bi_iter.bi_sector; __entry->sector = bio->bi_iter.bi_sector;
__entry->nr_sector = bio_sectors(bio); __entry->nr_sector = bio_sectors(bio);
blk_fill_rwbs(__entry->rwbs, bio_op(bio), bio->bi_opf, blk_fill_rwbs(__entry->rwbs, bio->bi_opf, bio->bi_iter.bi_size);
bio->bi_iter.bi_size);
memcpy(__entry->comm, current->comm, TASK_COMM_LEN); memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
), ),
...@@ -409,8 +404,7 @@ TRACE_EVENT(block_bio_queue, ...@@ -409,8 +404,7 @@ TRACE_EVENT(block_bio_queue,
__entry->dev = bio->bi_bdev->bd_dev; __entry->dev = bio->bi_bdev->bd_dev;
__entry->sector = bio->bi_iter.bi_sector; __entry->sector = bio->bi_iter.bi_sector;
__entry->nr_sector = bio_sectors(bio); __entry->nr_sector = bio_sectors(bio);
blk_fill_rwbs(__entry->rwbs, bio_op(bio), bio->bi_opf, blk_fill_rwbs(__entry->rwbs, bio->bi_opf, bio->bi_iter.bi_size);
bio->bi_iter.bi_size);
memcpy(__entry->comm, current->comm, TASK_COMM_LEN); memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
), ),
...@@ -438,7 +432,7 @@ DECLARE_EVENT_CLASS(block_get_rq, ...@@ -438,7 +432,7 @@ DECLARE_EVENT_CLASS(block_get_rq,
__entry->dev = bio ? bio->bi_bdev->bd_dev : 0; __entry->dev = bio ? bio->bi_bdev->bd_dev : 0;
__entry->sector = bio ? bio->bi_iter.bi_sector : 0; __entry->sector = bio ? bio->bi_iter.bi_sector : 0;
__entry->nr_sector = bio ? bio_sectors(bio) : 0; __entry->nr_sector = bio ? bio_sectors(bio) : 0;
blk_fill_rwbs(__entry->rwbs, bio ? bio_op(bio) : 0, blk_fill_rwbs(__entry->rwbs,
bio ? bio->bi_opf : 0, __entry->nr_sector); bio ? bio->bi_opf : 0, __entry->nr_sector);
memcpy(__entry->comm, current->comm, TASK_COMM_LEN); memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
), ),
...@@ -573,8 +567,7 @@ TRACE_EVENT(block_split, ...@@ -573,8 +567,7 @@ TRACE_EVENT(block_split,
__entry->dev = bio->bi_bdev->bd_dev; __entry->dev = bio->bi_bdev->bd_dev;
__entry->sector = bio->bi_iter.bi_sector; __entry->sector = bio->bi_iter.bi_sector;
__entry->new_sector = new_sector; __entry->new_sector = new_sector;
blk_fill_rwbs(__entry->rwbs, bio_op(bio), bio->bi_opf, blk_fill_rwbs(__entry->rwbs, bio->bi_opf, bio->bi_iter.bi_size);
bio->bi_iter.bi_size);
memcpy(__entry->comm, current->comm, TASK_COMM_LEN); memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
), ),
...@@ -617,8 +610,7 @@ TRACE_EVENT(block_bio_remap, ...@@ -617,8 +610,7 @@ TRACE_EVENT(block_bio_remap,
__entry->nr_sector = bio_sectors(bio); __entry->nr_sector = bio_sectors(bio);
__entry->old_dev = dev; __entry->old_dev = dev;
__entry->old_sector = from; __entry->old_sector = from;
blk_fill_rwbs(__entry->rwbs, bio_op(bio), bio->bi_opf, blk_fill_rwbs(__entry->rwbs, bio->bi_opf, bio->bi_iter.bi_size);
bio->bi_iter.bi_size);
), ),
TP_printk("%d,%d %s %llu + %u <- (%d,%d) %llu", TP_printk("%d,%d %s %llu + %u <- (%d,%d) %llu",
...@@ -664,8 +656,7 @@ TRACE_EVENT(block_rq_remap, ...@@ -664,8 +656,7 @@ TRACE_EVENT(block_rq_remap,
__entry->old_dev = dev; __entry->old_dev = dev;
__entry->old_sector = from; __entry->old_sector = from;
__entry->nr_bios = blk_rq_count_bios(rq); __entry->nr_bios = blk_rq_count_bios(rq);
blk_fill_rwbs(__entry->rwbs, req_op(rq), rq->cmd_flags, blk_fill_rwbs(__entry->rwbs, rq->cmd_flags, blk_rq_bytes(rq));
blk_rq_bytes(rq));
), ),
TP_printk("%d,%d %s %llu + %u <- (%d,%d) %llu %u", TP_printk("%d,%d %s %llu + %u <- (%d,%d) %llu %u",
......
...@@ -1777,14 +1777,14 @@ void blk_dump_cmd(char *buf, struct request *rq) ...@@ -1777,14 +1777,14 @@ void blk_dump_cmd(char *buf, struct request *rq)
} }
} }
void blk_fill_rwbs(char *rwbs, int op, u32 rw, int bytes) void blk_fill_rwbs(char *rwbs, unsigned int op, int bytes)
{ {
int i = 0; int i = 0;
if (rw & REQ_PREFLUSH) if (op & REQ_PREFLUSH)
rwbs[i++] = 'F'; rwbs[i++] = 'F';
switch (op) { switch (op & REQ_OP_MASK) {
case REQ_OP_WRITE: case REQ_OP_WRITE:
case REQ_OP_WRITE_SAME: case REQ_OP_WRITE_SAME:
rwbs[i++] = 'W'; rwbs[i++] = 'W';
...@@ -1806,13 +1806,13 @@ void blk_fill_rwbs(char *rwbs, int op, u32 rw, int bytes) ...@@ -1806,13 +1806,13 @@ void blk_fill_rwbs(char *rwbs, int op, u32 rw, int bytes)
rwbs[i++] = 'N'; rwbs[i++] = 'N';
} }
if (rw & REQ_FUA) if (op & REQ_FUA)
rwbs[i++] = 'F'; rwbs[i++] = 'F';
if (rw & REQ_RAHEAD) if (op & REQ_RAHEAD)
rwbs[i++] = 'A'; rwbs[i++] = 'A';
if (rw & REQ_SYNC) if (op & REQ_SYNC)
rwbs[i++] = 'S'; rwbs[i++] = 'S';
if (rw & REQ_META) if (op & REQ_META)
rwbs[i++] = 'M'; rwbs[i++] = 'M';
rwbs[i] = '\0'; rwbs[i] = '\0';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment