dlm: tracing, config and null-ptr fixes
Alexander Aring
maintainercover dlm: tracing, config and null-ptr fixes
Hi,
those pending DLM patches are taken out of the current pending patches of patch series:
https://lore.kernel.org/gfs2/[email protected]/
and
https://lore.kernel.org/gfs2/[email protected]/
as I need more time to change the strategy how to bring those patches upstream. The patches are independent from their original patch-series functionality and there should no problem to apply them in this merge window.
Thanks.
- Alex
Alexander Aring (7):
dlm: fix swapped args sb_flags vs sb_status
dlm: fix possible lkb_resource null dereference
dlm: disallow different configs nodeid storages
dlm: handle port as __be16 network byte order
dlm: use dlm_config as only cluster configuration
dlm: dlm_config_info config fields to unsigned int
dlm: make add_to_waiters() that it can't fail
fs/dlm/ast.c | 2 +- fs/dlm/config.c | 170 +++++++++++++++++++++++++--------------------- fs/dlm/config.h | 26 +++---- fs/dlm/lock.c | 53 +++++---------- fs/dlm/lowcomms.c | 8 +-- fs/dlm/member.c | 2 +- 6 files changed, 130 insertions(+), 131 deletions(-)
Signature · 1 line
2.43.0
Alexander Aring
maintainerPATCH 1/7 dlm: fix swapped args sb_flags vs sb_status
The arguments got swapped by commit 986ae3c2a8df ("dlm: fix race between final callback and remove") fixing this now.
--- fs/dlm/ast.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dlm/ast.c +1 -1
@@ -30,7 +30,7 @@ static void dlm_run_callback(uint32_t ls_id, uint32_t lkb_id, int8_t mode,trace_dlm_bast (ls_id, lkb_id, mode, res_name, res_length);bastfn (astparam, mode); }else if (flags &DLM_CB_CAST ) { -trace_dlm_ast (ls_id, lkb_id, sb_status, sb_flags, res_name, +trace_dlm_ast (ls_id, lkb_id, sb_flags, sb_status, res_name, res_length); lksb->sb_status = sb_status; lksb->sb_flags = sb_flags;
Signature · 1 line
2.43.0
Alexander Aring
maintainerPATCH 2/7 dlm: fix possible lkb_resource null dereference
In reply to Alexander AringThis patch fixes a possible null pointer dereference when this function is called from request_lock() as lkb->lkb_resource is not assigned yet, only after validate_lock_args() by calling attach_lkb(). Another issue is that a resource name could be a non printable bytearray and we cannot assume to be ASCII coded.
The log functionality is probably never being hit when DLM is used in normal way and no debug logging is enabled. The null pointer dereference can only occur on a new created lkb that does not have the resource assigned yet, it probably never hits the null pointer dereference but we should be sure that other changes might not change this behaviour and we actually can hit the mentioned null pointer dereference.
In this patch we just drop the printout of the resource name, the lkb id is enough to make a possible connection to a resource name if this exists.
--- fs/dlm/lock.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
fs/dlm/lock.c +4 -6
@@ -2861,16 +2861,14 @@ static int validate_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb,case -EINVAL :/* annoy the user because dlm usage is wrong */ WARN_ON (1 ); -log_error (ls,"%s %d %x %x %x %d %d %s" , __func__, +log_error (ls,"%s %d %x %x %x %d %d" , __func__, rv, lkb->lkb_id,dlm_iflags_val (lkb), args->flags, - lkb->lkb_status, lkb->lkb_wait_type, - lkb->lkb_resource->res_name); + lkb->lkb_status, lkb->lkb_wait_type);break ;default : -log_debug (ls,"%s %d %x %x %x %d %d %s" , __func__, +log_debug (ls,"%s %d %x %x %x %d %d" , __func__, rv, lkb->lkb_id,dlm_iflags_val (lkb), args->flags, - lkb->lkb_status, lkb->lkb_wait_type, - lkb->lkb_resource->res_name); + lkb->lkb_status, lkb->lkb_wait_type);break ; }
Signature · 1 line
2.43.0
Alexander Aring
maintainerPATCH 3/7 dlm: disallow different configs nodeid storages
In reply to Alexander AringThe DLM configfs path has usually a nodeid in it's directory path and again a file to store the nodeid again in a separate storage. It is forced that the user space will set both (the directory name and nodeid file) storage to the same value if it doesn't do that we run in some kind of broken state.
This patch will simply represent the file storage to it's upper directory nodeid name. It will force the user now to use a valid unsigned int as nodeid directory name and will ignore all nodeid writes in the nodeid file storage as this will now always represent the upper nodeid directory name.
--- fs/dlm/config.c | 69 +++++++++++++++++++++++++++++++++---------------- fs/dlm/config.h | 2 +- fs/dlm/member.c | 2 +- 3 files changed, 49 insertions(+), 24 deletions(-)
fs/dlm/config.c +47 -22
@@ -24,9 +24,9 @@#include "lowcomms.h" /* -* /config/dlm/<cluster>/spaces/<space>/nodes/<node>/nodeid +* /config/dlm/<cluster>/spaces/<space>/nodes/<node>/nodeid (refers to <node>) * /config/dlm/<cluster>/spaces/<space>/nodes/<node>/weight -* /config/dlm/<cluster>/comms/<comm>/nodeid +* /config/dlm/<cluster>/comms/<comm>/nodeid (refers to <comm>) * /config/dlm/<cluster>/comms/<comm>/local * /config/dlm/<cluster>/comms/<comm>/addr (write only) * /config/dlm/<cluster>/comms/<comm>/addr_list (read only)
@@ -517,6 +517,12 @@ static void release_space(struct config_item *i)static struct config_item *make_comm (struct config_group *g,const char *name) {struct dlm_comm *cm; +unsigned int nodeid; +int rv; + + rv =kstrtouint (name,0 , &nodeid); +if (rv) +return ERR_PTR (rv); cm =kzalloc (sizeof (struct dlm_comm ),GFP_NOFS );if (!cm)
@@ -528,7 +534,7 @@ static struct config_item *make_comm(struct config_group *g, const char *name)if (!cm->seq) cm->seq = dlm_comm_count++; - cm->nodeid =-1 ; + cm->nodeid = nodeid; cm->local =0 ; cm->addr_count =0 ; cm->mark =0 ;
@@ -555,16 +561,25 @@ static void release_comm(struct config_item *i)static struct config_item *make_node (struct config_group *g,const char *name) {struct dlm_space *sp =config_item_to_space (g->cg_item.ci_parent); +unsigned int nodeid;struct dlm_node *nd; +uint32_t seq =0 ; +int rv; + + rv =kstrtouint (name,0 , &nodeid); +if (rv) +return ERR_PTR (rv); nd =kzalloc (sizeof (struct dlm_node ),GFP_NOFS );if (!nd)return ERR_PTR (-ENOMEM );config_item_init_type_name (&nd->item, name, &node_type); - nd->nodeid =-1 ; + nd->nodeid = nodeid; nd->weight =1 ;/* default weight of 1 if none is set */ nd->new =1 ;/* set to 0 once it's been read by dlm_nodeid_list() */ +dlm_comm_seq (nodeid, &seq, true); + nd->comm_seq = seq;mutex_lock (&sp->members_lock);list_add (&nd->list, &sp->members);
@@ -622,16 +637,19 @@ void dlm_config_exit(void)static ssize_t comm_nodeid_show (struct config_item *item,char *buf) { -return sprintf (buf,"%d\n" ,config_item_to_comm (item)->nodeid); +unsigned int nodeid; +int rv; + + rv =kstrtouint (config_item_name (item),0 , &nodeid); +if (WARN_ON (rv)) +return rv; + +return sprintf (buf,"%u\n" , nodeid); }static ssize_t comm_nodeid_store (struct config_item *item,const char *buf,size_t len) { -int rc =kstrtoint (buf,0 , &config_item_to_comm (item)->nodeid); - -if (rc) -return rc;return len; }
@@ -772,20 +790,19 @@ static struct configfs_attribute *comm_attrs[] = {static ssize_t node_nodeid_show (struct config_item *item,char *buf) { -return sprintf (buf,"%d\n" ,config_item_to_node (item)->nodeid); +unsigned int nodeid; +int rv; + + rv =kstrtouint (config_item_name (item),0 , &nodeid); +if (WARN_ON (rv)) +return rv; + +return sprintf (buf,"%u\n" , nodeid); }static ssize_t node_nodeid_store (struct config_item *item,const char *buf,size_t len) { -struct dlm_node *nd =config_item_to_node (item); -uint32_t seq =0 ; -int rc =kstrtoint (buf,0 , &nd->nodeid); - -if (rc) -return rc; -dlm_comm_seq (nd->nodeid, &seq); - nd->comm_seq = seq;return len; }
@@ -845,7 +862,7 @@ static struct dlm_comm *get_comm(int nodeid)if (!comm_list)return NULL ; -mutex_lock (&clusters_root.subsys.su_mutex); +WARN_ON_ONCE (!mutex_is_locked (&clusters_root.subsys.su_mutex));list_for_each_entry (i, &comm_list->cg_children, ci_entry) { cm =config_item_to_comm (i);
@@ -856,7 +873,6 @@ static struct dlm_comm *get_comm(int nodeid)config_item_get (i);break ; } -mutex_unlock (&clusters_root.subsys.su_mutex);if (!found) cm =NULL ;
@@ -916,11 +932,20 @@ int dlm_config_nodes(char *lsname, struct dlm_config_node **nodes_out,return rv; } -int dlm_comm_seq (int nodeid,uint32_t *seq) +int dlm_comm_seq (int nodeid,uint32_t *seq,bool locked) { -struct dlm_comm *cm =get_comm (nodeid); +struct dlm_comm *cm; + +if (locked) { + cm =get_comm (nodeid); + }else { +mutex_lock (&clusters_root.subsys.su_mutex); + cm =get_comm (nodeid); +mutex_unlock (&clusters_root.subsys.su_mutex); + }if (!cm)return -EEXIST ; + *seq = cm->seq;put_comm (cm);return 0 ;
fs/dlm/config.h +1 -1
@@ -50,7 +50,7 @@ int dlm_config_init(void);void dlm_config_exit (void );int dlm_config_nodes (char *lsname,struct dlm_config_node **nodes_out,int *count_out); -int dlm_comm_seq (int nodeid,uint32_t *seq); +int dlm_comm_seq (int nodeid,uint32_t *seq,bool locked);int dlm_our_nodeid (void );int dlm_our_addr (struct sockaddr_storage *addr,int num);
fs/dlm/member.c +1 -1
@@ -493,7 +493,7 @@ static void dlm_lsop_recover_slot(struct dlm_ls *ls, struct dlm_member *memb)we consider the node to have failed (versus being removed due to dlm_release_lockspace) */ - error =dlm_comm_seq (memb->nodeid, &seq); + error =dlm_comm_seq (memb->nodeid, &seq, false);if (!error && seq == memb->comm_seq)return ;
Signature · 1 line
2.43.0
Alexander Aring
maintainerPATCH 4/7 dlm: handle port as __be16 network byte order
In reply to Alexander AringThis patch handles the DLM listen port setting internally as byte order as it is a value that is used as network byte on the wire. The user space still sets this value as host byte order for configfs as we don't break UAPI here.
--- fs/dlm/config.c | 55 +++++++++++++++++++++++++++++++++++------------ fs/dlm/config.h | 2 +- fs/dlm/lowcomms.c | 8 +++---- 3 files changed, 46 insertions(+), 19 deletions(-)
fs/dlm/config.c +41 -14
@@ -73,7 +73,7 @@ const struct rhashtable_params dlm_rhash_rsb_params = {struct dlm_cluster {struct config_group group; -unsigned int cl_tcp_port; +__be16 cl_tcp_port;unsigned int cl_buffer_size;unsigned int cl_rsbtbl_size;unsigned int cl_recover_timer;
@@ -132,6 +132,45 @@ static ssize_t cluster_cluster_name_store(struct config_item *item,CONFIGFS_ATTR (cluster_, cluster_name); +static ssize_t cluster_tcp_port_show (struct config_item *item,char *buf) +{ +return sprintf (buf,"%u\n" ,be16_to_cpu (dlm_config.ci_tcp_port)); +} + +static int dlm_check_zero_and_dlm_running (unsigned int x) +{ +if (!x) +return -EINVAL ; + +if (dlm_lowcomms_is_running ()) +return -EBUSY ; + +return 0 ; +} + +static ssize_t cluster_tcp_port_store (struct config_item *item, +const char *buf,size_t len) +{ +int rc; +u16 x; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + + rc =kstrtou16 (buf,0 , &x); +if (rc) +return rc; + + rc =dlm_check_zero_and_dlm_running (x); +if (rc) +return rc; + + dlm_config.ci_tcp_port =cpu_to_be16 (x); +return len; +} + +CONFIGFS_ATTR (cluster_, tcp_port); +static ssize_t cluster_set (struct dlm_cluster *cl,unsigned int *cl_field,int *info_field,int (*check_cb)(unsigned int x),const char *buf,size_t len)
@@ -191,17 +230,6 @@ static int dlm_check_protocol_and_dlm_running(unsigned int x)return 0 ; } -static int dlm_check_zero_and_dlm_running (unsigned int x) -{ -if (!x) -return -EINVAL ; - -if (dlm_lowcomms_is_running ()) -return -EBUSY ; - -return 0 ; -} -static int dlm_check_zero (unsigned int x) {if (!x)
@@ -218,7 +246,6 @@ static int dlm_check_buffer_size(unsigned int x)return 0 ; } -CLUSTER_ATTR (tcp_port, dlm_check_zero_and_dlm_running);CLUSTER_ATTR (buffer_size, dlm_check_buffer_size);CLUSTER_ATTR (rsbtbl_size, dlm_check_zero);CLUSTER_ATTR (recover_timer, dlm_check_zero);
@@ -982,7 +1009,7 @@ int dlm_our_addr(struct sockaddr_storage *addr, int num)#define DEFAULT_CLUSTER_NAME ""struct dlm_config_info dlm_config = { - .ci_tcp_port =DEFAULT_TCP_PORT , + .ci_tcp_port =cpu_to_be16 (DEFAULT_TCP_PORT ), .ci_buffer_size =DLM_MAX_SOCKET_BUFSIZE , .ci_rsbtbl_size =DEFAULT_RSBTBL_SIZE , .ci_recover_timer =DEFAULT_RECOVER_TIMER ,
fs/dlm/config.h +1 -1
@@ -29,7 +29,7 @@ extern const struct rhashtable_params dlm_rhash_rsb_params;#define DLM_PROTO_SCTP 1struct dlm_config_info { -int ci_tcp_port; +__be16 ci_tcp_port;int ci_buffer_size;int ci_rsbtbl_size;int ci_recover_timer;
fs/dlm/lowcomms.c +4 -4
@@ -660,18 +660,18 @@ static void add_sock(struct socket *sock, struct connection *con)/* Add the port number to an IPv6 or 4 sockaddr and return the address length */ -static void make_sockaddr (struct sockaddr_storage *saddr,uint16_t port, +static void make_sockaddr (struct sockaddr_storage *saddr,__be16 port,int *addr_len) { saddr->ss_family = dlm_local_addr[0 ].ss_family;if (saddr->ss_family ==AF_INET ) {struct sockaddr_in *in4_addr = (struct sockaddr_in *)saddr; - in4_addr->sin_port =cpu_to_be16 (port); + in4_addr->sin_port = port; *addr_len =sizeof (struct sockaddr_in );memset (&in4_addr->sin_zero,0 ,sizeof (in4_addr->sin_zero)); }else {struct sockaddr_in6 *in6_addr = (struct sockaddr_in6 *)saddr; - in6_addr->sin6_port =cpu_to_be16 (port); + in6_addr->sin6_port = port; *addr_len =sizeof (struct sockaddr_in6 ); }memset ((char *)saddr + *addr_len,0 ,sizeof (struct sockaddr_storage ) - *addr_len);
@@ -1121,7 +1121,7 @@ static void writequeue_entry_complete(struct writequeue_entry *e, int completed)/* * sctp_bind_addrs - bind a SCTP socket to all our addresses */ -static int sctp_bind_addrs (struct socket *sock,uint16_t port) +static int sctp_bind_addrs (struct socket *sock,__be16 port) {struct sockaddr_storage localaddr;struct sockaddr *addr = (struct sockaddr *)&localaddr;
Signature · 1 line
2.43.0
Alexander Aring
maintainerPATCH 5/7 dlm: use dlm_config as only cluster configuration
In reply to Alexander AringThis patch removes the configfs storage fields from the dlm_cluster structure to store per cluster values. Those fields also exists for the dlm_config global variable and get stored in both when setting configfs values. To read values it will always be read out from the dlm_cluster configfs structure but this patch changes it to only use the global dlm_config variable. Storing them in two places makes no sense as both are able to be changed under certain conditions during DLM runtime.
--- fs/dlm/config.c | 47 +++++------------------------------------------ 1 file changed, 5 insertions(+), 42 deletions(-)
fs/dlm/config.c +5 -42
@@ -73,20 +73,6 @@ const struct rhashtable_params dlm_rhash_rsb_params = {struct dlm_cluster {struct config_group group; -__be16 cl_tcp_port; -unsigned int cl_buffer_size; -unsigned int cl_rsbtbl_size; -unsigned int cl_recover_timer; -unsigned int cl_toss_secs; -unsigned int cl_scan_secs; -unsigned int cl_log_debug; -unsigned int cl_log_info; -unsigned int cl_protocol; -unsigned int cl_mark; -unsigned int cl_new_rsb_count; -unsigned int cl_recover_callbacks; -char cl_cluster_name[DLM_LOCKSPACE_LEN ]; -struct dlm_spaces *sps;struct dlm_comms *cms; };
@@ -115,18 +101,14 @@ enum {static ssize_t cluster_cluster_name_show (struct config_item *item,char *buf) { -struct dlm_cluster *cl =config_item_to_cluster (item); -return sprintf (buf,"%s\n" , cl->cl_cluster_name); +return sprintf (buf,"%s\n" , dlm_config.ci_cluster_name); }static ssize_t cluster_cluster_name_store (struct config_item *item,const char *buf,size_t len) { -struct dlm_cluster *cl =config_item_to_cluster (item); -strscpy (dlm_config.ci_cluster_name, buf, -sizeof (dlm_config.ci_cluster_name)); -strscpy (cl->cl_cluster_name, buf,sizeof (cl->cl_cluster_name)); +sizeof (dlm_config.ci_cluster_name));return len; }
@@ -171,8 +153,7 @@ static ssize_t cluster_tcp_port_store(struct config_item *item,CONFIGFS_ATTR (cluster_, tcp_port); -static ssize_t cluster_set (struct dlm_cluster *cl,unsigned int *cl_field, -int *info_field,int (*check_cb)(unsigned int x), +static ssize_t cluster_set (int *info_field,int (*check_cb)(unsigned int x),const char *buf,size_t len) {unsigned int x;
@@ -190,7 +171,6 @@ static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field,return rc; } - *cl_field = x; *info_field = x;return len;
@@ -200,14 +180,11 @@ static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field, static ssize_t cluster_##name##_store(struct config_item *item, \ const char *buf, size_t len) \ { \ - struct dlm_cluster *cl = config_item_to_cluster(item); \ - return cluster_set(cl, &cl->cl_##name, &dlm_config.ci_##name, \ - check_cb, buf, len); \ + return cluster_set(&dlm_config.ci_##name, check_cb, buf, len); \ } \ static ssize_t cluster_##name##_show(struct config_item *item, char *buf) \ { \ - struct dlm_cluster *cl = config_item_to_cluster(item); \ - return snprintf(buf, PAGE_SIZE, "%u\n", cl->cl_##name); \ + return snprintf(buf, PAGE_SIZE, "%u\n", dlm_config.ci_##name); \ } \ CONFIGFS_ATTR(cluster_, name);
@@ -450,20 +427,6 @@ static struct config_group *make_cluster(struct config_group *g,configfs_add_default_group (&sps->ss_group, &cl->group);configfs_add_default_group (&cms->cs_group, &cl->group); - cl->cl_tcp_port = dlm_config.ci_tcp_port; - cl->cl_buffer_size = dlm_config.ci_buffer_size; - cl->cl_rsbtbl_size = dlm_config.ci_rsbtbl_size; - cl->cl_recover_timer = dlm_config.ci_recover_timer; - cl->cl_toss_secs = dlm_config.ci_toss_secs; - cl->cl_scan_secs = dlm_config.ci_scan_secs; - cl->cl_log_debug = dlm_config.ci_log_debug; - cl->cl_log_info = dlm_config.ci_log_info; - cl->cl_protocol = dlm_config.ci_protocol; - cl->cl_new_rsb_count = dlm_config.ci_new_rsb_count; - cl->cl_recover_callbacks = dlm_config.ci_recover_callbacks; -memcpy (cl->cl_cluster_name, dlm_config.ci_cluster_name, -DLM_LOCKSPACE_LEN ); - space_list = &sps->ss_group; comm_list = &cms->cs_group;return &cl->group;
Signature · 1 line
2.43.0
Alexander Aring
maintainerPATCH 6/7 dlm: dlm_config_info config fields to unsigned int
In reply to Alexander AringWe are using kstrtouint() to parse common integer fields. This patch will switch to use unsigned int instead of int as we are parsing unsigned integer values.
--- fs/dlm/config.c | 3 ++- fs/dlm/config.h | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-)
fs/dlm/config.c +2 -1
@@ -153,7 +153,8 @@ static ssize_t cluster_tcp_port_store(struct config_item *item,CONFIGFS_ATTR (cluster_, tcp_port); -static ssize_t cluster_set (int *info_field,int (*check_cb)(unsigned int x), +static ssize_t cluster_set (unsigned int *info_field, +int (*check_cb)(unsigned int x),const char *buf,size_t len) {unsigned int x;
fs/dlm/config.h +11 -11
@@ -30,17 +30,17 @@ extern const struct rhashtable_params dlm_rhash_rsb_params;struct dlm_config_info {__be16 ci_tcp_port; -int ci_buffer_size; -int ci_rsbtbl_size; -int ci_recover_timer; -int ci_toss_secs; -int ci_scan_secs; -int ci_log_debug; -int ci_log_info; -int ci_protocol; -int ci_mark; -int ci_new_rsb_count; -int ci_recover_callbacks; +unsigned int ci_buffer_size; +unsigned int ci_rsbtbl_size; +unsigned int ci_recover_timer; +unsigned int ci_toss_secs; +unsigned int ci_scan_secs; +unsigned int ci_log_debug; +unsigned int ci_log_info; +unsigned int ci_protocol; +unsigned int ci_mark; +unsigned int ci_new_rsb_count; +unsigned int ci_recover_callbacks;char ci_cluster_name[DLM_LOCKSPACE_LEN ]; };
Signature · 1 line
2.43.0
Alexander Aring
maintainerPATCH 7/7 dlm: make add_to_waiters() that it can't fail
In reply to Alexander AringIf add_to_waiters() fails we have a problem because the previous called functions such as validate_lock_args() or validate_unlock_args() sets specific lkb values that are set for a request, there exists no way back to revert those changes. When there is a pending lock request the original request arguments will be overwritten with unknown consequences.
The good news are that I believe those cases that we fail in add_to_waiters() can't happen or very unlikely to happen (only if the DLM user does stupid API things), but if so we have the above mentioned problem.
There are two conditions that will be removed here. The first one is the -EINVAL case which contains is_overlap_unlock() or (is_overlap_cancel() and mstype == DLM_MSG_CANCEL).
The is_overlap_unlock() is missing for the normal UNLOCK case which is moved to validate_unlock_args(). The is_overlap_cancel() already happens in validate_unlock_args() when DLM_LKF_CANCEL is set. In case of validate_lock_args() we check on is_overlap() when it is not a new request, on a new request the lkb is always new and does not have those values set.
The -EBUSY check can't happen in case as for non new lock requests (when DLM_LKF_CONVERT is set) we already check in validate_lock_args() for lkb_wait_type and is_overlap(). Then there is only validate_unlock_args() that will never hit the default case because dlm_unlock() will produce DLM_MSG_UNLOCK and DLM_MSG_CANCEL messages.
--- fs/dlm/lock.c | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-)
fs/dlm/lock.c +14 -29
@@ -1703,19 +1703,11 @@ static int msg_reply_type(int mstype)/* add/remove lkb from global waiters list of lkb's waiting for a reply from a remote node */ -static int add_to_waiters (struct dlm_lkb *lkb,int mstype,int to_nodeid) +static void add_to_waiters (struct dlm_lkb *lkb,int mstype,int to_nodeid) {struct dlm_ls *ls = lkb->lkb_resource->res_ls; -int error =0 ;spin_lock_bh (&ls->ls_waiters_lock); - -if (is_overlap_unlock (lkb) || - (is_overlap_cancel (lkb) && (mstype ==DLM_MSG_CANCEL ))) { - error = -EINVAL ; - goto out; - } -if (lkb->lkb_wait_type ||is_overlap_cancel (lkb)) {switch (mstype) {case DLM_MSG_UNLOCK :
@@ -1725,7 +1717,11 @@ static int add_to_waiters(struct dlm_lkb *lkb, int mstype, int to_nodeid)set_bit (DLM_IFL_OVERLAP_CANCEL_BIT , &lkb->lkb_iflags);break ;default : - error = -EBUSY ; +/* should never happen as validate_lock_args() checks +* on lkb_wait_type and validate_unlock_args() only +* creates UNLOCK or CANCEL messages. +*/ +WARN_ON_ONCE (1 ); goto out; } lkb->lkb_wait_count++;
@@ -1747,12 +1743,7 @@ static int add_to_waiters(struct dlm_lkb *lkb, int mstype, int to_nodeid)hold_lkb (lkb);list_add (&lkb->lkb_wait_reply, &ls->ls_waiters); out: -if (error) -log_error (ls,"addwait error %x %d flags %x %d %d %s" , - lkb->lkb_id, error,dlm_iflags_val (lkb), mstype, - lkb->lkb_wait_type, lkb->lkb_resource->res_name);spin_unlock_bh (&ls->ls_waiters_lock); -return error; }/* We clear the RESEND flag because we might be taking an lkb off the waiters
@@ -2926,13 +2917,16 @@ static int validate_unlock_args(struct dlm_lkb *lkb, struct dlm_args *args) goto out; } +if (is_overlap_unlock (lkb)) + goto out; +/* cancel not allowed with another cancel/unlock in progress */ if (args->flags &DLM_LKF_CANCEL ) {if (lkb->lkb_exflags &DLM_LKF_CANCEL ) goto out; -if (is_overlap (lkb)) +if (is_overlap_cancel (lkb)) goto out;if (test_bit (DLM_IFL_RESEND_BIT , &lkb->lkb_iflags)) {
@@ -2970,9 +2964,6 @@ static int validate_unlock_args(struct dlm_lkb *lkb, struct dlm_args *args)if (lkb->lkb_exflags &DLM_LKF_FORCEUNLOCK ) goto out; -if (is_overlap_unlock (lkb)) - goto out; -if (test_bit (DLM_IFL_RESEND_BIT , &lkb->lkb_iflags)) {set_bit (DLM_IFL_OVERLAP_UNLOCK_BIT , &lkb->lkb_iflags); rv = -EBUSY ;
@@ -3608,10 +3599,7 @@ static int send_common(struct dlm_rsb *r, struct dlm_lkb *lkb, int mstype) to_nodeid = r->res_nodeid; - error =add_to_waiters (lkb, mstype, to_nodeid); -if (error) -return error; - +add_to_waiters (lkb, mstype, to_nodeid); error =create_message (r, lkb, to_nodeid, mstype, &ms, &mh);if (error) goto fail;
@@ -3714,10 +3702,7 @@ static int send_lookup(struct dlm_rsb *r, struct dlm_lkb *lkb) to_nodeid =dlm_dir_nodeid (r); - error =add_to_waiters (lkb,DLM_MSG_LOOKUP , to_nodeid); -if (error) -return error; - +add_to_waiters (lkb,DLM_MSG_LOOKUP , to_nodeid); error =create_message (r,NULL , to_nodeid,DLM_MSG_LOOKUP , &ms, &mh);if (error) goto fail;
@@ -6342,8 +6327,8 @@ int dlm_debug_add_lkb_to_waiters(struct dlm_ls *ls, uint32_t lkb_id,if (error)return error; - error =add_to_waiters (lkb, mstype, to_nodeid); +add_to_waiters (lkb, mstype, to_nodeid);dlm_put_lkb (lkb); -return error; +return 0 ; }
Signature · 1 line
2.43.0