From 58dd106db88f00b08d20d4a949a001629238dbc0 Mon Sep 17 00:00:00 2001 From: "Chia-Lin Kao (AceLan)" Date: Mon, 28 Aug 2023 02:34:08 -0400 Subject: [PATCH] Revert "md: only delete entries from all_mddevs when the disk is freed" This reverts commit 12a6caf273240ae42842de8cc05feaa86e582d61. --- drivers/md/md.c | 52 ++++++++++++++++--------------------------------- drivers/md/md.h | 2 -- 2 files changed, 17 insertions(+), 37 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 78be7811a89f..af5d379ad357 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -606,10 +606,6 @@ EXPORT_SYMBOL(md_flush_request); static inline struct mddev *mddev_get(struct mddev *mddev) { - lockdep_assert_held(&all_mddevs_lock); - - if (test_bit(MD_DELETED, &mddev->flags)) - return NULL; atomic_inc(&mddev->active); return mddev; } @@ -624,7 +620,7 @@ void mddev_put(struct mddev *mddev) mddev->ctime == 0 && !mddev->hold_active) { /* Array is not configured at all, and not held active, * so destroy it */ - set_bit(MD_DELETED, &mddev->flags); + list_del_init(&mddev->all_mddevs); /* * Call queue_work inside the spinlock so that @@ -3285,8 +3281,6 @@ static bool md_rdev_overlaps(struct md_rdev *rdev) spin_lock(&all_mddevs_lock); list_for_each_entry(mddev, &all_mddevs, all_mddevs) { - if (test_bit(MD_DELETED, &mddev->flags)) - continue; rdev_for_each(rdev2, mddev) { if (rdev != rdev2 && rdev->bdev == rdev2->bdev && md_rdevs_overlap(rdev, rdev2)) { @@ -5488,10 +5482,11 @@ md_attr_show(struct kobject *kobj, struct attribute *attr, char *page) if (!entry->show) return -EIO; spin_lock(&all_mddevs_lock); - if (!mddev_get(mddev)) { + if (list_empty(&mddev->all_mddevs)) { spin_unlock(&all_mddevs_lock); return -EBUSY; } + mddev_get(mddev); spin_unlock(&all_mddevs_lock); rv = entry->show(mddev, page); @@ -5512,10 +5507,11 @@ md_attr_store(struct kobject *kobj, struct attribute *attr, if (!capable(CAP_SYS_ADMIN)) return -EACCES; spin_lock(&all_mddevs_lock); - if (!mddev_get(mddev)) { + if (list_empty(&mddev->all_mddevs)) { spin_unlock(&all_mddevs_lock); return -EBUSY; } + mddev_get(mddev); spin_unlock(&all_mddevs_lock); rv = entry->store(mddev, page, length); mddev_put(mddev); @@ -7826,6 +7822,7 @@ static void md_free_disk(struct gendisk *disk) struct mddev *mddev = disk->private_data; percpu_ref_exit(&mddev->writes_pending); + mddev_free(mddev); } @@ -8159,8 +8156,7 @@ static void *md_seq_start(struct seq_file *seq, loff_t *pos) list_for_each(tmp,&all_mddevs) if (!l--) { mddev = list_entry(tmp, struct mddev, all_mddevs); - if (!mddev_get(mddev)) - continue; + mddev_get(mddev); spin_unlock(&all_mddevs_lock); return mddev; } @@ -8174,35 +8170,25 @@ static void *md_seq_next(struct seq_file *seq, void *v, loff_t *pos) { struct list_head *tmp; struct mddev *next_mddev, *mddev = v; - struct mddev *to_put = NULL; ++*pos; if (v == (void*)2) return NULL; spin_lock(&all_mddevs_lock); - if (v == (void*)1) { + if (v == (void*)1) tmp = all_mddevs.next; - } else { - to_put = mddev; - tmp = mddev->all_mddevs.next; - } - - for (;;) { - if (tmp == &all_mddevs) { - next_mddev = (void*)2; - *pos = 0x10000; - break; - } - next_mddev = list_entry(tmp, struct mddev, all_mddevs); - if (mddev_get(next_mddev)) - break; - mddev = next_mddev; + else tmp = mddev->all_mddevs.next; + if (tmp != &all_mddevs) + next_mddev = mddev_get(list_entry(tmp,struct mddev,all_mddevs)); + else { + next_mddev = (void*)2; + *pos = 0x10000; } spin_unlock(&all_mddevs_lock); - if (to_put) + if (v != (void*)1) mddev_put(mddev); return next_mddev; @@ -8772,8 +8758,6 @@ void md_do_sync(struct md_thread *thread) goto skip; spin_lock(&all_mddevs_lock); list_for_each_entry(mddev2, &all_mddevs, all_mddevs) { - if (test_bit(MD_DELETED, &mddev2->flags)) - continue; if (mddev2 == mddev) continue; if (!mddev->parallel_resync @@ -9577,8 +9561,7 @@ static int md_notify_reboot(struct notifier_block *this, spin_lock(&all_mddevs_lock); list_for_each_entry_safe(mddev, n, &all_mddevs, all_mddevs) { - if (!mddev_get(mddev)) - continue; + mddev_get(mddev); spin_unlock(&all_mddevs_lock); if (mddev_trylock(mddev)) { if (mddev->pers) @@ -9934,8 +9917,7 @@ static __exit void md_exit(void) spin_lock(&all_mddevs_lock); list_for_each_entry_safe(mddev, n, &all_mddevs, all_mddevs) { - if (!mddev_get(mddev)) - continue; + mddev_get(mddev); spin_unlock(&all_mddevs_lock); export_array(mddev); mddev->ctime = 0; diff --git a/drivers/md/md.h b/drivers/md/md.h index 1aef86bf3fc3..4e265e38c229 100644 --- a/drivers/md/md.h +++ b/drivers/md/md.h @@ -252,7 +252,6 @@ struct md_cluster_info; * @MD_NOT_READY: do_md_run() is active, so 'array_state', ust not report that * array is ready yet. * @MD_BROKEN: This is used to stop writes and mark array as failed. - * @MD_DELETED: This device is being deleted * * change UNSUPPORTED_MDDEV_FLAGS for each array type if new flag is added */ @@ -269,7 +268,6 @@ enum mddev_flags { MD_UPDATING_SB, MD_NOT_READY, MD_BROKEN, - MD_DELETED, }; enum mddev_sb_flags { -- 2.37.2