2001-04-17 20:45:23 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1997 Berkeley Software Design, Inc. 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.
|
|
|
|
* 3. Berkeley Software Design Inc's name may not be used to endorse or
|
|
|
|
* promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``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 BERKELEY SOFTWARE DESIGN INC 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.
|
|
|
|
*
|
|
|
|
* from BSDI nfs_lock.c,v 2.4 1998/12/14 23:49:56 jch Exp
|
|
|
|
*/
|
|
|
|
|
2001-09-18 23:32:09 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2001-04-17 20:45:23 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2004-12-06 08:31:32 +00:00
|
|
|
#include <sys/conf.h>
|
2001-04-17 20:45:23 +00:00
|
|
|
#include <sys/fcntl.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/kernel.h> /* for hz */
|
2003-04-29 13:36:06 +00:00
|
|
|
#include <sys/limits.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/lock.h>
|
2001-04-17 20:45:23 +00:00
|
|
|
#include <sys/malloc.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/lockf.h> /* for hz */ /* Must come after sys/malloc.h */
|
2001-04-17 20:45:23 +00:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/namei.h>
|
2007-04-21 18:11:19 +00:00
|
|
|
#include <sys/priv.h>
|
2001-04-17 20:45:23 +00:00
|
|
|
#include <sys/proc.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/resourcevar.h>
|
|
|
|
#include <sys/socket.h>
|
2001-04-17 20:45:23 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/unistd.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
#include <nfs/nfsproto.h>
|
2001-09-18 23:32:09 +00:00
|
|
|
#include <nfsclient/nfs.h>
|
|
|
|
#include <nfsclient/nfsmount.h>
|
|
|
|
#include <nfsclient/nfsnode.h>
|
|
|
|
#include <nfsclient/nfs_lock.h>
|
|
|
|
#include <nfsclient/nlminfo.h>
|
2001-04-17 20:45:23 +00:00
|
|
|
|
2005-10-26 07:18:37 +00:00
|
|
|
extern void (*nlminfo_release_p)(struct proc *p);
|
|
|
|
|
2005-10-31 15:41:29 +00:00
|
|
|
MALLOC_DEFINE(M_NFSLOCK, "nfsclient_lock", "NFS lock request");
|
|
|
|
MALLOC_DEFINE(M_NLMINFO, "nfsclient_nlminfo", "NFS lock process structure");
|
2004-12-06 08:31:32 +00:00
|
|
|
|
|
|
|
static int nfslockdans(struct thread *td, struct lockd_ans *ansp);
|
2005-10-26 07:18:37 +00:00
|
|
|
static void nlminfo_release(struct proc *p);
|
2004-12-06 08:31:32 +00:00
|
|
|
/*
|
|
|
|
* --------------------------------------------------------------------
|
|
|
|
* A miniature device driver which the userland uses to talk to us.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct cdev *nfslock_dev;
|
|
|
|
static struct mtx nfslock_mtx;
|
|
|
|
static int nfslock_isopen;
|
|
|
|
static TAILQ_HEAD(,__lock_msg) nfslock_list;
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfslock_open(struct cdev *dev, int oflags, int devtype, struct thread *td)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2007-04-21 18:11:19 +00:00
|
|
|
error = priv_check(td, PRIV_NFS_LOCKD);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
2004-12-06 08:31:32 +00:00
|
|
|
mtx_lock(&nfslock_mtx);
|
|
|
|
if (!nfslock_isopen) {
|
|
|
|
error = 0;
|
|
|
|
nfslock_isopen = 1;
|
|
|
|
} else {
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
mtx_unlock(&nfslock_mtx);
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfslock_close(struct cdev *dev, int fflag, int devtype, struct thread *td)
|
|
|
|
{
|
|
|
|
struct __lock_msg *lm;
|
|
|
|
|
|
|
|
mtx_lock(&nfslock_mtx);
|
|
|
|
nfslock_isopen = 0;
|
|
|
|
while (!TAILQ_EMPTY(&nfslock_list)) {
|
|
|
|
lm = TAILQ_FIRST(&nfslock_list);
|
|
|
|
/* XXX: answer request */
|
|
|
|
TAILQ_REMOVE(&nfslock_list, lm, lm_link);
|
|
|
|
free(lm, M_NFSLOCK);
|
|
|
|
}
|
|
|
|
mtx_unlock(&nfslock_mtx);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfslock_read(struct cdev *dev, struct uio *uio, int ioflag)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct __lock_msg *lm;
|
|
|
|
|
|
|
|
if (uio->uio_resid != sizeof *lm)
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
lm = NULL;
|
|
|
|
error = 0;
|
|
|
|
mtx_lock(&nfslock_mtx);
|
|
|
|
while (TAILQ_EMPTY(&nfslock_list)) {
|
|
|
|
error = msleep(&nfslock_list, &nfslock_mtx, PSOCK | PCATCH,
|
|
|
|
"nfslockd", 0);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!error) {
|
|
|
|
lm = TAILQ_FIRST(&nfslock_list);
|
|
|
|
TAILQ_REMOVE(&nfslock_list, lm, lm_link);
|
|
|
|
}
|
|
|
|
mtx_unlock(&nfslock_mtx);
|
|
|
|
if (!error) {
|
|
|
|
error = uiomove(lm, sizeof *lm, uio);
|
|
|
|
free(lm, M_NFSLOCK);
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfslock_write(struct cdev *dev, struct uio *uio, int ioflag)
|
|
|
|
{
|
|
|
|
struct lockd_ans la;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (uio->uio_resid != sizeof la)
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
error = uiomove(&la, sizeof la, uio);
|
|
|
|
if (!error)
|
|
|
|
error = nfslockdans(curthread, &la);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfslock_send(struct __lock_msg *lm)
|
|
|
|
{
|
|
|
|
struct __lock_msg *lm2;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = 0;
|
|
|
|
lm2 = malloc(sizeof *lm2, M_NFSLOCK, M_WAITOK);
|
|
|
|
mtx_lock(&nfslock_mtx);
|
|
|
|
if (nfslock_isopen) {
|
|
|
|
memcpy(lm2, lm, sizeof *lm2);
|
|
|
|
TAILQ_INSERT_TAIL(&nfslock_list, lm2, lm_link);
|
|
|
|
wakeup(&nfslock_list);
|
|
|
|
} else {
|
|
|
|
error = EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
mtx_unlock(&nfslock_mtx);
|
|
|
|
if (error)
|
|
|
|
free(lm2, M_NFSLOCK);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cdevsw nfslock_cdevsw = {
|
|
|
|
.d_version = D_VERSION,
|
|
|
|
.d_open = nfslock_open,
|
|
|
|
.d_close = nfslock_close,
|
|
|
|
.d_read = nfslock_read,
|
|
|
|
.d_write = nfslock_write,
|
|
|
|
.d_name = "nfslock"
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
nfslock_modevent(module_t mod __unused, int type, void *data __unused)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case MOD_LOAD:
|
|
|
|
if (bootverbose)
|
|
|
|
printf("nfslock: pseudo-device\n");
|
|
|
|
mtx_init(&nfslock_mtx, "nfslock", NULL, MTX_DEF);
|
|
|
|
TAILQ_INIT(&nfslock_list);
|
2005-10-26 07:18:37 +00:00
|
|
|
nlminfo_release_p = nlminfo_release;
|
2004-12-06 08:31:32 +00:00
|
|
|
nfslock_dev = make_dev(&nfslock_cdevsw, 0,
|
|
|
|
UID_ROOT, GID_KMEM, 0600, _PATH_NFSLCKDEV);
|
|
|
|
return (0);
|
|
|
|
default:
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEV_MODULE(nfslock, nfslock_modevent, NULL);
|
|
|
|
MODULE_VERSION(nfslock, 1);
|
|
|
|
|
|
|
|
|
2001-04-17 20:45:23 +00:00
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* We have to let the process know if the call succeeded. I'm using an extra
|
2001-09-18 23:32:09 +00:00
|
|
|
* field in the p_nlminfo field in the proc structure, as it is already for
|
2001-04-17 20:45:23 +00:00
|
|
|
* lockd stuff.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nfs_advlock --
|
|
|
|
* NFS advisory byte-level locks.
|
Move the head of byte-level advisory lock list from the
filesystem-specific vnode data to the struct vnode. Provide the
default implementation for the vop_advlock and vop_advlockasync.
Purge the locks on the vnode reclaim by using the lf_purgelocks().
The default implementation is augmented for the nfs and smbfs.
In the nfs_advlock, push the Giant inside the nfs_dolock.
Before the change, the vop_advlock and vop_advlockasync have taken the
unlocked vnode and dereferenced the fs-private inode data, racing with
with the vnode reclamation due to forced unmount. Now, the vop_getattr
under the shared vnode lock is used to obtain the inode size, and
later, in the lf_advlockasync, after locking the vnode interlock, the
VI_DOOMED flag is checked to prevent an operation on the doomed vnode.
The implementation of the lf_purgelocks() is submitted by dfr.
Reported by: kris
Tested by: kris, pho
Discussed with: jeff, dfr
MFC after: 2 weeks
2008-04-16 11:33:32 +00:00
|
|
|
*
|
|
|
|
* The vnode shall be (shared) locked on the entry, it is
|
|
|
|
* unconditionally unlocked after.
|
2001-04-17 20:45:23 +00:00
|
|
|
*/
|
|
|
|
int
|
2001-09-18 23:32:09 +00:00
|
|
|
nfs_dolock(struct vop_advlock_args *ap)
|
2001-04-17 20:45:23 +00:00
|
|
|
{
|
|
|
|
LOCKD_MSG msg;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
2004-12-06 08:31:32 +00:00
|
|
|
struct vnode *vp;
|
|
|
|
int error;
|
2001-04-17 20:45:23 +00:00
|
|
|
struct flock *fl;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct proc *p;
|
|
|
|
|
|
|
|
td = curthread;
|
|
|
|
p = td->td_proc;
|
2001-04-17 20:45:23 +00:00
|
|
|
|
|
|
|
vp = ap->a_vp;
|
|
|
|
fl = ap->a_fl;
|
|
|
|
|
Move the head of byte-level advisory lock list from the
filesystem-specific vnode data to the struct vnode. Provide the
default implementation for the vop_advlock and vop_advlockasync.
Purge the locks on the vnode reclaim by using the lf_purgelocks().
The default implementation is augmented for the nfs and smbfs.
In the nfs_advlock, push the Giant inside the nfs_dolock.
Before the change, the vop_advlock and vop_advlockasync have taken the
unlocked vnode and dereferenced the fs-private inode data, racing with
with the vnode reclamation due to forced unmount. Now, the vop_getattr
under the shared vnode lock is used to obtain the inode size, and
later, in the lf_advlockasync, after locking the vnode interlock, the
VI_DOOMED flag is checked to prevent an operation on the doomed vnode.
The implementation of the lf_purgelocks() is submitted by dfr.
Reported by: kris
Tested by: kris, pho
Discussed with: jeff, dfr
MFC after: 2 weeks
2008-04-16 11:33:32 +00:00
|
|
|
ASSERT_VOP_LOCKED(vp, "nfs_dolock");
|
|
|
|
|
|
|
|
bcopy(VFSTONFS(vp->v_mount)->nm_nam, &msg.lm_addr,
|
|
|
|
min(sizeof msg.lm_addr, VFSTONFS(vp->v_mount)->nm_nam->sa_len));
|
|
|
|
msg.lm_fh_len = NFS_ISV3(vp) ? VTONFS(vp)->n_fhsize : NFSX_V2FH;
|
|
|
|
bcopy(VTONFS(vp)->n_fhp, msg.lm_fh, msg.lm_fh_len);
|
|
|
|
msg.lm_nfsv3 = NFS_ISV3(vp);
|
|
|
|
VOP_UNLOCK(vp, 0);
|
|
|
|
|
2001-04-17 20:45:23 +00:00
|
|
|
/*
|
|
|
|
* the NLM protocol doesn't allow the server to return an error
|
2001-08-23 08:20:21 +00:00
|
|
|
* on ranges, so we do it.
|
2001-04-17 20:45:23 +00:00
|
|
|
*/
|
2001-08-23 14:21:26 +00:00
|
|
|
if (fl->l_whence != SEEK_END) {
|
2001-08-23 18:02:29 +00:00
|
|
|
if ((fl->l_whence != SEEK_CUR && fl->l_whence != SEEK_SET) ||
|
2001-08-23 16:13:59 +00:00
|
|
|
fl->l_start < 0 ||
|
|
|
|
(fl->l_len < 0 &&
|
|
|
|
(fl->l_start == 0 || fl->l_start + fl->l_len < 0)))
|
2001-08-23 14:21:26 +00:00
|
|
|
return (EINVAL);
|
2001-08-23 16:13:59 +00:00
|
|
|
if (fl->l_len > 0 &&
|
|
|
|
(fl->l_len - 1 > OFF_MAX - fl->l_start))
|
2001-08-23 14:21:26 +00:00
|
|
|
return (EOVERFLOW);
|
|
|
|
}
|
2001-04-17 20:45:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill in the information structure.
|
|
|
|
*/
|
|
|
|
msg.lm_version = LOCKD_MSG_VERSION;
|
|
|
|
msg.lm_msg_ident.pid = p->p_pid;
|
Move the head of byte-level advisory lock list from the
filesystem-specific vnode data to the struct vnode. Provide the
default implementation for the vop_advlock and vop_advlockasync.
Purge the locks on the vnode reclaim by using the lf_purgelocks().
The default implementation is augmented for the nfs and smbfs.
In the nfs_advlock, push the Giant inside the nfs_dolock.
Before the change, the vop_advlock and vop_advlockasync have taken the
unlocked vnode and dereferenced the fs-private inode data, racing with
with the vnode reclamation due to forced unmount. Now, the vop_getattr
under the shared vnode lock is used to obtain the inode size, and
later, in the lf_advlockasync, after locking the vnode interlock, the
VI_DOOMED flag is checked to prevent an operation on the doomed vnode.
The implementation of the lf_purgelocks() is submitted by dfr.
Reported by: kris
Tested by: kris, pho
Discussed with: jeff, dfr
MFC after: 2 weeks
2008-04-16 11:33:32 +00:00
|
|
|
|
|
|
|
mtx_lock(&Giant);
|
2001-04-17 20:45:23 +00:00
|
|
|
/*
|
|
|
|
* if there is no nfsowner table yet, allocate one.
|
|
|
|
*/
|
|
|
|
if (p->p_nlminfo == NULL) {
|
2008-10-23 20:26:15 +00:00
|
|
|
p->p_nlminfo = malloc(sizeof(struct nlminfo),
|
|
|
|
M_NLMINFO, M_WAITOK | M_ZERO);
|
2001-04-17 20:45:23 +00:00
|
|
|
p->p_nlminfo->pid_start = p->p_stats->p_start;
|
2003-05-01 16:59:23 +00:00
|
|
|
timevaladd(&p->p_nlminfo->pid_start, &boottime);
|
2001-04-17 20:45:23 +00:00
|
|
|
}
|
|
|
|
msg.lm_msg_ident.pid_start = p->p_nlminfo->pid_start;
|
|
|
|
msg.lm_msg_ident.msg_seq = ++(p->p_nlminfo->msg_seq);
|
|
|
|
|
|
|
|
msg.lm_fl = *fl;
|
|
|
|
msg.lm_wait = ap->a_flags & F_WAIT;
|
|
|
|
msg.lm_getlk = ap->a_op == F_GETLK;
|
2002-08-15 21:52:22 +00:00
|
|
|
cru2x(td->td_ucred, &msg.lm_cred);
|
2001-04-17 20:45:23 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2004-12-06 08:31:32 +00:00
|
|
|
error = nfslock_send(&msg);
|
|
|
|
if (error)
|
Move the head of byte-level advisory lock list from the
filesystem-specific vnode data to the struct vnode. Provide the
default implementation for the vop_advlock and vop_advlockasync.
Purge the locks on the vnode reclaim by using the lf_purgelocks().
The default implementation is augmented for the nfs and smbfs.
In the nfs_advlock, push the Giant inside the nfs_dolock.
Before the change, the vop_advlock and vop_advlockasync have taken the
unlocked vnode and dereferenced the fs-private inode data, racing with
with the vnode reclamation due to forced unmount. Now, the vop_getattr
under the shared vnode lock is used to obtain the inode size, and
later, in the lf_advlockasync, after locking the vnode interlock, the
VI_DOOMED flag is checked to prevent an operation on the doomed vnode.
The implementation of the lf_purgelocks() is submitted by dfr.
Reported by: kris
Tested by: kris, pho
Discussed with: jeff, dfr
MFC after: 2 weeks
2008-04-16 11:33:32 +00:00
|
|
|
goto out;
|
2001-04-17 20:45:23 +00:00
|
|
|
|
2004-12-06 08:31:32 +00:00
|
|
|
/* Unlocks succeed immediately. */
|
2001-04-17 20:45:23 +00:00
|
|
|
if (fl->l_type == F_UNLCK)
|
Move the head of byte-level advisory lock list from the
filesystem-specific vnode data to the struct vnode. Provide the
default implementation for the vop_advlock and vop_advlockasync.
Purge the locks on the vnode reclaim by using the lf_purgelocks().
The default implementation is augmented for the nfs and smbfs.
In the nfs_advlock, push the Giant inside the nfs_dolock.
Before the change, the vop_advlock and vop_advlockasync have taken the
unlocked vnode and dereferenced the fs-private inode data, racing with
with the vnode reclamation due to forced unmount. Now, the vop_getattr
under the shared vnode lock is used to obtain the inode size, and
later, in the lf_advlockasync, after locking the vnode interlock, the
VI_DOOMED flag is checked to prevent an operation on the doomed vnode.
The implementation of the lf_purgelocks() is submitted by dfr.
Reported by: kris
Tested by: kris, pho
Discussed with: jeff, dfr
MFC after: 2 weeks
2008-04-16 11:33:32 +00:00
|
|
|
goto out;
|
2001-04-17 20:45:23 +00:00
|
|
|
|
|
|
|
/*
|
2006-08-16 23:53:05 +00:00
|
|
|
* Retry after 20 seconds if we haven't gotten a response yet.
|
2001-04-17 20:45:23 +00:00
|
|
|
* This number was picked out of thin air... but is longer
|
|
|
|
* then even a reasonably loaded system should take (at least
|
2001-09-18 23:32:09 +00:00
|
|
|
* on a local network). XXX Probably should use a back-off
|
2001-04-17 20:45:23 +00:00
|
|
|
* scheme.
|
2003-06-11 03:32:42 +00:00
|
|
|
*
|
|
|
|
* XXX: No PCATCH here since we currently have no useful
|
|
|
|
* way to signal to the userland rpc.lockd that the request
|
|
|
|
* has been aborted. Once the rpc.lockd implementation
|
|
|
|
* can handle aborts, and we report them properly,
|
|
|
|
* PCATCH can be put back. In the mean time, if we did
|
|
|
|
* permit aborting, the lock attempt would "get lost"
|
|
|
|
* and the lock would get stuck in the locked state.
|
2001-04-17 20:45:23 +00:00
|
|
|
*/
|
rpc.lockd stability workaround: remove PCATCH from the tsleep() in
nfs_lock.c. Right now, if we permit a signal to interrupt the sleep,
we will slip the lock and no process on that client, the server, or
any other client will be able to acquire the lock. This can happen,
for example, if a user hits Ctrl-C or Ctrl-T while a process is
waiting for the lock. By removing PCATCH, we prevent that from
happening, at the cost of not permitting a user-requested lock abort:
also nasty. However, a user interface bug might be preferable to a
serious semantic bug, so we go with that for now.
We need to teach the rpc.lockd/kernel protocol how to abort lock
requests, and rpc.lockd how to handle aborted lock requests; patches
for the kernel bit are floating around, but no rpc.lockd bit yet.
Approved by: re (scottl)
2003-05-30 17:15:56 +00:00
|
|
|
error = tsleep(p->p_nlminfo, PUSER, "lockd", 20*hz);
|
2002-11-20 15:21:06 +00:00
|
|
|
if (error != 0) {
|
2001-04-17 20:45:23 +00:00
|
|
|
if (error == EWOULDBLOCK) {
|
|
|
|
/*
|
|
|
|
* We timed out, so we rewrite the request
|
2006-01-13 23:16:29 +00:00
|
|
|
* to the fifo.
|
2001-04-17 20:45:23 +00:00
|
|
|
*/
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg.lm_getlk && p->p_nlminfo->retcode == 0) {
|
|
|
|
if (p->p_nlminfo->set_getlk_pid) {
|
2008-03-26 15:23:12 +00:00
|
|
|
fl->l_sysid = 0; /* XXX */
|
2001-04-17 20:45:23 +00:00
|
|
|
fl->l_pid = p->p_nlminfo->getlk_pid;
|
|
|
|
} else {
|
|
|
|
fl->l_type = F_UNLCK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error = p->p_nlminfo->retcode;
|
|
|
|
break;
|
|
|
|
}
|
Move the head of byte-level advisory lock list from the
filesystem-specific vnode data to the struct vnode. Provide the
default implementation for the vop_advlock and vop_advlockasync.
Purge the locks on the vnode reclaim by using the lf_purgelocks().
The default implementation is augmented for the nfs and smbfs.
In the nfs_advlock, push the Giant inside the nfs_dolock.
Before the change, the vop_advlock and vop_advlockasync have taken the
unlocked vnode and dereferenced the fs-private inode data, racing with
with the vnode reclamation due to forced unmount. Now, the vop_getattr
under the shared vnode lock is used to obtain the inode size, and
later, in the lf_advlockasync, after locking the vnode interlock, the
VI_DOOMED flag is checked to prevent an operation on the doomed vnode.
The implementation of the lf_purgelocks() is submitted by dfr.
Reported by: kris
Tested by: kris, pho
Discussed with: jeff, dfr
MFC after: 2 weeks
2008-04-16 11:33:32 +00:00
|
|
|
out:
|
|
|
|
mtx_unlock(&Giant);
|
2004-12-06 08:31:32 +00:00
|
|
|
return (error);
|
2001-04-17 20:45:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* nfslockdans --
|
|
|
|
* NFS advisory byte-level locks answer from the lock daemon.
|
|
|
|
*/
|
2004-12-06 08:31:32 +00:00
|
|
|
static int
|
2001-11-14 18:20:45 +00:00
|
|
|
nfslockdans(struct thread *td, struct lockd_ans *ansp)
|
2001-04-17 20:45:23 +00:00
|
|
|
{
|
2001-11-14 18:20:45 +00:00
|
|
|
struct proc *targetp;
|
2001-04-17 20:45:23 +00:00
|
|
|
|
|
|
|
/* the version should match, or we're out of sync */
|
|
|
|
if (ansp->la_vers != LOCKD_ANS_VERSION)
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
/* Find the process, set its return errno and wake it up. */
|
2001-11-14 18:20:45 +00:00
|
|
|
if ((targetp = pfind(ansp->la_msg_ident.pid)) == NULL)
|
2001-04-17 20:45:23 +00:00
|
|
|
return (ESRCH);
|
|
|
|
|
2001-09-18 23:32:09 +00:00
|
|
|
/* verify the pid hasn't been reused (if we can), and it isn't waiting
|
2001-04-17 20:45:23 +00:00
|
|
|
* for an answer from a more recent request. We return an EPIPE if
|
|
|
|
* the match fails, because we've already used ESRCH above, and this
|
|
|
|
* is sort of like writing on a pipe after the reader has closed it.
|
|
|
|
*/
|
2001-11-14 18:20:45 +00:00
|
|
|
if (targetp->p_nlminfo == NULL ||
|
2001-04-17 20:45:23 +00:00
|
|
|
((ansp->la_msg_ident.msg_seq != -1) &&
|
2001-11-14 18:20:45 +00:00
|
|
|
(timevalcmp(&targetp->p_nlminfo->pid_start,
|
2001-04-17 20:45:23 +00:00
|
|
|
&ansp->la_msg_ident.pid_start, !=) ||
|
2001-11-14 18:20:45 +00:00
|
|
|
targetp->p_nlminfo->msg_seq != ansp->la_msg_ident.msg_seq))) {
|
|
|
|
PROC_UNLOCK(targetp);
|
2001-04-17 20:45:23 +00:00
|
|
|
return (EPIPE);
|
2001-06-01 01:30:51 +00:00
|
|
|
}
|
2001-04-17 20:45:23 +00:00
|
|
|
|
2001-11-14 18:20:45 +00:00
|
|
|
targetp->p_nlminfo->retcode = ansp->la_errno;
|
|
|
|
targetp->p_nlminfo->set_getlk_pid = ansp->la_set_getlk_pid;
|
|
|
|
targetp->p_nlminfo->getlk_pid = ansp->la_getlk_pid;
|
2001-04-17 20:45:23 +00:00
|
|
|
|
2002-11-20 15:21:06 +00:00
|
|
|
wakeup(targetp->p_nlminfo);
|
2001-04-17 20:45:23 +00:00
|
|
|
|
2001-11-14 18:20:45 +00:00
|
|
|
PROC_UNLOCK(targetp);
|
2001-04-17 20:45:23 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2004-12-06 08:31:32 +00:00
|
|
|
|
2005-10-26 07:18:37 +00:00
|
|
|
/*
|
|
|
|
* Free nlminfo attached to process.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nlminfo_release(struct proc *p)
|
|
|
|
{
|
|
|
|
free(p->p_nlminfo, M_NLMINFO);
|
|
|
|
p->p_nlminfo = NULL;
|
|
|
|
}
|