home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume21 / amd / part04 / restart.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-10  |  4.4 KB  |  162 lines

  1. /*
  2.  * $Id: restart.c,v 5.1.1.2 90/01/11 17:18:41 jsp Exp Locker: jsp $
  3.  *
  4.  * Copyright (c) 1990 Jan-Simon Pendry
  5.  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
  6.  * Copyright (c) 1990 The Regents of the University of California.
  7.  * All rights reserved.
  8.  *
  9.  * This code is derived from software contributed to Berkeley by
  10.  * Jan-Simon Pendry at Imperial College, London.
  11.  *
  12.  * Redistribution and use in source and binary forms are permitted
  13.  * provided that the above copyright notice and this paragraph are
  14.  * duplicated in all such forms and that any documentation,
  15.  * advertising materials, and other materials related to such
  16.  * distribution and use acknowledge that the software was developed
  17.  * by Imperial College of Science, Technology and Medicine, London, UK.
  18.  * The names of the College and University may not be used to endorse
  19.  * or promote products derived from this software without specific
  20.  * prior written permission.
  21.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  22.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  23.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  24.  *
  25.  *    %W% (Berkeley) %G%
  26.  */
  27.  
  28. #include "am.h"
  29.  
  30. /*
  31.  * Handle an amd restart.
  32.  *
  33.  * Scan through the mount list finding all "interesting" mount points.
  34.  * Next hack up partial data structures and add the mounted file
  35.  * system to the list of known filesystems.  This will leave a
  36.  * dangling reference to that filesystems, so when the filesystem is
  37.  * finally inherited, an extra "free" must be done on it.
  38.  *
  39.  * This module relies on internal details of other components.  If
  40.  * you change something else make *sure* restart() still works.
  41.  */
  42. void restart()
  43. {
  44.     /*
  45.      * Read the existing mount table
  46.      */
  47.     mntlist *ml, *mlp;
  48.  
  49.     /*
  50.      * For each entry, find nfs, ufs or auto mounts
  51.      * and create a partial am_node to represent it.
  52.      */
  53.     for (mlp = ml = read_mtab("restart"); mlp; mlp = mlp->mnext) {
  54.         struct mntent *me = mlp->mnt;
  55.         am_ops *fs_ops = 0;
  56.         if (STREQ(me->mnt_type, MTAB_TYPE_UFS)) {
  57.             /*
  58.              * UFS entry
  59.              */
  60.             fs_ops = &ufs_ops;
  61.         } else if (STREQ(me->mnt_type, MTAB_TYPE_NFS)) {
  62.             /*
  63.              * NFS entry, or possibly an Amd entry...
  64.              */
  65.             int au_pid;
  66.             char *colon = strchr(me->mnt_fsname, ':');
  67.             if (colon && sscanf(colon, ":(pid%d)", &au_pid) == 1) {
  68.                 plog(XLOG_WARNING, "%s is an existing automount point", me->mnt_dir);
  69.                 fs_ops = &sfs_ops;
  70.             } else {
  71.                 fs_ops = &nfs_ops;
  72.             }
  73. #ifdef MTAB_TYPE_MFS
  74.         } else if (STREQ(me->mnt_type, MTAB_TYPE_MFS)) {
  75.             /*
  76.              * MFS entry.  Fake with a symlink.
  77.              */
  78.             fs_ops = &sfs_ops;
  79. #endif
  80.         } else {
  81.             /*
  82.              * Catch everything else with symlinks to
  83.              * avoid recursive mounts.  This is debatable...
  84.              */
  85.             fs_ops = &sfs_ops;
  86.         }
  87.  
  88.         /*
  89.          * If we found something to do
  90.          */
  91.         if (fs_ops) {
  92.             mntfs *mf;
  93.             am_opts mo;
  94.             char *cp;
  95.             cp = strchr(me->mnt_fsname, ':');
  96.             /*
  97.              * Partially fake up an opts structure
  98.              */
  99.             mo.opt_rhost = 0;
  100.             mo.opt_rfs = 0;
  101.             if (cp) {
  102.                 *cp = '\0';
  103.                 mo.opt_rhost = strdup(me->mnt_fsname);
  104.                 mo.opt_rfs = strdup(cp+1);
  105.                 *cp = ':';
  106.             } else if (fs_ops->ffserver == find_nfs_srvr) {
  107.                 /* 
  108.                  * Prototype 4.4 BSD used to end up here -
  109.                  * might as well keep the workaround for now
  110.                  */
  111.                 plog(XLOG_WARNING, "NFS server entry assumed to be %s:/", me->mnt_fsname);
  112.                 mo.opt_rhost = strdup(me->mnt_fsname);
  113.                 mo.opt_rfs = strdup("/");
  114.                 me->mnt_fsname = str3cat(me->mnt_fsname, mo.opt_rhost, ":", "/");
  115.             }
  116.             mo.opt_fs = me->mnt_dir;
  117.  
  118.             /*
  119.              * Make a new mounted filesystem
  120.              */
  121.             mf = find_mntfs(fs_ops, &mo, me->mnt_dir,
  122.                 me->mnt_fsname, me->mnt_opts);
  123.             if (mf->mf_refc == 1) {
  124.                 mf->mf_flags |= MFF_RESTART|MFF_MOUNTED;
  125.                 mf->mf_error = 0;    /* Already mounted correctly */
  126.                 /*
  127.                  * If the restarted type is a link then
  128.                  * don't time out.
  129.                  */
  130.                 if (fs_ops == &sfs_ops)
  131.                     mf->mf_flags |= MFF_RSTKEEP;
  132.                 if (fs_ops->fs_init) {
  133.                     /*
  134.                      * Don't care whether this worked since
  135.                      * it is checked again when the fs is
  136.                      * inherited.
  137.                      */
  138.                     (void) (*fs_ops->fs_init)(mf);
  139.                 }
  140.  
  141.                 plog(XLOG_INFO, "%s restarted fstype %s on %s",
  142.                     me->mnt_fsname, fs_ops->fs_type, me->mnt_dir);
  143.             } else {
  144.                 /* Something strange happened - two mounts at the same place! */
  145.                 free_mntfs(mf);
  146.             }
  147.             /*
  148.              * Clean up mo
  149.              */
  150.             if (mo.opt_rhost)
  151.                 free(mo.opt_rhost);
  152.             if (mo.opt_rfs)
  153.                 free(mo.opt_rfs);
  154.         }
  155.     }
  156.  
  157.     /*
  158.      * Free the mount list
  159.      */
  160.     free_mntlist(ml);
  161. }
  162.