Skip to contentSkip to conversation

lustre: push patches ready from lustre-testing

PATCH New James Simmons 1 participant 11 messages Jul 22, 2019 Networking

lore
Share & tools
lore
#0 lore raw

cover lustre: push patches ready from lustre-testing

Several patches from lustre-testing have been reviewed and tested. They are ready to land to the main lustre branch. One patch in lustre-testing to remove set_cblist in ptlrpc has been replaced by a patch from John Hammond that removed even more.

John L. Hammond (1):
lustre: ptlrpc: simplify struct ptlrpc_request_set

NeilBrown (9):
lustre: ldlm: discard varname in ldlm_pool.
lustre: lprocfs: use log2.h macros instead of shift loop.
lustre: ptlrpc: make ptlrpc_bulk_frag_ops always const.
lustre: mgc: remove llog_process_lock
lustre: don't declare extern variables in C files.
lnet: socklnd: fix infinite loop in ksocknal_push()
lustre: ptlrpc: remove inline on non-inlined functions.
lustre: convert rsi_sem to a spinlock.
lustre: ptlrpc: make ptlrpc_last_xid an atomic64_t

 fs/lustre/include/lustre_net.h      | 47 +-------------------
 fs/lustre/include/obd_class.h       | 25 +----------
 fs/lustre/ldlm/ldlm_internal.h      |  2 -
 fs/lustre/ldlm/ldlm_pool.c          | 18 +++-----
 fs/lustre/ldlm/ldlm_resource.c      |  2 -
 fs/lustre/llite/llite_lib.c         |  8 ++--
 fs/lustre/llite/lproc_llite.c       |  4 +-
 fs/lustre/lov/lov_obd.c             | 85 ++++++++++++-------------------------
 fs/lustre/mgc/mgc_request.c         |  6 +--
 fs/lustre/obdclass/lprocfs_status.c | 18 +++-----
 fs/lustre/ptlrpc/client.c           | 82 ++++++++++++++---------------------
 fs/lustre/ptlrpc/import.c           |  1 -
 fs/lustre/ptlrpc/ptlrpc_module.c    |  5 ---
 net/lnet/klnds/socklnd/socklnd.c    |  2 +-
 14 files changed, 82 insertions(+), 223 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/10 lustre: ldlm: discard varname in ldlm_pool.

From: NeilBrown <[email protected]>

This allocated buffer serves no purpose.
A constant string is copied into it, it is passed to some function which copies it out again, then the buffer is freed. Instead, we can pass the constant string to that function.

WC-bug-id: https://jira.whamcloud.com/browse/LU-4423
Reviewed-on: https://review.whamcloud.com/35273

---
 fs/lustre/ldlm/ldlm_internal.h |  2 --
 fs/lustre/ldlm/ldlm_pool.c     | 18 +++++-------------
 2 files changed, 5 insertions(+), 15 deletions(-)
fs/lustre/ldlm/ldlm_internal.h +0 -2
index 05d5b08..a6dee9f 100644
@@ -31,8 +31,6 @@
  * Lustre is a trademark of Sun Microsystems, Inc.
  */
 
-#define MAX_STRING_SIZE 128
-
 extern int ldlm_srv_namespace_nr;
 extern int ldlm_cli_namespace_nr;
 extern struct mutex ldlm_srv_namespace_lock;
