The drive is constructed in a fairly modular fashion. A lot of low-level functionality, such as threads, timing, et cetera, is provided by the general NASD API. Additionally, I/O modules provide low-level mechanisms for the drive to access the physical media. A caching module provides cache management, including tracking dirty blocks and writing them back asynchronously. Separate modules handle mapping, layout, tracing, and other functionality. The details of the various modules that compose the drive will be described in later sections.
There are two header files which most drive files include. nasd_od.h
defines all of the datastructures and constants which are written directly to
the storage media. For example, the inode structure is defined here. nasd_cache.h
defines most of the shared software structures for the drive. Prototypes for
most drive functions can be found in nasd_cache.h
.
General-purpose disk management, including partition manipulation and
start-of-day/end-of-day code, is found in nasd_diskman.c
.
At start-of-day, nasd_basic_init()
is called. This function
initializes various NASD-general modules that the drive will use (such as
the memory and timeout
modules), and creates a global shutdown list nasd_odc_shutdown
.
Later, nasd_setup_disk()
is called. This function in turn initializes
all drive-internal modules. These modules register any necessary cleanup
on nasd_odc_shutdown
. New modules which are added to the drive
should call their initialization routine from nasd_setup_disk()
.
drive/
subdirectory of the
NASD tree, with a few key files in include/nasd/
. Here's a list of
some key files:
include/nasd/nasd_od.h
: Basic definitions of on-disk datastructures
and constants for NASD filesystem.
include/nasd/nasd_cache.h
: Definitions for in-core datastructures
for new NASD drive. Also includes prototypes for implementation of drive
functionality.
include/nasd/nasd_drive_types.idl
: Includes RPC type definitions.
See Adding RPCs for more information.
include/nasd/nasd_pdrive.idl
: Definitions file for drive RPCs.
See Adding RPCs for more information.
include/nasd/nasd_control.idl
: Definitions file for the various
drive control objects.
See Adding control objects for more information.
nasd_bmap.c
: Handles mapping of logical object blocks to physical
drive blocks. Decision-making about block allocation is made in the layout module,
not here.
nasd_cbasic.c
: Cache basics- allocate, deallocate memory, perform
some simple cache block ops.
nasd_cblock.c
: Core of cache- hash table of in-core
blocks, simple state machine.
nasd_control.c
: Implements the special "control" objects
nasd_dirty.c
: Dirty-block handling for cache.
nasd_diskman.c
: Fundamental disk management. Create and destroy
partitions, format disk, global initialization and shutdown.
nasd_free.c
: Tracks what blocks are unallocated on drive. The
functionality of this module is rather overloaded. It includes many
functions for managing lists of blocks, which other modules find useful
for their own nefarious purposes.
nasd_ioqueue.c
: Queueing and dispatching for physical
I/Os. Determines the order in which I/O will be performed when the I/O
subsystem is so busy that some I/Os must wait. Makes calls into queueing
policy modules which determine actual ordering. Examples of these
modules include nasd_ioqueue_fifo.c
and nasd_ioqueue_cscan.c
.
nasd_layout.c
: Master layout module. Provides bookkeeping
on block allocation, and makes calls into policy modules which perform
decision-making. Examples of policy modules include nasd_layout_seq.c
and nasd_layout_reg.c
.
nasd_ref.c
: Per-block reference counting engine. Handles
changes to reference counts on ranges of blocks, and marks blocks free as
their reference count goes to zero.
nasd_obj.c
: Fundamental implementation of NASD operations, and
basic object management. This module provides an internal API which is called
by the RPC layer, and is appropriate for being called by something such as
a remote execution environment.
nasd_od_ops.c
: RPC dispatch- all RPC stubs are here (most are
wrappers around calls to things in nasd_obj.c
).
nasd_trace_dr.c
: Provides an API for the rest of the drive to
log timestamped events, and a control-object interface for clients to
enable and disable tracing as well as extract traces.
nasd_od_kio.c
: DU-kernel-specific I/O module.
nasd_od_uio.c
: Generic UNIX user-level I/O module.
nasd_od_drive.c
: Contains main()
for user-level drive.
pikdrive.c
: Stub for in-kernel drive that calls start-the-drive
system call.
nasd_cbasic.c
, nasd_cblock.c
, nasd_dirty.c
nasd_bmap.c
nasd_free.c
, nasd_diskman.c
nasd_free.c
, nasd_layout.c
, as well as layout policy modules
nasd_ioqueue.c
as well as queueing policy modules
nasd_ref.c
, nasd_bmap.c
nasd_obj.c
, nasd_control.c
nasd_od_ops.c
![]() | ![]() | ![]() |
---|---|---|
Drive operations | Drive transport | NASD Programmer's Documentation |