/*
* Copyright (c) 2000-2001, Boris Popov
* 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
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Boris Popov.
* 4. Neither the name of the author nor the names of any co-contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 THE AUTHOR OR CONTRIBUTORS 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.
*
* $Id: smbfs_node.h,v 1.31.52.1 2005/05/27 02:35:28 lindak Exp $
*/
/*
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _FS_SMBFS_NODE_H_
#define _FS_SMBFS_NODE_H_
/*
* Much code copied into here from Sun NFS.
* Compare with nfs_clnt.h
*/
#include <netsmb/smb_subr.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* Cache whole directories (not yet)
*/
typedef struct rddir_cache {
} rddir_cache;
/*
* two requirements not addressed by the system primitives. They
* are that the `enter" operation is optionally interruptible and
* that that they can be re`enter'ed by writers without deadlock.
*/
typedef struct smbfs_rwlock {
int count;
int waiters;
/*
* The format of the smbfs node header, which contains the
* fields used to link nodes in the AVL tree, and those
* fields needed by the AVL node comparison functions.
* It's a separate struct so we can call avl_find with
* this relatively small struct as a stack local.
*
* The AVL tree is mntinfo.smi_hash_avl,
* and its lock is mntinfo.smi_hash_lk.
*/
typedef struct smbfs_node_hdr {
/*
* Our linkage in the node cache AVL tree.
*/
/*
* Identity of this node: The full path name,
* in server form, relative to the share root.
*/
char *hdr_n_rpath;
int hdr_n_rplen;
/*
* Below is the SMBFS-specific representation of a "node".
* This struct is a mixture of Sun NFS and Darwin code.
* Fields starting with "r_" came from NFS struct "rnode"
* and fields starting with "n_" came from Darwin, or
* were added during the Solaris port. We have avoided
* renaming fields so we would not cause excessive
* changes in the code using this struct.
*
* Now using an AVL tree instead of hash lists, but kept the
* "hash" in some member names and functions to reduce churn.
* One AVL tree per mount replaces the global hash buckets.
*
* Notes carried over from the NFS code:
*
* The smbnode is the "inode" for remote files. It contains all the
* information necessary to handle remote file on the client side.
*
* Note on file sizes: we keep two file sizes in the smbnode: the size
* according to the client (r_size) and the size according to the server
* (r_attr.fa_size). They can differ because we modify r_size during a
* write system call (smbfs_rdwr), before the write request goes over the
* wire (before the file is actually modified on the server). If an OTW
* request occurs before the cached data is written to the server the file
* size returned from the server (r_attr.fa_size) may not match r_size.
* r_size is the one we use, in general. r_attr.fa_size is only used to
* determine whether or not our cached data is valid.
*
* Each smbnode has 3 locks associated with it (not including the smbnode
* "hash" AVL tree and free list locks):
*
* r_rwlock: Serializes smbfs_write and smbfs_setattr requests
* and allows smbfs_read requests to proceed in parallel.
*
* r_lkserlock: Serializes lock requests with map, write, and
* readahead operations.
*
* r_statelock: Protects all fields in the smbnode except for
* those listed below. This lock is intented
* to be held for relatively short periods of
* time (not accross entire putpage operations,
* for example).
*
* The following members are protected by the mutex smbfreelist_lock:
* r_freef
* r_freeb
*
* The following members are protected by the AVL tree rwlock:
* r_avl_node (r__hdr.hdr_avl_node)
*
* Note: r_modaddr is only accessed when the r_statelock mutex is held.
* Its value is also controlled via r_rwlock. It is assumed that
* there will be only 1 writer active at a time, so it safe to
* set r_modaddr and release r_statelock as long as the r_rwlock
* writer lock is held.
*
* 64-bit offsets: the code formerly assumed that atomic reads of
* r_size were safe and reliable; on 32-bit architectures, this is
* not true since an intervening bus cycle from another processor
* could update half of the size field. The r_statelock must now
* be held whenever any kind of access of r_size is made.
*
* Lock ordering:
* r_rwlock > r_lkserlock > r_statelock
*/
typedef struct smbnode {
/* Our linkage in the node cache AVL tree (see above). */
/* short-hand names for r__hdr members */
/*
* Linkage in smbfreelist, for reclaiming nodes.
* Lock for the free list is: smbfreelist_lock
*/
/*
* File handle, directory search handle,
* and reference counts for them, etc.
* Lock for these is: r_lkserlock
*/
int n_dirrefs;
int n_fidrefs;
/*
* Misc. bookkeeping
*/
/*
* Attributes: local, and as last seen on the server.
* See notes above re: r_size vs r_attr.fa_size, etc.
*/
/*
* Security attributes.
*/
/*
* Other attributes, not carried in smbfattr_t
*/
} smbnode_t;
/*
* Flag bits in: smbnode_t .n_flag
*/
/*
* Flag bits in: smbnode_t .r_flags
*/
/*
* Convert between vnode and smbnode
*/
/*
* A macro to compute the separator that should be used for
* names under some directory. See smbfs_fullpath().
*/
#ifdef __cplusplus
}
#endif
#endif /* _FS_SMBFS_NODE_H_ */