MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / fs / lockd / svcshare.c
blob4943fb7836cee2d9d2a1eeb1fc67832cac1a8239
1 /*
2 * linux/fs/lockd/svcshare.c
4 * Management of DOS shares.
6 * Copyright (C) 1996 Olaf Kirch <okir@monad.swb.de>
7 */
9 #include <linux/time.h>
10 #include <linux/unistd.h>
11 #include <linux/string.h>
12 #include <linux/slab.h>
14 #include <linux/sunrpc/clnt.h>
15 #include <linux/sunrpc/svc.h>
16 #include <linux/lockd/lockd.h>
17 #include <linux/lockd/share.h>
19 static inline int
20 nlm_cmp_owner(struct nlm_share *share, struct xdr_netobj *oh)
22 return share->s_owner.len == oh->len
23 && !memcmp(share->s_owner.data, oh->data, oh->len);
26 u32
27 nlmsvc_share_file(struct nlm_host *host, struct nlm_file *file,
28 struct nlm_args *argp)
30 struct nlm_share *share;
31 struct xdr_netobj *oh = &argp->lock.oh;
32 u8 *ohdata;
34 for (share = file->f_shares; share; share = share->s_next) {
35 if (share->s_host == host && nlm_cmp_owner(share, oh))
36 goto update;
37 if ((argp->fsm_access & share->s_mode)
38 || (argp->fsm_mode & share->s_access ))
39 return nlm_lck_denied;
42 share = (struct nlm_share *) kmalloc(sizeof(*share) + oh->len,
43 GFP_KERNEL);
44 if (share == NULL)
45 return nlm_lck_denied_nolocks;
47 /* Copy owner handle */
48 ohdata = (u8 *) (share + 1);
49 memcpy(ohdata, oh->data, oh->len);
51 share->s_file = file;
52 share->s_host = host;
53 share->s_owner.data = ohdata;
54 share->s_owner.len = oh->len;
55 share->s_next = file->f_shares;
56 file->f_shares = share;
58 update:
59 share->s_access = argp->fsm_access;
60 share->s_mode = argp->fsm_mode;
61 return nlm_granted;
65 * Delete a share.
67 u32
68 nlmsvc_unshare_file(struct nlm_host *host, struct nlm_file *file,
69 struct nlm_args *argp)
71 struct nlm_share *share, **shpp;
72 struct xdr_netobj *oh = &argp->lock.oh;
74 for (shpp = &file->f_shares; (share = *shpp) != 0; shpp = &share->s_next) {
75 if (share->s_host == host && nlm_cmp_owner(share, oh)) {
76 *shpp = share->s_next;
77 kfree(share);
78 return nlm_granted;
82 /* X/Open spec says return success even if there was no
83 * corresponding share. */
84 return nlm_granted;
88 * Traverse all shares for a given file (and host).
89 * NLM_ACT_CHECK is handled by nlmsvc_inspect_file.
91 int
92 nlmsvc_traverse_shares(struct nlm_host *host, struct nlm_file *file, int action)
94 struct nlm_share *share, **shpp;
96 shpp = &file->f_shares;
97 while ((share = *shpp) != NULL) {
98 if (action == NLM_ACT_MARK)
99 share->s_host->h_inuse = 1;
100 else if (action == NLM_ACT_UNLOCK) {
101 if (host == NULL || host == share->s_host) {
102 *shpp = share->s_next;
103 kfree(share);
104 continue;
107 shpp = &share->s_next;
110 return 0;