Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions libnvme/libnvme3/attr-accessors.i
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,19 @@

return PyLong_FromLong(val);
}
static const char *libnvme_ns_wwid_get(const struct libnvme_ns *p)
{
const char *val;
int ret = libnvme_ns_get_wwid(p, &val, NULL);

if (ret == 0)
return val;
if (ret == -ENOENT)
return NULL;

raise_nvme(NvmeError, ret);
return NULL;
}
static PyObject *libnvme_ns_command_retry_count_get(const struct libnvme_ns *p)
{
long val;
Expand Down Expand Up @@ -656,6 +669,10 @@
$action
if (PyErr_Occurred()) SWIG_fail;
}
%exception libnvme_ns::wwid {
$action
if (PyErr_Occurred()) SWIG_fail;
}
%exception libnvme_ns::command_retry_count {
$action
if (PyErr_Occurred()) SWIG_fail;
Expand Down Expand Up @@ -686,6 +703,8 @@
PyObject * meta_size;
%immutable csi;
PyObject * csi;
%immutable wwid;
const char * wwid;
%immutable command_retry_count;
PyObject * command_retry_count;
%immutable command_error_count;
Expand Down
1 change: 1 addition & 0 deletions libnvme/src/attr-accessors.ld
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ LIBNVME_ATTR_ACCESSORS_3 {
libnvme_ns_get_eui64;
libnvme_ns_get_nguid;
libnvme_ns_get_uuid;
libnvme_ns_get_wwid;
libnvme_ns_get_command_retry_count;
libnvme_ns_get_command_error_count;
libnvme_ns_get_io_requeue_no_usable_path_count;
Expand Down
5 changes: 5 additions & 0 deletions libnvme/src/nvme/attr_accessors_specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@
'type': 'unsigned char *',
'custom': True,
},
{
'name': 'wwid',
'attr': 'wwid',
'type': 'char *',
},
# The four diag/* counters need no per-OS override: like most
# CTRL_ATTRS members, Windows absence falls out of the existing
# libnvme_get_ns_attr() stub (unconditionally NULL) for free --
Expand Down
24 changes: 24 additions & 0 deletions libnvme/src/nvme/generated/attr-accessors.c
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ struct libnvme_ns_attrs {
uint8_t *eui64;
uint8_t *nguid;
unsigned char *uuid;
char *wwid;
long command_retry_count;
long command_error_count;
long io_requeue_no_usable_path_count;
Expand Down Expand Up @@ -615,9 +616,32 @@ void libnvme_ns_attrs_free(
ATTR_FREE(attrs->eui64);
ATTR_FREE(attrs->nguid);
ATTR_FREE(attrs->uuid);
ATTR_FREE(attrs->wwid);
free(attrs);
}

__shr_public int libnvme_ns_get_wwid(
const struct libnvme_ns *p,
const char **val,
const char *dflt)
{
struct libnvme_ns *c = (struct libnvme_ns *)p;

*val = dflt;

if (__shr_unlikely(!ATTR_IS_LOADED(c->attrs->wwid))) {
c->attrs->wwid = libnvme_get_ns_attr(c, "wwid");
if (!c->attrs->wwid)
c->attrs->wwid = NO_ATTR;
}

if (ATTR_IS_ABSENT(c->attrs->wwid))
return -ENOENT;

*val = c->attrs->wwid;
return 0;
}

__shr_public int libnvme_ns_get_command_retry_count(
const struct libnvme_ns *p,
long *val,
Expand Down
14 changes: 14 additions & 0 deletions libnvme/src/nvme/generated/attr-accessors.h
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,20 @@ int libnvme_ns_get_uuid(
const unsigned char **uuid,
const unsigned char *dflt);

/**
* libnvme_ns_get_wwid() - Get wwid.
* @p: The &struct libnvme_ns instance to query.
* @wwid: Where to store the value on success.
* @dflt: Value to store in @wwid on failure.
*
* Return: 0 on success, -ENOENT if the attribute does not
* exist, or a negative errno on failure.
*/
int libnvme_ns_get_wwid(
const struct libnvme_ns *p,
const char **wwid,
const char *dflt);

/**
* libnvme_ns_get_command_retry_count() - Get command_retry_count.
* @p: The &struct libnvme_ns instance to query.
Expand Down
16 changes: 5 additions & 11 deletions libnvme/tests/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,9 @@ static void print_hex(const uint8_t *x, int len)
printf("%02x", x[i]);
}

/* Safe display fallbacks for the lazy eui64/nguid/uuid getters below. */
/* Safe display fallbacks for the lazy eui64/nguid getters below. */
static const uint8_t zero_eui64[8];
static const uint8_t zero_nguid[16];
static const unsigned char zero_uuid[NVME_UUID_LEN];

int main(int argc, char **argv)
{
Expand Down Expand Up @@ -448,8 +447,7 @@ int main(int argc, char **argv)
libnvme_ctrl_get_state(c));

libnvme_ctrl_for_each_ns(c, n) {
char uuid_str[NVME_UUID_LEN_STRING];
const unsigned char *uuid;
const char *wwid;
const uint8_t *eui64;
const uint8_t *nguid;
int lba_size;
Expand All @@ -471,15 +469,11 @@ int main(int argc, char **argv)
libnvme_ns_get_nguid(n, &nguid,
zero_nguid);
print_hex(nguid, 16);
libnvme_ns_get_uuid(n, &uuid,
zero_uuid);
libnvme_uuid_to_string(
(unsigned char *)uuid,
uuid_str);
libnvme_ns_get_wwid(n, &wwid, "");
libnvme_ns_get_csi(n, &csi,
NVME_CSI_NVM);
printf(" uuid:%s csi:%d\n",
uuid_str, csi);
printf(" wwid:%s csi:%d\n",
wwid, csi);
}

libnvme_ctrl_for_each_path(c, p) {
Expand Down
Loading