- Describe some locking.

- Add VOP argument comments, add some asserts.
- Update/fix/remove outdated/missleading comments.
- Clean up, de-indent, KNF, misc.

No functional changes intended.
This commit is contained in:
rmind 2011-05-24 20:17:49 +00:00
parent a99f8b0b24
commit 9d8a062828
9 changed files with 838 additions and 1220 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: tmpfs.h,v 1.40 2011/05/19 03:21:23 rmind Exp $ */
/* $NetBSD: tmpfs.h,v 1.41 2011/05/24 20:17:49 rmind Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@ -41,93 +41,46 @@
/*
* Internal representation of a tmpfs directory entry.
*
* All fields are protected by vnode lock.
*/
struct tmpfs_dirent {
typedef struct tmpfs_dirent {
TAILQ_ENTRY(tmpfs_dirent) td_entries;
/* Length of the name stored in this directory entry. This avoids
* the need to recalculate it every time the name is used. */
uint16_t td_namelen;
/* The name of the entry, allocated from a string pool. This
* string is not required to be zero-terminated; therefore, the
* td_namelen field must always be used when accessing its value. */
char * td_name;
/* Pointer to the node this entry refers to. */
/* Pointer to the inode this entry refers to. */
struct tmpfs_node * td_node;
};
/* A directory in tmpfs holds a sorted list of directory entries, which in
* turn point to other files (which can be directories themselves).
*
* In tmpfs, this list is managed by a tail queue, whose head is defined by
* the struct tmpfs_dir type.
*
* It is imporant to notice that directories do not have entries for . and
* .. as other file systems do. These can be generated when requested
* based on information available by other means, such as the pointer to
* the node itself in the former case or the pointer to the parent directory
* in the latter case. This is done to simplify tmpfs's code and, more
* importantly, to remove redundancy. */
/* Name and its length. */
char * td_name;
uint16_t td_namelen;
} tmpfs_dirent_t;
TAILQ_HEAD(tmpfs_dir, tmpfs_dirent);
/* Each entry in a directory has a cookie that identifies it. Cookies
* supersede offsets within directories because, given how tmpfs stores
* directories in memory, there is no such thing as an offset. (Emulating
* a real offset could be very difficult.)
*
* The '.', '..' and the end of directory markers have fixed cookies which
* cannot collide with the cookies generated by other entries. The cookies
* fot the other entries are generated based on the memory address on which
* stores their information is stored.
*
* Ideally, using the entry's memory pointer as the cookie would be enough
* to represent it and it wouldn't cause collisions in any system.
* Unfortunately, this results in "offsets" with very large values which
* later raise problems in the Linux compatibility layer (and maybe in other
* places) as described in PR kern/32034. Hence we need to workaround this
* with a rather ugly hack.
*
* Linux 32-bit binaries, unless built with _FILE_OFFSET_BITS=64, have off_t
* set to 'long', which is a 32-bit *signed* long integer. Regardless of
* the macro value, GLIBC (2.3 at least) always uses the getdents64
* system call (when calling readdir) which internally returns off64_t
* offsets. In order to make 32-bit binaries work, *GLIBC* converts the
* 64-bit values returned by the kernel to 32-bit ones and aborts with
* EOVERFLOW if the conversion results in values that won't fit in 32-bit
* integers (which it assumes is because the directory is extremely large).
* This wouldn't cause problems if we were dealing with unsigned integers,
* but as we have signed integers, this check fails due to sign expansion.
*
* For example, consider that the kernel returns the 0xc1234567 cookie to
* userspace in a off64_t integer. Later on, GLIBC casts this value to
* off_t (remember, signed) with code similar to:
* system call returns the offset in kernel_value;
* off_t casted_value = kernel_value;
* if (sizeof(off_t) != sizeof(off64_t) &&
* kernel_value != casted_value)
* error!
* In this case, casted_value still has 0xc1234567, but when it is compared
* for equality against kernel_value, it is promoted to a 64-bit integer and
* becomes 0xffffffffc1234567, which is different than 0x00000000c1234567.
* Then, GLIBC assumes this is because the directory is very large.
*
* Given that all the above happens in user-space, we have no control over
* it; therefore we must workaround the issue here. We do this by
* truncating the pointer value to a 32-bit integer and hope that there
* won't be collisions. In fact, this will not cause any problems in
* 32-bit platforms but some might arise in 64-bit machines (I'm not sure
* if they can happen at all in practice).
*
* XXX A nicer solution shall be attempted. */
#if defined(_KERNEL)
/* Validate maximum td_namelen length. */
CTASSERT(MAXNAMLEN < UINT16_MAX);
#define TMPFS_DIRCOOKIE_DOT 0
#define TMPFS_DIRCOOKIE_DOTDOT 1
#define TMPFS_DIRCOOKIE_EOF 2
static __inline
off_t
tmpfs_dircookie(struct tmpfs_dirent *de)
/*
* Each entry in a directory has a cookie that identifies it. Cookies
* supersede offsets within directories, as tmpfs has no offsets as such.
*
* The '.', '..' and the end of directory markers have fixed cookies,
* which cannot collide with the cookies generated by other entries.
*
* The cookies for the other entries are generated based on the memory
* address of their representative meta-data structure.
*
* XXX: Truncating directory cookies to 31 bits now - workaround for
* problem with Linux compat, see PR/32034.
*/
static inline off_t
tmpfs_dircookie(tmpfs_dirent_t *de)
{
off_t cookie;
@ -138,43 +91,31 @@ tmpfs_dircookie(struct tmpfs_dirent *de)
return cookie;
}
#endif /* defined(_KERNEL) */
/* --------------------------------------------------------------------- */
#endif
/*
* Internal representation of a tmpfs file system node.
* Internal representation of a tmpfs file system node -- inode.
*
* This structure is splitted in two parts: one holds attributes common
* to all file types and the other holds data that is only applicable to
* a particular type. The code must be careful to only access those
* attributes that are actually allowed by the node's type.
* a particular type.
*
* All fields are protected by vnode lock. The vnode association itself
* is protected by tmpfs_node_t::tn_vlock.
*/
struct tmpfs_node {
/* Doubly-linked list entry which links all existing nodes for a
* single file system. This is provided to ease the removal of
* all nodes during the unmount operation. */
typedef struct tmpfs_node {
LIST_ENTRY(tmpfs_node) tn_entries;
/* The node's type. Any of 'VBLK', 'VCHR', 'VDIR', 'VFIFO',
* 'VLNK', 'VREG' and 'VSOCK' is allowed. The usage of vnode
* types instead of a custom enumeration is to make things simpler
* and faster, as we do not need to convert between two types. */
/* The inode type: VBLK, VCHR, VDIR, VFIFO, VLNK, VREG or VSOCK. */
enum vtype tn_type;
/* Node identifier. */
/* Inode identifier. */
ino_t tn_id;
/* Node's internal status. This is used by several file system
* operations to do modifications to the node in a delayed
* fashion. */
/* Inode status flags (for operations in delayed manner). */
int tn_status;
#define TMPFS_NODE_ACCESSED (1 << 1)
#define TMPFS_NODE_MODIFIED (1 << 2)
#define TMPFS_NODE_CHANGED (1 << 3)
/* The node size. It does not necessarily match the real amount
* of memory consumed by it. */
/* The inode size. */
off_t tn_size;
/* Generic node attributes. */
@ -192,128 +133,105 @@ struct tmpfs_node {
/* Head of byte-level lock list (used by tmpfs_advlock). */
struct lockf * tn_lockf;
/* As there is a single vnode for each active file within the
* system, care has to be taken to avoid allocating more than one
* vnode per file. In order to do this, a bidirectional association
* is kept between vnodes and nodes.
/*
* Each inode has a corresponding vnode. It is a bi-directional
* association. Whenever vnode is allocated, its v_data field is
* set to the inode it reference, and tmpfs_node_t::tn_vnode is
* set to point to the said vnode.
*
* Whenever a vnode is allocated, its v_data field is updated to
* point to the node it references. At the same time, the node's
* tn_vnode field is modified to point to the new vnode representing
* it. Further attempts to allocate a vnode for this same node will
* Further attempts to allocate a vnode for this same node will
* result in returning a new reference to the value stored in
* tn_vnode.
*
* May be NULL when the node is unused (that is, no vnode has been
* allocated for it or it has been reclaimed). */
* tn_vnode. It may be NULL when the node is unused (that is,
* no vnode has been allocated or it has been reclaimed).
*/
kmutex_t tn_vlock;
struct vnode * tn_vnode;
vnode_t * tn_vnode;
union {
/* Valid when tn_type == VBLK || tn_type == VCHR. */
/* Type case: VBLK or VCHR. */
struct {
dev_t tn_rdev;
} tn_dev;
/* Valid when tn_type == VDIR. */
/* Type case: VDIR. */
struct {
/* Pointer to the parent directory. The root
* directory has a pointer to itself in this field;
* this property identifies the root node. */
/* Parent directory (root inode points to itself). */
struct tmpfs_node * tn_parent;
/* Head of a tail-queue that links the contents of
* the directory together. See above for a
* description of its contents. */
/* List of directory entries. */
struct tmpfs_dir tn_dir;
/* Number and pointer of the first directory entry
* returned by the readdir operation if it were
* called again to continue reading data from the
* same directory as before. This is used to speed
* up reads of long directories, assuming that no
* more than one read is in progress at a given time.
* Otherwise, these values are discarded and a linear
* scan is performed from the beginning up to the
* point where readdir starts returning values. */
/*
* Number and pointer of the last directory entry
* returned by the readdir(3) operation.
*/
off_t tn_readdir_lastn;
struct tmpfs_dirent * tn_readdir_lastp;
} tn_dir;
/* Valid when tn_type == VLNK. */
/* Type case: VLNK. */
struct tn_lnk {
/* The link's target, allocated from a string pool. */
/* The link's target. */
char * tn_link;
} tn_lnk;
/* Valid when tn_type == VREG. */
/* Type case: VREG. */
struct tn_reg {
/* The contents of regular files stored in a tmpfs
* file system are represented by a single anonymous
* memory object (aobj, for short). The aobj provides
* direct access to any position within the file,
* because its contents are always mapped in a
* contiguous region of virtual memory. It is a task
* of the memory management subsystem (see uvm(9)) to
* issue the required page ins or page outs whenever
* a position within the file is accessed. */
/* Underlying UVM object to store contents. */
struct uvm_object * tn_aobj;
size_t tn_aobj_pages;
} tn_reg;
} tn_spec;
};
#define TMPFS_NODE_WHITEOUT ((struct tmpfs_node *)-1)
} tmpfs_node_t;
#if defined(_KERNEL)
LIST_HEAD(tmpfs_node_list, tmpfs_node);
/* --------------------------------------------------------------------- */
/* Status flags. */
#define TMPFS_NODE_ACCESSED 0x01
#define TMPFS_NODE_MODIFIED 0x02
#define TMPFS_NODE_CHANGED 0x04
#define TMPFS_NODE_STATUSALL \
(TMPFS_NODE_ACCESSED | TMPFS_NODE_MODIFIED | TMPFS_NODE_CHANGED)
/* White-out inode indicator. */
#define TMPFS_NODE_WHITEOUT ((struct tmpfs_node *)-1)
/*
* Internal representation of a tmpfs mount point.
*/
struct tmpfs_mount {
typedef struct tmpfs_mount {
/* Limit and number of bytes in use by the file system. */
uint64_t tm_mem_limit;
uint64_t tm_bytes_used;
kmutex_t tm_acc_lock;
/* Pointer to the node representing the root directory of this
* file system. */
struct tmpfs_node * tm_root;
/* Pointer to the root inode. */
tmpfs_node_t * tm_root;
/* Maximum number of possible nodes for this file system; set
* during mount time. We need a hard limit on the maximum number
* of nodes to avoid allocating too much of them; their objects
* cannot be released until the file system is unmounted.
* Otherwise, we could easily run out of memory by creating lots
* of empty files and then simply removing them. */
/* Maximum number of possible nodes for this file system. */
unsigned int tm_nodes_max;
/* Number of nodes currently allocated. This number only grows.
* When it reaches tm_nodes_max, no more new nodes can be allocated.
* Of course, the old, unused ones can be reused. */
/* Number of nodes currently allocated. */
unsigned int tm_nodes_cnt;
/* Node list. */
/* List of inodes and the lock protecting it. */
kmutex_t tm_lock;
struct tmpfs_node_list tm_nodes;
};
/* --------------------------------------------------------------------- */
} tmpfs_mount_t;
/*
* This structure maps a file identifier to a tmpfs node. Used by the
* NFS code.
*/
struct tmpfs_fid {
typedef struct tmpfs_fid {
uint16_t tf_len;
uint16_t tf_pad;
uint32_t tf_gen;
ino_t tf_id;
};
/* --------------------------------------------------------------------- */
} tmpfs_fid_t;
/*
* Prototypes for tmpfs_subr.c.
@ -347,9 +265,6 @@ int tmpfs_chsize(struct vnode *, u_quad_t, kauth_cred_t, struct lwp *);
int tmpfs_chtimes(struct vnode *, const struct timespec *,
const struct timespec *, const struct timespec *, int, kauth_cred_t,
struct lwp *);
void tmpfs_itimes(struct vnode *, const struct timespec *,
const struct timespec *, const struct timespec *);
void tmpfs_update(struct vnode *, const struct timespec *,
const struct timespec *, const struct timespec *, int);
int tmpfs_truncate(struct vnode *, off_t);
@ -377,26 +292,6 @@ char * tmpfs_strname_alloc(struct tmpfs_mount *, size_t);
void tmpfs_strname_free(struct tmpfs_mount *, char *, size_t);
bool tmpfs_strname_neqlen(struct componentname *, struct componentname *);
/* --------------------------------------------------------------------- */
/*
* Convenience macros to simplify some logical expressions.
*/
#define IMPLIES(a, b) (!(a) || (b))
#define IFF(a, b) (IMPLIES(a, b) && IMPLIES(b, a))
/* --------------------------------------------------------------------- */
/*
* Checks that the directory entry pointed by 'de' matches the name 'name'
* with a length of 'len'.
*/
#define TMPFS_DIRENT_MATCHES(de, name, len) \
(de->td_namelen == (uint16_t)len && \
memcmp((de)->td_name, (name), (de)->td_namelen) == 0)
/* --------------------------------------------------------------------- */
/*
* Ensures that the node pointed by 'node' is a directory and that its
* contents are consistent with respect to directories.
@ -408,64 +303,46 @@ bool tmpfs_strname_neqlen(struct componentname *, struct componentname *);
tmpfs_dircookie((node)->tn_spec.tn_dir.tn_readdir_lastp) == \
(node)->tn_spec.tn_dir.tn_readdir_lastn);
/* --------------------------------------------------------------------- */
/*
* Memory management stuff.
*/
/* Amount of memory pages to reserve for the system (e.g., to not use by
* tmpfs).
* XXX: Should this be tunable through sysctl, for instance? */
#define TMPFS_PAGES_RESERVED (4 * 1024 * 1024 / PAGE_SIZE)
/* Amount of memory pages to reserve for the system. */
#define TMPFS_PAGES_RESERVED (4 * 1024 * 1024 / PAGE_SIZE)
/*
* Macros/functions to convert from generic data structures to tmpfs
* specific ones.
* Routines to convert VFS structures to tmpfs internal ones.
*/
static __inline
struct tmpfs_mount *
static inline tmpfs_mount_t *
VFS_TO_TMPFS(struct mount *mp)
{
struct tmpfs_mount *tmp;
tmpfs_mount_t *tmp = mp->mnt_data;
#ifdef KASSERT
KASSERT((mp) != NULL && (mp)->mnt_data != NULL);
#endif
tmp = (struct tmpfs_mount *)(mp)->mnt_data;
KASSERT(tmp != NULL);
return tmp;
}
static inline tmpfs_node_t *
VP_TO_TMPFS_DIR(vnode_t *vp)
{
tmpfs_node_t *node = vp->v_data;
KASSERT(node != NULL);
TMPFS_VALIDATE_DIR(node);
return node;
}
#endif /* defined(_KERNEL) */
static __inline
struct tmpfs_node *
static __inline tmpfs_node_t *
VP_TO_TMPFS_NODE(struct vnode *vp)
{
struct tmpfs_node *node;
tmpfs_node_t *node = vp->v_data;
#ifdef KASSERT
KASSERT((vp) != NULL && (vp)->v_data != NULL);
#endif
node = (struct tmpfs_node *)vp->v_data;
return node;
}
#if defined(_KERNEL)
static __inline
struct tmpfs_node *
VP_TO_TMPFS_DIR(struct vnode *vp)
{
struct tmpfs_node *node;
node = VP_TO_TMPFS_NODE(vp);
#ifdef KASSERT
TMPFS_VALIDATE_DIR(node);
KASSERT(node != NULL);
#endif
return node;
}
#endif /* defined(_KERNEL) */
#endif /* _FS_TMPFS_TMPFS_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: tmpfs_fifoops.c,v 1.8 2008/06/19 23:57:22 skd Exp $ */
/* $NetBSD: tmpfs_fifoops.c,v 1.9 2011/05/24 20:17:49 rmind Exp $ */
/*
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tmpfs_fifoops.c,v 1.8 2008/06/19 23:57:22 skd Exp $");
__KERNEL_RCSID(0, "$NetBSD: tmpfs_fifoops.c,v 1.9 2011/05/24 20:17:49 rmind Exp $");
#include <sys/param.h>
#include <sys/vnode.h>
@ -43,8 +43,6 @@ __KERNEL_RCSID(0, "$NetBSD: tmpfs_fifoops.c,v 1.8 2008/06/19 23:57:22 skd Exp $"
#include <fs/tmpfs/tmpfs.h>
#include <fs/tmpfs/tmpfs_fifoops.h>
/* --------------------------------------------------------------------- */
/*
* vnode operations vector used for fifos stored in a tmpfs file system.
*/
@ -93,41 +91,50 @@ const struct vnodeopv_entry_desc tmpfs_fifoop_entries[] = {
{ &vop_putpages_desc, tmpfs_fifo_putpages },
{ NULL, NULL }
};
const struct vnodeopv_desc tmpfs_fifoop_opv_desc =
{ &tmpfs_fifoop_p, tmpfs_fifoop_entries };
/* --------------------------------------------------------------------- */
const struct vnodeopv_desc tmpfs_fifoop_opv_desc = {
&tmpfs_fifoop_p, tmpfs_fifoop_entries
};
int
tmpfs_fifo_close(void *v)
{
struct vnode *vp = ((struct vop_close_args *)v)->a_vp;
int error;
struct vop_close_args /* {
struct vnode *a_vp;
int a_fflag;
kauth_cred_t a_cred;
} */ *ap = v;
vnode_t *vp = ap->a_vp;
tmpfs_update(vp, NULL, NULL, NULL, UPDATE_CLOSE);
error = VOCALL(fifo_vnodeop_p, VOFFSET(vop_close), v);
return error;
return VOCALL(fifo_vnodeop_p, VOFFSET(vop_close), v);
}
/* --------------------------------------------------------------------- */
int
tmpfs_fifo_read(void *v)
{
struct vnode *vp = ((struct vop_read_args *)v)->a_vp;
struct vop_read_args /* {
struct vnode *a_vp;
struct uio *a_uio;
int a_ioflag;
kauth_cred_t a_cred;
} */ *ap = v;
vnode_t *vp = ap->a_vp;
VP_TO_TMPFS_NODE(vp)->tn_status |= TMPFS_NODE_ACCESSED;
return VOCALL(fifo_vnodeop_p, VOFFSET(vop_read), v);
}
/* --------------------------------------------------------------------- */
int
tmpfs_fifo_write(void *v)
{
struct vnode *vp = ((struct vop_write_args *)v)->a_vp;
struct vop_write_args /* {
struct vnode *a_vp;
struct uio *a_uio;
int a_ioflag;
kauth_cred_t a_cred;
} */ *ap = v;
vnode_t *vp = ap->a_vp;
VP_TO_TMPFS_NODE(vp)->tn_status |= TMPFS_NODE_MODIFIED;
return VOCALL(fifo_vnodeop_p, VOFFSET(vop_write), v);

View File

@ -1,4 +1,4 @@
/* $NetBSD: tmpfs_fifoops.h,v 1.7 2010/03/29 13:11:33 pooka Exp $ */
/* $NetBSD: tmpfs_fifoops.h,v 1.8 2011/05/24 20:17:49 rmind Exp $ */
/*
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@ -40,8 +40,6 @@
#include <miscfs/fifofs/fifo.h>
#include <fs/tmpfs/tmpfs_vnops.h>
/* --------------------------------------------------------------------- */
/*
* Declarations for tmpfs_fifoops.c.
*/
@ -89,5 +87,4 @@ int tmpfs_fifo_write (void *);
#define tmpfs_fifo_getpages genfs_badop
#define tmpfs_fifo_putpages vn_fifo_bypass
/* --------------------------------------------------------------------- */
#endif /* _FS_TMPFS_TMPFS_FIFOOPS_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: tmpfs_specops.c,v 1.9 2008/06/20 00:07:47 skd Exp $ */
/* $NetBSD: tmpfs_specops.c,v 1.10 2011/05/24 20:17:49 rmind Exp $ */
/*
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tmpfs_specops.c,v 1.9 2008/06/20 00:07:47 skd Exp $");
__KERNEL_RCSID(0, "$NetBSD: tmpfs_specops.c,v 1.10 2011/05/24 20:17:49 rmind Exp $");
#include <sys/param.h>
#include <sys/vnode.h>
@ -43,13 +43,13 @@ __KERNEL_RCSID(0, "$NetBSD: tmpfs_specops.c,v 1.9 2008/06/20 00:07:47 skd Exp $"
#include <fs/tmpfs/tmpfs.h>
#include <fs/tmpfs/tmpfs_specops.h>
/* --------------------------------------------------------------------- */
/*
* vnode operations vector used for special devices stored in a tmpfs
* file system.
*/
int (**tmpfs_specop_p)(void *);
const struct vnodeopv_entry_desc tmpfs_specop_entries[] = {
{ &vop_default_desc, vn_default_error },
{ &vop_lookup_desc, tmpfs_spec_lookup },
@ -94,41 +94,50 @@ const struct vnodeopv_entry_desc tmpfs_specop_entries[] = {
{ &vop_putpages_desc, tmpfs_spec_putpages },
{ NULL, NULL }
};
const struct vnodeopv_desc tmpfs_specop_opv_desc =
{ &tmpfs_specop_p, tmpfs_specop_entries };
/* --------------------------------------------------------------------- */
const struct vnodeopv_desc tmpfs_specop_opv_desc = {
&tmpfs_specop_p, tmpfs_specop_entries
};
int
tmpfs_spec_close(void *v)
{
struct vnode *vp = ((struct vop_close_args *)v)->a_vp;
int error;
struct vop_close_args /* {
struct vnode *a_vp;
int a_fflag;
kauth_cred_t a_cred;
} */ *ap = v;
vnode_t *vp = ap->a_vp;
tmpfs_update(vp, NULL, NULL, NULL, UPDATE_CLOSE);
error = VOCALL(spec_vnodeop_p, VOFFSET(vop_close), v);
return error;
return VOCALL(spec_vnodeop_p, VOFFSET(vop_close), v);
}
/* --------------------------------------------------------------------- */
int
tmpfs_spec_read(void *v)
{
struct vnode *vp = ((struct vop_read_args *)v)->a_vp;
struct vop_read_args /* {
struct vnode *a_vp;
struct uio *a_uio;
int a_ioflag;
kauth_cred_t a_cred;
} */ *ap = v;
vnode_t *vp = ap->a_vp;
VP_TO_TMPFS_NODE(vp)->tn_status |= TMPFS_NODE_ACCESSED;
return VOCALL(spec_vnodeop_p, VOFFSET(vop_read), v);
}
/* --------------------------------------------------------------------- */
int
tmpfs_spec_write(void *v)
{
struct vnode *vp = ((struct vop_write_args *)v)->a_vp;
struct vop_write_args /* {
struct vnode *a_vp;
struct uio *a_uio;
int a_ioflag;
kauth_cred_t a_cred;
} */ *ap = v;
vnode_t *vp = ap->a_vp;
VP_TO_TMPFS_NODE(vp)->tn_status |= TMPFS_NODE_MODIFIED;
return VOCALL(spec_vnodeop_p, VOFFSET(vop_write), v);

View File

@ -1,4 +1,4 @@
/* $NetBSD: tmpfs_specops.h,v 1.7 2008/04/28 20:24:02 martin Exp $ */
/* $NetBSD: tmpfs_specops.h,v 1.8 2011/05/24 20:17:49 rmind Exp $ */
/*
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@ -40,8 +40,6 @@
#include <miscfs/specfs/specdev.h>
#include <fs/tmpfs/tmpfs_vnops.h>
/* --------------------------------------------------------------------- */
/*
* Declarations for tmpfs_specops.c.
*/
@ -89,6 +87,4 @@ int tmpfs_spec_write (void *);
#define tmpfs_spec_getpages spec_getpages
#define tmpfs_spec_putpages spec_putpages
/* --------------------------------------------------------------------- */
#endif /* _FS_TMPFS_TMPFS_SPECOPS_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: tmpfs_vfsops.c,v 1.49 2011/05/24 01:09:47 rmind Exp $ */
/* $NetBSD: tmpfs_vfsops.c,v 1.50 2011/05/24 20:17:49 rmind Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.49 2011/05/24 01:09:47 rmind Exp $");
__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.50 2011/05/24 20:17:49 rmind Exp $");
#include <sys/param.h>
#include <sys/types.h>
@ -51,7 +51,6 @@ __KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.49 2011/05/24 01:09:47 rmind Exp
#include <sys/stat.h>
#include <sys/systm.h>
#include <sys/vnode.h>
#include <sys/proc.h>
#include <sys/module.h>
#include <miscfs/genfs/genfs.h>
@ -66,24 +65,23 @@ struct pool tmpfs_node_pool;
static int tmpfs_mount(struct mount *, const char *, void *, size_t *);
static int tmpfs_start(struct mount *, int);
static int tmpfs_unmount(struct mount *, int);
static int tmpfs_root(struct mount *, struct vnode **);
static int tmpfs_vget(struct mount *, ino_t, struct vnode **);
static int tmpfs_fhtovp(struct mount *, struct fid *, struct vnode **);
static int tmpfs_root(struct mount *, vnode_t **);
static int tmpfs_vget(struct mount *, ino_t, vnode_t **);
static int tmpfs_fhtovp(struct mount *, struct fid *, vnode_t **);
static int tmpfs_vptofh(struct vnode *, struct fid *, size_t *);
static int tmpfs_statvfs(struct mount *, struct statvfs *);
static int tmpfs_sync(struct mount *, int, kauth_cred_t);
static void tmpfs_init(void);
static void tmpfs_done(void);
static int tmpfs_snapshot(struct mount *, struct vnode *,
struct timespec *);
static int tmpfs_snapshot(struct mount *, vnode_t *, struct timespec *);
static void
tmpfs_init(void)
{
pool_init(&tmpfs_dirent_pool, sizeof(struct tmpfs_dirent), 0, 0, 0,
pool_init(&tmpfs_dirent_pool, sizeof(tmpfs_dirent_t), 0, 0, 0,
"tmpfs_dirent", &pool_allocator_nointr, IPL_NONE);
pool_init(&tmpfs_node_pool, sizeof(struct tmpfs_node), 0, 0, 0,
pool_init(&tmpfs_node_pool, sizeof(tmpfs_node_t), 0, 0, 0,
"tmpfs_node", &pool_allocator_nointr, IPL_NONE);
}
@ -98,9 +96,9 @@ tmpfs_done(void)
static int
tmpfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
{
struct tmpfs_mount *tmp;
struct tmpfs_node *root;
struct tmpfs_args *args = data;
tmpfs_mount_t *tmp;
tmpfs_node_t *root;
uint64_t memlimit;
ino_t nodes;
int error;
@ -155,7 +153,7 @@ tmpfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
KASSERT(nodes >= 3);
/* Allocate the tmpfs mount structure and fill it. */
tmp = kmem_zalloc(sizeof(struct tmpfs_mount), KM_SLEEP);
tmp = kmem_zalloc(sizeof(tmpfs_mount_t), KM_SLEEP);
if (tmp == NULL)
return ENOMEM;
@ -200,8 +198,8 @@ tmpfs_start(struct mount *mp, int flags)
static int
tmpfs_unmount(struct mount *mp, int mntflags)
{
struct tmpfs_mount *tmp;
struct tmpfs_node *node;
tmpfs_mount_t *tmp;
tmpfs_node_t *node;
int error, flags = 0;
/* Handle forced unmounts. */
@ -215,32 +213,24 @@ tmpfs_unmount(struct mount *mp, int mntflags)
tmp = VFS_TO_TMPFS(mp);
/* Free all associated data. The loop iterates over the linked list
* we have containing all used nodes. For each of them that is
* a directory, we free all its directory entries. Note that after
* freeing a node, it will automatically go to the available list,
* so we will later have to iterate over it to release its items. */
node = LIST_FIRST(&tmp->tm_nodes);
while (node != NULL) {
struct tmpfs_node *next;
/* Destroy any existing inodes. */
while ((node = LIST_FIRST(&tmp->tm_nodes)) != NULL) {
if (node->tn_type == VDIR) {
struct tmpfs_dirent *de;
tmpfs_dirent_t *de;
/* Destroy any directory entries. */
de = TAILQ_FIRST(&node->tn_spec.tn_dir.tn_dir);
while (de != NULL) {
struct tmpfs_dirent *nde;
tmpfs_dirent_t *nde;
nde = TAILQ_NEXT(de, td_entries);
tmpfs_free_dirent(tmp, de, false);
node->tn_size -= sizeof(tmpfs_dirent_t);
de = nde;
node->tn_size -= sizeof(struct tmpfs_dirent);
}
}
next = LIST_NEXT(node, tn_entries);
/* Removes inode from the list. */
tmpfs_free_node(tmp, node);
node = next;
}
/* Throw away the tmpfs_mount structure. */
@ -252,42 +242,35 @@ tmpfs_unmount(struct mount *mp, int mntflags)
return 0;
}
/* --------------------------------------------------------------------- */
static int
tmpfs_root(struct mount *mp, struct vnode **vpp)
tmpfs_root(struct mount *mp, vnode_t **vpp)
{
return tmpfs_alloc_vp(mp, VFS_TO_TMPFS(mp)->tm_root, vpp);
}
/* --------------------------------------------------------------------- */
static int
tmpfs_vget(struct mount *mp, ino_t ino,
struct vnode **vpp)
tmpfs_vget(struct mount *mp, ino_t ino, vnode_t **vpp)
{
printf("tmpfs_vget called; need for it unknown yet\n");
return EOPNOTSUPP;
}
/* --------------------------------------------------------------------- */
static int
tmpfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
tmpfs_fhtovp(struct mount *mp, struct fid *fhp, vnode_t **vpp)
{
tmpfs_mount_t *tmp;
tmpfs_node_t *node;
tmpfs_fid_t tfh;
bool found;
struct tmpfs_fid tfh;
struct tmpfs_mount *tmp;
struct tmpfs_node *node;
tmp = VFS_TO_TMPFS(mp);
if (fhp->fid_len != sizeof(struct tmpfs_fid))
if (fhp->fid_len != sizeof(tmpfs_fid_t))
return EINVAL;
memcpy(&tfh, fhp, sizeof(struct tmpfs_fid));
memcpy(&tfh, fhp, sizeof(tmpfs_fid_t));
found = false;
mutex_enter(&tmp->tm_lock);
@ -304,23 +287,21 @@ tmpfs_fhtovp(struct mount *mp, struct fid *fhp, struct vnode **vpp)
return found ? tmpfs_alloc_vp(mp, node, vpp) : ESTALE;
}
/* --------------------------------------------------------------------- */
static int
tmpfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
tmpfs_vptofh(vnode_t *vp, struct fid *fhp, size_t *fh_size)
{
struct tmpfs_fid tfh;
struct tmpfs_node *node;
tmpfs_fid_t tfh;
tmpfs_node_t *node;
if (*fh_size < sizeof(struct tmpfs_fid)) {
*fh_size = sizeof(struct tmpfs_fid);
if (*fh_size < sizeof(tmpfs_fid_t)) {
*fh_size = sizeof(tmpfs_fid_t);
return E2BIG;
}
*fh_size = sizeof(struct tmpfs_fid);
*fh_size = sizeof(tmpfs_fid_t);
node = VP_TO_TMPFS_NODE(vp);
memset(&tfh, 0, sizeof(tfh));
tfh.tf_len = sizeof(struct tmpfs_fid);
tfh.tf_len = sizeof(tmpfs_fid_t);
tfh.tf_gen = node->tn_gen;
tfh.tf_id = node->tn_id;
memcpy(fhp, &tfh, sizeof(tfh));
@ -328,12 +309,10 @@ tmpfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
return 0;
}
/* --------------------------------------------------------------------- */
static int
tmpfs_statvfs(struct mount *mp, struct statvfs *sbp)
{
struct tmpfs_mount *tmp;
tmpfs_mount_t *tmp;
fsfilcnt_t freenodes;
size_t avail;
@ -348,7 +327,7 @@ tmpfs_statvfs(struct mount *mp, struct statvfs *sbp)
sbp->f_bresvd = 0;
freenodes = MIN(tmp->tm_nodes_max - tmp->tm_nodes_cnt,
avail * PAGE_SIZE / sizeof(struct tmpfs_node));
avail * PAGE_SIZE / sizeof(tmpfs_node_t));
sbp->f_files = tmp->tm_nodes_cnt + freenodes;
sbp->f_favail = sbp->f_ffree = freenodes;
@ -360,27 +339,20 @@ tmpfs_statvfs(struct mount *mp, struct statvfs *sbp)
return 0;
}
/* --------------------------------------------------------------------- */
/* ARGSUSED0 */
static int
tmpfs_sync(struct mount *mp, int waitfor,
kauth_cred_t uc)
tmpfs_sync(struct mount *mp, int waitfor, kauth_cred_t uc)
{
return 0;
}
static int
tmpfs_snapshot(struct mount *mp, struct vnode *vp,
struct timespec *ctime)
tmpfs_snapshot(struct mount *mp, vnode_t *vp, struct timespec *ctime)
{
return EOPNOTSUPP;
}
/* --------------------------------------------------------------------- */
/*
* tmpfs vfs operations.
*/

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: tmpfs_vnops.h,v 1.12 2011/01/13 13:35:12 pooka Exp $ */
/* $NetBSD: tmpfs_vnops.h,v 1.13 2011/05/24 20:17:49 rmind Exp $ */
/*
* Copyright (c) 2005, 2006 The NetBSD Foundation, Inc.
@ -39,8 +39,6 @@
#include <miscfs/genfs/genfs.h>
/* --------------------------------------------------------------------- */
/*
* Declarations for tmpfs_vnops.c.
*/
@ -89,6 +87,4 @@ int tmpfs_getpages (void *);
int tmpfs_putpages (void *);
int tmpfs_whiteout (void *);
/* --------------------------------------------------------------------- */
#endif /* _FS_TMPFS_TMPFS_VNOPS_H_ */