nfs4_fs.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. * struct rpc_sequence ensures that RPC calls are sent in the exact
  41. * order that they appear on the list.
  42. */
  43. struct rpc_sequence {
  44. struct rpc_wait_queue wait; /* RPC call delay queue */
  45. spinlock_t lock; /* Protects the list */
  46. struct list_head list; /* Defines sequence of RPC calls */
  47. };
  48. #define NFS_SEQID_CONFIRMED 1
  49. struct nfs_seqid_counter {
  50. struct rpc_sequence *sequence;
  51. int flags;
  52. u32 counter;
  53. };
  54. struct nfs_seqid {
  55. struct nfs_seqid_counter *sequence;
  56. struct list_head list;
  57. };
  58. static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status)
  59. {
  60. if (seqid_mutating_err(-status))
  61. seqid->flags |= NFS_SEQID_CONFIRMED;
  62. }
  63. /*
  64. * NFS4 state_owners and lock_owners are simply labels for ordered
  65. * sequences of RPC calls. Their sole purpose is to provide once-only
  66. * semantics by allowing the server to identify replayed requests.
  67. */
  68. struct nfs4_state_owner {
  69. spinlock_t so_lock;
  70. struct list_head so_list; /* per-clientid list of state_owners */
  71. struct nfs_client *so_client;
  72. u32 so_id; /* 32-bit identifier, unique */
  73. atomic_t so_count;
  74. struct rpc_cred *so_cred; /* Associated cred */
  75. struct list_head so_states;
  76. struct list_head so_delegations;
  77. struct nfs_seqid_counter so_seqid;
  78. struct rpc_sequence so_sequence;
  79. };
  80. /*
  81. * struct nfs4_state maintains the client-side state for a given
  82. * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
  83. *
  84. * OPEN:
  85. * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
  86. * we need to know how many files are open for reading or writing on a
  87. * given inode. This information too is stored here.
  88. *
  89. * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
  90. */
  91. struct nfs4_lock_state {
  92. struct list_head ls_locks; /* Other lock stateids */
  93. struct nfs4_state * ls_state; /* Pointer to open state */
  94. fl_owner_t ls_owner; /* POSIX lock owner */
  95. #define NFS_LOCK_INITIALIZED 1
  96. int ls_flags;
  97. struct nfs_seqid_counter ls_seqid;
  98. u32 ls_id;
  99. nfs4_stateid ls_stateid;
  100. atomic_t ls_count;
  101. };
  102. /* bits for nfs4_state->flags */
  103. enum {
  104. LK_STATE_IN_USE,
  105. NFS_DELEGATED_STATE,
  106. };
  107. struct nfs4_state {
  108. struct list_head open_states; /* List of states for the same state_owner */
  109. struct list_head inode_states; /* List of states for the same inode */
  110. struct list_head lock_states; /* List of subservient lock stateids */
  111. struct nfs4_state_owner *owner; /* Pointer to the open owner */
  112. struct inode *inode; /* Pointer to the inode */
  113. unsigned long flags; /* Do we hold any locks? */
  114. spinlock_t state_lock; /* Protects the lock_states list */
  115. nfs4_stateid stateid;
  116. unsigned int n_rdonly;
  117. unsigned int n_wronly;
  118. unsigned int n_rdwr;
  119. int state; /* State on the server (R,W, or RW) */
  120. atomic_t count;
  121. };
  122. struct nfs4_exception {
  123. long timeout;
  124. int retry;
  125. };
  126. struct nfs4_state_recovery_ops {
  127. int (*recover_open)(struct nfs4_state_owner *, struct nfs4_state *);
  128. int (*recover_lock)(struct nfs4_state *, struct file_lock *);
  129. };
  130. extern struct dentry_operations nfs4_dentry_operations;
  131. extern const struct inode_operations nfs4_dir_inode_operations;
  132. /* inode.c */
  133. extern ssize_t nfs4_getxattr(struct dentry *, const char *, void *, size_t);
  134. extern int nfs4_setxattr(struct dentry *, const char *, const void *, size_t, int);
  135. extern ssize_t nfs4_listxattr(struct dentry *, char *, size_t);
  136. /* nfs4proc.c */
  137. extern int nfs4_map_errors(int err);
  138. extern int nfs4_proc_setclientid(struct nfs_client *, u32, unsigned short, struct rpc_cred *);
  139. extern int nfs4_proc_setclientid_confirm(struct nfs_client *, struct rpc_cred *);
  140. extern int nfs4_proc_async_renew(struct nfs_client *, struct rpc_cred *);
  141. extern int nfs4_proc_renew(struct nfs_client *, struct rpc_cred *);
  142. extern int nfs4_do_close(struct inode *inode, struct nfs4_state *state);
  143. extern struct dentry *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *);
  144. extern int nfs4_open_revalidate(struct inode *, struct dentry *, int, struct nameidata *);
  145. extern int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle);
  146. extern int nfs4_proc_fs_locations(struct inode *dir, struct qstr *name,
  147. struct nfs4_fs_locations *fs_locations, struct page *page);
  148. extern struct nfs4_state_recovery_ops nfs4_reboot_recovery_ops;
  149. extern struct nfs4_state_recovery_ops nfs4_network_partition_recovery_ops;
  150. extern const u32 nfs4_fattr_bitmap[2];
  151. extern const u32 nfs4_statfs_bitmap[2];
  152. extern const u32 nfs4_pathconf_bitmap[2];
  153. extern const u32 nfs4_fsinfo_bitmap[2];
  154. extern const u32 nfs4_fs_locations_bitmap[2];
  155. /* nfs4renewd.c */
  156. extern void nfs4_schedule_state_renewal(struct nfs_client *);
  157. extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
  158. extern void nfs4_kill_renewd(struct nfs_client *);
  159. extern void nfs4_renew_state(struct work_struct *);
  160. /* nfs4state.c */
  161. struct rpc_cred *nfs4_get_renew_cred(struct nfs_client *clp);
  162. extern u32 nfs4_alloc_lockowner_id(struct nfs_client *);
  163. extern struct nfs4_state_owner * nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *);
  164. extern void nfs4_put_state_owner(struct nfs4_state_owner *);
  165. extern void nfs4_drop_state_owner(struct nfs4_state_owner *);
  166. extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
  167. extern void nfs4_put_open_state(struct nfs4_state *);
  168. extern void nfs4_close_state(struct nfs4_state *, mode_t);
  169. extern void nfs4_state_set_mode_locked(struct nfs4_state *, mode_t);
  170. extern void nfs4_schedule_state_recovery(struct nfs_client *);
  171. extern void nfs4_put_lock_state(struct nfs4_lock_state *lsp);
  172. extern int nfs4_set_lock_state(struct nfs4_state *state, struct file_lock *fl);
  173. extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t);
  174. extern struct nfs_seqid *nfs_alloc_seqid(struct nfs_seqid_counter *counter);
  175. extern int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task);
  176. extern void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid);
  177. extern void nfs_increment_lock_seqid(int status, struct nfs_seqid *seqid);
  178. extern void nfs_free_seqid(struct nfs_seqid *seqid);
  179. extern const nfs4_stateid zero_stateid;
  180. /* nfs4xdr.c */
  181. extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus);
  182. extern struct rpc_procinfo nfs4_procedures[];
  183. struct nfs4_mount_data;
  184. /* callback_xdr.c */
  185. extern struct svc_version nfs4_callback_version1;
  186. #else
  187. #define nfs4_close_state(a, b) do { } while (0)
  188. #endif /* CONFIG_NFS_V4 */
  189. #endif /* __LINUX_FS_NFS_NFS4_FS.H */