fs/lustre/ldlm/ldlm_pool.c +5 -13
index 6714c30..3dfbde5 100644
@@ -504,9 +504,9 @@ static ssize_t grant_speed_show(struct kobject *kobj, struct attribute *attr,
 LDLM_POOL_SYSFS_WRITER_NOLOCK_STORE(lock_volume_factor, atomic);
 LUSTRE_RW_ATTR(lock_volume_factor);
 
-#define LDLM_POOL_ADD_VAR(name, var, ops)			\
+#define LDLM_POOL_ADD_VAR(_name, var, ops)			\
 	do {							\
-		snprintf(var_name, MAX_STRING_SIZE, #name);	\
+		pool_vars[0].name = #_name;			\
 		pool_vars[0].data = var;			\
 		pool_vars[0].fops = ops;			\
 		ldebugfs_add_vars(pl->pl_debugfs_entry, pool_vars, NULL);\
@@ -558,25 +558,18 @@ static int ldlm_pool_debugfs_init(struct ldlm_pool *pl)
 						 ns_pool);
 	struct dentry *debugfs_ns_parent;
 	struct lprocfs_vars pool_vars[2];
-	char *var_name = NULL;
 	int rc = 0;
 
-	var_name = kzalloc(MAX_STRING_SIZE + 1, GFP_NOFS);
-	if (!var_name)
-		return -ENOMEM;
-
 	debugfs_ns_parent = ns->ns_debugfs_entry;
 	if (IS_ERR_OR_NULL(debugfs_ns_parent)) {
 		CERROR("%s: debugfs entry is not initialized\n",
 		       ldlm_ns_name(ns));
 		rc = -EINVAL;
-		goto out_free_name;
+		goto out;
 	}
 	pl->pl_debugfs_entry = debugfs_create_dir("pool", debugfs_ns_parent);
 
-	var_name[MAX_STRING_SIZE] = '\0';
 	memset(pool_vars, 0, sizeof(pool_vars));
-	pool_vars[0].name = var_name;
 
 	LDLM_POOL_ADD_VAR(state, pl, &lprocfs_pool_state_fops);
 
@@ -584,7 +577,7 @@ static int ldlm_pool_debugfs_init(struct ldlm_pool *pl)
 					   LDLM_POOL_FIRST_STAT, 0);
 	if (!pl->pl_stats) {
 		rc = -ENOMEM;
-		goto out_free_name;
+		goto out;
 	}
 
 	lprocfs_counter_init(pl->pl_stats, LDLM_POOL_GRANTED_STAT,
@@ -623,8 +616,7 @@ static int ldlm_pool_debugfs_init(struct ldlm_pool *pl)
 	debugfs_create_file("stats", 0644, pl->pl_debugfs_entry, pl->pl_stats,
 			    &lprocfs_stats_seq_fops);
 
-out_free_name:
-	kfree(var_name);
+out:
 	return rc;
 }
 
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/10 lustre: lprocfs: use log2.h macros instead of shift loop.

In reply to James Simmons

From: NeilBrown <[email protected]>

These shift loops seem to be trying to avoid doing a multiplication.
The same effect can be achieved more transparently using rounddown_pow_of_two(). Even though there is a multiplication in the C code, the resulting machine code just does a single shift.

As rounddown_pow_of_two() is not defined for 0, and as we cannot be positively use the blk_size is non-zero, use blk_size ?: 1.

WC-bug-id: https://jira.whamcloud.com/browse/LU-4423
Reviewed-on: https://review.whamcloud.com/35274

---
 fs/lustre/obdclass/lprocfs_status.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
fs/lustre/obdclass/lprocfs_status.c +3 -7
index c5f5807..2b4302e 100644
@@ -373,9 +373,7 @@ static ssize_t kbytestotal_show(struct kobject *kobj, struct attribute *attr,
 		u32 blk_size = osfs.os_bsize >> 10;
 		u64 result = osfs.os_blocks;
 
-		while (blk_size >>= 1)
-			result <<= 1;
-
+		result *= rounddown_pow_of_two(blk_size ?: 1);
 		return sprintf(buf, "%llu\n", result);
 	}
 
@@ -396,8 +394,7 @@ static ssize_t kbytesfree_show(struct kobject *kobj, struct attribute *attr,
 		u32 blk_size = osfs.os_bsize >> 10;
 		u64 result = osfs.os_bfree;
 
-		while (blk_size >>= 1)
-			result <<= 1;
+		result *= rounddown_pow_of_two(blk_size ?: 1);
 
 		return sprintf(buf, "%llu\n", result);
 	}
@@ -419,8 +416,7 @@ static ssize_t kbytesavail_show(struct kobject *kobj, struct attribute *attr,
 		u32 blk_size = osfs.os_bsize >> 10;
 		u64 result = osfs.os_bavail;
 
-		while (blk_size >>= 1)
-			result <<= 1;
+		result *= rounddown_pow_of_two(blk_size ?: 1);
 
 		return sprintf(buf, "%llu\n", result);
 	}
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 3/10 lustre: ptlrpc: make ptlrpc_bulk_frag_ops always const.

In reply to James Simmons

From: NeilBrown <[email protected]>

There is one place where a non-const pointer to this struct exists, and that causes a cast to be required.

Make it always const, and discard the cast.

WC-bug-id: https://jira.whamcloud.com/browse/LU-4423
Reviewed-on: https://review.whamcloud.com/35295

---
 fs/lustre/include/lustre_net.h | 2 +-
 fs/lustre/ptlrpc/client.c      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
fs/lustre/include/lustre_net.h +1 -1
index 1cf0f12..83f8aff 100644
@@ -1222,7 +1222,7 @@ struct ptlrpc_bulk_desc {
 	struct obd_import		*bd_import;
 	/** Back pointer to the request */
 	struct ptlrpc_request		*bd_req;
-	struct ptlrpc_bulk_frag_ops	*bd_frag_ops;
+	const struct ptlrpc_bulk_frag_ops *bd_frag_ops;
 	wait_queue_head_t		bd_waitq;     /* server side only WQ */
 	int				bd_iov_count; /* # entries in bd_iov */
 	int				bd_max_iov;   /* allocated size of bd_iov */
fs/lustre/ptlrpc/client.c +1 -1
index 364c61f..ff1fa68 100644
@@ -150,7 +150,7 @@ struct ptlrpc_bulk_desc *ptlrpc_new_bulk(unsigned int nfrags,
 	desc->bd_portal = portal;
 	desc->bd_type = type;
 	desc->bd_md_count = 0;
-	desc->bd_frag_ops = (struct ptlrpc_bulk_frag_ops *)ops;
+	desc->bd_frag_ops = ops;
 	LASSERT(max_brw > 0);
 	desc->bd_md_max_brw = min(max_brw, PTLRPC_BULK_OPS_COUNT);
 	/*
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 4/10 lustre: mgc: remove llog_process_lock

In reply to James Simmons

From: NeilBrown <[email protected]>

This mutex is never used, so remove it.

WC-bug-id: https://jira.whamcloud.com/browse/LU-4423
Reviewed-on: https://review.whamcloud.com/35293

---
 fs/lustre/mgc/mgc_request.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
fs/lustre/mgc/mgc_request.c +1 -5
index fa0be5c..581ffb0 100644
@@ -384,8 +384,6 @@ struct config_llog_data *do_config_log_add(struct obd_device *obd,
 	return ERR_PTR(rc);
 }
 
-static DEFINE_MUTEX(llog_process_lock);
-
 static inline void config_mark_cld_stop(struct config_llog_data *cld)
 {
 	if (!cld)
@@ -1538,9 +1536,7 @@ static int mgc_process_cfg_log(struct obd_device *mgc,
 	__llog_ctxt_put(env, ctxt);
 
 	/*
-	 * update settings on existing OBDs. doing it inside
-	 * of llog_process_lock so no device is attaching/detaching
-	 * in parallel.
+	 * update settings on existing OBDs.
 	 * the logname must be <fsname>-sptlrpc
 	 */
 	if (sptlrpc_started) {
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH 5/10 lustre: don't declare extern variables in C files.

In reply to James Simmons

From: NeilBrown <[email protected]>

'extern' declarations should only appear in .h files. All these names are declared in .h files as needed, and these duplicate declarations in .c files can be removed.

WC-bug-id: https://jira.whamcloud.com/browse/LU-4423
Reviewed-on: https://review.whamcloud.com/35294

---
 fs/lustre/ldlm/ldlm_resource.c   | 2 --
 fs/lustre/ptlrpc/import.c        | 1 -
 fs/lustre/ptlrpc/ptlrpc_module.c | 5 -----
 3 files changed, 8 deletions(-)
fs/lustre/ldlm/ldlm_resource.c +0 -2
index 45b2e97..372a290 100644
@@ -681,8 +681,6 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name,
 }
 EXPORT_SYMBOL(ldlm_namespace_new);
 
-extern struct ldlm_lock *ldlm_lock_get(struct ldlm_lock *lock);
-
 /**
  * Cancel and destroy all locks on a resource.
  *
fs/lustre/ptlrpc/import.c +0 -1
index d49707a..67a66a5 100644
@@ -1572,7 +1572,6 @@ int ptlrpc_disconnect_import(struct obd_import *imp, int noclose)
 EXPORT_SYMBOL(ptlrpc_disconnect_import);
 
 /* Adaptive Timeout utils */
-extern unsigned int at_min, at_max, at_history;
 
 /*
  *Update at_current with the specified value (bounded by at_min and at_max),
fs/lustre/ptlrpc/ptlrpc_module.c +0 -5
index f73ba41..6888df9 100644
@@ -40,11 +40,6 @@
 
 #include "ptlrpc_internal.h"
 
-extern spinlock_t ptlrpc_last_xid_lock;
-#if RS_DEBUG
-extern spinlock_t ptlrpc_rs_debug_lock;
-#endif
-
 DEFINE_MUTEX(ptlrpc_startup);
 static int ptlrpc_active;
 
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH 6/10 lnet: socklnd: fix infinite loop in ksocknal_push()

In reply to James Simmons

From: NeilBrown <[email protected]>

If the list_for_each_entry() loop in ksocknal_push() ever finds a match, then it will increment 'i', and the outer loop will continue.

Once peer_off becomes larger than the number of matches in a given chain, 'peer_ni' will be an invalid pointer, and ksocknal_push_peer() will probably crash when called on it.

To abort the outer loop properly, we need to test if "i <= peer_off", which indicates that all patching peers have been found.

This bug can easily be reproduced by running
lctl --net tcp push

WC-bug-id: https://jira.whamcloud.com/browse/LU-12101
Reviewed-on: https://review.whamcloud.com/34499

---
 net/lnet/klnds/socklnd/socklnd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/lnet/klnds/socklnd/socklnd.c +1 -1
index 08feaf7..a422481 100644
@@ -1952,7 +1952,7 @@ static int ksocknal_push(struct lnet_ni *ni, struct lnet_process_id id)
 			}
 			read_unlock(&ksocknal_data.ksnd_global_lock);
 
-			if (!i) /* no match */
+			if (i <= peer_off) /* no match */
 				break;
 
 			rc = 0;
Signature · 1 line
1.8.3.1
#7 lore raw

PATCH 7/10 lustre: ptlrpc: remove inline on non-inlined functions.

In reply to James Simmons

From: NeilBrown <[email protected]>

These three functions are never inlined. The only time they are used, their address is taken, and this forces them to be compiled as stand-alone functions. So having the "inline" declaration is misleading.

Move the functions to the place where their address is used, and remove the 'inline' tag.

WC-bug-id: https://jira.whamcloud.com/browse/LU-4423
Reviewed-on: https://review.whamcloud.com/35296

---
 fs/lustre/include/lustre_net.h | 21 ---------------------
 fs/lustre/ptlrpc/client.c      | 22 ++++++++++++++++++++++
 2 files changed, 22 insertions(+), 21 deletions(-)
fs/lustre/include/lustre_net.h +0 -21
index 83f8aff..f7bd8ad 100644
@@ -1872,30 +1872,9 @@ int ptlrpc_prep_bulk_frag(struct ptlrpc_bulk_desc *desc,
 void __ptlrpc_prep_bulk_page(struct ptlrpc_bulk_desc *desc,
 			     struct page *page, int pageoffset, int len,
 			     int pin);
-static inline void ptlrpc_prep_bulk_page_pin(struct ptlrpc_bulk_desc *desc,
-					     struct page *page, int pageoffset,
-					     int len)
-{
-	__ptlrpc_prep_bulk_page(desc, page, pageoffset, len, 1);
-}
-
-static inline void ptlrpc_prep_bulk_page_nopin(struct ptlrpc_bulk_desc *desc,
-					       struct page *page, int pageoffset,
-					       int len)
-{
-	__ptlrpc_prep_bulk_page(desc, page, pageoffset, len, 0);
-}
 
 void ptlrpc_free_bulk(struct ptlrpc_bulk_desc *bulk);
 
-static inline void ptlrpc_release_bulk_page_pin(struct ptlrpc_bulk_desc *desc)
-{
-	int i;
-
-	for (i = 0; i < desc->bd_iov_count ; i++)
-		put_page(BD_GET_KIOV(desc, i).bv_page);
-}
-
 void ptlrpc_retain_replayable_request(struct ptlrpc_request *req,
 				      struct obd_import *imp);
 u64 ptlrpc_next_xid(void);
fs/lustre/ptlrpc/client.c +22 -0
index ff1fa68..5f3dc3f 100644
@@ -48,6 +48,28 @@
 
 #include "ptlrpc_internal.h"
 
+static void ptlrpc_prep_bulk_page_pin(struct ptlrpc_bulk_desc *desc,
+				      struct page *page, int pageoffset,
+				      int len)
+{
+	__ptlrpc_prep_bulk_page(desc, page, pageoffset, len, 1);
+}
+
+static void ptlrpc_prep_bulk_page_nopin(struct ptlrpc_bulk_desc *desc,
+					struct page *page, int pageoffset,
+					int len)
+{
+	__ptlrpc_prep_bulk_page(desc, page, pageoffset, len, 0);
+}
+
+static void ptlrpc_release_bulk_page_pin(struct ptlrpc_bulk_desc *desc)
+{
+	int i;
+
+	for (i = 0; i < desc->bd_iov_count ; i++)
+		put_page(BD_GET_KIOV(desc, i).bv_page);
+}
+
 const struct ptlrpc_bulk_frag_ops ptlrpc_bulk_kiov_pin_ops = {
 	.add_kiov_frag		= ptlrpc_prep_bulk_page_pin,
 	.release_frags		= ptlrpc_release_bulk_page_pin,
Signature · 1 line
1.8.3.1
#8 lore raw

PATCH 8/10 lustre: convert rsi_sem to a spinlock.

In reply to James Simmons

From: NeilBrown <[email protected]>

This lock is never held over code that sleeps, and is only ever held for short periods of time.
So a simple spinlock is best.

WC-bug-id: https://jira.whamcloud.com/browse/LU-4423
Reviewed-on: https://review.whamcloud.com/35279

---
 fs/lustre/include/obd_class.h       | 3 +--
 fs/lustre/llite/llite_lib.c         | 6 +++---
 fs/lustre/llite/lproc_llite.c       | 4 ++--
 fs/lustre/obdclass/lprocfs_status.c | 8 ++++----
 4 files changed, 10 insertions(+), 11 deletions(-)
fs/lustre/include/obd_class.h +1 -2
index 34a8511..2f02efe 100644
@@ -1689,12 +1689,11 @@ static inline void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out)
 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
 
 /* root squash info */
-struct rw_semaphore;
 struct root_squash_info {
 	uid_t			rsi_uid;
 	gid_t			rsi_gid;
 	struct list_head	rsi_nosquash_nids;
-	struct rw_semaphore	rsi_sem;
+	spinlock_t		rsi_lock;	/* protects rsi_nosquash_nids */
 };
 
 /* linux-module.c */
fs/lustre/llite/llite_lib.c +3 -3
index 4e09f0f..b933f37 100644
@@ -131,7 +131,7 @@ static struct ll_sb_info *ll_init_sbi(void)
 	sbi->ll_squash.rsi_uid = 0;
 	sbi->ll_squash.rsi_gid = 0;
 	INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
-	init_rwsem(&sbi->ll_squash.rsi_sem);
+	spin_lock_init(&sbi->ll_squash.rsi_lock);
 
 	return sbi;
 }
@@ -2578,7 +2578,7 @@ void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
 	int i;
 
 	/* Update norootsquash flag */
-	down_write(&squash->rsi_sem);
+	spin_lock(&squash->rsi_lock);
 	if (list_empty(&squash->rsi_nosquash_nids)) {
 		spin_lock(&sbi->ll_lock);
 		sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
@@ -2606,7 +2606,7 @@ void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
 			sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
 		spin_unlock(&sbi->ll_lock);
 	}
-	up_write(&squash->rsi_sem);
+	spin_unlock(&squash->rsi_lock);
 }
 
 /**
fs/lustre/llite/lproc_llite.c +2 -2
index 99e8a82..69f4f25 100644
@@ -1157,7 +1157,7 @@ static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
 	struct root_squash_info *squash = &sbi->ll_squash;
 	int len;
 
-	down_read(&squash->rsi_sem);
+	spin_lock(&squash->rsi_lock);
 	if (!list_empty(&squash->rsi_nosquash_nids)) {
 		len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
 					&squash->rsi_nosquash_nids);
@@ -1166,7 +1166,7 @@ static int ll_nosquash_nids_seq_show(struct seq_file *m, void *v)
 	} else {
 		seq_puts(m, "NONE\n");
 	}
-	up_read(&squash->rsi_sem);
+	spin_unlock(&squash->rsi_lock);
 
 	return 0;
 }
fs/lustre/obdclass/lprocfs_status.c +4 -4
index 2b4302e..01b8f90 100644
@@ -1747,10 +1747,10 @@ int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
 	if ((len == 4 && !strncmp(kernbuf, "NONE", len)) ||
 	    (len == 5 && !strncmp(kernbuf, "clear", len))) {
 		/* empty string is special case */
-		down_write(&squash->rsi_sem);
+		spin_lock(&squash->rsi_lock);
 		if (!list_empty(&squash->rsi_nosquash_nids))
 			cfs_free_nidlist(&squash->rsi_nosquash_nids);
-		up_write(&squash->rsi_sem);
+		spin_unlock(&squash->rsi_lock);
 		LCONSOLE_INFO("%s: nosquash_nids is cleared\n", name);
 		kfree(kernbuf);
 		return count;
@@ -1767,11 +1767,11 @@ int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
 	kfree(kernbuf);
 	kernbuf = NULL;
 
-	down_write(&squash->rsi_sem);
+	spin_lock(&squash->rsi_lock);
 	if (!list_empty(&squash->rsi_nosquash_nids))
 		cfs_free_nidlist(&squash->rsi_nosquash_nids);
 	list_splice(&tmp, &squash->rsi_nosquash_nids);
-	up_write(&squash->rsi_sem);
+	spin_unlock(&squash->rsi_lock);
 
 	return count;
 
Signature · 1 line
1.8.3.1
#9 lore raw

PATCH 9/10 lustre: ptlrpc: make ptlrpc_last_xid an atomic64_t

In reply to James Simmons

From: NeilBrown <[email protected]>

This variable is treated like an atomic64_t, so change it's type and simplify the code.

WC-bug-id: https://jira.whamcloud.com/browse/LU-4423
Reviewed-on: https://review.whamcloud.com/35510

---
 fs/lustre/ptlrpc/client.c | 39 ++++++++++-----------------------------
 1 file changed, 10 insertions(+), 29 deletions(-)
fs/lustre/ptlrpc/client.c +10 -29
index 5f3dc3f..5c0a3ec 100644
@@ -3062,8 +3062,7 @@ void ptlrpc_abort_set(struct ptlrpc_request_set *set)
 	}
 }
 
