smartpqi

title: smartpqi(4)

summary: Microsemi Smart Family SCSI driver

text:
# smartpqi(4)

## NAME
smartpqi - Microsemi Smart Family SCSI driver

## SYNOPSIS
modprobe smartpqi

[disable_device_id_wildcards={0|1}] [disable_heartbeat={0|1}] [disable_ctrl_shutdown={0|1}] [lockup_action={none|reboot|panic}] [expose_ld_first={0|1}] [hide_vsep={0|1}]

## DESCRIPTION
smartpqi is a SCSI driver for Microsemi Smart Family controllers.

### Supported ioctl() operations
For compatibility with applications written for the cciss(4) and hpsa(4) drivers, many, but not all of the ioctl(2) operations supported by the hpsa driver are also supported by the smartpqi driver. The data structures used by these operations are described in the Linux kernel source file include/linux/cciss_ioctl.h.

CCISS_DEREGDISK, CCISS_REGNEWDISK, CCISS_REGNEWD

These operations all do exactly the same thing, which is to cause the driver to re-scan for new devices. This does exactly the same thing as writing to the smartpqi-specific host rescan attribute.

CCISS_GETPCIINFO

This operation returns the PCI domain, bus, device, and function and "board ID" (PCI subsystem ID).

CCISS_GETDRIVVER

This operation returns the driver version in four bytes, encoded as:

```
(major_version << 28) | (minor_version << 24) |

        (release << 16) | revision

```

CCISS_PASSTHRU

Allows BMIC and CISS commands to be passed through to the controller.

### Boot options
disable_device_id_wildcards={0|1}

Disables support for device ID wildcards. The default value is 0.

disable_heartbeat={0|1}

Disables support for the controller's heartbeat check. This parameter is used for debugging purposes. The default value is 0, leaving the controller's heartbeat check active.

disable_ctrl_shutdown={0|1}

Disables support for shutting down the controller in the event of a controller lockup. The default value is 0.

lockup_action={none|reboot|panic}

Specifies the action the driver takes when a controller lockup is detected. The default action is none. parameter

action

none

take controller offline only

reboot

reboot the system

panic

panic the system

expose_ld_first={0|1}

This option enables support for exposing logical devices to the operating system before physical devices. The default value is 0.

hide_vsep={0|1}

This option enables disabling exposure of the virtual SEP to the host. This is usually associated with direct attached drives. The default value is 0.

## FILES

### Device nodes
Logical drives are accessed via the SCSI disk driver (sd), tape drives via the SCSI tape driver (st), and the RAID controller via the SCSI generic driver (sg), with device nodes named /dev/sd*, /dev/st*, and /dev/sg*, respectively.

### SmartPQI-specific host attribute files in /sys
/sys/class/scsi_host/host*/rescan

The host rescan attribute is a write-only attribute. Writing to this attribute will cause the driver to scan for new, changed, or removed devices (e.g., hot-plugged tape drives, or newly configured or deleted logical drives) and notify the SCSI mid-layer of any changes detected. Usually this action is triggered automatically by configuration changes, so the user should not normally have to write to this file. Doing so may be useful when hot-plugging devices such as tape drives or entire storage boxes containing pre-configured logical drives.

/sys/class/scsi_host/host*/version

The host version attribute is a read-only attribute. This attribute contains the driver version and the controller firmware version.

For example:

```
$
cat /sys/class/scsi_host/host1/version
driver: 1.1.2-126
firmware: 1.29-112

```

/sys/class/scsi_host/host*/lockup_action

The host lockup_action attribute is a read/write attribute. This attribute will cause the driver to perform a specific action in the unlikely event that a controller lockup has been detected. See OPTIONS above for an explanation of the lockup_action values.

/sys/class/scsi_host/host*/driver_version

The driver_version attribute is read-only. This attribute contains the smartpqi driver version.

For example:

```
$
cat /sys/class/scsi_host/host1/driver_version
1.1.2-126

```

/sys/class/scsi_host/host*/firmware_version

The firmware_version attribute is read-only. This attribute contains the controller firmware version.

For example:

```
$
cat /sys/class/scsi_host/host1/firmware_version
1.29-112

```

/sys/class/scsi_host/host*/model

The model attribute is read-only. This attribute contains the product identification string of the controller.

For example:

```
$
cat /sys/class/scsi_host/host1/model
1100-16i

```

/sys/class/scsi_host/host*/serial_number

The serial_number attribute is read-only. This attribute contains the unique identification number of the controller.

For example:

```
$
cat /sys/class/scsi_host/host1/serial_number
6A316373777

```

/sys/class/scsi_host/host*/vendor

The vendor attribute is read-only. This attribute contains the vendor identification string of the controller.

For example:

```
$
cat /sys/class/scsi_host/host1/vendor
Adaptec

```

### SmartPQI-specific disk attribute files in /sys
In the file specifications below, c stands for the number of the appropriate SCSI controller, b is the bus number, t the target number, and l is the logical unit number (LUN).

/sys/class/scsi_disk/c:b:t:l/device/raid_level

The raid_level attribute is read-only. This attribute contains the RAID level of each logical drive.

For example:

```
$
cat /sys/class/scsi_disk/4:0:0:0/device/raid_level
RAID 0

```

/sys/class/scsi_disk/c:b:t:l/device/sas_address

The sas_address attribute is read-only. This attribute contains the unique identifier of the disk.

For example:

```
$
cat /sys/class/scsi_disk/1:0:3:0/device/sas_address
0x5001173d028543a2

```

/sys/class/scsi_disk/c:b:t:l/device/ssd_smart_path_enabled

The ssd_smart_path_enabled attribute is read-only. This attribute is for ioaccel-enabled volumes. (Ioaccel is an alternative driver submission path that allows the driver to send I/O requests directly to backend SCSI devices, bypassing the controller firmware. This results in an increase in performance. This method is used for HBA disks and for logical volumes comprised of SSDs.) Contains 1 if ioaccel is enabled for the volume and 0 otherwise.

For example:

```
$
cat /sys/class/scsi_disk/1:0:3:0/device/ssd_smart_path_enabled
0

```

## VERSIONS
The smartpqi driver was added in Linux 4.9.

## NOTES

### Configuration
To configure a Microsemi Smart Family controller, refer to the User Guide for the controller, which can be found by searching for the specific controller at https://storage.microsemi.com/.

## SEE ALSO
cciss(4), hpsa(4), sd(4), st(4)

Documentation/ABI/testing/sysfs-bus-pci-devices-cciss in the Linux kernel source tree.


st

package: man-pages

title: st(4)

summary: SCSI tape device

text:
# st(4)

## NAME
st - SCSI tape device

## SYNOPSIS

```
#include <sys/mtio.h>
```

```
int ioctl(int fd, int request [, (void *)arg3]);
int ioctl(int fd, MTIOCTOP, (struct mtop *)mt_cmd);
int ioctl(int fd, MTIOCGET, (struct mtget *)mt_status);
int ioctl(int fd, MTIOCPOS, (struct mtpos *)mt_pos);
```

## DESCRIPTION
The st driver provides the interface to a variety of SCSI tape devices. Currently, the driver takes control of all detected devices of type “sequential-access”. The st driver uses major device number 9.

Each device uses eight minor device numbers. The lowermost five bits in the minor numbers are assigned sequentially in the order of detection. In the 2.6 kernel, the bits above the eight lowermost bits are concatenated to the five lowermost bits to form the tape number. The minor numbers can be grouped into two sets of four numbers: the principal (auto-rewind) minor device numbers, n, and the “no-rewind” device numbers, (n + 128). Devices opened using the principal device number will be sent a REWIND command when they are closed. Devices opened using the “no-rewind” device number will not. (Note that using an auto-rewind device for positioning the tape with, for instance, mt does not lead to the desired result: the tape is rewound after the mt command and the next command starts from the beginning of the tape).

Within each group, four minor numbers are available to define devices with different characteristics (block size, compression, density, etc.) When the system starts up, only the first device is available. The other three are activated when the default characteristics are defined (see below). (By changing compile-time constants, it is possible to change the balance between the maximum number of tape drives and the number of minor numbers for each drive. The default allocation allows control of 32 tape drives. For instance, it is possible to control up to 64 tape drives with two minor numbers for different options.)

Devices are typically created by:

```
mknod -m 666 /dev/st0 c 9 0
mknod -m 666 /dev/st0l c 9 32
mknod -m 666 /dev/st0m c 9 64
mknod -m 666 /dev/st0a c 9 96
mknod -m 666 /dev/nst0 c 9 128
mknod -m 666 /dev/nst0l c 9 160
mknod -m 666 /dev/nst0m c 9 192
mknod -m 666 /dev/nst0a c 9 224
```

There is no corresponding block device.

The driver uses an internal buffer that has to be large enough to hold at least one tape block. Before Linux 2.1.121, the buffer is allocated as one contiguous block. This limits the block size to the largest contiguous block of memory the kernel allocator can provide. The limit is currently 128 kB for 32-bit architectures and 256 kB for 64-bit architectures. In newer kernels the driver allocates the buffer in several parts if necessary. By default, the maximum number of parts is 16. This means that the maximum block size is very large (2 MB if allocation of 16 blocks of 128 kB succeeds).

The driver's internal buffer size is determined by a compile-time constant which can be overridden with a kernel startup option. In addition to this, the driver tries to allocate a larger temporary buffer at run time if necessary. However, run-time allocation of large contiguous blocks of memory may fail and it is advisable not to rely too much on dynamic buffer allocation before Linux 2.1.121 (this applies also to demand-loading the driver with kerneld or kmod).

The driver does not specifically support any tape drive brand or model. After system start-up the tape device options are defined by the drive firmware. For example, if the drive firmware selects fixed-block mode, the tape device uses fixed-block mode. The options can be changed with explicit ioctl(2) calls and remain in effect when the device is closed and reopened. Setting the options affects both the auto-rewind and the nonrewind device.

Different options can be specified for the different devices within the subgroup of four. The options take effect when the device is opened. For example, the system administrator can define one device that writes in fixed-block mode with a certain block size, and one which writes in variable-block mode (if the drive supports both modes).

