GFS2: The DLM interface module
PATCH 14/16 GFS2: The DLM interface module
[PATCH 14/16] GFS2: The DLM interface module
The interface between GFS2 and the DLM. This is the bit which is actually part of GFS2.
fs/gfs2/locking/dlm/Makefile | 3 fs/gfs2/locking/dlm/lock.c | 541 +++++++++++++++++++++++++++++++++++++++++ fs/gfs2/locking/dlm/lock_dlm.h | 188 ++++++++++++++ fs/gfs2/locking/dlm/main.c | 64 ++++ fs/gfs2/locking/dlm/mount.c | 256 +++++++++++++++++++ fs/gfs2/locking/dlm/plock.c | 302 ++++++++++++++++++++++ fs/gfs2/locking/dlm/sysfs.c | 225 +++++++++++++++++ fs/gfs2/locking/dlm/thread.c | 359 +++++++++++++++++++++++++++ include/linux/lock_dlm_plock.h | 41 +++ 9 files changed, 1979 insertions(+)
fs/gfs2/locking/dlm/main.c new file +64 -0
@@ -0,0 +1,64 @@ +/* +* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. +* Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved. +* +* This copyrighted material is made available to anyone wishing to use, +* modify, copy, or redistribute it subject to the terms and conditions +* of the GNU General Public License v.2. +*/ + +#include <linux/init.h> + +#include "lock_dlm.h" + +extern int gdlm_drop_count; +extern int gdlm_drop_period; + +extern struct lm_lockops gdlm_ops; + +static int __init init_lock_dlm (void ) +{ +int error; + + error =gfs2_register_lockproto (&gdlm_ops); +if (error) { +printk (KERN_WARNING "lock_dlm: can't register protocol: %d\n" , + error); +return error; + } + + error =gdlm_sysfs_init (); +if (error) { +gfs2_unregister_lockproto (&gdlm_ops); +return error; + } + + error =gdlm_plock_init (); +if (error) { +gdlm_sysfs_exit (); +gfs2_unregister_lockproto (&gdlm_ops); +return error; + } + + gdlm_drop_count =GDLM_DROP_COUNT ; + gdlm_drop_period =GDLM_DROP_PERIOD ; + +printk (KERN_INFO +"Lock_DLM (built %s %s) installed\n" , __DATE__, __TIME__); +return 0 ; +} + +static void __exit exit_lock_dlm(void) +{ +gdlm_plock_exit (); +gdlm_sysfs_exit (); +gfs2_unregister_lockproto (&gdlm_ops); +} + +module_init (init_lock_dlm); +module_exit (exit_lock_dlm); + +MODULE_DESCRIPTION ("GFS DLM Locking Module" ); +MODULE_AUTHOR ("Red Hat, Inc." ); +MODULE_LICENSE ("GPL" ); +
fs/gfs2/locking/dlm/lock.c new file +541 -0
541 lines not on this page · raw message
fs/gfs2/locking/dlm/mount.c new file +256 -0
256 lines not on this page · raw message
fs/gfs2/locking/dlm/plock.c new file +302 -0
302 lines not on this page · raw message
fs/gfs2/locking/dlm/sysfs.c new file +225 -0
225 lines not on this page · raw message
fs/gfs2/locking/dlm/thread.c new file +359 -0
359 lines not on this page · raw message
fs/gfs2/locking/dlm/lock_dlm.h new file +188 -0
188 lines not on this page · raw message
fs/gfs2/locking/dlm/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_GFS2_FS) += lock_dlm.o +lock_dlm-y := lock.o main.o mount.o sysfs.o thread.o plock.o +
include/linux/lock_dlm_plock.h new file +41 -0
41 lines not on this page · raw message
fs/gfs2/locking/dlm/lock.c line 158
Quoted 8 lines
fs/gfs2/locking/dlm/lock.c new file +7
-0+/* make_strname - convert GFS lock numbers to a string */ + +static inline void make_strname (struct lm_lockname *lockname, +struct gdlm_strname *str) +{ +sprintf (str->name,"%8x%16llx" , lockname->ln_type, + (unsigned long long )lockname->ln_number);
Is this format specifier safe enough? "%08x%016llx" perhaps?
Imagine (if this happens at all):
ln_type = 1; ln_number = 16; %8x = "1", "%16llx" = "10", giving us "110"
ln_type = 17; ln_number = 0;
%8x = "11", "%16llx" = "0", giving us "110".
Whoops, name clash.
fs/gfs2/locking/dlm/lock.c line 218
Quoted 9 lines
fs/gfs2/locking/dlm/lock.c new file +9
-0+int gdlm_get_lock (lm_lockspace_t *lockspace,struct lm_lockname *name, +lm_lock_t **lockp) +{ +struct gdlm_lock *lp; +int error; + + error =gdlm_create_lp ((struct gdlm_ls *) lockspace, name, &lp); + + *lockp = (lm_lock_t *) lp;
This cast is alright in itself. Considering however that lm_lock_t is currently typedef'ed to void, it looks a little different. (One _could_ get rid of it, but better not while it is called lm_lock_t. Leave as-is for now.)
Quoted 53 lines
fs/gfs2/locking/dlm/plock.c new file +53
-0+static wait_queue_head_t send_wq; +static wait_queue_head_t recv_wq; + +struct plock_op { +struct list_head list; +int done; +struct gdlm_plock_info info; +}; + +static inline void set_version (struct gdlm_plock_info *info) +{ + info->version[0 ] =GDLM_PLOCK_VERSION_MAJOR ; + info->version[1 ] =GDLM_PLOCK_VERSION_MINOR ; + info->version[2 ] =GDLM_PLOCK_VERSION_PATCH ; +} + +static int check_version (struct gdlm_plock_info *info) +{ +if ((GDLM_PLOCK_VERSION_MAJOR != info->version[0 ]) || + (GDLM_PLOCK_VERSION_MINOR < info->version[1 ])) { +log_error ("plock device version mismatch: " +"kernel (%u.%u.%u), user (%u.%u.%u)" , +GDLM_PLOCK_VERSION_MAJOR , +GDLM_PLOCK_VERSION_MINOR , +GDLM_PLOCK_VERSION_PATCH , + info->version[0 ], + info->version[1 ], + info->version[2 ]); +return -EINVAL ; + } +return 0 ; +} + +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); +wake_up (&send_wq); +} + +int gdlm_plock (lm_lockspace_t *lockspace,struct lm_lockname *name, +struct file *file,int cmd,struct file_lock *fl) +{ +struct gdlm_ls *ls = (struct gdlm_ls *) lockspace; +struct plock_op *op; +int rv; + + op =kzalloc (sizeof (*op),GFP_KERNEL ); +if (!op) +return -ENOMEM ;
fs/gfs2/locking/dlm/plock.c line 80
Quoted 10 lines
fs/gfs2/locking/dlm/plock.c new file +10
-0+ + op->info.optype =GDLM_PLOCK_OP_LOCK ; + op->info.pid = fl->fl_pid; + op->info.ex = (fl->fl_type ==F_WRLCK ); + op->info.wait =IS_SETLKW (cmd); + op->info.fsid = ls->id; + op->info.number = name->ln_number; + op->info.start = fl->fl_start; + op->info.end = fl->fl_end; + op->info.owner = (__u64 )(long ) fl->fl_owner;
Can't op->info.owner be a 'struct fowner *'? Is op->info.owner shared over the network?
fs/gfs2/locking/dlm/sysfs.c line 29
Quoted 8 lines
fs/gfs2/locking/dlm/sysfs.c new file +8
-0+static ssize_t block_show (struct gdlm_ls *ls,char *buf) +{ +ssize_t ret; +int val =0 ; + +if (test_bit (DFL_BLOCK_LOCKS , &ls->flags)) + val =1 ; + ret =sprintf (buf,"%d\n" , val);
Safe enough - @buf big enough?
fs/gfs2/locking/dlm/sysfs.c line 46
Quoted 7 lines
fs/gfs2/locking/dlm/sysfs.c new file +7
-0+if (val ==1 ) +set_bit (DFL_BLOCK_LOCKS , &ls->flags); +else if (val ==0 ) { +clear_bit (DFL_BLOCK_LOCKS , &ls->flags); +gdlm_submit_delayed (ls); + }else + ret = -EINVAL ;
Ingo surely wants you to {} it.
Quoted 14 lines
fs/gfs2/locking/dlm/sysfs.c new file +14
-0+static ssize_t id_show (struct gdlm_ls *ls,char *buf) +{ +return sprintf (buf,"%u\n" , ls->id); +} + +static ssize_t jid_show (struct gdlm_ls *ls,char *buf) +{ +return sprintf (buf,"%d\n" , ls->jid); +} + +static ssize_t first_show (struct gdlm_ls *ls,char *buf) +{ +return sprintf (buf,"%d\n" , ls->first); +}
fs/gfs2/locking/dlm/sysfs.c line 99
Quoted 10 lines
fs/gfs2/locking/dlm/sysfs.c new file +10
-0+ +static ssize_t first_done_show (struct gdlm_ls *ls,char *buf) +{ +return sprintf (buf,"%d\n" , ls->first_done); +} + +static ssize_t recover_show (struct gdlm_ls *ls,char *buf) +{ +return sprintf (buf,"%d\n" , ls->recover_jid); +}
Big enough?
fs/gfs2/locking/dlm/sysfs.c line 116
Quoted 9 lines
fs/gfs2/locking/dlm/sysfs.c new file +9
-0+static ssize_t recover_done_show (struct gdlm_ls *ls,char *buf) +{ +return sprintf (buf,"%d\n" , ls->recover_jid_done); +} + +static ssize_t recover_status_show (struct gdlm_ls *ls,char *buf) +{ +return sprintf (buf,"%d\n" , ls->recover_jid_status); +}
Jan Engelhardt
Hi,
Quoted 12 lines · Jan Engelhardt
fs/gfs2/locking/dlm/lock.c line 158
Quoted 7 lines
fs/gfs2/locking/dlm/lock.c new file +7
-0+/* make_strname - convert GFS lock numbers to a string */ + +static inline void make_strname (struct lm_lockname *lockname, +struct gdlm_strname *str) +{ +sprintf (str->name,"%8x%16llx" , lockname->ln_type, + (unsigned long long )lockname->ln_number);Is this format specifier safe enough? "%08x%016llx" perhaps?
Imagine (if this happens at all):
Quoted 8 lines
ln_type = 1; ln_number = 16; %8x = "1", "%16llx" = "10", giving us "110"
ln_type= 17;ln_number= 0;
%8x = "11", "%16llx" = "0", giving us "110".Whoops, name clash.
In this case the field sizes mean that the numbers are padded with spaces. Also we "know" that ln_type will always be a single digit at least with the current implementation.
[lines snipped]
Quoted 5 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ op->info.owner = (__u64)(long) fl->fl_owner;Can't
op->info.ownerbe a 'struct fowner *'? Isop->info.ownershared over the network?
It is shared over the network.
Quoted 11 lines
fs/gfs2/locking/dlm/sysfs.c line 29
Quoted 8 lines
fs/gfs2/locking/dlm/sysfs.c new file +8
-0+static ssize_t block_show (struct gdlm_ls *ls,char *buf) +{ +ssize_t ret; +int val =0 ; + +if (test_bit (DFL_BLOCK_LOCKS , &ls->flags)) + val =1 ; + ret =sprintf (buf,"%d\n" , val);Safe enough - @buf big enough?
Yes, buf is one page in size. However Dave Teigland has sent me a couple of patches to update these routines to the "best practice" according to the docs for sysfs.
Quoted 10 lines
fs/gfs2/locking/dlm/sysfs.c line 46
Quoted 7 lines
fs/gfs2/locking/dlm/sysfs.c new file +7
-0+if (val ==1 ) +set_bit (DFL_BLOCK_LOCKS , &ls->flags); +else if (val ==0 ) { +clear_bit (DFL_BLOCK_LOCKS , &ls->flags); +gdlm_submit_delayed (ls); + }else + ret = -EINVAL ;Ingo surely wants you to {} it.
I've fixed that now. This email's patches are:
http://www.kernel.org/git/?p=linux/kernel/git/steve/gfs2-2.6.git;a=commitdiff;h=c53921248c79197befa7caa4c17b1af5c077a2c2
http://www.kernel.org/git/?p=linux/kernel/git/steve/gfs2-2.6.git;a=commitdiff;h=3204a6c05588788f7686bc45585185a9a4788430
http://www.kernel.org/git/?p=linux/kernel/git/steve/gfs2-2.6.git;a=commitdiff;h=a1d144c71ddc11d3e9d9f29e92cf037da382a541
http://www.kernel.org/git/?p=linux/kernel/git/steve/gfs2-2.6.git;a=commitdiff;h=62f140c173f2c85e15527eefc6e2fb3c37a97eb1
Steve.
Quoted 15 lines · Jan Engelhardt
fs/gfs2/locking/dlm/lock.c line 218
Quoted 10 lines
fs/gfs2/locking/dlm/lock.c new file +9
-0+int gdlm_get_lock (lm_lockspace_t *lockspace,struct lm_lockname *name, +lm_lock_t **lockp) +{ +struct gdlm_lock *lp; +int error; + + error =gdlm_create_lp ((struct gdlm_ls *) lockspace, name, &lp); + + *lockp = (lm_lock_t *) lp;This cast is alright in itself. Considering however that
lm_lock_tis currently typedef'ed to void, it looks a little different. (One _could_ get rid of it, but better not while it is calledlm_lock_t. Leave as-is for now.)
Hi Jan,
I'm wondering what you might suggest instead of using the lm_lockspace_t, lm_lock_t, lm_fsdata_t typedefs. These are opaque objects passed between gfs and the lock modules. Could you give an example or point to some code that shows what you're thinking?
Thanks,
Dave
Hi David,
Quoted 8 lines
Quoted 7 lines
fs/gfs2/locking/dlm/lock.c line 211
Quoted 2 lines
fs/gfs2/locking/dlm/lock.c new file +2
-0+int gdlm_get_lock (lm_lockspace_t *lockspace,struct lm_lockname *name, +lm_lock_t **lockp)[
lm_lock_tis]
currently typedef'ed to void [...]. (One _could_
get rid of it, but better not while it is calledlm_lock_t. Leave as-is for now.)
Quoted 4 lines
I'm wondering what you might suggest instead of using the
lm_lockspace_t,lm_lock_t,lm_fsdata_ttypedefs. These are opaque objects passed between gfs and the lock modules. Could you give an example or point to some code that shows what you're thinking?
What I was thinking about:
int gdlm_get_lock(void *lockspace, struct lm_lockname *name, void **lockp)
Jan Engelhardt
Hi,
Quoted 16 lines · Jan Engelhardt
Hi David,
Quoted 8 lines
Quoted 7 lines
fs/gfs2/locking/dlm/lock.c line 211
Quoted 2 lines
fs/gfs2/locking/dlm/lock.c new file +2
-0+int gdlm_get_lock (lm_lockspace_t *lockspace,struct lm_lockname *name, +lm_lock_t **lockp)[
lm_lock_tis]
currently typedef'ed to void [...]. (One _could_
get rid of it, but better not while it is calledlm_lock_t. Leave as-is for now.)Quoted 4 lines
I'm wondering what you might suggest instead of using the
lm_lockspace_t,lm_lock_t,lm_fsdata_ttypedefs. These are opaque objects passed between gfs and the lock modules. Could you give an example or point to some code that shows what you're thinking?
Quoted 5 lines
What I was thinking about:
intgdlm_get_lock(void *lockspace, struct lm_lockname *name, void **lockp)Jan Engelhardt
I've had a bash at this and the results are here:
http://www.kernel.org/git/?p=linux/kernel/git/steve/gfs2-2.6.git;a=commitdiff;h=9b47c11d1cbedcba685c9bd90c73fd41acdfab0e
Let me know if thats ok,
Steve.