Lines Matching defs:clnt
3 * linux/net/sunrpc/clnt.c
36 #include <linux/sunrpc/clnt.h>
77 static int rpc_ping(struct rpc_clnt *clnt);
80 static void rpc_register_client(struct rpc_clnt *clnt)
82 struct net *net = rpc_net_ns(clnt);
86 list_add(&clnt->cl_clients, &sn->all_clients);
90 static void rpc_unregister_client(struct rpc_clnt *clnt)
92 struct net *net = rpc_net_ns(clnt);
96 list_del(&clnt->cl_clients);
100 static void __rpc_clnt_remove_pipedir(struct rpc_clnt *clnt)
102 rpc_remove_client_dir(clnt);
105 static void rpc_clnt_remove_pipedir(struct rpc_clnt *clnt)
107 struct net *net = rpc_net_ns(clnt);
112 if (pipefs_sb == clnt->pipefs_sb)
113 __rpc_clnt_remove_pipedir(clnt);
119 struct rpc_clnt *clnt)
122 const char *dir_name = clnt->cl_program->pipe_dir_name;
132 snprintf(name, sizeof(name), "clnt%x", (unsigned int)clntid++);
134 dentry = rpc_create_client_dir(dir, name, clnt);
149 rpc_setup_pipedir(struct super_block *pipefs_sb, struct rpc_clnt *clnt)
153 clnt->pipefs_sb = pipefs_sb;
155 if (clnt->cl_program->pipe_dir_name != NULL) {
156 dentry = rpc_setup_pipedir_sb(pipefs_sb, clnt);
163 static int rpc_clnt_skip_event(struct rpc_clnt *clnt, unsigned long event)
165 if (clnt->cl_program->pipe_dir_name == NULL)
170 if (clnt->cl_pipedir_objects.pdh_dentry != NULL)
172 if (atomic_read(&clnt->cl_count) == 0)
176 if (clnt->cl_pipedir_objects.pdh_dentry == NULL)
183 static int __rpc_clnt_handle_event(struct rpc_clnt *clnt, unsigned long event,
190 dentry = rpc_setup_pipedir_sb(sb, clnt);
197 __rpc_clnt_remove_pipedir(clnt);
206 static int __rpc_pipefs_event(struct rpc_clnt *clnt, unsigned long event,
211 for (;; clnt = clnt->cl_parent) {
212 if (!rpc_clnt_skip_event(clnt, event))
213 error = __rpc_clnt_handle_event(clnt, event, sb);
214 if (error || clnt == clnt->cl_parent)
223 struct rpc_clnt *clnt;
226 list_for_each_entry(clnt, &sn->all_clients, cl_clients) {
227 if (rpc_clnt_skip_event(clnt, event))
230 return clnt;
240 struct rpc_clnt *clnt;
243 while ((clnt = rpc_get_client_for_event(sb->s_fs_info, event))) {
244 error = __rpc_pipefs_event(clnt, event, sb);
266 static struct rpc_xprt *rpc_clnt_set_transport(struct rpc_clnt *clnt,
272 spin_lock(&clnt->cl_lock);
273 old = rcu_dereference_protected(clnt->cl_xprt,
274 lockdep_is_held(&clnt->cl_lock));
277 clnt->cl_autobind = 1;
279 clnt->cl_timeout = timeout;
280 rcu_assign_pointer(clnt->cl_xprt, xprt);
281 spin_unlock(&clnt->cl_lock);
286 static void rpc_clnt_set_nodename(struct rpc_clnt *clnt, const char *nodename)
288 clnt->cl_nodelen = strlcpy(clnt->cl_nodename,
289 nodename, sizeof(clnt->cl_nodename));
292 static int rpc_client_register(struct rpc_clnt *clnt,
301 struct net *net = rpc_net_ns(clnt);
305 rpc_clnt_debugfs_register(clnt);
309 err = rpc_setup_pipedir(pipefs_sb, clnt);
314 rpc_register_client(clnt);
318 auth = rpcauth_create(&auth_args, clnt);
328 rpc_unregister_client(clnt);
329 __rpc_clnt_remove_pipedir(clnt);
333 rpc_clnt_debugfs_unregister(clnt);
344 static int rpc_alloc_clid(struct rpc_clnt *clnt)
351 clnt->cl_clid = clid;
355 static void rpc_free_clid(struct rpc_clnt *clnt)
357 ida_simple_remove(&rpc_clids, clnt->cl_clid);
367 struct rpc_clnt *clnt = NULL;
384 clnt = kzalloc(sizeof(*clnt), GFP_KERNEL);
385 if (!clnt)
387 clnt->cl_parent = parent ? : clnt;
389 err = rpc_alloc_clid(clnt);
393 clnt->cl_cred = get_cred(args->cred);
394 clnt->cl_procinfo = version->procs;
395 clnt->cl_maxproc = version->nrprocs;
396 clnt->cl_prog = args->prognumber ? : program->number;
397 clnt->cl_vers = version->number;
398 clnt->cl_stats = args->stats ? : program->stats;
399 clnt->cl_metrics = rpc_alloc_iostats(clnt);
400 rpc_init_pipe_dir_head(&clnt->cl_pipedir_objects);
402 if (clnt->cl_metrics == NULL)
404 clnt->cl_program = program;
405 INIT_LIST_HEAD(&clnt->cl_tasks);
406 spin_lock_init(&clnt->cl_lock);
410 memcpy(&clnt->cl_timeout_default, args->timeout,
411 sizeof(clnt->cl_timeout_default));
412 timeout = &clnt->cl_timeout_default;
415 rpc_clnt_set_transport(clnt, xprt, timeout);
416 xprt_iter_init(&clnt->cl_xpi, xps);
419 clnt->cl_rtt = &clnt->cl_rtt_default;
420 rpc_init_rtt(&clnt->cl_rtt_default, clnt->cl_timeout->to_initval);
422 atomic_set(&clnt->cl_count, 1);
427 rpc_clnt_set_nodename(clnt, nodename);
429 err = rpc_client_register(clnt, args->authflavor, args->client_name);
435 trace_rpc_clnt_new(clnt, xprt, program->name, args->servername);
436 return clnt;
439 rpc_free_iostats(clnt->cl_metrics);
441 put_cred(clnt->cl_cred);
442 rpc_free_clid(clnt);
444 kfree(clnt);
457 struct rpc_clnt *clnt = NULL;
475 clnt = rpc_new_client(args, xps, xprt, NULL);
476 if (IS_ERR(clnt))
477 return clnt;
480 int err = rpc_ping(clnt);
482 rpc_shutdown_client(clnt);
487 clnt->cl_softrtry = 1;
489 clnt->cl_softrtry = 0;
491 clnt->cl_softerr = 1;
495 clnt->cl_autobind = 1;
497 clnt->cl_noretranstimeo = 1;
499 clnt->cl_discrtry = 1;
501 clnt->cl_chatty = 1;
503 return clnt;
529 struct rpc_clnt *clnt;
596 clnt = rpc_create_xprt(args, xprt);
597 if (IS_ERR(clnt) || args->nconnect <= 1)
598 return clnt;
601 if (rpc_clnt_add_xprt(clnt, &xprtargs, NULL, NULL) < 0)
604 return clnt;
614 struct rpc_clnt *clnt)
623 xprt = xprt_get(rcu_dereference(clnt->cl_xprt));
624 xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch));
632 args->nodename = clnt->cl_nodename;
634 new = rpc_new_client(args, xps, xprt, clnt);
640 new->cl_softrtry = clnt->cl_softrtry;
641 new->cl_softerr = clnt->cl_softerr;
642 new->cl_noretranstimeo = clnt->cl_noretranstimeo;
643 new->cl_discrtry = clnt->cl_discrtry;
644 new->cl_chatty = clnt->cl_chatty;
645 new->cl_principal = clnt->cl_principal;
649 trace_rpc_clnt_clone_err(clnt, err);
656 * @clnt: RPC client whose parameters are copied
660 struct rpc_clnt *rpc_clone_client(struct rpc_clnt *clnt)
663 .program = clnt->cl_program,
664 .prognumber = clnt->cl_prog,
665 .version = clnt->cl_vers,
666 .authflavor = clnt->cl_auth->au_flavor,
667 .cred = clnt->cl_cred,
668 .stats = clnt->cl_stats,
670 return __rpc_clone_client(&args, clnt);
677 * @clnt: RPC client whose parameters are copied
683 rpc_clone_client_set_auth(struct rpc_clnt *clnt, rpc_authflavor_t flavor)
686 .program = clnt->cl_program,
687 .prognumber = clnt->cl_prog,
688 .version = clnt->cl_vers,
690 .cred = clnt->cl_cred,
691 .stats = clnt->cl_stats,
693 return __rpc_clone_client(&args, clnt);
699 * @clnt: pointer to a struct rpc_clnt
704 * rpc_clnt structure 'clnt' to allow it to connect to a mirrored NFS
708 * Returns zero if "clnt" is now using the new xprt. Otherwise a
709 * negative errno is returned, and "clnt" continues to use the old
712 int rpc_switch_client_transport(struct rpc_clnt *clnt,
733 pseudoflavor = clnt->cl_auth->au_flavor;
735 old_timeo = clnt->cl_timeout;
736 old = rpc_clnt_set_transport(clnt, xprt, timeout);
737 oldxps = xprt_iter_xchg_switch(&clnt->cl_xpi, xps);
739 rpc_unregister_client(clnt);
740 __rpc_clnt_remove_pipedir(clnt);
741 rpc_clnt_debugfs_unregister(clnt);
744 * A new transport was created. "clnt" therefore
745 * becomes the root of a new cl_parent tree. clnt's
748 parent = clnt->cl_parent;
749 clnt->cl_parent = clnt;
756 err = rpc_client_register(clnt, pseudoflavor, NULL);
761 if (parent != clnt)
765 trace_rpc_clnt_replace_xprt(clnt);
769 xps = xprt_iter_xchg_switch(&clnt->cl_xpi, oldxps);
770 rpc_clnt_set_transport(clnt, old, old_timeo);
771 clnt->cl_parent = parent;
772 rpc_client_register(clnt, pseudoflavor, NULL);
775 trace_rpc_clnt_replace_xprt_err(clnt);
781 int rpc_clnt_xprt_iter_init(struct rpc_clnt *clnt, struct rpc_xprt_iter *xpi)
786 xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch));
797 * @clnt: pointer to client
802 * client and applies the function fn(clnt, xprt, data).
806 int rpc_clnt_iterate_for_each_xprt(struct rpc_clnt *clnt,
813 ret = rpc_clnt_xprt_iter_init(clnt, &xpi);
821 ret = fn(clnt, xprt, data);
835 void rpc_killall_tasks(struct rpc_clnt *clnt)
840 if (list_empty(&clnt->cl_tasks))
846 trace_rpc_clnt_killall(clnt);
847 spin_lock(&clnt->cl_lock);
848 list_for_each_entry(rovr, &clnt->cl_tasks, tk_task)
850 spin_unlock(&clnt->cl_lock);
858 void rpc_shutdown_client(struct rpc_clnt *clnt)
862 trace_rpc_clnt_shutdown(clnt);
864 while (!list_empty(&clnt->cl_tasks)) {
865 rpc_killall_tasks(clnt);
867 list_empty(&clnt->cl_tasks), 1*HZ);
870 rpc_release_client(clnt);
879 struct rpc_clnt *clnt = container_of(work, struct rpc_clnt, cl_work);
881 trace_rpc_clnt_free(clnt);
887 rpc_clnt_debugfs_unregister(clnt);
888 rpc_free_clid(clnt);
889 rpc_clnt_remove_pipedir(clnt);
890 xprt_put(rcu_dereference_raw(clnt->cl_xprt));
892 kfree(clnt);
896 rpc_free_client(struct rpc_clnt *clnt)
900 trace_rpc_clnt_release(clnt);
901 if (clnt->cl_parent != clnt)
902 parent = clnt->cl_parent;
903 rpc_unregister_client(clnt);
904 rpc_free_iostats(clnt->cl_metrics);
905 clnt->cl_metrics = NULL;
906 xprt_iter_destroy(&clnt->cl_xpi);
907 put_cred(clnt->cl_cred);
909 INIT_WORK(&clnt->cl_work, rpc_free_client_work);
910 schedule_work(&clnt->cl_work);
918 rpc_free_auth(struct rpc_clnt *clnt)
920 if (clnt->cl_auth == NULL)
921 return rpc_free_client(clnt);
928 atomic_inc(&clnt->cl_count);
929 rpcauth_release(clnt->cl_auth);
930 clnt->cl_auth = NULL;
931 if (atomic_dec_and_test(&clnt->cl_count))
932 return rpc_free_client(clnt);
940 rpc_release_client(struct rpc_clnt *clnt)
943 if (list_empty(&clnt->cl_tasks))
945 if (!atomic_dec_and_test(&clnt->cl_count))
947 clnt = rpc_free_auth(clnt);
948 } while (clnt != NULL);
974 struct rpc_clnt *clnt;
977 clnt = __rpc_clone_client(&args, old);
978 if (IS_ERR(clnt))
980 err = rpc_ping(clnt);
982 rpc_shutdown_client(clnt);
983 clnt = ERR_PTR(err);
986 return clnt;
991 rpc_task_get_xprt(struct rpc_clnt *clnt, struct rpc_xprt *xprt)
998 xps = rcu_dereference(clnt->cl_xpi.xpi_xpswitch);
1007 rpc_task_release_xprt(struct rpc_clnt *clnt, struct rpc_xprt *xprt)
1013 xps = rcu_dereference(clnt->cl_xpi.xpi_xpswitch);
1036 struct rpc_clnt *clnt = task->tk_client;
1039 if (clnt != NULL) {
1041 spin_lock(&clnt->cl_lock);
1043 spin_unlock(&clnt->cl_lock);
1046 rpc_release_client(clnt);
1051 rpc_task_get_first_xprt(struct rpc_clnt *clnt)
1056 xprt = xprt_get(rcu_dereference(clnt->cl_xprt));
1058 return rpc_task_get_xprt(clnt, xprt);
1062 rpc_task_get_next_xprt(struct rpc_clnt *clnt)
1064 return rpc_task_get_xprt(clnt, xprt_iter_get_next(&clnt->cl_xpi));
1068 void rpc_task_set_transport(struct rpc_task *task, struct rpc_clnt *clnt)
1073 task->tk_xprt = rpc_task_get_first_xprt(clnt);
1075 task->tk_xprt = rpc_task_get_next_xprt(clnt);
1079 void rpc_task_set_client(struct rpc_task *task, struct rpc_clnt *clnt)
1082 if (clnt != NULL) {
1083 rpc_task_set_transport(task, clnt);
1084 task->tk_client = clnt;
1085 atomic_inc(&clnt->cl_count);
1086 if (clnt->cl_softrtry)
1088 if (clnt->cl_softerr)
1090 if (clnt->cl_noretranstimeo)
1092 if (atomic_read(&clnt->cl_swapper))
1095 spin_lock(&clnt->cl_lock);
1096 list_add_tail(&task->tk_task, &clnt->cl_tasks);
1097 spin_unlock(&clnt->cl_lock);
1153 * @clnt: pointer to RPC client
1157 int rpc_call_sync(struct rpc_clnt *clnt, const struct rpc_message *msg, int flags)
1161 .rpc_client = clnt,
1186 * @clnt: pointer to RPC client
1193 rpc_call_async(struct rpc_clnt *clnt, const struct rpc_message *msg, int flags,
1198 .rpc_client = clnt,
1278 * rpc_peeraddr - extract remote peer address from clnt's xprt
1279 * @clnt: RPC client structure
1285 size_t rpc_peeraddr(struct rpc_clnt *clnt, struct sockaddr *buf, size_t bufsize)
1291 xprt = rcu_dereference(clnt->cl_xprt);
1305 * @clnt: RPC client structure
1312 const char *rpc_peeraddr2str(struct rpc_clnt *clnt,
1317 xprt = rcu_dereference(clnt->cl_xprt);
1436 * @clnt: RPC client structure
1450 int rpc_localaddr(struct rpc_clnt *clnt, struct sockaddr *buf, size_t buflen)
1460 xprt = rcu_dereference(clnt->cl_xprt);
1477 rpc_setbufsize(struct rpc_clnt *clnt, unsigned int sndsize, unsigned int rcvsize)
1482 xprt = rcu_dereference(clnt->cl_xprt);
1491 * @clnt: RPC client to query
1494 struct net *rpc_net_ns(struct rpc_clnt *clnt)
1499 ret = rcu_dereference(clnt->cl_xprt)->xprt_net;
1507 * @clnt: RPC client to query
1514 size_t rpc_max_payload(struct rpc_clnt *clnt)
1519 ret = rcu_dereference(clnt->cl_xprt)->max_payload;
1527 * @clnt: RPC client to query
1529 size_t rpc_max_bc_payload(struct rpc_clnt *clnt)
1535 xprt = rcu_dereference(clnt->cl_xprt);
1542 unsigned int rpc_num_bc_slots(struct rpc_clnt *clnt)
1548 xprt = rcu_dereference(clnt->cl_xprt);
1557 * @clnt: client to rebind
1560 void rpc_force_rebind(struct rpc_clnt *clnt)
1562 if (clnt->cl_autobind) {
1564 xprt_clear_bound(rcu_dereference(clnt->cl_xprt));
1640 struct rpc_clnt *clnt = task->tk_client;
1646 if (clnt->cl_program->version[clnt->cl_vers])
1647 clnt->cl_program->version[clnt->cl_vers]->counts[idx]++;
1648 clnt->cl_stats->rpccnt++;
1650 rpc_task_set_transport(task, clnt);
2061 struct rpc_clnt *clnt = task->tk_client;
2072 clnt->cl_stats->netreconn++;
2087 if (clnt->cl_autobind) {
2088 rpc_force_rebind(clnt);
2306 struct rpc_clnt *clnt = task->tk_client;
2340 rpc_force_rebind(clnt);
2357 if (clnt->cl_chatty)
2359 clnt->cl_program->name, -status);
2381 struct rpc_clnt *clnt = task->tk_client;
2409 if (clnt->cl_chatty) {
2412 clnt->cl_program->name,
2424 if (clnt->cl_chatty) {
2427 clnt->cl_program->name,
2431 rpc_force_rebind(clnt);
2445 struct rpc_clnt *clnt = task->tk_client;
2456 if (clnt->cl_chatty) {
2458 clnt->cl_program->name,
2513 struct rpc_clnt *clnt = task->tk_client;
2525 *p++ = cpu_to_be32(clnt->cl_prog);
2526 *p++ = cpu_to_be32(clnt->cl_vers);
2542 struct rpc_clnt *clnt = task->tk_client;
2595 clnt->cl_stats->rpcgarbage++;
2680 static int rpc_ping(struct rpc_clnt *clnt)
2686 err = rpc_call_sync(clnt, &msg, RPC_TASK_SOFT | RPC_TASK_SOFTCONN |
2692 struct rpc_task *rpc_call_null_helper(struct rpc_clnt *clnt,
2700 .rpc_client = clnt,
2713 struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred, int flags)
2715 return rpc_call_null_helper(clnt, NULL, cred, flags, NULL, NULL);
2748 * @clnt: pointer to struct rpc_clnt
2753 int rpc_clnt_test_and_add_xprt(struct rpc_clnt *clnt,
2770 task = rpc_call_null_helper(clnt, xprt, NULL, RPC_TASK_ASYNC,
2791 * @clnt: struct rpc_clnt to get the new transport
2797 int rpc_clnt_setup_test_and_add_xprt(struct rpc_clnt *clnt,
2813 task = rpc_call_null_helper(clnt, xprt, NULL, 0, NULL, NULL);
2825 xtest->add_xprt_test(clnt, xprt, xtest->data);
2843 * @clnt: pointer to struct rpc_clnt
2849 * adds it to clnt.
2854 int rpc_clnt_add_xprt(struct rpc_clnt *clnt,
2870 xps = xprt_switch_get(rcu_dereference(clnt->cl_xpi.xpi_xpswitch));
2871 xprt = xprt_iter_xprt(&clnt->cl_xpi);
2897 ret = setup(clnt, xps, xprt, data);
2916 rpc_xprt_set_connect_timeout(struct rpc_clnt *clnt,
2930 rpc_set_connect_timeout(struct rpc_clnt *clnt,
2938 rpc_clnt_iterate_for_each_xprt(clnt,
2944 void rpc_clnt_xprt_switch_put(struct rpc_clnt *clnt)
2947 xprt_switch_put(rcu_dereference(clnt->cl_xpi.xpi_xpswitch));
2952 void rpc_clnt_xprt_switch_add_xprt(struct rpc_clnt *clnt, struct rpc_xprt *xprt)
2955 rpc_xprt_switch_add_xprt(rcu_dereference(clnt->cl_xpi.xpi_xpswitch),
2961 bool rpc_clnt_xprt_switch_has_addr(struct rpc_clnt *clnt,
2968 xps = rcu_dereference(clnt->cl_xpi.xpi_xpswitch);
2982 static void rpc_show_task(const struct rpc_clnt *clnt,
2992 clnt, task->tk_rqstp, rpc_task_timeout(task), task->tk_ops,
2993 clnt->cl_program->name, clnt->cl_vers, rpc_proc_name(task),
2999 struct rpc_clnt *clnt;
3005 list_for_each_entry(clnt, &sn->all_clients, cl_clients) {
3006 spin_lock(&clnt->cl_lock);
3007 list_for_each_entry(task, &clnt->cl_tasks, tk_task) {
3012 rpc_show_task(clnt, task);
3014 spin_unlock(&clnt->cl_lock);
3022 rpc_clnt_swap_activate_callback(struct rpc_clnt *clnt,
3030 rpc_clnt_swap_activate(struct rpc_clnt *clnt)
3032 while (clnt != clnt->cl_parent)
3033 clnt = clnt->cl_parent;
3034 if (atomic_inc_return(&clnt->cl_swapper) == 1)
3035 return rpc_clnt_iterate_for_each_xprt(clnt,
3042 rpc_clnt_swap_deactivate_callback(struct rpc_clnt *clnt,
3051 rpc_clnt_swap_deactivate(struct rpc_clnt *clnt)
3053 while (clnt != clnt->cl_parent)
3054 clnt = clnt->cl_parent;
3055 if (atomic_dec_if_positive(&clnt->cl_swapper) == 0)
3056 rpc_clnt_iterate_for_each_xprt(clnt,