fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / include / linux / nfsd / state.h
index 32ffcd8..ab5c236 100644 (file)
@@ -38,6 +38,7 @@
 #define _NFSD4_STATE_H
 
 #include <linux/list.h>
+#include <linux/kref.h>
 #include <linux/sunrpc/clnt.h>
 
 #define NFS4_OPAQUE_LIMIT 1024
@@ -60,28 +61,50 @@ typedef struct {
 #define si_stateownerid   si_opaque.so_stateownerid
 #define si_fileid         si_opaque.so_fileid
 
-extern stateid_t zerostateid;
-extern stateid_t onestateid;
 
-#define ZERO_STATEID(stateid)       (!memcmp((stateid), &zerostateid, sizeof(stateid_t)))
-#define ONE_STATEID(stateid)        (!memcmp((stateid), &onestateid, sizeof(stateid_t)))
+struct nfs4_cb_recall {
+       u32                     cbr_ident;
+       int                     cbr_trunc;
+       stateid_t               cbr_stateid;
+       u32                     cbr_fhlen;
+       u32                     cbr_fhval[NFS4_FHSIZE];
+       struct nfs4_delegation  *cbr_dp;
+};
+
+struct nfs4_delegation {
+       struct list_head        dl_perfile;
+       struct list_head        dl_perclnt;
+       struct list_head        dl_recall_lru;  /* delegation recalled */
+       atomic_t                dl_count;       /* ref count */
+       struct nfs4_client      *dl_client;
+       struct nfs4_file        *dl_file;
+       struct file_lock        *dl_flock;
+       struct file             *dl_vfs_file;
+       u32                     dl_type;
+       time_t                  dl_time;
+       struct nfs4_cb_recall   dl_recall;
+};
+
+#define dl_stateid      dl_recall.cbr_stateid
+#define dl_fhlen        dl_recall.cbr_fhlen
+#define dl_fhval        dl_recall.cbr_fhval
 
 /* client delegation callback info */
 struct nfs4_callback {
        /* SETCLIENTID info */
-       u32                     cb_parsed;  /* addr parsed */
        u32                     cb_addr;
        unsigned short          cb_port;
        u32                     cb_prog;
        u32                     cb_ident;
-       struct xdr_netobj       cb_netid;
        /* RPC client info */
-       u32                     cb_set;     /* successful CB_NULL call */
+       atomic_t                cb_set;     /* successful CB_NULL call */
        struct rpc_program      cb_program;
        struct rpc_stat         cb_stat;
        struct rpc_clnt *       cb_client;
 };
 
+#define HEXDIR_LEN     33 /* hex version of 16 byte md5 of cl_name plus '\0' */
+
 /*
  * struct nfs4_client - one per client.  Clientids live here.
  *     o Each nfs4_client is hashed by clientid.
@@ -95,17 +118,20 @@ struct nfs4_callback {
 struct nfs4_client {
        struct list_head        cl_idhash;      /* hash by cl_clientid.id */
        struct list_head        cl_strhash;     /* hash by cl_name */
-       struct list_head        cl_perclient;   /* list: stateowners */
+       struct list_head        cl_openowners;
+       struct list_head        cl_delegations;
        struct list_head        cl_lru;         /* tail queue */
        struct xdr_netobj       cl_name;        /* id generated by client */
+       char                    cl_recdir[HEXDIR_LEN]; /* recovery dir */
        nfs4_verifier           cl_verifier;    /* generated by client */
        time_t                  cl_time;        /* time of last lease renewal */
-       u32                     cl_addr;        /* client ipaddress */
+       __be32                  cl_addr;        /* client ipaddress */
        struct svc_cred         cl_cred;        /* setclientid principal */
        clientid_t              cl_clientid;    /* generated by server */
        nfs4_verifier           cl_confirm;     /* generated by server */
        struct nfs4_callback    cl_callback;    /* callback info */
-       time_t                  cl_first_state; /* first state aquisition*/
+       atomic_t                cl_count;       /* ref count */
+       u32                     cl_firststate;  /* recovery dir creation */
 };
 
 /* struct nfs4_client_reset
@@ -115,9 +141,7 @@ struct nfs4_client {
  */
 struct nfs4_client_reclaim {
        struct list_head        cr_strhash;     /* hash by cr_name */
-       struct xdr_netobj       cr_name;        /* id generated by client */
-       time_t                  cr_first_state; /* first state aquisition */
-       u32                     cr_expired;     /* boolean: lease expired? */
+       char                    cr_recdir[HEXDIR_LEN]; /* recover dir */
 };
 
 static inline void
