dlm: use bool for coniditonal expressions
Alexander Aring
maintainerPATCH 1/2 dlm: use bool for coniditonal expressions
This patch changes the return value of functions instead of using int and their corresponding value 1/0 for true/false. Instead we use the predefined true/false definitions.
Signed-off-by Alexander Aring <[email protected]>
--- fs/dlm/dlm_internal.h | 2 +- fs/dlm/lock.c | 151 +++++++++++++++++++++--------------------- fs/dlm/lowcomms.c | 16 ++--- fs/dlm/member.c | 18 ++--- fs/dlm/member.h | 6 +- fs/dlm/requestqueue.c | 12 ++-- fs/dlm/user.c | 16 ++--- fs/dlm/user.h | 2 +- 8 files changed, 111 insertions(+), 112 deletions(-)
fs/dlm/dlm_internal.h +1 -1
@@ -381,7 +381,7 @@ static inline void rsb_clear_flag(struct dlm_rsb *r, enum rsb_flags flag)__clear_bit (flag, &r->res_flags); } -static inline int rsb_flag (struct dlm_rsb *r,enum rsb_flags flag) +static inline bool rsb_flag (struct dlm_rsb *r,enum rsb_flags flag) {return test_bit (flag, &r->res_flags); }
fs/dlm/lock.c +75 -76
423 lines not on this page · raw message
fs/dlm/lowcomms.c +8 -8
@@ -331,32 +331,32 @@ static struct connection *nodeid2con(int nodeid, gfp_t alloc)return con; } -static int addr_compare (const struct sockaddr_storage *x, -const struct sockaddr_storage *y) +static bool addr_compare (const struct sockaddr_storage *x, +const struct sockaddr_storage *y) {switch (x->ss_family) {case AF_INET : {struct sockaddr_in *sinx = (struct sockaddr_in *)x;struct sockaddr_in *siny = (struct sockaddr_in *)y;if (sinx->sin_addr.s_addr != siny->sin_addr.s_addr) -return 0 ; +return false;if (sinx->sin_port != siny->sin_port) -return 0 ; +return false;break ; }case AF_INET6 : {struct sockaddr_in6 *sinx = (struct sockaddr_in6 *)x;struct sockaddr_in6 *siny = (struct sockaddr_in6 *)y;if (!ipv6_addr_equal (&sinx->sin6_addr, &siny->sin6_addr)) -return 0 ; +return false;if (sinx->sin6_port != siny->sin6_port) -return 0 ; +return false;break ; }default : -return 0 ; +return false; } -return 1 ; +return true; } static int nodeid_to_addr(int nodeid, struct sockaddr_storage *sas_out,
fs/dlm/member.c +9 -9
@@ -18,11 +18,11 @@#include "midcomms.h" #include "lowcomms.h" -int dlm_slots_version (const struct dlm_header *h) +bool dlm_slots_version (const struct dlm_header *h) {if ((le32_to_cpu (h->h_version) &0x0000FFFF ) <DLM_HEADER_SLOTS ) -return 0 ; -return 1 ; +return false; +return true; } void dlm_slot_save(struct dlm_ls *ls, struct dlm_rcom *rc,
@@ -357,20 +357,20 @@ static struct dlm_member *find_memb(struct list_head *head, int nodeid)return NULL ; } -int dlm_is_member (struct dlm_ls *ls,int nodeid) +bool dlm_is_member (struct dlm_ls *ls,int nodeid) {if (find_memb (&ls->ls_nodes, nodeid)) -return 1 ; -return 0 ; +return true; +return false; } -int dlm_is_removed (struct dlm_ls *ls,int nodeid) +bool dlm_is_removed (struct dlm_ls *ls,int nodeid) {WARN_ON_ONCE (!nodeid || nodeid ==-1 );if (find_memb (&ls->ls_nodes_gone, nodeid)) -return 1 ; -return 0 ; +return true; +return false; } static void clear_memb_list(struct list_head *head,
fs/dlm/member.h +3 -3
@@ -16,9 +16,9 @@ int dlm_ls_start(struct dlm_ls *ls);void dlm_clear_members (struct dlm_ls *ls);void dlm_clear_members_gone (struct dlm_ls *ls);int dlm_recover_members (struct dlm_ls *ls,struct dlm_recover *rv,int *neg_out); -int dlm_is_removed (struct dlm_ls *ls,int nodeid); -int dlm_is_member (struct dlm_ls *ls,int nodeid); -int dlm_slots_version (const struct dlm_header *h); +bool dlm_is_removed (struct dlm_ls *ls,int nodeid); +bool dlm_is_member (struct dlm_ls *ls,int nodeid); +bool dlm_slots_version (const struct dlm_header *h);void dlm_slot_save (struct dlm_ls *ls,struct dlm_rcom *rc,struct dlm_member *memb);void dlm_slots_copy_out (struct dlm_ls *ls,struct dlm_rcom *rc);
fs/dlm/requestqueue.c +6 -6
@@ -105,16 +105,16 @@ int dlm_process_requestqueue(struct dlm_ls *ls)return error; } -static int purge_request (struct dlm_ls *ls,struct dlm_message *ms,int nodeid) +static bool purge_request (struct dlm_ls *ls,struct dlm_message *ms,int nodeid) {__le32 type = ms->m_type;/* the ls is being cleaned up and freed by release_lockspace */ if (!atomic_read (&ls->ls_count)) -return 1 ; +return true;if (dlm_is_removed (ls, nodeid)) -return 1 ; +return true;/* directory operations are always purged because the directory is always rebuilt during recovery and the lookups resent */
@@ -122,12 +122,12 @@ static int purge_request(struct dlm_ls *ls, struct dlm_message *ms, int nodeid)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 ; +return true;if (!dlm_no_directory (ls)) -return 0 ; +return false; -return 1 ; +return true; }void dlm_purge_requestqueue (struct dlm_ls *ls)
fs/dlm/user.c +8 -8
@@ -156,20 +156,20 @@ static void compat_output(struct dlm_lock_result *res,not related to the lifetime of the lkb struct which is managed entirely by refcount. */ -static int lkb_is_endoflife (int mode,int status) +static bool lkb_is_endoflife (int mode,int status) {switch (status) {case -DLM_EUNLOCK : -return 1 ; +return true;case -DLM_ECANCEL :case -ETIMEDOUT :case -EDEADLK :case -EAGAIN :if (mode ==DLM_LOCK_IV ) -return 1 ; +return true;break ; } -return 0 ; +return false; }/* we could possibly check if the cancel of an orphan has resulted in the lkb
@@ -877,13 +877,13 @@ static __poll_t device_poll(struct file *file, poll_table *wait)return 0 ; } -int dlm_user_daemon_available (void ) +bool dlm_user_daemon_available (void ) {/* dlm_controld hasn't started (or, has started, but not properly populated configfs) */ if (!dlm_our_nodeid ()) -return 0 ; +return false;/* This is to deal with versions of dlm_controld that don't know about the monitor device. We assume that if the
@@ -892,9 +892,9 @@ int dlm_user_daemon_available(void)should open the monitor device before populating configfs. */ if (dlm_monitor_unused) -return 1 ; +return true; -return atomic_read (&dlm_monitor_opened) ?1 :0 ; +return !!atomic_read (&dlm_monitor_opened); }static int ctl_device_open (struct inode *inode,struct file *file)
fs/dlm/user.h +1 -1
@@ -12,6 +12,6 @@ void dlm_user_add_ast(struct dlm_lkb *lkb, uint32_t flags, int mode,int dlm_user_init (void );void dlm_user_exit (void );int dlm_device_deregister (struct dlm_ls *ls); -int dlm_user_daemon_available (void ); +bool dlm_user_daemon_available (void );#endif
Signature · 1 line
2.43.0
Alexander Aring
maintainerPATCH 2/2 dlm: use coniditon expression instead return scalars
Removes the condition and the scalar returns, instead we return directly the boolean expression.
Signed-off-by Alexander Aring <[email protected]>
--- fs/dlm/lock.c | 47 ++++++++++++------------------------------- fs/dlm/member.c | 12 +++-------- fs/dlm/requestqueue.c | 5 +---- 3 files changed, 17 insertions(+), 47 deletions(-)
fs/dlm/lock.c +13 -34
@@ -260,10 +260,8 @@ static inline bool is_master_copy(struct dlm_lkb *lkb)static inline bool middle_conversion (struct dlm_lkb *lkb) { -if ((lkb->lkb_grmode==DLM_LOCK_PR && lkb->lkb_rqmode==DLM_LOCK_CW ) || - (lkb->lkb_rqmode==DLM_LOCK_PR && lkb->lkb_grmode==DLM_LOCK_CW )) -return true; -return false; +return ((lkb->lkb_grmode ==DLM_LOCK_PR && lkb->lkb_rqmode ==DLM_LOCK_CW ) || + (lkb->lkb_rqmode ==DLM_LOCK_PR && lkb->lkb_grmode ==DLM_LOCK_CW )); }static inline bool down_conversion (struct dlm_lkb *lkb)
@@ -2139,10 +2137,7 @@ static inline bool first_in_list(struct dlm_lkb *lkb, struct list_head *head) { struct dlm_lkb *first = list_entry(head->next, struct dlm_lkb, lkb_statequeue); -if (lkb->lkb_id == first->lkb_id) -return true; - -return false; +return (lkb->lkb_id == first->lkb_id); }/* Check if the given lkb conflicts with another lkb on the queue. */
@@ -2379,11 +2374,8 @@ static bool _can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, bool now,* of the most restrictive lock granted on the resource. */ -if (!now && !conv &&list_empty (&r->res_convertqueue) && -first_in_list (lkb, &r->res_waitqueue)) -return true; - -return false; +return (!now && !conv &&list_empty (&r->res_convertqueue) && +first_in_list (lkb, &r->res_waitqueue)); } static bool can_be_granted(struct dlm_rsb *r, struct dlm_lkb *lkb, bool now,
@@ -2543,16 +2535,11 @@ static int grant_pending_wait(struct dlm_rsb *r, int high, bool *cw,static bool lock_requires_bast (struct dlm_lkb *gr,int high,bool cw) { -if (gr->lkb_grmode ==DLM_LOCK_PR && cw) { -if (gr->lkb_highbast <DLM_LOCK_EX ) -return true; -return false; - } +if (gr->lkb_grmode ==DLM_LOCK_PR && cw) +return (gr->lkb_highbast <DLM_LOCK_EX ); -if (gr->lkb_highbast < high && - !__dlm_compat_matrix[gr->lkb_grmode+1 ][high+1 ]) -return true; -return false; +return (gr->lkb_highbast < high && + !__dlm_compat_matrix[gr->lkb_grmode+1 ][high+1 ]); }static void grant_pending_locks (struct dlm_rsb *r,unsigned int *count)
@@ -2594,15 +2581,10 @@ static void grant_pending_locks(struct dlm_rsb *r, unsigned int *count)static int modes_require_bast (struct dlm_lkb *gr,struct dlm_lkb *rq) {if ((gr->lkb_grmode ==DLM_LOCK_PR && rq->lkb_rqmode ==DLM_LOCK_CW ) || - (gr->lkb_grmode ==DLM_LOCK_CW && rq->lkb_rqmode ==DLM_LOCK_PR )) { -if (gr->lkb_highbast <DLM_LOCK_EX ) -return true; -return false; - } + (gr->lkb_grmode ==DLM_LOCK_CW && rq->lkb_rqmode ==DLM_LOCK_PR )) +return (gr->lkb_highbast <DLM_LOCK_EX ); -if (gr->lkb_highbast < rq->lkb_rqmode && !modes_compat (gr, rq)) -return true; -return false; +return (gr->lkb_highbast < rq->lkb_rqmode && !modes_compat (gr, rq)); } static void send_bast_queue(struct dlm_rsb *r, struct list_head *head,
@@ -5029,10 +5011,7 @@ static bool waiter_needs_recovery(struct dlm_ls *ls, struct dlm_lkb *lkb,if (dlm_no_directory (ls))return true; -if (dlm_is_removed (ls, lkb->lkb_wait_nodeid)) -return true; - -return false; +return dlm_is_removed (ls, lkb->lkb_wait_nodeid); }/* Recovery for locks that are waiting for replies from nodes that are now
fs/dlm/member.c +3 -9
@@ -20,9 +20,7 @@bool dlm_slots_version (const struct dlm_header *h) { -if ((le32_to_cpu (h->h_version) &0x0000FFFF ) <DLM_HEADER_SLOTS ) -return false; -return true; +return !((le32_to_cpu (h->h_version) &0x0000FFFF ) <DLM_HEADER_SLOTS ); } void dlm_slot_save(struct dlm_ls *ls, struct dlm_rcom *rc,
@@ -359,18 +357,14 @@ static struct dlm_member *find_memb(struct list_head *head, int nodeid)bool dlm_is_member (struct dlm_ls *ls,int nodeid) { -if (find_memb (&ls->ls_nodes, nodeid)) -return true; -return false; +return !!find_memb (&ls->ls_nodes, nodeid); }bool dlm_is_removed (struct dlm_ls *ls,int nodeid) {WARN_ON_ONCE (!nodeid || nodeid ==-1 ); -if (find_memb (&ls->ls_nodes_gone, nodeid)) -return true; -return false; +return !!find_memb (&ls->ls_nodes_gone, nodeid); } static void clear_memb_list(struct list_head *head,
fs/dlm/requestqueue.c +1 -4
@@ -124,10 +124,7 @@ static bool purge_request(struct dlm_ls *ls, struct dlm_message *ms, int nodeid) type == cpu_to_le32(DLM_MSG_LOOKUP_REPLY))return true; -if (!dlm_no_directory (ls)) -return false; - -return true; +return dlm_no_directory (ls); }void dlm_purge_requestqueue (struct dlm_ls *ls)
Signature · 1 line
2.43.0