Skip to content

Commit

Permalink
Merge pull request collectd#4165 from octo/netlink/valgrind_issue
Browse files Browse the repository at this point in the history
Netlink plugin: complete initialize structs used for testing.
  • Loading branch information
octo authored Nov 25, 2023
2 parents f45a71a + 16db68e commit ee96176
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 101 deletions.
35 changes: 16 additions & 19 deletions src/netlink_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,25 +213,22 @@ DEF_TEST(ignorelist_test) {
#ifdef HAVE_IFLA_VF_STATS
DEF_TEST(vf_submit_test) {
const char *test_dev = "eth0";
vf_stats_t test_stats;
struct ifla_vf_mac test_mac;
test_mac.mac[0] = 0x01;
test_mac.mac[1] = 0x1a;
test_mac.mac[2] = 0x2b;
test_mac.mac[3] = 0x3c;
test_mac.mac[4] = 0x4d;
test_mac.mac[5] = 0x5e;
test_mac.vf = 2;
test_stats.vf_mac = &test_mac;
test_stats.vlan = 100;
test_stats.spoofcheck = 1;
test_stats.link_state = 2;
test_stats.broadcast = 1234;
test_stats.multicast = 0;
test_stats.rx_packets = 21110;
test_stats.tx_packets = 31110;
test_stats.rx_bytes = 4294967295;
test_stats.tx_bytes = 8;
vf_stats_t test_stats = {
.vf_mac =
&(struct ifla_vf_mac){
.mac = {0x01, 0x1a, 0x2b, 0x3c, 0x4d, 0x5e},
.vf = 2,
},
.vlan = 100,
.spoofcheck = 1,
.link_state = 2,
.broadcast = 1234,
.multicast = 0,
.rx_packets = 21110,
.tx_packets = 31110,
.rx_bytes = 4294967295,
.tx_bytes = 8,
};

g_instance[0] = '\0';
vf_info_submit(test_dev, &test_stats);
Expand Down
156 changes: 74 additions & 82 deletions src/smart.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,7 @@ static int smart_read_nvme_disk(const char *dev, char const *name) {
}

static int smart_read_nvme_intel_disk(const char *dev, char const *name) {

DEBUG("name = %s", name);
DEBUG("dev = %s", dev);

struct nvme_additional_smart_log intel_smart_log;
int fd, status;
fd = open(dev, O_RDWR);
int fd = open(dev, O_RDWR);
if (fd < 0) {
ERROR(PLUGIN_NAME ": open failed with %s\n", strerror(errno));
return fd;
Expand All @@ -400,88 +394,86 @@ static int smart_read_nvme_intel_disk(const char *dev, char const *name) {
* - Additional SMART Attributes (Log Identfiter CAh)
*/

status =
ioctl(fd, NVME_IOCTL_ADMIN_CMD,
&(struct nvme_admin_cmd){.opcode = NVME_ADMIN_GET_LOG_PAGE,
.nsid = NVME_NSID_ALL,
.addr = (unsigned long)&intel_smart_log,
.data_len = sizeof(intel_smart_log),
.cdw10 = NVME_SMART_INTEL_CDW10});
struct nvme_additional_smart_log intel_smart_log = {0};
int status = ioctl(fd, NVME_IOCTL_ADMIN_CMD,
&(struct nvme_admin_cmd){
.opcode = NVME_ADMIN_GET_LOG_PAGE,
.nsid = NVME_NSID_ALL,
.addr = (unsigned long)&intel_smart_log,
.data_len = sizeof(intel_smart_log),
.cdw10 = NVME_SMART_INTEL_CDW10,
});
if (status < 0) {
ERROR(PLUGIN_NAME ": ioctl for NVME_IOCTL_ADMIN_CMD failed with %s\n",
strerror(errno));
close(fd);
return status;
} else {

smart_submit(name, "nvme_program_fail_count", "norm",
(double)intel_smart_log.program_fail_cnt.norm);
smart_submit(name, "nvme_program_fail_count", "raw",
int48_to_double(intel_smart_log.program_fail_cnt.raw));
smart_submit(name, "nvme_erase_fail_count", "norm",
(double)intel_smart_log.erase_fail_cnt.norm);
smart_submit(name, "nvme_erase_fail_count", "raw",
int48_to_double(intel_smart_log.program_fail_cnt.raw));
smart_submit(name, "nvme_wear_leveling", "norm",
(double)intel_smart_log.wear_leveling_cnt.norm);
smart_submit(
name, "nvme_wear_leveling", "min",
(double)le16_to_cpu(intel_smart_log.wear_leveling_cnt.wear_level.min));
smart_submit(
name, "nvme_wear_leveling", "max",
(double)le16_to_cpu(intel_smart_log.wear_leveling_cnt.wear_level.max));
smart_submit(
name, "nvme_wear_leveling", "avg",
(double)le16_to_cpu(intel_smart_log.wear_leveling_cnt.wear_level.avg));
smart_submit(name, "nvme_end_to_end_error_detection_count", "norm",
(double)intel_smart_log.e2e_err_cnt.norm);
smart_submit(name, "nvme_end_to_end_error_detection_count", "raw",
int48_to_double(intel_smart_log.e2e_err_cnt.raw));
smart_submit(name, "nvme_crc_error_count", "norm",
(double)intel_smart_log.crc_err_cnt.norm);
smart_submit(name, "nvme_crc_error_count", "raw",
int48_to_double(intel_smart_log.crc_err_cnt.raw));
smart_submit(name, "nvme_timed_workload_media_wear", "norm",
(double)intel_smart_log.timed_workload_media_wear.norm);
smart_submit(
name, "nvme_timed_workload_media_wear", "raw",
int48_to_double(intel_smart_log.timed_workload_media_wear.raw));
smart_submit(name, "nvme_timed_workload_host_reads", "norm",
(double)intel_smart_log.timed_workload_host_reads.norm);
smart_submit(
name, "nvme_timed_workload_host_reads", "raw",
int48_to_double(intel_smart_log.timed_workload_host_reads.raw));
smart_submit(name, "nvme_timed_workload_timer", "norm",
(double)intel_smart_log.timed_workload_timer.norm);
smart_submit(name, "nvme_timed_workload_timer", "raw",
int48_to_double(intel_smart_log.timed_workload_timer.raw));
smart_submit(name, "nvme_thermal_throttle_status", "norm",
(double)intel_smart_log.thermal_throttle_status.norm);
smart_submit(
name, "nvme_thermal_throttle_status", "pct",
(double)intel_smart_log.thermal_throttle_status.thermal_throttle.pct);
smart_submit(
name, "nvme_thermal_throttle_status", "count",
(double)intel_smart_log.thermal_throttle_status.thermal_throttle.count);
smart_submit(name, "nvme_retry_buffer_overflow_count", "norm",
(double)intel_smart_log.retry_buffer_overflow_cnt.norm);
smart_submit(
name, "nvme_retry_buffer_overflow_count", "raw",
int48_to_double(intel_smart_log.retry_buffer_overflow_cnt.raw));
smart_submit(name, "nvme_pll_lock_loss_count", "norm",
(double)intel_smart_log.pll_lock_loss_cnt.norm);
smart_submit(name, "nvme_pll_lock_loss_count", "raw",
int48_to_double(intel_smart_log.pll_lock_loss_cnt.raw));
smart_submit(name, "nvme_nand_bytes_written", "norm",
(double)intel_smart_log.host_bytes_written.norm);
smart_submit(name, "nvme_nand_bytes_written", "raw",
int48_to_double(intel_smart_log.host_bytes_written.raw));
smart_submit(name, "nvme_host_bytes_written", "norm",
(double)intel_smart_log.host_bytes_written.norm);
smart_submit(name, "nvme_host_bytes_written", "raw",
int48_to_double(intel_smart_log.host_bytes_written.raw));
}

smart_submit(name, "nvme_program_fail_count", "norm",
(double)intel_smart_log.program_fail_cnt.norm);
smart_submit(name, "nvme_program_fail_count", "raw",
int48_to_double(intel_smart_log.program_fail_cnt.raw));
smart_submit(name, "nvme_erase_fail_count", "norm",
(double)intel_smart_log.erase_fail_cnt.norm);
smart_submit(name, "nvme_erase_fail_count", "raw",
int48_to_double(intel_smart_log.program_fail_cnt.raw));
smart_submit(name, "nvme_wear_leveling", "norm",
(double)intel_smart_log.wear_leveling_cnt.norm);
smart_submit(
name, "nvme_wear_leveling", "min",
(double)le16_to_cpu(intel_smart_log.wear_leveling_cnt.wear_level.min));
smart_submit(
name, "nvme_wear_leveling", "max",
(double)le16_to_cpu(intel_smart_log.wear_leveling_cnt.wear_level.max));
smart_submit(
name, "nvme_wear_leveling", "avg",
(double)le16_to_cpu(intel_smart_log.wear_leveling_cnt.wear_level.avg));
smart_submit(name, "nvme_end_to_end_error_detection_count", "norm",
(double)intel_smart_log.e2e_err_cnt.norm);
smart_submit(name, "nvme_end_to_end_error_detection_count", "raw",
int48_to_double(intel_smart_log.e2e_err_cnt.raw));
smart_submit(name, "nvme_crc_error_count", "norm",
(double)intel_smart_log.crc_err_cnt.norm);
smart_submit(name, "nvme_crc_error_count", "raw",
int48_to_double(intel_smart_log.crc_err_cnt.raw));
smart_submit(name, "nvme_timed_workload_media_wear", "norm",
(double)intel_smart_log.timed_workload_media_wear.norm);
smart_submit(name, "nvme_timed_workload_media_wear", "raw",
int48_to_double(intel_smart_log.timed_workload_media_wear.raw));
smart_submit(name, "nvme_timed_workload_host_reads", "norm",
(double)intel_smart_log.timed_workload_host_reads.norm);
smart_submit(name, "nvme_timed_workload_host_reads", "raw",
int48_to_double(intel_smart_log.timed_workload_host_reads.raw));
smart_submit(name, "nvme_timed_workload_timer", "norm",
(double)intel_smart_log.timed_workload_timer.norm);
smart_submit(name, "nvme_timed_workload_timer", "raw",
int48_to_double(intel_smart_log.timed_workload_timer.raw));
smart_submit(name, "nvme_thermal_throttle_status", "norm",
(double)intel_smart_log.thermal_throttle_status.norm);
smart_submit(
name, "nvme_thermal_throttle_status", "pct",
(double)intel_smart_log.thermal_throttle_status.thermal_throttle.pct);
smart_submit(
name, "nvme_thermal_throttle_status", "count",
(double)intel_smart_log.thermal_throttle_status.thermal_throttle.count);
smart_submit(name, "nvme_retry_buffer_overflow_count", "norm",
(double)intel_smart_log.retry_buffer_overflow_cnt.norm);
smart_submit(name, "nvme_retry_buffer_overflow_count", "raw",
int48_to_double(intel_smart_log.retry_buffer_overflow_cnt.raw));
smart_submit(name, "nvme_pll_lock_loss_count", "norm",
(double)intel_smart_log.pll_lock_loss_cnt.norm);
smart_submit(name, "nvme_pll_lock_loss_count", "raw",
int48_to_double(intel_smart_log.pll_lock_loss_cnt.raw));
smart_submit(name, "nvme_nand_bytes_written", "norm",
(double)intel_smart_log.host_bytes_written.norm);
smart_submit(name, "nvme_nand_bytes_written", "raw",
int48_to_double(intel_smart_log.host_bytes_written.raw));
smart_submit(name, "nvme_host_bytes_written", "norm",
(double)intel_smart_log.host_bytes_written.norm);
smart_submit(name, "nvme_host_bytes_written", "raw",
int48_to_double(intel_smart_log.host_bytes_written.raw));

close(fd);
return 0;
}
Expand Down

0 comments on commit ee96176

Please sign in to comment.