2 * Copyright (c) 1997-2006 Erez Zadok
3 * Copyright (c) 1990 Jan-Simon Pendry
4 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
5 * Copyright (c) 1990 The Regents of the University of California.
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry at Imperial College, London.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgment:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 * File: am-utils/amd/amq_subr.c
44 * Auxiliary routines for amq tool
49 #endif /* HAVE_CONFIG_H */
53 /* forward definitions */
54 bool_t xdr_amq_mount_tree_node(XDR *xdrs, amq_mount_tree *objp);
55 bool_t xdr_amq_mount_subtree(XDR *xdrs, amq_mount_tree *objp);
59 amqproc_null_1_svc(voidp argp, struct svc_req *rqstp)
68 * Return a sub-tree of mounts
71 amqproc_mnttree_1_svc(voidp argp, struct svc_req *rqstp)
75 mp = find_ap(*(char **) argp);
76 return (amq_mount_tree_p *) ((void *)&mp);
81 * Unmount a single node
84 amqproc_umnt_1_svc(voidp argp, struct svc_req *rqstp)
87 am_node *mp = find_ap(*(char **) argp);
90 forcibly_timeout_mp(mp);
97 * Return global statistics
100 amqproc_stats_1_svc(voidp argp, struct svc_req *rqstp)
102 return (amq_mount_stats *) ((void *)&amd_stats);
107 * Return the entire tree of mount nodes
109 amq_mount_tree_list *
110 amqproc_export_1_svc(voidp argp, struct svc_req *rqstp)
112 static amq_mount_tree_list aml;
115 mp = get_exported_ap(0);
116 aml.amq_mount_tree_list_val = (amq_mount_tree_p *) ((void *) &mp);
117 aml.amq_mount_tree_list_len = 1; /* XXX */
124 amqproc_setopt_1_svc(voidp argp, struct svc_req *rqstp)
127 amq_setopt *opt = (amq_setopt *) argp;
131 switch (opt->as_opt) {
134 if (debug_option(opt->as_str))
139 if (gopt.logfile && opt->as_str
140 && STREQ(gopt.logfile, opt->as_str)) {
141 if (switch_to_logfile(opt->as_str, orig_umask, 0))
149 if (switch_option(opt->as_str))
153 case AMOPT_FLUSHMAPC:
154 if (amd_state == Run) {
155 plog(XLOG_INFO, "amq says flush cache");
157 flush_nfs_fhandle_cache((fserver *) NULL);
158 flush_srvr_nfs_cache((fserver *) NULL);
167 amq_mount_info_list *
168 amqproc_getmntfs_1_svc(voidp argp, struct svc_req *rqstp)
170 return (amq_mount_info_list *) ((void *)&mfhead); /* XXX */
175 amqproc_getvers_1_svc(voidp argp, struct svc_req *rqstp)
177 static amq_string res;
179 res = get_version_string();
184 /* get PID of remote amd */
186 amqproc_getpid_1_svc(voidp argp, struct svc_req *rqstp)
196 * Process PAWD string of remote pawd tool.
198 * We repeat the resolution of the string until the resolved string resolves
199 * to itself. This ensures that we follow path resolutions through all
200 * possible Amd mount points until we reach some sort of convergence. To
201 * prevent possible infinite loops, we break out of this loop if the strings
202 * do not converge after MAX_PAWD_TRIES times.
205 amqproc_pawd_1_svc(voidp argp, struct svc_req *rqstp)
207 static amq_string res;
208 #define MAX_PAWD_TRIES 10
209 int index, len, maxagain = MAX_PAWD_TRIES;
212 char *dir = *(char **) argp;
213 static char tmp_buf[MAXPATHLEN];
214 char prev_buf[MAXPATHLEN];
216 tmp_buf[0] = prev_buf[0] = '\0'; /* default is empty string: no match */
218 for (mp = get_first_exported_ap(&index);
220 mp = get_next_exported_ap(&index)) {
221 if (STREQ(mp->am_mnt->mf_ops->fs_type, "toplvl"))
223 if (STREQ(mp->am_mnt->mf_ops->fs_type, "auto"))
225 mountpoint = (mp->am_link ? mp->am_link : mp->am_mnt->mf_mount);
226 len = strlen(mountpoint);
229 if (!NSTREQ(mountpoint, dir, len))
231 if (dir[len] != '\0' && dir[len] != '/')
233 xstrlcpy(tmp_buf, mp->am_path, sizeof(tmp_buf));
234 xstrlcat(tmp_buf, &dir[len], sizeof(tmp_buf));
236 } /* end of "for" loop */
237 /* once tmp_buf and prev_buf are equal, break out of "do" loop */
238 if (STREQ(tmp_buf, prev_buf))
241 xstrlcpy(prev_buf, tmp_buf, sizeof(prev_buf));
242 } while (--maxagain);
243 /* check if we couldn't resolve the string after MAX_PAWD_TRIES times */
245 plog(XLOG_WARNING, "path \"%s\" did not resolve after %d tries",
246 tmp_buf, MAX_PAWD_TRIES);
259 xdr_amq_setopt(XDR *xdrs, amq_setopt *objp)
261 if (!xdr_enum(xdrs, (enum_t *) ((voidp) &objp->as_opt))) {
264 if (!xdr_string(xdrs, &objp->as_str, AMQ_STRLEN)) {
272 * More XDR routines - Should be used for OUTPUT ONLY.
275 xdr_amq_mount_tree_node(XDR *xdrs, amq_mount_tree *objp)
277 am_node *mp = (am_node *) objp;
280 if (!xdr_amq_string(xdrs, &mp->am_mnt->mf_info)) {
283 if (!xdr_amq_string(xdrs, &mp->am_path)) {
286 if (!xdr_amq_string(xdrs, mp->am_link ? &mp->am_link : &mp->am_mnt->mf_mount)) {
289 if (!xdr_amq_string(xdrs, &mp->am_mnt->mf_ops->fs_type)) {
292 mtime = mp->am_stats.s_mtime;
293 if (!xdr_long(xdrs, &mtime)) {
296 if (!xdr_u_short(xdrs, &mp->am_stats.s_uid)) {
299 if (!xdr_int(xdrs, &mp->am_stats.s_getattr)) {
302 if (!xdr_int(xdrs, &mp->am_stats.s_lookup)) {
305 if (!xdr_int(xdrs, &mp->am_stats.s_readdir)) {
308 if (!xdr_int(xdrs, &mp->am_stats.s_readlink)) {
311 if (!xdr_int(xdrs, &mp->am_stats.s_statfs)) {
319 xdr_amq_mount_subtree(XDR *xdrs, amq_mount_tree *objp)
321 am_node *mp = (am_node *) objp;
323 if (!xdr_amq_mount_tree_node(xdrs, objp)) {
326 if (!xdr_pointer(xdrs,
327 (char **) ((voidp) &mp->am_osib),
328 sizeof(amq_mount_tree),
329 (XDRPROC_T_TYPE) xdr_amq_mount_subtree)) {
332 if (!xdr_pointer(xdrs,
333 (char **) ((voidp) &mp->am_child),
334 sizeof(amq_mount_tree),
335 (XDRPROC_T_TYPE) xdr_amq_mount_subtree)) {
343 xdr_amq_mount_tree(XDR *xdrs, amq_mount_tree *objp)
345 am_node *mp = (am_node *) objp;
346 am_node *mnil = NULL;
348 if (!xdr_amq_mount_tree_node(xdrs, objp)) {
351 if (!xdr_pointer(xdrs,
352 (char **) ((voidp) &mnil),
353 sizeof(amq_mount_tree),
354 (XDRPROC_T_TYPE) xdr_amq_mount_subtree)) {
357 if (!xdr_pointer(xdrs,
358 (char **) ((voidp) &mp->am_child),
359 sizeof(amq_mount_tree),
360 (XDRPROC_T_TYPE) xdr_amq_mount_subtree)) {
368 xdr_amq_mount_tree_p(XDR *xdrs, amq_mount_tree_p *objp)
370 if (!xdr_pointer(xdrs, (char **) objp, sizeof(amq_mount_tree), (XDRPROC_T_TYPE) xdr_amq_mount_tree)) {
378 xdr_amq_mount_stats(XDR *xdrs, amq_mount_stats *objp)
380 if (!xdr_int(xdrs, &objp->as_drops)) {
383 if (!xdr_int(xdrs, &objp->as_stale)) {
386 if (!xdr_int(xdrs, &objp->as_mok)) {
389 if (!xdr_int(xdrs, &objp->as_merr)) {
392 if (!xdr_int(xdrs, &objp->as_uerr)) {
401 xdr_amq_mount_tree_list(XDR *xdrs, amq_mount_tree_list *objp)
404 (char **) ((voidp) &objp->amq_mount_tree_list_val),
405 (u_int *) &objp->amq_mount_tree_list_len,
407 sizeof(amq_mount_tree_p),
408 (XDRPROC_T_TYPE) xdr_amq_mount_tree_p)) {
417 * Compute length of list
420 xdr_amq_mount_info_qelem(XDR *xdrs, qelem *qhead)
425 for (mf = AM_LAST(mntfs, qhead); mf != HEAD(mntfs, qhead); mf = PREV(mntfs, mf)) {
426 if (!(mf->mf_fsflags & FS_AMQINFO))
430 xdr_u_int(xdrs, &len);
433 * Send individual data items
435 for (mf = AM_LAST(mntfs, qhead); mf != HEAD(mntfs, qhead); mf = PREV(mntfs, mf)) {
437 if (!(mf->mf_fsflags & FS_AMQINFO))
440 if (!xdr_amq_string(xdrs, &mf->mf_ops->fs_type)) {
443 if (!xdr_amq_string(xdrs, &mf->mf_mount)) {
446 if (!xdr_amq_string(xdrs, &mf->mf_info)) {
449 if (!xdr_amq_string(xdrs, &mf->mf_server->fs_host)) {
452 if (!xdr_int(xdrs, &mf->mf_error)) {
455 if (!xdr_int(xdrs, &mf->mf_refc)) {
458 if (FSRV_ERROR(mf->mf_server) || FSRV_ISDOWN(mf->mf_server))
460 else if (FSRV_ISUP(mf->mf_server))
464 if (!xdr_int(xdrs, &up)) {
473 xdr_pri_free(XDRPROC_T_TYPE xdr_args, caddr_t args_ptr)
478 return ((*xdr_args) (&xdr, (caddr_t *) args_ptr));