Whamcloud - gitweb
LU-11085 ldlm: move interval_insert call from ldlm_lock to ldlm_extent 21/34021/18
authorNeilBrown <neilb@suse.com>
Fri, 9 Aug 2019 17:10:03 +0000 (13:10 -0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 29 May 2024 04:44:12 +0000 (04:44 +0000)
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.

Change-Id: I7b392cc57b69969f4bb3c4b51fa406ed643a37b3
Signed-off-by: NeilBrown <neilb@suse.com>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/34021
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Yang Sheng <ys@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
lustre/ldlm/ldlm_extent.c
lustre/ldlm/ldlm_internal.h
lustre/ldlm/ldlm_lock.c

index c5835b6..7e6b91c 100644 (file)
@@ -1024,3 +1024,29 @@ 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);
+}
index 6398dc1..3b128db 100644 (file)
@@ -204,6 +204,10 @@ int ldlm_process_extent_lock(struct ldlm_lock *lock, __u64 *flags,
 #endif
 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);
 
 int ldlm_inodebits_alloc_lock(struct ldlm_lock *lock);
 void ldlm_inodebits_add_lock(struct ldlm_resource *res, struct list_head *head,
index 760a7b8..3519a7b 100644 (file)
@@ -1187,8 +1187,9 @@ void ldlm_grant_lock(struct ldlm_lock *lock, struct list_head *work_list)
  *
  * RETURN      returns true if @lock matches @data, false otherwise
  */
-static bool lock_matches(struct ldlm_lock *lock, struct ldlm_match_data *data)
+static bool lock_matches(struct ldlm_lock *lock, void *vdata)
 {
+       struct ldlm_match_data *data = vdata;
        union ldlm_policy_data *lpol = &lock->l_policy_data;
        enum ldlm_mode match = LCK_MINMODE;
 
@@ -1293,16 +1294,6 @@ matched:
        return true;
 }
 
-static unsigned int itree_overlap_cb(struct interval_node *in, void *args)
-{
-       struct ldlm_lock *lock = container_of(in, struct ldlm_lock,
-                                             l_tree_node);
-       struct ldlm_match_data *data = args;
-
-       return lock_matches(lock, data) ?
-               INTERVAL_ITER_STOP : INTERVAL_ITER_CONT;
-}
-
 /**
  * Search for a lock with given parameters in interval trees.
  *
@@ -1334,8 +1325,8 @@ 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);
                if (data->lmd_lock)
                        return data->lmd_lock;
        }