The driver supports tape partitions if they are supported by the drive. (Note that the tape partitions have nothing to do with disk partitions. A partitioned tape can be seen as several logical tapes within one medium.) Partition support has to be enabled with an ioctl(2). The tape location is preserved within each partition across partition changes. The partition used for subsequent tape operations is selected with an ioctl(2). The partition switch is executed together with the next tape operation in order to avoid unnecessary tape movement. The maximum number of partitions on a tape is defined by a compile-time constant (originally four). The driver contains an ioctl(2) that can format a tape with either one or two partitions.

Device /dev/tape is usually created as a hard or soft link to the default tape device on the system.

Starting from Linux 2.6.2, the driver exports in the sysfs directory /sys/class/scsi_tape the attached devices and some parameters assigned to the devices.

### Data transfer
The driver supports operation in both fixed-block mode and variable-block mode (if supported by the drive). In fixed-block mode the drive writes blocks of the specified size and the block size is not dependent on the byte counts of the write system calls. In variable-block mode one tape block is written for each write call and the byte count determines the size of the corresponding tape block. Note that the blocks on the tape don't contain any information about the writing mode: when reading, the only important thing is to use commands that accept the block sizes on the tape.

In variable-block mode the read byte count does not have to match the tape block size exactly. If the byte count is larger than the next block on tape, the driver returns the data and the function returns the actual block size. If the block size is larger than the byte count, an error is returned.

In fixed-block mode the read byte counts can be arbitrary if buffering is enabled, or a multiple of the tape block size if buffering is disabled. Before Linux 2.1.121 allow writes with arbitrary byte count if buffering is enabled. In all other cases (before Linux 2.1.121 with buffering disabled or newer kernel) the write byte count must be a multiple of the tape block size.

In Linux 2.6, the driver tries to use direct transfers between the user buffer and the device. If this is not possible, the driver's internal buffer is used. The reasons for not using direct transfers include improper alignment of the user buffer (default is 512 bytes but this can be changed by the HBA driver), one or more pages of the user buffer not reachable by the SCSI adapter, and so on.

A filemark is automatically written to tape if the last tape operation before close was a write.

When a filemark is encountered while reading, the following happens. If there are data remaining in the buffer when the filemark is found, the buffered data is returned. The next read returns zero bytes. The following read returns data from the next file. The end of recorded data is signaled by returning zero bytes for two consecutive read calls. The third read returns an error.

### Ioctls
The driver supports three ioctl(2) requests. Requests not recognized by the st driver are passed to the SCSI driver. The definitions below are from /usr/include/linux/mtio.h:

### MTIOCTOP — perform a tape operation
This request takes an argument of type (struct mtop *). Not all drives support all operations. The driver returns an EIO error if the drive rejects an operation.

```
/* Structure for MTIOCTOP - mag tape op command: */
struct mtop {

    short   mt_op;       /* operations defined below */

    int     mt_count;    /* how many of them */
};
```

Magnetic tape operations for normal tape use:

MTBSF

Backward space over mt_count filemarks.

MTBSFM

Backward space over mt_count filemarks. Reposition the tape to the EOT side of the last filemark.

MTBSR

Backward space over mt_count records (tape blocks).

MTBSS

Backward space over mt_count setmarks.

MTCOMPRESSION

Enable compression of tape data within the drive if mt_count is nonzero and disable compression if mt_count is zero. This command uses the MODE page 15 supported by most DATs.

MTEOM

Go to the end of the recorded media (for appending files).

MTERASE

Erase tape. With Linux 2.6, short erase (mark tape empty) is performed if the argument is zero. Otherwise, long erase (erase all) is done.

MTFSF

Forward space over mt_count filemarks.

MTFSFM

Forward space over mt_count filemarks. Reposition the tape to the BOT side of the last filemark.

MTFSR

Forward space over mt_count records (tape blocks).

MTFSS

Forward space over mt_count setmarks.

MTLOAD

Execute the SCSI load command. A special case is available for some HP autoloaders. If mt_count is the constant MT_ST_HPLOADER_OFFSET plus a number, the number is sent to the drive to control the autoloader.

MTLOCK

Lock the tape drive door.

MTMKPART

Format the tape into one or two partitions. If mt_count is positive, it gives the size of partition 1 and partition 0 contains the rest of the tape. If mt_count is zero, the tape is formatted into one partition. From Linux 4.6, a negative mt_count specifies the size of partition 0 and the rest of the tape contains partition 1. The physical ordering of partitions depends on the drive. This command is not allowed for a drive unless the partition support is enabled for the drive (see MT_ST_CAN_PARTITIONS below).

MTNOP

No op—flushes the driver's buffer as a side effect. Should be used before reading status with MTIOCGET.

MTOFFL

Rewind and put the drive off line.

MTRESET

Reset drive.

MTRETEN

Re-tension tape.

MTREW

Rewind.

MTSEEK

Seek to the tape block number specified in mt_count. This operation requires either a SCSI-2 drive that supports the LOCATE command (device-specific address) or a Tandberg-compatible SCSI-1 drive (Tandberg, Archive Viper, Wangtek, ...). The block number should be one that was previously returned by MTIOCPOS if device-specific addresses are used.

MTSETBLK

Set the drive's block length to the value specified in mt_count. A block length of zero sets the drive to variable block size mode.

MTSETDENSITY

Set the tape density to the code in mt_count. The density codes supported by a drive can be found from the drive documentation.

MTSETPART

The active partition is switched to mt_count. The partitions are numbered from zero. This command is not allowed for a drive unless the partition support is enabled for the drive (see MT_ST_CAN_PARTITIONS below).

MTUNLOAD

Execute the SCSI unload command (does not eject the tape).

MTUNLOCK

Unlock the tape drive door.

MTWEOF

Write mt_count filemarks.

MTWSM

Write mt_count setmarks.

Magnetic tape operations for setting of device options (by the superuser):

MTSETDRVBUFFER

Set various drive and driver options according to bits encoded in mt_count. These consist of the drive's buffering mode, a set of Boolean driver options, the buffer write threshold, defaults for the block size and density, and timeouts (only since Linux 2.1). A single operation can affect only one item in the list below (the Booleans counted as one item.)

A value having zeros in the high-order 4 bits will be used to set the drive's buffering mode. The buffering modes are:

0

The drive will not report GOOD status on write commands until the data blocks are actually written to the medium.

1

The drive may report GOOD status on write commands as soon as all the data has been transferred to the drive's internal buffer.

2

The drive may report GOOD status on write commands as soon as (a) all the data has been transferred to the drive's internal buffer, and (b) all buffered data from different initiators has been successfully written to the medium.

To control the write threshold the value in mt_count must include the constant MT_ST_WRITE_THRESHOLD bitwise ORed with a block count in the low 28 bits. The block count refers to 1024-byte blocks, not the physical block size on the tape. The threshold cannot exceed the driver's internal buffer size (see DESCRIPTION, above).

To set and clear the Boolean options the value in mt_count must include one of the constants MT_ST_BOOLEANS, MT_ST_SETBOOLEANS, MT_ST_CLEARBOOLEANS, or MT_ST_DEFBOOLEANS bitwise ORed with whatever combination of the following options is desired. Using MT_ST_BOOLEANS the options can be set to the values defined in the corresponding bits. With MT_ST_SETBOOLEANS the options can be selectively set and with MT_ST_DEFBOOLEANS selectively cleared.

The default options for a tape device are set with MT_ST_DEFBOOLEANS. A nonactive tape device (e.g., device with minor 32 or 160) is activated when the default options for it are defined the first time. An activated device inherits from the device activated at start-up the options not set explicitly.

The Boolean options are:

MT_ST_BUFFER_WRITES (Default: true)

Buffer all write operations in fixed-block mode. If this option is false and the drive uses a fixed block size, then all write operations must be for a multiple of the block size. This option must be set false to write reliable multivolume archives.

MT_ST_ASYNC_WRITES (Default: true)

When this option is true, write operations return immediately without waiting for the data to be transferred to the drive if the data fits into the driver's buffer. The write threshold determines how full the buffer must be before a new SCSI write command is issued. Any errors reported by the drive will be held until the next operation. This option must be set false to write reliable multivolume archives.

MT_ST_READ_AHEAD (Default: true)

This option causes the driver to provide read buffering and read-ahead in fixed-block mode. If this option is false and the drive uses a fixed block size, then all read operations must be for a multiple of the block size.

MT_ST_TWO_FM (Default: false)

This option modifies the driver behavior when a file is closed. The normal action is to write a single filemark. If the option is true, the driver will write two filemarks and backspace over the second one.

Note: This option should not be set true for QIC tape drives since they are unable to overwrite a filemark. These drives detect the end of recorded data by testing for blank tape rather than two consecutive filemarks. Most other current drives also detect the end of recorded data and using two filemarks is usually necessary only when interchanging tapes with some other systems.

MT_ST_DEBUGGING (Default: false)

This option turns on various debugging messages from the driver (effective only if the driver was compiled with DEBUG defined nonzero).

MT_ST_FAST_EOM (Default: false)

This option causes the MTEOM operation to be sent directly to the drive, potentially speeding up the operation but causing the driver to lose track of the current file number normally returned by the MTIOCGET request. If MT_ST_FAST_EOM is false, the driver will respond to an MTEOM request by forward spacing over files.

MT_ST_AUTO_LOCK (Default: false)

When this option is true, the drive door is locked when the device file is opened and unlocked when it is closed.

MT_ST_DEF_WRITES (Default: false)

The tape options (block size, mode, compression, etc.) may change when changing from one device linked to a drive to another device linked to the same drive depending on how the devices are defined. This option defines when the changes are enforced by the driver using SCSI-commands and when the drives auto-detection capabilities are relied upon. If this option is false, the driver sends the SCSI-commands immediately when the device is changed. If the option is true, the SCSI-commands are not sent until a write is requested. In this case, the drive firmware is allowed to detect the tape structure when reading and the SCSI-commands are used only to make sure that a tape is written according to the correct specification.

MT_ST_CAN_BSR (Default: false)

