+/**
+ * collectd - src/intel-nvme.h
+ * MIT License
+ *
+ * Copyright (C) 2020 Intel Corporation. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Bartlomiej Kotlowski <bartlomiej.kotlowski@intel.com>
+ * **/
+
#include <linux/types.h>
#ifdef __CHECKER__
+/**
+ * collectd - src/nvme.h
+ * MIT License
+ *
+ * Copyright (C) 2020 Intel Corporation. All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Bartlomiej Kotlowski <bartlomiej.kotlowski@intel.com>
+ * **/
+
#include <linux/types.h>
#define NVME_NSID_ALL 0xffffffff
#define O_RDWR 02
#define NVME_SMART_CDW10 0x00800002
-
+#define SHIFT_BYTE_LEFT 256
struct nvme_admin_cmd {
__u8 opcode;
__u8 rsvd1[3];
static inline double compute_field(__u8 *data) {
double sum = 0;
+ double add = 0;
- for (int i = 0; i < 16; i++)
- sum += data[i] << (i * 8);
-
+ for (int i = 0; i < 16; i++) {
+ add = data[15 - i];
+ for (int j = i + 1; j < 16; j++) {
+ add *= SHIFT_BYTE_LEFT;
+ }
+ sum += add;
+ }
return sum;
}
+
static inline double int48_to_double(__u8 *data) {
double sum = 0;
+ double add = 0;
for (int i = 0; i < 6; i++) {
- sum += data[i] << (i * 8);
+ add = data[5 - i];
+ for (int j = i + 1; j < 6; j++) {
+ add *= SHIFT_BYTE_LEFT;
+ }
+ sum += add;
}
return sum;
}
/**
* collectd - src/smart_test.c
- * Copyright (C) 2018 Intel Corporation. All rights reserved.
+ * MIT License
+ *
+ * Copyright (C) 2020 Intel Corporation. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
#include "testing.h"
int VENDOR_ID = 0x8086;
-char *CORRET_DEV_PATH = "/dev/nvme0n1";
+char *CORRECT_DEV_PATH = "/dev/nvme0n1";
int ioctl(int __fd, unsigned long int __request, ...) {
va_list valist;
};
int open(const char *__path, int __oflag, ...) {
- if (__path == CORRET_DEV_PATH) {
+ if (__path == CORRECT_DEV_PATH) {
return 0;
}
return -1;
DEF_TEST(x) {
int ret;
- ret = get_vendor_id(CORRET_DEV_PATH, "stub");
+ ret = get_vendor_id(CORRECT_DEV_PATH, "stub");
EXPECT_EQ_INT(VENDOR_ID, ret);
VENDOR_ID = 0x144D;
- ret = get_vendor_id(CORRET_DEV_PATH, "stub");
+ ret = get_vendor_id(CORRECT_DEV_PATH, "stub");
EXPECT_EQ_INT(VENDOR_ID, ret);
VENDOR_ID = 0x8086;
ret = get_vendor_id("dev/nvme0nXX", "stub");
EXPECT_EQ_INT(-1, ret);
- ret = smart_read_nvme_intel_disk(CORRET_DEV_PATH, "stub");
+ ret = smart_read_nvme_intel_disk(CORRECT_DEV_PATH, "stub");
EXPECT_EQ_INT(0, ret);
// incorrect with DEV_PATH
ret = smart_read_nvme_intel_disk("dev/nvme0nXX", "stub");
EXPECT_EQ_INT(-1, ret);
- CORRET_DEV_PATH = "dev/sda0";
+ CORRECT_DEV_PATH = "dev/sda0";
- ret = smart_read_nvme_disk(CORRET_DEV_PATH, "stub");
+ ret = smart_read_nvme_disk(CORRECT_DEV_PATH, "stub");
EXPECT_EQ_INT(0, ret);
// incorrect with DEV_PATH