netmount, localmount, halt.sh and net scripts now check OS specific flags to see if a mount is network mounted (linux = fstab, *bsd = "local" in mount options) or not, #192772.
This commit is contained in:
parent
e89805e0c0
commit
dc0ba7ebf3
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
09 Oct 2007; Roy Marples <uberlord@gentoo.org>:
|
09 Oct 2007; Roy Marples <uberlord@gentoo.org>:
|
||||||
|
|
||||||
|
netmount, localmount, halt.sh and net scripts now check OS specific flags
|
||||||
|
to see if a mount is network mounted (linux = fstab, *bsd = "local" in
|
||||||
|
mount options) or not, #192772.
|
||||||
txqueuelen_eth0= now works, #190538.
|
txqueuelen_eth0= now works, #190538.
|
||||||
|
|
||||||
03 Oct 2007; Roy Marples <uberlord@gentoo.org>:
|
03 Oct 2007; Roy Marples <uberlord@gentoo.org>:
|
||||||
|
@ -72,7 +72,9 @@ if [ "${RC_UNAME}" = "Linux" ] ; then
|
|||||||
fs="${fs}${fs:+|}${x}"
|
fs="${fs}${fs:+|}${x}"
|
||||||
done
|
done
|
||||||
[ -n "${fs}" ] && fs="^(${fs})$"
|
[ -n "${fs}" ] && fs="^(${fs})$"
|
||||||
do_unmount "mount -n -o remount,ro" "^(/dev|/dev/.*|/proc|/proc/.*|/sys|/sys/.*)$" "" "" "${fs}"
|
do_unmount "mount -n -o remount,ro" \
|
||||||
|
--skip-point-regex "^(/dev|/dev/.*|/proc|/proc/.*|/sys|/sys/.*)$" \
|
||||||
|
${fs:+--skip-fstype-regex} ${fs} --nonetdev
|
||||||
eoutdent
|
eoutdent
|
||||||
eend $?
|
eend $?
|
||||||
unmounted=$?
|
unmounted=$?
|
||||||
|
@ -203,7 +203,8 @@ stop() {
|
|||||||
# Umount loopback devices
|
# Umount loopback devices
|
||||||
einfo "Unmounting loopback devices"
|
einfo "Unmounting loopback devices"
|
||||||
eindent
|
eindent
|
||||||
do_unmount "umount -d" "${no_umounts}" "^/dev/loop"
|
do_unmount "umount -d" --skip-point-regex "${no_umounts}" \
|
||||||
|
--node-regex "^/dev/loop"
|
||||||
eoutdent
|
eoutdent
|
||||||
|
|
||||||
# Now everything else, except network filesystems as the
|
# Now everything else, except network filesystems as the
|
||||||
@ -215,7 +216,8 @@ stop() {
|
|||||||
fs="${fs}${fs:+|}${x}"
|
fs="${fs}${fs:+|}${x}"
|
||||||
done
|
done
|
||||||
[ -n "${fs}" ] && fs="^(${fs})$"
|
[ -n "${fs}" ] && fs="^(${fs})$"
|
||||||
do_unmount "umount" "${no_umounts}" "" "" "${fs}"
|
do_unmount "umount" --skip-point-regex "${no_umounts}" \
|
||||||
|
${fs:+--skip-fstype-regex} ${fs} --nonetdev
|
||||||
eoutdent
|
eoutdent
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
@ -21,7 +21,7 @@ depend() {
|
|||||||
# Only have portmap as a dependency if there is a nfs mount in fstab that
|
# Only have portmap as a dependency if there is a nfs mount in fstab that
|
||||||
# is set to mount at boot
|
# is set to mount at boot
|
||||||
local pmap=""
|
local pmap=""
|
||||||
if need_portmap ; then
|
if need_portmap; then
|
||||||
[ -x /etc/init.d/rpcbind ] \
|
[ -x /etc/init.d/rpcbind ] \
|
||||||
&& pmap="rpcbind" \
|
&& pmap="rpcbind" \
|
||||||
|| pmap="portmap"
|
|| pmap="portmap"
|
||||||
@ -37,7 +37,7 @@ start() {
|
|||||||
[ -x /etc/init.d/rpcbind ] && pmap="rpcbind"
|
[ -x /etc/init.d/rpcbind ] && pmap="rpcbind"
|
||||||
|
|
||||||
local x= fs=
|
local x= fs=
|
||||||
for x in ${RC_NET_FS_LIST} ; do
|
for x in ${RC_NET_FS_LIST}; do
|
||||||
case "${x}" in
|
case "${x}" in
|
||||||
nfs|nfs4)
|
nfs|nfs4)
|
||||||
# If the nfsmount script took care of the nfs filesystems,
|
# If the nfsmount script took care of the nfs filesystems,
|
||||||
@ -47,7 +47,7 @@ start() {
|
|||||||
# Only try to mount NFS filesystems if portmap was started.
|
# Only try to mount NFS filesystems if portmap was started.
|
||||||
# This is to fix "hang" problems for new users who do not
|
# This is to fix "hang" problems for new users who do not
|
||||||
# add portmap to the default runlevel.
|
# add portmap to the default runlevel.
|
||||||
if need_portmap && ! service_started "${pmap}" ; then
|
if need_portmap && ! service_started "${pmap}"; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@ -63,28 +63,28 @@ start() {
|
|||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
local x= fs=
|
local x= fs=
|
||||||
|
|
||||||
|
ebegin "Unmounting network filesystems"
|
||||||
|
. "${RC_LIBDIR}/sh/rc-mount.sh"
|
||||||
|
|
||||||
for x in ${RC_NET_FS_LIST} ; do
|
for x in ${RC_NET_FS_LIST} ; do
|
||||||
fs="${fs}${fs:+,}${x}"
|
fs="${fs}${fs:+,}${x}"
|
||||||
done
|
done
|
||||||
|
if [ -n "${fs}" ]; then
|
||||||
ebegin "Unmounting network filesystems"
|
umount -at ${fs} || eerror "Failed to simply unmount filesystems"
|
||||||
umount -at ${fs}
|
|
||||||
local retval=$?
|
|
||||||
eend ${retval} "Failed to simply unmount filesystems"
|
|
||||||
|
|
||||||
if [ ${retval} -ne 0 ] ; then
|
|
||||||
. "${RC_LIBDIR}/sh/rc-mount.sh"
|
|
||||||
eindent
|
|
||||||
fs=
|
|
||||||
for x in ${RC_NET_FS_LIST} ; do
|
|
||||||
fs="${fs:+|}${x}"
|
|
||||||
done
|
|
||||||
do_unmount "umount" "" "" "^(${fs})$"
|
|
||||||
retval=$?
|
|
||||||
eoutdent
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return ${retval}
|
eindent
|
||||||
|
fs=
|
||||||
|
for x in ${RC_NET_FS_LIST}; do
|
||||||
|
fs="${fs}${fs:+|}${x}"
|
||||||
|
done
|
||||||
|
[ -n "${fs}" ] && fs="^(${fs})$"
|
||||||
|
do_unmount "umount" ${fs:+--fstype-regex} ${fs} --netdev
|
||||||
|
retval=$?
|
||||||
|
|
||||||
|
eoutdent
|
||||||
|
eend ${retval} "Failed to unmount network filesystems"
|
||||||
}
|
}
|
||||||
|
|
||||||
# vim: set ts=4 :
|
# vim: set ts=4 :
|
||||||
|
@ -26,6 +26,11 @@ stop_addon() {
|
|||||||
is_net_fs() {
|
is_net_fs() {
|
||||||
[ -z "$1" ] && return 1
|
[ -z "$1" ] && return 1
|
||||||
|
|
||||||
|
# Check OS specific flags to see if we're local or net mounted
|
||||||
|
mountinfo --quiet --netdev "$1" && return 0
|
||||||
|
mountinfo --quiet --nonetdev "$1" && return 1
|
||||||
|
|
||||||
|
# Fall back on fs types
|
||||||
local t=$(mountinfo --fstype "$1")
|
local t=$(mountinfo --fstype "$1")
|
||||||
for x in ${RC_NET_FS_LIST}; do
|
for x in ${RC_NET_FS_LIST}; do
|
||||||
[ "${x}" = "${t}" ] && return 0
|
[ "${x}" = "${t}" ] && return 0
|
||||||
|
@ -12,8 +12,8 @@ do_unmount() {
|
|||||||
f_kill="-"
|
f_kill="-"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mountinfo ${2:+--skip-point-regex} $2 ${3:+--node-regex} $3 ${4:+--fstype-regex} $4 ${5:+--skip-fstype-regex} $5 | \
|
shift
|
||||||
while read mnt; do
|
mountinfo "$@" | while read mnt; do
|
||||||
case "${cmd}" in
|
case "${cmd}" in
|
||||||
umount*)
|
umount*)
|
||||||
# If we're using the mount (probably /usr) then don't unmount us
|
# If we're using the mount (probably /usr) then don't unmount us
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/ucred.h>
|
#include <sys/ucred.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
#elif defined (__linux__)
|
||||||
|
#include <mntent.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -38,6 +40,12 @@ typedef enum {
|
|||||||
mount_options
|
mount_options
|
||||||
} mount_type;
|
} mount_type;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
net_ignore,
|
||||||
|
net_yes,
|
||||||
|
net_no
|
||||||
|
} net_opts;
|
||||||
|
|
||||||
struct args {
|
struct args {
|
||||||
regex_t *node_regex;
|
regex_t *node_regex;
|
||||||
regex_t *skip_node_regex;
|
regex_t *skip_node_regex;
|
||||||
@ -47,10 +55,12 @@ struct args {
|
|||||||
regex_t *skip_options_regex;
|
regex_t *skip_options_regex;
|
||||||
char **mounts;
|
char **mounts;
|
||||||
mount_type mount_type;
|
mount_type mount_type;
|
||||||
|
net_opts netdev;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int process_mount (char ***list, struct args *args,
|
static int process_mount (char ***list, struct args *args,
|
||||||
char *from, char *to, char *fstype, char *options)
|
char *from, char *to, char *fstype, char *options,
|
||||||
|
int netdev)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
@ -62,26 +72,34 @@ static int process_mount (char ***list, struct args *args,
|
|||||||
return (-1);
|
return (-1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (args->node_regex &&
|
if (args->netdev == net_yes && netdev != -1) {
|
||||||
regexec (args->node_regex, from, 0, NULL, 0) != 0)
|
if (netdev != 0)
|
||||||
return (1);
|
return (1);
|
||||||
if (args->skip_node_regex &&
|
} else if (args->netdev == net_no && netdev != -1) {
|
||||||
regexec (args->skip_node_regex, from, 0, NULL, 0) == 0)
|
if (netdev != 1)
|
||||||
return (1);
|
return (1);
|
||||||
|
} else {
|
||||||
|
if (args->node_regex &&
|
||||||
|
regexec (args->node_regex, from, 0, NULL, 0) != 0)
|
||||||
|
return (1);
|
||||||
|
if (args->skip_node_regex &&
|
||||||
|
regexec (args->skip_node_regex, from, 0, NULL, 0) == 0)
|
||||||
|
return (1);
|
||||||
|
|
||||||
if (args->fstype_regex &&
|
if (args->fstype_regex &&
|
||||||
regexec (args->fstype_regex, fstype, 0, NULL, 0) != 0)
|
regexec (args->fstype_regex, fstype, 0, NULL, 0) != 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
if (args->skip_fstype_regex &&
|
if (args->skip_fstype_regex &&
|
||||||
regexec (args->skip_fstype_regex, fstype, 0, NULL, 0) == 0)
|
regexec (args->skip_fstype_regex, fstype, 0, NULL, 0) == 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
if (args->options_regex &&
|
if (args->options_regex &&
|
||||||
regexec (args->options_regex, options, 0, NULL, 0) != 0)
|
regexec (args->options_regex, options, 0, NULL, 0) != 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
if (args->skip_options_regex &&
|
if (args->skip_options_regex &&
|
||||||
regexec (args->skip_options_regex, options, 0, NULL, 0) == 0)
|
regexec (args->skip_options_regex, options, 0, NULL, 0) == 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
}
|
||||||
|
|
||||||
if (args->mounts) {
|
if (args->mounts) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
@ -169,9 +187,12 @@ static char **find_mounts (struct args *args)
|
|||||||
eerrorx ("getmntinfo: %s", strerror (errno));
|
eerrorx ("getmntinfo: %s", strerror (errno));
|
||||||
|
|
||||||
for (i = 0; i < nmnts; i++) {
|
for (i = 0; i < nmnts; i++) {
|
||||||
|
int netdev = 0;
|
||||||
flags = mnts[i].f_flags & MNT_VISFLAGMASK;
|
flags = mnts[i].f_flags & MNT_VISFLAGMASK;
|
||||||
for (o = optnames; flags && o->o_opt; o++) {
|
for (o = optnames; flags && o->o_opt; o++) {
|
||||||
if (flags & o->o_opt) {
|
if (flags & o->o_opt) {
|
||||||
|
if (o->o_opt == MNT_LOCAL)
|
||||||
|
netdev = 1;
|
||||||
if (! options)
|
if (! options)
|
||||||
options = xstrdup (o->o_name);
|
options = xstrdup (o->o_name);
|
||||||
else {
|
else {
|
||||||
@ -188,7 +209,8 @@ static char **find_mounts (struct args *args)
|
|||||||
mnts[i].f_mntfromname,
|
mnts[i].f_mntfromname,
|
||||||
mnts[i].f_mntonname,
|
mnts[i].f_mntonname,
|
||||||
mnts[i].f_fstypename,
|
mnts[i].f_fstypename,
|
||||||
options);
|
options,
|
||||||
|
netdev);
|
||||||
|
|
||||||
free (options);
|
free (options);
|
||||||
options = NULL;
|
options = NULL;
|
||||||
@ -198,6 +220,20 @@ static char **find_mounts (struct args *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#elif defined (__linux__)
|
#elif defined (__linux__)
|
||||||
|
static struct mntent *getmntfile (const char *file)
|
||||||
|
{
|
||||||
|
struct mntent *ent = NULL;
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
fp = setmntent ("/etc/fstab", "r");
|
||||||
|
while ((ent = getmntent (fp)))
|
||||||
|
if (strcmp (file, ent->mnt_dir) == 0)
|
||||||
|
break;
|
||||||
|
endmntent (fp);
|
||||||
|
|
||||||
|
return (ent);
|
||||||
|
}
|
||||||
|
|
||||||
static char **find_mounts (struct args *args)
|
static char **find_mounts (struct args *args)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
@ -208,18 +244,26 @@ static char **find_mounts (struct args *args)
|
|||||||
char *fst;
|
char *fst;
|
||||||
char *opts;
|
char *opts;
|
||||||
char **list = NULL;
|
char **list = NULL;
|
||||||
|
struct mntent *ent;
|
||||||
|
int netdev;
|
||||||
|
|
||||||
if ((fp = fopen ("/proc/mounts", "r")) == NULL)
|
if ((fp = fopen ("/proc/mounts", "r")) == NULL)
|
||||||
eerrorx ("getmntinfo: %s", strerror (errno));
|
eerrorx ("getmntinfo: %s", strerror (errno));
|
||||||
|
|
||||||
while (fgets (buffer, sizeof (buffer), fp)) {
|
while (fgets (buffer, sizeof (buffer), fp)) {
|
||||||
|
netdev = -1;
|
||||||
p = buffer;
|
p = buffer;
|
||||||
from = strsep (&p, " ");
|
from = strsep (&p, " ");
|
||||||
to = strsep (&p, " ");
|
to = strsep (&p, " ");
|
||||||
fst = strsep (&p, " ");
|
fst = strsep (&p, " ");
|
||||||
opts = strsep (&p, " ");
|
opts = strsep (&p, " ");
|
||||||
|
|
||||||
process_mount (&list, args, from, to, fst, opts);
|
if ((ent = getmntfile (to))) {
|
||||||
|
if (strstr (ent->mnt_opts, "_netdev"))
|
||||||
|
netdev = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
process_mount (&list, args, from, to, fst, opts, netdev);
|
||||||
}
|
}
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
|
|
||||||
@ -260,6 +304,8 @@ static struct option longopts[] = {
|
|||||||
{ "options", 0, NULL, 'i'},
|
{ "options", 0, NULL, 'i'},
|
||||||
{ "fstype", 0, NULL, 's'},
|
{ "fstype", 0, NULL, 's'},
|
||||||
{ "node", 0, NULL, 't'},
|
{ "node", 0, NULL, 't'},
|
||||||
|
{ "netdev", 0, NULL, 'e'},
|
||||||
|
{ "nonetdev", 0, NULL, 'E'},
|
||||||
longopts_COMMON
|
longopts_COMMON
|
||||||
{ NULL, 0, NULL, 0}
|
{ NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
@ -298,11 +344,18 @@ int mountinfo (int argc, char **argv)
|
|||||||
|
|
||||||
memset (&args, 0, sizeof (struct args));
|
memset (&args, 0, sizeof (struct args));
|
||||||
args.mount_type = mount_to;
|
args.mount_type = mount_to;
|
||||||
|
args.netdev = net_ignore;
|
||||||
|
|
||||||
while ((opt = getopt_long (argc, argv, getoptstring,
|
while ((opt = getopt_long (argc, argv, getoptstring,
|
||||||
longopts, (int *) 0)) != -1)
|
longopts, (int *) 0)) != -1)
|
||||||
{
|
{
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
|
case 'e':
|
||||||
|
args.netdev = net_yes;
|
||||||
|
break;
|
||||||
|
case 'E':
|
||||||
|
args.netdev = net_no;
|
||||||
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
DO_REG (args.fstype_regex);
|
DO_REG (args.fstype_regex);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user