Skip to contentSkip to conversation

md: generate CHANGE uevents for md device

PATCH Superseded Kinga Stefaniuk 3 participants 4 messages Aug 23, 2024 – Aug 26, 2024 MD RAID

v11 of 14 Superseded Latest is v14 →

lore
Share & tools
lore
#0 lore raw

v11 cover md: generate CHANGE uevents for md device

Patch is caused by changes in mdadm - now mdmonitor is relying on udev events instead of pooling changes on /proc/mdstat file. This change gave possibility to send events to the userspace.
Now, more events will be read by mdmonitor, but mechanism of getting details of the event will remain the same - all devices have to be scanned on new event and their parameters read. It can be changed by adding environmental data, which will fully describe this uevent, as Kuai suggested. This change needs to be analyzed and planned, because it requires a lot of work in md and design changes in mdmonitor - to stop scanning all of the devices on new event and read uevent details directly from udev. Mariusz will take care of this topic, and follow up on this later.
Paul, the test suite which was used is internal and checks if mdmonitor has noticed expected events. For now there is no plan for adding test, which checking events to mdadm.

Kinga Stefaniuk (1):
md: generate CHANGE uevents for md device

 drivers/md/md.c     | 75 +++++++++++++++++++++++++++++++--------------
 drivers/md/md.h     |  3 +-
 drivers/md/raid10.c |  2 +-
 drivers/md/raid5.c  |  2 +-
 4 files changed, 56 insertions(+), 26 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v11 1/1 md: generate CHANGE uevents for md device

In mdadm commit 49b69533e8 ("mdmonitor: check if udev has finished events processing") mdmonitor has been learnt to wait for udev to finish processing, and later in commit 9935cf0f64f3 ("Mdmonitor: Improve udev event handling") pooling for MD events on /proc/mdstat file has been deprecated because relying on udev events is more reliable and less bug prone (we are not competing with udev).

After those changes we are still observing missing mdmonitor events in some scenarios, especially SpareEvent is likely to be missed. With this patch MD will be able to generate more change uevents and wakeup mdmonitor more frequently to give it possibility to notice events. MD has md_new_events() functionality to trigger events and with this patch this function is extended to generate udev CHANGE uevents. It cannot be done directly because this function is called on interrupts context, so appropriate workqueue is created. Uevents are less time critical, it is safe to use workqueue. It is limited to CHANGE event as there is no need to generate other uevents for now.
With this change, mdmonitor events are less likely to be missed. Our internal tests suite confirms that, mdmonitor reliability is (again) improved.

---
v11: use irq methods to lock/unlock all_mddevs_lock
v10: move mddev_get into md_new_event
v9: add using md_wq and fix if (sync) condition
v8: fix possible conflict with del_work by adding spin_lock,
change default sync value to true, now false only on md_error
v7: add new work struct for these events, use md_misc_wq workqueue,
fix work cancellation
v6: use another workqueue and only on md_error, make configurable
if kobject_uevent is run immediately on event or queued
v5: fix flush_work missing and commit message fixes
v4: add more detailed commit message
v3: fix problems with calling function from interrupt context,
add work_queue and queue events notification
v2: resolve merge conflicts with applying the patch

---
 drivers/md/md.c     | 75 +++++++++++++++++++++++++++++++--------------
 drivers/md/md.h     |  3 +-
 drivers/md/raid10.c |  2 +-
 drivers/md/raid5.c  |  2 +-
 4 files changed, 56 insertions(+), 26 deletions(-)