When read-ahead is used, the tape must sometimes be spaced backward to the correct position when the device is closed and the SCSI command to space backward over records is used for this purpose. Some older drives can't process this command reliably and this option can be used to instruct the driver not to use the command. The end result is that, with read-ahead and fixed-block mode, the tape may not be correctly positioned within a file when the device is closed. With Linux 2.6, the default is true for drives supporting SCSI-3.

MT_ST_NO_BLKLIMS (Default: false)

Some drives don't accept the READ BLOCK LIMITS SCSI command. If this is used, the driver does not use the command. The drawback is that the driver can't check before sending commands if the selected block size is acceptable to the drive.

MT_ST_CAN_PARTITIONS (Default: false)

This option enables support for several partitions within a tape. The option applies to all devices linked to a drive.

MT_ST_SCSI2LOGICAL (Default: false)

This option instructs the driver to use the logical block addresses defined in the SCSI-2 standard when performing the seek and tell operations (both with MTSEEK and MTIOCPOS commands and when changing tape partition). Otherwise, the device-specific addresses are used. It is highly advisable to set this option if the drive supports the logical addresses because they count also filemarks. There are some drives that support only the logical block addresses.

MT_ST_SYSV (Default: false)

When this option is enabled, the tape devices use the System V semantics. Otherwise, the BSD semantics are used. The most important difference between the semantics is what happens when a device used for reading is closed: in System V semantics the tape is spaced forward past the next filemark if this has not happened while using the device. In BSD semantics the tape position is not changed.

MT_NO_WAIT (Default: false)

Enables immediate mode (i.e., don't wait for the command to finish) for some commands (e.g., rewind).

An example:

```
struct mtop mt_cmd;
mt_cmd.mt_op = MTSETDRVBUFFER;
mt_cmd.mt_count = MT_ST_BOOLEANS |

        MT_ST_BUFFER_WRITES | MT_ST_ASYNC_WRITES;
ioctl(fd, MTIOCTOP, mt_cmd);
```

The default block size for a device can be set with MT_ST_DEF_BLKSIZE and the default density code can be set with MT_ST_DEFDENSITY. The values for the parameters are or'ed with the operation code.

With Linux 2.1.x and later, the timeout values can be set with the subcommand MT_ST_SET_TIMEOUT ORed with the timeout in seconds. The long timeout (used for rewinds and other commands that may take a long time) can be set with MT_ST_SET_LONG_TIMEOUT. The kernel defaults are very long to make sure that a successful command is not timed out with any drive. Because of this, the driver may seem stuck even if it is only waiting for the timeout. These commands can be used to set more practical values for a specific drive. The timeouts set for one device apply for all devices linked to the same drive.

Starting from Linux 2.4.19 and Linux 2.5.43, the driver supports a status bit which indicates whether the drive requests cleaning. The method used by the drive to return cleaning information is set using the MT_ST_SEL_CLN subcommand. If the value is zero, the cleaning bit is always zero. If the value is one, the TapeAlert data defined in the SCSI-3 standard is used (not yet implemented). Values 2–17 are reserved. If the lowest eight bits are >= 18, bits from the extended sense data are used. The bits 9–16 specify a mask to select the bits to look at and the bits 17–23 specify the bit pattern to look for. If the bit pattern is zero, one or more bits under the mask indicate the cleaning request. If the pattern is nonzero, the pattern must match the masked sense data byte.

### MTIOCGET — get status
This request takes an argument of type (struct mtget *).

```
/* structure for MTIOCGET - mag tape get status command */
struct mtget {

    long     mt_type;

    long     mt_resid;

    /* the following registers are device dependent */

    long     mt_dsreg;

    long     mt_gstat;

    long     mt_erreg;

    /* The next two fields are not always used */

    daddr_t  mt_fileno;

    daddr_t  mt_blkno;
};
```

mt_type

The header file defines many values for mt_type, but the current driver reports only the generic types MT_ISSCSI1 (Generic SCSI-1 tape) and MT_ISSCSI2 (Generic SCSI-2 tape).

mt_resid

contains the current tape partition number.

mt_dsreg

reports the drive's current settings for block size (in the low 24 bits) and density (in the high 8 bits). These fields are defined by MT_ST_BLKSIZE_SHIFT, MT_ST_BLKSIZE_MASK, MT_ST_DENSITY_SHIFT, and MT_ST_DENSITY_MASK.

mt_gstat

reports generic (device independent) status information. The header file defines macros for testing these status bits:

GMT_EOF(x)

The tape is positioned just after a filemark (always false after an MTSEEK operation).

GMT_BOT(x)

The tape is positioned at the beginning of the first file (always false after an MTSEEK operation).

GMT_EOT(x)

A tape operation has reached the physical End Of Tape.

GMT_SM(x)

The tape is currently positioned at a setmark (always false after an MTSEEK operation).

GMT_EOD(x)

The tape is positioned at the end of recorded data.

GMT_WR_PROT(x)

The drive is write-protected. For some drives this can also mean that the drive does not support writing on the current medium type.

GMT_ONLINE(x)

The last open(2) found the drive with a tape in place and ready for operation.

GMT_D_6250(x)

GMT_D_1600(x)

GMT_D_800(x)

This “generic” status information reports the current density setting for 9-track ½" tape drives only.

GMT_DR_OPEN(x)

The drive does not have a tape in place.

GMT_IM_REP_EN(x)

Immediate report mode. This bit is set if there are no guarantees that the data has been physically written to the tape when the write call returns. It is set zero only when the driver does not buffer data and the drive is set not to buffer data.

GMT_CLN(x)

The drive has requested cleaning. Implemented since Linux 2.4.19 and Linux 2.5.43.

mt_erreg

The only field defined in mt_erreg is the recovered error count in the low 16 bits (as defined by MT_ST_SOFTERR_SHIFT and MT_ST_SOFTERR_MASK). Due to inconsistencies in the way drives report recovered errors, this count is often not maintained (most drives do not by default report soft errors but this can be changed with a SCSI MODE SELECT command).

mt_fileno

reports the current file number (zero-based). This value is set to -1 when the file number is unknown (e.g., after MTBSS or MTSEEK).

mt_blkno

reports the block number (zero-based) within the current file. This value is set to -1 when the block number is unknown (e.g., after MTBSF, MTBSS, or MTSEEK).

### MTIOCPOS — get tape position
This request takes an argument of type (struct mtpos *) and reports the drive's notion of the current tape block number, which is not the same as mt_blkno returned by MTIOCGET. This drive must be a SCSI-2 drive that supports the READ POSITION command (device-specific address) or a Tandberg-compatible SCSI-1 drive (Tandberg, Archive Viper, Wangtek, ... ).

```
/* structure for MTIOCPOS - mag tape get position command */
struct mtpos {

    long mt_blkno;    /* current block number */
};
```

## RETURN VALUE
EACCES

An attempt was made to write or erase a write-protected tape. (This error is not detected during open(2).)

EBUSY

The device is already in use or the driver was unable to allocate a buffer.

EFAULT

The command parameters point to memory not belonging to the calling process.

EINVAL

An ioctl(2) had an invalid argument, or a requested block size was invalid.

EIO

The requested operation could not be completed.

ENOMEM

The byte count in read(2) is smaller than the next physical block on the tape. (Before Linux 2.2.18 and Linux 2.4.0 the extra bytes have been silently ignored.)

ENOSPC

A write operation could not be completed because the tape reached end-of-medium.

ENOSYS

Unknown ioctl(2).

ENXIO

During opening, the tape device does not exist.

EOVERFLOW

An attempt was made to read or write a variable-length block that is larger than the driver's internal buffer.

EROFS

Open is attempted with O_WRONLY or O_RDWR when the tape in the drive is write-protected.

## FILES
/dev/st*

the auto-rewind SCSI tape devices

/dev/nst*

the nonrewind SCSI tape devices

## NOTES
•

When exchanging data between systems, both systems have to agree on the physical tape block size. The parameters of a drive after startup are often not the ones most operating systems use with these devices. Most systems use drives in variable-block mode if the drive supports that mode. This applies to most modern drives, including DATs, 8mm helical scan drives, DLTs, etc. It may be advisable to use these drives in variable-block mode also in Linux (i.e., use MTSETBLK or MTSETDEFBLK at system startup to set the mode), at least when exchanging data with a foreign system. The drawback of this is that a fairly large tape block size has to be used to get acceptable data transfer rates on the SCSI bus.

•

Many programs (e.g., tar(1)) allow the user to specify the blocking factor on the command line. Note that this determines the physical block size on tape only in variable-block mode.

•

In order to use SCSI tape drives, the basic SCSI driver, a SCSI-adapter driver and the SCSI tape driver must be either configured into the kernel or loaded as modules. If the SCSI-tape driver is not present, the drive is recognized but the tape support described in this page is not available.

•

The driver writes error messages to the console/log. The SENSE codes written into some messages are automatically translated to text if verbose SCSI messages are enabled in kernel configuration.

•

The driver's internal buffering allows good throughput in fixed-block mode also with small read(2) and write(2) byte counts. With direct transfers this is not possible and may cause a surprise when moving to the 2.6 kernel. The solution is to tell the software to use larger transfers (often telling it to use larger blocks). If this is not possible, direct transfers can be disabled.

## SEE ALSO
mt(1)

The file drivers/scsi/README.st or Documentation/scsi/st.txt (kernel >= 2.6) in the Linux kernel source tree contains the most recent information about the driver and its configuration possibilities

branch: sisyphus


tty

title: tty(4)

summary: controlling terminal

text:
# tty(4)

## NAME
tty - controlling terminal

## DESCRIPTION
The file /dev/tty is a character file with major number 5 and minor number 0, usually with mode 0666 and ownership root:tty. It is a synonym for the controlling terminal of a process, if any.

In addition to the ioctl(2) requests supported by the device that tty refers to, the ioctl(2) request TIOCNOTTY is supported.

### TIOCNOTTY
Detach the calling process from its controlling terminal.

If the process is the session leader, then SIGHUP and SIGCONT signals are sent to the foreground process group and all processes in the current session lose their controlling tty.

This ioctl(2) call works only on file descriptors connected to /dev/tty. It is used by daemon processes when they are invoked by a user at a terminal. The process attempts to open /dev/tty. If the open succeeds, it detaches itself from the terminal by using TIOCNOTTY, while if the open fails, it is obviously not attached to a terminal and does not need to detach itself.

## FILES
/dev/tty

## SEE ALSO
chown(1), mknod(1), ioctl(2), ioctl_console(2), ioctl_tty(2), termios(3), ttyS(4), vcs(4), pty(7), agetty(8), mingetty(8)


ttyS

title: ttyS(4)

summary: serial terminal lines

text:
# ttyS(4)

## NAME
ttyS - serial terminal lines

## DESCRIPTION
ttyS[0-3] are character devices for the serial terminal lines.

They are typically created by:

```
mknod -m 660 /dev/ttyS0 c 4 64 # base address 0x3f8
mknod -m 660 /dev/ttyS1 c 4 65 # base address 0x2f8
mknod -m 660 /dev/ttyS2 c 4 66 # base address 0x3e8
mknod -m 660 /dev/ttyS3 c 4 67 # base address 0x2e8
chown root:tty /dev/ttyS[0-3]
```

## FILES
/dev/ttyS[0-3]

## SEE ALSO
chown(1), mknod(1), tty(4), agetty(8), mingetty(8), setserial(8)


vcs

title: vcs(4)

summary: virtual console memory

text:
# vcs(4)

## NAME
vcs, vcsa - virtual console memory

## DESCRIPTION
/dev/vcs0 is a character device with major number 7 and minor number 0, usually with mode 0644 and ownership root:tty. It refers to the memory of the currently displayed virtual console terminal.

/dev/vcs[1-63] are character devices for virtual console terminals, they have major number 7 and minor number 1 to 63, usually mode 0644 and ownership root:tty. /dev/vcsa[0-63] are the same, but using unsigned shorts (in host byte order) that include attributes, and prefixed with four bytes giving the screen dimensions and cursor position: lines, columns, x, y. (x = y = 0 at the top left corner of the screen.)

When a 512-character font is loaded, the 9th bit position can be fetched by applying the ioctl(2) VT_GETHIFONTMASK operation (available since Linux 2.6.18) on /dev/tty[1-63]; the value is returned in the unsigned short pointed to by the third ioctl(2) argument.

These devices replace the screendump ioctl(2) operations of ioctl_console(2), so the system administrator can control access using filesystem permissions.

The devices for the first eight virtual consoles may be created by:

```
for x in 0 1 2 3 4 5 6 7 8; do

    mknod -m 644 /dev/vcs$x c 7 $x;

    mknod -m 644 /dev/vcsa$x c 7 $[$x+128];
done
chown root:tty /dev/vcs*
```

No ioctl(2) requests are supported.

## FILES
/dev/vcs[0-63]

/dev/vcsa[0-63]

## VERSIONS
Introduced with Linux 1.1.92.

## EXAMPLES
You may do a screendump on vt3 by switching to vt1 and typing

```
cat /dev/vcs3 >foo
```

Note that the output does not contain newline characters, so some processing may be required, like in

```
fold -w 81 /dev/vcs3 | lpr
```

or (horrors)

```
setterm -dump 3 -file /proc/self/fd/1
```

The /dev/vcsa0 device is used for Braille support.

This program displays the character and screen attributes under the cursor of the second virtual console, then changes the background color there:

```
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/vt.h>
int
main(void)
{

    int fd;

    char *device = "/dev/vcsa2";

    char *console = "/dev/tty2";

    struct {unsigned char lines, cols, x, y;} scrn;

    unsigned short s;

    unsigned short mask;

    unsigned char attrib;

    int ch;

    fd = open(console, O_RDWR);

    if (fd < 0) {

        perror(console);

        exit(EXIT_FAILURE);

    }

    if (ioctl(fd, VT_GETHIFONTMASK, &mask) < 0) {

        perror("VT_GETHIFONTMASK");

        exit(EXIT_FAILURE);

    }

    (void) close(fd);

    fd = open(device, O_RDWR);

    if (fd < 0) {

        perror(device);

        exit(EXIT_FAILURE);

    }

    (void) read(fd, &scrn, 4);

    (void) lseek(fd, 4 + 2*(scrn.y*scrn.cols + scrn.x), SEEK_SET);

    (void) read(fd, &s, 2);

    ch = s & 0xff;

    if (s & mask)

        ch |= 0x100;

    attrib = ((s & ~mask) >> 8);

    printf("ch=%#03x attrib=%#02x\n", ch, attrib);

    s ^= 0x1000;

    (void) lseek(fd, -2, SEEK_CUR);

    (void) write(fd, &s, 2);

    exit(EXIT_SUCCESS);
}
```

## SEE ALSO
ioctl_console(2), tty(4), ttyS(4), gpm(8)


veth

title: veth(4)

summary: Virtual Ethernet Device

text:
# veth(4)

## NAME
veth - Virtual Ethernet Device

## DESCRIPTION
The veth devices are virtual Ethernet devices. They can act as tunnels between network namespaces to create a bridge to a physical network device in another namespace, but can also be used as standalone network devices.

veth devices are always created in interconnected pairs. A pair can be created using the command:

```
# ip link add <p1-name> type veth peer name <p2-name>
```

In the above, p1-name and p2-name are the names assigned to the two connected end points.

Packets transmitted on one device in the pair are immediately received on the other device. When either device is down, the link state of the pair is down.

veth device pairs are useful for combining the network facilities of the kernel together in interesting ways. A particularly interesting use case is to place one end of a veth pair in one network namespace and the other end in another network namespace, thus allowing communication between network namespaces. To do this, one can provide the netns parameter when creating the interfaces:

```
# ip link add <p1-name> netns <p1-ns> type veth peer <p2-name> netns <p2-ns>
```

or, for an existing veth pair, move one side to the other namespace:

```
# ip link set <p2-name> netns <p2-ns>
```

ethtool(8) can be used to find the peer of a veth network interface, using commands something like:

```
# ip link add ve_A type veth peer name ve_B   # Create veth pair
# ethtool -S ve_A         # Discover interface index of peer
NIC statistics:

     peer_ifindex: 16
# ip link | grep '^16:'   # Look up interface
16: ve_B@ve_A: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc ...
```

## SEE ALSO
clone(2), network_namespaces(7), ip(8), ip-link(8), ip-netns(8)


wavelan

title: wavelan(4)

summary: AT&T GIS WaveLAN ISA device driver

text:
# wavelan(4)

## NAME
wavelan - AT&T GIS WaveLAN ISA device driver

## SYNOPSIS

```
insmod wavelan_cs.o [io=B,B..] [ irq=I,I..] [name=N,N..]
```

## DESCRIPTION
This driver is obsolete: it was removed in Linux 2.6.35.

wavelan is the low-level device driver for the NCR / AT&T / Lucent WaveLAN ISA and Digital (DEC) RoamAbout DS wireless ethernet adapter. This driver is available as a module or might be compiled in the kernel. This driver supports multiple cards in both forms (up to 4) and allocates the next available ethernet device (eth0..eth#) for each card found, unless a device name is explicitly specified (see below). This device name will be reported in the kernel log file with the MAC address, NWID, and frequency used by the card.

### Parameters
This section applies to the module form (parameters passed on the insmod(8) command line). If the driver is included in the kernel, use the ether=IRQ,IO,NAME syntax on the kernel command line.

io

Specify the list of base addresses where to search for wavelan cards (setting by dip switch on the card). If you don't specify any io address, the driver will scan 0x390 and 0x3E0 addresses, which might conflict with other hardware...

irq

Set the list of IRQs that each wavelan card should use (the value is saved in permanent storage for future use).

name

Set the list of names to be used for each wavelan card device (name used by ifconfig(8)).

### Wireless extensions
Use iwconfig(8) to manipulate wireless extensions.

### NWID (or domain)
Set the network ID [0 to FFFF] or disable it [off]. As the NWID is stored in the card Permanent Storage Area, it will be reused at any further invocation of the driver.

### Frequency & channels
For the 2.4 GHz 2.00 Hardware, you are able to set the frequency by specifying one of the 10 defined channels (2.412, 2.422, 2.425, 2.4305, 2.432, 2.442, 2.452, 2.460, 2.462 or 2.484) or directly as a numeric value. The frequency is changed immediately and permanently. Frequency availability depends on the regulations...

### Statistics spy
Set a list of MAC addresses in the driver (up to 8) and get the last quality of link for each of those (see iwspy(8)).

### /proc/net/wireless
status is the status reported by the modem. Link quality reports the quality of the modulation on the air (direct sequence spread spectrum) [max = 16]. Level and Noise refer to the signal level and noise level [max = 64]. The crypt discarded packet and misc discarded packet counters are not implemented.

### Private ioctl
You may use iwpriv(8) to manipulate private ioctls.

### Quality and level threshold
Enables you to define the quality and level threshold used by the modem (packet below that level are discarded).

### Histogram
This functionality makes it possible to set a number of signal level intervals and to count the number of packets received in each of those defined intervals. This distribution might be used to calculate the mean value and standard deviation of the signal level.

### Specific notes
This driver fails to detect some non-NCR/AT&T/Lucent Wavelan cards. If this happens for you, you must look in the source code on how to add your card to the detection routine.

Some of the mentioned features are optional. You may enable or disable them by changing flags in the driver header and recompile.

## SEE ALSO
wavelan_cs(4), ifconfig(8), insmod(8), iwconfig(8), iwpriv(8), iwspy(8)


md

package: mdadm-tool

title: md(4)

text:
# md(4)

## NAME
md - Multiple Device driver aka Linux Software RAID

## SYNOPSIS
/dev/mdn

/dev/md/n

/dev/md/name

## DESCRIPTION
The md driver provides virtual devices that are created from one or more independent underlying devices. This array of devices often contains redundancy and the devices are often disk drives, hence the acronym RAID which stands for a Redundant Array of Independent Disks.

md supports RAID levels 1 (mirroring), 4 (striped array with parity device), 5 (striped array with distributed parity information), 6 (striped array with distributed dual redundancy information), and 10 (striped and mirrored). If some number of underlying devices fails while using one of these levels, the array will continue to function; this number is one for RAID levels 4 and 5, two for RAID level 6, and all but one (N-1) for RAID level 1, and dependent on configuration for level 10.

md also supports a number of pseudo RAID (non-redundant) configurations including RAID0 (striped array), LINEAR (catenated array), MULTIPATH (a set of different interfaces to the same device), and FAULTY (a layer over a single device into which errors can be injected).

### MD METADATA
Each device in an array may have some metadata stored in the device. This metadata is sometimes called a superblock. The metadata records information about the structure and state of the array. This allows the array to be reliably re-assembled after a shutdown.

md provides support for two different formats of metadata, and other formats can be added.

The common format — known as version 0.90 — has a superblock that is 4K long and is written into a 64K aligned block that starts at least 64K and less than 128K from the end of the device (i.e. to get the address of the superblock round the size of the device down to a multiple of 64K and then subtract 64K). The available size of each device is the amount of space before the super block, so between 64K and 128K is lost when a device in incorporated into an MD array. This superblock stores multi-byte fields in a processor-dependent manner, so arrays cannot easily be moved between computers with different processors.

The new format — known as version 1 — has a superblock that is normally 1K long, but can be longer. It is normally stored between 8K and 12K from the end of the device, on a 4K boundary, though variations can be stored at the start of the device (version 1.1) or 4K from the start of the device (version 1.2). This metadata format stores multibyte data in a processor-independent format and supports up to hundreds of component devices (version 0.90 only supports 28).

The metadata contains, among other things:

LEVEL

The manner in which the devices are arranged into the array (LINEAR, RAID0, RAID1, RAID4, RAID5, RAID10, MULTIPATH).

UUID

a 128 bit Universally Unique Identifier that identifies the array that contains this device.

When a version 0.90 array is being reshaped (e.g. adding extra devices to a RAID5), the version number is temporarily set to 0.91. This ensures that if the reshape process is stopped in the middle (e.g. by a system crash) and the machine boots into an older kernel that does not support reshaping, then the array will not be assembled (which would cause data corruption) but will be left untouched until a kernel that can complete the reshape processes is used.

### ARRAYS WITHOUT METADATA
While it is usually best to create arrays with superblocks so that they can be assembled reliably, there are some circumstances when an array without superblocks is preferred. These include:

LEGACY ARRAYS

Early versions of the md driver only supported LINEAR and RAID0 configurations and did not use a superblock (which is less critical with these configurations). While such arrays should be rebuilt with superblocks if possible, md continues to support them.

FAULTY

Being a largely transparent layer over a different device, the FAULTY personality doesn't gain anything from having a superblock.

MULTIPATH

It is often possible to detect devices which are different paths to the same storage directly rather than having a distinctive superblock written to the device and searched for on all paths. In this case, a MULTIPATH array with no superblock makes sense.

RAID1

In some configurations it might be desired to create a RAID1 configuration that does not use a superblock, and to maintain the state of the array elsewhere. While not encouraged for general use, it does have special-purpose uses and is supported.

### ARRAYS WITH EXTERNAL METADATA
md driver supports arrays with externally managed metadata. That is, the metadata is not managed by the kernel but rather by a user-space program which is external to the kernel. This allows support for a variety of metadata formats without cluttering the kernel with lots of details.

md is able to communicate with the user-space program through various sysfs attributes so that it can make appropriate changes to the metadata - for example to mark a device as faulty. When necessary, md will wait for the program to acknowledge the event by writing to a sysfs attribute. The manual page for mdmon(8) contains more detail about this interaction.

### CONTAINERS
Many metadata formats use a single block of metadata to describe a number of different arrays which all use the same set of devices. In this case it is helpful for the kernel to know about the full set of devices as a whole. This set is known to md as a container. A container is an md array with externally managed metadata and with device offset and size so that it just covers the metadata part of the devices. The remainder of each device is available to be incorporated into various arrays.

### LINEAR
A LINEAR array simply catenates the available space on each drive to form one large virtual drive.

One advantage of this arrangement over the more common RAID0 arrangement is that the array may be reconfigured at a later time with an extra drive, so the array is made bigger without disturbing the data that is on the array. This can even be done on a live array.

If a chunksize is given with a LINEAR array, the usable space on each device is rounded down to a multiple of this chunksize.

### RAID0
A RAID0 array (which has zero redundancy) is also known as a striped array. A RAID0 array is configured at creation with a Chunk Size which must be at least 4 kibibytes.

The RAID0 driver assigns the first chunk of the array to the first device, the second chunk to the second device, and so on until all drives have been assigned one chunk. This collection of chunks forms a stripe. Further chunks are gathered into stripes in the same way, and are assigned to the remaining space in the drives.

If devices in the array are not all the same size, then once the smallest device has been exhausted, the RAID0 driver starts collecting chunks into smaller stripes that only span the drives which still have remaining space.

A bug was introduced in linux 3.14 which changed the layout of blocks in a RAID0 beyond the region that is striped over all devices. This bug does not affect an array with all devices the same size, but can affect other RAID0 arrays.

Linux 5.4 (and some stable kernels to which the change was backported) will not normally assemble such an array as it cannot know which layout to use. There is a module parameter "raid0.default_layout" which can be set to "1" to force the kernel to use the pre-3.14 layout or to "2" to force it to use the 3.14-and-later layout. when creating a new RAID0 array, mdadm will record the chosen layout in the metadata in a way that allows newer kernels to assemble the array without needing a module parameter.

To assemble an old array on a new kernel without using the module parameter, use either the --update=layout-original option or the --update=layout-alternate option.

Once you have updated the layout you will not be able to mount the array on an older kernel. If you need to revert to an older kernel, the layout information can be erased with the --update=layout-unspecificed option. If you use this option to --assemble while running a newer kernel, the array will NOT assemble, but the metadata will be update so that it can be assembled on an older kernel.

Note that setting the layout to "unspecified" removes protections against this bug, and you must be sure that the kernel you use matches the layout of the array.

### RAID1
A RAID1 array is also known as a mirrored set (though mirrors tend to provide reflected images, which RAID1 does not) or a plex.

Once initialised, each device in a RAID1 array contains exactly the same data. Changes are written to all devices in parallel. Data is read from any one device. The driver attempts to distribute read requests across all devices to maximise performance.

All devices in a RAID1 array should be the same size. If they are not, then only the amount of space available on the smallest device is used (any extra space on other devices is wasted).

Note that the read balancing done by the driver does not make the RAID1 performance profile be the same as for RAID0; a single stream of sequential input will not be accelerated (e.g. a single dd), but multiple sequential streams or a random workload will use more than one spindle. In theory, having an N-disk RAID1 will allow N sequential threads to read from all disks.

Individual devices in a RAID1 can be marked as "write-mostly". These drives are excluded from the normal read balancing and will only be read from when there is no other option. This can be useful for devices connected over a slow link.

### RAID4
A RAID4 array is like a RAID0 array with an extra device for storing parity. This device is the last of the active devices in the array. Unlike RAID0, RAID4 also requires that all stripes span all drives, so extra space on devices that are larger than the smallest is wasted.

When any block in a RAID4 array is modified, the parity block for that stripe (i.e. the block in the parity device at the same device offset as the stripe) is also modified so that the parity block always contains the "parity" for the whole stripe. I.e. its content is equivalent to the result of performing an exclusive-or operation between all the data blocks in the stripe.

This allows the array to continue to function if one device fails. The data that was on that device can be calculated as needed from the parity block and the other data blocks.

### RAID5
RAID5 is very similar to RAID4. The difference is that the parity blocks for each stripe, instead of being on a single device, are distributed across all devices. This allows more parallelism when writing, as two different block updates will quite possibly affect parity blocks on different devices so there is less contention.

This also allows more parallelism when reading, as read requests are distributed over all the devices in the array instead of all but one.

### RAID6
RAID6 is similar to RAID5, but can handle the loss of any two devices without data loss. Accordingly, it requires N+2 drives to store N drives worth of data.

The performance for RAID6 is slightly lower but comparable to RAID5 in normal mode and single disk failure mode. It is very slow in dual disk failure mode, however.

### RAID10
RAID10 provides a combination of RAID1 and RAID0, and is sometimes known as RAID1+0. Every datablock is duplicated some number of times, and the resulting collection of datablocks are distributed over multiple drives.

When configuring a RAID10 array, it is necessary to specify the number of replicas of each data block that are required (this will usually be 2) and whether their layout should be "near", "far" or "offset".

About the RAID10 Layout Examples:

The examples below visualise the chunk distribution on the underlying devices for the respective layout.

For simplicity it is assumed that the size of the chunks equals the size of the blocks of the underlying devices as well as those of the RAID10 device exported by the kernel (for example /dev/md/name).

Therefore the chunks / chunk numbers map directly to the blocks /block addresses of the exported RAID10 device.

Decimal numbers (0, 1, 2, ...) are the chunks of the RAID10 and due to the above assumption also the blocks and block addresses of the exported RAID10 device.

Repeated numbers mean copies of a chunk / block (obviously on different underlying devices).

Hexadecimal numbers (0x00, 0x01, 0x02, ...) are the block addresses of the underlying devices.

"near" Layout

When "near" replicas are chosen, the multiple copies of a given chunk are laid out consecutively ("as close to each other as possible") across the stripes of the array. With an even number of devices, they will likely (unless some misalignment is present) lay at the very same offset on the different devices.

This is as the "classic" RAID1+0; that is two groups of mirrored devices (in the example below the groups Device #1 / #2 and Device #3 / #4 are each a RAID1) both in turn forming a striped RAID0.

Example with 2 copies per chunk and an even number (4) of devices:

Device #1

Device #2

Device #3

Device #4

0x00

0

0

1

1

0x01

2

2

3

3

:

:

:

:

:

0x80

254

254

255

255

\---------v---------/

\---------v---------/

RAID1

RAID1

\---------------------v---------------------/

RAID0

Example with 2 copies per chunk and an odd number (5) of devices:

Dev #1

Dev #2

Dev #3

Dev #4

Dev #5

0x00

0

0

1

1

2

0x01

2

3

3

4

4

:

:

:

:

:

:

0x80

317

318

318

319

319

"far" Layout

When "far" replicas are chosen, the multiple copies of a given chunk are laid out quite distant ("as far as reasonably possible") from each other. First a complete sequence of all data blocks (that is all the data one sees on the exported RAID10 block device) is striped over the devices. Then another (though "shifted") complete sequence of all data blocks; and so on (in the case of more than 2 copies per chunk).

The "shift" needed to prevent placing copies of the same chunks on the same devices is actually a cyclic permutation with offset 1 of each of the stripes within a complete sequence of chunks.

The offset 1 is relative to the previous complete sequence of chunks, so in case of more than 2 copies per chunk one gets the following offsets:

1. complete sequence of chunks: offset = 0

2. complete sequence of chunks: offset = 1

3. complete sequence of chunks: offset = 2

:

n. complete sequence of chunks: offset = n-1

Example with 2 copies per chunk and an even number (4) of devices:

Device #1

Device #2

Device #3

Device #4

0x00

0

1

2

3

\

0x01

4

5

6

7

> [#]

:

:

:

:

:

:

0x40

252

253

254

255

/

0x41

3

0

1

2

\

0x42

7

4

5

6

> [#]~

:

:

:

:

:

:

0x80

255

252

253

254

/

Example with 2 copies per chunk and an odd number (5) of devices:

Dev #1

Dev #2

Dev #3

Dev #4

Dev #5

0x00

0

1

2

3

4

\

0x01

5

6

7

8

9

> [#]

:

:

:

:

:

:

:

0x40

315

316

317

318

319

/

0x41

4

0

1

2

3

\

0x42

9

5

6

7

8

> [#]~

:

:

:

:

:

:

:

0x80

319

315

316

317

318

/

With [#] being the complete sequence of chunks and [#]~ the cyclic permutation with offset 1 thereof (in the case of more than 2 copies per chunk there would be ([#]~)~, (([#]~)~)~, ...).

The advantage of this layout is that MD can easily spread sequential reads over the devices, making them similar to RAID0 in terms of speed.

The cost is more seeking for writes, making them substantially slower.

"offset" Layout

When "offset" replicas are chosen, all the copies of a given chunk are striped consecutively ("offset by the stripe length after each other") over the devices. Explained in detail, <number of devices> consecutive chunks are striped over the devices, immediately followed by a "shifted" copy of these chunks (and by further such "shifted" copies in the case of more than 2 copies per chunk).

This pattern repeats for all further consecutive chunks of the exported RAID10 device (in other words: all further data blocks).

The "shift" needed to prevent placing copies of the same chunks on the same devices is actually a cyclic permutation with offset 1 of each of the striped copies of <number of devices> consecutive chunks.

The offset 1 is relative to the previous striped copy of <number of devices> consecutive chunks, so in case of more than 2 copies per chunk one gets the following offsets:

1. <number of devices> consecutive chunks: offset = 0

2. <number of devices> consecutive chunks: offset = 1

3. <number of devices> consecutive chunks: offset = 2

:

n. <number of devices> consecutive chunks: offset = n-1

Example with 2 copies per chunk and an even number (4) of devices:

Device #1

Device #2

Device #3

Device #4

0x00

0

1

2

3

) AA

0x01

3

0

1

2

) AA~

0x02

4

5

6

7

) AB

0x03

7

4

5

6

) AB~

:

:

:

:

:

:

0x79

251

252

253

254

) EX

0x80

254

251

252

253

) EX~

Example with 2 copies per chunk and an odd number (5) of devices:

Dev #1

Dev #2

Dev #3

Dev #4

Dev #5

0x00

0

1

2

3

4

) AA

0x01

4

0

1

2

3

) AA~

