fs: dlm: change lock and endianness handling
Alexander Aring
maintainercover fs: dlm: change lock and endianness handling
Hi,
this patch series removes all sparse warnings which are occur when calling:
make C=2 fs/dlm/*.o
This patch series will not fix anything, but changes e.g. the endianness handling in dlm so we probably can find issues in future if dlm wire message value is compared against a host byte order value.
Otherwise there are some changes regarding casting or move functions around to make sparse quiet that it does not complain about those sections which are in my opinion false positives or at least handle it in such way right now to find a better solution in future.
I hope I caught all necessary endianness conversions (sparse does not complain if a format string and a value is handled as non host byte order for printout, but I tried to caught them all). There might be some better options to handle e.g. lkb types directly in little endian as it is dlm wire byte order. However this patch series will at first remove the in/out functionality for byte order conversion. There might be in future more follow up patches to change the byte order conversion in dlm application stack.
- Alex
Alexander Aring (9):
fs: dlm: add __CHECKER__ for false positives
fs: dlm: use __le types for options header
fs: dlm: use __le types for dlm header
fs: dlm: use __le types for rcom messages
fs: dlm: use __le types for dlm messages
fs: dlm: move conversion to compile time
fs: dlm: remove __user conversion warnings
fs: dlm: remove found label in dlm_master_lookup
fs: dlm: cleanup lock handling in dlm_master_lookup
fs/dlm/dir.c | 2 +- fs/dlm/dlm_internal.h | 66 ++--- fs/dlm/lock.c | 545 ++++++++++++++++++++++-------------------- fs/dlm/lowcomms.c | 10 + fs/dlm/member.c | 11 +- fs/dlm/midcomms.c | 58 +++-- fs/dlm/rcom.c | 120 +++++----- fs/dlm/recover.c | 10 +- fs/dlm/requestqueue.c | 20 +- fs/dlm/user.c | 16 +- fs/dlm/util.c | 92 +------ fs/dlm/util.h | 8 +- 12 files changed, 458 insertions(+), 500 deletions(-)
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH 1/9 fs: dlm: add __CHECKER__ for false positives
This patch will adds #ifndef __CHECKER__ for false positives warnings about an imbalance lock/unlock srcu handling. Which are shown by running sparse checks:
fs/dlm/midcomms.c:1065:20: warning: context imbalance in 'dlm_midcomms_get_mhandle' - wrong count at exit
Using __CHECKER__ will tell sparse to ignore these sections.
Those imbalances are false positive because from upper layer it is always required to call a function in sequence, e.g. if dlm_midcomms_get_mhandle() is successful there must be a dlm_midcomms_commit_mhandle() call afterwards.
--- fs/dlm/lowcomms.c | 10 ++++++++++ fs/dlm/midcomms.c | 10 ++++++++++ 2 files changed, 20 insertions(+)
fs/dlm/lowcomms.c +10 -0
@@ -1303,6 +1303,10 @@ static struct dlm_msg *dlm_lowcomms_new_msg_con(struct connection *con, int len,return msg; } +/* avoid false positive for nodes_srcu, unlock happens in +* dlm_lowcomms_commit_msg which is a must call if success +*/ +#ifndef __CHECKER__struct dlm_msg *dlm_lowcomms_new_msg (int nodeid,int len,gfp_t allocation,char **ppc,void (*cb)(void *data),void *data)
@@ -1336,6 +1340,7 @@ struct dlm_msg *dlm_lowcomms_new_msg(int nodeid, int len, gfp_t allocation, msg->idx = idx; return msg; } +#endif static void _dlm_lowcomms_commit_msg (struct dlm_msg *msg) {
@@ -1362,11 +1367,16 @@ static void _dlm_lowcomms_commit_msg(struct dlm_msg *msg)return ; } +/* avoid false positive for nodes_srcu, lock was happen in +* dlm_lowcomms_new_msg +*/ +#ifndef __CHECKER__void dlm_lowcomms_commit_msg (struct dlm_msg *msg) {_dlm_lowcomms_commit_msg (msg);srcu_read_unlock (&connections_srcu, msg->idx); } +#endif void dlm_lowcomms_put_msg (struct dlm_msg *msg) {
fs/dlm/midcomms.c +10 -0
@@ -1062,6 +1062,10 @@ static struct dlm_msg *dlm_midcomms_get_msg_3_2(struct dlm_mhandle *mh, int nodereturn msg; } +/* avoid false positive for nodes_srcu, unlock happens in +* dlm_midcomms_commit_mhandle which is a must call if success +*/ +#ifndef __CHECKER__struct dlm_mhandle *dlm_midcomms_get_mhandle (int nodeid,int len,gfp_t allocation,char **ppc) {
@@ -1127,6 +1131,7 @@ struct dlm_mhandle *dlm_midcomms_get_mhandle(int nodeid, int len,srcu_read_unlock (&nodes_srcu, idx); return NULL; } +#endif static void dlm_midcomms_commit_msg_3_2 (struct dlm_mhandle *mh) {
@@ -1136,6 +1141,10 @@ static void dlm_midcomms_commit_msg_3_2(struct dlm_mhandle *mh)dlm_lowcomms_commit_msg (mh->msg); } +/* avoid false positive for nodes_srcu, lock was happen in +* dlm_midcomms_get_mhandle +*/ +#ifndef __CHECKER__void dlm_midcomms_commit_mhandle (struct dlm_mhandle *mh) {switch (mh->node->version) {
@@ -1157,6 +1166,7 @@ void dlm_midcomms_commit_mhandle(struct dlm_mhandle *mh) break; } } +#endif int dlm_midcomms_start (void ) {
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH 2/9 fs: dlm: use __le types for options header
In reply to Alexander AringThis patch changes to use __le types directly in the dlm option headers structures which are casted at the right dlm message buffer positions.
Currently only midcomms.c using those headers which already was calling endian conversions on-the-fly without using in/out functionality like other endianness handling in dlm. Using __le types now will hopefully get useful warnings in future if we do comparison against host byte order values.
--- fs/dlm/dlm_internal.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/dlm/dlm_internal.h +5 -5
@@ -460,9 +460,9 @@ struct dlm_rcom { };struct dlm_opt_header { -uint16_t t_type; -uint16_t t_length; -uint32_t t_pad; +__le16 t_type; +__le16 t_length; +__le32 t_pad;/* need to be 8 byte aligned */ char t_value[]; };
@@ -472,8 +472,8 @@ struct dlm_opts {struct dlm_header o_header;uint8_t o_nextcmd;uint8_t o_pad; -uint16_t o_optlen; -uint32_t o_pad2; +__le16 o_optlen; +__le32 o_pad2;char o_opts[]; };
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH 3/9 fs: dlm: use __le types for dlm header
In reply to Alexander AringThis patch changes to use __le types directly in the dlm header structure which is casted at the right dlm message buffer positions.
The main goal what is reached here is to remove sparse warnings regarding to host to little byte order conversion or vice versa. Leaving those sparse issues ignored and always do it in out/in functionality tends to leave it unknown in which byte order the variable is being handled.
--- fs/dlm/dir.c | 2 +- fs/dlm/dlm_internal.h | 10 ++--- fs/dlm/lock.c | 95 +++++++++++++++++++++++-------------------- fs/dlm/member.c | 2 +- fs/dlm/midcomms.c | 28 ++++++------- fs/dlm/rcom.c | 42 ++++++++++--------- fs/dlm/requestqueue.c | 7 ++-- fs/dlm/util.c | 26 ------------ fs/dlm/util.h | 2 - 9 files changed, 98 insertions(+), 116 deletions(-)
fs/dlm/dir.c +1 -1
@@ -101,7 +101,7 @@ int dlm_recover_directory(struct dlm_ls *ls)*/ b = ls->ls_recover_buf->rc_buf; - left = ls->ls_recover_buf->rc_header.h_length; + left =le16_to_cpu (ls->ls_recover_buf->rc_header.h_length); left -=sizeof (struct dlm_rcom );for (;;) {
fs/dlm/dlm_internal.h +5 -5
@@ -379,15 +379,15 @@ static inline int rsb_flag(struct dlm_rsb *r, enum rsb_flags flag)#define DLM_FIN 5struct dlm_header { -uint32_t h_version; +__le32 h_version;union {/* for DLM_MSG and DLM_RCOM */ -uint32_t h_lockspace; +__le32 h_lockspace;/* for DLM_ACK and DLM_OPTS */ -uint32_t h_seq; +__le32 h_seq; } u; -uint32_t h_nodeid;/* nodeid of sender */ -uint16_t h_length; +__le32 h_nodeid;/* nodeid of sender */ +__le16 h_length;uint8_t h_cmd;/* DLM_MSG, DLM_RCOM */ uint8_t h_pad; };
fs/dlm/lock.c +52 -43
287 lines not on this page · raw message
fs/dlm/member.c +1 -1
@@ -20,7 +20,7 @@int dlm_slots_version (struct dlm_header *h) { -if ((h->h_version &0x0000FFFF ) <DLM_HEADER_SLOTS ) +if ((le32_to_cpu (h->h_version) &0x0000FFFF ) <DLM_HEADER_SLOTS )return 0 ;return 1 ; }
fs/dlm/midcomms.c +12 -16
@@ -380,13 +380,12 @@ static int dlm_send_ack(int nodeid, uint32_t seq) m_header = (struct dlm_header *)ppc; - m_header->h_version = (DLM_HEADER_MAJOR |DLM_HEADER_MINOR ); - m_header->h_nodeid =dlm_our_nodeid (); - m_header->h_length = mb_len; + m_header->h_version =cpu_to_le32 (DLM_HEADER_MAJOR |DLM_HEADER_MINOR ); + m_header->h_nodeid =cpu_to_le32 (dlm_our_nodeid ()); + m_header->h_length =cpu_to_le16 (mb_len); m_header->h_cmd =DLM_ACK ; - m_header->u.h_seq = seq; + m_header->u.h_seq =cpu_to_le32 (seq); -header_out (m_header);dlm_lowcomms_commit_msg (msg);dlm_lowcomms_put_msg (msg);
@@ -409,13 +408,11 @@ static int dlm_send_fin(struct midcomms_node *node, m_header = (struct dlm_header *)ppc; - m_header->h_version = (DLM_HEADER_MAJOR |DLM_HEADER_MINOR ); - m_header->h_nodeid =dlm_our_nodeid (); - m_header->h_length = mb_len; + m_header->h_version =cpu_to_le32 (DLM_HEADER_MAJOR |DLM_HEADER_MINOR ); + m_header->h_nodeid =cpu_to_le32 (dlm_our_nodeid ()); + m_header->h_length =cpu_to_le16 (mb_len); m_header->h_cmd =DLM_FIN ; -header_out (m_header); -pr_debug ("sending fin msg to node %d\n" , node->nodeid);dlm_midcomms_commit_mhandle (mh);set_bit (DLM_NODE_FLAG_STOP_TX , &node->flags);
@@ -1020,11 +1017,10 @@ static void dlm_fill_opts_header(struct dlm_opts *opts, uint16_t inner_len, uint32_t seq) { opts->o_header.h_cmd =DLM_OPTS ; - opts->o_header.h_version = (DLM_HEADER_MAJOR |DLM_HEADER_MINOR ); - opts->o_header.h_nodeid =dlm_our_nodeid (); - opts->o_header.h_length =DLM_MIDCOMMS_OPT_LEN + inner_len; - opts->o_header.u.h_seq = seq; -header_out (&opts->o_header); + opts->o_header.h_version =cpu_to_le32 (DLM_HEADER_MAJOR |DLM_HEADER_MINOR ); + opts->o_header.h_nodeid =cpu_to_le32 (dlm_our_nodeid ()); + opts->o_header.h_length =cpu_to_le16 (DLM_MIDCOMMS_OPT_LEN + inner_len); + opts->o_header.u.h_seq =cpu_to_le32 (seq); }static void midcomms_new_msg_cb (void *data)
@@ -1465,7 +1461,7 @@ static void midcomms_new_rawmsg_cb(void *data)switch (h->h_cmd) {case DLM_OPTS :if (!h->u.h_seq) - h->u.h_seq = rd->node->seq_send++; + h->u.h_seq =cpu_to_le32 (rd->node->seq_send++);break ;default :break ;
fs/dlm/rcom.c +23 -19
109 lines not on this page · raw message
fs/dlm/requestqueue.c +4 -3
@@ -32,7 +32,8 @@ struct rq_entry {void dlm_add_requestqueue (struct dlm_ls *ls,int nodeid,struct dlm_message *ms) {struct rq_entry *e; -int length = ms->m_header.h_length -sizeof (struct dlm_message ); +int length =le16_to_cpu (ms->m_header.h_length) - +sizeof (struct dlm_message ); e =kmalloc (sizeof (struct rq_entry ) + length,GFP_NOFS );if (!e) {
@@ -42,7 +43,7 @@ void dlm_add_requestqueue(struct dlm_ls *ls, int nodeid, struct dlm_message *ms) e->recover_seq = ls->ls_recover_seq &0xFFFFFFFF ; e->nodeid = nodeid; -memcpy (&e->request, ms, ms->m_header.h_length); +memcpy (&e->request, ms,le16_to_cpu (ms->m_header.h_length));atomic_inc (&ls->ls_requestqueue_cnt);mutex_lock (&ls->ls_requestqueue_mutex);
@@ -82,7 +83,7 @@ int dlm_process_requestqueue(struct dlm_ls *ls)log_limit (ls,"dlm_process_requestqueue msg %d from %d " "lkid %x remid %x result %d seq %u" , - ms->m_type, ms->m_header.h_nodeid, + ms->m_type,le32_to_cpu (ms->m_header.h_nodeid), ms->m_lkid, ms->m_remid, ms->m_result, e->recover_seq);
fs/dlm/util.c +0 -26
@@ -20,24 +20,6 @@#define DLM_ERRNO_ETIMEDOUT 110#define DLM_ERRNO_EINPROGRESS 115 -void header_out (struct dlm_header *hd) -{ - hd->h_version =cpu_to_le32 (hd->h_version); -/* does it for others u32 in union as well */ - hd->u.h_lockspace =cpu_to_le32 (hd->u.h_lockspace); - hd->h_nodeid =cpu_to_le32 (hd->h_nodeid); - hd->h_length =cpu_to_le16 (hd->h_length); -} - -void header_in (struct dlm_header *hd) -{ - hd->h_version =le32_to_cpu (hd->h_version); -/* does it for others u32 in union as well */ - hd->u.h_lockspace =le32_to_cpu (hd->u.h_lockspace); - hd->h_nodeid =le32_to_cpu (hd->h_nodeid); - hd->h_length =le16_to_cpu (hd->h_length); -} -/* higher errno values are inconsistent across architectures, so select one set of values for on the wire */
@@ -85,8 +67,6 @@ static int from_dlm_errno(int err)void dlm_message_out (struct dlm_message *ms) { -header_out (&ms->m_header); - ms->m_type =cpu_to_le32 (ms->m_type); ms->m_nodeid =cpu_to_le32 (ms->m_nodeid); ms->m_pid =cpu_to_le32 (ms->m_pid);
@@ -109,8 +89,6 @@ void dlm_message_out(struct dlm_message *ms)void dlm_message_in (struct dlm_message *ms) { -header_in (&ms->m_header); - ms->m_type =le32_to_cpu (ms->m_type); ms->m_nodeid =le32_to_cpu (ms->m_nodeid); ms->m_pid =le32_to_cpu (ms->m_pid);
@@ -133,8 +111,6 @@ void dlm_message_in(struct dlm_message *ms)void dlm_rcom_out (struct dlm_rcom *rc) { -header_out (&rc->rc_header); - rc->rc_type =cpu_to_le32 (rc->rc_type); rc->rc_result =cpu_to_le32 (rc->rc_result); rc->rc_id =cpu_to_le64 (rc->rc_id);
@@ -144,8 +120,6 @@ void dlm_rcom_out(struct dlm_rcom *rc)void dlm_rcom_in (struct dlm_rcom *rc) { -header_in (&rc->rc_header); - rc->rc_type =le32_to_cpu (rc->rc_type); rc->rc_result =le32_to_cpu (rc->rc_result); rc->rc_id =le64_to_cpu (rc->rc_id);
fs/dlm/util.h +0 -2
@@ -15,8 +15,6 @@ void dlm_message_out(struct dlm_message *ms);void dlm_message_in (struct dlm_message *ms);void dlm_rcom_out (struct dlm_rcom *rc);void dlm_rcom_in (struct dlm_rcom *rc); -void header_out (struct dlm_header *hd); -void header_in (struct dlm_header *hd);#endif
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH 4/9 fs: dlm: use __le types for rcom messages
In reply to Alexander AringThis patch changes to use __le types directly in the dlm rcom structure which is casted at the right dlm message buffer positions.
The main goal what is reached here is to remove sparse warnings regarding to host to little byte order conversion or vice versa. Leaving those sparse issues ignored and always do it in out/in functionality tends to leave it unknown in which byte order the variable is being handled.
--- fs/dlm/dlm_internal.h | 10 +++--- fs/dlm/lock.c | 3 +- fs/dlm/member.c | 9 ++--- fs/dlm/rcom.c | 80 +++++++++++++++++++++---------------------- fs/dlm/recover.c | 10 +++--- fs/dlm/util.c | 18 ---------- fs/dlm/util.h | 2 -- 7 files changed, 52 insertions(+), 80 deletions(-)
fs/dlm/dlm_internal.h +5 -5
@@ -451,11 +451,11 @@ struct dlm_message {struct dlm_rcom {struct dlm_header rc_header; -uint32_t rc_type;/* DLM_RCOM_ */ -int rc_result;/* multi-purpose */ -uint64_t rc_id;/* match reply with request */ -uint64_t rc_seq;/* sender's ls_recover_seq */ -uint64_t rc_seq_reply;/* remote ls_recover_seq */ +__le32 rc_type;/* DLM_RCOM_ */ +__le32 rc_result;/* multi-purpose */ +__le64 rc_id;/* match reply with request */ +__le64 rc_seq;/* sender's ls_recover_seq */ +__le64 rc_seq_reply;/* remote ls_recover_seq */ char rc_buf[]; };
fs/dlm/lock.c +1 -2
@@ -5061,8 +5061,7 @@ void dlm_receive_buffer(union dlm_packet *p, int nodeid) type = p->message.m_type;break ;case DLM_RCOM : -dlm_rcom_in (&p->rcom); - type = p->rcom.rc_type; + type =le32_to_cpu (p->rcom.rc_type);break ;default :log_print ("invalid h_cmd %d from %u" , hd->h_cmd, nodeid);
fs/dlm/member.c +2 -7
@@ -120,18 +120,13 @@ int dlm_slots_copy_in(struct dlm_ls *ls) ro0 = (struct rcom_slot *)(rc->rc_buf +sizeof (struct rcom_config )); -for (i =0 , ro = ro0; i < num_slots; i++, ro++) { - ro->ro_nodeid =le32_to_cpu (ro->ro_nodeid); - ro->ro_slot =le16_to_cpu (ro->ro_slot); - } -log_slots (ls, gen, num_slots, ro0,NULL ,0 );list_for_each_entry (memb, &ls->ls_nodes, list) {for (i =0 , ro = ro0; i < num_slots; i++, ro++) { -if (ro->ro_nodeid != memb->nodeid) +if (le32_to_cpu (ro->ro_nodeid) != memb->nodeid)continue ; - memb->slot = ro->ro_slot; + memb->slot =le16_to_cpu (ro->ro_slot); memb->slot_prev = memb->slot;break ; }
fs/dlm/rcom.c +39 -41
243 lines not on this page · raw message
fs/dlm/recover.c +5 -5
@@ -114,7 +114,7 @@ static int wait_status_all(struct dlm_ls *ls, uint32_t wait_status,if (save_slots)dlm_slot_save (ls, rc, memb); -if (rc->rc_result & wait_status) +if (le32_to_cpu (rc->rc_result) & wait_status)break ;if (delay <1000 ) delay +=20 ;
@@ -141,7 +141,7 @@ static int wait_status_low(struct dlm_ls *ls, uint32_t wait_status,if (error)break ; -if (rc->rc_result & wait_status) +if (le32_to_cpu (rc->rc_result) & wait_status)break ;if (delay <1000 ) delay +=20 ;
@@ -568,14 +568,14 @@ int dlm_recover_master_reply(struct dlm_ls *ls, struct dlm_rcom *rc)struct dlm_rsb *r;int ret_nodeid, new_master; - r =recover_idr_find (ls, rc->rc_id); + r =recover_idr_find (ls,le64_to_cpu (rc->rc_id));if (!r) {log_error (ls,"dlm_recover_master_reply no id %llx" , - (unsigned long long )rc->rc_id); + (unsigned long long )le64_to_cpu (rc->rc_id)); goto out; } - ret_nodeid = rc->rc_result; + ret_nodeid =le32_to_cpu (rc->rc_result);if (ret_nodeid ==dlm_our_nodeid ()) new_master =0 ;
fs/dlm/util.c +0 -18
@@ -108,21 +108,3 @@ void dlm_message_in(struct dlm_message *ms) ms->m_asts =le32_to_cpu (ms->m_asts); ms->m_result =from_dlm_errno (le32_to_cpu (ms->m_result)); } - -void dlm_rcom_out (struct dlm_rcom *rc) -{ - rc->rc_type =cpu_to_le32 (rc->rc_type); - rc->rc_result =cpu_to_le32 (rc->rc_result); - rc->rc_id =cpu_to_le64 (rc->rc_id); - rc->rc_seq =cpu_to_le64 (rc->rc_seq); - rc->rc_seq_reply =cpu_to_le64 (rc->rc_seq_reply); -} - -void dlm_rcom_in (struct dlm_rcom *rc) -{ - rc->rc_type =le32_to_cpu (rc->rc_type); - rc->rc_result =le32_to_cpu (rc->rc_result); - rc->rc_id =le64_to_cpu (rc->rc_id); - rc->rc_seq =le64_to_cpu (rc->rc_seq); - rc->rc_seq_reply =le64_to_cpu (rc->rc_seq_reply); -}
fs/dlm/util.h +0 -2
@@ -13,8 +13,6 @@void dlm_message_out (struct dlm_message *ms);void dlm_message_in (struct dlm_message *ms); -void dlm_rcom_out (struct dlm_rcom *rc); -void dlm_rcom_in (struct dlm_rcom *rc);#endif
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH 5/9 fs: dlm: use __le types for dlm messages
In reply to Alexander AringThis patch changes to use __le types directly in the dlm message structure which is casted at the right dlm message buffer positions.
The main goal what is reached here is to remove sparse warnings regarding to host to little byte order conversion or vice versa. Leaving those sparse issues ignored and always do it in out/in functionality tends to leave it unknown in which byte order the variable is being handled.
--- fs/dlm/dlm_internal.h | 36 +++--- fs/dlm/lock.c | 276 ++++++++++++++++++++++-------------------- fs/dlm/requestqueue.c | 15 ++- fs/dlm/util.c | 48 +------- fs/dlm/util.h | 4 +- 5 files changed, 174 insertions(+), 205 deletions(-)
fs/dlm/dlm_internal.h +18 -18
@@ -409,24 +409,24 @@ struct dlm_header {struct dlm_message {struct dlm_header m_header; -uint32_t m_type;/* DLM_MSG_ */ -uint32_t m_nodeid; -uint32_t m_pid; -uint32_t m_lkid;/* lkid on sender */ -uint32_t m_remid;/* lkid on receiver */ -uint32_t m_parent_lkid; -uint32_t m_parent_remid; -uint32_t m_exflags; -uint32_t m_sbflags; -uint32_t m_flags; -uint32_t m_lvbseq; -uint32_t m_hash; -int m_status; -int m_grmode; -int m_rqmode; -int m_bastmode; -int m_asts; -int m_result;/* 0 or -EXXX */ +__le32 m_type;/* DLM_MSG_ */ +__le32 m_nodeid; +__le32 m_pid; +__le32 m_lkid;/* lkid on sender */ +__le32 m_remid;/* lkid on receiver */ +__le32 m_parent_lkid; +__le32 m_parent_remid; +__le32 m_exflags; +__le32 m_sbflags; +__le32 m_flags; +__le32 m_lvbseq; +__le32 m_hash; +__le32 m_status; +__le32 m_grmode; +__le32 m_rqmode; +__le32 m_bastmode; +__le32 m_asts; +__le32 m_result;/* 0 or -EXXX */ char m_extra[];/* name or lvb */ };
fs/dlm/lock.c +143 -133
699 lines not on this page · raw message
fs/dlm/requestqueue.c +9 -6
@@ -14,6 +14,7 @@#include "dir.h" #include "config.h" #include "requestqueue.h" +#include "util.h" struct rq_entry {struct list_head list;
@@ -83,8 +84,10 @@ int dlm_process_requestqueue(struct dlm_ls *ls)log_limit (ls,"dlm_process_requestqueue msg %d from %d " "lkid %x remid %x result %d seq %u" , - ms->m_type,le32_to_cpu (ms->m_header.h_nodeid), - ms->m_lkid, ms->m_remid, ms->m_result, +le32_to_cpu (ms->m_type), +le32_to_cpu (ms->m_header.h_nodeid), +le32_to_cpu (ms->m_lkid),le32_to_cpu (ms->m_remid), +from_dlm_errno (le32_to_cpu (ms->m_result)), e->recover_seq);dlm_receive_message_saved (ls, &e->request, e->recover_seq);
@@ -125,7 +128,7 @@ void dlm_wait_requestqueue(struct dlm_ls *ls)static int purge_request (struct dlm_ls *ls,struct dlm_message *ms,int nodeid) { -uint32_t type = ms->m_type; +__le32 type = ms->m_type;/* the ls is being cleaned up and freed by release_lockspace */ if (!atomic_read (&ls->ls_count))
@@ -137,9 +140,9 @@ static int purge_request(struct dlm_ls *ls, struct dlm_message *ms, int nodeid)/* directory operations are always purged because the directory is always rebuilt during recovery and the lookups resent */ -if (type ==DLM_MSG_REMOVE || - type ==DLM_MSG_LOOKUP || - type ==DLM_MSG_LOOKUP_REPLY ) +if (type ==cpu_to_le32 (DLM_MSG_REMOVE ) || + type ==cpu_to_le32 (DLM_MSG_LOOKUP ) || + type ==cpu_to_le32 (DLM_MSG_LOOKUP_REPLY ))return 1 ;if (!dlm_no_directory (ls))
fs/dlm/util.c +2 -46
63 lines not on this page · raw message
fs/dlm/util.h +2 -2
@@ -11,8 +11,8 @@#ifndef __UTIL_DOT_H__#define __UTIL_DOT_H__ -void dlm_message_out (struct dlm_message *ms); -void dlm_message_in (struct dlm_message *ms); +int to_dlm_errno (int err); +int from_dlm_errno (int err);#endif
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH 6/9 fs: dlm: move conversion to compile time
In reply to Alexander AringThis patch is a cleanup to move the byte order conversion to compile time. In a simple comparison like this it's possible to move it to static values so the compiler will always convert those values at compile time.
--- fs/dlm/midcomms.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
fs/dlm/midcomms.c +10 -10
@@ -571,14 +571,14 @@ dlm_midcomms_recv_node_lookup(int nodeid, const union dlm_packet *p,return NULL ; } -switch (le32_to_cpu (p->rcom.rc_type)) { -case DLM_RCOM_NAMES : +switch (p->rcom.rc_type) { +case cpu_to_le32 (DLM_RCOM_NAMES ): fallthrough; -case DLM_RCOM_NAMES_REPLY : +case cpu_to_le32 (DLM_RCOM_NAMES_REPLY ): fallthrough; -case DLM_RCOM_STATUS : +case cpu_to_le32 (DLM_RCOM_STATUS ): fallthrough; -case DLM_RCOM_STATUS_REPLY : +case cpu_to_le32 (DLM_RCOM_STATUS_REPLY ): node =nodeid2node (nodeid,0 );if (node) {spin_lock (&node->state_lock);
@@ -738,14 +738,14 @@ static void dlm_midcomms_receive_buffer_3_2(union dlm_packet *p, int nodeid)* * length already checked. */ -switch (le32_to_cpu (p->rcom.rc_type)) { -case DLM_RCOM_NAMES : +switch (p->rcom.rc_type) { +case cpu_to_le32 (DLM_RCOM_NAMES ): fallthrough; -case DLM_RCOM_NAMES_REPLY : +case cpu_to_le32 (DLM_RCOM_NAMES_REPLY ): fallthrough; -case DLM_RCOM_STATUS : +case cpu_to_le32 (DLM_RCOM_STATUS ): fallthrough; -case DLM_RCOM_STATUS_REPLY : +case cpu_to_le32 (DLM_RCOM_STATUS_REPLY ):break ;default : log_print("unsupported rcom type received: %u, will skip this message from node %d",
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH 7/9 fs: dlm: remove __user conversion warnings
In reply to Alexander AringThis patch avoids the following sparse warning:
fs/dlm/user.c:111:38: warning: incorrect type in assignment (different address spaces)fs/dlm/user.c:111:38: expected void [noderef] __user *castparamfs/dlm/user.c:111:38: got void *fs/dlm/user.c:112:37: warning: incorrect type in assignment (different address spaces)fs/dlm/user.c:112:37: expected void [noderef] __user *castaddrfs/dlm/user.c:112:37: got void *fs/dlm/user.c:113:38: warning: incorrect type in assignment (different address spaces)fs/dlm/user.c:113:38: expected void [noderef] __user *bastparamfs/dlm/user.c:113:38: got void *fs/dlm/user.c:114:37: warning: incorrect type in assignment (different address spaces)fs/dlm/user.c:114:37: expected void [noderef] __user *bastaddrfs/dlm/user.c:114:37: got void *fs/dlm/user.c:115:33: warning: incorrect type in assignment (different address spaces)fs/dlm/user.c:115:33: expected struct dlm_lksb [noderef] __user *lksbfs/dlm/user.c:115:33: got void *fs/dlm/user.c:130:39: warning: cast removes address space '__user' of expression fs/dlm/user.c:131:40: warning: cast removes address space '__user' of expression fs/dlm/user.c:132:36: warning: cast removes address space '__user' of expression
So far I see there is no direct handling of copying a pointer value to another pointer value. The handling only copies the actual pointer address to a scalar type or vice versa. This should be okay because it never handles dereferencing anything of those addresses in the kernel space. To get rid of those warnings we doing some different casting which results in no warnings in sparse or compiler.
--- fs/dlm/user.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
fs/dlm/user.c +8 -8
@@ -108,11 +108,11 @@ static void compat_input(struct dlm_write_request *kb, kb->i.lock.parent = kb32->i.lock.parent; kb->i.lock.xid = kb32->i.lock.xid; kb->i.lock.timeout = kb32->i.lock.timeout; - kb->i.lock.castparam = (void *)(long )kb32->i.lock.castparam; - kb->i.lock.castaddr = (void *)(long )kb32->i.lock.castaddr; - kb->i.lock.bastparam = (void *)(long )kb32->i.lock.bastparam; - kb->i.lock.bastaddr = (void *)(long )kb32->i.lock.bastaddr; - kb->i.lock.lksb = (void *)(long )kb32->i.lock.lksb; + kb->i.lock.castparam = (__user void *)(long )kb32->i.lock.castparam; + kb->i.lock.castaddr = (__user void *)(long )kb32->i.lock.castaddr; + kb->i.lock.bastparam = (__user void *)(long )kb32->i.lock.bastparam; + kb->i.lock.bastaddr = (__user void *)(long )kb32->i.lock.bastaddr; + kb->i.lock.lksb = (__user void *)(long )kb32->i.lock.lksb;memcpy (kb->i.lock.lvb, kb32->i.lock.lvb,DLM_USER_LVB_LEN );memcpy (kb->i.lock.name, kb32->i.lock.name, namelen); }
@@ -127,9 +127,9 @@ static void compat_output(struct dlm_lock_result *res, res32->version[1 ] = res->version[1 ]; res32->version[2 ] = res->version[2 ]; - res32->user_astaddr = (__u32 )(long )res->user_astaddr; - res32->user_astparam = (__u32 )(long )res->user_astparam; - res32->user_lksb = (__u32 )(long )res->user_lksb; + res32->user_astaddr = (__u32 )(__force long )res->user_astaddr; + res32->user_astparam = (__u32 )(__force long )res->user_astparam; + res32->user_lksb = (__u32 )(__force long )res->user_lksb; res32->bast_mode = res->bast_mode; res32->lvb_offset = res->lvb_offset;
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH 8/9 fs: dlm: remove found label in dlm_master_lookup
In reply to Alexander AringThis patch cleanups a not necessary label found which can be replaced by a proper else handling to jump over a specific code block.
--- fs/dlm/lock.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
fs/dlm/lock.c +9 -9
@@ -954,18 +954,18 @@ int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, char *name, int len,hold_rsb (r);spin_unlock (&ls->ls_rsbtbl[b].lock);lock_rsb (r); - goto found; - } + }else { + error =dlm_search_rsb_tree (&ls->ls_rsbtbl[b].toss, name, len, &r); +if (error) + goto not_found; - error =dlm_search_rsb_tree (&ls->ls_rsbtbl[b].toss, name, len, &r); -if (error) - goto not_found; +/* because the rsb is inactive (on toss list), it's not refcounted +* and lock_rsb is not used, but is protected by the rsbtbl lock +*/ -/* because the rsb is inactive (on toss list), it's not refcounted -and lock_rsb is not used, but is protected by the rsbtbl lock */ + toss_list =1 ; + } - toss_list =1 ; - found:if (r->res_dir_nodeid != our_nodeid) {/* should not happen, but may as well fix it and carry on */ log_error(ls, "dlm_master_lookup res_dir %d our %d %s",
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH 9/9 fs: dlm: cleanup lock handling in dlm_master_lookup
In reply to Alexander AringThis patch will remove the following warning by sparse:
fs/dlm/lock.c:1049:9: warning: context imbalance in 'dlm_master_lookup' - different lock contexts for basic block
I tried to find any issues with the current handling and I did not find any. However it is hard to follow the lock handling in this area of dlm_master_lookup() and I suppose that sparse cannot realize that there are no issues. The variable "toss_list" makes it really hard to follow the lock handling because if it's set the rsb lock/refcount isn't held but the ls->ls_rsbtbl[b].lock is held and this is one reason why the rsb lock/refcount does not need to be held. If it's not set the ls->ls_rsbtbl[b].lock is not held but the rsb lock/refcount is held. The indicator of toss_list will be used to store the actual lock state. Another possibility is that a retry can happen and then it's hard to follow the specific code part. I did not find any issues but sparse cannot realize that there are no issues.
To make it more easier to understand for developers and sparse as well, we remove the toss_list variable which indicates a specific lock state and move handling in between of this lock state in a separate function. This function can be called now in case when the initial lock states are taken which was previously signalled if toss_list was set or not. The advantage here is that we can release all locks/refcounts in mostly the same code block as it was taken.
Afterwards sparse had no issues to figure out that there are no problems with the current lock behaviour.
--- fs/dlm/lock.c | 189 +++++++++++++++++++++++++++----------------------- 1 file changed, 102 insertions(+), 87 deletions(-)
fs/dlm/lock.c +102 -87
@@ -880,6 +880,88 @@ static int validate_master_nodeid(struct dlm_ls *ls, struct dlm_rsb *r, } } +static void __dlm_master_lookup (struct dlm_ls *ls,struct dlm_rsb *r,int our_nodeid, +int from_nodeid,bool toss_list,unsigned int flags, +int *r_nodeid,int *result) +{ +int fix_master = (flags &DLM_LU_RECOVER_MASTER ); +int from_master = (flags &DLM_LU_RECOVER_DIR ); + +if (r->res_dir_nodeid != our_nodeid) { +/* should not happen, but may as well fix it and carry on */ +log_error (ls,"%s res_dir %d our %d %s" , __func__, + r->res_dir_nodeid, our_nodeid, r->res_name); + r->res_dir_nodeid = our_nodeid; + } + +if (fix_master &&dlm_is_removed (ls, r->res_master_nodeid)) { +/* Recovery uses this function to set a new master when +* the previous master failed. Setting NEW_MASTER will +* force dlm_recover_masters to call recover_master on this +* rsb even though the res_nodeid is no longer removed. +*/ + + r->res_master_nodeid = from_nodeid; + r->res_nodeid = from_nodeid; +rsb_set_flag (r,RSB_NEW_MASTER ); + +if (toss_list) { +/* I don't think we should ever find it on toss list. */ +log_error (ls,"%s fix_master on toss" , __func__); +dlm_dump_rsb (r); + } + } + +if (from_master && (r->res_master_nodeid != from_nodeid)) { +/* this will happen if from_nodeid became master during +* a previous recovery cycle, and we aborted the previous +* cycle before recovering this master value +*/ + +log_limit (ls,"%s from_master %d master_nodeid %d res_nodeid %d first %x %s" , + __func__, from_nodeid, r->res_master_nodeid, + r->res_nodeid, r->res_first_lkid, r->res_name); + +if (r->res_master_nodeid == our_nodeid) { +log_error (ls,"from_master %d our_master" , from_nodeid); +dlm_dump_rsb (r); + goto ret_assign; + } + + r->res_master_nodeid = from_nodeid; + r->res_nodeid = from_nodeid; +rsb_set_flag (r,RSB_NEW_MASTER ); + } + +if (!r->res_master_nodeid) { +/* this will happen if recovery happens while we're looking +* up the master for this rsb +*/ + +log_debug (ls,"%s master 0 to %d first %x %s" , __func__, + from_nodeid, r->res_first_lkid, r->res_name); + r->res_master_nodeid = from_nodeid; + r->res_nodeid = from_nodeid; + } + +if (!from_master && !fix_master && + (r->res_master_nodeid == from_nodeid)) { +/* this can happen when the master sends remove, the dir node +* finds the rsb on the keep list and ignores the remove, +* and the former master sends a lookup +*/ + +log_limit (ls,"%s from master %d flags %x first %x %s" , + __func__, from_nodeid, flags, r->res_first_lkid, + r->res_name); + } + + ret_assign: + *r_nodeid = r->res_master_nodeid; +if (result) + *result =DLM_LU_MATCH ; +} +/* * We're the dir node for this res and another node wants to know the * master nodeid. During normal operation (non recovery) this is only
@@ -914,10 +996,8 @@ int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, char *name, int len, {struct dlm_rsb *r =NULL ;uint32_t hash, b; -int from_master = (flags &DLM_LU_RECOVER_DIR ); -int fix_master = (flags &DLM_LU_RECOVER_MASTER );int our_nodeid =dlm_our_nodeid (); -int dir_nodeid, error, toss_list =0 ; +int dir_nodeid, error;if (len >DLM_RESNAME_MAXLEN )return -EINVAL ;
@@ -949,103 +1029,38 @@ int dlm_master_lookup(struct dlm_ls *ls, int from_nodeid, char *name, int len, error =dlm_search_rsb_tree (&ls->ls_rsbtbl[b].keep, name, len, &r);if (!error) {/* because the rsb is active, we need to lock_rsb before -checking/changing re_master_nodeid */ +* checking/changing re_master_nodeid +*/ hold_rsb (r);spin_unlock (&ls->ls_rsbtbl[b].lock);lock_rsb (r); - }else { - error =dlm_search_rsb_tree (&ls->ls_rsbtbl[b].toss, name, len, &r); -if (error) - goto not_found; - -/* because the rsb is inactive (on toss list), it's not refcounted -* and lock_rsb is not used, but is protected by the rsbtbl lock -*/ - - toss_list =1 ; - } - -if (r->res_dir_nodeid != our_nodeid) { -/* should not happen, but may as well fix it and carry on */ -log_error (ls,"dlm_master_lookup res_dir %d our %d %s" , - r->res_dir_nodeid, our_nodeid, r->res_name); - r->res_dir_nodeid = our_nodeid; - } - -if (fix_master &&dlm_is_removed (ls, r->res_master_nodeid)) { -/* Recovery uses this function to set a new master when -the previous master failed. Setting NEW_MASTER will -force dlm_recover_masters to call recover_master on this -rsb even though the res_nodeid is no longer removed. */ - - r->res_master_nodeid = from_nodeid; - r->res_nodeid = from_nodeid; -rsb_set_flag (r,RSB_NEW_MASTER ); - -if (toss_list) { -/* I don't think we should ever find it on toss list. */ -log_error (ls,"dlm_master_lookup fix_master on toss" ); -dlm_dump_rsb (r); - } - } -if (from_master && (r->res_master_nodeid != from_nodeid)) { -/* this will happen if from_nodeid became master during -a previous recovery cycle, and we aborted the previous -cycle before recovering this master value */ +__dlm_master_lookup (ls, r, our_nodeid, from_nodeid, false, + flags, r_nodeid, result); -log_limit (ls,"dlm_master_lookup from_master %d " -"master_nodeid %d res_nodeid %d first %x %s" , - from_nodeid, r->res_master_nodeid, r->res_nodeid, - r->res_first_lkid, r->res_name); - -if (r->res_master_nodeid == our_nodeid) { -log_error (ls,"from_master %d our_master" , from_nodeid); -dlm_dump_rsb (r); - goto out_found; - } +/* the rsb was active */ +unlock_rsb (r); +put_rsb (r); - r->res_master_nodeid = from_nodeid; - r->res_nodeid = from_nodeid; -rsb_set_flag (r,RSB_NEW_MASTER ); +return 0 ; } -if (!r->res_master_nodeid) { -/* this will happen if recovery happens while we're looking -up the master for this rsb */ - -log_debug (ls,"dlm_master_lookup master 0 to %d first %x %s" , - from_nodeid, r->res_first_lkid, r->res_name); - r->res_master_nodeid = from_nodeid; - r->res_nodeid = from_nodeid; - } + error =dlm_search_rsb_tree (&ls->ls_rsbtbl[b].toss, name, len, &r); +if (error) + goto not_found; -if (!from_master && !fix_master && - (r->res_master_nodeid == from_nodeid)) { -/* this can happen when the master sends remove, the dir node -finds the rsb on the keep list and ignores the remove, -and the former master sends a lookup */ +/* because the rsb is inactive (on toss list), it's not refcounted +* and lock_rsb is not used, but is protected by the rsbtbl lock +*/ -log_limit (ls,"dlm_master_lookup from master %d flags %x " -"first %x %s" , from_nodeid, flags, - r->res_first_lkid, r->res_name); - } +__dlm_master_lookup (ls, r, our_nodeid, from_nodeid, true, flags, + r_nodeid, result); - out_found: - *r_nodeid = r->res_master_nodeid; -if (result) - *result =DLM_LU_MATCH ; + r->res_toss_time = jiffies; +/* the rsb was inactive (on toss list) */ +spin_unlock (&ls->ls_rsbtbl[b].lock); -if (toss_list) { - r->res_toss_time = jiffies; -/* the rsb was inactive (on toss list) */ -spin_unlock (&ls->ls_rsbtbl[b].lock); - }else { -/* the rsb was active */ -unlock_rsb (r); -put_rsb (r); - }return 0 ; not_found:
Signature · 1 line
2.31.1