Skip to content

Commit a89d312

Browse files
committed
libnvme: generate read-only accessor for 'phy_slot'
No reason why it should not be auto-generated. Signed-off-by: Hannes Reinecke <[email protected]>
1 parent a19cf14 commit a89d312

6 files changed

Lines changed: 20 additions & 21 deletions

File tree

libnvme/src/accessors.ld

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ LIBNVME_ACCESSORS_3 {
8686
nvme_ctrl_set_discovered;
8787
nvme_ctrl_get_persistent;
8888
nvme_ctrl_set_persistent;
89+
nvme_ctrl_get_phy_slot;
8990
nvme_subsystem_get_name;
9091
nvme_subsystem_set_name;
9192
nvme_subsystem_get_sysfs_dir;

libnvme/src/nvme/accessors.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,11 @@ const char *nvme_ctrl_get_dctype(const struct nvme_ctrl *p)
387387
return p->dctype;
388388
}
389389

390+
const char *nvme_ctrl_get_phy_slot(const struct nvme_ctrl *p)
391+
{
392+
return p->phy_slot;
393+
}
394+
390395
void nvme_ctrl_set_host_traddr(struct nvme_ctrl *p, const char *host_traddr)
391396
{
392397
free(p->host_traddr);

libnvme/src/nvme/accessors.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,14 @@ void nvme_ctrl_set_dctype(struct nvme_ctrl *p, const char *dctype);
532532
*/
533533
const char *nvme_ctrl_get_dctype(const struct nvme_ctrl *p);
534534

535+
/**
536+
* nvme_ctrl_get_phy_slot() - Get phy_slot.
537+
* @p: The &struct nvme_ctrl instance to query.
538+
*
539+
* Return: The value of the phy_slot field, or NULL if not set.
540+
*/
541+
const char *nvme_ctrl_get_phy_slot(const struct nvme_ctrl *p);
542+
535543
/**
536544
* nvme_ctrl_set_host_traddr() - Set host_traddr.
537545
* @p: The &struct nvme_ctrl instance to update.

libnvme/src/nvme/private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ struct nvme_ctrl { /*!generate-accessors*/
206206
char *cntrltype;
207207
char *cntlid;
208208
char *dctype;
209-
char *phy_slot; //!accessors:none
209+
char *phy_slot; //!accessors:readonly
210210
char *host_traddr;
211211
char *host_iface;
212212
bool discovery_ctrl;

libnvme/src/nvme/tree.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -921,11 +921,6 @@ char *nvme_ctrl_get_src_addr(nvme_ctrl_t c, char *src_addr, size_t src_addr_len)
921921
return src_addr;
922922
}
923923

924-
const char *nvme_ctrl_get_phy_slot(nvme_ctrl_t c)
925-
{
926-
return c->phy_slot ? c->phy_slot : "";
927-
}
928-
929924
const char *nvme_ctrl_get_state(nvme_ctrl_t c)
930925
{
931926
char *state = c->state;
@@ -1603,8 +1598,7 @@ static int nvme_ctrl_lookup_subsystem_name(struct nvme_global_ctx *ctx,
16031598
}
16041599

16051600
static int nvme_ctrl_lookup_phy_slot(struct nvme_global_ctx *ctx,
1606-
const char *address,
1607-
char **slotp)
1601+
nvme_ctrl_t c)
16081602
{
16091603
const char *slots_sysfs_dir = nvme_slots_sysfs_dir();
16101604
_cleanup_free_ char *target_addr = NULL;
@@ -1613,7 +1607,7 @@ static int nvme_ctrl_lookup_phy_slot(struct nvme_global_ctx *ctx,
16131607
char *slot;
16141608
int ret;
16151609

1616-
if (!address)
1610+
if (!c->address)
16171611
return -EINVAL;
16181612

16191613
slots_dir = opendir(slots_sysfs_dir);
@@ -1623,7 +1617,7 @@ static int nvme_ctrl_lookup_phy_slot(struct nvme_global_ctx *ctx,
16231617
return -errno;
16241618
}
16251619

1626-
target_addr = strndup(address, 10);
1620+
target_addr = strndup(c->address, 10);
16271621
while ((entry = readdir(slots_dir))) {
16281622
if (entry->d_type == DT_DIR &&
16291623
strncmp(entry->d_name, ".", 1) != 0 &&
@@ -1647,7 +1641,7 @@ static int nvme_ctrl_lookup_phy_slot(struct nvme_global_ctx *ctx,
16471641
if (!slot)
16481642
return -ENOMEM;
16491643

1650-
*slotp = slot;
1644+
c->phy_slot = slot;
16511645
return 0;
16521646
}
16531647
}
@@ -1760,7 +1754,7 @@ static int nvme_reconfigure_ctrl(struct nvme_global_ctx *ctx, nvme_ctrl_t c, con
17601754
c->cntrltype = nvme_get_ctrl_attr(c, "cntrltype");
17611755
c->cntlid = nvme_get_ctrl_attr(c, "cntlid");
17621756
c->dctype = nvme_get_ctrl_attr(c, "dctype");
1763-
nvme_ctrl_lookup_phy_slot(ctx, c->address, &c->phy_slot);
1757+
nvme_ctrl_lookup_phy_slot(ctx, c);
17641758
nvme_read_sysfs_dhchap(ctx, c);
17651759
nvme_read_sysfs_tls(ctx, c);
17661760

libnvme/src/nvme/tree.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -726,15 +726,6 @@ void nvme_ctrl_release_transport_handle(nvme_ctrl_t c);
726726
*/
727727
char *nvme_ctrl_get_src_addr(nvme_ctrl_t c, char *src_addr, size_t src_addr_len);
728728

729-
/**
730-
* nvme_ctrl_get_phy_slot() - PCI physical slot number of a controller
731-
* @c: Controller instance
732-
*
733-
* Return: PCI physical slot number of @c or empty string if slot
734-
* number is not present.
735-
*/
736-
const char *nvme_ctrl_get_phy_slot(nvme_ctrl_t c);
737-
738729
/**
739730
* nvme_ctrl_get_state() - Running state of a controller
740731
* @c: Controller instance

0 commit comments

Comments
 (0)