Date: Sat, 4 Nov 2017 14:38:00 +0000 (UTC) From: Edward Tomasz Napierala <trasz@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r325392 - head/etc/autofs Message-ID: <201711041438.vA4Ec0vx097305@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: trasz Date: Sat Nov 4 14:38:00 2017 New Revision: 325392 URL: https://svnweb.freebsd.org/changeset/base/325392 Log: Add NIS automounter map, which supports rewriting of self-hosted locations to make them nullfs. PR: 221010 Submitted by: G. Paul Ziemba MFC after: 2 weeks Added: head/etc/autofs/include_nis (contents, props changed) Modified: head/etc/autofs/Makefile Modified: head/etc/autofs/Makefile ============================================================================== --- head/etc/autofs/Makefile Sat Nov 4 14:35:01 2017 (r325391) +++ head/etc/autofs/Makefile Sat Nov 4 14:38:00 2017 (r325392) @@ -1,6 +1,6 @@ # $FreeBSD$ -FILES= include_ldap special_hosts special_media special_noauto special_null +FILES= include_ldap include_nis special_hosts special_media special_noauto special_null NO_OBJ= FILESDIR= /etc/autofs Added: head/etc/autofs/include_nis ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/etc/autofs/include_nis Sat Nov 4 14:38:00 2017 (r325392) @@ -0,0 +1,180 @@ +#!/usr/bin/awk -f +#- +# Copyright (c) 2017 G. Paul Ziemba +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 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. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 +# SUCH DAMAGE. +# +# $FreeBSD$ +# + +# +# /etc/autofs/include_nis +# +# automountd Directory Services script for NIS +# +# SYNOPSIS +# include_nis <mapname> +# +# include_nis <mapname> <key> +# +# DESCRIPTION +# +# This script provides a Directory Services map for automountd +# based on NIS. Please see auto_master(5) for general information. +# +# The first form, with one argument, emits the entire named NIS map. +# The second form, with two arguments, emits the map entry for the +# key given in the second argument. +# +# This script attempts to determine the names and IP addresses +# of the local host. Map entries matching the local host are +# rewritten to specify nullfs mounts (instead of the default +# NFS) to reduce access overhead in the kernel. +# +# If a map entry contains multiple location fields, it is not changed. +# + + +# Populate list of names and IP addrs thet mean "this host" +# into myhostnames array +BEGIN { + # + # Set self hostnames + # + + "hostname -s" | getline; + myhostnames[$0] = 1; + + "hostname -f" | getline; + myhostnames[$0] = 1; + + myhostnames["localhost"] = 1 + + "hostname -f" | getline; + localdomain=$0 + myhostnames["localhost."localdomain] = 1 + + while ("ifconfig" | getline) { + if ($1 == "inet") { + myhostnames[$2] = 1; + } + } + + # debug +# print "--- hostname list start ----" +# for (i in myhostnames) { +# print i +# } +# print "--- hostname list end ----" + + if (ARGC == 2) { + # mapname only + while ("ypcat -k " ARGV[1] | getline) { + proc_mapline(1) + } + } + if (ARGC == 3) { + # mapname and keyname + while ("ypmatch " ARGV[2] " " ARGV[1] | getline) { + proc_mapline(0) + } + } + exit 0 +} + +function is_self(hostname) +{ + if (myhostnames[hostname]) { + return 1 + } + return 0 +} + +# +# Lines are of the form [key] [-opts] location1 [... locationN] +# +# indicate index of key field with first positional parameter +# 1 means keyfield is the first field +# 0 means keyfield is not present +# +function proc_mapline(keyfield) +{ + optionsfield = 0 + locationfield = 0 + locationcount = 0 + + for (i=keyfield+1; i <= NF; ++i) { + if (!optionsfield) { + if ($i ~ /^-/) { + # the first options field found on the line + optionsfield = i; + continue + } + } + # Assumption: location contains colon (":") + if (optionsfield && ($i ~ /:/) && ($i !~ /^-/)) { + ++locationcount + if (!locationfield) { + # the first location field found on the line + locationfield = i + } + } + } + + # + # If location not found, do not modify. + # + # If there is more than one location, do not modify. Rationale: + # Options are applied to all locations. We ca not have "nullfs" + # for only some locations and "nfs" for others for a given + # map key (i.e., a line). The usual reason for multiple + # locations is for redundancy using replicated volumes on + # multiple hosts, so multiple hosts imply fstype=nfs (the + # FreeBSD default for automounter maps). + # + # Hypothetically there could be a map entry with multiple + # locations all with host parts matching "me". In that case, + # it would be safe to rewrite the locations and specify + # nullfs, but the code does not handle this case. + # + if (locationcount == 1) { + # + # We have a line with exactly one location field + # + # Assumption: location has no more than one colon (":") + # + n=split($locationfield,location,":") + if (is_self(location[1])) { + $locationfield = ":" location[2] + if (optionsfield) { + # append to existing options + $optionsfield = $optionsfield ",fstype=nullfs" + } else { + # sneak in ahead of location + $locationfield = "-fstype=nullfs " $locationfield + } + } + } + + print +}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201711041438.vA4Ec0vx097305>