Skip to content

Commit f4788ae

Browse files
Ming Leiaxboe
authored andcommitted
loop: move command blkcg/memcg initialization into loop_queue_work
Move loop command blkcg/memcg initialization into loop_queue_work, and prepare for supporting to handle loop io command by IOCB_NOWAIT. Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent c66e970 commit f4788ae

1 file changed

Lines changed: 17 additions & 15 deletions

File tree

drivers/block/loop.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -831,11 +831,28 @@ static inline int queue_on_root_worker(struct cgroup_subsys_state *css)
831831

832832
static void loop_queue_work(struct loop_device *lo, struct loop_cmd *cmd)
833833
{
834+
struct request __maybe_unused *rq = blk_mq_rq_from_pdu(cmd);
834835
struct rb_node **node, *parent = NULL;
835836
struct loop_worker *cur_worker, *worker = NULL;
836837
struct work_struct *work;
837838
struct list_head *cmd_list;
838839

840+
/* always use the first bio's css */
841+
cmd->blkcg_css = NULL;
842+
cmd->memcg_css = NULL;
843+
#ifdef CONFIG_BLK_CGROUP
844+
if (rq->bio) {
845+
cmd->blkcg_css = bio_blkcg_css(rq->bio);
846+
#ifdef CONFIG_MEMCG
847+
if (cmd->blkcg_css) {
848+
cmd->memcg_css =
849+
cgroup_get_e_css(cmd->blkcg_css->cgroup,
850+
&memory_cgrp_subsys);
851+
}
852+
#endif
853+
}
854+
#endif
855+
839856
spin_lock_irq(&lo->lo_work_lock);
840857

841858
if (queue_on_root_worker(cmd->blkcg_css))
@@ -1907,21 +1924,6 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx,
19071924
break;
19081925
}
19091926

1910-
/* always use the first bio's css */
1911-
cmd->blkcg_css = NULL;
1912-
cmd->memcg_css = NULL;
1913-
#ifdef CONFIG_BLK_CGROUP
1914-
if (rq->bio) {
1915-
cmd->blkcg_css = bio_blkcg_css(rq->bio);
1916-
#ifdef CONFIG_MEMCG
1917-
if (cmd->blkcg_css) {
1918-
cmd->memcg_css =
1919-
cgroup_get_e_css(cmd->blkcg_css->cgroup,
1920-
&memory_cgrp_subsys);
1921-
}
1922-
#endif
1923-
}
1924-
#endif
19251927
loop_queue_work(lo, cmd);
19261928

19271929
return BLK_STS_OK;

0 commit comments

Comments
 (0)