0x02

5

6

7

8

9

) AB

0x03

9

5

6

7

8

) AB~

:

:

:

:

:

:

:

0x79

314

315

316

317

318

) EX

0x80

318

314

315

316

317

) EX~

With AA, AB, ..., AZ, BA, ... being the sets of <number of devices> consecutive chunks and AA~, AB~, ..., AZ~, BA~, ... the cyclic permutations with offset 1 thereof (in the case of more than 2 copies per chunk there would be (AA~)~, ... as well as ((AA~)~)~, ... and so on).

This should give similar read characteristics to "far" if a suitably large chunk size is used, but without as much seeking for writes.

It should be noted that the number of devices in a RAID10 array need not be a multiple of the number of replica of each data block; however, there must be at least as many devices as replicas.

If, for example, an array is created with 5 devices and 2 replicas, then space equivalent to 2.5 of the devices will be available, and every block will be stored on two different devices.

Finally, it is possible to have an array with both "near" and "far" copies. If an array is configured with 2 near copies and 2 far copies, then there will be a total of 4 copies of each block, each on a different drive. This is an artifact of the implementation and is unlikely to be of real value.

### MULTIPATH
MULTIPATH is not really a RAID at all as there is only one real device in a MULTIPATH md array. However there are multiple access points (paths) to this device, and one of these paths might fail, so there are some similarities.

