darwin-xnu/bsd/nfs/nfs_lock.h
<<
>>
Prefs
   1/*
   2 * Copyright (c) 2002-2005 Apple Computer, Inc. All rights reserved.
   3 *
   4 * @APPLE_LICENSE_HEADER_START@
   5 * 
   6 * The contents of this file constitute Original Code as defined in and
   7 * are subject to the Apple Public Source License Version 1.1 (the
   8 * "License").  You may not use this file except in compliance with the
   9 * License.  Please obtain a copy of the License at
  10 * http://www.apple.com/publicsource and read it before using this file.
  11 * 
  12 * This Original Code and all software distributed under the License are
  13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
  16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
  17 * License for the specific language governing rights and limitations
  18 * under the License.
  19 * 
  20 * @APPLE_LICENSE_HEADER_END@
  21 */
  22/*-
  23 * Copyright (c) 1998 Berkeley Software Design, Inc. All rights reserved.
  24 * Redistribution and use in source and binary forms, with or without
  25 * modification, are permitted provided that the following conditions
  26 * are met:
  27 * 1. Redistributions of source code must retain the above copyright
  28 *    notice, this list of conditions and the following disclaimer.
  29 * 2. Redistributions in binary form must reproduce the above copyright
  30 *    notice, this list of conditions and the following disclaimer in the
  31 *    documentation and/or other materials provided with the distribution.
  32 * 3. Berkeley Software Design Inc's name may not be used to endorse or
  33 *    promote products derived from this software without specific prior
  34 *    written permission.
  35 *
  36 * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
  37 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  39 * ARE DISCLAIMED.  IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
  40 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  41 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  42 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  44 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  45 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46 * SUCH DAMAGE.
  47 *
  48 *      from nfs_lock.h,v 2.2 1998/04/28 19:38:41 don Exp
  49 * $FreeBSD$
  50 */
  51
  52#include <sys/appleapiopts.h>
  53
  54#ifdef __APPLE_API_PRIVATE
  55
  56/*
  57 * lockd uses the nfsclnt system call for the unique kernel services it needs.
  58 * It passes in a request structure with a version number at the start.
  59 * This prevents libc from needing to change if the information passed
  60 * between lockd and the kernel needs to change.
  61 *
  62 * If a structure changes, you must bump the version number.
  63 */
  64
  65#include <nfs/nfsproto.h>
  66
  67/*
  68 * The fifo where the kernel writes requests for locks on remote NFS files,
  69 * and where lockd reads these requests.  Note this is no longer hardwired
  70 * in the kernel binary - lockd passes the file descriptor down via nfsclnt()
  71 */
  72#define _PATH_LCKFIFO   "/var/run/nfslockd"
  73
  74/*
  75 * The structure that the kernel hands lockd for each lock request.
  76 */
  77#define LOCKD_MSG_VERSION       3
  78typedef struct nfs_lock_msg {
  79        int                     lm_version;             /* LOCKD_MSG version */
  80        int                     lm_flags;               /* request flags */
  81        u_int64_t               lm_xid;                 /* unique message transaction ID */
  82        struct flock            lm_fl;                  /* The lock request. */
  83        struct sockaddr_storage lm_addr;                /* The address. */
  84        int                     lm_fh_len;              /* The file handle length. */
  85        struct xucred           lm_cred;                /* user cred for lock req */
  86        u_int8_t                lm_fh[NFS_SMALLFH];     /* The file handle. */
  87} LOCKD_MSG;
  88
  89/* lm_flags */
  90#define LOCKD_MSG_BLOCK         0x0001  /* a blocking request */
  91#define LOCKD_MSG_TEST          0x0002  /* just a lock test */
  92#define LOCKD_MSG_NFSV3         0x0004  /* NFSv3 request */
  93#define LOCKD_MSG_CANCEL        0x0008  /* cancelling blocked request */
  94
  95/* The structure used to maintain the pending request queue */
  96typedef struct nfs_lock_msg_request {
  97        TAILQ_ENTRY(nfs_lock_msg_request) lmr_next;     /* in-kernel pending request list */
  98        int                     lmr_answered;           /* received an answer? */
  99        int                     lmr_errno;              /* return status */
 100        int                     lmr_saved_errno;        /* original return status */
 101        LOCKD_MSG               lmr_msg;                /* the message */
 102} LOCKD_MSG_REQUEST;
 103
 104TAILQ_HEAD(nfs_lock_msg_queue, nfs_lock_msg_request);
 105typedef struct nfs_lock_msg_queue LOCKD_MSG_QUEUE;
 106
 107
 108/*
 109 * The structure that lockd hands the kernel for each lock answer.
 110 */
 111#define LOCKD_ANS_VERSION       2
 112struct lockd_ans {
 113        int             la_version;             /* lockd_ans version */
 114        int             la_errno;               /* return status */
 115        u_int64_t       la_xid;                 /* unique message transaction ID */
 116        int             la_flags;               /* answer flags */
 117        pid_t           la_pid;                 /* pid of lock requester/owner */
 118        off_t           la_start;               /* lock starting offset */
 119        off_t           la_len;                 /* lock length */
 120        int             la_fh_len;              /* The file handle length. */
 121        u_int8_t        la_fh[NFS_SMALLFH];     /* The file handle. */
 122};
 123
 124/* la_flags */
 125#define LOCKD_ANS_GRANTED       0x0001  /* NLM_GRANTED request */
 126#define LOCKD_ANS_LOCK_INFO     0x0002  /* lock info valid */
 127#define LOCKD_ANS_LOCK_EXCL     0x0004  /* lock is exclusive */
 128
 129
 130#ifdef KERNEL
 131void    nfs_lockinit(void);
 132int     nfs_dolock(struct vnop_advlock_args *ap);
 133int     nfslockdans(proc_t p, struct lockd_ans *ansp);
 134int     nfslockdfd(proc_t p, int fd);
 135int     nfslockdwait(proc_t p);
 136
 137extern vnode_t nfslockdvnode;
 138extern int nfslockdwaiting;
 139#endif
 140#endif /* __APPLE_API_PRIVATE */
 141
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.