vnode.h revision 1b300de97c3a03432cd287d7e82a800782dcd236
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#ifndef _SYS_VNODE_H
#define _SYS_VNODE_H
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/rwstlock.h>
#include <sys/time_impl.h>
#include <sys/resource.h>
#include <vm/seg_enum.h>
#ifdef _KERNEL
#endif /* _KERNEL */
#ifdef __cplusplus
extern "C" {
#endif
/*
* Statistics for all vnode operations.
* Certain I/O operations (read, write, readdir) also record number
* of bytes transferred.
* This appears in two places in the system: one is embedded in each
* vfs_t. There is also an array of vopstats_t structures allocated
* on a per-fstype basis.
*/
typedef struct vopstats {
} vopstats_t;
/*
* The vnode is the focus of all file activity in UNIX.
* A vnode is allocated for each active file, each current
* directory, each mounted-on file, and the root.
*
* Each vnode is usually associated with a file-system-specific node (for
* UFS, this is the in-memory inode). Generally, a vnode and an fs-node
* should be created and destroyed together as a pair.
*
* If a vnode is reused for a new file, it should be reinitialized by calling
* either vn_reinit() or vn_recycle().
*
* vn_reinit() resets the entire vnode as if it was returned by vn_alloc().
* The caller is responsible for setting up the entire vnode after calling
* vn_reinit(). This is important when using kmem caching where the vnode is
* allocated by a constructor, for instance.
*
* vn_recycle() is used when the file system keeps some state around in both
* the vnode and the associated FS-node. In UFS, for example, the inode of
* a deleted file can be reused immediately. The v_data, v_vfsp, v_op, etc.
* remains the same but certain fields related to the previous instance need
* to be reset. In particular:
* v_femhead
* v_path
* v_rdcnt, v_wrcnt
* v_mmap_read, v_mmap_write
*/
/*
* vnode types. VNON means no type. These values are unrelated to
* values in on-disk inodes.
*/
typedef enum vtype {
VNON = 0,
VREG = 1,
VDIR = 2,
VBLK = 3,
VCHR = 4,
VLNK = 5,
VFIFO = 6,
VDOOR = 7,
VPROC = 8,
VSOCK = 9,
VPORT = 10,
VBAD = 11
} vtype_t;
/*
* VSD - Vnode Specific Data
* Used to associate additional private data with a vnode.
*/
struct vsd_node {
};
/*
* Many of the fields in the vnode are read-only once they are initialized
* at vnode creation time. Other fields are protected by locks.
*
* IMPORTANT: vnodes should be created ONLY by calls to vn_alloc(). They
* may not be embedded into the file-system specific node (inode). The
* size of vnodes may change.
*
* The v_lock protects:
* v_flag
* v_stream
* v_count
* v_shrlocks
* v_path
* v_vsd
*
* A special lock (implemented by vn_vfswlock in vnode.c) protects:
* v_vfsmountedhere
*
* The global flock_lock mutex (in flock.c) protects:
* v_filocks
*
* IMPORTANT NOTE:
*
* The following vnode fields are considered public and may safely be
* accessed by file systems or other consumers:
*
* v_lock
* v_flag
* v_count
* v_data
* v_vfsp
* v_stream
* v_type
* v_rdev
*
* ALL OTHER FIELDS SHOULD BE ACCESSED ONLY BY THE OWNER OF THAT FIELD.
* In particular, file systems should not access other fields; they may
* change or even be removed. The functionality which was once provided
* by these fields is available through vn_* functions.
*/
typedef struct vnode {
void *v_data; /* private data for fs */
/* PRIVATE FIELDS BELOW - DO NOT USE */
void *v_locality; /* hook for locality info */
char *v_path; /* cached path */
void *v_mpssdata; /* info for large page mappings */
void *v_fopdata; /* list of file ops event watches */
} vnode_t;
/*
* vnode flags.
*/
typedef struct vn_vfslocks_entry {
void *ve_vpvfs;
struct vn_vfslocks_entry *ve_next;
sizeof (uint32_t)];
/*
* The following two flags are used to lock the v_vfsmountedhere field
*/
#define VVFSLOCK 0x100
#define VVFSWAIT 0x200
/*
* Used to serialize VM operations on a vnode
*/
#define VVMLOCK 0x400
/*
* Tell vn_open() not to fail a directory open for writing but
* to go ahead and call VOP_OPEN() to let the filesystem check.
*/
#define VDIROPEN 0x800
/*
* Flag to let the VM system know that this file is most likely a binary
* or shared library since it has been mmap()ed EXEC at some time.
*/
#define VVMEXEC 0x1000
/*
* Flag that indicates the VM should maintain the v_pages list with all modified
* pages on one end and unmodified pages at the other. This makes finding dirty
* pages to write back to disk much faster at the expense of taking a minor
* fault on the first store instruction which touches a writable page.
*/
#define VMODSORT (0x10000)
#define IS_VMODSORT(vp) \
/*
* Vnode attributes. A bit-mask is supplied as part of the
* structure to indicate the attributes the caller wants to
* set (setattr) or extract (getattr).
*/
/*
* Note that va_nodeid and va_nblocks are 64bit data type.
* We support large files over NFSV3. With Solaris client and
* Server that generates 64bit ino's and sizes these fields
* will overflow if they are 32 bit sizes.
*/
typedef struct vattr {
} vattr_t;
#ifdef _SYSCALL32
/*
* For bigtypes time_t changed to 64 bit on the 64-bit kernel.
*/
#pragma pack(4)
#endif
typedef struct vattr32 {
} vattr32_t;
#pragma pack()
#endif
#else /* not _SYSCALL32 */
#endif /* _SYSCALL32 */
/*
* Attributes of interest to the caller of setattr or getattr.
*/
#define AT_TYPE 0x0001
#define AT_MODE 0x0002
#define AT_UID 0x0004
#define AT_GID 0x0008
#define AT_FSID 0x0010
#define AT_NODEID 0x0020
#define AT_NLINK 0x0040
#define AT_SIZE 0x0080
#define AT_ATIME 0x0100
#define AT_MTIME 0x0200
#define AT_CTIME 0x0400
#define AT_RDEV 0x0800
#define AT_BLKSIZE 0x1000
#define AT_NBLOCKS 0x2000
/* 0x4000 */ /* unused */
#define AT_SEQ 0x8000
/*
* Modes. Some values same as S_xxx entries from stat.h for convenience.
*/
/*
* Permissions.
*/
#define VREAD 00400
#define VWRITE 00200
#define VEXEC 00100
/*
* Check whether mandatory file locking is enabled.
*/
/*
* Flags for vnode operations.
*/
typedef enum symfollow symfollow_t;
/* Vnode Events - Used by VOP_VNEVENT */
typedef enum vnevent {
VE_SUPPORT = 0, /* Query */
} vnevent_t;
/*
* Values for checking vnode open and map counts
*/
#define V_TRUE 1
#define V_FALSE 0
/*
* Structure used on VOP_GETSECATTR and VOP_SETSECATTR operations
*/
typedef struct vsecattr {
int vsa_aclcnt; /* ACL entry count */
void *vsa_aclentp; /* pointer to ACL entries */
int vsa_dfaclcnt; /* default ACL entry count */
void *vsa_dfaclentp; /* pointer to default ACL entries */
} vsecattr_t;
/* vsa_mask values */
#define VSA_ACL 0x0001
#define VSA_ACLCNT 0x0002
#define VSA_DFACL 0x0004
#define VSA_DFACLCNT 0x0008
#define VSA_ACE 0x0010
#define VSA_ACECNT 0x0020
/*
* Structure used by various vnode operations to determine
* the context (pid, host, identity) of a caller.
*
* The cc_caller_id is used to identify one or more callers who invoke
* operations, possibly on behalf of others. For example, the NFS
* server could have it's own cc_caller_id which can be detected by
* caller IDs are generated by fs_new_caller_id().
*/
typedef struct caller_context {
int cc_sysid; /* System ID, used for remote calls */
/*
* Structure tags for function prototypes, defined elsewhere.
*/
struct pathname;
struct fid;
struct flock64;
struct flk_callback;
struct shrlock;
struct page;
struct seg;
struct as;
struct pollhead;
#ifdef _KERNEL
/*
* VNODE_OPS defines all the vnode operations. It is used to define
* the vnodeops structure (below) and the fs_func_p union (vfs_opreg.h).
*/
#define VNODE_OPS \
caller_context_t *); \
caller_context_t *); \
int *); \
caller_context_t *); \
struct pathname *, \
cred_t *); \
cred_t *); \
cred_t *); \
int, offset_t, \
struct flk_callback *, cred_t *); \
int, offset_t, \
cred_t *, caller_context_t *); \
int, cred_t *); \
struct pollhead **); \
int (*vop_dumpctl)(vnode_t *, int, int *); \
int, int, cred_t *); \
int, cred_t *); \
int, cred_t *); \
int, cred_t *); \
/* NB: No ";" */
/*
* Operations on vnodes. Note: File systems must never operate directly
* on a 'vnodeops' structure -- it WILL change in future releases! They
* must use vn_make_ops() to create the structure.
*/
typedef struct vnodeops {
const char *vnop_name;
VNODE_OPS; /* Signatures of all vnode operations (vops) */
} vnodeops_t;
typedef int (*fs_generic_func_p) (); /* Generic vop/vfsop/femop/fsemop ptr */
caller_context_t *);
caller_context_t *);
struct flk_callback *, cred_t *);
cred_t *, caller_context_t *);
cred_t *);
extern int fop_dumpctl(vnode_t *, int, int *);
#endif /* _KERNEL */
#define VOPNAME_OPEN "open"
#define VOPNAME_CLOSE "close"
#define VOPNAME_READ "read"
#define VOPNAME_WRITE "write"
#define VOPNAME_IOCTL "ioctl"
#define VOPNAME_SETFL "setfl"
#define VOPNAME_GETATTR "getattr"
#define VOPNAME_SETATTR "setattr"
#define VOPNAME_ACCESS "access"
#define VOPNAME_LOOKUP "lookup"
#define VOPNAME_CREATE "create"
#define VOPNAME_REMOVE "remove"
#define VOPNAME_LINK "link"
#define VOPNAME_RENAME "rename"
#define VOPNAME_MKDIR "mkdir"
#define VOPNAME_RMDIR "rmdir"
#define VOPNAME_READDIR "readdir"
#define VOPNAME_SYMLINK "symlink"
#define VOPNAME_READLINK "readlink"
#define VOPNAME_FSYNC "fsync"
#define VOPNAME_INACTIVE "inactive"
#define VOPNAME_FID "fid"
#define VOPNAME_RWLOCK "rwlock"
#define VOPNAME_RWUNLOCK "rwunlock"
#define VOPNAME_SEEK "seek"
#define VOPNAME_CMP "cmp"
#define VOPNAME_FRLOCK "frlock"
#define VOPNAME_SPACE "space"
#define VOPNAME_REALVP "realvp"
#define VOPNAME_GETPAGE "getpage"
#define VOPNAME_PUTPAGE "putpage"
#define VOPNAME_MAP "map"
#define VOPNAME_ADDMAP "addmap"
#define VOPNAME_DELMAP "delmap"
#define VOPNAME_POLL "poll"
#define VOPNAME_DUMP "dump"
#define VOPNAME_PATHCONF "pathconf"
#define VOPNAME_PAGEIO "pageio"
#define VOPNAME_DUMPCTL "dumpctl"
#define VOPNAME_DISPOSE "dispose"
#define VOPNAME_GETSECATTR "getsecattr"
#define VOPNAME_SETSECATTR "setsecattr"
#define VOPNAME_SHRLOCK "shrlock"
#define VOPNAME_VNEVENT "vnevent"
/*
* Flags for VOP_LOOKUP
*/
/*
* Flags for VOP_RWLOCK/VOP_RWUNLOCK
* VOP_RWLOCK will return the flag that was actually set, or -1 if none.
*/
#define V_WRITELOCK_FALSE (0) /* Request read-lock on the vnode */
/*
* Flags for VOP_DUMPCTL
*/
#define DUMP_ALLOC 0
#define DUMP_FREE 1
#define DUMP_SCAN 2
/*
* Public vnode manipulation functions.
*/
#ifdef _KERNEL
void vn_recycle(vnode_t *);
int vn_is_readonly(vnode_t *);
int vn_has_flocks(vnode_t *);
int vn_has_mandatory_locks(vnode_t *, int);
int vn_has_cached_data(vnode_t *);
int vn_ismntpt(vnode_t *);
void vn_create_cache(void);
void vn_destroy_cache(void);
void vn_freevnodeops(vnodeops_t *);
vn_vfslocks_entry_t *vn_vfslocks_getlock(void *);
void vn_vfslocks_rele(vn_vfslocks_entry_t *);
/* Vnode event notification */
void vnevent_create(vnode_t *);
void vnevent_link(vnode_t *);
void vnevent_rename_dest_dir(vnode_t *);
void vnevent_mountedover(vnode_t *);
int vnevent_support(vnode_t *);
/* Vnode specific data */
void vsd_create(uint_t *, void (*)(void *));
void vsd_destroy(uint_t *);
/* Context identification */
int vn_vmpss_usepageio(vnode_t *);
/*
* Needed for use of IS_VMODSORT() in kernel.
*/
extern uint_t pvn_vmodsort_supported;
}
}
}
/*
* Compare two vnodes for equality. In general this macro should be used
* in preference to calling VOP_CMP directly.
*/
#endif /* _KERNEL */
/*
* Flags to VOP_SETATTR/VOP_GETATTR.
*/
/*
* Generally useful macros.
*/
#ifdef _KERNEL
/*
* Structure used while handling asynchronous VOP_PUTPAGE operations.
*/
struct async_reqs {
int a_flags; /* flags to indicate operation type */
};
/*
* VN_DISPOSE() -- given a page pointer, safely invoke VOP_DISPOSE().
*/
else \
}
#endif /* _KERNEL */
#ifdef __cplusplus
}
#endif
#endif /* _SYS_VNODE_H */