#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/fcntl.h>
#include <sys/kernel.h>
#include <sys/file_internal.h>
#include <sys/malloc.h>
#include <sys/lockf.h>
#include <sys/kpi_mbuf.h>
#include <sys/mount_internal.h>
#include <sys/proc_internal.h>
#include <sys/kauth.h>
#include <sys/resourcevar.h>
#include <sys/socket.h>
#include <sys/unistd.h>
#include <sys/user.h>
#include <sys/vnode_internal.h>
#include <kern/thread.h>
#include <kern/host.h>
#include <machine/limits.h>
#include <net/if.h>
#include <nfs/rpcv2.h>
#include <nfs/nfsproto.h>
#include <nfs/nfs.h>
#include <nfs/nfs_gss.h>
#include <nfs/nfsmount.h>
#include <nfs/nfsnode.h>
#include <nfs/nfs_lock.h>
#include <mach/host_priv.h>
#include <mach/mig_errors.h>
#include <mach/host_special_ports.h>
#include <lockd/lockd_mach.h>
extern void ipc_port_release_send(ipc_port_t);
static uint64_t nfs_lockxid = 0;
static LOCKD_MSG_QUEUE nfs_pendlockq;
TAILQ_HEAD(nfs_lockd_mount_list,nfsmount) nfs_lockd_mount_list;
static lck_grp_t *nfs_lock_lck_grp;
static lck_mtx_t *nfs_lock_mutex;
void nfs_lockdmsg_enqueue(LOCKD_MSG_REQUEST *);
void nfs_lockdmsg_dequeue(LOCKD_MSG_REQUEST *);
int nfs_lockdmsg_compare_to_answer(LOCKD_MSG_REQUEST *, struct lockd_ans *);
LOCKD_MSG_REQUEST *nfs_lockdmsg_find_by_answer(struct lockd_ans *);
LOCKD_MSG_REQUEST *nfs_lockdmsg_find_by_xid(uint64_t);
uint64_t nfs_lockxid_get(void);
int nfs_lockd_send_request(LOCKD_MSG *, int);
void
nfs_lockinit(void)
{
TAILQ_INIT(&nfs_pendlockq);
TAILQ_INIT(&nfs_lockd_mount_list);
nfs_lock_lck_grp = lck_grp_alloc_init("nfs_lock", LCK_GRP_ATTR_NULL);
nfs_lock_mutex = lck_mtx_alloc_init(nfs_lock_lck_grp, LCK_ATTR_NULL);
}
void
nfs_lockd_mount_register(struct nfsmount *nmp)
{
lck_mtx_lock(nfs_lock_mutex);
TAILQ_INSERT_HEAD(&nfs_lockd_mount_list, nmp, nm_ldlink);
nfs_lockd_mounts++;
lck_mtx_unlock(nfs_lock_mutex);
}
void
nfs_lockd_mount_unregister(struct nfsmount *nmp)
{
int send_shutdown;
mach_port_t lockd_port = IPC_PORT_NULL;
kern_return_t kr;
lck_mtx_lock(nfs_lock_mutex);
if (nmp->nm_ldlink.tqe_next == NFSNOLIST) {
lck_mtx_unlock(nfs_lock_mutex);
return;
}
TAILQ_REMOVE(&nfs_lockd_mount_list, nmp, nm_ldlink);
nmp->nm_ldlink.tqe_next = NFSNOLIST;
nfs_lockd_mounts--;
send_shutdown = ((nfs_lockd_mounts == 0) && nfs_lockd_request_sent);
if (send_shutdown)
nfs_lockd_request_sent = 0;
lck_mtx_unlock(nfs_lock_mutex);
if (!send_shutdown)
return;
kr = host_get_lockd_port(host_priv_self(), &lockd_port);
if ((kr != KERN_SUCCESS) || !IPC_PORT_VALID(lockd_port)) {
printf("nfs_lockd_mount_change: shutdown couldn't get port, kr %d, port %s\n",
kr, (lockd_port == IPC_PORT_NULL) ? "NULL" :
(lockd_port == IPC_PORT_DEAD) ? "DEAD" : "VALID");
return;
}
kr = lockd_shutdown(lockd_port);
if (kr != KERN_SUCCESS)
printf("nfs_lockd_mount_change: shutdown %d\n", kr);
ipc_port_release_send(lockd_port);
}
void
nfs_lockdmsg_enqueue(LOCKD_MSG_REQUEST *msgreq)
{
LOCKD_MSG_REQUEST *mr;
mr = TAILQ_LAST(&nfs_pendlockq, nfs_lock_msg_queue);
if (!mr || (msgreq->lmr_msg.lm_xid > mr->lmr_msg.lm_xid)) {
TAILQ_INSERT_TAIL(&nfs_pendlockq, msgreq, lmr_next);
return;
}
while (mr && (msgreq->lmr_msg.lm_xid > mr->lmr_msg.lm_xid)) {
mr = TAILQ_PREV(mr, nfs_lock_msg_queue, lmr_next);
}
if (mr) {
TAILQ_INSERT_AFTER(&nfs_pendlockq, mr, msgreq, lmr_next);
} else {
TAILQ_INSERT_HEAD(&nfs_pendlockq, msgreq, lmr_next);
}
}
void
nfs_lockdmsg_dequeue(LOCKD_MSG_REQUEST *msgreq)
{
TAILQ_REMOVE(&nfs_pendlockq, msgreq, lmr_next);
}
LOCKD_MSG_REQUEST *
nfs_lockdmsg_find_by_xid(uint64_t lockxid)
{
LOCKD_MSG_REQUEST *mr;
TAILQ_FOREACH(mr, &nfs_pendlockq, lmr_next) {
if (mr->lmr_msg.lm_xid == lockxid)
return mr;
if (mr->lmr_msg.lm_xid > lockxid)
return NULL;
}
return mr;
}
int
nfs_lockdmsg_compare_to_answer(LOCKD_MSG_REQUEST *msgreq, struct lockd_ans *ansp)
{
if (!(ansp->la_flags & LOCKD_ANS_LOCK_INFO))
return 1;
if (msgreq->lmr_msg.lm_fl.l_pid != ansp->la_pid)
return 1;
if (msgreq->lmr_msg.lm_fl.l_start != ansp->la_start)
return 1;
if (msgreq->lmr_msg.lm_fl.l_len != ansp->la_len)
return 1;
if (msgreq->lmr_msg.lm_fh_len != ansp->la_fh_len)
return 1;
if (bcmp(msgreq->lmr_msg.lm_fh, ansp->la_fh, ansp->la_fh_len))
return 1;
return 0;
}
LOCKD_MSG_REQUEST *
nfs_lockdmsg_find_by_answer(struct lockd_ans *ansp)
{
LOCKD_MSG_REQUEST *mr;
if (!(ansp->la_flags & LOCKD_ANS_LOCK_INFO))
return NULL;
TAILQ_FOREACH(mr, &nfs_pendlockq, lmr_next) {
if (!nfs_lockdmsg_compare_to_answer(mr, ansp))
break;
}
return mr;
}
uint64_t
nfs_lockxid_get(void)
{
LOCKD_MSG_REQUEST *mr;
if (!nfs_lockxid) {
struct timeval tv;
microtime(&tv);
nfs_lockxid = (uint64_t)tv.tv_sec << 12;
}
do {
if (++nfs_lockxid == 0)
nfs_lockxid++;
if (!(mr = TAILQ_LAST(&nfs_pendlockq, nfs_lock_msg_queue)) ||
(mr->lmr_msg.lm_xid < nfs_lockxid)) {
break;
}
} while (nfs_lockdmsg_find_by_xid(nfs_lockxid));
return nfs_lockxid;
}
#define MACH_MAX_TRIES 3
int
nfs_lockd_send_request(LOCKD_MSG *msg, int interruptable)
{
kern_return_t kr;
int retries = 0;
mach_port_t lockd_port = IPC_PORT_NULL;
kr = host_get_lockd_port(host_priv_self(), &lockd_port);
if (kr != KERN_SUCCESS || !IPC_PORT_VALID(lockd_port))
return (ENOTSUP);
do {
do {
kr = lockd_request(
lockd_port,
msg->lm_version,
msg->lm_flags,
msg->lm_xid,
msg->lm_fl.l_start,
msg->lm_fl.l_len,
msg->lm_fl.l_pid,
msg->lm_fl.l_type,
msg->lm_fl.l_whence,
(uint32_t *)&msg->lm_addr,
(uint32_t *)&msg->lm_cred,
msg->lm_fh_len,
msg->lm_fh);
if (kr != KERN_SUCCESS)
printf("lockd_request received %d!\n", kr);
} while (!interruptable && kr == MACH_SEND_INTERRUPTED);
} while (kr == MIG_SERVER_DIED && retries++ < MACH_MAX_TRIES);
ipc_port_release_send(lockd_port);
switch (kr) {
case MACH_SEND_INTERRUPTED:
return (EINTR);
default:
return (EAGAIN);
}
return (kr);
}
int
nfs3_lockd_request(
nfsnode_t np,
int type,
LOCKD_MSG_REQUEST *msgreq,
int flags,
thread_t thd)
{
LOCKD_MSG *msg = &msgreq->lmr_msg;
int error, error2;
int interruptable, slpflag;
struct nfsmount *nmp;
struct timeval now;
int timeo, starttime, endtime, lastmsg, wentdown = 0;
struct timespec ts;
struct sockaddr *saddr;
nmp = NFSTONMP(np);
if (!nmp || !nmp->nm_saddr)
return (ENXIO);
lck_mtx_lock(&nmp->nm_lock);
saddr = nmp->nm_saddr;
bcopy(saddr, &msg->lm_addr, min(sizeof msg->lm_addr, saddr->sa_len));
if (nmp->nm_vers == NFS_VER3)
msg->lm_flags |= LOCKD_MSG_NFSV3;
if (nmp->nm_sotype != SOCK_DGRAM)
msg->lm_flags |= LOCKD_MSG_TCP;
microuptime(&now);
starttime = now.tv_sec;
lastmsg = now.tv_sec - ((nmp->nm_tprintf_delay) - (nmp->nm_tprintf_initial_delay));
interruptable = NMFLAG(nmp, INTR);
lck_mtx_unlock(&nmp->nm_lock);
lck_mtx_lock(nfs_lock_mutex);
msg->lm_xid = nfs_lockxid_get();
nfs_lockdmsg_enqueue(msgreq);
timeo = 4;
for (;;) {
nfs_lockd_request_sent = 1;
lck_mtx_unlock(nfs_lock_mutex);
error = nfs_lockd_send_request(msg, interruptable);
lck_mtx_lock(nfs_lock_mutex);
if (error && error != EAGAIN)
break;
wait_for_granted:
error = EWOULDBLOCK;
slpflag = (interruptable && (type != F_UNLCK)) ? PCATCH : 0;
ts.tv_sec = 2;
ts.tv_nsec = 0;
microuptime(&now);
endtime = now.tv_sec + timeo;
while (now.tv_sec < endtime) {
error = error2 = 0;
if (!msgreq->lmr_answered) {
error = msleep(msgreq, nfs_lock_mutex, slpflag | PUSER, "lockd", &ts);
slpflag = 0;
}
if (msgreq->lmr_answered) {
nmp = NFSTONMP(np);
if ((msgreq->lmr_errno == ENOTSUP) && nmp &&
(nmp->nm_state & NFSSTA_LOCKSWORK)) {
error = EWOULDBLOCK;
} else {
error = 0;
}
break;
}
if (error != EWOULDBLOCK)
break;
nmp = NFSTONMP(np);
if ((error2 = nfs_sigintr(nmp, NULL, NULL, 0))) {
error = error2;
if (type == F_UNLCK)
printf("nfs3_lockd_request: aborting unlock request, error %d\n", error);
break;
}
lck_mtx_lock(&nmp->nm_lock);
if (nmp->nm_lockmode == NFS_LOCK_MODE_DISABLED) {
lck_mtx_unlock(&nmp->nm_lock);
break;
}
if ((nmp->nm_state & NFSSTA_RECOVER) && !(flags & R_RECOVER)) {
error = NFSERR_GRACE;
lck_mtx_unlock(&nmp->nm_lock);
break;
}
interruptable = NMFLAG(nmp, INTR);
lck_mtx_unlock(&nmp->nm_lock);
microuptime(&now);
}
if (error) {
nmp = NFSTONMP(np);
if ((error2 = nfs_sigintr(nmp, NULL, NULL, 0))) {
error = error2;
if (error2 != EINTR) {
if (type == F_UNLCK)
printf("nfs3_lockd_request: aborting unlock request, error %d\n", error);
break;
}
}
lck_mtx_lock(&nmp->nm_lock);
if (nmp->nm_lockmode == NFS_LOCK_MODE_DISABLED) {
if (error == EWOULDBLOCK)
error = ENOTSUP;
lck_mtx_unlock(&nmp->nm_lock);
break;
}
if ((error == EWOULDBLOCK) && (nmp->nm_state & NFSSTA_RECOVER) && !(flags & R_RECOVER)) {
error = NFSERR_DENIED;
lck_mtx_unlock(&nmp->nm_lock);
break;
}
interruptable = NMFLAG(nmp, INTR);
if ((error != EWOULDBLOCK) ||
((nmp->nm_state & NFSSTA_RECOVER) && !(flags & R_RECOVER)) ||
((flags & R_RECOVER) && ((now.tv_sec - starttime) > 30))) {
if ((error == EWOULDBLOCK) && (flags & R_RECOVER)) {
error = ETIMEDOUT;
} else if ((nmp->nm_state & NFSSTA_RECOVER) && !(flags & R_RECOVER)) {
error = NFSERR_GRACE;
}
lck_mtx_unlock(&nmp->nm_lock);
if ((msgreq->lmr_errno == EINPROGRESS) &&
!(msg->lm_flags & LOCKD_MSG_CANCEL)) {
msg->lm_flags |= LOCKD_MSG_CANCEL;
nfs_lockdmsg_dequeue(msgreq);
msg->lm_xid = nfs_lockxid_get();
nfs_lockdmsg_enqueue(msgreq);
msgreq->lmr_saved_errno = error;
msgreq->lmr_errno = 0;
msgreq->lmr_answered = 0;
timeo = 2;
continue;
}
break;
}
microuptime(&now);
if ((msgreq->lmr_errno != EINPROGRESS) &&
!(msg->lm_flags & LOCKD_MSG_DENIED_GRACE) &&
(nmp->nm_tprintf_initial_delay != 0) &&
((lastmsg + nmp->nm_tprintf_delay) < now.tv_sec)) {
lck_mtx_unlock(&nmp->nm_lock);
lastmsg = now.tv_sec;
nfs_down(nmp, thd, 0, NFSSTA_LOCKTIMEO, "lockd not responding", 0);
wentdown = 1;
} else
lck_mtx_unlock(&nmp->nm_lock);
if (msgreq->lmr_errno == EINPROGRESS) {
msg->lm_flags |= LOCKD_MSG_CANCEL;
nfs_lockdmsg_dequeue(msgreq);
msg->lm_xid = nfs_lockxid_get();
nfs_lockdmsg_enqueue(msgreq);
msgreq->lmr_saved_errno = msgreq->lmr_errno;
msgreq->lmr_errno = 0;
msgreq->lmr_answered = 0;
timeo = 2;
continue;
}
if (!(flags & R_RECOVER))
timeo *= 2;
if (timeo > 30)
timeo = 30;
continue;
}
nfs_up(NFSTONMP(np), thd, NFSSTA_LOCKTIMEO,
wentdown ? "lockd alive again" : NULL);
wentdown = 0;
if (msgreq->lmr_answered && (msg->lm_flags & LOCKD_MSG_DENIED_GRACE)) {
msgreq->lmr_saved_errno = msgreq->lmr_errno = error = NFSERR_GRACE;
}
if (msgreq->lmr_errno == EINPROGRESS) {
timeo = 30;
msgreq->lmr_answered = 0;
goto wait_for_granted;
}
if ((msg->lm_flags & LOCKD_MSG_CANCEL) &&
(msgreq->lmr_saved_errno == EINPROGRESS)) {
msg->lm_flags &= ~LOCKD_MSG_CANCEL;
nfs_lockdmsg_dequeue(msgreq);
error = NFSERR_DENIED;
break;
}
if (msg->lm_flags & LOCKD_MSG_CANCEL) {
msg->lm_flags &= ~LOCKD_MSG_CANCEL;
error = msgreq->lmr_saved_errno;
} else {
error = msgreq->lmr_errno;
}
nmp = NFSTONMP(np);
if ((error == ENOTSUP) && nmp && !(nmp->nm_state & NFSSTA_LOCKSWORK)) {
nfs_lockdmsg_dequeue(msgreq);
lck_mtx_unlock(nfs_lock_mutex);
lck_mtx_lock(&nmp->nm_lock);
if (nmp->nm_lockmode == NFS_LOCK_MODE_ENABLED) {
nmp->nm_lockmode = NFS_LOCK_MODE_DISABLED;
nfs_lockd_mount_unregister(nmp);
}
nmp->nm_state &= ~NFSSTA_LOCKTIMEO;
lck_mtx_unlock(&nmp->nm_lock);
printf("lockd returned ENOTSUP, disabling locks for nfs server: %s\n",
vfs_statfs(nmp->nm_mountp)->f_mntfromname);
return (error);
}
if (!error) {
if (nmp) {
lck_mtx_lock(&nmp->nm_lock);
if (!(nmp->nm_state & NFSSTA_LOCKSWORK))
nmp->nm_state |= NFSSTA_LOCKSWORK;
lck_mtx_unlock(&nmp->nm_lock);
}
}
break;
}
nfs_lockdmsg_dequeue(msgreq);
lck_mtx_unlock(nfs_lock_mutex);
return (error);
}
int
nfs3_setlock_rpc(
nfsnode_t np,
struct nfs_open_file *nofp,
struct nfs_file_lock *nflp,
int reclaim,
int flags,
thread_t thd,
kauth_cred_t cred)
{
struct nfs_lock_owner *nlop = nflp->nfl_owner;
struct nfsmount *nmp;
int error;
LOCKD_MSG_REQUEST msgreq;
LOCKD_MSG *msg;
nmp = NFSTONMP(np);
if (nfs_mount_gone(nmp))
return (ENXIO);
if (!nlop->nlo_open_owner) {
nfs_open_owner_ref(nofp->nof_owner);
nlop->nlo_open_owner = nofp->nof_owner;
}
if ((error = nfs_lock_owner_set_busy(nlop, thd)))
return (error);
bzero(&msgreq, sizeof(msgreq));
msg = &msgreq.lmr_msg;
msg->lm_version = LOCKD_MSG_VERSION;
if ((nflp->nfl_flags & NFS_FILE_LOCK_WAIT) && !reclaim)
msg->lm_flags |= LOCKD_MSG_BLOCK;
if (reclaim)
msg->lm_flags |= LOCKD_MSG_RECLAIM;
msg->lm_fh_len = (nmp->nm_vers == NFS_VER2) ? NFSX_V2FH : np->n_fhsize;
bcopy(np->n_fhp, msg->lm_fh, msg->lm_fh_len);
cru2x(cred, &msg->lm_cred);
msg->lm_fl.l_whence = SEEK_SET;
msg->lm_fl.l_start = nflp->nfl_start;
msg->lm_fl.l_len = NFS_FLOCK_LENGTH(nflp->nfl_start, nflp->nfl_end);
msg->lm_fl.l_type = nflp->nfl_type;
msg->lm_fl.l_pid = nlop->nlo_pid;
error = nfs3_lockd_request(np, 0, &msgreq, flags, thd);
nfs_lock_owner_clear_busy(nlop);
return (error);
}
int
nfs3_unlock_rpc(
nfsnode_t np,
struct nfs_lock_owner *nlop,
__unused int type,
uint64_t start,
uint64_t end,
int flags,
thread_t thd,
kauth_cred_t cred)
{
struct nfsmount *nmp;
LOCKD_MSG_REQUEST msgreq;
LOCKD_MSG *msg;
nmp = NFSTONMP(np);
if (!nmp)
return (ENXIO);
bzero(&msgreq, sizeof(msgreq));
msg = &msgreq.lmr_msg;
msg->lm_version = LOCKD_MSG_VERSION;
msg->lm_fh_len = (nmp->nm_vers == NFS_VER2) ? NFSX_V2FH : np->n_fhsize;
bcopy(np->n_fhp, msg->lm_fh, msg->lm_fh_len);
cru2x(cred, &msg->lm_cred);
msg->lm_fl.l_whence = SEEK_SET;
msg->lm_fl.l_start = start;
msg->lm_fl.l_len = NFS_FLOCK_LENGTH(start, end);
msg->lm_fl.l_type = F_UNLCK;
msg->lm_fl.l_pid = nlop->nlo_pid;
return (nfs3_lockd_request(np, F_UNLCK, &msgreq, flags, thd));
}
int
nfs3_getlock_rpc(
nfsnode_t np,
struct nfs_lock_owner *nlop,
struct flock *fl,
uint64_t start,
uint64_t end,
vfs_context_t ctx)
{
struct nfsmount *nmp;
int error;
LOCKD_MSG_REQUEST msgreq;
LOCKD_MSG *msg;
nmp = NFSTONMP(np);
if (nfs_mount_gone(nmp))
return (ENXIO);
bzero(&msgreq, sizeof(msgreq));
msg = &msgreq.lmr_msg;
msg->lm_version = LOCKD_MSG_VERSION;
msg->lm_flags |= LOCKD_MSG_TEST;
msg->lm_fh_len = (nmp->nm_vers == NFS_VER2) ? NFSX_V2FH : np->n_fhsize;
bcopy(np->n_fhp, msg->lm_fh, msg->lm_fh_len);
cru2x(vfs_context_ucred(ctx), &msg->lm_cred);
msg->lm_fl.l_whence = SEEK_SET;
msg->lm_fl.l_start = start;
msg->lm_fl.l_len = NFS_FLOCK_LENGTH(start, end);
msg->lm_fl.l_type = fl->l_type;
msg->lm_fl.l_pid = nlop->nlo_pid;
error = nfs3_lockd_request(np, 0, &msgreq, 0, vfs_context_thread(ctx));
if (!error && (msg->lm_flags & LOCKD_MSG_TEST) && !msgreq.lmr_errno) {
if (msg->lm_fl.l_type != F_UNLCK) {
fl->l_type = msg->lm_fl.l_type;
fl->l_pid = msg->lm_fl.l_pid;
fl->l_start = msg->lm_fl.l_start;
fl->l_len = msg->lm_fl.l_len;
fl->l_whence = SEEK_SET;
} else
fl->l_type = F_UNLCK;
}
return (error);
}
int
nfslockdans(proc_t p, struct lockd_ans *ansp)
{
LOCKD_MSG_REQUEST *msgreq;
int error;
error = proc_suser(p);
if (error)
return (error);
if (ansp->la_version != LOCKD_ANS_VERSION)
return (EINVAL);
lck_mtx_lock(nfs_lock_mutex);
msgreq = nfs_lockdmsg_find_by_xid(ansp->la_xid);
if (ansp->la_flags & LOCKD_ANS_GRANTED) {
if (!msgreq || nfs_lockdmsg_compare_to_answer(msgreq, ansp))
msgreq = nfs_lockdmsg_find_by_answer(ansp);
if (msgreq && (msgreq->lmr_msg.lm_flags & LOCKD_MSG_CANCEL))
msgreq = NULL;
}
if (!msgreq) {
lck_mtx_unlock(nfs_lock_mutex);
return (EPIPE);
}
msgreq->lmr_errno = ansp->la_errno;
if ((msgreq->lmr_msg.lm_flags & LOCKD_MSG_TEST) && msgreq->lmr_errno == 0) {
if (ansp->la_flags & LOCKD_ANS_LOCK_INFO) {
if (ansp->la_flags & LOCKD_ANS_LOCK_EXCL)
msgreq->lmr_msg.lm_fl.l_type = F_WRLCK;
else
msgreq->lmr_msg.lm_fl.l_type = F_RDLCK;
msgreq->lmr_msg.lm_fl.l_pid = ansp->la_pid;
msgreq->lmr_msg.lm_fl.l_start = ansp->la_start;
msgreq->lmr_msg.lm_fl.l_len = ansp->la_len;
} else {
msgreq->lmr_msg.lm_fl.l_type = F_UNLCK;
}
}
if (ansp->la_flags & LOCKD_ANS_DENIED_GRACE)
msgreq->lmr_msg.lm_flags |= LOCKD_MSG_DENIED_GRACE;
msgreq->lmr_answered = 1;
lck_mtx_unlock(nfs_lock_mutex);
wakeup(msgreq);
return (0);
}
int
nfslockdnotify(proc_t p, user_addr_t argp)
{
int error, i, headsize;
struct lockd_notify ln;
struct nfsmount *nmp;
struct sockaddr *saddr;
error = proc_suser(p);
if (error)
return (error);
headsize = (char*)&ln.ln_addr[0] - (char*)&ln.ln_version;
error = copyin(argp, &ln, headsize);
if (error)
return (error);
if (ln.ln_version != LOCKD_NOTIFY_VERSION)
return (EINVAL);
if ((ln.ln_addrcount < 1) || (ln.ln_addrcount > 128))
return (EINVAL);
argp += headsize;
saddr = (struct sockaddr *)&ln.ln_addr[0];
lck_mtx_lock(nfs_lock_mutex);
for (i=0; i < ln.ln_addrcount; i++) {
error = copyin(argp, &ln.ln_addr[0], sizeof(ln.ln_addr[0]));
if (error)
break;
argp += sizeof(ln.ln_addr[0]);
TAILQ_FOREACH(nmp, &nfs_lockd_mount_list, nm_ldlink) {
if (!nmp->nm_saddr || nfs_sockaddr_cmp(saddr, nmp->nm_saddr))
continue;
lck_mtx_lock(&nmp->nm_lock);
nfs_need_recover(nmp, 0);
lck_mtx_unlock(&nmp->nm_lock);
}
}
lck_mtx_unlock(nfs_lock_mutex);
return (error);
}