GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.sbin/amd/amd/amq_subr.c Lines: 0 126 0.0 %
Date: 2017-11-13 Branches: 0 97 0.0 %

Line Branch Exec Source
1
/*
2
 * Copyright (c) 1990 Jan-Simon Pendry
3
 * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
4
 * Copyright (c) 1990, 1993
5
 *	The Regents of the University of California.  All rights reserved.
6
 *
7
 * This code is derived from software contributed to Berkeley by
8
 * Jan-Simon Pendry at Imperial College, London.
9
 *
10
 * Redistribution and use in source and binary forms, with or without
11
 * modification, are permitted provided that the following conditions
12
 * are met:
13
 * 1. Redistributions of source code must retain the above copyright
14
 *    notice, this list of conditions and the following disclaimer.
15
 * 2. Redistributions in binary form must reproduce the above copyright
16
 *    notice, this list of conditions and the following disclaimer in the
17
 *    documentation and/or other materials provided with the distribution.
18
 * 3. Neither the name of the University nor the names of its contributors
19
 *    may be used to endorse or promote products derived from this software
20
 *    without specific prior written permission.
21
 *
22
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32
 * SUCH DAMAGE.
33
 *
34
 *	from: @(#)amq_subr.c	8.1 (Berkeley) 6/6/93
35
 *	$Id: amq_subr.c,v 1.18 2015/01/21 09:50:25 guenther Exp $
36
 */
37
38
/*
39
 * Auxilliary routines for amq tool
40
 */
41
42
#include "am.h"
43
#include "amq.h"
44
#include <ctype.h>
45
46
bool_t	xdr_amq_mount_info_list(XDR *, amq_mount_info_list *);
47
48
void *
49
amqproc_null_57_svc(void *argp, struct svc_req *rqstp)
50
{
51
	static char res;
52
53
	return &res;
54
}
55
56
/*
57
 * Return a sub-tree of mounts
58
 */
59
amq_mount_tree_p *
60
amqproc_mnttree_57_svc(amq_string *argp, struct svc_req *rqstp)
61
{
62
	static am_node *mp;
63
64
	mp = find_ap(*argp);
65
	return (amq_mount_tree_p *) &mp;
66
}
67
68
/*
69
 * Unmount a single node
70
 */
71
void *
72
amqproc_umnt_57_svc(amq_string *argp, struct svc_req *rqstp)
73
{
74
	static char res;
75
76
	am_node *mp = find_ap(*argp);
77
	if (mp)
78
		forcibly_timeout_mp(mp);
79
80
	return &res;
81
}
82
83
/*
84
 * Return global statistics
85
 */
86
amq_mount_stats *
87
amqproc_stats_57_svc(void *argp, struct svc_req *rqstp)
88
{
89
	return (amq_mount_stats *) &amd_stats;
90
}
91
92
/*
93
 * Return the entire tree of mount nodes
94
 */
95
amq_mount_tree_list *
96
amqproc_export_57_svc(void *argp, struct svc_req *rqstp)
97
{
98
	static amq_mount_tree_list aml;
99
100
	aml.amq_mount_tree_list_val = (amq_mount_tree_p *) &exported_ap[0];
101
	aml.amq_mount_tree_list_len = 1;	/* XXX */
102
103
	return &aml;
104
}
105
106
int *
107
amqproc_setopt_57_svc(amq_setopt *argp, struct svc_req *rqstp)
108
{
109
	static int rc;
110
111
	rc = 0;
112
	switch (argp->as_opt) {
113
	case AMOPT_DEBUG:
114
#ifdef DEBUG
115
		if (debug_option(argp->as_str))
116
			rc = EINVAL;
117
#else
118
		rc = EINVAL;
119
#endif /* DEBUG */
120
		break;
121
122
	case AMOPT_LOGFILE:
123
#ifdef not_yet
124
		if (switch_to_logfile(argp->as_str))
125
			rc = EINVAL;
126
#else
127
		rc = EACCES;
128
#endif /* not_yet */
129
		break;
130
131
	case AMOPT_XLOG:
132
		if (switch_option(argp->as_str))
133
			rc = EINVAL;
134
		break;
135
136
	case AMOPT_FLUSHMAPC:
137
		if (amd_state == Run) {
138
			plog(XLOG_INFO, "amq says flush cache");
139
			do_mapc_reload = 0;
140
			flush_nfs_fhandle_cache((fserver *) 0);
141
			flush_srvr_nfs_cache();
142
		}
143
		break;
144
	}
145
	return &rc;
146
}
147
148
amq_mount_info_list *
149
amqproc_getmntfs_57_svc(void *argp, struct svc_req *rqstp)
150
{
151
	extern qelem mfhead;
152
	return (amq_mount_info_list *) &mfhead;	/* XXX */
153
}
154
155
amq_string *
156
amqproc_getvers_57_svc(void *argp, struct svc_req *rqstp)
157
{
158
	static amq_string res;
159
160
	res = "amd 1.1.1.1 of 1995/10/18 08:47:13 bsd44";
161
	return &res;
162
}
163
164
/*
165
 * XDR routines.
166
 */
