nfs4_fs.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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_MANAGER_RUNNING = 0,
  37. NFS4CLNT_CHECK_LEASE,
  38. NFS4CLNT_LEASE_EXPIRED,
  39. NFS4CLNT_RECLAIM_REBOOT,
  40. NFS4CLNT_RECLAIM_NOGRACE,
  41. NFS4CLNT_DELEGRETURN,
  42. NFS4CLNT_SESSION_SETUP,
  43. };
  44. /*
  45. * struct rpc_sequence ensures that RPC calls are sent in the exact
  46. * order that they appear on the list.
  47. */
  48. struct rpc_sequence {
  49. struct rpc_wait_queue wait; /* RPC call delay queue */
  50. spinlock_t lock; /* Protects the list */
  51. struct list_head list; /* Defines sequence of RPC calls */
  52. };
  53. #define NFS_SEQID_CONFIRMED 1
  54. struct nfs_seqid_counter {
  55. struct rpc_sequence *sequence;
  56. int flags;
  57. u32 counter;
  58. };
  59. struct nfs_seqid {
  60. struct nfs_seqid_counter *sequence;
  61. struct list_head list;
  62. };
  63. static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
  64. {
  65. if (seqid_mutating_err(-status))
  66. seqid->flags |= NFS_SEQID_CONFIRMED;
  67. }
  68. struct nfs_unique_id {
  69. struct rb_node rb_node;
  70. __u64 id;
  71. };
  72. /*
  73. * NFS4 state_owners and lock_owners are simply labels for ordered
  74. * sequences of RPC calls. Their sole purpose is to provide once-only
  75. * semantics by allowing the server to identify replayed requests.
  76. */
  77. struct nfs4_state_owner {
  78. struct nfs_unique_id so_owner_id;
  79. struct nfs_client *so_client;
  80. struct nfs_server *so_server;
  81. struct rb_node so_client_node;
  82. struct rpc_cred *so_cred; /* Associated cred */
  83. spinlock_t so_lock;
  84. atomic_t so_count;
  85. unsigned long so_flags;
  86. struct list_head so_states;
  87. struct list_head so_delegations;
  88. struct nfs_seqid_counter so_seqid;
  89. struct rpc_sequence so_sequence;
  90. };
  91. enum {
  92. NFS_OWNER_RECLAIM_REBOOT,
  93. NFS_OWNER_RECLAIM_NOGRACE
  94. };
  95. /*
  96. * struct nfs4_state maintains the client-side state for a given
  97. * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
  98. *
  99. * OPEN:
  100. * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
  101. * we need to know how many files are open for reading or writing on a
  102. * given inode. This information too is stored here.
  103. *
  104. * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
  105. */
  106. struct nfs4_lock_state {
  107. struct list_head ls_locks; /* Other lock stateids */
  108. struct nfs4_state * ls_state; /* Pointer to open state */
  109. fl_owner_t ls_owner; /* POSIX lock owner */
  110. #define NFS_LOCK_INITIALIZED 1
  111. int ls_flags;
  112. struct nfs_seqid_counter ls_seqid;
  113. struct rpc_sequence ls_sequence;
  114. struct nfs_unique_id ls_id;
  115. nfs4_stateid ls_stateid;
  116. atomic_t ls_count;
  117. };
  118. /* bits for nfs4_state->flags */
  119. enum {
  120. LK_STATE_IN_USE,
  121. NFS_DELEGATED_STATE, /* Current stateid is delegation */
  122. NFS_O_RDONLY_STATE, /* OPEN stateid has read-only state */
  123. NFS_O_WRONLY_STATE, /* OPEN stateid has write-only state */
  124. NFS_O_RDWR_STATE, /* OPEN stateid has read/write state */
  125. NFS_STATE_RECLAIM_REBOOT, /* OPEN stateid server rebooted */
  126. NFS_STATE_RECLAIM_NOGRACE, /* OPEN stateid needs to recover state */
  127. };
  128. struct nfs4_state {
  129. struct list_head open_states; /* List of states for the same state_owner */
  130. struct list_head inode_states; /* List of states for the same inode */
  131. struct list_head lock_states; /* List of subservient lock stateids */
  132. struct nfs4_state_owner *owner; /* Pointer to the open owner */
  133. struct inode *inode; /* Pointer to the inode */
  134. unsigned long flags; /* Do we hold any locks? */
  135. spinlock_t state_lock; /* Protects the lock_states list */
  136. seqlock_t seqlock; /* Protects the stateid/open_stateid */
  137. nfs4_stateid stateid; /* Current stateid: may be delegation */
  138. nfs4_stateid open_stateid; /* OPEN stateid */
  139. /* The following 3 fields are protected by owner->so_lock */
  140. unsigned int n_rdonly; /* Number of read-only references */
  141. unsigned int n_wronly; /* Number of write-only references */
  142. unsigned int n_rdwr; /* Number of read/write references */
  143. fmode_t state; /* State on the server (R,W, or RW) */
  144. atomic_t count;
  145. };
  146. struct nfs4_exception {
  147. long timeout;
  148. int retry;
  149. struct nfs4_state *state;
  150. };
  151. struct nfs4_state_recovery_ops {
  152. int owner_flag_bit;
  153. int state_flag_bit;
  154. int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *);
  155. int (*recover_lock)(struct nfs4_state *, struct file_lock *);
  156. int (*establish_clid)(struct nfs_client *, struct rpc_cred *);
  157. struct rpc_cred * (*get_clid_cred)(struct nfs_client *);
  158. };
  159. struct nfs4_state_maintenance_ops {
  160. int (*sched_state_renewal)(struct nfs_client *, struct rpc_cred *);
  161. struct rpc_cred * (*get_state_renewal_cred_locked)(struct nfs_client *);
  162. int (*renew_lease)(struct nfs_client *, struct rpc_cred *);
  163. };
  164. extern const struct dentry_operations nfs4_dentry_operations;
  165. extern const struct inode_operations nfs4_dir_inode_operations;
  166. /* inode.c */
  167. extern ssize_t nfs4_getxattr(struct dentry *, const char *, void *, size_t);
  168. extern int nfs4_setxattr(struct dentry *, const char *, const void *, size_t, int);
  169. extern ssize_t nfs4_listxattr(struct dentry *, char *, size_t);
  170. /* nfs4proc.c */
  171. extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *);
  172. extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct rpc_cred *);
  173. extern int nfs4_proc_async_renew(struct nfs_client *, struct rpc_cred *);
  174. extern int nfs4_proc_renew(struct nfs_client *, struct rpc_cred *);
  175. extern int nfs4_init_clientid(struct nfs_client *, struct rpc_cred *);
  176. extern int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait);
  177. extern struct dentry *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *);
  178. extern int nfs4_open_revalidate(struct inode *, struct dentry *, int, struct nameidata *);
  179. extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
  180. extern int nfs4_proc_fs_locations(struct inode *dir, const struct qstr *name,
  181. struct nfs4_fs_locations *fs_locations, struct page *page);
  182. extern struct nfs4_state_recovery_ops *nfs4_reboot_recovery_ops[];
  183. extern struct nfs4_state_recovery_ops *nfs4_nograce_recovery_ops[];
  184. #if defined(CONFIG_NFS_V4_1)
  185. extern int nfs4_setup_sequence(struct nfs_client *clp,
  186. struct nfs4_sequence_args *args, struct nfs4_sequence_res *res,
  187. int cache_reply, struct rpc_task *task);
  188. extern void nfs4_destroy_session(struct nfs4_session *session);
  189. extern struct nfs4_session *nfs4_alloc_session(struct nfs_client *clp);
  190. extern int nfs4_proc_create_session(struct nfs_client *, int reset);
  191. extern int nfs4_proc_destroy_session(struct nfs4_session *);
  192. extern int nfs4_init_session(struct nfs_server *server);
  193. #else /* CONFIG_NFS_v4_1 */
  194. static inline int nfs4_setup_sequence(struct nfs_client *clp,
  195. struct nfs4_sequence_args *args, struct nfs4_sequence_res *res,
  196. int cache_reply, struct rpc_task *task)
  197. {
  198. return 0;
  199. }
  200. static inline int nfs4_init_session(struct nfs_server *server)
  201. {
  202. return 0;
  203. }
  204. #endif /* CONFIG_NFS_V4_1 */
  205. extern struct nfs4_state_maintenance_ops *nfs4_state_renewal_ops[];
  206. extern const u32 nfs4_fattr_bitmap[2];
  207. extern const u32 nfs4_statfs_bitmap[2];
  208. extern const u32 nfs4_pathconf_bitmap[2];
  209. extern const u32 nfs4_fsinfo_bitmap[2];
  210. extern const u32 nfs4_fs_locations_bitmap[2];
  211. /* nfs4renewd.c */
  212. extern void nfs4_schedule_state_renewal(struct nfs_client *);
  213. extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
  214. extern void nfs4_kill_renewd(struct nfs_client *);
  215. extern void nfs4_renew_state(struct work_struct *);
  216. /* nfs4state.c */
  217. struct rpc_cred *nfs4_get_setclientid_cred(struct nfs_client *clp);
  218. struct rpc_cred *nfs4_get_renew_cred_locked(struct nfs_client *clp);
  219. #if defined(CONFIG_NFS_V4_1)
  220. struct rpc_cred *nfs4_get_machine_cred_locked(struct nfs_client *clp);
  221. struct rpc_cred *nfs4_get_exchange_id_cred(struct nfs_client *clp);
  222. #endif /* CONFIG_NFS_V4_1 */
  223. extern struct nfs4_state_owner * nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *);
  224. extern void nfs4_put_state_owner(struct nfs4_state_owner *);
  225. extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
  226. extern void nfs4_put_open_state(struct nfs4_state *);
  227. extern void nfs4_close_state(struct path *, struct nfs4_state *, fmode_t);
  228. extern void nfs4_close_sync(struct path *, struct nfs4_state *, fmode_t);
  229. extern void nfs4_state_set_mode_locked(struct nfs4_state *, fmode_t);
  230. extern void nfs4_schedule_state_recovery(struct nfs_client *);
  231. extern void nfs4_schedule_state_manager(struct nfs_client *);
  232. extern int nfs4_state_mark_reclaim_nograce(struct nfs_client *clp, struct nfs4_state *state);
  233. extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
  234. extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
  235. extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t);
  236. extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter);
  237. extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
  238. extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
  239. extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
  240. extern void nfs_free_seqid(struct nfs_seqid *seqid);
  241. extern const nfs4_stateid zero_stateid;
  242. /* nfs4xdr.c */
  243. extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus);
  244. extern struct rpc_procinfo nfs4_procedures[];
  245. struct nfs4_mount_data;
  246. /* callback_xdr.c */
  247. extern struct svc_version nfs4_callback_version1;
  248. #else
  249. #define nfs4_close_state(a, b, c) do { } while (0)
  250. #define nfs4_close_sync(a, b, c) do { } while (0)
  251. #endif /* CONFIG_NFS_V4 */
  252. #endif /* __LINUX_FS_NFS_NFS4_FS.H */