2018-06-06 06:12:43

by NeilBrown

[permalink] [raw]
Subject: [md PATCH 00/11] staging: More lustre cleanup - particularly interval-trees

Hi all,
here is my next batch of cleanups for lustre.
Note that this series conflicts with a patch that Greg posted recently
but that has not yet landed in staging-next (it is in
staging-testing).
Up to Greg which gets into staging-next first of course.

I started with the last 5 patches but noticed interval-tree and
decided I should deal with that first. So I added the
interval-tree clean-up. That set is more work to review,
so I put it first.

Comments welcome,

Thanks,
NeilBrown

---

NeilBrown (11):
staging: lustre: simplify use of interval-tree.
staging: lustre: change lock_matches() to return bool.
staging: lustre: move interval_insert call from ldlm_lock to ldlm_extent
staging: lustre: convert range_lock to linux interval_trees.
staging: lustre: convert ldlm extent locks to linux extent-tree
staging: lustre: remove interval_tree
staging: lustre: fold lprocfs_call_handler functionality into lnet_debugfs_*
staging: lustre: obdclass: move linux/linux-foo.c to foo.c
staging: lustre: discard WIRE_ATTR
staging: lustre: move ldlm into ptlrpc
staging: lustre: centralize setting of subdir-ccflags-y


drivers/staging/lustre/Makefile | 3
.../staging/lustre/include/linux/libcfs/libcfs.h | 4
.../staging/lustre/include/linux/lnet/socklnd.h | 8
.../lustre/include/uapi/linux/lnet/lnet-types.h | 28
.../lustre/include/uapi/linux/lnet/lnetst.h | 4
drivers/staging/lustre/lnet/klnds/o2iblnd/Makefile | 2
.../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h | 22
drivers/staging/lustre/lnet/klnds/socklnd/Makefile | 2
drivers/staging/lustre/lnet/libcfs/Makefile | 2
drivers/staging/lustre/lnet/libcfs/module.c | 84 -
drivers/staging/lustre/lnet/lnet/Makefile | 2
drivers/staging/lustre/lnet/lnet/router_proc.c | 41
drivers/staging/lustre/lnet/selftest/Makefile | 2
drivers/staging/lustre/lnet/selftest/rpc.h | 48
drivers/staging/lustre/lustre/fid/Makefile | 2
drivers/staging/lustre/lustre/fld/Makefile | 2
.../staging/lustre/lustre/include/interval_tree.h | 119 -
drivers/staging/lustre/lustre/include/lustre_dlm.h | 19
drivers/staging/lustre/lustre/ldlm/interval_tree.c | 599 ------
drivers/staging/lustre/lustre/ldlm/l_lock.c | 73 -
drivers/staging/lustre/lustre/ldlm/ldlm_extent.c | 258 --
drivers/staging/lustre/lustre/ldlm/ldlm_flock.c | 486 -----
.../staging/lustre/lustre/ldlm/ldlm_inodebits.c | 69 -
drivers/staging/lustre/lustre/ldlm/ldlm_internal.h | 342 ---
drivers/staging/lustre/lustre/ldlm/ldlm_lib.c | 842 --------
drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 2135 --------------------
drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 1163 -----------
drivers/staging/lustre/lustre/ldlm/ldlm_plain.c | 68 -
drivers/staging/lustre/lustre/ldlm/ldlm_pool.c | 1013 ---------
drivers/staging/lustre/lustre/ldlm/ldlm_request.c | 2033 -------------------
drivers/staging/lustre/lustre/ldlm/ldlm_resource.c | 1318 ------------
drivers/staging/lustre/lustre/llite/Makefile | 2
drivers/staging/lustre/lustre/llite/file.c | 8
drivers/staging/lustre/lustre/llite/range_lock.c | 141 -
drivers/staging/lustre/lustre/llite/range_lock.h | 25
drivers/staging/lustre/lustre/lmv/Makefile | 2
drivers/staging/lustre/lustre/lov/Makefile | 2
drivers/staging/lustre/lustre/mdc/Makefile | 2
drivers/staging/lustre/lustre/mgc/Makefile | 2
drivers/staging/lustre/lustre/obdclass/Makefile | 4
.../lustre/lustre/obdclass/linux/linux-module.c | 514 -----
.../lustre/lustre/obdclass/linux/linux-sysctl.c | 162 --
drivers/staging/lustre/lustre/obdclass/module.c | 514 +++++
drivers/staging/lustre/lustre/obdclass/sysctl.c | 162 ++
drivers/staging/lustre/lustre/obdecho/Makefile | 2
drivers/staging/lustre/lustre/osc/Makefile | 2
drivers/staging/lustre/lustre/ptlrpc/Makefile | 17
drivers/staging/lustre/lustre/ptlrpc/l_lock.c | 73 +
drivers/staging/lustre/lustre/ptlrpc/ldlm_extent.c | 206 ++
drivers/staging/lustre/lustre/ptlrpc/ldlm_flock.c | 486 +++++
.../staging/lustre/lustre/ptlrpc/ldlm_inodebits.c | 69 +
.../staging/lustre/lustre/ptlrpc/ldlm_internal.h | 329 +++
drivers/staging/lustre/lustre/ptlrpc/ldlm_lib.c | 842 ++++++++
drivers/staging/lustre/lustre/ptlrpc/ldlm_lock.c | 2103 ++++++++++++++++++++
drivers/staging/lustre/lustre/ptlrpc/ldlm_lockd.c | 1154 +++++++++++
drivers/staging/lustre/lustre/ptlrpc/ldlm_plain.c | 68 +
drivers/staging/lustre/lustre/ptlrpc/ldlm_pool.c | 1013 +++++++++
.../staging/lustre/lustre/ptlrpc/ldlm_request.c | 2033 +++++++++++++++++++
.../staging/lustre/lustre/ptlrpc/ldlm_resource.c | 1318 ++++++++++++
.../staging/lustre/lustre/ptlrpc/ptlrpc_internal.h | 2
60 files changed, 10527 insertions(+), 11523 deletions(-)
delete mode 100644 drivers/staging/lustre/lustre/include/interval_tree.h
delete mode 100644 drivers/staging/lustre/lustre/ldlm/interval_tree.c
delete mode 100644 drivers/staging/lustre/lustre/ldlm/l_lock.c
delete mode 100644 drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
delete mode 100644 drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
delete mode 100644 drivers/staging/lustre/lustre/ldlm/ldlm_inodebits.c
delete mode 100644 drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
delete mode 100644 drivers/staging/lustre/lustre/ldlm/ldlm_lib.c
delete mode 100644 drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
delete mode 100644 drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
delete mode 100644 drivers/staging/lustre/lustre/ldlm/ldlm_plain.c
delete mode 100644 drivers/staging/lustre/lustre/ldlm/ldlm_pool.c
delete mode 100644 drivers/staging/lustre/lustre/ldlm/ldlm_request.c
delete mode 100644 drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
delete mode 100644 drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
delete mode 100644 drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
create mode 100644 drivers/staging/lustre/lustre/obdclass/module.c
create mode 100644 drivers/staging/lustre/lustre/obdclass/sysctl.c
create mode 100644 drivers/staging/lustre/lustre/ptlrpc/l_lock.c
create mode 100644 drivers/staging/lustre/lustre/ptlrpc/ldlm_extent.c
create mode 100644 drivers/staging/lustre/lustre/ptlrpc/ldlm_flock.c
create mode 100644 drivers/staging/lustre/lustre/ptlrpc/ldlm_inodebits.c
create mode 100644 drivers/staging/lustre/lustre/ptlrpc/ldlm_internal.h
create mode 100644 drivers/staging/lustre/lustre/ptlrpc/ldlm_lib.c
create mode 100644 drivers/staging/lustre/lustre/ptlrpc/ldlm_lock.c
create mode 100644 drivers/staging/lustre/lustre/ptlrpc/ldlm_lockd.c
create mode 100644 drivers/staging/lustre/lustre/ptlrpc/ldlm_plain.c
create mode 100644 drivers/staging/lustre/lustre/ptlrpc/ldlm_pool.c
create mode 100644 drivers/staging/lustre/lustre/ptlrpc/ldlm_request.c
create mode 100644 drivers/staging/lustre/lustre/ptlrpc/ldlm_resource.c

--
Signature



2018-06-06 06:12:10

by NeilBrown

[permalink] [raw]
Subject: [PATCH 02/11] staging: lustre: change lock_matches() to return bool.

The name of the function lock_matches() sounds like it
performs a test (it does) and so should return a bool.
Returning a bool gives a slight code simplification (in
search_queue) and more simplification in future patches.

Signed-off-by: NeilBrown <[email protected]>
---
drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 37 ++++++++++++------------
1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
index 13b1b5fdada9..034935e06393 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
@@ -1053,20 +1053,20 @@ struct lock_match_data {
* \param lock test-against this lock
* \param data parameters
*/
-static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data)
+static bool lock_matches(struct ldlm_lock *lock, struct lock_match_data *data)
{
union ldlm_policy_data *lpol = &lock->l_policy_data;
enum ldlm_mode match;

if (lock == data->lmd_old)
- return INTERVAL_ITER_STOP;
+ return true;

/*
* Check if this lock can be matched.
* Used by LU-2919(exclusive open) for open lease lock
*/
if (ldlm_is_excl(lock))
- return INTERVAL_ITER_CONT;
+ return false;

/*
* llite sometimes wants to match locks that will be
@@ -1078,26 +1078,26 @@ static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data)
*/
if (ldlm_is_cbpending(lock) &&
!(data->lmd_flags & LDLM_FL_CBPENDING))
- return INTERVAL_ITER_CONT;
+ return false;

if (!data->lmd_unref && ldlm_is_cbpending(lock) &&
!lock->l_readers && !lock->l_writers)
- return INTERVAL_ITER_CONT;
+ return false;

if (!(lock->l_req_mode & *data->lmd_mode))
- return INTERVAL_ITER_CONT;
+ return false;
match = lock->l_req_mode;

switch (lock->l_resource->lr_type) {
case LDLM_EXTENT:
if (lpol->l_extent.start > data->lmd_policy->l_extent.start ||
lpol->l_extent.end < data->lmd_policy->l_extent.end)
- return INTERVAL_ITER_CONT;
+ return false;

if (unlikely(match == LCK_GROUP) &&
data->lmd_policy->l_extent.gid != LDLM_GID_ANY &&
lpol->l_extent.gid != data->lmd_policy->l_extent.gid)
- return INTERVAL_ITER_CONT;
+ return false;
break;
case LDLM_IBITS:
/*
@@ -1107,7 +1107,7 @@ static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data)
if ((lpol->l_inodebits.bits &
data->lmd_policy->l_inodebits.bits) !=
data->lmd_policy->l_inodebits.bits)
- return INTERVAL_ITER_CONT;
+ return false;
break;
default:
break;
@@ -1117,10 +1117,10 @@ static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data)
* of bits.
*/
if (!data->lmd_unref && LDLM_HAVE_MASK(lock, GONE))
- return INTERVAL_ITER_CONT;
+ return false;

if (!equi(data->lmd_flags & LDLM_FL_LOCAL_ONLY, ldlm_is_local(lock)))
- return INTERVAL_ITER_CONT;
+ return false;

if (data->lmd_flags & LDLM_FL_TEST_LOCK) {
LDLM_LOCK_GET(lock);
@@ -1132,15 +1132,17 @@ static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data)
*data->lmd_mode = match;
data->lmd_lock = lock;

- return INTERVAL_ITER_STOP;
+ return true;
}

static enum interval_iter itree_overlap_cb(struct interval_node *in, void *args)
{
struct lock_match_data *data = args;
- struct ldlm_lock *lock = container_of(in, struct ldlm_lock, l_tree_node);
+ struct ldlm_lock *lock = container_of(in, struct ldlm_lock,
+ l_tree_node);

- return lock_matches(lock, data);
+ return lock_matches(lock, data) ?
+ INTERVAL_ITER_STOP : INTERVAL_ITER_CONT;
}

/**
@@ -1187,13 +1189,10 @@ static struct ldlm_lock *search_queue(struct list_head *queue,
struct lock_match_data *data)
{
struct ldlm_lock *lock;
- int rc;

- list_for_each_entry(lock, queue, l_res_link) {
- rc = lock_matches(lock, data);
- if (rc == INTERVAL_ITER_STOP)
+ list_for_each_entry(lock, queue, l_res_link)
+ if (lock_matches(lock, data))
return data->lmd_lock;
- }
return NULL;
}




2018-06-06 06:12:29

by NeilBrown

[permalink] [raw]
Subject: [PATCH 04/11] staging: lustre: convert range_lock to linux interval_trees.

Linux has a fully-generic interval tree implementation
which can be tailored to different use cases.
Use it for range_lock rather than the lustre version.
This allows us to get rid of some call-backs and generally
simplifies the code.

We cannot use the pre-built version in lib/interval_tree.c
as we need 64bit endpoints and it only provides "unsigned long".

Signed-off-by: NeilBrown <[email protected]>
---
drivers/staging/lustre/lustre/llite/file.c | 8 +-
drivers/staging/lustre/lustre/llite/range_lock.c | 94 ++++++++--------------
drivers/staging/lustre/lustre/llite/range_lock.h | 17 ++--
3 files changed, 47 insertions(+), 72 deletions(-)

diff --git a/drivers/staging/lustre/lustre/llite/file.c b/drivers/staging/lustre/lustre/llite/file.c
index 02295931883b..e888ed6e74bc 100644
--- a/drivers/staging/lustre/lustre/llite/file.c
+++ b/drivers/staging/lustre/lustre/llite/file.c
@@ -1086,8 +1086,8 @@ ll_file_io_generic(const struct lu_env *env, struct vvp_io_args *args,
(iot == CIT_READ && (file->f_flags & O_DIRECT))) &&
!(vio->vui_fd->fd_flags & LL_FILE_GROUP_LOCKED)) {
CDEBUG(D_VFSTRACE, "Range lock [%llu, %llu]\n",
- range.rl_node.in_extent.start,
- range.rl_node.in_extent.end);
+ range.rl_start,
+ range.rl_last);
rc = range_lock(&lli->lli_write_tree, &range);
if (rc < 0)
goto out;
@@ -1099,8 +1099,8 @@ ll_file_io_generic(const struct lu_env *env, struct vvp_io_args *args,
ll_cl_remove(file, env);
if (range_locked) {
CDEBUG(D_VFSTRACE, "Range unlock [%llu, %llu]\n",
- range.rl_node.in_extent.start,
- range.rl_node.in_extent.end);
+ range.rl_start,
+ range.rl_last);
range_unlock(&lli->lli_write_tree, &range);
}
} else {
diff --git a/drivers/staging/lustre/lustre/llite/range_lock.c b/drivers/staging/lustre/lustre/llite/range_lock.c
index eaa23f4c414e..acdb0dc00a89 100644
--- a/drivers/staging/lustre/lustre/llite/range_lock.c
+++ b/drivers/staging/lustre/lustre/llite/range_lock.c
@@ -37,7 +37,13 @@
#include "range_lock.h"
#include <uapi/linux/lustre/lustre_idl.h>
#include <linux/libcfs/libcfs.h>
+#include <linux/interval_tree_generic.h>

+#define START(node) ((node)->rl_start)
+#define LAST(node) ((node)->rl_last)
+
+INTERVAL_TREE_DEFINE(struct range_lock, rl_rb, __u64, __subtree_last,
+ START, LAST, static, range);
/**
* Initialize a range lock tree
*
@@ -48,7 +54,7 @@
*/
void range_lock_tree_init(struct range_lock_tree *tree)
{
- tree->rlt_root = NULL;
+ tree->rlt_root = RB_ROOT_CACHED;
tree->rlt_sequence = 0;
spin_lock_init(&tree->rlt_lock);
}
@@ -65,43 +71,19 @@ void range_lock_tree_init(struct range_lock_tree *tree)
*/
int range_lock_init(struct range_lock *lock, __u64 start, __u64 end)
{
- int rc;
+ RB_CLEAR_NODE(&lock->rl_rb);

- memset(&lock->rl_node, 0, sizeof(lock->rl_node));
if (end != LUSTRE_EOF)
end >>= PAGE_SHIFT;
- rc = interval_set(&lock->rl_node, start >> PAGE_SHIFT, end);
- if (rc)
- return rc;
+ lock->rl_start = start >> PAGE_SHIFT;
+ lock->rl_last = end;
+ if (lock->rl_start > lock->rl_last)
+ return -ERANGE;

lock->rl_task = NULL;
lock->rl_blocking_ranges = 0;
lock->rl_sequence = 0;
- return rc;
-}
-
-/**
- * Helper function of range_unlock()
- *
- * \param node [in] a range lock found overlapped during interval node
- * search
- * \param arg [in] the range lock to be tested
- *
- * \retval INTERVAL_ITER_CONT indicate to continue the search for next
- * overlapping range node
- * \retval INTERVAL_ITER_STOP indicate to stop the search
- */
-static enum interval_iter range_unlock_cb(struct interval_node *node, void *arg)
-{
- struct range_lock *lock = arg;
- struct range_lock *overlap = node2rangelock(node);
-
- if (overlap->rl_sequence > lock->rl_sequence) {
- --overlap->rl_blocking_ranges;
- if (overlap->rl_blocking_ranges == 0)
- wake_up_process(overlap->rl_task);
- }
- return INTERVAL_ITER_CONT;
+ return 0;
}

/**
@@ -112,36 +94,27 @@ static enum interval_iter range_unlock_cb(struct interval_node *node, void *arg)
*
* If this lock has been granted, relase it; if not, just delete it from
* the tree or the same region lock list. Wake up those locks only blocked
- * by this lock through range_unlock_cb().
+ * by this lock.
*/
void range_unlock(struct range_lock_tree *tree, struct range_lock *lock)
{
- spin_lock(&tree->rlt_lock);
- LASSERT(interval_is_intree(&lock->rl_node));
- interval_erase(&lock->rl_node, &tree->rlt_root);
+ struct range_lock *overlap;

- interval_search(tree->rlt_root, &lock->rl_node.in_extent,
- range_unlock_cb, lock);
- spin_unlock(&tree->rlt_lock);
-}
+ spin_lock(&tree->rlt_lock);
+ LASSERT(!RB_EMPTY_NODE(&lock->rl_rb));
+ range_remove(lock, &tree->rlt_root);

-/**
- * Helper function of range_lock()
- *
- * \param node [in] a range lock found overlapped during interval node
- * search
- * \param arg [in] the range lock to be tested
- *
- * \retval INTERVAL_ITER_CONT indicate to continue the search for next
- * overlapping range node
- * \retval INTERVAL_ITER_STOP indicate to stop the search
- */
-static enum interval_iter range_lock_cb(struct interval_node *node, void *arg)
-{
- struct range_lock *lock = arg;
+ for (overlap = range_iter_first(&tree->rlt_root,
+ lock->rl_start, lock->rl_last);
+ overlap;
+ overlap = range_iter_next(overlap, lock->rl_start, lock->rl_last))
+ if (overlap->rl_sequence > lock->rl_sequence) {
+ --overlap->rl_blocking_ranges;
+ if (overlap->rl_blocking_ranges == 0)
+ wake_up_process(overlap->rl_task);
+ }

- lock->rl_blocking_ranges++;
- return INTERVAL_ITER_CONT;
+ spin_unlock(&tree->rlt_lock);
}

/**
@@ -160,15 +133,20 @@ static enum interval_iter range_lock_cb(struct interval_node *node, void *arg)
int range_lock(struct range_lock_tree *tree, struct range_lock *lock)
{
int rc = 0;
+ struct range_lock *it;

spin_lock(&tree->rlt_lock);
/*
* We need to check for all conflicting intervals
* already in the tree.
*/
- interval_search(tree->rlt_root, &lock->rl_node.in_extent,
- range_lock_cb, lock);
- interval_insert(&lock->rl_node, &tree->rlt_root);
+ for (it = range_iter_first(&tree->rlt_root,
+ lock->rl_start, lock->rl_last);
+ it;
+ it = range_iter_next(it, lock->rl_start, lock->rl_last))
+ lock->rl_blocking_ranges++;
+
+ range_insert(lock, &tree->rlt_root);
lock->rl_sequence = ++tree->rlt_sequence;

while (lock->rl_blocking_ranges > 0) {
diff --git a/drivers/staging/lustre/lustre/llite/range_lock.h b/drivers/staging/lustre/lustre/llite/range_lock.h
index 10ef1a995d26..2a0704d21481 100644
--- a/drivers/staging/lustre/lustre/llite/range_lock.h
+++ b/drivers/staging/lustre/lustre/llite/range_lock.h
@@ -38,10 +38,12 @@
#define _RANGE_LOCK_H

#include <linux/spinlock.h>
-#include <interval_tree.h>
+#include <linux/rbtree.h>

struct range_lock {
- struct interval_node rl_node;
+ struct rb_node rl_rb;
+ __u64 rl_start, rl_last;
+ __u64 __subtree_last;
/**
* Process to enqueue this lock.
*/
@@ -57,15 +59,10 @@ struct range_lock {
__u64 rl_sequence;
};

-static inline struct range_lock *node2rangelock(const struct interval_node *n)
-{
- return container_of(n, struct range_lock, rl_node);
-}
-
struct range_lock_tree {
- struct interval_node *rlt_root;
- spinlock_t rlt_lock; /* protect range lock tree */
- __u64 rlt_sequence;
+ struct rb_root_cached rlt_root;
+ spinlock_t rlt_lock; /* protect range lock tree */
+ __u64 rlt_sequence;
};

void range_lock_tree_init(struct range_lock_tree *tree);



2018-06-06 06:12:30

by NeilBrown

[permalink] [raw]
Subject: [PATCH 05/11] staging: lustre: convert ldlm extent locks to linux extent-tree

As linux has a fully customizable extent tree implementation,
use that instead of the one in lustre.
This has a small benefit in that the start/end only need to
be stored in the ldlm_lock once instead of twice - in both
l_policy_data.l_exent and l_tree_node.
It also makes the code simpler.

Signed-off-by: NeilBrown <[email protected]>
---
drivers/staging/lustre/lustre/include/lustre_dlm.h | 9 ++-
drivers/staging/lustre/lustre/ldlm/ldlm_extent.c | 61 ++++++++------------
drivers/staging/lustre/lustre/ldlm/ldlm_internal.h | 4 +
drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 11 ++--
drivers/staging/lustre/lustre/ldlm/ldlm_resource.c | 2 -
5 files changed, 36 insertions(+), 51 deletions(-)

diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
index baeb8c63352b..4f196c27b76b 100644
--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
@@ -49,7 +49,6 @@
#include <lustre_net.h>
#include <lustre_import.h>
#include <lustre_handles.h>
-#include <interval_tree.h> /* for interval_node{}, ldlm_extent */
#include <lu_ref.h>

#include "lustre_dlm_flags.h"
@@ -523,7 +522,7 @@ struct ldlm_interval_tree {
/** Tree size. */
int lit_size;
enum ldlm_mode lit_mode; /* lock mode */
- struct interval_node *lit_root; /* actual ldlm_interval */
+ struct rb_root_cached lit_root; /* actual interval tree */
};

/** Whether to track references to exports by LDLM locks. */
@@ -619,9 +618,11 @@ struct ldlm_lock {
*/
struct list_head l_res_link;
/**
- * Tree node for ldlm_extent.
+ * Interval-tree node for ldlm_extent.
*/
- struct interval_node l_tree_node;
+ struct rb_node l_rb;
+ __u64 __subtree_last;
+
/**
* Requested mode.
* Protected by lr_lock.
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
index eb1a9077a514..225c023b0bba 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
@@ -53,6 +53,12 @@
#include <obd_class.h>
#include <lustre_lib.h>
#include "ldlm_internal.h"
+#include <linux/interval_tree_generic.h>
+
+#define START(node) ((node)->l_policy_data.l_extent.start)
+#define LAST(node) ((node)->l_policy_data.l_extent.end)
+INTERVAL_TREE_DEFINE(struct ldlm_lock, l_rb, __u64, __subtree_last,
+ START, LAST, static, extent);

/* When a lock is cancelled by a client, the KMS may undergo change if this
* is the "highest lock". This function returns the new KMS value.
@@ -108,26 +114,20 @@ static inline int lock_mode_to_index(enum ldlm_mode mode)
void ldlm_extent_add_lock(struct ldlm_resource *res,
struct ldlm_lock *lock)
{
- struct interval_node **root;
- struct ldlm_extent *extent;
- int idx, rc;
+ struct ldlm_interval_tree *tree;
+ int idx;

LASSERT(lock->l_granted_mode == lock->l_req_mode);

- LASSERT(!interval_is_intree(&lock->l_tree_node));
+ LASSERT(RB_EMPTY_NODE(&lock->l_rb));

idx = lock_mode_to_index(lock->l_granted_mode);
LASSERT(lock->l_granted_mode == 1 << idx);
LASSERT(lock->l_granted_mode == res->lr_itree[idx].lit_mode);

- /* node extent initialize */
- extent = &lock->l_policy_data.l_extent;
- rc = interval_set(&lock->l_tree_node, extent->start, extent->end);
- LASSERT(!rc);
-
- root = &res->lr_itree[idx].lit_root;
- interval_insert(&lock->l_tree_node, root);
- res->lr_itree[idx].lit_size++;
+ tree = &res->lr_itree[idx];
+ extent_insert(lock, &tree->lit_root);
+ tree->lit_size++;

/* even though we use interval tree to manage the extent lock, we also
* add the locks into grant list, for debug purpose, ..
@@ -163,17 +163,15 @@ void ldlm_extent_unlink_lock(struct ldlm_lock *lock)
struct ldlm_interval_tree *tree;
int idx;

- if (!interval_is_intree(&lock->l_tree_node)) /* duplicate unlink */
+ if (RB_EMPTY_NODE(&lock->l_rb)) /* duplicate unlink */
return;

idx = lock_mode_to_index(lock->l_granted_mode);
LASSERT(lock->l_granted_mode == 1 << idx);
tree = &res->lr_itree[idx];

- LASSERT(tree->lit_root); /* assure the tree is not null */
-
tree->lit_size--;
- interval_erase(&lock->l_tree_node, &tree->lit_root);
+ extent_remove(lock, &tree->lit_root);
}

void ldlm_extent_policy_wire_to_local(const union ldlm_wire_policy_data *wpolicy,
@@ -193,29 +191,16 @@ void ldlm_extent_policy_local_to_wire(const union ldlm_policy_data *lpolicy,
wpolicy->l_extent.gid = lpolicy->l_extent.gid;
}

-struct cb {
- void *arg;
- bool (*found)(struct ldlm_lock *lock, void *arg);
-};
-
-static enum interval_iter itree_overlap_cb(struct interval_node *in, void *arg)
-{
- struct cb *cb = arg;
- struct ldlm_lock *lock = container_of(in, struct ldlm_lock,
- l_tree_node);
-
- return cb->found(lock, cb->arg) ?
- INTERVAL_ITER_STOP : INTERVAL_ITER_CONT;
-}
-
-void ldlm_extent_search(struct interval_node *root,
- struct interval_node_extent *ext,
+void ldlm_extent_search(struct rb_root_cached *root,
+ __u64 start, __u64 end,
bool (*matches)(struct ldlm_lock *lock, void *data),
void *data)
{
- struct cb cb = {
- .arg = data,
- .found = matches,
- };
- interval_search(root, ext, itree_overlap_cb, &cb);
+ struct ldlm_lock *lock;
+
+ for (lock = extent_iter_first(root, start, end);
+ lock;
+ lock = extent_iter_next(lock, start, end))
+ if (matches(lock, data))
+ break;
}
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h b/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
index 756fa3d9db3c..60a15b963c8a 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
@@ -169,8 +169,8 @@ extern struct kmem_cache *ldlm_lock_slab;
/* ldlm_extent.c */
void ldlm_extent_add_lock(struct ldlm_resource *res, struct ldlm_lock *lock);
void ldlm_extent_unlink_lock(struct ldlm_lock *lock);
-void ldlm_extent_search(struct interval_node *root,
- struct interval_node_extent *ext,
+void ldlm_extent_search(struct rb_root_cached *root,
+ __u64 start, __u64 end,
bool (*matches)(struct ldlm_lock *lock, void *data),
void *data);

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
index 4213fe047073..2fb2e088dc87 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
@@ -405,6 +405,7 @@ static struct ldlm_lock *ldlm_lock_new(struct ldlm_resource *resource)
lock->l_blocking_lock = NULL;
INIT_LIST_HEAD(&lock->l_sl_mode);
INIT_LIST_HEAD(&lock->l_sl_policy);
+ RB_CLEAR_NODE(&lock->l_rb);

lprocfs_counter_incr(ldlm_res_to_ns(resource)->ns_stats,
LDLM_NSS_LOCKS);
@@ -1147,22 +1148,20 @@ static bool lock_matches(struct ldlm_lock *lock, void *vdata)
static struct ldlm_lock *search_itree(struct ldlm_resource *res,
struct lock_match_data *data)
{
- struct interval_node_extent ext = {
- .start = data->lmd_policy->l_extent.start,
- .end = data->lmd_policy->l_extent.end
- };
int idx;

for (idx = 0; idx < LCK_MODE_NUM; idx++) {
struct ldlm_interval_tree *tree = &res->lr_itree[idx];

- if (!tree->lit_root)
+ if (RB_EMPTY_ROOT(&tree->lit_root.rb_root))
continue;

if (!(tree->lit_mode & *data->lmd_mode))
continue;

- ldlm_extent_search(tree->lit_root, &ext,
+ ldlm_extent_search(&tree->lit_root,
+ data->lmd_policy->l_extent.start,
+ data->lmd_policy->l_extent.end,
lock_matches, data);
}
return data->lmd_lock;
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
index c93b019b8e37..3946d62ff009 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
@@ -1017,7 +1017,7 @@ static struct ldlm_resource *ldlm_resource_new(void)
for (idx = 0; idx < LCK_MODE_NUM; idx++) {
res->lr_itree[idx].lit_size = 0;
res->lr_itree[idx].lit_mode = 1 << idx;
- res->lr_itree[idx].lit_root = NULL;
+ res->lr_itree[idx].lit_root = RB_ROOT_CACHED;
}

atomic_set(&res->lr_refcount, 1);



2018-06-06 06:12:40

by NeilBrown

[permalink] [raw]
Subject: [PATCH 06/11] staging: lustre: remove interval_tree

There are no remaining users for this library,
so discard it.

Signed-off-by: NeilBrown <[email protected]>
---
.../staging/lustre/lustre/include/interval_tree.h | 119 ----
drivers/staging/lustre/lustre/ldlm/interval_tree.c | 590 --------------------
drivers/staging/lustre/lustre/ptlrpc/Makefile | 1
3 files changed, 710 deletions(-)
delete mode 100644 drivers/staging/lustre/lustre/include/interval_tree.h
delete mode 100644 drivers/staging/lustre/lustre/ldlm/interval_tree.c

diff --git a/drivers/staging/lustre/lustre/include/interval_tree.h b/drivers/staging/lustre/lustre/include/interval_tree.h
deleted file mode 100644
index bcda74fc7875..000000000000
--- a/drivers/staging/lustre/lustre/include/interval_tree.h
+++ /dev/null
@@ -1,119 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.gnu.org/licenses/gpl-2.0.html
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * lustre/include/interval_tree.h
- *
- * Author: Huang Wei <[email protected]>
- * Author: Jay Xiong <[email protected]>
- */
-
-#ifndef _INTERVAL_H__
-#define _INTERVAL_H__
-
-#include <linux/errno.h>
-#include <linux/string.h>
-#include <linux/types.h>
-
-struct interval_node {
- struct interval_node *in_left;
- struct interval_node *in_right;
- struct interval_node *in_parent;
- unsigned in_color:1,
- in_intree:1, /** set if the node is in tree */
- in_res1:30;
- __u8 in_res2[4]; /** tags, 8-bytes aligned */
- __u64 in_max_high;
- struct interval_node_extent {
- __u64 start;
- __u64 end;
- } in_extent;
-};
-
-enum interval_iter {
- INTERVAL_ITER_CONT = 1,
- INTERVAL_ITER_STOP = 2
-};
-
-static inline int interval_is_intree(struct interval_node *node)
-{
- return node->in_intree == 1;
-}
-
-static inline __u64 interval_low(struct interval_node *node)
-{
- return node->in_extent.start;
-}
-
-static inline __u64 interval_high(struct interval_node *node)
-{
- return node->in_extent.end;
-}
-
-static inline int interval_set(struct interval_node *node,
- __u64 start, __u64 end)
-{
- if (start > end)
- return -ERANGE;
- node->in_extent.start = start;
- node->in_extent.end = end;
- node->in_max_high = end;
- return 0;
-}
-
-/*
- * Rules to write an interval callback.
- * - the callback returns INTERVAL_ITER_STOP when it thinks the iteration
- * should be stopped. It will then cause the iteration function to return
- * immediately with return value INTERVAL_ITER_STOP.
- * - callbacks for interval_iterate and interval_iterate_reverse: Every
- * nodes in the tree will be set to @node before the callback being called
- * - callback for interval_search: Only overlapped node will be set to @node
- * before the callback being called.
- */
-typedef enum interval_iter (*interval_callback_t)(struct interval_node *node,
- void *args);
-
-void interval_insert(struct interval_node *node,
- struct interval_node **root);
-void interval_erase(struct interval_node *node, struct interval_node **root);
-
-/*
- * Search the extents in the tree and call @func for each overlapped
- * extents.
- */
-enum interval_iter interval_search(struct interval_node *root,
- struct interval_node_extent *ex,
- interval_callback_t func, void *data);
-
-enum interval_iter interval_iterate_reverse(struct interval_node *root,
- interval_callback_t func,
- void *data);
-
-#endif
diff --git a/drivers/staging/lustre/lustre/ldlm/interval_tree.c b/drivers/staging/lustre/lustre/ldlm/interval_tree.c
deleted file mode 100644
index f5232059d1b1..000000000000
--- a/drivers/staging/lustre/lustre/ldlm/interval_tree.c
+++ /dev/null
@@ -1,590 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.gnu.org/licenses/gpl-2.0.html
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * lustre/ldlm/interval_tree.c
- *
- * Interval tree library used by ldlm extent lock code
- *
- * Author: Huang Wei <[email protected]>
- * Author: Jay Xiong <[email protected]>
- */
-#include <lustre_dlm.h>
-#include <obd_support.h>
-#include <interval_tree.h>
-
-enum {
- INTERVAL_RED = 0,
- INTERVAL_BLACK = 1
-};
-
-static inline int node_is_left_child(struct interval_node *node)
-{
- return node == node->in_parent->in_left;
-}
-
-static inline int node_is_right_child(struct interval_node *node)
-{
- return node == node->in_parent->in_right;
-}
-
-static inline int node_is_red(struct interval_node *node)
-{
- return node->in_color == INTERVAL_RED;
-}
-
-static inline int node_is_black(struct interval_node *node)
-{
- return node->in_color == INTERVAL_BLACK;
-}
-
-static inline int extent_compare(struct interval_node_extent *e1,
- struct interval_node_extent *e2)
-{
- int rc;
-
- if (e1->start == e2->start) {
- if (e1->end < e2->end)
- rc = -1;
- else if (e1->end > e2->end)
- rc = 1;
- else
- rc = 0;
- } else {
- if (e1->start < e2->start)
- rc = -1;
- else
- rc = 1;
- }
- return rc;
-}
-
-static inline int extent_equal(struct interval_node_extent *e1,
- struct interval_node_extent *e2)
-{
- return (e1->start == e2->start) && (e1->end == e2->end);
-}
-
-static inline int extent_overlapped(struct interval_node_extent *e1,
- struct interval_node_extent *e2)
-{
- return (e1->start <= e2->end) && (e2->start <= e1->end);
-}
-
-static struct interval_node *interval_first(struct interval_node *node)
-{
- if (!node)
- return NULL;
- while (node->in_left)
- node = node->in_left;
- return node;
-}
-
-static struct interval_node *interval_last(struct interval_node *node)
-{
- if (!node)
- return NULL;
- while (node->in_right)
- node = node->in_right;
- return node;
-}
-
-static struct interval_node *interval_next(struct interval_node *node)
-{
- if (!node)
- return NULL;
- if (node->in_right)
- return interval_first(node->in_right);
- while (node->in_parent && node_is_right_child(node))
- node = node->in_parent;
- return node->in_parent;
-}
-
-static struct interval_node *interval_prev(struct interval_node *node)
-{
- if (!node)
- return NULL;
-
- if (node->in_left)
- return interval_last(node->in_left);
-
- while (node->in_parent && node_is_left_child(node))
- node = node->in_parent;
-
- return node->in_parent;
-}
-
-enum interval_iter interval_iterate_reverse(struct interval_node *root,
- interval_callback_t func,
- void *data)
-{
- enum interval_iter rc = INTERVAL_ITER_CONT;
- struct interval_node *node;
-
- for (node = interval_last(root); node; node = interval_prev(node)) {
- rc = func(node, data);
- if (rc == INTERVAL_ITER_STOP)
- break;
- }
-
- return rc;
-}
-EXPORT_SYMBOL(interval_iterate_reverse);
-
-static void __rotate_change_maxhigh(struct interval_node *node,
- struct interval_node *rotate)
-{
- __u64 left_max, right_max;
-
- rotate->in_max_high = node->in_max_high;
- left_max = node->in_left ? node->in_left->in_max_high : 0;
- right_max = node->in_right ? node->in_right->in_max_high : 0;
- node->in_max_high = max(interval_high(node),
- max(left_max, right_max));
-}
-
-/* The left rotation "pivots" around the link from node to node->right, and
- * - node will be linked to node->right's left child, and
- * - node->right's left child will be linked to node's right child.
- */
-static void __rotate_left(struct interval_node *node,
- struct interval_node **root)
-{
- struct interval_node *right = node->in_right;
- struct interval_node *parent = node->in_parent;
-
- node->in_right = right->in_left;
- if (node->in_right)
- right->in_left->in_parent = node;
-
- right->in_left = node;
- right->in_parent = parent;
- if (parent) {
- if (node_is_left_child(node))
- parent->in_left = right;
- else
- parent->in_right = right;
- } else {
- *root = right;
- }
- node->in_parent = right;
-
- /* update max_high for node and right */
- __rotate_change_maxhigh(node, right);
-}
-
-/* The right rotation "pivots" around the link from node to node->left, and
- * - node will be linked to node->left's right child, and
- * - node->left's right child will be linked to node's left child.
- */
-static void __rotate_right(struct interval_node *node,
- struct interval_node **root)
-{
- struct interval_node *left = node->in_left;
- struct interval_node *parent = node->in_parent;
-
- node->in_left = left->in_right;
- if (node->in_left)
- left->in_right->in_parent = node;
- left->in_right = node;
-
- left->in_parent = parent;
- if (parent) {
- if (node_is_right_child(node))
- parent->in_right = left;
- else
- parent->in_left = left;
- } else {
- *root = left;
- }
- node->in_parent = left;
-
- /* update max_high for node and left */
- __rotate_change_maxhigh(node, left);
-}
-
-#define interval_swap(a, b) do { \
- struct interval_node *c = a; a = b; b = c; \
-} while (0)
-
-/*
- * Operations INSERT and DELETE, when run on a tree with n keys,
- * take O(logN) time.Because they modify the tree, the result
- * may violate the red-black properties.To restore these properties,
- * we must change the colors of some of the nodes in the tree
- * and also change the pointer structure.
- */
-static void interval_insert_color(struct interval_node *node,
- struct interval_node **root)
-{
- struct interval_node *parent, *gparent;
-
- while ((parent = node->in_parent) && node_is_red(parent)) {
- gparent = parent->in_parent;
- /* Parent is RED, so gparent must not be NULL */
- if (node_is_left_child(parent)) {
- struct interval_node *uncle;
-
- uncle = gparent->in_right;
- if (uncle && node_is_red(uncle)) {
- uncle->in_color = INTERVAL_BLACK;
- parent->in_color = INTERVAL_BLACK;
- gparent->in_color = INTERVAL_RED;
- node = gparent;
- continue;
- }
-
- if (parent->in_right == node) {
- __rotate_left(parent, root);
- interval_swap(node, parent);
- }
-
- parent->in_color = INTERVAL_BLACK;
- gparent->in_color = INTERVAL_RED;
- __rotate_right(gparent, root);
- } else {
- struct interval_node *uncle;
-
- uncle = gparent->in_left;
- if (uncle && node_is_red(uncle)) {
- uncle->in_color = INTERVAL_BLACK;
- parent->in_color = INTERVAL_BLACK;
- gparent->in_color = INTERVAL_RED;
- node = gparent;
- continue;
- }
-
- if (node_is_left_child(node)) {
- __rotate_right(parent, root);
- interval_swap(node, parent);
- }
-
- parent->in_color = INTERVAL_BLACK;
- gparent->in_color = INTERVAL_RED;
- __rotate_left(gparent, root);
- }
- }
-
- (*root)->in_color = INTERVAL_BLACK;
-}
-
-void interval_insert(struct interval_node *node,
- struct interval_node **root)
-
-{
- struct interval_node **p, *parent = NULL;
-
- LASSERT(!interval_is_intree(node));
- p = root;
- while (*p) {
- parent = *p;
-
- /* max_high field must be updated after each iteration */
- if (parent->in_max_high < interval_high(node))
- parent->in_max_high = interval_high(node);
-
- if (extent_compare(&node->in_extent, &parent->in_extent) < 0)
- p = &parent->in_left;
- else
- p = &parent->in_right;
- }
-
- /* link node into the tree */
- node->in_parent = parent;
- node->in_color = INTERVAL_RED;
- node->in_left = NULL;
- node->in_right = NULL;
- *p = node;
-
- interval_insert_color(node, root);
- node->in_intree = 1;
-}
-EXPORT_SYMBOL(interval_insert);
-
-static inline int node_is_black_or_0(struct interval_node *node)
-{
- return !node || node_is_black(node);
-}
-
-static void interval_erase_color(struct interval_node *node,
- struct interval_node *parent,
- struct interval_node **root)
-{
- struct interval_node *tmp;
-
- while (node_is_black_or_0(node) && node != *root) {
- if (parent->in_left == node) {
- tmp = parent->in_right;
- if (node_is_red(tmp)) {
- tmp->in_color = INTERVAL_BLACK;
- parent->in_color = INTERVAL_RED;
- __rotate_left(parent, root);
- tmp = parent->in_right;
- }
- if (node_is_black_or_0(tmp->in_left) &&
- node_is_black_or_0(tmp->in_right)) {
- tmp->in_color = INTERVAL_RED;
- node = parent;
- parent = node->in_parent;
- } else {
- if (node_is_black_or_0(tmp->in_right)) {
- struct interval_node *o_left;
-
- o_left = tmp->in_left;
- if (o_left)
- o_left->in_color = INTERVAL_BLACK;
- tmp->in_color = INTERVAL_RED;
- __rotate_right(tmp, root);
- tmp = parent->in_right;
- }
- tmp->in_color = parent->in_color;
- parent->in_color = INTERVAL_BLACK;
- if (tmp->in_right)
- tmp->in_right->in_color = INTERVAL_BLACK;
- __rotate_left(parent, root);
- node = *root;
- break;
- }
- } else {
- tmp = parent->in_left;
- if (node_is_red(tmp)) {
- tmp->in_color = INTERVAL_BLACK;
- parent->in_color = INTERVAL_RED;
- __rotate_right(parent, root);
- tmp = parent->in_left;
- }
- if (node_is_black_or_0(tmp->in_left) &&
- node_is_black_or_0(tmp->in_right)) {
- tmp->in_color = INTERVAL_RED;
- node = parent;
- parent = node->in_parent;
- } else {
- if (node_is_black_or_0(tmp->in_left)) {
- struct interval_node *o_right;
-
- o_right = tmp->in_right;
- if (o_right)
- o_right->in_color = INTERVAL_BLACK;
- tmp->in_color = INTERVAL_RED;
- __rotate_left(tmp, root);
- tmp = parent->in_left;
- }
- tmp->in_color = parent->in_color;
- parent->in_color = INTERVAL_BLACK;
- if (tmp->in_left)
- tmp->in_left->in_color = INTERVAL_BLACK;
- __rotate_right(parent, root);
- node = *root;
- break;
- }
- }
- }
- if (node)
- node->in_color = INTERVAL_BLACK;
-}
-
-/*
- * if the @max_high value of @node is changed, this function traverse a path
- * from node up to the root to update max_high for the whole tree.
- */
-static void update_maxhigh(struct interval_node *node,
- __u64 old_maxhigh)
-{
- __u64 left_max, right_max;
-
- while (node) {
- left_max = node->in_left ? node->in_left->in_max_high : 0;
- right_max = node->in_right ? node->in_right->in_max_high : 0;
- node->in_max_high = max(interval_high(node),
- max(left_max, right_max));
-
- if (node->in_max_high >= old_maxhigh)
- break;
- node = node->in_parent;
- }
-}
-
-void interval_erase(struct interval_node *node,
- struct interval_node **root)
-{
- struct interval_node *child, *parent;
- int color;
-
- LASSERT(interval_is_intree(node));
- node->in_intree = 0;
- if (!node->in_left) {
- child = node->in_right;
- } else if (!node->in_right) {
- child = node->in_left;
- } else { /* Both left and right child are not NULL */
- struct interval_node *old = node;
-
- node = interval_next(node);
- child = node->in_right;
- parent = node->in_parent;
- color = node->in_color;
-
- if (child)
- child->in_parent = parent;
- if (parent == old)
- parent->in_right = child;
- else
- parent->in_left = child;
-
- node->in_color = old->in_color;
- node->in_right = old->in_right;
- node->in_left = old->in_left;
- node->in_parent = old->in_parent;
-
- if (old->in_parent) {
- if (node_is_left_child(old))
- old->in_parent->in_left = node;
- else
- old->in_parent->in_right = node;
- } else {
- *root = node;
- }
-
- old->in_left->in_parent = node;
- if (old->in_right)
- old->in_right->in_parent = node;
- update_maxhigh(child ? : parent, node->in_max_high);
- update_maxhigh(node, old->in_max_high);
- if (parent == old)
- parent = node;
- goto color;
- }
- parent = node->in_parent;
- color = node->in_color;
-
- if (child)
- child->in_parent = parent;
- if (parent) {
- if (node_is_left_child(node))
- parent->in_left = child;
- else
- parent->in_right = child;
- } else {
- *root = child;
- }
-
- update_maxhigh(child ? : parent, node->in_max_high);
-
-color:
- if (color == INTERVAL_BLACK)
- interval_erase_color(child, parent, root);
-}
-EXPORT_SYMBOL(interval_erase);
-
-static inline int interval_may_overlap(struct interval_node *node,
- struct interval_node_extent *ext)
-{
- return (ext->start <= node->in_max_high &&
- ext->end >= interval_low(node));
-}
-
-/*
- * This function finds all intervals that overlap interval ext,
- * and calls func to handle resulted intervals one by one.
- * in lustre, this function will find all conflicting locks in
- * the granted queue and add these locks to the ast work list.
- *
- * {
- * if (!node)
- * return 0;
- * if (ext->end < interval_low(node)) {
- * interval_search(node->in_left, ext, func, data);
- * } else if (interval_may_overlap(node, ext)) {
- * if (extent_overlapped(ext, &node->in_extent))
- * func(node, data);
- * interval_search(node->in_left, ext, func, data);
- * interval_search(node->in_right, ext, func, data);
- * }
- * return 0;
- * }
- *
- */
-enum interval_iter interval_search(struct interval_node *node,
- struct interval_node_extent *ext,
- interval_callback_t func,
- void *data)
-{
- enum interval_iter rc = INTERVAL_ITER_CONT;
- struct interval_node *parent;
-
- LASSERT(ext);
- LASSERT(func);
-
- while (node) {
- if (ext->end < interval_low(node)) {
- if (node->in_left) {
- node = node->in_left;
- continue;
- }
- } else if (interval_may_overlap(node, ext)) {
- if (extent_overlapped(ext, &node->in_extent)) {
- rc = func(node, data);
- if (rc == INTERVAL_ITER_STOP)
- break;
- }
-
- if (node->in_left) {
- node = node->in_left;
- continue;
- }
- if (node->in_right) {
- node = node->in_right;
- continue;
- }
- }
-
- parent = node->in_parent;
- while (parent) {
- if (node_is_left_child(node) &&
- parent->in_right) {
- /*
- * If we ever got the left, it means that the
- * parent met ext->end<interval_low(parent), or
- * may_overlap(parent). If the former is true,
- * we needn't go back. So stop early and check
- * may_overlap(parent) after this loop.
- */
- node = parent->in_right;
- break;
- }
- node = parent;
- parent = parent->in_parent;
- }
- if (!parent || !interval_may_overlap(parent, ext))
- break;
- }
-
- return rc;
-}
-EXPORT_SYMBOL(interval_search);
diff --git a/drivers/staging/lustre/lustre/ptlrpc/Makefile b/drivers/staging/lustre/lustre/ptlrpc/Makefile
index 1deb1971b39e..77f8eabb2e28 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/Makefile
+++ b/drivers/staging/lustre/lustre/ptlrpc/Makefile
@@ -11,7 +11,6 @@ ldlm_objs += $(LDLM)ldlm_plain.o $(LDLM)ldlm_extent.o
ldlm_objs += $(LDLM)ldlm_request.o $(LDLM)ldlm_lockd.o
ldlm_objs += $(LDLM)ldlm_flock.o $(LDLM)ldlm_inodebits.o
ldlm_objs += $(LDLM)ldlm_pool.o
-ldlm_objs += $(LDLM)interval_tree.o
ptlrpc_objs := client.o recover.o connection.o niobuf.o pack_generic.o
ptlrpc_objs += events.o ptlrpc_module.o service.o pinger.o
ptlrpc_objs += llog_net.o llog_client.o import.o ptlrpcd.o



2018-06-06 06:13:07

by NeilBrown

[permalink] [raw]
Subject: [PATCH 09/11] staging: lustre: discard WIRE_ATTR

This macro adds nothing of value, and make the code harder
to read for new readers.

Signed-off-by: NeilBrown <[email protected]>
---
.../staging/lustre/include/linux/lnet/socklnd.h | 8 ++-
.../lustre/include/uapi/linux/lnet/lnet-types.h | 28 +++++-------
.../lustre/include/uapi/linux/lnet/lnetst.h | 4 +-
.../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h | 22 +++++----
drivers/staging/lustre/lnet/selftest/rpc.h | 48 ++++++++++----------
5 files changed, 54 insertions(+), 56 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/lnet/socklnd.h b/drivers/staging/lustre/include/linux/lnet/socklnd.h
index 6bd1bca190a3..9f69257e000b 100644
--- a/drivers/staging/lustre/include/linux/lnet/socklnd.h
+++ b/drivers/staging/lustre/include/linux/lnet/socklnd.h
@@ -50,7 +50,7 @@ struct ksock_hello_msg {
__u32 kshm_ctype; /* connection type */
__u32 kshm_nips; /* # IP addrs */
__u32 kshm_ips[0]; /* IP addrs */
-} WIRE_ATTR;
+} __packed;

struct ksock_lnet_msg {
struct lnet_hdr ksnm_hdr; /* lnet hdr */
@@ -61,7 +61,7 @@ struct ksock_lnet_msg {
* structure definitions. lnet payload will be stored just after
* the body of structure ksock_lnet_msg_t
*/
-} WIRE_ATTR;
+} __packed;

struct ksock_msg {
__u32 ksm_type; /* type of socklnd message */
@@ -71,8 +71,8 @@ struct ksock_msg {
struct ksock_lnet_msg lnetmsg; /* lnet message, it's empty if
* it's NOOP
*/
- } WIRE_ATTR ksm_u;
-} WIRE_ATTR;
+ } __packed ksm_u;
+} __packed;

#define KSOCK_MSG_NOOP 0xC0 /* ksm_u empty */
#define KSOCK_MSG_LNET 0xC1 /* lnet msg */
diff --git a/drivers/staging/lustre/include/uapi/linux/lnet/lnet-types.h b/drivers/staging/lustre/include/uapi/linux/lnet/lnet-types.h
index 1be9b7aa7326..f97e7d9d881f 100644
--- a/drivers/staging/lustre/include/uapi/linux/lnet/lnet-types.h
+++ b/drivers/staging/lustre/include/uapi/linux/lnet/lnet-types.h
@@ -112,14 +112,12 @@ static inline __u32 LNET_MKNET(__u32 type, __u32 num)
return (type << 16) | num;
}

-#define WIRE_ATTR __packed
-
/* Packed version of lnet_process_id to transfer via network */
struct lnet_process_id_packed {
/* node id / process id */
lnet_nid_t nid;
lnet_pid_t pid;
-} WIRE_ATTR;
+} __packed;

/*
* The wire handle's interface cookie only matches one network interface in
@@ -130,7 +128,7 @@ struct lnet_process_id_packed {
struct lnet_handle_wire {
__u64 wh_interface_cookie;
__u64 wh_object_cookie;
-} WIRE_ATTR;
+} __packed;

enum lnet_msg_type {
LNET_MSG_ACK = 0,
@@ -150,7 +148,7 @@ struct lnet_ack {
struct lnet_handle_wire dst_wmd;
__u64 match_bits;
__u32 mlength;
-} WIRE_ATTR;
+} __packed;

struct lnet_put {
struct lnet_handle_wire ack_wmd;
@@ -158,7 +156,7 @@ struct lnet_put {
__u64 hdr_data;
__u32 ptl_index;
__u32 offset;
-} WIRE_ATTR;
+} __packed;

struct lnet_get {
struct lnet_handle_wire return_wmd;
@@ -166,16 +164,16 @@ struct lnet_get {
__u32 ptl_index;
__u32 src_offset;
__u32 sink_length;
-} WIRE_ATTR;
+} __packed;

struct lnet_reply {
struct lnet_handle_wire dst_wmd;
-} WIRE_ATTR;
+} __packed;

struct lnet_hello {
__u64 incarnation;
__u32 type;
-} WIRE_ATTR;
+} __packed;

struct lnet_hdr {
lnet_nid_t dest_nid;
@@ -192,7 +190,7 @@ struct lnet_hdr {
struct lnet_reply reply;
struct lnet_hello hello;
} msg;
-} WIRE_ATTR;
+} __packed;

/*
* A HELLO message contains a magic number and protocol version
@@ -208,7 +206,7 @@ struct lnet_magicversion {
__u32 magic; /* LNET_PROTO_TCP_MAGIC */
__u16 version_major; /* increment on incompatible change */
__u16 version_minor; /* increment on compatible change */
-} WIRE_ATTR;
+} __packed;

