Restore support for older gcc and glibc
cover Restore support for older gcc and glibc
Hi Keith,
The three patches in this series fix recently introduced regressions for older gcc / glibc versions and fix more endianness issues. Please consider these patches.
Thanks,
Bart.
Bart Van Assche (3):
nvme-cli: Restore support for older gcc versions
nvme-cli: Restore RHEL 7 compatibility
nvme-cli: Fix more endianness issues
fabrics.c | 2 +- linux/nvme.h | 9 ++-- nvme-ioctl.c | 30 ++++++------- nvme-print.c | 53 ++++++++++++++--------- nvme.c | 2 +- nvme.h | 54 ++++++++++++++--------- plugins/intel/intel-nvme.c | 16 +++---- plugins/virtium/virtium-nvme.c | 2 +- plugins/wdc/wdc-nvme.c | 79 +++++++++++++++++----------------- 9 files changed, 136 insertions(+), 111 deletions(-)
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH 1/3 nvme-cli: Restore support for older gcc versions
Older versions of gcc do not support initializing another than the first member of a union in an initializer. Rewrite some code such that support for older gcc versions is restored.
--- nvme-ioctl.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
nvme-ioctl.c +15 -15
@@ -576,16 +576,16 @@ static void nvme_to_passthru_cmd(struct nvme_passthru_cmd *pcmd,int nvme_get_property (int fd,int offset,uint64_t *value) {struct nvme_passthru_cmd pcmd; -struct nvme_command gcmd = { - .prop_get = { - .opcode = nvme_fabrics_command, - .fctype = nvme_fabrics_type_property_get, - .offset =cpu_to_le32 (offset), - .attrib =is_64bit_reg (offset), - } +struct nvmf_property_get_command pg = { + .opcode = nvme_fabrics_command, + .fctype = nvme_fabrics_type_property_get, + .offset =cpu_to_le32 (offset), + .attrib =is_64bit_reg (offset), }; +struct nvme_command gcmd;int err; + gcmd.prop_get = pg;nvme_to_passthru_cmd (&pcmd, &gcmd); err =nvme_submit_admin_passthru (fd, &pcmd);if (!err) {
@@ -635,17 +635,17 @@ int nvme_get_properties(int fd, void **pbar)int nvme_set_property (int fd,int offset,uint64_t value) { -struct nvme_command scmd = { - .prop_set = { - .opcode = nvme_fabrics_command, - .fctype = nvme_fabrics_type_property_set, - .offset =cpu_to_le32 (offset), - .value =cpu_to_le64 (value), - .attrib =is_64bit_reg (offset), - } +struct nvmf_property_set_command ps = { + .opcode = nvme_fabrics_command, + .fctype = nvme_fabrics_type_property_set, + .offset =cpu_to_le32 (offset), + .value =cpu_to_le64 (value), + .attrib =is_64bit_reg (offset), }; +struct nvme_command scmd;struct nvme_passthru_cmd pcmd; + scmd.prop_set = ps;nvme_to_passthru_cmd (&pcmd, &scmd);return nvme_submit_admin_passthru (fd, &pcmd); }
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH 1/3 nvme-cli: Restore support for older gcc versions
It looks good to me:
PATCH 2/3 nvme-cli: Restore RHEL 7 compatibility
In reply to Bart Van AsscheWith glibc version 2.24 and before the endianness conversion macros return a value with an incorrect type. Avoid that this causes the nvme-cli build to fail on e.g. RHEL 7. A side effect of this patch is that it allows sparse to verify the type of the endianness conversion functions.
See also https://sourceware.org/bugzilla/show_bug.cgi?id=16458
--- nvme.h | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-)
nvme.h +25 -13
@@ -119,19 +119,31 @@ struct nvme_bar_cap {#define __force#endif -#define cpu_to_le16 (x) \ - ((__force __le16)htole16(x)) -#define cpu_to_le32 (x) \ - ((__force __le32)htole32(x)) -#define cpu_to_le64 (x) \ - ((__force __le64)htole64(x)) - -#define le16_to_cpu (x) \ - le16toh((__force __u16)(x)) -#define le32_to_cpu (x) \ - le32toh((__force __u32)(x)) -#define le64_to_cpu (x) \ - le64toh((__force __u64)(x)) +static inline __le16 cpu_to_le16 (uint16_t x) +{ +return (__force __le16 )htole16 (x); +} +static inline __le32 cpu_to_le32 (uint32_t x) +{ +return (__force __le32 )htole32 (x); +} +static inline __le64 cpu_to_le64 (uint64_t x) +{ +return (__force __le64 )htole64 (x); +} + +static inline uint16_t le16_to_cpu (__le16 x) +{ +return le16toh ((__force __u16 )x); +} +static inline uint32_t le32_to_cpu (__le32 x) +{ +return le32toh ((__force __u32 )x); +} +static inline uint64_t le64_to_cpu (__le64 x) +{ +return le64toh ((__force __u64 )x); +}#define MAX_LIST_ITEMS 256struct list_item {
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog
PATCH 2/3 nvme-cli: Restore RHEL 7 compatibility
Quoted 6 lines · Bart Van Assche
With glibc version 2.24 and before the endianness conversion macros return a value with an incorrect type. Avoid that this causes the nvme-cli build to fail on e.g. RHEL 7. A side effect of this patch is that it allows sparse to verify the type of the endianness conversion functions.
Quoted 7 lines
See also https://sourceware.org/bugzilla/show_bug.cgi?id=16458
Cc Mikhail Skorzhinskii <mskorzhinskiy at solarflare.com>Cc Minwoo Im <minwoo.im.dev at gmail.com>Reported-by Mikhail Skorzhinskii <mskorzhinskiy at solarflare.com>Fixes e68409e447b2 ("Remove superfluous casts")Signed-off-by Bart Van Assche <bvanassche at acm.org>
Not only for REHL 7, Ubuntu 16.04 which is my VM has had same issue :)
Also for the build:
PATCH 3/3 nvme-cli: Fix more endianness issues
In reply to Bart Van AsscheDeclare little endian variables as __le*. Use the proper le*_to_cpu() conversion functions for little endian integers. Do not use le*_to_cpu() for variables of type uint8_t.
--- fabrics.c | 2 +- linux/nvme.h | 9 ++-- nvme-print.c | 53 ++++++++++++++--------- nvme.c | 2 +- nvme.h | 16 +++---- plugins/intel/intel-nvme.c | 16 +++---- plugins/virtium/virtium-nvme.c | 2 +- plugins/wdc/wdc-nvme.c | 79 +++++++++++++++++----------------- 8 files changed, 96 insertions(+), 83 deletions(-)
fabrics.c +1 -1
@@ -397,7 +397,7 @@ static int nvmf_get_log_page_discovery(const char *dev_path, goto out_free_log; } -if (*numrec !=le32_to_cpu (log->numrec)) { +if (*numrec !=le64_to_cpu (log->numrec)) { error =DISC_NOT_EQUAL ; goto out_free_log; }
linux/nvme.h +5 -4
@@ -616,12 +616,13 @@ enum { NVME_LBART_ATTRIB_HIDE = 1 << 1, }; +/* Predictable Latency Mode - Deterministic Threshold Configuration Data */ struct nvme_plm_config { -__u16 enable_event; +__le16 enable_event;__u8 rsvd2[30 ]; -__u64 dtwin_reads_thresh; -__u64 dtwin_writes_thresh; -__u64 dtwin_time_thresh; +__le64 dtwin_reads_thresh; +__le64 dtwin_writes_thresh; +__le64 dtwin_time_thresh;__u8 rsvd56[456 ]; };
nvme-print.c +32 -21
119 lines not on this page · raw message
nvme.c +1 -1
@@ -986,7 +986,7 @@ static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *plconst char *namespace_id ="first nsid returned list should start from" ;const char *all ="show all namespaces in the subsystem, whether attached or inactive" ;int err, i, fd; -__u32 ns_list[1024 ]; +__le32 ns_list[1024 ];struct config {__u32 namespace_id;
nvme.h +8 -8
@@ -40,16 +40,16 @@ struct nvme_effects_log_page { };struct nvme_error_log_page { -__u64 error_count; -__u16 sqid; -__u16 cmdid; -__u16 status_field; -__u16 parm_error_location; -__u64 lba; -__u32 nsid; +__le64 error_count; +__le16 sqid; +__le16 cmdid; +__le16 status_field; +__le16 parm_error_location; +__le64 lba; +__le32 nsid;__u8 vs;__u8 resv[3 ]; -__u64 cs; +__le64 cs;__u8 resv2[24 ]; };
plugins/intel/intel-nvme.c +8 -8
@@ -307,15 +307,15 @@ static int get_market_log(int argc, char **argv, struct command *cmd, struct plustruct intel_temp_stats { -__u64 curr; -__u64 last_overtemp; -__u64 life_overtemp; -__u64 highest_temp; -__u64 lowest_temp; +__le64 curr; +__le64 last_overtemp; +__le64 life_overtemp; +__le64 highest_temp; +__le64 lowest_temp;__u8 rsvd[40 ]; -__u64 max_operating_temp; -__u64 min_operating_temp; -__u64 est_offset; +__le64 max_operating_temp; +__le64 min_operating_temp; +__le64 est_offset; };static void show_temp_stats (struct intel_temp_stats *stats)
plugins/virtium/virtium-nvme.c +1 -1
@@ -727,7 +727,7 @@ static void vt_parse_detail_identify(const struct nvme_id_ctrl *ctrl)vt_convert_data_buffer_to_hex_string (&buf[326 ],2 , true, s);printf (" \"Maximum Thermal Management Temperature\":\"%sh\",\n" , s); - temp =le16_to_cpu (ctrl->sanicap); + temp =le32_to_cpu (ctrl->sanicap);printf (" \"Sanitize Capabilities\":{\n" );vt_convert_data_buffer_to_hex_string (&buf[328 ],2 , true, s);printf (" \"Value\":\"%sh\",\n" , s);
plugins/wdc/wdc-nvme.c +40 -39
187 lines not on this page · raw message
Signature · 1 line
2.22.0.410.gd8fdbe21b5-goog