public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: use list_entry_rq
@ 2017-01-13 15:17 Geliang Tang
  2017-01-13 15:17 ` [PATCH] elevator: add fall through comment Geliang Tang
  2017-01-13 15:17 ` [PATCH] writeback: use rb_entry() Geliang Tang
  0 siblings, 2 replies; 5+ messages in thread
From: Geliang Tang @ 2017-01-13 15:17 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Geliang Tang, linux-block, linux-kernel

Use list_entry_rq() instead of open-coding it.

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
 block/blk-core.c | 4 ++--
 block/blk-mq.c   | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index 61ba08c..3c254d9 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -3148,8 +3148,8 @@ EXPORT_SYMBOL(blk_start_plug);
 
 static int plug_rq_cmp(void *priv, struct list_head *a, struct list_head *b)
 {
-	struct request *rqa = container_of(a, struct request, queuelist);
-	struct request *rqb = container_of(b, struct request, queuelist);
+	struct request *rqa = list_entry_rq(a);
+	struct request *rqb = list_entry_rq(b);
 
 	return !(rqa->q < rqb->q ||
 		(rqa->q == rqb->q && blk_rq_pos(rqa) < blk_rq_pos(rqb)));
diff --git a/block/blk-mq.c b/block/blk-mq.c
index a8e67a1..e24b881 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -553,7 +553,7 @@ static void blk_mq_requeue_work(struct work_struct *work)
 	}
 
 	while (!list_empty(&rq_list)) {
-		rq = list_entry(rq_list.next, struct request, queuelist);
+		rq = list_entry_rq(rq_list.next);
 		list_del_init(&rq->queuelist);
 		blk_mq_insert_request(rq, false, false, false);
 	}
