Skip to content

Commit c23112e

Browse files
committed
Merge tag 'md/4.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shli/md
Pull MD updates from Shaohua Li: "This update includes: - new AVX512 instruction based raid6 gen/recovery algorithm - a couple of md-cluster related bug fixes - fix a potential deadlock - set nonrotational bit for raid array with SSD - set correct max_hw_sectors for raid5/6, which hopefuly can improve performance a little bit - other minor fixes" * tag 'md/4.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shli/md: md: set rotational bit raid6/test/test.c: bug fix: Specify aligned(alignment) attributes to the char arrays raid5: handle register_shrinker failure raid5: fix to detect failure of register_shrinker md: fix a potential deadlock md/bitmap: fix wrong cleanup raid5: allow arbitrary max_hw_sectors lib/raid6: Add AVX512 optimized xor_syndrome functions lib/raid6/test/Makefile: Add avx512 gen_syndrome and recovery functions lib/raid6: Add AVX512 optimized recovery functions lib/raid6: Add AVX512 optimized gen_syndrome functions md-cluster: make resync lock also could be interruptted md-cluster: introduce dlm_lock_sync_interruptible to fix tasks hang md-cluster: convert the completion to wait queue md-cluster: protect md_find_rdev_nr_rcu with rcu lock md-cluster: clean related infos of cluster md: changes for MD_STILL_CLOSED flag md-cluster: remove some unnecessary dlm_unlock_sync md-cluster: use FORCEUNLOCK in lockres_free md-cluster: call md_kick_rdev_from_array once ack failed
2 parents 4dfddf5 + bb086a8 commit c23112e

14 files changed

Lines changed: 1111 additions & 54 deletions

File tree

‎arch/x86/Makefile‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,12 @@ asinstr += $(call as-instr,pshufb %xmm0$(comma)%xmm0,-DCONFIG_AS_SSSE3=1)
163163
asinstr += $(call as-instr,crc32l %eax$(comma)%eax,-DCONFIG_AS_CRC32=1)
164164
avx_instr := $(call as-instr,vxorps %ymm0$(comma)%ymm1$(comma)%ymm2,-DCONFIG_AS_AVX=1)
165165
avx2_instr :=$(call as-instr,vpbroadcastb %xmm0$(comma)%ymm1,-DCONFIG_AS_AVX2=1)
166+
avx512_instr :=$(call as-instr,vpmovm2b %k1$(comma)%zmm5,-DCONFIG_AS_AVX512=1)
166167
sha1_ni_instr :=$(call as-instr,sha1msg1 %xmm0$(comma)%xmm1,-DCONFIG_AS_SHA1_NI=1)
167168
sha256_ni_instr :=$(call as-instr,sha256msg1 %xmm0$(comma)%xmm1,-DCONFIG_AS_SHA256_NI=1)
168169

169-
KBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(sha1_ni_instr) $(sha256_ni_instr)
170-
KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(sha1_ni_instr) $(sha256_ni_instr)
170+
KBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr)
171+
KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) $(asinstr) $(avx_instr) $(avx2_instr) $(avx512_instr) $(sha1_ni_instr) $(sha256_ni_instr)
171172

172173
LDFLAGS := -m elf_$(UTS_MACHINE)
173174

