Merge branch 'nfs-for-2.6.32'
[pandora-kernel.git] / include / linux / sunrpc / clnt.h
1 /*
2  *  linux/include/linux/sunrpc/clnt.h
3  *
4  *  Declarations for the high-level RPC client interface
5  *
6  *  Copyright (C) 1995, 1996, Olaf Kirch <okir@monad.swb.de>
7  */
8
9 #ifndef _LINUX_SUNRPC_CLNT_H
10 #define _LINUX_SUNRPC_CLNT_H
11
12 #include <linux/socket.h>
13 #include <linux/in.h>
14 #include <linux/in6.h>
15
16 #include <linux/sunrpc/msg_prot.h>
17 #include <linux/sunrpc/sched.h>
18 #include <linux/sunrpc/xprt.h>
19 #include <linux/sunrpc/auth.h>
20 #include <linux/sunrpc/stats.h>
21 #include <linux/sunrpc/xdr.h>
22 #include <linux/sunrpc/timer.h>
23 #include <asm/signal.h>
24 #include <linux/path.h>
25
26 struct rpc_inode;
27
28 /*
29  * The high-level client handle
30  */
31 struct rpc_clnt {
32         struct kref             cl_kref;        /* Number of references */
33         struct list_head        cl_clients;     /* Global list of clients */
34         struct list_head        cl_tasks;       /* List of tasks */
35         spinlock_t              cl_lock;        /* spinlock */
36         struct rpc_xprt *       cl_xprt;        /* transport */
37         struct rpc_procinfo *   cl_procinfo;    /* procedure info */
38         u32                     cl_prog,        /* RPC program number */
39                                 cl_vers,        /* RPC version number */
40                                 cl_maxproc;     /* max procedure number */
41
42         char *                  cl_server;      /* server machine name */
43         char *                  cl_protname;    /* protocol name */
44         struct rpc_auth *       cl_auth;        /* authenticator */
45         struct rpc_stat *       cl_stats;       /* per-program statistics */
46         struct rpc_iostats *    cl_metrics;     /* per-client statistics */
47
48         unsigned int            cl_softrtry : 1,/* soft timeouts */
49                                 cl_discrtry : 1,/* disconnect before retry */
50                                 cl_autobind : 1,/* use getport() */
51                                 cl_chatty   : 1;/* be verbose */
52
53         struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
54         const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
55
56         int                     cl_nodelen;     /* nodename length */
57         char                    cl_nodename[UNX_MAXNODENAME];
58         struct path             cl_path;
59         struct rpc_clnt *       cl_parent;      /* Points to parent of clones */
60         struct rpc_rtt          cl_rtt_default;
61         struct rpc_timeout      cl_timeout_default;
62         struct rpc_program *    cl_program;
63         char                    cl_inline_name[32];
64         char                    *cl_principal;  /* target to authenticate to */
65 };
66
67 /*
68  * General RPC program info
69  */
70 #define RPC_MAXVERSION          4
71 struct rpc_program {
72         char *                  name;           /* protocol name */
73         u32                     number;         /* program number */
74         unsigned int            nrvers;         /* number of versions */
75         struct rpc_version **   version;        /* version array */
76         struct rpc_stat *       stats;          /* statistics */
77         char *                  pipe_dir_name;  /* path to rpc_pipefs dir */
78 };
79
80 struct rpc_version {
81         u32                     number;         /* version number */
82         unsigned int            nrprocs;        /* number of procs */
83         struct rpc_procinfo *   procs;          /* procedure array */
84 };
85
86 /*
87  * Procedure information
88  */
89 struct rpc_procinfo {
90         u32                     p_proc;         /* RPC procedure number */
91         kxdrproc_t              p_encode;       /* XDR encode function */
92         kxdrproc_t              p_decode;       /* XDR decode function */
93         unsigned int            p_arglen;       /* argument hdr length (u32) */
94         unsigned int            p_replen;       /* reply hdr length (u32) */
95         unsigned int            p_count;        /* call count */
96         unsigned int            p_timer;        /* Which RTT timer to use */
97         u32                     p_statidx;      /* Which procedure to account */
98         char *                  p_name;         /* name of procedure */
99 };
100
101 #ifdef __KERNEL__
102
103 struct rpc_create_args {
104         int                     protocol;
105         struct sockaddr         *address;
106         size_t                  addrsize;
107         struct sockaddr         *saddress;
108         const struct rpc_timeout *timeout;
109         char                    *servername;
110         struct rpc_program      *program;
111         u32                     prognumber;     /* overrides program->number */
112         u32                     version;
113         rpc_authflavor_t        authflavor;
114         unsigned long           flags;
115         char                    *client_name;
116 };
117
118 /* Values for "flags" field */
119 #define RPC_CLNT_CREATE_HARDRTRY        (1UL << 0)
120 #define RPC_CLNT_CREATE_AUTOBIND        (1UL << 2)
121 #define RPC_CLNT_CREATE_NONPRIVPORT     (1UL << 3)
122 #define RPC_CLNT_CREATE_NOPING          (1UL << 4)
123 #define RPC_CLNT_CREATE_DISCRTRY        (1UL << 5)
124 #define RPC_CLNT_CREATE_QUIET           (1UL << 6)
125
126 struct rpc_clnt *rpc_create(struct rpc_create_args *args);
127 struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *,
128                                 struct rpc_program *, u32);
129 struct rpc_clnt *rpc_clone_client(struct rpc_clnt *);
130 void            rpc_shutdown_client(struct rpc_clnt *);
131 void            rpc_release_client(struct rpc_clnt *);
132
133 int             rpcb_register(u32, u32, int, unsigned short);
134 int             rpcb_v4_register(const u32 program, const u32 version,
135                                  const struct sockaddr *address,
136                                  const char *netid);
137 int             rpcb_getport_sync(struct sockaddr_in *, u32, u32, int);
138 void            rpcb_getport_async(struct rpc_task *);
139
140 void            rpc_call_start(struct rpc_task *);
141 int             rpc_call_async(struct rpc_clnt *clnt,
142                                const struct rpc_message *msg, int flags,
143                                const struct rpc_call_ops *tk_ops,
144                                void *calldata);
145 int             rpc_call_sync(struct rpc_clnt *clnt,
146                               const struct rpc_message *msg, int flags);
147 struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred,
148                                int flags);
149 void            rpc_restart_call_prepare(struct rpc_task *);
150 void            rpc_restart_call(struct rpc_task *);
151 void            rpc_setbufsize(struct rpc_clnt *, unsigned int, unsigned int);
152 size_t          rpc_max_payload(struct rpc_clnt *);
153 void            rpc_force_rebind(struct rpc_clnt *);
154 size_t          rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t);
155 const char      *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t);
156
157 size_t          rpc_ntop(const struct sockaddr *, char *, const size_t);
158 size_t          rpc_pton(const char *, const size_t,
159                          struct sockaddr *, const size_t);
160 char *          rpc_sockaddr2uaddr(const struct sockaddr *);
161 size_t          rpc_uaddr2sockaddr(const char *, const size_t,
162                                    struct sockaddr *, const size_t);
163
164 static inline unsigned short rpc_get_port(const struct sockaddr *sap)
165 {
166         switch (sap->sa_family) {
167         case AF_INET:
168                 return ntohs(((struct sockaddr_in *)sap)->sin_port);
169         case AF_INET6:
170                 return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
171         }
172         return 0;
173 }
174
175 static inline void rpc_set_port(struct sockaddr *sap,
176                                 const unsigned short port)
177 {
178         switch (sap->sa_family) {
179         case AF_INET:
180                 ((struct sockaddr_in *)sap)->sin_port = htons(port);
181                 break;
182         case AF_INET6:
183                 ((struct sockaddr_in6 *)sap)->sin6_port = htons(port);
184                 break;
185         }
186 }
187
188 #define IPV6_SCOPE_DELIMITER            '%'
189 #define IPV6_SCOPE_ID_LEN               sizeof("%nnnnnnnnnn")
190
191 #endif /* __KERNEL__ */
192 #endif /* _LINUX_SUNRPC_CLNT_H */