X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/55e303ae13a4cf49d70f2294092726f2fffb9ef2..15129b1c8dbb3650c63b70adb1cad9af601c6c17:/bsd/nfs/nfs_lock.h diff --git a/bsd/nfs/nfs_lock.h b/bsd/nfs/nfs_lock.h index f7f77da19..5a5efe3e4 100644 --- a/bsd/nfs/nfs_lock.h +++ b/bsd/nfs/nfs_lock.h @@ -1,3 +1,30 @@ +/* + * Copyright (c) 2002-2010 Apple Inc. All rights reserved. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ + */ /*- * Copyright (c) 1998 Berkeley Software Design, Inc. All rights reserved. * Redistribution and use in source and binary forms, with or without @@ -41,62 +68,88 @@ * If a structure changes, you must bump the version number. */ -#include +#include /* - * The fifo where the kernel writes requests for locks on remote NFS files, - * and where lockd reads these requests. Note this is no longer hardwired - * in the kernel binary - lockd passes the file descriptor down via nfsclnt() + * The structure that the kernel hands lockd for each lock request. */ -#define _PATH_LCKFIFO "/var/run/nfslockd" +#define LOCKD_MSG_VERSION 3 +typedef struct nfs_lock_msg { + int lm_version; /* LOCKD_MSG version */ + int lm_flags; /* request flags */ + u_int64_t lm_xid; /* unique message transaction ID */ + struct flock lm_fl; /* The lock request. */ + struct sockaddr_storage lm_addr; /* The address. */ + int lm_fh_len; /* The file handle length. */ + struct xucred lm_cred; /* user cred for lock req */ + u_int8_t lm_fh[NFSV3_MAX_FH_SIZE]; /* The file handle. */ +} LOCKD_MSG; + +/* lm_flags */ +#define LOCKD_MSG_BLOCK 0x0001 /* a blocking request */ +#define LOCKD_MSG_TEST 0x0002 /* just a lock test */ +#define LOCKD_MSG_NFSV3 0x0004 /* NFSv3 request */ +#define LOCKD_MSG_CANCEL 0x0008 /* cancelling blocked request */ +#define LOCKD_MSG_DENIED_GRACE 0x0010 /* lock denied due to grace period */ +#define LOCKD_MSG_RECLAIM 0x0020 /* lock reclaim request */ +#define LOCKD_MSG_TCP 0x0040 /* (try to) use TCP for request */ + +/* The structure used to maintain the pending request queue */ +typedef struct nfs_lock_msg_request { + TAILQ_ENTRY(nfs_lock_msg_request) lmr_next; /* in-kernel pending request list */ + int lmr_answered; /* received an answer? */ + int lmr_errno; /* return status */ + int lmr_saved_errno; /* original return status */ + LOCKD_MSG lmr_msg; /* the message */ +} LOCKD_MSG_REQUEST; + +TAILQ_HEAD(nfs_lock_msg_queue, nfs_lock_msg_request); +typedef struct nfs_lock_msg_queue LOCKD_MSG_QUEUE; + /* - * This structure is used to uniquely identify the process which originated - * a particular message to lockd. A sequence number is used to differentiate - * multiple messages from the same process. A process start time is used to - * detect the unlikely, but possible, event of the recycling of a pid. + * The structure that lockd hands the kernel for each lock answer. */ -struct lockd_msg_ident { - pid_t pid; /* The process ID. */ - struct timeval pid_start; /* Start time of process id */ - int msg_seq; /* Sequence number of message */ - struct uthread *ut; +#define LOCKD_ANS_VERSION 2 +struct lockd_ans { + int la_version; /* lockd_ans version */ + int la_errno; /* return status */ + u_int64_t la_xid; /* unique message transaction ID */ + int la_flags; /* answer flags */ + pid_t la_pid; /* pid of lock requester/owner */ + off_t la_start; /* lock starting offset */ + off_t la_len; /* lock length */ + int la_fh_len; /* The file handle length. */ + u_int8_t la_fh[NFSV3_MAX_FH_SIZE];/* The file handle. */ }; -#define LOCKD_MSG_VERSION 2 +/* la_flags */ +#define LOCKD_ANS_GRANTED 0x0001 /* NLM_GRANTED request */ +#define LOCKD_ANS_LOCK_INFO 0x0002 /* lock info valid */ +#define LOCKD_ANS_LOCK_EXCL 0x0004 /* lock is exclusive */ +#define LOCKD_ANS_DENIED_GRACE 0x0008 /* lock denied due to grace period */ + /* - * The structure that the kernel hands us for each lock request. + * The structure that lockd hands the kernel for each notify. */ -typedef struct __lock_msg { - int lm_version; /* which version is this */ - struct lockd_msg_ident lm_msg_ident; /* originator of the message */ - struct flock lm_fl; /* The lock request. */ - int lm_wait; /* The F_WAIT flag. */ - int lm_getlk; /* is this a F_GETLK request */ - struct sockaddr_storage lm_addr; /* The address. */ - int lm_nfsv3; /* If NFS version 3. */ - size_t lm_fh_len; /* The file handle length. */ - struct xucred lm_cred; /* user cred for lock req */ - u_int8_t lm_fh[NFS_SMALLFH];/* The file handle. */ -} LOCKD_MSG; - -#define LOCKD_ANS_VERSION 1 - -struct lockd_ans { - int la_vers; - struct lockd_msg_ident la_msg_ident; /* originator of the message */ - int la_errno; - int la_getlk_set; /* use returned getlk values */ - int la_getlk_pid; /* returned pid for F_GETLK */ - off_t la_getlk_start; /* returned starting offset */ - off_t la_getlk_len; /* returned length */ +#define LOCKD_NOTIFY_VERSION 1 +struct lockd_notify { + int ln_version; /* lockd_notify version */ + int ln_flags; /* notify flags */ + int ln_pad; /* (for alignment) */ + int ln_addrcount; /* # of addresss */ + struct sockaddr_storage ln_addr[1]; /* List of addresses. */ }; + #ifdef KERNEL -int nfs_dolock(struct vop_advlock_args *ap); -int nfslockdans(struct proc *p, struct lockd_ans *ansp); -int nfslockdfd(struct proc *p, int fd); -int nfslockdwait(struct proc *p); +void nfs_lockinit(void); +void nfs_lockd_mount_register(struct nfsmount *); +void nfs_lockd_mount_unregister(struct nfsmount *); +int nfs3_lockd_request(nfsnode_t, int, LOCKD_MSG_REQUEST *, int, thread_t); +int nfslockdans(proc_t p, struct lockd_ans *ansp); +int nfslockdnotify(proc_t p, user_addr_t argp); + #endif #endif /* __APPLE_API_PRIVATE */