fs: dlm: resend patches for v5.18-rc1
Alexander Aring
maintainercover fs: dlm: resend patches for v5.18-rc1
Hi all,
this is a resend of all pending patches for dlm/next based on v5.18-rc1. I removed some pending traces patches, I working on a dlm state viewer and currently I need to figure out the needs for tracing.
- Alex
Alexander Aring (18):
fs: dlm: fix missing check in validate_lock_args
fs: dlm: fix plock invalid read
fs: dlm: replace sanity checks with WARN_ON
fs: dlm: cleanup plock_op vs plock_xop
fs: dlm: rearrange async condition return
fs: dlm: improve plock logging if interrupted
fs: dlm: remove unnecessary INIT_LIST_HEAD()
fs: dlm: move global to static inits
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: check required context while close
Dan Carpenter (1):
fs: dlm: uninitialized variable on error in dlm_listen_for_all()
fs/dlm/dir.c | 2 +- fs/dlm/dlm_internal.h | 66 ++--- fs/dlm/lock.c | 548 ++++++++++++++++++++++-------------------- fs/dlm/lockspace.c | 12 + fs/dlm/lockspace.h | 1 + fs/dlm/lowcomms.c | 12 +- fs/dlm/member.c | 11 +- fs/dlm/midcomms.c | 61 +++-- fs/dlm/plock.c | 156 ++++++------ 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 +- 15 files changed, 546 insertions(+), 589 deletions(-)
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH RESEND 1/19 fs: dlm: uninitialized variable on error in dlm_listen_for_all()
From: Dan Carpenter <[email protected]>
The "sock" variable is not initialized on this error path.
--- fs/dlm/lowcomms.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/dlm/lowcomms.c +1 -1
@@ -1789,7 +1789,7 @@ static int dlm_listen_for_all(void) SOCK_STREAM, dlm_proto_ops->proto, &sock);if (result <0 ) {log_print ("Can't create comms socket: %d" , result); - goto out; +return result; }sock_set_mark (sock->sk, dlm_config.ci_mark);
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH RESEND 2/19 fs: dlm: fix missing check in validate_lock_args
In reply to Alexander AringThis patch adds a additional check if lkb->lkb_wait_count is non zero as it is done in validate_unlock_args() to check if any operation is in progress. While on it add a comment taken from validate_unlock_args() to signal what the check is doing.
There might be no changes because if lkb->lkb_wait_type is non zero implies that lkb->lkb_wait_count is non zero. However we should add the check as it does validate_unlock_args().
--- fs/dlm/lock.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/dlm/lock.c +2 -1
@@ -2912,7 +2912,8 @@ static int validate_lock_args(struct dlm_ls *ls, struct dlm_lkb *lkb,if (lkb->lkb_status !=DLM_LKSTS_GRANTED ) goto out; -if (lkb->lkb_wait_type) +/* lock not allowed if there's any op in progress */ +if (lkb->lkb_wait_type || lkb->lkb_wait_count) goto out;if (is_overlap (lkb))
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH RESEND 3/19 fs: dlm: fix plock invalid read
In reply to Alexander AringThis patch fixes an invalid read showed by KASAN. A unlock will allocate a "struct plock_op" and a followed send_op() will append it to a global send_list data structure. In some cases a followed dev_read() moves it to recv_list and dev_write() will cast it to "struct plock_xop" and access fields which are only available in those structures. At this point an invalid read happens by accessing those fields.
To fix this issue the "callback" field is moved to "struct plock_op" to indicate that a cast to "plock_xop" is allowed and does the additional "plock_xop" handling if set.
Example of the KASAN output which showed the invalid read:
[ 2064.296453] ================================================================== [ 2064.304852] BUG: KASAN: slab-out-of-bounds in dev_write+0x52b/0x5a0 [dlm] [ 2064.306491] Read of size 8 at addr ffff88800ef227d8 by task dlm_controld/7484 [ 2064.308168] [ 2064.308575] CPU: 0 PID: 7484 Comm: dlm_controld Kdump: loaded Not tainted 5.14.0+ #9 [ 2064.310292] Hardware name: Red Hat KVM, BIOS 0.5.1 01/01/2011 [ 2064.311618] Call Trace: [ 2064.312218] dump_stack_lvl+0x56/0x7b [ 2064.313150] print_address_description.constprop.8+0x21/0x150 [ 2064.314578] ? dev_write+0x52b/0x5a0 [dlm] [ 2064.315610] ? dev_write+0x52b/0x5a0 [dlm] [ 2064.316595] kasan_report.cold.14+0x7f/0x11b [ 2064.317674] ? dev_write+0x52b/0x5a0 [dlm] [ 2064.318687] dev_write+0x52b/0x5a0 [dlm] [ 2064.319629] ? dev_read+0x4a0/0x4a0 [dlm] [ 2064.320713] ? bpf_lsm_kernfs_init_security+0x10/0x10 [ 2064.321926] vfs_write+0x17e/0x930 [ 2064.322769] ? __fget_light+0x1aa/0x220 [ 2064.323753] ksys_write+0xf1/0x1c0 [ 2064.324548] ? __ia32_sys_read+0xb0/0xb0 [ 2064.325464] do_syscall_64+0x3a/0x80 [ 2064.326387] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 2064.327606] RIP: 0033:0x7f807e4ba96f [ 2064.328470] Code: 89 54 24 18 48 89 74 24 10 89 7c 24 08 e8 39 87 f8 ff 48 8b 54 24 18 48 8b 74 24 10 41 89 c0 8b 7c 24 08 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 31 44 89 c7 48 89 44 24 08 e8 7c 87 f8 ff 48 [ 2064.332902] RSP: 002b:00007ffd50cfe6e0 EFLAGS: 00000293 ORIG_RAX: 0000000000000001 [ 2064.334658] RAX: ffffffffffffffda RBX: 000055cc3886eb30 RCX: 00007f807e4ba96f [ 2064.336275] RDX: 0000000000000040 RSI: 00007ffd50cfe7e0 RDI: 0000000000000010 [ 2064.337980] RBP: 00007ffd50cfe7e0 R08: 0000000000000000 R09: 0000000000000001 [ 2064.339560] R10: 000055cc3886eb30 R11: 0000000000000293 R12: 000055cc3886eb80 [ 2064.341237] R13: 000055cc3886eb00 R14: 000055cc3886f590 R15: 0000000000000001 [ 2064.342857] [ 2064.343226] Allocated by task 12438: [ 2064.344057] kasan_save_stack+0x1c/0x40 [ 2064.345079] __kasan_kmalloc+0x84/0xa0 [ 2064.345933] kmem_cache_alloc_trace+0x13b/0x220 [ 2064.346953] dlm_posix_unlock+0xec/0x720 [dlm] [ 2064.348811] do_lock_file_wait.part.32+0xca/0x1d0 [ 2064.351070] fcntl_setlk+0x281/0xbc0 [ 2064.352879] do_fcntl+0x5e4/0xfe0 [ 2064.354657] __x64_sys_fcntl+0x11f/0x170 [ 2064.356550] do_syscall_64+0x3a/0x80 [ 2064.358259] entry_SYSCALL_64_after_hwframe+0x44/0xae [ 2064.360745] [ 2064.361511] Last potentially related work creation: [ 2064.363957] kasan_save_stack+0x1c/0x40 [ 2064.365811] __kasan_record_aux_stack+0xaf/0xc0 [ 2064.368100] call_rcu+0x11b/0xf70 [ 2064.369785] dlm_process_incoming_buffer+0x47d/0xfd0 [dlm] [ 2064.372404] receive_from_sock+0x290/0x770 [dlm] [ 2064.374607] process_recv_sockets+0x32/0x40 [dlm] [ 2064.377290] process_one_work+0x9a8/0x16e0 [ 2064.379357] worker_thread+0x87/0xbf0 [ 2064.381188] kthread+0x3ac/0x490 [ 2064.383460] ret_from_fork+0x22/0x30 [ 2064.385588] [ 2064.386518] Second to last potentially related work creation: [ 2064.389219] kasan_save_stack+0x1c/0x40 [ 2064.391043] __kasan_record_aux_stack+0xaf/0xc0 [ 2064.393303] call_rcu+0x11b/0xf70 [ 2064.394885] dlm_process_incoming_buffer+0x47d/0xfd0 [dlm] [ 2064.397694] receive_from_sock+0x290/0x770 [dlm] [ 2064.399932] process_recv_sockets+0x32/0x40 [dlm] [ 2064.402180] process_one_work+0x9a8/0x16e0 [ 2064.404388] worker_thread+0x87/0xbf0 [ 2064.406124] kthread+0x3ac/0x490 [ 2064.408021] ret_from_fork+0x22/0x30 [ 2064.409834] [ 2064.410599] The buggy address belongs to the object at ffff88800ef22780 [ 2064.410599] which belongs to the cache kmalloc-96 of size 96 [ 2064.416495] The buggy address is located 88 bytes inside of [ 2064.416495] 96-byte region [ffff88800ef22780, ffff88800ef227e0) [ 2064.422045] The buggy address belongs to the page: [ 2064.424635] page:00000000b6bef8bc refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0xef22 [ 2064.428970] flags: 0xfffffc0000200(slab|node=0|zone=1|lastcpupid=0x1fffff) [ 2064.432515] raw: 000fffffc0000200 ffffea0000d68b80 0000001400000014 ffff888001041780 [ 2064.436110] raw: 0000000000000000 0000000080200020 00000001ffffffff 0000000000000000 [ 2064.439813] page dumped because: kasan: bad access detected [ 2064.442548] [ 2064.443310] Memory state around the buggy address: [ 2064.445988] ffff88800ef22680: 00 00 00 00 00 00 00 00 00 00 00 00 fc fc fc fc [ 2064.449444] ffff88800ef22700: 00 00 00 00 00 00 00 00 00 00 00 00 fc fc fc fc [ 2064.452941] >ffff88800ef22780: 00 00 00 00 00 00 00 00 00 00 00 fc fc fc fc fc [ 2064.456383] ^ [ 2064.459386] ffff88800ef22800: 00 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc [ 2064.462788] ffff88800ef22880: 00 00 00 00 00 00 00 00 00 00 00 00 fc fc fc fc [ 2064.466239] ==================================================================
reproducer in python:
import argparse
import struct
import fcntl
import os
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--file',
help='file to use fcntl, must be on dlm lock filesystem e.g. gfs2')
args = parser.parse_args()
f = open(args.file, 'wb+')
lockdata = struct.pack('hhllhh', fcntl.F_WRLCK,0,0,0,0,0) fcntl.fcntl(f, fcntl.F_SETLK, lockdata)
lockdata = struct.pack('hhllhh', fcntl.F_UNLCK,0,0,0,0,0) fcntl.fcntl(f, fcntl.F_SETLK, lockdata)
--- fs/dlm/plock.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
fs/dlm/plock.c +5 -7
@@ -23,11 +23,11 @@ struct plock_op {struct list_head list;int done;struct dlm_plock_info info; +int (*callback)(struct file_lock *fl,int result); };struct plock_xop {struct plock_op xop; -int (*callback)(struct file_lock *fl,int result);void *fl;void *file;struct file_lock flc;
@@ -129,19 +129,18 @@ int dlm_posix_lock(dlm_lockspace_t *lockspace, u64 number, struct file *file,/* fl_owner is lockd which doesn't distinguish processes on the nfs client */ op->info.owner = (__u64 ) fl->fl_pid; - xop->callback = fl->fl_lmops->lm_grant; + op->callback = fl->fl_lmops->lm_grant;locks_init_lock (&xop->flc);locks_copy_lock (&xop->flc, fl); xop->fl = fl; xop->file = file; }else { op->info.owner = (__u64 )(long ) fl->fl_owner; - xop->callback =NULL ; }send_op (op); -if (xop->callback ==NULL ) { +if (!op->callback) { rv =wait_event_interruptible (recv_wq, (op->done !=0 ));if (rv == -ERESTARTSYS ) { log_debug(ls, "dlm_posix_lock: wait killed %llx",
@@ -203,7 +202,7 @@ static int dlm_plock_callback(struct plock_op *op) file = xop->file; flc = &xop->flc; fl = xop->fl; - notify = xop->callback; + notify = op->callback;if (op->info.rv) {notify (fl, op->info.rv);
@@ -436,10 +435,9 @@ static ssize_t dev_write(struct file *file, const char __user *u, size_t count,if (op->info.fsid == info.fsid && op->info.number == info.number && op->info.owner == info.owner) { -struct plock_xop *xop = (struct plock_xop *)op;list_del_init (&op->list);memcpy (&op->info, &info,sizeof (info)); -if (xop->callback) +if (op->callback) do_callback =1 ;else op->done =1 ;
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH RESEND 4/19 fs: dlm: replace sanity checks with WARN_ON
In reply to Alexander AringThere are several sanity checks and recover handling if they occur in the dlm plock handling. From my understanding those operation can't run in parallel with any list manipulation which involved setting the list holder of plock_op, if so we have a bug which this sanity check will warn about. Previously if such sanity check occurred the dlm plock handling was trying to recover from it by deleting the plock_op from a list which the holder was set to. However there is a bug in the dlm plock handling if this case ever happens. To make such bugs are more visible for further investigations we add a WARN_ON() on those sanity checks and remove the recovering handling because other possible side effects.
--- fs/dlm/plock.c | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-)
fs/dlm/plock.c +4 -28
@@ -157,13 +157,7 @@ int dlm_posix_lock(dlm_lockspace_t *lockspace, u64 number, struct file *file, goto out; } -spin_lock (&ops_lock); -if (!list_empty (&op->list)) { -log_error (ls,"dlm_posix_lock: op on list %llx" , - (unsigned long long )number); -list_del (&op->list); - } -spin_unlock (&ops_lock); +WARN_ON (!list_empty (&op->list)); rv = op->info.rv;
@@ -190,13 +184,7 @@ static int dlm_plock_callback(struct plock_op *op)struct plock_xop *xop = (struct plock_xop *)op;int rv =0 ; -spin_lock (&ops_lock); -if (!list_empty (&op->list)) { -log_print ("dlm_plock_callback: op on list %llx" , - (unsigned long long )op->info.number); -list_del (&op->list); - } -spin_unlock (&ops_lock); +WARN_ON (!list_empty (&op->list));/* check if the following 2 are still valid or make a copy */ file = xop->file;
@@ -289,13 +277,7 @@ int dlm_posix_unlock(dlm_lockspace_t *lockspace, u64 number, struct file *file,send_op (op);wait_event (recv_wq, (op->done !=0 )); -spin_lock (&ops_lock); -if (!list_empty (&op->list)) { -log_error (ls,"dlm_posix_unlock: op on list %llx" , - (unsigned long long )number); -list_del (&op->list); - } -spin_unlock (&ops_lock); +WARN_ON (!list_empty (&op->list)); rv = op->info.rv;
@@ -343,13 +325,7 @@ int dlm_posix_get(dlm_lockspace_t *lockspace, u64 number, struct file *file,send_op (op);wait_event (recv_wq, (op->done !=0 )); -spin_lock (&ops_lock); -if (!list_empty (&op->list)) { -log_error (ls,"dlm_posix_get: op on list %llx" , - (unsigned long long )number); -list_del (&op->list); - } -spin_unlock (&ops_lock); +WARN_ON (!list_empty (&op->list));/* info.rv from userspace is 1 for conflict, 0 for no-conflict, -ENOENT if there are no locks on the file */
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH RESEND 5/19 fs: dlm: cleanup plock_op vs plock_xop
In reply to Alexander AringLately the different casting between plock_op and plock_xop and list holders which was involved showed some issues which were hard to see. This patch removes the "plock_xop" structure and introduces a "struct plock_async_data". This structure will be set in "struct plock_op" in case of asynchronous lock handling as the original "plock_xop" was made for. There is no need anymore to cast pointers around for additional fields in case of asynchronous lock handling. As disadvantage another allocation was introduces but only needed in the asynchronous case which is currently only used in combination with nfs lockd.
--- fs/dlm/plock.c | 77 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 31 deletions(-)
fs/dlm/plock.c +46 -31
@@ -19,20 +19,20 @@ static struct list_head recv_list;static wait_queue_head_t send_wq;static wait_queue_head_t recv_wq; -struct plock_op { -struct list_head list; -int done; -struct dlm_plock_info info; -int (*callback)(struct file_lock *fl,int result); -}; - -struct plock_xop { -struct plock_op xop; +struct plock_async_data {void *fl;void *file;struct file_lock flc; +int (*callback)(struct file_lock *fl,int result); }; +struct plock_op { +struct list_head list; +int done; +struct dlm_plock_info info; +/* if set indicates async handling */ +struct plock_async_data *data; +};static inline void set_version (struct dlm_plock_info *info) {
@@ -58,6 +58,12 @@ static int check_version(struct dlm_plock_info *info)return 0 ; } +static void dlm_release_plock_op (struct plock_op *op) +{ +kfree (op->data); +kfree (op); +} +static void send_op (struct plock_op *op) {set_version (&op->info);
@@ -101,22 +107,21 @@ static void do_unlock_close(struct dlm_ls *ls, u64 number,int dlm_posix_lock (dlm_lockspace_t *lockspace,u64 number,struct file *file,int cmd,struct file_lock *fl) { +struct plock_async_data *op_data;struct dlm_ls *ls;struct plock_op *op; -struct plock_xop *xop;int rv; ls =dlm_find_lockspace_local (lockspace);if (!ls)return -EINVAL ; - xop =kzalloc (sizeof (*xop),GFP_NOFS ); -if (!xop) { + op =kzalloc (sizeof (*op),GFP_NOFS ); +if (!op) { rv = -ENOMEM ; goto out; } - op = &xop->xop; op->info.optype =DLM_PLOCK_OP_LOCK ; op->info.pid = fl->fl_pid; op->info.ex = (fl->fl_type ==F_WRLCK );
@@ -125,22 +130,32 @@ int dlm_posix_lock(dlm_lockspace_t *lockspace, u64 number, struct file *file, op->info.number = number; op->info.start = fl->fl_start; op->info.end = fl->fl_end; +/* async handling */ if (fl->fl_lmops && fl->fl_lmops->lm_grant) { + op_data =kzalloc (sizeof (*op_data),GFP_NOFS ); +if (!op_data) { +dlm_release_plock_op (op); + rv = -ENOMEM ; + goto out; + } +/* fl_owner is lockd which doesn't distinguish processes on the nfs client */ op->info.owner = (__u64 ) fl->fl_pid; - op->callback = fl->fl_lmops->lm_grant; -locks_init_lock (&xop->flc); -locks_copy_lock (&xop->flc, fl); - xop->fl = fl; - xop->file = file; + op_data->callback = fl->fl_lmops->lm_grant; +locks_init_lock (&op_data->flc); +locks_copy_lock (&op_data->flc, fl); + op_data->fl = fl; + op_data->file = file; + + op->data = op_data; }else { op->info.owner = (__u64 )(long ) fl->fl_owner; }send_op (op); -if (!op->callback) { +if (!op->data) { rv =wait_event_interruptible (recv_wq, (op->done !=0 ));if (rv == -ERESTARTSYS ) { log_debug(ls, "dlm_posix_lock: wait killed %llx",
@@ -148,7 +163,7 @@ int dlm_posix_lock(dlm_lockspace_t *lockspace, u64 number, struct file *file,spin_lock (&ops_lock);list_del (&op->list);spin_unlock (&ops_lock); -kfree (xop); +dlm_release_plock_op (op);do_unlock_close (ls, number, file, fl); goto out; }
@@ -167,7 +182,7 @@ int dlm_posix_lock(dlm_lockspace_t *lockspace, u64 number, struct file *file, (unsigned long long)number); } -kfree (xop); +dlm_release_plock_op (op); out:dlm_put_lockspace (ls);return rv;
@@ -177,20 +192,20 @@ EXPORT_SYMBOL_GPL(dlm_posix_lock);/* Returns failure iff a successful lock operation should be canceled */ static int dlm_plock_callback (struct plock_op *op) { +struct plock_async_data *op_data = op->data;struct file *file;struct file_lock *fl;struct file_lock *flc;int (*notify)(struct file_lock *fl,int result) =NULL ; -struct plock_xop *xop = (struct plock_xop *)op;int rv =0 ;WARN_ON (!list_empty (&op->list));/* check if the following 2 are still valid or make a copy */ - file = xop->file; - flc = &xop->flc; - fl = xop->fl; - notify = op->callback; + file = op_data->file; + flc = &op_data->flc; + fl = op_data->fl; + notify = op_data->callback;if (op->info.rv) {notify (fl, op->info.rv);
@@ -221,7 +236,7 @@ static int dlm_plock_callback(struct plock_op *op) } out: -kfree (xop); +dlm_release_plock_op (op);return rv; }
@@ -285,7 +300,7 @@ int dlm_posix_unlock(dlm_lockspace_t *lockspace, u64 number, struct file *file, rv =0 ; out_free: -kfree (op); +dlm_release_plock_op (op); out:dlm_put_lockspace (ls); fl->fl_flags = fl_flags;
@@ -345,7 +360,7 @@ int dlm_posix_get(dlm_lockspace_t *lockspace, u64 number, struct file *file, rv =0 ; } -kfree (op); +dlm_release_plock_op (op); out:dlm_put_lockspace (ls);return rv;
@@ -381,7 +396,7 @@ static ssize_t dev_read(struct file *file, char __user *u, size_t count,(the process did not make an unlock call). */ if (op->info.flags &DLM_PLOCK_FL_CLOSE ) -kfree (op); +dlm_release_plock_op (op);if (copy_to_user (u, &info,sizeof (info)))return -EFAULT ;
@@ -413,7 +428,7 @@ static ssize_t dev_write(struct file *file, const char __user *u, size_t count, op->info.owner == info.owner) {list_del_init (&op->list);memcpy (&op->info, &info,sizeof (info)); -if (op->callback) +if (op->data) do_callback =1 ;else op->done =1 ;
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH RESEND 6/19 fs: dlm: rearrange async condition return
In reply to Alexander AringThis patch moves the return of FILE_LOCK_DEFERRED a little bit earlier than checking afterwards again if the request was an asynchronous request.
--- fs/dlm/plock.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-)
fs/dlm/plock.c +13 -14
@@ -149,26 +149,25 @@ int dlm_posix_lock(dlm_lockspace_t *lockspace, u64 number, struct file *file, op_data->file = file; op->data = op_data; + +send_op (op); + rv =FILE_LOCK_DEFERRED ; + goto out; }else { op->info.owner = (__u64 )(long ) fl->fl_owner; }send_op (op); -if (!op->data) { - rv =wait_event_interruptible (recv_wq, (op->done !=0 )); -if (rv == -ERESTARTSYS ) { -log_debug (ls,"dlm_posix_lock: wait killed %llx" , - (unsigned long long )number); -spin_lock (&ops_lock); -list_del (&op->list); -spin_unlock (&ops_lock); -dlm_release_plock_op (op); -do_unlock_close (ls, number, file, fl); - goto out; - } - }else { - rv =FILE_LOCK_DEFERRED ; + rv =wait_event_interruptible (recv_wq, (op->done !=0 )); +if (rv == -ERESTARTSYS ) { +log_debug (ls,"%s: wait killed %llx" , __func__, + (unsigned long long )number); +spin_lock (&ops_lock); +list_del (&op->list); +spin_unlock (&ops_lock); +dlm_release_plock_op (op); +do_unlock_close (ls, number, file, fl); goto out; }
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH RESEND 7/19 fs: dlm: improve plock logging if interrupted
In reply to Alexander AringThis patch changes the log level if a plock is removed when interrupted from debug to info. Additional it signals now that the plock entity was removed to let the user know what's happening.
If on a dev_write() a pending plock cannot be find it will signal that it might have been removed because wait interruption.
Before this patch there might be a "dev_write no op ..." info message and the users can only guess that the plock was removed before because the wait interruption. To be sure that is the case we log both messages on the same log level.
Let both message be logged on info layer because it should not happened a lot and if it happens it should be clear why the op was not found.
--- fs/dlm/plock.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/dlm/plock.c +5 -4
@@ -161,11 +161,12 @@ int dlm_posix_lock(dlm_lockspace_t *lockspace, u64 number, struct file *file, rv =wait_event_interruptible (recv_wq, (op->done !=0 ));if (rv == -ERESTARTSYS ) { -log_debug (ls,"%s: wait killed %llx" , __func__, - (unsigned long long )number);spin_lock (&ops_lock);list_del (&op->list);spin_unlock (&ops_lock); +log_print ("%s: wait interrupted %x %llx, op removed" , + __func__, ls->ls_global_id, + (unsigned long long )number);dlm_release_plock_op (op);do_unlock_close (ls, number, file, fl); goto out;
@@ -443,8 +444,8 @@ static ssize_t dev_write(struct file *file, const char __user *u, size_t count,else wake_up (&recv_wq); }else -log_print ("dev_write no op %x %llx" , info.fsid, - (unsigned long long )info.number); +log_print ("%s: no op %x %llx - may got interrupted?" , __func__, + info.fsid, (unsigned long long )info.number);return count; }
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH RESEND 8/19 fs: dlm: remove unnecessary INIT_LIST_HEAD()
In reply to Alexander AringThere is no need to call INIT_LIST_HEAD() when it's set directly afterwards by list_add_tail().
--- fs/dlm/plock.c | 1 - 1 file changed, 1 deletion(-)
fs/dlm/plock.c +0 -1
@@ -67,7 +67,6 @@ static void dlm_release_plock_op(struct plock_op *op)static void send_op (struct plock_op *op) {set_version (&op->info); -INIT_LIST_HEAD (&op->list);spin_lock (&ops_lock);list_add_tail (&op->list, &send_list);spin_unlock (&ops_lock);
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH RESEND 9/19 fs: dlm: move global to static inits
In reply to Alexander AringInstead of init global module at module loading time we can move the initialization of those global variables at memory initialization of the module loader.
--- fs/dlm/plock.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)
fs/dlm/plock.c +5 -11
@@ -13,11 +13,11 @@#include "dlm_internal.h" #include "lockspace.h" -static spinlock_t ops_lock; -static struct list_head send_list; -static struct list_head recv_list; -static wait_queue_head_t send_wq; -static wait_queue_head_t recv_wq; +static DEFINE_SPINLOCK (ops_lock); +static LIST_HEAD (send_list); +static LIST_HEAD (recv_list); +static DECLARE_WAIT_QUEUE_HEAD (send_wq); +static DECLARE_WAIT_QUEUE_HEAD (recv_wq);struct plock_async_data {void *fl;
@@ -480,12 +480,6 @@ int dlm_plock_init(void) {int rv; -spin_lock_init (&ops_lock); -INIT_LIST_HEAD (&send_list); -INIT_LIST_HEAD (&recv_list); -init_waitqueue_head (&send_wq); -init_waitqueue_head (&recv_wq); - rv =misc_register (&plock_dev_misc);if (rv)log_print ("dlm_plock_init: misc_register failed %d" , rv);
Signature · 1 line
2.31.1
Alexander Aring
maintainerPATCH RESEND 10/19 fs: dlm: add __CHECKER__ for false positives
In reply to Alexander AringThis 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 RESEND 11/19 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 RESEND 12/19 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 RESEND 13/19 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
@@ -5062,8 +5062,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 RESEND 14/19 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 RESEND 15/19 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 RESEND 16/19 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 RESEND 17/19 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 RESEND 18/19 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
Alexander Aring
maintainerPATCH RESEND 19/19 fs: dlm: check required context while close
In reply to Alexander AringThis patch adds a WARN_ON() check to validate the right context while dlm_midcomms_close() is called. Even before commit 489d8e559c65 ("fs: dlm: add reliable connection if reconnect") in this context dlm_lowcomms_close() flushes all ongoing transmission triggered by dlm application stack. If we do that, it's required that no new message will be triggered by the dlm application stack. The function dlm_midcomms_close() is not called often so we can check if all lockspaces are in such context.
--- fs/dlm/lockspace.c | 12 ++++++++++++ fs/dlm/lockspace.h | 1 + fs/dlm/midcomms.c | 3 +++ 3 files changed, 16 insertions(+)
fs/dlm/lockspace.c +12 -0
@@ -922,3 +922,15 @@ void dlm_stop_lockspaces(void)log_print ("dlm user daemon left %d lockspaces" , count); } +void dlm_stop_lockspaces_check (void ) +{ +struct dlm_ls *ls; + +spin_lock (&lslist_lock); +list_for_each_entry (ls, &lslist, ls_list) { +if (WARN_ON (!rwsem_is_locked (&ls->ls_in_recovery) || + !dlm_locking_stopped (ls))) +break ; + } +spin_unlock (&lslist_lock); +}
fs/dlm/lockspace.h +1 -0
@@ -19,6 +19,7 @@ struct dlm_ls *dlm_find_lockspace_local(void *id);struct dlm_ls *dlm_find_lockspace_device (int minor);void dlm_put_lockspace (struct dlm_ls *ls);void dlm_stop_lockspaces (void ); +void dlm_stop_lockspaces_check (void );#endif /* __LOCKSPACE_DOT_H__ */
fs/dlm/midcomms.c +3 -0
@@ -135,6 +135,7 @@#include <net/tcp.h> #include "dlm_internal.h" +#include "lockspace.h" #include "lowcomms.h" #include "config.h" #include "memory.h"
@@ -1412,6 +1413,8 @@ int dlm_midcomms_close(int nodeid)if (nodeid ==dlm_our_nodeid ())return 0 ; +dlm_stop_lockspaces_check (); + idx =srcu_read_lock (&nodes_srcu);/* Abort pending close/remove operation */ node =nodeid2node (nodeid,0 );
Signature · 1 line
2.31.1