@@ -1002,6 +1002,7 @@ void md_rdev_clear(struct md_rdev *rdev)
put_page(rdev->bb_page);
rdev->bb_page = NULL;
}
+ percpu_ref_exit(&rdev->nr_pending);
badblocks_exit(&rdev->badblocks);
}
EXPORT_SYMBOL_GPL(md_rdev_clear);
@@ -3724,8 +3725,14 @@ static const struct kobj_type rdev_ktype = {
.default_groups = rdev_default_groups,
};
+static void percpu_wakeup_handle_req_pending(struct percpu_ref *ref)
+{
+}
+
int md_rdev_init(struct md_rdev *rdev)
{
+ int ret;
+
rdev->desc_nr = -1;
rdev->saved_raid_disk = -1;
rdev->raid_disk = -1;
@@ -3736,7 +3743,11 @@ int md_rdev_init(struct md_rdev *rdev)
rdev->last_read_error = 0;
rdev->sb_loaded = 0;
rdev->bb_page = NULL;
- atomic_set(&rdev->nr_pending, 0);
+ ret = percpu_ref_init(&rdev->nr_pending, percpu_wakeup_handle_req_pending,
+ PERCPU_REF_ALLOW_REINIT, GFP_KERNEL);
+ WARN_ON(ret);
+ percpu_ref_switch_to_atomic_sync(&rdev->nr_pending);
+ nr_pending_dec(rdev);
atomic_set(&rdev->read_errors, 0);
atomic_set(&rdev->corrected_errors, 0);
@@ -107,10 +107,10 @@ struct md_rdev {
*/
};
- atomic_t nr_pending; /* number of pending requests.
- * only maintained for arrays that
- * support hot removal
- */
+ struct percpu_ref nr_pending; /* number of pending requests.
+ * only maintained for arrays that
+ * support hot removal
+ */
atomic_t read_errors; /* number of consecutive read errors that
* we have tried to ignore.
*/
@@ -213,27 +213,27 @@ enum flag_bits {
static inline void nr_pending_inc(struct md_rdev *rdev)
{
- atomic_inc(&rdev->nr_pending);
+ percpu_ref_get(&rdev->nr_pending);
}
static inline void nr_pending_dec(struct md_rdev *rdev)
{
- atomic_dec(&rdev->nr_pending);
+ percpu_ref_put(&rdev->nr_pending);
}
static inline bool nr_pending_is_zero(struct md_rdev *rdev)
{
- return atomic_read(&rdev->nr_pending) == 0;
+ return percpu_ref_is_zero(&rdev->nr_pending);
}
static inline bool nr_pending_is_not_zero(struct md_rdev *rdev)
{
- return atomic_read(&rdev->nr_pending) != 0;
+ return !percpu_ref_is_zero(&rdev->nr_pending);
}
static inline unsigned long nr_pending_read(struct md_rdev *rdev)
{
- return (unsigned long)atomic_read(&rdev->nr_pending);
+ return atomic_long_read(&rdev->nr_pending.data->count);
}
static inline int is_badblock(struct md_rdev *rdev, sector_t s, int sectors,