@@ -1192,8 +1192,8 @@ static void blk_mq_insert_requests(struct request_queue *q,
 
 static int plug_ctx_cmp(void *priv, struct list_head *a, struct list_head *b)
 {
-	struct request *rqa = container_of(a, struct request, queuelist);
-	struct request *rqb = container_of(b, struct request, queuelist);
+	struct request *rqa = list_entry_rq(a);
+	struct request *rqb = list_entry_rq(b);
 
 	return !(rqa->mq_ctx < rqb->mq_ctx ||
 		 (rqa->mq_ctx == rqb->mq_ctx &&
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] elevator: add fall through comment
  2017-01-13 15:17 [PATCH] block: use list_entry_rq Geliang Tang
@ 2017-01-13 15:17 ` Geliang Tang
  2017-01-13 15:17 ` [PATCH] writeback: use rb_entry() Geliang Tang
  1 sibling, 0 replies; 5+ messages in thread
From: Geliang Tang @ 2017-01-13 15:17 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Geliang Tang, linux-block, linux-kernel

Add fall through comment for ELEVATOR_INSERT_SORT_MERGE.

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
 block/elevator.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/block/elevator.c b/block/elevator.c
index 40f0c04..6db8f89 100644
--- a/block/elevator.c
+++ b/block/elevator.c
@@ -638,6 +638,7 @@ void __elv_add_request(struct request_queue *q, struct request *rq, int where)
 		 */
 		if (elv_attempt_insert_merge(q, rq))
 			break;
+		/* Fall through */
 	case ELEVATOR_INSERT_SORT:
 		BUG_ON(rq->cmd_type != REQ_TYPE_FS);
 		rq->rq_flags |= RQF_SORTED;
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH] writeback: use rb_entry()
  2017-01-13 15:17 [PATCH] block: use list_entry_rq Geliang Tang
  2017-01-13 15:17 ` [PATCH] elevator: add fall through comment Geliang Tang
@ 2017-01-13 15:17 ` Geliang Tang
  2017-01-15 23:54   ` Tejun Heo
  1 sibling, 1 reply; 5+ messages in thread
From: Geliang Tang @ 2017-01-13 15:17 UTC (permalink / raw)
  To: Andrew Morton, Michal Hocko, Jens Axboe, Tejun Heo,
	Johannes Weiner
  Cc: Geliang Tang, linux-mm, linux-kernel

To make the code clearer, use rb_entry() instead of container_of() to
deal with rbtree.

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
 mm/backing-dev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/backing-dev.c b/mm/backing-dev.c
index 3bfed5ab..ffb77a1 100644
--- a/mm/backing-dev.c
+++ b/mm/backing-dev.c
@@ -410,8 +410,8 @@ wb_congested_get_create(struct backing_dev_info *bdi, int blkcg_id, gfp_t gfp)
 
 	while (*node != NULL) {
 		parent = *node;
-		congested = container_of(parent, struct bdi_writeback_congested,
-					 rb_node);
+		congested = rb_entry(parent, struct bdi_writeback_congested,
+				     rb_node);
 		if (congested->blkcg_id < blkcg_id)
 			node = &parent->rb_left;
 		else if (congested->blkcg_id > blkcg_id)
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] writeback: use rb_entry()
  2017-01-13 15:17 ` [PATCH] writeback: use rb_entry() Geliang Tang
@ 2017-01-15 23:54   ` Tejun Heo
  2017-01-22 14:40     ` Geliang Tang
  0 siblings, 1 reply; 5+ messages in thread
From: Tejun Heo @ 2017-01-15 23:54 UTC (permalink / raw)
  To: Geliang Tang
  Cc: Andrew Morton, Michal Hocko, Jens Axboe, Johannes Weiner,
	linux-mm, linux-kernel

On Fri, Jan 13, 2017 at 11:17:12PM +0800, Geliang Tang wrote:
> To make the code clearer, use rb_entry() instead of container_of() to
> deal with rbtree.
> 
> Signed-off-by: Geliang Tang <geliangtang@gmail.com>
> ---
>  mm/backing-dev.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/backing-dev.c b/mm/backing-dev.c
> index 3bfed5ab..ffb77a1 100644
> --- a/mm/backing-dev.c
> +++ b/mm/backing-dev.c
> @@ -410,8 +410,8 @@ wb_congested_get_create(struct backing_dev_info *bdi, int blkcg_id, gfp_t gfp)
>  
>  	while (*node != NULL) {
>  		parent = *node;
> -		congested = container_of(parent, struct bdi_writeback_congested,
> -					 rb_node);
> +		congested = rb_entry(parent, struct bdi_writeback_congested,
> +				     rb_node);

I don't get the rb_entry() macro.  It's just another name for
container_of().  I have no objection to the patch but this macro is a
bit silly.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] writeback: use rb_entry()
  2017-01-15 23:54   ` Tejun Heo
@ 2017-01-22 14:40     ` Geliang Tang
  0 siblings, 0 replies; 5+ messages in thread
From: Geliang Tang @ 2017-01-22 14:40 UTC (permalink / raw)
  To: Tejun Heo
  Cc: Andrew Morton, Michal Hocko, Jens Axboe, Johannes Weiner,
	linux-mm, linux-kernel

On Sun, Jan 15, 2017 at 06:54:31PM -0500, Tejun Heo wrote:
> On Fri, Jan 13, 2017 at 11:17:12PM +0800, Geliang Tang wrote:
> > To make the code clearer, use rb_entry() instead of container_of() to
> > deal with rbtree.
> > 
> > Signed-off-by: Geliang Tang <geliangtang@gmail.com>
> > ---
> >  mm/backing-dev.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/mm/backing-dev.c b/mm/backing-dev.c
> > index 3bfed5ab..ffb77a1 100644
> > --- a/mm/backing-dev.c
> > +++ b/mm/backing-dev.c
> > @@ -410,8 +410,8 @@ wb_congested_get_create(struct backing_dev_info *bdi, int blkcg_id, gfp_t gfp)
> >  
> >  	while (*node != NULL) {
> >  		parent = *node;
> > -		congested = container_of(parent, struct bdi_writeback_congested,
> > -					 rb_node);
> > +		congested = rb_entry(parent, struct bdi_writeback_congested,
> > +				     rb_node);
> 
> I don't get the rb_entry() macro.  It's just another name for
> container_of().  I have no objection to the patch but this macro is a
> bit silly.
> 

There are several *_entry macros which are defined in kernel data
structures, like list_entry, hlist_entry, rb_entry, etc. Each of them is
just another name for container_of. We use different *_entry so that we
could identify the specific type of data structure that we are dealing
with.

-Geliang

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-01-22 14:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-13 15:17 [PATCH] block: use list_entry_rq Geliang Tang
2017-01-13 15:17 ` [PATCH] elevator: add fall through comment Geliang Tang
2017-01-13 15:17 ` [PATCH] writeback: use rb_entry() Geliang Tang
2017-01-15 23:54   ` Tejun Heo
2017-01-22 14:40     ` Geliang Tang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox