nvme updates for Linux 5.16

- support the current discovery subsystem entry (Hannes Reinecke)
  - use flex_array_size and struct_size (Len Baker)
 -----BEGIN PGP SIGNATURE-----
 
 iQI/BAABCgApFiEEgdbnc3r/njty3Iq9D55TZVIEUYMFAmF6sxwLHGhjaEBsc3Qu
 ZGUACgkQD55TZVIEUYNoQhAAwzsSvGXXoncIqal93fZ7SPmY/Y3Xr/M44QRZlh32
 o8WeC+/BUAixaACi5TUuT4wAyuHLweOnvvNSlx818R6eSQ6HaeQfJSvIHc6uxtoQ
 HgaABVu4I70Bt8oHcH9WTvu4Y8AOQG7btYhrV6vaScDKLNugpDnmh7ULGehW2l3D
 5xBH/PccO2df+lj1EzYMV0i7fXJWMuR1vR1bWFk+zbIKzY7rzhb5M+q8rfNSaNk1
 J18iZbyegWyWGQNx8bpa0NHW8J7EZfv9Lsp3DLWzgktJ6f4JAc+6VK9fjhcsiKDa
 zLBSLBlSA8r8/gi2X5r/wpRUgn7CVY0IRTbjy8giLs+0Xmem89edjzAVHbiVGcwY
 NXCcP16RxzNPSJv+7M2aV3BtyInYQLSZ9PwGMJhmm580RjRkrqVcPA1Yfx3qCGuI
 XxlvlD3KLzB4vBRkxAIIl9IO/M3mdSDvg8Bsl1WSXbLBjBYl5NIRP7a874ATZgz6
 A7P/t+/RrnW+alK5Pb6ITXGUBnmjmXSzv3216QotYdLpi0ooqhRkuRbTEbtwmT8k
 a1fCnkbugnuOK3RLfZtQppIrOnfxDxEcYR7hvML2CSy6WfNAOFT3LNEQMc+aP3Et
 nBXtSALKag5VCRbNmHrFSOWF23jlQ+Z/BMQa2CfLGgvTD2X39w8/BOWawYeYX9XA
 i5Q=
 =GMQd
 -----END PGP SIGNATURE-----

Merge tag 'nvme-5.16-2021-10-28' of git://git.infradead.org/nvme into for-5.16/drivers

Pull NVMe updates from Christoph:

"nvme updates for Linux 5.16

 - support the current discovery subsystem entry (Hannes Reinecke)
 - use flex_array_size and struct_size (Len Baker)"

* tag 'nvme-5.16-2021-10-28' of git://git.infradead.org/nvme:
  nvmet: use flex_array_size and struct_size
  nvmet: register discovery subsystem as 'current'
  nvmet: switch check for subsystem type
  nvme: add new discovery log page entry definitions
This commit is contained in:
Jens Axboe 2021-10-28 08:35:02 -06:00
commit ca7787973a
6 changed files with 31 additions and 12 deletions

View File

