Skip to content

Commit c6fce9f

Browse files
Christoph Hellwigkeithbusch
authored andcommitted
nvme: split out a nvme_identify_ns_nvm helper
Split the logic to query the Identify Namespace Data Structure, NVM Command Set into a separate helper. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Max Gurtovoy <mgurtovoy@nvidia.com> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent 46e7422 commit c6fce9f

1 file changed

Lines changed: 26 additions & 12 deletions

File tree

drivers/nvme/host/core.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,12 +1831,35 @@ static bool nvme_ns_ids_equal(struct nvme_ns_ids *a, struct nvme_ns_ids *b)
18311831
a->csi == b->csi;
18321832
}
18331833

1834+
static int nvme_identify_ns_nvm(struct nvme_ctrl *ctrl, unsigned int nsid,
1835+
struct nvme_id_ns_nvm **nvmp)
1836+
{
1837+
struct nvme_command c = {
1838+
.identify.opcode = nvme_admin_identify,
1839+
.identify.nsid = cpu_to_le32(nsid),
1840+
.identify.cns = NVME_ID_CNS_CS_NS,
1841+
.identify.csi = NVME_CSI_NVM,
1842+
};
1843+
struct nvme_id_ns_nvm *nvm;
1844+
int ret;
1845+
1846+
nvm = kzalloc(sizeof(*nvm), GFP_KERNEL);
1847+
if (!nvm)
1848+
return -ENOMEM;
1849+
1850+
ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, nvm, sizeof(*nvm));
1851+
if (ret)
1852+
kfree(nvm);
1853+
else
1854+
*nvmp = nvm;
1855+
return ret;
1856+
}
1857+
18341858
static int nvme_init_ms(struct nvme_ctrl *ctrl, struct nvme_ns_head *head,
18351859
struct nvme_id_ns *id)
18361860
{
18371861
bool first = id->dps & NVME_NS_DPS_PI_FIRST;
18381862
unsigned lbaf = nvme_lbaf_index(id->flbas);
1839-
struct nvme_command c = { };
18401863
struct nvme_id_ns_nvm *nvm;
18411864
int ret = 0;
18421865
u32 elbaf;
@@ -1849,18 +1872,9 @@ static int nvme_init_ms(struct nvme_ctrl *ctrl, struct nvme_ns_head *head,
18491872
goto set_pi;
18501873
}
18511874

1852-
nvm = kzalloc(sizeof(*nvm), GFP_KERNEL);
1853-
if (!nvm)
1854-
return -ENOMEM;
1855-
1856-
c.identify.opcode = nvme_admin_identify;
1857-
c.identify.nsid = cpu_to_le32(head->ns_id);
1858-
c.identify.cns = NVME_ID_CNS_CS_NS;
1859-
c.identify.csi = NVME_CSI_NVM;
1860-
1861-
ret = nvme_submit_sync_cmd(ctrl->admin_q, &c, nvm, sizeof(*nvm));
1875+
ret = nvme_identify_ns_nvm(ctrl, head->ns_id, &nvm);
18621876
if (ret)
1863-
goto free_data;
1877+
goto set_pi;
18641878

18651879
elbaf = le32_to_cpu(nvm->elbaf[lbaf]);
18661880

0 commit comments

Comments
 (0)