Skip to content

Commit f6ed5bf

Browse files
Refactored errno and ifaddrs compatibility
- Moved missing error code definitions to util.c where they are used. - Refactored ENAVAIL usage in nvme.c to use a custom, local error code definition, since it was being used as an internal flag anyway. - Removed ifaddrs struct (not needed). - Cleaned up build warnings in ocp-nvme.c
1 parent 3824169 commit f6ed5bf

4 files changed

Lines changed: 17 additions & 29 deletions

File tree

libnvme/src/nvme/util.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99

1010
#include <errno.h>
1111
#include <fcntl.h>
12+
#include <malloc.h>
1213
#include <stdbool.h>
1314
#include <stdio.h>
15+
#include <stdlib.h>
1416
#include <string.h>
1517
#include <unistd.h>
1618

@@ -44,6 +46,13 @@
4446
#define LINE_MAX 2048
4547
#endif
4648

49+
/* Windows errno.h doesn't define these*/
50+
#if defined (_WIN32) || defined(_WIN64)
51+
#define EREMOTEIO 121
52+
#define EDQUOT 122
53+
#define ERESTART 85
54+
#endif
55+
4756
/* Source Code Control System, query version of binary with 'what' */
4857
const char sccsid[] = "@(#)libnvme " GIT_VERSION;
4958

libnvme/src/platform/windows.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,6 @@ static inline int random_uuid(unsigned char *uuid, size_t len)
5858
}
5959

6060

61-
/* errno.h compatibility */
62-
63-
#define EREMOTEIO 121 // util.c
64-
#define EDQUOT 122 // util.c
65-
#define ERESTART 85 // util.c
66-
#define ENOTBLK 15 // sfx-nvme.c - could they just use libnvme's check for char device instead?
67-
#define ENAVAIL 119 // nvme.c - just used internally, define a custom, internal error code for this?
68-
69-
70-
/* ifaddrs.h compatibility */
71-
72-
struct ifaddrs {
73-
struct ifaddrs *ifa_next;
74-
char *ifa_name;
75-
unsigned int ifa_flags;
76-
struct sockaddr *ifa_addr;
77-
struct sockaddr *ifa_netmask;
78-
struct sockaddr *ifa_broadaddr;
79-
void *ifa_data;
80-
};
81-
82-
8361
/* time.h POSIX compatibility */
8462

8563
static inline struct tm *gmtime_r(const time_t *timep, struct tm *result)

nvme.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7353,6 +7353,9 @@ static void get_pif_sts(struct nvme_id_ns *ns, struct nvme_nvm_id_ns *nvm_ns,
73537353
*pif = (elbaf & NVME_NVM_ELBAF_QPIF_MASK) >> 9;
73547354
}
73557355

7356+
7357+
#define ERR_IGNORE_INVALID_FIELD 0x2000 /* invalid field error - ignore */
7358+
73567359
static int get_pi_info(struct libnvme_transport_handle *hdl,
73577360
__u32 nsid, __u8 prinfo, __u64 ilbrt, __u64 lbst,
73587361
unsigned int *logical_block_size, __u16 *metadata_size)
@@ -7394,7 +7397,7 @@ static int get_pi_info(struct libnvme_transport_handle *hdl,
73947397
* Keep the I/O commands behavior same as before.
73957398
* Since the error returned by drives unsupported.
73967399
*/
7397-
return -ENAVAIL;
7400+
return ERR_IGNORE_INVALID_FIELD;
73987401

73997402
pi_size = (pif == NVME_NVM_PIF_16B_GUARD) ? 8 : 16;
74007403
if (NVME_FLBAS_META_EXT(ns->flbas)) {
@@ -7449,7 +7452,7 @@ static int init_pi_tags(struct libnvme_transport_handle *hdl,
74497452
* Keep the I/O commands behavior same as before.
74507453
* Since the error returned by drives unsupported.
74517454
*/
7452-
return -ENAVAIL;
7455+
return ERR_IGNORE_INVALID_FIELD;
74537456

74547457
if (invalid_tags(lbst, ilbrt, sts, pif))
74557458
return -EINVAL;
@@ -7565,7 +7568,7 @@ static int write_zeroes(int argc, char **argv,
75657568

75667569
err = init_pi_tags(hdl, &cmd, cfg.nsid, cfg.ilbrt, cfg.lbst, cfg.lbat,
75677570
cfg.lbatm);
7568-
if (err && err != -ENAVAIL)
7571+
if (err && err != ERR_IGNORE_INVALID_FIELD)
75697572
return err;
75707573

75717574
err = libnvme_submit_io_passthru(hdl, &cmd);
@@ -7908,7 +7911,7 @@ static int copy_cmd(int argc, char **argv, struct command *acmd, struct plugin *
79087911
cfg.fua, cfg.lr, 0, cfg.dspec, copy->f0);
79097912
err = init_pi_tags(hdl, &cmd, cfg.nsid, cfg.ilbrt, cfg.lbst, cfg.lbat,
79107913
cfg.lbatm);
7911-
if (err != 0 && err != -ENAVAIL)
7914+
if (err != 0 && err != ERR_IGNORE_INVALID_FIELD)
79127915
return err;
79137916
err = libnvme_submit_io_passthru(hdl, &cmd);
79147917
if (err) {
@@ -8747,7 +8750,7 @@ static int verify_cmd(int argc, char **argv, struct command *acmd, struct plugin
87478750
cfg.block_count, control, 0, NULL, 0, NULL, 0);
87488751
err = init_pi_tags(hdl, &cmd, cfg.nsid, cfg.ilbrt, cfg.lbst,
87498752
cfg.lbat, cfg.lbatm);
8750-
if (err != 0 && err != -ENAVAIL)
8753+
if (err != 0 && err != ERR_IGNORE_INVALID_FIELD)
87518754
return err;
87528755
err = libnvme_submit_io_passthru(hdl, &cmd);
87538756
if (err) {

plugins/ocp/ocp-nvme.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,6 @@ int ocp_set_latency_monitor_feature(int argc, char **argv, struct command *acmd,
292292
__u64 result;
293293
struct feature_latency_monitor buf = { 0 };
294294
__u32 nsid = NVME_NSID_ALL;
295-
struct stat nvme_stat;
296295
struct nvme_id_ctrl ctrl;
297296

298297
const char *desc = "Set Latency Monitor feature.";
@@ -1433,7 +1432,6 @@ static int ocp_telemetry_log(int argc, char **argv, struct command *acmd, struct
14331432
__cleanup_nvme_transport_handle struct libnvme_transport_handle *hdl = NULL;
14341433
int err = 0;
14351434
__u32 nsid = NVME_NSID_ALL;
1436-
struct stat nvme_stat;
14371435
char sn[21] = {0,};
14381436
struct nvme_id_ctrl ctrl;
14391437
bool is_support_telemetry_controller;

0 commit comments

Comments
 (0)