linux/include/linux/sunrpc/clnt.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2/*
   3 *  linux/include/linux/sunrpc/clnt.h
   4 *
   5 *  Declarations for the high-level RPC client interface
   6 *
   7 *  Copyright (C) 1995, 1996, Olaf Kirch <okir@monad.swb.de>
   8 */
   9
  10#ifndef _LINUX_SUNRPC_CLNT_H
  11#define _LINUX_SUNRPC_CLNT_H
  12
  13#include <linux/types.h>
  14#include <linux/socket.h>
  15#include <linux/in.h>
  16#include <linux/in6.h>
  17
  18#include <linux/sunrpc/msg_prot.h>
  19#include <linux/sunrpc/sched.h>
  20#include <linux/sunrpc/xprt.h>
  21#include <linux/sunrpc/auth.h>
  22#include <linux/sunrpc/stats.h>
  23#include <linux/sunrpc/xdr.h>
  24#include <linux/sunrpc/timer.h>
  25#include <linux/sunrpc/rpc_pipe_fs.h>
  26#include <asm/signal.h>
  27#include <linux/path.h>
  28#include <net/ipv6.h>
  29#include <linux/sunrpc/xprtmultipath.h>
  30
  31struct rpc_inode;
  32struct rpc_sysfs_client;
  33
  34/*
  35 * The high-level client handle
  36 */
  37struct rpc_clnt {
  38        atomic_t                cl_count;       /* Number of references */
  39        unsigned int            cl_clid;        /* client id */
  40        struct list_head        cl_clients;     /* Global list of clients */
  41        struct list_head        cl_tasks;       /* List of tasks */
  42        spinlock_t              cl_lock;        /* spinlock */
  43        struct rpc_xprt __rcu * cl_xprt;        /* transport */
  44        const struct rpc_procinfo *cl_procinfo; /* procedure info */
  45        u32                     cl_prog,        /* RPC program number */
  46                                cl_vers,        /* RPC version number */
  47                                cl_maxproc;     /* max procedure number */
  48
  49        struct rpc_auth *       cl_auth;        /* authenticator */
  50        struct rpc_stat *       cl_stats;       /* per-program statistics */
  51        struct rpc_iostats *    cl_metrics;     /* per-client statistics */
  52
  53        unsigned int            cl_softrtry : 1,/* soft timeouts */
  54                                cl_softerr  : 1,/* Timeouts return errors */
  55                                cl_discrtry : 1,/* disconnect before retry */
  56                                cl_noretranstimeo: 1,/* No retransmit timeouts */
  57                                cl_autobind : 1,/* use getport() */
  58                                cl_chatty   : 1;/* be verbose */
  59
  60        struct rpc_rtt *        cl_rtt;         /* RTO estimator data */
  61        const struct rpc_timeout *cl_timeout;   /* Timeout strategy */
  62
  63        atomic_t                cl_swapper;     /* swapfile count */
  64        int                     cl_nodelen;     /* nodename length */
  65        char                    cl_nodename[UNX_MAXNODENAME+1];
  66        struct rpc_pipe_dir_head cl_pipedir_objects;
  67        struct rpc_clnt *       cl_parent;      /* Points to parent of clones */
  68        struct rpc_rtt          cl_rtt_default;
  69        struct rpc_timeout      cl_timeout_default;
  70        const struct rpc_program *cl_program;
  71        const char *            cl_principal;   /* use for machine cred */
  72#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
  73        struct dentry           *cl_debugfs;    /* debugfs directory */
  74#endif
  75        struct rpc_sysfs_client *cl_sysfs;      /* sysfs directory */
  76        /* cl_work is only needed after cl_xpi is no longer used,
  77         * and that are of similar size
  78         */
  79        union {
  80                struct rpc_xprt_iter    cl_xpi;
  81                struct work_struct      cl_work;
  82        };
  83        const struct cred       *cl_cred;
  84};
  85
  86/*
  87 * General RPC program info
  88 */
  89#define RPC_MAXVERSION          4
  90struct rpc_program {
  91        const char *            name;           /* protocol name */
  92        u32                     number;         /* program number */
  93        unsigned int            nrvers;         /* number of versions */
  94        const struct rpc_version **     version;        /* version array */
  95        struct rpc_stat *       stats;          /* statistics */
  96        const char *            pipe_dir_name;  /* path to rpc_pipefs dir */
  97};
  98
  99struct rpc_version {
 100        u32                     number;         /* version number */
 101        unsigned int            nrprocs;        /* number of procs */
 102        const struct rpc_procinfo *procs;       /* procedure array */
 103        unsigned int            *counts;        /* call counts */
 104};
 105
 106/*
 107 * Procedure information
 108 */
 109struct rpc_procinfo {
 110        u32                     p_proc;         /* RPC procedure number */
 111        kxdreproc_t             p_encode;       /* XDR encode function */
 112        kxdrdproc_t             p_decode;       /* XDR decode function */
 113        unsigned int            p_arglen;       /* argument hdr length (u32) */
 114        unsigned int            p_replen;       /* reply hdr length (u32) */
 115        unsigned int            p_timer;        /* Which RTT timer to use */
 116        u32                     p_statidx;      /* Which procedure to account */
 117        const char *            p_name;         /* name of procedure */
 118};
 119
 120struct rpc_create_args {
 121        struct net              *net;
 122        int                     protocol;
 123        struct sockaddr         *address;
 124        size_t                  addrsize;
 125        struct sockaddr         *saddress;
 126        const struct rpc_timeout *timeout;
 127        const char              *servername;
 128        const char              *nodename;
 129        const struct rpc_program *program;
 130        u32                     prognumber;     /* overrides program->number */
 131        u32                     version;
 132        rpc_authflavor_t        authflavor;
 133        u32                     nconnect;
 134        unsigned long           flags;
 135        char                    *client_name;
 136        struct svc_xprt         *bc_xprt;       /* NFSv4.1 backchannel */
 137        const struct cred       *cred;
 138};
 139
 140struct rpc_add_xprt_test {
 141        void (*add_xprt_test)(struct rpc_clnt *clnt,
 142                struct rpc_xprt *xprt,
 143                void *calldata);
 144        void *data;
 145};
 146
 147/* Values for "flags" field */
 148#define RPC_CLNT_CREATE_HARDRTRY        (1UL << 0)
 149#define RPC_CLNT_CREATE_AUTOBIND        (1UL << 2)
 150#define RPC_CLNT_CREATE_NONPRIVPORT     (1UL << 3)
 151#define RPC_CLNT_CREATE_NOPING          (1UL << 4)
 152#define RPC_CLNT_CREATE_DISCRTRY        (1UL << 5)
 153#define RPC_CLNT_CREATE_QUIET           (1UL << 6)
 154#define RPC_CLNT_CREATE_INFINITE_SLOTS  (1UL << 7)
 155#define RPC_CLNT_CREATE_NO_IDLE_TIMEOUT (1UL << 8)
 156#define RPC_CLNT_CREATE_NO_RETRANS_TIMEOUT      (1UL << 9)
 157#define RPC_CLNT_CREATE_SOFTERR         (1UL << 10)
 158#define RPC_CLNT_CREATE_REUSEPORT       (1UL << 11)
 159
 160struct rpc_clnt *rpc_create(struct rpc_create_args *args);
 161struct rpc_clnt *rpc_bind_new_program(struct rpc_clnt *,
 162                                const struct rpc_program *, u32);
 163struct rpc_clnt *rpc_clone_client(struct rpc_clnt *);
 164struct rpc_clnt *rpc_clone_client_set_auth(struct rpc_clnt *,
 165                                rpc_authflavor_t);
 166int             rpc_switch_client_transport(struct rpc_clnt *,
 167                                struct xprt_create *,
 168                                const struct rpc_timeout *);
 169
 170void            rpc_shutdown_client(struct rpc_clnt *);
 171void            rpc_release_client(struct rpc_clnt *);
 172void            rpc_task_release_transport(struct rpc_task *);
 173void            rpc_task_release_client(struct rpc_task *);
 174struct rpc_xprt *rpc_task_get_xprt(struct rpc_clnt *clnt,
 175                struct rpc_xprt *xprt);
 176
 177int             rpcb_create_local(struct net *);
 178void            rpcb_put_local(struct net *);
 179int             rpcb_register(struct net *, u32, u32, int, unsigned short);
 180int             rpcb_v4_register(struct net *net, const u32 program,
 181                                 const u32 version,
 182                                 const struct sockaddr *address,
 183                                 const char *netid);
 184void            rpcb_getport_async(struct rpc_task *);
 185
 186void rpc_prepare_reply_pages(struct rpc_rqst *req, struct page **pages,
 187                             unsigned int base, unsigned int len,
 188                             unsigned int hdrsize);
 189void            rpc_call_start(struct rpc_task *);
 190int             rpc_call_async(struct rpc_clnt *clnt,
 191                               const struct rpc_message *msg, int flags,
 192                               const struct rpc_call_ops *tk_ops,
 193                               void *calldata);
 194int             rpc_call_sync(struct rpc_clnt *clnt,
 195                              const struct rpc_message *msg, int flags);
 196struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred,
 197                               int flags);
 198int             rpc_restart_call_prepare(struct rpc_task *);
 199int             rpc_restart_call(struct rpc_task *);
 200void            rpc_setbufsize(struct rpc_clnt *, unsigned int, unsigned int);
 201struct net *    rpc_net_ns(struct rpc_clnt *);
 202size_t          rpc_max_payload(struct rpc_clnt *);
 203size_t          rpc_max_bc_payload(struct rpc_clnt *);
 204unsigned int    rpc_num_bc_slots(struct rpc_clnt *);
 205void            rpc_force_rebind(struct rpc_clnt *);
 206size_t          rpc_peeraddr(struct rpc_clnt *, struct sockaddr *, size_t);
 207const char      *rpc_peeraddr2str(struct rpc_clnt *, enum rpc_display_format_t);
 208int             rpc_localaddr(struct rpc_clnt *, struct sockaddr *, size_t);
 209
 210int             rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt,
 211                        int (*fn)(struct rpc_clnt *, struct rpc_xprt *, void *),
 212                        void *data);
 213
 214int             rpc_clnt_test_and_add_xprt(struct rpc_clnt *clnt,
 215                        struct rpc_xprt_switch *xps,
 216                        struct rpc_xprt *xprt,
 217                        void *dummy);
 218int             rpc_clnt_add_xprt(struct rpc_clnt *, struct xprt_create *,
 219                        int (*setup)(struct rpc_clnt *,
 220                                struct rpc_xprt_switch *,
 221                                struct rpc_xprt *,
 222                                void *),
 223                        void *data);
 224void            rpc_set_connect_timeout(struct rpc_clnt *clnt,
 225                        unsigned long connect_timeout,
 226                        unsigned long reconnect_timeout);
 227
 228int             rpc_clnt_setup_test_and_add_xprt(struct rpc_clnt *,
 229                        struct rpc_xprt_switch *,
 230                        struct rpc_xprt *,
 231                        void *);
 232
 233const char *rpc_proc_name(const struct rpc_task *task);
 234
 235void rpc_clnt_xprt_switch_put(struct rpc_clnt *);
 236void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *, struct rpc_xprt *);
 237bool rpc_clnt_xprt_switch_has_addr(struct rpc_clnt *clnt,
 238                        const struct sockaddr *sap);
 239void rpc_cleanup_clids(void);
 240
 241static inline int rpc_reply_expected(struct rpc_task *task)
 242{
 243        return (task->tk_msg.rpc_proc != NULL) &&
 244                (task->tk_msg.rpc_proc->p_decode != NULL);
 245}
 246
 247static inline void rpc_task_close_connection(struct rpc_task *task)
 248{
 249        if (task->tk_xprt)
 250                xprt_force_disconnect(task->tk_xprt);
 251}
 252#endif /* _LINUX_SUNRPC_CLNT_H */
 253