NAME
devfs_cleanup.sh - remove dead disk devices when all storage paths are healthy
SYNOPSIS
/opt/omnicube/sbin/devfs_cleanup.sh [-n]
DESCRIPTION
devfs_cleanup.sh removes the disk devices of LUNs that no longer exist. Devices of deleted, unmapped or relocated LUNs otherwise accumulate, and format(8) opens every one of them and waits for each open to fail, so listing disks gets slower with every LUN the node has ever seen. Two steps do the work:
A path that is down at this moment is indistinguishable from a LUN that was deleted. The script therefore cleans only when it can establish that storage is settled, and a check that cannot be evaluated counts as a failed check. The pass is skipped, with an info() record and exit status 0, when any of the following holds:
-
the node is isolated, that is, /var/run/omnicube/isolate_node.lock exists (see isolate_node.sh(8));
-
svc:/network/iscsi/initiator:default is in a state other than online or disabled;
-
the initiator is online and iscsiadm list target -S fails, lists a target with Connections: 0, lists a LUN whose OS Device Name is Not Available, or lists no target at all although static or SendTargets discovery is enabled and configured;
-
an FC initiator port that must be online is not (see config/devfs_cleanup_fc_ports below), a listed port is not present, or fcinfo hba-port fails;
-
an FC LUN is in condition failing or failed, or LUNs are unusable behind a remote port that is no longer logged in, which means the target is down rather than the LUNs deleted;
-
mpathadm list lu fails, or reports an LU with fewer operational paths than total paths, or with no operational path;
-
zpool status -x reports anything other than all pools are healthy.
Each transport is checked only where it is in use, so the same script serves iSCSI nodes, FC/SAN nodes, mixed nodes and nodes with local disks only. iSCSI is in use when the initiator service is online and discovery is configured or a target is logged in; a disabled or absent initiator is not used. FC is in use when fcinfo(8) reports an initiator HBA port; target-mode ports are ignored. With MPxIO on, the path-count check covers both transports.
The checks pass, then the unusable FC LUNs are counted and a dry run (devfsadm -C -s -v -c disk) lists the links that would go. If there is nothing the script exits. If the distinct disks with dangling links plus the unusable FC LUNs exceed config/devfs_cleanup_max_devices, nothing is removed and a warning() lists them, since a pass that large is not routine LUN churn. Otherwise the checks are repeated, step 1 then step 2 run.
The script is meant to run weekly from root's crontab; a sample entry is shipped in /opt/omnicube/share/README. A skipped week costs nothing, so a skip is not mailed: the degraded state that caused it is reported by pool_monitor.sh(8) and sys_monitor(8).
OPTIONS
EXAMPLES
Example 1: weekly cron entry, Sunday 04:52
52 4 * * 0 /opt/omnicube/sbin/devfs_cleanup.sh >/dev/null
Example 2: see what the next pass would remove
pfexec /opt/omnicube/sbin/devfs_cleanup.sh -n
Example 3: SAN node with a spare, unplugged HBA port
Only the two ports in use must be online:
svccfg -s svc:/omnicube/sysadm:default setprop \\
config/devfs_cleanup_fc_ports = astring: '("2100000e1e000001" "2100000e1e000101")'
svcadm refresh svc:/omnicube/sysadm:default
Example 4: node with an FC HBA that is not used
svccfg -s svc:/omnicube/sysadm:default setprop \\
config/devfs_cleanup_fc_ports = astring: none
svcadm refresh svc:/omnicube/sysadm:default
Example 5: review past passes, including the per-link devfsadm output
grep devfs_cleanup /var/log/misc.log
EXIT STATUS
FILES
ENVIRONMENT
SMF PROPERTIES
SECURITY
devfsadm, iscsiadm, mpathadm, fcinfo and cfgadm are run through ${PFEXEC}, which is empty for root and pfexec otherwise. A non-root caller needs the OmniCube Administration profile and the matching entries in /etc/security/exec_attr.d/omnicube. That profile is root-equivalent as a whole.
SEE ALSO
cfgadm(8), cfgadm_fp(8), devfsadm(8), fcinfo(8), format(8), iscsiadm(8), mpathadm(8), isolate_node.sh(8), pool_monitor.sh(8), sys_monitor(8), oc_lock(3), oc_runlevel(3), omnicube_utils(3), omnicube(7).
NOTES
Removed links are not lost for good: when a device attaches again the kernel event makes devfsadmd(8) recreate them. The guards exist because a pool import or a zone boot that runs before the path returns would not find them.
Only FC LUNs in condition unusable are unconfigured. Other stale nodes under /devices are left alone.