drivers/md/md.c +52 -23
index d3a837506a36..8b146120cc62 100644
@@ -107,6 +107,7 @@ static int remove_and_add_spares(struct mddev *mddev,
 static void mddev_detach(struct mddev *mddev);
 static void export_rdev(struct md_rdev *rdev, struct mddev *mddev);
 static void md_wakeup_thread_directly(struct md_thread __rcu *thread);
+static inline struct mddev *mddev_get(struct mddev *mddev);
 
 /*
  * Default number of read corrections we'll attempt on an rdev
@@ -323,6 +324,24 @@ static int start_readonly;
  */
 static bool create_on_open = true;
 
+/*
+ * Enables to iterate over all existing md arrays
+ * all_mddevs_lock protects this list.
+ */
+static LIST_HEAD(all_mddevs);
+static DEFINE_SPINLOCK(all_mddevs_lock);
+
+/*
+ * Send every new event to the userspace.
+ */
+static void md_kobject_uevent_fn(struct work_struct *work)
+{
+	struct mddev *mddev = container_of(work, struct mddev, uevent_work);
+
+	kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE);
+	mddev_put(mddev);
+}
+
 /*
  * We have a system wide 'event count' that is incremented
  * on any 'interesting' event, and readers of /proc/mdstat
@@ -335,20 +354,29 @@ static bool create_on_open = true;
  */
 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
 static atomic_t md_event_count;
-void md_new_event(void)
+
+void md_new_event(struct mddev *mddev, bool sync)
 {
 	atomic_inc(&md_event_count);
 	wake_up(&md_event_waiters);
+
+	if (mddev_is_dm(mddev))
+		return;
+
+	if (!sync) {
+		unsigned long flags;
+
+		spin_lock_irq(&all_mddevs_lock);
+		mddev = mddev_get(mddev);
+		spin_unlock_irq(&all_mddevs_lock);
+		if (mddev == NULL)
+			return;
+		queue_work(md_wq, &mddev->uevent_work);
+	}
+	kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE);
 }
 EXPORT_SYMBOL_GPL(md_new_event);
 
-/*
- * Enables to iterate over all existing md arrays
- * all_mddevs_lock protects this list.
- */
-static LIST_HEAD(all_mddevs);
-static DEFINE_SPINLOCK(all_mddevs_lock);
-
 static bool is_md_suspended(struct mddev *mddev)
 {
 	return percpu_ref_is_dying(&mddev->active_io);
@@ -720,7 +748,7 @@ void mddev_put(struct mddev *mddev)
 		return;
 
 	__mddev_put(mddev);
-	spin_unlock(&all_mddevs_lock);
+	spin_unlock_irq(&all_mddevs_lock);
 }
 
 static void md_safemode_timeout(struct timer_list *t);
@@ -773,6 +801,7 @@ int mddev_init(struct mddev *mddev)
 	mddev->resync_max = MaxSector;
 	mddev->level = LEVEL_NONE;
 
+	INIT_WORK(&mddev->uevent_work, md_kobject_uevent_fn);
 	INIT_WORK(&mddev->sync_work, md_start_sync);
 	INIT_WORK(&mddev->del_work, mddev_delayed_delete);
 
@@ -2898,7 +2927,7 @@ static int add_bound_rdev(struct md_rdev *rdev)
 	if (mddev->degraded)
 		set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
 	set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
-	md_new_event();
+	md_new_event(mddev, true);
 	return 0;
 }
 
@@ -3015,7 +3044,7 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len)
 				md_kick_rdev_from_array(rdev);
 				if (mddev->pers)
 					set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
-				md_new_event();
+				md_new_event(mddev, true);
 			}
 		}
 	} else if (cmd_match(buf, "writemostly")) {
@@ -4131,7 +4160,7 @@ level_store(struct mddev *mddev, const char *buf, size_t len)
 	if (!mddev->thread)
 		md_update_sb(mddev, 1);
 	sysfs_notify_dirent_safe(mddev->sysfs_level);
-	md_new_event();
+	md_new_event(mddev, true);
 	rv = len;
 out_unlock:
 	mddev_unlock_and_resume(mddev);
@@ -4658,7 +4687,7 @@ new_dev_store(struct mddev *mddev, const char *buf, size_t len)
 		export_rdev(rdev, mddev);
 	mddev_unlock_and_resume(mddev);
 	if (!err)
-		md_new_event();
+		md_new_event(mddev, true);
 	return err ? err : len;
 }
 
