Home | History | Annotate | Line # | Download | only in fsinfo
fsi_analyze.c revision 1.1
      1  1.1  christos /*	$NetBSD: fsi_analyze.c,v 1.1 2008/09/19 20:07:21 christos Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*
      4  1.1  christos  * Copyright (c) 1997-2007 Erez Zadok
      5  1.1  christos  * Copyright (c) 1989 Jan-Simon Pendry
      6  1.1  christos  * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
      7  1.1  christos  * Copyright (c) 1989 The Regents of the University of California.
      8  1.1  christos  * All rights reserved.
      9  1.1  christos  *
     10  1.1  christos  * This code is derived from software contributed to Berkeley by
     11  1.1  christos  * Jan-Simon Pendry at Imperial College, London.
     12  1.1  christos  *
     13  1.1  christos  * Redistribution and use in source and binary forms, with or without
     14  1.1  christos  * modification, are permitted provided that the following conditions
     15  1.1  christos  * are met:
     16  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     17  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     18  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     19  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     20  1.1  christos  *    documentation and/or other materials provided with the distribution.
     21  1.1  christos  * 3. All advertising materials mentioning features or use of this software
     22  1.1  christos  *    must display the following acknowledgment:
     23  1.1  christos  *      This product includes software developed by the University of
     24  1.1  christos  *      California, Berkeley and its contributors.
     25  1.1  christos  * 4. Neither the name of the University nor the names of its contributors
     26  1.1  christos  *    may be used to endorse or promote products derived from this software
     27  1.1  christos  *    without specific prior written permission.
     28  1.1  christos  *
     29  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     30  1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     31  1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     32  1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     33  1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     34  1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     35  1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     36  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     37  1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     38  1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     39  1.1  christos  * SUCH DAMAGE.
     40  1.1  christos  *
     41  1.1  christos  *
     42  1.1  christos  * File: am-utils/fsinfo/fsi_analyze.c
     43  1.1  christos  *
     44  1.1  christos  */
     45  1.1  christos 
     46  1.1  christos /*
     47  1.1  christos  * Analyze filesystem declarations
     48  1.1  christos  *
     49  1.1  christos  * Note: most of this is magic!
     50  1.1  christos  */
     51  1.1  christos 
     52  1.1  christos #ifdef HAVE_CONFIG_H
     53  1.1  christos # include <config.h>
     54  1.1  christos #endif /* HAVE_CONFIG_H */
     55  1.1  christos #include <am_defs.h>
     56  1.1  christos #include <fsi_data.h>
     57  1.1  christos #include <fsinfo.h>
     58  1.1  christos 
     59  1.1  christos char *disk_fs_strings[] =
     60  1.1  christos {
     61  1.1  christos   "fstype", "opts", "dumpset", "passno", "freq", "mount", "log", NULL,
     62  1.1  christos };
     63  1.1  christos 
     64  1.1  christos char *mount_strings[] =
     65  1.1  christos {
     66  1.1  christos   "volname", "exportfs", NULL,
     67  1.1  christos };
     68  1.1  christos 
     69  1.1  christos char *fsmount_strings[] =
     70  1.1  christos {
     71  1.1  christos   "as", "volname", "fstype", "opts", "from", NULL,
     72  1.1  christos };
     73  1.1  christos 
     74  1.1  christos char *host_strings[] =
     75  1.1  christos {
     76  1.1  christos   "host", "netif", "config", "arch", "cluster", "os", NULL,
     77  1.1  christos };
     78  1.1  christos 
     79  1.1  christos char *ether_if_strings[] =
     80  1.1  christos {
     81  1.1  christos   "inaddr", "netmask", "hwaddr", NULL,
     82  1.1  christos };
     83  1.1  christos 
     84  1.1  christos 
     85  1.1  christos /*
     86  1.1  christos  * Strip off the trailing part of a domain
     87  1.1  christos  * to produce a short-form domain relative
     88  1.1  christos  * to the local host domain.
     89  1.1  christos  * Note that this has no effect if the domain
     90  1.1  christos  * names do not have the same number of
     91  1.1  christos  * components.  If that restriction proves
     92  1.1  christos  * to be a problem then the loop needs recoding
     93  1.1  christos  * to skip from right to left and do partial
     94  1.1  christos  * matches along the way -- ie more expensive.
     95  1.1  christos  */
     96  1.1  christos void
     97  1.1  christos domain_strip(char *otherdom, char *localdom)
     98  1.1  christos {
     99  1.1  christos   char *p1, *p2;
    100  1.1  christos 
    101  1.1  christos   if ((p1 = strchr(otherdom, '.')) &&
    102  1.1  christos       (p2 = strchr(localdom, '.')) &&
    103  1.1  christos       STREQ(p1 + 1, p2 + 1))
    104  1.1  christos     *p1 = '\0';
    105  1.1  christos }
    106  1.1  christos 
    107  1.1  christos 
    108  1.1  christos /*
    109  1.1  christos  * Take a little-endian domain name and
    110  1.1  christos  * transform into a big-endian Un*x pathname.
    111  1.1  christos  * For example: kiska.doc.ic -> ic/doc/kiska
    112  1.1  christos  */
    113  1.1  christos static char *
    114  1.1  christos compute_hostpath(char *hn)
    115  1.1  christos {
    116  1.1  christos   char *p = xmalloc(MAXPATHLEN);
    117  1.1  christos   char *d;
    118  1.1  christos   char path[MAXPATHLEN];
    119  1.1  christos 
    120  1.1  christos   xstrlcpy(p, hn, MAXPATHLEN);
    121  1.1  christos   domain_strip(p, hostname);
    122  1.1  christos   path[0] = '\0';
    123  1.1  christos 
    124  1.1  christos   do {
    125  1.1  christos     d = strrchr(p, '.');
    126  1.1  christos     if (d) {
    127  1.1  christos       *d = '\0';
    128  1.1  christos       xstrlcat(path, d + 1, sizeof(path));
    129  1.1  christos       xstrlcat(path, "/", sizeof(path));
    130  1.1  christos     } else {
    131  1.1  christos       xstrlcat(path, p, sizeof(path));
    132  1.1  christos     }
    133  1.1  christos   } while (d);
    134  1.1  christos 
    135  1.1  christos   fsi_log("hostpath of '%s' is '%s'", hn, path);
    136  1.1  christos 
    137  1.1  christos   xstrlcpy(p, path, MAXPATHLEN);
    138  1.1  christos   return p;
    139  1.1  christos }
    140  1.1  christos 
    141  1.1  christos 
    142  1.1  christos static dict_ent *
    143  1.1  christos find_volname(char *nn)
    144  1.1  christos {
    145  1.1  christos   dict_ent *de;
    146  1.1  christos   char *p = strdup(nn);
    147  1.1  christos   char *q;
    148  1.1  christos 
    149  1.1  christos   do {
    150  1.1  christos     fsi_log("Searching for volname %s", p);
    151  1.1  christos     de = dict_locate(dict_of_volnames, p);
    152  1.1  christos     q = strrchr(p, '/');
    153  1.1  christos     if (q)
    154  1.1  christos       *q = '\0';
    155  1.1  christos   } while (!de && q);
    156  1.1  christos 
    157  1.1  christos   XFREE(p);
    158  1.1  christos   return de;
    159  1.1  christos }
    160  1.1  christos 
    161  1.1  christos 
    162  1.1  christos static void
    163  1.1  christos show_required(ioloc *l, int mask, char *info, char *hostname, char *strings[])
    164  1.1  christos {
    165  1.1  christos   int i;
    166  1.1  christos   fsi_log("mask left for %s:%s is %#x", hostname, info, mask);
    167  1.1  christos 
    168  1.1  christos   for (i = 0; strings[i]; i++)
    169  1.1  christos     if (ISSET(mask, i))
    170  1.1  christos       lerror(l, "%s:%s needs field \"%s\"", hostname, info, strings[i]);
    171  1.1  christos }
    172  1.1  christos 
    173  1.1  christos 
    174  1.1  christos /*
    175  1.1  christos  * Check and fill in "exportfs" details.
    176  1.1  christos  * Make sure the m_exported field references
    177  1.1  christos  * the most local node with an "exportfs" entry.
    178  1.1  christos  */
    179  1.1  christos static int
    180  1.1  christos check_exportfs(qelem *q, fsi_mount *e)
    181  1.1  christos {
    182  1.1  christos   fsi_mount *mp;
    183  1.1  christos   int errors = 0;
    184  1.1  christos 
    185  1.1  christos   ITER(mp, fsi_mount, q) {
    186  1.1  christos     if (ISSET(mp->m_mask, DM_EXPORTFS)) {
    187  1.1  christos       if (e)
    188  1.1  christos 	lwarning(mp->m_ioloc, "%s has duplicate exportfs data", mp->m_name);
    189  1.1  christos       mp->m_exported = mp;
    190  1.1  christos       if (!ISSET(mp->m_mask, DM_VOLNAME))
    191  1.1  christos 	set_mount(mp, DM_VOLNAME, strdup(mp->m_name));
    192  1.1  christos     } else {
    193  1.1  christos       mp->m_exported = e;
    194  1.1  christos     }
    195  1.1  christos 
    196  1.1  christos     /*
    197  1.1  christos      * Recursively descend the mount tree
    198  1.1  christos      */
    199  1.1  christos     if (mp->m_mount)
    200  1.1  christos       errors += check_exportfs(mp->m_mount, mp->m_exported);
    201  1.1  christos 
    202  1.1  christos     /*
    203  1.1  christos      * If a volume name has been specified, but this node and none
    204  1.1  christos      * of its parents has been exported, report an error.
    205  1.1  christos      */
    206  1.1  christos     if (ISSET(mp->m_mask, DM_VOLNAME) && !mp->m_exported) {
    207  1.1  christos       lerror(mp->m_ioloc, "%s has a volname but no exportfs data", mp->m_name);
    208  1.1  christos       errors++;
    209  1.1  christos     }
    210  1.1  christos   }
    211  1.1  christos 
    212  1.1  christos   return errors;
    213  1.1  christos }
    214  1.1  christos 
    215  1.1  christos 
    216  1.1  christos static int
    217  1.1  christos analyze_dkmount_tree(qelem *q, fsi_mount *parent, disk_fs *dk)
    218  1.1  christos {
    219  1.1  christos   fsi_mount *mp;
    220  1.1  christos   int errors = 0;
    221  1.1  christos 
    222  1.1  christos   ITER(mp, fsi_mount, q) {
    223  1.1  christos     fsi_log("Mount %s:", mp->m_name);
    224  1.1  christos     if (parent) {
    225  1.1  christos       char n[MAXPATHLEN];
    226  1.1  christos       xsnprintf(n, sizeof(n), "%s/%s", parent->m_name, mp->m_name);
    227  1.1  christos       if (*mp->m_name == '/')
    228  1.1  christos 	lerror(mp->m_ioloc, "sub-directory %s of %s starts with '/'", mp->m_name, parent->m_name);
    229  1.1  christos       else if (STREQ(mp->m_name, "default"))
    230  1.1  christos 	lwarning(mp->m_ioloc, "sub-directory of %s is named \"default\"", parent->m_name);
    231  1.1  christos       fsi_log("Changing name %s to %s", mp->m_name, n);
    232  1.1  christos       XFREE(mp->m_name);
    233  1.1  christos       mp->m_name = strdup(n);
    234  1.1  christos     }
    235  1.1  christos 
    236  1.1  christos     mp->m_name_len = strlen(mp->m_name);
    237  1.1  christos     mp->m_parent = parent;
    238  1.1  christos     mp->m_dk = dk;
    239  1.1  christos     if (mp->m_mount)
    240  1.1  christos       analyze_dkmount_tree(mp->m_mount, mp, dk);
    241  1.1  christos   }
    242  1.1  christos 
    243  1.1  christos   return errors;
    244  1.1  christos }
    245  1.1  christos 
    246  1.1  christos 
    247  1.1  christos /*
    248  1.1  christos  * The mount tree is a singleton list
    249  1.1  christos  * containing the top-level mount
    250  1.1  christos  * point for a disk.
    251  1.1  christos  */
    252  1.1  christos static int
    253  1.1  christos analyze_dkmounts(disk_fs *dk, qelem *q)
    254  1.1  christos {
    255  1.1  christos   int errors = 0;
    256  1.1  christos   fsi_mount *mp, *mp2 = NULL;
    257  1.1  christos   int i = 0;
    258  1.1  christos 
    259  1.1  christos   /*
    260  1.1  christos    * First scan the list of subdirs to make
    261  1.1  christos    * sure there is only one - and remember it
    262  1.1  christos    */
    263  1.1  christos   if (q) {
    264  1.1  christos     ITER(mp, fsi_mount, q) {
    265  1.1  christos       mp2 = mp;
    266  1.1  christos       i++;
    267  1.1  christos     }
    268  1.1  christos   }
    269  1.1  christos 
    270  1.1  christos   /*
    271  1.1  christos    * Check...
    272  1.1  christos    */
    273  1.1  christos   if (i < 1) {
    274  1.1  christos     lerror(dk->d_ioloc, "%s:%s has no mount point", dk->d_host->h_hostname, dk->d_dev);
    275  1.1  christos     return 1;
    276  1.1  christos   }
    277  1.1  christos 
    278  1.1  christos   if (i > 1) {
    279  1.1  christos     lerror(dk->d_ioloc, "%s:%s has more than one mount point", dk->d_host->h_hostname, dk->d_dev);
    280  1.1  christos     errors++;
    281  1.1  christos   }
    282  1.1  christos 
    283  1.1  christos   /*
    284  1.1  christos    * Now see if a default mount point is required
    285  1.1  christos    */
    286  1.1  christos   if (mp2 && STREQ(mp2->m_name, "default")) {
    287  1.1  christos     if (ISSET(mp2->m_mask, DM_VOLNAME)) {
    288  1.1  christos       char nbuf[1024];
    289  1.1  christos       compute_automount_point(nbuf, sizeof(nbuf), dk->d_host, mp2->m_volname);
    290  1.1  christos       XFREE(mp2->m_name);
    291  1.1  christos       mp2->m_name = strdup(nbuf);
    292  1.1  christos       fsi_log("%s:%s has default mount on %s", dk->d_host->h_hostname, dk->d_dev, mp2->m_name);
    293  1.1  christos     } else {
    294  1.1  christos       lerror(dk->d_ioloc, "no volname given for %s:%s", dk->d_host->h_hostname, dk->d_dev);
    295  1.1  christos       errors++;
    296  1.1  christos     }
    297  1.1  christos   }
    298  1.1  christos 
    299  1.1  christos   /*
    300  1.1  christos    * Fill in the disk mount point
    301  1.1  christos    */
    302  1.1  christos   if (!errors && mp2 && mp2->m_name)
    303  1.1  christos     dk->d_mountpt = strdup(mp2->m_name);
    304  1.1  christos   else
    305  1.1  christos     dk->d_mountpt = strdup("error");
    306  1.1  christos 
    307  1.1  christos   /*
    308  1.1  christos    * Analyze the mount tree
    309  1.1  christos    */
    310  1.1  christos   errors += analyze_dkmount_tree(q, NULL, dk);
    311  1.1  christos 
    312  1.1  christos   /*
    313  1.1  christos    * Analyze the export tree
    314  1.1  christos    */
    315  1.1  christos   errors += check_exportfs(q, NULL);
    316  1.1  christos 
    317  1.1  christos   return errors;
    318  1.1  christos }
    319  1.1  christos 
    320  1.1  christos 
    321  1.1  christos static void
    322  1.1  christos fixup_required_disk_info(disk_fs *dp)
    323  1.1  christos {
    324  1.1  christos   /*
    325  1.1  christos    * "fstype"
    326  1.1  christos    */
    327  1.1  christos   if (ISSET(dp->d_mask, DF_FSTYPE)) {
    328  1.1  christos     if (STREQ(dp->d_fstype, "swap")) {
    329  1.1  christos 
    330  1.1  christos       /*
    331  1.1  christos        * Fixup for a swap device
    332  1.1  christos        */
    333  1.1  christos       if (!ISSET(dp->d_mask, DF_PASSNO)) {
    334  1.1  christos 	dp->d_passno = 0;
    335  1.1  christos 	BITSET(dp->d_mask, DF_PASSNO);
    336  1.1  christos       } else if (dp->d_freq != 0) {
    337  1.1  christos 	lwarning(dp->d_ioloc,
    338  1.1  christos 		 "Pass number for %s:%s is non-zero",
    339  1.1  christos 		 dp->d_host->h_hostname, dp->d_dev);
    340  1.1  christos       }
    341  1.1  christos 
    342  1.1  christos       /*
    343  1.1  christos        * "freq"
    344  1.1  christos        */
    345  1.1  christos       if (!ISSET(dp->d_mask, DF_FREQ)) {
    346  1.1  christos 	dp->d_freq = 0;
    347  1.1  christos 	BITSET(dp->d_mask, DF_FREQ);
    348  1.1  christos       } else if (dp->d_freq != 0) {
    349  1.1  christos 	lwarning(dp->d_ioloc,
    350  1.1  christos 		 "dump frequency for %s:%s is non-zero",
    351  1.1  christos 		 dp->d_host->h_hostname, dp->d_dev);
    352  1.1  christos       }
    353  1.1  christos 
    354  1.1  christos       /*
    355  1.1  christos        * "opts"
    356  1.1  christos        */
    357  1.1  christos       if (!ISSET(dp->d_mask, DF_OPTS))
    358  1.1  christos 	set_disk_fs(dp, DF_OPTS, strdup("swap"));
    359  1.1  christos 
    360  1.1  christos       /*
    361  1.1  christos        * "mount"
    362  1.1  christos        */
    363  1.1  christos       if (!ISSET(dp->d_mask, DF_MOUNT)) {
    364  1.1  christos 	qelem *q = new_que();
    365  1.1  christos 	fsi_mount *m = new_mount();
    366  1.1  christos 
    367  1.1  christos 	m->m_name = strdup("swap");
    368  1.1  christos 	m->m_mount = new_que();
    369  1.1  christos 	ins_que(&m->m_q, q->q_back);
    370  1.1  christos 	dp->d_mount = q;
    371  1.1  christos 	BITSET(dp->d_mask, DF_MOUNT);
    372  1.1  christos       } else {
    373  1.1  christos 	lerror(dp->d_ioloc, "%s: mount field specified for swap partition", dp->d_host->h_hostname);
    374  1.1  christos       }
    375  1.1  christos     } else if (STREQ(dp->d_fstype, "export")) {
    376  1.1  christos 
    377  1.1  christos       /*
    378  1.1  christos        * "passno"
    379  1.1  christos        */
    380  1.1  christos       if (!ISSET(dp->d_mask, DF_PASSNO)) {
    381  1.1  christos 	dp->d_passno = 0;
    382  1.1  christos 	BITSET(dp->d_mask, DF_PASSNO);
    383  1.1  christos       } else if (dp->d_passno != 0) {
    384  1.1  christos 	lwarning(dp->d_ioloc,
    385  1.1  christos 		 "pass number for %s:%s is non-zero",
    386  1.1  christos 		 dp->d_host->h_hostname, dp->d_dev);
    387  1.1  christos       }
    388  1.1  christos 
    389  1.1  christos       /*
    390  1.1  christos        * "freq"
    391  1.1  christos        */
    392  1.1  christos       if (!ISSET(dp->d_mask, DF_FREQ)) {
    393  1.1  christos 	dp->d_freq = 0;
    394  1.1  christos 	BITSET(dp->d_mask, DF_FREQ);
    395  1.1  christos       } else if (dp->d_freq != 0) {
    396  1.1  christos 	lwarning(dp->d_ioloc,
    397  1.1  christos 		 "dump frequency for %s:%s is non-zero",
    398  1.1  christos 		 dp->d_host->h_hostname, dp->d_dev);
    399  1.1  christos       }
    400  1.1  christos 
    401  1.1  christos       /*
    402  1.1  christos        * "opts"
    403  1.1  christos        */
    404  1.1  christos       if (!ISSET(dp->d_mask, DF_OPTS))
    405  1.1  christos 	set_disk_fs(dp, DF_OPTS, strdup("rw,defaults"));
    406  1.1  christos 
    407  1.1  christos     }
    408  1.1  christos   }
    409  1.1  christos }
    410  1.1  christos 
    411  1.1  christos 
    412  1.1  christos static void
    413  1.1  christos fixup_required_mount_info(fsmount *fp, dict_ent *de)
    414  1.1  christos {
    415  1.1  christos   if (!ISSET(fp->f_mask, FM_FROM)) {
    416  1.1  christos     if (de->de_count != 1) {
    417  1.1  christos       lerror(fp->f_ioloc, "ambiguous mount: %s is a replicated filesystem", fp->f_volname);
    418  1.1  christos     } else {
    419  1.1  christos       dict_data *dd;
    420  1.1  christos       fsi_mount *mp = NULL;
    421  1.1  christos       dd = AM_FIRST(dict_data, &de->de_q);
    422  1.1  christos       mp = (fsi_mount *) dd->dd_data;
    423  1.1  christos       if (!mp)
    424  1.1  christos 	abort();
    425  1.1  christos       fp->f_ref = mp;
    426  1.1  christos       set_fsmount(fp, FM_FROM, mp->m_dk->d_host->h_hostname);
    427  1.1  christos       fsi_log("set: %s comes from %s", fp->f_volname, fp->f_from);
    428  1.1  christos     }
    429  1.1  christos   }
    430  1.1  christos 
    431  1.1  christos   if (!ISSET(fp->f_mask, FM_FSTYPE)) {
    432  1.1  christos     set_fsmount(fp, FM_FSTYPE, strdup("nfs"));
    433  1.1  christos     fsi_log("set: fstype is %s", fp->f_fstype);
    434  1.1  christos   }
    435  1.1  christos 
    436  1.1  christos   if (!ISSET(fp->f_mask, FM_OPTS)) {
    437  1.1  christos     set_fsmount(fp, FM_OPTS, strdup("rw,nosuid,grpid,defaults"));
    438  1.1  christos     fsi_log("set: opts are %s", fp->f_opts);
    439  1.1  christos   }
    440  1.1  christos 
    441  1.1  christos   if (!ISSET(fp->f_mask, FM_LOCALNAME)) {
    442  1.1  christos     if (fp->f_ref) {
    443  1.1  christos       set_fsmount(fp, FM_LOCALNAME, strdup(fp->f_volname));
    444  1.1  christos       fsi_log("set: localname is %s", fp->f_localname);
    445  1.1  christos     } else {
    446  1.1  christos       lerror(fp->f_ioloc, "cannot determine localname since volname %s is not uniquely defined", fp->f_volname);
    447  1.1  christos     }
    448  1.1  christos   }
    449  1.1  christos }
    450  1.1  christos 
    451  1.1  christos 
    452  1.1  christos /*
    453  1.1  christos  * For each disk on a host
    454  1.1  christos  * analyze the mount information
    455  1.1  christos  * and fill in any derivable
    456  1.1  christos  * details.
    457  1.1  christos  */
    458  1.1  christos static void
    459  1.1  christos analyze_drives(host *hp)
    460  1.1  christos {
    461  1.1  christos   qelem *q = hp->h_disk_fs;
    462  1.1  christos   disk_fs *dp;
    463  1.1  christos 
    464  1.1  christos   ITER(dp, disk_fs, q) {
    465  1.1  christos     int req;
    466  1.1  christos     fsi_log("Disk %s:", dp->d_dev);
    467  1.1  christos     dp->d_host = hp;
    468  1.1  christos     fixup_required_disk_info(dp);
    469  1.1  christos     req = ~dp->d_mask & DF_REQUIRED;
    470  1.1  christos     if (req)
    471  1.1  christos       show_required(dp->d_ioloc, req, dp->d_dev, hp->h_hostname, disk_fs_strings);
    472  1.1  christos     analyze_dkmounts(dp, dp->d_mount);
    473  1.1  christos   }
    474  1.1  christos }
    475  1.1  christos 
    476  1.1  christos 
    477  1.1  christos /*
    478  1.1  christos  * Check that all static mounts make sense and
    479  1.1  christos  * that the source volumes exist.
    480  1.1  christos  */
    481  1.1  christos static void
    482  1.1  christos analyze_mounts(host *hp)
    483  1.1  christos {
    484  1.1  christos   qelem *q = hp->h_mount;
    485  1.1  christos   fsmount *fp;
    486  1.1  christos   int netbootp = 0;
    487  1.1  christos 
    488  1.1  christos   ITER(fp, fsmount, q) {
    489  1.1  christos     char *p;
    490  1.1  christos     char *nn = strdup(fp->f_volname);
    491  1.1  christos     int req;
    492  1.1  christos     dict_ent *de = (dict_ent *) NULL;
    493  1.1  christos     int found = 0;
    494  1.1  christos     int matched = 0;
    495  1.1  christos 
    496  1.1  christos     if (ISSET(fp->f_mask, FM_DIRECT)) {
    497  1.1  christos       found = 1;
    498  1.1  christos       matched = 1;
    499  1.1  christos     } else
    500  1.1  christos       do {
    501  1.1  christos 	p = NULL;
    502  1.1  christos 	de = find_volname(nn);
    503  1.1  christos 	fsi_log("Mount: %s (trying %s)", fp->f_volname, nn);
    504  1.1  christos 
    505  1.1  christos 	if (de) {
    506  1.1  christos 	  found = 1;
    507  1.1  christos 
    508  1.1  christos 	  /*
    509  1.1  christos 	   * Check that the from field is really exporting
    510  1.1  christos 	   * the filesystem requested.
    511  1.1  christos 	   * LBL: If fake mount, then don't care about
    512  1.1  christos 	   *      consistency check.
    513  1.1  christos 	   */
    514  1.1  christos 	  if (ISSET(fp->f_mask, FM_FROM) && !ISSET(fp->f_mask, FM_DIRECT)) {
    515  1.1  christos 	    dict_data *dd;
    516  1.1  christos 	    fsi_mount *mp2 = NULL;
    517  1.1  christos 
    518  1.1  christos 	    ITER(dd, dict_data, &de->de_q) {
    519  1.1  christos 	      fsi_mount *mp = (fsi_mount *) dd->dd_data;
    520  1.1  christos 
    521  1.1  christos 	      if (fp->f_from &&
    522  1.1  christos 		  STREQ(mp->m_dk->d_host->h_hostname, fp->f_from)) {
    523  1.1  christos 		mp2 = mp;
    524  1.1  christos 		break;
    525  1.1  christos 	      }
    526  1.1  christos 	    }
    527  1.1  christos 
    528  1.1  christos 	    if (mp2) {
    529  1.1  christos 	      fp->f_ref = mp2;
    530  1.1  christos 	      matched = 1;
    531  1.1  christos 	      break;
    532  1.1  christos 	    }
    533  1.1  christos 	  } else {
    534  1.1  christos 	    matched = 1;
    535  1.1  christos 	    break;
    536  1.1  christos 	  }
    537  1.1  christos 	}
    538  1.1  christos 	p = strrchr(nn, '/');
    539  1.1  christos 	if (p)
    540  1.1  christos 	  *p = '\0';
    541  1.1  christos       } while (de && p);
    542  1.1  christos     XFREE(nn);
    543  1.1  christos 
    544  1.1  christos     if (!found) {
    545  1.1  christos       lerror(fp->f_ioloc, "volname %s unknown", fp->f_volname);
    546  1.1  christos     } else if (matched) {
    547  1.1  christos 
    548  1.1  christos       if (de)
    549  1.1  christos 	fixup_required_mount_info(fp, de);
    550  1.1  christos       req = ~fp->f_mask & FM_REQUIRED;
    551  1.1  christos       if (req) {
    552  1.1  christos 	show_required(fp->f_ioloc, req, fp->f_volname, hp->h_hostname,
    553  1.1  christos 		      fsmount_strings);
    554  1.1  christos       } else if (STREQ(fp->f_localname, "/")) {
    555  1.1  christos 	hp->h_netroot = fp;
    556  1.1  christos 	netbootp |= FM_NETROOT;
    557  1.1  christos       } else if (STREQ(fp->f_localname, "swap")) {
    558  1.1  christos 	hp->h_netswap = fp;
    559  1.1  christos 	netbootp |= FM_NETSWAP;
    560  1.1  christos       }
    561  1.1  christos 
    562  1.1  christos     } else {
    563  1.1  christos       lerror(fp->f_ioloc, "volname %s not exported from %s", fp->f_volname,
    564  1.1  christos 	     fp->f_from ? fp->f_from : "anywhere");
    565  1.1  christos     }
    566  1.1  christos   }
    567  1.1  christos 
    568  1.1  christos   if (netbootp && (netbootp != FM_NETBOOT))
    569  1.1  christos     lerror(hp->h_ioloc, "network booting requires both root and swap areas");
    570  1.1  christos }
    571  1.1  christos 
    572  1.1  christos 
    573  1.1  christos void
    574  1.1  christos analyze_hosts(qelem *q)
    575  1.1  christos {
    576  1.1  christos   host *hp;
    577  1.1  christos 
    578  1.1  christos   show_area_being_processed("analyze hosts", 5);
    579  1.1  christos 
    580  1.1  christos   /*
    581  1.1  christos    * Check all drives
    582  1.1  christos    */
    583  1.1  christos   ITER(hp, host, q) {
    584  1.1  christos     fsi_log("disks on host %s", hp->h_hostname);
    585  1.1  christos     show_new("ana-host");
    586  1.1  christos     hp->h_hostpath = compute_hostpath(hp->h_hostname);
    587  1.1  christos 
    588  1.1  christos     if (hp->h_disk_fs)
    589  1.1  christos       analyze_drives(hp);
    590  1.1  christos 
    591  1.1  christos   }
    592  1.1  christos 
    593  1.1  christos   show_area_being_processed("analyze mounts", 5);
    594  1.1  christos 
    595  1.1  christos   /*
    596  1.1  christos    * Check static mounts
    597  1.1  christos    */
    598  1.1  christos   ITER(hp, host, q) {
    599  1.1  christos     fsi_log("mounts on host %s", hp->h_hostname);
    600  1.1  christos     show_new("ana-mount");
    601  1.1  christos     if (hp->h_mount)
    602  1.1  christos       analyze_mounts(hp);
    603  1.1  christos 
    604  1.1  christos   }
    605  1.1  christos }
    606  1.1  christos 
    607  1.1  christos 
    608  1.1  christos /*
    609  1.1  christos  * Check an automount request
    610  1.1  christos  */
    611  1.1  christos static void
    612  1.1  christos analyze_automount(automount *ap)
    613  1.1  christos {
    614  1.1  christos   dict_ent *de = find_volname(ap->a_volname);
    615  1.1  christos 
    616  1.1  christos   if (de) {
    617  1.1  christos     ap->a_mounted = de;
    618  1.1  christos   } else {
    619  1.1  christos     if (STREQ(ap->a_volname, ap->a_name))
    620  1.1  christos       lerror(ap->a_ioloc, "unknown volname %s automounted", ap->a_volname);
    621  1.1  christos     else
    622  1.1  christos       lerror(ap->a_ioloc, "unknown volname %s automounted on %s", ap->a_volname, ap->a_name);
    623  1.1  christos   }
    624  1.1  christos }
    625  1.1  christos 
    626  1.1  christos 
    627  1.1  christos static void
    628  1.1  christos analyze_automount_tree(qelem *q, char *pref, int lvl)
    629  1.1  christos {
    630  1.1  christos   automount *ap;
    631  1.1  christos 
    632  1.1  christos   ITER(ap, automount, q) {
    633  1.1  christos     char nname[1024];
    634  1.1  christos 
    635  1.1  christos     if (lvl > 0 || ap->a_mount)
    636  1.1  christos       if (ap->a_name[1] && strchr(ap->a_name + 1, '/'))
    637  1.1  christos 	lerror(ap->a_ioloc, "not allowed '/' in a directory name");
    638  1.1  christos     xsnprintf(nname, sizeof(nname), "%s/%s", pref, ap->a_name);
    639  1.1  christos     XFREE(ap->a_name);
    640  1.1  christos     ap->a_name = strdup(nname[1] == '/' ? nname + 1 : nname);
    641  1.1  christos     fsi_log("automount point %s:", ap->a_name);
    642  1.1  christos     show_new("ana-automount");
    643  1.1  christos 
    644  1.1  christos     if (ap->a_mount) {
    645  1.1  christos       analyze_automount_tree(ap->a_mount, ap->a_name, lvl + 1);
    646  1.1  christos     } else if (ap->a_hardwiredfs) {
    647  1.1  christos       fsi_log("\thardwired from %s to %s", ap->a_volname, ap->a_hardwiredfs);
    648  1.1  christos     } else if (ap->a_volname) {
    649  1.1  christos       fsi_log("\tautomount from %s", ap->a_volname);
    650  1.1  christos       analyze_automount(ap);
    651  1.1  christos     } else if (ap->a_symlink) {
    652  1.1  christos       fsi_log("\tsymlink to %s", ap->a_symlink);
    653  1.1  christos     } else {
    654  1.1  christos       ap->a_volname = strdup(ap->a_name);
    655  1.1  christos       fsi_log("\timplicit automount from %s", ap->a_volname);
    656  1.1  christos       analyze_automount(ap);
    657  1.1  christos     }
    658  1.1  christos   }
    659  1.1  christos }
    660  1.1  christos 
    661  1.1  christos 
    662  1.1  christos void
    663  1.1  christos analyze_automounts(qelem *q)
    664  1.1  christos {
    665  1.1  christos   auto_tree *tp;
    666  1.1  christos 
    667  1.1  christos   show_area_being_processed("analyze automount", 5);
    668  1.1  christos 
    669  1.1  christos   /*
    670  1.1  christos    * q is a list of automounts
    671  1.1  christos    */
    672  1.1  christos   ITER(tp, auto_tree, q)
    673  1.1  christos     analyze_automount_tree(tp->t_mount, "", 0);
    674  1.1  christos }
    675