blob: 6b342e82ebb3dbe58735a81e2dca3b77b2844f69 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/nfs/callback_proc.c
3 *
4 * Copyright (C) 2004 Trond Myklebust
5 *
6 * NFSv4 callback procedures
7 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/nfs4.h>
9#include <linux/nfs_fs.h>
Trond Myklebust4ce79712005-06-22 17:16:21 +000010#include "nfs4_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include "callback.h"
12#include "delegation.h"
David Howells24c8dbb2006-08-22 20:06:10 -040013#include "internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Chuck Lever1d98fe62007-12-10 14:57:23 -050015#ifdef NFS_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#define NFSDBG_FACILITY NFSDBG_CALLBACK
Chuck Lever1d98fe62007-12-10 14:57:23 -050017#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Al Viroe6f684f2006-10-19 23:28:50 -070019__be32 nfs4_callback_getattr(struct cb_getattrargs *args, struct cb_getattrres *res)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020{
David Howellsadfa6f92006-08-22 20:06:08 -040021 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 struct nfs_delegation *delegation;
23 struct nfs_inode *nfsi;
24 struct inode *inode;
Chuck Lever1d98fe62007-12-10 14:57:23 -050025
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 res->bitmap[0] = res->bitmap[1] = 0;
27 res->status = htonl(NFS4ERR_BADHANDLE);
Chuck Leverff052642007-12-10 14:58:44 -050028 clp = nfs_find_client(args->addr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 if (clp == NULL)
30 goto out;
Chuck Lever1d98fe62007-12-10 14:57:23 -050031
32 dprintk("NFS: GETATTR callback request from %s\n",
33 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 inode = nfs_delegation_find_inode(clp, &args->fh);
36 if (inode == NULL)
37 goto out_putclient;
38 nfsi = NFS_I(inode);
39 down_read(&nfsi->rwsem);
40 delegation = nfsi->delegation;
41 if (delegation == NULL || (delegation->type & FMODE_WRITE) == 0)
42 goto out_iput;
43 res->size = i_size_read(inode);
Trond Myklebustbeb2a5e2006-01-03 09:55:37 +010044 res->change_attr = delegation->change_attr;
45 if (nfsi->npages != 0)
46 res->change_attr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 res->ctime = inode->i_ctime;
48 res->mtime = inode->i_mtime;
49 res->bitmap[0] = (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE) &
50 args->bitmap[0];
51 res->bitmap[1] = (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY) &
52 args->bitmap[1];
53 res->status = 0;
54out_iput:
55 up_read(&nfsi->rwsem);
56 iput(inode);
57out_putclient:
David Howells24c8dbb2006-08-22 20:06:10 -040058 nfs_put_client(clp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059out:
Harvey Harrison3110ff82008-05-02 13:42:44 -070060 dprintk("%s: exit with status = %d\n", __func__, ntohl(res->status));
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 return res->status;
62}
63
Al Viroe6f684f2006-10-19 23:28:50 -070064__be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
David Howellsadfa6f92006-08-22 20:06:08 -040066 struct nfs_client *clp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 struct inode *inode;
Al Viroe6f684f2006-10-19 23:28:50 -070068 __be32 res;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70 res = htonl(NFS4ERR_BADHANDLE);
Chuck Leverff052642007-12-10 14:58:44 -050071 clp = nfs_find_client(args->addr, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 if (clp == NULL)
73 goto out;
Chuck Lever1d98fe62007-12-10 14:57:23 -050074
75 dprintk("NFS: RECALL callback request from %s\n",
76 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
77
Trond Myklebust3fbd67a2008-01-26 01:06:40 -050078 do {
79 struct nfs_client *prev = clp;
80
81 inode = nfs_delegation_find_inode(clp, &args->fh);
82 if (inode != NULL) {
83 /* Set up a helper thread to actually return the delegation */
84 switch(nfs_async_inode_return_delegation(inode, &args->stateid)) {
85 case 0:
86 res = 0;
87 break;
88 case -ENOENT:
89 if (res != 0)
90 res = htonl(NFS4ERR_BAD_STATEID);
91 break;
92 default:
93 res = htonl(NFS4ERR_RESOURCE);
94 }
95 iput(inode);
96 }
97 clp = nfs_find_client_next(prev);
98 nfs_put_client(prev);
99 } while (clp != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100out:
Harvey Harrison3110ff82008-05-02 13:42:44 -0700101 dprintk("%s: exit with status = %d\n", __func__, ntohl(res));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 return res;
103}
Benny Halevyd49433e2009-04-01 09:23:25 -0400104
105#if defined(CONFIG_NFS_V4_1)
106
Ricardo Labiaga963891a2009-04-01 09:23:34 -0400107/*
108 * Returns a pointer to a held 'struct nfs_client' that matches the server's
109 * address, major version number, and session ID. It is the caller's
110 * responsibility to release the returned reference.
111 *
112 * Returns NULL if there are no connections with sessions, or if no session
113 * matches the one of interest.
114 */
115 static struct nfs_client *find_client_with_session(
116 const struct sockaddr *addr, u32 nfsversion,
117 struct nfs4_sessionid *sessionid)
118{
119 struct nfs_client *clp;
120
121 clp = nfs_find_client(addr, 4);
122 if (clp == NULL)
123 return NULL;
124
125 do {
126 struct nfs_client *prev = clp;
127
128 if (clp->cl_session != NULL) {
129 if (memcmp(clp->cl_session->sess_id.data,
130 sessionid->data,
131 NFS4_MAX_SESSIONID_LEN) == 0) {
132 /* Returns a held reference to clp */
133 return clp;
134 }
135 }
136 clp = nfs_find_client_next(prev);
137 nfs_put_client(prev);
138 } while (clp != NULL);
139
140 return NULL;
141}
142
Benny Halevyd49433e2009-04-01 09:23:25 -0400143/* FIXME: validate args->cbs_{sequence,slot}id */
144/* FIXME: referring calls should be processed */
145unsigned nfs4_callback_sequence(struct cb_sequenceargs *args,
146 struct cb_sequenceres *res)
147{
148 int i;
149 unsigned status = 0;
150
151 for (i = 0; i < args->csa_nrclists; i++)
152 kfree(args->csa_rclists[i].rcl_refcalls);
153 kfree(args->csa_rclists);
154
155 memcpy(&res->csr_sessionid, &args->csa_sessionid,
156 sizeof(res->csr_sessionid));
157 res->csr_sequenceid = args->csa_sequenceid;
158 res->csr_slotid = args->csa_slotid;
159 res->csr_highestslotid = NFS41_BC_MAX_CALLBACKS - 1;
160 res->csr_target_highestslotid = NFS41_BC_MAX_CALLBACKS - 1;
161
162 dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
163 res->csr_status = status;
164 return status;
165}
166
167#endif /* CONFIG_NFS_V4_1 */