/* PROTO MAGIC for LNDs */
#define LNET_PROTO_IB_MAGIC 0x0be91b91
@@ -232,7 +230,7 @@ struct lnet_acceptor_connreq {
__u32 acr_magic; /* PTL_ACCEPTOR_PROTO_MAGIC */
__u32 acr_version; /* protocol version */
__u64 acr_nid; /* target NID */
-} WIRE_ATTR;
+} __packed;

#define LNET_PROTO_ACCEPTOR_VERSION 1

@@ -240,7 +238,7 @@ struct lnet_ni_status {
lnet_nid_t ns_nid;
__u32 ns_status;
__u32 ns_unused;
-} WIRE_ATTR;
+} __packed;

struct lnet_ping_info {
__u32 pi_magic;
@@ -248,7 +246,7 @@ struct lnet_ping_info {
lnet_pid_t pi_pid;
__u32 pi_nnis;
struct lnet_ni_status pi_ni[0];
-} WIRE_ATTR;
+} __packed;

struct lnet_counters {
__u32 msgs_alloc;
@@ -262,7 +260,7 @@ struct lnet_counters {
__u64 recv_length;
__u64 route_length;
__u64 drop_length;
-} WIRE_ATTR;
+} __packed;

#define LNET_NI_STATUS_UP 0x15aac0de
#define LNET_NI_STATUS_DOWN 0xdeadface
diff --git a/drivers/staging/lustre/include/uapi/linux/lnet/lnetst.h b/drivers/staging/lustre/include/uapi/linux/lnet/lnetst.h
index a4f9ff01d458..7edba2c5bb87 100644
--- a/drivers/staging/lustre/include/uapi/linux/lnet/lnetst.h
+++ b/drivers/staging/lustre/include/uapi/linux/lnet/lnetst.h
@@ -542,7 +542,7 @@ struct srpc_counters {
__u32 rpcs_expired;
__u64 bulk_get;
__u64 bulk_put;
-} WIRE_ATTR;
+} __packed;

struct sfw_counters {
/** milliseconds since current session started */
@@ -551,6 +551,6 @@ struct sfw_counters {
__u32 zombie_sessions;
__u32 brw_errors;
__u32 ping_errors;
-} WIRE_ATTR;
+} __packed;

#endif
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
index 217503f125bc..7d8429672616 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
@@ -359,45 +359,45 @@ struct kib_connparams {
__u16 ibcp_queue_depth;
__u16 ibcp_max_frags;
__u32 ibcp_max_msg_size;
-} WIRE_ATTR;
+} __packed;

struct kib_immediate_msg {
struct lnet_hdr ibim_hdr; /* portals header */
char ibim_payload[0]; /* piggy-backed payload */
-} WIRE_ATTR;
+} __packed;

struct kib_rdma_frag {
__u32 rf_nob; /* # bytes this frag */
__u64 rf_addr; /* CAVEAT EMPTOR: misaligned!! */
-} WIRE_ATTR;
+} __packed;

struct kib_rdma_desc {
__u32 rd_key; /* local/remote key */
__u32 rd_nfrags; /* # fragments */
struct kib_rdma_frag rd_frags[0]; /* buffer frags */
-} WIRE_ATTR;
+} __packed;

struct kib_putreq_msg {
struct lnet_hdr ibprm_hdr; /* portals header */
__u64 ibprm_cookie; /* opaque completion cookie */
-} WIRE_ATTR;
+} __packed;

struct kib_putack_msg {
__u64 ibpam_src_cookie; /* reflected completion cookie */
__u64 ibpam_dst_cookie; /* opaque completion cookie */
struct kib_rdma_desc ibpam_rd; /* sender's sink buffer */
-} WIRE_ATTR;
+} __packed;

struct kib_get_msg {
struct lnet_hdr ibgm_hdr; /* portals header */
__u64 ibgm_cookie; /* opaque completion cookie */
struct kib_rdma_desc ibgm_rd; /* rdma descriptor */
-} WIRE_ATTR;
+} __packed;

struct kib_completion_msg {
__u64 ibcm_cookie; /* opaque completion cookie */
__s32 ibcm_status; /* < 0 failure: >= 0 length */
-} WIRE_ATTR;
+} __packed;

struct kib_msg {
/* First 2 fields fixed FOR ALL TIME */
@@ -420,8 +420,8 @@ struct kib_msg {
struct kib_putack_msg putack;
struct kib_get_msg get;
struct kib_completion_msg completion;
- } WIRE_ATTR ibm_u;
-} WIRE_ATTR;
+ } __packed ibm_u;
+} __packed;

#define IBLND_MSG_MAGIC LNET_PROTO_IB_MAGIC /* unique magic */

@@ -447,7 +447,7 @@ struct kib_rej {
__u8 ibr_padding; /* padding */
__u64 ibr_incarnation; /* incarnation of peer */
struct kib_connparams ibr_cp; /* connection parameters */
-} WIRE_ATTR;
+} __packed;

/* connection rejection reasons */
#define IBLND_REJECT_CONN_RACE 1 /* You lost connection race */
diff --git a/drivers/staging/lustre/lnet/selftest/rpc.h b/drivers/staging/lustre/lnet/selftest/rpc.h
index 465b5b534423..9ce336739449 100644
--- a/drivers/staging/lustre/lnet/selftest/rpc.h
+++ b/drivers/staging/lustre/lnet/selftest/rpc.h
@@ -72,12 +72,12 @@ enum srpc_msg_type {
struct srpc_generic_reqst {
__u64 rpyid; /* reply buffer matchbits */
__u64 bulkid; /* bulk buffer matchbits */
-} WIRE_ATTR;
+} __packed;

struct srpc_generic_reply {
__u32 status;
struct lst_sid sid;
-} WIRE_ATTR;
+} __packed;

/* FRAMEWORK RPCs */
struct srpc_mksn_reqst {
@@ -85,30 +85,30 @@ struct srpc_mksn_reqst {
struct lst_sid mksn_sid; /* session id */
__u32 mksn_force; /* use brute force */
char mksn_name[LST_NAME_SIZE];
-} WIRE_ATTR; /* make session request */
+} __packed; /* make session request */

struct srpc_mksn_reply {
__u32 mksn_status; /* session status */
struct lst_sid mksn_sid; /* session id */
__u32 mksn_timeout; /* session timeout */
char mksn_name[LST_NAME_SIZE];
-} WIRE_ATTR; /* make session reply */
+} __packed; /* make session reply */

struct srpc_rmsn_reqst {
__u64 rmsn_rpyid; /* reply buffer matchbits */
struct lst_sid rmsn_sid; /* session id */
-} WIRE_ATTR; /* remove session request */
+} __packed; /* remove session request */

struct srpc_rmsn_reply {
__u32 rmsn_status;
struct lst_sid rmsn_sid; /* session id */
-} WIRE_ATTR; /* remove session reply */
+} __packed; /* remove session reply */

struct srpc_join_reqst {
__u64 join_rpyid; /* reply buffer matchbits */
struct lst_sid join_sid; /* session id to join */
char join_group[LST_NAME_SIZE]; /* group name */
-} WIRE_ATTR;
+} __packed;

struct srpc_join_reply {
__u32 join_status; /* returned status */
@@ -117,13 +117,13 @@ struct srpc_join_reply {
* expire
*/
char join_session[LST_NAME_SIZE]; /* session name */
-} WIRE_ATTR;
+} __packed;

struct srpc_debug_reqst {
__u64 dbg_rpyid; /* reply buffer matchbits */
struct lst_sid dbg_sid; /* session id */
__u32 dbg_flags; /* bitmap of debug */
-} WIRE_ATTR;
+} __packed;

struct srpc_debug_reply {
__u32 dbg_status; /* returned code */
@@ -131,7 +131,7 @@ struct srpc_debug_reply {
__u32 dbg_timeout; /* session timeout */
__u32 dbg_nbatch; /* # of batches in the node */
char dbg_name[LST_NAME_SIZE]; /* session name */
-} WIRE_ATTR;
+} __packed;

#define SRPC_BATCH_OPC_RUN 1
#define SRPC_BATCH_OPC_STOP 2
@@ -144,20 +144,20 @@ struct srpc_batch_reqst {
__u32 bar_opc; /* create/start/stop batch */
__u32 bar_testidx; /* index of test */
__u32 bar_arg; /* parameters */
-} WIRE_ATTR;
+} __packed;

struct srpc_batch_reply {
__u32 bar_status; /* status of request */
struct lst_sid bar_sid; /* session id */
__u32 bar_active; /* # of active tests in batch/test */
__u32 bar_time; /* remained time */
-} WIRE_ATTR;
+} __packed;

struct srpc_stat_reqst {
__u64 str_rpyid; /* reply buffer matchbits */
struct lst_sid str_sid; /* session id */
__u32 str_type; /* type of stat */
-} WIRE_ATTR;
+} __packed;

struct srpc_stat_reply {
__u32 str_status;
@@ -165,25 +165,25 @@ struct srpc_stat_reply {
struct sfw_counters str_fw;
struct srpc_counters str_rpc;
struct lnet_counters str_lnet;
-} WIRE_ATTR;
+} __packed;

struct test_bulk_req {
__u32 blk_opc; /* bulk operation code */
__u32 blk_npg; /* # of pages */
__u32 blk_flags; /* reserved flags */
-} WIRE_ATTR;
+} __packed;

struct test_bulk_req_v1 {
__u16 blk_opc; /* bulk operation code */
__u16 blk_flags; /* data check flags */
__u32 blk_len; /* data length */
__u32 blk_offset; /* offset */
-} WIRE_ATTR;
+} __packed;

struct test_ping_req {
__u32 png_size; /* size of ping message */
__u32 png_flags; /* reserved flags */
-} WIRE_ATTR;
+} __packed;

struct srpc_test_reqst {
__u64 tsr_rpyid; /* reply buffer matchbits */
@@ -204,12 +204,12 @@ struct srpc_test_reqst {
struct test_bulk_req bulk_v0;
struct test_bulk_req_v1 bulk_v1;
} tsr_u;
-} WIRE_ATTR;
+} __packed;

struct srpc_test_reply {
__u32 tsr_status; /* returned code */
struct lst_sid tsr_sid;
-} WIRE_ATTR;
+} __packed;

/* TEST RPCs */
struct srpc_ping_reqst {
@@ -218,13 +218,13 @@ struct srpc_ping_reqst {
__u32 pnr_seq;
__u64 pnr_time_sec;
__u64 pnr_time_usec;
-} WIRE_ATTR;
+} __packed;

struct srpc_ping_reply {
__u32 pnr_status;
__u32 pnr_magic;
__u32 pnr_seq;
-} WIRE_ATTR;
+} __packed;

struct srpc_brw_reqst {
__u64 brw_rpyid; /* reply buffer matchbits */
@@ -232,11 +232,11 @@ struct srpc_brw_reqst {
__u32 brw_rw; /* read or write */
__u32 brw_len; /* bulk data len */
__u32 brw_flags; /* bulk data patterns */
-} WIRE_ATTR; /* bulk r/w request */
+} __packed; /* bulk r/w request */

struct srpc_brw_reply {
__u32 brw_status;
-} WIRE_ATTR; /* bulk r/w reply */
+} __packed; /* bulk r/w reply */

#define SRPC_MSG_MAGIC 0xeeb0f00d
#define SRPC_MSG_VERSION 1
@@ -272,7 +272,7 @@ struct srpc_msg {
struct srpc_brw_reqst brw_reqst;
struct srpc_brw_reply brw_reply;
} msg_body;
-} WIRE_ATTR;
+} __packed;

static inline void
srpc_unpack_msg_hdr(struct srpc_msg *msg)



2018-06-06 06:13:10

by NeilBrown

