2019-05-21 01:08:10 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-03-08 01:21:15 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015, SUSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
2016-08-12 13:42:42 +08:00
|
|
|
#include <linux/kthread.h>
|
2014-03-08 03:49:26 +08:00
|
|
|
#include <linux/dlm.h>
|
|
|
|
#include <linux/sched.h>
|
2014-10-30 07:51:31 +08:00
|
|
|
#include <linux/raid/md_p.h>
|
2014-03-08 03:49:26 +08:00
|
|
|
#include "md.h"
|
2017-10-11 05:02:41 +08:00
|
|
|
#include "md-bitmap.h"
|
2014-03-29 23:01:53 +08:00
|
|
|
#include "md-cluster.h"
|
2014-03-08 03:49:26 +08:00
|
|
|
|
|
|
|
#define LVB_SIZE 64
|
2014-10-30 07:51:31 +08:00
|
|
|
#define NEW_DEV_TIMEOUT 5000
|
2014-03-08 03:49:26 +08:00
|
|
|
|
|
|
|
struct dlm_lock_resource {
|
|
|
|
dlm_lockspace_t *ls;
|
|
|
|
struct dlm_lksb lksb;
|
|
|
|
char *name; /* lock name. */
|
|
|
|
uint32_t flags; /* flags to pass to dlm_lock() */
|
2016-08-12 13:42:41 +08:00
|
|
|
wait_queue_head_t sync_locking; /* wait queue for synchronized locking */
|
|
|
|
bool sync_locking_done;
|
2014-03-29 23:20:02 +08:00
|
|
|
void (*bast)(void *arg, int mode); /* blocking AST function pointer*/
|
|
|
|
struct mddev *mddev; /* pointing back to mddev. */
|
2015-10-02 02:20:27 +08:00
|
|
|
int mode;
|
2014-03-29 23:20:02 +08:00
|
|
|
};
|
|
|
|
|
2014-06-07 01:35:34 +08:00
|
|
|
struct resync_info {
|
|
|
|
__le64 lo;
|
|
|
|
__le64 hi;
|
|
|
|
};
|
|
|
|
|
2015-03-03 00:55:49 +08:00
|
|
|
/* md_cluster_info flags */
|
|
|
|
#define MD_CLUSTER_WAITING_FOR_NEWDISK 1
|
2015-06-24 22:30:32 +08:00
|
|
|
#define MD_CLUSTER_SUSPEND_READ_BALANCING 2
|
2015-07-10 17:01:21 +08:00
|
|
|
#define MD_CLUSTER_BEGIN_JOIN_CLUSTER 3
|
2015-03-03 00:55:49 +08:00
|
|
|
|
2015-12-21 07:51:00 +08:00
|
|
|
/* Lock the send communication. This is done through
|
|
|
|
* bit manipulation as opposed to a mutex in order to
|
|
|
|
* accomodate lock and hold. See next comment.
|
|
|
|
*/
|
|
|
|
#define MD_CLUSTER_SEND_LOCK 4
|
2015-12-21 07:51:01 +08:00
|
|
|
/* If cluster operations (such as adding a disk) must lock the
|
|
|
|
* communication channel, so as to perform extra operations
|
|
|
|
* (update metadata) and no other operation is allowed on the
|
|
|
|
* MD. Token needs to be locked and held until the operation
|
|
|
|
* completes witha md_update_sb(), which would eventually release
|
|
|
|
* the lock.
|
2015-12-21 07:51:00 +08:00
|
|
|
*/
|
|
|
|
#define MD_CLUSTER_SEND_LOCKED_ALREADY 5
|
2016-05-04 14:17:09 +08:00
|
|
|
/* We should receive message after node joined cluster and
|
|
|
|
* set up all the related infos such as bitmap and personality */
|
|
|
|
#define MD_CLUSTER_ALREADY_IN_CLUSTER 6
|
|
|
|
#define MD_CLUSTER_PENDING_RECV_EVENT 7
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
#define MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD 8
|
2015-03-03 00:55:49 +08:00
|
|
|
|
2014-03-29 23:20:02 +08:00
|
|
|
struct md_cluster_info {
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
struct mddev *mddev; /* the md device which md_cluster_info belongs to */
|
2014-03-29 23:20:02 +08:00
|
|
|
/* dlm lock space and resources for clustered raid. */
|
|
|
|
dlm_lockspace_t *lockspace;
|
2014-03-30 13:42:49 +08:00
|
|
|
int slot_number;
|
|
|
|
struct completion completion;
|
2015-12-21 07:51:00 +08:00
|
|
|
struct mutex recv_mutex;
|
2014-06-07 01:12:32 +08:00
|
|
|
struct dlm_lock_resource *bitmap_lockres;
|
2015-12-21 07:51:00 +08:00
|
|
|
struct dlm_lock_resource **other_bitmap_lockres;
|
2015-10-01 02:20:35 +08:00
|
|
|
struct dlm_lock_resource *resync_lockres;
|
2014-06-07 01:35:34 +08:00
|
|
|
struct list_head suspend_list;
|
2018-10-18 16:37:48 +08:00
|
|
|
|
2014-06-07 01:35:34 +08:00
|
|
|
spinlock_t suspend_lock;
|
2018-10-18 16:37:48 +08:00
|
|
|
/* record the region which write should be suspended */
|
|
|
|
sector_t suspend_lo;
|
|
|
|
sector_t suspend_hi;
|
|
|
|
int suspend_from; /* the slot which broadcast suspend_lo/hi */
|
|
|
|
|
2014-06-07 13:45:22 +08:00
|
|
|
struct md_thread *recovery_thread;
|
|
|
|
unsigned long recovery_map;
|
2014-06-07 14:08:29 +08:00
|
|
|
/* communication loc resources */
|
|
|
|
struct dlm_lock_resource *ack_lockres;
|
|
|
|
struct dlm_lock_resource *message_lockres;
|
|
|
|
struct dlm_lock_resource *token_lockres;
|
2014-10-30 07:51:31 +08:00
|
|
|
struct dlm_lock_resource *no_new_dev_lockres;
|
2014-06-07 14:08:29 +08:00
|
|
|
struct md_thread *recv_thread;
|
2014-10-30 07:51:31 +08:00
|
|
|
struct completion newdisk_completion;
|
2015-12-21 07:51:00 +08:00
|
|
|
wait_queue_head_t wait;
|
2015-03-03 00:55:49 +08:00
|
|
|
unsigned long state;
|
2016-05-02 23:50:12 +08:00
|
|
|
/* record the region in RESYNCING message */
|
|
|
|
sector_t sync_low;
|
|
|
|
sector_t sync_hi;
|
2014-06-07 14:08:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
enum msg_type {
|
|
|
|
METADATA_UPDATED = 0,
|
|
|
|
RESYNCING,
|
2014-10-30 07:51:31 +08:00
|
|
|
NEWDISK,
|
2015-04-14 23:44:44 +08:00
|
|
|
REMOVE,
|
2015-04-14 23:45:42 +08:00
|
|
|
RE_ADD,
|
2015-07-10 16:54:04 +08:00
|
|
|
BITMAP_NEEDS_SYNC,
|
2017-03-01 16:42:38 +08:00
|
|
|
CHANGE_CAPACITY,
|
2018-10-18 16:37:41 +08:00
|
|
|
BITMAP_RESIZE,
|
2014-06-07 14:08:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cluster_msg {
|
2015-10-16 15:40:22 +08:00
|
|
|
__le32 type;
|
|
|
|
__le32 slot;
|
2014-10-30 07:51:31 +08:00
|
|
|
/* TODO: Unionize this for smaller footprint */
|
2015-10-16 15:40:22 +08:00
|
|
|
__le64 low;
|
|
|
|
__le64 high;
|
2014-10-30 07:51:31 +08:00
|
|
|
char uuid[16];
|
2015-10-16 15:40:22 +08:00
|
|
|
__le32 raid_slot;
|
2014-03-08 03:49:26 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void sync_ast(void *arg)
|
|
|
|
{
|
|
|
|
struct dlm_lock_resource *res;
|
|
|
|
|
2015-10-19 12:42:18 +08:00
|
|
|
res = arg;
|
2016-08-12 13:42:41 +08:00
|
|
|
res->sync_locking_done = true;
|
|
|
|
wake_up(&res->sync_locking);
|
2014-03-08 03:49:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dlm_lock_sync(struct dlm_lock_resource *res, int mode)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ret = dlm_lock(res->ls, mode, &res->lksb,
|
|
|
|
res->flags, res->name, strlen(res->name),
|
|
|
|
0, sync_ast, res, res->bast);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2016-08-12 13:42:41 +08:00
|
|
|
wait_event(res->sync_locking, res->sync_locking_done);
|
|
|
|
res->sync_locking_done = false;
|
2015-10-02 02:20:27 +08:00
|
|
|
if (res->lksb.sb_status == 0)
|
|
|
|
res->mode = mode;
|
2014-03-08 03:49:26 +08:00
|
|
|
return res->lksb.sb_status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dlm_unlock_sync(struct dlm_lock_resource *res)
|
|
|
|
{
|
|
|
|
return dlm_lock_sync(res, DLM_LOCK_NL);
|
|
|
|
}
|
|
|
|
|
2016-08-12 13:42:42 +08:00
|
|
|
/*
|
|
|
|
* An variation of dlm_lock_sync, which make lock request could
|
|
|
|
* be interrupted
|
|
|
|
*/
|
|
|
|
static int dlm_lock_sync_interruptible(struct dlm_lock_resource *res, int mode,
|
|
|
|
struct mddev *mddev)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ret = dlm_lock(res->ls, mode, &res->lksb,
|
|
|
|
res->flags, res->name, strlen(res->name),
|
|
|
|
0, sync_ast, res, res->bast);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
wait_event(res->sync_locking, res->sync_locking_done
|
2016-08-12 13:42:43 +08:00
|
|
|
|| kthread_should_stop()
|
|
|
|
|| test_bit(MD_CLOSING, &mddev->flags));
|
2016-08-12 13:42:42 +08:00
|
|
|
if (!res->sync_locking_done) {
|
|
|
|
/*
|
|
|
|
* the convert queue contains the lock request when request is
|
|
|
|
* interrupted, and sync_ast could still be run, so need to
|
|
|
|
* cancel the request and reset completion
|
|
|
|
*/
|
|
|
|
ret = dlm_unlock(res->ls, res->lksb.sb_lkid, DLM_LKF_CANCEL,
|
|
|
|
&res->lksb, res);
|
|
|
|
res->sync_locking_done = false;
|
|
|
|
if (unlikely(ret != 0))
|
|
|
|
pr_info("failed to cancel previous lock request "
|
|
|
|
"%s return %d\n", res->name, ret);
|
|
|
|
return -EPERM;
|
|
|
|
} else
|
|
|
|
res->sync_locking_done = false;
|
|
|
|
if (res->lksb.sb_status == 0)
|
|
|
|
res->mode = mode;
|
|
|
|
return res->lksb.sb_status;
|
|
|
|
}
|
|
|
|
|
2014-03-29 23:20:02 +08:00
|
|
|
static struct dlm_lock_resource *lockres_init(struct mddev *mddev,
|
2014-03-08 03:49:26 +08:00
|
|
|
char *name, void (*bastfn)(void *arg, int mode), int with_lvb)
|
|
|
|
{
|
|
|
|
struct dlm_lock_resource *res = NULL;
|
|
|
|
int ret, namelen;
|
2014-03-29 23:20:02 +08:00
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
2014-03-08 03:49:26 +08:00
|
|
|
|
|
|
|
res = kzalloc(sizeof(struct dlm_lock_resource), GFP_KERNEL);
|
|
|
|
if (!res)
|
|
|
|
return NULL;
|
2016-08-12 13:42:41 +08:00
|
|
|
init_waitqueue_head(&res->sync_locking);
|
|
|
|
res->sync_locking_done = false;
|
2014-03-29 23:20:02 +08:00
|
|
|
res->ls = cinfo->lockspace;
|
|
|
|
res->mddev = mddev;
|
2015-10-02 02:20:27 +08:00
|
|
|
res->mode = DLM_LOCK_IV;
|
2014-03-08 03:49:26 +08:00
|
|
|
namelen = strlen(name);
|
|
|
|
res->name = kzalloc(namelen + 1, GFP_KERNEL);
|
|
|
|
if (!res->name) {
|
|
|
|
pr_err("md-cluster: Unable to allocate resource name for resource %s\n", name);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
strlcpy(res->name, name, namelen + 1);
|
|
|
|
if (with_lvb) {
|
|
|
|
res->lksb.sb_lvbptr = kzalloc(LVB_SIZE, GFP_KERNEL);
|
|
|
|
if (!res->lksb.sb_lvbptr) {
|
|
|
|
pr_err("md-cluster: Unable to allocate LVB for resource %s\n", name);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
res->flags = DLM_LKF_VALBLK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bastfn)
|
|
|
|
res->bast = bastfn;
|
|
|
|
|
|
|
|
res->flags |= DLM_LKF_EXPEDITE;
|
|
|
|
|
|
|
|
ret = dlm_lock_sync(res, DLM_LOCK_NL);
|
|
|
|
if (ret) {
|
|
|
|
pr_err("md-cluster: Unable to lock NL on new lock resource %s\n", name);
|
|
|
|
goto out_err;
|
|
|
|
}
|
|
|
|
res->flags &= ~DLM_LKF_EXPEDITE;
|
|
|
|
res->flags |= DLM_LKF_CONVERT;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
out_err:
|
|
|
|
kfree(res->lksb.sb_lvbptr);
|
|
|
|
kfree(res->name);
|
|
|
|
kfree(res);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void lockres_free(struct dlm_lock_resource *res)
|
|
|
|
{
|
2016-08-12 13:42:35 +08:00
|
|
|
int ret = 0;
|
2015-07-10 17:01:17 +08:00
|
|
|
|
2014-03-08 03:49:26 +08:00
|
|
|
if (!res)
|
|
|
|
return;
|
|
|
|
|
2016-08-12 13:42:35 +08:00
|
|
|
/*
|
|
|
|
* use FORCEUNLOCK flag, so we can unlock even the lock is on the
|
|
|
|
* waiting or convert queue
|
|
|
|
*/
|
|
|
|
ret = dlm_unlock(res->ls, res->lksb.sb_lkid, DLM_LKF_FORCEUNLOCK,
|
|
|
|
&res->lksb, res);
|
|
|
|
if (unlikely(ret != 0))
|
|
|
|
pr_err("failed to unlock %s return %d\n", res->name, ret);
|
|
|
|
else
|
2016-08-12 13:42:41 +08:00
|
|
|
wait_event(res->sync_locking, res->sync_locking_done);
|
2014-03-08 03:49:26 +08:00
|
|
|
|
|
|
|
kfree(res->name);
|
|
|
|
kfree(res->lksb.sb_lvbptr);
|
|
|
|
kfree(res);
|
|
|
|
}
|
2014-03-08 01:21:15 +08:00
|
|
|
|
2015-10-19 12:44:00 +08:00
|
|
|
static void add_resync_info(struct dlm_lock_resource *lockres,
|
|
|
|
sector_t lo, sector_t hi)
|
2014-06-07 01:35:34 +08:00
|
|
|
{
|
|
|
|
struct resync_info *ri;
|
|
|
|
|
|
|
|
ri = (struct resync_info *)lockres->lksb.sb_lvbptr;
|
|
|
|
ri->lo = cpu_to_le64(lo);
|
|
|
|
ri->hi = cpu_to_le64(hi);
|
|
|
|
}
|
|
|
|
|
2018-10-18 16:37:48 +08:00
|
|
|
static int read_resync_info(struct mddev *mddev,
|
|
|
|
struct dlm_lock_resource *lockres)
|
2014-06-07 01:35:34 +08:00
|
|
|
{
|
|
|
|
struct resync_info ri;
|
2018-10-18 16:37:48 +08:00
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
int ret = 0;
|
2014-06-07 01:35:34 +08:00
|
|
|
|
|
|
|
dlm_lock_sync(lockres, DLM_LOCK_CR);
|
|
|
|
memcpy(&ri, lockres->lksb.sb_lvbptr, sizeof(struct resync_info));
|
2018-10-18 16:37:48 +08:00
|
|
|
if (le64_to_cpu(ri.hi) > 0) {
|
|
|
|
cinfo->suspend_hi = le64_to_cpu(ri.hi);
|
|
|
|
cinfo->suspend_lo = le64_to_cpu(ri.lo);
|
|
|
|
ret = 1;
|
2014-06-07 01:35:34 +08:00
|
|
|
}
|
|
|
|
dlm_unlock_sync(lockres);
|
2018-10-18 16:37:48 +08:00
|
|
|
return ret;
|
2014-06-07 01:35:34 +08:00
|
|
|
}
|
|
|
|
|
2015-02-28 07:04:37 +08:00
|
|
|
static void recover_bitmaps(struct md_thread *thread)
|
2014-06-07 13:45:22 +08:00
|
|
|
{
|
|
|
|
struct mddev *mddev = thread->mddev;
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
struct dlm_lock_resource *bm_lockres;
|
|
|
|
char str[64];
|
|
|
|
int slot, ret;
|
|
|
|
sector_t lo, hi;
|
|
|
|
|
|
|
|
while (cinfo->recovery_map) {
|
|
|
|
slot = fls64((u64)cinfo->recovery_map) - 1;
|
|
|
|
|
|
|
|
snprintf(str, 64, "bitmap%04d", slot);
|
|
|
|
bm_lockres = lockres_init(mddev, str, NULL, 1);
|
|
|
|
if (!bm_lockres) {
|
|
|
|
pr_err("md-cluster: Cannot initialize bitmaps\n");
|
|
|
|
goto clear_bit;
|
|
|
|
}
|
|
|
|
|
2016-08-12 13:42:42 +08:00
|
|
|
ret = dlm_lock_sync_interruptible(bm_lockres, DLM_LOCK_PW, mddev);
|
2014-06-07 13:45:22 +08:00
|
|
|
if (ret) {
|
|
|
|
pr_err("md-cluster: Could not DLM lock %s: %d\n",
|
|
|
|
str, ret);
|
|
|
|
goto clear_bit;
|
|
|
|
}
|
2018-08-02 06:20:50 +08:00
|
|
|
ret = md_bitmap_copy_from_slot(mddev, slot, &lo, &hi, true);
|
2014-06-07 13:52:29 +08:00
|
|
|
if (ret) {
|
2014-06-07 13:45:22 +08:00
|
|
|
pr_err("md-cluster: Could not copy data from bitmap %d\n", slot);
|
2016-08-12 13:42:36 +08:00
|
|
|
goto clear_bit;
|
2014-06-07 13:52:29 +08:00
|
|
|
}
|
2018-07-02 16:26:24 +08:00
|
|
|
|
|
|
|
/* Clear suspend_area associated with the bitmap */
|
|
|
|
spin_lock_irq(&cinfo->suspend_lock);
|
2018-10-18 16:37:48 +08:00
|
|
|
cinfo->suspend_hi = 0;
|
|
|
|
cinfo->suspend_lo = 0;
|
|
|
|
cinfo->suspend_from = -1;
|
2018-07-02 16:26:24 +08:00
|
|
|
spin_unlock_irq(&cinfo->suspend_lock);
|
|
|
|
|
2018-10-18 16:37:47 +08:00
|
|
|
/* Kick off a reshape if needed */
|
|
|
|
if (test_bit(MD_RESYNCING_REMOTE, &mddev->recovery) &&
|
|
|
|
test_bit(MD_RECOVERY_RESHAPE, &mddev->recovery) &&
|
|
|
|
mddev->reshape_position != MaxSector)
|
|
|
|
md_wakeup_thread(mddev->sync_thread);
|
|
|
|
|
2014-06-07 13:52:29 +08:00
|
|
|
if (hi > 0) {
|
|
|
|
if (lo < mddev->recovery_cp)
|
|
|
|
mddev->recovery_cp = lo;
|
2016-05-02 23:33:10 +08:00
|
|
|
/* wake up thread to continue resync in case resync
|
|
|
|
* is not finished */
|
|
|
|
if (mddev->recovery_cp != MaxSector) {
|
2018-07-02 16:26:25 +08:00
|
|
|
/*
|
|
|
|
* clear the REMOTE flag since we will launch
|
|
|
|
* resync thread in current node.
|
|
|
|
*/
|
|
|
|
clear_bit(MD_RESYNCING_REMOTE,
|
|
|
|
&mddev->recovery);
|
|
|
|
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
|
|
|
|
md_wakeup_thread(mddev->thread);
|
2016-05-02 23:33:10 +08:00
|
|
|
}
|
2014-06-07 13:52:29 +08:00
|
|
|
}
|
2014-06-07 13:45:22 +08:00
|
|
|
clear_bit:
|
2016-01-23 07:54:42 +08:00
|
|
|
lockres_free(bm_lockres);
|
2014-06-07 13:45:22 +08:00
|
|
|
clear_bit(slot, &cinfo->recovery_map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-30 13:42:49 +08:00
|
|
|
static void recover_prep(void *arg)
|
|
|
|
{
|
2015-06-24 22:30:32 +08:00
|
|
|
struct mddev *mddev = arg;
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
set_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state);
|
2014-03-30 13:42:49 +08:00
|
|
|
}
|
|
|
|
|
2015-07-10 16:54:03 +08:00
|
|
|
static void __recover_slot(struct mddev *mddev, int slot)
|
2014-03-30 13:42:49 +08:00
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
|
2015-07-10 16:54:03 +08:00
|
|
|
set_bit(slot, &cinfo->recovery_map);
|
2014-06-07 13:45:22 +08:00
|
|
|
if (!cinfo->recovery_thread) {
|
|
|
|
cinfo->recovery_thread = md_register_thread(recover_bitmaps,
|
|
|
|
mddev, "recover");
|
|
|
|
if (!cinfo->recovery_thread) {
|
|
|
|
pr_warn("md-cluster: Could not create recovery thread\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
md_wakeup_thread(cinfo->recovery_thread);
|
2014-03-30 13:42:49 +08:00
|
|
|
}
|
|
|
|
|
2015-07-10 16:54:03 +08:00
|
|
|
static void recover_slot(void *arg, struct dlm_slot *slot)
|
|
|
|
{
|
|
|
|
struct mddev *mddev = arg;
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
|
|
|
|
pr_info("md-cluster: %s Node %d/%d down. My slot: %d. Initiating recovery.\n",
|
|
|
|
mddev->bitmap_info.cluster_name,
|
|
|
|
slot->nodeid, slot->slot,
|
|
|
|
cinfo->slot_number);
|
|
|
|
/* deduct one since dlm slot starts from one while the num of
|
|
|
|
* cluster-md begins with 0 */
|
|
|
|
__recover_slot(mddev, slot->slot - 1);
|
|
|
|
}
|
|
|
|
|
2014-03-30 13:42:49 +08:00
|
|
|
static void recover_done(void *arg, struct dlm_slot *slots,
|
|
|
|
int num_slots, int our_slot,
|
|
|
|
uint32_t generation)
|
|
|
|
{
|
|
|
|
struct mddev *mddev = arg;
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
|
|
|
|
cinfo->slot_number = our_slot;
|
2015-07-10 17:01:21 +08:00
|
|
|
/* completion is only need to be complete when node join cluster,
|
|
|
|
* it doesn't need to run during another node's failure */
|
|
|
|
if (test_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state)) {
|
|
|
|
complete(&cinfo->completion);
|
|
|
|
clear_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state);
|
|
|
|
}
|
2015-06-24 22:30:32 +08:00
|
|
|
clear_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state);
|
2014-03-30 13:42:49 +08:00
|
|
|
}
|
|
|
|
|
2015-07-10 17:01:21 +08:00
|
|
|
/* the ops is called when node join the cluster, and do lock recovery
|
|
|
|
* if node failure occurs */
|
2014-03-30 13:42:49 +08:00
|
|
|
static const struct dlm_lockspace_ops md_ls_ops = {
|
|
|
|
.recover_prep = recover_prep,
|
|
|
|
.recover_slot = recover_slot,
|
|
|
|
.recover_done = recover_done,
|
|
|
|
};
|
|
|
|
|
2014-06-07 14:08:29 +08:00
|
|
|
/*
|
|
|
|
* The BAST function for the ack lock resource
|
|
|
|
* This function wakes up the receive thread in
|
|
|
|
* order to receive and process the message.
|
|
|
|
*/
|
|
|
|
static void ack_bast(void *arg, int mode)
|
|
|
|
{
|
2015-10-19 12:42:18 +08:00
|
|
|
struct dlm_lock_resource *res = arg;
|
2014-06-07 14:08:29 +08:00
|
|
|
struct md_cluster_info *cinfo = res->mddev->cluster_info;
|
|
|
|
|
2016-05-04 14:17:09 +08:00
|
|
|
if (mode == DLM_LOCK_EX) {
|
|
|
|
if (test_bit(MD_CLUSTER_ALREADY_IN_CLUSTER, &cinfo->state))
|
|
|
|
md_wakeup_thread(cinfo->recv_thread);
|
|
|
|
else
|
|
|
|
set_bit(MD_CLUSTER_PENDING_RECV_EVENT, &cinfo->state);
|
|
|
|
}
|
2014-06-07 14:08:29 +08:00
|
|
|
}
|
|
|
|
|
2015-10-10 00:27:01 +08:00
|
|
|
static void remove_suspend_info(struct mddev *mddev, int slot)
|
2014-06-07 15:30:30 +08:00
|
|
|
{
|
2015-10-10 00:27:01 +08:00
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
2017-10-19 09:49:15 +08:00
|
|
|
mddev->pers->quiesce(mddev, 1);
|
2014-06-07 15:30:30 +08:00
|
|
|
spin_lock_irq(&cinfo->suspend_lock);
|
2018-10-18 16:37:48 +08:00
|
|
|
cinfo->suspend_hi = 0;
|
|
|
|
cinfo->suspend_lo = 0;
|
2014-06-07 15:30:30 +08:00
|
|
|
spin_unlock_irq(&cinfo->suspend_lock);
|
2017-10-19 09:49:15 +08:00
|
|
|
mddev->pers->quiesce(mddev, 0);
|
2014-06-07 15:30:30 +08:00
|
|
|
}
|
|
|
|
|
2015-08-15 01:19:40 +08:00
|
|
|
static void process_suspend_info(struct mddev *mddev,
|
2014-06-07 15:30:30 +08:00
|
|
|
int slot, sector_t lo, sector_t hi)
|
|
|
|
{
|
2015-08-15 01:19:40 +08:00
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
2018-10-18 16:37:46 +08:00
|
|
|
struct mdp_superblock_1 *sb = NULL;
|
|
|
|
struct md_rdev *rdev;
|
2014-06-07 15:30:30 +08:00
|
|
|
|
|
|
|
if (!hi) {
|
2018-07-02 16:26:25 +08:00
|
|
|
/*
|
|
|
|
* clear the REMOTE flag since resync or recovery is finished
|
|
|
|
* in remote node.
|
|
|
|
*/
|
|
|
|
clear_bit(MD_RESYNCING_REMOTE, &mddev->recovery);
|
2015-10-10 00:27:01 +08:00
|
|
|
remove_suspend_info(mddev, slot);
|
2015-10-01 02:20:35 +08:00
|
|
|
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
|
|
|
|
md_wakeup_thread(mddev->thread);
|
2014-06-07 15:30:30 +08:00
|
|
|
return;
|
|
|
|
}
|
2016-05-02 23:50:12 +08:00
|
|
|
|
2018-10-18 16:37:46 +08:00
|
|
|
rdev_for_each(rdev, mddev)
|
|
|
|
if (rdev->raid_disk > -1 && !test_bit(Faulty, &rdev->flags)) {
|
|
|
|
sb = page_address(rdev->sb_page);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-05-02 23:50:12 +08:00
|
|
|
/*
|
|
|
|
* The bitmaps are not same for different nodes
|
|
|
|
* if RESYNCING is happening in one node, then
|
|
|
|
* the node which received the RESYNCING message
|
|
|
|
* probably will perform resync with the region
|
|
|
|
* [lo, hi] again, so we could reduce resync time
|
|
|
|
* a lot if we can ensure that the bitmaps among
|
|
|
|
* different nodes are match up well.
|
|
|
|
*
|
|
|
|
* sync_low/hi is used to record the region which
|
|
|
|
* arrived in the previous RESYNCING message,
|
|
|
|
*
|
2018-10-18 16:37:46 +08:00
|
|
|
* Call md_bitmap_sync_with_cluster to clear NEEDED_MASK
|
|
|
|
* and set RESYNC_MASK since resync thread is running
|
|
|
|
* in another node, so we don't need to do the resync
|
|
|
|
* again with the same section.
|
|
|
|
*
|
|
|
|
* Skip md_bitmap_sync_with_cluster in case reshape
|
|
|
|
* happening, because reshaping region is small and
|
|
|
|
* we don't want to trigger lots of WARN.
|
|
|
|
*/
|
|
|
|
if (sb && !(le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE))
|
|
|
|
md_bitmap_sync_with_cluster(mddev, cinfo->sync_low,
|
|
|
|
cinfo->sync_hi, lo, hi);
|
2016-05-02 23:50:12 +08:00
|
|
|
cinfo->sync_low = lo;
|
|
|
|
cinfo->sync_hi = hi;
|
|
|
|
|
2015-08-15 01:19:40 +08:00
|
|
|
mddev->pers->quiesce(mddev, 1);
|
2014-06-07 15:30:30 +08:00
|
|
|
spin_lock_irq(&cinfo->suspend_lock);
|
2018-10-18 16:37:48 +08:00
|
|
|
cinfo->suspend_from = slot;
|
|
|
|
cinfo->suspend_lo = lo;
|
|
|
|
cinfo->suspend_hi = hi;
|
2014-06-07 15:30:30 +08:00
|
|
|
spin_unlock_irq(&cinfo->suspend_lock);
|
2017-10-19 09:49:15 +08:00
|
|
|
mddev->pers->quiesce(mddev, 0);
|
2014-06-07 15:30:30 +08:00
|
|
|
}
|
|
|
|
|
2014-10-30 07:51:31 +08:00
|
|
|
static void process_add_new_disk(struct mddev *mddev, struct cluster_msg *cmsg)
|
|
|
|
{
|
|
|
|
char disk_uuid[64];
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
char event_name[] = "EVENT=ADD_DEVICE";
|
|
|
|
char raid_slot[16];
|
|
|
|
char *envp[] = {event_name, disk_uuid, raid_slot, NULL};
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = snprintf(disk_uuid, 64, "DEVICE_UUID=");
|
2015-07-10 16:54:02 +08:00
|
|
|
sprintf(disk_uuid + len, "%pU", cmsg->uuid);
|
2015-10-12 17:21:21 +08:00
|
|
|
snprintf(raid_slot, 16, "RAID_DISK=%d", le32_to_cpu(cmsg->raid_slot));
|
2014-10-30 07:51:31 +08:00
|
|
|
pr_info("%s:%d Sending kobject change with %s and %s\n", __func__, __LINE__, disk_uuid, raid_slot);
|
|
|
|
init_completion(&cinfo->newdisk_completion);
|
2015-03-03 00:55:49 +08:00
|
|
|
set_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state);
|
2014-10-30 07:51:31 +08:00
|
|
|
kobject_uevent_env(&disk_to_dev(mddev->gendisk)->kobj, KOBJ_CHANGE, envp);
|
|
|
|
wait_for_completion_timeout(&cinfo->newdisk_completion,
|
|
|
|
NEW_DEV_TIMEOUT);
|
2015-03-03 00:55:49 +08:00
|
|
|
clear_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state);
|
2014-10-30 07:51:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void process_metadata_update(struct mddev *mddev, struct cluster_msg *msg)
|
|
|
|
{
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
int got_lock = 0;
|
2014-10-30 07:51:31 +08:00
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
2015-12-21 07:51:00 +08:00
|
|
|
mddev->good_device_nr = le32_to_cpu(msg->raid_slot);
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
|
2014-10-30 07:51:31 +08:00
|
|
|
dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR);
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
wait_event(mddev->thread->wqueue,
|
|
|
|
(got_lock = mddev_trylock(mddev)) ||
|
|
|
|
test_bit(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state));
|
|
|
|
md_reload_sb(mddev, mddev->good_device_nr);
|
|
|
|
if (got_lock)
|
|
|
|
mddev_unlock(mddev);
|
2014-10-30 07:51:31 +08:00
|
|
|
}
|
|
|
|
|
2015-04-14 23:44:44 +08:00
|
|
|
static void process_remove_disk(struct mddev *mddev, struct cluster_msg *msg)
|
|
|
|
{
|
2016-08-12 13:42:39 +08:00
|
|
|
struct md_rdev *rdev;
|
2015-04-14 23:44:44 +08:00
|
|
|
|
2016-08-12 13:42:39 +08:00
|
|
|
rcu_read_lock();
|
|
|
|
rdev = md_find_rdev_nr_rcu(mddev, le32_to_cpu(msg->raid_slot));
|
2015-12-21 07:50:59 +08:00
|
|
|
if (rdev) {
|
|
|
|
set_bit(ClusterRemove, &rdev->flags);
|
|
|
|
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
|
|
|
|
md_wakeup_thread(mddev->thread);
|
|
|
|
}
|
2015-04-14 23:44:44 +08:00
|
|
|
else
|
2015-10-12 17:21:21 +08:00
|
|
|
pr_warn("%s: %d Could not find disk(%d) to REMOVE\n",
|
|
|
|
__func__, __LINE__, le32_to_cpu(msg->raid_slot));
|
2016-08-12 13:42:39 +08:00
|
|
|
rcu_read_unlock();
|
2015-04-14 23:44:44 +08:00
|
|
|
}
|
|
|
|
|
2015-04-14 23:45:42 +08:00
|
|
|
static void process_readd_disk(struct mddev *mddev, struct cluster_msg *msg)
|
|
|
|
{
|
2016-08-12 13:42:39 +08:00
|
|
|
struct md_rdev *rdev;
|
2015-04-14 23:45:42 +08:00
|
|
|
|
2016-08-12 13:42:39 +08:00
|
|
|
rcu_read_lock();
|
|
|
|
rdev = md_find_rdev_nr_rcu(mddev, le32_to_cpu(msg->raid_slot));
|
2015-04-14 23:45:42 +08:00
|
|
|
if (rdev && test_bit(Faulty, &rdev->flags))
|
|
|
|
clear_bit(Faulty, &rdev->flags);
|
|
|
|
else
|
2015-10-12 17:21:21 +08:00
|
|
|
pr_warn("%s: %d Could not find disk(%d) which is faulty",
|
|
|
|
__func__, __LINE__, le32_to_cpu(msg->raid_slot));
|
2016-08-12 13:42:39 +08:00
|
|
|
rcu_read_unlock();
|
2015-04-14 23:45:42 +08:00
|
|
|
}
|
|
|
|
|
2016-05-04 10:22:15 +08:00
|
|
|
static int process_recvd_msg(struct mddev *mddev, struct cluster_msg *msg)
|
2014-06-07 14:08:29 +08:00
|
|
|
{
|
2016-05-04 10:22:15 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
2015-10-12 17:21:23 +08:00
|
|
|
if (WARN(mddev->cluster_info->slot_number - 1 == le32_to_cpu(msg->slot),
|
|
|
|
"node %d received it's own msg\n", le32_to_cpu(msg->slot)))
|
2016-05-04 10:22:15 +08:00
|
|
|
return -1;
|
2015-10-16 15:40:22 +08:00
|
|
|
switch (le32_to_cpu(msg->type)) {
|
2014-06-07 14:08:29 +08:00
|
|
|
case METADATA_UPDATED:
|
2014-10-30 07:51:31 +08:00
|
|
|
process_metadata_update(mddev, msg);
|
2014-06-07 14:08:29 +08:00
|
|
|
break;
|
2017-03-01 16:42:38 +08:00
|
|
|
case CHANGE_CAPACITY:
|
|
|
|
set_capacity(mddev->gendisk, mddev->array_sectors);
|
2020-09-01 23:57:43 +08:00
|
|
|
revalidate_disk_size(mddev->gendisk, true);
|
2017-03-01 16:42:38 +08:00
|
|
|
break;
|
2014-06-07 14:08:29 +08:00
|
|
|
case RESYNCING:
|
2018-07-02 16:26:25 +08:00
|
|
|
set_bit(MD_RESYNCING_REMOTE, &mddev->recovery);
|
2015-10-16 15:40:22 +08:00
|
|
|
process_suspend_info(mddev, le32_to_cpu(msg->slot),
|
|
|
|
le64_to_cpu(msg->low),
|
|
|
|
le64_to_cpu(msg->high));
|
2014-06-07 14:08:29 +08:00
|
|
|
break;
|
2014-10-30 07:51:31 +08:00
|
|
|
case NEWDISK:
|
|
|
|
process_add_new_disk(mddev, msg);
|
2015-04-14 23:44:44 +08:00
|
|
|
break;
|
|
|
|
case REMOVE:
|
|
|
|
process_remove_disk(mddev, msg);
|
|
|
|
break;
|
2015-04-14 23:45:42 +08:00
|
|
|
case RE_ADD:
|
|
|
|
process_readd_disk(mddev, msg);
|
|
|
|
break;
|
2015-07-10 16:54:04 +08:00
|
|
|
case BITMAP_NEEDS_SYNC:
|
2015-10-16 15:40:22 +08:00
|
|
|
__recover_slot(mddev, le32_to_cpu(msg->slot));
|
2015-07-10 16:54:04 +08:00
|
|
|
break;
|
2018-10-18 16:37:41 +08:00
|
|
|
case BITMAP_RESIZE:
|
|
|
|
if (le64_to_cpu(msg->high) != mddev->pers->size(mddev, 0, 0))
|
|
|
|
ret = md_bitmap_resize(mddev->bitmap,
|
|
|
|
le64_to_cpu(msg->high), 0, 0);
|
|
|
|
break;
|
2015-04-14 23:44:44 +08:00
|
|
|
default:
|
2016-05-04 10:22:15 +08:00
|
|
|
ret = -1;
|
2015-04-14 23:44:44 +08:00
|
|
|
pr_warn("%s:%d Received unknown message from %d\n",
|
|
|
|
__func__, __LINE__, msg->slot);
|
2015-02-28 09:16:08 +08:00
|
|
|
}
|
2016-05-04 10:22:15 +08:00
|
|
|
return ret;
|
2014-06-07 14:08:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* thread for receiving message
|
|
|
|
*/
|
|
|
|
static void recv_daemon(struct md_thread *thread)
|
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = thread->mddev->cluster_info;
|
|
|
|
struct dlm_lock_resource *ack_lockres = cinfo->ack_lockres;
|
|
|
|
struct dlm_lock_resource *message_lockres = cinfo->message_lockres;
|
|
|
|
struct cluster_msg msg;
|
2015-07-10 17:01:17 +08:00
|
|
|
int ret;
|
2014-06-07 14:08:29 +08:00
|
|
|
|
2015-12-21 07:51:00 +08:00
|
|
|
mutex_lock(&cinfo->recv_mutex);
|
2014-06-07 14:08:29 +08:00
|
|
|
/*get CR on Message*/
|
|
|
|
if (dlm_lock_sync(message_lockres, DLM_LOCK_CR)) {
|
|
|
|
pr_err("md/raid1:failed to get CR on MESSAGE\n");
|
2015-12-21 07:51:00 +08:00
|
|
|
mutex_unlock(&cinfo->recv_mutex);
|
2014-06-07 14:08:29 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read lvb and wake up thread to process this message_lockres */
|
|
|
|
memcpy(&msg, message_lockres->lksb.sb_lvbptr, sizeof(struct cluster_msg));
|
2016-05-04 10:22:15 +08:00
|
|
|
ret = process_recvd_msg(thread->mddev, &msg);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
2014-06-07 14:08:29 +08:00
|
|
|
|
|
|
|
/*release CR on ack_lockres*/
|
2015-07-10 17:01:17 +08:00
|
|
|
ret = dlm_unlock_sync(ack_lockres);
|
|
|
|
if (unlikely(ret != 0))
|
|
|
|
pr_info("unlock ack failed return %d\n", ret);
|
2015-07-10 17:01:15 +08:00
|
|
|
/*up-convert to PR on message_lockres*/
|
2015-07-10 17:01:17 +08:00
|
|
|
ret = dlm_lock_sync(message_lockres, DLM_LOCK_PR);
|
|
|
|
if (unlikely(ret != 0))
|
|
|
|
pr_info("lock PR on msg failed return %d\n", ret);
|
2014-06-07 14:08:29 +08:00
|
|
|
/*get CR on ack_lockres again*/
|
2015-07-10 17:01:17 +08:00
|
|
|
ret = dlm_lock_sync(ack_lockres, DLM_LOCK_CR);
|
|
|
|
if (unlikely(ret != 0))
|
|
|
|
pr_info("lock CR on ack failed return %d\n", ret);
|
2016-05-04 10:22:15 +08:00
|
|
|
out:
|
2014-06-07 14:08:29 +08:00
|
|
|
/*release CR on message_lockres*/
|
2015-07-10 17:01:17 +08:00
|
|
|
ret = dlm_unlock_sync(message_lockres);
|
|
|
|
if (unlikely(ret != 0))
|
|
|
|
pr_info("unlock msg failed return %d\n", ret);
|
2015-12-21 07:51:00 +08:00
|
|
|
mutex_unlock(&cinfo->recv_mutex);
|
2014-06-07 14:08:29 +08:00
|
|
|
}
|
|
|
|
|
2015-12-21 07:51:00 +08:00
|
|
|
/* lock_token()
|
2014-06-07 14:28:53 +08:00
|
|
|
* Takes the lock on the TOKEN lock resource so no other
|
|
|
|
* node can communicate while the operation is underway.
|
|
|
|
*/
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
static int lock_token(struct md_cluster_info *cinfo, bool mddev_locked)
|
2014-06-07 14:28:53 +08:00
|
|
|
{
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
int error, set_bit = 0;
|
|
|
|
struct mddev *mddev = cinfo->mddev;
|
2014-06-07 14:28:53 +08:00
|
|
|
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
/*
|
|
|
|
* If resync thread run after raid1d thread, then process_metadata_update
|
|
|
|
* could not continue if raid1d held reconfig_mutex (and raid1d is blocked
|
|
|
|
* since another node already got EX on Token and waitting the EX of Ack),
|
|
|
|
* so let resync wake up thread in case flag is set.
|
|
|
|
*/
|
|
|
|
if (mddev_locked && !test_bit(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD,
|
|
|
|
&cinfo->state)) {
|
|
|
|
error = test_and_set_bit_lock(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD,
|
|
|
|
&cinfo->state);
|
|
|
|
WARN_ON_ONCE(error);
|
|
|
|
md_wakeup_thread(mddev->thread);
|
|
|
|
set_bit = 1;
|
|
|
|
}
|
2014-06-07 14:28:53 +08:00
|
|
|
error = dlm_lock_sync(cinfo->token_lockres, DLM_LOCK_EX);
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
if (set_bit)
|
|
|
|
clear_bit_unlock(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state);
|
|
|
|
|
2014-06-07 14:28:53 +08:00
|
|
|
if (error)
|
|
|
|
pr_err("md-cluster(%s:%d): failed to get EX on TOKEN (%d)\n",
|
|
|
|
__func__, __LINE__, error);
|
2015-12-21 07:51:00 +08:00
|
|
|
|
|
|
|
/* Lock the receive sequence */
|
|
|
|
mutex_lock(&cinfo->recv_mutex);
|
2014-06-07 14:28:53 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2015-12-21 07:51:00 +08:00
|
|
|
/* lock_comm()
|
|
|
|
* Sets the MD_CLUSTER_SEND_LOCK bit to lock the send channel.
|
|
|
|
*/
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
static int lock_comm(struct md_cluster_info *cinfo, bool mddev_locked)
|
2015-12-21 07:51:00 +08:00
|
|
|
{
|
|
|
|
wait_event(cinfo->wait,
|
|
|
|
!test_and_set_bit(MD_CLUSTER_SEND_LOCK, &cinfo->state));
|
|
|
|
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
return lock_token(cinfo, mddev_locked);
|
2015-12-21 07:51:00 +08:00
|
|
|
}
|
|
|
|
|
2014-06-07 14:28:53 +08:00
|
|
|
static void unlock_comm(struct md_cluster_info *cinfo)
|
|
|
|
{
|
2015-10-02 02:20:27 +08:00
|
|
|
WARN_ON(cinfo->token_lockres->mode != DLM_LOCK_EX);
|
2015-12-21 07:51:00 +08:00
|
|
|
mutex_unlock(&cinfo->recv_mutex);
|
2014-06-07 14:28:53 +08:00
|
|
|
dlm_unlock_sync(cinfo->token_lockres);
|
2015-12-21 07:51:00 +08:00
|
|
|
clear_bit(MD_CLUSTER_SEND_LOCK, &cinfo->state);
|
|
|
|
wake_up(&cinfo->wait);
|
2014-06-07 14:28:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* __sendmsg()
|
|
|
|
* This function performs the actual sending of the message. This function is
|
|
|
|
* usually called after performing the encompassing operation
|
|
|
|
* The function:
|
|
|
|
* 1. Grabs the message lockresource in EX mode
|
|
|
|
* 2. Copies the message to the message LVB
|
2015-07-10 17:01:15 +08:00
|
|
|
* 3. Downconverts message lockresource to CW
|
2014-06-07 14:28:53 +08:00
|
|
|
* 4. Upconverts ack lock resource from CR to EX. This forces the BAST on other nodes
|
|
|
|
* and the other nodes read the message. The thread will wait here until all other
|
|
|
|
* nodes have released ack lock resource.
|
|
|
|
* 5. Downconvert ack lockresource to CR
|
|
|
|
*/
|
|
|
|
static int __sendmsg(struct md_cluster_info *cinfo, struct cluster_msg *cmsg)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
int slot = cinfo->slot_number - 1;
|
|
|
|
|
|
|
|
cmsg->slot = cpu_to_le32(slot);
|
|
|
|
/*get EX on Message*/
|
|
|
|
error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_EX);
|
|
|
|
if (error) {
|
|
|
|
pr_err("md-cluster: failed to get EX on MESSAGE (%d)\n", error);
|
|
|
|
goto failed_message;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(cinfo->message_lockres->lksb.sb_lvbptr, (void *)cmsg,
|
|
|
|
sizeof(struct cluster_msg));
|
2015-07-10 17:01:15 +08:00
|
|
|
/*down-convert EX to CW on Message*/
|
|
|
|
error = dlm_lock_sync(cinfo->message_lockres, DLM_LOCK_CW);
|
2014-06-07 14:28:53 +08:00
|
|
|
if (error) {
|
2015-07-10 17:01:15 +08:00
|
|
|
pr_err("md-cluster: failed to convert EX to CW on MESSAGE(%d)\n",
|
2014-06-07 14:28:53 +08:00
|
|
|
error);
|
2015-07-10 17:01:15 +08:00
|
|
|
goto failed_ack;
|
2014-06-07 14:28:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*up-convert CR to EX on Ack*/
|
|
|
|
error = dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_EX);
|
|
|
|
if (error) {
|
|
|
|
pr_err("md-cluster: failed to convert CR to EX on ACK(%d)\n",
|
|
|
|
error);
|
|
|
|
goto failed_ack;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*down-convert EX to CR on Ack*/
|
|
|
|
error = dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_CR);
|
|
|
|
if (error) {
|
|
|
|
pr_err("md-cluster: failed to convert EX to CR on ACK(%d)\n",
|
|
|
|
error);
|
|
|
|
goto failed_ack;
|
|
|
|
}
|
|
|
|
|
|
|
|
failed_ack:
|
2015-07-10 17:01:17 +08:00
|
|
|
error = dlm_unlock_sync(cinfo->message_lockres);
|
|
|
|
if (unlikely(error != 0)) {
|
|
|
|
pr_err("md-cluster: failed convert to NL on MESSAGE(%d)\n",
|
|
|
|
error);
|
|
|
|
/* in case the message can't be released due to some reason */
|
|
|
|
goto failed_ack;
|
|
|
|
}
|
2014-06-07 14:28:53 +08:00
|
|
|
failed_message:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
static int sendmsg(struct md_cluster_info *cinfo, struct cluster_msg *cmsg,
|
|
|
|
bool mddev_locked)
|
2014-06-07 14:28:53 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
lock_comm(cinfo, mddev_locked);
|
2014-06-07 14:28:53 +08:00
|
|
|
ret = __sendmsg(cinfo, cmsg);
|
|
|
|
unlock_comm(cinfo);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-06-07 01:35:34 +08:00
|
|
|
static int gather_all_resync_info(struct mddev *mddev, int total_slots)
|
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
int i, ret = 0;
|
|
|
|
struct dlm_lock_resource *bm_lockres;
|
|
|
|
char str[64];
|
2015-07-10 17:01:22 +08:00
|
|
|
sector_t lo, hi;
|
2014-06-07 01:35:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < total_slots; i++) {
|
|
|
|
memset(str, '\0', 64);
|
|
|
|
snprintf(str, 64, "bitmap%04d", i);
|
|
|
|
bm_lockres = lockres_init(mddev, str, NULL, 1);
|
|
|
|
if (!bm_lockres)
|
|
|
|
return -ENOMEM;
|
2016-01-23 07:54:42 +08:00
|
|
|
if (i == (cinfo->slot_number - 1)) {
|
|
|
|
lockres_free(bm_lockres);
|
2014-06-07 01:35:34 +08:00
|
|
|
continue;
|
2016-01-23 07:54:42 +08:00
|
|
|
}
|
2014-06-07 01:35:34 +08:00
|
|
|
|
|
|
|
bm_lockres->flags |= DLM_LKF_NOQUEUE;
|
|
|
|
ret = dlm_lock_sync(bm_lockres, DLM_LOCK_PW);
|
|
|
|
if (ret == -EAGAIN) {
|
2018-10-18 16:37:48 +08:00
|
|
|
if (read_resync_info(mddev, bm_lockres)) {
|
2014-06-07 01:35:34 +08:00
|
|
|
pr_info("%s:%d Resync[%llu..%llu] in progress on %d\n",
|
|
|
|
__func__, __LINE__,
|
2018-10-18 16:37:48 +08:00
|
|
|
(unsigned long long) cinfo->suspend_lo,
|
|
|
|
(unsigned long long) cinfo->suspend_hi,
|
|
|
|
i);
|
|
|
|
cinfo->suspend_from = i;
|
2014-06-07 01:35:34 +08:00
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
lockres_free(bm_lockres);
|
|
|
|
continue;
|
|
|
|
}
|
2015-07-10 17:01:20 +08:00
|
|
|
if (ret) {
|
|
|
|
lockres_free(bm_lockres);
|
2014-06-07 01:35:34 +08:00
|
|
|
goto out;
|
2015-07-10 17:01:20 +08:00
|
|
|
}
|
2015-07-10 17:01:22 +08:00
|
|
|
|
|
|
|
/* Read the disk bitmap sb and check if it needs recovery */
|
2018-08-02 06:20:50 +08:00
|
|
|
ret = md_bitmap_copy_from_slot(mddev, i, &lo, &hi, false);
|
2015-07-10 17:01:22 +08:00
|
|
|
if (ret) {
|
|
|
|
pr_warn("md-cluster: Could not gather bitmaps from slot %d", i);
|
|
|
|
lockres_free(bm_lockres);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if ((hi > 0) && (lo < mddev->recovery_cp)) {
|
|
|
|
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
|
|
|
|
mddev->recovery_cp = lo;
|
|
|
|
md_check_recovery(mddev);
|
|
|
|
}
|
|
|
|
|
2014-06-07 01:35:34 +08:00
|
|
|
lockres_free(bm_lockres);
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-29 23:01:53 +08:00
|
|
|
static int join(struct mddev *mddev, int nodes)
|
|
|
|
{
|
2014-03-29 23:20:02 +08:00
|
|
|
struct md_cluster_info *cinfo;
|
2014-03-30 13:42:49 +08:00
|
|
|
int ret, ops_rv;
|
2014-03-29 23:20:02 +08:00
|
|
|
char str[64];
|
|
|
|
|
|
|
|
cinfo = kzalloc(sizeof(struct md_cluster_info), GFP_KERNEL);
|
|
|
|
if (!cinfo)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2015-07-10 17:01:18 +08:00
|
|
|
INIT_LIST_HEAD(&cinfo->suspend_list);
|
|
|
|
spin_lock_init(&cinfo->suspend_lock);
|
2014-03-30 13:42:49 +08:00
|
|
|
init_completion(&cinfo->completion);
|
2015-07-10 17:01:21 +08:00
|
|
|
set_bit(MD_CLUSTER_BEGIN_JOIN_CLUSTER, &cinfo->state);
|
2015-12-21 07:51:00 +08:00
|
|
|
init_waitqueue_head(&cinfo->wait);
|
|
|
|
mutex_init(&cinfo->recv_mutex);
|
2014-03-30 13:42:49 +08:00
|
|
|
|
|
|
|
mddev->cluster_info = cinfo;
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
cinfo->mddev = mddev;
|
2014-03-30 13:42:49 +08:00
|
|
|
|
2014-03-29 23:20:02 +08:00
|
|
|
memset(str, 0, 64);
|
2015-07-10 16:54:02 +08:00
|
|
|
sprintf(str, "%pU", mddev->uuid);
|
2014-03-30 13:42:49 +08:00
|
|
|
ret = dlm_new_lockspace(str, mddev->bitmap_info.cluster_name,
|
|
|
|
DLM_LSFL_FS, LVB_SIZE,
|
|
|
|
&md_ls_ops, mddev, &ops_rv, &cinfo->lockspace);
|
2014-03-29 23:20:02 +08:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
2014-03-30 13:42:49 +08:00
|
|
|
wait_for_completion(&cinfo->completion);
|
2015-04-22 00:25:52 +08:00
|
|
|
if (nodes < cinfo->slot_number) {
|
|
|
|
pr_err("md-cluster: Slot allotted(%d) is greater than available slots(%d).",
|
|
|
|
cinfo->slot_number, nodes);
|
2014-06-07 00:50:56 +08:00
|
|
|
ret = -ERANGE;
|
|
|
|
goto err;
|
|
|
|
}
|
2014-06-07 14:08:29 +08:00
|
|
|
/* Initiate the communication resources */
|
|
|
|
ret = -ENOMEM;
|
|
|
|
cinfo->recv_thread = md_register_thread(recv_daemon, mddev, "cluster_recv");
|
|
|
|
if (!cinfo->recv_thread) {
|
|
|
|
pr_err("md-cluster: cannot allocate memory for recv_thread!\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
cinfo->message_lockres = lockres_init(mddev, "message", NULL, 1);
|
|
|
|
if (!cinfo->message_lockres)
|
|
|
|
goto err;
|
|
|
|
cinfo->token_lockres = lockres_init(mddev, "token", NULL, 0);
|
|
|
|
if (!cinfo->token_lockres)
|
|
|
|
goto err;
|
2014-10-30 07:51:31 +08:00
|
|
|
cinfo->no_new_dev_lockres = lockres_init(mddev, "no-new-dev", NULL, 0);
|
|
|
|
if (!cinfo->no_new_dev_lockres)
|
|
|
|
goto err;
|
|
|
|
|
2016-05-02 23:33:12 +08:00
|
|
|
ret = dlm_lock_sync(cinfo->token_lockres, DLM_LOCK_EX);
|
|
|
|
if (ret) {
|
|
|
|
ret = -EAGAIN;
|
|
|
|
pr_err("md-cluster: can't join cluster to avoid lock issue\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
cinfo->ack_lockres = lockres_init(mddev, "ack", ack_bast, 0);
|
2016-08-21 22:42:25 +08:00
|
|
|
if (!cinfo->ack_lockres) {
|
|
|
|
ret = -ENOMEM;
|
2016-05-02 23:33:12 +08:00
|
|
|
goto err;
|
2016-08-21 22:42:25 +08:00
|
|
|
}
|
2014-06-07 14:08:29 +08:00
|
|
|
/* get sync CR lock on ACK. */
|
|
|
|
if (dlm_lock_sync(cinfo->ack_lockres, DLM_LOCK_CR))
|
|
|
|
pr_err("md-cluster: failed to get a sync CR lock on ACK!(%d)\n",
|
|
|
|
ret);
|
2016-05-02 23:33:12 +08:00
|
|
|
dlm_unlock_sync(cinfo->token_lockres);
|
2014-10-30 07:51:31 +08:00
|
|
|
/* get sync CR lock on no-new-dev. */
|
|
|
|
if (dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR))
|
|
|
|
pr_err("md-cluster: failed to get a sync CR lock on no-new-dev!(%d)\n", ret);
|
|
|
|
|
2014-06-07 01:12:32 +08:00
|
|
|
|
|
|
|
pr_info("md-cluster: Joined cluster %s slot %d\n", str, cinfo->slot_number);
|
|
|
|
snprintf(str, 64, "bitmap%04d", cinfo->slot_number - 1);
|
|
|
|
cinfo->bitmap_lockres = lockres_init(mddev, str, NULL, 1);
|
2016-08-21 22:42:25 +08:00
|
|
|
if (!cinfo->bitmap_lockres) {
|
|
|
|
ret = -ENOMEM;
|
2014-06-07 01:12:32 +08:00
|
|
|
goto err;
|
2016-08-21 22:42:25 +08:00
|
|
|
}
|
2014-06-07 01:12:32 +08:00
|
|
|
if (dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW)) {
|
|
|
|
pr_err("Failed to get bitmap lock\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2015-10-01 02:20:35 +08:00
|
|
|
cinfo->resync_lockres = lockres_init(mddev, "resync", NULL, 0);
|
2016-08-21 22:42:25 +08:00
|
|
|
if (!cinfo->resync_lockres) {
|
|
|
|
ret = -ENOMEM;
|
2015-10-01 02:20:35 +08:00
|
|
|
goto err;
|
2016-08-21 22:42:25 +08:00
|
|
|
}
|
2015-10-01 02:20:35 +08:00
|
|
|
|
2014-03-29 23:01:53 +08:00
|
|
|
return 0;
|
2014-03-29 23:20:02 +08:00
|
|
|
err:
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
set_bit(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state);
|
2016-05-02 23:33:11 +08:00
|
|
|
md_unregister_thread(&cinfo->recovery_thread);
|
|
|
|
md_unregister_thread(&cinfo->recv_thread);
|
2014-06-07 14:08:29 +08:00
|
|
|
lockres_free(cinfo->message_lockres);
|
|
|
|
lockres_free(cinfo->token_lockres);
|
|
|
|
lockres_free(cinfo->ack_lockres);
|
2014-10-30 07:51:31 +08:00
|
|
|
lockres_free(cinfo->no_new_dev_lockres);
|
2015-10-01 02:20:35 +08:00
|
|
|
lockres_free(cinfo->resync_lockres);
|
2014-06-07 01:35:34 +08:00
|
|
|
lockres_free(cinfo->bitmap_lockres);
|
2014-03-29 23:20:02 +08:00
|
|
|
if (cinfo->lockspace)
|
|
|
|
dlm_release_lockspace(cinfo->lockspace, 2);
|
2014-03-30 13:42:49 +08:00
|
|
|
mddev->cluster_info = NULL;
|
2014-03-29 23:20:02 +08:00
|
|
|
kfree(cinfo);
|
|
|
|
return ret;
|
2014-03-29 23:01:53 +08:00
|
|
|
}
|
|
|
|
|
2016-05-04 14:17:09 +08:00
|
|
|
static void load_bitmaps(struct mddev *mddev, int total_slots)
|
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
|
|
|
|
/* load all the node's bitmap info for resync */
|
|
|
|
if (gather_all_resync_info(mddev, total_slots))
|
|
|
|
pr_err("md-cluster: failed to gather all resyn infos\n");
|
|
|
|
set_bit(MD_CLUSTER_ALREADY_IN_CLUSTER, &cinfo->state);
|
|
|
|
/* wake up recv thread in case something need to be handled */
|
|
|
|
if (test_and_clear_bit(MD_CLUSTER_PENDING_RECV_EVENT, &cinfo->state))
|
|
|
|
md_wakeup_thread(cinfo->recv_thread);
|
|
|
|
}
|
|
|
|
|
2015-10-01 00:09:18 +08:00
|
|
|
static void resync_bitmap(struct mddev *mddev)
|
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
struct cluster_msg cmsg = {0};
|
|
|
|
int err;
|
|
|
|
|
|
|
|
cmsg.type = cpu_to_le32(BITMAP_NEEDS_SYNC);
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
err = sendmsg(cinfo, &cmsg, 1);
|
2015-10-01 00:09:18 +08:00
|
|
|
if (err)
|
|
|
|
pr_err("%s:%d: failed to send BITMAP_NEEDS_SYNC message (%d)\n",
|
|
|
|
__func__, __LINE__, err);
|
|
|
|
}
|
|
|
|
|
2015-12-21 07:51:00 +08:00
|
|
|
static void unlock_all_bitmaps(struct mddev *mddev);
|
2014-03-29 23:01:53 +08:00
|
|
|
static int leave(struct mddev *mddev)
|
|
|
|
{
|
2014-03-29 23:20:02 +08:00
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
|
|
|
|
if (!cinfo)
|
|
|
|
return 0;
|
2015-10-01 00:09:18 +08:00
|
|
|
|
2018-10-18 16:37:47 +08:00
|
|
|
/*
|
|
|
|
* BITMAP_NEEDS_SYNC message should be sent when node
|
2015-10-01 00:09:18 +08:00
|
|
|
* is leaving the cluster with dirty bitmap, also we
|
2018-10-18 16:37:47 +08:00
|
|
|
* can only deliver it when dlm connection is available.
|
|
|
|
*
|
|
|
|
* Also, we should send BITMAP_NEEDS_SYNC message in
|
|
|
|
* case reshaping is interrupted.
|
|
|
|
*/
|
|
|
|
if ((cinfo->slot_number > 0 && mddev->recovery_cp != MaxSector) ||
|
|
|
|
(mddev->reshape_position != MaxSector &&
|
|
|
|
test_bit(MD_CLOSING, &mddev->flags)))
|
2015-10-01 00:09:18 +08:00
|
|
|
resync_bitmap(mddev);
|
|
|
|
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
set_bit(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state);
|
2014-06-07 13:45:22 +08:00
|
|
|
md_unregister_thread(&cinfo->recovery_thread);
|
2014-06-07 14:08:29 +08:00
|
|
|
md_unregister_thread(&cinfo->recv_thread);
|
|
|
|
lockres_free(cinfo->message_lockres);
|
|
|
|
lockres_free(cinfo->token_lockres);
|
|
|
|
lockres_free(cinfo->ack_lockres);
|
2014-10-30 07:51:31 +08:00
|
|
|
lockres_free(cinfo->no_new_dev_lockres);
|
2016-01-23 07:54:42 +08:00
|
|
|
lockres_free(cinfo->resync_lockres);
|
2014-06-07 01:12:32 +08:00
|
|
|
lockres_free(cinfo->bitmap_lockres);
|
2015-12-21 07:51:00 +08:00
|
|
|
unlock_all_bitmaps(mddev);
|
2014-03-29 23:20:02 +08:00
|
|
|
dlm_release_lockspace(cinfo->lockspace, 2);
|
2017-02-24 11:15:12 +08:00
|
|
|
kfree(cinfo);
|
2014-03-29 23:01:53 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-30 13:42:49 +08:00
|
|
|
/* slot_number(): Returns the MD slot number to use
|
|
|
|
* DLM starts the slot numbers from 1, wheras cluster-md
|
|
|
|
* wants the number to be from zero, so we deduct one
|
|
|
|
*/
|
|
|
|
static int slot_number(struct mddev *mddev)
|
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
|
|
|
|
return cinfo->slot_number - 1;
|
|
|
|
}
|
|
|
|
|
2015-12-21 07:51:00 +08:00
|
|
|
/*
|
|
|
|
* Check if the communication is already locked, else lock the communication
|
|
|
|
* channel.
|
|
|
|
* If it is already locked, token is in EX mode, and hence lock_token()
|
|
|
|
* should not be called.
|
|
|
|
*/
|
2014-06-07 14:44:51 +08:00
|
|
|
static int metadata_update_start(struct mddev *mddev)
|
|
|
|
{
|
2015-12-21 07:51:00 +08:00
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* metadata_update_start is always called with the protection of
|
|
|
|
* reconfig_mutex, so set WAITING_FOR_TOKEN here.
|
|
|
|
*/
|
|
|
|
ret = test_and_set_bit_lock(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD,
|
|
|
|
&cinfo->state);
|
|
|
|
WARN_ON_ONCE(ret);
|
|
|
|
md_wakeup_thread(mddev->thread);
|
2015-12-21 07:51:00 +08:00
|
|
|
|
|
|
|
wait_event(cinfo->wait,
|
|
|
|
!test_and_set_bit(MD_CLUSTER_SEND_LOCK, &cinfo->state) ||
|
|
|
|
test_and_clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state));
|
|
|
|
|
|
|
|
/* If token is already locked, return 0 */
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
if (cinfo->token_lockres->mode == DLM_LOCK_EX) {
|
|
|
|
clear_bit_unlock(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state);
|
2015-12-21 07:51:00 +08:00
|
|
|
return 0;
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
}
|
2015-12-21 07:51:00 +08:00
|
|
|
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
ret = lock_token(cinfo, 1);
|
|
|
|
clear_bit_unlock(MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD, &cinfo->state);
|
|
|
|
return ret;
|
2014-06-07 14:44:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int metadata_update_finish(struct mddev *mddev)
|
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
struct cluster_msg cmsg;
|
2015-08-21 23:33:39 +08:00
|
|
|
struct md_rdev *rdev;
|
|
|
|
int ret = 0;
|
2015-10-16 10:48:35 +08:00
|
|
|
int raid_slot = -1;
|
2014-06-07 14:44:51 +08:00
|
|
|
|
|
|
|
memset(&cmsg, 0, sizeof(cmsg));
|
|
|
|
cmsg.type = cpu_to_le32(METADATA_UPDATED);
|
2015-08-21 23:33:39 +08:00
|
|
|
/* Pick up a good active device number to send.
|
|
|
|
*/
|
|
|
|
rdev_for_each(rdev, mddev)
|
|
|
|
if (rdev->raid_disk > -1 && !test_bit(Faulty, &rdev->flags)) {
|
2015-10-16 10:48:35 +08:00
|
|
|
raid_slot = rdev->desc_nr;
|
2015-08-21 23:33:39 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-10-16 10:48:35 +08:00
|
|
|
if (raid_slot >= 0) {
|
|
|
|
cmsg.raid_slot = cpu_to_le32(raid_slot);
|
2015-08-21 23:33:39 +08:00
|
|
|
ret = __sendmsg(cinfo, &cmsg);
|
2015-10-16 10:48:35 +08:00
|
|
|
} else
|
2015-08-21 23:33:39 +08:00
|
|
|
pr_warn("md-cluster: No good device id found to send\n");
|
2015-12-21 07:51:00 +08:00
|
|
|
clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state);
|
2014-06-07 14:44:51 +08:00
|
|
|
unlock_comm(cinfo);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-02 02:20:27 +08:00
|
|
|
static void metadata_update_cancel(struct mddev *mddev)
|
2014-06-07 14:44:51 +08:00
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
2015-12-21 07:51:00 +08:00
|
|
|
clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state);
|
2015-10-02 02:20:27 +08:00
|
|
|
unlock_comm(cinfo);
|
2014-06-07 14:44:51 +08:00
|
|
|
}
|
|
|
|
|
2018-10-18 16:37:41 +08:00
|
|
|
static int update_bitmap_size(struct mddev *mddev, sector_t size)
|
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
struct cluster_msg cmsg = {0};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
cmsg.type = cpu_to_le32(BITMAP_RESIZE);
|
|
|
|
cmsg.high = cpu_to_le64(size);
|
|
|
|
ret = sendmsg(cinfo, &cmsg, 0);
|
|
|
|
if (ret)
|
|
|
|
pr_err("%s:%d: failed to send BITMAP_RESIZE message (%d)\n",
|
|
|
|
__func__, __LINE__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int resize_bitmaps(struct mddev *mddev, sector_t newsize, sector_t oldsize)
|
|
|
|
{
|
|
|
|
struct bitmap_counts *counts;
|
|
|
|
char str[64];
|
|
|
|
struct dlm_lock_resource *bm_lockres;
|
|
|
|
struct bitmap *bitmap = mddev->bitmap;
|
|
|
|
unsigned long my_pages = bitmap->counts.pages;
|
|
|
|
int i, rv;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to ensure all the nodes can grow to a larger
|
|
|
|
* bitmap size before make the reshaping.
|
|
|
|
*/
|
|
|
|
rv = update_bitmap_size(mddev, newsize);
|
|
|
|
if (rv)
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
for (i = 0; i < mddev->bitmap_info.nodes; i++) {
|
|
|
|
if (i == md_cluster_ops->slot_number(mddev))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bitmap = get_bitmap_from_slot(mddev, i);
|
|
|
|
if (IS_ERR(bitmap)) {
|
|
|
|
pr_err("can't get bitmap from slot %d\n", i);
|
2020-08-04 18:16:45 +08:00
|
|
|
bitmap = NULL;
|
2018-10-18 16:37:41 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
counts = &bitmap->counts;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we can hold the bitmap lock of one node then
|
|
|
|
* the slot is not occupied, update the pages.
|
|
|
|
*/
|
|
|
|
snprintf(str, 64, "bitmap%04d", i);
|
|
|
|
bm_lockres = lockres_init(mddev, str, NULL, 1);
|
|
|
|
if (!bm_lockres) {
|
|
|
|
pr_err("Cannot initialize %s lock\n", str);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
bm_lockres->flags |= DLM_LKF_NOQUEUE;
|
|
|
|
rv = dlm_lock_sync(bm_lockres, DLM_LOCK_PW);
|
|
|
|
if (!rv)
|
|
|
|
counts->pages = my_pages;
|
|
|
|
lockres_free(bm_lockres);
|
|
|
|
|
|
|
|
if (my_pages != counts->pages)
|
|
|
|
/*
|
|
|
|
* Let's revert the bitmap size if one node
|
|
|
|
* can't resize bitmap
|
|
|
|
*/
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
out:
|
|
|
|
md_bitmap_free(bitmap);
|
|
|
|
update_bitmap_size(mddev, oldsize);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-03-01 16:42:39 +08:00
|
|
|
/*
|
|
|
|
* return 0 if all the bitmaps have the same sync_size
|
|
|
|
*/
|
2017-10-03 17:51:17 +08:00
|
|
|
static int cluster_check_sync_size(struct mddev *mddev)
|
2017-03-01 16:42:39 +08:00
|
|
|
{
|
|
|
|
int i, rv;
|
|
|
|
bitmap_super_t *sb;
|
|
|
|
unsigned long my_sync_size, sync_size = 0;
|
|
|
|
int node_num = mddev->bitmap_info.nodes;
|
|
|
|
int current_slot = md_cluster_ops->slot_number(mddev);
|
|
|
|
struct bitmap *bitmap = mddev->bitmap;
|
|
|
|
char str[64];
|
|
|
|
struct dlm_lock_resource *bm_lockres;
|
|
|
|
|
|
|
|
sb = kmap_atomic(bitmap->storage.sb_page);
|
|
|
|
my_sync_size = sb->sync_size;
|
|
|
|
kunmap_atomic(sb);
|
|
|
|
|
|
|
|
for (i = 0; i < node_num; i++) {
|
|
|
|
if (i == current_slot)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
bitmap = get_bitmap_from_slot(mddev, i);
|
|
|
|
if (IS_ERR(bitmap)) {
|
|
|
|
pr_err("can't get bitmap from slot %d\n", i);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we can hold the bitmap lock of one node then
|
|
|
|
* the slot is not occupied, update the sb.
|
|
|
|
*/
|
|
|
|
snprintf(str, 64, "bitmap%04d", i);
|
|
|
|
bm_lockres = lockres_init(mddev, str, NULL, 1);
|
|
|
|
if (!bm_lockres) {
|
|
|
|
pr_err("md-cluster: Cannot initialize %s\n", str);
|
2018-08-02 06:20:50 +08:00
|
|
|
md_bitmap_free(bitmap);
|
2017-03-01 16:42:39 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
bm_lockres->flags |= DLM_LKF_NOQUEUE;
|
|
|
|
rv = dlm_lock_sync(bm_lockres, DLM_LOCK_PW);
|
|
|
|
if (!rv)
|
2018-08-02 06:20:50 +08:00
|
|
|
md_bitmap_update_sb(bitmap);
|
2017-03-01 16:42:39 +08:00
|
|
|
lockres_free(bm_lockres);
|
|
|
|
|
|
|
|
sb = kmap_atomic(bitmap->storage.sb_page);
|
|
|
|
if (sync_size == 0)
|
|
|
|
sync_size = sb->sync_size;
|
|
|
|
else if (sync_size != sb->sync_size) {
|
|
|
|
kunmap_atomic(sb);
|
2018-08-02 06:20:50 +08:00
|
|
|
md_bitmap_free(bitmap);
|
2017-03-01 16:42:39 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
kunmap_atomic(sb);
|
2018-08-02 06:20:50 +08:00
|
|
|
md_bitmap_free(bitmap);
|
2017-03-01 16:42:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return (my_sync_size == sync_size) ? 0 : -1;
|
|
|
|
}
|
|
|
|
|
2017-03-01 16:42:40 +08:00
|
|
|
/*
|
|
|
|
* Update the size for cluster raid is a little more complex, we perform it
|
|
|
|
* by the steps:
|
|
|
|
* 1. hold token lock and update superblock in initiator node.
|
|
|
|
* 2. send METADATA_UPDATED msg to other nodes.
|
|
|
|
* 3. The initiator node continues to check each bitmap's sync_size, if all
|
|
|
|
* bitmaps have the same value of sync_size, then we can set capacity and
|
|
|
|
* let other nodes to perform it. If one node can't update sync_size
|
|
|
|
* accordingly, we need to revert to previous value.
|
|
|
|
*/
|
|
|
|
static void update_size(struct mddev *mddev, sector_t old_dev_sectors)
|
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
struct cluster_msg cmsg;
|
|
|
|
struct md_rdev *rdev;
|
|
|
|
int ret = 0;
|
|
|
|
int raid_slot = -1;
|
|
|
|
|
|
|
|
md_update_sb(mddev, 1);
|
|
|
|
lock_comm(cinfo, 1);
|
|
|
|
|
|
|
|
memset(&cmsg, 0, sizeof(cmsg));
|
|
|
|
cmsg.type = cpu_to_le32(METADATA_UPDATED);
|
|
|
|
rdev_for_each(rdev, mddev)
|
|
|
|
if (rdev->raid_disk >= 0 && !test_bit(Faulty, &rdev->flags)) {
|
|
|
|
raid_slot = rdev->desc_nr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (raid_slot >= 0) {
|
|
|
|
cmsg.raid_slot = cpu_to_le32(raid_slot);
|
|
|
|
/*
|
|
|
|
* We can only change capiticy after all the nodes can do it,
|
|
|
|
* so need to wait after other nodes already received the msg
|
|
|
|
* and handled the change
|
|
|
|
*/
|
|
|
|
ret = __sendmsg(cinfo, &cmsg);
|
|
|
|
if (ret) {
|
|
|
|
pr_err("%s:%d: failed to send METADATA_UPDATED msg\n",
|
|
|
|
__func__, __LINE__);
|
|
|
|
unlock_comm(cinfo);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pr_err("md-cluster: No good device id found to send\n");
|
|
|
|
unlock_comm(cinfo);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check the sync_size from other node's bitmap, if sync_size
|
|
|
|
* have already updated in other nodes as expected, send an
|
|
|
|
* empty metadata msg to permit the change of capacity
|
|
|
|
*/
|
|
|
|
if (cluster_check_sync_size(mddev) == 0) {
|
|
|
|
memset(&cmsg, 0, sizeof(cmsg));
|
|
|
|
cmsg.type = cpu_to_le32(CHANGE_CAPACITY);
|
|
|
|
ret = __sendmsg(cinfo, &cmsg);
|
|
|
|
if (ret)
|
|
|
|
pr_err("%s:%d: failed to send CHANGE_CAPACITY msg\n",
|
|
|
|
__func__, __LINE__);
|
|
|
|
set_capacity(mddev->gendisk, mddev->array_sectors);
|
2020-09-01 23:57:43 +08:00
|
|
|
revalidate_disk_size(mddev->gendisk, true);
|
2017-03-01 16:42:40 +08:00
|
|
|
} else {
|
|
|
|
/* revert to previous sectors */
|
|
|
|
ret = mddev->pers->resize(mddev, old_dev_sectors);
|
|
|
|
if (!ret)
|
2020-09-01 23:57:43 +08:00
|
|
|
revalidate_disk_size(mddev->gendisk, true);
|
2017-03-01 16:42:40 +08:00
|
|
|
ret = __sendmsg(cinfo, &cmsg);
|
|
|
|
if (ret)
|
|
|
|
pr_err("%s:%d: failed to send METADATA_UPDATED msg\n",
|
|
|
|
__func__, __LINE__);
|
|
|
|
}
|
|
|
|
unlock_comm(cinfo);
|
|
|
|
}
|
|
|
|
|
2015-10-01 02:20:35 +08:00
|
|
|
static int resync_start(struct mddev *mddev)
|
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
2016-08-12 13:42:43 +08:00
|
|
|
return dlm_lock_sync_interruptible(cinfo->resync_lockres, DLM_LOCK_EX, mddev);
|
2015-10-01 02:20:35 +08:00
|
|
|
}
|
|
|
|
|
2018-10-18 16:37:43 +08:00
|
|
|
static void resync_info_get(struct mddev *mddev, sector_t *lo, sector_t *hi)
|
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
|
|
|
|
spin_lock_irq(&cinfo->suspend_lock);
|
2018-10-18 16:37:48 +08:00
|
|
|
*lo = cinfo->suspend_lo;
|
|
|
|
*hi = cinfo->suspend_hi;
|
2018-10-18 16:37:43 +08:00
|
|
|
spin_unlock_irq(&cinfo->suspend_lock);
|
|
|
|
}
|
|
|
|
|
2015-08-19 06:14:42 +08:00
|
|
|
static int resync_info_update(struct mddev *mddev, sector_t lo, sector_t hi)
|
2014-06-07 15:16:58 +08:00
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
2015-12-21 07:50:59 +08:00
|
|
|
struct resync_info ri;
|
2015-10-12 17:21:24 +08:00
|
|
|
struct cluster_msg cmsg = {0};
|
2014-06-07 15:16:58 +08:00
|
|
|
|
2015-12-21 07:50:59 +08:00
|
|
|
/* do not send zero again, if we have sent before */
|
|
|
|
if (hi == 0) {
|
|
|
|
memcpy(&ri, cinfo->bitmap_lockres->lksb.sb_lvbptr, sizeof(struct resync_info));
|
|
|
|
if (le64_to_cpu(ri.hi) == 0)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-10-19 12:44:00 +08:00
|
|
|
add_resync_info(cinfo->bitmap_lockres, lo, hi);
|
2015-08-19 06:14:42 +08:00
|
|
|
/* Re-acquire the lock to refresh LVB */
|
|
|
|
dlm_lock_sync(cinfo->bitmap_lockres, DLM_LOCK_PW);
|
|
|
|
cmsg.type = cpu_to_le32(RESYNCING);
|
2014-06-07 15:16:58 +08:00
|
|
|
cmsg.low = cpu_to_le64(lo);
|
|
|
|
cmsg.high = cpu_to_le64(hi);
|
2015-10-01 02:20:35 +08:00
|
|
|
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
/*
|
|
|
|
* mddev_lock is held if resync_info_update is called from
|
|
|
|
* resync_finish (md_reap_sync_thread -> resync_finish)
|
|
|
|
*/
|
|
|
|
if (lo == 0 && hi == 0)
|
|
|
|
return sendmsg(cinfo, &cmsg, 1);
|
|
|
|
else
|
|
|
|
return sendmsg(cinfo, &cmsg, 0);
|
2014-06-07 15:16:58 +08:00
|
|
|
}
|
|
|
|
|
2015-10-01 02:20:35 +08:00
|
|
|
static int resync_finish(struct mddev *mddev)
|
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
2018-08-31 10:05:57 +08:00
|
|
|
int ret = 0;
|
2018-07-02 16:26:25 +08:00
|
|
|
|
|
|
|
clear_bit(MD_RESYNCING_REMOTE, &mddev->recovery);
|
2018-07-02 16:26:26 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If resync thread is interrupted so we can't say resync is finished,
|
|
|
|
* another node will launch resync thread to continue.
|
|
|
|
*/
|
2018-08-31 10:05:57 +08:00
|
|
|
if (!test_bit(MD_CLOSING, &mddev->flags))
|
|
|
|
ret = resync_info_update(mddev, 0, 0);
|
|
|
|
dlm_unlock_sync(cinfo->resync_lockres);
|
|
|
|
return ret;
|
2015-10-01 02:20:35 +08:00
|
|
|
}
|
|
|
|
|
2015-06-24 22:30:32 +08:00
|
|
|
static int area_resyncing(struct mddev *mddev, int direction,
|
|
|
|
sector_t lo, sector_t hi)
|
2014-06-07 15:39:37 +08:00
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
int ret = 0;
|
|
|
|
|
2015-06-24 22:30:32 +08:00
|
|
|
if ((direction == READ) &&
|
|
|
|
test_bit(MD_CLUSTER_SUSPEND_READ_BALANCING, &cinfo->state))
|
|
|
|
return 1;
|
|
|
|
|
2014-06-07 15:39:37 +08:00
|
|
|
spin_lock_irq(&cinfo->suspend_lock);
|
2018-10-18 16:37:48 +08:00
|
|
|
if (hi > cinfo->suspend_lo && lo < cinfo->suspend_hi)
|
|
|
|
ret = 1;
|
2014-06-07 15:39:37 +08:00
|
|
|
spin_unlock_irq(&cinfo->suspend_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-02 02:20:27 +08:00
|
|
|
/* add_new_disk() - initiates a disk add
|
|
|
|
* However, if this fails before writing md_update_sb(),
|
|
|
|
* add_new_disk_cancel() must be called to release token lock
|
|
|
|
*/
|
|
|
|
static int add_new_disk(struct mddev *mddev, struct md_rdev *rdev)
|
2014-10-30 07:51:31 +08:00
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
struct cluster_msg cmsg;
|
|
|
|
int ret = 0;
|
|
|
|
struct mdp_superblock_1 *sb = page_address(rdev->sb_page);
|
|
|
|
char *uuid = sb->device_uuid;
|
|
|
|
|
|
|
|
memset(&cmsg, 0, sizeof(cmsg));
|
|
|
|
cmsg.type = cpu_to_le32(NEWDISK);
|
|
|
|
memcpy(cmsg.uuid, uuid, 16);
|
2015-10-12 17:21:21 +08:00
|
|
|
cmsg.raid_slot = cpu_to_le32(rdev->desc_nr);
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
lock_comm(cinfo, 1);
|
2014-10-30 07:51:31 +08:00
|
|
|
ret = __sendmsg(cinfo, &cmsg);
|
2017-05-16 14:01:25 +08:00
|
|
|
if (ret) {
|
|
|
|
unlock_comm(cinfo);
|
2014-10-30 07:51:31 +08:00
|
|
|
return ret;
|
2017-05-16 14:01:25 +08:00
|
|
|
}
|
2014-10-30 07:51:31 +08:00
|
|
|
cinfo->no_new_dev_lockres->flags |= DLM_LKF_NOQUEUE;
|
|
|
|
ret = dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_EX);
|
|
|
|
cinfo->no_new_dev_lockres->flags &= ~DLM_LKF_NOQUEUE;
|
|
|
|
/* Some node does not "see" the device */
|
|
|
|
if (ret == -EAGAIN)
|
|
|
|
ret = -ENOENT;
|
2015-10-02 02:20:27 +08:00
|
|
|
if (ret)
|
|
|
|
unlock_comm(cinfo);
|
2015-12-21 07:51:00 +08:00
|
|
|
else {
|
2014-10-30 07:51:31 +08:00
|
|
|
dlm_lock_sync(cinfo->no_new_dev_lockres, DLM_LOCK_CR);
|
2015-12-21 07:51:01 +08:00
|
|
|
/* Since MD_CHANGE_DEVS will be set in add_bound_rdev which
|
|
|
|
* will run soon after add_new_disk, the below path will be
|
|
|
|
* invoked:
|
|
|
|
* md_wakeup_thread(mddev->thread)
|
|
|
|
* -> conf->thread (raid1d)
|
|
|
|
* -> md_check_recovery -> md_update_sb
|
|
|
|
* -> metadata_update_start/finish
|
|
|
|
* MD_CLUSTER_SEND_LOCKED_ALREADY will be cleared eventually.
|
|
|
|
*
|
|
|
|
* For other failure cases, metadata_update_cancel and
|
|
|
|
* add_new_disk_cancel also clear below bit as well.
|
|
|
|
* */
|
2015-12-21 07:51:00 +08:00
|
|
|
set_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state);
|
|
|
|
wake_up(&cinfo->wait);
|
|
|
|
}
|
2014-10-30 07:51:31 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-02 02:20:27 +08:00
|
|
|
static void add_new_disk_cancel(struct mddev *mddev)
|
2014-10-30 07:51:31 +08:00
|
|
|
{
|
2015-10-02 02:20:27 +08:00
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
2015-12-21 07:51:00 +08:00
|
|
|
clear_bit(MD_CLUSTER_SEND_LOCKED_ALREADY, &cinfo->state);
|
2015-10-02 02:20:27 +08:00
|
|
|
unlock_comm(cinfo);
|
2014-10-30 07:51:31 +08:00
|
|
|
}
|
|
|
|
|
2015-03-03 00:55:49 +08:00
|
|
|
static int new_disk_ack(struct mddev *mddev, bool ack)
|
2014-10-30 07:51:31 +08:00
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
|
2015-03-03 00:55:49 +08:00
|
|
|
if (!test_bit(MD_CLUSTER_WAITING_FOR_NEWDISK, &cinfo->state)) {
|
|
|
|
pr_warn("md-cluster(%s): Spurious cluster confirmation\n", mdname(mddev));
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2014-10-30 07:51:31 +08:00
|
|
|
if (ack)
|
|
|
|
dlm_unlock_sync(cinfo->no_new_dev_lockres);
|
|
|
|
complete(&cinfo->newdisk_completion);
|
2015-03-03 00:55:49 +08:00
|
|
|
return 0;
|
2014-10-30 07:51:31 +08:00
|
|
|
}
|
|
|
|
|
2015-04-14 23:44:44 +08:00
|
|
|
static int remove_disk(struct mddev *mddev, struct md_rdev *rdev)
|
|
|
|
{
|
2015-10-12 17:21:24 +08:00
|
|
|
struct cluster_msg cmsg = {0};
|
2015-04-14 23:44:44 +08:00
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
2015-10-12 17:21:21 +08:00
|
|
|
cmsg.type = cpu_to_le32(REMOVE);
|
|
|
|
cmsg.raid_slot = cpu_to_le32(rdev->desc_nr);
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
return sendmsg(cinfo, &cmsg, 1);
|
2015-04-14 23:44:44 +08:00
|
|
|
}
|
|
|
|
|
2015-12-21 07:51:00 +08:00
|
|
|
static int lock_all_bitmaps(struct mddev *mddev)
|
|
|
|
{
|
|
|
|
int slot, my_slot, ret, held = 1, i = 0;
|
|
|
|
char str[64];
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
|
treewide: kzalloc() -> kcalloc()
The kzalloc() function has a 2-factor argument form, kcalloc(). This
patch replaces cases of:
kzalloc(a * b, gfp)
with:
kcalloc(a * b, gfp)
as well as handling cases of:
kzalloc(a * b * c, gfp)
with:
kzalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kzalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kzalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kzalloc
+ kcalloc
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kzalloc(sizeof(THING) * C2, ...)
|
kzalloc(sizeof(TYPE) * C2, ...)
|
kzalloc(C1 * C2 * C3, ...)
|
kzalloc(C1 * C2, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * E2
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kzalloc
+ kcalloc
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 05:03:40 +08:00
|
|
|
cinfo->other_bitmap_lockres =
|
|
|
|
kcalloc(mddev->bitmap_info.nodes - 1,
|
|
|
|
sizeof(struct dlm_lock_resource *), GFP_KERNEL);
|
2015-12-21 07:51:00 +08:00
|
|
|
if (!cinfo->other_bitmap_lockres) {
|
|
|
|
pr_err("md: can't alloc mem for other bitmap locks\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
my_slot = slot_number(mddev);
|
|
|
|
for (slot = 0; slot < mddev->bitmap_info.nodes; slot++) {
|
|
|
|
if (slot == my_slot)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
memset(str, '\0', 64);
|
|
|
|
snprintf(str, 64, "bitmap%04d", slot);
|
|
|
|
cinfo->other_bitmap_lockres[i] = lockres_init(mddev, str, NULL, 1);
|
|
|
|
if (!cinfo->other_bitmap_lockres[i])
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
cinfo->other_bitmap_lockres[i]->flags |= DLM_LKF_NOQUEUE;
|
|
|
|
ret = dlm_lock_sync(cinfo->other_bitmap_lockres[i], DLM_LOCK_PW);
|
|
|
|
if (ret)
|
|
|
|
held = -1;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return held;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unlock_all_bitmaps(struct mddev *mddev)
|
|
|
|
{
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* release other node's bitmap lock if they are existed */
|
|
|
|
if (cinfo->other_bitmap_lockres) {
|
|
|
|
for (i = 0; i < mddev->bitmap_info.nodes - 1; i++) {
|
|
|
|
if (cinfo->other_bitmap_lockres[i]) {
|
|
|
|
lockres_free(cinfo->other_bitmap_lockres[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
kfree(cinfo->other_bitmap_lockres);
|
2020-07-09 11:29:29 +08:00
|
|
|
cinfo->other_bitmap_lockres = NULL;
|
2015-12-21 07:51:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-14 23:45:42 +08:00
|
|
|
static int gather_bitmaps(struct md_rdev *rdev)
|
|
|
|
{
|
|
|
|
int sn, err;
|
|
|
|
sector_t lo, hi;
|
2015-10-12 17:21:24 +08:00
|
|
|
struct cluster_msg cmsg = {0};
|
2015-04-14 23:45:42 +08:00
|
|
|
struct mddev *mddev = rdev->mddev;
|
|
|
|
struct md_cluster_info *cinfo = mddev->cluster_info;
|
|
|
|
|
2015-10-12 17:21:21 +08:00
|
|
|
cmsg.type = cpu_to_le32(RE_ADD);
|
|
|
|
cmsg.raid_slot = cpu_to_le32(rdev->desc_nr);
|
md-cluster: use sync way to handle METADATA_UPDATED msg
Previously, when node received METADATA_UPDATED msg, it just
need to wakeup mddev->thread, then md_reload_sb will be called
eventually.
We taken the asynchronous way to avoid a deadlock issue, the
deadlock issue could happen when one node is receiving the
METADATA_UPDATED msg (wants reconfig_mutex) and trying to run
the path:
md_check_recovery -> mddev_trylock(hold reconfig_mutex)
-> md_update_sb-metadata_update_start
(want EX on token however token is
got by the sending node)
Since we will support resizing for clustered raid, and we
need the metadata update handling to be synchronous so that
the initiating node can detect failure, so we need to change
the way for handling METADATA_UPDATED msg.
But, we obviously need to avoid above deadlock with the
sync way. To make this happen, we considered to not hold
reconfig_mutex to call md_reload_sb, if some other thread
has already taken reconfig_mutex and waiting for the 'token',
then process_recvd_msg() can safely call md_reload_sb()
without taking the mutex. This is because we can be certain
that no other thread will take the mutex, and we also certain
that the actions performed by md_reload_sb() won't interfere
with anything that the other thread is in the middle of.
To make this more concrete, we added a new cinfo->state bit
MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
Which is set in lock_token() just before dlm_lock_sync() is
called, and cleared just after. As lock_token() is always
called with reconfig_mutex() held (the specific case is the
resync_info_update which is distinguished well in previous
patch), if process_recvd_msg() finds that the new bit is set,
then the mutex must be held by some other thread, and it will
keep waiting.
So process_metadata_update() can call md_reload_sb() if either
mddev_trylock() succeeds, or if MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD
is set. The tricky bit is what to do if neither of these apply.
We need to wait. Fortunately mddev_unlock() always calls wake_up()
on mddev->thread->wqueue. So we can get lock_token() to call
wake_up() on that when it sets the bit.
There are also some related changes inside this commit:
1. remove RELOAD_SB related codes since there are not valid anymore.
2. mddev is added into md_cluster_info then we can get mddev inside
lock_token.
3. add new parameter for lock_token to distinguish reconfig_mutex
is held or not.
And, we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD in below:
1. set it before unregister thread, otherwise a deadlock could
appear if stop a resyncing array.
This is because md_unregister_thread(&cinfo->recv_thread) is
blocked by recv_daemon -> process_recvd_msg
-> process_metadata_update.
To resolve the issue, MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
also need to be set before unregister thread.
2. set it in metadata_update_start to fix another deadlock.
a. Node A sends METADATA_UPDATED msg (held Token lock).
b. Node B wants to do resync, and is blocked since it can't
get Token lock, but MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD is
not set since the callchain
(md_do_sync -> sync_request
-> resync_info_update
-> sendmsg
-> lock_comm -> lock_token)
doesn't hold reconfig_mutex.
c. Node B trys to update sb (held reconfig_mutex), but stopped
at wait_event() in metadata_update_start since we have set
MD_CLUSTER_SEND_LOCK flag in lock_comm (step 2).
d. Then Node B receives METADATA_UPDATED msg from A, of course
recv_daemon is blocked forever.
Since metadata_update_start always calls lock_token with reconfig_mutex,
we need to set MD_CLUSTER_HOLDING_MUTEX_FOR_RECVD here as well, and
lock_token don't need to set it twice unless lock_token is invoked from
lock_comm.
Finally, thanks to Neil for his great idea and help!
Reviewed-by: NeilBrown <neilb@suse.com>
Signed-off-by: Guoqing Jiang <gqjiang@suse.com>
Signed-off-by: Shaohua Li <shli@fb.com>
2017-03-01 17:30:29 +08:00
|
|
|
err = sendmsg(cinfo, &cmsg, 1);
|
2015-04-14 23:45:42 +08:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
for (sn = 0; sn < mddev->bitmap_info.nodes; sn++) {
|
|
|
|
if (sn == (cinfo->slot_number - 1))
|
|
|
|
continue;
|
2018-08-02 06:20:50 +08:00
|
|
|
err = md_bitmap_copy_from_slot(mddev, sn, &lo, &hi, false);
|
2015-04-14 23:45:42 +08:00
|
|
|
if (err) {
|
|
|
|
pr_warn("md-cluster: Could not gather bitmaps from slot %d", sn);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if ((hi > 0) && (lo < mddev->recovery_cp))
|
|
|
|
mddev->recovery_cp = lo;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-03-29 23:01:53 +08:00
|
|
|
static struct md_cluster_operations cluster_ops = {
|
|
|
|
.join = join,
|
|
|
|
.leave = leave,
|
2014-03-30 13:42:49 +08:00
|
|
|
.slot_number = slot_number,
|
2015-10-01 02:20:35 +08:00
|
|
|
.resync_start = resync_start,
|
|
|
|
.resync_finish = resync_finish,
|
2014-06-07 01:35:34 +08:00
|
|
|
.resync_info_update = resync_info_update,
|
2018-10-18 16:37:43 +08:00
|
|
|
.resync_info_get = resync_info_get,
|
2014-06-07 14:44:51 +08:00
|
|
|
.metadata_update_start = metadata_update_start,
|
|
|
|
.metadata_update_finish = metadata_update_finish,
|
|
|
|
.metadata_update_cancel = metadata_update_cancel,
|
2014-06-07 15:39:37 +08:00
|
|
|
.area_resyncing = area_resyncing,
|
2015-10-02 02:20:27 +08:00
|
|
|
.add_new_disk = add_new_disk,
|
|
|
|
.add_new_disk_cancel = add_new_disk_cancel,
|
2014-10-30 07:51:31 +08:00
|
|
|
.new_disk_ack = new_disk_ack,
|
2015-04-14 23:44:44 +08:00
|
|
|
.remove_disk = remove_disk,
|
2016-05-04 14:17:09 +08:00
|
|
|
.load_bitmaps = load_bitmaps,
|
2015-04-14 23:45:42 +08:00
|
|
|
.gather_bitmaps = gather_bitmaps,
|
2018-10-18 16:37:41 +08:00
|
|
|
.resize_bitmaps = resize_bitmaps,
|
2015-12-21 07:51:00 +08:00
|
|
|
.lock_all_bitmaps = lock_all_bitmaps,
|
|
|
|
.unlock_all_bitmaps = unlock_all_bitmaps,
|
2017-03-01 16:42:40 +08:00
|
|
|
.update_size = update_size,
|
2014-03-29 23:01:53 +08:00
|
|
|
};
|
|
|
|
|
2014-03-08 01:21:15 +08:00
|
|
|
static int __init cluster_init(void)
|
|
|
|
{
|
2017-10-24 15:11:53 +08:00
|
|
|
pr_warn("md-cluster: support raid1 and raid10 (limited support)\n");
|
2014-03-08 01:21:15 +08:00
|
|
|
pr_info("Registering Cluster MD functions\n");
|
2014-03-29 23:01:53 +08:00
|
|
|
register_md_cluster_operations(&cluster_ops, THIS_MODULE);
|
2014-03-08 01:21:15 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cluster_exit(void)
|
|
|
|
{
|
2014-03-29 23:01:53 +08:00
|
|
|
unregister_md_cluster_operations();
|
2014-03-08 01:21:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(cluster_init);
|
|
|
|
module_exit(cluster_exit);
|
2015-10-12 17:21:25 +08:00
|
|
|
MODULE_AUTHOR("SUSE");
|
2014-03-08 01:21:15 +08:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("Clustering support for MD");
|