diff options
author | Patrick Caulfield <pcaulfie@redhat.com> | 2006-12-06 10:10:37 -0500 |
---|---|---|
committer | Steven Whitehouse <swhiteho@redhat.com> | 2006-12-07 09:25:13 -0500 |
commit | ac33d0710595579e3cfca42dde2257eb0b123f6d (patch) | |
tree | ebb3050be68aa49666ee03f51ffe2667f5b18c74 /fs/dlm/main.c | |
parent | 34126f9f41901ca9d7d0031c2b11fc0d6c07b72d (diff) |
[DLM] Clean up lowcomms
This fixes up most of the things pointed out by akpm and Pavel Machek
with comments below indicating why some things have been left:
Andrew Morton wrote:
>
>> +static struct nodeinfo *nodeid2nodeinfo(int nodeid, gfp_t alloc)
>> +{
>> + struct nodeinfo *ni;
>> + int r;
>> + int n;
>> +
>> + down_read(&nodeinfo_lock);
>
> Given that this function can sleep, I wonder if `alloc' is useful.
>
> I see lots of callers passing in a literal "0" for `alloc'. That's in fact
> a secret (GFP_ATOMIC & ~__GFP_HIGH). I doubt if that's what you really
> meant. Particularly as the code could at least have used __GFP_WAIT (aka
> GFP_NOIO) which is much, much more reliable than "0". In fact "0" is the
> least reliable mode possible.
>
> IOW, this is all bollixed up.
When 0 is passed into nodeid2nodeinfo the function does not try to allocate a
new structure at all. it's an indication that the caller only wants the nodeinfo
struct for that nodeid if there actually is one in existance.
I've tidied the function itself so it's more obvious, (and tidier!)
>> +/* Data received from remote end */
>> +static int receive_from_sock(void)
>> +{
>> + int ret = 0;
>> + struct msghdr msg;
>> + struct kvec iov[2];
>> + unsigned len;
>> + int r;
>> + struct sctp_sndrcvinfo *sinfo;
>> + struct cmsghdr *cmsg;
>> + struct nodeinfo *ni;
>> +
>> + /* These two are marginally too big for stack allocation, but this
>> + * function is (currently) only called by dlm_recvd so static should be
>> + * OK.
>> + */
>> + static struct sockaddr_storage msgname;
>> + static char incmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))];
>
> whoa. This is globally singly-threaded code??
Yes. it is only ever run in the context of dlm_recvd.
>>
>> +static void initiate_association(int nodeid)
>> +{
>> + struct sockaddr_storage rem_addr;
>> + static char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))];
>
> Another static buffer to worry about. Globally singly-threaded code?
Yes. Only ever called by dlm_sendd.
>> +
>> +/* Send a message */
>> +static int send_to_sock(struct nodeinfo *ni)
>> +{
>> + int ret = 0;
>> + struct writequeue_entry *e;
>> + int len, offset;
>> + struct msghdr outmsg;
>> + static char outcmsg[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))];
>
> Singly-threaded?
Yep.
>>
>> +static void dealloc_nodeinfo(void)
>> +{
>> + int i;
>> +
>> + for (i=1; i<=max_nodeid; i++) {
>> + struct nodeinfo *ni = nodeid2nodeinfo(i, 0);
>> + if (ni) {
>> + idr_remove(&nodeinfo_idr, i);
>
> Didn't that need locking?
Not. it's only ever called at DLM shutdown after all the other threads
have been stopped.
>>
>> +static int write_list_empty(void)
>> +{
>> + int status;
>> +
>> + spin_lock_bh(&write_nodes_lock);
>> + status = list_empty(&write_nodes);
>> + spin_unlock_bh(&write_nodes_lock);
>> +
>> + return status;
>> +}
>
> This function's return value is meaningless. As soon as the lock gets
> dropped, the return value can get out of sync with reality.
>
> Looking at the caller, this _might_ happen to be OK, but it's a nasty and
> dangerous thing. Really the locking should be moved into the caller.
It's just an optimisation to allow the caller to schedule if there is no work
to do. if something arrives immediately afterwards then it will get picked up
when the process re-awakes (and it will be woken by that arrival).
The 'accepting' atomic has gone completely. as Andrew pointed out it didn't
really achieve much anyway. I suspect it was a plaster over some other
startup or shutdown bug to be honest.
Signed-off-by: Patrick Caulfield <pcaulfie@redhat.com>
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Cc: Andrew Morton <akpm@osdl.org>
Cc: Pavel Machek <pavel@ucw.cz>
Diffstat (limited to 'fs/dlm/main.c')
-rw-r--r-- | fs/dlm/main.c | 10 |
1 files changed, 1 insertions, 9 deletions
diff --git a/fs/dlm/main.c b/fs/dlm/main.c index a8da8dc36b2e..162fbae58fe5 100644 --- a/fs/dlm/main.c +++ b/fs/dlm/main.c | |||
@@ -16,7 +16,6 @@ | |||
16 | #include "lock.h" | 16 | #include "lock.h" |
17 | #include "user.h" | 17 | #include "user.h" |
18 | #include "memory.h" | 18 | #include "memory.h" |
19 | #include "lowcomms.h" | ||
20 | #include "config.h" | 19 | #include "config.h" |
21 | 20 | ||
22 | #ifdef CONFIG_DLM_DEBUG | 21 | #ifdef CONFIG_DLM_DEBUG |
@@ -47,20 +46,14 @@ static int __init init_dlm(void) | |||
47 | if (error) | 46 | if (error) |
48 | goto out_config; | 47 | goto out_config; |
49 | 48 | ||
50 | error = dlm_lowcomms_init(); | ||
51 | if (error) | ||
52 | goto out_debug; | ||
53 | |||
54 | error = dlm_user_init(); | 49 | error = dlm_user_init(); |
55 | if (error) | 50 | if (error) |
56 | goto out_lowcomms; | 51 | goto out_debug; |
57 | 52 | ||
58 | printk("DLM (built %s %s) installed\n", __DATE__, __TIME__); | 53 | printk("DLM (built %s %s) installed\n", __DATE__, __TIME__); |
59 | 54 | ||
60 | return 0; | 55 | return 0; |
61 | 56 | ||
62 | out_lowcomms: | ||
63 | dlm_lowcomms_exit(); | ||
64 | out_debug: | 57 | out_debug: |
65 | dlm_unregister_debugfs(); | 58 | dlm_unregister_debugfs(); |
66 | out_config: | 59 | out_config: |
@@ -76,7 +69,6 @@ static int __init init_dlm(void) | |||
76 | static void __exit exit_dlm(void) | 69 | static void __exit exit_dlm(void) |
77 | { | 70 | { |
78 | dlm_user_exit(); | 71 | dlm_user_exit(); |
79 | dlm_lowcomms_exit(); | ||
80 | dlm_config_exit(); | 72 | dlm_config_exit(); |
81 | dlm_memory_exit(); | 73 | dlm_memory_exit(); |
82 | dlm_lockspace_exit(); | 74 | dlm_lockspace_exit(); |