Kernel: vnode Operations
From TechPubs Wiki
Summary of known vfs operations and vnode operations.
1. VFS Operations (vfsops_t)
These are operations on the filesystem as a whole:
| Operation | Purpose / Semantics | Typical FS Relevance |
|---|---|---|
mount
|
Mount the filesystem; initialize structures, link root vnode. | All FS |
umount
|
Unmount; flush buffers, release resources. | All FS |
sync
|
Flush all dirty buffers and VM pages to disk. | Persistent FS (EFS, XFS) |
statvfs
|
Retrieve filesystem statistics (free space, block size). | All FS |
vget
|
Retrieve vnode by inode number or identifier. | Persistent FS |
quotactl
|
Manage quotas on filesystem (user/group limits). | Optional, persistent FS |
import
|
Integrate remote filesystem structures (NFS, exported FS). | Network FS |
root
|
Return root vnode of filesystem. | All FS |
reclaim
|
Cleanup filesystem-specific vnode data before freeing vnode memory. | All FS |
fsid
|
Return filesystem ID. | Persistent FS |
check
|
Perform consistency or integrity checks (optional). | Persistent FS |
remount
|
Update mount options without unmounting. | Optional |
statfs
|
Return summarized filesystem status. | Persistent FS |
Notes:
- Pseudo-filesystems (pipefs, fifofs) stub most of these functions; only
rootorvgetmay return in-memory structures. - Real filesystems (EFS, XFS) implement almost all operations for proper filesystem management.
2. Vnode Operations (vnodeops_t)
These are operations on individual vnodes, dispatched via the BHV layer.
| Operation | Purpose / Semantics | FS Relevance / Typical Implementation |
|---|---|---|
read
|
Read data from vnode into user or kernel buffer. | All FS supporting files or streams |
write
|
Write data to vnode from buffer. | All FS supporting files or streams |
ioctl
|
Perform device-specific or FS-specific commands. | Devices, pseudo-FS, streams |
getattr
|
Retrieve vnode attributes (mode, owner, size, timestamps). | All FS |
setattr
|
Update vnode attributes. | All FS |
access
|
Check access permissions. | All FS |
lookup
|
Resolve pathname component to vnode. | Directory FS (EFS, XFS, pipefs limited) |
create
|
Create a new file. | Persistent FS; pseudo-FS may stub |
remove
|
Remove a file. | Persistent FS; pipefs/FIFO may implement |
mkdir
|
Create directory. | Persistent FS |
rmdir
|
Remove directory. | Persistent FS |
readdir
|
Read directory entries. | Persistent FS |
symlink
|
Create symbolic link. | Optional, persistent FS |
readlink
|
Read symbolic link target. | Optional, persistent FS |
rename
|
Rename a file. | Persistent FS |
link
|
Create hard link. | Persistent FS |
unlink
|
Remove a link. | Persistent FS |
fsync
|
Flush vnode’s buffers to disk. | Persistent FS |
map
|
Map file pages into VM. | Persistent FS, memory-mapped files |
addmap
|
Notify FS of memory mapping. | Persistent FS |
delmap
|
Notify FS of unmapped region. | Persistent FS |
frlock
|
File region locking. | All FS supporting advisory locks |
poll
|
Determine readiness for I/O. | Streams, pipes, devices |
seek
|
Validate seek operation. | Regular files, optionally pseudo-FS |
inactive
|
Called when last reference released; free resources. | All FS |
reclaim
|
Called to cleanup filesystem-specific vnode state. | All FS |
realvp
|
Return underlying “real” vnode in layered FS. | Stacked or layered FS |
cover
|
Return vnode that this vnode overlays. | Stacked FS |
link_removed
|
Notify FS that a link was removed. | Persistent FS |
Notes:
- Pseudo-filesystems (pipefs, fifofs):
- Implement
read,write,poll,inactive - Many other operations are stubs (
fs_nosys) because they have no persistent storage.
- Implement
- Persistent filesystems (EFS, XFS):
- Implement almost all operations fully.
- VM integration (
map,addmap,delmap) links vnode buffers with page cache. - Locking (
frlock) and attribute operations are critical for filesystem consistency.
- Streams / devices:
- Integrate with
poll/selectvia pollhead structures. ioctlis heavily used to expose device-specific functionality.
- Integrate with
3. Behavior Semantics
- Vnode operations are dispatched via the behavior chain, allowing:
- Layered filesystems: stacking additional behaviors (e.g., shadow vnodes, network FS).
- Pseudo-filesystems: handle vnodes without disk backing.
- Operations are always invoked on BHV descriptors, not directly on vnodes. This ensures correct dispatch in multi-layer environments.
4. Filesystem Type Considerations
| FS Type | Implemented Operations |
|---|---|
| Persistent (EFS/XFS) | All VFS and vnode ops; full VM/page cache integration, locking, attributes |
| Pseudo-FS (pipefs/fifofs) | read, write, poll, inactive; stubs for most others
|
| Device FS (devfs) | read, write, ioctl, poll, getattr/setattr
|
| Network FS (NFS-like) | import, vget, root, lookup, read, write
|
5. Reference / Lifecycle Management
- VFS ops:
reclaimandsyncensure global cleanup. - Vnode ops:
inactiveandreclaimensure per-vnode cleanup. - BHVs: behavior chain allows multiple layers to participate in cleanup or dispatch.