[permalink] [raw]
Subject: [PATCH 01/11] staging: lustre: simplify use of interval-tree.

Lustre has a private interval-tree implementation. This
implementation (inexplicably) refuses to insert an interval if an
identical interval already exists. It is OK with all sorts of
overlapping intervals, but identical intervals are rejected.

Both users of interval-tree in lustre would be simpler if this was not
the case. They need to store all intervals, even if some are
identical.

llite/range_lock.c add a rl_next_lock list_head to each lock.
If it cannot insert a new lock because the range is in use, it
attached the new lock to the existing lock using rl_next_lock.
This requires extra code to iterate over the rl_next_lock lists when
iterating over locks, and to update the list when deleting a lock from
the tree.

ldlm_extend allocates a separate ldlm_interval which as a list of
ldlm_locks which share the same interval. This is linked together
by over-loading the l_sl_policy which, for non-extent locks, is used
for linking together locks with the same policy.
This doesn't only require extra code, but also an extra memory
allocation.

This patch removes all that complexity.
- interval_insert() now never fails.
- consequently rl_next_lock is always empty and
rl_lock_count is always zero. so they are removed
- every ldlm_lock has linked directly into the
interval tree, so each has an embedded interval_node
rather than a pointer to a 'struct ldlm_interval'
- ldlm_interval is now unused, so it is gone as it
the kmemcache from which they were allocated.
- the various functions for allocating an ldlm_interval
and attaching to a lock or detaching from a lock
are also gone.

Signed-off-by: NeilBrown <[email protected]>
---
.../staging/lustre/lustre/include/interval_tree.h | 4 +
drivers/staging/lustre/lustre/include/lustre_dlm.h | 12 ---
drivers/staging/lustre/lustre/ldlm/interval_tree.c | 13 +--
drivers/staging/lustre/lustre/ldlm/ldlm_extent.c | 76 ++------------------
drivers/staging/lustre/lustre/ldlm/ldlm_internal.h | 17 ----
drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 25 +------
drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 9 --
drivers/staging/lustre/lustre/llite/range_lock.c | 59 +---------------
drivers/staging/lustre/lustre/llite/range_lock.h | 8 --
9 files changed, 17 insertions(+), 206 deletions(-)

diff --git a/drivers/staging/lustre/lustre/include/interval_tree.h b/drivers/staging/lustre/lustre/include/interval_tree.h
index 7d119c1a0469..bcda74fc7875 100644
--- a/drivers/staging/lustre/lustre/include/interval_tree.h
+++ b/drivers/staging/lustre/lustre/include/interval_tree.h
@@ -100,8 +100,8 @@ static inline int interval_set(struct interval_node *node,
typedef enum interval_iter (*interval_callback_t)(struct interval_node *node,
void *args);

-struct interval_node *interval_insert(struct interval_node *node,
- struct interval_node **root);
+void interval_insert(struct interval_node *node,
+ struct interval_node **root);
void interval_erase(struct interval_node *node, struct interval_node **root);

/*
diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
index 2c55241258cc..baeb8c63352b 100644
--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
@@ -513,16 +513,6 @@ struct ldlm_glimpse_work {
/** The ldlm_glimpse_work is allocated on the stack and should not be freed. */
#define LDLM_GL_WORK_NOFREE 0x1

-/** Interval node data for each LDLM_EXTENT lock. */
-struct ldlm_interval {
- struct interval_node li_node; /* node for tree management */
- struct list_head li_group; /* the locks which have the same
- * policy - group of the policy
- */
-};
-
-#define to_ldlm_interval(n) container_of(n, struct ldlm_interval, li_node)
-
/**
* Interval tree for extent locks.
* The interval tree must be accessed under the resource lock.
@@ -631,7 +621,7 @@ struct ldlm_lock {
/**
* Tree node for ldlm_extent.
*/
- struct ldlm_interval *l_tree_node;
+ struct interval_node l_tree_node;
/**
* Requested mode.
* Protected by lr_lock.
diff --git a/drivers/staging/lustre/lustre/ldlm/interval_tree.c b/drivers/staging/lustre/lustre/ldlm/interval_tree.c
index 8df7a4463c21..f5232059d1b1 100644
--- a/drivers/staging/lustre/lustre/ldlm/interval_tree.c
+++ b/drivers/staging/lustre/lustre/ldlm/interval_tree.c
@@ -97,11 +97,6 @@ static inline int extent_overlapped(struct interval_node_extent *e1,
return (e1->start <= e2->end) && (e2->start <= e1->end);
}

-static inline int node_equal(struct interval_node *n1, struct interval_node *n2)
-{
- return extent_equal(&n1->in_extent, &n2->in_extent);
-}
-
static struct interval_node *interval_first(struct interval_node *node)
{
if (!node)
@@ -299,8 +294,8 @@ static void interval_insert_color(struct interval_node *node,
(*root)->in_color = INTERVAL_BLACK;
}

-struct interval_node *interval_insert(struct interval_node *node,
- struct interval_node **root)
+void interval_insert(struct interval_node *node,
+ struct interval_node **root)

{
struct interval_node **p, *parent = NULL;
@@ -309,8 +304,6 @@ struct interval_node *interval_insert(struct interval_node *node,
p = root;
while (*p) {
parent = *p;
- if (node_equal(parent, node))
- return parent;

/* max_high field must be updated after each iteration */
if (parent->in_max_high < interval_high(node))
@@ -331,8 +324,6 @@ struct interval_node *interval_insert(struct interval_node *node,

interval_insert_color(node, root);
node->in_intree = 1;
-
- return NULL;
}
EXPORT_SYMBOL(interval_insert);

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
index 4da23ade2bb3..2f4c305bb340 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
@@ -92,55 +92,6 @@ __u64 ldlm_extent_shift_kms(struct ldlm_lock *lock, __u64 old_kms)
}
EXPORT_SYMBOL(ldlm_extent_shift_kms);

-struct kmem_cache *ldlm_interval_slab;
-
-/* interval tree, for LDLM_EXTENT. */
-static void ldlm_interval_attach(struct ldlm_interval *n, struct ldlm_lock *l)
-{
- LASSERT(!l->l_tree_node);
- LASSERT(l->l_resource->lr_type == LDLM_EXTENT);
-
- list_add_tail(&l->l_sl_policy, &n->li_group);
- l->l_tree_node = n;
-}
-
-struct ldlm_interval *ldlm_interval_alloc(struct ldlm_lock *lock)
-{
- struct ldlm_interval *node;
-
- LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
- node = kmem_cache_zalloc(ldlm_interval_slab, GFP_NOFS);
- if (!node)
- return NULL;
-
- INIT_LIST_HEAD(&node->li_group);
- ldlm_interval_attach(node, lock);
- return node;
-}
-
-void ldlm_interval_free(struct ldlm_interval *node)
-{
- if (node) {
- LASSERT(list_empty(&node->li_group));
- LASSERT(!interval_is_intree(&node->li_node));
- kmem_cache_free(ldlm_interval_slab, node);
- }
-}
-
-struct ldlm_interval *ldlm_interval_detach(struct ldlm_lock *l)
-{
- struct ldlm_interval *n = l->l_tree_node;
-
- if (!n)
- return NULL;
-
- LASSERT(!list_empty(&n->li_group));
- l->l_tree_node = NULL;
- list_del_init(&l->l_sl_policy);
-
- return list_empty(&n->li_group) ? n : NULL;
-}
-
static inline int lock_mode_to_index(enum ldlm_mode mode)
{
int index;
@@ -157,16 +108,13 @@ static inline int lock_mode_to_index(enum ldlm_mode mode)
void ldlm_extent_add_lock(struct ldlm_resource *res,
struct ldlm_lock *lock)
{
- struct interval_node *found, **root;
- struct ldlm_interval *node;
+ struct interval_node **root;
struct ldlm_extent *extent;
int idx, rc;

LASSERT(lock->l_granted_mode == lock->l_req_mode);

- node = lock->l_tree_node;
- LASSERT(node);
- LASSERT(!interval_is_intree(&node->li_node));
+ LASSERT(!interval_is_intree(&lock->l_tree_node));

idx = lock_mode_to_index(lock->l_granted_mode);
LASSERT(lock->l_granted_mode == 1 << idx);
@@ -174,18 +122,11 @@ void ldlm_extent_add_lock(struct ldlm_resource *res,

/* node extent initialize */
extent = &lock->l_policy_data.l_extent;
- rc = interval_set(&node->li_node, extent->start, extent->end);
+ rc = interval_set(&lock->l_tree_node, extent->start, extent->end);
LASSERT(!rc);

root = &res->lr_itree[idx].lit_root;
- found = interval_insert(&node->li_node, root);
- if (found) { /* The policy group found. */
- struct ldlm_interval *tmp;
-
- tmp = ldlm_interval_detach(lock);
- ldlm_interval_free(tmp);
- ldlm_interval_attach(to_ldlm_interval(found), lock);
- }
+ interval_insert(&lock->l_tree_node, root);
res->lr_itree[idx].lit_size++;

/* even though we use interval tree to manage the extent lock, we also
@@ -219,11 +160,10 @@ void ldlm_extent_add_lock(struct ldlm_resource *res,
void ldlm_extent_unlink_lock(struct ldlm_lock *lock)
{
struct ldlm_resource *res = lock->l_resource;
- struct ldlm_interval *node = lock->l_tree_node;
struct ldlm_interval_tree *tree;
int idx;

- if (!node || !interval_is_intree(&node->li_node)) /* duplicate unlink */
+ if (!interval_is_intree(&lock->l_tree_node)) /* duplicate unlink */
return;

idx = lock_mode_to_index(lock->l_granted_mode);
@@ -233,11 +173,7 @@ void ldlm_extent_unlink_lock(struct ldlm_lock *lock)
LASSERT(tree->lit_root); /* assure the tree is not null */

tree->lit_size--;
- node = ldlm_interval_detach(lock);
- if (node) {
- interval_erase(&node->li_node, &tree->lit_root);
- ldlm_interval_free(node);
- }
+ interval_erase(&lock->l_tree_node, &tree->lit_root);
}

void ldlm_extent_policy_wire_to_local(const union ldlm_wire_policy_data *wpolicy,
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h b/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
index bc33ca100620..159de8a59cbb 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
@@ -189,23 +189,6 @@ __u64 ldlm_pool_get_slv(struct ldlm_pool *pl);
void ldlm_pool_set_clv(struct ldlm_pool *pl, __u64 clv);
__u32 ldlm_pool_get_lvf(struct ldlm_pool *pl);

-/* interval tree, for LDLM_EXTENT. */
-extern struct kmem_cache *ldlm_interval_slab; /* slab cache for ldlm_interval */
-struct ldlm_interval *ldlm_interval_detach(struct ldlm_lock *l);
-struct ldlm_interval *ldlm_interval_alloc(struct ldlm_lock *lock);
-void ldlm_interval_free(struct ldlm_interval *node);
-/* this function must be called with res lock held */
-static inline struct ldlm_extent *
-ldlm_interval_extent(struct ldlm_interval *node)
-{
- struct ldlm_lock *lock;
-
- LASSERT(!list_empty(&node->li_group));
-
- lock = list_entry(node->li_group.next, struct ldlm_lock, l_sl_policy);
- return &lock->l_policy_data.l_extent;
-}
-
int ldlm_init(void);
void ldlm_exit(void);

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
index a644d133063b..13b1b5fdada9 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
@@ -185,7 +185,6 @@ void ldlm_lock_put(struct ldlm_lock *lock)

kfree(lock->l_lvb_data);

- ldlm_interval_free(ldlm_interval_detach(lock));
lu_ref_fini(&lock->l_reference);
OBD_FREE_RCU(lock, sizeof(*lock), &lock->l_handle);
}
@@ -1138,17 +1137,10 @@ static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data)

static enum interval_iter itree_overlap_cb(struct interval_node *in, void *args)
{
- struct ldlm_interval *node = to_ldlm_interval(in);
struct lock_match_data *data = args;
- struct ldlm_lock *lock;
- int rc;
+ struct ldlm_lock *lock = container_of(in, struct ldlm_lock, l_tree_node);

- list_for_each_entry(lock, &node->li_group, l_sl_policy) {
- rc = lock_matches(lock, data);
- if (rc == INTERVAL_ITER_STOP)
- return INTERVAL_ITER_STOP;
- }
- return INTERVAL_ITER_CONT;
+ return lock_matches(lock, data);
}

/**
@@ -1564,15 +1556,6 @@ struct ldlm_lock *ldlm_lock_create(struct ldlm_namespace *ns,
lock->l_glimpse_ast = cbs->lcs_glimpse;
}

- lock->l_tree_node = NULL;
- /* if this is the extent lock, allocate the interval tree node */
- if (type == LDLM_EXTENT) {
- if (!ldlm_interval_alloc(lock)) {
- rc = -ENOMEM;
- goto out;
- }
- }
-
if (lvb_len) {
lock->l_lvb_len = lvb_len;
lock->l_lvb_data = kzalloc(lvb_len, GFP_NOFS);
@@ -1625,10 +1608,6 @@ enum ldlm_error ldlm_lock_enqueue(struct ldlm_namespace *ns,

ldlm_resource_unlink_lock(lock);

- /* Cannot happen unless on the server */
- if (res->lr_type == LDLM_EXTENT && !lock->l_tree_node)
- LBUG();
-
/* Some flags from the enqueue want to make it into the AST, via the
* lock's l_flags.
*/
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
index 5963e90d0938..f410ef6c02ef 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
@@ -1134,14 +1134,6 @@ int ldlm_init(void)
return -ENOMEM;
}

- ldlm_interval_slab = kmem_cache_create("interval_node",
- sizeof(struct ldlm_interval),
- 0, SLAB_HWCACHE_ALIGN, NULL);
- if (!ldlm_interval_slab) {
- kmem_cache_destroy(ldlm_resource_slab);
- kmem_cache_destroy(ldlm_lock_slab);
- return -ENOMEM;
- }
#if LUSTRE_TRACKS_LOCK_EXP_REFS
class_export_dump_hook = ldlm_dump_export_locks;
#endif
@@ -1159,5 +1151,4 @@ void ldlm_exit(void)
*/
synchronize_rcu();
kmem_cache_destroy(ldlm_lock_slab);
- kmem_cache_destroy(ldlm_interval_slab);
}
diff --git a/drivers/staging/lustre/lustre/llite/range_lock.c b/drivers/staging/lustre/lustre/llite/range_lock.c
index 008a8874118d..eaa23f4c414e 100644
--- a/drivers/staging/lustre/lustre/llite/range_lock.c
+++ b/drivers/staging/lustre/lustre/llite/range_lock.c
@@ -74,19 +74,12 @@ int range_lock_init(struct range_lock *lock, __u64 start, __u64 end)
if (rc)
return rc;

- INIT_LIST_HEAD(&lock->rl_next_lock);
lock->rl_task = NULL;
- lock->rl_lock_count = 0;
lock->rl_blocking_ranges = 0;
lock->rl_sequence = 0;
return rc;
}

-static inline struct range_lock *next_lock(struct range_lock *lock)
-{
- return list_entry(lock->rl_next_lock.next, typeof(*lock), rl_next_lock);
-}
-
/**
* Helper function of range_unlock()
*
@@ -102,14 +95,7 @@ static enum interval_iter range_unlock_cb(struct interval_node *node, void *arg)
{
struct range_lock *lock = arg;
struct range_lock *overlap = node2rangelock(node);
- struct range_lock *iter;

- list_for_each_entry(iter, &overlap->rl_next_lock, rl_next_lock) {
- if (iter->rl_sequence > lock->rl_sequence) {
- --iter->rl_blocking_ranges;
- LASSERT(iter->rl_blocking_ranges > 0);
- }
- }
if (overlap->rl_sequence > lock->rl_sequence) {
--overlap->rl_blocking_ranges;
if (overlap->rl_blocking_ranges == 0)
@@ -131,32 +117,8 @@ static enum interval_iter range_unlock_cb(struct interval_node *node, void *arg)
void range_unlock(struct range_lock_tree *tree, struct range_lock *lock)
{
spin_lock(&tree->rlt_lock);
- if (!list_empty(&lock->rl_next_lock)) {
- struct range_lock *next;
-
- if (interval_is_intree(&lock->rl_node)) { /* first lock */
- /* Insert the next same range lock into the tree */
- next = next_lock(lock);
- next->rl_lock_count = lock->rl_lock_count - 1;
- interval_erase(&lock->rl_node, &tree->rlt_root);
- interval_insert(&next->rl_node, &tree->rlt_root);
- } else {
- /* find the first lock in tree */
- list_for_each_entry(next, &lock->rl_next_lock,
- rl_next_lock) {
- if (!interval_is_intree(&next->rl_node))
- continue;
-
- LASSERT(next->rl_lock_count > 0);
- next->rl_lock_count--;
- break;
- }
- }
- list_del_init(&lock->rl_next_lock);
- } else {
- LASSERT(interval_is_intree(&lock->rl_node));
- interval_erase(&lock->rl_node, &tree->rlt_root);
- }
+ LASSERT(interval_is_intree(&lock->rl_node));
+ interval_erase(&lock->rl_node, &tree->rlt_root);

interval_search(tree->rlt_root, &lock->rl_node.in_extent,
range_unlock_cb, lock);
@@ -177,9 +139,8 @@ void range_unlock(struct range_lock_tree *tree, struct range_lock *lock)
static enum interval_iter range_lock_cb(struct interval_node *node, void *arg)
{
struct range_lock *lock = arg;
- struct range_lock *overlap = node2rangelock(node);

- lock->rl_blocking_ranges += overlap->rl_lock_count + 1;
+ lock->rl_blocking_ranges++;
return INTERVAL_ITER_CONT;
}

