/*
* Copyright (c) 1997-2014 Erez Zadok
* Copyright (c) 1990 Jan-Simon Pendry
* Copyright (c) 1990 Imperial College of Science, Technology & Medicine
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* 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
* 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.
* 3. 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
* SUCH DAMAGE.
*
*
* File: am-utils/amd/mntfs.c
*
*/
/* find a matching mntfs in our list */
mntfs *
locate_mntfs(am_ops *ops, am_opts *mo, char *mp, char *info, char *auto_opts, char *mopts, char *remopts)
{
mntfs *mf;
dlog("Locating mntfs reference to (%s,%s)", mp, info);
ITER(mf, mntfs, &mfhead) {
/*
* For backwards compatibility purposes, we treat already-mounted
* filesystems differently and only require a match of their mount point,
* not of their server info. After all, there is little we can do if
* the user asks us to mount two different things onto the same mount: one
* will always cover the other one.
*/
if (STREQ(mf->mf_mount, mp) &&
((mf->mf_flags & MFF_MOUNTED && !(mf->mf_fsflags & FS_DIRECT))
|| (STREQ(mf->mf_info, info) && mf->mf_ops == ops))) {
/*
* Handle cases where error ops are involved
*/
if (ops == &amfs_error_ops) {
/*
* If the existing ops are not amfs_error_ops
* then continue...
*/
if (mf->mf_ops != &amfs_error_ops)
continue;
return dup_mntfs(mf);
}
/*
* If we are restarting an amd internal filesystem,
* we need to initialize it a bit.
*
* We know it's internal because it is marked as toplvl.
*/
if (mf->mf_ops == &amfs_toplvl_ops) {
mf->mf_ops = ops;
mf->mf_info = strealloc(mf->mf_info, info);
ops->mounted(mf); /* XXX: not right, but will do for now */
}
/*
* We shouldn't ever be called to free something that has
* a non-positive refcount. Something is badly wrong if
* we have been! Ignore the request for now...
*/
if (mf->mf_refc <= 0) {
plog(XLOG_ERROR, "IGNORING free_mntfs for <%s>: refc %d, flags %x (bug?)",
mf->mf_mount, mf->mf_refc, mf->mf_flags);
return;
}
/* don't discard last reference of a restarted/kept mntfs */
if (mf->mf_refc == 1 && mf->mf_flags & MFF_RSTKEEP) {
plog(XLOG_ERROR, "IGNORING free_mntfs for <%s>: refc %d, flags %x (restarted)",
mf->mf_mount, mf->mf_refc, mf->mf_flags);
return;
}
if (--mf->mf_refc == 0) {
if (mf->mf_flags & MFF_MOUNTED) {
int quoted;
mf->mf_flags &= ~MFF_MOUNTED;
if (mf->mf_refc == 1 &&
mf->mf_flags & MFF_RESTART &&
STREQ(mf->mf_mount, mp)) {
/*
* If we are inheriting then just return
* the same node...
*/
return mf;
}
/*
* Re-use the existing mntfs if it is mounted.
* This traps a race in nfsx.
*/
if (mf->mf_ops != &amfs_error_ops &&
(mf->mf_flags & MFF_MOUNTED) &&
!FSRV_ISDOWN(mf->mf_server)) {
return mf;
}