@@ -6276,7 +6305,7 @@ int md_run(struct mddev *mddev)
 	if (mddev->sb_flags)
 		md_update_sb(mddev, 0);
 
-	md_new_event();
+	md_new_event(mddev, true);
 	return 0;
 
 bitmap_abort:
@@ -6635,7 +6664,7 @@ static int do_md_stop(struct mddev *mddev, int mode)
 		if (mddev->hold_active == UNTIL_STOP)
 			mddev->hold_active = 0;
 	}
-	md_new_event();
+	md_new_event(mddev, true);
 	sysfs_notify_dirent_safe(mddev->sysfs_state);
 	return 0;
 }
@@ -7131,7 +7160,7 @@ static int hot_remove_disk(struct mddev *mddev, dev_t dev)
 	set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
 	if (!mddev->thread)
 		md_update_sb(mddev, 1);
-	md_new_event();
+	md_new_event(mddev, true);
 
 	return 0;
 busy:
@@ -7202,7 +7231,7 @@ static int hot_add_disk(struct mddev *mddev, dev_t dev)
 	 * array immediately.
 	 */
 	set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
-	md_new_event();
+	md_new_event(mddev, true);
 	return 0;
 
 abort_export:
@@ -8176,7 +8205,7 @@ void md_error(struct mddev *mddev, struct md_rdev *rdev)
 	}
 	if (mddev->event_work.func)
 		queue_work(md_misc_wq, &mddev->event_work);
-	md_new_event();
+	md_new_event(mddev, false);
 }
 EXPORT_SYMBOL(md_error);
 
@@ -9073,7 +9102,7 @@ void md_do_sync(struct md_thread *thread)
 		mddev->curr_resync = MD_RESYNC_ACTIVE; /* no longer delayed */
 	mddev->curr_resync_completed = j;
 	sysfs_notify_dirent_safe(mddev->sysfs_completed);
-	md_new_event();
+	md_new_event(mddev, true);
 	update_time = jiffies;
 
 	blk_start_plug(&plug);
@@ -9145,7 +9174,7 @@ void md_do_sync(struct md_thread *thread)
 			/* this is the earliest that rebuild will be
 			 * visible in /proc/mdstat
 			 */
-			md_new_event();
+			md_new_event(mddev, true);
 
 		if (last_check + window > io_sectors || j == max_sectors)
 			continue;
@@ -9411,7 +9440,7 @@ static int remove_and_add_spares(struct mddev *mddev,
 			sysfs_link_rdev(mddev, rdev);
 			if (!test_bit(Journal, &rdev->flags))
 				spares++;
-			md_new_event();
+			md_new_event(mddev, true);
 			set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
 		}
 	}
@@ -9530,7 +9559,7 @@ static void md_start_sync(struct work_struct *ws)
 		__mddev_resume(mddev, false);
 	md_wakeup_thread(mddev->sync_thread);
 	sysfs_notify_dirent_safe(mddev->sysfs_action);
-	md_new_event();
+	md_new_event(mddev, true);
 	return;
 
 not_running:
@@ -9782,7 +9811,7 @@ void md_reap_sync_thread(struct mddev *mddev)
 	set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
 	sysfs_notify_dirent_safe(mddev->sysfs_completed);
 	sysfs_notify_dirent_safe(mddev->sysfs_action);
-	md_new_event();
+	md_new_event(mddev, true);
 	if (mddev->event_work.func)
 		queue_work(md_misc_wq, &mddev->event_work);
 	wake_up(&resync_wait);
drivers/md/md.h +2 -1
index a0d6827dced9..ab340618828c 100644
@@ -582,6 +582,7 @@ struct mddev {
 						*/
 	struct work_struct flush_work;
 	struct work_struct event_work;	/* used by dm to report failure event */
+	struct work_struct uevent_work;
 	mempool_t *serial_info_pool;
 	void (*sync_super)(struct mddev *mddev, struct md_rdev *rdev);
 	struct md_cluster_info		*cluster_info;
@@ -883,7 +884,7 @@ extern int md_super_wait(struct mddev *mddev);
 extern int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
 		struct page *page, blk_opf_t opf, bool metadata_op);
 extern void md_do_sync(struct md_thread *thread);
