Skip to content

Commit cdbff4f

Browse files
author
Christoph Hellwig
committed
nvme: remove nvme_revalidate_ns
The function is used in two places, and the shared code for those will diverge later in this series. Instead factor out a new helper to get the ids for a namespace, simplify the calling conventions for nvme_identify_ns and just open code the sequence. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Keith Busch <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]>
1 parent 57eeaf8 commit cdbff4f

File tree

1 file changed

+53
-47
lines changed

1 file changed

+53
-47
lines changed

drivers/nvme/host/core.c

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,8 @@ static int nvme_identify_ctrl(struct nvme_ctrl *dev, struct nvme_id_ctrl **id)
783783
return error;
784784
}
785785

786-
static int nvme_identify_ns_descs(struct nvme_ns *ns, unsigned nsid)
786+
static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, unsigned nsid,
787+
u8 *eui64, u8 *nguid, uuid_t *uuid)
787788
{
788789
struct nvme_command c = { };
789790
int status;
@@ -799,7 +800,7 @@ static int nvme_identify_ns_descs(struct nvme_ns *ns, unsigned nsid)
799800
if (!data)
800801
return -ENOMEM;
801802

802-
status = nvme_submit_sync_cmd(ns->ctrl->admin_q, &c, data,
803+
status = nvme_submit_sync_cmd(ctrl->admin_q, &c, data,
803804
NVME_IDENTIFY_DATA_SIZE);
804805
if (status)
805806
goto free_data;
@@ -813,33 +814,33 @@ static int nvme_identify_ns_descs(struct nvme_ns *ns, unsigned nsid)
813814
switch (cur->nidt) {
814815
case NVME_NIDT_EUI64:
815816
if (cur->nidl != NVME_NIDT_EUI64_LEN) {
816-
dev_warn(ns->ctrl->device,
817+
dev_warn(ctrl->device,
817818
"ctrl returned bogus length: %d for NVME_NIDT_EUI64\n",
818819
cur->nidl);
819820
goto free_data;
820821
}
821822
len = NVME_NIDT_EUI64_LEN;
822-
memcpy(ns->eui, data + pos + sizeof(*cur), len);
823+
memcpy(eui64, data + pos + sizeof(*cur), len);
823824
break;
824825
case NVME_NIDT_NGUID:
825826
if (cur->nidl != NVME_NIDT_NGUID_LEN) {
826-
dev_warn(ns->ctrl->device,
827+
dev_warn(ctrl->device,
827828
"ctrl returned bogus length: %d for NVME_NIDT_NGUID\n",
828829
cur->nidl);
829830
goto free_data;
830831
}
831832
len = NVME_NIDT_NGUID_LEN;
832-
memcpy(ns->nguid, data + pos + sizeof(*cur), len);
833+
memcpy(nguid, data + pos + sizeof(*cur), len);
833834
break;
834835
case NVME_NIDT_UUID:
835836
if (cur->nidl != NVME_NIDT_UUID_LEN) {
836-
dev_warn(ns->ctrl->device,
837+
dev_warn(ctrl->device,
837838
"ctrl returned bogus length: %d for NVME_NIDT_UUID\n",
838839
cur->nidl);
839840
goto free_data;
840841
}
841842
len = NVME_NIDT_UUID_LEN;
842-
uuid_copy(&ns->uuid, data + pos + sizeof(*cur));
843+
uuid_copy(uuid, data + pos + sizeof(*cur));
843844
break;
844845
default:
845846
/* Skip unnkown types */
@@ -864,9 +865,10 @@ static int nvme_identify_ns_list(struct nvme_ctrl *dev, unsigned nsid, __le32 *n
864865
return nvme_submit_sync_cmd(dev->admin_q, &c, ns_list, 0x1000);
865866
}
866867

867-
static int nvme_identify_ns(struct nvme_ctrl *dev, unsigned nsid,
868-
struct nvme_id_ns **id)
868+
static struct nvme_id_ns *nvme_identify_ns(struct nvme_ctrl *ctrl,
869+
unsigned nsid)
869870
{
871+
struct nvme_id_ns *id;
870872
struct nvme_command c = { };
871873
int error;
872874

@@ -875,15 +877,18 @@ static int nvme_identify_ns(struct nvme_ctrl *dev, unsigned nsid,
875877
c.identify.nsid = cpu_to_le32(nsid);
876878
c.identify.cns = NVME_ID_CNS_NS;
877879

878-
*id = kmalloc(sizeof(struct nvme_id_ns), GFP_KERNEL);
879-
if (!*id)
880-
return -ENOMEM;
880+
id = kmalloc(sizeof(*id), GFP_KERNEL);
881+
if (!id)
882+
return NULL;
881883

882-
error = nvme_submit_sync_cmd(dev->admin_q, &c, *id,
883-
sizeof(struct nvme_id_ns));
884-
if (error)
885-
kfree(*id);
886-
return error;
884+
error = nvme_submit_sync_cmd(ctrl->admin_q, &c, id, sizeof(*id));
885+
if (error) {
886+
dev_warn(ctrl->device, "Identify namespace failed\n");
887+
kfree(id);
888+
return NULL;
889+
}
890+
891+
return id;
887892
}
888893

889894
static int nvme_set_features(struct nvme_ctrl *dev, unsigned fid, unsigned dword11,
@@ -1174,32 +1179,21 @@ static void nvme_config_discard(struct nvme_ns *ns)
11741179
blk_queue_max_write_zeroes_sectors(ns->queue, UINT_MAX);
11751180
}
11761181

1177-
static int nvme_revalidate_ns(struct nvme_ns *ns, struct nvme_id_ns **id)
1182+
static void nvme_report_ns_ids(struct nvme_ctrl *ctrl, unsigned int nsid,
1183+
struct nvme_id_ns *id, u8 *eui64, u8 *nguid, uuid_t *uuid)
11781184
{
1179-
if (nvme_identify_ns(ns->ctrl, ns->ns_id, id)) {
1180-
dev_warn(ns->ctrl->device, "Identify namespace failed\n");
1181-
return -ENODEV;
1182-
}
1183-
1184-
if ((*id)->ncap == 0) {
1185-
kfree(*id);
1186-
return -ENODEV;
1187-
}
1188-
1189-
if (ns->ctrl->vs >= NVME_VS(1, 1, 0))
1190-
memcpy(ns->eui, (*id)->eui64, sizeof(ns->eui));
1191-
if (ns->ctrl->vs >= NVME_VS(1, 2, 0))
1192-
memcpy(ns->nguid, (*id)->nguid, sizeof(ns->nguid));
1193-
if (ns->ctrl->vs >= NVME_VS(1, 3, 0)) {
1185+
if (ctrl->vs >= NVME_VS(1, 1, 0))
1186+
memcpy(eui64, id->eui64, sizeof(id->eui64));
1187+
if (ctrl->vs >= NVME_VS(1, 2, 0))
1188+
memcpy(nguid, id->nguid, sizeof(id->nguid));
1189+
if (ctrl->vs >= NVME_VS(1, 3, 0)) {
11941190
/* Don't treat error as fatal we potentially
11951191
* already have a NGUID or EUI-64
11961192
*/
1197-
if (nvme_identify_ns_descs(ns, ns->ns_id))
1198-
dev_warn(ns->ctrl->device,
1193+
if (nvme_identify_ns_descs(ctrl, nsid, eui64, nguid, uuid))
1194+
dev_warn(ctrl->device,
11991195
"%s: Identify Descriptors failed\n", __func__);
12001196
}
1201-
1202-
return 0;
12031197
}
12041198

12051199
static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
@@ -1240,22 +1234,28 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id)
12401234
static int nvme_revalidate_disk(struct gendisk *disk)
12411235
{
12421236
struct nvme_ns *ns = disk->private_data;
1243-
struct nvme_id_ns *id = NULL;
1244-
int ret;
1237+
struct nvme_ctrl *ctrl = ns->ctrl;
1238+
struct nvme_id_ns *id;
1239+
int ret = 0;
12451240

12461241
if (test_bit(NVME_NS_DEAD, &ns->flags)) {
12471242
set_capacity(disk, 0);
12481243
return -ENODEV;
12491244
}
12501245

1251-
ret = nvme_revalidate_ns(ns, &id);
1252-
if (ret)
1253-
return ret;
1246+
id = nvme_identify_ns(ctrl, ns->ns_id);
1247+
if (!id)
1248+
return -ENODEV;
12541249

1255-
__nvme_revalidate_disk(disk, id);
1256-
kfree(id);
1250+
if (id->ncap == 0) {
1251+
ret = -ENODEV;
1252+
goto out;
1253+
}
12571254

1258-
return 0;
1255+
nvme_report_ns_ids(ctrl, ns->ns_id, id, ns->eui, ns->nguid, &ns->uuid);
1256+
out:
1257+
kfree(id);
1258+
return ret;
12591259
}
12601260

12611261
static char nvme_pr_type(enum pr_type type)
@@ -2361,9 +2361,15 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
23612361

23622362
sprintf(disk_name, "nvme%dn%d", ctrl->instance, ns->instance);
23632363

2364-
if (nvme_revalidate_ns(ns, &id))
2364+
id = nvme_identify_ns(ctrl, nsid);
2365+
if (!id)
23652366
goto out_free_queue;
23662367

2368+
if (id->ncap == 0)
2369+
goto out_free_id;
2370+
2371+
nvme_report_ns_ids(ctrl, ns->ns_id, id, ns->eui, ns->nguid, &ns->uuid);
2372+
23672373
if (nvme_nvm_ns_supported(ns, id) &&
23682374
nvme_nvm_register(ns, disk_name, node)) {
23692375
dev_warn(ctrl->device, "%s: LightNVM init failure\n", __func__);

0 commit comments

Comments
 (0)