@@ -140,7 +164,7 @@ update_stateid(stateid_t *stateid)
  * is cached. 
  */
 struct nfs4_replay {
-       u32                     rp_status;
+       __be32                  rp_status;
        unsigned int            rp_buflen;
        char                    *rp_buf;
        unsigned                intrp_allocated;
@@ -168,17 +192,20 @@ struct nfs4_replay {
 *         reaped by laundramat thread after lease period.
 */
 struct nfs4_stateowner {
+       struct kref             so_ref;
        struct list_head        so_idhash;   /* hash by so_id */
        struct list_head        so_strhash;   /* hash by op_name */
-       struct list_head        so_perclient; /* nfs4_client->cl_perclient */
-       struct list_head        so_perfilestate; /* list: nfs4_stateid */
-       struct list_head        so_perlockowner; /* nfs4_stateid->st_perlockowner */
+       struct list_head        so_perclient;
+       struct list_head        so_stateids;
+       struct list_head        so_perstateid; /* for lockowners only */
        struct list_head        so_close_lru; /* tail queue */
        time_t                  so_time; /* time of placement on so_close_lru */
        int                     so_is_open_owner; /* 1=openowner,0=lockowner */
        u32                     so_id;
        struct nfs4_client *    so_client;
-       u32                     so_seqid;    
+       /* after increment in ENCODE_SEQID_OP_TAIL, represents the next
+        * sequence id expected from the client: */
+       u32                     so_seqid;
        struct xdr_netobj       so_owner;     /* open owner name */
        int                     so_confirmed; /* successful OPEN_CONFIRM? */
        struct nfs4_replay      so_replay;
@@ -190,8 +217,10 @@ struct nfs4_stateowner {
 *      share_acces, share_deny on the file.
 */
 struct nfs4_file {
+       struct kref             fi_ref;
        struct list_head        fi_hash;    /* hash by "struct inode *" */
-       struct list_head        fi_perfile; /* list: nfs4_stateid */
+       struct list_head        fi_stateids;
+       struct list_head        fi_delegations;
        struct inode            *fi_inode;
        u32                     fi_id;      /* used with stateowner->so_id 
                                             * for stateid_hashtbl hash */
@@ -208,20 +237,24 @@ struct nfs4_file {
 *       st_perlockowner: (open stateid) list of lock nfs4_stateowners
 *      st_access_bmap: used only for open stateid
 *      st_deny_bmap: used only for open stateid
+*      st_openstp: open stateid lock stateid was derived from
+*
+* XXX: open stateids and lock stateids have diverged sufficiently that
+* we should consider defining separate structs for the two cases.
 */
 
 struct nfs4_stateid {
        struct list_head              st_hash; 
        struct list_head              st_perfile;
-       struct list_head              st_perfilestate; 
-       struct list_head              st_perlockowner;
+       struct list_head              st_perstateowner;
+       struct list_head              st_lockowners;
        struct nfs4_stateowner      * st_stateowner;
        struct nfs4_file            * st_file;
        stateid_t                     st_stateid;
-       struct file                   st_vfs_file;
-       int                           st_vfs_set;
+       struct file                 * st_vfs_file;
        unsigned long                 st_access_bmap;
        unsigned long                 st_deny_bmap;
+       struct nfs4_stateid         * st_openstp;
 };
 
 /* flags for preprocess_seqid_op() */
@@ -229,8 +262,10 @@ struct nfs4_stateid {
 #define CONFIRM                 0x00000002
 #define OPEN_STATE              0x00000004
 #define LOCK_STATE              0x00000008
-#define RDWR_STATE              0x00000010
-#define CLOSE_STATE             0x00000020
+#define RD_STATE               0x00000010
+#define WR_STATE               0x00000020
+#define CLOSE_STATE             0x00000040
+#define DELEG_RET               0x00000080
 
 #define seqid_mutating_err(err)                       \
        (((err) != nfserr_stale_clientid) &&    \
@@ -238,14 +273,37 @@ struct nfs4_stateid {
        ((err) != nfserr_stale_stateid) &&      \
        ((err) != nfserr_bad_stateid))
 
-extern time_t nfs4_laundromat(void);
-extern int nfsd4_renew(clientid_t *clid);
-extern int nfs4_preprocess_stateid_op(struct svc_fh *current_fh, 
-               stateid_t *stateid, int flags, struct nfs4_stateid **stpp);
-extern int nfs4_share_conflict(struct svc_fh *current_fh, 
-               unsigned int deny_type);
+extern __be32 nfs4_preprocess_stateid_op(struct svc_fh *current_fh,
+               stateid_t *stateid, int flags, struct file **filp);
 extern void nfs4_lock_state(void);
 extern void nfs4_unlock_state(void);
 extern int nfs4_in_grace(void);
-extern int nfs4_check_open_reclaim(clientid_t *clid);
+extern __be32 nfs4_check_open_reclaim(clientid_t *clid);
+extern void put_nfs4_client(struct nfs4_client *clp);
+extern void nfs4_free_stateowner(struct kref *kref);
+extern void nfsd4_probe_callback(struct nfs4_client *clp);
+extern void nfsd4_cb_recall(struct nfs4_delegation *dp);
+extern void nfs4_put_delegation(struct nfs4_delegation *dp);
+extern __be32 nfs4_make_rec_clidname(char *clidname, struct xdr_netobj *clname);
+extern void nfsd4_init_recdir(char *recdir_name);
+extern int nfsd4_recdir_load(void);
+extern void nfsd4_shutdown_recdir(void);
+extern int nfs4_client_to_reclaim(const char *name);
+extern int nfs4_has_reclaimed_state(const char *name);
+extern void nfsd4_recdir_purge_old(void);
+extern int nfsd4_create_clid_dir(struct nfs4_client *clp);
+extern void nfsd4_remove_clid_dir(struct nfs4_client *clp);
+
+static inline void
+nfs4_put_stateowner(struct nfs4_stateowner *so)
+{
+       kref_put(&so->so_ref, nfs4_free_stateowner);
+}
+
+static inline void
+nfs4_get_stateowner(struct nfs4_stateowner *so)
+{
+       kref_get(&so->so_ref);
+}
+
 #endif   /* NFSD4_STATE_H */