-extern void md_new_event(void);
+extern void md_new_event(struct mddev *mddev, bool sync);
 extern void md_allow_write(struct mddev *mddev);
 extern void md_wait_for_blocked_rdev(struct md_rdev *rdev, struct mddev *mddev);
 extern void md_set_array_sectors(struct mddev *mddev, sector_t array_sectors);
drivers/md/raid10.c +1 -1
index 2a9c4ee982e0..f76571079845 100644
@@ -4542,7 +4542,7 @@ static int raid10_start_reshape(struct mddev *mddev)
 	set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
 	set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
 	conf->reshape_checkpoint = jiffies;
-	md_new_event();
+	md_new_event(mddev, true);
 	return 0;
 
 abort:
drivers/md/raid5.c +1 -1
index c14cf2410365..9da091b000d7 100644
@@ -8525,7 +8525,7 @@ static int raid5_start_reshape(struct mddev *mddev)
 	set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
 	set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
 	conf->reshape_checkpoint = jiffies;
-	md_new_event();
+	md_new_event(mddev, true);
 	return 0;
 }
 
Signature · 1 line
2.43.0
#2 lore raw

Hi,

Quoted 98 lines · Kinga Stefaniuk

In mdadm commit 49b69533e8 ("mdmonitor: check if udev has finished events processing") mdmonitor has been learnt to wait for udev to finish processing, and later in commit 9935cf0f64f3 ("Mdmonitor: Improve udev event handling") pooling for MD events on /proc/mdstat file has been deprecated because relying on udev events is more reliable and less bug prone (we are not competing with udev).

After those changes we are still observing missing mdmonitor events in some scenarios, especially SpareEvent is likely to be missed. With this patch MD will be able to generate more change uevents and wakeup mdmonitor more frequently to give it possibility to notice events. MD has md_new_events() functionality to trigger events and with this patch this function is extended to generate udev CHANGE uevents. It cannot be done directly because this function is called on interrupts context, so appropriate workqueue is created. Uevents are less time critical, it is safe to use workqueue. It is limited to CHANGE event as there is no need to generate other uevents for now.
With this change, mdmonitor events are less likely to be missed. Our internal tests suite confirms that, mdmonitor reliability is (again) improved.

---
v11: use irq methods to lock/unlock all_mddevs_lock
v10: move mddev_get into md_new_event
v9: add using md_wq and fix if (sync) condition
v8: fix possible conflict with del_work by adding spin_lock,
change default sync value to true, now false only on md_error
v7: add new work struct for these events, use md_misc_wq workqueue,
fix work cancellation
v6: use another workqueue and only on md_error, make configurable
if kobject_uevent is run immediately on event or queued
v5: fix flush_work missing and commit message fixes
v4: add more detailed commit message
v3: fix problems with calling function from interrupt context,
add work_queue and queue events notification
v2: resolve merge conflicts with applying the patch

---
  drivers/md/md.c     | 75 +++++++++++++++++++++++++++++++--------------
  drivers/md/md.h     |  3 +-
  drivers/md/raid10.c |  2 +-
  drivers/md/raid5.c  |  2 +-
  4 files changed, 56 insertions(+), 26 deletions(-)