167
bool_t
168
xdr_amq_string(XDR *xdrs, amq_string *objp)
169
{
170
	if (!xdr_string(xdrs, objp, AMQ_STRLEN)) {
171
		return (FALSE);
172
	}
173
	return (TRUE);
174
}
175
176
bool_t
177
xdr_amq_setopt(XDR *xdrs, amq_setopt *objp)
178
{
179
	if (!xdr_enum(xdrs, (enum_t *)&objp->as_opt)) {
180
		return (FALSE);
181
	}
182
	if (!xdr_string(xdrs, &objp->as_str, AMQ_STRLEN)) {
183
		return (FALSE);
184
	}
185
	return (TRUE);
186
}
187
188
/*
189
 * More XDR routines  - Should be used for OUTPUT ONLY.
190
 */
191
static bool_t
192
xdr_amq_mount_tree_node(XDR *xdrs, amq_mount_tree *objp)
193
{
194
	am_node *mp = (am_node *) objp;
195
	long long mounttime = mp->am_stats.s_mtime;
196
197
	if (!xdr_amq_string(xdrs, &mp->am_mnt->mf_info)) {
198
		return (FALSE);
199
	}
200
	if (!xdr_amq_string(xdrs, &mp->am_path)) {
201
		return (FALSE);
202
	}
203
	if (!xdr_amq_string(xdrs, mp->am_link ? &mp->am_link : &mp->am_mnt->mf_mount)) {
204
		return (FALSE);
205
	}
206
	if (!xdr_amq_string(xdrs, &mp->am_mnt->mf_ops->fs_type)) {
207
		return (FALSE);
208
	}
209
	if (!xdr_int64_t(xdrs, &mounttime)) {
210
		return (FALSE);
211
	}
212
	if (!xdr_u_short(xdrs, &mp->am_stats.s_uid)) {
213
		return (FALSE);
214
	}
215
	if (!xdr_int(xdrs, &mp->am_stats.s_getattr)) {
216
		return (FALSE);
217
	}
218
	if (!xdr_int(xdrs, &mp->am_stats.s_lookup)) {
219
		return (FALSE);
220
	}
221
	if (!xdr_int(xdrs, &mp->am_stats.s_readdir)) {
222
		return (FALSE);
223
	}
224
	if (!xdr_int(xdrs, &mp->am_stats.s_readlink)) {
225
		return (FALSE);
226
	}
227
	if (!xdr_int(xdrs, &mp->am_stats.s_statfs)) {
228
		return (FALSE);
229
	}
230
	return (TRUE);
231
}
232
233
static bool_t
234
xdr_amq_mount_subtree(XDR *xdrs, amq_mount_tree *objp)
235
{
236
	am_node *mp = (am_node *) objp;
237
238
	if (!xdr_amq_mount_tree_node(xdrs, objp)) {
239
		return (FALSE);
240
	}
241
	if (!xdr_pointer(xdrs, (char **)&mp->am_osib, sizeof(amq_mount_tree), xdr_amq_mount_subtree)) {
242
		return (FALSE);
243
	}
244
	if (!xdr_pointer(xdrs, (char **)&mp->am_child, sizeof(amq_mount_tree), xdr_amq_mount_subtree)) {
245
		return (FALSE);
246
	}
247
	return (TRUE);
248
}
249
250
bool_t
251
xdr_amq_mount_tree(XDR *xdrs, amq_mount_tree *objp)
252
{
253
	am_node *mp = (am_node *) objp;
254
	am_node *mnil = 0;
255
256
	if (!xdr_amq_mount_tree_node(xdrs, objp)) {
257
		return (FALSE);
258
	}
259
	if (!xdr_pointer(xdrs, (char **)&mnil, sizeof(amq_mount_tree), xdr_amq_mount_subtree)) {
260
		return (FALSE);
261
	}
262
	if (!xdr_pointer(xdrs, (char **)&mp->am_child, sizeof(amq_mount_tree), xdr_amq_mount_subtree)) {
263
		return (FALSE);
264
	}
265
	return (TRUE);
266
}
267
268
bool_t
269
xdr_amq_mount_tree_p(XDR *xdrs, amq_mount_tree_p *objp)
270
{
271
	if (!xdr_pointer(xdrs, (char **)objp, sizeof(amq_mount_tree), xdr_amq_mount_tree)) {
272
		return (FALSE);
273
	}
274
	return (TRUE);
275
}
276
277
278
bool_t
279
xdr_amq_mount_stats(XDR *xdrs, amq_mount_stats *objp)
280
{
281
	if (!xdr_int(xdrs, &objp->as_drops)) {
282
		return (FALSE);
283
	}
284
	if (!xdr_int(xdrs, &objp->as_stale)) {
285
		return (FALSE);
286
	}
287
	if (!xdr_int(xdrs, &objp->as_mok)) {
288
		return (FALSE);
289
	}
290
	if (!xdr_int(xdrs, &objp->as_merr)) {
291
		return (FALSE);
292
	}
293
	if (!xdr_int(xdrs, &objp->as_uerr)) {
294
		return (FALSE);
295
	}
296
	return (TRUE);
297
}
298
299
300
bool_t
301
xdr_amq_mount_tree_list(XDR *xdrs, amq_mount_tree_list *objp)
302
{
303
	 if (!xdr_array(xdrs, (char **)&objp->amq_mount_tree_list_val, (u_int *)&objp->amq_mount_tree_list_len, ~0, sizeof(amq_mount_tree_p), xdr_amq_mount_tree_p)) {
304
		return (FALSE);
305
	}
306
	return (TRUE);
307
}
308
309
bool_t
310
xdr_amq_mount_info_list(XDR *xdrs, amq_mount_info_list *arg)
311
{
312
	qelem *qhead = (qelem *)arg;
313
314
	/*
315
	 * Compute length of list
316
	 */
317
	mntfs *mf;
318
	u_int len = 0;
319
320
	for (mf = LAST(mntfs, qhead); mf != HEAD(mntfs, qhead); mf = PREV(mntfs, mf)) {
321
		if (!(mf->mf_ops->fs_flags & FS_AMQINFO))
322
			continue;
323
		len++;
324
	}
325
	xdr_u_int(xdrs, &len);
326
327
	/*
328
	 * Send individual data items
329
	 */
330
	for (mf = LAST(mntfs, qhead); mf != HEAD(mntfs, qhead); mf = PREV(mntfs, mf)) {
331
		int up;
332
		if (!(mf->mf_ops->fs_flags & FS_AMQINFO))
333
			continue;
334
335
		if (!xdr_amq_string(xdrs, &mf->mf_ops->fs_type)) {
336
			return (FALSE);
337
		}
338
		if (!xdr_amq_string(xdrs, &mf->mf_mount)) {
339
			return (FALSE);
340
		}
341
		if (!xdr_amq_string(xdrs, &mf->mf_info)) {
342
			return (FALSE);
343
		}
344
		if (!xdr_amq_string(xdrs, &mf->mf_server->fs_host)) {
345
			return (FALSE);
346
		}
347
		if (!xdr_int(xdrs, &mf->mf_error)) {
348
			return (FALSE);
349
		}
350
		if (!xdr_int(xdrs, &mf->mf_refc)) {
351
			return (FALSE);
352
		}
353
		if (mf->mf_server->fs_flags & FSF_ERROR)
354
			up = 0;
355
		else switch (mf->mf_server->fs_flags & (FSF_DOWN|FSF_VALID)) {
356
		case FSF_DOWN|FSF_VALID: up = 0; break;
357
		case FSF_VALID: up = 1; break;
358
		default: up = -1; break;
359
		}
360
		if (!xdr_int(xdrs, &up)) {
361
			return (FALSE);
362
		}
363
	}
364
	return (TRUE);
365
}