-static u64 ptlrpc_last_xid;
-static spinlock_t ptlrpc_last_xid_lock;
+static atomic64_t ptlrpc_last_xid;
 
 /**
  * Initialize the XID for the node.  This is common among all requests on
@@ -3084,19 +3083,20 @@ void ptlrpc_abort_set(struct ptlrpc_request_set *set)
 void ptlrpc_init_xid(void)
 {
 	time64_t now = ktime_get_real_seconds();
+	u64 xid;
 
-	spin_lock_init(&ptlrpc_last_xid_lock);
 	if (now < YEAR_2004) {
-		get_random_bytes(&ptlrpc_last_xid, sizeof(ptlrpc_last_xid));
-		ptlrpc_last_xid >>= 2;
-		ptlrpc_last_xid |= (1ULL << 61);
+		get_random_bytes(&xid, sizeof(xid));
+		xid >>= 2;
+		xid |= (1ULL << 61);
 	} else {
-		ptlrpc_last_xid = (u64)now << 20;
+		xid = (u64)now << 20;
 	}
 
 	/* Always need to be aligned to a power-of-two for multi-bulk BRW */
 	BUILD_BUG_ON(((PTLRPC_BULK_OPS_COUNT - 1) & PTLRPC_BULK_OPS_COUNT) != 0);