A MULTIPATH array is composed of a number of logically different devices, often fibre channel interfaces, that all refer the the same real device. If one of these interfaces fails (e.g. due to cable problems), the MULTIPATH driver will attempt to redirect requests to another interface.

The MULTIPATH drive is not receiving any ongoing development and should be considered a legacy driver. The device-mapper based multipath drivers should be preferred for new installations.

### FAULTY
The FAULTY md module is provided for testing purposes. A FAULTY array has exactly one component device and is normally assembled without a superblock, so the md array created provides direct access to all of the data in the component device.

The FAULTY module may be requested to simulate faults to allow testing of other md levels or of filesystems. Faults can be chosen to trigger on read requests or write requests, and can be transient (a subsequent read/write at the address will probably succeed) or persistent (subsequent read/write of the same address will fail). Further, read faults can be "fixable" meaning that they persist until a write request at the same address.

Fault types can be requested with a period. In this case, the fault will recur repeatedly after the given number of requests of the relevant type. For example if persistent read faults have a period of 100, then every 100th read request would generate a fault, and the faulty sector would be recorded so that subsequent reads on that sector would also fail.

There is a limit to the number of faulty sectors that are remembered. Faults generated after this limit is exhausted are treated as transient.

The list of faulty sectors can be flushed, and the active list of failure modes can be cleared.

### UNCLEAN SHUTDOWN
When changes are made to a RAID1, RAID4, RAID5, RAID6, or RAID10 array there is a possibility of inconsistency for short periods of time as each update requires at least two block to be written to different devices, and these writes probably won't happen at exactly the same time. Thus if a system with one of these arrays is shutdown in the middle of a write operation (e.g. due to power failure), the array may not be consistent.

To handle this situation, the md driver marks an array as "dirty" before writing any data to it, and marks it as "clean" when the array is being disabled, e.g. at shutdown. If the md driver finds an array to be dirty at startup, it proceeds to correct any possibly inconsistency. For RAID1, this involves copying the contents of the first drive onto all other drives. For RAID4, RAID5 and RAID6 this involves recalculating the parity for each stripe and making sure that the parity block has the correct data. For RAID10 it involves copying one of the replicas of each block onto all the others. This process, known as "resynchronising" or "resync" is performed in the background. The array can still be used, though possibly with reduced performance.

If a RAID4, RAID5 or RAID6 array is degraded (missing at least one drive, two for RAID6) when it is restarted after an unclean shutdown, it cannot recalculate parity, and so it is possible that data might be undetectably corrupted. The md driver will fail to start an array in this condition without manual intervention, though this behaviour can be overridden by a kernel parameter.

### RECOVERY
If the md driver detects a write error on a device in a RAID1, RAID4, RAID5, RAID6, or RAID10 array, it immediately disables that device (marking it as faulty) and continues operation on the remaining devices. If there are spare drives, the driver will start recreating on one of the spare drives the data which was on that failed drive, either by copying a working drive in a RAID1 configuration, or by doing calculations with the parity block on RAID4, RAID5 or RAID6, or by finding and copying originals for RAID10.

A read-error will cause md to attempt a recovery by overwriting the bad block. i.e. it will find the correct data from elsewhere, write it over the block that failed, and then try to read it back again. If either the write or the re-read fail, md will treat the error the same way that a write error is treated, and will fail the whole device.

While this recovery process is happening, the md driver will monitor accesses to the array and will slow down the rate of recovery if other activity is happening, so that normal access to the array will not be unduly affected. When no other activity is happening, the recovery process proceeds at full speed. The actual speed targets for the two different situations can be controlled by the speed_limit_min and speed_limit_max control files mentioned below.

### SCRUBBING AND MISMATCHES
As storage devices can develop bad blocks at any time it is valuable to regularly read all blocks on all devices in an array so as to catch such bad blocks early. This process is called scrubbing.

md arrays can be scrubbed by writing either check or repair to the file md/sync_action in the sysfs directory for the device.

Requesting a scrub will cause md to read every block on every device in the array, and check that the data is consistent. For RAID1 and RAID10, this means checking that the copies are identical. For RAID4, RAID5, RAID6 this means checking that the parity block is (or blocks are) correct.

If a read error is detected during this process, the normal read-error handling causes correct data to be found from other devices and to be written back to the faulty device. In many case this will effectively fix the bad block.

If all blocks read successfully but are found to not be consistent, then this is regarded as a mismatch.

If check was used, then no action is taken to handle the mismatch, it is simply recorded. If repair was used, then a mismatch will be repaired in the same way that resync repairs arrays. For RAID5/RAID6 new parity blocks are written. For RAID1/RAID10, all but one block are overwritten with the content of that one block.

A count of mismatches is recorded in the sysfs file md/mismatch_cnt. This is set to zero when a scrub starts and is incremented whenever a sector is found that is a mismatch. md normally works in units much larger than a single sector and when it finds a mismatch, it does not determine exactly how many actual sectors were affected but simply adds the number of sectors in the IO unit that was used. So a value of 128 could simply mean that a single 64KB check found an error (128 x 512bytes = 64KB).

If an array is created by mdadm with --assume-clean then a subsequent check could be expected to find some mismatches.

