Kernel: pfile

From TechPubs Wiki

Revision as of 03:28, 4 January 2026 by Raion (talk | contribs) (Created page with "== Overview == The pfile (physical file) object in the IRIX kernel represents per-open-file state beyond the vnode (file system-independent) and vfile (open file description) layers. It primarily manages the current file offset (pf_offset) and associated synchronization (pf_offlock). In single-cell (non-distributed) configurations, the pfile layer directly handles offset and flag operations. In distributed (multi-cell) environments using Cellular IRIX features, higher la...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Overview

The pfile (physical file) object in the IRIX kernel represents per-open-file state beyond the vnode (file system-independent) and vfile (open file description) layers. It primarily manages the current file offset (pf_offset) and associated synchronization (pf_offlock). In single-cell (non-distributed) configurations, the pfile layer directly handles offset and flag operations. In distributed (multi-cell) environments using Cellular IRIX features, higher layers (DC - Distributed Coordinator, DS - Distributed Server) take over offset and flag management for coherence across cells. The pfile is integrated via the behavior descriptor (bhv_desc_t) mechanism, part of IRIX's chained vnode/behavior system. This allows stacking behaviors (e.g., pfile on top of filesystem-specific behaviors) on a common vfile_t structure. The pfile behavior is registered through pfile_ops (a vfileops_t table) at position VFILE_POSITION_PFILE.

Key Functions

The implementation provides operations for creation, offset management, flag handling, teardown, close, and migration. Initialization (pfile_init) Allocates a kernel zone (pfile_zone) for efficient pfile_t structures using kmem_zone_init. Creation (pfile_create) Called on file open: allocates a pfile_t from the zone, initializes offset mutex and sets offset to 0, creates and inserts a bhv_desc_t (pf_bd) into the vfile_t behavior chain at the initial position. Migration (pfile_target_migrate) Used during distributed target migration (e.g., cell handover): creates a new pfile behavior, inserts it into the chain, and sets a specific offset (preserving position across migration). Flag Management (pfile_setflags) Locks the vfile_t, modifies open flags (vf_flag) using atomic mask/or operations, unlocks. Offset Access (pfile_getoffset / pfile_setoffset) Simple unprotected read/write of pf_offset. VFILE_NO_OFFSET is ignored on set. Locked Offset Access (pfile_getoffset_locked / pfile_setoffset_locked) Optional locking of pf_offlock (cell mutex) around offset operations for distributed safety. Teardown (pfile_teardown) Destroys offset mutex, removes behavior from chain (if vnode exists), frees pfile_t to zone. Asserts mutex not held. Close Handling (pfile_close) Called twice per close (first/last): decrements vf_count in vfile_t, returns flags indicating last close.

Undocumented or IRIX-Specific Interfaces and Behaviors

Critical Structures

pfile_t (from pfile_private.h): off_t pf_offset — current file position. mutex_t pf_offlock — mutex protecting offset in distributed mode. bhv_desc_t pf_bd — behavior descriptor linking to vfile.

vfileops_t pfile_ops — operations table registered in behavior chain: Position: VFILE_POSITION_PFILE Functions: setflags, getoffset, setoffset, locked variants, teardown, close.

Integration with vfile_t: Contains vf_flag (open flags), vf_count (reference count), vf_bh (behavior chain head).


Distributed vs Single-Cell Behavior

Single-cell: pfile directly manages offset/flags. Multi-cell (Cellular IRIX): DC/DS layers override; pfile provides fallback or local cache.

Behavior Chain Mechanics Uses bhv_desc_t chaining (bhv_insert_initial, bhv_insert, bhv_remove). Allows dynamic stacking of behaviors (e.g., pfile over XFS/EFS vnode). Migration Support pfile_target_migrate enables seamless offset preservation during distributed file target changes (rare in standard IRIX, specific to Cellular configurations).

Similarities to illumos and BSD libc/kernel Implementations

IRIX file handling differs significantly from modern open-file-description models due to its vnode/behavior layering. illumos (Solaris-derived) Moderate similarity in layered vnode design (vnode ops, but no direct behavior chaining). File offsets live in struct file (user fd) or uio; no separate pfile-like object. Distributed features (Cluster) use different mechanisms. illumos uses struct cred, zones; no exact pfile equivalent. BSD (FreeBSD, etc.) Less similar: file offsets in struct file (per-fd), with filedesc table. Vnode ops direct, no behavior descriptors/chaining. No distributed cell concept; clustering separate. Close handling simpler (single decrement). Overall, IRIX's pfile is unique to its bhv_desc_t behavior system, designed for extensibility and distributed coherence. For replication or porting, focus on exact behavior insertion order and mutex usage. No direct illumos/BSD analog for easy porting; closest is Solaris vnode layering but without pfile separation.