* Copyright (c) 1989 Jan-Simon Pendry
* Copyright (c) 1989 Imperial College of Science, Technology & Medicine
* Copyright (c) 1989 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* Jan-Simon Pendry at Imperial College, London.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* @(#)fsi_analyze.c 5.3 (Berkeley) 5/12/91
* $Id: fsi_analyze.c,v 5.2.1.3 91/05/07 22:19:06 jsp Alpha $
* Analyze filesystem declarations
* Note: most of this is magic!
#include "../fsinfo/fsinfo.h"
char *disk_fs_strings
[] = {
"fstype", "opts", "dumpset", "passno", "freq", "mount", "log", 0,
char *mount_strings
[] = {
"volname", "exportfs", 0,
char *fsmount_strings
[] = {
"as", "volname", "fstype", "opts", "from", 0,
"host", "netif", "config", "arch", "cluster", "os", 0,
char *ether_if_strings
[] = {
"inaddr", "netmask", "hwaddr", 0,
* Strip off the trailing part of a domain
* to produce a short-form domain relative
* to the local host domain.
* Note that this has no effect if the domain
* names do not have the same number of
* components. If that restriction proves
* to be a problem then the loop needs recoding
* to skip from right to left and do partial
* matches along the way -- ie more expensive.
void domain_strip(otherdom
, localdom
)
char *otherdom
, *localdom
;
if (p1
= strchr(p1
+1, '.'))
if (p2
= strchr(p2
+1, '.'))
if ((p1
= strchr(otherdom
, '.')) &&
(p2
= strchr(localdom
, '.')) &&
(strcmp(p1
+1, p2
+1) == 0))
#endif /* PARTIAL_DOMAINS */
* Take a little-endian domain name and
* transform into a big-endian Un*x pathname.
* For example: kiska.doc.ic -> ic/doc/kiska
static char *compute_hostpath(hn
)
domain_strip(p
, hostname
);
log("hostpath of '%s' is '%s'", hn
, path
);
static dict_ent
*find_volname(nn
)
log("Searching for volname %s", p
);
de
= dict_locate(dict_of_volnames
, p
);
static show_required(l
, mask
, info
, hostname
, strings
)
log("mask left for %s:%s is %#x", hostname
, info
, mask
);
for (i
= 0; strings
[i
]; i
++)
lerror(l
, "%s:%s needs field \"%s\"", hostname
, info
, strings
[i
]);
* Check and fill in "exportfs" details.
* Make sure the m_exported field references
* the most local node with an "exportfs" entry.
static int check_exportfs(q
, e
)
if (ISSET(mp
->m_mask
, DM_EXPORTFS
)) {
lwarning(mp
->m_ioloc
, "%s has duplicate exportfs data", mp
->m_name
);
if (!ISSET(mp
->m_mask
, DM_VOLNAME
))
set_mount(mp
, DM_VOLNAME
, strdup(mp
->m_name
));
* Recursively descend the mount tree
errors
+= check_exportfs(mp
->m_mount
, mp
->m_exported
);
* If a volume name has been specified, but this node and none
* of its parents has been exported, report an error.
if (ISSET(mp
->m_mask
, DM_VOLNAME
) && !mp
->m_exported
) {
lerror(mp
->m_ioloc
, "%s has a volname but no exportfs data", mp
->m_name
);
static int analyze_dkmount_tree(q
, parent
, dk
)
log("Mount %s:", mp
->m_name
);
sprintf(n
, "%s/%s", parent
->m_name
, mp
->m_name
);
lerror(mp
->m_ioloc
, "sub-directory %s of %s starts with '/'", mp
->m_name
, parent
->m_name
);
else if (STREQ(mp
->m_name
, "default"))
lwarning(mp
->m_ioloc
, "sub-directory of %s is named \"default\"", parent
->m_name
);
log("Changing name %s to %s", mp
->m_name
, n
);
mp
->m_name_len
= strlen(mp
->m_name
);
analyze_dkmount_tree(mp
->m_mount
, mp
, dk
);
* The mount tree is a singleton list
* containing the top-level mount
static int analyze_dkmounts(dk
, q
)
* First scan the list of subdirs to make
* sure there is only one - and remember it
lerror(dk
->d_ioloc
, "%s:%s has no mount point", dk
->d_host
->h_hostname
, dk
->d_dev
);
lerror(dk
->d_ioloc
, "%s:%s has more than one mount point", dk
->d_host
->h_hostname
, dk
->d_dev
);
* Now see if a default mount point is required
if (STREQ(mp2
->m_name
, "default")) {
if (ISSET(mp2
->m_mask
, DM_VOLNAME
)) {
compute_automount_point(nbuf
, dk
->d_host
, mp2
->m_volname
);
mp2
->m_name
= strdup(nbuf
);
log("%s:%s has default mount on %s", dk
->d_host
->h_hostname
, dk
->d_dev
, mp2
->m_name
);
lerror(dk
->d_ioloc
, "no volname given for %s:%s", dk
->d_host
->h_hostname
, dk
->d_dev
);
* Fill in the disk mount point
if (!errors
&& mp2
&& mp2
->m_name
)
dk
->d_mountpt
= strdup(mp2
->m_name
);
dk
->d_mountpt
= strdup("error");
errors
+= analyze_dkmount_tree(q
, 0, dk
);
* Analyze the export tree
errors
+= check_exportfs(q
, 0);
static void fixup_required_disk_info(dp
)
if (ISSET(dp
->d_mask
, DF_FSTYPE
)) {
if (STREQ(dp
->d_fstype
, "swap")) {
* Fixup for a swap device
if (!ISSET(dp
->d_mask
, DF_PASSNO
)) {
BITSET(dp
->d_mask
, DF_PASSNO
);
} else if (dp
->d_freq
!= 0) {
"Pass number for %s:%s is non-zero",
dp
->d_host
->h_hostname
, dp
->d_dev
);
if (!ISSET(dp
->d_mask
, DF_FREQ
)) {
BITSET(dp
->d_mask
, DF_FREQ
);
} else if (dp
->d_freq
!= 0) {
"dump frequency for %s:%s is non-zero",
dp
->d_host
->h_hostname
, dp
->d_dev
);
if (!ISSET(dp
->d_mask
, DF_OPTS
))
set_disk_fs(dp
, DF_OPTS
, strdup("swap"));
if (!ISSET(dp
->d_mask
, DF_MOUNT
)) {
m
->m_name
= strdup("swap");
ins_que(&m
->m_q
, q
->q_back
);
BITSET(dp
->d_mask
, DF_MOUNT
);
lerror(dp
->d_ioloc
, "%s: mount field specified for swap partition", dp
->d_host
->h_hostname
);
} else if (STREQ(dp
->d_fstype
, "export")) {
if (!ISSET(dp
->d_mask
, DF_PASSNO
)) {
BITSET(dp
->d_mask
, DF_PASSNO
);
} else if (dp
->d_passno
!= 0) {
"pass number for %s:%s is non-zero",
dp
->d_host
->h_hostname
, dp
->d_dev
);
if (!ISSET(dp
->d_mask
, DF_FREQ
)) {
BITSET(dp
->d_mask
, DF_FREQ
);
} else if (dp
->d_freq
!= 0) {
"dump frequency for %s:%s is non-zero",
dp
->d_host
->h_hostname
, dp
->d_dev
);
if (!ISSET(dp
->d_mask
, DF_OPTS
))
set_disk_fs(dp
, DF_OPTS
, strdup("rw,defaults"));
static void fixup_required_mount_info(fp
, de
)
if (!ISSET(fp
->f_mask
, FM_FROM
)) {
lerror(fp
->f_ioloc
, "ambiguous mount: %s is a replicated filesystem", fp
->f_volname
);
ITER(dd
, dict_data
, &de
->de_q
) {
mp
= (mount
*) dd
->dd_data
;
set_fsmount(fp
, FM_FROM
, mp
->m_dk
->d_host
->h_hostname
);
log("set: %s comes from %s", fp
->f_volname
, fp
->f_from
);
if (!ISSET(fp
->f_mask
, FM_FSTYPE
)) {
set_fsmount(fp
, FM_FSTYPE
, strdup("nfs"));
log("set: fstype is %s", fp
->f_fstype
);
if (!ISSET(fp
->f_mask
, FM_OPTS
)) {
set_fsmount(fp
, FM_OPTS
, strdup("rw,nosuid,grpid,defaults"));
log("set: opts are %s", fp
->f_opts
);
if (!ISSET(fp
->f_mask
, FM_LOCALNAME
)) {
set_fsmount(fp
, FM_LOCALNAME
, strdup(fp
->f_volname
));
log("set: localname is %s", fp
->f_localname
);
lerror(fp
->f_ioloc
, "cannot determine localname since volname %s is not uniquely defined", fp
->f_volname
);
* For each disk on a host
* analyze the mount information
* and fill in any derivable
static void analyze_drives(hp
)
qelem
*q
= hp
->h_disk_fs
;
log("Disk %s:", dp
->d_dev
);
fixup_required_disk_info(dp
);
req
= ~dp
->d_mask
& DF_REQUIRED
;
show_required(dp
->d_ioloc
, req
, dp
->d_dev
, hp
->h_hostname
, disk_fs_strings
);
analyze_dkmounts(dp
, dp
->d_mount
);
* Check that all static mounts make sense and
* that the source volumes exist.
static void analyze_mounts(hp
)
char *nn
= strdup(fp
->f_volname
);
log("Mount: %s (trying %s)", fp
->f_volname
, nn
);
* Check that the from field is really exporting
* the filesystem requested.
if (ISSET(fp
->f_mask
, FM_FROM
)) {
ITER(dd
, dict_data
, &de
->de_q
) {
mount
*mp
= (mount
*) dd
->dd_data
;
if (STREQ(mp
->m_dk
->d_host
->h_hostname
, fp
->f_from
)) {
lerror(fp
->f_ioloc
, "volname %s unknown", fp
->f_volname
);
fixup_required_mount_info(fp
, de
);
req
= ~fp
->f_mask
& FM_REQUIRED
;
show_required(fp
->f_ioloc
, req
, fp
->f_volname
, hp
->h_hostname
,
} else if (strcmp(fp
->f_localname
, "/") == 0) {
} else if (strcmp(fp
->f_localname
, "swap") == 0) {
lerror(fp
->f_ioloc
, "volname %s not exported from %s", fp
->f_volname
,
fp
->f_from
? fp
->f_from
: "anywhere");
if (netbootp
&& (netbootp
!= FM_NETBOOT
))
lerror(hp
->h_ioloc
, "network booting requires both root and swap areas");
show_area_being_processed("analyze hosts", 5);
log("disks on host %s", hp
->h_hostname
);
hp
->h_hostpath
= compute_hostpath(hp
->h_hostname
);
show_area_being_processed("analyze mounts", 5);
log("mounts on host %s", hp
->h_hostname
);
* Check an automount request
static void analyze_automount(ap
)
dict_ent
*de
= find_volname(ap
->a_volname
);
if (STREQ(ap
->a_volname
, ap
->a_name
))
lerror(ap
->a_ioloc
, "unknown volname %s automounted", ap
->a_volname
);
lerror(ap
->a_ioloc
, "unknown volname %s automounted on %s", ap
->a_volname
, ap
->a_name
);
static void analyze_automount_tree(q
, pref
, lvl
)
if (lvl
> 0 || ap
->a_mount
)
if (ap
->a_name
[1] && strchr(ap
->a_name
+1, '/'))
lerror(ap
->a_ioloc
, "not allowed '/' in a directory name");
sprintf(nname
, "%s/%s", pref
, ap
->a_name
);
ap
->a_name
= strdup(nname
[1] == '/' ? nname
+1 : nname
);
log("automount point %s:", ap
->a_name
);
show_new("ana-automount");
analyze_automount_tree(ap
->a_mount
, ap
->a_name
, lvl
+1);
} else if (ap
->a_volname
) {
log("\tautomount from %s", ap
->a_volname
);
} else if (ap
->a_symlink
) {
log("\tsymlink to %s", ap
->a_symlink
);
ap
->a_volname
= strdup(ap
->a_name
);
log("\timplicit automount from %s", ap
->a_volname
);
void analyze_automounts(q
)
show_area_being_processed("analyze automount", 5);
* q is a list of automounts
analyze_automount_tree(tp
->t_mount
, "", 0);