drivers/md/md.c +24 -1
index d3a837506a36..8b146120cc62 100644
@@ -107,6 +107,7 @@ static int remove_and_add_spares(struct mddev *mddev,
  static void mddev_detach(struct mddev *mddev);
  static void export_rdev(struct md_rdev *rdev, struct mddev *mddev);
  static void md_wakeup_thread_directly(struct md_thread __rcu *thread);
+static inline struct mddev *mddev_get(struct mddev *mddev);
 
  /*
   * Default number of read corrections we'll attempt on an rdev
@@ -323,6 +324,24 @@ static int start_readonly;
   */
  static bool create_on_open = true;
 
+/*
+ * Enables to iterate over all existing md arrays
+ * all_mddevs_lock protects this list.
+ */
+static LIST_HEAD(all_mddevs);
+static DEFINE_SPINLOCK(all_mddevs_lock);
+
+/*
+ * Send every new event to the userspace.
+ */
+static void md_kobject_uevent_fn(struct work_struct *work)
+{
+	struct mddev *mddev = container_of(work, struct mddev, uevent_work);
+
+	kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE);
+	mddev_put(mddev);
+}
+
  /*
   * We have a system wide 'event count' that is incremented
   * on any 'interesting' event, and readers of /proc/mdstat
@@ -335,20 +354,29 @@ static bool create_on_open = true;
   */
  static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
  static atomic_t md_event_count;
-void md_new_event(void)
+
+void md_new_event(struct mddev *mddev, bool sync)
  {
  	atomic_inc(&md_event_count);
  	wake_up(&md_event_waiters);
+
+	if (mddev_is_dm(mddev))
+		return;

drivers/md/md.c static bool create_on_open = true; · line 374

Quoted 10 lines
drivers/md/md.c +10 -0
+
+	if (!sync) {
+		unsigned long flags;
+
+		spin_lock_irq(&all_mddevs_lock);
+		mddev = mddev_get(mddev);
+		spin_unlock_irq(&all_mddevs_lock);
+		if (mddev == NULL)
+			return;
+		queue_work(md_wq, &mddev->uevent_work);

You forgot to return here. And you should use spin_lock_irqsave() and spin_unlock_irqrestore() instead, because this is interupt context.

drivers/md/md.c void mddev_put(struct mddev *mddev)

Quoted 16 lines
drivers/md/md.c +2 -7
+	}
+	kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE);
  }
  EXPORT_SYMBOL_GPL(md_new_event);
 
-/*
- * Enables to iterate over all existing md arrays
- * all_mddevs_lock protects this list.
- */
-static LIST_HEAD(all_mddevs);
-static DEFINE_SPINLOCK(all_mddevs_lock);
-
  static bool is_md_suspended(struct mddev *mddev)
  {
  	return percpu_ref_is_dying(&mddev->active_io);
@@ -720,7 +748,7 @@ void mddev_put(struct mddev *mddev)

atomic_dec_and_lock() from mddev_put() also need to use irq version. And also all the other places as well.

sed -i 's/spin_lock(\&all_mddevs_lock)/spin_lock_irq(\&all_mddevs_lock)/g' drivers/md/md.c sed -i 's/spin_unlock(\&all_mddevs_lock)/spin_unlock_irq(\&all_mddevs_lock)/g' drivers/md/md.c

Thanks,
Kuai

Quoted 190 lines
drivers/md/md.c +16 -15
  		return;
 
  	__mddev_put(mddev);
-	spin_unlock(&all_mddevs_lock);
+	spin_unlock_irq(&all_mddevs_lock);
  }
 
  static void md_safemode_timeout(struct timer_list *t);
@@ -773,6 +801,7 @@ int mddev_init(struct mddev *mddev)
  	mddev->resync_max = MaxSector;
  	mddev->level = LEVEL_NONE;
 
+	INIT_WORK(&mddev->uevent_work, md_kobject_uevent_fn);
  	INIT_WORK(&mddev->sync_work, md_start_sync);
  	INIT_WORK(&mddev->del_work, mddev_delayed_delete);
 
@@ -2898,7 +2927,7 @@ static int add_bound_rdev(struct md_rdev *rdev)
  	if (mddev->degraded)
  		set_bit(MD_RECOVERY_RECOVER, &mddev->recovery);
  	set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
-	md_new_event();
+	md_new_event(mddev, true);
  	return 0;
  }
 
@@ -3015,7 +3044,7 @@ state_store(struct md_rdev *rdev, const char *buf, size_t len)
  				md_kick_rdev_from_array(rdev);
  				if (mddev->pers)
  					set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
