Skip to content

Commit 6a550ae

Browse files
committed
Merge tag 'dlm-6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm
Pull dlm updates from David Teigland: - Fix recovery of locks that are being converted between PR/CW modes - Fix cleanup of rsb list if recovery is interrupted during recover_members - Fix null dereference in debug code if dlm api is called improperly - Fix wrong args passed to trace function - Move error checks out of add_to_waiters so the function can't fail - Clean up some code for configfs * tag 'dlm-6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/teigland/linux-dlm: dlm: fix dlm_recover_members refcount on error dlm: fix recovery of middle conversions dlm: make add_to_waiters() that it can't fail dlm: dlm_config_info config fields to unsigned int dlm: use dlm_config as only cluster configuration dlm: handle port as __be16 network byte order dlm: disallow different configs nodeid storages dlm: fix possible lkb_resource null dereference dlm: fix swapped args sb_flags vs sb_status
2 parents 2dde263 + 200b977 commit 6a550ae

File tree

8 files changed

+165
-153
lines changed

8 files changed

+165
-153
lines changed

fs/dlm/ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void dlm_run_callback(uint32_t ls_id, uint32_t lkb_id, int8_t mode,
3030
trace_dlm_bast(ls_id, lkb_id, mode, res_name, res_length);
3131
bastfn(astparam, mode);
3232
} else if (flags & DLM_CB_CAST) {
33-
trace_dlm_ast(ls_id, lkb_id, sb_status, sb_flags, res_name,
33+
trace_dlm_ast(ls_id, lkb_id, sb_flags, sb_status, res_name,
3434
res_length);
3535
lksb->sb_status = sb_status;
3636
lksb->sb_flags = sb_flags;

fs/dlm/config.c

Lines changed: 93 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
#include "lowcomms.h"
2525

2626
/*
27-
* /config/dlm/<cluster>/spaces/<space>/nodes/<node>/nodeid
27+
* /config/dlm/<cluster>/spaces/<space>/nodes/<node>/nodeid (refers to <node>)
2828
* /config/dlm/<cluster>/spaces/<space>/nodes/<node>/weight
29-
* /config/dlm/<cluster>/comms/<comm>/nodeid
29+
* /config/dlm/<cluster>/comms/<comm>/nodeid (refers to <comm>)
3030
* /config/dlm/<cluster>/comms/<comm>/local
3131
* /config/dlm/<cluster>/comms/<comm>/addr (write only)
3232
* /config/dlm/<cluster>/comms/<comm>/addr_list (read only)
@@ -73,20 +73,6 @@ const struct rhashtable_params dlm_rhash_rsb_params = {
7373

7474
struct dlm_cluster {
7575
struct config_group group;
76-
unsigned int cl_tcp_port;
77-
unsigned int cl_buffer_size;
78-
unsigned int cl_rsbtbl_size;
79-
unsigned int cl_recover_timer;
80-
unsigned int cl_toss_secs;
81-
unsigned int cl_scan_secs;
82-
unsigned int cl_log_debug;
83-
unsigned int cl_log_info;
84-
unsigned int cl_protocol;
85-
unsigned int cl_mark;
86-
unsigned int cl_new_rsb_count;
87-
unsigned int cl_recover_callbacks;
88-
char cl_cluster_name[DLM_LOCKSPACE_LEN];
89-
9076
struct dlm_spaces *sps;
9177
struct dlm_comms *cms;
9278
};
@@ -115,25 +101,60 @@ enum {
115101

116102
static ssize_t cluster_cluster_name_show(struct config_item *item, char *buf)
117103
{
118-
struct dlm_cluster *cl = config_item_to_cluster(item);
119-
return sprintf(buf, "%s\n", cl->cl_cluster_name);
104+
return sprintf(buf, "%s\n", dlm_config.ci_cluster_name);
120105
}
121106

122107
static ssize_t cluster_cluster_name_store(struct config_item *item,
123108
const char *buf, size_t len)
124109
{
125-
struct dlm_cluster *cl = config_item_to_cluster(item);
126-
127110
strscpy(dlm_config.ci_cluster_name, buf,
128-
sizeof(dlm_config.ci_cluster_name));
129-
strscpy(cl->cl_cluster_name, buf, sizeof(cl->cl_cluster_name));
111+
sizeof(dlm_config.ci_cluster_name));
130112
return len;
131113
}
132114

133115
CONFIGFS_ATTR(cluster_, cluster_name);
134116

135-
static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field,
136-
int *info_field, int (*check_cb)(unsigned int x),
117+
static ssize_t cluster_tcp_port_show(struct config_item *item, char *buf)
118+
{
119+
return sprintf(buf, "%u\n", be16_to_cpu(dlm_config.ci_tcp_port));
120+
}
121+
122+
static int dlm_check_zero_and_dlm_running(unsigned int x)
123+
{
124+
if (!x)
125+
return -EINVAL;
126+
127+
if (dlm_lowcomms_is_running())
128+
return -EBUSY;
129+
130+
return 0;
131+
}
132+
133+
static ssize_t cluster_tcp_port_store(struct config_item *item,
134+
const char *buf, size_t len)
135+
{
136+
int rc;
137+
u16 x;
138+
139+
if (!capable(CAP_SYS_ADMIN))
140+
return -EPERM;
141+
142+
rc = kstrtou16(buf, 0, &x);
143+
if (rc)
144+
return rc;
145+
146+
rc = dlm_check_zero_and_dlm_running(x);
147+
if (rc)
148+
return rc;
149+
150+
dlm_config.ci_tcp_port = cpu_to_be16(x);
151+
return len;
152+
}
153+
154+
CONFIGFS_ATTR(cluster_, tcp_port);
155+
156+
static ssize_t cluster_set(unsigned int *info_field,
157+
int (*check_cb)(unsigned int x),
137158
const char *buf, size_t len)
138159
{
139160
unsigned int x;
@@ -151,7 +172,6 @@ static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field,
151172
return rc;
152173
}
153174

154-
*cl_field = x;
155175
*info_field = x;
156176

157177
return len;
@@ -161,14 +181,11 @@ static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field,
161181
static ssize_t cluster_##name##_store(struct config_item *item, \
162182
const char *buf, size_t len) \
163183
{ \
164-
struct dlm_cluster *cl = config_item_to_cluster(item); \
165-
return cluster_set(cl, &cl->cl_##name, &dlm_config.ci_##name, \
166-
check_cb, buf, len); \
184+
return cluster_set(&dlm_config.ci_##name, check_cb, buf, len); \
167185
} \
168186
static ssize_t cluster_##name##_show(struct config_item *item, char *buf) \
169187
{ \
170-
struct dlm_cluster *cl = config_item_to_cluster(item); \
171-
return snprintf(buf, PAGE_SIZE, "%u\n", cl->cl_##name); \
188+
return snprintf(buf, PAGE_SIZE, "%u\n", dlm_config.ci_##name); \
172189
} \
173190
CONFIGFS_ATTR(cluster_, name);
174191

@@ -191,17 +208,6 @@ static int dlm_check_protocol_and_dlm_running(unsigned int x)
191208
return 0;
192209
}
193210

194-
static int dlm_check_zero_and_dlm_running(unsigned int x)
195-
{
196-
if (!x)
197-
return -EINVAL;
198-
199-
if (dlm_lowcomms_is_running())
200-
return -EBUSY;
201-
202-
return 0;
203-
}
204-
205211
static int dlm_check_zero(unsigned int x)
206212
{
207213
if (!x)
@@ -218,7 +224,6 @@ static int dlm_check_buffer_size(unsigned int x)
218224
return 0;
219225
}
220226

221-
CLUSTER_ATTR(tcp_port, dlm_check_zero_and_dlm_running);
222227
CLUSTER_ATTR(buffer_size, dlm_check_buffer_size);
223228
CLUSTER_ATTR(rsbtbl_size, dlm_check_zero);
224229
CLUSTER_ATTR(recover_timer, dlm_check_zero);
@@ -423,20 +428,6 @@ static struct config_group *make_cluster(struct config_group *g,
423428
configfs_add_default_group(&sps->ss_group, &cl->group);
424429
configfs_add_default_group(&cms->cs_group, &cl->group);
425430

426-
cl->cl_tcp_port = dlm_config.ci_tcp_port;
427-
cl->cl_buffer_size = dlm_config.ci_buffer_size;
428-
cl->cl_rsbtbl_size = dlm_config.ci_rsbtbl_size;
429-
cl->cl_recover_timer = dlm_config.ci_recover_timer;
430-
cl->cl_toss_secs = dlm_config.ci_toss_secs;
431-
cl->cl_scan_secs = dlm_config.ci_scan_secs;
432-
cl->cl_log_debug = dlm_config.ci_log_debug;
433-
cl->cl_log_info = dlm_config.ci_log_info;
434-
cl->cl_protocol = dlm_config.ci_protocol;
435-
cl->cl_new_rsb_count = dlm_config.ci_new_rsb_count;
436-
cl->cl_recover_callbacks = dlm_config.ci_recover_callbacks;
437-
memcpy(cl->cl_cluster_name, dlm_config.ci_cluster_name,
438-
DLM_LOCKSPACE_LEN);
439-
440431
space_list = &sps->ss_group;
441432
comm_list = &cms->cs_group;
442433
return &cl->group;
@@ -517,6 +508,12 @@ static void release_space(struct config_item *i)
517508
static struct config_item *make_comm(struct config_group *g, const char *name)
518509
{
519510
struct dlm_comm *cm;
511+
unsigned int nodeid;
512+
int rv;
513+
514+
rv = kstrtouint(name, 0, &nodeid);
515+
if (rv)
516+
return ERR_PTR(rv);
520517

521518
cm = kzalloc(sizeof(struct dlm_comm), GFP_NOFS);
522519
if (!cm)
@@ -528,7 +525,7 @@ static struct config_item *make_comm(struct config_group *g, const char *name)
528525
if (!cm->seq)
529526
cm->seq = dlm_comm_count++;
530527

531-
cm->nodeid = -1;
528+
cm->nodeid = nodeid;
532529
cm->local = 0;
533530
cm->addr_count = 0;
534531
cm->mark = 0;
@@ -555,16 +552,25 @@ static void release_comm(struct config_item *i)
555552
static struct config_item *make_node(struct config_group *g, const char *name)
556553
{
557554
struct dlm_space *sp = config_item_to_space(g->cg_item.ci_parent);
555+
unsigned int nodeid;
558556
struct dlm_node *nd;
557+
uint32_t seq = 0;
558+
int rv;
559+
560+
rv = kstrtouint(name, 0, &nodeid);
561+
if (rv)
562+
return ERR_PTR(rv);
559563

560564
nd = kzalloc(sizeof(struct dlm_node), GFP_NOFS);
561565
if (!nd)
562566
return ERR_PTR(-ENOMEM);
563567

564568
config_item_init_type_name(&nd->item, name, &node_type);
565-
nd->nodeid = -1;
569+
nd->nodeid = nodeid;
566570
nd->weight = 1; /* default weight of 1 if none is set */
567571
nd->new = 1; /* set to 0 once it's been read by dlm_nodeid_list() */
572+
dlm_comm_seq(nodeid, &seq, true);
573+
nd->comm_seq = seq;
568574

569575
mutex_lock(&sp->members_lock);
570576
list_add(&nd->list, &sp->members);
@@ -622,16 +628,19 @@ void dlm_config_exit(void)
622628

623629
static ssize_t comm_nodeid_show(struct config_item *item, char *buf)
624630
{
625-
return sprintf(buf, "%d\n", config_item_to_comm(item)->nodeid);
631+
unsigned int nodeid;
632+
int rv;
633+
634+
rv = kstrtouint(config_item_name(item), 0, &nodeid);
635+
if (WARN_ON(rv))
636+
return rv;
637+
638+
return sprintf(buf, "%u\n", nodeid);
626639
}
627640

628641
static ssize_t comm_nodeid_store(struct config_item *item, const char *buf,
629642
size_t len)
630643
{
631-
int rc = kstrtoint(buf, 0, &config_item_to_comm(item)->nodeid);
632-
633-
if (rc)
634-
return rc;
635644
return len;
636645
}
637646

@@ -772,20 +781,19 @@ static struct configfs_attribute *comm_attrs[] = {
772781

773782
static ssize_t node_nodeid_show(struct config_item *item, char *buf)
774783
{
775-
return sprintf(buf, "%d\n", config_item_to_node(item)->nodeid);
784+
unsigned int nodeid;
785+
int rv;
786+
787+
rv = kstrtouint(config_item_name(item), 0, &nodeid);
788+
if (WARN_ON(rv))
789+
return rv;
790+
791+
return sprintf(buf, "%u\n", nodeid);
776792
}
777793

778794
static ssize_t node_nodeid_store(struct config_item *item, const char *buf,
779795
size_t len)
780796
{
781-
struct dlm_node *nd = config_item_to_node(item);
782-
uint32_t seq = 0;
783-
int rc = kstrtoint(buf, 0, &nd->nodeid);
784-
785-
if (rc)
786-
return rc;
787-
dlm_comm_seq(nd->nodeid, &seq);
788-
nd->comm_seq = seq;
789797
return len;
790798
}
791799

@@ -845,7 +853,7 @@ static struct dlm_comm *get_comm(int nodeid)
845853
if (!comm_list)
846854
return NULL;
847855

848-
mutex_lock(&clusters_root.subsys.su_mutex);
856+
WARN_ON_ONCE(!mutex_is_locked(&clusters_root.subsys.su_mutex));
849857

850858
list_for_each_entry(i, &comm_list->cg_children, ci_entry) {
851859
cm = config_item_to_comm(i);
@@ -856,7 +864,6 @@ static struct dlm_comm *get_comm(int nodeid)
856864
config_item_get(i);
857865
break;
858866
}
859-
mutex_unlock(&clusters_root.subsys.su_mutex);
860867

861868
if (!found)
862869
cm = NULL;
@@ -916,11 +923,20 @@ int dlm_config_nodes(char *lsname, struct dlm_config_node **nodes_out,
916923
return rv;
917924
}
918925

919-
int dlm_comm_seq(int nodeid, uint32_t *seq)
926+
int dlm_comm_seq(int nodeid, uint32_t *seq, bool locked)
920927
{
921-
struct dlm_comm *cm = get_comm(nodeid);
928+
struct dlm_comm *cm;
929+
930+
if (locked) {
931+
cm = get_comm(nodeid);
932+
} else {
933+
mutex_lock(&clusters_root.subsys.su_mutex);
934+
cm = get_comm(nodeid);
935+
mutex_unlock(&clusters_root.subsys.su_mutex);
936+
}
922937
if (!cm)
923938
return -EEXIST;
939+
924940
*seq = cm->seq;
925941
put_comm(cm);
926942
return 0;
@@ -957,7 +973,7 @@ int dlm_our_addr(struct sockaddr_storage *addr, int num)
957973
#define DEFAULT_CLUSTER_NAME ""
958974

959975
struct dlm_config_info dlm_config = {
960-
.ci_tcp_port = DEFAULT_TCP_PORT,
976+
.ci_tcp_port = cpu_to_be16(DEFAULT_TCP_PORT),
961977
.ci_buffer_size = DLM_MAX_SOCKET_BUFSIZE,
962978
.ci_rsbtbl_size = DEFAULT_RSBTBL_SIZE,
963979
.ci_recover_timer = DEFAULT_RECOVER_TIMER,

fs/dlm/config.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ extern const struct rhashtable_params dlm_rhash_rsb_params;
2929
#define DLM_PROTO_SCTP 1
3030

3131
struct dlm_config_info {
32-
int ci_tcp_port;
33-
int ci_buffer_size;
34-
int ci_rsbtbl_size;
35-
int ci_recover_timer;
36-
int ci_toss_secs;
37-
int ci_scan_secs;
38-
int ci_log_debug;
39-
int ci_log_info;
40-
int ci_protocol;
41-
int ci_mark;
42-
int ci_new_rsb_count;
43-
int ci_recover_callbacks;
32+
__be16 ci_tcp_port;
33+
unsigned int ci_buffer_size;
34+
unsigned int ci_rsbtbl_size;
35+
unsigned int ci_recover_timer;
36+
unsigned int ci_toss_secs;
37+
unsigned int ci_scan_secs;
38+
unsigned int ci_log_debug;
39+
unsigned int ci_log_info;
40+
unsigned int ci_protocol;
41+
unsigned int ci_mark;
42+
unsigned int ci_new_rsb_count;
43+
unsigned int ci_recover_callbacks;
4444
char ci_cluster_name[DLM_LOCKSPACE_LEN];
4545
};
4646

@@ -50,7 +50,7 @@ int dlm_config_init(void);
5050
void dlm_config_exit(void);
5151
int dlm_config_nodes(char *lsname, struct dlm_config_node **nodes_out,
5252
int *count_out);
53-
int dlm_comm_seq(int nodeid, uint32_t *seq);
53+
int dlm_comm_seq(int nodeid, uint32_t *seq, bool locked);
5454
int dlm_our_nodeid(void);
5555
int dlm_our_addr(struct sockaddr_storage *addr, int num);
5656

0 commit comments

Comments
 (0)