‎drivers/md/bitmap.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,10 +1903,8 @@ int bitmap_copy_from_slot(struct mddev *mddev, int slot,
19031903
struct bitmap_counts *counts;
19041904
struct bitmap *bitmap = bitmap_create(mddev, slot);
19051905

1906-
if (IS_ERR(bitmap)) {
1907-
bitmap_free(bitmap);
1906+
if (IS_ERR(bitmap))
19081907
return PTR_ERR(bitmap);
1909-
}
19101908

19111909
rv = bitmap_init_from_disk(bitmap, 0);
19121910
if (rv)

‎drivers/md/md-cluster.c‎

Lines changed: 69 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
#include <linux/module.h>
13+
#include <linux/kthread.h>
1314
#include <linux/dlm.h>
1415
#include <linux/sched.h>
1516
#include <linux/raid/md_p.h>
@@ -25,7 +26,8 @@ struct dlm_lock_resource {
2526
struct dlm_lksb lksb;
2627
char *name; /* lock name. */
2728
uint32_t flags; /* flags to pass to dlm_lock() */
28-
struct completion completion; /* completion for synchronized locking */
29+
wait_queue_head_t sync_locking; /* wait queue for synchronized locking */
30+
bool sync_locking_done;
2931
void (*bast)(void *arg, int mode); /* blocking AST function pointer*/
3032
struct mddev *mddev; /* pointing back to mddev. */
3133
int mode;
@@ -118,7 +120,8 @@ static void sync_ast(void *arg)
118120
struct dlm_lock_resource *res;
119121

120122
res = arg;
121-
complete(&res->completion);
123+
res->sync_locking_done = true;
124+
wake_up(&res->sync_locking);
122125
}
123126

124127
static int dlm_lock_sync(struct dlm_lock_resource *res, int mode)
@@ -130,7 +133,8 @@ static int dlm_lock_sync(struct dlm_lock_resource *res, int mode)
130133
0, sync_ast, res, res->bast);
131134
if (ret)
132135
return ret;
133-
wait_for_completion(&res->completion);
136+
wait_event(res->sync_locking, res->sync_locking_done);
137+
res->sync_locking_done = false;
134138
if (res->lksb.sb_status == 0)
135139
res->mode = mode;
136140
return res->lksb.sb_status;
@@ -141,6 +145,44 @@ static int dlm_unlock_sync(struct dlm_lock_resource *res)
141145
return dlm_lock_sync(res, DLM_LOCK_NL);
142146
}
143147