-	ptlrpc_last_xid &= PTLRPC_BULK_OPS_MASK;
+	xid &= PTLRPC_BULK_OPS_MASK;
+	atomic64_set(&ptlrpc_last_xid, xid);
 }
 
 /**
@@ -3113,14 +3113,7 @@ void ptlrpc_init_xid(void)
  */
 u64 ptlrpc_next_xid(void)
 {
-	u64 next;
-
-	spin_lock(&ptlrpc_last_xid_lock);
-	next = ptlrpc_last_xid + PTLRPC_BULK_OPS_COUNT;
-	ptlrpc_last_xid = next;
-	spin_unlock(&ptlrpc_last_xid_lock);
-
-	return next;
+	return atomic64_add_return(PTLRPC_BULK_OPS_COUNT, &ptlrpc_last_xid);
 }
 
 /**
@@ -3195,19 +3188,7 @@ void ptlrpc_set_bulk_mbits(struct ptlrpc_request *req)
  */
 u64 ptlrpc_sample_next_xid(void)
 {
-#if BITS_PER_LONG == 32
-	/* need to avoid possible word tearing on 32-bit systems */
-	u64 next;
-
-	spin_lock(&ptlrpc_last_xid_lock);
-	next = ptlrpc_last_xid + PTLRPC_BULK_OPS_COUNT;
-	spin_unlock(&ptlrpc_last_xid_lock);
-
-	return next;
-#else
-	/* No need to lock, since returned value is racy anyways */
-	return ptlrpc_last_xid + PTLRPC_BULK_OPS_COUNT;
-#endif
+	return atomic64_read(&ptlrpc_last_xid) + PTLRPC_BULK_OPS_COUNT;
 }
 EXPORT_SYMBOL(ptlrpc_sample_next_xid);
 
