smbfs_node.h revision 91d632c867159b669d90fc7e172295433d0519ef
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Copyright (c) 2000-2001, Boris Popov
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * All rights reserved.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Redistribution and use in source and binary forms, with or without
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * modification, are permitted provided that the following conditions
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * 1. Redistributions of source code must retain the above copyright
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * notice, this list of conditions and the following disclaimer.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * 2. Redistributions in binary form must reproduce the above copyright
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * notice, this list of conditions and the following disclaimer in the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * documentation and/or other materials provided with the distribution.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * 3. All advertising materials mentioning features or use of this software
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * must display the following acknowledgement:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * This product includes software developed by Boris Popov.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * 4. Neither the name of the author nor the names of any co-contributors
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * may be used to endorse or promote products derived from this software
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * without specific prior written permission.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * SUCH DAMAGE.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * $Id: smbfs_node.h,v 1.31.52.1 2005/05/27 02:35:28 lindak Exp $
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Use is subject to license terms.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#pragma ident "%Z%%M% %I% %E% SMI"
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Much code copied into here from Sun NFS.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otaextern "C" {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otatypedef struct rddir_cache {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota lloff_t _cookie; /* cookie used to find this cache entry */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota lloff_t _ncookie; /* cookie used to find the next cache entry */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota char *entries; /* buffer containing dirent entries */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota int buflen; /* size of the buffer used to store entries */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define RDDIR 0x1 /* readdir operation in progress */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define RDDIRWAIT 0x2 /* waiting on readdir in progress */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define RDDIRREQ 0x4 /* a new readdir is required */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define HAVE_RDDIR_CACHE(rp) (avl_numnodes(&(rp)->r_dir) > 0)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * A homegrown reader/writer lock implementation. It addresses
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * two requirements not addressed by the system primitives. They
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * are that the `enter" operation is optionally interruptible and
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * that that they can be re`enter'ed by writers without deadlock.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otatypedef struct smbfs_rwlock {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * The format of the hash bucket used to lookup smbnodes from a file handle.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otatypedef struct rhashq {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Remote file information structure.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * The smbnode is the "inode" for remote files. It contains all the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * information necessary to handle remote file on the client side.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Note on file sizes: we keep two file sizes in the smbnode: the size
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * according to the client (r_size) and the size according to the server
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * (r_attr.va_size). They can differ because we modify r_size during a
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * write system call (smbfs_rdwr), before the write request goes over the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * wire (before the file is actually modified on the server). If an OTW
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * request occurs before the cached data is written to the server the file
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * size returned from the server (r_attr.va_size) may not match r_size.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * r_size is the one we use, in general. r_attr.va_size is only used to
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * determine whether or not our cached data is valid.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Each smbnode has 3 locks associated with it (not including the smbnode
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * hash table and free list locks):
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * r_rwlock: Serializes smbfs_write and smbfs_setattr requests
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * and allows smbfs_read requests to proceed in parallel.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Serializes reads/updates to directories.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * r_lkserlock: Serializes lock requests with map, write, and
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * readahead operations.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * r_statelock: Protects all fields in the smbnode except for
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * those listed below. This lock is intented
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * to be held for relatively short periods of
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * time (not accross entire putpage operations,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * for example).
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * The following members are protected by the mutex rpfreelist_lock:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * The following members are protected by the hash bucket rwlock:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Note: r_modaddr is only accessed when the r_statelock mutex is held.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Its value is also controlled via r_rwlock. It is assumed that
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * there will be only 1 writer active at a time, so it safe to
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * set r_modaddr and release r_statelock as long as the r_rwlock
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * writer lock is held.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * 64-bit offsets: the code formerly assumed that atomic reads of
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * r_size were safe and reliable; on 32-bit architectures, this is
6e18d381c642549b8bb1774a803d3510aec6baafagiri * not true since an intervening bus cycle from another processor
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * could update half of the size field. The r_statelock must now
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * be held whenever any kind of access of r_size is made.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Lock ordering:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * r_rwlock > r_lkserlock > r_statelock
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otastruct failinfo; /* defined in smbfs/smbfs_clnt.h */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* Bits for smbnode.n_flag */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define NFLUSHWANT 0x00002 /* they should gone ... */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define NMODIFIED 0x00004 /* bogus, until async IO implemented */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define NREFPARENT 0x00010 /* node holds parent from recycling */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define NRDIRSERIAL 0x00080 /* serialize readdir operation */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define NATTRCHANGED 0x02000 /* use smbfs_attr_cacheremove at close */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define N_XATTR 0x10000 /* extended attribute (dir or file) */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otatypedef struct smbnode {
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* from Sun NFS struct rnode (XXX: cleanup needed) */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* the hash fields must be first to match the rhashq_t */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* Lock for the hash queue is: np->r_hashq->r_lock */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota struct smbnode *r_hashf; /* hash queue forward pointer */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota struct smbnode *r_hashb; /* hash queue back pointer */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* Lock for the free list is: smbfreelist_lock */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota struct smbnode *r_freef; /* free list forward pointer */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota struct smbnode *r_freeb; /* free list back pointer */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rhashq_t *r_hashq; /* pointer to the hash bucket */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota smbfs_rwlock_t r_rwlock; /* serializes write/setattr requests */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota smbfs_rwlock_t r_lkserlock; /* serialize lock with other ops */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota kmutex_t r_statelock; /* protects (most of) smbnode fields */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota u_offset_t r_nextr; /* next byte read offset (read-ahead) */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota hrtime_t r_attrtime; /* time attributes become invalid */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota uint_t r_count; /* # of refs not reflect in v_count */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota uint_t r_awcount; /* # of outstanding async write */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota uint_t r_gcount; /* getattrs waiting to flush pages */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota rddir_cache *r_direof; /* pointer to the EOF entry */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Members derived from Darwin struct smbnode.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Note: n_parent node pointer removed because it
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * caused unwanted "holds" on nodes in our cache.
6e18d381c642549b8bb1774a803d3510aec6baafagiri * Now keeping just the full remote path instead,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * in server form, relative to the share root.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* Lock for the next 8 is r_lkserlock */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota /* Lock for the rest is r_statelock */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * XXX: Maybe use this instead:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * #define n_atime r_attr.va_atime
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#endif /* _KERNEL */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define RREADDIRPLUS 0x1 /* issue a READDIRPLUS instead of READDIR */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define RDIRTY 0x2 /* dirty pages from write operation */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define RMODINPROGRESS 0x8 /* page modification happening */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define RTRUNCATE 0x10 /* truncating, don't commit */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define RHAVEVERF 0x20 /* have a write verifier to compare against */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define RCOMMITWAIT 0x80 /* someone is waiting to do a commit */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define RHASHED 0x100 /* smbnode is in hash queues */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define ROUTOFSPACE 0x200 /* an out of space error has happened */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define RDIRECTIO 0x400 /* bypass the buffer cache */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define RLOOKUP 0x800 /* a lookup has been performed */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define RWRITEATTR 0x1000 /* attributes came from WRITE */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define RINDNLCPURGE 0x2000 /* in the process of purging DNLC references */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota#define RDELMAPLIST 0x4000 /* delmap callers tracking for as callback */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Convert between vnode and smbnode
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* Attribute cache timeouts in seconds */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Function definitions.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otaint smbfs_nget(vnode_t *dvp, const char *name, int nmlen,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otavoid smbfs_attr_cacheenter(vnode_t *vp, struct smbfattr *fap);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otaint smbfs_attr_cachelookup(vnode_t *vp, struct vattr *va);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otachar *smbfs_name_alloc(const char *name, int nmlen);
#ifdef __cplusplus