148+
/*
149+
* An variation of dlm_lock_sync, which make lock request could
150+
* be interrupted
151+
*/
152+
static int dlm_lock_sync_interruptible(struct dlm_lock_resource *res, int mode,
153+
struct mddev *mddev)
154+
{
155+
int ret = 0;
156+
157+
ret = dlm_lock(res->ls, mode, &res->lksb,
158+
res->flags, res->name, strlen(res->name),
159+
0, sync_ast, res, res->bast);
160+
if (ret)
161+
return ret;
162+
163+
wait_event(res->sync_locking, res->sync_locking_done
164+
|| kthread_should_stop()
165+
|| test_bit(MD_CLOSING, &mddev->flags));
166+
if (!res->sync_locking_done) {
167+
/*
168+
* the convert queue contains the lock request when request is
169+
* interrupted, and sync_ast could still be run, so need to
170+
* cancel the request and reset completion
171+
*/
172+
ret = dlm_unlock(res->ls, res->lksb.sb_lkid, DLM_LKF_CANCEL,
173+
&res->lksb, res);
174+
res->sync_locking_done = false;
175+
if (unlikely(ret != 0))
176+
pr_info("failed to cancel previous lock request "
177+
"%s return %d\n", res->name, ret);
178+
return -EPERM;
179+
} else
180+
res->sync_locking_done = false;
181+
if (res->lksb.sb_status == 0)
182+
res->mode = mode;
183+
return res->lksb.sb_status;
184+
}
185+
144186
static struct dlm_lock_resource *lockres_init(struct mddev *mddev,
145187
char *name, void (*bastfn)(void *arg, int mode), int with_lvb)
146188
{
@@ -151,7 +193,8 @@ static struct dlm_lock_resource *lockres_init(struct mddev *mddev,
151193
res = kzalloc(sizeof(struct dlm_lock_resource), GFP_KERNEL);
152194
if (!res)
153195
return NULL;
154-
init_completion(&res->completion);
196+
init_waitqueue_head(&res->sync_locking);
197+
res->sync_locking_done = false;
155198
res->ls = cinfo->lockspace;
156199
res->mddev = mddev;
157200
res->mode = DLM_LOCK_IV;
@@ -194,25 +237,21 @@ static struct dlm_lock_resource *lockres_init(struct mddev *mddev,
194237

195238
static void lockres_free(struct dlm_lock_resource *res)
196239
{
197-
int ret;
240+
int ret = 0;
198241

199242
if (!res)
200243
return;
201244

202-
/* cancel a lock request or a conversion request that is blocked */
203-
res->flags |= DLM_LKF_CANCEL;
204-
retry:
205-
ret = dlm_unlock(res->ls, res->lksb.sb_lkid, 0, &res->lksb, res);
206-
if (unlikely(ret != 0)) {
207-
pr_info("%s: failed to unlock %s return %d\n", __func__, res->name, ret);
208-
209-
/* if a lock conversion is cancelled, then the lock is put
210-
* back to grant queue, need to ensure it is unlocked */
211-
if (ret == -DLM_ECANCEL)
212-
goto retry;
213-
}
214-
res->flags &= ~DLM_LKF_CANCEL;
215-
wait_for_completion(&res->completion);
245+
/*
246+
* use FORCEUNLOCK flag, so we can unlock even the lock is on the
247+
* waiting or convert queue
248+
*/
249+
ret = dlm_unlock(res->ls, res->lksb.sb_lkid, DLM_LKF_FORCEUNLOCK,
250+
&res->lksb, res);
251+
if (unlikely(ret != 0))
252+
pr_err("failed to unlock %s return %d\n", res->name, ret);
253+
else
254+
wait_event(res->sync_locking, res->sync_locking_done);
216255

217256
kfree(res->name);
218257
kfree(res->lksb.sb_lvbptr);
@@ -279,7 +318,7 @@ static void recover_bitmaps(struct md_thread *thread)
279318
goto clear_bit;
280319
}
281320

282-
ret = dlm_lock_sync(bm_lockres, DLM_LOCK_PW);
321+
ret = dlm_lock_sync_interruptible(bm_lockres, DLM_LOCK_PW, mddev);
283322
if (ret) {
284323
pr_err("md-cluster: Could not DLM lock %s: %d\n",
285324
str, ret);
@@ -288,7 +327,7 @@ static void recover_bitmaps(struct md_thread *thread)
288327
ret = bitmap_copy_from_slot(mddev, slot, &lo, &hi, true);
289328
if (ret) {
290329
pr_err("md-cluster: Could not copy data from bitmap %d\n", slot);
291-
goto dlm_unlock;
330+
goto clear_bit;
292331
}
293332
if (hi > 0) {
294333
if (lo < mddev->recovery_cp)
@@ -300,8 +339,6 @@ static void recover_bitmaps(struct md_thread *thread)
300339
md_wakeup_thread(mddev->thread);
301340
}
302341
}
303-
dlm_unlock:
304-
dlm_unlock_sync(bm_lockres);
305342
clear_bit:
306343
lockres_free(bm_lockres);
307344
clear_bit(slot, &cinfo->recovery_map);
@@ -495,9 +532,10 @@ static void process_metadata_update(struct mddev *mddev, struct cluster_msg *msg
495532

496533
static void process_remove_disk(struct mddev *mddev, struct cluster_msg *msg)
497534
{
498-
struct md_rdev *rdev = md_find_rdev_nr_rcu(mddev,
499-
le32_to_cpu(msg->raid_slot));
535+
struct md_rdev *rdev;
500536

537+
rcu_read_lock();
538+
rdev = md_find_rdev_nr_rcu(mddev, le32_to_cpu(msg->raid_slot));
501539
if (rdev) {
502540
set_bit(ClusterRemove, &rdev->flags);
503541
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
@@ -506,18 +544,21 @@ static void process_remove_disk(struct mddev *mddev, struct cluster_msg *msg)
506544
else
507545
pr_warn("%s: %d Could not find disk(%d) to REMOVE\n",
508546
__func__, __LINE__, le32_to_cpu(msg->raid_slot));
547+
rcu_read_unlock();
509548
}
510549

511550
static void process_readd_disk(struct mddev *mddev, struct cluster_msg *msg)
512551
{
513-
struct md_rdev *rdev = md_find_rdev_nr_rcu(mddev,
514-
le32_to_cpu(msg->raid_slot));
552+
struct md_rdev *rdev;
515553

554+
rcu_read_lock();
555+
rdev = md_find_rdev_nr_rcu(mddev, le32_to_cpu(msg->raid_slot));
516556
if (rdev && test_bit(Faulty, &rdev->flags))
517557
clear_bit(Faulty, &rdev->flags);
518558
else
519559
pr_warn("%s: %d Could not find disk(%d) which is faulty",
520560
__func__, __LINE__, le32_to_cpu(msg->raid_slot));
561+
rcu_read_unlock();
521562
}
522563

523564
static int process_recvd_msg(struct mddev *mddev, struct cluster_msg *msg)
@@ -770,7 +811,6 @@ static int gather_all_resync_info(struct mddev *mddev, int total_slots)
770811
md_check_recovery(mddev);
771812
}
772813

773-
dlm_unlock_sync(bm_lockres);
774814
lockres_free(bm_lockres);
775815
}
776816
out:
@@ -1006,7 +1046,7 @@ static void metadata_update_cancel(struct mddev *mddev)
10061046
static int resync_start(struct mddev *mddev)
10071047
{
10081048
struct md_cluster_info *cinfo = mddev->cluster_info;
1009-
return dlm_lock_sync(cinfo->resync_lockres, DLM_LOCK_EX);
1049+
return dlm_lock_sync_interruptible(cinfo->resync_lockres, DLM_LOCK_EX, mddev);
10101050
}
10111051

10121052
static int resync_info_update(struct mddev *mddev, sector_t lo, sector_t hi)
@@ -1186,7 +1226,6 @@ static void unlock_all_bitmaps(struct mddev *mddev)
11861226
if (cinfo->other_bitmap_lockres) {
11871227
for (i = 0; i < mddev->bitmap_info.nodes - 1; i++) {
11881228
if (cinfo->other_bitmap_lockres[i]) {
1189-
dlm_unlock_sync(cinfo->other_bitmap_lockres[i]);
11901229
lockres_free(cinfo->other_bitmap_lockres[i]);
11911230
}
11921231
}

‎drivers/md/md.c‎

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5297,6 +5297,21 @@ int md_run(struct mddev *mddev)
52975297
return err;
52985298
}
52995299
if (mddev->queue) {
5300+
bool nonrot = true;
5301+
5302+
rdev_for_each(rdev, mddev) {
5303+
if (rdev->raid_disk >= 0 &&
5304+
!blk_queue_nonrot(bdev_get_queue(rdev->bdev))) {
5305+
nonrot = false;
5306+
break;
5307+
}
5308+
}
5309+
if (mddev->degraded)
5310+
nonrot = false;
5311+
if (nonrot)
5312+
queue_flag_set_unlocked(QUEUE_FLAG_NONROT, mddev->queue);
5313+
else
5314+
queue_flag_clear_unlocked(QUEUE_FLAG_NONROT, mddev->queue);
53005315
mddev->queue->backing_dev_info.congested_data = mddev;
53015316
mddev->queue->backing_dev_info.congested_fn = md_congested;
53025317
}
@@ -5454,12 +5469,14 @@ static void md_clean(struct mddev *mddev)
54545469
mddev->degraded = 0;
54555470
mddev->safemode = 0;
54565471
mddev->private = NULL;
5472+
mddev->cluster_info = NULL;
54575473
mddev->bitmap_info.offset = 0;
54585474
mddev->bitmap_info.default_offset = 0;
54595475
mddev->bitmap_info.default_space = 0;
54605476
mddev->bitmap_info.chunksize = 0;
54615477
mddev->bitmap_info.daemon_sleep = 0;
54625478
mddev->bitmap_info.max_write_behind = 0;
5479+
mddev->bitmap_info.nodes = 0;
54635480
}
54645481

54655482
static void __md_stop_writes(struct mddev *mddev)
@@ -5573,8 +5590,7 @@ static int md_set_readonly(struct mddev *mddev, struct block_device *bdev)
55735590
mutex_lock(&mddev->open_mutex);
55745591
if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) ||
55755592
mddev->sync_thread ||
5576-
test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
5577-
(bdev && !test_bit(MD_STILL_CLOSED, &mddev->flags))) {
5593+
test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
55785594
printk("md: %s still in use.\n",mdname(mddev));
55795595
if (did_freeze) {
55805596
clear_bit(MD_RECOVERY_FROZEN, &mddev->recovery);
@@ -5636,8 +5652,7 @@ static int do_md_stop(struct mddev *mddev, int mode,
56365652
if ((mddev->pers && atomic_read(&mddev->openers) > !!bdev) ||
56375653
mddev->sysfs_active ||
56385654
mddev->sync_thread ||
5639-
test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) ||
5640-
(bdev && !test_bit(MD_STILL_CLOSED, &mddev->flags))) {
5655+
test_bit(MD_RECOVERY_RUNNING, &mddev->recovery)) {
56415656
printk("md: %s still in use.\n",mdname(mddev));
56425657
mutex_unlock(&mddev->open_mutex);
56435658
if (did_freeze) {
@@ -6101,9 +6116,14 @@ static int add_new_disk(struct mddev *mddev, mdu_disk_info_t *info)
61016116
export_rdev(rdev);
61026117

61036118
if (mddev_is_clustered(mddev)) {
6104-
if (info->state & (1 << MD_DISK_CANDIDATE))
6105-
md_cluster_ops->new_disk_ack(mddev, (err == 0));
6106-
else {
6119+
if (info->state & (1 << MD_DISK_CANDIDATE)) {
6120+
if (!err) {
6121+
err = md_cluster_ops->new_disk_ack(mddev,
6122+
err == 0);
6123+
if (err)
6124+
md_kick_rdev_from_array(rdev);
6125+
}
6126+
} else {
61076127
if (err)
61086128
md_cluster_ops->add_new_disk_cancel(mddev);
61096129
else
@@ -6821,7 +6841,7 @@ static int md_ioctl(struct block_device *bdev, fmode_t mode,
68216841
err = -EBUSY;
68226842
goto out;
68236843
}
6824-
set_bit(MD_STILL_CLOSED, &mddev->flags);
6844+
set_bit(MD_CLOSING, &mddev->flags);
68256845
mutex_unlock(&mddev->open_mutex);
68266846
sync_blockdev(bdev);
68276847
}
@@ -7070,9 +7090,13 @@ static int md_open(struct block_device *bdev, fmode_t mode)
70707090
if ((err = mutex_lock_interruptible(&mddev->open_mutex)))
70717091
goto out;
70727092

7093+
if (test_bit(MD_CLOSING, &mddev->flags)) {
7094+
mutex_unlock(&mddev->open_mutex);
7095+
return -ENODEV;
7096+
}
7097+
70737098
err = 0;
70747099
atomic_inc(&mddev->openers);
7075-
clear_bit(MD_STILL_CLOSED, &mddev->flags);
70767100
mutex_unlock(&mddev->open_mutex);
70777101

70787102
check_disk_change(bdev);
@@ -8873,7 +8897,9 @@ static void autostart_arrays(int part)
88738897
list_del(&node_detected_dev->list);
88748898
dev = node_detected_dev->dev;
88758899
kfree(node_detected_dev);
8900+
mutex_unlock(&detected_devices_mutex);
88768901
rdev = md_import_device(dev,0, 90);
8902+
mutex_lock(&detected_devices_mutex);
88778903
if (IS_ERR(rdev))
88788904
continue;
88798905

‎drivers/md/md.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,8 @@ struct mddev {
201201
#define MD_CHANGE_PENDING 2 /* switch from 'clean' to 'active' in progress */
202202
#define MD_UPDATE_SB_FLAGS (1 | 2 | 4) /* If these are set, md_update_sb needed */
203203
#define MD_ARRAY_FIRST_USE 3 /* First use of array, needs initialization */
204-
#define MD_STILL_CLOSED 4 /* If set, then array has not been opened since
205-
* md_ioctl checked on it.
206-
*/
204+
#define MD_CLOSING 4 /* If set, we are closing the array, do not open
205+
* it then */
207206
#define MD_JOURNAL_CLEAN 5 /* A raid with journal is already clean */
208207
#define MD_HAS_JOURNAL 6 /* The raid array has journal feature set */
209208
#define MD_RELOAD_SB 7 /* Reload the superblock because another node

‎drivers/md/raid5.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6370,7 +6370,7 @@ static void free_conf(struct r5conf *conf)
63706370
{
63716371
if (conf->log)
63726372
r5l_exit_log(conf->log);
6373-
if (conf->shrinker.seeks)
6373+
if (conf->shrinker.nr_deferred)
63746374
unregister_shrinker(&conf->shrinker);
63756375

63766376
free_thread_groups(conf);
@@ -6632,7 +6632,12 @@ static struct r5conf *setup_conf(struct mddev *mddev)
66326632
conf->shrinker.count_objects = raid5_cache_count;
66336633
conf->shrinker.batch = 128;
66346634
conf->shrinker.flags = 0;
6635-
register_shrinker(&conf->shrinker);
6635+
if (register_shrinker(&conf->shrinker)) {
6636+
printk(KERN_ERR
6637+
"md/raid:%s: couldn't register shrinker.\n",
6638+
mdname(mddev));
6639+
goto abort;
6640+
}
66366641

66376642
sprintf(pers_name, "raid%d", mddev->new_level);
66386643
conf->thread = md_register_thread(raid5d, mddev, pers_name);
@@ -7028,6 +7033,8 @@ static int raid5_run(struct mddev *mddev)
70287033
else
70297034
queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD,
70307035
mddev->queue);
7036+
7037+
blk_queue_max_hw_sectors(mddev->queue, UINT_MAX);
70317038
}
70327039

70337040
if (journal_dev) {

0 commit comments

Comments
 (0)