From nobody Sun Dec 28 19:30:48 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1436CC10DC1 for ; Wed, 6 Dec 2023 08:13:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377162AbjLFIM5 (ORCPT ); Wed, 6 Dec 2023 03:12:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377078AbjLFIMt (ORCPT ); Wed, 6 Dec 2023 03:12:49 -0500 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 707681A4 for ; Wed, 6 Dec 2023 00:12:52 -0800 (PST) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E5FBA2206F; Wed, 6 Dec 2023 08:12:50 +0000 (UTC) Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id CCB57133DD; Wed, 6 Dec 2023 08:12:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id clNbMAItcGUXHgAAn2gu4w (envelope-from ); Wed, 06 Dec 2023 08:12:50 +0000 From: Daniel Wagner To: linux-nvme@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Keith Busch , Christoph Hellwig , Sagi Grimberg , Hannes Reinecke , Daniel Wagner Subject: [PATCH v3 3/4] nvme: move ns id info to struct nvme_ns_head Date: Wed, 6 Dec 2023 09:12:43 +0100 Message-ID: <20231206081244.32733-4-dwagner@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231206081244.32733-1-dwagner@suse.de> References: <20231206081244.32733-1-dwagner@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Result: default: False [1.98 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:98:from]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; R_SPF_SOFTFAIL(0.00)[~all:c]; RCVD_COUNT_THREE(0.00)[3]; MX_GOOD(-0.01)[]; NEURAL_HAM_SHORT(-0.01)[-0.046]; RCPT_COUNT_SEVEN(0.00)[7]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%]; DMARC_POLICY_SOFTFAIL(0.10)[suse.de : No valid SPF, No valid DKIM,none] X-Spamd-Bar: + X-Rspamd-Server: rspamd1 Authentication-Results: smtp-out1.suse.de; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=suse.de (policy=none); spf=softfail (smtp-out1.suse.de: 2a07:de40:b281:104:10:150:64:98 is neither permitted nor denied by domain of dwagner@suse.de) smtp.mailfrom=dwagner@suse.de X-Rspamd-Queue-Id: E5FBA2206F Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Move the namesapce info to struct nvme_ns_head, because it's the same for all associated namespaces. The head pointer is accessible from the ns pointer so we could just update all places with ns->x to ns->head->x. While this is okay for the slow path, it's not for the fast path. Thus we store the head pointer as private data into request_queue. Signed-off-by: Daniel Wagner --- drivers/nvme/host/apple.c | 4 +- drivers/nvme/host/core.c | 192 +++++++++++++++++---------------- drivers/nvme/host/fc.c | 4 +- drivers/nvme/host/ioctl.c | 20 ++-- drivers/nvme/host/multipath.c | 31 +++--- drivers/nvme/host/nvme.h | 60 ++++++----- drivers/nvme/host/rdma.c | 10 +- drivers/nvme/host/tcp.c | 8 +- drivers/nvme/host/zns.c | 34 +++--- drivers/nvme/target/loop.c | 4 +- drivers/nvme/target/passthru.c | 8 +- 11 files changed, 197 insertions(+), 178 deletions(-) diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index 596bb11eeba5..04c1c5fbd4d1 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -732,7 +732,7 @@ static int apple_nvme_remove_sq(struct apple_nvme *anv) static blk_status_t apple_nvme_queue_rq(struct blk_mq_hw_ctx *hctx, const struct blk_mq_queue_data *bd) { - struct nvme_ns *ns =3D hctx->queue->queuedata; + struct nvme_ns_head *head =3D hctx->queue->queuedata; struct apple_nvme_queue *q =3D hctx->driver_data; struct apple_nvme *anv =3D queue_to_apple_nvme(q); struct request *req =3D bd->rq; @@ -753,7 +753,7 @@ static blk_status_t apple_nvme_queue_rq(struct blk_mq_h= w_ctx *hctx, if (!nvme_check_ready(&anv->ctrl, req, true)) return nvme_fail_nonready_command(&anv->ctrl, req); =20 - ret =3D nvme_setup_cmd(ns, req); + ret =3D nvme_setup_cmd(head, req); if (ret) return ret; =20 diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 1fabe1b81de0..caa52c2f57c8 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -308,16 +308,16 @@ static void nvme_retry_req(struct request *req) =20 static void nvme_log_error(struct request *req) { - struct nvme_ns *ns =3D req->q->queuedata; + struct nvme_ns_head *head =3D req->q->queuedata; struct nvme_request *nr =3D nvme_req(req); =20 - if (ns) { - pr_err_ratelimited("%s: %s(0x%x) @ LBA %llu, %llu blocks, %s (sct 0x%x /= sc 0x%x) %s%s\n", - ns->disk ? ns->disk->disk_name : "?", + if (head) { + pr_err_ratelimited("%s: %s(0x%x) @ LBA %llu, %u blocks, %s (sct 0x%x / s= c 0x%x) %s%s\n", + head->disk ? head->disk->disk_name : "?", nvme_get_opcode_str(nr->cmd->common.opcode), nr->cmd->common.opcode, - (unsigned long long)nvme_sect_to_lba(ns, blk_rq_pos(req)), - (unsigned long long)blk_rq_bytes(req) >> ns->lba_shift, + nvme_sect_to_lba(head, blk_rq_pos(req)), + blk_rq_bytes(req) >> head->lba_shift, nvme_get_error_status_str(nr->status), nr->status >> 8 & 7, /* Status Code Type */ nr->status & 0xff, /* Status Code */ @@ -757,16 +757,16 @@ bool __nvme_check_ready(struct nvme_ctrl *ctrl, struc= t request *rq, } EXPORT_SYMBOL_GPL(__nvme_check_ready); =20 -static inline void nvme_setup_flush(struct nvme_ns *ns, +static inline void nvme_setup_flush(struct nvme_ns_head *head, struct nvme_command *cmnd) { memset(cmnd, 0, sizeof(*cmnd)); cmnd->common.opcode =3D nvme_cmd_flush; - cmnd->common.nsid =3D cpu_to_le32(ns->head->ns_id); + cmnd->common.nsid =3D cpu_to_le32(head->ns_id); } =20 -static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request = *req, - struct nvme_command *cmnd) +static blk_status_t nvme_setup_discard(struct nvme_ns_head *head, + struct request *req, struct nvme_command *cmnd) { unsigned short segments =3D blk_rq_nr_discard_segments(req), n =3D 0; struct nvme_ctrl *ctrl =3D nvme_req(req)->ctrl; @@ -794,8 +794,8 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *= ns, struct request *req, } =20 if (queue_max_discard_segments(req->q) =3D=3D 1) { - u64 slba =3D nvme_sect_to_lba(ns, blk_rq_pos(req)); - u32 nlb =3D blk_rq_sectors(req) >> (ns->lba_shift - 9); + u64 slba =3D nvme_sect_to_lba(head, blk_rq_pos(req)); + u32 nlb =3D blk_rq_sectors(req) >> (head->lba_shift - 9); =20 range[0].cattr =3D cpu_to_le32(0); range[0].nlb =3D cpu_to_le32(nlb); @@ -803,8 +803,9 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *= ns, struct request *req, n =3D 1; } else { __rq_for_each_bio(bio, req) { - u64 slba =3D nvme_sect_to_lba(ns, bio->bi_iter.bi_sector); - u32 nlb =3D bio->bi_iter.bi_size >> ns->lba_shift; + u64 slba =3D nvme_sect_to_lba(head, + bio->bi_iter.bi_sector); + u32 nlb =3D bio->bi_iter.bi_size >> head->lba_shift; =20 if (n < segments) { range[n].cattr =3D cpu_to_le32(0); @@ -825,7 +826,7 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *= ns, struct request *req, =20 memset(cmnd, 0, sizeof(*cmnd)); cmnd->dsm.opcode =3D nvme_cmd_dsm; - cmnd->dsm.nsid =3D cpu_to_le32(ns->head->ns_id); + cmnd->dsm.nsid =3D cpu_to_le32(head->ns_id); cmnd->dsm.nr =3D cpu_to_le32(segments - 1); cmnd->dsm.attributes =3D cpu_to_le32(NVME_DSMGMT_AD); =20 @@ -835,14 +836,14 @@ static blk_status_t nvme_setup_discard(struct nvme_ns= *ns, struct request *req, return BLK_STS_OK; } =20 -static void nvme_set_ref_tag(struct nvme_ns *ns, struct nvme_command *cmnd, - struct request *req) +static void nvme_set_ref_tag(struct nvme_ns_head *head, + struct nvme_command *cmnd, struct request *req) { u32 upper, lower; u64 ref48; =20 /* both rw and write zeroes share the same reftag format */ - switch (ns->guard_type) { + switch (head->guard_type) { case NVME_NVM_NS_16B_GUARD: cmnd->rw.reftag =3D cpu_to_le32(t10_pi_ref_tag(req)); break; @@ -859,7 +860,7 @@ static void nvme_set_ref_tag(struct nvme_ns *ns, struct= nvme_command *cmnd, } } =20 -static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns, +static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns_head *he= ad, struct request *req, struct nvme_command *cmnd) { struct nvme_ctrl *ctrl =3D nvme_req(req)->ctrl; @@ -867,25 +868,25 @@ static inline blk_status_t nvme_setup_write_zeroes(st= ruct nvme_ns *ns, memset(cmnd, 0, sizeof(*cmnd)); =20 if (ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES) - return nvme_setup_discard(ns, req, cmnd); + return nvme_setup_discard(head, req, cmnd); =20 cmnd->write_zeroes.opcode =3D nvme_cmd_write_zeroes; - cmnd->write_zeroes.nsid =3D cpu_to_le32(ns->head->ns_id); + cmnd->write_zeroes.nsid =3D cpu_to_le32(head->ns_id); cmnd->write_zeroes.slba =3D - cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req))); + cpu_to_le64(nvme_sect_to_lba(head, blk_rq_pos(req))); cmnd->write_zeroes.length =3D - cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1); + cpu_to_le16((blk_rq_bytes(req) >> head->lba_shift) - 1); =20 - if (!(req->cmd_flags & REQ_NOUNMAP) && (ns->features & NVME_NS_DEAC)) + if (!(req->cmd_flags & REQ_NOUNMAP) && (head->features & NVME_NS_DEAC)) cmnd->write_zeroes.control |=3D cpu_to_le16(NVME_WZ_DEAC); =20 - if (nvme_ns_has_pi(ns)) { + if (nvme_ns_has_pi(head)) { cmnd->write_zeroes.control |=3D cpu_to_le16(NVME_RW_PRINFO_PRACT); =20 - switch (ns->pi_type) { + switch (head->pi_type) { case NVME_NS_DPS_PI_TYPE1: case NVME_NS_DPS_PI_TYPE2: - nvme_set_ref_tag(ns, cmnd, req); + nvme_set_ref_tag(head, cmnd, req); break; } } @@ -893,7 +894,7 @@ static inline blk_status_t nvme_setup_write_zeroes(stru= ct nvme_ns *ns, return BLK_STS_OK; } =20 -static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, +static inline blk_status_t nvme_setup_rw(struct nvme_ns_head *head, struct request *req, struct nvme_command *cmnd, enum nvme_opcode op) { @@ -910,17 +911,19 @@ static inline blk_status_t nvme_setup_rw(struct nvme_= ns *ns, =20 cmnd->rw.opcode =3D op; cmnd->rw.flags =3D 0; - cmnd->rw.nsid =3D cpu_to_le32(ns->head->ns_id); + cmnd->rw.nsid =3D cpu_to_le32(head->ns_id); cmnd->rw.cdw2 =3D 0; cmnd->rw.cdw3 =3D 0; cmnd->rw.metadata =3D 0; - cmnd->rw.slba =3D cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req))); - cmnd->rw.length =3D cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1); + cmnd->rw.slba =3D + cpu_to_le64(nvme_sect_to_lba(head, blk_rq_pos(req))); + cmnd->rw.length =3D + cpu_to_le16((blk_rq_bytes(req) >> head->lba_shift) - 1); cmnd->rw.reftag =3D 0; cmnd->rw.apptag =3D 0; cmnd->rw.appmask =3D 0; =20 - if (ns->ms) { + if (head->ms) { /* * If formated with metadata, the block layer always provides a * metadata buffer if CONFIG_BLK_DEV_INTEGRITY is enabled. Else @@ -928,12 +931,12 @@ static inline blk_status_t nvme_setup_rw(struct nvme_= ns *ns, * namespace capacity to zero to prevent any I/O. */ if (!blk_integrity_rq(req)) { - if (WARN_ON_ONCE(!nvme_ns_has_pi(ns))) + if (WARN_ON_ONCE(!nvme_ns_has_pi(head))) return BLK_STS_NOTSUPP; control |=3D NVME_RW_PRINFO_PRACT; } =20 - switch (ns->pi_type) { + switch (head->pi_type) { case NVME_NS_DPS_PI_TYPE3: control |=3D NVME_RW_PRINFO_PRCHK_GUARD; break; @@ -943,7 +946,7 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns= *ns, NVME_RW_PRINFO_PRCHK_REF; if (op =3D=3D nvme_cmd_zone_append) control |=3D NVME_RW_APPEND_PIREMAP; - nvme_set_ref_tag(ns, cmnd, req); + nvme_set_ref_tag(head, cmnd, req); break; } } @@ -966,7 +969,7 @@ void nvme_cleanup_cmd(struct request *req) } EXPORT_SYMBOL_GPL(nvme_cleanup_cmd); =20 -blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req) +blk_status_t nvme_setup_cmd(struct nvme_ns_head *head, struct request *req) { struct nvme_command *cmd =3D nvme_req(req)->cmd; blk_status_t ret =3D BLK_STS_OK; @@ -980,35 +983,39 @@ blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struc= t request *req) /* these are setup prior to execution in nvme_init_request() */ break; case REQ_OP_FLUSH: - nvme_setup_flush(ns, cmd); + nvme_setup_flush(head, cmd); break; case REQ_OP_ZONE_RESET_ALL: case REQ_OP_ZONE_RESET: - ret =3D nvme_setup_zone_mgmt_send(ns, req, cmd, NVME_ZONE_RESET); + ret =3D nvme_setup_zone_mgmt_send(head, req, + cmd, NVME_ZONE_RESET); break; case REQ_OP_ZONE_OPEN: - ret =3D nvme_setup_zone_mgmt_send(ns, req, cmd, NVME_ZONE_OPEN); + ret =3D nvme_setup_zone_mgmt_send(head, req, + cmd, NVME_ZONE_OPEN); break; case REQ_OP_ZONE_CLOSE: - ret =3D nvme_setup_zone_mgmt_send(ns, req, cmd, NVME_ZONE_CLOSE); + ret =3D nvme_setup_zone_mgmt_send(head, req, + cmd, NVME_ZONE_CLOSE); break; case REQ_OP_ZONE_FINISH: - ret =3D nvme_setup_zone_mgmt_send(ns, req, cmd, NVME_ZONE_FINISH); + ret =3D nvme_setup_zone_mgmt_send(head, req, + cmd, NVME_ZONE_FINISH); break; case REQ_OP_WRITE_ZEROES: - ret =3D nvme_setup_write_zeroes(ns, req, cmd); + ret =3D nvme_setup_write_zeroes(head, req, cmd); break; case REQ_OP_DISCARD: - ret =3D nvme_setup_discard(ns, req, cmd); + ret =3D nvme_setup_discard(head, req, cmd); break; case REQ_OP_READ: - ret =3D nvme_setup_rw(ns, req, cmd, nvme_cmd_read); + ret =3D nvme_setup_rw(head, req, cmd, nvme_cmd_read); break; case REQ_OP_WRITE: - ret =3D nvme_setup_rw(ns, req, cmd, nvme_cmd_write); + ret =3D nvme_setup_rw(head, req, cmd, nvme_cmd_write); break; case REQ_OP_ZONE_APPEND: - ret =3D nvme_setup_rw(ns, req, cmd, nvme_cmd_zone_append); + ret =3D nvme_setup_rw(head, req, cmd, nvme_cmd_zone_append); break; default: WARN_ON_ONCE(1); @@ -1084,12 +1091,13 @@ int nvme_submit_sync_cmd(struct request_queue *q, s= truct nvme_command *cmd, } EXPORT_SYMBOL_GPL(nvme_submit_sync_cmd); =20 -u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 op= code) +u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns_head *head, + u8 opcode) { u32 effects =3D 0; =20 - if (ns) { - effects =3D le32_to_cpu(ns->head->effects->iocs[opcode]); + if (head) { + effects =3D le32_to_cpu(head->effects->iocs[opcode]); if (effects & ~(NVME_CMD_EFFECTS_CSUPP | NVME_CMD_EFFECTS_LBCC)) dev_warn_once(ctrl->device, "IO command:%02x has unusual effects:%08x\n", @@ -1109,9 +1117,10 @@ u32 nvme_command_effects(struct nvme_ctrl *ctrl, str= uct nvme_ns *ns, u8 opcode) } EXPORT_SYMBOL_NS_GPL(nvme_command_effects, NVME_TARGET_PASSTHRU); =20 -u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opc= ode) +u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns_head *head, + u8 opcode) { - u32 effects =3D nvme_command_effects(ctrl, ns, opcode); + u32 effects =3D nvme_command_effects(ctrl, head, opcode); =20 /* * For simplicity, IO to all namespaces is quiesced even if the command @@ -1129,8 +1138,8 @@ u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struc= t nvme_ns *ns, u8 opcode) } EXPORT_SYMBOL_NS_GPL(nvme_passthru_start, NVME_TARGET_PASSTHRU); =20 -void nvme_passthru_end(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u32 eff= ects, - struct nvme_command *cmd, int status) +void nvme_passthru_end(struct nvme_ctrl *ctrl, struct nvme_ns_head *head, + u32 effects, struct nvme_command *cmd, int status) { if (effects & NVME_CMD_EFFECTS_CSE_MASK) { nvme_unfreeze(ctrl); @@ -1149,7 +1158,7 @@ void nvme_passthru_end(struct nvme_ctrl *ctrl, struct= nvme_ns *ns, u32 effects, nvme_queue_scan(ctrl); flush_work(&ctrl->scan_work); } - if (ns) + if (head) return; =20 switch (cmd->common.opcode) { @@ -1679,9 +1688,9 @@ static void nvme_init_integrity(struct gendisk *disk,= struct nvme_ns *ns, { struct blk_integrity integrity =3D { }; =20 - switch (ns->pi_type) { + switch (ns->head->pi_type) { case NVME_NS_DPS_PI_TYPE3: - switch (ns->guard_type) { + switch (ns->head->guard_type) { case NVME_NVM_NS_16B_GUARD: integrity.profile =3D &t10_pi_type3_crc; integrity.tag_size =3D sizeof(u16) + sizeof(u32); @@ -1699,7 +1708,7 @@ static void nvme_init_integrity(struct gendisk *disk,= struct nvme_ns *ns, break; case NVME_NS_DPS_PI_TYPE1: case NVME_NS_DPS_PI_TYPE2: - switch (ns->guard_type) { + switch (ns->head->guard_type) { case NVME_NVM_NS_16B_GUARD: integrity.profile =3D &t10_pi_type1_crc; integrity.tag_size =3D sizeof(u16); @@ -1720,7 +1729,7 @@ static void nvme_init_integrity(struct gendisk *disk,= struct nvme_ns *ns, break; } =20 - integrity.tuple_size =3D ns->ms; + integrity.tuple_size =3D ns->head->ms; blk_integrity_register(disk, &integrity); blk_queue_max_integrity_segments(disk->queue, max_integrity_segments); } @@ -1737,8 +1746,10 @@ static void nvme_config_discard(struct gendisk *disk= , struct nvme_ns *ns) struct request_queue *queue =3D disk->queue; u32 size =3D queue_logical_block_size(queue); =20 - if (ctrl->dmrsl && ctrl->dmrsl <=3D nvme_sect_to_lba(ns, UINT_MAX)) - ctrl->max_discard_sectors =3D nvme_lba_to_sect(ns, ctrl->dmrsl); + if (ctrl->dmrsl && + ctrl->dmrsl <=3D nvme_sect_to_lba(ns->head, UINT_MAX)) + ctrl->max_discard_sectors =3D + nvme_lba_to_sect(ns->head, ctrl->dmrsl); =20 if (ctrl->max_discard_sectors =3D=3D 0) { blk_queue_max_discard_sectors(queue, 0); @@ -1779,11 +1790,11 @@ static int nvme_init_ms(struct nvme_ns *ns, struct = nvme_id_ns *id) int ret =3D 0; u32 elbaf; =20 - ns->pi_size =3D 0; - ns->ms =3D le16_to_cpu(id->lbaf[lbaf].ms); + ns->head->pi_size =3D 0; + ns->head->ms =3D le16_to_cpu(id->lbaf[lbaf].ms); if (!(ctrl->ctratt & NVME_CTRL_ATTR_ELBAS)) { - ns->pi_size =3D sizeof(struct t10_pi_tuple); - ns->guard_type =3D NVME_NVM_NS_16B_GUARD; + ns->head->pi_size =3D sizeof(struct t10_pi_tuple); + ns->head->guard_type =3D NVME_NVM_NS_16B_GUARD; goto set_pi; } =20 @@ -1806,13 +1817,13 @@ static int nvme_init_ms(struct nvme_ns *ns, struct = nvme_id_ns *id) if (nvme_elbaf_sts(elbaf)) goto free_data; =20 - ns->guard_type =3D nvme_elbaf_guard_type(elbaf); - switch (ns->guard_type) { + ns->head->guard_type =3D nvme_elbaf_guard_type(elbaf); + switch (ns->head->guard_type) { case NVME_NVM_NS_64B_GUARD: - ns->pi_size =3D sizeof(struct crc64_pi_tuple); + ns->head->pi_size =3D sizeof(struct crc64_pi_tuple); break; case NVME_NVM_NS_16B_GUARD: - ns->pi_size =3D sizeof(struct t10_pi_tuple); + ns->head->pi_size =3D sizeof(struct t10_pi_tuple); break; default: break; @@ -1821,10 +1832,10 @@ static int nvme_init_ms(struct nvme_ns *ns, struct = nvme_id_ns *id) free_data: kfree(nvm); set_pi: - if (ns->pi_size && (first || ns->ms =3D=3D ns->pi_size)) - ns->pi_type =3D id->dps & NVME_NS_DPS_PI_MASK; + if (ns->head->pi_size && (first || ns->head->ms =3D=3D ns->head->pi_size)) + ns->head->pi_type =3D id->dps & NVME_NS_DPS_PI_MASK; else - ns->pi_type =3D 0; + ns->head->pi_type =3D 0; =20 return ret; } @@ -1838,8 +1849,8 @@ static int nvme_configure_metadata(struct nvme_ns *ns= , struct nvme_id_ns *id) if (ret) return ret; =20 - ns->features &=3D ~(NVME_NS_METADATA_SUPPORTED | NVME_NS_EXT_LBAS); - if (!ns->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)) + ns->head->features &=3D ~(NVME_NS_METADATA_SUPPORTED | NVME_NS_EXT_LBAS); + if (!ns->head->ms || !(ctrl->ops->flags & NVME_F_METADATA_SUPPORTED)) return 0; =20 if (ctrl->ops->flags & NVME_F_FABRICS) { @@ -1851,7 +1862,7 @@ static int nvme_configure_metadata(struct nvme_ns *ns= , struct nvme_id_ns *id) if (WARN_ON_ONCE(!(id->flbas & NVME_NS_FLBAS_META_EXT))) return 0; =20 - ns->features |=3D NVME_NS_EXT_LBAS; + ns->head->features |=3D NVME_NS_EXT_LBAS; =20 /* * The current fabrics transport drivers support namespace @@ -1862,8 +1873,8 @@ static int nvme_configure_metadata(struct nvme_ns *ns= , struct nvme_id_ns *id) * Note, this check will need to be modified if any drivers * gain the ability to use other metadata formats. */ - if (ctrl->max_integrity_segments && nvme_ns_has_pi(ns)) - ns->features |=3D NVME_NS_METADATA_SUPPORTED; + if (ctrl->max_integrity_segments && nvme_ns_has_pi(ns->head)) + ns->head->features |=3D NVME_NS_METADATA_SUPPORTED; } else { /* * For PCIe controllers, we can't easily remap the separate @@ -1872,9 +1883,9 @@ static int nvme_configure_metadata(struct nvme_ns *ns= , struct nvme_id_ns *id) * We allow extended LBAs for the passthrough interface, though. */ if (id->flbas & NVME_NS_FLBAS_META_EXT) - ns->features |=3D NVME_NS_EXT_LBAS; + ns->head->features |=3D NVME_NS_EXT_LBAS; else - ns->features |=3D NVME_NS_METADATA_SUPPORTED; + ns->head->features |=3D NVME_NS_METADATA_SUPPORTED; } return 0; } @@ -1900,8 +1911,8 @@ static void nvme_set_queue_limits(struct nvme_ctrl *c= trl, static void nvme_update_disk_info(struct gendisk *disk, struct nvme_ns *ns, struct nvme_id_ns *id) { - sector_t capacity =3D nvme_lba_to_sect(ns, le64_to_cpu(id->nsze)); - u32 bs =3D 1U << ns->lba_shift; + sector_t capacity =3D nvme_lba_to_sect(ns->head, le64_to_cpu(id->nsze)); + u32 bs =3D 1U << ns->head->lba_shift; u32 atomic_bs, phys_bs, io_opt =3D 0; =20 /* @@ -1909,7 +1920,8 @@ static void nvme_update_disk_info(struct gendisk *dis= k, * or smaller than a sector size yet, so catch this early and don't * allow block I/O. */ - if (ns->lba_shift > PAGE_SHIFT || ns->lba_shift < SECTOR_SHIFT) { + if (ns->head->lba_shift > PAGE_SHIFT || + ns->head->lba_shift < SECTOR_SHIFT) { capacity =3D 0; bs =3D (1 << 9); } @@ -1952,12 +1964,12 @@ static void nvme_update_disk_info(struct gendisk *d= isk, * I/O to namespaces with metadata except when the namespace supports * PI, as it can strip/insert in that case. */ - if (ns->ms) { + if (ns->head->ms) { if (IS_ENABLED(CONFIG_BLK_DEV_INTEGRITY) && - (ns->features & NVME_NS_METADATA_SUPPORTED)) + (ns->head->features & NVME_NS_METADATA_SUPPORTED)) nvme_init_integrity(disk, ns, ns->ctrl->max_integrity_segments); - else if (!nvme_ns_has_pi(ns)) + else if (!nvme_ns_has_pi(ns->head)) capacity =3D 0; } =20 @@ -1988,7 +2000,7 @@ static void nvme_set_chunk_sectors(struct nvme_ns *ns= , struct nvme_id_ns *id) is_power_of_2(ctrl->max_hw_sectors)) iob =3D ctrl->max_hw_sectors; else - iob =3D nvme_lba_to_sect(ns, le16_to_cpu(id->noiob)); + iob =3D nvme_lba_to_sect(ns->head, le16_to_cpu(id->noiob)); =20 if (!iob) return; @@ -2021,7 +2033,7 @@ static int nvme_update_ns_info_generic(struct nvme_ns= *ns, if (nvme_ns_head_multipath(ns->head)) { blk_mq_freeze_queue(ns->head->disk->queue); set_disk_ro(ns->head->disk, nvme_ns_is_readonly(ns, info)); - nvme_mpath_revalidate_paths(ns); + nvme_mpath_revalidate_paths(ns->head); blk_stack_limits(&ns->head->disk->queue->limits, &ns->queue->limits, 0); ns->head->disk->flags |=3D GENHD_FL_HIDDEN; @@ -2055,7 +2067,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *= ns, =20 blk_mq_freeze_queue(ns->disk->queue); lbaf =3D nvme_lbaf_index(id->flbas); - ns->lba_shift =3D id->lbaf[lbaf].ds; + ns->head->lba_shift =3D id->lbaf[lbaf].ds; nvme_set_queue_limits(ns->ctrl, ns->queue); =20 ret =3D nvme_configure_metadata(ns, id); @@ -2081,7 +2093,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *= ns, * do not return zeroes. */ if ((id->dlfeat & 0x7) =3D=3D 0x1 && (id->dlfeat & (1 << 3))) - ns->features |=3D NVME_NS_DEAC; + ns->head->features |=3D NVME_NS_DEAC; set_disk_ro(ns->disk, nvme_ns_is_readonly(ns, info)); set_bit(NVME_NS_READY, &ns->flags); blk_mq_unfreeze_queue(ns->disk->queue); @@ -2096,7 +2108,7 @@ static int nvme_update_ns_info_block(struct nvme_ns *= ns, blk_mq_freeze_queue(ns->head->disk->queue); nvme_update_disk_info(ns->head->disk, ns, id); set_disk_ro(ns->head->disk, nvme_ns_is_readonly(ns, info)); - nvme_mpath_revalidate_paths(ns); + nvme_mpath_revalidate_paths(ns->head); blk_stack_limits(&ns->head->disk->queue->limits, &ns->queue->limits, 0); disk_update_readahead(ns->head->disk); @@ -3618,7 +3630,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, str= uct nvme_ns_info *info) if (nvme_init_ns_head(ctrl, info, &ns->head)) goto out_free_ns; =20 - disk =3D blk_mq_alloc_disk(ctrl->tagset, ns); + disk =3D blk_mq_alloc_disk(ctrl->tagset, ns->head); if (IS_ERR(disk)) goto out_free_head; disk->fops =3D &nvme_bdev_ops; diff --git a/drivers/nvme/host/fc.c b/drivers/nvme/host/fc.c index fb22976a36a8..41f9bacae6f4 100644 --- a/drivers/nvme/host/fc.c +++ b/drivers/nvme/host/fc.c @@ -2799,7 +2799,7 @@ static blk_status_t nvme_fc_queue_rq(struct blk_mq_hw_ctx *hctx, const struct blk_mq_queue_data *bd) { - struct nvme_ns *ns =3D hctx->queue->queuedata; + struct nvme_ns_head *head =3D hctx->queue->queuedata; struct nvme_fc_queue *queue =3D hctx->driver_data; struct nvme_fc_ctrl *ctrl =3D queue->ctrl; struct request *rq =3D bd->rq; @@ -2813,7 +2813,7 @@ nvme_fc_queue_rq(struct blk_mq_hw_ctx *hctx, !nvme_check_ready(&queue->ctrl->ctrl, rq, queue_ready)) return nvme_fail_nonready_command(&queue->ctrl->ctrl, rq); =20 - ret =3D nvme_setup_cmd(ns, rq); + ret =3D nvme_setup_cmd(head, rq); if (ret) return ret; =20 diff --git a/drivers/nvme/host/ioctl.c b/drivers/nvme/host/ioctl.c index 529b9954d2b8..29263009bb6e 100644 --- a/drivers/nvme/host/ioctl.c +++ b/drivers/nvme/host/ioctl.c @@ -61,7 +61,7 @@ static bool nvme_cmd_allowed(struct nvme_ns *ns, struct n= vme_command *c, * and marks this command as supported. If not reject unprivileged * passthrough. */ - effects =3D nvme_command_effects(ns->ctrl, ns, c->common.opcode); + effects =3D nvme_command_effects(ns->ctrl, ns->head, c->common.opcode); if (!(effects & NVME_CMD_EFFECTS_CSUPP)) return false; =20 @@ -168,8 +168,8 @@ static int nvme_map_user_request(struct request *req, u= 64 ubuffer, unsigned int flags) { struct request_queue *q =3D req->q; - struct nvme_ns *ns =3D q->queuedata; - struct block_device *bdev =3D ns ? ns->disk->part0 : NULL; + struct nvme_ns_head *head =3D q->queuedata; + struct block_device *bdev =3D head ? head->disk->part0 : NULL; struct bio *bio =3D NULL; void *meta =3D NULL; int ret; @@ -222,7 +222,7 @@ static int nvme_submit_user_cmd(struct request_queue *q, void __user *meta_buffer, unsigned meta_len, u32 meta_seed, u64 *result, unsigned timeout, unsigned int flags) { - struct nvme_ns *ns =3D q->queuedata; + struct nvme_ns_head *head =3D q->queuedata; struct nvme_ctrl *ctrl; struct request *req; void *meta =3D NULL; @@ -245,7 +245,7 @@ static int nvme_submit_user_cmd(struct request_queue *q, bio =3D req->bio; ctrl =3D nvme_req(req)->ctrl; =20 - effects =3D nvme_passthru_start(ctrl, ns, cmd->common.opcode); + effects =3D nvme_passthru_start(ctrl, head, cmd->common.opcode); ret =3D nvme_execute_rq(req, false); if (result) *result =3D le64_to_cpu(nvme_req(req)->result.u64); @@ -257,7 +257,7 @@ static int nvme_submit_user_cmd(struct request_queue *q, blk_mq_free_request(req); =20 if (effects) - nvme_passthru_end(ctrl, ns, effects, cmd, ret); + nvme_passthru_end(ctrl, head, effects, cmd, ret); =20 return ret; } @@ -283,10 +283,10 @@ static int nvme_submit_io(struct nvme_ns *ns, struct = nvme_user_io __user *uio) return -EINVAL; } =20 - length =3D (io.nblocks + 1) << ns->lba_shift; + length =3D (io.nblocks + 1) << ns->head->lba_shift; =20 if ((io.control & NVME_RW_PRINFO_PRACT) && - ns->ms =3D=3D sizeof(struct t10_pi_tuple)) { + ns->head->ms =3D=3D sizeof(struct t10_pi_tuple)) { /* * Protection information is stripped/inserted by the * controller. @@ -296,11 +296,11 @@ static int nvme_submit_io(struct nvme_ns *ns, struct = nvme_user_io __user *uio) meta_len =3D 0; metadata =3D NULL; } else { - meta_len =3D (io.nblocks + 1) * ns->ms; + meta_len =3D (io.nblocks + 1) * ns->head->ms; metadata =3D nvme_to_user_ptr(io.metadata); } =20 - if (ns->features & NVME_NS_EXT_LBAS) { + if (ns->head->features & NVME_NS_EXT_LBAS) { length +=3D meta_len; meta_len =3D 0; } else if (meta_len) { diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c index 0a88d7bdc5e3..24ccd5b9c350 100644 --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -82,11 +82,14 @@ void nvme_mpath_start_freeze(struct nvme_subsystem *sub= sys) =20 void nvme_failover_req(struct request *req) { - struct nvme_ns *ns =3D req->q->queuedata; + struct nvme_ns_head *head =3D req->q->queuedata; + struct nvme_ctrl *ctrl =3D nvme_req(req)->ctrl; + struct nvme_ns *ns; u16 status =3D nvme_req(req)->status & 0x7ff; unsigned long flags; struct bio *bio; =20 + ns =3D nvme_find_get_ns(ctrl, head->ns_id); nvme_mpath_clear_current_path(ns); =20 /* @@ -94,14 +97,14 @@ void nvme_failover_req(struct request *req) * ready to serve this namespace. Kick of a re-read of the ANA * information page, and just try any other available path for now. */ - if (nvme_is_ana_error(status) && ns->ctrl->ana_log_buf) { + if (nvme_is_ana_error(status) && ctrl->ana_log_buf) { set_bit(NVME_NS_ANA_PENDING, &ns->flags); - queue_work(nvme_wq, &ns->ctrl->ana_work); + queue_work(nvme_wq, &ctrl->ana_work); } =20 - spin_lock_irqsave(&ns->head->requeue_lock, flags); + spin_lock_irqsave(&head->requeue_lock, flags); for (bio =3D req->bio; bio; bio =3D bio->bi_next) { - bio_set_dev(bio, ns->head->disk->part0); + bio_set_dev(bio, head->disk->part0); if (bio->bi_opf & REQ_POLLED) { bio->bi_opf &=3D ~REQ_POLLED; bio->bi_cookie =3D BLK_QC_T_NONE; @@ -115,17 +118,17 @@ void nvme_failover_req(struct request *req) */ bio->bi_opf &=3D ~REQ_NOWAIT; } - blk_steal_bios(&ns->head->requeue_list, req); - spin_unlock_irqrestore(&ns->head->requeue_lock, flags); + blk_steal_bios(&head->requeue_list, req); + spin_unlock_irqrestore(&head->requeue_lock, flags); =20 blk_mq_end_request(req, 0); - kblockd_schedule_work(&ns->head->requeue_work); + kblockd_schedule_work(&head->requeue_work); } =20 void nvme_mpath_start_request(struct request *rq) { - struct nvme_ns *ns =3D rq->q->queuedata; - struct gendisk *disk =3D ns->head->disk; + struct nvme_ns_head *head =3D rq->q->queuedata; + struct gendisk *disk =3D head->disk; =20 if (!blk_queue_io_stat(disk->queue) || blk_rq_is_passthrough(rq)) return; @@ -138,11 +141,11 @@ EXPORT_SYMBOL_GPL(nvme_mpath_start_request); =20 void nvme_mpath_end_request(struct request *rq) { - struct nvme_ns *ns =3D rq->q->queuedata; + struct nvme_ns_head *head =3D rq->q->queuedata; =20 if (!(nvme_req(rq)->flags & NVME_MPATH_IO_STATS)) return; - bdev_end_io_acct(ns->head->disk->part0, req_op(rq), + bdev_end_io_acct(head->disk->part0, req_op(rq), blk_rq_bytes(rq) >> SECTOR_SHIFT, nvme_req(rq)->start_time); } @@ -202,10 +205,10 @@ void nvme_mpath_clear_ctrl_paths(struct nvme_ctrl *ct= rl) up_read(&ctrl->namespaces_rwsem); } =20 -void nvme_mpath_revalidate_paths(struct nvme_ns *ns) +void nvme_mpath_revalidate_paths(struct nvme_ns_head *head) { - struct nvme_ns_head *head =3D ns->head; sector_t capacity =3D get_capacity(head->disk); + struct nvme_ns *ns; int node; int srcu_idx; =20 diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 578e6d311bc9..e6c7890b14c9 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -451,6 +451,17 @@ struct nvme_ns_head { bool shared; int instance; struct nvme_effects_log *effects; + int lba_shift; + u16 ms; + u16 pi_size; + u16 sgs; + u32 sws; + u8 pi_type; + u8 guard_type; +#ifdef CONFIG_BLK_DEV_ZONED + u64 zsze; +#endif + unsigned long features; =20 struct cdev cdev; struct device cdev_device; @@ -492,17 +503,6 @@ struct nvme_ns { struct kref kref; struct nvme_ns_head *head; =20 - int lba_shift; - u16 ms; - u16 pi_size; - u16 sgs; - u32 sws; - u8 pi_type; - u8 guard_type; -#ifdef CONFIG_BLK_DEV_ZONED - u64 zsze; -#endif - unsigned long features; unsigned long flags; #define NVME_NS_REMOVING 0 #define NVME_NS_ANA_PENDING 2 @@ -517,9 +517,9 @@ struct nvme_ns { }; =20 /* NVMe ns supports metadata actions by the controller (generate/strip) */ -static inline bool nvme_ns_has_pi(struct nvme_ns *ns) +static inline bool nvme_ns_has_pi(struct nvme_ns_head *head) { - return ns->pi_type && ns->ms =3D=3D ns->pi_size; + return head->pi_type && head->ms =3D=3D head->pi_size; } =20 struct nvme_ctrl_ops { @@ -651,17 +651,17 @@ static inline int nvme_reset_subsystem(struct nvme_ct= rl *ctrl) /* * Convert a 512B sector number to a device logical block number. */ -static inline u64 nvme_sect_to_lba(struct nvme_ns *ns, sector_t sector) +static inline u64 nvme_sect_to_lba(struct nvme_ns_head *head, sector_t sec= tor) { - return sector >> (ns->lba_shift - SECTOR_SHIFT); + return sector >> (head->lba_shift - SECTOR_SHIFT); } =20 /* * Convert a device logical block number to a 512B sector number. */ -static inline sector_t nvme_lba_to_sect(struct nvme_ns *ns, u64 lba) +static inline sector_t nvme_lba_to_sect(struct nvme_ns_head *head, u64 lba) { - return lba << (ns->lba_shift - SECTOR_SHIFT); + return lba << (head->lba_shift - SECTOR_SHIFT); } =20 /* @@ -792,7 +792,7 @@ static inline enum req_op nvme_req_op(struct nvme_comma= nd *cmd) #define NVME_QID_ANY -1 void nvme_init_request(struct request *req, struct nvme_command *cmd); void nvme_cleanup_cmd(struct request *req); -blk_status_t nvme_setup_cmd(struct nvme_ns *ns, struct request *req); +blk_status_t nvme_setup_cmd(struct nvme_ns_head *head, struct request *req= ); blk_status_t nvme_fail_nonready_command(struct nvme_ctrl *ctrl, struct request *req); bool __nvme_check_ready(struct nvme_ctrl *ctrl, struct request *rq, @@ -901,7 +901,7 @@ void nvme_mpath_update(struct nvme_ctrl *ctrl); void nvme_mpath_uninit(struct nvme_ctrl *ctrl); void nvme_mpath_stop(struct nvme_ctrl *ctrl); bool nvme_mpath_clear_current_path(struct nvme_ns *ns); -void nvme_mpath_revalidate_paths(struct nvme_ns *ns); +void nvme_mpath_revalidate_paths(struct nvme_ns_head *head); void nvme_mpath_clear_ctrl_paths(struct nvme_ctrl *ctrl); void nvme_mpath_shutdown_disk(struct nvme_ns_head *head); void nvme_mpath_start_request(struct request *rq); @@ -909,10 +909,10 @@ void nvme_mpath_end_request(struct request *rq); =20 static inline void nvme_trace_bio_complete(struct request *req) { - struct nvme_ns *ns =3D req->q->queuedata; + struct nvme_ns_head *head =3D req->q->queuedata; =20 if ((req->cmd_flags & REQ_NVME_MPATH) && req->bio) - trace_block_bio_complete(ns->head->disk->queue, req->bio); + trace_block_bio_complete(head->disk->queue, req->bio); } =20 extern bool multipath; @@ -1004,13 +1004,14 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector= _t sector, unsigned int nr_zones, report_zones_cb cb, void *data); #ifdef CONFIG_BLK_DEV_ZONED int nvme_update_zone_info(struct nvme_ns *ns, unsigned lbaf); -blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *ns, struct request = *req, +blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns_head *head, + struct request *req, struct nvme_command *cmnd, enum nvme_zone_mgmt_action action); #else -static inline blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *ns, - struct request *req, struct nvme_command *cmnd, - enum nvme_zone_mgmt_action action) +static inline blk_status_t nvme_setup_zone_mgmt_send( + struct nvme_ns_head *head, struct request *req, + struct nvme_command *cmnd, enum nvme_zone_mgmt_action action) { return BLK_STS_NOTSUPP; } @@ -1086,12 +1087,13 @@ static inline int nvme_auth_wait(struct nvme_ctrl *= ctrl, int qid) static inline void nvme_auth_free(struct nvme_ctrl *ctrl) {}; #endif =20 -u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns *ns, +u32 nvme_command_effects(struct nvme_ctrl *ctrl, struct nvme_ns_head *head, u8 opcode); -u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u8 opc= ode); +u32 nvme_passthru_start(struct nvme_ctrl *ctrl, struct nvme_ns_head *head, + u8 opcode); int nvme_execute_rq(struct request *rq, bool at_head); -void nvme_passthru_end(struct nvme_ctrl *ctrl, struct nvme_ns *ns, u32 eff= ects, - struct nvme_command *cmd, int status); +void nvme_passthru_end(struct nvme_ctrl *ctrl, struct nvme_ns_head *head, + u32 effects, struct nvme_command *cmd, int status); struct nvme_ctrl *nvme_ctrl_from_file(struct file *file); struct nvme_ns *nvme_find_get_ns(struct nvme_ctrl *ctrl, unsigned nsid); void nvme_put_ns(struct nvme_ns *ns); diff --git a/drivers/nvme/host/rdma.c b/drivers/nvme/host/rdma.c index 81e2621169e5..0e967413ee43 100644 --- a/drivers/nvme/host/rdma.c +++ b/drivers/nvme/host/rdma.c @@ -1407,7 +1407,7 @@ static int nvme_rdma_map_sg_pi(struct nvme_rdma_queue= *queue, struct nvme_rdma_sgl *sgl =3D &req->data_sgl; struct ib_reg_wr *wr =3D &req->reg_wr; struct request *rq =3D blk_mq_rq_from_pdu(req); - struct nvme_ns *ns =3D rq->q->queuedata; + struct nvme_ns_head *head =3D rq->q->queuedata; struct bio *bio =3D rq->bio; struct nvme_keyed_sgl_desc *sg =3D &c->common.dptr.ksgl; int nr; @@ -1423,7 +1423,7 @@ static int nvme_rdma_map_sg_pi(struct nvme_rdma_queue= *queue, goto mr_put; =20 nvme_rdma_set_sig_attrs(blk_get_integrity(bio->bi_bdev->bd_disk), c, - req->mr->sig_attrs, ns->pi_type); + req->mr->sig_attrs, head->pi_type); nvme_rdma_set_prot_checks(c, &req->mr->sig_attrs->check_mask); =20 ib_update_fast_reg_key(req->mr, ib_inc_rkey(req->mr->rkey)); @@ -1979,7 +1979,7 @@ static enum blk_eh_timer_return nvme_rdma_timeout(str= uct request *rq) static blk_status_t nvme_rdma_queue_rq(struct blk_mq_hw_ctx *hctx, const struct blk_mq_queue_data *bd) { - struct nvme_ns *ns =3D hctx->queue->queuedata; + struct nvme_ns_head *head =3D hctx->queue->queuedata; struct nvme_rdma_queue *queue =3D hctx->driver_data; struct request *rq =3D bd->rq; struct nvme_rdma_request *req =3D blk_mq_rq_to_pdu(rq); @@ -2007,7 +2007,7 @@ static blk_status_t nvme_rdma_queue_rq(struct blk_mq_= hw_ctx *hctx, ib_dma_sync_single_for_cpu(dev, sqe->dma, sizeof(struct nvme_command), DMA_TO_DEVICE); =20 - ret =3D nvme_setup_cmd(ns, rq); + ret =3D nvme_setup_cmd(head, rq); if (ret) goto unmap_qe; =20 @@ -2017,7 +2017,7 @@ static blk_status_t nvme_rdma_queue_rq(struct blk_mq_= hw_ctx *hctx, queue->pi_support && (c->common.opcode =3D=3D nvme_cmd_write || c->common.opcode =3D=3D nvme_cmd_read) && - nvme_ns_has_pi(ns)) + nvme_ns_has_pi(head)) req->use_sig_mr =3D true; else req->use_sig_mr =3D false; diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 08805f027810..169462faad47 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -2483,7 +2483,7 @@ static blk_status_t nvme_tcp_map_data(struct nvme_tcp= _queue *queue, return 0; } =20 -static blk_status_t nvme_tcp_setup_cmd_pdu(struct nvme_ns *ns, +static blk_status_t nvme_tcp_setup_cmd_pdu(struct nvme_ns_head *head, struct request *rq) { struct nvme_tcp_request *req =3D blk_mq_rq_to_pdu(rq); @@ -2492,7 +2492,7 @@ static blk_status_t nvme_tcp_setup_cmd_pdu(struct nvm= e_ns *ns, u8 hdgst =3D nvme_tcp_hdgst_len(queue), ddgst =3D 0; blk_status_t ret; =20 - ret =3D nvme_setup_cmd(ns, rq); + ret =3D nvme_setup_cmd(head, rq); if (ret) return ret; =20 @@ -2548,7 +2548,7 @@ static void nvme_tcp_commit_rqs(struct blk_mq_hw_ctx = *hctx) static blk_status_t nvme_tcp_queue_rq(struct blk_mq_hw_ctx *hctx, const struct blk_mq_queue_data *bd) { - struct nvme_ns *ns =3D hctx->queue->queuedata; + struct nvme_ns_head *head =3D hctx->queue->queuedata; struct nvme_tcp_queue *queue =3D hctx->driver_data; struct request *rq =3D bd->rq; struct nvme_tcp_request *req =3D blk_mq_rq_to_pdu(rq); @@ -2558,7 +2558,7 @@ static blk_status_t nvme_tcp_queue_rq(struct blk_mq_h= w_ctx *hctx, if (!nvme_check_ready(&queue->ctrl->ctrl, rq, queue_ready)) return nvme_fail_nonready_command(&queue->ctrl->ctrl, rq); =20 - ret =3D nvme_tcp_setup_cmd_pdu(ns, rq); + ret =3D nvme_tcp_setup_cmd_pdu(head, rq); if (unlikely(ret)) return ret; =20 diff --git a/drivers/nvme/host/zns.c b/drivers/nvme/host/zns.c index ec8557810c21..51ac3a61ce3f 100644 --- a/drivers/nvme/host/zns.c +++ b/drivers/nvme/host/zns.c @@ -11,7 +11,7 @@ int nvme_revalidate_zones(struct nvme_ns *ns) { struct request_queue *q =3D ns->queue; =20 - blk_queue_chunk_sectors(q, ns->zsze); + blk_queue_chunk_sectors(q, ns->head->zsze); blk_queue_max_zone_append_sectors(q, ns->ctrl->max_zone_append); =20 return blk_revalidate_disk_zones(ns->disk, NULL); @@ -99,11 +99,12 @@ int nvme_update_zone_info(struct nvme_ns *ns, unsigned = lbaf) goto free_data; } =20 - ns->zsze =3D nvme_lba_to_sect(ns, le64_to_cpu(id->lbafe[lbaf].zsze)); - if (!is_power_of_2(ns->zsze)) { + ns->head->zsze =3D + nvme_lba_to_sect(ns->head, le64_to_cpu(id->lbafe[lbaf].zsze)); + if (!is_power_of_2(ns->head->zsze)) { dev_warn(ns->ctrl->device, "invalid zone size:%llu for namespace:%u\n", - ns->zsze, ns->head->ns_id); + ns->head->zsze, ns->head->ns_id); status =3D -ENODEV; goto free_data; } @@ -128,7 +129,7 @@ static void *nvme_zns_alloc_report_buffer(struct nvme_n= s *ns, sizeof(struct nvme_zone_descriptor); =20 nr_zones =3D min_t(unsigned int, nr_zones, - get_capacity(ns->disk) >> ilog2(ns->zsze)); + get_capacity(ns->head->disk) >> ilog2(ns->head->zsze)); =20 bufsize =3D sizeof(struct nvme_zone_report) + nr_zones * sizeof(struct nvme_zone_descriptor); @@ -162,13 +163,13 @@ static int nvme_zone_parse_entry(struct nvme_ns *ns, =20 zone.type =3D BLK_ZONE_TYPE_SEQWRITE_REQ; zone.cond =3D entry->zs >> 4; - zone.len =3D ns->zsze; - zone.capacity =3D nvme_lba_to_sect(ns, le64_to_cpu(entry->zcap)); - zone.start =3D nvme_lba_to_sect(ns, le64_to_cpu(entry->zslba)); + zone.len =3D ns->head->zsze; + zone.capacity =3D nvme_lba_to_sect(ns->head, le64_to_cpu(entry->zcap)); + zone.start =3D nvme_lba_to_sect(ns->head, le64_to_cpu(entry->zslba)); if (zone.cond =3D=3D BLK_ZONE_COND_FULL) zone.wp =3D zone.start + zone.len; else - zone.wp =3D nvme_lba_to_sect(ns, le64_to_cpu(entry->wp)); + zone.wp =3D nvme_lba_to_sect(ns->head, le64_to_cpu(entry->wp)); =20 return cb(&zone, idx, data); } @@ -196,11 +197,11 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t= sector, c.zmr.zrasf =3D NVME_ZRASF_ZONE_REPORT_ALL; c.zmr.pr =3D NVME_REPORT_ZONE_PARTIAL; =20 - sector &=3D ~(ns->zsze - 1); + sector &=3D ~(ns->head->zsze - 1); while (zone_idx < nr_zones && sector < get_capacity(ns->disk)) { memset(report, 0, buflen); =20 - c.zmr.slba =3D cpu_to_le64(nvme_sect_to_lba(ns, sector)); + c.zmr.slba =3D cpu_to_le64(nvme_sect_to_lba(ns->head, sector)); ret =3D nvme_submit_sync_cmd(ns->queue, &c, report, buflen); if (ret) { if (ret > 0) @@ -220,7 +221,7 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t s= ector, zone_idx++; } =20 - sector +=3D ns->zsze * nz; + sector +=3D ns->head->zsze * nz; } =20 if (zone_idx > 0) @@ -232,14 +233,15 @@ int nvme_ns_report_zones(struct nvme_ns *ns, sector_t= sector, return ret; } =20 -blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns *ns, struct request = *req, - struct nvme_command *c, enum nvme_zone_mgmt_action action) +blk_status_t nvme_setup_zone_mgmt_send(struct nvme_ns_head *head, + struct request *req, struct nvme_command *c, + enum nvme_zone_mgmt_action action) { memset(c, 0, sizeof(*c)); =20 c->zms.opcode =3D nvme_cmd_zone_mgmt_send; - c->zms.nsid =3D cpu_to_le32(ns->head->ns_id); - c->zms.slba =3D cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req))); + c->zms.nsid =3D cpu_to_le32(head->ns_id); + c->zms.slba =3D cpu_to_le64(nvme_sect_to_lba(head, blk_rq_pos(req))); c->zms.zsa =3D action; =20 if (req_op(req) =3D=3D REQ_OP_ZONE_RESET_ALL) diff --git a/drivers/nvme/target/loop.c b/drivers/nvme/target/loop.c index 9cb434c58075..1c3abadecaa7 100644 --- a/drivers/nvme/target/loop.c +++ b/drivers/nvme/target/loop.c @@ -131,7 +131,7 @@ static void nvme_loop_execute_work(struct work_struct *= work) static blk_status_t nvme_loop_queue_rq(struct blk_mq_hw_ctx *hctx, const struct blk_mq_queue_data *bd) { - struct nvme_ns *ns =3D hctx->queue->queuedata; + struct nvme_ns_head *head =3D hctx->queue->queuedata; struct nvme_loop_queue *queue =3D hctx->driver_data; struct request *req =3D bd->rq; struct nvme_loop_iod *iod =3D blk_mq_rq_to_pdu(req); @@ -141,7 +141,7 @@ static blk_status_t nvme_loop_queue_rq(struct blk_mq_hw= _ctx *hctx, if (!nvme_check_ready(&queue->ctrl->ctrl, req, queue_ready)) return nvme_fail_nonready_command(&queue->ctrl->ctrl, req); =20 - ret =3D nvme_setup_cmd(ns, req); + ret =3D nvme_setup_cmd(head, req); if (ret) return ret; =20 diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c index 9fe07d7efa96..7c13084a8f87 100644 --- a/drivers/nvme/target/passthru.c +++ b/drivers/nvme/target/passthru.c @@ -216,11 +216,11 @@ static void nvmet_passthru_execute_cmd_work(struct wo= rk_struct *w) struct nvmet_req *req =3D container_of(w, struct nvmet_req, p.work); struct request *rq =3D req->p.rq; struct nvme_ctrl *ctrl =3D nvme_req(rq)->ctrl; - struct nvme_ns *ns =3D rq->q->queuedata; + struct nvme_ns_head *head =3D rq->q->queuedata; u32 effects; int status; =20 - effects =3D nvme_passthru_start(ctrl, ns, req->cmd->common.opcode); + effects =3D nvme_passthru_start(ctrl, head, req->cmd->common.opcode); status =3D nvme_execute_rq(rq, false); if (status =3D=3D NVME_SC_SUCCESS && req->cmd->common.opcode =3D=3D nvme_admin_identify) { @@ -243,7 +243,7 @@ static void nvmet_passthru_execute_cmd_work(struct work= _struct *w) blk_mq_free_request(rq); =20 if (effects) - nvme_passthru_end(ctrl, ns, effects, req->cmd, status); + nvme_passthru_end(ctrl, head, effects, req->cmd, status); } =20 static enum rq_end_io_ret nvmet_passthru_req_done(struct request *rq, @@ -339,7 +339,7 @@ static void nvmet_passthru_execute_cmd(struct nvmet_req= *req) * non-trivial effects, make sure to execute the command synchronously * in a workqueue so that nvme_passthru_end gets called. */ - effects =3D nvme_command_effects(ctrl, ns, req->cmd->common.opcode); + effects =3D nvme_command_effects(ctrl, ns->head, req->cmd->common.opcode); if (req->p.use_workqueue || (effects & ~(NVME_CMD_EFFECTS_CSUPP | NVME_CMD_EFFECTS_LBCC))) { INIT_WORK(&req->p.work, nvmet_passthru_execute_cmd_work); --=20 2.43.0