@@ -198,7 +159,6 @@ static enum interval_iter range_lock_cb(struct interval_node *node, void *arg)
*/
int range_lock(struct range_lock_tree *tree, struct range_lock *lock)
{
- struct interval_node *node;
int rc = 0;

spin_lock(&tree->rlt_lock);
@@ -208,18 +168,7 @@ int range_lock(struct range_lock_tree *tree, struct range_lock *lock)
*/
interval_search(tree->rlt_root, &lock->rl_node.in_extent,
range_lock_cb, lock);
- /*
- * Insert to the tree if I am unique, otherwise I've been linked to
- * the rl_next_lock of another lock which has the same range as mine
- * in range_lock_cb().
- */
- node = interval_insert(&lock->rl_node, &tree->rlt_root);
- if (node) {
- struct range_lock *tmp = node2rangelock(node);
-
- list_add_tail(&lock->rl_next_lock, &tmp->rl_next_lock);
- tmp->rl_lock_count++;
- }
+ interval_insert(&lock->rl_node, &tree->rlt_root);
lock->rl_sequence = ++tree->rlt_sequence;

while (lock->rl_blocking_ranges > 0) {
diff --git a/drivers/staging/lustre/lustre/llite/range_lock.h b/drivers/staging/lustre/lustre/llite/range_lock.h
index 9ebac09160f2..10ef1a995d26 100644
--- a/drivers/staging/lustre/lustre/llite/range_lock.h
+++ b/drivers/staging/lustre/lustre/llite/range_lock.h
@@ -46,14 +46,6 @@ struct range_lock {
* Process to enqueue this lock.
*/
struct task_struct *rl_task;
- /**
- * List of locks with the same range.
- */
- struct list_head rl_next_lock;
- /**
- * Number of locks in the list rl_next_lock
- */
- unsigned int rl_lock_count;
/**
* Number of ranges which are blocking acquisition of the lock
*/



2018-06-06 06:13:12

by NeilBrown

[permalink] [raw]
Subject: [PATCH 03/11] staging: lustre: move interval_insert call from ldlm_lock to ldlm_extent

Moving this call results in all interval-tree handling code
being in the one file. This will simplify conversion to
use Linux interval trees.

The addition of 'struct cb' is a little ugly, but will be gone
is a subsequent patch.

Signed-off-by: NeilBrown <[email protected]>
---
drivers/staging/lustre/lustre/ldlm/ldlm_extent.c | 27 ++++++++++++++++++++
drivers/staging/lustre/lustre/ldlm/ldlm_internal.h | 4 +++
drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 17 +++----------
3 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
index 2f4c305bb340..eb1a9077a514 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
@@ -192,3 +192,30 @@ void ldlm_extent_policy_local_to_wire(const union ldlm_policy_data *lpolicy,
wpolicy->l_extent.end = lpolicy->l_extent.end;
wpolicy->l_extent.gid = lpolicy->l_extent.gid;
}
+
+struct cb {
+ void *arg;
+ bool (*found)(struct ldlm_lock *lock, void *arg);
+};
+
+static enum interval_iter itree_overlap_cb(struct interval_node *in, void *arg)
+{
+ struct cb *cb = arg;
+ struct ldlm_lock *lock = container_of(in, struct ldlm_lock,
+ l_tree_node);
+
+ return cb->found(lock, cb->arg) ?
+ INTERVAL_ITER_STOP : INTERVAL_ITER_CONT;
+}
+
+void ldlm_extent_search(struct interval_node *root,
+ struct interval_node_extent *ext,
+ bool (*matches)(struct ldlm_lock *lock, void *data),
+ void *data)
+{
+ struct cb cb = {
+ .arg = data,
+ .found = matches,
+ };
+ interval_search(root, ext, itree_overlap_cb, &cb);
+}
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h b/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
index 159de8a59cbb..756fa3d9db3c 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
@@ -169,6 +169,10 @@ extern struct kmem_cache *ldlm_lock_slab;
/* ldlm_extent.c */
void ldlm_extent_add_lock(struct ldlm_resource *res, struct ldlm_lock *lock);
void ldlm_extent_unlink_lock(struct ldlm_lock *lock);
+void ldlm_extent_search(struct interval_node *root,
+ struct interval_node_extent *ext,
+ bool (*matches)(struct ldlm_lock *lock, void *data),
+ void *data);

/* l_lock.c */
void l_check_ns_lock(struct ldlm_namespace *ns);
diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
index 034935e06393..4213fe047073 100644
--- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
@@ -1053,8 +1053,9 @@ struct lock_match_data {
* \param lock test-against this lock
* \param data parameters
*/
-static bool lock_matches(struct ldlm_lock *lock, struct lock_match_data *data)
+static bool lock_matches(struct ldlm_lock *lock, void *vdata)
{
+ struct lock_match_data *data = vdata;
union ldlm_policy_data *lpol = &lock->l_policy_data;
enum ldlm_mode match;

@@ -1135,16 +1136,6 @@ static bool lock_matches(struct ldlm_lock *lock, struct lock_match_data *data)
return true;
}

-static enum interval_iter itree_overlap_cb(struct interval_node *in, void *args)
-{
- struct lock_match_data *data = args;
- struct ldlm_lock *lock = container_of(in, struct ldlm_lock,
- l_tree_node);
-
- return lock_matches(lock, data) ?
- INTERVAL_ITER_STOP : INTERVAL_ITER_CONT;
-}
-
/**
* Search for a lock with given parameters in interval trees.
*
@@ -1171,8 +1162,8 @@ static struct ldlm_lock *search_itree(struct ldlm_resource *res,
if (!(tree->lit_mode & *data->lmd_mode))
continue;

- interval_search(tree->lit_root, &ext,
- itree_overlap_cb, data);
+ ldlm_extent_search(tree->lit_root, &ext,
+ lock_matches, data);
}
return data->lmd_lock;
}



2018-06-06 06:13:42

by NeilBrown

[permalink] [raw]
Subject: [PATCH 07/11] staging: lustre: fold lprocfs_call_handler functionality into lnet_debugfs_*

The calling convention for ->proc_handler is rather clumsy,
as a comment in fs/procfs/proc_sysctl.c confirms.
lustre has copied this convention to lnet_debugfs_{read,write},
and then provided a wrapper for handlers - lprocfs_call_handler -
to work around the clumsiness.

It is cleaner to just fold the functionality of lprocfs_call_handler()
into lnet_debugfs_* and let them call the final handler directly.

If these files were ever moved to /proc/sys (which seems unlikely) the
handling in fs/procfs/proc_sysctl.c would need to be fixed to, but
that would not be a bad thing.

So modify all the functions that did use the wrapper to not need it
now that a more sane calling convention is available.

Signed-off-by: NeilBrown <[email protected]>
---
.../staging/lustre/include/linux/libcfs/libcfs.h | 4 -
drivers/staging/lustre/lnet/libcfs/module.c | 84 +++++++-------------
drivers/staging/lustre/lnet/lnet/router_proc.c | 41 +++-------
3 files changed, 41 insertions(+), 88 deletions(-)

diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs.h b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
index edc7ed0dcb94..7ac609328256 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
@@ -57,10 +57,6 @@ int libcfs_setup(void);
extern struct workqueue_struct *cfs_rehash_wq;

void lustre_insert_debugfs(struct ctl_table *table);
-int lprocfs_call_handler(void *data, int write, loff_t *ppos,
- void __user *buffer, size_t *lenp,
- int (*handler)(void *data, int write, loff_t pos,
- void __user *buffer, int len));

/*
* Memory
diff --git a/drivers/staging/lustre/lnet/libcfs/module.c b/drivers/staging/lustre/lnet/libcfs/module.c
index 5dc7de9e6478..02c404c6738e 100644
--- a/drivers/staging/lustre/lnet/libcfs/module.c
+++ b/drivers/staging/lustre/lnet/libcfs/module.c
@@ -290,33 +290,15 @@ static struct miscdevice libcfs_dev = {

static int libcfs_dev_registered;

-int lprocfs_call_handler(void *data, int write, loff_t *ppos,
- void __user *buffer, size_t *lenp,
- int (*handler)(void *data, int write, loff_t pos,
- void __user *buffer, int len))
-{
- int rc = handler(data, write, *ppos, buffer, *lenp);
-
- if (rc < 0)
- return rc;
-
- if (write) {
- *ppos += *lenp;
- } else {
- *lenp = rc;
- *ppos += rc;
- }
- return 0;
-}
-EXPORT_SYMBOL(lprocfs_call_handler);
-
-static int __proc_dobitmasks(void *data, int write,
- loff_t pos, void __user *buffer, int nob)
+static int proc_dobitmasks(struct ctl_table *table, int write,
+ void __user *buffer, size_t *lenp, loff_t *ppos)
{
const int tmpstrlen = 512;
char *tmpstr;
int rc;
- unsigned int *mask = data;
+ size_t nob = *lenp;
+ loff_t pos = *ppos;
+ unsigned int *mask = table->data;
int is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0;
int is_printk = (mask == &libcfs_printk) ? 1 : 0;

@@ -351,32 +333,23 @@ static int __proc_dobitmasks(void *data, int write,
return rc;
}

-static int proc_dobitmasks(struct ctl_table *table, int write,
- void __user *buffer, size_t *lenp, loff_t *ppos)
+static int proc_dump_kernel(struct ctl_table *table, int write,
+ void __user *buffer, size_t *lenp, loff_t *ppos)
{
- return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
- __proc_dobitmasks);
-}
+ size_t nob = *lenp;

-static int __proc_dump_kernel(void *data, int write,
- loff_t pos, void __user *buffer, int nob)
-{
if (!write)
return 0;

return cfs_trace_dump_debug_buffer_usrstr(buffer, nob);
}

-static int proc_dump_kernel(struct ctl_table *table, int write,
+static int proc_daemon_file(struct ctl_table *table, int write,
void __user *buffer, size_t *lenp, loff_t *ppos)
{
- return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
- __proc_dump_kernel);
-}
+ size_t nob = *lenp;
+ loff_t pos = *ppos;

-static int __proc_daemon_file(void *data, int write,
- loff_t pos, void __user *buffer, int nob)
-{
if (!write) {
int len = strlen(cfs_tracefile);

@@ -390,13 +363,6 @@ static int __proc_daemon_file(void *data, int write,
return cfs_trace_daemon_command_usrstr(buffer, nob);
}

-static int proc_daemon_file(struct ctl_table *table, int write,
- void __user *buffer, size_t *lenp, loff_t *ppos)
-{
- return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
- __proc_daemon_file);
-}
-
static int libcfs_force_lbug(struct ctl_table *table, int write,
void __user *buffer,
size_t *lenp, loff_t *ppos)
@@ -419,9 +385,11 @@ static int proc_fail_loc(struct ctl_table *table, int write,
return rc;
}

-static int __proc_cpt_table(void *data, int write,
- loff_t pos, void __user *buffer, int nob)
+static int proc_cpt_table(struct ctl_table *table, int write,
+ void __user *buffer, size_t *lenp, loff_t *ppos)
{
+ size_t nob = *lenp;
+ loff_t pos = *ppos;
char *buf = NULL;
int len = 4096;
int rc = 0;
@@ -457,13 +425,6 @@ static int __proc_cpt_table(void *data, int write,
return rc;
}

-static int proc_cpt_table(struct ctl_table *table, int write,
- void __user *buffer, size_t *lenp, loff_t *ppos)
-{
- return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
- __proc_cpt_table);
-}
-
static struct ctl_table lnet_table[] = {
{
.procname = "debug",
@@ -573,10 +534,17 @@ static ssize_t lnet_debugfs_read(struct file *filp, char __user *buf,
{
struct ctl_table *table = filp->private_data;
int error;
+ loff_t old_pos = *ppos;

error = table->proc_handler(table, 0, (void __user *)buf, &count, ppos);
- if (!error)
+ /*
+ * On success, the length read is either in error or in count.
+ * If ppos changed, then use count, else use error
+ */
+ if (!error && *ppos != old_pos)
error = count;
+ else if (error > 0)
+ *ppos += error;

return error;
}
@@ -586,10 +554,14 @@ static ssize_t lnet_debugfs_write(struct file *filp, const char __user *buf,
{
struct ctl_table *table = filp->private_data;
int error;
+ loff_t old_pos = *ppos;

error = table->proc_handler(table, 1, (void __user *)buf, &count, ppos);
- if (!error)
+ if (!error) {
error = count;
+ if (*ppos == old_pos)
+ *ppos += count;
+ }

return error;
}
diff --git a/drivers/staging/lustre/lnet/lnet/router_proc.c b/drivers/staging/lustre/lnet/lnet/router_proc.c
index ae4b7f5953a0..f135082fec5c 100644
--- a/drivers/staging/lustre/lnet/lnet/router_proc.c
+++ b/drivers/staging/lustre/lnet/lnet/router_proc.c
@@ -74,11 +74,13 @@

#define LNET_PROC_VERSION(v) ((unsigned int)((v) & LNET_PROC_VER_MASK))

-static int __proc_lnet_stats(void *data, int write,
- loff_t pos, void __user *buffer, int nob)
+static int proc_lnet_stats(struct ctl_table *table, int write,
+ void __user *buffer, size_t *lenp, loff_t *ppos)
{
int rc;
struct lnet_counters *ctrs;
+ size_t nob = *lenp;
+ loff_t pos = *ppos;
int len;
char *tmpstr;
const int tmpsiz = 256; /* 7 %u and 4 %llu */
@@ -122,13 +124,6 @@ static int __proc_lnet_stats(void *data, int write,
return rc;
}

-static int proc_lnet_stats(struct ctl_table *table, int write,
- void __user *buffer, size_t *lenp, loff_t *ppos)
-{
- return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
- __proc_lnet_stats);
-}
-
static int proc_lnet_routes(struct ctl_table *table, int write,
void __user *buffer, size_t *lenp, loff_t *ppos)
{
@@ -562,9 +557,11 @@ static int proc_lnet_peers(struct ctl_table *table, int write,
return rc;
}

-static int __proc_lnet_buffers(void *data, int write,
- loff_t pos, void __user *buffer, int nob)
+static int proc_lnet_buffers(struct ctl_table *table, int write,
+ void __user *buffer, size_t *lenp, loff_t *ppos)
{
+ size_t nob = *lenp;
+ loff_t pos = *ppos;
char *s;
char *tmpstr;
int tmpsiz;
@@ -620,13 +617,6 @@ static int __proc_lnet_buffers(void *data, int write,
return rc;
}

-static int proc_lnet_buffers(struct ctl_table *table, int write,
- void __user *buffer, size_t *lenp, loff_t *ppos)
-{
- return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
- __proc_lnet_buffers);
-}
-
static int proc_lnet_nis(struct ctl_table *table, int write,
void __user *buffer, size_t *lenp, loff_t *ppos)
{
@@ -784,10 +774,13 @@ static struct lnet_portal_rotors portal_rotors[] = {
},
};

-static int __proc_lnet_portal_rotor(void *data, int write,
- loff_t pos, void __user *buffer, int nob)
+static int proc_lnet_portal_rotor(struct ctl_table *table, int write,
+ void __user *buffer, size_t *lenp,
+ loff_t *ppos)
{
const int buf_len = 128;
+ size_t nob = *lenp;
+ loff_t pos = *ppos;
char *buf;
char *tmp;
int rc;
@@ -845,14 +838,6 @@ static int __proc_lnet_portal_rotor(void *data, int write,
return rc;
}

-static int proc_lnet_portal_rotor(struct ctl_table *table, int write,
- void __user *buffer, size_t *lenp,
- loff_t *ppos)
-{
- return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
- __proc_lnet_portal_rotor);
-}
-
static struct ctl_table lnet_table[] = {
/*
* NB No .strategy entries have been provided since sysctl(8) prefers



2018-06-06 06:13:57

by NeilBrown

[permalink] [raw]
Subject: [PATCH 08/11] staging: lustre: obdclass: move linux/linux-foo.c to foo.c

As lustre is now linux-only, having this linux sub-directory
with files named "linux-something" is just noise. Move them
to a more friendly name.

Signed-off-by: NeilBrown <[email protected]>
---
drivers/staging/lustre/lustre/obdclass/Makefile | 2
.../lustre/lustre/obdclass/linux/linux-module.c | 514 --------------------
.../lustre/lustre/obdclass/linux/linux-sysctl.c | 162 ------
drivers/staging/lustre/lustre/obdclass/module.c | 514 ++++++++++++++++++++
drivers/staging/lustre/lustre/obdclass/sysctl.c | 162 ++++++
5 files changed, 677 insertions(+), 677 deletions(-)
delete mode 100644 drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
delete mode 100644 drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
create mode 100644 drivers/staging/lustre/lustre/obdclass/module.c
create mode 100644 drivers/staging/lustre/lustre/obdclass/sysctl.c

diff --git a/drivers/staging/lustre/lustre/obdclass/Makefile b/drivers/staging/lustre/lustre/obdclass/Makefile
index e3fa9acff4c4..e36ba2167d10 100644
--- a/drivers/staging/lustre/lustre/obdclass/Makefile
+++ b/drivers/staging/lustre/lustre/obdclass/Makefile
@@ -4,7 +4,7 @@ subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include

obj-$(CONFIG_LUSTRE_FS) += obdclass.o

-obdclass-y := linux/linux-module.o linux/linux-sysctl.o \
+obdclass-y := module.o sysctl.o \
llog.o llog_cat.o llog_obd.o llog_swab.o class_obd.o debug.o \
genops.o uuid.o lprocfs_status.o lprocfs_counters.o \
lustre_handles.o lustre_peer.o statfs_pack.o linkea.o \
diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
deleted file mode 100644
index 9c800580053b..000000000000
--- a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
+++ /dev/null
@@ -1,514 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.gnu.org/licenses/gpl-2.0.html
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2011, 2012, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * lustre/obdclass/linux/linux-module.c
- *
- * Object Devices Class Driver
- * These are the only exported functions, they provide some generic
- * infrastructure for managing object devices
- */
-
-#define DEBUG_SUBSYSTEM S_CLASS
-
-#include <linux/module.h>
-#include <linux/errno.h>
-#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/lp.h>
-#include <linux/slab.h>
-#include <linux/ioport.h>
-#include <linux/fcntl.h>
-#include <linux/delay.h>
-#include <linux/skbuff.h>
-#include <linux/fs.h>
-#include <linux/poll.h>
-#include <linux/list.h>
-#include <linux/highmem.h>
-#include <linux/io.h>
-#include <asm/ioctls.h>
-#include <linux/uaccess.h>
-#include <linux/miscdevice.h>
-#include <linux/seq_file.h>
-#include <linux/kobject.h>
-
-#include <uapi/linux/lnet/lnetctl.h>
-#include <obd_support.h>
-#include <obd_class.h>
-#include <lprocfs_status.h>
-#include <uapi/linux/lustre/lustre_ioctl.h>
-#include <uapi/linux/lustre/lustre_ver.h>
-
-#define OBD_MAX_IOCTL_BUFFER 8192
-
-static int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
-{
- if (data->ioc_len > BIT(30)) {
- CERROR("OBD ioctl: ioc_len larger than 1<<30\n");
- return 1;
- }
-
- if (data->ioc_inllen1 > BIT(30)) {
- CERROR("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
- return 1;
- }
-
- if (data->ioc_inllen2 > BIT(30)) {
- CERROR("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
- return 1;
- }
-
- if (data->ioc_inllen3 > BIT(30)) {
- CERROR("OBD ioctl: ioc_inllen3 larger than 1<<30\n");
- return 1;
- }
-
- if (data->ioc_inllen4 > BIT(30)) {
- CERROR("OBD ioctl: ioc_inllen4 larger than 1<<30\n");
- return 1;
- }
-
- if (data->ioc_inlbuf1 && data->ioc_inllen1 == 0) {
- CERROR("OBD ioctl: inlbuf1 pointer but 0 length\n");
- return 1;
- }
-
- if (data->ioc_inlbuf2 && data->ioc_inllen2 == 0) {
- CERROR("OBD ioctl: inlbuf2 pointer but 0 length\n");
- return 1;
- }
-
- if (data->ioc_inlbuf3 && data->ioc_inllen3 == 0) {
- CERROR("OBD ioctl: inlbuf3 pointer but 0 length\n");
- return 1;
- }
-
- if (data->ioc_inlbuf4 && data->ioc_inllen4 == 0) {
- CERROR("OBD ioctl: inlbuf4 pointer but 0 length\n");
- return 1;
- }
-
- if (data->ioc_pbuf1 && data->ioc_plen1 == 0) {
- CERROR("OBD ioctl: pbuf1 pointer but 0 length\n");
- return 1;
- }
-
- if (data->ioc_pbuf2 && data->ioc_plen2 == 0) {
- CERROR("OBD ioctl: pbuf2 pointer but 0 length\n");
- return 1;
- }
-
- if (!data->ioc_pbuf1 && data->ioc_plen1 != 0) {
- CERROR("OBD ioctl: plen1 set but NULL pointer\n");
- return 1;
- }
-
- if (!data->ioc_pbuf2 && data->ioc_plen2 != 0) {
- CERROR("OBD ioctl: plen2 set but NULL pointer\n");
- return 1;
- }
-
- if (obd_ioctl_packlen(data) > data->ioc_len) {
- CERROR("OBD ioctl: packlen exceeds ioc_len (%d > %d)\n",
- obd_ioctl_packlen(data), data->ioc_len);
- return 1;
- }
-
- return 0;
-}
-
-/* buffer MUST be at least the size of obd_ioctl_hdr */
-int obd_ioctl_getdata(char **buf, int *len, void __user *arg)
-{
- struct obd_ioctl_hdr hdr;
- struct obd_ioctl_data *data;
- int err;
- int offset = 0;
-
- if (copy_from_user(&hdr, arg, sizeof(hdr)))
- return -EFAULT;
-
- if (hdr.ioc_version != OBD_IOCTL_VERSION) {
- CERROR("Version mismatch kernel (%x) vs application (%x)\n",
- OBD_IOCTL_VERSION, hdr.ioc_version);
- return -EINVAL;
- }
-
- if (hdr.ioc_len > OBD_MAX_IOCTL_BUFFER) {
- CERROR("User buffer len %d exceeds %d max buffer\n",
- hdr.ioc_len, OBD_MAX_IOCTL_BUFFER);
- return -EINVAL;
- }
-
- if (hdr.ioc_len < sizeof(struct obd_ioctl_data)) {
- CERROR("User buffer too small for ioctl (%d)\n", hdr.ioc_len);
- return -EINVAL;
- }
-
- /* When there are lots of processes calling vmalloc on multi-core
- * system, the high lock contention will hurt performance badly,
- * obdfilter-survey is an example, which relies on ioctl. So we'd
- * better avoid vmalloc on ioctl path. LU-66
- */
- *buf = kvzalloc(hdr.ioc_len, GFP_KERNEL);
- if (!*buf) {
- CERROR("Cannot allocate control buffer of len %d\n",
- hdr.ioc_len);
- return -EINVAL;
- }
- *len = hdr.ioc_len;
- data = (struct obd_ioctl_data *)*buf;
-
- if (copy_from_user(*buf, arg, hdr.ioc_len)) {
- err = -EFAULT;
- goto free_buf;
- }
- if (hdr.ioc_len != data->ioc_len) {
- err = -EINVAL;
- goto free_buf;
- }
-
- if (obd_ioctl_is_invalid(data)) {
- CERROR("ioctl not correctly formatted\n");
- err = -EINVAL;
- goto free_buf;
- }
-
- if (data->ioc_inllen1) {
- data->ioc_inlbuf1 = &data->ioc_bulk[0];
- offset += cfs_size_round(data->ioc_inllen1);
- }
-
- if (data->ioc_inllen2) {
- data->ioc_inlbuf2 = &data->ioc_bulk[0] + offset;
- offset += cfs_size_round(data->ioc_inllen2);
- }
-
- if (data->ioc_inllen3) {
- data->ioc_inlbuf3 = &data->ioc_bulk[0] + offset;
- offset += cfs_size_round(data->ioc_inllen3);
- }
-
- if (data->ioc_inllen4)
- data->ioc_inlbuf4 = &data->ioc_bulk[0] + offset;
-
- return 0;
-
-free_buf:
- kvfree(*buf);
- return err;
-}
-EXPORT_SYMBOL(obd_ioctl_getdata);
-
-/* opening /dev/obd */
-static int obd_class_open(struct inode *inode, struct file *file)
-{
- try_module_get(THIS_MODULE);
- return 0;
-}
-
-/* closing /dev/obd */
-static int obd_class_release(struct inode *inode, struct file *file)
-{
- module_put(THIS_MODULE);
- return 0;
-}
-
-/* to control /dev/obd */
-static long obd_class_ioctl(struct file *filp, unsigned int cmd,
- unsigned long arg)
-{
- int err = 0;
-
- /* Allow non-root access for OBD_IOC_PING_TARGET - used by lfs check */
- if (!capable(CAP_SYS_ADMIN) && (cmd != OBD_IOC_PING_TARGET))
- return err = -EACCES;
- if ((cmd & 0xffffff00) == ((int)'T') << 8) /* ignore all tty ioctls */
- return err = -ENOTTY;
-
- err = class_handle_ioctl(cmd, (unsigned long)arg);
-
- return err;
-}
-
-/* declare character device */
-static const struct file_operations obd_psdev_fops = {
- .owner = THIS_MODULE,
- .unlocked_ioctl = obd_class_ioctl, /* unlocked_ioctl */
- .open = obd_class_open, /* open */
- .release = obd_class_release, /* release */
-};
-
-/* modules setup */
-struct miscdevice obd_psdev = {
- .minor = MISC_DYNAMIC_MINOR,
- .name = OBD_DEV_NAME,
- .fops = &obd_psdev_fops,
-};
-
-static ssize_t version_show(struct kobject *kobj, struct attribute *attr,
- char *buf)
-{
- return sprintf(buf, "%s\n", LUSTRE_VERSION_STRING);
-}
-
-static ssize_t pinger_show(struct kobject *kobj, struct attribute *attr,
- char *buf)
-{
- return sprintf(buf, "%s\n", "on");
-}
-
-static ssize_t
-health_check_show(struct kobject *kobj, struct attribute *attr, char *buf)
-{
- bool healthy = true;
- int i;
- size_t len = 0;
-
- if (libcfs_catastrophe)
- return sprintf(buf, "LBUG\n");
-
- read_lock(&obd_dev_lock);
- for (i = 0; i < class_devno_max(); i++) {
- struct obd_device *obd;
-
- obd = class_num2obd(i);
- if (!obd || !obd->obd_attached || !obd->obd_set_up)
- continue;
-
- LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
- if (obd->obd_stopping)
- continue;
-
- class_incref(obd, __func__, current);
- read_unlock(&obd_dev_lock);
-
- if (obd_health_check(NULL, obd))
- healthy = false;
- class_decref(obd, __func__, current);
- read_lock(&obd_dev_lock);
- }
- read_unlock(&obd_dev_lock);
-
- if (healthy)
- len = sprintf(buf, "healthy\n");
- else
- len = sprintf(buf, "NOT HEALTHY\n");
-
- return len;
-}
-
-static ssize_t jobid_var_show(struct kobject *kobj, struct attribute *attr,
- char *buf)
-{
- return snprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_var);
-}
-
-static ssize_t jobid_var_store(struct kobject *kobj, struct attribute *attr,
- const char *buffer,
- size_t count)
-{
- if (!count || count > JOBSTATS_JOBID_VAR_MAX_LEN)
- return -EINVAL;
-
- memset(obd_jobid_var, 0, JOBSTATS_JOBID_VAR_MAX_LEN + 1);
-
- memcpy(obd_jobid_var, buffer, count);
-
- /* Trim the trailing '\n' if any */
- if (obd_jobid_var[count - 1] == '\n')
- obd_jobid_var[count - 1] = 0;
-
- return count;
-}
-
-static ssize_t jobid_name_show(struct kobject *kobj, struct attribute *attr,
- char *buf)
-{
- return snprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_node);
-}
-
-static ssize_t jobid_name_store(struct kobject *kobj, struct attribute *attr,
- const char *buffer,
- size_t count)
-{
- if (!count || count > LUSTRE_JOBID_SIZE)
- return -EINVAL;
-
- memcpy(obd_jobid_node, buffer, count);
-
- obd_jobid_node[count] = 0;
-
- /* Trim the trailing '\n' if any */
- if (obd_jobid_node[count - 1] == '\n')
- obd_jobid_node[count - 1] = 0;
-
- return count;
-}
-
-/* Root for /sys/kernel/debug/lustre */
-struct dentry *debugfs_lustre_root;
-EXPORT_SYMBOL_GPL(debugfs_lustre_root);
-
-LUSTRE_RO_ATTR(version);
-LUSTRE_RO_ATTR(pinger);
-LUSTRE_RO_ATTR(health_check);
-LUSTRE_RW_ATTR(jobid_var);
-LUSTRE_RW_ATTR(jobid_name);
-
-static struct attribute *lustre_attrs[] = {
- &lustre_attr_version.attr,
- &lustre_attr_pinger.attr,
- &lustre_attr_health_check.attr,
- &lustre_attr_jobid_name.attr,
- &lustre_attr_jobid_var.attr,
- NULL,
-};
-
-static void *obd_device_list_seq_start(struct seq_file *p, loff_t *pos)
-{
- if (*pos >= class_devno_max())
- return NULL;
-
- return pos;
-}
-
-static void obd_device_list_seq_stop(struct seq_file *p, void *v)
-{
-}
-
-static void *obd_device_list_seq_next(struct seq_file *p, void *v, loff_t *pos)
-{
- ++*pos;
- if (*pos >= class_devno_max())
- return NULL;
-
- return pos;
-}
-
-static int obd_device_list_seq_show(struct seq_file *p, void *v)
-{
- loff_t index = *(loff_t *)v;
- struct obd_device *obd = class_num2obd((int)index);
- char *status;
-
- if (!obd)
- return 0;
-
- LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
- if (obd->obd_stopping)
- status = "ST";
- else if (obd->obd_inactive)
- status = "IN";
- else if (obd->obd_set_up)
- status = "UP";
- else if (obd->obd_attached)
- status = "AT";
- else
- status = "--";
-
- seq_printf(p, "%3d %s %s %s %s %d\n",
- (int)index, status, obd->obd_type->typ_name,
- obd->obd_name, obd->obd_uuid.uuid,
- atomic_read(&obd->obd_refcount));
- return 0;
-}
-
-static const struct seq_operations obd_device_list_sops = {
- .start = obd_device_list_seq_start,
- .stop = obd_device_list_seq_stop,
- .next = obd_device_list_seq_next,
- .show = obd_device_list_seq_show,
-};
-
-static int obd_device_list_open(struct inode *inode, struct file *file)
-{
- struct seq_file *seq;
- int rc = seq_open(file, &obd_device_list_sops);
-
- if (rc)
- return rc;
-
- seq = file->private_data;
- seq->private = inode->i_private;
-
- return 0;
-}
-
-static const struct file_operations obd_device_list_fops = {
- .owner = THIS_MODULE,
- .open = obd_device_list_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = seq_release,
-};
-
-struct kobject *lustre_kobj;
-EXPORT_SYMBOL_GPL(lustre_kobj);
-
-static const struct attribute_group lustre_attr_group = {
- .attrs = lustre_attrs,
-};
-
-int class_procfs_init(void)
-{
- int rc = -ENOMEM;
-
- lustre_kobj = kobject_create_and_add("lustre", fs_kobj);
- if (!lustre_kobj)
- goto out;
-
- /* Create the files associated with this kobject */
- rc = sysfs_create_group(lustre_kobj, &lustre_attr_group);
- if (rc) {
- kobject_put(lustre_kobj);
- goto out;
- }
-
- debugfs_lustre_root = debugfs_create_dir("lustre", NULL);
-
- debugfs_create_file("devices", 0444, debugfs_lustre_root, NULL,
- &obd_device_list_fops);
-out:
- return rc;
-}
-
-int class_procfs_clean(void)
-{
- debugfs_remove_recursive(debugfs_lustre_root);
-
- debugfs_lustre_root = NULL;
-
- sysfs_remove_group(lustre_kobj, &lustre_attr_group);
- kobject_put(lustre_kobj);
-
- return 0;
-}
diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
deleted file mode 100644
index e5e8687784ee..000000000000
--- a/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
+++ /dev/null
@@ -1,162 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.gnu.org/licenses/gpl-2.0.html
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2011, 2015, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- */
-
-#include <linux/module.h>
-#include <linux/sysctl.h>
-#include <linux/sched.h>
-#include <linux/mm.h>
-#include <linux/slab.h>
-#include <linux/stat.h>
-#include <linux/ctype.h>
-#include <linux/bitops.h>
-#include <linux/uaccess.h>
-#include <linux/utsname.h>
-
-#define DEBUG_SUBSYSTEM S_CLASS
-
-#include <obd_support.h>
-#include <lprocfs_status.h>
-#include <obd_class.h>
-
-struct static_lustre_uintvalue_attr {
- struct {
- struct attribute attr;
- ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
- char *buf);
- ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
- const char *buf, size_t len);
- } u;
- int *value;
-};
-
-static ssize_t static_uintvalue_show(struct kobject *kobj,
- struct attribute *attr,
- char *buf)
-{
- struct static_lustre_uintvalue_attr *lattr = (void *)attr;
-
- return sprintf(buf, "%d\n", *lattr->value);
-}
-
-static ssize_t static_uintvalue_store(struct kobject *kobj,
- struct attribute *attr,
- const char *buffer, size_t count)
-{
- struct static_lustre_uintvalue_attr *lattr = (void *)attr;
- int rc;
- unsigned int val;
-
- rc = kstrtouint(buffer, 10, &val);
- if (rc)
- return rc;
-
- *lattr->value = val;
-
- return count;
-}
-
-#define LUSTRE_STATIC_UINT_ATTR(name, value) \
-static struct static_lustre_uintvalue_attr lustre_sattr_##name = \
- {__ATTR(name, 0644, \
- static_uintvalue_show, \
- static_uintvalue_store),\
- value }
-
-LUSTRE_STATIC_UINT_ATTR(timeout, &obd_timeout);
-
-static ssize_t max_dirty_mb_show(struct kobject *kobj, struct attribute *attr,
- char *buf)
-{
- return sprintf(buf, "%lu\n",
- obd_max_dirty_pages / (1 << (20 - PAGE_SHIFT)));
-}
-
-static ssize_t max_dirty_mb_store(struct kobject *kobj, struct attribute *attr,
- const char *buffer, size_t count)
-{
- int rc;
- unsigned long val;
-
- rc = kstrtoul(buffer, 10, &val);
- if (rc)
- return rc;
-
- val *= 1 << (20 - PAGE_SHIFT); /* convert to pages */
-
- if (val > ((totalram_pages / 10) * 9)) {
- /* Somebody wants to assign too much memory to dirty pages */
- return -EINVAL;
- }
-
- if (val < 4 << (20 - PAGE_SHIFT)) {
- /* Less than 4 Mb for dirty cache is also bad */
- return -EINVAL;
- }
-
- obd_max_dirty_pages = val;
-
- return count;
-}
-LUSTRE_RW_ATTR(max_dirty_mb);
-
-LUSTRE_STATIC_UINT_ATTR(debug_peer_on_timeout, &obd_debug_peer_on_timeout);
-LUSTRE_STATIC_UINT_ATTR(dump_on_timeout, &obd_dump_on_timeout);
-LUSTRE_STATIC_UINT_ATTR(dump_on_eviction, &obd_dump_on_eviction);
-LUSTRE_STATIC_UINT_ATTR(at_min, &at_min);
-LUSTRE_STATIC_UINT_ATTR(at_max, &at_max);
-LUSTRE_STATIC_UINT_ATTR(at_extra, &at_extra);
-LUSTRE_STATIC_UINT_ATTR(at_early_margin, &at_early_margin);
-LUSTRE_STATIC_UINT_ATTR(at_history, &at_history);
-
-static struct attribute *lustre_attrs[] = {
- &lustre_sattr_timeout.u.attr,
- &lustre_attr_max_dirty_mb.attr,
- &lustre_sattr_debug_peer_on_timeout.u.attr,
- &lustre_sattr_dump_on_timeout.u.attr,
- &lustre_sattr_dump_on_eviction.u.attr,
- &lustre_sattr_at_min.u.attr,
- &lustre_sattr_at_max.u.attr,
- &lustre_sattr_at_extra.u.attr,
- &lustre_sattr_at_early_margin.u.attr,
- &lustre_sattr_at_history.u.attr,
- NULL,
-};
-
-static const struct attribute_group lustre_attr_group = {
- .attrs = lustre_attrs,
-};
-
-int obd_sysctl_init(void)
-{
- return sysfs_create_group(lustre_kobj, &lustre_attr_group);
-}
diff --git a/drivers/staging/lustre/lustre/obdclass/module.c b/drivers/staging/lustre/lustre/obdclass/module.c
new file mode 100644
index 000000000000..9c800580053b
--- /dev/null
+++ b/drivers/staging/lustre/lustre/obdclass/module.c
@@ -0,0 +1,514 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2012, Intel Corporation.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lustre/obdclass/linux/linux-module.c
+ *
+ * Object Devices Class Driver
+ * These are the only exported functions, they provide some generic
+ * infrastructure for managing object devices
+ */
+
+#define DEBUG_SUBSYSTEM S_CLASS
+
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/lp.h>
+#include <linux/slab.h>
+#include <linux/ioport.h>
+#include <linux/fcntl.h>
+#include <linux/delay.h>
+#include <linux/skbuff.h>
+#include <linux/fs.h>
+#include <linux/poll.h>
+#include <linux/list.h>
+#include <linux/highmem.h>
+#include <linux/io.h>
+#include <asm/ioctls.h>
+#include <linux/uaccess.h>
+#include <linux/miscdevice.h>
+#include <linux/seq_file.h>
+#include <linux/kobject.h>
+
+#include <uapi/linux/lnet/lnetctl.h>
+#include <obd_support.h>
+#include <obd_class.h>
+#include <lprocfs_status.h>
+#include <uapi/linux/lustre/lustre_ioctl.h>
+#include <uapi/linux/lustre/lustre_ver.h>
+
+#define OBD_MAX_IOCTL_BUFFER 8192
+
+static int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
+{
+ if (data->ioc_len > BIT(30)) {
+ CERROR("OBD ioctl: ioc_len larger than 1<<30\n");
+ return 1;
+ }
+
+ if (data->ioc_inllen1 > BIT(30)) {
+ CERROR("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
+ return 1;
+ }
+
+ if (data->ioc_inllen2 > BIT(30)) {
+ CERROR("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
+ return 1;
+ }
+
+ if (data->ioc_inllen3 > BIT(30)) {
+ CERROR("OBD ioctl: ioc_inllen3 larger than 1<<30\n");
+ return 1;
+ }
+
+ if (data->ioc_inllen4 > BIT(30)) {
+ CERROR("OBD ioctl: ioc_inllen4 larger than 1<<30\n");
+ return 1;
+ }
+
+ if (data->ioc_inlbuf1 && data->ioc_inllen1 == 0) {
+ CERROR("OBD ioctl: inlbuf1 pointer but 0 length\n");
+ return 1;
+ }
+
+ if (data->ioc_inlbuf2 && data->ioc_inllen2 == 0) {
+ CERROR("OBD ioctl: inlbuf2 pointer but 0 length\n");
+ return 1;
+ }
+
+ if (data->ioc_inlbuf3 && data->ioc_inllen3 == 0) {
+ CERROR("OBD ioctl: inlbuf3 pointer but 0 length\n");
+ return 1;
+ }
+
+ if (data->ioc_inlbuf4 && data->ioc_inllen4 == 0) {
+ CERROR("OBD ioctl: inlbuf4 pointer but 0 length\n");
+ return 1;
+ }
+
+ if (data->ioc_pbuf1 && data->ioc_plen1 == 0) {
+ CERROR("OBD ioctl: pbuf1 pointer but 0 length\n");
+ return 1;
+ }
+
+ if (data->ioc_pbuf2 && data->ioc_plen2 == 0) {
+ CERROR("OBD ioctl: pbuf2 pointer but 0 length\n");
+ return 1;
+ }
+
+ if (!data->ioc_pbuf1 && data->ioc_plen1 != 0) {
+ CERROR("OBD ioctl: plen1 set but NULL pointer\n");
+ return 1;
+ }
+
+ if (!data->ioc_pbuf2 && data->ioc_plen2 != 0) {
+ CERROR("OBD ioctl: plen2 set but NULL pointer\n");
+ return 1;
+ }
+
+ if (obd_ioctl_packlen(data) > data->ioc_len) {
+ CERROR("OBD ioctl: packlen exceeds ioc_len (%d > %d)\n",
+ obd_ioctl_packlen(data), data->ioc_len);
+ return 1;
+ }
+
+ return 0;
+}
+
+/* buffer MUST be at least the size of obd_ioctl_hdr */
+int obd_ioctl_getdata(char **buf, int *len, void __user *arg)
+{
+ struct obd_ioctl_hdr hdr;
+ struct obd_ioctl_data *data;
+ int err;
+ int offset = 0;
+
+ if (copy_from_user(&hdr, arg, sizeof(hdr)))
+ return -EFAULT;
+
+ if (hdr.ioc_version != OBD_IOCTL_VERSION) {
+ CERROR("Version mismatch kernel (%x) vs application (%x)\n",
+ OBD_IOCTL_VERSION, hdr.ioc_version);
+ return -EINVAL;
+ }
+
+ if (hdr.ioc_len > OBD_MAX_IOCTL_BUFFER) {
+ CERROR("User buffer len %d exceeds %d max buffer\n",
+ hdr.ioc_len, OBD_MAX_IOCTL_BUFFER);
+ return -EINVAL;
+ }
+
+ if (hdr.ioc_len < sizeof(struct obd_ioctl_data)) {
+ CERROR("User buffer too small for ioctl (%d)\n", hdr.ioc_len);
+ return -EINVAL;
+ }
+
+ /* When there are lots of processes calling vmalloc on multi-core
+ * system, the high lock contention will hurt performance badly,
+ * obdfilter-survey is an example, which relies on ioctl. So we'd
+ * better avoid vmalloc on ioctl path. LU-66
+ */
+ *buf = kvzalloc(hdr.ioc_len, GFP_KERNEL);
+ if (!*buf) {
+ CERROR("Cannot allocate control buffer of len %d\n",
+ hdr.ioc_len);
+ return -EINVAL;
+ }
+ *len = hdr.ioc_len;
+ data = (struct obd_ioctl_data *)*buf;
+
+ if (copy_from_user(*buf, arg, hdr.ioc_len)) {
+ err = -EFAULT;
+ goto free_buf;
+ }
+ if (hdr.ioc_len != data->ioc_len) {
+ err = -EINVAL;
+ goto free_buf;
+ }
+
+ if (obd_ioctl_is_invalid(data)) {
+ CERROR("ioctl not correctly formatted\n");
+ err = -EINVAL;
+ goto free_buf;
+ }
+
+ if (data->ioc_inllen1) {
+ data->ioc_inlbuf1 = &data->ioc_bulk[0];
+ offset += cfs_size_round(data->ioc_inllen1);
+ }
+
+ if (data->ioc_inllen2) {
+ data->ioc_inlbuf2 = &data->ioc_bulk[0] + offset;
+ offset += cfs_size_round(data->ioc_inllen2);
+ }
+
+ if (data->ioc_inllen3) {
+ data->ioc_inlbuf3 = &data->ioc_bulk[0] + offset;
+ offset += cfs_size_round(data->ioc_inllen3);
+ }
+
+ if (data->ioc_inllen4)
+ data->ioc_inlbuf4 = &data->ioc_bulk[0] + offset;
+
+ return 0;
+
+free_buf:
+ kvfree(*buf);
+ return err;
+}
+EXPORT_SYMBOL(obd_ioctl_getdata);
+
+/* opening /dev/obd */
+static int obd_class_open(struct inode *inode, struct file *file)
+{
+ try_module_get(THIS_MODULE);
+ return 0;
+}
+
+/* closing /dev/obd */
+static int obd_class_release(struct inode *inode, struct file *file)
+{
+ module_put(THIS_MODULE);
+ return 0;
+}
+
+/* to control /dev/obd */
+static long obd_class_ioctl(struct file *filp, unsigned int cmd,
+ unsigned long arg)
+{
+ int err = 0;
+
+ /* Allow non-root access for OBD_IOC_PING_TARGET - used by lfs check */
+ if (!capable(CAP_SYS_ADMIN) && (cmd != OBD_IOC_PING_TARGET))
+ return err = -EACCES;
+ if ((cmd & 0xffffff00) == ((int)'T') << 8) /* ignore all tty ioctls */
+ return err = -ENOTTY;
+
+ err = class_handle_ioctl(cmd, (unsigned long)arg);
+
+ return err;
+}
+
+/* declare character device */
+static const struct file_operations obd_psdev_fops = {
+ .owner = THIS_MODULE,
+ .unlocked_ioctl = obd_class_ioctl, /* unlocked_ioctl */
+ .open = obd_class_open, /* open */
+ .release = obd_class_release, /* release */
+};
+
+/* modules setup */
+struct miscdevice obd_psdev = {
+ .minor = MISC_DYNAMIC_MINOR,
+ .name = OBD_DEV_NAME,
+ .fops = &obd_psdev_fops,
+};
+
+static ssize_t version_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
+{
+ return sprintf(buf, "%s\n", LUSTRE_VERSION_STRING);
+}
+
+static ssize_t pinger_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
+{
+ return sprintf(buf, "%s\n", "on");
+}
+
+static ssize_t
+health_check_show(struct kobject *kobj, struct attribute *attr, char *buf)
+{
+ bool healthy = true;
+ int i;
+ size_t len = 0;
+
+ if (libcfs_catastrophe)
+ return sprintf(buf, "LBUG\n");
+
+ read_lock(&obd_dev_lock);
+ for (i = 0; i < class_devno_max(); i++) {
+ struct obd_device *obd;
+
+ obd = class_num2obd(i);
+ if (!obd || !obd->obd_attached || !obd->obd_set_up)
+ continue;
+
+ LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
+ if (obd->obd_stopping)
+ continue;
+
+ class_incref(obd, __func__, current);
+ read_unlock(&obd_dev_lock);
+
+ if (obd_health_check(NULL, obd))
+ healthy = false;
+ class_decref(obd, __func__, current);
+ read_lock(&obd_dev_lock);
+ }
+ read_unlock(&obd_dev_lock);
+
+ if (healthy)
+ len = sprintf(buf, "healthy\n");
+ else
+ len = sprintf(buf, "NOT HEALTHY\n");
+
+ return len;
+}
+
+static ssize_t jobid_var_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
+{
+ return snprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_var);
+}
+
+static ssize_t jobid_var_store(struct kobject *kobj, struct attribute *attr,
+ const char *buffer,
+ size_t count)
+{
+ if (!count || count > JOBSTATS_JOBID_VAR_MAX_LEN)
+ return -EINVAL;
+
+ memset(obd_jobid_var, 0, JOBSTATS_JOBID_VAR_MAX_LEN + 1);
+
+ memcpy(obd_jobid_var, buffer, count);
+
+ /* Trim the trailing '\n' if any */
+ if (obd_jobid_var[count - 1] == '\n')
+ obd_jobid_var[count - 1] = 0;
+
+ return count;
+}
+
+static ssize_t jobid_name_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
+{
+ return snprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_node);
+}
+
+static ssize_t jobid_name_store(struct kobject *kobj, struct attribute *attr,
+ const char *buffer,
+ size_t count)
+{
+ if (!count || count > LUSTRE_JOBID_SIZE)
+ return -EINVAL;
+
+ memcpy(obd_jobid_node, buffer, count);
+
+ obd_jobid_node[count] = 0;
+
+ /* Trim the trailing '\n' if any */
+ if (obd_jobid_node[count - 1] == '\n')
+ obd_jobid_node[count - 1] = 0;
+
+ return count;
+}
+
+/* Root for /sys/kernel/debug/lustre */
+struct dentry *debugfs_lustre_root;
+EXPORT_SYMBOL_GPL(debugfs_lustre_root);
+
+LUSTRE_RO_ATTR(version);
+LUSTRE_RO_ATTR(pinger);
+LUSTRE_RO_ATTR(health_check);
+LUSTRE_RW_ATTR(jobid_var);
+LUSTRE_RW_ATTR(jobid_name);
+
+static struct attribute *lustre_attrs[] = {
+ &lustre_attr_version.attr,
+ &lustre_attr_pinger.attr,
+ &lustre_attr_health_check.attr,
+ &lustre_attr_jobid_name.attr,
+ &lustre_attr_jobid_var.attr,
+ NULL,
+};
+
+static void *obd_device_list_seq_start(struct seq_file *p, loff_t *pos)
+{
+ if (*pos >= class_devno_max())
+ return NULL;
+
+ return pos;
+}
+
+static void obd_device_list_seq_stop(struct seq_file *p, void *v)
+{
+}
+
+static void *obd_device_list_seq_next(struct seq_file *p, void *v, loff_t *pos)
+{
+ ++*pos;
+ if (*pos >= class_devno_max())
+ return NULL;
+
+ return pos;
+}
+
+static int obd_device_list_seq_show(struct seq_file *p, void *v)
+{
+ loff_t index = *(loff_t *)v;
+ struct obd_device *obd = class_num2obd((int)index);
+ char *status;
+
+ if (!obd)
+ return 0;
+
+ LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
+ if (obd->obd_stopping)
+ status = "ST";
+ else if (obd->obd_inactive)
+ status = "IN";
+ else if (obd->obd_set_up)
+ status = "UP";
+ else if (obd->obd_attached)
+ status = "AT";
+ else
+ status = "--";
+
+ seq_printf(p, "%3d %s %s %s %s %d\n",
+ (int)index, status, obd->obd_type->typ_name,
+ obd->obd_name, obd->obd_uuid.uuid,
+ atomic_read(&obd->obd_refcount));
+ return 0;
+}
+
+static const struct seq_operations obd_device_list_sops = {
+ .start = obd_device_list_seq_start,
+ .stop = obd_device_list_seq_stop,
+ .next = obd_device_list_seq_next,
+ .show = obd_device_list_seq_show,
+};
+
+static int obd_device_list_open(struct inode *inode, struct file *file)
+{
+ struct seq_file *seq;
+ int rc = seq_open(file, &obd_device_list_sops);
+
+ if (rc)
+ return rc;
+
+ seq = file->private_data;
+ seq->private = inode->i_private;
+
+ return 0;
+}
+
+static const struct file_operations obd_device_list_fops = {
+ .owner = THIS_MODULE,
+ .open = obd_device_list_open,
+ .read = seq_read,
+ .llseek = seq_lseek,
+ .release = seq_release,
+};
+
+struct kobject *lustre_kobj;
+EXPORT_SYMBOL_GPL(lustre_kobj);
+
+static const struct attribute_group lustre_attr_group = {
+ .attrs = lustre_attrs,
+};
+
+int class_procfs_init(void)
+{
+ int rc = -ENOMEM;
+
+ lustre_kobj = kobject_create_and_add("lustre", fs_kobj);
+ if (!lustre_kobj)
+ goto out;
+
+ /* Create the files associated with this kobject */
+ rc = sysfs_create_group(lustre_kobj, &lustre_attr_group);
+ if (rc) {
+ kobject_put(lustre_kobj);
+ goto out;
+ }
+
+ debugfs_lustre_root = debugfs_create_dir("lustre", NULL);
+
+ debugfs_create_file("devices", 0444, debugfs_lustre_root, NULL,
+ &obd_device_list_fops);
+out:
+ return rc;
+}
+
+int class_procfs_clean(void)
+{
+ debugfs_remove_recursive(debugfs_lustre_root);
+
+ debugfs_lustre_root = NULL;
+
+ sysfs_remove_group(lustre_kobj, &lustre_attr_group);
+ kobject_put(lustre_kobj);
+
+ return 0;
+}
diff --git a/drivers/staging/lustre/lustre/obdclass/sysctl.c b/drivers/staging/lustre/lustre/obdclass/sysctl.c
new file mode 100644
index 000000000000..e5e8687784ee
--- /dev/null
+++ b/drivers/staging/lustre/lustre/obdclass/sysctl.c
@@ -0,0 +1,162 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2015, Intel Corporation.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ */
+
+#include <linux/module.h>
+#include <linux/sysctl.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/stat.h>
+#include <linux/ctype.h>
+#include <linux/bitops.h>
+#include <linux/uaccess.h>
+#include <linux/utsname.h>
+
+#define DEBUG_SUBSYSTEM S_CLASS
+
+#include <obd_support.h>
+#include <lprocfs_status.h>
+#include <obd_class.h>
+
+struct static_lustre_uintvalue_attr {
+ struct {
+ struct attribute attr;
+ ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
+ char *buf);
+ ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
+ const char *buf, size_t len);
+ } u;
+ int *value;
+};
+
+static ssize_t static_uintvalue_show(struct kobject *kobj,
+ struct attribute *attr,
+ char *buf)
+{
+ struct static_lustre_uintvalue_attr *lattr = (void *)attr;
+
+ return sprintf(buf, "%d\n", *lattr->value);
+}
+
+static ssize_t static_uintvalue_store(struct kobject *kobj,
+ struct attribute *attr,
+ const char *buffer, size_t count)
+{
+ struct static_lustre_uintvalue_attr *lattr = (void *)attr;
+ int rc;
+ unsigned int val;
+
+ rc = kstrtouint(buffer, 10, &val);
+ if (rc)
+ return rc;
+
+ *lattr->value = val;
+
+ return count;
+}
+
+#define LUSTRE_STATIC_UINT_ATTR(name, value) \
+static struct static_lustre_uintvalue_attr lustre_sattr_##name = \
+ {__ATTR(name, 0644, \
+ static_uintvalue_show, \
+ static_uintvalue_store),\
+ value }
+
+LUSTRE_STATIC_UINT_ATTR(timeout, &obd_timeout);
+
+static ssize_t max_dirty_mb_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
+{
+ return sprintf(buf, "%lu\n",
+ obd_max_dirty_pages / (1 << (20 - PAGE_SHIFT)));
+}
+
+static ssize_t max_dirty_mb_store(struct kobject *kobj, struct attribute *attr,
+ const char *buffer, size_t count)
+{
+ int rc;
+ unsigned long val;
+
+ rc = kstrtoul(buffer, 10, &val);
+ if (rc)
+ return rc;
+
+ val *= 1 << (20 - PAGE_SHIFT); /* convert to pages */
+
+ if (val > ((totalram_pages / 10) * 9)) {
+ /* Somebody wants to assign too much memory to dirty pages */
+ return -EINVAL;
+ }
+
+ if (val < 4 << (20 - PAGE_SHIFT)) {
+ /* Less than 4 Mb for dirty cache is also bad */
+ return -EINVAL;
+ }
+
+ obd_max_dirty_pages = val;
+
+ return count;
+}
+LUSTRE_RW_ATTR(max_dirty_mb);
+
+LUSTRE_STATIC_UINT_ATTR(debug_peer_on_timeout, &obd_debug_peer_on_timeout);
+LUSTRE_STATIC_UINT_ATTR(dump_on_timeout, &obd_dump_on_timeout);
+LUSTRE_STATIC_UINT_ATTR(dump_on_eviction, &obd_dump_on_eviction);
+LUSTRE_STATIC_UINT_ATTR(at_min, &at_min);
+LUSTRE_STATIC_UINT_ATTR(at_max, &at_max);
+LUSTRE_STATIC_UINT_ATTR(at_extra, &at_extra);
+LUSTRE_STATIC_UINT_ATTR(at_early_margin, &at_early_margin);
+LUSTRE_STATIC_UINT_ATTR(at_history, &at_history);
+
+static struct attribute *lustre_attrs[] = {
+ &lustre_sattr_timeout.u.attr,
+ &lustre_attr_max_dirty_mb.attr,
+ &lustre_sattr_debug_peer_on_timeout.u.attr,
+ &lustre_sattr_dump_on_timeout.u.attr,
+ &lustre_sattr_dump_on_eviction.u.attr,
+ &lustre_sattr_at_min.u.attr,
+ &lustre_sattr_at_max.u.attr,
+ &lustre_sattr_at_extra.u.attr,
+ &lustre_sattr_at_early_margin.u.attr,
+ &lustre_sattr_at_history.u.attr,
+ NULL,
+};
+
+static const struct attribute_group lustre_attr_group = {
+ .attrs = lustre_attrs,
+};
+
+int obd_sysctl_init(void)
+{
+ return sysfs_create_group(lustre_kobj, &lustre_attr_group);
+}



2018-06-06 06:14:49

by NeilBrown

[permalink] [raw]
Subject: [PATCH 11/11] staging: lustre: centralize setting of subdir-ccflags-y

We don't need to set subdir-ccflags-y in every Makefile.
The whole point of the "subdir-" bit is that the setting
can go once in the top-level Makefile.

Signed-off-by: NeilBrown <[email protected]>
---
drivers/staging/lustre/Makefile | 3 +++
drivers/staging/lustre/lnet/klnds/o2iblnd/Makefile | 2 --
drivers/staging/lustre/lnet/klnds/socklnd/Makefile | 2 --
drivers/staging/lustre/lnet/libcfs/Makefile | 2 --
drivers/staging/lustre/lnet/lnet/Makefile | 2 --
drivers/staging/lustre/lnet/selftest/Makefile | 2 --
drivers/staging/lustre/lustre/fid/Makefile | 2 --
drivers/staging/lustre/lustre/fld/Makefile | 2 --
drivers/staging/lustre/lustre/llite/Makefile | 2 --
drivers/staging/lustre/lustre/lmv/Makefile | 2 --
drivers/staging/lustre/lustre/lov/Makefile | 2 --
drivers/staging/lustre/lustre/mdc/Makefile | 2 --
drivers/staging/lustre/lustre/mgc/Makefile | 2 --
drivers/staging/lustre/lustre/obdclass/Makefile | 2 --
drivers/staging/lustre/lustre/obdecho/Makefile | 2 --
drivers/staging/lustre/lustre/osc/Makefile | 2 --
drivers/staging/lustre/lustre/ptlrpc/Makefile | 2 --
17 files changed, 3 insertions(+), 32 deletions(-)

diff --git a/drivers/staging/lustre/Makefile b/drivers/staging/lustre/Makefile
index 95ffe337a80a..a44086fa8668 100644
--- a/drivers/staging/lustre/Makefile
+++ b/drivers/staging/lustre/Makefile
@@ -1,2 +1,5 @@
+subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
+subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
+
obj-$(CONFIG_LNET) += lnet/
obj-$(CONFIG_LUSTRE_FS) += lustre/
diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/Makefile b/drivers/staging/lustre/lnet/klnds/o2iblnd/Makefile
index 4affe1d79948..e1a05ece130c 100644
--- a/drivers/staging/lustre/lnet/klnds/o2iblnd/Makefile
+++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/Makefile
@@ -1,5 +1,3 @@
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include

obj-$(CONFIG_LNET_XPRT_IB) += ko2iblnd.o
ko2iblnd-y := o2iblnd.o o2iblnd_cb.o o2iblnd_modparams.o
diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/Makefile b/drivers/staging/lustre/lnet/klnds/socklnd/Makefile
index a7da1abfc804..4d03cad997c1 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/Makefile
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/Makefile
@@ -1,5 +1,3 @@
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include

obj-$(CONFIG_LNET) += ksocklnd.o

diff --git a/drivers/staging/lustre/lnet/libcfs/Makefile b/drivers/staging/lustre/lnet/libcfs/Makefile
index 6a1b232da495..3d6b99c6e883 100644
--- a/drivers/staging/lustre/lnet/libcfs/Makefile
+++ b/drivers/staging/lustre/lnet/libcfs/Makefile
@@ -1,6 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include

obj-$(CONFIG_LNET) += libcfs.o

diff --git a/drivers/staging/lustre/lnet/lnet/Makefile b/drivers/staging/lustre/lnet/lnet/Makefile
index 0a9d70924fe0..ba33e90e47ec 100644
--- a/drivers/staging/lustre/lnet/lnet/Makefile
+++ b/drivers/staging/lustre/lnet/lnet/Makefile
@@ -1,6 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include

obj-$(CONFIG_LNET) += lnet.o

diff --git a/drivers/staging/lustre/lnet/selftest/Makefile b/drivers/staging/lustre/lnet/selftest/Makefile
index 3ccc8966b566..16f8efcd1531 100644
--- a/drivers/staging/lustre/lnet/selftest/Makefile
+++ b/drivers/staging/lustre/lnet/selftest/Makefile
@@ -1,5 +1,3 @@
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include

obj-$(CONFIG_LNET_SELFTEST) := lnet_selftest.o

diff --git a/drivers/staging/lustre/lustre/fid/Makefile b/drivers/staging/lustre/lustre/fid/Makefile
index 77b65b92667d..11f6e4046e61 100644
--- a/drivers/staging/lustre/lustre/fid/Makefile
+++ b/drivers/staging/lustre/lustre/fid/Makefile
@@ -1,5 +1,3 @@
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include/

obj-$(CONFIG_LUSTRE_FS) += fid.o
fid-y := fid_request.o fid_lib.o lproc_fid.o
diff --git a/drivers/staging/lustre/lustre/fld/Makefile b/drivers/staging/lustre/lustre/fld/Makefile
index 426deba8b815..e7843d7aac9d 100644
--- a/drivers/staging/lustre/lustre/fld/Makefile
+++ b/drivers/staging/lustre/lustre/fld/Makefile
@@ -1,5 +1,3 @@
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include/

obj-$(CONFIG_LUSTRE_FS) += fld.o
fld-y := fld_request.o fld_cache.o lproc_fld.o
diff --git a/drivers/staging/lustre/lustre/llite/Makefile b/drivers/staging/lustre/lustre/llite/Makefile
index 5200924182ae..f46b61770254 100644
--- a/drivers/staging/lustre/lustre/llite/Makefile
+++ b/drivers/staging/lustre/lustre/llite/Makefile
@@ -1,6 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include

obj-$(CONFIG_LUSTRE_FS) += lustre.o
lustre-y := dcache.o dir.o file.o llite_lib.o llite_nfs.o \
diff --git a/drivers/staging/lustre/lustre/lmv/Makefile b/drivers/staging/lustre/lustre/lmv/Makefile
index 91c99114aa13..7a392c31c508 100644
--- a/drivers/staging/lustre/lustre/lmv/Makefile
+++ b/drivers/staging/lustre/lustre/lmv/Makefile
@@ -1,5 +1,3 @@
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include

obj-$(CONFIG_LUSTRE_FS) += lmv.o
lmv-y := lmv_obd.o lmv_intent.o lmv_fld.o lproc_lmv.o
diff --git a/drivers/staging/lustre/lustre/lov/Makefile b/drivers/staging/lustre/lustre/lov/Makefile
index 1ebf0193f61a..6294769aca95 100644
--- a/drivers/staging/lustre/lustre/lov/Makefile
+++ b/drivers/staging/lustre/lustre/lov/Makefile
@@ -1,6 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include

obj-$(CONFIG_LUSTRE_FS) += lov.o
lov-y := lov_obd.o lov_pack.o lov_offset.o lov_merge.o \
diff --git a/drivers/staging/lustre/lustre/mdc/Makefile b/drivers/staging/lustre/lustre/mdc/Makefile
index c7bc3351ccb0..c3bc71f6596d 100644
--- a/drivers/staging/lustre/lustre/mdc/Makefile
+++ b/drivers/staging/lustre/lustre/mdc/Makefile
@@ -1,5 +1,3 @@
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include

obj-$(CONFIG_LUSTRE_FS) += mdc.o
mdc-y := mdc_request.o mdc_reint.o mdc_lib.o mdc_locks.o lproc_mdc.o
diff --git a/drivers/staging/lustre/lustre/mgc/Makefile b/drivers/staging/lustre/lustre/mgc/Makefile
index 8abf108dbcf7..301cd7a1fa25 100644
--- a/drivers/staging/lustre/lustre/mgc/Makefile
+++ b/drivers/staging/lustre/lustre/mgc/Makefile
@@ -1,5 +1,3 @@
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include

obj-$(CONFIG_LUSTRE_FS) += mgc.o
mgc-y := mgc_request.o lproc_mgc.o
diff --git a/drivers/staging/lustre/lustre/obdclass/Makefile b/drivers/staging/lustre/lustre/obdclass/Makefile
index e36ba2167d10..be118391b402 100644
--- a/drivers/staging/lustre/lustre/obdclass/Makefile
+++ b/drivers/staging/lustre/lustre/obdclass/Makefile
@@ -1,6 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include

obj-$(CONFIG_LUSTRE_FS) += obdclass.o

diff --git a/drivers/staging/lustre/lustre/obdecho/Makefile b/drivers/staging/lustre/lustre/obdecho/Makefile
index 6be66fbab872..4ae346f5ddcd 100644
--- a/drivers/staging/lustre/lustre/obdecho/Makefile
+++ b/drivers/staging/lustre/lustre/obdecho/Makefile
@@ -1,5 +1,3 @@
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include

obj-$(CONFIG_LUSTRE_FS) += obdecho.o
obdecho-y := echo_client.o
diff --git a/drivers/staging/lustre/lustre/osc/Makefile b/drivers/staging/lustre/lustre/osc/Makefile
index 30dec90e64e8..ecdf07e925c7 100644
--- a/drivers/staging/lustre/lustre/osc/Makefile
+++ b/drivers/staging/lustre/lustre/osc/Makefile
@@ -1,5 +1,3 @@
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include

obj-$(CONFIG_LUSTRE_FS) += osc.o
osc-y := osc_request.o osc_dev.o osc_object.o \
diff --git a/drivers/staging/lustre/lustre/ptlrpc/Makefile b/drivers/staging/lustre/lustre/ptlrpc/Makefile
index aa152e652002..0fae7de09de2 100644
--- a/drivers/staging/lustre/lustre/ptlrpc/Makefile
+++ b/drivers/staging/lustre/lustre/ptlrpc/Makefile
@@ -1,6 +1,4 @@
# SPDX-License-Identifier: GPL-2.0
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
-subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include

obj-$(CONFIG_LUSTRE_FS) += ptlrpc.o




2018-06-13 21:39:06

by James Simmons

[permalink] [raw]
Subject: Re: [PATCH 11/11] staging: lustre: centralize setting of subdir-ccflags-y


> We don't need to set subdir-ccflags-y in every Makefile.
> The whole point of the "subdir-" bit is that the setting
> can go once in the top-level Makefile.
>

Nak: When attempting to build individual components I get:

~/lustre-upstream$ make SUBDIRS=drivers/staging/lustre/lustre/lmv modules
-j 16

WARNING: Symbol version dump ./Module.symvers
is missing; modules will have no dependencies and modversions.

CC [M] drivers/staging/lustre/lustre/lmv/lmv_obd.o
CC [M] drivers/staging/lustre/lustre/lmv/lmv_intent.o
CC [M] drivers/staging/lustre/lustre/lmv/lmv_fld.o
CC [M] drivers/staging/lustre/lustre/lmv/lproc_lmv.o
drivers/staging/lustre/lustre/lmv/lproc_lmv.c:38:28: fatal error:
lprocfs_status.h: No such file or directory
#include <lprocfs_status.h>
^
compilation terminated.


> Signed-off-by: NeilBrown <[email protected]>
> ---
> drivers/staging/lustre/Makefile | 3 +++
> drivers/staging/lustre/lnet/klnds/o2iblnd/Makefile | 2 --
> drivers/staging/lustre/lnet/klnds/socklnd/Makefile | 2 --
> drivers/staging/lustre/lnet/libcfs/Makefile | 2 --
> drivers/staging/lustre/lnet/lnet/Makefile | 2 --
> drivers/staging/lustre/lnet/selftest/Makefile | 2 --
> drivers/staging/lustre/lustre/fid/Makefile | 2 --
> drivers/staging/lustre/lustre/fld/Makefile | 2 --
> drivers/staging/lustre/lustre/llite/Makefile | 2 --
> drivers/staging/lustre/lustre/lmv/Makefile | 2 --
> drivers/staging/lustre/lustre/lov/Makefile | 2 --
> drivers/staging/lustre/lustre/mdc/Makefile | 2 --
> drivers/staging/lustre/lustre/mgc/Makefile | 2 --
> drivers/staging/lustre/lustre/obdclass/Makefile | 2 --
> drivers/staging/lustre/lustre/obdecho/Makefile | 2 --
> drivers/staging/lustre/lustre/osc/Makefile | 2 --
> drivers/staging/lustre/lustre/ptlrpc/Makefile | 2 --
> 17 files changed, 3 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/staging/lustre/Makefile b/drivers/staging/lustre/Makefile
> index 95ffe337a80a..a44086fa8668 100644
> --- a/drivers/staging/lustre/Makefile
> +++ b/drivers/staging/lustre/Makefile
> @@ -1,2 +1,5 @@
> +subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> +subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
> +
> obj-$(CONFIG_LNET) += lnet/
> obj-$(CONFIG_LUSTRE_FS) += lustre/
> diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/Makefile b/drivers/staging/lustre/lnet/klnds/o2iblnd/Makefile
> index 4affe1d79948..e1a05ece130c 100644
> --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/Makefile
> +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/Makefile
> @@ -1,5 +1,3 @@
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
>
> obj-$(CONFIG_LNET_XPRT_IB) += ko2iblnd.o
> ko2iblnd-y := o2iblnd.o o2iblnd_cb.o o2iblnd_modparams.o
> diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/Makefile b/drivers/staging/lustre/lnet/klnds/socklnd/Makefile
> index a7da1abfc804..4d03cad997c1 100644
> --- a/drivers/staging/lustre/lnet/klnds/socklnd/Makefile
> +++ b/drivers/staging/lustre/lnet/klnds/socklnd/Makefile
> @@ -1,5 +1,3 @@
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
>
> obj-$(CONFIG_LNET) += ksocklnd.o
>
> diff --git a/drivers/staging/lustre/lnet/libcfs/Makefile b/drivers/staging/lustre/lnet/libcfs/Makefile
> index 6a1b232da495..3d6b99c6e883 100644
> --- a/drivers/staging/lustre/lnet/libcfs/Makefile
> +++ b/drivers/staging/lustre/lnet/libcfs/Makefile
> @@ -1,6 +1,4 @@
> # SPDX-License-Identifier: GPL-2.0
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
>
> obj-$(CONFIG_LNET) += libcfs.o
>
> diff --git a/drivers/staging/lustre/lnet/lnet/Makefile b/drivers/staging/lustre/lnet/lnet/Makefile
> index 0a9d70924fe0..ba33e90e47ec 100644
> --- a/drivers/staging/lustre/lnet/lnet/Makefile
> +++ b/drivers/staging/lustre/lnet/lnet/Makefile
> @@ -1,6 +1,4 @@
> # SPDX-License-Identifier: GPL-2.0
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
>
> obj-$(CONFIG_LNET) += lnet.o
>
> diff --git a/drivers/staging/lustre/lnet/selftest/Makefile b/drivers/staging/lustre/lnet/selftest/Makefile
> index 3ccc8966b566..16f8efcd1531 100644
> --- a/drivers/staging/lustre/lnet/selftest/Makefile
> +++ b/drivers/staging/lustre/lnet/selftest/Makefile
> @@ -1,5 +1,3 @@
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
>
> obj-$(CONFIG_LNET_SELFTEST) := lnet_selftest.o
>
> diff --git a/drivers/staging/lustre/lustre/fid/Makefile b/drivers/staging/lustre/lustre/fid/Makefile
> index 77b65b92667d..11f6e4046e61 100644
> --- a/drivers/staging/lustre/lustre/fid/Makefile
> +++ b/drivers/staging/lustre/lustre/fid/Makefile
> @@ -1,5 +1,3 @@
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include/
>
> obj-$(CONFIG_LUSTRE_FS) += fid.o
> fid-y := fid_request.o fid_lib.o lproc_fid.o
> diff --git a/drivers/staging/lustre/lustre/fld/Makefile b/drivers/staging/lustre/lustre/fld/Makefile
> index 426deba8b815..e7843d7aac9d 100644
> --- a/drivers/staging/lustre/lustre/fld/Makefile
> +++ b/drivers/staging/lustre/lustre/fld/Makefile
> @@ -1,5 +1,3 @@
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include/
>
> obj-$(CONFIG_LUSTRE_FS) += fld.o
> fld-y := fld_request.o fld_cache.o lproc_fld.o
> diff --git a/drivers/staging/lustre/lustre/llite/Makefile b/drivers/staging/lustre/lustre/llite/Makefile
> index 5200924182ae..f46b61770254 100644
> --- a/drivers/staging/lustre/lustre/llite/Makefile
> +++ b/drivers/staging/lustre/lustre/llite/Makefile
> @@ -1,6 +1,4 @@
> # SPDX-License-Identifier: GPL-2.0
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
>
> obj-$(CONFIG_LUSTRE_FS) += lustre.o
> lustre-y := dcache.o dir.o file.o llite_lib.o llite_nfs.o \
> diff --git a/drivers/staging/lustre/lustre/lmv/Makefile b/drivers/staging/lustre/lustre/lmv/Makefile
> index 91c99114aa13..7a392c31c508 100644
> --- a/drivers/staging/lustre/lustre/lmv/Makefile
> +++ b/drivers/staging/lustre/lustre/lmv/Makefile
> @@ -1,5 +1,3 @@
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
>
> obj-$(CONFIG_LUSTRE_FS) += lmv.o
> lmv-y := lmv_obd.o lmv_intent.o lmv_fld.o lproc_lmv.o
> diff --git a/drivers/staging/lustre/lustre/lov/Makefile b/drivers/staging/lustre/lustre/lov/Makefile
> index 1ebf0193f61a..6294769aca95 100644
> --- a/drivers/staging/lustre/lustre/lov/Makefile
> +++ b/drivers/staging/lustre/lustre/lov/Makefile
> @@ -1,6 +1,4 @@
> # SPDX-License-Identifier: GPL-2.0
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
>
> obj-$(CONFIG_LUSTRE_FS) += lov.o
> lov-y := lov_obd.o lov_pack.o lov_offset.o lov_merge.o \
> diff --git a/drivers/staging/lustre/lustre/mdc/Makefile b/drivers/staging/lustre/lustre/mdc/Makefile
> index c7bc3351ccb0..c3bc71f6596d 100644
> --- a/drivers/staging/lustre/lustre/mdc/Makefile
> +++ b/drivers/staging/lustre/lustre/mdc/Makefile
> @@ -1,5 +1,3 @@
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
>
> obj-$(CONFIG_LUSTRE_FS) += mdc.o
> mdc-y := mdc_request.o mdc_reint.o mdc_lib.o mdc_locks.o lproc_mdc.o
> diff --git a/drivers/staging/lustre/lustre/mgc/Makefile b/drivers/staging/lustre/lustre/mgc/Makefile
> index 8abf108dbcf7..301cd7a1fa25 100644
> --- a/drivers/staging/lustre/lustre/mgc/Makefile
> +++ b/drivers/staging/lustre/lustre/mgc/Makefile
> @@ -1,5 +1,3 @@
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
>
> obj-$(CONFIG_LUSTRE_FS) += mgc.o
> mgc-y := mgc_request.o lproc_mgc.o
> diff --git a/drivers/staging/lustre/lustre/obdclass/Makefile b/drivers/staging/lustre/lustre/obdclass/Makefile
> index e36ba2167d10..be118391b402 100644
> --- a/drivers/staging/lustre/lustre/obdclass/Makefile
> +++ b/drivers/staging/lustre/lustre/obdclass/Makefile
> @@ -1,6 +1,4 @@
> # SPDX-License-Identifier: GPL-2.0
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
>
> obj-$(CONFIG_LUSTRE_FS) += obdclass.o
>
> diff --git a/drivers/staging/lustre/lustre/obdecho/Makefile b/drivers/staging/lustre/lustre/obdecho/Makefile
> index 6be66fbab872..4ae346f5ddcd 100644
> --- a/drivers/staging/lustre/lustre/obdecho/Makefile
> +++ b/drivers/staging/lustre/lustre/obdecho/Makefile
> @@ -1,5 +1,3 @@
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
>
> obj-$(CONFIG_LUSTRE_FS) += obdecho.o
> obdecho-y := echo_client.o
> diff --git a/drivers/staging/lustre/lustre/osc/Makefile b/drivers/staging/lustre/lustre/osc/Makefile
> index 30dec90e64e8..ecdf07e925c7 100644
> --- a/drivers/staging/lustre/lustre/osc/Makefile
> +++ b/drivers/staging/lustre/lustre/osc/Makefile
> @@ -1,5 +1,3 @@
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
>
> obj-$(CONFIG_LUSTRE_FS) += osc.o
> osc-y := osc_request.o osc_dev.o osc_object.o \
> diff --git a/drivers/staging/lustre/lustre/ptlrpc/Makefile b/drivers/staging/lustre/lustre/ptlrpc/Makefile
> index aa152e652002..0fae7de09de2 100644
> --- a/drivers/staging/lustre/lustre/ptlrpc/Makefile
> +++ b/drivers/staging/lustre/lustre/ptlrpc/Makefile
> @@ -1,6 +1,4 @@
> # SPDX-License-Identifier: GPL-2.0
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/include
> -subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
>
> obj-$(CONFIG_LUSTRE_FS) += ptlrpc.o
>
>
>
>

2018-06-13 23:22:49

by NeilBrown

[permalink] [raw]
Subject: Re: [PATCH 11/11] staging: lustre: centralize setting of subdir-ccflags-y

On Wed, Jun 13 2018, James Simmons wrote:

>> We don't need to set subdir-ccflags-y in every Makefile.
>> The whole point of the "subdir-" bit is that the setting
>> can go once in the top-level Makefile.
>>
>
> Nak: When attempting to build individual components I get:
>
> ~/lustre-upstream$ make SUBDIRS=drivers/staging/lustre/lustre/lmv modules
> -j 16
>
> WARNING: Symbol version dump ./Module.symvers
> is missing; modules will have no dependencies and modversions.
>
> CC [M] drivers/staging/lustre/lustre/lmv/lmv_obd.o
> CC [M] drivers/staging/lustre/lustre/lmv/lmv_intent.o
> CC [M] drivers/staging/lustre/lustre/lmv/lmv_fld.o
> CC [M] drivers/staging/lustre/lustre/lmv/lproc_lmv.o
> drivers/staging/lustre/lustre/lmv/lproc_lmv.c:38:28: fatal error:
> lprocfs_status.h: No such file or directory
> #include <lprocfs_status.h>
> ^
> compilation terminated.

Yes, I noticed that too. Thanks.
It seems to suggest that subdir-ccflags-y isn't really a useful macro.
Maybe we should stick with cc-flags-y. It is much more widely used.

Thanks,
NeilBrown


Attachments:
signature.asc (847.00 B)

2018-06-14 02:38:55

by James Simmons

[permalink] [raw]
Subject: Re: [PATCH 07/11] staging: lustre: fold lprocfs_call_handler functionality into lnet_debugfs_*


> The calling convention for ->proc_handler is rather clumsy,
> as a comment in fs/procfs/proc_sysctl.c confirms.
> lustre has copied this convention to lnet_debugfs_{read,write},
> and then provided a wrapper for handlers - lprocfs_call_handler -
> to work around the clumsiness.
>
> It is cleaner to just fold the functionality of lprocfs_call_handler()
> into lnet_debugfs_* and let them call the final handler directly.
>
> If these files were ever moved to /proc/sys (which seems unlikely) the
> handling in fs/procfs/proc_sysctl.c would need to be fixed to, but
> that would not be a bad thing.
>
> So modify all the functions that did use the wrapper to not need it
> now that a more sane calling convention is available.

Reviewed-by: James Simmons <[email protected]>

> Signed-off-by: NeilBrown <[email protected]>
> ---
> .../staging/lustre/include/linux/libcfs/libcfs.h | 4 -
> drivers/staging/lustre/lnet/libcfs/module.c | 84 +++++++-------------
> drivers/staging/lustre/lnet/lnet/router_proc.c | 41 +++-------
> 3 files changed, 41 insertions(+), 88 deletions(-)
>
> diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs.h b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
> index edc7ed0dcb94..7ac609328256 100644
> --- a/drivers/staging/lustre/include/linux/libcfs/libcfs.h
> +++ b/drivers/staging/lustre/include/linux/libcfs/libcfs.h
> @@ -57,10 +57,6 @@ int libcfs_setup(void);
> extern struct workqueue_struct *cfs_rehash_wq;
>
> void lustre_insert_debugfs(struct ctl_table *table);
> -int lprocfs_call_handler(void *data, int write, loff_t *ppos,
> - void __user *buffer, size_t *lenp,
> - int (*handler)(void *data, int write, loff_t pos,
> - void __user *buffer, int len));
>
> /*
> * Memory
> diff --git a/drivers/staging/lustre/lnet/libcfs/module.c b/drivers/staging/lustre/lnet/libcfs/module.c
> index 5dc7de9e6478..02c404c6738e 100644
> --- a/drivers/staging/lustre/lnet/libcfs/module.c
> +++ b/drivers/staging/lustre/lnet/libcfs/module.c
> @@ -290,33 +290,15 @@ static struct miscdevice libcfs_dev = {
>
> static int libcfs_dev_registered;
>
> -int lprocfs_call_handler(void *data, int write, loff_t *ppos,
> - void __user *buffer, size_t *lenp,
> - int (*handler)(void *data, int write, loff_t pos,
> - void __user *buffer, int len))
> -{
> - int rc = handler(data, write, *ppos, buffer, *lenp);
> -
> - if (rc < 0)
> - return rc;
> -
> - if (write) {
> - *ppos += *lenp;
> - } else {
> - *lenp = rc;
> - *ppos += rc;
> - }
> - return 0;
> -}
> -EXPORT_SYMBOL(lprocfs_call_handler);
> -
> -static int __proc_dobitmasks(void *data, int write,
> - loff_t pos, void __user *buffer, int nob)
> +static int proc_dobitmasks(struct ctl_table *table, int write,
> + void __user *buffer, size_t *lenp, loff_t *ppos)
> {
> const int tmpstrlen = 512;
> char *tmpstr;
> int rc;
> - unsigned int *mask = data;
> + size_t nob = *lenp;
> + loff_t pos = *ppos;
> + unsigned int *mask = table->data;
> int is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0;
> int is_printk = (mask == &libcfs_printk) ? 1 : 0;
>
> @@ -351,32 +333,23 @@ static int __proc_dobitmasks(void *data, int write,
> return rc;
> }
>
> -static int proc_dobitmasks(struct ctl_table *table, int write,
> - void __user *buffer, size_t *lenp, loff_t *ppos)
> +static int proc_dump_kernel(struct ctl_table *table, int write,
> + void __user *buffer, size_t *lenp, loff_t *ppos)
> {
> - return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
> - __proc_dobitmasks);
> -}
> + size_t nob = *lenp;
>
> -static int __proc_dump_kernel(void *data, int write,
> - loff_t pos, void __user *buffer, int nob)
> -{
> if (!write)
> return 0;
>
> return cfs_trace_dump_debug_buffer_usrstr(buffer, nob);
> }
>
> -static int proc_dump_kernel(struct ctl_table *table, int write,
> +static int proc_daemon_file(struct ctl_table *table, int write,
> void __user *buffer, size_t *lenp, loff_t *ppos)
> {
> - return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
> - __proc_dump_kernel);
> -}
> + size_t nob = *lenp;
> + loff_t pos = *ppos;
>
> -static int __proc_daemon_file(void *data, int write,
> - loff_t pos, void __user *buffer, int nob)
> -{
> if (!write) {
> int len = strlen(cfs_tracefile);
>
> @@ -390,13 +363,6 @@ static int __proc_daemon_file(void *data, int write,
> return cfs_trace_daemon_command_usrstr(buffer, nob);
> }
>
> -static int proc_daemon_file(struct ctl_table *table, int write,
> - void __user *buffer, size_t *lenp, loff_t *ppos)
> -{
> - return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
> - __proc_daemon_file);
> -}
> -
> static int libcfs_force_lbug(struct ctl_table *table, int write,
> void __user *buffer,
> size_t *lenp, loff_t *ppos)
> @@ -419,9 +385,11 @@ static int proc_fail_loc(struct ctl_table *table, int write,
> return rc;
> }
>
> -static int __proc_cpt_table(void *data, int write,
> - loff_t pos, void __user *buffer, int nob)
> +static int proc_cpt_table(struct ctl_table *table, int write,
> + void __user *buffer, size_t *lenp, loff_t *ppos)
> {
> + size_t nob = *lenp;
> + loff_t pos = *ppos;
> char *buf = NULL;
> int len = 4096;
> int rc = 0;
> @@ -457,13 +425,6 @@ static int __proc_cpt_table(void *data, int write,
> return rc;
> }
>
> -static int proc_cpt_table(struct ctl_table *table, int write,
> - void __user *buffer, size_t *lenp, loff_t *ppos)
> -{
> - return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
> - __proc_cpt_table);
> -}
> -
> static struct ctl_table lnet_table[] = {
> {
> .procname = "debug",
> @@ -573,10 +534,17 @@ static ssize_t lnet_debugfs_read(struct file *filp, char __user *buf,
> {
> struct ctl_table *table = filp->private_data;
> int error;
> + loff_t old_pos = *ppos;
>
> error = table->proc_handler(table, 0, (void __user *)buf, &count, ppos);
> - if (!error)
> + /*
> + * On success, the length read is either in error or in count.
> + * If ppos changed, then use count, else use error
> + */
> + if (!error && *ppos != old_pos)
> error = count;
> + else if (error > 0)
> + *ppos += error;
>
> return error;
> }
> @@ -586,10 +554,14 @@ static ssize_t lnet_debugfs_write(struct file *filp, const char __user *buf,
> {
> struct ctl_table *table = filp->private_data;
> int error;
> + loff_t old_pos = *ppos;
>
> error = table->proc_handler(table, 1, (void __user *)buf, &count, ppos);
> - if (!error)
> + if (!error) {
> error = count;
> + if (*ppos == old_pos)
> + *ppos += count;
> + }
>
> return error;
> }
> diff --git a/drivers/staging/lustre/lnet/lnet/router_proc.c b/drivers/staging/lustre/lnet/lnet/router_proc.c
> index ae4b7f5953a0..f135082fec5c 100644
> --- a/drivers/staging/lustre/lnet/lnet/router_proc.c
> +++ b/drivers/staging/lustre/lnet/lnet/router_proc.c
> @@ -74,11 +74,13 @@
>
> #define LNET_PROC_VERSION(v) ((unsigned int)((v) & LNET_PROC_VER_MASK))
>
> -static int __proc_lnet_stats(void *data, int write,
> - loff_t pos, void __user *buffer, int nob)
> +static int proc_lnet_stats(struct ctl_table *table, int write,
> + void __user *buffer, size_t *lenp, loff_t *ppos)
> {
> int rc;
> struct lnet_counters *ctrs;
> + size_t nob = *lenp;
> + loff_t pos = *ppos;
> int len;
> char *tmpstr;
> const int tmpsiz = 256; /* 7 %u and 4 %llu */
> @@ -122,13 +124,6 @@ static int __proc_lnet_stats(void *data, int write,
> return rc;
> }
>
> -static int proc_lnet_stats(struct ctl_table *table, int write,
> - void __user *buffer, size_t *lenp, loff_t *ppos)
> -{
> - return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
> - __proc_lnet_stats);
> -}
> -
> static int proc_lnet_routes(struct ctl_table *table, int write,
> void __user *buffer, size_t *lenp, loff_t *ppos)
> {
> @@ -562,9 +557,11 @@ static int proc_lnet_peers(struct ctl_table *table, int write,
> return rc;
> }
>
> -static int __proc_lnet_buffers(void *data, int write,
> - loff_t pos, void __user *buffer, int nob)
> +static int proc_lnet_buffers(struct ctl_table *table, int write,
> + void __user *buffer, size_t *lenp, loff_t *ppos)
> {
> + size_t nob = *lenp;
> + loff_t pos = *ppos;
> char *s;
> char *tmpstr;
> int tmpsiz;
> @@ -620,13 +617,6 @@ static int __proc_lnet_buffers(void *data, int write,
> return rc;
> }
>
> -static int proc_lnet_buffers(struct ctl_table *table, int write,
> - void __user *buffer, size_t *lenp, loff_t *ppos)
> -{
> - return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
> - __proc_lnet_buffers);
> -}
> -
> static int proc_lnet_nis(struct ctl_table *table, int write,
> void __user *buffer, size_t *lenp, loff_t *ppos)
> {
> @@ -784,10 +774,13 @@ static struct lnet_portal_rotors portal_rotors[] = {
> },
> };
>
> -static int __proc_lnet_portal_rotor(void *data, int write,
> - loff_t pos, void __user *buffer, int nob)
> +static int proc_lnet_portal_rotor(struct ctl_table *table, int write,
> + void __user *buffer, size_t *lenp,
> + loff_t *ppos)
> {
> const int buf_len = 128;
> + size_t nob = *lenp;
> + loff_t pos = *ppos;
> char *buf;
> char *tmp;
> int rc;
> @@ -845,14 +838,6 @@ static int __proc_lnet_portal_rotor(void *data, int write,
> return rc;
> }
>
> -static int proc_lnet_portal_rotor(struct ctl_table *table, int write,
> - void __user *buffer, size_t *lenp,
> - loff_t *ppos)
> -{
> - return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
> - __proc_lnet_portal_rotor);
> -}
> -
> static struct ctl_table lnet_table[] = {
> /*
> * NB No .strategy entries have been provided since sysctl(8) prefers
>
>
>

2018-06-14 02:40:58

by James Simmons

[permalink] [raw]
Subject: Re: [PATCH 09/11] staging: lustre: discard WIRE_ATTR


> This macro adds nothing of value, and make the code harder
> to read for new readers.

Reviewed-by: James Simmons <[email protected]>

> Signed-off-by: NeilBrown <[email protected]>
> ---
> .../staging/lustre/include/linux/lnet/socklnd.h | 8 ++-
> .../lustre/include/uapi/linux/lnet/lnet-types.h | 28 +++++-------
> .../lustre/include/uapi/linux/lnet/lnetst.h | 4 +-
> .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h | 22 +++++----
> drivers/staging/lustre/lnet/selftest/rpc.h | 48 ++++++++++----------
> 5 files changed, 54 insertions(+), 56 deletions(-)
>
> diff --git a/drivers/staging/lustre/include/linux/lnet/socklnd.h b/drivers/staging/lustre/include/linux/lnet/socklnd.h
> index 6bd1bca190a3..9f69257e000b 100644
> --- a/drivers/staging/lustre/include/linux/lnet/socklnd.h
> +++ b/drivers/staging/lustre/include/linux/lnet/socklnd.h
> @@ -50,7 +50,7 @@ struct ksock_hello_msg {
> __u32 kshm_ctype; /* connection type */
> __u32 kshm_nips; /* # IP addrs */
> __u32 kshm_ips[0]; /* IP addrs */
> -} WIRE_ATTR;
> +} __packed;
>
> struct ksock_lnet_msg {
> struct lnet_hdr ksnm_hdr; /* lnet hdr */
> @@ -61,7 +61,7 @@ struct ksock_lnet_msg {
> * structure definitions. lnet payload will be stored just after
> * the body of structure ksock_lnet_msg_t
> */
> -} WIRE_ATTR;
> +} __packed;
>
> struct ksock_msg {
> __u32 ksm_type; /* type of socklnd message */
> @@ -71,8 +71,8 @@ struct ksock_msg {
> struct ksock_lnet_msg lnetmsg; /* lnet message, it's empty if
> * it's NOOP
> */
> - } WIRE_ATTR ksm_u;
> -} WIRE_ATTR;
> + } __packed ksm_u;
> +} __packed;
>
> #define KSOCK_MSG_NOOP 0xC0 /* ksm_u empty */
> #define KSOCK_MSG_LNET 0xC1 /* lnet msg */
> diff --git a/drivers/staging/lustre/include/uapi/linux/lnet/lnet-types.h b/drivers/staging/lustre/include/uapi/linux/lnet/lnet-types.h
> index 1be9b7aa7326..f97e7d9d881f 100644
> --- a/drivers/staging/lustre/include/uapi/linux/lnet/lnet-types.h
> +++ b/drivers/staging/lustre/include/uapi/linux/lnet/lnet-types.h
> @@ -112,14 +112,12 @@ static inline __u32 LNET_MKNET(__u32 type, __u32 num)
> return (type << 16) | num;
> }
>
> -#define WIRE_ATTR __packed
> -
> /* Packed version of lnet_process_id to transfer via network */
> struct lnet_process_id_packed {
> /* node id / process id */
> lnet_nid_t nid;
> lnet_pid_t pid;
> -} WIRE_ATTR;
> +} __packed;
>
> /*
> * The wire handle's interface cookie only matches one network interface in
> @@ -130,7 +128,7 @@ struct lnet_process_id_packed {
> struct lnet_handle_wire {
> __u64 wh_interface_cookie;
> __u64 wh_object_cookie;
> -} WIRE_ATTR;
> +} __packed;
>
> enum lnet_msg_type {
> LNET_MSG_ACK = 0,
> @@ -150,7 +148,7 @@ struct lnet_ack {
> struct lnet_handle_wire dst_wmd;
> __u64 match_bits;
> __u32 mlength;
> -} WIRE_ATTR;
> +} __packed;
>
> struct lnet_put {
> struct lnet_handle_wire ack_wmd;
> @@ -158,7 +156,7 @@ struct lnet_put {
> __u64 hdr_data;
> __u32 ptl_index;
> __u32 offset;
> -} WIRE_ATTR;
> +} __packed;
>
> struct lnet_get {
> struct lnet_handle_wire return_wmd;
> @@ -166,16 +164,16 @@ struct lnet_get {
> __u32 ptl_index;
> __u32 src_offset;
> __u32 sink_length;
> -} WIRE_ATTR;
> +} __packed;
>
> struct lnet_reply {
> struct lnet_handle_wire dst_wmd;
> -} WIRE_ATTR;
> +} __packed;
>
> struct lnet_hello {
> __u64 incarnation;
> __u32 type;
> -} WIRE_ATTR;
> +} __packed;
>
> struct lnet_hdr {
> lnet_nid_t dest_nid;
> @@ -192,7 +190,7 @@ struct lnet_hdr {
> struct lnet_reply reply;
> struct lnet_hello hello;
> } msg;
> -} WIRE_ATTR;
> +} __packed;
>
> /*
> * A HELLO message contains a magic number and protocol version
> @@ -208,7 +206,7 @@ struct lnet_magicversion {
> __u32 magic; /* LNET_PROTO_TCP_MAGIC */
> __u16 version_major; /* increment on incompatible change */
> __u16 version_minor; /* increment on compatible change */
> -} WIRE_ATTR;
> +} __packed;
>
> /* PROTO MAGIC for LNDs */
> #define LNET_PROTO_IB_MAGIC 0x0be91b91
> @@ -232,7 +230,7 @@ struct lnet_acceptor_connreq {
> __u32 acr_magic; /* PTL_ACCEPTOR_PROTO_MAGIC */
> __u32 acr_version; /* protocol version */
> __u64 acr_nid; /* target NID */
> -} WIRE_ATTR;
> +} __packed;
>
> #define LNET_PROTO_ACCEPTOR_VERSION 1
>
> @@ -240,7 +238,7 @@ struct lnet_ni_status {
> lnet_nid_t ns_nid;
> __u32 ns_status;
> __u32 ns_unused;
> -} WIRE_ATTR;
> +} __packed;
>
> struct lnet_ping_info {
> __u32 pi_magic;
> @@ -248,7 +246,7 @@ struct lnet_ping_info {
> lnet_pid_t pi_pid;
> __u32 pi_nnis;
> struct lnet_ni_status pi_ni[0];
> -} WIRE_ATTR;
> +} __packed;
>
> struct lnet_counters {
> __u32 msgs_alloc;
> @@ -262,7 +260,7 @@ struct lnet_counters {
> __u64 recv_length;
> __u64 route_length;
> __u64 drop_length;
> -} WIRE_ATTR;
> +} __packed;
>
> #define LNET_NI_STATUS_UP 0x15aac0de
> #define LNET_NI_STATUS_DOWN 0xdeadface
> diff --git a/drivers/staging/lustre/include/uapi/linux/lnet/lnetst.h b/drivers/staging/lustre/include/uapi/linux/lnet/lnetst.h
> index a4f9ff01d458..7edba2c5bb87 100644
> --- a/drivers/staging/lustre/include/uapi/linux/lnet/lnetst.h
> +++ b/drivers/staging/lustre/include/uapi/linux/lnet/lnetst.h
> @@ -542,7 +542,7 @@ struct srpc_counters {
> __u32 rpcs_expired;
> __u64 bulk_get;
> __u64 bulk_put;
> -} WIRE_ATTR;
> +} __packed;
>
> struct sfw_counters {
> /** milliseconds since current session started */
> @@ -551,6 +551,6 @@ struct sfw_counters {
> __u32 zombie_sessions;
> __u32 brw_errors;
> __u32 ping_errors;
> -} WIRE_ATTR;
> +} __packed;
>
> #endif
> diff --git a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
> index 217503f125bc..7d8429672616 100644
> --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
> +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h
> @@ -359,45 +359,45 @@ struct kib_connparams {
> __u16 ibcp_queue_depth;
> __u16 ibcp_max_frags;
> __u32 ibcp_max_msg_size;
> -} WIRE_ATTR;
> +} __packed;
>
> struct kib_immediate_msg {
> struct lnet_hdr ibim_hdr; /* portals header */
> char ibim_payload[0]; /* piggy-backed payload */
> -} WIRE_ATTR;
> +} __packed;
>
> struct kib_rdma_frag {
> __u32 rf_nob; /* # bytes this frag */
> __u64 rf_addr; /* CAVEAT EMPTOR: misaligned!! */
> -} WIRE_ATTR;
> +} __packed;
>
> struct kib_rdma_desc {
> __u32 rd_key; /* local/remote key */
> __u32 rd_nfrags; /* # fragments */
> struct kib_rdma_frag rd_frags[0]; /* buffer frags */
> -} WIRE_ATTR;
> +} __packed;
>
> struct kib_putreq_msg {
> struct lnet_hdr ibprm_hdr; /* portals header */
> __u64 ibprm_cookie; /* opaque completion cookie */
> -} WIRE_ATTR;
> +} __packed;
>
> struct kib_putack_msg {
> __u64 ibpam_src_cookie; /* reflected completion cookie */
> __u64 ibpam_dst_cookie; /* opaque completion cookie */
> struct kib_rdma_desc ibpam_rd; /* sender's sink buffer */
> -} WIRE_ATTR;
> +} __packed;
>
> struct kib_get_msg {
> struct lnet_hdr ibgm_hdr; /* portals header */
> __u64 ibgm_cookie; /* opaque completion cookie */
> struct kib_rdma_desc ibgm_rd; /* rdma descriptor */
> -} WIRE_ATTR;
> +} __packed;
>
> struct kib_completion_msg {
> __u64 ibcm_cookie; /* opaque completion cookie */
> __s32 ibcm_status; /* < 0 failure: >= 0 length */
> -} WIRE_ATTR;
> +} __packed;
>
> struct kib_msg {
> /* First 2 fields fixed FOR ALL TIME */
> @@ -420,8 +420,8 @@ struct kib_msg {
> struct kib_putack_msg putack;
> struct kib_get_msg get;
> struct kib_completion_msg completion;
> - } WIRE_ATTR ibm_u;
> -} WIRE_ATTR;
> + } __packed ibm_u;
> +} __packed;
>
> #define IBLND_MSG_MAGIC LNET_PROTO_IB_MAGIC /* unique magic */
>
> @@ -447,7 +447,7 @@ struct kib_rej {
> __u8 ibr_padding; /* padding */
> __u64 ibr_incarnation; /* incarnation of peer */
> struct kib_connparams ibr_cp; /* connection parameters */
> -} WIRE_ATTR;
> +} __packed;
>
> /* connection rejection reasons */
> #define IBLND_REJECT_CONN_RACE 1 /* You lost connection race */
> diff --git a/drivers/staging/lustre/lnet/selftest/rpc.h b/drivers/staging/lustre/lnet/selftest/rpc.h
> index 465b5b534423..9ce336739449 100644
> --- a/drivers/staging/lustre/lnet/selftest/rpc.h
> +++ b/drivers/staging/lustre/lnet/selftest/rpc.h
> @@ -72,12 +72,12 @@ enum srpc_msg_type {
> struct srpc_generic_reqst {
> __u64 rpyid; /* reply buffer matchbits */
> __u64 bulkid; /* bulk buffer matchbits */
> -} WIRE_ATTR;
> +} __packed;
>
> struct srpc_generic_reply {
> __u32 status;
> struct lst_sid sid;
> -} WIRE_ATTR;
> +} __packed;
>
> /* FRAMEWORK RPCs */
> struct srpc_mksn_reqst {
> @@ -85,30 +85,30 @@ struct srpc_mksn_reqst {
> struct lst_sid mksn_sid; /* session id */
> __u32 mksn_force; /* use brute force */
> char mksn_name[LST_NAME_SIZE];
> -} WIRE_ATTR; /* make session request */
> +} __packed; /* make session request */
>
> struct srpc_mksn_reply {
> __u32 mksn_status; /* session status */
> struct lst_sid mksn_sid; /* session id */
> __u32 mksn_timeout; /* session timeout */
> char mksn_name[LST_NAME_SIZE];
> -} WIRE_ATTR; /* make session reply */
> +} __packed; /* make session reply */
>
> struct srpc_rmsn_reqst {
> __u64 rmsn_rpyid; /* reply buffer matchbits */
> struct lst_sid rmsn_sid; /* session id */
> -} WIRE_ATTR; /* remove session request */
> +} __packed; /* remove session request */
>
> struct srpc_rmsn_reply {
> __u32 rmsn_status;
> struct lst_sid rmsn_sid; /* session id */
> -} WIRE_ATTR; /* remove session reply */
> +} __packed; /* remove session reply */
>
> struct srpc_join_reqst {
> __u64 join_rpyid; /* reply buffer matchbits */
> struct lst_sid join_sid; /* session id to join */
> char join_group[LST_NAME_SIZE]; /* group name */
> -} WIRE_ATTR;
> +} __packed;
>
> struct srpc_join_reply {
> __u32 join_status; /* returned status */
> @@ -117,13 +117,13 @@ struct srpc_join_reply {
> * expire
> */
> char join_session[LST_NAME_SIZE]; /* session name */
> -} WIRE_ATTR;
> +} __packed;
>
> struct srpc_debug_reqst {
> __u64 dbg_rpyid; /* reply buffer matchbits */
> struct lst_sid dbg_sid; /* session id */
> __u32 dbg_flags; /* bitmap of debug */
> -} WIRE_ATTR;
> +} __packed;
>
> struct srpc_debug_reply {
> __u32 dbg_status; /* returned code */
> @@ -131,7 +131,7 @@ struct srpc_debug_reply {
> __u32 dbg_timeout; /* session timeout */
> __u32 dbg_nbatch; /* # of batches in the node */
> char dbg_name[LST_NAME_SIZE]; /* session name */
> -} WIRE_ATTR;
> +} __packed;
>
> #define SRPC_BATCH_OPC_RUN 1
> #define SRPC_BATCH_OPC_STOP 2
> @@ -144,20 +144,20 @@ struct srpc_batch_reqst {
> __u32 bar_opc; /* create/start/stop batch */
> __u32 bar_testidx; /* index of test */
> __u32 bar_arg; /* parameters */
> -} WIRE_ATTR;
> +} __packed;
>
> struct srpc_batch_reply {
> __u32 bar_status; /* status of request */
> struct lst_sid bar_sid; /* session id */
> __u32 bar_active; /* # of active tests in batch/test */
> __u32 bar_time; /* remained time */
> -} WIRE_ATTR;
> +} __packed;
>
> struct srpc_stat_reqst {
> __u64 str_rpyid; /* reply buffer matchbits */
> struct lst_sid str_sid; /* session id */
> __u32 str_type; /* type of stat */
> -} WIRE_ATTR;
> +} __packed;
>
> struct srpc_stat_reply {
> __u32 str_status;
> @@ -165,25 +165,25 @@ struct srpc_stat_reply {
> struct sfw_counters str_fw;
> struct srpc_counters str_rpc;
> struct lnet_counters str_lnet;
> -} WIRE_ATTR;
> +} __packed;
>
> struct test_bulk_req {
> __u32 blk_opc; /* bulk operation code */
> __u32 blk_npg; /* # of pages */
> __u32 blk_flags; /* reserved flags */
> -} WIRE_ATTR;
> +} __packed;
>
> struct test_bulk_req_v1 {
> __u16 blk_opc; /* bulk operation code */
> __u16 blk_flags; /* data check flags */
> __u32 blk_len; /* data length */
> __u32 blk_offset; /* offset */
> -} WIRE_ATTR;
> +} __packed;
>
> struct test_ping_req {
> __u32 png_size; /* size of ping message */
> __u32 png_flags; /* reserved flags */
> -} WIRE_ATTR;
> +} __packed;
>
> struct srpc_test_reqst {
> __u64 tsr_rpyid; /* reply buffer matchbits */
> @@ -204,12 +204,12 @@ struct srpc_test_reqst {
> struct test_bulk_req bulk_v0;
> struct test_bulk_req_v1 bulk_v1;
> } tsr_u;
> -} WIRE_ATTR;
> +} __packed;
>
> struct srpc_test_reply {
> __u32 tsr_status; /* returned code */
> struct lst_sid tsr_sid;
> -} WIRE_ATTR;
> +} __packed;
>
> /* TEST RPCs */
> struct srpc_ping_reqst {
> @@ -218,13 +218,13 @@ struct srpc_ping_reqst {
> __u32 pnr_seq;
> __u64 pnr_time_sec;
> __u64 pnr_time_usec;
> -} WIRE_ATTR;
> +} __packed;
>
> struct srpc_ping_reply {
> __u32 pnr_status;
> __u32 pnr_magic;
> __u32 pnr_seq;
> -} WIRE_ATTR;
> +} __packed;
>
> struct srpc_brw_reqst {
> __u64 brw_rpyid; /* reply buffer matchbits */
> @@ -232,11 +232,11 @@ struct srpc_brw_reqst {
> __u32 brw_rw; /* read or write */
> __u32 brw_len; /* bulk data len */
> __u32 brw_flags; /* bulk data patterns */
> -} WIRE_ATTR; /* bulk r/w request */
> +} __packed; /* bulk r/w request */
>
> struct srpc_brw_reply {
> __u32 brw_status;
> -} WIRE_ATTR; /* bulk r/w reply */
> +} __packed; /* bulk r/w reply */
>
> #define SRPC_MSG_MAGIC 0xeeb0f00d
> #define SRPC_MSG_VERSION 1
> @@ -272,7 +272,7 @@ struct srpc_msg {
> struct srpc_brw_reqst brw_reqst;
> struct srpc_brw_reply brw_reply;
> } msg_body;
> -} WIRE_ATTR;
> +} __packed;
>
> static inline void
> srpc_unpack_msg_hdr(struct srpc_msg *msg)
>
>
>

