All of lore.kernel.org
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.com>
To: lustre-devel@lists.lustre.org
Subject: [lustre-devel] [PATCH 10/21] lustre: obdclass: use cl_object_for_each where appropriate
Date: Thu, 07 Feb 2019 11:03:33 +1100	[thread overview]
Message-ID: <154949781310.10620.8883358407999258821.stgit@noble.brown> (raw)
In-Reply-To: <154949776249.10620.1215070753973826063.stgit@noble.brown>

There are various places which have a list_for_each_entry()
where cl_object_for_each (or .._reverse) is more appropriate.

Several of these re-use the 'obj' function parameter as a loop
iterator, which is a little confusing.

Change these to use cl_object_for_each{_reverse}, and where needed,
introduce a new iterator variable 'o'.

Signed-off-by: NeilBrown <neilb@suse.com>
---
 drivers/staging/lustre/lustre/lov/lov_page.c       |    3 -
 drivers/staging/lustre/lustre/obdclass/cl_lock.c   |    3 -
 drivers/staging/lustre/lustre/obdclass/cl_object.c |   82 +++++++++-----------
 drivers/staging/lustre/lustre/obdclass/cl_page.c   |   11 +--
 4 files changed, 44 insertions(+), 55 deletions(-)

diff --git a/drivers/staging/lustre/lustre/lov/lov_page.c b/drivers/staging/lustre/lustre/lov/lov_page.c
index 08485a95ec01..e64b350601d2 100644
--- a/drivers/staging/lustre/lustre/lov/lov_page.c
+++ b/drivers/staging/lustre/lustre/lov/lov_page.c
@@ -103,8 +103,7 @@ int lov_page_init_composite(const struct lu_env *env, struct cl_object *obj,
 		return PTR_ERR(sub);
 
 	subobj = lovsub2cl(r0->lo_sub[stripe]);
-	list_for_each_entry(o, &subobj->co_lu.lo_header->loh_layers,
-			    co_lu.lo_linkage) {
+	cl_object_for_each(o, subobj) {
 		if (o->co_ops->coo_page_init) {
 			rc = o->co_ops->coo_page_init(sub->sub_env, o, page,
 						      cl_index(subobj, suboff));
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_lock.c b/drivers/staging/lustre/lustre/obdclass/cl_lock.c
index 8133d992cc73..fc5976d8b37b 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_lock.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_lock.c
@@ -103,8 +103,7 @@ int cl_lock_init(const struct lu_env *env, struct cl_lock *lock,
 	LASSERT(obj);
 
 	INIT_LIST_HEAD(&lock->cll_layers);
-	list_for_each_entry(scan, &obj->co_lu.lo_header->loh_layers,
-			    co_lu.lo_linkage) {
+	cl_object_for_each(scan, obj) {
 		result = scan->co_ops->coo_lock_init(env, scan, lock, io);
 		if (result != 0) {
 			cl_lock_fini(env, lock);
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_object.c b/drivers/staging/lustre/lustre/obdclass/cl_object.c
index f724b2d62df1..d71a680660da 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_object.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_object.c
@@ -190,16 +190,15 @@ EXPORT_SYMBOL(cl_object_attr_unlock);
 int cl_object_attr_get(const struct lu_env *env, struct cl_object *obj,
 		       struct cl_attr *attr)
 {
-	struct lu_object_header *top;
+	struct cl_object *o;
 	int result;
 
 	assert_spin_locked(cl_object_attr_guard(obj));
 
-	top = obj->co_lu.lo_header;
 	result = 0;
-	list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
-		if (obj->co_ops->coo_attr_get) {
-			result = obj->co_ops->coo_attr_get(env, obj, attr);
+	cl_object_for_each(o, obj) {
+		if (o->co_ops->coo_attr_get) {
+			result = o->co_ops->coo_attr_get(env, o, attr);
 			if (result != 0) {
 				if (result > 0)
 					result = 0;
@@ -221,17 +220,16 @@ EXPORT_SYMBOL(cl_object_attr_get);
 int cl_object_attr_update(const struct lu_env *env, struct cl_object *obj,
 			  const struct cl_attr *attr, unsigned int v)
 {
-	struct lu_object_header *top;
+	struct cl_object *o;
 	int result;
 
 	assert_spin_locked(cl_object_attr_guard(obj));
 
-	top = obj->co_lu.lo_header;
 	result = 0;
-	list_for_each_entry_reverse(obj, &top->loh_layers, co_lu.lo_linkage) {
-		if (obj->co_ops->coo_attr_update) {
-			result = obj->co_ops->coo_attr_update(env, obj, attr,
-							      v);
+	cl_object_for_each_reverse(o, obj) {
+		if (o->co_ops->coo_attr_update) {
+			result = o->co_ops->coo_attr_update(env, o, attr,
+							    v);
 			if (result != 0) {
 				if (result > 0)
 					result = 0;
@@ -254,19 +252,18 @@ EXPORT_SYMBOL(cl_object_attr_update);
 int cl_object_glimpse(const struct lu_env *env, struct cl_object *obj,
 		      struct ost_lvb *lvb)
 {
-	struct lu_object_header *top;
+	struct cl_object *o;
 	int result;
 
-	top = obj->co_lu.lo_header;
 	result = 0;
-	list_for_each_entry_reverse(obj, &top->loh_layers, co_lu.lo_linkage) {
-		if (obj->co_ops->coo_glimpse) {
-			result = obj->co_ops->coo_glimpse(env, obj, lvb);
+	cl_object_for_each_reverse(o, obj) {
+		if (o->co_ops->coo_glimpse) {
+			result = o->co_ops->coo_glimpse(env, o, lvb);
 			if (result != 0)
 				break;
 		}
 	}
-	LU_OBJECT_HEADER(D_DLMTRACE, env, lu_object_top(top),
+	LU_OBJECT_HEADER(D_DLMTRACE, env, lu_object_top(obj->co_lu.lo_header),
 			 "size: %llu mtime: %llu atime: %llu ctime: %llu blocks: %llu\n",
 			 lvb->lvb_size, lvb->lvb_mtime, lvb->lvb_atime,
 			 lvb->lvb_ctime, lvb->lvb_blocks);
@@ -280,14 +277,13 @@ EXPORT_SYMBOL(cl_object_glimpse);
 int cl_conf_set(const struct lu_env *env, struct cl_object *obj,
 		const struct cl_object_conf *conf)
 {
-	struct lu_object_header *top;
+	struct cl_object *o;
 	int result;
 
-	top = obj->co_lu.lo_header;
 	result = 0;
-	list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
-		if (obj->co_ops->coo_conf_set) {
-			result = obj->co_ops->coo_conf_set(env, obj, conf);
+	cl_object_for_each(o, obj) {
+		if (o->co_ops->coo_conf_set) {
+			result = o->co_ops->coo_conf_set(env, o, conf);
 			if (result != 0)
 				break;
 		}
@@ -301,13 +297,11 @@ EXPORT_SYMBOL(cl_conf_set);
  */
 int cl_object_prune(const struct lu_env *env, struct cl_object *obj)
 {
-	struct lu_object_header *top;
 	struct cl_object *o;
 	int result;
 
-	top = obj->co_lu.lo_header;
 	result = 0;
-	list_for_each_entry(o, &top->loh_layers, co_lu.lo_linkage) {
+	cl_object_for_each(o, obj) {
 		if (o->co_ops->coo_prune) {
 			result = o->co_ops->coo_prune(env, o);
 			if (result != 0)
@@ -325,14 +319,13 @@ EXPORT_SYMBOL(cl_object_prune);
 int cl_object_getstripe(const struct lu_env *env, struct cl_object *obj,
 			struct lov_user_md __user *uarg, size_t size)
 {
-	struct lu_object_header *top;
+	struct cl_object *o;
 	int result = 0;
 
-	top = obj->co_lu.lo_header;
-	list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
-		if (obj->co_ops->coo_getstripe) {
-			result = obj->co_ops->coo_getstripe(env, obj, uarg,
-							    size);
+	cl_object_for_each(o, obj) {
+		if (o->co_ops->coo_getstripe) {
+			result = o->co_ops->coo_getstripe(env, o, uarg,
+							  size);
 			if (result)
 				break;
 		}
@@ -357,14 +350,13 @@ int cl_object_fiemap(const struct lu_env *env, struct cl_object *obj,
 		     struct ll_fiemap_info_key *key,
 		     struct fiemap *fiemap, size_t *buflen)
 {
-	struct lu_object_header *top;
+	struct cl_object *o;
 	int result = 0;
 
-	top = obj->co_lu.lo_header;
-	list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
-		if (obj->co_ops->coo_fiemap) {
-			result = obj->co_ops->coo_fiemap(env, obj, key, fiemap,
-							 buflen);
+	cl_object_for_each(o, obj) {
+		if (o->co_ops->coo_fiemap) {
+			result = o->co_ops->coo_fiemap(env, o, key, fiemap,
+						       buflen);
 			if (result)
 				break;
 		}
@@ -376,11 +368,11 @@ EXPORT_SYMBOL(cl_object_fiemap);
 int cl_object_layout_get(const struct lu_env *env, struct cl_object *obj,
 			 struct cl_layout *cl)
 {
-	struct lu_object_header *top = obj->co_lu.lo_header;
+	struct cl_object *o;
 
-	list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
-		if (obj->co_ops->coo_layout_get)
-			return obj->co_ops->coo_layout_get(env, obj, cl);
+	cl_object_for_each(o, obj) {
+		if (o->co_ops->coo_layout_get)
+			return o->co_ops->coo_layout_get(env, o, cl);
 	}
 
 	return -EOPNOTSUPP;
@@ -389,12 +381,12 @@ EXPORT_SYMBOL(cl_object_layout_get);
 
 loff_t cl_object_maxbytes(struct cl_object *obj)
 {
-	struct lu_object_header *top = obj->co_lu.lo_header;
+	struct cl_object *o;
 	loff_t maxbytes = LLONG_MAX;
 
-	list_for_each_entry(obj, &top->loh_layers, co_lu.lo_linkage) {
-		if (obj->co_ops->coo_maxbytes)
-			maxbytes = min_t(loff_t, obj->co_ops->coo_maxbytes(obj),
+	cl_object_for_each(o, obj) {
+		if (o->co_ops->coo_maxbytes)
+			maxbytes = min_t(loff_t, o->co_ops->coo_maxbytes(o),
 					 maxbytes);
 	}
 
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_page.c b/drivers/staging/lustre/lustre/obdclass/cl_page.c
index 057318deaa4e..7d00a9233a3b 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_page.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_page.c
@@ -132,7 +132,7 @@ struct cl_page *cl_page_alloc(const struct lu_env *env,
 			      enum cl_page_type type)
 {
 	struct cl_page *page;
-	struct lu_object_header *head;
+	struct cl_object *o2;
 
 	page = kzalloc(cl_object_header(o)->coh_page_bufsize, GFP_NOFS);
 	if (page) {
@@ -149,11 +149,10 @@ struct cl_page *cl_page_alloc(const struct lu_env *env,
 		INIT_LIST_HEAD(&page->cp_layers);
 		INIT_LIST_HEAD(&page->cp_batch);
 		lu_ref_init(&page->cp_reference);
-		head = o->co_lu.lo_header;
-		list_for_each_entry(o, &head->loh_layers, co_lu.lo_linkage) {
-			if (o->co_ops->coo_page_init) {
-				result = o->co_ops->coo_page_init(env, o, page,
-								  ind);
+		cl_object_for_each(o2, o) {
+			if (o2->co_ops->coo_page_init) {
+				result = o2->co_ops->coo_page_init(env, o2, page,
+								   ind);
 				if (result != 0) {
 					__cl_page_delete(env, page);
 					cl_page_free(env, page);

  parent reply	other threads:[~2019-02-07  0:03 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-07  0:03 [lustre-devel] [PATCH 00/21] lustre: Assorted cleanups for obdclass NeilBrown
2019-02-07  0:03 ` [lustre-devel] [PATCH 02/21] lustre: obd_class: remove csi_barrier from struct cl_sync_io NeilBrown
2019-02-08  0:09   ` Andreas Dilger
2019-02-11  0:24     ` NeilBrown
2019-02-11  0:34   ` James Simmons
2019-02-11  1:09     ` NeilBrown
2019-02-07  0:03 ` [lustre-devel] [PATCH 05/21] lustre: use list_first_entry() in lustre subdirectory NeilBrown
2019-02-08  0:31   ` Andreas Dilger
2019-02-11  0:13     ` NeilBrown
2019-02-11  1:45   ` James Simmons
2019-02-11  3:08     ` NeilBrown
2019-02-07  0:03 ` [lustre-devel] [PATCH 03/21] lustre: obdclass: use list_sort() to sort a list NeilBrown
2019-02-08  0:13   ` Andreas Dilger
2019-02-11  0:39   ` James Simmons
2019-02-11  1:05     ` NeilBrown
2019-02-07  0:03 ` [lustre-devel] [PATCH 06/21] lustre: use list_first_entry() in lnet/lnet subdirectory NeilBrown
2019-02-08  0:44   ` Andreas Dilger
2019-02-11  1:46   ` James Simmons
2019-02-07  0:03 ` [lustre-devel] [PATCH 01/21] lustre: obdclass: discard csi_end_io NeilBrown
2019-02-07  0:20   ` Andreas Dilger
2019-02-11  0:19   ` James Simmons
2019-02-07  0:03 ` [lustre-devel] [PATCH 04/21] lustre: use list*entry macros in place of container_of() NeilBrown
2019-02-08  0:25   ` Andreas Dilger
2019-02-11  1:32   ` James Simmons
2019-02-11  3:14     ` NeilBrown
2019-02-07  0:03 ` [lustre-devel] [PATCH 13/21] lustre: make cp_ref in cl_page a refcount_t NeilBrown
2019-02-08  5:45   ` Andreas Dilger
2019-02-11  4:00   ` James Simmons
2019-02-07  0:03 ` [lustre-devel] [PATCH 14/21] lustre: make ccc_users in cl_client_cache " NeilBrown
2019-02-08  5:46   ` Andreas Dilger
2019-02-11  4:01   ` James Simmons
2019-02-07  0:03 ` [lustre-devel] [PATCH 08/21] lustre: use list_first_entry() throughout NeilBrown
2019-02-08  1:06   ` Andreas Dilger
2019-02-11  1:48   ` James Simmons
2019-02-07  0:03 ` [lustre-devel] [PATCH 20/21] lustre: obdclass: fix module load locking NeilBrown
2019-02-13  1:53   ` James Simmons
2019-02-07  0:03 ` [lustre-devel] [PATCH 17/21] lustre: obdclass: result of try_module_get() should not be ignored NeilBrown
2019-02-08  5:58   ` Andreas Dilger
2019-02-11  4:22   ` James Simmons
2019-02-11  5:01     ` NeilBrown
2019-02-11  5:09       ` [lustre-devel] [PATCH] lustre: don't manage module refs in obd_class_open/close NeilBrown
2019-02-12  4:17         ` James Simmons
2019-02-07  0:03 ` [lustre-devel] [PATCH 19/21] lustre: obdclass: avoid races in class_register_type() NeilBrown
2019-02-08  6:41   ` Andreas Dilger
2019-02-11  0:58     ` NeilBrown
2019-02-12  5:03   ` James Simmons
2019-02-14  3:43     ` NeilBrown
2019-02-07  0:03 ` [lustre-devel] [PATCH 11/21] lustre: cl_object: remove vestigial debugging NeilBrown
2019-02-08  1:31   ` Andreas Dilger
2019-02-11  0:48     ` NeilBrown
2019-02-11  2:04   ` James Simmons
2019-02-11  3:25     ` NeilBrown
2019-02-12  5:19       ` James Simmons
2019-02-12 13:56         ` Patrick Farrell
2019-02-12 22:12         ` NeilBrown
2019-02-13  0:19           ` James Simmons
2019-02-13  0:29             ` NeilBrown
2019-02-07  0:03 ` [lustre-devel] [PATCH 21/21] lustre: make exp_refcount in obd_export a refcount_t NeilBrown
2019-02-08  7:07   ` Andreas Dilger
2019-02-11  4:18   ` James Simmons
2019-02-07  0:03 ` NeilBrown [this message]
2019-02-08  1:10   ` [lustre-devel] [PATCH 10/21] lustre: obdclass: use cl_object_for_each where appropriate Andreas Dilger
2019-02-11  0:42     ` NeilBrown
2019-02-11  4:19       ` James Simmons
2019-02-15 18:15       ` Andreas Dilger
2019-02-11  1:57   ` James Simmons
2019-02-11  3:19     ` NeilBrown
2019-02-07  0:03 ` [lustre-devel] [PATCH 18/21] lustre: move debug.c from obdclass to obdecho NeilBrown
2019-02-08  6:02   ` Andreas Dilger
2019-02-11  4:17   ` James Simmons
2019-02-07  0:03 ` [lustre-devel] [PATCH 09/21] lustre: use list_last_entry() throughout NeilBrown
2019-02-08  1:07   ` Andreas Dilger
2019-02-11  1:48   ` James Simmons
2019-02-07  0:03 ` [lustre-devel] [PATCH 07/21] lustre: use list_first_entry() in lnet/klnds subdirectory NeilBrown
2019-02-08  0:59   ` Andreas Dilger
2019-02-11  0:34     ` NeilBrown
2019-02-11  1:47   ` James Simmons
2019-02-07  0:03 ` [lustre-devel] [PATCH 16/21] lustre: obdclass: normalize a switch statement NeilBrown
2019-02-08  5:57   ` Andreas Dilger
2019-02-11  4:03   ` James Simmons
2019-02-07  0:03 ` [lustre-devel] [PATCH 12/21] lustre: cl_page.c: remove PINVRNT() NeilBrown
2019-02-08  5:43   ` Andreas Dilger
2019-02-11  4:01   ` James Simmons
2019-02-07  0:03 ` [lustre-devel] [PATCH 15/21] lustre: obdclass: char obd_ioctl_getdata type NeilBrown
2019-02-08  5:56   ` Andreas Dilger
2019-02-11  0:52     ` NeilBrown
2019-02-11  4:03   ` James Simmons

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=154949781310.10620.8883358407999258821.stgit@noble.brown \
    --to=neilb@suse.com \
    --cc=lustre-devel@lists.lustre.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.