2 * linux/fs/nfs/callback_proc.c
4 * Copyright (C) 2004 Trond Myklebust
6 * NFSv4 callback procedures
8 #include <linux/nfs4.h>
9 #include <linux/nfs_fs.h>
12 #include "delegation.h"
16 #define NFSDBG_FACILITY NFSDBG_CALLBACK
19 __be32 nfs4_callback_getattr(struct cb_getattrargs *args, struct cb_getattrres *res)
21 struct nfs_client *clp;
22 struct nfs_delegation *delegation;
23 struct nfs_inode *nfsi;
26 res->bitmap[0] = res->bitmap[1] = 0;
27 res->status = htonl(NFS4ERR_BADHANDLE);
28 clp = nfs_find_client(args->addr, 4);
32 dprintk("NFS: GETATTR callback request from %s\n",
33 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
35 inode = nfs_delegation_find_inode(clp, &args->fh);
39 down_read(&nfsi->rwsem);
40 delegation = nfsi->delegation;
41 if (delegation == NULL || (delegation->type & FMODE_WRITE) == 0)
43 res->size = i_size_read(inode);
44 res->change_attr = delegation->change_attr;
45 if (nfsi->npages != 0)
47 res->ctime = inode->i_ctime;
48 res->mtime = inode->i_mtime;
49 res->bitmap[0] = (FATTR4_WORD0_CHANGE|FATTR4_WORD0_SIZE) &
51 res->bitmap[1] = (FATTR4_WORD1_TIME_METADATA|FATTR4_WORD1_TIME_MODIFY) &
55 up_read(&nfsi->rwsem);
60 dprintk("%s: exit with status = %d\n", __func__, ntohl(res->status));
64 __be32 nfs4_callback_recall(struct cb_recallargs *args, void *dummy)
66 struct nfs_client *clp;
70 res = htonl(NFS4ERR_BADHANDLE);
71 clp = nfs_find_client(args->addr, 4);
75 dprintk("NFS: RECALL callback request from %s\n",
76 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
79 struct nfs_client *prev = clp;
81 inode = nfs_delegation_find_inode(clp, &args->fh);
83 /* Set up a helper thread to actually return the delegation */
84 switch(nfs_async_inode_return_delegation(inode, &args->stateid)) {
90 res = htonl(NFS4ERR_BAD_STATEID);
93 res = htonl(NFS4ERR_RESOURCE);
97 clp = nfs_find_client_next(prev);
99 } while (clp != NULL);
101 dprintk("%s: exit with status = %d\n", __func__, ntohl(res));
105 #if defined(CONFIG_NFS_V4_1)
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.
112 * Returns NULL if there are no connections with sessions, or if no session
113 * matches the one of interest.
115 static struct nfs_client *find_client_with_session(
116 const struct sockaddr *addr, u32 nfsversion,
117 struct nfs4_sessionid *sessionid)
119 struct nfs_client *clp;
121 clp = nfs_find_client(addr, 4);
126 struct nfs_client *prev = clp;
128 if (clp->cl_session != NULL) {
129 if (memcmp(clp->cl_session->sess_id.data,
131 NFS4_MAX_SESSIONID_LEN) == 0) {
132 /* Returns a held reference to clp */
136 clp = nfs_find_client_next(prev);
137 nfs_put_client(prev);
138 } while (clp != NULL);
143 /* FIXME: validate args->cbs_{sequence,slot}id */
144 /* FIXME: referring calls should be processed */
145 unsigned nfs4_callback_sequence(struct cb_sequenceargs *args,
146 struct cb_sequenceres *res)
151 for (i = 0; i < args->csa_nrclists; i++)
152 kfree(args->csa_rclists[i].rcl_refcalls);
153 kfree(args->csa_rclists);
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;
162 dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
163 res->csr_status = status;
167 #endif /* CONFIG_NFS_V4_1 */