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