nfs4_fs.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*
  2. * linux/fs/nfs/nfs4_fs.h
  3. *
  4. * Copyright (C) 2005 Trond Myklebust
  5. *
  6. * NFSv4-specific filesystem definitions and declarations
  7. */
  8. #ifndef __LINUX_FS_NFS_NFS4_FS_H
  9. #define __LINUX_FS_NFS_NFS4_FS_H
  10. #ifdef CONFIG_NFS_V4
  11. struct idmap;
  12. /*
  13. * In a seqid-mutating op, this macro controls which error return
  14. * values trigger incrementation of the seqid.
  15. *
  16. * from rfc 3010:
  17. * The client MUST monotonically increment the sequence number for the
  18. * CLOSE, LOCK, LOCKU, OPEN, OPEN_CONFIRM, and OPEN_DOWNGRADE
  19. * operations. This is true even in the event that the previous
  20. * operation that used the sequence number received an error. The only
  21. * exception to this rule is if the previous operation received one of
  22. * the following errors: NFSERR_STALE_CLIENTID, NFSERR_STALE_STATEID,
  23. * NFSERR_BAD_STATEID, NFSERR_BAD_SEQID, NFSERR_BADXDR,
  24. * NFSERR_RESOURCE, NFSERR_NOFILEHANDLE.
  25. *
  26. */
  27. #define seqid_mutating_err(err) \
  28. (((err) != NFSERR_STALE_CLIENTID) && \
  29. ((err) != NFSERR_STALE_STATEID) && \
  30. ((err) != NFSERR_BAD_STATEID) && \
  31. ((err) != NFSERR_BAD_SEQID) && \
  32. ((err) != NFSERR_BAD_XDR) && \
  33. ((err) != NFSERR_RESOURCE) && \
  34. ((err) != NFSERR_NOFILEHANDLE))
  35. enum nfs4_client_state {
  36. NFS4CLNT_STATE_RECOVER = 0,
  37. NFS4CLNT_LEASE_EXPIRED,
  38. };
  39. /*
  40. * The nfs4_client identifies our client state to the server.
  41. */
  42. struct nfs4_client {
  43. struct list_head cl_servers; /* Global list of servers */
  44. struct in_addr cl_addr; /* Server identifier */
  45. u64 cl_clientid; /* constant */
  46. nfs4_verifier cl_confirm;
  47. unsigned long cl_state;
  48. u32 cl_lockowner_id;
  49. /*
  50. * The following rwsem ensures exclusive access to the server
  51. * while we recover the state following a lease expiration.
  52. */
  53. struct rw_semaphore cl_sem;
  54. struct list_head cl_delegations;
  55. struct list_head cl_state_owners;
  56. struct list_head cl_unused;
  57. int cl_nunused;
  58. spinlock_t cl_lock;
  59. atomic_t cl_count;
  60. struct rpc_clnt * cl_rpcclient;
  61. struct list_head cl_superblocks; /* List of nfs_server structs */
  62. unsigned long cl_lease_time;
  63. unsigned long cl_last_renewal;
  64. struct work_struct cl_renewd;
  65. struct work_struct cl_recoverd;
  66. struct rpc_wait_queue cl_rpcwaitq;
  67. /* used for the setclientid verifier */
  68. struct timespec cl_boot_time;
  69. /* idmapper */
  70. struct idmap * cl_idmap;
  71. /* Our own IP address, as a null-terminated string.
  72. * This is used to generate the clientid, and the callback address.
  73. */
  74. char cl_ipaddr[16];
  75. unsigned char cl_id_uniquifier;
  76. };
  77. /*
  78. * struct rpc_sequence ensures that RPC calls are sent in the exact
  79. * order that they appear on the list.
  80. */
  81. struct rpc_sequence {
  82. struct rpc_wait_queue wait; /* RPC call delay queue */
  83. spinlock_t lock; /* Protects the list */
  84. struct list_head list; /* Defines sequence of RPC calls */
  85. };
  86. #define NFS_SEQID_CONFIRMED 1
  87. struct nfs_seqid_counter {
  88. struct rpc_sequence *sequence;
  89. int flags;
  90. u32 counter;
  91. };
  92. struct nfs_seqid {
  93. struct nfs_seqid_counter *sequence;
  94. struct list_head list;
  95. };
  96. static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
  97. {
  98. if (seqid_mutating_err(-status))
  99. seqid->flags |= NFS_SEQID_CONFIRMED;
  100. }
  101. /*
  102. * NFS4 state_owners and lock_owners are simply labels for ordered
  103. * sequences of RPC calls. Their sole purpose is to provide once-only
  104. * semantics by allowing the server to identify replayed requests.
  105. */
  106. struct nfs4_state_owner {
  107. spinlock_t so_lock;
  108. struct list_head so_list; /* per-clientid list of state_owners */
  109. struct nfs4_client *so_client;
  110. u32 so_id; /* 32-bit identifier, unique */
  111. atomic_t so_count;
  112. struct rpc_cred *so_cred; /* Associated cred */
  113. struct list_head so_states;
  114. struct list_head so_delegations;
  115. struct nfs_seqid_counter so_seqid;
  116. struct rpc_sequence so_sequence;
  117. };
  118. /*
  119. * struct nfs4_state maintains the client-side state for a given
  120. * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
  121. *
  122. * OPEN:
  123. * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
  124. * we need to know how many files are open for reading or writing on a
  125. * given inode. This information too is stored here.
  126. *
  127. * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
  128. */
  129. struct nfs4_lock_state {
  130. struct list_head ls_locks; /* Other lock stateids */
  131. struct nfs4_state * ls_state; /* Pointer to open state */
  132. fl_owner_t ls_owner; /* POSIX lock owner */
  133. #define NFS_LOCK_INITIALIZED 1
  134. int ls_flags;
  135. struct nfs_seqid_counter ls_seqid;
  136. u32 ls_id;
  137. nfs4_stateid ls_stateid;
  138. atomic_t ls_count;
  139. };
  140. /* bits for nfs4_state->flags */
  141. enum {
  142. LK_STATE_IN_USE,
  143. NFS_DELEGATED_STATE,
  144. };
  145. struct nfs4_state {
  146. struct list_head open_states; /* List of states for the same state_owner */
  147. struct list_head inode_states; /* List of states for the same inode */
  148. struct list_head lock_states; /* List of subservient lock stateids */
  149. struct nfs4_state_owner *owner; /* Pointer to the open owner */
  150. struct inode *inode; /* Pointer to the inode */
  151. unsigned long flags; /* Do we hold any locks? */
  152. spinlock_t state_lock; /* Protects the lock_states list */
  153. nfs4_stateid stateid;
  154. unsigned int n_rdonly;
  155. unsigned int n_wronly;
  156. unsigned int n_rdwr;
  157. int state; /* State on the server (R,W, or RW) */
  158. atomic_t count;
  159. };
  160. struct nfs4_exception {
  161. long timeout;
  162. int retry;
  163. };
  164. struct nfs4_state_recovery_ops {
  165. int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *);
  166. int (*recover_lock)(struct nfs4_state *, struct file_lock *);
  167. };
  168. extern struct dentry_operations nfs4_dentry_operations;
  169. extern struct inode_operations nfs4_dir_inode_operations;
  170. /* inode.c */
  171. extern ssize_t nfs4_getxattr(struct dentry *, const char *, void *, size_t);
  172. extern int nfs4_setxattr(struct dentry *, const char *, const void *, size_t, int);
  173. extern ssize_t nfs4_listxattr(struct dentry *, char *, size_t);
  174. /* nfs4proc.c */
  175. extern int nfs4_map_errors(int err);
  176. extern int nfs4_proc_setclientid(struct nfs4_client *, u32, unsigned short, struct rpc_cred *);
  177. extern int nfs4_proc_setclientid_confirm(struct nfs4_client *, struct rpc_cred *);
  178. extern int nfs4_proc_async_renew(struct nfs4_client *, struct rpc_cred *);
  179. extern int nfs4_proc_renew(struct nfs4_client *, struct rpc_cred *);
  180. extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state);
  181. extern struct dentry *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *);
  182. extern int nfs4_open_revalidate(struct inode *, struct dentry *, int, struct nameidata *);
  183. extern struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops;
  184. extern struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops;
  185. extern const u32 nfs4_fattr_bitmap[2];
  186. extern const u32 nfs4_statfs_bitmap[2];
  187. extern const u32 nfs4_pathconf_bitmap[2];
  188. extern const u32 nfs4_fsinfo_bitmap[2];
  189. /* nfs4renewd.c */
  190. extern void nfs4_schedule_state_renewal(struct nfs4_client *);
  191. extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
  192. extern void nfs4_kill_renewd(struct nfs4_client *);
  193. extern void nfs4_renew_state(void *);
  194. /* nfs4state.c */
  195. extern void init_nfsv4_state(struct nfs_server *);
  196. extern void destroy_nfsv4_state(struct nfs_server *);
  197. extern struct nfs4_client *nfs4_get_client(struct in_addr *);
  198. extern void nfs4_put_client(struct nfs4_client *clp);
  199. extern struct nfs4_client *nfs4_find_client(struct in_addr *);
  200. struct rpc_cred *nfs4_get_renew_cred(struct nfs4_client *clp);
  201. extern u32 nfs4_alloc_lockowner_id(struct nfs4_client *);
  202. extern struct nfs4_state_owner * nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *);
  203. extern void nfs4_put_state_owner(struct nfs4_state_owner *);
  204. extern void nfs4_drop_state_owner(struct nfs4_state_owner *);
  205. extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
  206. extern void nfs4_put_open_state(struct nfs4_state *);
  207. extern void nfs4_close_state(struct nfs4_state *, mode_t);
  208. extern void nfs4_state_set_mode_locked(struct nfs4_state *, mode_t);
  209. extern void nfs4_schedule_state_recovery(struct nfs4_client *);
  210. extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
  211. extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
  212. extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t);
  213. extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter);
  214. extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
  215. extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
  216. extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
  217. extern void nfs_free_seqid(struct nfs_seqid *seqid);
  218. extern const nfs4_stateid zero_stateid;
  219. /* nfs4xdr.c */
  220. extern uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus);
  221. extern struct rpc_procinfo nfs4_procedures[];
  222. struct nfs4_mount_data;
  223. /* callback_xdr.c */
  224. extern struct svc_version nfs4_callback_version1;
  225. #else
  226. #define init_nfsv4_state(server) do { } while (0)
  227. #define destroy_nfsv4_state(server) do { } while (0)
  228. #define nfs4_put_state_owner(inode, owner) do { } while (0)
  229. #define nfs4_put_open_state(state) do { } while (0)
  230. #define nfs4_close_state(a, b) do { } while (0)
  231. #endif /* CONFIG_NFS_V4 */
  232. #endif /* __LINUX_FS_NFS_NFS4_FS.H */