Skip to content

Commit c6ff669

Browse files
committed
dlm: delayed reply message warning
Add an option (disabled by default) to print a warning message when a lock has been waiting a configurable amount of time for a reply message from another node. This is mainly for debugging. Signed-off-by: David Teigland <teigland@redhat.com>
1 parent 4bcad6c commit c6ff669

6 files changed

Lines changed: 108 additions & 11 deletions

File tree

‎fs/dlm/config.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct dlm_cluster {
100100
unsigned int cl_log_debug;
101101
unsigned int cl_protocol;
102102
unsigned int cl_timewarn_cs;
103+
unsigned int cl_waitwarn_us;
103104
};
104105

105106
enum {
@@ -114,6 +115,7 @@ enum {
114115
CLUSTER_ATTR_LOG_DEBUG,
115116
CLUSTER_ATTR_PROTOCOL,
116117
CLUSTER_ATTR_TIMEWARN_CS,
118+
CLUSTER_ATTR_WAITWARN_US,
117119
};
118120

119121
struct cluster_attribute {
@@ -166,6 +168,7 @@ CLUSTER_ATTR(scan_secs, 1);
166168
CLUSTER_ATTR(log_debug, 0);
167169
CLUSTER_ATTR(protocol, 0);
168170
CLUSTER_ATTR(timewarn_cs, 1);
171+
CLUSTER_ATTR(waitwarn_us, 0);
169172

170173
static struct configfs_attribute *cluster_attrs[] = {
171174
[CLUSTER_ATTR_TCP_PORT] = &cluster_attr_tcp_port.attr,
@@ -179,6 +182,7 @@ static struct configfs_attribute *cluster_attrs[] = {
179182
[CLUSTER_ATTR_LOG_DEBUG] = &cluster_attr_log_debug.attr,
180183
[CLUSTER_ATTR_PROTOCOL] = &cluster_attr_protocol.attr,
181184
[CLUSTER_ATTR_TIMEWARN_CS] = &cluster_attr_timewarn_cs.attr,
185+
[CLUSTER_ATTR_WAITWARN_US] = &cluster_attr_waitwarn_us.attr,
182186
NULL,
183187
};
184188

@@ -439,6 +443,7 @@ static struct config_group *make_cluster(struct config_group *g,
439443
cl->cl_log_debug = dlm_config.ci_log_debug;
440444
cl->cl_protocol = dlm_config.ci_protocol;
441445
cl->cl_timewarn_cs = dlm_config.ci_timewarn_cs;
446+
cl->cl_waitwarn_us = dlm_config.ci_waitwarn_us;
442447

443448
space_list = &sps->ss_group;
444449
comm_list = &cms->cs_group;
@@ -986,6 +991,7 @@ int dlm_our_addr(struct sockaddr_storage *addr, int num)
986991
#define DEFAULT_LOG_DEBUG 0
987992
#define DEFAULT_PROTOCOL 0
988993
#define DEFAULT_TIMEWARN_CS 500 /* 5 sec = 500 centiseconds */
994+
#define DEFAULT_WAITWARN_US 0
989995

990996
struct dlm_config_info dlm_config = {
991997
.ci_tcp_port = DEFAULT_TCP_PORT,
@@ -998,6 +1004,7 @@ struct dlm_config_info dlm_config = {
9981004
.ci_scan_secs = DEFAULT_SCAN_SECS,
9991005
.ci_log_debug = DEFAULT_LOG_DEBUG,
10001006
.ci_protocol = DEFAULT_PROTOCOL,
1001-
.ci_timewarn_cs = DEFAULT_TIMEWARN_CS
1007+
.ci_timewarn_cs = DEFAULT_TIMEWARN_CS,
1008+
.ci_waitwarn_us = DEFAULT_WAITWARN_US
10021009
};
10031010

‎fs/dlm/config.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct dlm_config_info {
2828
int ci_log_debug;
2929
int ci_protocol;
3030
int ci_timewarn_cs;
31+
int ci_waitwarn_us;
3132
};
3233

3334
extern struct dlm_config_info dlm_config;

‎fs/dlm/dlm_internal.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ struct dlm_lkb {
245245

246246
int8_t lkb_wait_type; /* type of reply waiting for */
247247
int8_t lkb_wait_count;
248+
int lkb_wait_nodeid; /* for debugging */
248249

249250
struct list_head lkb_idtbl_list; /* lockspace lkbtbl */
250251
struct list_head lkb_statequeue; /* rsb g/c/w list */
@@ -254,6 +255,7 @@ struct dlm_lkb {
254255
struct list_head lkb_ownqueue; /* list of locks for a process */
255256
struct list_head lkb_time_list;
256257
ktime_t lkb_timestamp;
258+
ktime_t lkb_wait_time;
257259
unsigned long lkb_timeout_cs;
258260

259261
struct dlm_callback lkb_callbacks[DLM_CALLBACKS_SIZE];

‎fs/dlm/lock.c‎

Lines changed: 93 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -799,10 +799,84 @@ static int msg_reply_type(int mstype)
799799
return -1;
800800
}
801801

802+
static int nodeid_warned(int nodeid, int num_nodes, int *warned)
803+
{
804+
int i;
805+
806+
for (i = 0; i < num_nodes; i++) {
807+
if (!warned[i]) {
808+
warned[i] = nodeid;
809+
return 0;
810+
}
811+
if (warned[i] == nodeid)
812+
return 1;
813+
}
814+
return 0;
815+
}
816+
817+
void dlm_scan_waiters(struct dlm_ls *ls)
818+
{
819+
struct dlm_lkb *lkb;
820+
ktime_t zero = ktime_set(0, 0);
821+
s64 us;
822+
s64 debug_maxus = 0;
823+
u32 debug_scanned = 0;
824+
u32 debug_expired = 0;
825+
int num_nodes = 0;
826+
int *warned = NULL;
827+
828+
if (!dlm_config.ci_waitwarn_us)
829+
return;
830+
831+
mutex_lock(&ls->ls_waiters_mutex);
832+
833+
list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) {
834+
if (ktime_equal(lkb->lkb_wait_time, zero))
835+
continue;
836+
837+
debug_scanned++;
838+
839+
us = ktime_to_us(ktime_sub(ktime_get(), lkb->lkb_wait_time));
840+
841+
if (us < dlm_config.ci_waitwarn_us)
842+
continue;
843+
844+
lkb->lkb_wait_time = zero;
845+
846+
debug_expired++;
847+
if (us > debug_maxus)
848+
debug_maxus = us;
849+
850+
if (!num_nodes) {
851+
num_nodes = ls->ls_num_nodes;
852+
warned = kmalloc(GFP_KERNEL, num_nodes * sizeof(int));
853+
if (warned)
854+
memset(warned, 0, num_nodes * sizeof(int));
855+
}
856+
if (!warned)
857+
continue;
858+
if (nodeid_warned(lkb->lkb_wait_nodeid, num_nodes, warned))
859+
continue;
860+
861+
log_error(ls, "waitwarn %x %lld %d us check connection to "
862+
"node %d", lkb->lkb_id, (long long)us,
863+
dlm_config.ci_waitwarn_us, lkb->lkb_wait_nodeid);
864+
}
865+
mutex_unlock(&ls->ls_waiters_mutex);
866+
867+
if (warned)
868+
kfree(warned);
869+
870+
if (debug_expired)
871+
log_debug(ls, "scan_waiters %u warn %u over %d us max %lld us",
872+
debug_scanned, debug_expired,
873+
dlm_config.ci_waitwarn_us, (long long)debug_maxus);
874+
}
875+
802876
/* add/remove lkb from global waiters list of lkb's waiting for
803877
a reply from a remote node */
804878

805-
static int add_to_waiters(struct dlm_lkb *lkb, int mstype)
879+
static int add_to_waiters(struct dlm_lkb *lkb, int mstype, int to_nodeid)
806880
{
807881
struct dlm_ls *ls = lkb->lkb_resource->res_ls;
808882
int error = 0;
@@ -842,6 +916,8 @@ static int add_to_waiters(struct dlm_lkb *lkb, int mstype)
842916

843917
lkb->lkb_wait_count++;
844918
lkb->lkb_wait_type = mstype;
919+
lkb->lkb_wait_time = ktime_get();
920+
lkb->lkb_wait_nodeid = to_nodeid; /* for debugging */
845921
hold_lkb(lkb);
846922
list_add(&lkb->lkb_wait_reply, &ls->ls_waiters);
847923
out:
@@ -1157,6 +1233,16 @@ void dlm_adjust_timeouts(struct dlm_ls *ls)
11571233
list_for_each_entry(lkb, &ls->ls_timeout, lkb_time_list)
11581234
lkb->lkb_timestamp = ktime_add_us(lkb->lkb_timestamp, adj_us);
11591235
mutex_unlock(&ls->ls_timeout_mutex);
1236+
1237+
if (!dlm_config.ci_waitwarn_us)
1238+
return;
1239+
1240+
mutex_lock(&ls->ls_waiters_mutex);
1241+
list_for_each_entry(lkb, &ls->ls_waiters, lkb_wait_reply) {
1242+
if (ktime_to_us(lkb->lkb_wait_time))
1243+
lkb->lkb_wait_time = ktime_get();
1244+
}
1245+
mutex_unlock(&ls->ls_waiters_mutex);
11601246
}
11611247

11621248
/* lkb is master or local copy */
@@ -2844,12 +2930,12 @@ static int send_common(struct dlm_rsb *r, struct dlm_lkb *lkb, int mstype)
28442930
struct dlm_mhandle *mh;
28452931
int to_nodeid, error;
28462932

2847-
error = add_to_waiters(lkb, mstype);
2933+
to_nodeid = r->res_nodeid;
2934+
2935+
error = add_to_waiters(lkb, mstype, to_nodeid);
28482936
if (error)
28492937
return error;
28502938

2851-
to_nodeid = r->res_nodeid;
2852-
28532939
error = create_message(r, lkb, to_nodeid, mstype, &ms, &mh);
28542940
if (error)
28552941
goto fail;
@@ -2951,12 +3037,12 @@ static int send_lookup(struct dlm_rsb *r, struct dlm_lkb *lkb)
29513037
struct dlm_mhandle *mh;
29523038
int to_nodeid, error;
29533039

2954-
error = add_to_waiters(lkb, DLM_MSG_LOOKUP);
3040+
to_nodeid = dlm_dir_nodeid(r);
3041+
3042+
error = add_to_waiters(lkb, DLM_MSG_LOOKUP, to_nodeid);
29553043
if (error)
29563044
return error;
29573045

2958-
to_nodeid = dlm_dir_nodeid(r);
2959-
29603046
error = create_message(r, NULL, to_nodeid, DLM_MSG_LOOKUP, &ms, &mh);
29613047
if (error)
29623048
goto fail;

‎fs/dlm/lock.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ int dlm_put_lkb(struct dlm_lkb *lkb);
2424
void dlm_scan_rsbs(struct dlm_ls *ls);
2525
int dlm_lock_recovery_try(struct dlm_ls *ls);
2626
void dlm_unlock_recovery(struct dlm_ls *ls);
27+
void dlm_scan_waiters(struct dlm_ls *ls);
2728
void dlm_scan_timeout(struct dlm_ls *ls);
2829
void dlm_adjust_timeouts(struct dlm_ls *ls);
2930

‎fs/dlm/lockspace.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ static struct dlm_ls *find_ls_to_scan(void)
243243
static int dlm_scand(void *data)
244244
{
245245
struct dlm_ls *ls;
246-
int timeout_jiffies = dlm_config.ci_scan_secs * HZ;
247246

248247
while (!kthread_should_stop()) {
249248
ls = find_ls_to_scan();
@@ -252,13 +251,14 @@ static int dlm_scand(void *data)
252251
ls->ls_scan_time = jiffies;
253252
dlm_scan_rsbs(ls);
254253
dlm_scan_timeout(ls);
254+
dlm_scan_waiters(ls);
255255
dlm_unlock_recovery(ls);
256256
} else {
257257
ls->ls_scan_time += HZ;
258258
}
259-
} else {
260-
schedule_timeout_interruptible(timeout_jiffies);
259+
continue;
261260
}
261+
schedule_timeout_interruptible(dlm_config.ci_scan_secs * HZ);
262262
}
263263
return 0;
264264
}

0 commit comments

Comments
 (0)