restart.c revision 38494
1/* 2 * Copyright (c) 1997-1998 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. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Jan-Simon Pendry at Imperial College, London. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 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 acknowledgement: 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. 26 * 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 37 * SUCH DAMAGE. 38 * 39 * %W% (Berkeley) %G% 40 * 41 * $Id: restart.c,v 5.2.2.2 1992/08/02 10:42:21 jsp Exp $ 42 * 43 */ 44 45#ifdef HAVE_CONFIG_H 46# include <config.h> 47#endif /* HAVE_CONFIG_H */ 48#include <am_defs.h> 49#include <amd.h> 50 51 52/* 53 * Handle an amd restart. 54 * 55 * Scan through the mount list finding all "interesting" mount points. 56 * Next hack up partial data structures and add the mounted file 57 * system to the list of known filesystems. This will leave a 58 * dangling reference to that filesystems, so when the filesystem is 59 * finally inherited, an extra "free" must be done on it. 60 * 61 * This module relies on internal details of other components. If 62 * you change something else make *sure* restart() still works. 63 */ 64void 65restart(void) 66{ 67 /* 68 * Read the existing mount table 69 */ 70 mntlist *ml, *mlp; 71 72 /* 73 * For each entry, find nfs, ufs or auto mounts 74 * and create a partial am_node to represent it. 75 */ 76 for (mlp = ml = read_mtab("restart", mnttab_file_name); 77 mlp; 78 mlp = mlp->mnext) { 79 mntent_t *me = mlp->mnt; 80 am_ops *fs_ops = 0; 81 if (STREQ(me->mnt_type, MNTTAB_TYPE_UFS)) { 82 /* 83 * UFS entry 84 */ 85 fs_ops = &ufs_ops; 86 } else if (STREQ(me->mnt_type, MNTTAB_TYPE_NFS)) { 87 /* 88 * NFS entry, or possibly an Amd entry... 89 * The mnt_fsname for daemon mount points is 90 * host:(pidXXX) 91 * or (seen on Solaris) 92 * host:daemon(pidXXX) 93 */ 94 char *colon = strchr(me->mnt_fsname, ':'); 95 96 if (colon && strstr(colon, "(pid")) { 97 plog(XLOG_WARNING, "%s is an existing automount point", me->mnt_dir); 98 fs_ops = &amfs_link_ops; 99 } else { 100 fs_ops = &nfs_ops; 101 } 102#ifdef MNTTAB_TYPE_NFS3 103 } else if (STREQ(me->mnt_type, MNTTAB_TYPE_NFS3)) { 104 fs_ops = &nfs_ops; 105#endif /* MNTTAB_TYPE_NFS3 */ 106#ifdef MNTTAB_TYPE_LOFS 107 } else if (STREQ(me->mnt_type, MNTTAB_TYPE_LOFS)) { 108 fs_ops = &lofs_ops; 109#endif /* MNTTAB_TYPE_LOFS */ 110#ifdef MNTTAB_TYPE_CDFS 111 } else if (STREQ(me->mnt_type, MNTTAB_TYPE_CDFS)) { 112 fs_ops = &cdfs_ops; 113#endif /* MNTTAB_TYPE_CDFS */ 114#ifdef MNTTAB_TYPE_PCFS 115 } else if (STREQ(me->mnt_type, MNTTAB_TYPE_PCFS)) { 116 fs_ops = &pcfs_ops; 117#endif /* MNTTAB_TYPE_PCFS */ 118#ifdef MNTTAB_TYPE_MFS 119 } else if (STREQ(me->mnt_type, MNTTAB_TYPE_MFS)) { 120 /* 121 * MFS entry. Fake with a symlink. 122 */ 123 fs_ops = &amfs_link_ops; 124#endif /* MNTTAB_TYPE_MFS */ 125 } else { 126 /* 127 * Catch everything else with symlinks to 128 * avoid recursive mounts. This is debatable... 129 */ 130 fs_ops = &amfs_link_ops; 131 } 132 133 /* 134 * If we found something to do 135 */ 136 if (fs_ops) { 137 mntfs *mf; 138 am_opts mo; 139 char *cp; 140 cp = strchr(me->mnt_fsname, ':'); 141 142 /* 143 * Partially fake up an opts structure 144 */ 145 mo.opt_rhost = 0; 146 mo.opt_rfs = 0; 147 if (cp) { 148 *cp = '\0'; 149 mo.opt_rhost = strdup(me->mnt_fsname); 150 mo.opt_rfs = strdup(cp + 1); 151 *cp = ':'; 152 } else if (fs_ops->ffserver == find_nfs_srvr) { 153 /* 154 * Prototype 4.4 BSD used to end up here - 155 * might as well keep the workaround for now 156 */ 157 plog(XLOG_WARNING, "NFS server entry assumed to be %s:/", me->mnt_fsname); 158 mo.opt_rhost = strdup(me->mnt_fsname); 159 mo.opt_rfs = strdup("/"); 160 me->mnt_fsname = str3cat(me->mnt_fsname, mo.opt_rhost, ":", "/"); 161 } 162 mo.opt_fs = me->mnt_dir; 163 mo.opt_opts = me->mnt_opts; 164 165 /* 166 * Make a new mounted filesystem 167 */ 168 mf = find_mntfs(fs_ops, &mo, me->mnt_dir, 169 me->mnt_fsname, "", me->mnt_opts, ""); 170 if (mf->mf_refc == 1) { 171 mf->mf_flags |= MFF_RESTART | MFF_MOUNTED; 172 mf->mf_error = 0; /* Already mounted correctly */ 173 mf->mf_fo = 0; 174 /* 175 * If the restarted type is a link then 176 * don't time out. 177 */ 178 if (fs_ops == &amfs_link_ops || fs_ops == &ufs_ops) 179 mf->mf_flags |= MFF_RSTKEEP; 180 if (fs_ops->fs_init) { 181 /* 182 * Don't care whether this worked since 183 * it is checked again when the fs is 184 * inherited. 185 */ 186 (void) (*fs_ops->fs_init) (mf); 187 } 188 plog(XLOG_INFO, "%s restarted fstype %s on %s", 189 me->mnt_fsname, fs_ops->fs_type, me->mnt_dir); 190 } else { 191 /* Something strange happened - two mounts at the same place! */ 192 free_mntfs(mf); 193 } 194 /* 195 * Clean up mo 196 */ 197 if (mo.opt_rhost) 198 XFREE(mo.opt_rhost); 199 if (mo.opt_rfs) 200 XFREE(mo.opt_rfs); 201 } 202 } 203 204 /* 205 * Free the mount list 206 */ 207 free_mntlist(ml); 208} 209