-				md_new_event();
+				md_new_event(mddev, true);
  			}
  		}
  	} else if (cmd_match(buf, "writemostly")) {
@@ -4131,7 +4160,7 @@ level_store(struct mddev *mddev, const char *buf, size_t len)
  	if (!mddev->thread)
  		md_update_sb(mddev, 1);
  	sysfs_notify_dirent_safe(mddev->sysfs_level);
-	md_new_event();
+	md_new_event(mddev, true);
  	rv = len;
  out_unlock:
  	mddev_unlock_and_resume(mddev);
@@ -4658,7 +4687,7 @@ new_dev_store(struct mddev *mddev, const char *buf, size_t len)
  		export_rdev(rdev, mddev);
  	mddev_unlock_and_resume(mddev);
  	if (!err)
-		md_new_event();
+		md_new_event(mddev, true);
  	return err ? err : len;
  }
 
@@ -6276,7 +6305,7 @@ int md_run(struct mddev *mddev)
  	if (mddev->sb_flags)
  		md_update_sb(mddev, 0);
 
-	md_new_event();
+	md_new_event(mddev, true);
  	return 0;
 
  bitmap_abort:
@@ -6635,7 +6664,7 @@ static int do_md_stop(struct mddev *mddev, int mode)
  		if (mddev->hold_active == UNTIL_STOP)
  			mddev->hold_active = 0;
  	}
-	md_new_event();
+	md_new_event(mddev, true);
  	sysfs_notify_dirent_safe(mddev->sysfs_state);
  	return 0;
  }
@@ -7131,7 +7160,7 @@ static int hot_remove_disk(struct mddev *mddev, dev_t dev)
  	set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
  	if (!mddev->thread)
  		md_update_sb(mddev, 1);
-	md_new_event();
+	md_new_event(mddev, true);
 
  	return 0;
  busy:
@@ -7202,7 +7231,7 @@ static int hot_add_disk(struct mddev *mddev, dev_t dev)
  	 * array immediately.
  	 */
  	set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
-	md_new_event();
+	md_new_event(mddev, true);
  	return 0;
 
  abort_export:
@@ -8176,7 +8205,7 @@ void md_error(struct mddev *mddev, struct md_rdev *rdev)
  	}
  	if (mddev->event_work.func)
  		queue_work(md_misc_wq, &mddev->event_work);
-	md_new_event();
+	md_new_event(mddev, false);
  }
  EXPORT_SYMBOL(md_error);
 
@@ -9073,7 +9102,7 @@ void md_do_sync(struct md_thread *thread)
  		mddev->curr_resync = MD_RESYNC_ACTIVE; /* no longer delayed */
  	mddev->curr_resync_completed = j;
  	sysfs_notify_dirent_safe(mddev->sysfs_completed);
-	md_new_event();
+	md_new_event(mddev, true);
  	update_time = jiffies;
 
  	blk_start_plug(&plug);
@@ -9145,7 +9174,7 @@ void md_do_sync(struct md_thread *thread)
  			/* this is the earliest that rebuild will be
  			 * visible in /proc/mdstat
  			 */
-			md_new_event();
+			md_new_event(mddev, true);
 
  		if (last_check + window > io_sectors || j == max_sectors)
  			continue;
@@ -9411,7 +9440,7 @@ static int remove_and_add_spares(struct mddev *mddev,
  			sysfs_link_rdev(mddev, rdev);
  			if (!test_bit(Journal, &rdev->flags))
  				spares++;
-			md_new_event();
+			md_new_event(mddev, true);
  			set_bit(MD_SB_CHANGE_DEVS, &mddev->sb_flags);
  		}
  	}
@@ -9530,7 +9559,7 @@ static void md_start_sync(struct work_struct *ws)
  		__mddev_resume(mddev, false);
  	md_wakeup_thread(mddev->sync_thread);
  	sysfs_notify_dirent_safe(mddev->sysfs_action);
-	md_new_event();
+	md_new_event(mddev, true);
  	return;
 
  not_running:
