Hi,

在 2025/01/23 10:07, Yu Kuai 写道:
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 264756a54f59..9451cc5cc574 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -83,6 +83,9 @@ static const char *action_name[NR_SYNC_ACTIONS] = {
  static LIST_HEAD(pers_list);
  static DEFINE_SPINLOCK(pers_lock);
+static LIST_HEAD(bitmap_list);
+static DEFINE_SPINLOCK(bitmap_lock);
+
  static const struct kobj_type md_ktype;
const struct md_cluster_operations *md_cluster_ops;
@@ -100,7 +103,6 @@ static struct workqueue_struct *md_wq;
   * workqueue whith reconfig_mutex grabbed.
   */
  static struct workqueue_struct *md_misc_wq;
-struct workqueue_struct *md_bitmap_wq;
static int remove_and_add_spares(struct mddev *mddev,
                                 struct md_rdev *this);
@@ -650,15 +652,73 @@ static void active_io_release(struct percpu_ref *ref)
static void no_op(struct percpu_ref *r) {} +void register_md_bitmap(struct bitmap_operations *op)
+{
+       pr_info("md: bitmap version %d registered\n", op->version);
+
+       spin_lock(&bitmap_lock);
+       list_add_tail(&op->list, &bitmap_list);
+       spin_unlock(&bitmap_lock);
+}
+
+void unregister_md_bitmap(struct bitmap_operations *op)
+{
+       pr_info("md: bitmap version %d unregistered\n", op->version);
+
+       spin_lock(&bitmap_lock);
+       list_del_init(&op->list);
+       spin_unlock(&bitmap_lock);
+}
+
+static struct bitmap_operations *find_bitmap(int version)
+{
+       struct bitmap_operations *op = NULL;
+       struct bitmap_operations *tmp;
+
+       spin_lock(&bitmap_lock);
+       list_for_each_entry(tmp, &bitmap_list, list) {
+               if (tmp->version == version) {
+                       op = tmp;
+                       break;
+               }
+       }
+       spin_unlock(&bitmap_lock);
+
+       return op;
+}

Noted that, we already have pers_lock and pers_list for personalities,
md_cluster_ops and md_cluster_mod for md-cluster. Now, add bitmap_lock
and bitmap_list is a bit ugly.

I decided to refactor this a bit, by adding a new struct
md_submodule_head and unify all sub modules registeration,
unregisteration and lookup. Will send a set soon :)

Thanks,
Kuai


Reply via email to