Signature · 1 line
1.8.3.1
#10 lore raw

PATCH 10/10 lustre: ptlrpc: simplify struct ptlrpc_request_set

In reply to James Simmons

From: "John L. Hammond" <[email protected]>

Remove obd_statfs_rqset(), replacing its only use with obd_statfs(). Collapse lov_statfs_async() and lov_statfs() into a single function, removing the need for lov_statfs_interpret().

Remove the then unused set_wakeup_ptr, set_cblist, set_interpret, and set_arg members of struct ptlrpc_request_set. Remove struct ptlrpc_set_cbdata and ptlrpc_set_add_cb(). On x86_64 this reduces the size of struct ptlrpc_request_set from 152 bytes to 112.

WC-bug-id: https://jira.whamcloud.com/browse/LU-10227
Reviewed-on: https://review.whamcloud.com/30060

---
 fs/lustre/include/lustre_net.h | 24 ------------
 fs/lustre/include/obd_class.h  | 22 -----------
 fs/lustre/llite/llite_lib.c    |  2 +-
 fs/lustre/lov/lov_obd.c        | 85 ++++++++++++++----------------------------
 fs/lustre/ptlrpc/client.c      | 19 ----------
 5 files changed, 28 insertions(+), 124 deletions(-)
fs/lustre/include/lustre_net.h +0 -24
index f7bd8ad..fde59df 100644
@@ -331,7 +331,6 @@ struct ptlrpc_client {
 };
 
 struct ptlrpc_request_set;
