GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.sbin/amd/amd/restart.c Lines: 0 44 0.0 %
Date: 2017-11-07 Branches: 0 22 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
35
#include "am.h"
36
37
/*
38
 * Handle an amd restart.
39
 *
40
 * Scan through the mount list finding all "interesting" mount points.
41
 * Next hack up partial data structures and add the mounted file
42
 * system to the list of known filesystems.  This will leave a
43
 * dangling reference to that filesystems, so when the filesystem is
44
 * finally inherited, an extra "free" must be done on it.
45
 *
46
 * This module relies on internal details of other components.  If
47
 * you change something else make *sure* restart() still works.
48
 */
49
void
50
restart()
51
{
52
	/*
53
	 * Read the existing mount table
54
	 */
55
	mntlist *ml, *mlp;
56
57
	/*
58
	 * For each entry, find nfs, ufs or auto mounts
59
	 * and create a partial am_node to represent it.
60
	 */
61
	for (mlp = ml = read_mtab("restart"); mlp; mlp = mlp->mnext) {
62
		struct mntent *me = mlp->mnt;
63
		am_ops *fs_ops = 0;
64
		if (STREQ(me->mnt_type, "ffs")) {
65
			/*
66
			 * UFS entry
67
			 */
68
			fs_ops = &ufs_ops;
69
		} else if (STREQ(me->mnt_type, "nfs")) {
70
			/*
71
			 * NFS entry, or possibly an Amd entry...
72
			 */
73
			int au_pid;
74
			char *colon = strchr(me->mnt_fsname, ':');
75
			if (colon && sscanf(colon, ":(pid%d)", &au_pid) == 1) {
76
				plog(XLOG_WARNING, "%s is an existing automount point", me->mnt_dir);
77
				fs_ops = &sfs_ops;
78
			} else {
79
				fs_ops = &nfs_ops;
80
			}
81
		} else if (STREQ(me->mnt_type, "mfs")) {
82
			/*
83
			 * MFS entry.  Fake with a symlink.
84
			 */
85
			fs_ops = &sfs_ops;
86
		} else {
87
			/*
88
			 * Catch everything else with symlinks to
89
			 * avoid recursive mounts.  This is debatable...
90
			 */
91
			fs_ops = &sfs_ops;
92
		}
93
94
		/*
95
		 * If we found something to do
96
		 */
97
		if (fs_ops) {
98
			mntfs *mf;
99
			am_opts mo;
100
			char *cp;
101
			cp = strchr(me->mnt_fsname, ':');
102
			/*
103
			 * Partially fake up an opts structure
104
			 */
105
			mo.opt_rhost = 0;
106
			mo.opt_rfs = 0;
107
			if (cp) {
108
				*cp = '\0';
109
				mo.opt_rhost = strdup(me->mnt_fsname);
110
				mo.opt_rfs = strdup(cp+1);
111
				*cp = ':';
112
			} else if (fs_ops->ffserver == find_nfs_srvr) {
113
				/*
114
				 * Prototype 4.4 BSD used to end up here -
115
				 * might as well keep the workaround for now
116
				 */
117
				plog(XLOG_WARNING, "NFS server entry assumed to be %s:/", me->mnt_fsname);
118
				mo.opt_rhost = strdup(me->mnt_fsname);
119
				mo.opt_rfs = strdup("/");
120
				me->mnt_fsname = str3cat(me->mnt_fsname, mo.opt_rhost, ":", "/");
121
			}
122
			mo.opt_fs = me->mnt_dir;
123
			mo.opt_opts = me->mnt_opts;
124
125
			/*
126
			 * Make a new mounted filesystem
127
			 */
128
			mf = find_mntfs(fs_ops, &mo, me->mnt_dir,
129
				me->mnt_fsname, "", me->mnt_opts, "");
130
			if (mf->mf_refc == 1) {
131
				mf->mf_flags |= MFF_RESTART|MFF_MOUNTED;
132
				mf->mf_error = 0;	/* Already mounted correctly */
133
				mf->mf_fo = 0;
134
				/*
135
				 * If the restarted type is a link then
136
				 * don't time out.
137
				 */
138
				if (fs_ops == &sfs_ops || fs_ops == &ufs_ops)
139
					mf->mf_flags |= MFF_RSTKEEP;
140
				if (fs_ops->fs_init) {
141
					/*
142
					 * Don't care whether this worked since
143
					 * it is checked again when the fs is
144
					 * inherited.
145
					 */
146
					(void) (*fs_ops->fs_init)(mf);
147
				}
148
149
				plog(XLOG_INFO, "%s restarted fstype %s on %s",
150
					me->mnt_fsname, fs_ops->fs_type, me->mnt_dir);
151
			} else {
152
				/* Something strange happened - two mounts at the same place! */
153
				free_mntfs(mf);
154
			}
155
			/*
156
			 * Clean up mo
157
			 */
158
			free(mo.opt_rhost);
159
			free(mo.opt_rfs);
160
		}
161
	}
162
163
	/*
164
	 * Free the mount list
165
	 */
166
	free_mntlist(ml);
167
}