2018-06-14 02:41:15

by James Simmons

[permalink] [raw]
Subject: Re: [PATCH 08/11] staging: lustre: obdclass: move linux/linux-foo.c to foo.c


> As lustre is now linux-only, having this linux sub-directory
> with files named "linux-something" is just noise. Move them
> to a more friendly name.

Reviewed-by: James Simmons <[email protected]>

> Signed-off-by: NeilBrown <[email protected]>
> ---
> drivers/staging/lustre/lustre/obdclass/Makefile | 2
> .../lustre/lustre/obdclass/linux/linux-module.c | 514 --------------------
> .../lustre/lustre/obdclass/linux/linux-sysctl.c | 162 ------
> drivers/staging/lustre/lustre/obdclass/module.c | 514 ++++++++++++++++++++
> drivers/staging/lustre/lustre/obdclass/sysctl.c | 162 ++++++
> 5 files changed, 677 insertions(+), 677 deletions(-)
> delete mode 100644 drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
> delete mode 100644 drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
> create mode 100644 drivers/staging/lustre/lustre/obdclass/module.c
> create mode 100644 drivers/staging/lustre/lustre/obdclass/sysctl.c
>
> diff --git a/drivers/staging/lustre/lustre/obdclass/Makefile b/drivers/staging/lustre/lustre/obdclass/Makefile
> index e3fa9acff4c4..e36ba2167d10 100644
> --- a/drivers/staging/lustre/lustre/obdclass/Makefile
> +++ b/drivers/staging/lustre/lustre/obdclass/Makefile
> @@ -4,7 +4,7 @@ subdir-ccflags-y += -I$(srctree)/drivers/staging/lustre/lustre/include
>
> obj-$(CONFIG_LUSTRE_FS) += obdclass.o
>
> -obdclass-y := linux/linux-module.o linux/linux-sysctl.o \
> +obdclass-y := module.o sysctl.o \
> llog.o llog_cat.o llog_obd.o llog_swab.o class_obd.o debug.o \
> genops.o uuid.o lprocfs_status.o lprocfs_counters.o \
> lustre_handles.o lustre_peer.o statfs_pack.o linkea.o \
> diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
> deleted file mode 100644
> index 9c800580053b..000000000000
> --- a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
> +++ /dev/null
> @@ -1,514 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -/*
> - * GPL HEADER START
> - *
> - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License version 2 only,
> - * as published by the Free Software Foundation.
> - *
> - * This program is distributed in the hope that it will be useful, but
> - * WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> - * General Public License version 2 for more details (a copy is included
> - * in the LICENSE file that accompanied this code).
> - *
> - * You should have received a copy of the GNU General Public License
> - * version 2 along with this program; If not, see
> - * http://www.gnu.org/licenses/gpl-2.0.html
> - *
> - * GPL HEADER END
> - */
> -/*
> - * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
> - * Use is subject to license terms.
> - *
> - * Copyright (c) 2011, 2012, Intel Corporation.
> - */
> -/*
> - * This file is part of Lustre, http://www.lustre.org/
> - * Lustre is a trademark of Sun Microsystems, Inc.
> - *
> - * lustre/obdclass/linux/linux-module.c
> - *
> - * Object Devices Class Driver
> - * These are the only exported functions, they provide some generic
> - * infrastructure for managing object devices
> - */
> -
> -#define DEBUG_SUBSYSTEM S_CLASS
> -
> -#include <linux/module.h>
> -#include <linux/errno.h>
> -#include <linux/kernel.h>
> -#include <linux/sched.h>
> -#include <linux/lp.h>
> -#include <linux/slab.h>
> -#include <linux/ioport.h>
> -#include <linux/fcntl.h>
> -#include <linux/delay.h>
> -#include <linux/skbuff.h>
> -#include <linux/fs.h>
> -#include <linux/poll.h>
> -#include <linux/list.h>
> -#include <linux/highmem.h>
> -#include <linux/io.h>
> -#include <asm/ioctls.h>
> -#include <linux/uaccess.h>
> -#include <linux/miscdevice.h>
> -#include <linux/seq_file.h>
> -#include <linux/kobject.h>
> -
> -#include <uapi/linux/lnet/lnetctl.h>
> -#include <obd_support.h>
> -#include <obd_class.h>
> -#include <lprocfs_status.h>
> -#include <uapi/linux/lustre/lustre_ioctl.h>
> -#include <uapi/linux/lustre/lustre_ver.h>
> -
> -#define OBD_MAX_IOCTL_BUFFER 8192
> -
> -static int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
> -{
> - if (data->ioc_len > BIT(30)) {
> - CERROR("OBD ioctl: ioc_len larger than 1<<30\n");
> - return 1;
> - }
> -
> - if (data->ioc_inllen1 > BIT(30)) {
> - CERROR("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
> - return 1;
> - }
> -
> - if (data->ioc_inllen2 > BIT(30)) {
> - CERROR("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
> - return 1;
> - }
> -
> - if (data->ioc_inllen3 > BIT(30)) {
> - CERROR("OBD ioctl: ioc_inllen3 larger than 1<<30\n");
> - return 1;
> - }
> -
> - if (data->ioc_inllen4 > BIT(30)) {
> - CERROR("OBD ioctl: ioc_inllen4 larger than 1<<30\n");
> - return 1;
> - }
> -
> - if (data->ioc_inlbuf1 && data->ioc_inllen1 == 0) {
> - CERROR("OBD ioctl: inlbuf1 pointer but 0 length\n");
> - return 1;
> - }
> -
> - if (data->ioc_inlbuf2 && data->ioc_inllen2 == 0) {
> - CERROR("OBD ioctl: inlbuf2 pointer but 0 length\n");
> - return 1;
> - }
> -
> - if (data->ioc_inlbuf3 && data->ioc_inllen3 == 0) {
> - CERROR("OBD ioctl: inlbuf3 pointer but 0 length\n");
> - return 1;
> - }
> -
> - if (data->ioc_inlbuf4 && data->ioc_inllen4 == 0) {
> - CERROR("OBD ioctl: inlbuf4 pointer but 0 length\n");
> - return 1;
> - }
> -
> - if (data->ioc_pbuf1 && data->ioc_plen1 == 0) {
> - CERROR("OBD ioctl: pbuf1 pointer but 0 length\n");
> - return 1;
> - }
> -
> - if (data->ioc_pbuf2 && data->ioc_plen2 == 0) {
> - CERROR("OBD ioctl: pbuf2 pointer but 0 length\n");
> - return 1;
> - }
> -
> - if (!data->ioc_pbuf1 && data->ioc_plen1 != 0) {
> - CERROR("OBD ioctl: plen1 set but NULL pointer\n");
> - return 1;
> - }
> -
> - if (!data->ioc_pbuf2 && data->ioc_plen2 != 0) {
> - CERROR("OBD ioctl: plen2 set but NULL pointer\n");
> - return 1;
> - }
> -
> - if (obd_ioctl_packlen(data) > data->ioc_len) {
> - CERROR("OBD ioctl: packlen exceeds ioc_len (%d > %d)\n",
> - obd_ioctl_packlen(data), data->ioc_len);
> - return 1;
> - }
> -
> - return 0;
> -}
> -
> -/* buffer MUST be at least the size of obd_ioctl_hdr */
> -int obd_ioctl_getdata(char **buf, int *len, void __user *arg)
> -{
> - struct obd_ioctl_hdr hdr;
> - struct obd_ioctl_data *data;
> - int err;
> - int offset = 0;
> -
> - if (copy_from_user(&hdr, arg, sizeof(hdr)))
> - return -EFAULT;
> -
> - if (hdr.ioc_version != OBD_IOCTL_VERSION) {
> - CERROR("Version mismatch kernel (%x) vs application (%x)\n",
> - OBD_IOCTL_VERSION, hdr.ioc_version);
> - return -EINVAL;
> - }
> -
> - if (hdr.ioc_len > OBD_MAX_IOCTL_BUFFER) {
> - CERROR("User buffer len %d exceeds %d max buffer\n",
> - hdr.ioc_len, OBD_MAX_IOCTL_BUFFER);
> - return -EINVAL;
> - }
> -
> - if (hdr.ioc_len < sizeof(struct obd_ioctl_data)) {
> - CERROR("User buffer too small for ioctl (%d)\n", hdr.ioc_len);
> - return -EINVAL;
> - }
> -
> - /* When there are lots of processes calling vmalloc on multi-core
> - * system, the high lock contention will hurt performance badly,
> - * obdfilter-survey is an example, which relies on ioctl. So we'd
> - * better avoid vmalloc on ioctl path. LU-66
> - */
> - *buf = kvzalloc(hdr.ioc_len, GFP_KERNEL);
> - if (!*buf) {
> - CERROR("Cannot allocate control buffer of len %d\n",
> - hdr.ioc_len);
> - return -EINVAL;
> - }
> - *len = hdr.ioc_len;
> - data = (struct obd_ioctl_data *)*buf;
> -
> - if (copy_from_user(*buf, arg, hdr.ioc_len)) {
> - err = -EFAULT;
> - goto free_buf;
> - }
> - if (hdr.ioc_len != data->ioc_len) {
> - err = -EINVAL;
> - goto free_buf;
> - }
> -
> - if (obd_ioctl_is_invalid(data)) {
> - CERROR("ioctl not correctly formatted\n");
> - err = -EINVAL;
> - goto free_buf;
> - }
> -
> - if (data->ioc_inllen1) {
> - data->ioc_inlbuf1 = &data->ioc_bulk[0];
> - offset += cfs_size_round(data->ioc_inllen1);
> - }
> -
> - if (data->ioc_inllen2) {
> - data->ioc_inlbuf2 = &data->ioc_bulk[0] + offset;
> - offset += cfs_size_round(data->ioc_inllen2);
> - }
> -
> - if (data->ioc_inllen3) {
> - data->ioc_inlbuf3 = &data->ioc_bulk[0] + offset;
> - offset += cfs_size_round(data->ioc_inllen3);
> - }
> -
> - if (data->ioc_inllen4)
> - data->ioc_inlbuf4 = &data->ioc_bulk[0] + offset;
> -
> - return 0;
> -
> -free_buf:
> - kvfree(*buf);
> - return err;
> -}
> -EXPORT_SYMBOL(obd_ioctl_getdata);
> -
> -/* opening /dev/obd */
> -static int obd_class_open(struct inode *inode, struct file *file)
> -{
> - try_module_get(THIS_MODULE);
> - return 0;
> -}
> -
> -/* closing /dev/obd */
> -static int obd_class_release(struct inode *inode, struct file *file)
> -{
> - module_put(THIS_MODULE);
> - return 0;
> -}
> -
> -/* to control /dev/obd */
> -static long obd_class_ioctl(struct file *filp, unsigned int cmd,
> - unsigned long arg)
> -{
> - int err = 0;
> -
> - /* Allow non-root access for OBD_IOC_PING_TARGET - used by lfs check */
> - if (!capable(CAP_SYS_ADMIN) && (cmd != OBD_IOC_PING_TARGET))
> - return err = -EACCES;
> - if ((cmd & 0xffffff00) == ((int)'T') << 8) /* ignore all tty ioctls */
> - return err = -ENOTTY;
> -
> - err = class_handle_ioctl(cmd, (unsigned long)arg);
> -
> - return err;
> -}
> -
> -/* declare character device */
> -static const struct file_operations obd_psdev_fops = {
> - .owner = THIS_MODULE,
> - .unlocked_ioctl = obd_class_ioctl, /* unlocked_ioctl */
> - .open = obd_class_open, /* open */
> - .release = obd_class_release, /* release */
> -};
> -
> -/* modules setup */
> -struct miscdevice obd_psdev = {
> - .minor = MISC_DYNAMIC_MINOR,
> - .name = OBD_DEV_NAME,
> - .fops = &obd_psdev_fops,
> -};
> -
> -static ssize_t version_show(struct kobject *kobj, struct attribute *attr,
> - char *buf)
> -{
> - return sprintf(buf, "%s\n", LUSTRE_VERSION_STRING);
> -}
> -
> -static ssize_t pinger_show(struct kobject *kobj, struct attribute *attr,
> - char *buf)
> -{
> - return sprintf(buf, "%s\n", "on");
> -}
> -
> -static ssize_t
> -health_check_show(struct kobject *kobj, struct attribute *attr, char *buf)
> -{
> - bool healthy = true;
> - int i;
> - size_t len = 0;
> -
> - if (libcfs_catastrophe)
> - return sprintf(buf, "LBUG\n");
> -
> - read_lock(&obd_dev_lock);
> - for (i = 0; i < class_devno_max(); i++) {
> - struct obd_device *obd;
> -
> - obd = class_num2obd(i);
> - if (!obd || !obd->obd_attached || !obd->obd_set_up)
> - continue;
> -
> - LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
> - if (obd->obd_stopping)
> - continue;
> -
> - class_incref(obd, __func__, current);
> - read_unlock(&obd_dev_lock);
> -
> - if (obd_health_check(NULL, obd))
> - healthy = false;
> - class_decref(obd, __func__, current);
> - read_lock(&obd_dev_lock);
> - }
> - read_unlock(&obd_dev_lock);
> -
> - if (healthy)
> - len = sprintf(buf, "healthy\n");
> - else
> - len = sprintf(buf, "NOT HEALTHY\n");
> -
> - return len;
> -}
> -
> -static ssize_t jobid_var_show(struct kobject *kobj, struct attribute *attr,
> - char *buf)
> -{
> - return snprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_var);
> -}
> -
> -static ssize_t jobid_var_store(struct kobject *kobj, struct attribute *attr,
> - const char *buffer,
> - size_t count)
> -{
> - if (!count || count > JOBSTATS_JOBID_VAR_MAX_LEN)
> - return -EINVAL;
> -
> - memset(obd_jobid_var, 0, JOBSTATS_JOBID_VAR_MAX_LEN + 1);
> -
> - memcpy(obd_jobid_var, buffer, count);
> -
> - /* Trim the trailing '\n' if any */
> - if (obd_jobid_var[count - 1] == '\n')
> - obd_jobid_var[count - 1] = 0;
> -
> - return count;
> -}
> -
> -static ssize_t jobid_name_show(struct kobject *kobj, struct attribute *attr,
> - char *buf)
> -{
> - return snprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_node);
> -}
> -
> -static ssize_t jobid_name_store(struct kobject *kobj, struct attribute *attr,
> - const char *buffer,
> - size_t count)
> -{
> - if (!count || count > LUSTRE_JOBID_SIZE)
> - return -EINVAL;
> -
> - memcpy(obd_jobid_node, buffer, count);
> -
> - obd_jobid_node[count] = 0;
> -
> - /* Trim the trailing '\n' if any */
> - if (obd_jobid_node[count - 1] == '\n')
> - obd_jobid_node[count - 1] = 0;
> -
> - return count;
> -}
> -
> -/* Root for /sys/kernel/debug/lustre */
> -struct dentry *debugfs_lustre_root;
> -EXPORT_SYMBOL_GPL(debugfs_lustre_root);
> -
> -LUSTRE_RO_ATTR(version);
> -LUSTRE_RO_ATTR(pinger);
> -LUSTRE_RO_ATTR(health_check);
> -LUSTRE_RW_ATTR(jobid_var);
> -LUSTRE_RW_ATTR(jobid_name);
> -
> -static struct attribute *lustre_attrs[] = {
> - &lustre_attr_version.attr,
> - &lustre_attr_pinger.attr,
> - &lustre_attr_health_check.attr,
> - &lustre_attr_jobid_name.attr,
> - &lustre_attr_jobid_var.attr,
> - NULL,
> -};
> -
> -static void *obd_device_list_seq_start(struct seq_file *p, loff_t *pos)
> -{
> - if (*pos >= class_devno_max())
> - return NULL;
> -
> - return pos;
> -}
> -
> -static void obd_device_list_seq_stop(struct seq_file *p, void *v)
> -{
> -}
> -
> -static void *obd_device_list_seq_next(struct seq_file *p, void *v, loff_t *pos)
> -{
> - ++*pos;
> - if (*pos >= class_devno_max())
> - return NULL;
> -
> - return pos;
> -}
> -
> -static int obd_device_list_seq_show(struct seq_file *p, void *v)
> -{
> - loff_t index = *(loff_t *)v;
> - struct obd_device *obd = class_num2obd((int)index);
> - char *status;
> -
> - if (!obd)
> - return 0;
> -
> - LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
> - if (obd->obd_stopping)
> - status = "ST";
> - else if (obd->obd_inactive)
> - status = "IN";
> - else if (obd->obd_set_up)
> - status = "UP";
> - else if (obd->obd_attached)
> - status = "AT";
> - else
> - status = "--";
> -
> - seq_printf(p, "%3d %s %s %s %s %d\n",
> - (int)index, status, obd->obd_type->typ_name,
> - obd->obd_name, obd->obd_uuid.uuid,
> - atomic_read(&obd->obd_refcount));
> - return 0;
> -}
> -
> -static const struct seq_operations obd_device_list_sops = {
> - .start = obd_device_list_seq_start,
> - .stop = obd_device_list_seq_stop,
> - .next = obd_device_list_seq_next,
> - .show = obd_device_list_seq_show,
> -};
> -
> -static int obd_device_list_open(struct inode *inode, struct file *file)
> -{
> - struct seq_file *seq;
> - int rc = seq_open(file, &obd_device_list_sops);
> -
> - if (rc)
> - return rc;
> -
> - seq = file->private_data;
> - seq->private = inode->i_private;
> -
> - return 0;
> -}
> -
> -static const struct file_operations obd_device_list_fops = {
> - .owner = THIS_MODULE,
> - .open = obd_device_list_open,
> - .read = seq_read,
> - .llseek = seq_lseek,
> - .release = seq_release,
> -};
> -
> -struct kobject *lustre_kobj;
> -EXPORT_SYMBOL_GPL(lustre_kobj);
> -
> -static const struct attribute_group lustre_attr_group = {
> - .attrs = lustre_attrs,
> -};
> -
> -int class_procfs_init(void)
> -{
> - int rc = -ENOMEM;
> -
> - lustre_kobj = kobject_create_and_add("lustre", fs_kobj);
> - if (!lustre_kobj)
> - goto out;
> -
> - /* Create the files associated with this kobject */
> - rc = sysfs_create_group(lustre_kobj, &lustre_attr_group);
> - if (rc) {
> - kobject_put(lustre_kobj);
> - goto out;
> - }
> -
> - debugfs_lustre_root = debugfs_create_dir("lustre", NULL);
> -
> - debugfs_create_file("devices", 0444, debugfs_lustre_root, NULL,
> - &obd_device_list_fops);
> -out:
> - return rc;
> -}
> -
> -int class_procfs_clean(void)
> -{
> - debugfs_remove_recursive(debugfs_lustre_root);
> -
> - debugfs_lustre_root = NULL;
> -
> - sysfs_remove_group(lustre_kobj, &lustre_attr_group);
> - kobject_put(lustre_kobj);
> -
> - return 0;
> -}
> diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
> deleted file mode 100644
> index e5e8687784ee..000000000000
> --- a/drivers/staging/lustre/lustre/obdclass/linux/linux-sysctl.c
> +++ /dev/null
> @@ -1,162 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -/*
> - * GPL HEADER START
> - *
> - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
> - *
> - * This program is free software; you can redistribute it and/or modify
> - * it under the terms of the GNU General Public License version 2 only,
> - * as published by the Free Software Foundation.
> - *
> - * This program is distributed in the hope that it will be useful, but
> - * WITHOUT ANY WARRANTY; without even the implied warranty of
> - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> - * General Public License version 2 for more details (a copy is included
> - * in the LICENSE file that accompanied this code).
> - *
> - * You should have received a copy of the GNU General Public License
> - * version 2 along with this program; If not, see
> - * http://www.gnu.org/licenses/gpl-2.0.html
> - *
> - * GPL HEADER END
> - */
> -/*
> - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
> - * Use is subject to license terms.
> - *
> - * Copyright (c) 2011, 2015, Intel Corporation.
> - */
> -/*
> - * This file is part of Lustre, http://www.lustre.org/
> - * Lustre is a trademark of Sun Microsystems, Inc.
> - */
> -
> -#include <linux/module.h>
> -#include <linux/sysctl.h>
> -#include <linux/sched.h>
> -#include <linux/mm.h>
> -#include <linux/slab.h>
> -#include <linux/stat.h>
> -#include <linux/ctype.h>
> -#include <linux/bitops.h>
> -#include <linux/uaccess.h>
> -#include <linux/utsname.h>
> -
> -#define DEBUG_SUBSYSTEM S_CLASS
> -
> -#include <obd_support.h>
> -#include <lprocfs_status.h>
> -#include <obd_class.h>
> -
> -struct static_lustre_uintvalue_attr {
> - struct {
> - struct attribute attr;
> - ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
> - char *buf);
> - ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
> - const char *buf, size_t len);
> - } u;
> - int *value;
> -};
> -
> -static ssize_t static_uintvalue_show(struct kobject *kobj,
> - struct attribute *attr,
> - char *buf)
> -{
> - struct static_lustre_uintvalue_attr *lattr = (void *)attr;
> -
> - return sprintf(buf, "%d\n", *lattr->value);
> -}
> -
> -static ssize_t static_uintvalue_store(struct kobject *kobj,
> - struct attribute *attr,
> - const char *buffer, size_t count)
> -{
> - struct static_lustre_uintvalue_attr *lattr = (void *)attr;
> - int rc;
> - unsigned int val;
> -
> - rc = kstrtouint(buffer, 10, &val);
> - if (rc)
> - return rc;
> -
> - *lattr->value = val;
> -
> - return count;
> -}
> -
> -#define LUSTRE_STATIC_UINT_ATTR(name, value) \
> -static struct static_lustre_uintvalue_attr lustre_sattr_##name = \
> - {__ATTR(name, 0644, \
> - static_uintvalue_show, \
> - static_uintvalue_store),\
> - value }
> -
> -LUSTRE_STATIC_UINT_ATTR(timeout, &obd_timeout);
> -
> -static ssize_t max_dirty_mb_show(struct kobject *kobj, struct attribute *attr,
> - char *buf)
> -{
> - return sprintf(buf, "%lu\n",
> - obd_max_dirty_pages / (1 << (20 - PAGE_SHIFT)));
> -}
> -
> -static ssize_t max_dirty_mb_store(struct kobject *kobj, struct attribute *attr,
> - const char *buffer, size_t count)
> -{
> - int rc;
> - unsigned long val;
> -
> - rc = kstrtoul(buffer, 10, &val);
> - if (rc)
> - return rc;
> -
> - val *= 1 << (20 - PAGE_SHIFT); /* convert to pages */
> -
> - if (val > ((totalram_pages / 10) * 9)) {
> - /* Somebody wants to assign too much memory to dirty pages */
> - return -EINVAL;
> - }
> -
> - if (val < 4 << (20 - PAGE_SHIFT)) {
> - /* Less than 4 Mb for dirty cache is also bad */
> - return -EINVAL;
> - }
> -
> - obd_max_dirty_pages = val;
> -
> - return count;
> -}
> -LUSTRE_RW_ATTR(max_dirty_mb);
> -
> -LUSTRE_STATIC_UINT_ATTR(debug_peer_on_timeout, &obd_debug_peer_on_timeout);
> -LUSTRE_STATIC_UINT_ATTR(dump_on_timeout, &obd_dump_on_timeout);
> -LUSTRE_STATIC_UINT_ATTR(dump_on_eviction, &obd_dump_on_eviction);
> -LUSTRE_STATIC_UINT_ATTR(at_min, &at_min);
> -LUSTRE_STATIC_UINT_ATTR(at_max, &at_max);
> -LUSTRE_STATIC_UINT_ATTR(at_extra, &at_extra);
> -LUSTRE_STATIC_UINT_ATTR(at_early_margin, &at_early_margin);
> -LUSTRE_STATIC_UINT_ATTR(at_history, &at_history);
> -
> -static struct attribute *lustre_attrs[] = {
> - &lustre_sattr_timeout.u.attr,
> - &lustre_attr_max_dirty_mb.attr,
> - &lustre_sattr_debug_peer_on_timeout.u.attr,
> - &lustre_sattr_dump_on_timeout.u.attr,
> - &lustre_sattr_dump_on_eviction.u.attr,
> - &lustre_sattr_at_min.u.attr,
> - &lustre_sattr_at_max.u.attr,
> - &lustre_sattr_at_extra.u.attr,
> - &lustre_sattr_at_early_margin.u.attr,
> - &lustre_sattr_at_history.u.attr,
> - NULL,
> -};
> -
> -static const struct attribute_group lustre_attr_group = {
> - .attrs = lustre_attrs,
> -};
> -
> -int obd_sysctl_init(void)
> -{
> - return sysfs_create_group(lustre_kobj, &lustre_attr_group);
> -}
> diff --git a/drivers/staging/lustre/lustre/obdclass/module.c b/drivers/staging/lustre/lustre/obdclass/module.c
> new file mode 100644
> index 000000000000..9c800580053b
> --- /dev/null
> +++ b/drivers/staging/lustre/lustre/obdclass/module.c
> @@ -0,0 +1,514 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * GPL HEADER START
> + *
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 only,
> + * as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * General Public License version 2 for more details (a copy is included
> + * in the LICENSE file that accompanied this code).
> + *
> + * You should have received a copy of the GNU General Public License
> + * version 2 along with this program; If not, see
> + * http://www.gnu.org/licenses/gpl-2.0.html
> + *
> + * GPL HEADER END
> + */
> +/*
> + * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
> + * Use is subject to license terms.
> + *
> + * Copyright (c) 2011, 2012, Intel Corporation.
> + */
> +/*
> + * This file is part of Lustre, http://www.lustre.org/
> + * Lustre is a trademark of Sun Microsystems, Inc.
> + *
> + * lustre/obdclass/linux/linux-module.c
> + *
> + * Object Devices Class Driver
> + * These are the only exported functions, they provide some generic
> + * infrastructure for managing object devices
> + */
> +
> +#define DEBUG_SUBSYSTEM S_CLASS
> +
> +#include <linux/module.h>
> +#include <linux/errno.h>
> +#include <linux/kernel.h>
> +#include <linux/sched.h>
> +#include <linux/lp.h>
> +#include <linux/slab.h>
> +#include <linux/ioport.h>
> +#include <linux/fcntl.h>
> +#include <linux/delay.h>
> +#include <linux/skbuff.h>
> +#include <linux/fs.h>
> +#include <linux/poll.h>
> +#include <linux/list.h>
> +#include <linux/highmem.h>
> +#include <linux/io.h>
> +#include <asm/ioctls.h>
> +#include <linux/uaccess.h>
> +#include <linux/miscdevice.h>
> +#include <linux/seq_file.h>
> +#include <linux/kobject.h>
> +
> +#include <uapi/linux/lnet/lnetctl.h>
> +#include <obd_support.h>
> +#include <obd_class.h>
> +#include <lprocfs_status.h>
> +#include <uapi/linux/lustre/lustre_ioctl.h>
> +#include <uapi/linux/lustre/lustre_ver.h>
> +
> +#define OBD_MAX_IOCTL_BUFFER 8192
> +
> +static int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
> +{
> + if (data->ioc_len > BIT(30)) {
> + CERROR("OBD ioctl: ioc_len larger than 1<<30\n");
> + return 1;
> + }
> +
> + if (data->ioc_inllen1 > BIT(30)) {
> + CERROR("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
> + return 1;
> + }
> +
> + if (data->ioc_inllen2 > BIT(30)) {
> + CERROR("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
> + return 1;
> + }
> +
> + if (data->ioc_inllen3 > BIT(30)) {
> + CERROR("OBD ioctl: ioc_inllen3 larger than 1<<30\n");
> + return 1;
> + }
> +
> + if (data->ioc_inllen4 > BIT(30)) {
> + CERROR("OBD ioctl: ioc_inllen4 larger than 1<<30\n");
> + return 1;
> + }
> +
> + if (data->ioc_inlbuf1 && data->ioc_inllen1 == 0) {
> + CERROR("OBD ioctl: inlbuf1 pointer but 0 length\n");
> + return 1;
> + }
> +
> + if (data->ioc_inlbuf2 && data->ioc_inllen2 == 0) {
> + CERROR("OBD ioctl: inlbuf2 pointer but 0 length\n");
> + return 1;
> + }
> +
> + if (data->ioc_inlbuf3 && data->ioc_inllen3 == 0) {
> + CERROR("OBD ioctl: inlbuf3 pointer but 0 length\n");
> + return 1;
> + }
> +
> + if (data->ioc_inlbuf4 && data->ioc_inllen4 == 0) {
> + CERROR("OBD ioctl: inlbuf4 pointer but 0 length\n");
> + return 1;
> + }
> +
> + if (data->ioc_pbuf1 && data->ioc_plen1 == 0) {
> + CERROR("OBD ioctl: pbuf1 pointer but 0 length\n");
> + return 1;
> + }
> +
> + if (data->ioc_pbuf2 && data->ioc_plen2 == 0) {
> + CERROR("OBD ioctl: pbuf2 pointer but 0 length\n");
> + return 1;
> + }
> +
> + if (!data->ioc_pbuf1 && data->ioc_plen1 != 0) {
> + CERROR("OBD ioctl: plen1 set but NULL pointer\n");
> + return 1;
> + }
> +
> + if (!data->ioc_pbuf2 && data->ioc_plen2 != 0) {
> + CERROR("OBD ioctl: plen2 set but NULL pointer\n");
> + return 1;
> + }
> +
> + if (obd_ioctl_packlen(data) > data->ioc_len) {
> + CERROR("OBD ioctl: packlen exceeds ioc_len (%d > %d)\n",
> + obd_ioctl_packlen(data), data->ioc_len);
> + return 1;
> + }
> +
> + return 0;
> +}
> +
> +/* buffer MUST be at least the size of obd_ioctl_hdr */
> +int obd_ioctl_getdata(char **buf, int *len, void __user *arg)
> +{
> + struct obd_ioctl_hdr hdr;
> + struct obd_ioctl_data *data;
> + int err;
> + int offset = 0;
> +
> + if (copy_from_user(&hdr, arg, sizeof(hdr)))
> + return -EFAULT;
> +
> + if (hdr.ioc_version != OBD_IOCTL_VERSION) {
> + CERROR("Version mismatch kernel (%x) vs application (%x)\n",
> + OBD_IOCTL_VERSION, hdr.ioc_version);
> + return -EINVAL;
> + }
> +
> + if (hdr.ioc_len > OBD_MAX_IOCTL_BUFFER) {
> + CERROR("User buffer len %d exceeds %d max buffer\n",
> + hdr.ioc_len, OBD_MAX_IOCTL_BUFFER);
> + return -EINVAL;
> + }
> +
> + if (hdr.ioc_len < sizeof(struct obd_ioctl_data)) {
> + CERROR("User buffer too small for ioctl (%d)\n", hdr.ioc_len);
> + return -EINVAL;
> + }
> +
> + /* When there are lots of processes calling vmalloc on multi-core
> + * system, the high lock contention will hurt performance badly,
> + * obdfilter-survey is an example, which relies on ioctl. So we'd
> + * better avoid vmalloc on ioctl path. LU-66
> + */
> + *buf = kvzalloc(hdr.ioc_len, GFP_KERNEL);
> + if (!*buf) {
> + CERROR("Cannot allocate control buffer of len %d\n",
> + hdr.ioc_len);
> + return -EINVAL;
> + }
> + *len = hdr.ioc_len;
> + data = (struct obd_ioctl_data *)*buf;
> +
> + if (copy_from_user(*buf, arg, hdr.ioc_len)) {
> + err = -EFAULT;
> + goto free_buf;
> + }
> + if (hdr.ioc_len != data->ioc_len) {
> + err = -EINVAL;
> + goto free_buf;
> + }
> +
> + if (obd_ioctl_is_invalid(data)) {
> + CERROR("ioctl not correctly formatted\n");
> + err = -EINVAL;
> + goto free_buf;
> + }
> +
> + if (data->ioc_inllen1) {
> + data->ioc_inlbuf1 = &data->ioc_bulk[0];
> + offset += cfs_size_round(data->ioc_inllen1);
> + }
> +
> + if (data->ioc_inllen2) {
> + data->ioc_inlbuf2 = &data->ioc_bulk[0] + offset;
> + offset += cfs_size_round(data->ioc_inllen2);
> + }
> +
> + if (data->ioc_inllen3) {
> + data->ioc_inlbuf3 = &data->ioc_bulk[0] + offset;
> + offset += cfs_size_round(data->ioc_inllen3);
> + }
> +
> + if (data->ioc_inllen4)
> + data->ioc_inlbuf4 = &data->ioc_bulk[0] + offset;
> +
> + return 0;
> +
> +free_buf:
> + kvfree(*buf);
> + return err;
> +}
> +EXPORT_SYMBOL(obd_ioctl_getdata);
> +
> +/* opening /dev/obd */
> +static int obd_class_open(struct inode *inode, struct file *file)
> +{
> + try_module_get(THIS_MODULE);
> + return 0;
> +}
> +
> +/* closing /dev/obd */
> +static int obd_class_release(struct inode *inode, struct file *file)
> +{
> + module_put(THIS_MODULE);
> + return 0;
> +}
> +
> +/* to control /dev/obd */
> +static long obd_class_ioctl(struct file *filp, unsigned int cmd,
> + unsigned long arg)
> +{
> + int err = 0;
> +
> + /* Allow non-root access for OBD_IOC_PING_TARGET - used by lfs check */
> + if (!capable(CAP_SYS_ADMIN) && (cmd != OBD_IOC_PING_TARGET))
> + return err = -EACCES;
> + if ((cmd & 0xffffff00) == ((int)'T') << 8) /* ignore all tty ioctls */
> + return err = -ENOTTY;
> +
> + err = class_handle_ioctl(cmd, (unsigned long)arg);
> +
> + return err;
> +}
> +
> +/* declare character device */
> +static const struct file_operations obd_psdev_fops = {
> + .owner = THIS_MODULE,
> + .unlocked_ioctl = obd_class_ioctl, /* unlocked_ioctl */
> + .open = obd_class_open, /* open */
> + .release = obd_class_release, /* release */
> +};
> +
> +/* modules setup */
> +struct miscdevice obd_psdev = {
> + .minor = MISC_DYNAMIC_MINOR,
> + .name = OBD_DEV_NAME,
> + .fops = &obd_psdev_fops,
> +};
> +
> +static ssize_t version_show(struct kobject *kobj, struct attribute *attr,
> + char *buf)
> +{
> + return sprintf(buf, "%s\n", LUSTRE_VERSION_STRING);
> +}
> +
> +static ssize_t pinger_show(struct kobject *kobj, struct attribute *attr,
> + char *buf)
> +{
> + return sprintf(buf, "%s\n", "on");
> +}
> +
> +static ssize_t
> +health_check_show(struct kobject *kobj, struct attribute *attr, char *buf)
> +{
> + bool healthy = true;
> + int i;
> + size_t len = 0;
> +
> + if (libcfs_catastrophe)
> + return sprintf(buf, "LBUG\n");
> +
> + read_lock(&obd_dev_lock);
> + for (i = 0; i < class_devno_max(); i++) {
> + struct obd_device *obd;
> +
> + obd = class_num2obd(i);
> + if (!obd || !obd->obd_attached || !obd->obd_set_up)
> + continue;
> +
> + LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
> + if (obd->obd_stopping)
> + continue;
> +
> + class_incref(obd, __func__, current);
> + read_unlock(&obd_dev_lock);
> +
> + if (obd_health_check(NULL, obd))
> + healthy = false;
> + class_decref(obd, __func__, current);
> + read_lock(&obd_dev_lock);
> + }
> + read_unlock(&obd_dev_lock);
> +
> + if (healthy)
> + len = sprintf(buf, "healthy\n");
> + else
> + len = sprintf(buf, "NOT HEALTHY\n");
> +
> + return len;
> +}
> +
> +static ssize_t jobid_var_show(struct kobject *kobj, struct attribute *attr,
> + char *buf)
> +{
> + return snprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_var);
> +}
> +
> +static ssize_t jobid_var_store(struct kobject *kobj, struct attribute *attr,
> + const char *buffer,
> + size_t count)
> +{
> + if (!count || count > JOBSTATS_JOBID_VAR_MAX_LEN)
> + return -EINVAL;
> +
> + memset(obd_jobid_var, 0, JOBSTATS_JOBID_VAR_MAX_LEN + 1);
> +
> + memcpy(obd_jobid_var, buffer, count);
> +
> + /* Trim the trailing '\n' if any */
> + if (obd_jobid_var[count - 1] == '\n')
> + obd_jobid_var[count - 1] = 0;
> +
> + return count;
> +}
> +
> +static ssize_t jobid_name_show(struct kobject *kobj, struct attribute *attr,
> + char *buf)
> +{
> + return snprintf(buf, PAGE_SIZE, "%s\n", obd_jobid_node);
> +}
> +
> +static ssize_t jobid_name_store(struct kobject *kobj, struct attribute *attr,
> + const char *buffer,
> + size_t count)
> +{
> + if (!count || count > LUSTRE_JOBID_SIZE)
> + return -EINVAL;
> +
> + memcpy(obd_jobid_node, buffer, count);
> +
> + obd_jobid_node[count] = 0;
> +
> + /* Trim the trailing '\n' if any */
> + if (obd_jobid_node[count - 1] == '\n')
> + obd_jobid_node[count - 1] = 0;
> +
> + return count;
> +}
> +
> +/* Root for /sys/kernel/debug/lustre */
> +struct dentry *debugfs_lustre_root;
> +EXPORT_SYMBOL_GPL(debugfs_lustre_root);
> +
> +LUSTRE_RO_ATTR(version);
> +LUSTRE_RO_ATTR(pinger);
> +LUSTRE_RO_ATTR(health_check);
> +LUSTRE_RW_ATTR(jobid_var);
> +LUSTRE_RW_ATTR(jobid_name);
> +
> +static struct attribute *lustre_attrs[] = {
> + &lustre_attr_version.attr,
> + &lustre_attr_pinger.attr,
> + &lustre_attr_health_check.attr,
> + &lustre_attr_jobid_name.attr,
> + &lustre_attr_jobid_var.attr,
> + NULL,
> +};
> +
> +static void *obd_device_list_seq_start(struct seq_file *p, loff_t *pos)
> +{
> + if (*pos >= class_devno_max())
> + return NULL;
> +
> + return pos;
> +}
> +
> +static void obd_device_list_seq_stop(struct seq_file *p, void *v)
> +{
> +}
> +
> +static void *obd_device_list_seq_next(struct seq_file *p, void *v, loff_t *pos)
> +{
> + ++*pos;
> + if (*pos >= class_devno_max())
> + return NULL;
> +
> + return pos;
> +}
> +
> +static int obd_device_list_seq_show(struct seq_file *p, void *v)
> +{
> + loff_t index = *(loff_t *)v;
> + struct obd_device *obd = class_num2obd((int)index);
> + char *status;
> +
> + if (!obd)
> + return 0;
> +
> + LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
> + if (obd->obd_stopping)
> + status = "ST";
> + else if (obd->obd_inactive)
> + status = "IN";
> + else if (obd->obd_set_up)
> + status = "UP";
> + else if (obd->obd_attached)
> + status = "AT";
> + else
> + status = "--";
> +
> + seq_printf(p, "%3d %s %s %s %s %d\n",
> + (int)index, status, obd->obd_type->typ_name,
> + obd->obd_name, obd->obd_uuid.uuid,
> + atomic_read(&obd->obd_refcount));
> + return 0;
> +}
> +
> +static const struct seq_operations obd_device_list_sops = {
> + .start = obd_device_list_seq_start,
> + .stop = obd_device_list_seq_stop,
> + .next = obd_device_list_seq_next,
> + .show = obd_device_list_seq_show,
> +};
> +
> +static int obd_device_list_open(struct inode *inode, struct file *file)
> +{
> + struct seq_file *seq;
> + int rc = seq_open(file, &obd_device_list_sops);
> +
> + if (rc)
> + return rc;
> +
> + seq = file->private_data;
> + seq->private = inode->i_private;
> +
> + return 0;
> +}
> +
> +static const struct file_operations obd_device_list_fops = {
> + .owner = THIS_MODULE,
> + .open = obd_device_list_open,
> + .read = seq_read,
> + .llseek = seq_lseek,
> + .release = seq_release,
> +};
> +
> +struct kobject *lustre_kobj;
> +EXPORT_SYMBOL_GPL(lustre_kobj);
> +
> +static const struct attribute_group lustre_attr_group = {
> + .attrs = lustre_attrs,
> +};
> +
> +int class_procfs_init(void)
> +{
> + int rc = -ENOMEM;
> +
> + lustre_kobj = kobject_create_and_add("lustre", fs_kobj);
> + if (!lustre_kobj)
> + goto out;
> +
> + /* Create the files associated with this kobject */
> + rc = sysfs_create_group(lustre_kobj, &lustre_attr_group);
> + if (rc) {
> + kobject_put(lustre_kobj);
> + goto out;
> + }
> +
> + debugfs_lustre_root = debugfs_create_dir("lustre", NULL);
> +
> + debugfs_create_file("devices", 0444, debugfs_lustre_root, NULL,
> + &obd_device_list_fops);
> +out:
> + return rc;
> +}
> +
> +int class_procfs_clean(void)
> +{
> + debugfs_remove_recursive(debugfs_lustre_root);
> +
> + debugfs_lustre_root = NULL;
> +
> + sysfs_remove_group(lustre_kobj, &lustre_attr_group);
> + kobject_put(lustre_kobj);
> +
> + return 0;
> +}
> diff --git a/drivers/staging/lustre/lustre/obdclass/sysctl.c b/drivers/staging/lustre/lustre/obdclass/sysctl.c
> new file mode 100644
> index 000000000000..e5e8687784ee
> --- /dev/null
> +++ b/drivers/staging/lustre/lustre/obdclass/sysctl.c
> @@ -0,0 +1,162 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * GPL HEADER START
> + *
> + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 only,
> + * as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful, but
> + * WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * General Public License version 2 for more details (a copy is included
> + * in the LICENSE file that accompanied this code).
> + *
> + * You should have received a copy of the GNU General Public License
> + * version 2 along with this program; If not, see
> + * http://www.gnu.org/licenses/gpl-2.0.html
> + *
> + * GPL HEADER END
> + */
> +/*
> + * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
> + * Use is subject to license terms.
> + *
> + * Copyright (c) 2011, 2015, Intel Corporation.
> + */
> +/*
> + * This file is part of Lustre, http://www.lustre.org/
> + * Lustre is a trademark of Sun Microsystems, Inc.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/sysctl.h>
> +#include <linux/sched.h>
> +#include <linux/mm.h>
> +#include <linux/slab.h>
> +#include <linux/stat.h>
> +#include <linux/ctype.h>
> +#include <linux/bitops.h>
> +#include <linux/uaccess.h>
> +#include <linux/utsname.h>
> +
> +#define DEBUG_SUBSYSTEM S_CLASS
> +
> +#include <obd_support.h>
> +#include <lprocfs_status.h>
> +#include <obd_class.h>
> +
> +struct static_lustre_uintvalue_attr {
> + struct {
> + struct attribute attr;
> + ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
> + char *buf);
> + ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
> + const char *buf, size_t len);
> + } u;
> + int *value;
> +};
> +
> +static ssize_t static_uintvalue_show(struct kobject *kobj,
> + struct attribute *attr,
> + char *buf)
> +{
> + struct static_lustre_uintvalue_attr *lattr = (void *)attr;
> +
> + return sprintf(buf, "%d\n", *lattr->value);
> +}
> +
> +static ssize_t static_uintvalue_store(struct kobject *kobj,
> + struct attribute *attr,
> + const char *buffer, size_t count)
> +{
> + struct static_lustre_uintvalue_attr *lattr = (void *)attr;
> + int rc;
> + unsigned int val;
> +
> + rc = kstrtouint(buffer, 10, &val);
> + if (rc)
> + return rc;
> +
> + *lattr->value = val;
> +
> + return count;
> +}
> +
> +#define LUSTRE_STATIC_UINT_ATTR(name, value) \
> +static struct static_lustre_uintvalue_attr lustre_sattr_##name = \
> + {__ATTR(name, 0644, \
> + static_uintvalue_show, \
> + static_uintvalue_store),\
> + value }
> +
> +LUSTRE_STATIC_UINT_ATTR(timeout, &obd_timeout);
> +
> +static ssize_t max_dirty_mb_show(struct kobject *kobj, struct attribute *attr,
> + char *buf)
> +{
> + return sprintf(buf, "%lu\n",
> + obd_max_dirty_pages / (1 << (20 - PAGE_SHIFT)));
> +}
> +
> +static ssize_t max_dirty_mb_store(struct kobject *kobj, struct attribute *attr,
> + const char *buffer, size_t count)
> +{
> + int rc;
> + unsigned long val;
> +
> + rc = kstrtoul(buffer, 10, &val);
> + if (rc)
> + return rc;
> +
> + val *= 1 << (20 - PAGE_SHIFT); /* convert to pages */
> +
> + if (val > ((totalram_pages / 10) * 9)) {
> + /* Somebody wants to assign too much memory to dirty pages */
> + return -EINVAL;
> + }
> +
> + if (val < 4 << (20 - PAGE_SHIFT)) {
> + /* Less than 4 Mb for dirty cache is also bad */
> + return -EINVAL;
> + }
> +
> + obd_max_dirty_pages = val;
> +
> + return count;
> +}
> +LUSTRE_RW_ATTR(max_dirty_mb);
> +
> +LUSTRE_STATIC_UINT_ATTR(debug_peer_on_timeout, &obd_debug_peer_on_timeout);
> +LUSTRE_STATIC_UINT_ATTR(dump_on_timeout, &obd_dump_on_timeout);
> +LUSTRE_STATIC_UINT_ATTR(dump_on_eviction, &obd_dump_on_eviction);
> +LUSTRE_STATIC_UINT_ATTR(at_min, &at_min);
> +LUSTRE_STATIC_UINT_ATTR(at_max, &at_max);
> +LUSTRE_STATIC_UINT_ATTR(at_extra, &at_extra);
> +LUSTRE_STATIC_UINT_ATTR(at_early_margin, &at_early_margin);
> +LUSTRE_STATIC_UINT_ATTR(at_history, &at_history);
> +
> +static struct attribute *lustre_attrs[] = {
> + &lustre_sattr_timeout.u.attr,
> + &lustre_attr_max_dirty_mb.attr,
> + &lustre_sattr_debug_peer_on_timeout.u.attr,
> + &lustre_sattr_dump_on_timeout.u.attr,
> + &lustre_sattr_dump_on_eviction.u.attr,
> + &lustre_sattr_at_min.u.attr,
> + &lustre_sattr_at_max.u.attr,
> + &lustre_sattr_at_extra.u.attr,
> + &lustre_sattr_at_early_margin.u.attr,
> + &lustre_sattr_at_history.u.attr,
> + NULL,
> +};
> +
> +static const struct attribute_group lustre_attr_group = {
> + .attrs = lustre_attrs,
> +};
> +
> +int obd_sysctl_init(void)
> +{
> + return sysfs_create_group(lustre_kobj, &lustre_attr_group);
> +}
>
>
>