-typedef int (*set_interpreter_func)(struct ptlrpc_request_set *, void *, int);
 typedef int (*set_producer_func)(struct ptlrpc_request_set *, void *);
 
 /**
@@ -353,20 +352,9 @@ struct ptlrpc_request_set {
 	atomic_t		set_remaining;
 	/** wait queue to wait on for request events */
 	wait_queue_head_t	set_waitq;
-	wait_queue_head_t	*set_wakeup_ptr;
 	/** List of requests in the set */
 	struct list_head	set_requests;
 	/**
-	 * List of completion callbacks to be called when the set is completed
-	 * This is only used if @set_interpret is NULL.
-	 * Links struct ptlrpc_set_cbdata.
-	 */
-	struct list_head	set_cblist;
-	/** Completion callback, if only one. */
-	set_interpreter_func	set_interpret;
-	/** opaq argument passed to completion @set_interpret callback. */
-	void			*set_arg;
-	/**
 	 * Lock for @set_new_requests manipulations
 	 * locked so that any old caller can communicate requests to
 	 * the set holder who can then fold them into the lock-free set
@@ -386,18 +374,6 @@ struct ptlrpc_request_set {
 	void			*set_producer_arg;
 };
 
-/**
- * Description of a single ptrlrpc_set callback
- */
-struct ptlrpc_set_cbdata {
-	/** List linkage item */
-	struct list_head	psc_item;
-	/** Pointer to interpreting function */
-	set_interpreter_func    psc_interpret;
-	/** Opaq argument to pass to the callback */
-	void			*psc_data;
-};
-
 struct ptlrpc_bulk_desc;
 struct ptlrpc_service_part;
 struct ptlrpc_service;