@@ -9782,7 +9811,7 @@ void md_reap_sync_thread(struct mddev *mddev)
  	set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
  	sysfs_notify_dirent_safe(mddev->sysfs_completed);
  	sysfs_notify_dirent_safe(mddev->sysfs_action);
-	md_new_event();
+	md_new_event(mddev, true);
  	if (mddev->event_work.func)
  		queue_work(md_misc_wq, &mddev->event_work);
  	wake_up(&resync_wait);
drivers/md/md.h +2 -1
index a0d6827dced9..ab340618828c 100644
@@ -582,6 +582,7 @@ struct mddev {
  						*/
  	struct work_struct flush_work;
  	struct work_struct event_work;	/* used by dm to report failure event */
+	struct work_struct uevent_work;
  	mempool_t *serial_info_pool;
  	void (*sync_super)(struct mddev *mddev, struct md_rdev *rdev);
  	struct md_cluster_info		*cluster_info;
@@ -883,7 +884,7 @@ extern int md_super_wait(struct mddev *mddev);
  extern int sync_page_io(struct md_rdev *rdev, sector_t sector, int size,
  		struct page *page, blk_opf_t opf, bool metadata_op);
  extern void md_do_sync(struct md_thread *thread);
-extern void md_new_event(void);
+extern void md_new_event(struct mddev *mddev, bool sync);
  extern void md_allow_write(struct mddev *mddev);
  extern void md_wait_for_blocked_rdev(struct md_rdev *rdev, struct mddev *mddev);
  extern void md_set_array_sectors(struct mddev *mddev, sector_t array_sectors);
drivers/md/raid10.c +1 -1
index 2a9c4ee982e0..f76571079845 100644
@@ -4542,7 +4542,7 @@ static int raid10_start_reshape(struct mddev *mddev)
  	set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
  	set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
  	conf->reshape_checkpoint = jiffies;
-	md_new_event();
+	md_new_event(mddev, true);
  	return 0;
 
  abort:
drivers/md/raid5.c +1 -1
index c14cf2410365..9da091b000d7 100644
@@ -8525,7 +8525,7 @@ static int raid5_start_reshape(struct mddev *mddev)
  	set_bit(MD_RECOVERY_RESHAPE, &mddev->recovery);
  	set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
  	conf->reshape_checkpoint = jiffies;
-	md_new_event();
+	md_new_event(mddev, true);
  	return 0;
  }
 
#3 lore raw
In reply to Kinga Stefaniuk
kernel test robot noticed the following build warnings:

Hi Kinga,

kernel test robot noticed the following build warnings:

[auto build test WARNING on v6.11-rc5]
[also build test WARNING on linus/master]
[cannot apply to song-md/md-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Kinga-Stefaniuk/md-generate-CHANGE-uevents-for-md-device/20240826-145852
base:   v6.11-rc5
patch link:    https://lore.kernel.org/r/20240823145438.23432-2-kinga.stefaniuk%40intel.com
patch subject: [PATCH v11 1/1] md: generate CHANGE uevents for md device
config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20240826/[email protected]/config)
compiler: sh4-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240826/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/md/md.c: In function 'md_new_event':

>> drivers/md/md.c:367:31: warning: unused variable 'flags' [-Wunused-variable]
     367 |                 unsigned long flags;
         |                               ^~~~~

vim +/flags +367 drivers/md/md.c

357
358 void md_new_event(struct mddev *mddev, bool sync)
359 {
360 atomic_inc(&md_event_count);
361 wake_up(&md_event_waiters);
362
363 if (mddev_is_dm(mddev))
364 return;
365
366 if (!sync) {

 > 367			unsigned long flags;

368
369 spin_lock_irq(&all_mddevs_lock);
370 mddev = mddev_get(mddev);
371 spin_unlock_irq(&all_mddevs_lock);
372 if (mddev == NULL)
373 return;
374 queue_work(md_wq, &mddev->uevent_work);
375 }
376 kobject_uevent(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE);
377 }
378 EXPORT_SYMBOL_GPL(md_new_event);
379

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki