Skip to content

Commit

Permalink
Add a vdev_size payload to the ereport if vdev_path is set.
Browse files Browse the repository at this point in the history
Signed-off-by: Turbo Fredriksson <turbo@bayour.com>

Closes: openzfs#2562
  • Loading branch information
FransUrbo committed Sep 9, 2014
1 parent 223df01 commit 85e59b9
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
24 changes: 22 additions & 2 deletions cmd/zed/zed.d/io-spare.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Replace a device with a hot spare in response to IO or checksum errors.
# The following actions will be performed automatically when the number
Expand Down Expand Up @@ -61,6 +61,17 @@ vdev_status() {
return 0
}

# Given a <device>, return the size
vdev_size() {
local VDEV=`basename $1`

for dir in /dev /dev/disk/by-*; do
if [[ -L $dir/$VDEV ]]; then
blockdev --getsize64 $dir/$VDEV
fi
done
}

# Fault devices after N I/O errors.
if [ "${ZEVENT_CLASS}" = "ereport.fs.zfs.io" ]; then
ERRORS=`expr ${ZEVENT_VDEV_READ_ERRORS} + ${ZEVENT_VDEV_WRITE_ERRORS}`
Expand All @@ -69,6 +80,7 @@ if [ "${ZEVENT_CLASS}" = "ereport.fs.zfs.io" ]; then
${ERRORS} -ge ${ZED_SPARE_ON_IO_ERRORS} ]; then
ACTION="fault"
fi

# Degrade devices after N checksum errors.
elif [ "${ZEVENT_CLASS}" = "ereport.fs.zfs.checksum" ]; then
ERRORS=${ZEVENT_VDEV_CKSUM_ERRORS}
Expand All @@ -77,12 +89,12 @@ elif [ "${ZEVENT_CLASS}" = "ereport.fs.zfs.checksum" ]; then
${ERRORS} -ge ${ZED_SPARE_ON_CHECKSUM_ERRORS} ]; then
ACTION="degrade"
fi

else
ACTION=
fi

if [ -n "${ACTION}" ]; then

# Device is already FAULTED or DEGRADED
set -- `vdev_status ${ZEVENT_POOL} ${ZEVENT_VDEV_PATH}`
ZEVENT_VDEV_PATH_FOUND=$1
Expand Down Expand Up @@ -110,10 +122,18 @@ if [ -n "${ACTION}" ]; then
# Round robin through the spares selecting those which are available.
#
for SPARE in ${ZEVENT_VDEV_SPARE_PATHS}; do
orig_size=${ZEVENT_VDEV_SIZE}
spare_size=$(vdev_size ${SPARE})
echo "${ZEVENT_POOL}:${ZEVENT_VDEV_GUID} = '$orig_size'" >> /tmp/zed.out
echo "${ZEVENT_POOL}:${SPARE} = '$spare_size'" >> /tmp/zed.out

set -- `vdev_status ${ZEVENT_POOL} ${SPARE}`
SPARE_VDEV_FOUND=$1
STATUS=$2
echo " SPARE_VDEV_FOUND='$SPARE_VDEV_FOUND', STATUS='$STATUS'" >> /tmp/zed.out

if [ "${STATUS}" = "AVAIL" ]; then
echo " ${ZPOOL} replace ${ZEVENT_POOL} ${ZEVENT_VDEV_GUID} ${SPARE_VDEV_FOUND}" >> /tmp/zed.out
${ZPOOL} replace ${ZEVENT_POOL} \
${ZEVENT_VDEV_GUID} ${SPARE_VDEV_FOUND} && exit 0
fi
Expand Down
1 change: 1 addition & 0 deletions include/sys/fm/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ extern "C" {
#define FM_EREPORT_PAYLOAD_ZFS_VDEV_FRU "vdev_fru"
#define FM_EREPORT_PAYLOAD_ZFS_VDEV_STATE "vdev_state"
#define FM_EREPORT_PAYLOAD_ZFS_VDEV_ASHIFT "vdev_ashift"
#define FM_EREPORT_PAYLOAD_ZFS_VDEV_SIZE "vdev_size"
#define FM_EREPORT_PAYLOAD_ZFS_VDEV_COMP_TS "vdev_complete_ts"
#define FM_EREPORT_PAYLOAD_ZFS_VDEV_DELTA_TS "vdev_delta_ts"
#define FM_EREPORT_PAYLOAD_ZFS_VDEV_SPARE_PATHS "vdev_spare_paths"
Expand Down
10 changes: 10 additions & 0 deletions man/man5/zfs-events.5
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,16 @@ The GUID of the vdev in question (the vdev failing or operated upon with
\fBzpool clear\fR etc).
.RE

.sp
.ne 2
.na
\fBvdev_size\fR
.ad
.RS 12n
Size of the vdev in question (the vdev failing or operated upon with
\fBzpool clear\fR etc).
.RE

.sp
.ne 2
.na
Expand Down
4 changes: 3 additions & 1 deletion module/zfs/zfs_fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ zfs_ereport_start(nvlist_t **ereport_out, nvlist_t **detector_out,
if (pvd->vdev_path)
fm_payload_set(ereport,
FM_EREPORT_PAYLOAD_ZFS_PARENT_PATH,
DATA_TYPE_STRING, pvd->vdev_path, NULL);
DATA_TYPE_STRING, pvd->vdev_path,
FM_EREPORT_PAYLOAD_ZFS_VDEV_SIZE,
DATA_TYPE_UINT64, pvd->vdev_psize, NULL);
if (pvd->vdev_devid)
fm_payload_set(ereport,
FM_EREPORT_PAYLOAD_ZFS_PARENT_DEVID,
Expand Down

0 comments on commit 85e59b9

Please sign in to comment.