fs/lustre/include/obd_class.h +0 -22
index 2f02efe..f26ca17 100644
@@ -909,28 +909,6 @@ static inline int obd_statfs_async(struct obd_export *exp,
 	return rc;
 }
 
-static inline int obd_statfs_rqset(struct obd_export *exp,
-				   struct obd_statfs *osfs, u64 max_age,
-				   u32 flags)
-{
-	struct ptlrpc_request_set *set = NULL;
-	struct obd_info oinfo = {
-		.oi_osfs = osfs,
-		.oi_flags = flags,
-	};
-	int rc = 0;
-
-	set = ptlrpc_prep_set();
-	if (!set)
-		return -ENOMEM;
-
-	rc = obd_statfs_async(exp, &oinfo, max_age, set);
-	if (rc == 0)
-		rc = ptlrpc_set_wait(set);
-	ptlrpc_set_destroy(set);
-	return rc;
-}
-
 /*
  * @max_age is the oldest time in jiffies that we accept using a cached data.
  * If the cache is older than @max_age we will get a new value from the
fs/lustre/llite/llite_lib.c +1 -1
index b933f37..83b63d8 100644
@@ -1710,7 +1710,7 @@ int ll_statfs_internal(struct ll_sb_info *sbi, struct obd_statfs *osfs,
 	if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
 		flags |= OBD_STATFS_NODELAY;
 
-	rc = obd_statfs_rqset(sbi->ll_dt_exp, &obd_osfs, max_age, flags);
+	rc = obd_statfs(NULL, sbi->ll_dt_exp, &obd_osfs, max_age, flags);
 	if (rc) {
 		CERROR("obd_statfs fails: rc = %d\n", rc);
 		return rc;
fs/lustre/lov/lov_obd.c +27 -58

112 lines not on this page · raw message

fs/lustre/ptlrpc/client.c +0 -19
index 5c0a3ec..f7f3678 100644
@@ -980,7 +980,6 @@ struct ptlrpc_request_set *ptlrpc_prep_set(void)
 	atomic_set(&set->set_remaining, 0);
 	spin_lock_init(&set->set_new_req_lock);
 	INIT_LIST_HEAD(&set->set_new_requests);
-	INIT_LIST_HEAD(&set->set_cblist);
 	set->set_max_inflight = UINT_MAX;
 	set->set_producer = NULL;
 	set->set_producer_arg = NULL;
@@ -2353,24 +2352,6 @@ int ptlrpc_set_wait(struct ptlrpc_request_set *set)
 			rc = req->rq_status;
 	}
 
-	if (set->set_interpret) {
-		int (*interpreter)(struct ptlrpc_request_set *set, void *, int) =
-			set->set_interpret;
-		rc = interpreter(set, set->set_arg, rc);
-	} else {
-		struct ptlrpc_set_cbdata *cbdata, *n;
-		int err;
-
-		list_for_each_entry_safe(cbdata, n,
-					 &set->set_cblist, psc_item) {
-			list_del_init(&cbdata->psc_item);
-			err = cbdata->psc_interpret(set, cbdata->psc_data, rc);
-			if (err && !rc)
-				rc = err;
-			kfree(cbdata);
-		}
-	}
-
 	return rc;
 }
 EXPORT_SYMBOL(ptlrpc_set_wait);
Signature · 1 line
1.8.3.1