On a truly clean RAID5 or RAID6 array, any mismatches should indicate a hardware problem at some level - software issues should never cause such a mismatch.

However on RAID1 and RAID10 it is possible for software issues to cause a mismatch to be reported. This does not necessarily mean that the data on the array is corrupted. It could simply be that the system does not care what is stored on that part of the array - it is unused space.

The most likely cause for an unexpected mismatch on RAID1 or RAID10 occurs if a swap partition or swap file is stored on the array.

When the swap subsystem wants to write a page of memory out, it flags the page as 'clean' in the memory manager and requests the swap device to write it out. It is quite possible that the memory will be changed while the write-out is happening. In that case the 'clean' flag will be found to be clear when the write completes and so the swap subsystem will simply forget that the swapout had been attempted, and will possibly choose a different page to write out.

If the swap device was on RAID1 (or RAID10), then the data is sent from memory to a device twice (or more depending on the number of devices in the array). Thus it is possible that the memory gets changed between the times it is sent, so different data can be written to the different devices in the array. This will be detected by check as a mismatch. However it does not reflect any corruption as the block where this mismatch occurs is being treated by the swap system as being empty, and the data will never be read from that block.

It is conceivable for a similar situation to occur on non-swap files, though it is less likely.

Thus the mismatch_cnt value can not be interpreted very reliably on RAID1 or RAID10, especially when the device is used for swap.

### BITMAP WRITE-INTENT LOGGING
md supports a bitmap based write-intent log. If configured, the bitmap is used to record which blocks of the array may be out of sync. Before any write request is honoured, md will make sure that the corresponding bit in the log is set. After a period of time with no writes to an area of the array, the corresponding bit will be cleared.

This bitmap is used for two optimisations.

Firstly, after an unclean shutdown, the resync process will consult the bitmap and only resync those blocks that correspond to bits in the bitmap that are set. This can dramatically reduce resync time.

Secondly, when a drive fails and is removed from the array, md stops clearing bits in the intent log. If that same drive is re-added to the array, md will notice and will only recover the sections of the drive that are covered by bits in the intent log that are set. This can allow a device to be temporarily removed and reinserted without causing an enormous recovery cost.

The intent log can be stored in a file on a separate device, or it can be stored near the superblocks of an array which has superblocks.

It is possible to add an intent log to an active array, or remove an intent log if one is present.

All raid levels with redundancy are supported.

### BAD BLOCK LIST
Each device in an md array can store a list of known-bad-blocks. This list is 4K in size and usually positioned at the end of the space between the superblock and the data.

When a block cannot be read and cannot be repaired by writing data recovered from other devices, the address of the block is stored in the bad block list. Similarly if an attempt to write a block fails, the address will be recorded as a bad block. If attempting to record the bad block fails, the whole device will be marked faulty.

Attempting to read from a known bad block will cause a read error. Attempting to write to a known bad block will be ignored if any write errors have been reported by the device. If there have been no write errors then the data will be written to the known bad block and if that succeeds, the address will be removed from the list.

This allows an array to fail more gracefully - a few blocks on different devices can be faulty without taking the whole array out of action.

The list is particularly useful when recovering to a spare. If a few blocks cannot be read from the other devices, the bulk of the recovery can complete and those few bad blocks will be recorded in the bad block list.

### RAID WRITE HOLE
Due to non-atomicity nature of RAID write operations, interruption of write operations (system crash, etc.) to RAID456 array can lead to inconsistent parity and data loss (so called RAID-5 write hole). To plug the write hole md supports two mechanisms described below.

DIRTY STRIPE JOURNAL

From Linux 4.4, md supports write ahead journal for RAID456. When the array is created, an additional journal device can be added to the array through write-journal option. The RAID write journal works similar to file system journals. Before writing to the data disks, md persists data AND parity of the stripe to the journal device. After crashes, md searches the journal device for incomplete write operations, and replay them to the data disks. When the journal device fails, the RAID array is forced to run in read-only mode.

PARTIAL PARITY LOG

From Linux 4.12 md supports Partial Parity Log (PPL) for RAID5 arrays only. Partial parity for a write operation is the XOR of stripe data chunks not modified by the write. PPL is stored in the metadata region of RAID member drives, no additional journal drive is needed. After crashes, if one of the not modified data disks of the stripe is missing, this updated parity can be used to recover its data. See Documentation/driver-api/md/raid5-ppl.rst for implementation details.

### WRITE-BEHIND
This allows certain devices in the array to be flagged as write-mostly. MD will only read from such devices if there is no other option.

If a write-intent bitmap is also provided, write requests to write-mostly devices will be treated as write-behind requests and md will not wait for writes to those requests to complete before reporting the write as complete to the filesystem.