2018-06-16 03:02:29

by James Simmons

[permalink] [raw]
Subject: Re: [PATCH 01/11] staging: lustre: simplify use of interval-tree.


> Lustre has a private interval-tree implementation. This
> implementation (inexplicably) refuses to insert an interval if an
> identical interval already exists. It is OK with all sorts of
> overlapping intervals, but identical intervals are rejected.

I talked to Oleg about this since this changes the behavior. He is worried
about having identical items that would end up being merged. If we can
guarantee by some other means there are no identical nodes, we are
probably fine with the interval tree code allowing this. Oleg can explain
better than me in this case.

> Both users of interval-tree in lustre would be simpler if this was not
> the case. They need to store all intervals, even if some are
> identical.
>
> llite/range_lock.c add a rl_next_lock list_head to each lock.
> If it cannot insert a new lock because the range is in use, it
> attached the new lock to the existing lock using rl_next_lock.
> This requires extra code to iterate over the rl_next_lock lists when
> iterating over locks, and to update the list when deleting a lock from
> the tree.
>
> ldlm_extend allocates a separate ldlm_interval which as a list of
> ldlm_locks which share the same interval. This is linked together
> by over-loading the l_sl_policy which, for non-extent locks, is used
> for linking together locks with the same policy.
> This doesn't only require extra code, but also an extra memory
> allocation.
>
> This patch removes all that complexity.
> - interval_insert() now never fails.

