diff --git a/cmdline/device.c b/cmdline/device.c index 70d46dfc..1aadea94 100644 --- a/cmdline/device.c +++ b/cmdline/device.c @@ -535,41 +535,6 @@ static double raid_prob_of_one_or_more_failures(double array_failure_rate, doubl return poisson_prob_n_or_more_failures(raid_failure_rate, 1); } -static void state_info_log(devinfo_t* devinfo) -{ - char esc_buffer[ESC_MAX]; - - log_tag("info:%s:%s\n", devinfo->file, devinfo->name); - if (devinfo->serial[0]) - log_tag("attr:%s:%s:serial:%s\n", devinfo->file, devinfo->name, esc_tag(devinfo->serial, esc_buffer)); - if (devinfo->vendor[0]) - log_tag("attr:%s:%s:vendor:%s\n", devinfo->file, devinfo->name, esc_tag(devinfo->vendor, esc_buffer)); - if (devinfo->model[0]) - log_tag("attr:%s:%s:model:%s\n", devinfo->file, devinfo->name, esc_tag(devinfo->model, esc_buffer)); - if (devinfo->info[INFO_SIZE] != SMART_UNASSIGNED) - log_tag("attr:%s:%s:size:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->info[INFO_SIZE]); - if (devinfo->info[INFO_ROTATION_RATE] != SMART_UNASSIGNED) - log_tag("attr:%s:%s:rotationrate:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->info[INFO_ROTATION_RATE]); -} - -static void state_smart_log(devinfo_t* devinfo, double afr) -{ - unsigned j; - - log_tag("smart:%s:%s\n", devinfo->file, devinfo->name); - if (devinfo->smart[SMART_ERROR] != SMART_UNASSIGNED) - log_tag("attr:%s:%s:error:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_ERROR]); - if (devinfo->smart[SMART_FLAGS] != SMART_UNASSIGNED) - log_tag("attr:%s:%s:flags:%" PRIu64 ":%" PRIx64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_FLAGS], devinfo->smart[SMART_FLAGS]); - - if (afr != 0) - log_tag("attr:%s:%s:afr:%g:%g\n", devinfo->file, devinfo->name, afr, poisson_prob_n_or_more_failures(afr, 1)); - - for (j = 0; j < 256; ++j) - if (devinfo->smart[j] != SMART_UNASSIGNED) - log_tag("attr:%s:%s:%u:%" PRIu64 ":%" PRIx64 "\n", devinfo->file, devinfo->name, j, devinfo->smart[j], devinfo->smart[j]); -} - static void state_smart(struct snapraid_state* state, unsigned n, tommy_list* low) { tommy_node* i; @@ -582,6 +547,7 @@ static void state_smart(struct snapraid_state* state, unsigned n, tommy_list* lo int make_it_fail = 0; uint64_t mask32 = 0xffffffffU; uint64_t mask16 = 0xffffU; + char esc_buffer[ESC_MAX]; /* compute lengths for padding */ device_pad = 0; @@ -595,7 +561,7 @@ static void state_smart(struct snapraid_state* state, unsigned n, tommy_list* lo if (len > device_pad) device_pad = len; - len = strlen(devinfo->serial); + len = strlen(devinfo->smart_serial); if (len > serial_pad) serial_pad = len; @@ -680,12 +646,12 @@ static void state_smart(struct snapraid_state* state, unsigned n, tommy_list* lo /* if error running smartctl, skip AFR estimation */ afr = 0; printf(" n/a"); - } else if (devinfo->info[INFO_ROTATION_RATE] == 0) { + } else if (devinfo->smart[SMART_ROTATION_RATE] == 0) { /* if SSD, skip AFR estimation as data is from not SSD disks */ afr = 0; printf(" SSD"); } else { - afr = smart_afr(devinfo->smart, devinfo->model); + afr = smart_afr(devinfo->smart, devinfo->smart_model); if (afr == 0) { /* this happens only if no data */ @@ -699,14 +665,14 @@ static void state_smart(struct snapraid_state* state, unsigned n, tommy_list* lo } } - if (devinfo->info[INFO_SIZE] != SMART_UNASSIGNED) - printf(" %4.1f", devinfo->info[INFO_SIZE] / 1E12); + if (devinfo->smart[SMART_SIZE] != SMART_UNASSIGNED) + printf(" %4.1f", devinfo->smart[SMART_SIZE] / 1E12); else printf(" -"); printf(" "); - if (*devinfo->serial) - printl(devinfo->serial, serial_pad); + if (*devinfo->smart_serial) + printl(devinfo->smart_serial, serial_pad); else printl("-", serial_pad); @@ -724,8 +690,26 @@ static void state_smart(struct snapraid_state* state, unsigned n, tommy_list* lo printf("\n"); - state_info_log(devinfo); - state_smart_log(devinfo, afr); + log_tag("smart:%s:%s\n", devinfo->file, devinfo->name); + if (devinfo->smart_serial[0]) + log_tag("attr:%s:%s:serial:%s\n", devinfo->file, devinfo->name, esc_tag(devinfo->smart_serial, esc_buffer)); + if (devinfo->smart_vendor[0]) + log_tag("attr:%s:%s:vendor:%s\n", devinfo->file, devinfo->name, esc_tag(devinfo->smart_vendor, esc_buffer)); + if (devinfo->smart_model[0]) + log_tag("attr:%s:%s:model:%s\n", devinfo->file, devinfo->name, esc_tag(devinfo->smart_model, esc_buffer)); + if (afr != 0) + log_tag("attr:%s:%s:afr:%g:%g\n", devinfo->file, devinfo->name, afr, poisson_prob_n_or_more_failures(afr, 1)); + if (devinfo->smart[SMART_SIZE] != SMART_UNASSIGNED) + log_tag("attr:%s:%s:size:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_SIZE]); + if (devinfo->smart[SMART_ERROR] != SMART_UNASSIGNED) + log_tag("attr:%s:%s:error:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_ERROR]); + if (devinfo->smart[SMART_ROTATION_RATE] != SMART_UNASSIGNED) + log_tag("attr:%s:%s:rotationrate:%" PRIu64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_ROTATION_RATE]); + if (devinfo->smart[SMART_FLAGS] != SMART_UNASSIGNED) + log_tag("attr:%s:%s:flags:%" PRIu64 ":%" PRIx64 "\n", devinfo->file, devinfo->name, devinfo->smart[SMART_FLAGS], devinfo->smart[SMART_FLAGS]); + for (j = 0; j < 256; ++j) + if (devinfo->smart[j] != SMART_UNASSIGNED) + log_tag("attr:%s:%s:%u:%" PRIu64 ":%" PRIx64 "\n", devinfo->file, devinfo->name, j, devinfo->smart[j], devinfo->smart[j]); } printf("\n"); @@ -799,8 +783,6 @@ static void state_probe(struct snapraid_state* state, tommy_list* low) len = strlen(devinfo->file); if (len > device_pad) device_pad = len; - - state_info_log(devinfo); } printf("SnapRAID PROBE report:\n"); @@ -878,16 +860,16 @@ int devtest(tommy_list* high, tommy_list* low, int operation) } } - pathprint(entry->serial, sizeof(entry->serial), "FAKE_%s", devinfo->serial); - pathprint(entry->vendor, sizeof(entry->vendor), "FAKE_%s", devinfo->vendor); - pathprint(entry->model, sizeof(entry->model), "FAKE_%s", devinfo->model); + pathprint(entry->smart_serial, sizeof(entry->smart_serial), "FAKE_%s", devinfo->smart_serial); + pathprint(entry->smart_vendor, sizeof(entry->smart_vendor), "FAKE_%s", devinfo->smart_vendor); + pathprint(entry->smart_model, sizeof(entry->smart_model), "FAKE_%s", devinfo->smart_model); pathprint(entry->file, sizeof(entry->name), "FAKE_%s", devinfo->file); pathcpy(entry->name, sizeof(entry->name), devinfo->name); - entry->info[INFO_SIZE] = count * TERA; - entry->info[INFO_ROTATION_RATE] = 7200; + entry->smart[SMART_SIZE] = count * TERA; + entry->smart[SMART_ROTATION_RATE] = 7200; + entry->smart[SMART_TEMPERATURE_CELSIUS] = 27; entry->smart[SMART_ERROR] = 0; entry->smart[SMART_FLAGS] = SMART_UNASSIGNED; - entry->smart[SMART_TEMPERATURE_CELSIUS] = 27; switch (count) { case 3 : entry->smart[SMART_ERROR] = 1; break; diff --git a/cmdline/mingw.c b/cmdline/mingw.c index 6eddf561..a87bf841 100644 --- a/cmdline/mingw.c +++ b/cmdline/mingw.c @@ -710,7 +710,7 @@ static void windows_errno(DWORD error) errno = EIO; break; default : - log_fatal("Unexpected Windows error %lu.\n", error); + log_fatal("Unexpected Windows error %d.\n", (int)error); errno = EIO; break; } @@ -2498,7 +2498,7 @@ static int devscan(tommy_list* list) /** * Get SMART attributes. */ -static int devsmart(uint64_t device, const char* name, const char* smartctl, uint64_t* smart, uint64_t* info, char* serial, char* vendor, char* model) +static int devsmart(uint64_t device, const char* name, const char* smartctl, uint64_t* smart, char* serial, char* vendor, char* model) { char conv_buf[CONV_MAX]; WCHAR cmd[MAX_PATH + 128]; @@ -2526,16 +2526,14 @@ retry: f = _wpopen(cmd, L"rt"); if (!f) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:shell\n", file, name); log_fatal("Failed to run '%s' (from popen).\n", u16tou8(conv_buf, cmd)); return -1; /* LCOV_EXCL_STOP */ } - if (smartctl_attribute(f, file, name, smart, info, serial, vendor, model) != 0) { + if (smartctl_attribute(f, file, name, smart, serial, vendor, model) != 0) { /* LCOV_EXCL_START */ pclose(f); - log_tag("device:%s:%s:shell\n", file, name); return -1; /* LCOV_EXCL_STOP */ } @@ -2546,7 +2544,6 @@ retry: if (ret == -1) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:shell\n", file, name); log_fatal("Failed to run '%s' (from pclose).\n", u16tou8(conv_buf, cmd)); return -1; /* LCOV_EXCL_STOP */ @@ -2567,8 +2564,8 @@ retry: */ if ((ret == 0 || ret == 2) && smart[9] == SMART_UNASSIGNED - && info[INFO_SIZE] == SMART_UNASSIGNED - && info[INFO_ROTATION_RATE] == SMART_UNASSIGNED + && smart[SMART_SIZE] == SMART_UNASSIGNED + && smart[SMART_ROTATION_RATE] == SMART_UNASSIGNED ) { /* retry using the "sat" type */ snwprintf(cmd, sizeof(cmd), L"\"%lssmartctl.exe\" -a -d sat %s", exedir, file); @@ -2587,7 +2584,7 @@ retry: /** * Get POWER state */ -static int devprobe(uint64_t device, const char* name, const char* smartctl, int* power, uint64_t* info, char* serial, char* vendor, char* model) +static int devprobe(uint64_t device, const char* name, const char* smartctl, int* power) { char conv_buf[CONV_MAX]; WCHAR cmd[MAX_PATH + 128]; @@ -2615,16 +2612,14 @@ retry: f = _wpopen(cmd, L"rt"); if (!f) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:shell\n", file, name); log_fatal("Failed to run '%s' (from popen).\n", u16tou8(conv_buf, cmd)); return -1; /* LCOV_EXCL_STOP */ } - if (smartctl_attribute(f, file, name, 0, info, serial, vendor, model) != 0) { + if (smartctl_flush(f, file, name) != 0) { /* LCOV_EXCL_START */ pclose(f); - log_tag("device:%s:%s:shell\n", file, name); return -1; /* LCOV_EXCL_STOP */ } @@ -2635,7 +2630,6 @@ retry: if (ret == -1) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:shell\n", file, name); log_fatal("Failed to run '%s' (from pclose).\n", u16tou8(conv_buf, cmd)); return -1; /* LCOV_EXCL_STOP */ @@ -2660,16 +2654,12 @@ retry: } } - if (ret == 0) { - log_tag("device:%s:%s:active\n", file, name); + if (ret == 0) *power = POWER_ACTIVE; - } else if (ret == 3) { - log_tag("device:%s:%s:standby\n", file, name); + else if (ret == 3) *power = POWER_STANDBY; - } else { - log_tag("device:%s:%s:unknown\n", file, name); + else *power = POWER_UNKNOWN; - } return 0; } @@ -2705,7 +2695,6 @@ retry: f = _wpopen(cmd, L"rt"); if (!f) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:shell\n", file, name); log_fatal("Failed to run '%s' (from popen).\n", u16tou8(conv_buf, cmd)); return -1; /* LCOV_EXCL_STOP */ @@ -2714,7 +2703,6 @@ retry: if (smartctl_flush(f, file, name) != 0) { /* LCOV_EXCL_START */ pclose(f); - log_tag("device:%s:%s:shell\n", file, name); return -1; /* LCOV_EXCL_STOP */ } @@ -2725,7 +2713,6 @@ retry: if (ret == -1) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:shell\n", file, name); log_fatal("Failed to run '%s' (from pclose).\n", u16tou8(conv_buf, cmd)); return -1; /* LCOV_EXCL_STOP */ @@ -2752,14 +2739,11 @@ retry: if (ret != 0) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:exit:%d\n", file, name, ret); log_fatal("Failed to run '%s' with return code %xh.\n", u16tou8(conv_buf, cmd), ret); return -1; /* LCOV_EXCL_STOP */ } - log_tag("device:%s:%s:down\n", file, name); - return 0; } @@ -2770,7 +2754,7 @@ static int devdownifup(uint64_t device, const char* name, const char* smartctl, { *power = POWER_UNKNOWN; - if (devprobe(device, name, smartctl, power, 0, 0, 0, 0) != 0) + if (devprobe(device, name, smartctl, power) != 0) return -1; if (*power == POWER_ACTIVE) @@ -2782,7 +2766,7 @@ static int devdownifup(uint64_t device, const char* name, const char* smartctl, /** * Spin up a device. */ -static int devup(uint64_t device, const char* name, const char* wfile) +static int devup(const char* wfile) { wchar_t conv_buf[CONV_MAX]; HANDLE h; @@ -2790,16 +2774,11 @@ static int devup(uint64_t device, const char* name, const char* wfile) DISK_GEOMETRY dg; DWORD bytes; void* buffer; - char file[128]; - - snprintf(file, sizeof(file), "/dev/pd%" PRIu64, device); /* open the volume */ h = CreateFileW(convert(conv_buf, wfile), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH, 0); if (h == INVALID_HANDLE_VALUE) { - DWORD error = GetLastError(); - windows_errno(error); - log_tag("device:%s:%s:error:%lu\n", file, name, error); + windows_errno(GetLastError()); return -1; } @@ -2809,7 +2788,6 @@ static int devup(uint64_t device, const char* name, const char* wfile) DWORD error = GetLastError(); CloseHandle(h); windows_errno(error); - log_tag("device:%s:%s:error:%lu\n", file, name, error); return -1; } @@ -2818,7 +2796,6 @@ static int devup(uint64_t device, const char* name, const char* wfile) DWORD error = GetLastError(); CloseHandle(h); windows_errno(error); - log_tag("device:%s:%s:error:%lu\n", file, name, error); return -1; } @@ -2827,7 +2804,6 @@ static int devup(uint64_t device, const char* name, const char* wfile) DWORD error = GetLastError(); CloseHandle(h); windows_errno(error); - log_tag("device:%s:%s:error:%lu\n", file, name, error); return -1; } @@ -2835,14 +2811,11 @@ static int devup(uint64_t device, const char* name, const char* wfile) DWORD error = GetLastError(); VirtualFree(buffer, 0, MEM_RELEASE); windows_errno(error); - log_tag("device:%s:%s:error:%lu\n", file, name, error); return -1; } VirtualFree(buffer, 0, MEM_RELEASE); - log_tag("device:%s:%s:up\n", file, name); - return 0; } @@ -2856,7 +2829,7 @@ static void* thread_spinup(void* arg) start = tick_ms(); - if (devup(devinfo->device, devinfo->name, devinfo->wfile) != 0) { + if (devup(devinfo->wfile) != 0) { /* LCOV_EXCL_START */ return (void*)-1; /* LCOV_EXCL_STOP */ @@ -2918,7 +2891,7 @@ static void* thread_smart(void* arg) { devinfo_t* devinfo = arg; - if (devsmart(devinfo->device, devinfo->name, devinfo->smartctl, devinfo->smart, devinfo->info, devinfo->serial, devinfo->vendor, devinfo->model) != 0) { + if (devsmart(devinfo->device, devinfo->name, devinfo->smartctl, devinfo->smart, devinfo->smart_serial, devinfo->smart_vendor, devinfo->smart_model) != 0) { /* LCOV_EXCL_START */ return (void*)-1; /* LCOV_EXCL_STOP */ @@ -2934,7 +2907,7 @@ static void* thread_probe(void* arg) { devinfo_t* devinfo = arg; - if (devprobe(devinfo->device, devinfo->name, devinfo->smartctl, &devinfo->power, devinfo->info, devinfo->serial, devinfo->vendor, devinfo->model) != 0) { + if (devprobe(devinfo->device, devinfo->name, devinfo->smartctl, &devinfo->power) != 0) { /* LCOV_EXCL_START */ return (void*)-1; /* LCOV_EXCL_STOP */ diff --git a/cmdline/portable.h b/cmdline/portable.h index cc133ddf..374304a8 100644 --- a/cmdline/portable.h +++ b/cmdline/portable.h @@ -447,25 +447,18 @@ int randomize(void* ptr, size_t size); #define SMART_AIRFLOW_TEMPERATURE_CELSIUS 190 #define SMART_TEMPERATURE_CELSIUS 194 -#define SMART_FLAGS 256 /**< Flags returned by smartctl. */ -#define SMART_ERROR 257 /**< ATA Error count. */ +/** + * Additional SMART attributes. + */ +#define SMART_ERROR 256 /**< ATA Error count. */ +#define SMART_SIZE 257 /**< Size in bytes. */ +#define SMART_ROTATION_RATE 258 /**< Rotation speed. 0 for SSD. */ +#define SMART_FLAGS 259 /**< Flags returned by smartctl. */ /** * SMART attributes count. */ -#define SMART_COUNT 258 - -/** - * Info attributes. - */ -#define INFO_SIZE 0 /**< Size in bytes. */ -#define INFO_ROTATION_RATE 1 /**< Rotation speed. 0 for SSD. */ - -/** - * Info attributes count. - */ -#define INFO_COUNT 2 - +#define SMART_COUNT 260 #define SMART_IGNORE_MAX 4 /**< Max number of ignored smart attributes */ @@ -513,11 +506,10 @@ struct devinfo_struct { char wfile[PATH_MAX]; /**< File device in Windows format. Like \\.\PhysicalDriveX, or \\?\Volume{X}. */ #endif struct devinfo_struct* parent; /**< Pointer at the parent if any. */ - uint64_t smart[SMART_COUNT]; /**< SMART attributes. */ - uint64_t info[INFO_COUNT]; /**< Info attributes. */ - char serial[SMART_MAX]; /**< Serial number. */ - char vendor[SMART_MAX]; /**< Vendor. */ - char model[SMART_MAX]; /**< Model. */ + uint64_t smart[SMART_COUNT]; /**< SMART raw attributes. */ + char smart_serial[SMART_MAX]; /**< SMART serial number. */ + char smart_vendor[SMART_MAX]; /**< SMART vendor. */ + char smart_model[SMART_MAX]; /**< SMART model. */ int power; /**< POWER mode. */ #if HAVE_THREAD thread_id_t thread; diff --git a/cmdline/state.c b/cmdline/state.c index 179feb04..d666e439 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -2717,14 +2717,6 @@ static void state_read_content(struct snapraid_state* state, const char* path, S /* LCOV_EXCL_STOP */ } - /* log the info read from the content file */ - log_tag("content_disk:%s:%" PRIu64 ":%" PRIu64 ":%u:%s\n", - buffer, - v_total_blocks * (uint64_t)state->block_size, - v_free_blocks * (uint64_t)state->block_size, - v_pos, - uuid); - /* find the disk */ disk = find_disk_by_name(state, buffer); if (!disk) { @@ -2822,13 +2814,9 @@ static void state_read_content(struct snapraid_state* state, const char* path, S state->parity[v_level].free_blocks = v_free_blocks; /* log the info read from the content file */ - log_tag("content_parity:%s:%" PRIu64 ":%" PRIu64 ":%u:%s:%s:%" PRIi64 "\n", - lev_config_name(v_level), - v_total_blocks * (uint64_t)state->block_size, - v_free_blocks * (uint64_t)state->block_size, - 0, - state->parity[v_level].split_map[0].uuid, + log_tag("content:%s:0:%s:%s:%" PRIi64 "\n", lev_config_name(v_level), state->parity[v_level].split_map[0].path, + state->parity[v_level].split_map[0].uuid, state->parity[v_level].split_map[0].size); } } else if (c == 'Q') { @@ -2949,13 +2937,9 @@ static void state_read_content(struct snapraid_state* state, const char* path, S state->parity[v_level].split_map[s].size = v_size; /* log the info read from the content file */ - log_tag("content_parity:%s:%" PRIu64 ":%" PRIu64 ":%u:%s:%s:%" PRIi64 "\n", - lev_config_name(v_level), - v_total_blocks * (uint64_t)state->block_size, - v_free_blocks * (uint64_t)state->block_size, - s, - state->parity[v_level].split_map[s].uuid, + log_tag("content:%s:%u:%s:%s:%" PRIi64 "\n", lev_config_name(v_level), s, state->parity[v_level].split_map[s].path, + state->parity[v_level].split_map[s].uuid, state->parity[v_level].split_map[s].size); } } diff --git a/cmdline/support.c b/cmdline/support.c index 7ea03982..e5cfe9a1 100644 --- a/cmdline/support.c +++ b/cmdline/support.c @@ -1610,36 +1610,15 @@ static int smatch(const char* str, const char* pattern) return 0; } -int smartctl_attribute(FILE* f, const char* file, const char* name, uint64_t* smart, uint64_t* info, char* serial, char* vendor, char* model) +int smartctl_attribute(FILE* f, const char* file, const char* name, uint64_t* smart, char* serial, char* vendor, char* model) { unsigned i; int inside; - uint64_t dummy_smart[SMART_COUNT]; - uint64_t dummy_info[INFO_COUNT]; - char dummy_serial[SMART_MAX]; - char dummy_vendor[SMART_MAX]; - char dummy_model[SMART_MAX]; - /* dummy attributes */ - if (!smart) - smart = dummy_smart; - if (!info) - info = dummy_info; - if (!serial) - serial = dummy_serial; - if (!vendor) - vendor = dummy_vendor; - if (!model) - model = dummy_model; - - /* preclear attributes */ + /* preclear attribute */ *serial = 0; - *vendor = 0; - *model = 0; for (i = 0; i < SMART_COUNT; ++i) smart[i] = SMART_UNASSIGNED; - for (i = 0; i < INFO_COUNT; ++i) - info[i] = SMART_UNASSIGNED; /* read the file */ inside = 0; @@ -1666,23 +1645,23 @@ int smartctl_attribute(FILE* f, const char* file, const char* name, uint64_t* sm inside = 0; /* common */ } else if (smatch(s, "Rotation Rate: Solid State") == 0) { - info[INFO_ROTATION_RATE] = 0; - } else if (sscanf(s, "Rotation Rate: %" SCNu64, &info[INFO_ROTATION_RATE]) == 1) { + smart[SMART_ROTATION_RATE] = 0; + } else if (sscanf(s, "Rotation Rate: %" SCNu64, &smart[SMART_ROTATION_RATE]) == 1) { } else if (smatch(s, "User Capacity:") == 0) { char* begin = strchr(s, ':'); char* end = strstr(s, "bytes"); if (begin != 0 && end != 0 && begin < end) { char* p; - info[INFO_SIZE] = 0; + smart[SMART_SIZE] = 0; for (p = begin; p != end; ++p) { if (isdigit(*p)) { - info[INFO_SIZE] *= 10; - info[INFO_SIZE] += *p - '0'; + smart[SMART_SIZE] *= 10; + smart[SMART_SIZE] += *p - '0'; } } } - } else if (sscanf(s, "Model Family: %63[^\n]", vendor) == 1) { - } else if (sscanf(s, "Device Model: %63[^\n]", model) == 1) { + } else if (sscanf(s, "Device Model: %63s %63s", vendor, model) == 2) { + } else if (sscanf(s, "Device Model: %63s", model) == 1) { /* SCSI */ } else if (sscanf(s, "Serial number: %63s", serial) == 1) { /* note "n" of "number" lower case */ } else if (sscanf(s, "Elements in grown defect list: %" SCNu64, &smart[SMART_REALLOCATED_SECTOR_COUNT]) == 1) { diff --git a/cmdline/support.h b/cmdline/support.h index cfd7fa22..2221bf52 100644 --- a/cmdline/support.h +++ b/cmdline/support.h @@ -421,7 +421,7 @@ void malloc_fail(size_t size); * Read smartctl attributes from a stream. * Return 0 on success. */ -int smartctl_attribute(FILE* f, const char* file, const char* name, uint64_t* smart, uint64_t* info, char* serial, char* vendor, char* model); +int smartctl_attribute(FILE* f, const char* file, const char* name, uint64_t* smart, char* serial, char* vendor, char* model); /** * Flush smartctl output from a stream. diff --git a/cmdline/unix.c b/cmdline/unix.c index fe0e766d..8587f1c6 100644 --- a/cmdline/unix.c +++ b/cmdline/unix.c @@ -1140,7 +1140,7 @@ static int devscan(tommy_list* list) * Get SMART attributes. */ #if HAVE_LINUX_DEVICE -static int devsmart(dev_t device, const char* name, const char* smartctl, uint64_t* smart, uint64_t* info, char* serial, char* vendor, char* model) +static int devsmart(dev_t device, const char* name, const char* smartctl, uint64_t* smart, char* serial, char* vendor, char* model) { char cmd[PATH_MAX + 64]; char file[PATH_MAX]; @@ -1168,16 +1168,14 @@ static int devsmart(dev_t device, const char* name, const char* smartctl, uint64 f = popen(cmd, "r"); if (!f) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:shell\n", file, name); log_fatal("Failed to run '%s' (from popen).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } - if (smartctl_attribute(f, file, name, smart, info, serial, vendor, model) != 0) { + if (smartctl_attribute(f, file, name, smart, serial, vendor, model) != 0) { /* LCOV_EXCL_START */ pclose(f); - log_tag("device:%s:%s:shell\n", file, name); return -1; /* LCOV_EXCL_STOP */ } @@ -1188,14 +1186,12 @@ static int devsmart(dev_t device, const char* name, const char* smartctl, uint64 if (!WIFEXITED(ret)) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:error:abort\n", file, name); log_fatal("Failed to run '%s' (not exited).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } if (WEXITSTATUS(ret) == 127) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:shell\n", file, name); log_fatal("Failed to run '%s' (from sh).\n", cmd); return -1; /* LCOV_EXCL_STOP */ @@ -1212,7 +1208,7 @@ static int devsmart(dev_t device, const char* name, const char* smartctl, uint64 * Get POWER state. */ #if HAVE_LINUX_DEVICE -static int devprobe(dev_t device, const char* name, const char* smartctl, int* power, uint64_t* info, char* serial, char* vendor, char* model) +static int devprobe(dev_t device, const char* name, const char* smartctl, int* power) { char cmd[PATH_MAX + 64]; char file[PATH_MAX]; @@ -1240,16 +1236,14 @@ static int devprobe(dev_t device, const char* name, const char* smartctl, int* p f = popen(cmd, "r"); if (!f) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:shell\n", file, name); log_fatal("Failed to run '%s' (from popen).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } - if (smartctl_attribute(f, file, name, 0, info, serial, vendor, model) != 0) { + if (smartctl_flush(f, file, name) != 0) { /* LCOV_EXCL_START */ pclose(f); - log_tag("device:%s:%s:shell\n", file, name); return -1; /* LCOV_EXCL_STOP */ } @@ -1260,27 +1254,22 @@ static int devprobe(dev_t device, const char* name, const char* smartctl, int* p if (!WIFEXITED(ret)) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:abort\n", file, name); log_fatal("Failed to run '%s' (not exited).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } if (WEXITSTATUS(ret) == 127) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:shell\n", file, name); log_fatal("Failed to run '%s' (from sh).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } if (WEXITSTATUS(ret) == 0) { - log_tag("device:%s:%s:active\n", file, name); *power = POWER_ACTIVE; } else if (WEXITSTATUS(ret) == 3) { - log_tag("device:%s:%s:standby\n", file, name); *power = POWER_STANDBY; } else { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:exit:%d\n", file, name, WEXITSTATUS(ret)); log_fatal("Failed to run '%s' with return code %xh.\n", cmd, WEXITSTATUS(ret)); return -1; /* LCOV_EXCL_STOP */ @@ -1322,7 +1311,6 @@ static int devdown(dev_t device, const char* name, const char* smartctl) f = popen(cmd, "r"); if (!f) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:shell\n", file, name); log_fatal("Failed to run '%s' (from popen).\n", cmd); return -1; /* LCOV_EXCL_STOP */ @@ -1331,7 +1319,6 @@ static int devdown(dev_t device, const char* name, const char* smartctl) if (smartctl_flush(f, file, name) != 0) { /* LCOV_EXCL_START */ pclose(f); - log_tag("device:%s:%s:shell\n", file, name); return -1; /* LCOV_EXCL_STOP */ } @@ -1342,28 +1329,23 @@ static int devdown(dev_t device, const char* name, const char* smartctl) if (!WIFEXITED(ret)) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:abort\n", file, name); log_fatal("Failed to run '%s' (not exited).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } if (WEXITSTATUS(ret) == 127) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:shell\n", file, name); log_fatal("Failed to run '%s' (from sh).\n", cmd); return -1; /* LCOV_EXCL_STOP */ } if (WEXITSTATUS(ret) != 0) { /* LCOV_EXCL_START */ - log_tag("device:%s:%s:exit:%d\n", file, name, WEXITSTATUS(ret)); log_fatal("Failed to run '%s' with return code %xh.\n", cmd, WEXITSTATUS(ret)); return -1; /* LCOV_EXCL_STOP */ } - log_tag("device:%s:%s:down\n", file, name); - return 0; } #endif @@ -1376,7 +1358,7 @@ static int devdownifup(dev_t device, const char* name, const char* smartctl, int { *power = POWER_UNKNOWN; - if (devprobe(device, name, smartctl, power, 0, 0, 0, 0) != 0) + if (devprobe(device, name, smartctl, power) != 0) return -1; if (*power == POWER_ACTIVE) @@ -1390,7 +1372,7 @@ static int devdownifup(dev_t device, const char* name, const char* smartctl, int * Spin up a specific device. */ #if HAVE_LINUX_DEVICE -static int devup(dev_t device, const char* name) +static int devup(dev_t device) { char file[PATH_MAX]; int ret; @@ -1416,7 +1398,6 @@ static int devup(dev_t device, const char* name) if (f < 0) { /* LCOV_EXCL_START */ free(buf); - log_tag("device:%s:%s:error:%d\n", file, name, errno); log_fatal("Failed to open device '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ @@ -1427,7 +1408,6 @@ static int devup(dev_t device, const char* name) /* LCOV_EXCL_START */ close(f); free(buf); - log_tag("device:%s:%s:error:%d\n", file, name, errno); log_fatal("Failed to read device '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ @@ -1437,14 +1417,11 @@ static int devup(dev_t device, const char* name) if (ret < 0) { /* LCOV_EXCL_START */ free(buf); - log_tag("device:%s:%s:error:%d\n", file, name, errno); log_fatal("Failed to close device '%u:%u'.\n", major(device), minor(device)); return -1; /* LCOV_EXCL_STOP */ } - log_tag("device:%s:%s:up\n", file, name); - free(buf); return 0; } @@ -1465,7 +1442,7 @@ static void* thread_spinup(void* arg) start = tick_ms(); - if (devup(devinfo->device, devinfo->name) != 0) { + if (devup(devinfo->device) != 0) { /* LCOV_EXCL_START */ return (void*)-1; /* LCOV_EXCL_STOP */ @@ -1542,7 +1519,7 @@ static void* thread_smart(void* arg) #if HAVE_LINUX_DEVICE devinfo_t* devinfo = arg; - if (devsmart(devinfo->device, devinfo->name, devinfo->smartctl, devinfo->smart, devinfo->info, devinfo->serial, devinfo->vendor, devinfo->model) != 0) { + if (devsmart(devinfo->device, devinfo->name, devinfo->smartctl, devinfo->smart, devinfo->smart_serial, devinfo->smart_vendor, devinfo->smart_model) != 0) { /* LCOV_EXCL_START */ return (void*)-1; /* LCOV_EXCL_STOP */ @@ -1563,7 +1540,7 @@ static void* thread_probe(void* arg) #if HAVE_LINUX_DEVICE devinfo_t* devinfo = arg; - if (devprobe(devinfo->device, devinfo->name, devinfo->smartctl, &devinfo->power, devinfo->info, devinfo->serial, devinfo->vendor, devinfo->model) != 0) { + if (devprobe(devinfo->device, devinfo->name, devinfo->smartctl, &devinfo->power) != 0) { /* LCOV_EXCL_START */ return (void*)-1; /* LCOV_EXCL_STOP */ @@ -1812,7 +1789,6 @@ const char* AMBIENT_LABEL[] = { "systin", "auxtin", "mb", - "m/b", "board", "motherboard", "system", diff --git a/doc/snapraid_log.1 b/doc/snapraid_log.1 index d4fdab70..a73dacab 100644 --- a/doc/snapraid_log.1 +++ b/doc/snapraid_log.1 @@ -146,7 +146,7 @@ The absolute path to a content file being used (escaped). Content files store the metadata (like file hashes and timestamps) for the array. .TP -.B content_parity::::::: +.B content::::: The parity files as stored in the content file. .RS 4 .PD 0 @@ -154,53 +154,23 @@ The parity files as stored in the content file. .I One of \`parity\`, \`2\-parity\`, ..., \`6\-parity\`. .HP 4 -.I -The size of the data in the disk. -.HP 4 -.I -The free size in the disk at the time of the -latest \`sync\`. -.HP 4 .I The split index (uint). If no multiple split parity is configured, there is only the index 0. .HP 4 -.I -The UUID of the disk containing the path. -.HP 4 .I The path (escaped). .HP 4 -.I +.I +The UUID of the partition containing the path. +.HP 4 +.I The size of the parity file. Size is \-1 if not yet fixed, meaning it can grow. This happens for the latest split. .PD .RE -.TP -.B content_disk::::: -The data disk as stored in the content file. -.RS 4 -.PD 0 -.HP 4 -.I -Name of the data disk. -.HP 4 -.I -The size of the data in the disk. -.HP 4 -.I -The free size in the disk at the time of the -latest \`sync\`. -.HP 4 -.I -The disk position in the parity computation. -.HP 4 -.I -The UUID of the disk filesystem. -.PD -.RE .SH DIAGNOSTICS TAGS .TP .B version: @@ -1540,11 +1510,7 @@ The rotation rate (uint64, RPM). .RE .TP .B attr:::flags:: -Logs the SMART status flags from the \`smartctl\` utility. -Per the smartctl manpage, these flags are bit\-mapped -to indicate specific issues like \[dq]Command line did not parse\[dq], -\[dq]Device could not be opened\[dq], or \[dq]SMART status check -returned \'DISK FAILING\'\[dq]. +Logs the SMART status flags from the utility (e.g., smartctl). .RS 4 .PD 0 .HP 4 @@ -1591,68 +1557,30 @@ The probability of at least one disk failure in .RS 4 the next year (double). .RE -.SH DEVICE STATUS TAGS -These tags log the lifecycle of hardware interactions and external -command execution. They are primarily output during the \`up\` -(spin\-up), \`down\` (spin\-down), and \`probe\` (power state check) -commands. +.SH COMMAND PROBE TAGS +This section describes the tags output with the \`probe\` command. +.PP +Note that a \`\` may be associated with more \`\`, +in case the logical disk uses more physical disks. In such a case, +you\'ll see multiple tags for the same \`\` but with different +\`\`. +.SS Device Power State +Tags used to report the power state of each device. .TP -.B device:::active -Logs that the device was confirmed to be in an active power -state after a status probe. +.B probe::: +Logs the detected power state of a device. .RS 4 .PD 0 .HP 4 .I -The system path to the device node. +The file path of the device (e.g., /dev/sdb). .HP 4 .I -The SnapRAID internal disk disk_name. -.PD -.RE -.TP -.B device:::standby -Logs that the device was confirmed to be in a standby/spun\-down -state. -.TP -.B device:::up -Logs a successful spin\-up operation via direct O_DIRECT -read. -.TP -.B device:::down -Logs a successful spin\-down operation initiated via the -smartctl command. -.TP -.B device:::shell -Logs a failure in the command shell execution environment. -.TP -.B device:::error: -Logs a low\-level system error during direct file operations. -This is triggered when open(), read(), or close() -calls fail during a spin\-up attempt. -.RS 4 -.PD 0 +The configured name of the disk. .HP 4 -.I -The standard integer error number provided by -the OS. -.PD -.RE -.TP -.B device:::error:abort -Logs that an external process (smartctl) failed to complete -normally, such as being terminated by a signal rather than -exiting. -.TP -.B device:::exit: -Logs that the external command (smartctl) returned a non\-zero -exit code that was not explicitly recognized as a valid state. -.RS 4 -.PD 0 -.HP 4 -.I -The integer exit status returned by the -process. +.I +The numerical power state: 0: Unknown, +1: StandBy, 2: Active. .PD .RE .SH ERROR TAGS diff --git a/doc/snapraid_log.d b/doc/snapraid_log.d index ef65b629..f765095a 100644 --- a/doc/snapraid_log.d +++ b/doc/snapraid_log.d @@ -112,32 +112,19 @@ Configuration Tags Content files store the metadata (like file hashes and timestamps) for the array. - =content_parity::::::: + =content::::: The parity files as stored in the content file. - + - One of `parity`, `2-parity`, ..., `6-parity`. - - The size of the data in the disk. - - The free size in the disk at the time of the - latest `sync`. - The split index (uint). If no multiple split parity is configured, there is only the index 0. - - The UUID of the disk containing the path. - The path (escaped). - - The size of the parity file. Size is -1 if not yet + - The UUID of the partition containing the path. + - The size of the parity file. Size is -1 if not yet fixed, meaning it can grow. This happens for the latest split. - =content_disk::::: - The data disk as stored in the content file. - - - Name of the data disk. - - The size of the data in the disk. - - The free size in the disk at the time of the - latest `sync`. - - The disk position in the parity computation. - - The UUID of the disk filesystem. - Diagnostics Tags =version: The version of SnapRAID run. @@ -974,11 +961,7 @@ Command Smart Tags - The rotation rate (uint64, RPM). =attr:::flags:: - Logs the SMART status flags from the `smartctl` utility. - Per the smartctl manpage, these flags are bit-mapped - to indicate specific issues like "Command line did not parse", - "Device could not be opened", or "SMART status check - returned 'DISK FAILING'". + Logs the SMART status flags from the utility (e.g., smartctl). - The raw flags value (uint64, decimal). - The raw flags value (uint64, hexadecimal). @@ -1002,53 +985,24 @@ Command Smart Tags - The probability of at least one disk failure in the next year (double). -Device Status Tags - These tags log the lifecycle of hardware interactions and external - command execution. They are primarily output during the `up` - (spin-up), `down` (spin-down), and `probe` (power state check) - commands. +Command Probe Tags + This section describes the tags output with the `probe` command. - =device:::active - Logs that the device was confirmed to be in an active power - state after a status probe. + Note that a `` may be associated with more ``, + in case the logical disk uses more physical disks. In such a case, + you'll see multiple tags for the same `` but with different + ``. - - The system path to the device node. - - The SnapRAID internal disk disk_name. + Device Power State + Tags used to report the power state of each device. - =device:::standby - Logs that the device was confirmed to be in a standby/spun-down - state. + =probe::: + Logs the detected power state of a device. - =device:::up - Logs a successful spin-up operation via direct O_DIRECT - read. - - =device:::down - Logs a successful spin-down operation initiated via the - smartctl command. - - =device:::shell - Logs a failure in the command shell execution environment. - - =device:::error: - Logs a low-level system error during direct file operations. - This is triggered when open(), read(), or close() - calls fail during a spin-up attempt. - - - The standard integer error number provided by - the OS. - - =device:::error:abort - Logs that an external process (smartctl) failed to complete - normally, such as being terminated by a signal rather than - exiting. - - =device:::exit: - Logs that the external command (smartctl) returned a non-zero - exit code that was not explicitly recognized as a valid state. - - - The integer exit status returned by the - process. + - The file path of the device (e.g., /dev/sdb). + - The configured name of the disk. + - The numerical power state: 0: Unknown, + 1: StandBy, 2: Active. Error Tags These tags report specific errors that occur on data disks during the diff --git a/doc/snapraid_log.txt b/doc/snapraid_log.txt index 30e1bf0f..fef52b9a 100644 --- a/doc/snapraid_log.txt +++ b/doc/snapraid_log.txt @@ -118,32 +118,19 @@ scanning the disk and reading the list of files. Content files store the metadata (like file hashes and timestamps) for the array. - content_parity::::::: + content::::: The parity files as stored in the content file. - One of `parity`, `2-parity`, ..., `6-parity`. - - The size of the data in the disk. - - The free size in the disk at the time of the - latest `sync`. - The split index (uint). If no multiple split parity is configured, there is only the index 0. - - The UUID of the disk containing the path. - The path (escaped). - - The size of the parity file. Size is -1 if not yet + - The UUID of the partition containing the path. + - The size of the parity file. Size is -1 if not yet fixed, meaning it can grow. This happens for the latest split. - content_disk::::: - The data disk as stored in the content file. - - - Name of the data disk. - - The size of the data in the disk. - - The free size in the disk at the time of the - latest `sync`. - - The disk position in the parity computation. - - The UUID of the disk filesystem. - 3 DIAGNOSTICS TAGS ================== @@ -1016,11 +1003,7 @@ values. - The rotation rate (uint64, RPM). attr:::flags:: - Logs the SMART status flags from the `smartctl` utility. - Per the smartctl manpage, these flags are bit-mapped - to indicate specific issues like "Command line did not parse", - "Device could not be opened", or "SMART status check - returned 'DISK FAILING'". + Logs the SMART status flags from the utility (e.g., smartctl). - The raw flags value (uint64, decimal). - The raw flags value (uint64, hexadecimal). @@ -1045,55 +1028,26 @@ Tags logging the overall failure probabilities for the array. the next year (double). -15 DEVICE STATUS TAGS +15 COMMAND PROBE TAGS ===================== -These tags log the lifecycle of hardware interactions and external -command execution. They are primarily output during the `up` -(spin-up), `down` (spin-down), and `probe` (power state check) -commands. +This section describes the tags output with the `probe` command. - device:::active - Logs that the device was confirmed to be in an active power - state after a status probe. +Note that a `` may be associated with more ``, +in case the logical disk uses more physical disks. In such a case, +you'll see multiple tags for the same `` but with different +``. - - The system path to the device node. - - The SnapRAID internal disk disk_name. +---- 15.0.1 Device Power State ---- +Tags used to report the power state of each device. - device:::standby - Logs that the device was confirmed to be in a standby/spun-down - state. + probe::: + Logs the detected power state of a device. - device:::up - Logs a successful spin-up operation via direct O_DIRECT - read. - - device:::down - Logs a successful spin-down operation initiated via the - smartctl command. - - device:::shell - Logs a failure in the command shell execution environment. - - device:::error: - Logs a low-level system error during direct file operations. - This is triggered when open(), read(), or close() - calls fail during a spin-up attempt. - - - The standard integer error number provided by - the OS. - - device:::error:abort - Logs that an external process (smartctl) failed to complete - normally, such as being terminated by a signal rather than - exiting. - - device:::exit: - Logs that the external command (smartctl) returned a non-zero - exit code that was not explicitly recognized as a valid state. - - - The integer exit status returned by the - process. + - The file path of the device (e.g., /dev/sdb). + - The configured name of the disk. + - The numerical power state: 0: Unknown, + 1: StandBy, 2: Active. 16 ERROR TAGS