nfs4_fs.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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_OK = 0,
  37. };
  38. /*
  39. * The nfs4_client identifies our client state to the server.
  40. */
  41. struct nfs4_client {
  42. struct list_head cl_servers; /* Global list of servers */
  43. struct in_addr cl_addr; /* Server identifier */
  44. u64 cl_clientid; /* constant */
  45. nfs4_verifier cl_confirm;
  46. unsigned long cl_state;
  47. u32 cl_lockowner_id;
  48. /*
  49. * The following rwsem ensures exclusive access to the server
  50. * while we recover the state following a lease expiration.
  51. */
  52. struct rw_semaphore cl_sem;
  53. struct list_head cl_delegations;
  54. struct list_head cl_state_owners;
  55. struct list_head cl_unused;
  56. int cl_nunused;
  57. spinlock_t cl_lock;
  58. atomic_t cl_count;
  59. struct rpc_clnt * cl_rpcclient;
  60. struct rpc_cred * cl_cred;
  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. wait_queue_head_t cl_waitq;
  67. struct rpc_wait_queue cl_rpcwaitq;
  68. /* used for the setclientid verifier */
  69. struct timespec cl_boot_time;
  70. /* idmapper */
  71. struct idmap * cl_idmap;
  72. /* Our own IP address, as a null-terminated string.
  73. * This is used to generate the clientid, and the callback address.
  74. */
  75. char cl_ipaddr[16];
  76. unsigned char cl_id_uniquifier;
  77. };
  78. /*
  79. * NFS4 state_owners and lock_owners are simply labels for ordered
  80. * sequences of RPC calls. Their sole purpose is to provide once-only
  81. * semantics by allowing the server to identify replayed requests.
  82. *
  83. * The ->so_sema is held during all state_owner seqid-mutating operations:
  84. * OPEN, OPEN_DOWNGRADE, and CLOSE. Its purpose is to properly serialize
  85. * so_seqid.
  86. */
  87. struct nfs4_state_owner {
  88. struct list_head so_list; /* per-clientid list of state_owners */
  89. struct nfs4_client *so_client;
  90. u32 so_id; /* 32-bit identifier, unique */
  91. struct semaphore so_sema;
  92. u32 so_seqid; /* protected by so_sema */
  93. atomic_t so_count;
  94. struct rpc_cred *so_cred; /* Associated cred */
  95. struct list_head so_states;
  96. struct list_head so_delegations;
  97. };
  98. /*
  99. * struct nfs4_state maintains the client-side state for a given
  100. * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
  101. *
  102. * OPEN:
  103. * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
  104. * we need to know how many files are open for reading or writing on a
  105. * given inode. This information too is stored here.
  106. *
  107. * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
  108. */
  109. struct nfs4_lock_state {
  110. struct list_head ls_locks; /* Other lock stateids */
  111. struct nfs4_state * ls_state; /* Pointer to open state */
  112. fl_owner_t ls_owner; /* POSIX lock owner */
  113. #define NFS_LOCK_INITIALIZED 1
  114. int ls_flags;
  115. u32 ls_seqid;
  116. u32 ls_id;
  117. nfs4_stateid ls_stateid;
  118. atomic_t ls_count;
  119. };
  120. /* bits for nfs4_state->flags */
  121. enum {
  122. LK_STATE_IN_USE,
  123. NFS_DELEGATED_STATE,
  124. };
  125. struct nfs4_state {
  126. struct list_head open_states; /* List of states for the same state_owner */
  127. struct list_head inode_states; /* List of states for the same inode */
  128. struct list_head lock_states; /* List of subservient lock stateids */
  129. struct nfs4_state_owner *owner; /* Pointer to the open owner */
  130. struct inode *inode; /* Pointer to the inode */
  131. unsigned long flags; /* Do we hold any locks? */
  132. struct semaphore lock_sema; /* Serializes file locking operations */
  133. spinlock_t state_lock; /* Protects the lock_states list */
  134. nfs4_stateid stateid;
  135. unsigned int nreaders;
  136. unsigned int nwriters;
  137. int state; /* State on the server (R,W, or RW) */
  138. atomic_t count;
  139. };
  140. struct nfs4_exception {
  141. long timeout;
  142. int retry;
  143. };
  144. struct nfs4_state_recovery_ops {
  145. int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *);
  146. int (*recover_lock)(struct nfs4_state *, struct file_lock *);
  147. };
  148. extern struct dentry_operations nfs4_dentry_operations;
  149. extern struct inode_operations nfs4_dir_inode_operations;
  150. /* inode.c */
  151. extern ssize_t nfs4_getxattr(struct dentry *, const char *, void *, size_t);
  152. extern int nfs4_setxattr(struct dentry *, const char *, const void *, size_t, int);
  153. extern ssize_t nfs4_listxattr(struct dentry *, char *, size_t);
  154. /* nfs4proc.c */
  155. extern int nfs4_map_errors(int err);
  156. extern int nfs4_proc_setclientid(struct nfs4_client *, u32, unsigned short);
  157. extern int nfs4_proc_setclientid_confirm(struct nfs4_client *);
  158. extern int nfs4_proc_async_renew(struct nfs4_client *);
  159. extern int nfs4_proc_renew(struct nfs4_client *);
  160. extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state, mode_t mode);
  161. extern struct inode *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *);
  162. extern int nfs4_open_revalidate(struct inode *, struct dentry *, int);
  163. extern struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops;
  164. extern struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops;
  165. extern const u32 nfs4_fattr_bitmap[2];
  166. extern const u32 nfs4_statfs_bitmap[2];
  167. extern const u32 nfs4_pathconf_bitmap[2];
  168. extern const u32 nfs4_fsinfo_bitmap[2];
  169. /* nfs4renewd.c */
  170. extern void nfs4_schedule_state_renewal(struct nfs4_client *);
  171. extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
  172. extern void nfs4_kill_renewd(struct nfs4_client *);
  173. extern void nfs4_renew_state(void *);
  174. /* nfs4state.c */
  175. extern void init_nfsv4_state(struct nfs_server *);
  176. extern void destroy_nfsv4_state(struct nfs_server *);
  177. extern struct nfs4_client *nfs4_get_client(struct in_addr *);
  178. extern void nfs4_put_client(struct nfs4_client *clp);
  179. extern int nfs4_init_client(struct nfs4_client *clp);
  180. extern struct nfs4_client *nfs4_find_client(struct in_addr *);
  181. extern u32 nfs4_alloc_lockowner_id(struct nfs4_client *);
  182. extern struct nfs4_state_owner * nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *);
  183. extern void nfs4_put_state_owner(struct nfs4_state_owner *);
  184. extern void nfs4_drop_state_owner(struct nfs4_state_owner *);
  185. extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
  186. extern void nfs4_put_open_state(struct nfs4_state *);
  187. extern void nfs4_close_state(struct nfs4_state *, mode_t);
  188. extern struct nfs4_state *nfs4_find_state(struct inode *, struct rpc_cred *, mode_t mode);
  189. extern void nfs4_increment_seqid(int status, struct nfs4_state_owner *sp);
  190. extern void nfs4_schedule_state_recovery(struct nfs4_client *);
  191. extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
  192. extern void nfs4_increment_lock_seqid(int status, struct nfs4_lock_state *ls);
  193. extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t);
  194. extern const nfs4_stateid zero_stateid;
  195. /* nfs4xdr.c */
  196. extern uint32_t *nfs4_decode_dirent(uint32_t *p, struct nfs_entry *entry, int plus);
  197. extern struct rpc_procinfo nfs4_procedures[];
  198. struct nfs4_mount_data;
  199. /* callback_xdr.c */
  200. extern struct svc_version nfs4_callback_version1;
  201. #else
  202. #define init_nfsv4_state(server) do { } while (0)
  203. #define destroy_nfsv4_state(server) do { } while (0)
  204. #define nfs4_put_state_owner(inode, owner) do { } while (0)
  205. #define nfs4_put_open_state(state) do { } while (0)
  206. #define nfs4_close_state(a, b) do { } while (0)
  207. #endif /* CONFIG_NFS_V4 */
  208. #endif /* __LINUX_FS_NFS_NFS4_FS.H */