Its not really a failure. What it does is if it finds a already existing
node with the range requested it returns the already existing node
pointer. If not it just creates a new node and returns NULL. Sometimes
identical request can happen. A good example of this is with HSM request
on the MDS server. In that case sometimes we get identical progress
reports which we want to filter out so not add the same data.

> - consequently rl_next_lock is always empty and
> rl_lock_count is always zero. so they are removed
> - every ldlm_lock has linked directly into the
> interval tree, so each has an embedded interval_node
> rather than a pointer to a 'struct ldlm_interval'
> - ldlm_interval is now unused, so it is gone as it
> the kmemcache from which they were allocated.
> - the various functions for allocating an ldlm_interval
> and attaching to a lock or detaching from a lock
> are also gone.
>
> Signed-off-by: NeilBrown <[email protected]>
> ---
> .../staging/lustre/lustre/include/interval_tree.h | 4 +
> drivers/staging/lustre/lustre/include/lustre_dlm.h | 12 ---
> drivers/staging/lustre/lustre/ldlm/interval_tree.c | 13 +--
> drivers/staging/lustre/lustre/ldlm/ldlm_extent.c | 76 ++------------------
> drivers/staging/lustre/lustre/ldlm/ldlm_internal.h | 17 ----
> drivers/staging/lustre/lustre/ldlm/ldlm_lock.c | 25 +------
> drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 9 --
> drivers/staging/lustre/lustre/llite/range_lock.c | 59 +---------------
> drivers/staging/lustre/lustre/llite/range_lock.h | 8 --
> 9 files changed, 17 insertions(+), 206 deletions(-)
>
> diff --git a/drivers/staging/lustre/lustre/include/interval_tree.h b/drivers/staging/lustre/lustre/include/interval_tree.h
> index 7d119c1a0469..bcda74fc7875 100644
> --- a/drivers/staging/lustre/lustre/include/interval_tree.h
> +++ b/drivers/staging/lustre/lustre/include/interval_tree.h
> @@ -100,8 +100,8 @@ static inline int interval_set(struct interval_node *node,
> typedef enum interval_iter (*interval_callback_t)(struct interval_node *node,
> void *args);
>
> -struct interval_node *interval_insert(struct interval_node *node,
> - struct interval_node **root);
> +void interval_insert(struct interval_node *node,
> + struct interval_node **root);
> void interval_erase(struct interval_node *node, struct interval_node **root);
>
> /*
> diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
> index 2c55241258cc..baeb8c63352b 100644
> --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
> +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
> @@ -513,16 +513,6 @@ struct ldlm_glimpse_work {
> /** The ldlm_glimpse_work is allocated on the stack and should not be freed. */
> #define LDLM_GL_WORK_NOFREE 0x1
>
> -/** Interval node data for each LDLM_EXTENT lock. */
> -struct ldlm_interval {
> - struct interval_node li_node; /* node for tree management */
> - struct list_head li_group; /* the locks which have the same
> - * policy - group of the policy
> - */
> -};
> -
> -#define to_ldlm_interval(n) container_of(n, struct ldlm_interval, li_node)
> -
> /**
> * Interval tree for extent locks.
> * The interval tree must be accessed under the resource lock.
> @@ -631,7 +621,7 @@ struct ldlm_lock {
> /**
> * Tree node for ldlm_extent.
> */
> - struct ldlm_interval *l_tree_node;
> + struct interval_node l_tree_node;
> /**
> * Requested mode.
> * Protected by lr_lock.
> diff --git a/drivers/staging/lustre/lustre/ldlm/interval_tree.c b/drivers/staging/lustre/lustre/ldlm/interval_tree.c
> index 8df7a4463c21..f5232059d1b1 100644
> --- a/drivers/staging/lustre/lustre/ldlm/interval_tree.c
> +++ b/drivers/staging/lustre/lustre/ldlm/interval_tree.c
> @@ -97,11 +97,6 @@ static inline int extent_overlapped(struct interval_node_extent *e1,
> return (e1->start <= e2->end) && (e2->start <= e1->end);
> }
>
> -static inline int node_equal(struct interval_node *n1, struct interval_node *n2)
> -{
> - return extent_equal(&n1->in_extent, &n2->in_extent);
> -}
> -
> static struct interval_node *interval_first(struct interval_node *node)
> {
> if (!node)
> @@ -299,8 +294,8 @@ static void interval_insert_color(struct interval_node *node,
> (*root)->in_color = INTERVAL_BLACK;
> }
>
> -struct interval_node *interval_insert(struct interval_node *node,
> - struct interval_node **root)
> +void interval_insert(struct interval_node *node,
> + struct interval_node **root)
>
> {
> struct interval_node **p, *parent = NULL;
> @@ -309,8 +304,6 @@ struct interval_node *interval_insert(struct interval_node *node,
> p = root;
> while (*p) {
> parent = *p;
> - if (node_equal(parent, node))
> - return parent;
>
> /* max_high field must be updated after each iteration */
> if (parent->in_max_high < interval_high(node))
> @@ -331,8 +324,6 @@ struct interval_node *interval_insert(struct interval_node *node,
>
> interval_insert_color(node, root);
> node->in_intree = 1;
> -
> - return NULL;
> }
> EXPORT_SYMBOL(interval_insert);
>
> diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
> index 4da23ade2bb3..2f4c305bb340 100644
> --- a/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
> +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_extent.c
> @@ -92,55 +92,6 @@ __u64 ldlm_extent_shift_kms(struct ldlm_lock *lock, __u64 old_kms)
> }
> EXPORT_SYMBOL(ldlm_extent_shift_kms);
>
> -struct kmem_cache *ldlm_interval_slab;
> -
> -/* interval tree, for LDLM_EXTENT. */
> -static void ldlm_interval_attach(struct ldlm_interval *n, struct ldlm_lock *l)
> -{
> - LASSERT(!l->l_tree_node);
> - LASSERT(l->l_resource->lr_type == LDLM_EXTENT);
> -
> - list_add_tail(&l->l_sl_policy, &n->li_group);
> - l->l_tree_node = n;
> -}
> -
> -struct ldlm_interval *ldlm_interval_alloc(struct ldlm_lock *lock)
> -{
> - struct ldlm_interval *node;
> -
> - LASSERT(lock->l_resource->lr_type == LDLM_EXTENT);
> - node = kmem_cache_zalloc(ldlm_interval_slab, GFP_NOFS);
> - if (!node)
> - return NULL;
> -
> - INIT_LIST_HEAD(&node->li_group);
> - ldlm_interval_attach(node, lock);
> - return node;
> -}
> -
> -void ldlm_interval_free(struct ldlm_interval *node)
> -{
> - if (node) {
> - LASSERT(list_empty(&node->li_group));
> - LASSERT(!interval_is_intree(&node->li_node));
> - kmem_cache_free(ldlm_interval_slab, node);
> - }
> -}
> -
> -struct ldlm_interval *ldlm_interval_detach(struct ldlm_lock *l)
> -{
> - struct ldlm_interval *n = l->l_tree_node;
> -
> - if (!n)
> - return NULL;
> -
> - LASSERT(!list_empty(&n->li_group));
> - l->l_tree_node = NULL;
> - list_del_init(&l->l_sl_policy);
> -
> - return list_empty(&n->li_group) ? n : NULL;
> -}
> -
> static inline int lock_mode_to_index(enum ldlm_mode mode)
> {
> int index;
> @@ -157,16 +108,13 @@ static inline int lock_mode_to_index(enum ldlm_mode mode)
> void ldlm_extent_add_lock(struct ldlm_resource *res,
> struct ldlm_lock *lock)
> {
> - struct interval_node *found, **root;
> - struct ldlm_interval *node;
> + struct interval_node **root;
> struct ldlm_extent *extent;
> int idx, rc;
>
> LASSERT(lock->l_granted_mode == lock->l_req_mode);
>
> - node = lock->l_tree_node;
> - LASSERT(node);
> - LASSERT(!interval_is_intree(&node->li_node));
> + LASSERT(!interval_is_intree(&lock->l_tree_node));
>
> idx = lock_mode_to_index(lock->l_granted_mode);
> LASSERT(lock->l_granted_mode == 1 << idx);
> @@ -174,18 +122,11 @@ void ldlm_extent_add_lock(struct ldlm_resource *res,
>
> /* node extent initialize */
> extent = &lock->l_policy_data.l_extent;
> - rc = interval_set(&node->li_node, extent->start, extent->end);
> + rc = interval_set(&lock->l_tree_node, extent->start, extent->end);
> LASSERT(!rc);
>
> root = &res->lr_itree[idx].lit_root;
> - found = interval_insert(&node->li_node, root);
> - if (found) { /* The policy group found. */
> - struct ldlm_interval *tmp;
> -
> - tmp = ldlm_interval_detach(lock);
> - ldlm_interval_free(tmp);
> - ldlm_interval_attach(to_ldlm_interval(found), lock);
> - }
> + interval_insert(&lock->l_tree_node, root);
> res->lr_itree[idx].lit_size++;
>
> /* even though we use interval tree to manage the extent lock, we also
> @@ -219,11 +160,10 @@ void ldlm_extent_add_lock(struct ldlm_resource *res,
> void ldlm_extent_unlink_lock(struct ldlm_lock *lock)
> {
> struct ldlm_resource *res = lock->l_resource;
> - struct ldlm_interval *node = lock->l_tree_node;
> struct ldlm_interval_tree *tree;
> int idx;
>
> - if (!node || !interval_is_intree(&node->li_node)) /* duplicate unlink */
> + if (!interval_is_intree(&lock->l_tree_node)) /* duplicate unlink */
> return;
>
> idx = lock_mode_to_index(lock->l_granted_mode);
> @@ -233,11 +173,7 @@ void ldlm_extent_unlink_lock(struct ldlm_lock *lock)
> LASSERT(tree->lit_root); /* assure the tree is not null */
>
> tree->lit_size--;
> - node = ldlm_interval_detach(lock);
> - if (node) {
> - interval_erase(&node->li_node, &tree->lit_root);
> - ldlm_interval_free(node);
> - }
> + interval_erase(&lock->l_tree_node, &tree->lit_root);
> }
>
> void ldlm_extent_policy_wire_to_local(const union ldlm_wire_policy_data *wpolicy,
> diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h b/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
> index bc33ca100620..159de8a59cbb 100644
> --- a/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
> +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_internal.h
> @@ -189,23 +189,6 @@ __u64 ldlm_pool_get_slv(struct ldlm_pool *pl);
> void ldlm_pool_set_clv(struct ldlm_pool *pl, __u64 clv);
> __u32 ldlm_pool_get_lvf(struct ldlm_pool *pl);
>
> -/* interval tree, for LDLM_EXTENT. */
> -extern struct kmem_cache *ldlm_interval_slab; /* slab cache for ldlm_interval */
> -struct ldlm_interval *ldlm_interval_detach(struct ldlm_lock *l);
> -struct ldlm_interval *ldlm_interval_alloc(struct ldlm_lock *lock);
> -void ldlm_interval_free(struct ldlm_interval *node);
> -/* this function must be called with res lock held */
> -static inline struct ldlm_extent *
> -ldlm_interval_extent(struct ldlm_interval *node)
> -{
> - struct ldlm_lock *lock;
> -
> - LASSERT(!list_empty(&node->li_group));
> -
> - lock = list_entry(node->li_group.next, struct ldlm_lock, l_sl_policy);
> - return &lock->l_policy_data.l_extent;
> -}
> -
> int ldlm_init(void);
> void ldlm_exit(void);
>
> diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
> index a644d133063b..13b1b5fdada9 100644
> --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
> +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lock.c
> @@ -185,7 +185,6 @@ void ldlm_lock_put(struct ldlm_lock *lock)
>
> kfree(lock->l_lvb_data);
>
> - ldlm_interval_free(ldlm_interval_detach(lock));
> lu_ref_fini(&lock->l_reference);
> OBD_FREE_RCU(lock, sizeof(*lock), &lock->l_handle);
> }
> @@ -1138,17 +1137,10 @@ static int lock_matches(struct ldlm_lock *lock, struct lock_match_data *data)
>
> static enum interval_iter itree_overlap_cb(struct interval_node *in, void *args)
> {
> - struct ldlm_interval *node = to_ldlm_interval(in);
> struct lock_match_data *data = args;
> - struct ldlm_lock *lock;
> - int rc;
> + struct ldlm_lock *lock = container_of(in, struct ldlm_lock, l_tree_node);
>
> - list_for_each_entry(lock, &node->li_group, l_sl_policy) {
> - rc = lock_matches(lock, data);
> - if (rc == INTERVAL_ITER_STOP)
> - return INTERVAL_ITER_STOP;
> - }
> - return INTERVAL_ITER_CONT;
> + return lock_matches(lock, data);
> }
>
> /**
> @@ -1564,15 +1556,6 @@ struct ldlm_lock *ldlm_lock_create(struct ldlm_namespace *ns,
> lock->l_glimpse_ast = cbs->lcs_glimpse;
> }
>
> - lock->l_tree_node = NULL;
> - /* if this is the extent lock, allocate the interval tree node */
> - if (type == LDLM_EXTENT) {
> - if (!ldlm_interval_alloc(lock)) {
> - rc = -ENOMEM;
> - goto out;
> - }
> - }
> -
> if (lvb_len) {
> lock->l_lvb_len = lvb_len;
> lock->l_lvb_data = kzalloc(lvb_len, GFP_NOFS);
> @@ -1625,10 +1608,6 @@ enum ldlm_error ldlm_lock_enqueue(struct ldlm_namespace *ns,
>
> ldlm_resource_unlink_lock(lock);
>
> - /* Cannot happen unless on the server */
> - if (res->lr_type == LDLM_EXTENT && !lock->l_tree_node)
> - LBUG();
> -
> /* Some flags from the enqueue want to make it into the AST, via the
> * lock's l_flags.
> */
> diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
> index 5963e90d0938..f410ef6c02ef 100644
> --- a/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
> +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c
> @@ -1134,14 +1134,6 @@ int ldlm_init(void)
> return -ENOMEM;
> }
>
> - ldlm_interval_slab = kmem_cache_create("interval_node",
> - sizeof(struct ldlm_interval),
> - 0, SLAB_HWCACHE_ALIGN, NULL);
> - if (!ldlm_interval_slab) {
> - kmem_cache_destroy(ldlm_resource_slab);
> - kmem_cache_destroy(ldlm_lock_slab);
> - return -ENOMEM;
> - }
> #if LUSTRE_TRACKS_LOCK_EXP_REFS
> class_export_dump_hook = ldlm_dump_export_locks;
> #endif
> @@ -1159,5 +1151,4 @@ void ldlm_exit(void)
> */
> synchronize_rcu();
> kmem_cache_destroy(ldlm_lock_slab);
> - kmem_cache_destroy(ldlm_interval_slab);
> }
> diff --git a/drivers/staging/lustre/lustre/llite/range_lock.c b/drivers/staging/lustre/lustre/llite/range_lock.c
> index 008a8874118d..eaa23f4c414e 100644
> --- a/drivers/staging/lustre/lustre/llite/range_lock.c
> +++ b/drivers/staging/lustre/lustre/llite/range_lock.c
> @@ -74,19 +74,12 @@ int range_lock_init(struct range_lock *lock, __u64 start, __u64 end)
> if (rc)
> return rc;
>
> - INIT_LIST_HEAD(&lock->rl_next_lock);
> lock->rl_task = NULL;
> - lock->rl_lock_count = 0;
> lock->rl_blocking_ranges = 0;
> lock->rl_sequence = 0;
> return rc;
> }
>
> -static inline struct range_lock *next_lock(struct range_lock *lock)
> -{
> - return list_entry(lock->rl_next_lock.next, typeof(*lock), rl_next_lock);
> -}
> -
> /**
> * Helper function of range_unlock()
> *
> @@ -102,14 +95,7 @@ static enum interval_iter range_unlock_cb(struct interval_node *node, void *arg)
> {
> struct range_lock *lock = arg;
> struct range_lock *overlap = node2rangelock(node);
> - struct range_lock *iter;
>
> - list_for_each_entry(iter, &overlap->rl_next_lock, rl_next_lock) {
> - if (iter->rl_sequence > lock->rl_sequence) {
> - --iter->rl_blocking_ranges;
> - LASSERT(iter->rl_blocking_ranges > 0);
> - }
> - }
> if (overlap->rl_sequence > lock->rl_sequence) {
> --overlap->rl_blocking_ranges;
> if (overlap->rl_blocking_ranges == 0)
> @@ -131,32 +117,8 @@ static enum interval_iter range_unlock_cb(struct interval_node *node, void *arg)
> void range_unlock(struct range_lock_tree *tree, struct range_lock *lock)
> {
> spin_lock(&tree->rlt_lock);
> - if (!list_empty(&lock->rl_next_lock)) {
> - struct range_lock *next;
> -
> - if (interval_is_intree(&lock->rl_node)) { /* first lock */
> - /* Insert the next same range lock into the tree */
> - next = next_lock(lock);
> - next->rl_lock_count = lock->rl_lock_count - 1;
> - interval_erase(&lock->rl_node, &tree->rlt_root);
> - interval_insert(&next->rl_node, &tree->rlt_root);
> - } else {
> - /* find the first lock in tree */
> - list_for_each_entry(next, &lock->rl_next_lock,
> - rl_next_lock) {
> - if (!interval_is_intree(&next->rl_node))
> - continue;
> -
> - LASSERT(next->rl_lock_count > 0);
> - next->rl_lock_count--;
> - break;
> - }
> - }
> - list_del_init(&lock->rl_next_lock);
> - } else {
> - LASSERT(interval_is_intree(&lock->rl_node));
> - interval_erase(&lock->rl_node, &tree->rlt_root);
> - }
> + LASSERT(interval_is_intree(&lock->rl_node));
> + interval_erase(&lock->rl_node, &tree->rlt_root);
>
> interval_search(tree->rlt_root, &lock->rl_node.in_extent,
> range_unlock_cb, lock);
> @@ -177,9 +139,8 @@ void range_unlock(struct range_lock_tree *tree, struct range_lock *lock)
> static enum interval_iter range_lock_cb(struct interval_node *node, void *arg)
> {
> struct range_lock *lock = arg;
> - struct range_lock *overlap = node2rangelock(node);
>
> - lock->rl_blocking_ranges += overlap->rl_lock_count + 1;
> + lock->rl_blocking_ranges++;
> return INTERVAL_ITER_CONT;
> }
>
> @@ -198,7 +159,6 @@ static enum interval_iter range_lock_cb(struct interval_node *node, void *arg)
> */
> int range_lock(struct range_lock_tree *tree, struct range_lock *lock)
> {
> - struct interval_node *node;
> int rc = 0;
>
> spin_lock(&tree->rlt_lock);
> @@ -208,18 +168,7 @@ int range_lock(struct range_lock_tree *tree, struct range_lock *lock)
> */
> interval_search(tree->rlt_root, &lock->rl_node.in_extent,
> range_lock_cb, lock);
> - /*
> - * Insert to the tree if I am unique, otherwise I've been linked to
> - * the rl_next_lock of another lock which has the same range as mine
> - * in range_lock_cb().
> - */
> - node = interval_insert(&lock->rl_node, &tree->rlt_root);
> - if (node) {
> - struct range_lock *tmp = node2rangelock(node);
> -
> - list_add_tail(&lock->rl_next_lock, &tmp->rl_next_lock);
> - tmp->rl_lock_count++;
> - }
> + interval_insert(&lock->rl_node, &tree->rlt_root);
> lock->rl_sequence = ++tree->rlt_sequence;
>
> while (lock->rl_blocking_ranges > 0) {
> diff --git a/drivers/staging/lustre/lustre/llite/range_lock.h b/drivers/staging/lustre/lustre/llite/range_lock.h
> index 9ebac09160f2..10ef1a995d26 100644
> --- a/drivers/staging/lustre/lustre/llite/range_lock.h
> +++ b/drivers/staging/lustre/lustre/llite/range_lock.h
> @@ -46,14 +46,6 @@ struct range_lock {
> * Process to enqueue this lock.
> */
> struct task_struct *rl_task;
> - /**
> - * List of locks with the same range.
> - */
> - struct list_head rl_next_lock;
> - /**
> - * Number of locks in the list rl_next_lock
> - */
> - unsigned int rl_lock_count;
> /**
> * Number of ranges which are blocking acquisition of the lock
> */
>
>
>

2018-06-16 22:51:44

by NeilBrown

[permalink] [raw]
Subject: Re: [PATCH 01/11] staging: lustre: simplify use of interval-tree.

On Sat, Jun 16 2018, James Simmons wrote:

>> Lustre has a private interval-tree implementation. This
>> implementation (inexplicably) refuses to insert an interval if an
>> identical interval already exists. It is OK with all sorts of
>> overlapping intervals, but identical intervals are rejected.
>
> I talked to Oleg about this since this changes the behavior. He is worried
> about having identical items that would end up being merged. If we can
> guarantee by some other means there are no identical nodes, we are
> probably fine with the interval tree code allowing this. Oleg can explain
> better than me in this case.

I don't think this is a change in behaviour.
In the driver/staging client code, interval tree is being used in two
places and both of them have clumsy work-arounds for the fact that they
cannot insert duplicates in the interval tree.
The patch just cleans his up.

However if I have missed something, please provide details.
What "identical items" might get merged?

>
>> Both users of interval-tree in lustre would be simpler if this was not
>> the case. They need to store all intervals, even if some are
>> identical.
>>
>> llite/range_lock.c add a rl_next_lock list_head to each lock.
>> If it cannot insert a new lock because the range is in use, it
>> attached the new lock to the existing lock using rl_next_lock.
>> This requires extra code to iterate over the rl_next_lock lists when
>> iterating over locks, and to update the list when deleting a lock from
>> the tree.
>>
>> ldlm_extend allocates a separate ldlm_interval which as a list of
>> ldlm_locks which share the same interval. This is linked together
>> by over-loading the l_sl_policy which, for non-extent locks, is used
>> for linking together locks with the same policy.
>> This doesn't only require extra code, but also an extra memory
>> allocation.
>>
>> This patch removes all that complexity.
>> - interval_insert() now never fails.
>
> Its not really a failure. What it does is if it finds a already existing
> node with the range requested it returns the already existing node
> pointer. If not it just creates a new node and returns NULL. Sometimes
> identical request can happen. A good example of this is with HSM request
> on the MDS server. In that case sometimes we get identical progress
> reports which we want to filter out so not add the same data.

This example is server-side code which is not a focus at present.
Having a quick look, it looks like it would be easy enough to do a
lookup first and then only insert if the lookup failed.
I think this is a much nicer approach than never allowing duplicates in
the interval tree.

Thanks,
NeilBrown


Attachments:
signature.asc (847.00 B)

2018-07-06 01:38:20

by James Simmons

[permalink] [raw]
Subject: Re: [PATCH 01/11] staging: lustre: simplify use of interval-tree.


> >> Lustre has a private interval-tree implementation. This
> >> implementation (inexplicably) refuses to insert an interval if an
> >> identical interval already exists. It is OK with all sorts of
> >> overlapping intervals, but identical intervals are rejected.
> >
> > I talked to Oleg about this since this changes the behavior. He is worried
> > about having identical items that would end up being merged. If we can
> > guarantee by some other means there are no identical nodes, we are
> > probably fine with the interval tree code allowing this. Oleg can explain
> > better than me in this case.
>
> I don't think this is a change in behaviour.
> In the driver/staging client code, interval tree is being used in two
> places and both of them have clumsy work-arounds for the fact that they
> cannot insert duplicates in the interval tree.
> The patch just cleans his up.
>
> However if I have missed something, please provide details.
> What "identical items" might get merged?

Oleg could you fill in detail what your concerns are?

> >
> >> Both users of interval-tree in lustre would be simpler if this was not
> >> the case. They need to store all intervals, even if some are
> >> identical.
> >>
> >> llite/range_lock.c add a rl_next_lock list_head to each lock.
> >> If it cannot insert a new lock because the range is in use, it
> >> attached the new lock to the existing lock using rl_next_lock.
> >> This requires extra code to iterate over the rl_next_lock lists when
> >> iterating over locks, and to update the list when deleting a lock from
> >> the tree.
> >>
> >> ldlm_extend allocates a separate ldlm_interval which as a list of
> >> ldlm_locks which share the same interval. This is linked together
> >> by over-loading the l_sl_policy which, for non-extent locks, is used
> >> for linking together locks with the same policy.
> >> This doesn't only require extra code, but also an extra memory
> >> allocation.
> >>
> >> This patch removes all that complexity.
> >> - interval_insert() now never fails.
> >
> > Its not really a failure. What it does is if it finds a already existing
> > node with the range requested it returns the already existing node
> > pointer. If not it just creates a new node and returns NULL. Sometimes
> > identical request can happen. A good example of this is with HSM request
> > on the MDS server. In that case sometimes we get identical progress
> > reports which we want to filter out so not add the same data.
>
> This example is server-side code which is not a focus at present.
> Having a quick look, it looks like it would be easy enough to do a
> lookup first and then only insert if the lookup failed.
> I think this is a much nicer approach than never allowing duplicates in
> the interval tree.
>
> Thanks,
> NeilBrown
>