diff --git a/CMakeLists.txt b/CMakeLists.txt index 52a0e17e6..615a992c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1160,6 +1160,8 @@ elseif(SunOS) PRIVATE "socket" PRIVATE "kstat" PRIVATE "proc" + PRIVATE "zfs" + PRIVATE "nvpair" ) elseif(ANDROID) CHECK_LIBRARY_EXISTS(-l:libandroid-wordexp.a wordexp "" HAVE_LIBANDROID_WORDEXP_STATIC) diff --git a/src/detection/zpool/libzfs_simplified.h b/src/detection/zpool/libzfs_simplified.h index 509586ca2..3b97c222d 100644 --- a/src/detection/zpool/libzfs_simplified.h +++ b/src/detection/zpool/libzfs_simplified.h @@ -75,82 +75,7 @@ typedef enum { ZPROP_SRC_RECEIVED = 0x20 } zprop_source_t; -typedef enum zpool_errata { - ZPOOL_ERRATA_NONE, - ZPOOL_ERRATA_ZOL_2094_SCRUB, - ZPOOL_ERRATA_ZOL_2094_ASYNC_DESTROY, - ZPOOL_ERRATA_ZOL_6845_ENCRYPTION, - ZPOOL_ERRATA_ZOL_8308_ENCRYPTION, -} zpool_errata_t; - -typedef enum { - /* - * The following correspond to faults as defined in the (fault.fs.zfs.*) - * event namespace. Each is associated with a corresponding message ID. - * This must be kept in sync with the zfs_msgid_table in - * lib/libzfs/libzfs_status.c. - */ - ZPOOL_STATUS_CORRUPT_CACHE, /* corrupt /kernel/drv/zpool.cache */ - ZPOOL_STATUS_MISSING_DEV_R, /* missing device with replicas */ - ZPOOL_STATUS_MISSING_DEV_NR, /* missing device with no replicas */ - ZPOOL_STATUS_CORRUPT_LABEL_R, /* bad device label with replicas */ - ZPOOL_STATUS_CORRUPT_LABEL_NR, /* bad device label with no replicas */ - ZPOOL_STATUS_BAD_GUID_SUM, /* sum of device guids didn't match */ - ZPOOL_STATUS_CORRUPT_POOL, /* pool metadata is corrupted */ - ZPOOL_STATUS_CORRUPT_DATA, /* data errors in user (meta)data */ - ZPOOL_STATUS_FAILING_DEV, /* device experiencing errors */ - ZPOOL_STATUS_VERSION_NEWER, /* newer on-disk version */ - ZPOOL_STATUS_HOSTID_MISMATCH, /* last accessed by another system */ - ZPOOL_STATUS_HOSTID_ACTIVE, /* currently active on another system */ - ZPOOL_STATUS_HOSTID_REQUIRED, /* multihost=on and hostid=0 */ - ZPOOL_STATUS_IO_FAILURE_WAIT, /* failed I/O, failmode 'wait' */ - ZPOOL_STATUS_IO_FAILURE_CONTINUE, /* failed I/O, failmode 'continue' */ - ZPOOL_STATUS_IO_FAILURE_MMP, /* failed MMP, failmode not 'panic' */ - ZPOOL_STATUS_BAD_LOG, /* cannot read log chain(s) */ - ZPOOL_STATUS_ERRATA, /* informational errata available */ - - /* - * If the pool has unsupported features but can still be opened in - * read-only mode, its status is ZPOOL_STATUS_UNSUP_FEAT_WRITE. If the - * pool has unsupported features but cannot be opened at all, its - * status is ZPOOL_STATUS_UNSUP_FEAT_READ. - */ - ZPOOL_STATUS_UNSUP_FEAT_READ, /* unsupported features for read */ - ZPOOL_STATUS_UNSUP_FEAT_WRITE, /* unsupported features for write */ - - /* - * These faults have no corresponding message ID. At the time we are - * checking the status, the original reason for the FMA fault (I/O or - * checksum errors) has been lost. - */ - ZPOOL_STATUS_FAULTED_DEV_R, /* faulted device with replicas */ - ZPOOL_STATUS_FAULTED_DEV_NR, /* faulted device with no replicas */ - - /* - * The following are not faults per se, but still an error possibly - * requiring administrative attention. There is no corresponding - * message ID. - */ - ZPOOL_STATUS_VERSION_OLDER, /* older legacy on-disk version */ - ZPOOL_STATUS_FEAT_DISABLED, /* supported features are disabled */ - ZPOOL_STATUS_RESILVERING, /* device being resilvered */ - ZPOOL_STATUS_OFFLINE_DEV, /* device offline */ - ZPOOL_STATUS_REMOVED_DEV, /* removed device */ - ZPOOL_STATUS_REBUILDING, /* device being rebuilt */ - ZPOOL_STATUS_REBUILD_SCRUB, /* recommend scrubbing the pool */ - ZPOOL_STATUS_NON_NATIVE_ASHIFT, /* (e.g. 512e dev with ashift of 9) */ - ZPOOL_STATUS_COMPATIBILITY_ERR, /* bad 'compatibility' property */ - ZPOOL_STATUS_INCOMPATIBLE_FEAT, /* feature set outside compatibility */ - - /* - * Finally, the following indicates a healthy pool. - */ - ZPOOL_STATUS_OK -} zpool_status_t; - -#ifndef __sun typedef bool boolean_t; -#endif typedef struct libzfs_handle libzfs_handle_t; typedef struct zpool_handle zpool_handle_t; @@ -162,4 +87,3 @@ extern void libzfs_fini(libzfs_handle_t *); extern uint64_t zpool_get_prop_int(zpool_handle_t *, zpool_prop_t, zprop_source_t *); extern const char *zpool_get_name(zpool_handle_t *); extern const char *zpool_get_state_str(zpool_handle_t *); -extern zpool_status_t zpool_get_status(zpool_handle_t *, const char **, zpool_errata_t *); diff --git a/src/detection/zpool/zpool.h b/src/detection/zpool/zpool.h index 3b4bc5ef2..8cd53da36 100644 --- a/src/detection/zpool/zpool.h +++ b/src/detection/zpool/zpool.h @@ -6,7 +6,6 @@ typedef struct FFZpoolResult { FFstrbuf name; FFstrbuf state; - FFstrbuf status; uint64_t used; uint64_t total; uint64_t version; diff --git a/src/detection/zpool/zpool_linux.c b/src/detection/zpool/zpool_linux.c index 6df9b2ce0..ae937d9c0 100644 --- a/src/detection/zpool/zpool_linux.c +++ b/src/detection/zpool/zpool_linux.c @@ -1,6 +1,43 @@ #include "zpool.h" -#include "common/library.h" + +#ifdef __sun +#define FF_DISABLE_DLOPEN +#include + +const char* zpool_get_state_str(zpool_handle_t* zpool) +{ + if (zpool_get_state(zpool) == POOL_STATE_UNAVAIL) + return "FAULTED"; + else + { + const char *str; + zpool_errata_t errata; + zpool_status_t status = zpool_get_status(zpool, (char**) &str, &errata); + if (status == ZPOOL_STATUS_IO_FAILURE_WAIT || + status == ZPOOL_STATUS_IO_FAILURE_CONTINUE || + status == ZPOOL_STATUS_IO_FAILURE_MMP) + return "SUSPENDED"; + else + { + nvlist_t *nvroot = fnvlist_lookup_nvlist(zpool_get_config(zpool, NULL), ZPOOL_CONFIG_VDEV_TREE); + uint_t vsc; + vdev_stat_t *vs; + #ifdef __x86_64__ + if (nvlist_lookup_uint64_array(nvroot, ZPOOL_CONFIG_VDEV_STATS, (uint64_t**) &vs, &vsc) != 0) + #else + if (nvlist_lookup_uint32_array(nvroot, ZPOOL_CONFIG_VDEV_STATS, (uint32_t**) &vs, &vsc) != 0) + #endif + return "UNKNOWN"; + else + return zpool_state_to_name(vs->vs_state, vs->vs_aux); + } + } +} +#else #include "libzfs_simplified.h" +#endif + +#include "common/library.h" typedef struct FFZfsData { @@ -9,7 +46,6 @@ typedef struct FFZfsData FF_LIBRARY_SYMBOL(zpool_get_prop_int) FF_LIBRARY_SYMBOL(zpool_get_name) FF_LIBRARY_SYMBOL(zpool_get_state_str) - FF_LIBRARY_SYMBOL(zpool_get_status) libzfs_handle_t* handle; FFlist* result; @@ -31,13 +67,6 @@ static int enumZpoolCallback(zpool_handle_t* zpool, void* param) FFZpoolResult* item = ffListAdd(data->result); ffStrbufInitS(&item->name, data->ffzpool_get_name(zpool)); ffStrbufInitS(&item->state, data->ffzpool_get_state_str(zpool)); - const char* msgid = NULL; - zpool_status_t status = data->ffzpool_get_status(zpool, &msgid, NULL); - if (msgid && *msgid) - ffStrbufInitS(&item->status, msgid); - else - ffStrbufInitStatic(&item->status, status == ZPOOL_STATUS_OK ? "OK" : "NOT OK"); - item->version = data->ffzpool_get_prop_int(zpool, ZPOOL_PROP_VERSION, &source); item->total = data->ffzpool_get_prop_int(zpool, ZPOOL_PROP_SIZE, &source); item->used = item->total - data->ffzpool_get_prop_int(zpool, ZPOOL_PROP_FREE, &source); @@ -63,7 +92,6 @@ const char* ffDetectZpool(FFlist* result /* list of FFZpoolResult */) FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libzfs, data, zpool_get_prop_int); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libzfs, data, zpool_get_name); FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libzfs, data, zpool_get_state_str); - FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libzfs, data, zpool_get_status); if (ffzpool_iter(handle, enumZpoolCallback, &data) < 0) return "zpool_iter() failed"; diff --git a/src/modules/zpool/zpool.c b/src/modules/zpool/zpool.c index 0b3772d0c..e21112362 100644 --- a/src/modules/zpool/zpool.c +++ b/src/modules/zpool/zpool.c @@ -5,7 +5,7 @@ #include "modules/zpool/zpool.h" #include "util/stringUtils.h" -#define FF_ZPOOL_NUM_FORMAT_ARGS 9 +#define FF_ZPOOL_NUM_FORMAT_ARGS 8 static void printZpool(FFZpoolOptions* options, FFZpoolResult* result, uint8_t index) { @@ -44,7 +44,7 @@ static void printZpool(FFZpoolOptions* options, FFZpoolResult* result, uint8_t i ffPercentAppendNum(&buffer, bytesPercentage, options->percent, false, &options->moduleArgs); ffStrbufAppendS(&buffer, ", "); ffPercentAppendNum(&buffer, fragPercentage, options->percent, false, &options->moduleArgs); - ffStrbufAppendF(&buffer, " frag) - %s", result->status.chars); + ffStrbufAppendF(&buffer, " frag) - %s", result->state.chars); ffStrbufPutTo(&buffer, stdout); } else @@ -62,7 +62,6 @@ static void printZpool(FFZpoolOptions* options, FFZpoolResult* result, uint8_t i FF_PRINT_FORMAT_CHECKED(buffer.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_ZPOOL_NUM_FORMAT_ARGS, ((FFformatarg[]) { {FF_FORMAT_ARG_TYPE_STRBUF, &result->name, "name"}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->state, "state"}, - {FF_FORMAT_ARG_TYPE_STRBUF, &result->status, "status"}, {FF_FORMAT_ARG_TYPE_STRBUF, &usedPretty, "size-used"}, {FF_FORMAT_ARG_TYPE_STRBUF, &totalPretty, "size-total"}, {FF_FORMAT_ARG_TYPE_STRBUF, &bytesPercentageNum, "size-percentage"}, @@ -165,7 +164,6 @@ void ffGenerateZpoolJsonResult(FF_MAYBE_UNUSED FFZpoolOptions* options, yyjson_m yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr); yyjson_mut_obj_add_strbuf(doc, obj, "name", &zpool->name); yyjson_mut_obj_add_strbuf(doc, obj, "state", &zpool->state); - yyjson_mut_obj_add_strbuf(doc, obj, "status", &zpool->status); yyjson_mut_obj_add_uint(doc, obj, "used", zpool->used); yyjson_mut_obj_add_uint(doc, obj, "total", zpool->total); yyjson_mut_obj_add_uint(doc, obj, "version", zpool->version); @@ -184,7 +182,6 @@ void ffPrintZpoolHelpFormat(void) FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_ZPOOL_MODULE_NAME, "{3} / {4} ({5}, {6} frag)", FF_ZPOOL_NUM_FORMAT_ARGS, ((const char* []) { "Zpool name - name", "Zpool state - state", - "Zpool health status - status", "Size used - size-used", "Size total - size-total", "Size percentage num - size-percentage",