This allows for a RAID1 with WRITE-BEHIND to be used to mirror data over a slow link to a remote computer (providing the link isn't too slow). The extra latency of the remote link will not slow down normal operations, but the remote system will still have a reasonably up-to-date copy of all data.

### FAILFAST
From Linux 4.10, md supports FAILFAST for RAID1 and RAID10 arrays. This is a flag that can be set on individual drives, though it is usually set on all drives, or no drives.

When md sends an I/O request to a drive that is marked as FAILFAST, and when the array could survive the loss of that drive without losing data, md will request that the underlying device does not perform any retries. This means that a failure will be reported to md promptly, and it can mark the device as faulty and continue using the other device(s). md cannot control the timeout that the underlying devices use to determine failure. Any changes desired to that timeout must be set explictly on the underlying device, separately from using mdadm.

If a FAILFAST request does fail, and if it is still safe to mark the device as faulty without data loss, that will be done and the array will continue functioning on a reduced number of devices. If it is not possible to safely mark the device as faulty, md will retry the request without disabling retries in the underlying device. In any case, md will not attempt to repair read errors on a device marked as FAILFAST by writing out the correct. It will just mark the device as faulty.

FAILFAST is appropriate for storage arrays that have a low probability of true failure, but will sometimes introduce unacceptable delays to I/O requests while performing internal maintenance. The value of setting FAILFAST involves a trade-off. The gain is that the chance of unacceptable delays is substantially reduced. The cost is that the unlikely event of data-loss on one device is slightly more likely to result in data-loss for the array.

When a device in an array using FAILFAST is marked as faulty, it will usually become usable again in a short while. mdadm makes no attempt to detect that possibility. Some separate mechanism, tuned to the specific details of the expected failure modes, needs to be created to monitor devices to see when they return to full functionality, and to then re-add them to the array. In order of this "re-add" functionality to be effective, an array using FAILFAST should always have a write-intent bitmap.

### RESTRIPING
Restriping, also known as Reshaping, is the processes of re-arranging the data stored in each stripe into a new layout. This might involve changing the number of devices in the array (so the stripes are wider), changing the chunk size (so stripes are deeper or shallower), or changing the arrangement of data and parity (possibly changing the RAID level, e.g. 1 to 5 or 5 to 6).

md can reshape a RAID4, RAID5, or RAID6 array to have a different number of devices (more or fewer) and to have a different layout or chunk size. It can also convert between these different RAID levels. It can also convert between RAID0 and RAID10, and between RAID0 and RAID4 or RAID5. Other possibilities may follow in future kernels.

During any stripe process there is a 'critical section' during which live data is being overwritten on disk. For the operation of increasing the number of drives in a RAID5, this critical section covers the first few stripes (the number being the product of the old and new number of devices). After this critical section is passed, data is only written to areas of the array which no longer hold live data — the live data has already been located away.

For a reshape which reduces the number of devices, the 'critical section' is at the end of the reshape process.

md is not able to ensure data preservation if there is a crash (e.g. power failure) during the critical section. If md is asked to start an array which failed during a critical section of restriping, it will fail to start the array.

To deal with this possibility, a user-space program must

- Disable writes to that section of the array (using the sysfs interface),

- take a copy of the data somewhere (i.e. make a backup),

- allow the process to continue and invalidate the backup and restore write access once the critical section is passed, and

- provide for restoring the critical data before restarting the array after a system crash.

mdadm do this for growing a RAID5 array.

For operations that do not change the size of the array, like simply increasing chunk size, or converting RAID5 to RAID6 with one extra device, the entire process is the critical section. In this case, the restripe will need to progress in stages, as a section is suspended, backed up, restriped, and released.

### SYSFS INTERFACE
Each block device appears as a directory in sysfs (which is usually mounted at /sys). For MD devices, this directory will contain a subdirectory called md which contains various files for providing access to information about the array.

This interface is documented more fully in the file Documentation/admin-guide/md.rst which is distributed with the kernel sources. That file should be consulted for full documentation. The following are just a selection of attribute files that are available.

md/sync_speed_min

This value, if set, overrides the system-wide setting in /proc/sys/dev/raid/speed_limit_min for this array only. Writing the value system to this file will cause the system-wide setting to have effect.

md/sync_speed_max

This is the partner of md/sync_speed_min and overrides /proc/sys/dev/raid/speed_limit_max described below.

md/sync_action

This can be used to monitor and control the resync/recovery process of MD. In particular, writing "check" here will cause the array to read all data block and check that they are consistent (e.g. parity is correct, or all mirror replicas are the same). Any discrepancies found are NOT corrected. A count of problems found will be stored in md/mismatch_count.

Alternately, "repair" can be written which will cause the same check to be performed, but any errors will be corrected.

Finally, "idle" can be written to stop the check/repair process.

md/stripe_cache_size

This is only available on RAID5 and RAID6. It records the size (in pages per device) of the stripe cache which is used for synchronising all write operations to the array and all read operations if the array is degraded. The default is 256. Valid values are 17 to 32768. Increasing this number can increase performance in some situations, at some cost in system memory. Note, setting this value too high can result in an "out of memory" condition for the system. memory_consumed = system_page_size * nr_disks * stripe_cache_size

md/preread_bypass_threshold

This is only available on RAID5 and RAID6. This variable sets the number of times MD will service a full-stripe-write before servicing a stripe that requires some "prereading". For fairness this defaults to 1. Valid values are 0 to stripe_cache_size. Setting this to 0 maximizes sequential-write throughput at the cost of fairness to threads doing small or random writes.

md/bitmap/backlog

The value stored in the file only has any effect on RAID1 when write-mostly devices are active, and write requests to those devices are proceed in the background. This variable sets a limit on the number of concurrent background writes, the valid values are 0 to 16383, 0 means that write-behind is not allowed, while any other number means it can happen. If there are more write requests than the number, new writes will by synchronous.

md/bitmap/can_clear

This is for externally managed bitmaps, where the kernel writes the bitmap itself, but metadata describing the bitmap is managed by mdmon or similar. When the array is degraded, bits mustn't be cleared. When the array becomes optimal again, bit can be cleared, but first the metadata needs to record the current event count. So md sets this to 'false' and notifies mdmon, then mdmon updates the metadata and writes 'true'.

There is no code in mdmon to actually do this, so maybe it doesn't even work.

md/bitmap/chunksize

The bitmap chunksize can only be changed when no bitmap is active, and the value should be power of 2 and at least 512.

md/bitmap/location

This indicates where the write-intent bitmap for the array is stored. It can be "none" or "file" or a signed offset from the array metadata - measured in sectors. You cannot set a file by writing here - that can only be done with the SET_BITMAP_FILE ioctl. Write 'none' to 'bitmap/location' will clear bitmap, and the previous location value must be write to it to restore bitmap.

md/bitmap/max_backlog_used

This keeps track of the maximum number of concurrent write-behind requests for an md array, writing any value to this file will clear it.

md/bitmap/metadata

This can be 'internal' or 'clustered' or 'external'. 'internal' is set by default, which means the metadata for bitmap is stored in the first 256 bytes of the bitmap space. 'clustered' means separate bitmap metadata are used for each cluster node. 'external' means that bitmap metadata is managed externally to the kernel.

md/bitmap/space

This shows the space (in sectors) which is available at md/bitmap/location, and allows the kernel to know when it is safe to resize the bitmap to match a resized array. It should big enough to contain the total bytes in the bitmap. For 1.0 metadata, assume we can use up to the superblock if before, else to 4K beyond superblock. For other metadata versions, assume no change is possible.

md/bitmap/time_base

This shows the time (in seconds) between disk flushes, and is used to looking for bits in the bitmap to be cleared. The default value is 5 seconds, and it should be an unsigned long value.

### KERNEL PARAMETERS
The md driver recognised several different kernel parameters.

raid=noautodetect

This will disable the normal detection of md arrays that happens at boot time. If a drive is partitioned with MS-DOS style partitions, then if any of the 4 main partitions has a partition type of 0xFD, then that partition will normally be inspected to see if it is part of an MD array, and if any full arrays are found, they are started. This kernel parameter disables this behaviour.

md_mod.start_ro=1

/sys/module/md_mod/parameters/start_ro

This tells md to start all arrays in read-only mode. This is a soft read-only that will automatically switch to read-write on the first write request. However until that write request, nothing is written to any device by md, and in particular, no resync or recovery operation is started.

md_mod.start_dirty_degraded=1

/sys/module/md_mod/parameters/start_dirty_degraded

As mentioned above, md will not normally start a RAID4, RAID5, or RAID6 that is both dirty and degraded as this situation can imply hidden data loss. This can be awkward if the root filesystem is affected. Using this module parameter allows such arrays to be started at boot time. It should be understood that there is a real (though small) risk of data corruption in this situation.

md=n,dev,dev,...

md=dn,dev,dev,...

This tells the md driver to assemble /dev/md n from the listed devices. It is only necessary to start the device holding the root filesystem this way. Other arrays are best started once the system is booted.

md=n,l,c,i,dev...

This tells the md driver to assemble a legacy RAID0 or LINEAR array without a superblock. n gives the md device number, l gives the level, 0 for RAID0 or -1 for LINEAR, c gives the chunk size as a base-2 logarithm offset by twelve, so 0 means 4K, 1 means 8K. i is ignored (legacy support).

## FILES
/proc/mdstat

Contains information about the status of currently running array.

/proc/sys/dev/raid/speed_limit_min

A readable and writable file that reflects the current "goal" rebuild speed for times when non-rebuild activity is current on an array. The speed is in Kibibytes per second, and is a per-device rate, not a per-array rate (which means that an array with more disks will shuffle more data for a given speed). The default is 1000.

/proc/sys/dev/raid/speed_limit_max

A readable and writable file that reflects the current "goal" rebuild speed for times when no non-rebuild activity is current on an array. The default is 200,000.

## SEE ALSO
mdadm(8),


atalk

package: netatalk

title: atalk(4)

summary: AppleTalk protocol family

text:
# atalk(4)

## Name
atalk — AppleTalk protocol family

## Synopsis

```
#include <sys/types.h>
#include <netatalk/at.h>

```

## Description
The AppleTalk protocol family is a collection of protocols layered above the Datagram Delivery Protocol (DDP), and using AppleTalk address format. The AppleTalk family may provide SOCK_STREAM (ADSP), SOCK_DGRAM (DDP), SOCK_RDM (ATP), and SOCK_SEQPACKET (ASP). Currently, DDP is implemented in the kernel; ATP and ASP are implemented in Netatalk user level libraries.

## Addressing
AppleTalk addresses are three byte quantities, stored in network byte order. The include file <netatalk/at.h> defines the AppleTalk address format.

Sockets in the AppleTalk protocol family use the following address structure:

```
struct sockaddr_at {

    short sat_family;

    unsigned char sat_port;

    struct at_addr sat_addr;

    char sat_zero[8];
};

```

The port of a socket may be set with bind(2). The node for bind must always be ATADDR_ANYNODE: "this node." The net may be ATADDR_ANYNET or ATADDR_LATENET. ATADDR_ANYNET corresponds to the machine's "primary" address (the first configured). ATADDR_LATENET causes the address in outgoing packets to be determined when a packet is sent, i.e. determined late. ATADDR_LATENET is equivalent to opening one socket for each network interface. The port of a socket and either the primary address or ATADDR_LATENET are returned with getsockname(2).

## See Also
bind(2), getsockname(2), atalkd(8)

## Author
Contributors to the Netatalk Project


netatop

package: netatop

title: netatop(4)

text:
# netatop(4)

## NAME
netatop - per-process network statistics gathering

## SYNOPSIS
modprobe netatop

## DESCRIPTION
This manual page documents the netatop kernel module. This module uses the netfilter interface to gather statistics about TCP and UDP traffic per task, on level of process (thread group) and individual thread.

Once the module is loaded via modprobe, it is called for every packet that is transmitted by a local process and every packet that is received from an interface. For each packet it tries to determine the related process and thread to maintain statistical counters about the number of packets transmitted/received and the number of bytes transmitted/received. Separate counters are maintained for TCP and UDP packets. It does not only view the packets that contain the user data but also the protocol related packets (like SYN, ACK, ... for the TCP protocol).

Received packets can only be identified as related to a process after that process has transmitted at least one packet in the process' context.

## DETAILS
When the module discovers a packet for a new connection quintuple (TCP) or for a new local UDP port, it creates a so-called sockinfo structure. As soon as the netatop module knows to what process or thread the sockinfo struct is related, a reference is made from the sockinfo struct to the taskinfo struct that represents the proces or thread within the module. However, the related task can only be determined when a packet is transmitted, i.e. the module is called in the context of the transmitting process. At such moment the tgid (process) and pid (thread) can be obtained from the process administration to be stored in the module's own taskinfo structs (one for the process, one for the thread).

For the time that the sockinfo struct can not be related to a taskinfo struct (e.g. when only packets are received so far), counters are maintained temporarily in the sockinfo struct. After a related taskinfo struct has been discovered (i.e. the task transmits), counters will be maintained in the taskinfo struct itself. When packets are only received for a socket (e.g. another machine is sending UDP packets to the local machine) while the local task never responds, no match to a process can be made and the packets remain unidentified by the netatop module. At least one packet should have been sent by a local process to be able to identify packets for such process.

The module uses a garbage collector to cleanup the unused sockinfo structs if connections do not exist any more (TCP) or have not been used for some time (TCP/UDP). Furthermore, the garbage collector checks if taskinfo structs still represent existing processes or threads. If not, the taskinfo struct is destroyed (in case of a thread) or it is moved to a separate list of finished processes (in case of a process). Analysis programs can read the taskinfo of such finished process. When the taskinfo struct of a finished process is not read within 15 seconds, the taskinfo struct will be destroyed from the exitlist.

The garbage collector can be acivated by issueing a special getsockopt call from an analysis program (e.g. atop). Apart from that, a time-based garbage collector activation is issued anyhow every 15 seconds.

## SUPPORTED IOCTLS
Programs can open an IP socket and use the getsockopt() system call to issue commands to this module. With this system call the following commands can be issued:

ATOP_GETCNT_TGID

Obtain the current counters for a specific process (thread group) in a netpertask structure. When the required process does not exist, errno ESRCH is given.

ATOP_GETCNT_PID

Obtain the current counters for a specific thread in a netpertask structure. When the required thread does not exist, errno ESRCH is given.

ATOP_GETCNT_EXIT

Obtain the counters of an exited process. This command has to be issued within 15 seconds after a process has been declared 'finished' by the garbage collector. Whenever this command is issued while there is no exited process in the exitlist, the requesting process is blocked until an exited process is available.

NETATOP_FORCE_GC

Activate the garbage collector of the netatop module to determine if sockinfo structs of old connections/ports can be destroyed and to determine if taskinfo structs of exited processes can be moved to the exitlist.

NETATOP_EMPTY_EXIT

Block the calling process until the exitlist with the taskinfo structs of exited processes is empty.

## FILES
/proc/netatop

In this file, counters can be found that show the total number of packets sent/received and the number of packets that were unidentified (i.e. not accounted to a process/thread).

Furthermore, counters can be found about the current number of sockinfo structs, active taskinfo structs and taskinfo structs of exited processes.

## SEE ALSO
netatopd(8), atop(1), atopsar(1), atoprc(5)

https://www.atoptool.nl

## AUTHOR
Gerlof Langeveld (gerlof.langeveld@atoptool.nl)