@ -562,7 +562,7 @@ static int nvme_parse_ana_log(struct nvme_ctrl *ctrl, void *data,
return -EINVAL;
nr_nsids = le32_to_cpu(desc->nnsids);
nsid_buf_size = nr_nsids * sizeof(__le32);
nsid_buf_size = flex_array_size(desc, nsids, nr_nsids);
if (WARN_ON_ONCE(desc->grpid == 0))
return -EINVAL;

View File

@ -264,7 +264,7 @@ static u32 nvmet_format_ana_group(struct nvmet_req *req, u32 grpid,
desc->chgcnt = cpu_to_le64(nvmet_ana_chgcnt);
desc->state = req->port->ana_state[grpid];
memset(desc->rsvd17, 0, sizeof(desc->rsvd17));
return sizeof(struct nvme_ana_group_desc) + count * sizeof(__le32);
return struct_size(desc, nsids, count);
}
static void nvmet_execute_get_log_page_ana(struct nvmet_req *req)

View File

@ -1541,6 +1541,7 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,
subsys->max_qid = NVMET_NR_QUEUES;
break;
case NVME_NQN_DISC:
case NVME_NQN_CURR:
subsys->max_qid = 0;
break;
default:

View File

@ -146,7 +146,7 @@ static size_t discovery_log_entries(struct nvmet_req *req)
struct nvmet_ctrl *ctrl = req->sq->ctrl;
struct nvmet_subsys_link *p;
struct nvmet_port *r;
size_t entries = 0;
size_t entries = 1;
list_for_each_entry(p, &req->port->subsystems, entry) {
if (!nvmet_host_allowed(p->subsys, ctrl->hostnqn))
@ -171,6 +171,7 @@ static void nvmet_execute_disc_get_log_page(struct nvmet_req *req)
u32 numrec = 0;
u16 status = 0;
void *buffer;
char traddr[NVMF_TRADDR_SIZE];
if (!nvmet_check_transfer_len(req, data_len))
return;
@ -203,15 +204,19 @@ static void nvmet_execute_disc_get_log_page(struct nvmet_req *req)
status = NVME_SC_INTERNAL;
goto out;
}
hdr = buffer;
list_for_each_entry(p, &req->port->subsystems, entry) {
char traddr[NVMF_TRADDR_SIZE];
nvmet_set_disc_traddr(req, req->port, traddr);
nvmet_format_discovery_entry(hdr, req->port,
nvmet_disc_subsys->subsysnqn,
traddr, NVME_NQN_CURR, numrec);
numrec++;
list_for_each_entry(p, &req->port->subsystems, entry) {
if (!nvmet_host_allowed(p->subsys, ctrl->hostnqn))
continue;
nvmet_set_disc_traddr(req, req->port, traddr);
nvmet_format_discovery_entry(hdr, req->port,
p->subsys->subsysnqn, traddr,
NVME_NQN_NVME, numrec);
@ -389,7 +394,7 @@ u16 nvmet_parse_discovery_cmd(struct nvmet_req *req)
int __init nvmet_init_discovery(void)
{
nvmet_disc_subsys =
nvmet_subsys_alloc(NVME_DISC_SUBSYS_NAME, NVME_NQN_DISC);
nvmet_subsys_alloc(NVME_DISC_SUBSYS_NAME, NVME_NQN_CURR);
return PTR_ERR_OR_ZERO(nvmet_disc_subsys);
}

View File

@ -579,7 +579,7 @@ static inline struct nvmet_subsys *nvmet_req_subsys(struct nvmet_req *req)
static inline bool nvmet_is_disc_subsys(struct nvmet_subsys *subsys)
{
return subsys->type == NVME_NQN_DISC;
return subsys->type != NVME_NQN_NVME;
}
#ifdef CONFIG_NVME_TARGET_PASSTHRU

View File

@ -27,8 +27,14 @@
#define NVME_NSID_ALL 0xffffffff
enum nvme_subsys_type {
NVME_NQN_DISC = 1, /* Discovery type target subsystem */
NVME_NQN_NVME = 2, /* NVME type target subsystem */
/* Referral to another discovery type target subsystem */
NVME_NQN_DISC = 1,
/* NVME type target subsystem */
NVME_NQN_NVME = 2,
/* Current discovery type target subsystem */
NVME_NQN_CURR = 3,
};
enum nvme_ctrl_type {
@ -1312,6 +1318,12 @@ struct nvmf_common_command {
#define MAX_DISC_LOGS 255
/* Discovery log page entry flags (EFLAGS): */
enum {
NVME_DISC_EFLAGS_EPCSD = (1 << 1),
NVME_DISC_EFLAGS_DUPRETINFO = (1 << 0),
};
/* Discovery log page entry */
struct nvmf_disc_rsp_page_entry {
__u8 trtype;
@ -1321,7 +1333,8 @@ struct nvmf_disc_rsp_page_entry {
__le16 portid;
__le16 cntlid;
__le16 asqsz;
__u8 resv8[22];
__le16 eflags;
__u8 resv10[20];
char trsvcid[NVMF_TRSVCID_SIZE];
__u8 resv64[192];
char subnqn[NVMF_NQN_FIELD_LEN];