LCOV - code coverage report
Current view: top level - spdk/lib/nvmf - ctrlr.c (source / functions) Hit Total Coverage
Test: Combined Lines: 2160 2862 75.5 %
Date: 2024-11-20 09:04:35 Functions: 130 154 84.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4390 10903 40.3 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2017 Intel Corporation. All rights reserved.
       3                 :            :  *   Copyright (c) 2019, 2020 Mellanox Technologies LTD. All rights reserved.
       4                 :            :  *   Copyright (c) 2021, 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
       5                 :            :  */
       6                 :            : 
       7                 :            : #include "spdk/stdinc.h"
       8                 :            : 
       9                 :            : #include "nvmf_internal.h"
      10                 :            : #include "transport.h"
      11                 :            : 
      12                 :            : #include "spdk/bdev.h"
      13                 :            : #include "spdk/bdev_zone.h"
      14                 :            : #include "spdk/bit_array.h"
      15                 :            : #include "spdk/endian.h"
      16                 :            : #include "spdk/thread.h"
      17                 :            : #include "spdk/nvme_spec.h"
      18                 :            : #include "spdk/nvmf_cmd.h"
      19                 :            : #include "spdk/string.h"
      20                 :            : #include "spdk/util.h"
      21                 :            : #include "spdk/version.h"
      22                 :            : #include "spdk/log.h"
      23                 :            : #include "spdk_internal/usdt.h"
      24                 :            : 
      25                 :            : #define MIN_KEEP_ALIVE_TIMEOUT_IN_MS 10000
      26                 :            : #define NVMF_DISC_KATO_IN_MS 120000
      27                 :            : #define KAS_TIME_UNIT_IN_MS 100
      28                 :            : #define KAS_DEFAULT_VALUE (MIN_KEEP_ALIVE_TIMEOUT_IN_MS / KAS_TIME_UNIT_IN_MS)
      29                 :            : 
      30                 :            : #define NVMF_CC_RESET_SHN_TIMEOUT_IN_MS 10000
      31                 :            : 
      32                 :            : #define NVMF_CTRLR_RESET_SHN_TIMEOUT_IN_MS      (NVMF_CC_RESET_SHN_TIMEOUT_IN_MS + 5000)
      33                 :            : 
      34                 :            : #define DUPLICATE_QID_RETRY_US 1000
      35                 :            : 
      36                 :            : /*
      37                 :            :  * Report the SPDK version as the firmware revision.
      38                 :            :  * SPDK_VERSION_STRING won't fit into FR (only 8 bytes), so try to fit the most important parts.
      39                 :            :  */
      40                 :            : #define FW_VERSION SPDK_VERSION_MAJOR_STRING SPDK_VERSION_MINOR_STRING SPDK_VERSION_PATCH_STRING
      41                 :            : 
      42                 :            : #define ANA_TRANSITION_TIME_IN_SEC 10
      43                 :            : 
      44                 :            : #define NVMF_ABORT_COMMAND_LIMIT 3
      45                 :            : 
      46                 :            : /*
      47                 :            :  * Support for custom admin command handlers
      48                 :            :  */
      49                 :            : struct spdk_nvmf_custom_admin_cmd {
      50                 :            :         spdk_nvmf_custom_cmd_hdlr hdlr;
      51                 :            :         uint32_t nsid; /* nsid to forward */
      52                 :            : };
      53                 :            : 
      54                 :            : static struct spdk_nvmf_custom_admin_cmd g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_MAX_OPC + 1];
      55                 :            : 
      56                 :            : static void _nvmf_request_complete(void *ctx);
      57                 :            : int nvmf_passthru_admin_cmd_for_ctrlr(struct spdk_nvmf_request *req, struct spdk_nvmf_ctrlr *ctrlr);
      58                 :            : 
      59                 :            : static inline void
      60                 :        578 : nvmf_invalid_connect_response(struct spdk_nvmf_fabric_connect_rsp *rsp,
      61                 :            :                               uint8_t iattr, uint16_t ipo)
      62                 :            : {
      63   [ +  -  +  - ]:        578 :         rsp->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
      64   [ +  -  +  - ]:        578 :         rsp->status.sc = SPDK_NVMF_FABRIC_SC_INVALID_PARAM;
      65   [ +  -  +  -  :        578 :         rsp->status_code_specific.invalid.iattr = iattr;
             +  -  +  - ]
      66   [ +  -  +  -  :        578 :         rsp->status_code_specific.invalid.ipo = ipo;
             +  -  +  - ]
      67                 :        578 : }
      68                 :            : 
      69                 :            : #define SPDK_NVMF_INVALID_CONNECT_CMD(rsp, field)       \
      70                 :            :         nvmf_invalid_connect_response(rsp, 0, offsetof(struct spdk_nvmf_fabric_connect_cmd, field))
      71                 :            : #define SPDK_NVMF_INVALID_CONNECT_DATA(rsp, field)      \
      72                 :            :         nvmf_invalid_connect_response(rsp, 1, offsetof(struct spdk_nvmf_fabric_connect_data, field))
      73                 :            : 
      74                 :            : 
      75                 :            : static void
      76                 :       4635 : nvmf_ctrlr_stop_keep_alive_timer(struct spdk_nvmf_ctrlr *ctrlr)
      77                 :            : {
      78         [ +  + ]:       4635 :         if (!ctrlr) {
      79                 :          0 :                 SPDK_ERRLOG("Controller is NULL\n");
      80                 :          0 :                 return;
      81                 :            :         }
      82                 :            : 
      83   [ +  +  +  -  :       4635 :         if (ctrlr->keep_alive_poller == NULL) {
                   +  + ]
      84                 :       2339 :                 return;
      85                 :            :         }
      86                 :            : 
      87   [ +  +  +  +  :       2296 :         SPDK_DEBUGLOG(nvmf, "Stop keep alive poller\n");
                   +  - ]
      88         [ +  - ]:       2296 :         spdk_poller_unregister(&ctrlr->keep_alive_poller);
      89                 :       1931 : }
      90                 :            : 
      91                 :            : static void
      92                 :       4728 : nvmf_ctrlr_stop_association_timer(struct spdk_nvmf_ctrlr *ctrlr)
      93                 :            : {
      94         [ +  + ]:       4728 :         if (!ctrlr) {
      95                 :          0 :                 SPDK_ERRLOG("Controller is NULL\n");
      96         [ #  # ]:          0 :                 assert(false);
      97                 :            :                 return;
      98                 :            :         }
      99                 :            : 
     100   [ +  +  +  -  :       4728 :         if (ctrlr->association_timer == NULL) {
                   +  + ]
     101                 :       2555 :                 return;
     102                 :            :         }
     103                 :            : 
     104   [ +  +  +  +  :       2173 :         SPDK_DEBUGLOG(nvmf, "Stop association timer\n");
                   +  - ]
     105         [ +  - ]:       2173 :         spdk_poller_unregister(&ctrlr->association_timer);
     106                 :       1928 : }
     107                 :            : 
     108                 :            : static void
     109                 :          0 : nvmf_ctrlr_disconnect_qpairs_done(struct spdk_io_channel_iter *i, int status)
     110                 :            : {
     111         [ #  # ]:          0 :         if (status == 0) {
     112   [ #  #  #  #  :          0 :                 SPDK_DEBUGLOG(nvmf, "ctrlr disconnect qpairs complete successfully\n");
                   #  # ]
     113                 :          0 :         } else {
     114                 :          0 :                 SPDK_ERRLOG("Fail to disconnect ctrlr qpairs\n");
     115                 :            :         }
     116                 :          0 : }
     117                 :            : 
     118                 :            : static int
     119                 :       5105 : _nvmf_ctrlr_disconnect_qpairs_on_pg(struct spdk_io_channel_iter *i, bool include_admin)
     120                 :            : {
     121                 :       5105 :         int rc = 0;
     122                 :          0 :         struct spdk_nvmf_ctrlr *ctrlr;
     123                 :          0 :         struct spdk_nvmf_qpair *qpair, *temp_qpair;
     124                 :          0 :         struct spdk_io_channel *ch;
     125                 :          0 :         struct spdk_nvmf_poll_group *group;
     126                 :            : 
     127                 :       5105 :         ctrlr = spdk_io_channel_iter_get_ctx(i);
     128                 :       5105 :         ch = spdk_io_channel_iter_get_channel(i);
     129                 :       5105 :         group = spdk_io_channel_get_ctx(ch);
     130                 :            : 
     131   [ +  +  +  -  :      12824 :         TAILQ_FOREACH_SAFE(qpair, &group->qpairs, link, temp_qpair) {
          +  -  +  +  +  
          -  +  -  +  -  
                   +  + ]
     132   [ +  +  +  -  :       7719 :                 if (qpair->ctrlr == ctrlr && (include_admin || !nvmf_qpair_is_admin_queue(qpair))) {
          +  +  +  -  +  
                -  +  - ]
     133                 :         13 :                         rc = spdk_nvmf_qpair_disconnect(qpair, NULL, NULL);
     134         [ +  + ]:         13 :                         if (rc) {
     135         [ +  - ]:          3 :                                 if (rc == -EINPROGRESS) {
     136                 :          3 :                                         rc = 0;
     137                 :          0 :                                 } else {
     138                 :          0 :                                         SPDK_ERRLOG("Qpair disconnect failed\n");
     139                 :          0 :                                         return rc;
     140                 :            :                                 }
     141                 :          0 :                         }
     142                 :          0 :                 }
     143                 :        930 :         }
     144                 :            : 
     145                 :       5105 :         return rc;
     146                 :        930 : }
     147                 :            : 
     148                 :            : static void
     149                 :          0 : nvmf_ctrlr_disconnect_qpairs_on_pg(struct spdk_io_channel_iter *i)
     150                 :            : {
     151                 :          0 :         spdk_for_each_channel_continue(i, _nvmf_ctrlr_disconnect_qpairs_on_pg(i, true));
     152                 :          0 : }
     153                 :            : 
     154                 :            : static void
     155                 :       5105 : nvmf_ctrlr_disconnect_io_qpairs_on_pg(struct spdk_io_channel_iter *i)
     156                 :            : {
     157                 :       5105 :         spdk_for_each_channel_continue(i, _nvmf_ctrlr_disconnect_qpairs_on_pg(i, false));
     158                 :       5105 : }
     159                 :            : 
     160                 :            : static int
     161                 :        305 : nvmf_ctrlr_keep_alive_poll(void *ctx)
     162                 :            : {
     163                 :          0 :         uint64_t keep_alive_timeout_tick;
     164                 :        305 :         uint64_t now = spdk_get_ticks();
     165                 :        305 :         struct spdk_nvmf_ctrlr *ctrlr = ctx;
     166                 :            : 
     167   [ -  +  -  +  :        305 :         if (ctrlr->in_destruct) {
             #  #  #  # ]
     168                 :          0 :                 nvmf_ctrlr_stop_keep_alive_timer(ctrlr);
     169                 :          0 :                 return SPDK_POLLER_IDLE;
     170                 :            :         }
     171                 :            : 
     172   [ -  +  -  +  :        305 :         SPDK_DEBUGLOG(nvmf, "Polling ctrlr keep alive timeout\n");
                   #  # ]
     173                 :            : 
     174                 :            :         /* If the Keep alive feature is in use and the timer expires */
     175   [ #  #  #  # ]:        305 :         keep_alive_timeout_tick = ctrlr->last_keep_alive_tick +
     176   [ #  #  #  #  :        305 :                                   ctrlr->feat.keep_alive_timer.bits.kato * spdk_get_ticks_hz() / UINT64_C(1000);
          #  #  #  #  #  
                      # ]
     177         [ -  + ]:        305 :         if (now > keep_alive_timeout_tick) {
     178   [ #  #  #  #  :          0 :                 SPDK_NOTICELOG("Disconnecting host %s from subsystem %s due to keep alive timeout.\n",
             #  #  #  # ]
     179                 :            :                                ctrlr->hostnqn, ctrlr->subsys->subnqn);
     180                 :            :                 /* set the Controller Fatal Status bit to '1' */
     181   [ #  #  #  #  :          0 :                 if (ctrlr->vcprop.csts.bits.cfs == 0) {
          #  #  #  #  #  
                      # ]
     182                 :          0 :                         nvmf_ctrlr_set_fatal_status(ctrlr);
     183                 :            : 
     184                 :            :                         /*
     185                 :            :                          * disconnect qpairs, terminate Transport connection
     186                 :            :                          * destroy ctrlr, break the host to controller association
     187                 :            :                          * disconnect qpairs with qpair->ctrlr == ctrlr
     188                 :            :                          */
     189   [ #  #  #  #  :          0 :                         spdk_for_each_channel(ctrlr->subsys->tgt,
             #  #  #  # ]
     190                 :            :                                               nvmf_ctrlr_disconnect_qpairs_on_pg,
     191                 :          0 :                                               ctrlr,
     192                 :            :                                               nvmf_ctrlr_disconnect_qpairs_done);
     193                 :          0 :                         return SPDK_POLLER_BUSY;
     194                 :            :                 }
     195                 :          0 :         }
     196                 :            : 
     197                 :        305 :         return SPDK_POLLER_IDLE;
     198                 :          0 : }
     199                 :            : 
     200                 :            : static void
     201                 :       2422 : nvmf_ctrlr_start_keep_alive_timer(struct spdk_nvmf_ctrlr *ctrlr)
     202                 :            : {
     203         [ +  + ]:       2422 :         if (!ctrlr) {
     204                 :          0 :                 SPDK_ERRLOG("Controller is NULL\n");
     205                 :          0 :                 return;
     206                 :            :         }
     207                 :            : 
     208                 :            :         /* if cleared to 0 then the Keep Alive Timer is disabled */
     209   [ +  +  +  -  :       2422 :         if (ctrlr->feat.keep_alive_timer.bits.kato != 0) {
          +  -  +  -  +  
                      + ]
     210                 :            : 
     211   [ +  -  +  - ]:       2295 :                 ctrlr->last_keep_alive_tick = spdk_get_ticks();
     212                 :            : 
     213   [ +  +  +  +  :       2295 :                 SPDK_DEBUGLOG(nvmf, "Ctrlr add keep alive poller\n");
                   +  - ]
     214   [ +  -  +  -  :       2295 :                 ctrlr->keep_alive_poller = SPDK_POLLER_REGISTER(nvmf_ctrlr_keep_alive_poll, ctrlr,
          +  -  +  -  +  
                -  +  - ]
     215                 :            :                                            ctrlr->feat.keep_alive_timer.bits.kato * 1000);
     216                 :        927 :         }
     217                 :       1002 : }
     218                 :            : 
     219                 :            : static int _retry_qid_check(void *ctx);
     220                 :            : 
     221                 :            : static void
     222                 :      10622 : ctrlr_add_qpair_and_send_rsp(struct spdk_nvmf_qpair *qpair,
     223                 :            :                              struct spdk_nvmf_ctrlr *ctrlr,
     224                 :            :                              struct spdk_nvmf_request *req)
     225                 :            : {
     226   [ +  -  +  -  :      10622 :         struct spdk_nvmf_fabric_connect_rsp *rsp = &req->rsp->connect_rsp;
                   +  - ]
     227                 :            : 
     228   [ +  +  +  -  :      10622 :         assert(ctrlr->admin_qpair->group->thread == spdk_get_thread());
          +  -  +  -  +  
          -  +  -  +  -  
                   #  # ]
     229                 :            : 
     230   [ +  +  +  -  :      10622 :         if (spdk_bit_array_get(ctrlr->qpair_mask, qpair->qid)) {
          +  -  +  -  +  
                      + ]
     231   [ +  +  +  -  :         18 :                 if (qpair->connect_req != NULL) {
             +  -  +  + ]
     232   [ +  -  +  - ]:          6 :                         SPDK_ERRLOG("Got I/O connect with duplicate QID %u\n", qpair->qid);
     233   [ +  -  +  - ]:          6 :                         rsp->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
     234   [ +  -  +  - ]:          6 :                         rsp->status.sc = SPDK_NVME_SC_INVALID_QUEUE_IDENTIFIER;
     235   [ +  -  +  -  :          6 :                         qpair->connect_req = NULL;
                   +  - ]
     236   [ +  -  +  - ]:          6 :                         qpair->ctrlr = NULL;
     237                 :          6 :                         spdk_nvmf_request_complete(req);
     238                 :          1 :                 } else {
     239                 :         12 :                         SPDK_WARNLOG("Duplicate QID detected, re-check in %dus\n",
     240                 :            :                                      DUPLICATE_QID_RETRY_US);
     241   [ +  -  +  -  :         12 :                         qpair->connect_req = req;
                   +  - ]
     242                 :            :                         /* Set qpair->ctrlr here so that we'll have it when the poller expires. */
     243   [ +  -  +  - ]:         12 :                         qpair->ctrlr = ctrlr;
     244   [ +  -  +  - ]:         12 :                         req->poller = SPDK_POLLER_REGISTER(_retry_qid_check, qpair,
     245                 :            :                                                            DUPLICATE_QID_RETRY_US);
     246                 :            :                 }
     247                 :         18 :                 return;
     248                 :            :         }
     249                 :            : 
     250   [ +  -  +  - ]:      10604 :         qpair->ctrlr = ctrlr;
     251   [ +  -  +  -  :      10604 :         spdk_bit_array_set(ctrlr->qpair_mask, qpair->qid);
             +  -  +  - ]
     252                 :            : 
     253   [ +  -  +  - ]:      10604 :         rsp->status.sc = SPDK_NVME_SC_SUCCESS;
     254   [ +  -  +  -  :      10604 :         rsp->status_code_specific.success.cntlid = ctrlr->cntlid;
          +  -  +  -  +  
                -  +  - ]
     255   [ +  +  +  +  :      10604 :         SPDK_DEBUGLOG(nvmf, "connect capsule response: cntlid = 0x%04x\n",
          +  -  #  #  #  
             #  #  #  #  
                      # ]
     256                 :            :                       rsp->status_code_specific.success.cntlid);
     257                 :      10604 :         spdk_nvmf_request_complete(req);
     258                 :            : 
     259                 :       2969 :         SPDK_DTRACE_PROBE4_TICKS(nvmf_ctrlr_add_qpair, qpair, qpair->qid, ctrlr->subsys->subnqn,
     260                 :            :                                  ctrlr->hostnqn);
     261         [ -  + ]:       1937 : }
     262                 :            : 
     263                 :            : static int
     264                 :         12 : _retry_qid_check(void *ctx)
     265                 :            : {
     266                 :         12 :         struct spdk_nvmf_qpair *qpair = ctx;
     267   [ +  -  +  -  :         12 :         struct spdk_nvmf_request *req = qpair->connect_req;
                   +  - ]
     268   [ +  -  +  -  :         12 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
     269                 :            : 
     270         [ +  - ]:         12 :         spdk_poller_unregister(&req->poller);
     271                 :         12 :         ctrlr_add_qpair_and_send_rsp(qpair, ctrlr, req);
     272                 :         12 :         return SPDK_POLLER_BUSY;
     273                 :          2 : }
     274                 :            : 
     275                 :            : static void
     276                 :       2422 : _nvmf_ctrlr_add_admin_qpair(void *ctx)
     277                 :            : {
     278                 :       2422 :         struct spdk_nvmf_request *req = ctx;
     279   [ +  -  +  - ]:       2422 :         struct spdk_nvmf_qpair *qpair = req->qpair;
     280   [ +  -  +  - ]:       2422 :         struct spdk_nvmf_ctrlr *ctrlr = qpair->ctrlr;
     281                 :            : 
     282   [ +  -  +  - ]:       2422 :         ctrlr->admin_qpair = qpair;
     283   [ +  -  +  -  :       2422 :         ctrlr->association_timeout = qpair->transport->opts.association_timeout;
          +  -  +  -  +  
             -  +  -  +  
                      - ]
     284                 :       2422 :         nvmf_ctrlr_start_keep_alive_timer(ctrlr);
     285                 :       2422 :         ctrlr_add_qpair_and_send_rsp(qpair, ctrlr, req);
     286                 :       2422 : }
     287                 :            : 
     288                 :            : static void
     289                 :       2422 : _nvmf_subsystem_add_ctrlr(void *ctx)
     290                 :            : {
     291                 :       2422 :         struct spdk_nvmf_request *req = ctx;
     292   [ +  -  +  - ]:       2422 :         struct spdk_nvmf_qpair *qpair = req->qpair;
     293   [ +  -  +  -  :       2422 :         struct spdk_nvmf_fabric_connect_rsp *rsp = &req->rsp->connect_rsp;
                   +  - ]
     294   [ +  -  +  - ]:       2422 :         struct spdk_nvmf_ctrlr *ctrlr = qpair->ctrlr;
     295                 :            : 
     296   [ +  +  +  -  :       2422 :         if (nvmf_subsystem_add_ctrlr(ctrlr->subsys, ctrlr)) {
                   +  + ]
     297                 :          0 :                 SPDK_ERRLOG("Unable to add controller to subsystem\n");
     298         [ #  # ]:          0 :                 spdk_bit_array_free(&ctrlr->qpair_mask);
     299                 :          0 :                 free(ctrlr);
     300   [ #  #  #  # ]:          0 :                 qpair->ctrlr = NULL;
     301   [ #  #  #  # ]:          0 :                 rsp->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
     302                 :          0 :                 spdk_nvmf_request_complete(req);
     303                 :          0 :                 return;
     304                 :            :         }
     305                 :            : 
     306   [ +  -  +  - ]:       2422 :         spdk_thread_send_msg(ctrlr->thread, _nvmf_ctrlr_add_admin_qpair, req);
     307         [ -  + ]:       1002 : }
     308                 :            : 
     309                 :            : static void
     310                 :       2428 : nvmf_ctrlr_cdata_init(struct spdk_nvmf_transport *transport, struct spdk_nvmf_subsystem *subsystem,
     311                 :            :                       struct spdk_nvmf_ctrlr_data *cdata)
     312                 :            : {
     313   [ +  -  +  - ]:       2428 :         cdata->aerl = SPDK_NVMF_MAX_ASYNC_EVENTS - 1;
     314   [ +  -  +  - ]:       2428 :         cdata->kas = KAS_DEFAULT_VALUE;
     315   [ +  -  +  - ]:       2428 :         cdata->vid = SPDK_PCI_VID_INTEL;
     316   [ +  -  +  - ]:       2428 :         cdata->ssvid = SPDK_PCI_VID_INTEL;
     317                 :            :         /* INTEL OUI */
     318   [ +  -  +  -  :       2428 :         cdata->ieee[0] = 0xe4;
             +  -  +  - ]
     319   [ +  -  +  -  :       2428 :         cdata->ieee[1] = 0xd2;
             +  -  +  - ]
     320   [ +  -  +  -  :       2428 :         cdata->ieee[2] = 0x5c;
             +  -  +  - ]
     321   [ +  -  +  - ]:       2428 :         cdata->oncs.compare = 1;
     322   [ +  -  +  - ]:       2428 :         cdata->oncs.reservations = 1;
     323   [ +  -  +  - ]:       2428 :         cdata->fuses.compare_and_write = 1;
     324   [ +  -  +  - ]:       2428 :         cdata->oncs.copy = 1;
     325   [ +  -  +  - ]:       2428 :         cdata->sgls.supported = 1;
     326   [ +  -  +  - ]:       2428 :         cdata->sgls.keyed_sgl = 1;
     327   [ +  -  +  - ]:       2428 :         cdata->sgls.sgl_offset = 1;
     328   [ +  -  +  -  :       2428 :         cdata->nvmf_specific.ioccsz = sizeof(struct spdk_nvme_cmd) / 16;
                   +  - ]
     329   [ +  -  +  -  :       2428 :         cdata->nvmf_specific.ioccsz += transport->opts.in_capsule_data_size / 16;
          +  -  +  -  +  
             -  +  -  +  
                      - ]
     330   [ +  -  +  -  :       2428 :         cdata->nvmf_specific.iorcsz = sizeof(struct spdk_nvme_cpl) / 16;
                   +  - ]
     331   [ +  -  +  -  :       2428 :         cdata->nvmf_specific.icdoff = 0; /* offset starts directly after SQE */
                   +  - ]
     332   [ +  -  +  -  :       2428 :         cdata->nvmf_specific.ctrattr.ctrlr_model = SPDK_NVMF_CTRLR_MODEL_DYNAMIC;
                   +  - ]
     333   [ +  -  +  -  :       2428 :         cdata->nvmf_specific.msdbd = 1;
                   +  - ]
     334                 :            : 
     335   [ +  +  +  -  :       2428 :         if (transport->ops->cdata_init) {
          +  -  +  -  +  
                      + ]
     336   [ +  -  +  -  :        446 :                 transport->ops->cdata_init(transport, subsystem, cdata);
          +  -  +  -  -  
                +  +  - ]
     337                 :         74 :         }
     338                 :       2428 : }
     339                 :            : 
     340                 :            : static bool
     341                 :       2422 : nvmf_subsys_has_multi_iocs(struct spdk_nvmf_subsystem *subsystem)
     342                 :            : {
     343                 :          5 :         struct spdk_nvmf_ns *ns;
     344                 :          5 :         uint32_t i;
     345                 :            : 
     346   [ +  +  +  -  :      64899 :         for (i = 0; i < subsystem->max_nsid; i++) {
                   +  + ]
     347   [ +  -  +  -  :      62477 :                 ns = subsystem->ns[i];
             +  -  +  - ]
     348   [ +  +  +  -  :      62477 :                 if (ns && ns->bdev && spdk_bdev_is_zoned(ns->bdev)) {
          +  +  +  -  -  
             +  -  +  -  
                      + ]
     349                 :          0 :                         return true;
     350                 :            :                 }
     351                 :      31904 :         }
     352                 :       2422 :         return false;
     353                 :       1002 : }
     354                 :            : 
     355                 :            : static struct spdk_nvmf_ctrlr *
     356                 :       2422 : nvmf_ctrlr_create(struct spdk_nvmf_subsystem *subsystem,
     357                 :            :                   struct spdk_nvmf_request *req,
     358                 :            :                   struct spdk_nvmf_fabric_connect_cmd *connect_cmd,
     359                 :            :                   struct spdk_nvmf_fabric_connect_data *connect_data)
     360                 :            : {
     361                 :          5 :         struct spdk_nvmf_ctrlr *ctrlr;
     362   [ +  -  +  -  :       2422 :         struct spdk_nvmf_transport *transport = req->qpair->transport;
             +  -  +  - ]
     363                 :       2422 :         struct spdk_nvme_transport_id listen_trid = {};
     364                 :       2422 :         bool subsys_has_multi_iocs = false;
     365                 :            : 
     366                 :       2422 :         ctrlr = calloc(1, sizeof(*ctrlr));
     367         [ +  + ]:       2422 :         if (ctrlr == NULL) {
     368                 :          0 :                 SPDK_ERRLOG("Memory allocation failed\n");
     369                 :          0 :                 return NULL;
     370                 :            :         }
     371                 :            : 
     372   [ +  +  +  -  :       2422 :         if (spdk_nvme_trtype_is_fabrics(transport->ops->type)) {
          +  -  +  -  +  
                      + ]
     373   [ +  -  +  - ]:       2301 :                 ctrlr->dynamic_ctrlr = true;
     374                 :        928 :         } else {
     375   [ +  -  +  -  :        121 :                 ctrlr->cntlid = connect_data->cntlid;
             +  -  +  - ]
     376                 :            :         }
     377                 :            : 
     378                 :        557 :         SPDK_DTRACE_PROBE3_TICKS(nvmf_ctrlr_create, ctrlr, subsystem->subnqn,
     379                 :            :                                  spdk_thread_get_id(req->qpair->group->thread));
     380                 :            : 
     381   [ +  -  +  -  :       2422 :         STAILQ_INIT(&ctrlr->async_events);
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     382   [ +  -  +  -  :       2422 :         TAILQ_INIT(&ctrlr->log_head);
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     383   [ +  -  +  - ]:       2422 :         ctrlr->subsys = subsystem;
     384   [ +  -  +  -  :       2422 :         ctrlr->thread = req->qpair->group->thread;
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     385   [ +  -  +  - ]:       2422 :         ctrlr->disconnect_in_progress = false;
     386                 :            : 
     387   [ +  -  +  -  :       2422 :         ctrlr->qpair_mask = spdk_bit_array_create(transport->opts.max_qpairs_per_ctrlr);
          +  -  +  -  +  
                      - ]
     388   [ +  +  +  -  :       2422 :         if (!ctrlr->qpair_mask) {
                   +  - ]
     389                 :          0 :                 SPDK_ERRLOG("Failed to allocate controller qpair mask\n");
     390                 :          0 :                 goto err_qpair_mask;
     391                 :            :         }
     392                 :            : 
     393         [ +  - ]:       2422 :         nvmf_ctrlr_cdata_init(transport, subsystem, &ctrlr->cdata);
     394                 :            : 
     395                 :            :         /*
     396                 :            :          * KAS: This field indicates the granularity of the Keep Alive Timer in 100ms units.
     397                 :            :          * If this field is cleared to 0h, then Keep Alive is not supported.
     398                 :            :          */
     399   [ +  -  +  -  :       2422 :         if (ctrlr->cdata.kas) {
             +  -  -  + ]
     400   [ +  -  +  -  :       2422 :                 ctrlr->feat.keep_alive_timer.bits.kato = spdk_divide_round_up(connect_cmd->kato,
          +  -  +  -  +  
             -  +  -  +  
                      - ]
     401                 :       1002 :                                 KAS_DEFAULT_VALUE * KAS_TIME_UNIT_IN_MS) *
     402                 :       1002 :                                 KAS_DEFAULT_VALUE * KAS_TIME_UNIT_IN_MS;
     403                 :       1002 :         }
     404                 :            : 
     405   [ +  -  +  -  :       2422 :         ctrlr->feat.async_event_configuration.bits.ns_attr_notice = 1;
             +  -  +  - ]
     406   [ +  +  +  -  :       2422 :         if (ctrlr->subsys->flags.ana_reporting) {
          +  -  +  -  +  
                      - ]
     407   [ #  #  #  #  :         10 :                 ctrlr->feat.async_event_configuration.bits.ana_change_notice = 1;
             #  #  #  # ]
     408                 :          0 :         }
     409   [ +  -  +  -  :       2422 :         ctrlr->feat.volatile_write_cache.bits.wce = 1;
             +  -  +  - ]
     410                 :            :         /* Coalescing Disable */
     411   [ +  -  +  -  :       2422 :         ctrlr->feat.interrupt_vector_configuration.bits.cd = 1;
             +  -  +  - ]
     412                 :            : 
     413   [ +  +  +  -  :       2422 :         if (spdk_nvmf_subsystem_is_discovery(ctrlr->subsys)) {
                   +  + ]
     414                 :            :                 /*
     415                 :            :                  * If keep-alive timeout is not set, discovery controllers use some
     416                 :            :                  * arbitrary high value in order to cleanup stale discovery sessions
     417                 :            :                  *
     418                 :            :                  * From the 1.0a nvme-of spec:
     419                 :            :                  * "The Keep Alive command is reserved for
     420                 :            :                  * Discovery controllers. A transport may specify a
     421                 :            :                  * fixed Discovery controller activity timeout value
     422                 :            :                  * (e.g., 2 minutes). If no commands are received
     423                 :            :                  * by a Discovery controller within that time
     424                 :            :                  * period, the controller may perform the
     425                 :            :                  * actions for Keep Alive Timer expiration".
     426                 :            :                  *
     427                 :            :                  * From the 1.1 nvme-of spec:
     428                 :            :                  * "A host requests an explicit persistent connection
     429                 :            :                  * to a Discovery controller and Asynchronous Event Notifications from
     430                 :            :                  * the Discovery controller on that persistent connection by specifying
     431                 :            :                  * a non-zero Keep Alive Timer value in the Connect command."
     432                 :            :                  *
     433                 :            :                  * In case non-zero KATO is used, we enable discovery_log_change_notice
     434                 :            :                  * otherwise we disable it and use default discovery controller KATO.
     435                 :            :                  * KATO is in millisecond.
     436                 :            :                  */
     437   [ +  +  +  -  :        163 :                 if (ctrlr->feat.keep_alive_timer.bits.kato == 0) {
          +  -  +  -  +  
                      + ]
     438   [ -  +  -  +  :         38 :                         ctrlr->feat.keep_alive_timer.bits.kato = NVMF_DISC_KATO_IN_MS;
             -  +  -  + ]
     439   [ -  +  -  +  :         38 :                         ctrlr->feat.async_event_configuration.bits.discovery_log_change_notice = 0;
             -  +  -  + ]
     440                 :          1 :                 } else {
     441   [ +  -  +  -  :        125 :                         ctrlr->feat.async_event_configuration.bits.discovery_log_change_notice = 1;
             +  -  +  - ]
     442                 :            :                 }
     443                 :          2 :         }
     444                 :            : 
     445                 :            :         /* Subtract 1 for admin queue, 1 for 0's based */
     446   [ +  -  +  -  :       2422 :         ctrlr->feat.number_of_queues.bits.ncqr = transport->opts.max_qpairs_per_ctrlr - 1 -
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
     447                 :            :                         1;
     448   [ +  -  +  -  :       2422 :         ctrlr->feat.number_of_queues.bits.nsqr = transport->opts.max_qpairs_per_ctrlr - 1 -
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
     449                 :            :                         1;
     450                 :            : 
     451   [ +  -  +  - ]:       2422 :         spdk_uuid_copy(&ctrlr->hostid, (struct spdk_uuid *)connect_data->hostid);
     452   [ +  +  +  +  :       2422 :         memcpy(ctrlr->hostnqn, connect_data->hostnqn, sizeof(ctrlr->hostnqn));
             +  -  +  - ]
     453                 :            : 
     454   [ +  -  +  -  :       2422 :         ctrlr->vcprop.cap.raw = 0;
             +  -  +  - ]
     455   [ +  -  +  -  :       2422 :         ctrlr->vcprop.cap.bits.cqr = 1; /* NVMe-oF specification required */
             +  -  +  - ]
     456   [ +  -  +  -  :       2422 :         ctrlr->vcprop.cap.bits.mqes = transport->opts.max_queue_depth -
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     457                 :            :                                       1; /* max queue depth */
     458   [ +  -  +  -  :       2422 :         ctrlr->vcprop.cap.bits.ams = 0; /* optional arb mechanisms */
             +  -  +  - ]
     459                 :            :         /* ready timeout - 500 msec units */
     460   [ +  -  +  -  :       2422 :         ctrlr->vcprop.cap.bits.to = NVMF_CTRLR_RESET_SHN_TIMEOUT_IN_MS / 500;
             +  -  +  - ]
     461   [ +  -  +  -  :       2422 :         ctrlr->vcprop.cap.bits.dstrd = 0; /* fixed to 0 for NVMe-oF */
             +  -  +  - ]
     462                 :       2422 :         subsys_has_multi_iocs = nvmf_subsys_has_multi_iocs(subsystem);
     463   [ +  +  -  + ]:       2422 :         if (subsys_has_multi_iocs) {
     464   [ #  #  #  #  :          0 :                 ctrlr->vcprop.cap.bits.css =
             #  #  #  # ]
     465         [ #  # ]:          0 :                         SPDK_NVME_CAP_CSS_IOCS; /* One or more I/O command sets supported */
     466                 :          0 :         } else {
     467   [ +  -  +  -  :       2422 :                 ctrlr->vcprop.cap.bits.css = SPDK_NVME_CAP_CSS_NVM; /* NVM command set */
          +  -  +  -  +  
                      - ]
     468                 :            :         }
     469                 :            : 
     470   [ +  -  +  -  :       2422 :         ctrlr->vcprop.cap.bits.mpsmin = 0; /* 2 ^ (12 + mpsmin) == 4k */
             +  -  +  - ]
     471   [ +  -  +  -  :       2422 :         ctrlr->vcprop.cap.bits.mpsmax = 0; /* 2 ^ (12 + mpsmax) == 4k */
             +  -  +  - ]
     472                 :            : 
     473                 :            :         /* Version Supported: 1.3 */
     474   [ +  -  +  -  :       2422 :         ctrlr->vcprop.vs.bits.mjr = 1;
             +  -  +  - ]
     475   [ +  -  +  -  :       2422 :         ctrlr->vcprop.vs.bits.mnr = 3;
             +  -  +  - ]
     476   [ +  -  +  -  :       2422 :         ctrlr->vcprop.vs.bits.ter = 0;
             +  -  +  - ]
     477                 :            : 
     478   [ +  -  +  -  :       2422 :         ctrlr->vcprop.cc.raw = 0;
             +  -  +  - ]
     479   [ +  -  +  -  :       2422 :         ctrlr->vcprop.cc.bits.en = 0; /* Init controller disabled */
             +  -  +  - ]
     480   [ +  +  +  - ]:       2422 :         if (subsys_has_multi_iocs) {
     481   [ #  #  #  #  :          0 :                 ctrlr->vcprop.cc.bits.css =
             #  #  #  # ]
     482                 :            :                         SPDK_NVME_CC_CSS_IOCS; /* All supported I/O Command Sets */
     483                 :          0 :         }
     484                 :            : 
     485   [ +  -  +  -  :       2422 :         ctrlr->vcprop.csts.raw = 0;
             +  -  +  - ]
     486   [ +  -  +  -  :       2422 :         ctrlr->vcprop.csts.bits.rdy = 0; /* Init controller as not ready */
             +  -  +  - ]
     487                 :            : 
     488   [ +  +  +  +  :       2422 :         SPDK_DEBUGLOG(nvmf, "cap 0x%" PRIx64 "\n", ctrlr->vcprop.cap.raw);
          +  -  #  #  #  
             #  #  #  #  
                      # ]
     489   [ +  +  +  +  :       2422 :         SPDK_DEBUGLOG(nvmf, "vs 0x%x\n", ctrlr->vcprop.vs.raw);
          +  -  #  #  #  
             #  #  #  #  
                      # ]
     490   [ +  +  +  +  :       2422 :         SPDK_DEBUGLOG(nvmf, "cc 0x%x\n", ctrlr->vcprop.cc.raw);
          +  -  #  #  #  
             #  #  #  #  
                      # ]
     491   [ +  +  +  +  :       2422 :         SPDK_DEBUGLOG(nvmf, "csts 0x%x\n", ctrlr->vcprop.csts.raw);
          +  -  #  #  #  
             #  #  #  #  
                      # ]
     492                 :            : 
     493   [ +  +  +  -  :       2422 :         ctrlr->dif_insert_or_strip = transport->opts.dif_insert_or_strip;
          +  -  +  -  +  
                -  +  - ]
     494                 :            : 
     495   [ +  +  +  -  :       2422 :         if (ctrlr->subsys->subtype == SPDK_NVMF_SUBTYPE_NVME) {
          +  -  +  -  +  
                      + ]
     496   [ +  +  +  -  :       2259 :                 if (spdk_nvmf_qpair_get_listen_trid(req->qpair, &listen_trid) != 0) {
                   -  + ]
     497                 :          0 :                         SPDK_ERRLOG("Could not get listener transport ID\n");
     498                 :          0 :                         goto err_listener;
     499                 :            :                 }
     500                 :            : 
     501   [ -  +  -  +  :       2259 :                 ctrlr->listener = nvmf_subsystem_find_listener(ctrlr->subsys, &listen_trid);
             -  +  -  + ]
     502   [ -  +  -  +  :       2259 :                 if (!ctrlr->listener) {
                   +  - ]
     503                 :          0 :                         SPDK_ERRLOG("Listener was not found\n");
     504                 :          0 :                         goto err_listener;
     505                 :            :                 }
     506                 :       1000 :         }
     507                 :            : 
     508   [ +  -  +  -  :       2422 :         req->qpair->ctrlr = ctrlr;
             +  -  +  - ]
     509   [ +  -  +  - ]:       2422 :         spdk_thread_send_msg(subsystem->thread, _nvmf_subsystem_add_ctrlr, req);
     510                 :            : 
     511                 :       2422 :         return ctrlr;
     512                 :          0 : err_listener:
     513         [ #  # ]:          0 :         spdk_bit_array_free(&ctrlr->qpair_mask);
     514                 :          0 : err_qpair_mask:
     515                 :          0 :         free(ctrlr);
     516                 :          0 :         return NULL;
     517                 :       1002 : }
     518                 :            : 
     519                 :            : static void
     520                 :       2398 : _nvmf_ctrlr_destruct(void *ctx)
     521                 :            : {
     522                 :       2398 :         struct spdk_nvmf_ctrlr *ctrlr = ctx;
     523                 :          1 :         struct spdk_nvmf_reservation_log *log, *log_tmp;
     524                 :          1 :         struct spdk_nvmf_async_event_completion *event, *event_tmp;
     525                 :            : 
     526                 :        557 :         SPDK_DTRACE_PROBE3_TICKS(nvmf_ctrlr_destruct, ctrlr, ctrlr->subsys->subnqn,
     527                 :            :                                  spdk_thread_get_id(ctrlr->thread));
     528                 :            : 
     529   [ +  +  +  -  :       2398 :         assert(spdk_get_thread() == ctrlr->thread);
             +  -  #  # ]
     530   [ +  +  +  +  :       2398 :         assert(ctrlr->in_destruct);
          +  -  +  -  #  
                      # ]
     531                 :            : 
     532   [ +  +  +  +  :       2398 :         SPDK_DEBUGLOG(nvmf, "Destroy ctrlr 0x%hx\n", ctrlr->cntlid);
          +  -  #  #  #  
                      # ]
     533   [ +  +  +  +  :       2398 :         if (ctrlr->disconnect_in_progress) {
             +  -  -  + ]
     534                 :          0 :                 SPDK_ERRLOG("freeing ctrlr with disconnect in progress\n");
     535   [ #  #  #  # ]:          0 :                 spdk_thread_send_msg(ctrlr->thread, _nvmf_ctrlr_destruct, ctrlr);
     536                 :          0 :                 return;
     537                 :            :         }
     538                 :            : 
     539                 :       2398 :         nvmf_ctrlr_stop_keep_alive_timer(ctrlr);
     540                 :       2398 :         nvmf_ctrlr_stop_association_timer(ctrlr);
     541         [ +  - ]:       2398 :         spdk_bit_array_free(&ctrlr->qpair_mask);
     542                 :            : 
     543   [ +  +  +  -  :       2398 :         TAILQ_FOREACH_SAFE(log, &ctrlr->log_head, link, log_tmp) {
          +  -  +  -  #  
          #  #  #  #  #  
                   -  + ]
     544   [ #  #  #  #  :          0 :                 TAILQ_REMOVE(&ctrlr->log_head, log, link);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
     545                 :          0 :                 free(log);
     546                 :          0 :         }
     547   [ +  +  +  -  :       2398 :         STAILQ_FOREACH_SAFE(event, &ctrlr->async_events, link, event_tmp) {
          +  -  +  -  #  
          #  #  #  #  #  
                   -  + ]
     548   [ #  #  #  #  :          0 :                 STAILQ_REMOVE(&ctrlr->async_events, event, spdk_nvmf_async_event_completion, link);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
     549                 :          0 :                 free(event);
     550                 :          0 :         }
     551                 :       2398 :         free(ctrlr);
     552         [ -  + ]:        998 : }
     553                 :            : 
     554                 :            : void
     555                 :       2398 : nvmf_ctrlr_destruct(struct spdk_nvmf_ctrlr *ctrlr)
     556                 :            : {
     557   [ +  -  +  - ]:       2398 :         nvmf_subsystem_remove_ctrlr(ctrlr->subsys, ctrlr);
     558                 :            : 
     559   [ +  -  +  - ]:       2398 :         spdk_thread_send_msg(ctrlr->thread, _nvmf_ctrlr_destruct, ctrlr);
     560                 :       2398 : }
     561                 :            : 
     562                 :            : static void
     563                 :       8218 : nvmf_ctrlr_add_io_qpair(void *ctx)
     564                 :            : {
     565                 :       8218 :         struct spdk_nvmf_request *req = ctx;
     566   [ +  -  +  -  :       8218 :         struct spdk_nvmf_fabric_connect_rsp *rsp = &req->rsp->connect_rsp;
                   +  - ]
     567   [ +  -  +  - ]:       8218 :         struct spdk_nvmf_qpair *qpair = req->qpair;
     568   [ +  -  +  - ]:       8218 :         struct spdk_nvmf_ctrlr *ctrlr = qpair->ctrlr;
     569   [ +  -  +  - ]:       8218 :         struct spdk_nvmf_qpair *admin_qpair = ctrlr->admin_qpair;
     570                 :            : 
     571                 :       2412 :         SPDK_DTRACE_PROBE4_TICKS(nvmf_ctrlr_add_io_qpair, ctrlr, req->qpair, req->qpair->qid,
     572                 :            :                                  spdk_thread_get_id(ctrlr->thread));
     573                 :            : 
     574                 :            :         /* Unit test will check qpair->ctrlr after calling spdk_nvmf_ctrlr_connect.
     575                 :            :           * For error case, the value should be NULL. So set it to NULL at first.
     576                 :            :           */
     577   [ +  -  +  - ]:       8218 :         qpair->ctrlr = NULL;
     578                 :            : 
     579                 :            :         /* Make sure the controller is not being destroyed. */
     580   [ +  +  +  +  :       8218 :         if (ctrlr->in_destruct) {
             +  -  -  + ]
     581                 :          0 :                 SPDK_ERRLOG("Got I/O connect while ctrlr was being destroyed.\n");
     582                 :          0 :                 SPDK_NVMF_INVALID_CONNECT_CMD(rsp, qid);
     583                 :          0 :                 goto end;
     584                 :            :         }
     585                 :            : 
     586   [ +  +  +  -  :       8218 :         if (spdk_nvmf_subsystem_is_discovery(ctrlr->subsys)) {
                   +  + ]
     587                 :          6 :                 SPDK_ERRLOG("I/O connect not allowed on discovery controller\n");
     588                 :          6 :                 SPDK_NVMF_INVALID_CONNECT_CMD(rsp, qid);
     589                 :          6 :                 goto end;
     590                 :            :         }
     591                 :            : 
     592   [ +  +  +  -  :       8212 :         if (!ctrlr->vcprop.cc.bits.en) {
          +  -  +  -  +  
                      + ]
     593                 :          6 :                 SPDK_ERRLOG("Got I/O connect before ctrlr was enabled\n");
     594                 :          6 :                 SPDK_NVMF_INVALID_CONNECT_CMD(rsp, qid);
     595                 :          6 :                 goto end;
     596                 :            :         }
     597                 :            : 
     598   [ +  +  +  +  :       8206 :         if (1u << ctrlr->vcprop.cc.bits.iosqes != sizeof(struct spdk_nvme_cmd)) {
          +  -  +  -  +  
                -  +  + ]
     599   [ +  -  +  -  :          6 :                 SPDK_ERRLOG("Got I/O connect with invalid IOSQES %u\n",
             +  -  +  - ]
     600                 :            :                             ctrlr->vcprop.cc.bits.iosqes);
     601                 :          6 :                 SPDK_NVMF_INVALID_CONNECT_CMD(rsp, qid);
     602                 :          6 :                 goto end;
     603                 :            :         }
     604                 :            : 
     605   [ +  +  +  +  :       8200 :         if (1u << ctrlr->vcprop.cc.bits.iocqes != sizeof(struct spdk_nvme_cpl)) {
          +  -  +  -  +  
                -  +  + ]
     606   [ +  -  +  -  :          6 :                 SPDK_ERRLOG("Got I/O connect with invalid IOCQES %u\n",
             +  -  +  - ]
     607                 :            :                             ctrlr->vcprop.cc.bits.iocqes);
     608                 :          6 :                 SPDK_NVMF_INVALID_CONNECT_CMD(rsp, qid);
     609                 :          6 :                 goto end;
     610                 :            :         }
     611                 :            : 
     612   [ +  -  +  +  :       8194 :         if (admin_qpair->state != SPDK_NVMF_QPAIR_ACTIVE || admin_qpair->group == NULL) {
          +  -  +  -  +  
                -  -  + ]
     613                 :            :                 /* There is a chance that admin qpair is being destroyed at this moment due to e.g.
     614                 :            :                  * expired keep alive timer. Part of the qpair destruction process is change of qpair's
     615                 :            :                  * state to DEACTIVATING and removing it from poll group */
     616   [ #  #  #  #  :          0 :                 SPDK_ERRLOG("Inactive admin qpair (state %d, group %p)\n", admin_qpair->state, admin_qpair->group);
             #  #  #  # ]
     617                 :          0 :                 SPDK_NVMF_INVALID_CONNECT_CMD(rsp, qid);
     618                 :          0 :                 goto end;
     619                 :            :         }
     620                 :            : 
     621                 :            :         /* check if we would exceed ctrlr connection limit */
     622   [ +  +  +  -  :       8194 :         if (qpair->qid >= spdk_bit_array_capacity(ctrlr->qpair_mask)) {
          +  -  +  -  +  
                      + ]
     623   [ +  -  +  -  :          6 :                 SPDK_ERRLOG("Requested QID %u but Max QID is %u\n",
             +  -  +  - ]
     624                 :            :                             qpair->qid, spdk_bit_array_capacity(ctrlr->qpair_mask) - 1);
     625   [ +  -  +  - ]:          6 :                 rsp->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
     626   [ +  -  +  - ]:          6 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_QUEUE_IDENTIFIER;
     627                 :          6 :                 goto end;
     628                 :            :         }
     629                 :            : 
     630                 :       8188 :         ctrlr_add_qpair_and_send_rsp(qpair, ctrlr, req);
     631                 :       8188 :         return;
     632                 :         25 : end:
     633                 :         30 :         spdk_nvmf_request_complete(req);
     634         [ -  + ]:        938 : }
     635                 :            : 
     636                 :            : static void
     637                 :       8736 : _nvmf_ctrlr_add_io_qpair(void *ctx)
     638                 :            : {
     639                 :       8736 :         struct spdk_nvmf_request *req = ctx;
     640   [ +  -  +  -  :       8736 :         struct spdk_nvmf_fabric_connect_rsp *rsp = &req->rsp->connect_rsp;
                   +  - ]
     641                 :         10 :         struct spdk_nvmf_fabric_connect_data *data;
     642                 :         10 :         struct spdk_nvmf_ctrlr *ctrlr;
     643   [ +  -  +  - ]:       8736 :         struct spdk_nvmf_qpair *qpair = req->qpair;
     644                 :         10 :         struct spdk_nvmf_qpair *admin_qpair;
     645   [ +  -  +  -  :       8736 :         struct spdk_nvmf_tgt *tgt = qpair->transport->tgt;
             +  -  +  - ]
     646                 :         10 :         struct spdk_nvmf_subsystem *subsystem;
     647                 :       8736 :         struct spdk_nvme_transport_id listen_trid = {};
     648                 :         10 :         const struct spdk_nvmf_subsystem_listener *listener;
     649                 :            : 
     650   [ +  +  +  -  :       8736 :         assert(req->iovcnt == 1);
             +  -  #  # ]
     651                 :            : 
     652   [ +  -  +  -  :       8736 :         data = req->iov[0].iov_base;
          +  -  +  -  +  
                      - ]
     653                 :            : 
     654   [ +  +  +  +  :       8736 :         SPDK_DEBUGLOG(nvmf, "Connect I/O Queue for controller id 0x%x\n", data->cntlid);
          +  -  #  #  #  
                      # ]
     655                 :            : 
     656         [ +  - ]:       8736 :         subsystem = spdk_nvmf_tgt_find_subsystem(tgt, data->subnqn);
     657                 :            :         /* We already checked this in spdk_nvmf_ctrlr_connect */
     658   [ +  +  #  # ]:       8736 :         assert(subsystem != NULL);
     659                 :            : 
     660   [ +  -  +  - ]:       8736 :         ctrlr = nvmf_subsystem_get_ctrlr(subsystem, data->cntlid);
     661         [ +  + ]:       8736 :         if (ctrlr == NULL) {
     662   [ +  -  +  - ]:        512 :                 SPDK_ERRLOG("Unknown controller ID 0x%x\n", data->cntlid);
     663                 :        512 :                 SPDK_NVMF_INVALID_CONNECT_DATA(rsp, cntlid);
     664                 :        512 :                 spdk_nvmf_request_complete(req);
     665                 :        513 :                 return;
     666                 :            :         }
     667                 :            : 
     668                 :            :         /* fail before passing a message to the controller thread. */
     669   [ +  +  +  +  :       8224 :         if (ctrlr->in_destruct) {
             +  -  -  + ]
     670                 :          0 :                 SPDK_ERRLOG("Got I/O connect while ctrlr was being destroyed.\n");
     671                 :          0 :                 SPDK_NVMF_INVALID_CONNECT_CMD(rsp, qid);
     672                 :          0 :                 spdk_nvmf_request_complete(req);
     673                 :          0 :                 return;
     674                 :            :         }
     675                 :            : 
     676                 :            :         /* If ANA reporting is enabled, check if I/O connect is on the same listener. */
     677   [ +  +  +  -  :       8224 :         if (subsystem->flags.ana_reporting) {
                   +  - ]
     678   [ -  +  #  #  :         48 :                 if (spdk_nvmf_qpair_get_listen_trid(req->qpair, &listen_trid) != 0) {
                   #  # ]
     679                 :          0 :                         SPDK_ERRLOG("Could not get listener transport ID\n");
     680                 :          0 :                         SPDK_NVMF_INVALID_CONNECT_CMD(rsp, qid);
     681                 :          0 :                         spdk_nvmf_request_complete(req);
     682                 :          0 :                         return;
     683                 :            :                 }
     684                 :            : 
     685                 :         48 :                 listener = nvmf_subsystem_find_listener(subsystem, &listen_trid);
     686   [ -  +  #  #  :         48 :                 if (listener != ctrlr->listener) {
                   #  # ]
     687                 :          0 :                         SPDK_ERRLOG("I/O connect is on a listener different from admin connect\n");
     688                 :          0 :                         SPDK_NVMF_INVALID_CONNECT_CMD(rsp, qid);
     689                 :          0 :                         spdk_nvmf_request_complete(req);
     690                 :          0 :                         return;
     691                 :            :                 }
     692                 :          0 :         }
     693                 :            : 
     694   [ +  -  +  - ]:       8224 :         admin_qpair = ctrlr->admin_qpair;
     695   [ +  +  +  +  :       8224 :         if (admin_qpair->state != SPDK_NVMF_QPAIR_ACTIVE || admin_qpair->group == NULL) {
          +  +  +  -  +  
                -  +  - ]
     696                 :            :                 /* There is a chance that admin qpair is being destroyed at this moment due to e.g.
     697                 :            :                  * expired keep alive timer. Part of the qpair destruction process is change of qpair's
     698                 :            :                  * state to DEACTIVATING and removing it from poll group */
     699   [ +  -  +  -  :          6 :                 SPDK_ERRLOG("Inactive admin qpair (state %d, group %p)\n", admin_qpair->state, admin_qpair->group);
             +  -  +  - ]
     700                 :          6 :                 SPDK_NVMF_INVALID_CONNECT_CMD(rsp, qid);
     701                 :          6 :                 spdk_nvmf_request_complete(req);
     702                 :          6 :                 return;
     703                 :            :         }
     704   [ +  -  +  - ]:       8218 :         qpair->ctrlr = ctrlr;
     705   [ +  -  +  -  :       8218 :         spdk_thread_send_msg(admin_qpair->group->thread, nvmf_ctrlr_add_io_qpair, req);
             +  -  +  - ]
     706         [ -  + ]:        940 : }
     707                 :            : 
     708                 :            : static bool
     709                 :      11196 : nvmf_qpair_access_allowed(struct spdk_nvmf_qpair *qpair, struct spdk_nvmf_subsystem *subsystem,
     710                 :            :                           const char *hostnqn)
     711                 :            : {
     712                 :      11196 :         struct spdk_nvme_transport_id listen_trid = {};
     713                 :            : 
     714         [ +  + ]:      11196 :         if (!spdk_nvmf_subsystem_host_allowed(subsystem, hostnqn)) {
     715         [ +  - ]:         14 :                 SPDK_ERRLOG("Subsystem '%s' does not allow host '%s'\n", subsystem->subnqn, hostnqn);
     716                 :         14 :                 return false;
     717                 :            :         }
     718                 :            : 
     719         [ -  + ]:      11182 :         if (spdk_nvmf_qpair_get_listen_trid(qpair, &listen_trid)) {
     720         [ #  # ]:          0 :                 SPDK_ERRLOG("Subsystem '%s' is unable to enforce access control due to an internal error.\n",
     721                 :            :                             subsystem->subnqn);
     722                 :          0 :                 return false;
     723                 :            :         }
     724                 :            : 
     725         [ +  + ]:      11182 :         if (!spdk_nvmf_subsystem_listener_allowed(subsystem, &listen_trid)) {
     726         [ #  # ]:          0 :                 SPDK_ERRLOG("Subsystem '%s' does not allow host '%s' to connect at this address.\n",
     727                 :            :                             subsystem->subnqn, hostnqn);
     728                 :          0 :                 return false;
     729                 :            :         }
     730                 :            : 
     731                 :      11182 :         return true;
     732                 :       1947 : }
     733                 :            : 
     734                 :            : static int
     735                 :      11182 : _nvmf_ctrlr_connect(struct spdk_nvmf_request *req)
     736                 :            : {
     737   [ +  -  +  -  :      11182 :         struct spdk_nvmf_fabric_connect_data *data = req->iov[0].iov_base;
          +  -  +  -  +  
                      - ]
     738   [ +  -  +  -  :      11182 :         struct spdk_nvmf_fabric_connect_cmd *cmd = &req->cmd->connect_cmd;
                   +  - ]
     739   [ +  -  +  -  :      11182 :         struct spdk_nvmf_fabric_connect_rsp *rsp = &req->rsp->connect_rsp;
                   +  - ]
     740   [ +  -  +  - ]:      11182 :         struct spdk_nvmf_qpair *qpair = req->qpair;
     741   [ +  -  +  - ]:      11182 :         struct spdk_nvmf_transport *transport = qpair->transport;
     742                 :         19 :         struct spdk_nvmf_ctrlr *ctrlr;
     743                 :         19 :         struct spdk_nvmf_subsystem *subsystem;
     744                 :            : 
     745   [ +  +  +  +  :      11182 :         SPDK_DEBUGLOG(nvmf, "recfmt 0x%x qid %u sqsize %u\n",
          +  -  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
     746                 :            :                       cmd->recfmt, cmd->qid, cmd->sqsize);
     747                 :            : 
     748   [ +  +  +  +  :      11182 :         SPDK_DEBUGLOG(nvmf, "Connect data:\n");
                   +  - ]
     749   [ +  +  +  +  :      11182 :         SPDK_DEBUGLOG(nvmf, "  cntlid:  0x%04x\n", data->cntlid);
          +  -  #  #  #  
                      # ]
     750   [ +  +  +  +  :      11182 :         SPDK_DEBUGLOG(nvmf, "  hostid: %08x-%04x-%04x-%02x%02x-%04x%08x ***\n",
          +  -  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
     751                 :            :                       ntohl(*(uint32_t *)&data->hostid[0]),
     752                 :            :                       ntohs(*(uint16_t *)&data->hostid[4]),
     753                 :            :                       ntohs(*(uint16_t *)&data->hostid[6]),
     754                 :            :                       data->hostid[8],
     755                 :            :                       data->hostid[9],
     756                 :            :                       ntohs(*(uint16_t *)&data->hostid[10]),
     757                 :            :                       ntohl(*(uint32_t *)&data->hostid[12]));
     758   [ +  +  +  +  :      11182 :         SPDK_DEBUGLOG(nvmf, "  subnqn: \"%s\"\n", data->subnqn);
             +  -  #  # ]
     759   [ +  +  +  +  :      11182 :         SPDK_DEBUGLOG(nvmf, "  hostnqn: \"%s\"\n", data->hostnqn);
             +  -  #  # ]
     760                 :            : 
     761   [ +  -  +  -  :      11182 :         subsystem = spdk_nvmf_tgt_find_subsystem(transport->tgt, data->subnqn);
                   +  - ]
     762         [ +  + ]:      11182 :         if (!subsystem) {
     763                 :          0 :                 SPDK_NVMF_INVALID_CONNECT_DATA(rsp, subnqn);
     764                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
     765                 :            :         }
     766                 :            : 
     767   [ +  +  +  -  :      11182 :         if (cmd->recfmt != 0) {
                   +  + ]
     768   [ +  -  +  - ]:          6 :                 SPDK_ERRLOG("Connect command unsupported RECFMT %u\n", cmd->recfmt);
     769   [ +  -  +  - ]:          6 :                 rsp->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
     770   [ +  -  +  - ]:          6 :                 rsp->status.sc = SPDK_NVMF_FABRIC_SC_INCOMPATIBLE_FORMAT;
     771                 :          6 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
     772                 :            :         }
     773                 :            : 
     774                 :            :         /*
     775                 :            :          * SQSIZE is a 0-based value, so it must be at least 1 (minimum queue depth is 2) and
     776                 :            :          * strictly less than max_aq_depth (admin queues) or max_queue_depth (io queues).
     777                 :            :          */
     778   [ +  +  +  -  :      11176 :         if (cmd->sqsize == 0) {
                   +  + ]
     779                 :          6 :                 SPDK_ERRLOG("Invalid SQSIZE = 0\n");
     780                 :          6 :                 SPDK_NVMF_INVALID_CONNECT_CMD(rsp, sqsize);
     781                 :          6 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
     782                 :            :         }
     783                 :            : 
     784   [ +  +  +  -  :      11170 :         if (cmd->qid == 0) {
                   +  + ]
     785   [ +  +  +  -  :       2428 :                 if (cmd->sqsize >= transport->opts.max_aq_depth) {
          +  -  +  -  +  
                -  +  + ]
     786   [ +  -  +  -  :          6 :                         SPDK_ERRLOG("Invalid SQSIZE for admin queue %u (min 1, max %u)\n",
          +  -  +  -  +  
                      - ]
     787                 :            :                                     cmd->sqsize, transport->opts.max_aq_depth - 1);
     788                 :          6 :                         SPDK_NVMF_INVALID_CONNECT_CMD(rsp, sqsize);
     789                 :          6 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
     790                 :            :                 }
     791   [ +  +  +  -  :       9744 :         } else if (cmd->sqsize >= transport->opts.max_queue_depth) {
          +  -  +  -  +  
                -  +  + ]
     792   [ +  -  +  -  :          6 :                 SPDK_ERRLOG("Invalid SQSIZE %u (min 1, max %u)\n",
          +  -  +  -  +  
                -  +  - ]
     793                 :            :                             cmd->sqsize, transport->opts.max_queue_depth - 1);
     794                 :          6 :                 SPDK_NVMF_INVALID_CONNECT_CMD(rsp, sqsize);
     795                 :          6 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
     796                 :            :         }
     797                 :            : 
     798   [ +  -  +  -  :      11158 :         qpair->sq_head_max = cmd->sqsize;
             +  -  +  - ]
     799   [ +  -  +  -  :      11158 :         qpair->qid = cmd->qid;
             +  -  +  - ]
     800   [ +  -  +  - ]:      11158 :         qpair->connect_received = true;
     801                 :            : 
     802   [ +  +  +  -  :      11158 :         pthread_mutex_lock(&qpair->group->mutex);
             +  -  +  - ]
     803   [ +  -  +  -  :      11158 :         qpair->group->current_unassociated_qpairs--;
                   +  - ]
     804   [ +  +  +  -  :      11158 :         pthread_mutex_unlock(&qpair->group->mutex);
             +  -  +  - ]
     805                 :            : 
     806   [ +  +  +  -  :      11158 :         if (0 == qpair->qid) {
                   +  + ]
     807   [ +  -  +  -  :       2422 :                 qpair->group->stat.admin_qpairs++;
             +  -  +  - ]
     808   [ +  -  +  -  :       2422 :                 qpair->group->stat.current_admin_qpairs++;
             +  -  +  - ]
     809                 :       1002 :         } else {
     810   [ +  -  +  -  :       8736 :                 qpair->group->stat.io_qpairs++;
             +  -  +  - ]
     811   [ +  -  +  -  :       8736 :                 qpair->group->stat.current_io_qpairs++;
             +  -  +  - ]
     812                 :            :         }
     813                 :            : 
     814   [ +  +  +  -  :      11158 :         if (cmd->qid == 0) {
                   +  + ]
     815   [ +  +  +  +  :       2422 :                 SPDK_DEBUGLOG(nvmf, "Connect Admin Queue for controller ID 0x%x\n", data->cntlid);
          +  -  #  #  #  
                      # ]
     816                 :            : 
     817   [ +  +  +  +  :       2422 :                 if (spdk_nvme_trtype_is_fabrics(transport->ops->type) && data->cntlid != 0xFFFF) {
          +  -  +  -  +  
          +  +  -  +  -  
                   +  + ]
     818                 :            :                         /* This NVMf target only supports dynamic mode. */
     819   [ +  -  +  - ]:          6 :                         SPDK_ERRLOG("The NVMf target only supports dynamic mode (CNTLID = 0x%x).\n", data->cntlid);
     820                 :          6 :                         SPDK_NVMF_INVALID_CONNECT_DATA(rsp, cntlid);
     821                 :          6 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
     822                 :            :                 }
     823                 :            : 
     824                 :            :                 /* Establish a new ctrlr */
     825                 :       2416 :                 ctrlr = nvmf_ctrlr_create(subsystem, req, cmd, data);
     826         [ +  + ]:       2416 :                 if (!ctrlr) {
     827                 :          0 :                         SPDK_ERRLOG("nvmf_ctrlr_create() failed\n");
     828   [ #  #  #  # ]:          0 :                         rsp->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
     829                 :          0 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
     830                 :            :                 } else {
     831                 :       2416 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS;
     832                 :            :                 }
     833                 :            :         } else {
     834   [ +  -  +  - ]:       8736 :                 spdk_thread_send_msg(subsystem->thread, _nvmf_ctrlr_add_io_qpair, req);
     835                 :       8736 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS;
     836                 :            :         }
     837                 :       1946 : }
     838                 :            : 
     839                 :            : static struct spdk_nvmf_subsystem_poll_group *
     840                 :      11658 : nvmf_subsystem_pg_from_connect_cmd(struct spdk_nvmf_request *req)
     841                 :            : {
     842                 :          8 :         struct spdk_nvmf_fabric_connect_data *data;
     843                 :          8 :         struct spdk_nvmf_subsystem *subsystem;
     844                 :          8 :         struct spdk_nvmf_tgt *tgt;
     845                 :            : 
     846   [ +  +  #  # ]:      11658 :         assert(nvmf_request_is_fabric_connect(req));
     847   [ +  +  +  -  :      11658 :         assert(req->qpair->ctrlr == NULL);
          +  -  +  -  +  
                -  #  # ]
     848   [ +  +  +  -  :      11658 :         assert(req->iovcnt == 1);
             +  -  #  # ]
     849                 :            : 
     850   [ +  -  +  -  :      11658 :         data = req->iov[0].iov_base;
          +  -  +  -  +  
                      - ]
     851   [ +  -  +  -  :      11658 :         tgt = req->qpair->transport->tgt;
          +  -  +  -  +  
                -  +  - ]
     852                 :            : 
     853         [ +  - ]:      11658 :         subsystem = spdk_nvmf_tgt_find_subsystem(tgt, data->subnqn);
     854         [ +  + ]:      11658 :         if (subsystem == NULL) {
     855                 :          0 :                 return NULL;
     856                 :            :         }
     857                 :            : 
     858   [ +  -  +  -  :      11658 :         return &req->qpair->group->sgroups[subsystem->id];
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
     859                 :       1935 : }
     860                 :            : 
     861                 :            : int
     862                 :          0 : spdk_nvmf_ctrlr_connect(struct spdk_nvmf_request *req)
     863                 :            : {
     864   [ #  #  #  #  :          0 :         struct spdk_nvmf_fabric_connect_rsp *rsp = &req->rsp->connect_rsp;
                   #  # ]
     865                 :          0 :         struct spdk_nvmf_subsystem_poll_group *sgroup;
     866   [ #  #  #  # ]:          0 :         struct spdk_nvmf_qpair *qpair = req->qpair;
     867                 :          0 :         enum spdk_nvmf_request_exec_status status;
     868                 :            : 
     869   [ #  #  #  #  :          0 :         if (req->iovcnt > 1) {
                   #  # ]
     870   [ #  #  #  # ]:          0 :                 SPDK_ERRLOG("Connect command invalid iovcnt: %d\n", req->iovcnt);
     871   [ #  #  #  # ]:          0 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
     872                 :          0 :                 status = SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
     873                 :          0 :                 goto out;
     874                 :            :         }
     875                 :            : 
     876                 :          0 :         sgroup = nvmf_subsystem_pg_from_connect_cmd(req);
     877         [ #  # ]:          0 :         if (!sgroup) {
     878                 :          0 :                 SPDK_NVMF_INVALID_CONNECT_DATA(rsp, subnqn);
     879                 :          0 :                 status = SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
     880                 :          0 :                 goto out;
     881                 :            :         }
     882                 :            : 
     883         [ #  # ]:          0 :         sgroup->mgmt_io_outstanding++;
     884   [ #  #  #  #  :          0 :         TAILQ_INSERT_TAIL(&qpair->outstanding, req, link);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     885                 :            : 
     886                 :          0 :         status = _nvmf_ctrlr_connect(req);
     887                 :            : 
     888                 :          0 : out:
     889         [ #  # ]:          0 :         if (status == SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE) {
     890                 :          0 :                 _nvmf_request_complete(req);
     891                 :          0 :         }
     892                 :            : 
     893                 :          0 :         return status;
     894                 :          0 : }
     895                 :            : 
     896                 :            : static int
     897                 :      11214 : nvmf_ctrlr_cmd_connect(struct spdk_nvmf_request *req)
     898                 :            : {
     899   [ +  -  +  -  :      11214 :         struct spdk_nvmf_fabric_connect_data *data = req->iov[0].iov_base;
          +  -  +  -  +  
                      - ]
     900   [ +  -  +  -  :      11214 :         struct spdk_nvmf_fabric_connect_rsp *rsp = &req->rsp->connect_rsp;
                   +  - ]
     901   [ +  -  +  -  :      11214 :         struct spdk_nvmf_transport *transport = req->qpair->transport;
             +  -  +  - ]
     902                 :         23 :         struct spdk_nvmf_subsystem *subsystem;
     903                 :            : 
     904   [ +  +  +  -  :      11214 :         if (req->length < sizeof(struct spdk_nvmf_fabric_connect_data)) {
                   +  + ]
     905   [ +  -  +  - ]:          6 :                 SPDK_ERRLOG("Connect command data length 0x%x too small\n", req->length);
     906   [ +  -  +  - ]:          6 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
     907                 :          6 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
     908                 :            :         }
     909                 :            : 
     910   [ +  +  +  -  :      11208 :         if (req->iovcnt > 1) {
                   -  + ]
     911   [ #  #  #  # ]:          0 :                 SPDK_ERRLOG("Connect command invalid iovcnt: %d\n", req->iovcnt);
     912   [ #  #  #  # ]:          0 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
     913                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
     914                 :            :         }
     915                 :            : 
     916   [ +  -  +  -  :      11208 :         subsystem = spdk_nvmf_tgt_find_subsystem(transport->tgt, data->subnqn);
                   +  - ]
     917         [ +  + ]:      11208 :         if (!subsystem) {
     918                 :          6 :                 SPDK_NVMF_INVALID_CONNECT_DATA(rsp, subnqn);
     919                 :          6 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
     920                 :            :         }
     921                 :            : 
     922   [ +  -  +  -  :      13150 :         if ((subsystem->state == SPDK_NVMF_SUBSYSTEM_INACTIVE) ||
             +  -  -  + ]
     923   [ +  -  +  -  :      11202 :             (subsystem->state == SPDK_NVMF_SUBSYSTEM_PAUSING) ||
                   +  - ]
     924   [ +  -  +  -  :      11202 :             (subsystem->state == SPDK_NVMF_SUBSYSTEM_PAUSED) ||
                   +  - ]
     925   [ +  +  +  - ]:      11202 :             (subsystem->state == SPDK_NVMF_SUBSYSTEM_DEACTIVATING)) {
     926                 :          0 :                 struct spdk_nvmf_subsystem_poll_group *sgroup;
     927                 :            : 
     928                 :            :                 /* Subsystem is not ready to handle a connect. Decrement
     929                 :            :                  * the mgmt_io_outstanding to avoid the subsystem waiting
     930                 :            :                  * for this command to complete before unpausing. Queued
     931                 :            :                  * requests get retried when subsystem resumes.
     932                 :            :                  */
     933                 :          0 :                 sgroup = nvmf_subsystem_pg_from_connect_cmd(req);
     934   [ #  #  #  # ]:          0 :                 assert(sgroup != NULL);
     935         [ #  # ]:          0 :                 sgroup->mgmt_io_outstanding--;
     936   [ #  #  #  #  :          0 :                 TAILQ_REMOVE(&req->qpair->outstanding, req, link);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     937   [ #  #  #  #  :          0 :                 TAILQ_INSERT_TAIL(&sgroup->queued, req, link);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     938   [ #  #  #  #  :          0 :                 SPDK_DEBUGLOG(nvmf, "Subsystem '%s' is not ready for connect, retrying...\n", subsystem->subnqn);
             #  #  #  # ]
     939                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS;
     940                 :          0 :         }
     941                 :            : 
     942                 :            :         /* Ensure that hostnqn is null terminated */
     943   [ +  +  +  +  :      11202 :         if (!memchr(data->hostnqn, '\0', SPDK_NVMF_NQN_MAX_LEN + 1)) {
                   +  + ]
     944                 :          6 :                 SPDK_ERRLOG("Connect HOSTNQN is not null terminated\n");
     945                 :          6 :                 SPDK_NVMF_INVALID_CONNECT_DATA(rsp, hostnqn);
     946                 :          6 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
     947                 :            :         }
     948                 :            : 
     949   [ +  +  +  -  :      11196 :         if (!nvmf_qpair_access_allowed(req->qpair, subsystem, data->hostnqn)) {
             +  -  +  + ]
     950   [ +  -  +  - ]:         14 :                 rsp->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
     951   [ +  -  +  - ]:         14 :                 rsp->status.sc = SPDK_NVMF_FABRIC_SC_INVALID_HOST;
     952                 :         14 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
     953                 :            :         }
     954                 :            : 
     955                 :      11182 :         return _nvmf_ctrlr_connect(req);
     956                 :       1950 : }
     957                 :            : 
     958                 :            : static int
     959                 :          0 : nvmf_ctrlr_association_remove(void *ctx)
     960                 :            : {
     961                 :          0 :         struct spdk_nvmf_ctrlr *ctrlr = ctx;
     962                 :          0 :         int rc;
     963                 :            : 
     964                 :          0 :         nvmf_ctrlr_stop_association_timer(ctrlr);
     965                 :            : 
     966   [ #  #  #  #  :          0 :         if (ctrlr->in_destruct) {
             #  #  #  # ]
     967                 :          0 :                 return SPDK_POLLER_IDLE;
     968                 :            :         }
     969   [ #  #  #  #  :          0 :         SPDK_DEBUGLOG(nvmf, "Disconnecting host from subsystem %s due to association timeout.\n",
          #  #  #  #  #  
                #  #  # ]
     970                 :            :                       ctrlr->subsys->subnqn);
     971                 :            : 
     972   [ #  #  #  #  :          0 :         if (ctrlr->admin_qpair) {
                   #  # ]
     973   [ #  #  #  # ]:          0 :                 rc = spdk_nvmf_qpair_disconnect(ctrlr->admin_qpair, NULL, NULL);
     974   [ #  #  #  # ]:          0 :                 if (rc < 0 && rc != -EINPROGRESS) {
     975                 :          0 :                         SPDK_ERRLOG("Fail to disconnect admin ctrlr qpair\n");
     976         [ #  # ]:          0 :                         assert(false);
     977                 :            :                 }
     978                 :          0 :         }
     979                 :            : 
     980                 :          0 :         return SPDK_POLLER_BUSY;
     981                 :          0 : }
     982                 :            : 
     983                 :            : static int
     984                 :       2279 : _nvmf_ctrlr_cc_reset_shn_done(void *ctx)
     985                 :            : {
     986                 :       2279 :         struct spdk_nvmf_ctrlr *ctrlr = ctx;
     987                 :       2279 :         uint64_t now = spdk_get_ticks();
     988                 :          0 :         uint32_t count;
     989                 :            : 
     990   [ +  +  +  -  :       2279 :         if (ctrlr->cc_timer) {
                   +  - ]
     991         [ #  # ]:         55 :                 spdk_poller_unregister(&ctrlr->cc_timer);
     992                 :          0 :         }
     993                 :            : 
     994   [ +  -  +  - ]:       2279 :         count = spdk_bit_array_count_set(ctrlr->qpair_mask);
     995   [ +  +  +  +  :       2279 :         SPDK_DEBUGLOG(nvmf, "ctrlr %p active queue count %u\n", ctrlr, count);
                   +  - ]
     996                 :            : 
     997         [ +  + ]:       2279 :         if (count > 1) {
     998   [ +  -  #  #  :         55 :                 if (now < ctrlr->cc_timeout_tsc) {
                   #  # ]
     999                 :            :                         /* restart cc timer */
    1000   [ #  #  #  # ]:         55 :                         ctrlr->cc_timer = SPDK_POLLER_REGISTER(_nvmf_ctrlr_cc_reset_shn_done, ctrlr, 100 * 1000);
    1001                 :         55 :                         return SPDK_POLLER_IDLE;
    1002                 :            :                 } else {
    1003                 :            :                         /* controller fatal status */
    1004                 :          0 :                         SPDK_WARNLOG("IO timeout, ctrlr %p is in fatal status\n", ctrlr);
    1005                 :          0 :                         nvmf_ctrlr_set_fatal_status(ctrlr);
    1006                 :            :                 }
    1007                 :          0 :         }
    1008                 :            : 
    1009         [ +  - ]:       2224 :         spdk_poller_unregister(&ctrlr->cc_timeout_timer);
    1010                 :            : 
    1011   [ +  +  +  +  :       2224 :         if (ctrlr->disconnect_is_shn) {
             +  -  +  - ]
    1012   [ +  -  +  -  :       2219 :                 ctrlr->vcprop.csts.bits.shst = SPDK_NVME_SHST_COMPLETE;
             +  -  +  - ]
    1013   [ +  -  +  - ]:       2219 :                 ctrlr->disconnect_is_shn = false;
    1014                 :        930 :         } else {
    1015                 :            :                 /* Only a subset of the registers are cleared out on a reset */
    1016   [ #  #  #  #  :          5 :                 ctrlr->vcprop.cc.raw = 0;
             #  #  #  # ]
    1017   [ #  #  #  #  :          5 :                 ctrlr->vcprop.csts.raw = 0;
             #  #  #  # ]
    1018                 :            :         }
    1019                 :            : 
    1020                 :            :         /* After CC.EN transitions to 0 (due to shutdown or reset), the association
    1021                 :            :          * between the host and controller shall be preserved for at least 2 minutes */
    1022   [ +  +  +  -  :       2224 :         if (ctrlr->association_timer) {
                   +  - ]
    1023   [ #  #  #  #  :          0 :                 SPDK_DEBUGLOG(nvmf, "Association timer already set\n");
                   #  # ]
    1024                 :          0 :                 nvmf_ctrlr_stop_association_timer(ctrlr);
    1025                 :          0 :         }
    1026   [ +  +  +  -  :       2224 :         if (ctrlr->association_timeout) {
                   +  + ]
    1027   [ +  -  +  -  :       2173 :                 ctrlr->association_timer = SPDK_POLLER_REGISTER(nvmf_ctrlr_association_remove, ctrlr,
             +  -  +  - ]
    1028                 :            :                                            ctrlr->association_timeout * 1000);
    1029                 :        923 :         }
    1030   [ +  -  +  - ]:       2224 :         ctrlr->disconnect_in_progress = false;
    1031                 :       2224 :         return SPDK_POLLER_BUSY;
    1032                 :        930 : }
    1033                 :            : 
    1034                 :            : static void
    1035                 :       2224 : nvmf_ctrlr_cc_reset_shn_done(struct spdk_io_channel_iter *i, int status)
    1036                 :            : {
    1037                 :       2224 :         struct spdk_nvmf_ctrlr *ctrlr = spdk_io_channel_iter_get_ctx(i);
    1038                 :            : 
    1039         [ +  + ]:       2224 :         if (status < 0) {
    1040                 :          0 :                 SPDK_ERRLOG("Fail to disconnect io ctrlr qpairs\n");
    1041         [ #  # ]:          0 :                 assert(false);
    1042                 :            :         }
    1043                 :            : 
    1044                 :       2224 :         _nvmf_ctrlr_cc_reset_shn_done((void *)ctrlr);
    1045                 :       2224 : }
    1046                 :            : 
    1047                 :            : static void
    1048                 :          0 : nvmf_bdev_complete_reset(struct spdk_bdev_io *bdev_io, bool success, void *cb_arg)
    1049                 :            : {
    1050         [ #  # ]:          0 :         SPDK_NOTICELOG("Resetting bdev done with %s\n", success ? "success" : "failure");
    1051                 :            : 
    1052                 :          0 :         spdk_bdev_free_io(bdev_io);
    1053                 :          0 : }
    1054                 :            : 
    1055                 :            : 
    1056                 :            : static int
    1057                 :          0 : nvmf_ctrlr_cc_timeout(void *ctx)
    1058                 :            : {
    1059                 :          0 :         struct spdk_nvmf_ctrlr *ctrlr = ctx;
    1060   [ #  #  #  #  :          0 :         struct spdk_nvmf_poll_group *group = ctrlr->admin_qpair->group;
             #  #  #  # ]
    1061                 :          0 :         struct spdk_nvmf_ns *ns;
    1062                 :          0 :         struct spdk_nvmf_subsystem_pg_ns_info *ns_info;
    1063                 :            : 
    1064   [ #  #  #  #  :          0 :         assert(group != NULL && group->sgroups != NULL);
             #  #  #  # ]
    1065         [ #  # ]:          0 :         spdk_poller_unregister(&ctrlr->cc_timeout_timer);
    1066   [ #  #  #  #  :          0 :         SPDK_DEBUGLOG(nvmf, "Ctrlr %p reset or shutdown timeout\n", ctrlr);
                   #  # ]
    1067                 :            : 
    1068   [ #  #  #  #  :          0 :         for (ns = spdk_nvmf_subsystem_get_first_ns(ctrlr->subsys); ns != NULL;
                   #  # ]
    1069   [ #  #  #  # ]:          0 :              ns = spdk_nvmf_subsystem_get_next_ns(ctrlr->subsys, ns)) {
    1070   [ #  #  #  #  :          0 :                 if (ns->bdev == NULL) {
                   #  # ]
    1071                 :          0 :                         continue;
    1072                 :            :                 }
    1073   [ #  #  #  #  :          0 :                 ns_info = &group->sgroups[ctrlr->subsys->id].ns_info[ns->opts.nsid - 1];
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1074   [ #  #  #  #  :          0 :                 SPDK_NOTICELOG("Ctrlr %p resetting NSID %u\n", ctrlr, ns->opts.nsid);
                   #  # ]
    1075   [ #  #  #  #  :          0 :                 spdk_bdev_reset(ns->desc, ns_info->channel, nvmf_bdev_complete_reset, NULL);
             #  #  #  # ]
    1076                 :          0 :         }
    1077                 :            : 
    1078                 :          0 :         return SPDK_POLLER_BUSY;
    1079                 :          0 : }
    1080                 :            : 
    1081                 :            : const struct spdk_nvmf_registers *
    1082                 :       1058 : spdk_nvmf_ctrlr_get_regs(struct spdk_nvmf_ctrlr *ctrlr)
    1083                 :            : {
    1084         [ +  - ]:       1058 :         return &ctrlr->vcprop;
    1085                 :            : }
    1086                 :            : 
    1087                 :            : void
    1088                 :          0 : nvmf_ctrlr_set_fatal_status(struct spdk_nvmf_ctrlr *ctrlr)
    1089                 :            : {
    1090   [ #  #  #  #  :          0 :         ctrlr->vcprop.csts.bits.cfs = 1;
             #  #  #  # ]
    1091                 :          0 : }
    1092                 :            : 
    1093                 :            : static uint64_t
    1094                 :       2916 : nvmf_prop_get_cap(struct spdk_nvmf_ctrlr *ctrlr)
    1095                 :            : {
    1096   [ +  -  +  -  :       2916 :         return ctrlr->vcprop.cap.raw;
             +  -  +  - ]
    1097                 :            : }
    1098                 :            : 
    1099                 :            : static uint64_t
    1100                 :       2342 : nvmf_prop_get_vs(struct spdk_nvmf_ctrlr *ctrlr)
    1101                 :            : {
    1102   [ +  -  +  -  :       2342 :         return ctrlr->vcprop.vs.raw;
             +  -  +  - ]
    1103                 :            : }
    1104                 :            : 
    1105                 :            : static uint64_t
    1106                 :       4121 : nvmf_prop_get_cc(struct spdk_nvmf_ctrlr *ctrlr)
    1107                 :            : {
    1108   [ +  -  +  -  :       4121 :         return ctrlr->vcprop.cc.raw;
             +  -  +  - ]
    1109                 :            : }
    1110                 :            : 
    1111                 :            : static bool
    1112                 :       5013 : nvmf_prop_set_cc(struct spdk_nvmf_ctrlr *ctrlr, uint32_t value)
    1113                 :            : {
    1114                 :          1 :         union spdk_nvme_cc_register cc, diff;
    1115                 :          1 :         uint32_t cc_timeout_ms;
    1116                 :            : 
    1117                 :       5013 :         cc.raw = value;
    1118                 :            : 
    1119   [ +  +  +  +  :       5013 :         SPDK_DEBUGLOG(nvmf, "cur CC: 0x%08x\n", ctrlr->vcprop.cc.raw);
          +  -  #  #  #  
             #  #  #  #  
                      # ]
    1120   [ +  +  +  +  :       5013 :         SPDK_DEBUGLOG(nvmf, "new CC: 0x%08x\n", cc.raw);
                   +  - ]
    1121                 :            : 
    1122                 :            :         /*
    1123                 :            :          * Calculate which bits changed between the current and new CC.
    1124                 :            :          * Mark each bit as 0 once it is handled to determine if any unhandled bits were changed.
    1125                 :            :          */
    1126   [ +  -  +  -  :       5013 :         diff.raw = cc.raw ^ ctrlr->vcprop.cc.raw;
             +  -  +  - ]
    1127                 :            : 
    1128         [ +  + ]:       5013 :         if (diff.bits.en) {
    1129         [ +  + ]:       2335 :                 if (cc.bits.en) {
    1130   [ +  +  +  +  :       2330 :                         SPDK_DEBUGLOG(nvmf, "Property Set CC Enable!\n");
                   +  - ]
    1131                 :       2330 :                         nvmf_ctrlr_stop_association_timer(ctrlr);
    1132                 :            : 
    1133   [ +  -  +  -  :       2330 :                         ctrlr->vcprop.cc.bits.en = 1;
             +  -  +  - ]
    1134   [ +  -  +  -  :       2330 :                         ctrlr->vcprop.csts.bits.rdy = 1;
             +  -  +  - ]
    1135                 :        930 :                 } else {
    1136   [ -  +  -  +  :          5 :                         SPDK_DEBUGLOG(nvmf, "Property Set CC Disable!\n");
                   #  # ]
    1137   [ -  +  -  +  :          5 :                         if (ctrlr->disconnect_in_progress) {
             #  #  #  # ]
    1138   [ #  #  #  #  :          0 :                                 SPDK_DEBUGLOG(nvmf, "Disconnect in progress\n");
                   #  # ]
    1139                 :          0 :                                 return true;
    1140                 :            :                         }
    1141                 :            : 
    1142   [ #  #  #  # ]:          5 :                         ctrlr->cc_timeout_timer = SPDK_POLLER_REGISTER(nvmf_ctrlr_cc_timeout, ctrlr,
    1143                 :            :                                                   NVMF_CC_RESET_SHN_TIMEOUT_IN_MS * 1000);
    1144                 :            :                         /* Make sure cc_timeout_ms is between cc_timeout_timer and Host reset/shutdown timeout */
    1145                 :          5 :                         cc_timeout_ms = (NVMF_CC_RESET_SHN_TIMEOUT_IN_MS + NVMF_CTRLR_RESET_SHN_TIMEOUT_IN_MS) / 2;
    1146   [ #  #  #  #  :          5 :                         ctrlr->cc_timeout_tsc = spdk_get_ticks() + cc_timeout_ms * spdk_get_ticks_hz() / (uint64_t)1000;
                   #  # ]
    1147                 :            : 
    1148   [ #  #  #  #  :          5 :                         ctrlr->vcprop.cc.bits.en = 0;
             #  #  #  # ]
    1149   [ #  #  #  # ]:          5 :                         ctrlr->disconnect_in_progress = true;
    1150   [ #  #  #  # ]:          5 :                         ctrlr->disconnect_is_shn = false;
    1151   [ #  #  #  #  :          5 :                         spdk_for_each_channel(ctrlr->subsys->tgt,
             #  #  #  # ]
    1152                 :            :                                               nvmf_ctrlr_disconnect_io_qpairs_on_pg,
    1153                 :          0 :                                               ctrlr,
    1154                 :            :                                               nvmf_ctrlr_cc_reset_shn_done);
    1155                 :            :                 }
    1156                 :       2335 :                 diff.bits.en = 0;
    1157                 :        930 :         }
    1158                 :            : 
    1159         [ +  + ]:       5013 :         if (diff.bits.shn) {
    1160   [ -  +  #  # ]:       2219 :                 if (cc.bits.shn == SPDK_NVME_SHN_NORMAL ||
    1161         [ #  # ]:          0 :                     cc.bits.shn == SPDK_NVME_SHN_ABRUPT) {
    1162   [ +  +  +  +  :       2219 :                         SPDK_DEBUGLOG(nvmf, "Property Set CC Shutdown %u%ub!\n",
             +  -  #  # ]
    1163                 :            :                                       cc.bits.shn >> 1, cc.bits.shn & 1);
    1164   [ +  +  +  +  :       2219 :                         if (ctrlr->disconnect_in_progress) {
             +  -  -  + ]
    1165   [ #  #  #  #  :          0 :                                 SPDK_DEBUGLOG(nvmf, "Disconnect in progress\n");
                   #  # ]
    1166                 :          0 :                                 return true;
    1167                 :            :                         }
    1168                 :            : 
    1169   [ +  -  +  - ]:       2219 :                         ctrlr->cc_timeout_timer = SPDK_POLLER_REGISTER(nvmf_ctrlr_cc_timeout, ctrlr,
    1170                 :            :                                                   NVMF_CC_RESET_SHN_TIMEOUT_IN_MS * 1000);
    1171                 :            :                         /* Make sure cc_timeout_ms is between cc_timeout_timer and Host reset/shutdown timeout */
    1172                 :       2219 :                         cc_timeout_ms = (NVMF_CC_RESET_SHN_TIMEOUT_IN_MS + NVMF_CTRLR_RESET_SHN_TIMEOUT_IN_MS) / 2;
    1173   [ +  -  +  -  :       2219 :                         ctrlr->cc_timeout_tsc = spdk_get_ticks() + cc_timeout_ms * spdk_get_ticks_hz() / (uint64_t)1000;
                   +  - ]
    1174                 :            : 
    1175   [ +  -  +  -  :       2219 :                         ctrlr->vcprop.cc.bits.shn = cc.bits.shn;
             +  -  +  - ]
    1176   [ +  -  +  - ]:       2219 :                         ctrlr->disconnect_in_progress = true;
    1177   [ +  -  +  - ]:       2219 :                         ctrlr->disconnect_is_shn = true;
    1178   [ +  -  +  -  :       2219 :                         spdk_for_each_channel(ctrlr->subsys->tgt,
             +  -  +  - ]
    1179                 :            :                                               nvmf_ctrlr_disconnect_io_qpairs_on_pg,
    1180                 :        930 :                                               ctrlr,
    1181                 :            :                                               nvmf_ctrlr_cc_reset_shn_done);
    1182                 :            : 
    1183                 :            :                         /* From the time a shutdown is initiated the controller shall disable
    1184                 :            :                          * Keep Alive timer */
    1185                 :       2219 :                         nvmf_ctrlr_stop_keep_alive_timer(ctrlr);
    1186         [ #  # ]:        930 :                 } else if (cc.bits.shn == 0) {
    1187   [ #  #  #  #  :          0 :                         ctrlr->vcprop.cc.bits.shn = 0;
             #  #  #  # ]
    1188                 :          0 :                 } else {
    1189         [ #  # ]:          0 :                         SPDK_ERRLOG("Prop Set CC: Invalid SHN value %u%ub\n",
    1190                 :            :                                     cc.bits.shn >> 1, cc.bits.shn & 1);
    1191                 :          0 :                         return false;
    1192                 :            :                 }
    1193                 :       2219 :                 diff.bits.shn = 0;
    1194                 :        930 :         }
    1195                 :            : 
    1196         [ +  + ]:       5013 :         if (diff.bits.iosqes) {
    1197   [ +  +  +  +  :       2335 :                 SPDK_DEBUGLOG(nvmf, "Prop Set IOSQES = %u (%u bytes)\n",
             +  -  #  # ]
    1198                 :            :                               cc.bits.iosqes, 1u << cc.bits.iosqes);
    1199   [ +  -  +  -  :       2335 :                 ctrlr->vcprop.cc.bits.iosqes = cc.bits.iosqes;
             +  -  +  - ]
    1200                 :       2335 :                 diff.bits.iosqes = 0;
    1201                 :        930 :         }
    1202                 :            : 
    1203         [ +  + ]:       5013 :         if (diff.bits.iocqes) {
    1204   [ +  +  +  +  :       2335 :                 SPDK_DEBUGLOG(nvmf, "Prop Set IOCQES = %u (%u bytes)\n",
             +  -  #  # ]
    1205                 :            :                               cc.bits.iocqes, 1u << cc.bits.iocqes);
    1206   [ +  -  +  -  :       2335 :                 ctrlr->vcprop.cc.bits.iocqes = cc.bits.iocqes;
             +  -  +  - ]
    1207                 :       2335 :                 diff.bits.iocqes = 0;
    1208                 :        930 :         }
    1209                 :            : 
    1210         [ -  + ]:       5013 :         if (diff.bits.ams) {
    1211                 :          0 :                 SPDK_ERRLOG("Arbitration Mechanism Selected (AMS) 0x%x not supported!\n", cc.bits.ams);
    1212                 :          0 :                 return false;
    1213                 :            :         }
    1214                 :            : 
    1215         [ -  + ]:       5013 :         if (diff.bits.mps) {
    1216   [ #  #  #  #  :          0 :                 SPDK_ERRLOG("Memory Page Size (MPS) %u KiB not supported!\n", (1 << (2 + cc.bits.mps)));
                   #  # ]
    1217                 :          0 :                 return false;
    1218                 :            :         }
    1219                 :            : 
    1220         [ +  + ]:       5013 :         if (diff.bits.css) {
    1221         [ #  # ]:          0 :                 if (cc.bits.css > SPDK_NVME_CC_CSS_IOCS) {
    1222                 :          0 :                         SPDK_ERRLOG("I/O Command Set Selected (CSS) 0x%x not supported!\n", cc.bits.css);
    1223                 :          0 :                         return false;
    1224                 :            :                 }
    1225                 :          0 :                 diff.bits.css = 0;
    1226                 :          0 :         }
    1227                 :            : 
    1228         [ +  + ]:       5013 :         if (diff.raw != 0) {
    1229                 :            :                 /* Print an error message, but don't fail the command in this case.
    1230                 :            :                  * If we did want to fail in this case, we'd need to ensure we acted
    1231                 :            :                  * on no other bits or the initiator gets confused. */
    1232                 :          0 :                 SPDK_ERRLOG("Prop Set CC toggled reserved bits 0x%x!\n", diff.raw);
    1233                 :          0 :         }
    1234                 :            : 
    1235                 :       5013 :         return true;
    1236                 :       1861 : }
    1237                 :            : 
    1238                 :            : static uint64_t
    1239                 :      71190 : nvmf_prop_get_csts(struct spdk_nvmf_ctrlr *ctrlr)
    1240                 :            : {
    1241   [ +  -  +  -  :      71190 :         return ctrlr->vcprop.csts.raw;
             +  -  +  - ]
    1242                 :            : }
    1243                 :            : 
    1244                 :            : static uint64_t
    1245                 :          0 : nvmf_prop_get_aqa(struct spdk_nvmf_ctrlr *ctrlr)
    1246                 :            : {
    1247   [ #  #  #  #  :          0 :         return ctrlr->vcprop.aqa.raw;
             #  #  #  # ]
    1248                 :            : }
    1249                 :            : 
    1250                 :            : static bool
    1251                 :         59 : nvmf_prop_set_aqa(struct spdk_nvmf_ctrlr *ctrlr, uint32_t value)
    1252                 :            : {
    1253                 :          0 :         union spdk_nvme_aqa_register aqa;
    1254                 :            : 
    1255                 :         59 :         aqa.raw = value;
    1256                 :            : 
    1257                 :            :         /*
    1258                 :            :          * We don't need to explicitly check for maximum size, as the fields are
    1259                 :            :          * limited to 12 bits (4096).
    1260                 :            :          */
    1261   [ +  -  +  - ]:         66 :         if (aqa.bits.asqs < SPDK_NVME_ADMIN_QUEUE_MIN_ENTRIES - 1 ||
    1262         [ +  - ]:         59 :             aqa.bits.acqs < SPDK_NVME_ADMIN_QUEUE_MIN_ENTRIES - 1 ||
    1263   [ +  -  -  + ]:         59 :             aqa.bits.reserved1 != 0 || aqa.bits.reserved2 != 0) {
    1264                 :          0 :                 return false;
    1265                 :            :         }
    1266                 :            : 
    1267   [ +  -  +  -  :         59 :         ctrlr->vcprop.aqa.raw = value;
             +  -  +  - ]
    1268                 :            : 
    1269                 :         59 :         return true;
    1270                 :          7 : }
    1271                 :            : 
    1272                 :            : static uint64_t
    1273                 :          6 : nvmf_prop_get_asq(struct spdk_nvmf_ctrlr *ctrlr)
    1274                 :            : {
    1275   [ +  -  +  -  :          6 :         return ctrlr->vcprop.asq;
                   +  - ]
    1276                 :            : }
    1277                 :            : 
    1278                 :            : static bool
    1279                 :         65 : nvmf_prop_set_asq_lower(struct spdk_nvmf_ctrlr *ctrlr, uint32_t value)
    1280                 :            : {
    1281   [ +  -  +  -  :         65 :         ctrlr->vcprop.asq = (ctrlr->vcprop.asq & (0xFFFFFFFFULL << 32ULL)) | value;
          +  -  +  -  +  
             -  +  -  +  
                      - ]
    1282                 :            : 
    1283                 :         65 :         return true;
    1284                 :            : }
    1285                 :            : 
    1286                 :            : static bool
    1287                 :         59 : nvmf_prop_set_asq_upper(struct spdk_nvmf_ctrlr *ctrlr, uint32_t value)
    1288                 :            : {
    1289   [ +  -  +  -  :         59 :         ctrlr->vcprop.asq = (ctrlr->vcprop.asq & 0xFFFFFFFFULL) | ((uint64_t)value << 32ULL);
          +  -  +  -  +  
             -  +  -  +  
                      - ]
    1290                 :            : 
    1291                 :         59 :         return true;
    1292                 :            : }
    1293                 :            : 
    1294                 :            : static uint64_t
    1295                 :          0 : nvmf_prop_get_acq(struct spdk_nvmf_ctrlr *ctrlr)
    1296                 :            : {
    1297   [ #  #  #  #  :          0 :         return ctrlr->vcprop.acq;
                   #  # ]
    1298                 :            : }
    1299                 :            : 
    1300                 :            : static bool
    1301                 :         59 : nvmf_prop_set_acq_lower(struct spdk_nvmf_ctrlr *ctrlr, uint32_t value)
    1302                 :            : {
    1303   [ +  -  +  -  :         59 :         ctrlr->vcprop.acq = (ctrlr->vcprop.acq & (0xFFFFFFFFULL << 32ULL)) | value;
          +  -  +  -  +  
             -  +  -  +  
                      - ]
    1304                 :            : 
    1305                 :         59 :         return true;
    1306                 :            : }
    1307                 :            : 
    1308                 :            : static bool
    1309                 :         59 : nvmf_prop_set_acq_upper(struct spdk_nvmf_ctrlr *ctrlr, uint32_t value)
    1310                 :            : {
    1311   [ +  -  +  -  :         59 :         ctrlr->vcprop.acq = (ctrlr->vcprop.acq & 0xFFFFFFFFULL) | ((uint64_t)value << 32ULL);
          +  -  +  -  +  
             -  +  -  +  
                      - ]
    1312                 :            : 
    1313                 :         59 :         return true;
    1314                 :            : }
    1315                 :            : 
    1316                 :            : struct nvmf_prop {
    1317                 :            :         uint32_t ofst;
    1318                 :            :         uint8_t size;
    1319                 :            :         char name[11];
    1320                 :            :         uint64_t (*get_cb)(struct spdk_nvmf_ctrlr *ctrlr);
    1321                 :            :         bool (*set_cb)(struct spdk_nvmf_ctrlr *ctrlr, uint32_t value);
    1322                 :            :         bool (*set_upper_cb)(struct spdk_nvmf_ctrlr *ctrlr, uint32_t value);
    1323                 :            : };
    1324                 :            : 
    1325                 :            : #define PROP(field, size, get_cb, set_cb, set_upper_cb) \
    1326                 :            :         { \
    1327                 :            :                 offsetof(struct spdk_nvme_registers, field), \
    1328                 :            :                 size, \
    1329                 :            :                 #field, \
    1330                 :            :                 get_cb, set_cb, set_upper_cb \
    1331                 :            :         }
    1332                 :            : 
    1333                 :            : static const struct nvmf_prop nvmf_props[] = {
    1334                 :            :         PROP(cap,  8, nvmf_prop_get_cap,  NULL,                    NULL),
    1335                 :            :         PROP(vs,   4, nvmf_prop_get_vs,   NULL,                    NULL),
    1336                 :            :         PROP(cc,   4, nvmf_prop_get_cc,   nvmf_prop_set_cc,        NULL),
    1337                 :            :         PROP(csts, 4, nvmf_prop_get_csts, NULL,                    NULL),
    1338                 :            :         PROP(aqa,  4, nvmf_prop_get_aqa,  nvmf_prop_set_aqa,       NULL),
    1339                 :            :         PROP(asq,  8, nvmf_prop_get_asq,  nvmf_prop_set_asq_lower, nvmf_prop_set_asq_upper),
    1340                 :            :         PROP(acq,  8, nvmf_prop_get_acq,  nvmf_prop_set_acq_lower, nvmf_prop_set_acq_upper),
    1341                 :            : };
    1342                 :            : 
    1343                 :            : static const struct nvmf_prop *
    1344                 :      85849 : find_prop(uint32_t ofst, uint8_t size)
    1345                 :            : {
    1346                 :          6 :         size_t i;
    1347                 :            : 
    1348         [ +  + ]:     321433 :         for (i = 0; i < SPDK_COUNTOF(nvmf_props); i++) {
    1349   [ +  -  +  - ]:     321395 :                 const struct nvmf_prop *prop = &nvmf_props[i];
    1350                 :            : 
    1351   [ +  +  +  +  :     321395 :                 if ((ofst >= prop->ofst) && (ofst + size <= prop->ofst + prop->size)) {
          +  +  -  +  -  
          +  -  +  -  +  
                   +  + ]
    1352                 :      85811 :                         return prop;
    1353                 :            :                 }
    1354         [ +  + ]:      17015 :         }
    1355                 :            : 
    1356                 :         38 :         return NULL;
    1357                 :       8425 : }
    1358                 :            : 
    1359                 :            : static int
    1360                 :      80603 : nvmf_property_get(struct spdk_nvmf_request *req)
    1361                 :            : {
    1362   [ +  -  +  -  :      80603 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    1363   [ +  -  +  -  :      80603 :         struct spdk_nvmf_fabric_prop_get_cmd *cmd = &req->cmd->prop_get_cmd;
                   +  - ]
    1364   [ +  -  +  -  :      80603 :         struct spdk_nvmf_fabric_prop_get_rsp *response = &req->rsp->prop_get_rsp;
                   +  - ]
    1365                 :          3 :         const struct nvmf_prop *prop;
    1366                 :          3 :         uint8_t size;
    1367                 :            : 
    1368   [ +  -  +  - ]:      80603 :         response->status.sc = 0;
    1369   [ +  -  +  -  :      80603 :         response->value.u64 = 0;
                   +  - ]
    1370                 :            : 
    1371   [ +  +  +  +  :      80603 :         SPDK_DEBUGLOG(nvmf, "size %d, offset 0x%x\n",
          +  -  #  #  #  
             #  #  #  #  
                      # ]
    1372                 :            :                       cmd->attrib.size, cmd->ofst);
    1373                 :            : 
    1374   [ +  +  +  -  :      80603 :         switch (cmd->attrib.size) {
                -  +  + ]
    1375                 :      72225 :         case SPDK_NVMF_PROP_SIZE_4:
    1376                 :      77819 :                 size = 4;
    1377                 :      77819 :                 break;
    1378                 :       1847 :         case SPDK_NVMF_PROP_SIZE_8:
    1379                 :       2784 :                 size = 8;
    1380                 :       2784 :                 break;
    1381                 :          0 :         default:
    1382   [ #  #  #  #  :          0 :                 SPDK_DEBUGLOG(nvmf, "Invalid size value %d\n", cmd->attrib.size);
          #  #  #  #  #  
                      # ]
    1383   [ #  #  #  # ]:          0 :                 response->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
    1384   [ #  #  #  # ]:          0 :                 response->status.sc = SPDK_NVMF_FABRIC_SC_INVALID_PARAM;
    1385                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1386                 :            :         }
    1387                 :            : 
    1388   [ +  -  +  - ]:      80603 :         prop = find_prop(cmd->ofst, size);
    1389   [ +  +  +  +  :      80603 :         if (prop == NULL || prop->get_cb == NULL) {
             +  -  -  + ]
    1390   [ +  -  +  - ]:         28 :                 response->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
    1391   [ +  -  +  - ]:         28 :                 response->status.sc = SPDK_NVMF_FABRIC_SC_INVALID_PARAM;
    1392                 :         28 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1393                 :            :         }
    1394                 :            : 
    1395   [ +  +  +  +  :      80575 :         SPDK_DEBUGLOG(nvmf, "name: %s\n", prop->name);
             +  -  #  # ]
    1396                 :            : 
    1397   [ +  -  +  -  :      80575 :         response->value.u64 = prop->get_cb(ctrlr);
          -  +  +  -  +  
             -  +  -  +  
                      - ]
    1398                 :            : 
    1399   [ +  +  +  -  :      80575 :         if (size != prop->size) {
                   +  + ]
    1400                 :            :                 /* The size must be 4 and the prop->size is 8. Figure out which part of the property to read. */
    1401   [ +  +  #  # ]:        138 :                 assert(size == 4);
    1402   [ +  +  +  -  :        138 :                 assert(prop->size == 8);
             +  -  #  # ]
    1403                 :            : 
    1404   [ +  +  +  -  :        138 :                 if (cmd->ofst == prop->ofst) {
          +  -  +  -  +  
                      - ]
    1405                 :            :                         /* Keep bottom 4 bytes only */
    1406   [ +  -  +  -  :         72 :                         response->value.u64 &= 0xFFFFFFFF;
                   +  - ]
    1407                 :          1 :                 } else {
    1408                 :            :                         /* Keep top 4 bytes only */
    1409   [ #  #  #  #  :         66 :                         response->value.u64 >>= 32;
             #  #  #  # ]
    1410                 :            :                 }
    1411                 :          1 :         }
    1412                 :            : 
    1413   [ +  +  +  +  :      80575 :         SPDK_DEBUGLOG(nvmf, "response value: 0x%" PRIx64 "\n", response->value.u64);
          +  -  #  #  #  
                #  #  # ]
    1414                 :            : 
    1415                 :      80575 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1416                 :       6531 : }
    1417                 :            : 
    1418                 :            : static int
    1419                 :       5246 : nvmf_property_set(struct spdk_nvmf_request *req)
    1420                 :            : {
    1421   [ +  -  +  -  :       5246 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    1422   [ +  -  +  -  :       5246 :         struct spdk_nvmf_fabric_prop_set_cmd *cmd = &req->cmd->prop_set_cmd;
                   +  - ]
    1423   [ +  -  +  -  :       5246 :         struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
                   +  - ]
    1424                 :          3 :         const struct nvmf_prop *prop;
    1425                 :          3 :         uint64_t value;
    1426                 :          3 :         uint8_t size;
    1427                 :          3 :         bool ret;
    1428                 :            : 
    1429   [ +  +  +  +  :       5246 :         SPDK_DEBUGLOG(nvmf, "size %d, offset 0x%x, value 0x%" PRIx64 "\n",
          +  -  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                      # ]
    1430                 :            :                       cmd->attrib.size, cmd->ofst, cmd->value.u64);
    1431                 :            : 
    1432   [ +  +  +  -  :       5246 :         switch (cmd->attrib.size) {
                -  +  + ]
    1433                 :       3282 :         case SPDK_NVMF_PROP_SIZE_4:
    1434                 :       5162 :                 size = 4;
    1435                 :       5162 :                 break;
    1436                 :         70 :         case SPDK_NVMF_PROP_SIZE_8:
    1437                 :         84 :                 size = 8;
    1438                 :         84 :                 break;
    1439                 :          0 :         default:
    1440   [ #  #  #  #  :          0 :                 SPDK_DEBUGLOG(nvmf, "Invalid size value %d\n", cmd->attrib.size);
          #  #  #  #  #  
                      # ]
    1441   [ #  #  #  #  :          0 :                 response->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
                   #  # ]
    1442   [ #  #  #  #  :          0 :                 response->status.sc = SPDK_NVMF_FABRIC_SC_INVALID_PARAM;
                   #  # ]
    1443                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1444                 :            :         }
    1445                 :            : 
    1446   [ +  -  +  - ]:       5246 :         prop = find_prop(cmd->ofst, size);
    1447   [ +  +  +  +  :       5246 :         if (prop == NULL || prop->set_cb == NULL) {
             +  -  +  + ]
    1448   [ +  +  +  +  :         16 :                 SPDK_INFOLOG(nvmf, "Invalid offset 0x%x\n", cmd->ofst);
          +  -  #  #  #  
                      # ]
    1449   [ +  -  +  -  :         16 :                 response->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
                   +  - ]
    1450   [ +  -  +  -  :         16 :                 response->status.sc = SPDK_NVMF_FABRIC_SC_INVALID_PARAM;
                   +  - ]
    1451                 :         16 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1452                 :            :         }
    1453                 :            : 
    1454   [ +  +  +  +  :       5230 :         SPDK_DEBUGLOG(nvmf, "name: %s\n", prop->name);
             +  -  #  # ]
    1455                 :            : 
    1456   [ +  -  +  -  :       5230 :         value = cmd->value.u64;
                   +  - ]
    1457                 :            : 
    1458   [ +  +  +  -  :       5230 :         if (prop->size == 4) {
                   +  + ]
    1459   [ +  -  +  -  :       5072 :                 ret = prop->set_cb(ctrlr, (uint32_t)value);
             -  +  +  - ]
    1460   [ +  +  +  -  :       2026 :         } else if (size != prop->size) {
                   +  + ]
    1461                 :            :                 /* The size must be 4 and the prop->size is 8. Figure out which part of the property to write. */
    1462   [ +  +  #  # ]:         74 :                 assert(size == 4);
    1463   [ +  +  +  -  :         74 :                 assert(prop->size == 8);
             +  -  #  # ]
    1464                 :            : 
    1465   [ +  +  +  -  :         74 :                 if (cmd->ofst == prop->ofst) {
          +  -  +  -  +  
                      - ]
    1466   [ +  -  +  -  :         40 :                         ret = prop->set_cb(ctrlr, (uint32_t)value);
             -  +  +  - ]
    1467                 :          1 :                 } else {
    1468   [ #  #  #  #  :         34 :                         ret = prop->set_upper_cb(ctrlr, (uint32_t)value);
             #  #  #  # ]
    1469                 :            :                 }
    1470                 :          1 :         } else {
    1471   [ +  -  +  -  :         84 :                 ret = prop->set_cb(ctrlr, (uint32_t)value);
             -  +  +  - ]
    1472   [ +  -  -  + ]:         84 :                 if (ret) {
    1473   [ +  -  +  -  :         84 :                         ret = prop->set_upper_cb(ctrlr, (uint32_t)(value >> 32));
          -  +  +  -  +  
                      - ]
    1474                 :         14 :                 }
    1475                 :            :         }
    1476                 :            : 
    1477   [ +  +  +  - ]:       5230 :         if (!ret) {
    1478                 :          0 :                 SPDK_ERRLOG("prop set_cb failed\n");
    1479   [ #  #  #  #  :          0 :                 response->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
                   #  # ]
    1480   [ #  #  #  #  :          0 :                 response->status.sc = SPDK_NVMF_FABRIC_SC_INVALID_PARAM;
                   #  # ]
    1481                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1482                 :            :         }
    1483                 :            : 
    1484                 :       5230 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1485                 :       1894 : }
    1486                 :            : 
    1487                 :            : static int
    1488                 :         14 : nvmf_ctrlr_set_features_arbitration(struct spdk_nvmf_request *req)
    1489                 :            : {
    1490   [ +  -  +  -  :         14 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    1491   [ +  -  +  -  :         14 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    1492                 :            : 
    1493   [ +  -  +  -  :         14 :         SPDK_DEBUGLOG(nvmf, "Set Features - Arbitration (cdw11 = 0x%0x)\n", cmd->cdw11);
          +  -  #  #  #  
                #  #  # ]
    1494                 :            : 
    1495   [ +  -  +  -  :         14 :         ctrlr->feat.arbitration.raw = cmd->cdw11;
          +  -  +  -  +  
             -  +  -  +  
                      - ]
    1496   [ +  -  +  -  :         14 :         ctrlr->feat.arbitration.bits.reserved = 0;
             +  -  +  - ]
    1497                 :            : 
    1498                 :         14 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1499                 :          0 : }
    1500                 :            : 
    1501                 :            : static int
    1502                 :          4 : nvmf_ctrlr_set_features_power_management(struct spdk_nvmf_request *req)
    1503                 :            : {
    1504   [ +  -  +  -  :          4 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    1505   [ +  -  +  -  :          4 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    1506   [ +  -  +  -  :          4 :         struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
                   +  - ]
    1507                 :            : 
    1508   [ +  -  +  -  :          4 :         SPDK_DEBUGLOG(nvmf, "Set Features - Power Management (cdw11 = 0x%0x)\n", cmd->cdw11);
          +  -  #  #  #  
                #  #  # ]
    1509                 :            : 
    1510                 :            :         /* Only PS = 0 is allowed, since we report NPSS = 0 */
    1511   [ +  -  +  -  :          4 :         if (cmd->cdw11_bits.feat_power_management.bits.ps != 0) {
          +  -  +  -  +  
                -  -  + ]
    1512   [ +  -  +  -  :          4 :                 SPDK_ERRLOG("Invalid power state %u\n", cmd->cdw11_bits.feat_power_management.bits.ps);
          +  -  +  -  +  
                      - ]
    1513   [ +  -  +  -  :          4 :                 rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    1514   [ +  -  +  -  :          4 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   +  - ]
    1515                 :          4 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1516                 :            :         }
    1517                 :            : 
    1518   [ #  #  #  #  :          0 :         ctrlr->feat.power_management.raw = cmd->cdw11;
          #  #  #  #  #  
             #  #  #  #  
                      # ]
    1519   [ #  #  #  #  :          0 :         ctrlr->feat.power_management.bits.reserved = 0;
             #  #  #  # ]
    1520                 :            : 
    1521                 :          0 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1522                 :          4 : }
    1523                 :            : 
    1524                 :            : static bool
    1525                 :         50 : temp_threshold_opts_valid(const union spdk_nvme_feat_temperature_threshold *opts)
    1526                 :            : {
    1527                 :            :         /*
    1528                 :            :          * Valid TMPSEL values:
    1529                 :            :          *  0000b - 1000b: temperature sensors
    1530                 :            :          *  1111b: set all implemented temperature sensors
    1531                 :            :          */
    1532   [ +  +  +  -  :         50 :         if (opts->bits.tmpsel >= 9 && opts->bits.tmpsel != 15) {
          +  +  +  -  +  
                -  -  + ]
    1533                 :            :                 /* 1001b - 1110b: reserved */
    1534   [ -  +  -  + ]:         13 :                 SPDK_ERRLOG("Invalid TMPSEL %u\n", opts->bits.tmpsel);
    1535                 :         13 :                 return false;
    1536                 :            :         }
    1537                 :            : 
    1538                 :            :         /*
    1539                 :            :          * Valid THSEL values:
    1540                 :            :          *  00b: over temperature threshold
    1541                 :            :          *  01b: under temperature threshold
    1542                 :            :          */
    1543   [ +  +  +  -  :         37 :         if (opts->bits.thsel > 1) {
                   +  + ]
    1544                 :            :                 /* 10b - 11b: reserved */
    1545   [ +  -  +  - ]:          6 :                 SPDK_ERRLOG("Invalid THSEL %u\n", opts->bits.thsel);
    1546                 :          6 :                 return false;
    1547                 :            :         }
    1548                 :            : 
    1549                 :         31 :         return true;
    1550                 :          5 : }
    1551                 :            : 
    1552                 :            : static int
    1553                 :         24 : nvmf_ctrlr_set_features_temperature_threshold(struct spdk_nvmf_request *req)
    1554                 :            : {
    1555   [ +  -  +  -  :         24 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    1556   [ +  -  +  -  :         24 :         struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
                   +  - ]
    1557                 :            : 
    1558   [ +  +  +  +  :         24 :         SPDK_DEBUGLOG(nvmf, "Set Features - Temperature Threshold (cdw11 = 0x%0x)\n", cmd->cdw11);
          +  -  #  #  #  
                #  #  # ]
    1559                 :            : 
    1560   [ +  +  +  -  :         24 :         if (!temp_threshold_opts_valid(&cmd->cdw11_bits.feat_temp_threshold)) {
             +  -  +  + ]
    1561   [ +  -  +  -  :         13 :                 rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    1562   [ +  -  +  -  :         13 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   +  - ]
    1563                 :         13 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1564                 :            :         }
    1565                 :            : 
    1566                 :            :         /* TODO: no sensors implemented - ignore new values */
    1567                 :         11 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1568                 :          3 : }
    1569                 :            : 
    1570                 :            : static int
    1571                 :         26 : nvmf_ctrlr_get_features_temperature_threshold(struct spdk_nvmf_request *req)
    1572                 :            : {
    1573   [ +  -  +  -  :         26 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    1574   [ +  -  +  -  :         26 :         struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
                   +  - ]
    1575                 :            : 
    1576   [ +  +  +  +  :         26 :         SPDK_DEBUGLOG(nvmf, "Get Features - Temperature Threshold (cdw11 = 0x%0x)\n", cmd->cdw11);
          +  -  #  #  #  
                #  #  # ]
    1577                 :            : 
    1578   [ +  +  +  -  :         26 :         if (!temp_threshold_opts_valid(&cmd->cdw11_bits.feat_temp_threshold)) {
             +  -  +  + ]
    1579   [ +  -  +  -  :          6 :                 rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    1580   [ +  -  +  -  :          6 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   +  - ]
    1581                 :          6 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1582                 :            :         }
    1583                 :            : 
    1584                 :            :         /* TODO: no sensors implemented - return 0 for all thresholds */
    1585   [ +  -  +  - ]:         20 :         rsp->cdw0 = 0;
    1586                 :            : 
    1587                 :         20 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1588                 :          2 : }
    1589                 :            : 
    1590                 :            : static int
    1591                 :          3 : nvmf_ctrlr_get_features_interrupt_vector_configuration(struct spdk_nvmf_request *req)
    1592                 :            : {
    1593   [ #  #  #  #  :          3 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             #  #  #  # ]
    1594   [ #  #  #  #  :          3 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   #  # ]
    1595   [ #  #  #  #  :          3 :         struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
                   #  # ]
    1596                 :          3 :         union spdk_nvme_feat_interrupt_vector_configuration iv_conf = {};
    1597                 :            : 
    1598   [ -  +  -  +  :          3 :         SPDK_DEBUGLOG(nvmf, "Get Features - Interrupt Vector Configuration (cdw11 = 0x%0x)\n", cmd->cdw11);
          #  #  #  #  #  
                #  #  # ]
    1599                 :            : 
    1600   [ #  #  #  #  :          3 :         iv_conf.bits.iv = cmd->cdw11_bits.feat_interrupt_vector_configuration.bits.iv;
          #  #  #  #  #  
                      # ]
    1601   [ #  #  #  #  :          3 :         iv_conf.bits.cd = ctrlr->feat.interrupt_vector_configuration.bits.cd;
             #  #  #  # ]
    1602   [ #  #  #  # ]:          3 :         rsp->cdw0 = iv_conf.raw;
    1603                 :            : 
    1604                 :          3 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1605                 :          0 : }
    1606                 :            : 
    1607                 :            : static int
    1608                 :         16 : nvmf_ctrlr_set_features_error_recovery(struct spdk_nvmf_request *req)
    1609                 :            : {
    1610   [ +  -  +  -  :         16 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    1611   [ +  -  +  -  :         16 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    1612   [ +  -  +  -  :         16 :         struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
                   +  - ]
    1613                 :            : 
    1614   [ +  +  +  +  :         16 :         SPDK_DEBUGLOG(nvmf, "Set Features - Error Recovery (cdw11 = 0x%0x)\n", cmd->cdw11);
          +  -  #  #  #  
                #  #  # ]
    1615                 :            : 
    1616   [ +  +  +  -  :         16 :         if (cmd->cdw11_bits.feat_error_recovery.bits.dulbe) {
          +  -  +  -  +  
                -  +  + ]
    1617                 :            :                 /*
    1618                 :            :                  * Host is not allowed to set this bit, since we don't advertise it in
    1619                 :            :                  * Identify Namespace.
    1620                 :            :                  */
    1621                 :          8 :                 SPDK_ERRLOG("Host set unsupported DULBE bit\n");
    1622   [ +  -  +  -  :          8 :                 rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    1623   [ +  -  +  -  :          8 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   +  - ]
    1624                 :          8 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1625                 :            :         }
    1626                 :            : 
    1627   [ +  -  +  -  :          8 :         ctrlr->feat.error_recovery.raw = cmd->cdw11;
          +  -  +  -  +  
             -  +  -  +  
                      - ]
    1628   [ +  -  +  -  :          8 :         ctrlr->feat.error_recovery.bits.reserved = 0;
             +  -  +  - ]
    1629                 :            : 
    1630                 :          8 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1631                 :          2 : }
    1632                 :            : 
    1633                 :            : static int
    1634                 :          0 : nvmf_ctrlr_set_features_volatile_write_cache(struct spdk_nvmf_request *req)
    1635                 :            : {
    1636   [ #  #  #  #  :          0 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             #  #  #  # ]
    1637   [ #  #  #  #  :          0 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   #  # ]
    1638                 :            : 
    1639   [ #  #  #  #  :          0 :         SPDK_DEBUGLOG(nvmf, "Set Features - Volatile Write Cache (cdw11 = 0x%0x)\n", cmd->cdw11);
          #  #  #  #  #  
                #  #  # ]
    1640                 :            : 
    1641   [ #  #  #  #  :          0 :         ctrlr->feat.volatile_write_cache.raw = cmd->cdw11;
          #  #  #  #  #  
             #  #  #  #  
                      # ]
    1642   [ #  #  #  #  :          0 :         ctrlr->feat.volatile_write_cache.bits.reserved = 0;
             #  #  #  # ]
    1643                 :            : 
    1644   [ #  #  #  #  :          0 :         SPDK_DEBUGLOG(nvmf, "Set Features - Volatile Write Cache %s\n",
          #  #  #  #  #  
             #  #  #  #  
                      # ]
    1645                 :            :                       ctrlr->feat.volatile_write_cache.bits.wce ? "Enabled" : "Disabled");
    1646                 :          0 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1647                 :          0 : }
    1648                 :            : 
    1649                 :            : static int
    1650                 :          6 : nvmf_ctrlr_set_features_write_atomicity(struct spdk_nvmf_request *req)
    1651                 :            : {
    1652   [ #  #  #  #  :          6 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             #  #  #  # ]
    1653   [ #  #  #  #  :          6 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   #  # ]
    1654                 :            : 
    1655   [ -  +  -  +  :          6 :         SPDK_DEBUGLOG(nvmf, "Set Features - Write Atomicity (cdw11 = 0x%0x)\n", cmd->cdw11);
          #  #  #  #  #  
                #  #  # ]
    1656                 :            : 
    1657   [ #  #  #  #  :          6 :         ctrlr->feat.write_atomicity.raw = cmd->cdw11;
          #  #  #  #  #  
             #  #  #  #  
                      # ]
    1658   [ #  #  #  #  :          6 :         ctrlr->feat.write_atomicity.bits.reserved = 0;
             #  #  #  # ]
    1659                 :            : 
    1660                 :          6 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1661                 :          0 : }
    1662                 :            : 
    1663                 :            : static int
    1664                 :          1 : nvmf_ctrlr_set_features_host_identifier(struct spdk_nvmf_request *req)
    1665                 :            : {
    1666   [ #  #  #  #  :          1 :         struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
                   #  # ]
    1667                 :            : 
    1668                 :          1 :         SPDK_ERRLOG("Set Features - Host Identifier not allowed\n");
    1669   [ #  #  #  #  :          1 :         response->status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR;
                   #  # ]
    1670                 :          1 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1671                 :          0 : }
    1672                 :            : 
    1673                 :            : static int
    1674                 :          0 : nvmf_ctrlr_get_features_host_identifier(struct spdk_nvmf_request *req)
    1675                 :            : {
    1676   [ #  #  #  #  :          0 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             #  #  #  # ]
    1677   [ #  #  #  #  :          0 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   #  # ]
    1678   [ #  #  #  #  :          0 :         struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
                   #  # ]
    1679                 :          0 :         struct spdk_iov_xfer ix;
    1680                 :            : 
    1681   [ #  #  #  #  :          0 :         SPDK_DEBUGLOG(nvmf, "Get Features - Host Identifier\n");
                   #  # ]
    1682                 :            : 
    1683   [ #  #  #  #  :          0 :         if (!cmd->cdw11_bits.feat_host_identifier.bits.exhid) {
          #  #  #  #  #  
                #  #  # ]
    1684                 :            :                 /* NVMe over Fabrics requires EXHID=1 (128-bit/16-byte host ID) */
    1685                 :          0 :                 SPDK_ERRLOG("Get Features - Host Identifier with EXHID=0 not allowed\n");
    1686   [ #  #  #  #  :          0 :                 response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   #  # ]
    1687                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1688                 :            :         }
    1689                 :            : 
    1690   [ #  #  #  #  :          0 :         if (req->iovcnt < 1 || req->length < sizeof(ctrlr->hostid)) {
          #  #  #  #  #  
                #  #  # ]
    1691                 :          0 :                 SPDK_ERRLOG("Invalid data buffer for Get Features - Host Identifier\n");
    1692   [ #  #  #  #  :          0 :                 response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   #  # ]
    1693                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1694                 :            :         }
    1695                 :            : 
    1696   [ #  #  #  #  :          0 :         spdk_iov_xfer_init(&ix, req->iov, req->iovcnt);
                   #  # ]
    1697         [ #  # ]:          0 :         spdk_iov_xfer_from_buf(&ix, &ctrlr->hostid, sizeof(ctrlr->hostid));
    1698                 :            : 
    1699                 :          0 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1700                 :          0 : }
    1701                 :            : 
    1702                 :            : static int
    1703                 :          4 : nvmf_ctrlr_get_features_reservation_notification_mask(struct spdk_nvmf_request *req)
    1704                 :            : {
    1705   [ #  #  #  #  :          4 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             #  #  #  # ]
    1706   [ #  #  #  #  :          4 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   #  # ]
    1707   [ #  #  #  #  :          4 :         struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
                   #  # ]
    1708                 :          0 :         struct spdk_nvmf_ns *ns;
    1709                 :            : 
    1710   [ -  +  -  +  :          4 :         SPDK_DEBUGLOG(nvmf, "get Features - Reservation Notification Mask\n");
                   #  # ]
    1711                 :            : 
    1712   [ -  +  #  #  :          4 :         if (cmd->nsid == SPDK_NVME_GLOBAL_NS_TAG) {
                   #  # ]
    1713                 :          0 :                 SPDK_ERRLOG("get Features - Invalid Namespace ID\n");
    1714   [ #  #  #  #  :          0 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   #  # ]
    1715                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1716                 :            :         }
    1717                 :            : 
    1718   [ #  #  #  #  :          4 :         ns = _nvmf_subsystem_get_ns(ctrlr->subsys, cmd->nsid);
             #  #  #  # ]
    1719         [ -  + ]:          4 :         if (ns == NULL) {
    1720                 :          0 :                 SPDK_ERRLOG("Set Features - Invalid Namespace ID\n");
    1721   [ #  #  #  #  :          0 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   #  # ]
    1722                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1723                 :            :         }
    1724   [ #  #  #  #  :          4 :         rsp->cdw0 = ns->mask;
             #  #  #  # ]
    1725                 :            : 
    1726                 :          4 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1727                 :          0 : }
    1728                 :            : 
    1729                 :            : static int
    1730                 :          0 : nvmf_ctrlr_set_features_reservation_notification_mask(struct spdk_nvmf_request *req)
    1731                 :            : {
    1732   [ #  #  #  #  :          0 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             #  #  #  # ]
    1733   [ #  #  #  # ]:          0 :         struct spdk_nvmf_subsystem *subsystem = ctrlr->subsys;
    1734   [ #  #  #  #  :          0 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   #  # ]
    1735   [ #  #  #  #  :          0 :         struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
                   #  # ]
    1736                 :          0 :         struct spdk_nvmf_ns *ns;
    1737                 :            : 
    1738   [ #  #  #  #  :          0 :         SPDK_DEBUGLOG(nvmf, "Set Features - Reservation Notification Mask\n");
                   #  # ]
    1739                 :            : 
    1740   [ #  #  #  #  :          0 :         if (cmd->nsid == SPDK_NVME_GLOBAL_NS_TAG) {
                   #  # ]
    1741         [ #  # ]:          0 :                 for (ns = spdk_nvmf_subsystem_get_first_ns(subsystem); ns != NULL;
    1742                 :          0 :                      ns = spdk_nvmf_subsystem_get_next_ns(subsystem, ns)) {
    1743   [ #  #  #  #  :          0 :                         ns->mask = cmd->cdw11;
          #  #  #  #  #  
                      # ]
    1744                 :          0 :                 }
    1745                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1746                 :            :         }
    1747                 :            : 
    1748   [ #  #  #  #  :          0 :         ns = _nvmf_subsystem_get_ns(ctrlr->subsys, cmd->nsid);
             #  #  #  # ]
    1749         [ #  # ]:          0 :         if (ns == NULL) {
    1750                 :          0 :                 SPDK_ERRLOG("Set Features - Invalid Namespace ID\n");
    1751   [ #  #  #  #  :          0 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   #  # ]
    1752                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1753                 :            :         }
    1754   [ #  #  #  #  :          0 :         ns->mask = cmd->cdw11;
          #  #  #  #  #  
                      # ]
    1755                 :            : 
    1756                 :          0 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1757                 :          0 : }
    1758                 :            : 
    1759                 :            : static int
    1760                 :          8 : nvmf_ctrlr_get_features_reservation_persistence(struct spdk_nvmf_request *req)
    1761                 :            : {
    1762   [ +  -  +  -  :          8 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    1763   [ +  -  +  -  :          8 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    1764   [ +  -  +  -  :          8 :         struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
                   +  - ]
    1765                 :          1 :         struct spdk_nvmf_ns *ns;
    1766                 :            : 
    1767   [ +  +  +  +  :          8 :         SPDK_DEBUGLOG(nvmf, "Get Features - Reservation Persistence\n");
                   +  - ]
    1768                 :            : 
    1769   [ +  -  +  -  :          8 :         ns = _nvmf_subsystem_get_ns(ctrlr->subsys, cmd->nsid);
             +  -  +  - ]
    1770                 :            :         /* NSID with SPDK_NVME_GLOBAL_NS_TAG (=0xffffffff) also included */
    1771         [ +  + ]:          8 :         if (ns == NULL) {
    1772                 :          0 :                 SPDK_ERRLOG("Get Features - Invalid Namespace ID\n");
    1773   [ #  #  #  #  :          0 :                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    1774   [ #  #  #  #  :          0 :                 response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   #  # ]
    1775                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1776                 :            :         }
    1777                 :            : 
    1778   [ +  +  +  -  :          8 :         response->cdw0 = ns->ptpl_activated;
          +  -  +  -  +  
                      - ]
    1779                 :            : 
    1780   [ +  -  +  -  :          8 :         response->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    1781   [ +  -  +  -  :          8 :         response->status.sc = SPDK_NVME_SC_SUCCESS;
                   +  - ]
    1782                 :          8 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1783                 :          1 : }
    1784                 :            : 
    1785                 :            : static int
    1786                 :          7 : nvmf_ctrlr_set_features_reservation_persistence(struct spdk_nvmf_request *req)
    1787                 :            : {
    1788   [ +  -  +  -  :          7 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    1789   [ +  -  +  -  :          7 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    1790   [ +  -  +  -  :          7 :         struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
                   +  - ]
    1791                 :          1 :         struct spdk_nvmf_ns *ns;
    1792                 :          1 :         bool ptpl;
    1793                 :            : 
    1794   [ +  +  +  +  :          7 :         SPDK_DEBUGLOG(nvmf, "Set Features - Reservation Persistence\n");
                   +  - ]
    1795                 :            : 
    1796   [ +  -  +  -  :          7 :         ns = _nvmf_subsystem_get_ns(ctrlr->subsys, cmd->nsid);
             +  -  +  - ]
    1797   [ +  -  +  -  :          7 :         ptpl = cmd->cdw11_bits.feat_rsv_persistence.bits.ptpl;
          +  -  +  -  +  
                      - ]
    1798                 :            : 
    1799   [ +  -  +  -  :          7 :         if (cmd->nsid != SPDK_NVME_GLOBAL_NS_TAG && ns && nvmf_ns_is_ptpl_capable(ns)) {
          +  +  +  -  -  
                      + ]
    1800   [ +  -  +  -  :          6 :                 ns->ptpl_activated = ptpl;
                   +  - ]
    1801   [ -  +  #  #  :          2 :         } else if (cmd->nsid == SPDK_NVME_GLOBAL_NS_TAG) {
                   #  # ]
    1802   [ #  #  #  #  :          0 :                 for (ns = spdk_nvmf_subsystem_get_first_ns(ctrlr->subsys); ns;
                   #  # ]
    1803   [ #  #  #  # ]:          0 :                      ns = spdk_nvmf_subsystem_get_next_ns(ctrlr->subsys, ns)) {
    1804         [ #  # ]:          0 :                         if (nvmf_ns_is_ptpl_capable(ns)) {
    1805   [ #  #  #  #  :          0 :                                 ns->ptpl_activated = ptpl;
                   #  # ]
    1806                 :          0 :                         }
    1807                 :          0 :                 }
    1808                 :          0 :         } else {
    1809                 :          1 :                 SPDK_ERRLOG("Set Features - Invalid Namespace ID or Reservation Configuration\n");
    1810   [ #  #  #  #  :          1 :                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    1811   [ #  #  #  #  :          1 :                 response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   #  # ]
    1812                 :          1 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1813                 :            :         }
    1814                 :            : 
    1815                 :            :         /* TODO: Feature not changeable for now */
    1816   [ +  -  +  -  :          6 :         response->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
                   +  - ]
    1817   [ +  -  +  -  :          6 :         response->status.sc = SPDK_NVME_SC_FEATURE_ID_NOT_SAVEABLE;
                   +  - ]
    1818                 :          6 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1819                 :          1 : }
    1820                 :            : 
    1821                 :            : static int
    1822                 :         23 : nvmf_ctrlr_get_features_host_behavior_support(struct spdk_nvmf_request *req)
    1823                 :            : {
    1824   [ +  -  +  -  :         23 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    1825   [ +  -  +  -  :         23 :         struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
                   +  - ]
    1826                 :         23 :         struct spdk_nvme_host_behavior host_behavior = {};
    1827                 :         15 :         struct spdk_iov_xfer ix;
    1828                 :            : 
    1829   [ +  +  +  +  :         23 :         SPDK_DEBUGLOG(nvmf, "Get Features - Host Behavior Support\n");
                   +  - ]
    1830                 :            : 
    1831   [ +  +  +  +  :         23 :         if (req->iovcnt < 1 || req->length < sizeof(struct spdk_nvme_host_behavior)) {
          +  +  +  -  +  
                -  +  + ]
    1832                 :         16 :                 SPDK_ERRLOG("invalid data buffer for Host Behavior Support\n");
    1833   [ +  -  +  -  :         16 :                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    1834   [ +  -  +  -  :         16 :                 response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   +  - ]
    1835                 :         16 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1836                 :            :         }
    1837                 :            : 
    1838   [ +  +  +  -  :          7 :         host_behavior.acre = ctrlr->acre_enabled;
                   +  - ]
    1839                 :            : 
    1840   [ +  -  +  -  :          7 :         spdk_iov_xfer_init(&ix, req->iov, req->iovcnt);
                   +  - ]
    1841                 :          7 :         spdk_iov_xfer_from_buf(&ix, &host_behavior, sizeof(host_behavior));
    1842                 :            : 
    1843                 :          7 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1844                 :          3 : }
    1845                 :            : 
    1846                 :            : static int
    1847                 :         30 : nvmf_ctrlr_set_features_host_behavior_support(struct spdk_nvmf_request *req)
    1848                 :            : {
    1849   [ +  -  +  -  :         30 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    1850   [ +  -  +  -  :         30 :         struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
                   +  - ]
    1851                 :          5 :         struct spdk_nvme_host_behavior *host_behavior;
    1852                 :            : 
    1853   [ +  +  +  +  :         30 :         SPDK_DEBUGLOG(nvmf, "Set Features - Host Behavior Support\n");
                   +  - ]
    1854   [ +  +  +  -  :         30 :         if (req->iovcnt != 1) {
                   +  + ]
    1855   [ +  -  +  - ]:          6 :                 SPDK_ERRLOG("Host Behavior Support invalid iovcnt: %d\n", req->iovcnt);
    1856   [ +  -  +  -  :          6 :                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    1857   [ +  -  +  -  :          6 :                 response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   +  - ]
    1858                 :          6 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1859                 :            :         }
    1860   [ +  +  +  -  :         24 :         if (req->iov[0].iov_len != sizeof(struct spdk_nvme_host_behavior)) {
          +  -  +  -  +  
                -  +  + ]
    1861   [ +  -  +  -  :          6 :                 SPDK_ERRLOG("Host Behavior Support invalid iov_len: %zd\n", req->iov[0].iov_len);
          +  -  +  -  +  
                      - ]
    1862   [ +  -  +  -  :          6 :                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    1863   [ +  -  +  -  :          6 :                 response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   +  - ]
    1864                 :          6 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1865                 :            :         }
    1866                 :            : 
    1867   [ +  -  +  -  :         18 :         host_behavior = (struct spdk_nvme_host_behavior *)req->iov[0].iov_base;
          +  -  +  -  +  
                      - ]
    1868   [ +  +  +  -  :         18 :         if (host_behavior->acre == 0) {
                   +  + ]
    1869   [ +  -  +  - ]:          6 :                 ctrlr->acre_enabled = false;
    1870   [ +  +  +  -  :         13 :         } else if (host_behavior->acre == 1) {
                   +  + ]
    1871   [ +  -  +  - ]:          6 :                 ctrlr->acre_enabled = true;
    1872                 :          1 :         } else {
    1873   [ +  -  +  - ]:          6 :                 SPDK_ERRLOG("Host Behavior Support invalid acre: 0x%02x\n", host_behavior->acre);
    1874   [ +  -  +  -  :          6 :                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    1875   [ +  -  +  -  :          6 :                 response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   +  - ]
    1876                 :          6 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1877                 :            :         }
    1878                 :         12 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1879                 :          5 : }
    1880                 :            : 
    1881                 :            : static int
    1882                 :          2 : nvmf_ctrlr_set_features_keep_alive_timer(struct spdk_nvmf_request *req)
    1883                 :            : {
    1884   [ #  #  #  #  :          2 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             #  #  #  # ]
    1885   [ #  #  #  #  :          2 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   #  # ]
    1886   [ #  #  #  #  :          2 :         struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
                   #  # ]
    1887                 :            : 
    1888   [ -  +  -  +  :          2 :         SPDK_DEBUGLOG(nvmf, "Set Features - Keep Alive Timer (%u ms)\n", cmd->cdw11);
          #  #  #  #  #  
                #  #  # ]
    1889                 :            : 
    1890                 :            :         /*
    1891                 :            :          * if attempts to disable keep alive by setting kato to 0h
    1892                 :            :          * a status value of keep alive invalid shall be returned
    1893                 :            :          */
    1894   [ -  +  #  #  :          2 :         if (cmd->cdw11_bits.feat_keep_alive_timer.bits.kato == 0) {
          #  #  #  #  #  
                #  #  # ]
    1895   [ #  #  #  #  :          0 :                 rsp->status.sc = SPDK_NVME_SC_KEEP_ALIVE_INVALID;
                   #  # ]
    1896   [ -  +  #  #  :          2 :         } else if (cmd->cdw11_bits.feat_keep_alive_timer.bits.kato < MIN_KEEP_ALIVE_TIMEOUT_IN_MS) {
          #  #  #  #  #  
                #  #  # ]
    1897   [ #  #  #  #  :          0 :                 ctrlr->feat.keep_alive_timer.bits.kato = MIN_KEEP_ALIVE_TIMEOUT_IN_MS;
             #  #  #  # ]
    1898                 :          0 :         } else {
    1899                 :            :                 /* round up to milliseconds */
    1900   [ #  #  #  #  :          2 :                 ctrlr->feat.keep_alive_timer.bits.kato = spdk_divide_round_up(
          #  #  #  #  #  
                      # ]
    1901   [ #  #  #  #  :          2 :                                         cmd->cdw11_bits.feat_keep_alive_timer.bits.kato,
          #  #  #  #  #  
                      # ]
    1902                 :          0 :                                         KAS_DEFAULT_VALUE * KAS_TIME_UNIT_IN_MS) *
    1903                 :          0 :                                 KAS_DEFAULT_VALUE * KAS_TIME_UNIT_IN_MS;
    1904                 :            :         }
    1905                 :            : 
    1906                 :            :         /*
    1907                 :            :          * if change the keep alive timeout value successfully
    1908                 :            :          * update the keep alive poller.
    1909                 :            :          */
    1910   [ +  -  #  #  :          2 :         if (cmd->cdw11_bits.feat_keep_alive_timer.bits.kato != 0) {
          #  #  #  #  #  
                #  #  # ]
    1911   [ +  +  #  #  :          2 :                 if (ctrlr->keep_alive_poller != NULL) {
                   #  # ]
    1912         [ #  # ]:          1 :                         spdk_poller_unregister(&ctrlr->keep_alive_poller);
    1913                 :          0 :                 }
    1914   [ #  #  #  #  :          2 :                 ctrlr->keep_alive_poller = SPDK_POLLER_REGISTER(nvmf_ctrlr_keep_alive_poll, ctrlr,
          #  #  #  #  #  
                #  #  # ]
    1915                 :            :                                            ctrlr->feat.keep_alive_timer.bits.kato * 1000);
    1916                 :          0 :         }
    1917                 :            : 
    1918   [ -  +  -  +  :          2 :         SPDK_DEBUGLOG(nvmf, "Set Features - Keep Alive Timer set to %u ms\n",
          #  #  #  #  #  
             #  #  #  #  
                      # ]
    1919                 :            :                       ctrlr->feat.keep_alive_timer.bits.kato);
    1920                 :            : 
    1921                 :          2 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1922                 :          0 : }
    1923                 :            : 
    1924                 :            : static int
    1925                 :       2178 : nvmf_ctrlr_set_features_number_of_queues(struct spdk_nvmf_request *req)
    1926                 :            : {
    1927   [ +  -  +  -  :       2178 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    1928   [ +  -  +  -  :       2178 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    1929   [ +  -  +  -  :       2178 :         struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
                   +  - ]
    1930                 :          0 :         uint32_t count;
    1931                 :            : 
    1932   [ +  +  +  +  :       2178 :         SPDK_DEBUGLOG(nvmf, "Set Features - Number of Queues, cdw11 0x%x\n",
          +  -  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
    1933                 :            :                       req->cmd->nvme_cmd.cdw11);
    1934                 :            : 
    1935   [ +  +  +  -  :       3108 :         if (cmd->cdw11_bits.feat_num_of_queues.bits.ncqr == UINT16_MAX ||
          +  -  +  -  +  
             -  +  -  -  
                      + ]
    1936   [ +  +  +  -  :       2177 :             cmd->cdw11_bits.feat_num_of_queues.bits.nsqr == UINT16_MAX) {
          +  -  +  -  +  
                      - ]
    1937   [ #  #  #  #  :          1 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   #  # ]
    1938                 :          1 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1939                 :            :         }
    1940                 :            : 
    1941   [ +  -  +  - ]:       2177 :         count = spdk_bit_array_count_set(ctrlr->qpair_mask);
    1942                 :            :         /* verify that the controller is ready to process commands */
    1943         [ +  + ]:       2177 :         if (count > 1) {
    1944   [ -  +  -  +  :          2 :                 SPDK_DEBUGLOG(nvmf, "Queue pairs already active!\n");
                   #  # ]
    1945   [ #  #  #  #  :          2 :                 rsp->status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR;
                   #  # ]
    1946                 :          0 :         } else {
    1947                 :            :                 /*
    1948                 :            :                  * Ignore the value requested by the host -
    1949                 :            :                  * always return the pre-configured value based on max_qpairs_allowed.
    1950                 :            :                  */
    1951   [ +  -  +  -  :       2175 :                 rsp->cdw0 = ctrlr->feat.number_of_queues.raw;
          +  -  +  -  +  
                -  +  - ]
    1952                 :            :         }
    1953                 :            : 
    1954                 :       2177 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    1955                 :        930 : }
    1956                 :            : 
    1957                 :            : SPDK_STATIC_ASSERT(sizeof(struct spdk_nvmf_ctrlr) == 4920,
    1958                 :            :                    "Please check migration fields that need to be added or not");
    1959                 :            : 
    1960                 :            : static void
    1961                 :          0 : nvmf_ctrlr_migr_data_copy(struct spdk_nvmf_ctrlr_migr_data *data,
    1962                 :            :                           const struct spdk_nvmf_ctrlr_migr_data *data_src, size_t data_size)
    1963                 :            : {
    1964   [ #  #  #  # ]:          0 :         assert(data);
    1965   [ #  #  #  # ]:          0 :         assert(data_src);
    1966   [ #  #  #  # ]:          0 :         assert(data_size);
    1967                 :            : 
    1968   [ #  #  #  #  :          0 :         memcpy(&data->regs, &data_src->regs, spdk_min(data->regs_size, data_src->regs_size));
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1969   [ #  #  #  #  :          0 :         memcpy(&data->feat, &data_src->feat, spdk_min(data->feat_size, data_src->feat_size));
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    1970                 :            : 
    1971                 :            : #define SET_FIELD(field) \
    1972                 :            :     if (offsetof(struct spdk_nvmf_ctrlr_migr_data, field) + sizeof(data->field) <= data_size) { \
    1973                 :            :         data->field = data_src->field; \
    1974                 :            :     } \
    1975                 :            : 
    1976   [ #  #  #  #  :          0 :         SET_FIELD(cntlid);
          #  #  #  #  #  
                      # ]
    1977   [ #  #  #  #  :          0 :         SET_FIELD(acre);
          #  #  #  #  #  
                      # ]
    1978   [ #  #  #  #  :          0 :         SET_FIELD(num_aer_cids);
          #  #  #  #  #  
                      # ]
    1979   [ #  #  #  #  :          0 :         SET_FIELD(num_async_events);
          #  #  #  #  #  
                      # ]
    1980   [ #  #  #  #  :          0 :         SET_FIELD(notice_aen_mask);
          #  #  #  #  #  
                      # ]
    1981                 :            : #undef SET_FIELD
    1982                 :            : 
    1983                 :            : #define SET_ARRAY(arr) \
    1984                 :            :     if (offsetof(struct spdk_nvmf_ctrlr_migr_data, arr) + sizeof(data->arr) <= data_size) { \
    1985                 :            :         memcpy(&data->arr, &data_src->arr, sizeof(data->arr)); \
    1986                 :            :     } \
    1987                 :            : 
    1988   [ #  #  #  #  :          0 :         SET_ARRAY(async_events);
          #  #  #  #  #  
                      # ]
    1989   [ #  #  #  #  :          0 :         SET_ARRAY(aer_cids);
          #  #  #  #  #  
                      # ]
    1990                 :            : #undef SET_ARRAY
    1991                 :          0 : }
    1992                 :            : 
    1993                 :            : int
    1994                 :          0 : spdk_nvmf_ctrlr_save_migr_data(struct spdk_nvmf_ctrlr *ctrlr,
    1995                 :            :                                struct spdk_nvmf_ctrlr_migr_data *data)
    1996                 :            : {
    1997                 :          0 :         struct spdk_nvmf_async_event_completion *event, *event_tmp;
    1998                 :          0 :         uint32_t i;
    1999                 :          0 :         struct spdk_nvmf_ctrlr_migr_data data_local = {
    2000                 :            :                 .data_size = offsetof(struct spdk_nvmf_ctrlr_migr_data, unused),
    2001                 :            :                 .regs_size = sizeof(struct spdk_nvmf_registers),
    2002                 :            :                 .feat_size = sizeof(struct spdk_nvmf_ctrlr_feat)
    2003                 :            :         };
    2004                 :            : 
    2005   [ #  #  #  #  :          0 :         assert(data->data_size <= sizeof(data_local));
             #  #  #  # ]
    2006   [ #  #  #  #  :          0 :         assert(spdk_get_thread() == ctrlr->thread);
             #  #  #  # ]
    2007                 :            : 
    2008   [ #  #  #  #  :          0 :         memcpy(&data_local.regs, &ctrlr->vcprop, sizeof(struct spdk_nvmf_registers));
                   #  # ]
    2009   [ #  #  #  #  :          0 :         memcpy(&data_local.feat, &ctrlr->feat, sizeof(struct spdk_nvmf_ctrlr_feat));
                   #  # ]
    2010                 :            : 
    2011   [ #  #  #  #  :          0 :         data_local.cntlid = ctrlr->cntlid;
                   #  # ]
    2012   [ #  #  #  #  :          0 :         data_local.acre = ctrlr->acre_enabled;
             #  #  #  # ]
    2013   [ #  #  #  # ]:          0 :         data_local.num_aer_cids = ctrlr->nr_aer_reqs;
    2014                 :            : 
    2015   [ #  #  #  #  :          0 :         STAILQ_FOREACH_SAFE(event, &ctrlr->async_events, link, event_tmp) {
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    2016   [ #  #  #  # ]:          0 :                 if (data_local.num_async_events + 1 > SPDK_NVMF_MIGR_MAX_PENDING_AERS) {
    2017                 :          0 :                         SPDK_ERRLOG("ctrlr %p has too many pending AERs\n", ctrlr);
    2018                 :          0 :                         break;
    2019                 :            :                 }
    2020                 :            : 
    2021   [ #  #  #  #  :          0 :                 data_local.async_events[data_local.num_async_events++].raw = event->event.raw;
          #  #  #  #  #  
             #  #  #  #  
                      # ]
    2022                 :          0 :         }
    2023                 :            : 
    2024   [ #  #  #  #  :          0 :         for (i = 0; i < ctrlr->nr_aer_reqs; i++) {
                   #  # ]
    2025   [ #  #  #  #  :          0 :                 struct spdk_nvmf_request *req = ctrlr->aer_req[i];
             #  #  #  # ]
    2026   [ #  #  #  #  :          0 :                 data_local.aer_cids[i] = req->cmd->nvme_cmd.cid;
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    2027                 :          0 :         }
    2028   [ #  #  #  #  :          0 :         data_local.notice_aen_mask = ctrlr->notice_aen_mask;
                   #  # ]
    2029                 :            : 
    2030   [ #  #  #  #  :          0 :         nvmf_ctrlr_migr_data_copy(data, &data_local, spdk_min(data->data_size, data_local.data_size));
          #  #  #  #  #  
                      # ]
    2031                 :          0 :         return 0;
    2032                 :          0 : }
    2033                 :            : 
    2034                 :            : int
    2035                 :          0 : spdk_nvmf_ctrlr_restore_migr_data(struct spdk_nvmf_ctrlr *ctrlr,
    2036                 :            :                                   const struct spdk_nvmf_ctrlr_migr_data *data)
    2037                 :            : {
    2038                 :          0 :         uint32_t i;
    2039                 :          0 :         struct spdk_nvmf_ctrlr_migr_data data_local = {
    2040                 :            :                 .data_size = offsetof(struct spdk_nvmf_ctrlr_migr_data, unused),
    2041                 :            :                 .regs_size = sizeof(struct spdk_nvmf_registers),
    2042                 :            :                 .feat_size = sizeof(struct spdk_nvmf_ctrlr_feat)
    2043                 :            :         };
    2044                 :            : 
    2045   [ #  #  #  #  :          0 :         assert(data->data_size <= sizeof(data_local));
             #  #  #  # ]
    2046   [ #  #  #  #  :          0 :         assert(spdk_get_thread() == ctrlr->thread);
             #  #  #  # ]
    2047                 :            : 
    2048                 :            :         /* local version of data should have defaults set before copy */
    2049   [ #  #  #  #  :          0 :         nvmf_ctrlr_migr_data_copy(&data_local, data, spdk_min(data->data_size, data_local.data_size));
          #  #  #  #  #  
                      # ]
    2050   [ #  #  #  #  :          0 :         memcpy(&ctrlr->vcprop, &data_local.regs, sizeof(struct spdk_nvmf_registers));
                   #  # ]
    2051   [ #  #  #  #  :          0 :         memcpy(&ctrlr->feat, &data_local.feat, sizeof(struct spdk_nvmf_ctrlr_feat));
                   #  # ]
    2052                 :            : 
    2053   [ #  #  #  #  :          0 :         ctrlr->cntlid = data_local.cntlid;
                   #  # ]
    2054   [ #  #  #  #  :          0 :         ctrlr->acre_enabled = data_local.acre;
                   #  # ]
    2055                 :            : 
    2056   [ #  #  #  # ]:          0 :         for (i = 0; i < data_local.num_async_events; i++) {
    2057                 :          0 :                 struct spdk_nvmf_async_event_completion *event;
    2058                 :            : 
    2059                 :          0 :                 event = calloc(1, sizeof(*event));
    2060         [ #  # ]:          0 :                 if (!event) {
    2061                 :          0 :                         return -ENOMEM;
    2062                 :            :                 }
    2063                 :            : 
    2064   [ #  #  #  #  :          0 :                 event->event.raw = data_local.async_events[i].raw;
          #  #  #  #  #  
             #  #  #  #  
                      # ]
    2065   [ #  #  #  #  :          0 :                 STAILQ_INSERT_TAIL(&ctrlr->async_events, event, link);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  #  
                      # ]
    2066         [ #  # ]:          0 :         }
    2067   [ #  #  #  #  :          0 :         ctrlr->notice_aen_mask = data_local.notice_aen_mask;
                   #  # ]
    2068                 :            : 
    2069                 :          0 :         return 0;
    2070                 :          0 : }
    2071                 :            : 
    2072                 :            : static int
    2073                 :       2335 : nvmf_ctrlr_set_features_async_event_configuration(struct spdk_nvmf_request *req)
    2074                 :            : {
    2075   [ +  -  +  -  :       2335 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    2076   [ +  -  +  -  :       2335 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    2077                 :            : 
    2078   [ +  +  +  +  :       2335 :         SPDK_DEBUGLOG(nvmf, "Set Features - Async Event Configuration, cdw11 0x%08x\n",
          +  -  #  #  #  
                #  #  # ]
    2079                 :            :                       cmd->cdw11);
    2080   [ +  -  +  -  :       2335 :         ctrlr->feat.async_event_configuration.raw = cmd->cdw11;
          +  -  +  -  +  
             -  +  -  +  
                      - ]
    2081   [ +  -  +  -  :       2335 :         ctrlr->feat.async_event_configuration.bits.reserved1 = 0;
             +  -  +  - ]
    2082   [ +  -  +  -  :       2335 :         ctrlr->feat.async_event_configuration.bits.reserved2 = 0;
             +  -  +  - ]
    2083                 :       2335 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2084                 :          0 : }
    2085                 :            : 
    2086                 :            : static int
    2087                 :       8568 : nvmf_ctrlr_async_event_request(struct spdk_nvmf_request *req)
    2088                 :            : {
    2089   [ +  -  +  -  :       8568 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    2090   [ +  -  +  -  :       8568 :         struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
                   +  - ]
    2091                 :         10 :         struct spdk_nvmf_async_event_completion *pending_event;
    2092                 :            : 
    2093   [ +  +  +  +  :       8568 :         SPDK_DEBUGLOG(nvmf, "Async Event Request\n");
                   +  - ]
    2094                 :            : 
    2095                 :            :         /* Four asynchronous events are supported for now */
    2096   [ +  +  +  -  :       8568 :         if (ctrlr->nr_aer_reqs >= SPDK_NVMF_MAX_ASYNC_EVENTS) {
                   +  + ]
    2097   [ +  +  +  +  :          6 :                 SPDK_DEBUGLOG(nvmf, "AERL exceeded\n");
                   +  - ]
    2098   [ +  -  +  -  :          6 :                 rsp->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
                   +  - ]
    2099   [ +  -  +  -  :          6 :                 rsp->status.sc = SPDK_NVME_SC_ASYNC_EVENT_REQUEST_LIMIT_EXCEEDED;
                   +  - ]
    2100                 :          6 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2101                 :            :         }
    2102                 :            : 
    2103   [ +  +  +  -  :       8562 :         if (!STAILQ_EMPTY(&ctrlr->async_events)) {
             +  -  +  + ]
    2104   [ +  -  +  -  :         81 :                 pending_event = STAILQ_FIRST(&ctrlr->async_events);
                   +  - ]
    2105   [ +  -  +  -  :         81 :                 rsp->cdw0 = pending_event->event.raw;
          +  -  +  -  +  
                      - ]
    2106   [ +  -  +  +  :         81 :                 STAILQ_REMOVE(&ctrlr->async_events, pending_event, spdk_nvmf_async_event_completion, link);
          +  -  -  +  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  +  -  
          +  -  +  -  +  
          -  +  -  +  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
    2107                 :         81 :                 free(pending_event);
    2108                 :         81 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2109                 :            :         }
    2110                 :            : 
    2111   [ +  -  +  -  :       8481 :         ctrlr->aer_req[ctrlr->nr_aer_reqs++] = req;
          +  -  +  -  +  
                      - ]
    2112                 :       8481 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS;
    2113                 :       3730 : }
    2114                 :            : 
    2115                 :            : static void
    2116                 :         13 : nvmf_get_firmware_slot_log_page(struct iovec *iovs, int iovcnt, uint64_t offset, uint32_t length)
    2117                 :            : {
    2118                 :          0 :         struct spdk_nvme_firmware_page fw_page;
    2119                 :          0 :         size_t copy_len;
    2120                 :          0 :         struct spdk_iov_xfer ix;
    2121                 :            : 
    2122                 :         13 :         spdk_iov_xfer_init(&ix, iovs, iovcnt);
    2123                 :            : 
    2124         [ -  + ]:         13 :         memset(&fw_page, 0, sizeof(fw_page));
    2125                 :         13 :         fw_page.afi.active_slot = 1;
    2126                 :         13 :         fw_page.afi.next_reset_slot = 0;
    2127   [ #  #  #  # ]:         13 :         spdk_strcpy_pad(fw_page.revision[0], FW_VERSION, sizeof(fw_page.revision[0]), ' ');
    2128                 :            : 
    2129         [ +  - ]:         13 :         if (offset < sizeof(fw_page)) {
    2130         [ #  # ]:         13 :                 copy_len = spdk_min(sizeof(fw_page) - offset, length);
    2131         [ +  - ]:         13 :                 if (copy_len > 0) {
    2132         [ #  # ]:         13 :                         spdk_iov_xfer_from_buf(&ix, (const char *)&fw_page + offset, copy_len);
    2133                 :          0 :                 }
    2134                 :          0 :         }
    2135                 :         13 : }
    2136                 :            : 
    2137                 :            : /*
    2138                 :            :  * Asynchronous Event Mask Bit
    2139                 :            :  */
    2140                 :            : enum spdk_nvme_async_event_mask_bit {
    2141                 :            :         /* Mask Namespace Change Notification */
    2142                 :            :         SPDK_NVME_ASYNC_EVENT_NS_ATTR_CHANGE_MASK_BIT           = 0,
    2143                 :            :         /* Mask Asymmetric Namespace Access Change Notification */
    2144                 :            :         SPDK_NVME_ASYNC_EVENT_ANA_CHANGE_MASK_BIT               = 1,
    2145                 :            :         /* Mask Discovery Log Change Notification */
    2146                 :            :         SPDK_NVME_ASYNC_EVENT_DISCOVERY_LOG_CHANGE_MASK_BIT     = 2,
    2147                 :            :         /* Mask Reservation Log Page Available Notification */
    2148                 :            :         SPDK_NVME_ASYNC_EVENT_RESERVATION_LOG_AVAIL_MASK_BIT    = 3,
    2149                 :            :         /* Mask Error Event */
    2150                 :            :         SPDK_NVME_ASYNC_EVENT_ERROR_MASK_BIT                    = 4,
    2151                 :            :         /* 4 - 63 Reserved */
    2152                 :            : };
    2153                 :            : 
    2154                 :            : static inline void
    2155                 :        590 : nvmf_ctrlr_unmask_aen(struct spdk_nvmf_ctrlr *ctrlr,
    2156                 :            :                       enum spdk_nvme_async_event_mask_bit mask)
    2157                 :            : {
    2158   [ -  +  +  -  :        590 :         ctrlr->notice_aen_mask &= ~(1 << mask);
             +  -  +  - ]
    2159                 :        590 : }
    2160                 :            : 
    2161                 :            : static inline bool
    2162                 :       3772 : nvmf_ctrlr_mask_aen(struct spdk_nvmf_ctrlr *ctrlr,
    2163                 :            :                     enum spdk_nvme_async_event_mask_bit mask)
    2164                 :            : {
    2165   [ +  +  +  +  :       3772 :         if (ctrlr->notice_aen_mask & (1 << mask)) {
          -  +  +  -  +  
                      + ]
    2166                 :       3201 :                 return false;
    2167                 :            :         } else {
    2168   [ -  +  +  -  :        571 :                 ctrlr->notice_aen_mask |= (1 << mask);
             +  -  +  - ]
    2169                 :        571 :                 return true;
    2170                 :            :         }
    2171                 :         11 : }
    2172                 :            : 
    2173                 :            : /* we have to use the typedef in the function declaration to appease astyle. */
    2174                 :            : typedef enum spdk_nvme_ana_state spdk_nvme_ana_state_t;
    2175                 :            : 
    2176                 :            : static inline spdk_nvme_ana_state_t
    2177                 :   23860347 : nvmf_ctrlr_get_ana_state(struct spdk_nvmf_ctrlr *ctrlr, uint32_t anagrpid)
    2178                 :            : {
    2179   [ +  +  +  -  :   23860347 :         if (!ctrlr->subsys->flags.ana_reporting) {
          +  -  +  -  -  
                      + ]
    2180                 :   21081619 :                 return SPDK_NVME_ANA_OPTIMIZED_STATE;
    2181                 :            :         }
    2182                 :            : 
    2183   [ +  +  #  #  :    2778728 :         if (spdk_unlikely(ctrlr->listener == NULL)) {
                   #  # ]
    2184                 :         46 :                 return SPDK_NVME_ANA_INACCESSIBLE_STATE;
    2185                 :            :         }
    2186                 :            : 
    2187   [ -  +  #  #  :    2778682 :         assert(anagrpid - 1 < ctrlr->subsys->max_nsid);
          #  #  #  #  #  
                #  #  # ]
    2188   [ #  #  #  #  :    2778682 :         return ctrlr->listener->ana_state[anagrpid - 1];
          #  #  #  #  #  
                #  #  # ]
    2189                 :     143046 : }
    2190                 :            : 
    2191                 :            : static spdk_nvme_ana_state_t
    2192                 :      38224 : nvmf_ctrlr_get_ana_state_from_nsid(struct spdk_nvmf_ctrlr *ctrlr, uint32_t nsid)
    2193                 :            : {
    2194                 :          8 :         struct spdk_nvmf_ns *ns;
    2195                 :            : 
    2196                 :            :         /* We do not have NVM subsystem specific ANA state. Hence if NSID is either
    2197                 :            :          * SPDK_NVMF_GLOBAL_NS_TAG, invalid, or for inactive namespace, return
    2198                 :            :          * the optimized state.
    2199                 :            :          */
    2200   [ +  -  +  - ]:      38224 :         ns = _nvmf_subsystem_get_ns(ctrlr->subsys, nsid);
    2201         [ +  + ]:      38224 :         if (ns == NULL) {
    2202                 :      36186 :                 return SPDK_NVME_ANA_OPTIMIZED_STATE;
    2203                 :            :         }
    2204                 :            : 
    2205   [ +  -  +  - ]:       2038 :         return nvmf_ctrlr_get_ana_state(ctrlr, ns->anagrpid);
    2206                 :       2913 : }
    2207                 :            : 
    2208                 :            : static void
    2209                 :         17 : nvmf_get_error_log_page(struct spdk_nvmf_ctrlr *ctrlr, struct iovec *iovs, int iovcnt,
    2210                 :            :                         uint64_t offset, uint32_t length, uint32_t rae)
    2211                 :            : {
    2212         [ +  - ]:         17 :         if (!rae) {
    2213                 :         17 :                 nvmf_ctrlr_unmask_aen(ctrlr, SPDK_NVME_ASYNC_EVENT_ERROR_MASK_BIT);
    2214                 :          1 :         }
    2215                 :            : 
    2216                 :            :         /* TODO: actually fill out log page data */
    2217                 :         17 : }
    2218                 :            : 
    2219                 :            : static void
    2220                 :        157 : nvmf_get_ana_log_page(struct spdk_nvmf_ctrlr *ctrlr, struct iovec *iovs, int iovcnt,
    2221                 :            :                       uint64_t offset, uint32_t length, uint32_t rae)
    2222                 :            : {
    2223                 :         85 :         struct spdk_nvme_ana_page ana_hdr;
    2224                 :         85 :         struct spdk_nvme_ana_group_descriptor ana_desc;
    2225                 :         17 :         size_t copy_len, copied_len;
    2226                 :        157 :         uint32_t num_anagrp = 0, anagrpid;
    2227                 :         17 :         struct spdk_nvmf_ns *ns;
    2228                 :         85 :         struct spdk_iov_xfer ix;
    2229                 :            : 
    2230                 :        157 :         spdk_iov_xfer_init(&ix, iovs, iovcnt);
    2231                 :            : 
    2232         [ +  + ]:        157 :         if (length == 0) {
    2233                 :          0 :                 goto done;
    2234                 :            :         }
    2235                 :            : 
    2236         [ +  + ]:        157 :         if (offset >= sizeof(ana_hdr)) {
    2237                 :         78 :                 offset -= sizeof(ana_hdr);
    2238                 :         13 :         } else {
    2239   [ +  +  +  -  :       1215 :                 for (anagrpid = 1; anagrpid <= ctrlr->subsys->max_nsid; anagrpid++) {
          +  -  +  -  +  
                      + ]
    2240   [ +  +  +  -  :       1136 :                         if (ctrlr->subsys->ana_group[anagrpid - 1] > 0) {
          +  -  +  -  +  
             -  +  -  +  
                      + ]
    2241                 :        115 :                                 num_anagrp++;
    2242                 :         10 :                         }
    2243                 :         16 :                 }
    2244                 :            : 
    2245         [ +  + ]:         79 :                 memset(&ana_hdr, 0, sizeof(ana_hdr));
    2246                 :            : 
    2247         [ +  - ]:         79 :                 ana_hdr.num_ana_group_desc = num_anagrp;
    2248                 :            :                 /* TODO: Support Change Count. */
    2249                 :         79 :                 ana_hdr.change_count = 0;
    2250                 :            : 
    2251         [ +  + ]:         79 :                 copy_len = spdk_min(sizeof(ana_hdr) - offset, length);
    2252         [ +  - ]:         79 :                 copied_len = spdk_iov_xfer_from_buf(&ix, (const char *)&ana_hdr + offset, copy_len);
    2253   [ +  +  #  # ]:         79 :                 assert(copied_len == copy_len);
    2254                 :         79 :                 length -= copied_len;
    2255                 :         79 :                 offset = 0;
    2256                 :            :         }
    2257                 :            : 
    2258         [ +  + ]:        157 :         if (length == 0) {
    2259                 :         12 :                 goto done;
    2260                 :            :         }
    2261                 :            : 
    2262   [ +  +  +  -  :       1317 :         for (anagrpid = 1; anagrpid <= ctrlr->subsys->max_nsid; anagrpid++) {
          +  -  +  -  +  
                      - ]
    2263   [ +  +  +  -  :       1262 :                 if (ctrlr->subsys->ana_group[anagrpid - 1] == 0) {
          +  -  +  -  +  
             -  +  -  +  
                      + ]
    2264                 :       1027 :                         continue;
    2265                 :            :                 }
    2266                 :            : 
    2267         [ +  + ]:        235 :                 if (offset >= sizeof(ana_desc)) {
    2268                 :         72 :                         offset -= sizeof(ana_desc);
    2269                 :         12 :                 } else {
    2270         [ +  + ]:        163 :                         memset(&ana_desc, 0, sizeof(ana_desc));
    2271                 :            : 
    2272                 :        163 :                         ana_desc.ana_group_id = anagrpid;
    2273   [ +  -  +  -  :        163 :                         ana_desc.num_of_nsid = ctrlr->subsys->ana_group[anagrpid - 1];
          +  -  +  -  +  
             -  +  -  +  
                      - ]
    2274                 :        163 :                         ana_desc.ana_state = nvmf_ctrlr_get_ana_state(ctrlr, anagrpid);
    2275                 :            : 
    2276         [ +  + ]:        163 :                         copy_len = spdk_min(sizeof(ana_desc) - offset, length);
    2277         [ +  - ]:        163 :                         copied_len = spdk_iov_xfer_from_buf(&ix, (const char *)&ana_desc + offset,
    2278                 :         18 :                                                             copy_len);
    2279   [ -  +  #  # ]:        163 :                         assert(copied_len == copy_len);
    2280                 :        163 :                         length -= copied_len;
    2281                 :        163 :                         offset = 0;
    2282                 :            : 
    2283         [ +  + ]:        163 :                         if (length == 0) {
    2284                 :         60 :                                 goto done;
    2285                 :            :                         }
    2286                 :            :                 }
    2287                 :            : 
    2288                 :            :                 /* TODO: Revisit here about O(n^2) cost if we have subsystem with
    2289                 :            :                  * many namespaces in the future.
    2290                 :            :                  */
    2291   [ +  +  +  -  :        626 :                 for (ns = spdk_nvmf_subsystem_get_first_ns(ctrlr->subsys); ns != NULL;
                   +  + ]
    2292   [ -  +  -  + ]:        451 :                      ns = spdk_nvmf_subsystem_get_next_ns(ctrlr->subsys, ns)) {
    2293   [ +  +  +  -  :        481 :                         if (ns->anagrpid != anagrpid) {
                   +  + ]
    2294                 :        234 :                                 continue;
    2295                 :            :                         }
    2296                 :            : 
    2297         [ +  + ]:        247 :                         if (offset >= sizeof(uint32_t)) {
    2298                 :         96 :                                 offset -= sizeof(uint32_t);
    2299                 :         96 :                                 continue;
    2300                 :            :                         }
    2301                 :            : 
    2302         [ +  + ]:        151 :                         copy_len = spdk_min(sizeof(uint32_t) - offset, length);
    2303   [ +  -  +  - ]:        151 :                         copied_len = spdk_iov_xfer_from_buf(&ix, (const char *)&ns->nsid + offset,
    2304                 :         16 :                                                             copy_len);
    2305   [ -  +  #  # ]:        151 :                         assert(copied_len == copy_len);
    2306                 :        151 :                         length -= copied_len;
    2307                 :        151 :                         offset = 0;
    2308                 :            : 
    2309         [ +  + ]:        151 :                         if (length == 0) {
    2310                 :         30 :                                 goto done;
    2311                 :            :                         }
    2312                 :         11 :                 }
    2313                 :         15 :         }
    2314                 :            : 
    2315                 :        123 : done:
    2316         [ +  - ]:        157 :         if (!rae) {
    2317                 :        157 :                 nvmf_ctrlr_unmask_aen(ctrlr, SPDK_NVME_ASYNC_EVENT_ANA_CHANGE_MASK_BIT);
    2318                 :         17 :         }
    2319                 :        157 : }
    2320                 :            : 
    2321                 :            : void
    2322                 :       3660 : nvmf_ctrlr_ns_changed(struct spdk_nvmf_ctrlr *ctrlr, uint32_t nsid)
    2323                 :            : {
    2324                 :       3660 :         uint16_t max_changes = SPDK_COUNTOF(ctrlr->changed_ns_list.ns_list);
    2325                 :          0 :         uint16_t i;
    2326                 :       3660 :         bool found = false;
    2327                 :            : 
    2328   [ +  +  #  #  :       3746 :         for (i = 0; i < ctrlr->changed_ns_list_count; i++) {
                   #  # ]
    2329   [ +  +  #  #  :       3185 :                 if (ctrlr->changed_ns_list.ns_list[i] == nsid) {
          #  #  #  #  #  
                      # ]
    2330                 :            :                         /* nsid is already in the list */
    2331                 :       3099 :                         found = true;
    2332                 :       3099 :                         break;
    2333                 :            :                 }
    2334                 :          0 :         }
    2335                 :            : 
    2336   [ +  +  #  # ]:       3660 :         if (!found) {
    2337   [ -  +  #  #  :        561 :                 if (ctrlr->changed_ns_list_count == max_changes) {
                   #  # ]
    2338                 :            :                         /* Out of space - set first entry to FFFFFFFFh and zero-fill the rest. */
    2339   [ #  #  #  #  :          0 :                         ctrlr->changed_ns_list.ns_list[0] = 0xFFFFFFFFu;
             #  #  #  # ]
    2340         [ #  # ]:          0 :                         for (i = 1; i < max_changes; i++) {
    2341   [ #  #  #  #  :          0 :                                 ctrlr->changed_ns_list.ns_list[i] = 0;
             #  #  #  # ]
    2342                 :          0 :                         }
    2343                 :          0 :                 } else {
    2344   [ #  #  #  #  :        561 :                         ctrlr->changed_ns_list.ns_list[ctrlr->changed_ns_list_count++] = nsid;
          #  #  #  #  #  
                      # ]
    2345                 :            :                 }
    2346                 :          0 :         }
    2347                 :       3660 : }
    2348                 :            : 
    2349                 :            : static void
    2350                 :        137 : nvmf_get_changed_ns_list_log_page(struct spdk_nvmf_ctrlr *ctrlr,
    2351                 :            :                                   struct iovec *iovs, int iovcnt, uint64_t offset, uint32_t length, uint32_t rae)
    2352                 :            : {
    2353                 :          2 :         size_t copy_length;
    2354                 :         21 :         struct spdk_iov_xfer ix;
    2355                 :            : 
    2356                 :        137 :         spdk_iov_xfer_init(&ix, iovs, iovcnt);
    2357                 :            : 
    2358         [ +  + ]:        137 :         if (offset < sizeof(ctrlr->changed_ns_list)) {
    2359         [ -  + ]:        137 :                 copy_length = spdk_min(length, sizeof(ctrlr->changed_ns_list) - offset);
    2360         [ +  - ]:        137 :                 if (copy_length) {
    2361   [ +  -  +  - ]:        137 :                         spdk_iov_xfer_from_buf(&ix, (char *)&ctrlr->changed_ns_list + offset, copy_length);
    2362                 :          2 :                 }
    2363                 :          2 :         }
    2364                 :            : 
    2365                 :            :         /* Clear log page each time it is read */
    2366   [ +  -  +  - ]:        137 :         ctrlr->changed_ns_list_count = 0;
    2367   [ +  +  +  - ]:        137 :         memset(&ctrlr->changed_ns_list, 0, sizeof(ctrlr->changed_ns_list));
    2368                 :            : 
    2369         [ +  + ]:        137 :         if (!rae) {
    2370                 :        131 :                 nvmf_ctrlr_unmask_aen(ctrlr, SPDK_NVME_ASYNC_EVENT_NS_ATTR_CHANGE_MASK_BIT);
    2371                 :          1 :         }
    2372                 :        137 : }
    2373                 :            : 
    2374                 :            : /* The structure can be modified if we provide support for other commands in future */
    2375                 :            : static const struct spdk_nvme_cmds_and_effect_log_page g_cmds_and_effect_log_page = {
    2376                 :            :         .admin_cmds_supported = {
    2377                 :            :                 /* CSUPP, LBCC, NCC, NIC, CCC, CSE */
    2378                 :            :                 /* Get Log Page */
    2379                 :            :                 [SPDK_NVME_OPC_GET_LOG_PAGE]            = {1, 0, 0, 0, 0, 0, 0, 0},
    2380                 :            :                 /* Identify */
    2381                 :            :                 [SPDK_NVME_OPC_IDENTIFY]                = {1, 0, 0, 0, 0, 0, 0, 0},
    2382                 :            :                 /* Abort */
    2383                 :            :                 [SPDK_NVME_OPC_ABORT]                   = {1, 0, 0, 0, 0, 0, 0, 0},
    2384                 :            :                 /* Set Features */
    2385                 :            :                 [SPDK_NVME_OPC_SET_FEATURES]            = {1, 0, 0, 0, 0, 0, 0, 0},
    2386                 :            :                 /* Get Features */
    2387                 :            :                 [SPDK_NVME_OPC_GET_FEATURES]            = {1, 0, 0, 0, 0, 0, 0, 0},
    2388                 :            :                 /* Async Event Request */
    2389                 :            :                 [SPDK_NVME_OPC_ASYNC_EVENT_REQUEST]     = {1, 0, 0, 0, 0, 0, 0, 0},
    2390                 :            :                 /* Keep Alive */
    2391                 :            :                 [SPDK_NVME_OPC_KEEP_ALIVE]              = {1, 0, 0, 0, 0, 0, 0, 0},
    2392                 :            :         },
    2393                 :            :         .io_cmds_supported = {
    2394                 :            :                 /* FLUSH */
    2395                 :            :                 [SPDK_NVME_OPC_FLUSH]                   = {1, 1, 0, 0, 0, 0, 0, 0},
    2396                 :            :                 /* WRITE */
    2397                 :            :                 [SPDK_NVME_OPC_WRITE]                   = {1, 1, 0, 0, 0, 0, 0, 0},
    2398                 :            :                 /* READ */
    2399                 :            :                 [SPDK_NVME_OPC_READ]                    = {1, 0, 0, 0, 0, 0, 0, 0},
    2400                 :            :                 /* WRITE ZEROES */
    2401                 :            :                 [SPDK_NVME_OPC_WRITE_ZEROES]            = {1, 1, 0, 0, 0, 0, 0, 0},
    2402                 :            :                 /* DATASET MANAGEMENT */
    2403                 :            :                 [SPDK_NVME_OPC_DATASET_MANAGEMENT]      = {1, 1, 0, 0, 0, 0, 0, 0},
    2404                 :            :                 /* COMPARE */
    2405                 :            :                 [SPDK_NVME_OPC_COMPARE]                 = {1, 0, 0, 0, 0, 0, 0, 0},
    2406                 :            :                 /* ZONE MANAGEMENT SEND */
    2407                 :            :                 [SPDK_NVME_OPC_ZONE_MGMT_SEND]          = {1, 1, 0, 0, 0, 0, 0, 0},
    2408                 :            :                 /* ZONE MANAGEMENT RECEIVE */
    2409                 :            :                 [SPDK_NVME_OPC_ZONE_MGMT_RECV]          = {1, 0, 0, 0, 0, 0, 0, 0},
    2410                 :            :                 /* COPY */
    2411                 :            :                 [SPDK_NVME_OPC_COPY]                    = {1, 1, 0, 0, 0, 0, 0, 0},
    2412                 :            :         },
    2413                 :            : };
    2414                 :            : 
    2415                 :            : static void
    2416                 :        415 : nvmf_get_cmds_and_effects_log_page(struct spdk_nvmf_ctrlr *ctrlr, struct iovec *iovs, int iovcnt,
    2417                 :            :                                    uint64_t offset, uint32_t length)
    2418                 :            : {
    2419                 :        415 :         uint32_t page_size = sizeof(struct spdk_nvme_cmds_and_effect_log_page);
    2420                 :        415 :         size_t copy_len = 0;
    2421                 :        415 :         struct spdk_nvme_cmds_and_effect_log_page cmds_and_effect_log_page = g_cmds_and_effect_log_page;
    2422                 :        415 :         struct spdk_nvme_cmds_and_effect_entry csupp_and_lbcc_effect_entry = {1, 1, 0, 0, 0, 0, 0, 0};
    2423                 :         12 :         struct spdk_iov_xfer ix;
    2424                 :            : 
    2425                 :        415 :         spdk_iov_xfer_init(&ix, iovs, iovcnt);
    2426                 :            : 
    2427         [ +  - ]:        415 :         if (offset < page_size) {
    2428   [ -  +  -  +  :        415 :                 if (ctrlr->subsys->zone_append_supported) {
          #  #  #  #  #  
                #  #  # ]
    2429   [ #  #  #  # ]:          0 :                         cmds_and_effect_log_page.io_cmds_supported[SPDK_NVME_OPC_ZONE_APPEND] =
    2430                 :          0 :                                 csupp_and_lbcc_effect_entry;
    2431                 :          0 :                 }
    2432         [ #  # ]:        415 :                 copy_len = spdk_min(page_size - offset, length);
    2433         [ #  # ]:        415 :                 spdk_iov_xfer_from_buf(&ix, (char *)(&cmds_and_effect_log_page) + offset, copy_len);
    2434                 :          0 :         }
    2435                 :        415 : }
    2436                 :            : 
    2437                 :            : static void
    2438                 :          6 : nvmf_get_reservation_notification_log_page(struct spdk_nvmf_ctrlr *ctrlr,
    2439                 :            :                 struct iovec *iovs, int iovcnt, uint64_t offset, uint32_t length, uint32_t rae)
    2440                 :            : {
    2441                 :          1 :         uint32_t unit_log_len, avail_log_len, next_pos, copy_len;
    2442                 :          1 :         struct spdk_nvmf_reservation_log *log, *log_tmp;
    2443                 :          5 :         struct spdk_iov_xfer ix;
    2444                 :            : 
    2445                 :          6 :         spdk_iov_xfer_init(&ix, iovs, iovcnt);
    2446                 :            : 
    2447                 :          6 :         unit_log_len = sizeof(struct spdk_nvme_reservation_notification_log);
    2448                 :            :         /* No available log, return zeroed log pages */
    2449   [ +  +  +  -  :          6 :         if (!ctrlr->num_avail_log_pages) {
                   +  - ]
    2450                 :          0 :                 return;
    2451                 :            :         }
    2452                 :            : 
    2453   [ +  -  +  - ]:          6 :         avail_log_len = ctrlr->num_avail_log_pages * unit_log_len;
    2454         [ -  + ]:          6 :         if (offset >= avail_log_len) {
    2455                 :          0 :                 return;
    2456                 :            :         }
    2457                 :            : 
    2458                 :          6 :         next_pos = 0;
    2459   [ +  +  -  +  :         18 :         TAILQ_FOREACH_SAFE(log, &ctrlr->log_head, link, log_tmp) {
          -  +  -  +  +  
          -  +  -  +  -  
                   -  + ]
    2460   [ +  +  +  -  :         18 :                 TAILQ_REMOVE(&ctrlr->log_head, log, link);
          +  -  +  +  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]
    2461         [ +  - ]:         18 :                 ctrlr->num_avail_log_pages--;
    2462                 :            : 
    2463                 :         18 :                 next_pos += unit_log_len;
    2464         [ +  + ]:         18 :                 if (next_pos > offset) {
    2465         [ +  + ]:         18 :                         copy_len = spdk_min(next_pos - offset, length);
    2466         [ +  - ]:         18 :                         spdk_iov_xfer_from_buf(&ix, &log->log, copy_len);
    2467                 :         18 :                         length -= copy_len;
    2468                 :         18 :                         offset += copy_len;
    2469                 :          3 :                 }
    2470                 :         18 :                 free(log);
    2471                 :            : 
    2472         [ +  + ]:         18 :                 if (length == 0) {
    2473                 :          6 :                         break;
    2474                 :            :                 }
    2475                 :          2 :         }
    2476                 :            : 
    2477         [ +  + ]:          6 :         if (!rae) {
    2478                 :          6 :                 nvmf_ctrlr_unmask_aen(ctrlr, SPDK_NVME_ASYNC_EVENT_RESERVATION_LOG_AVAIL_MASK_BIT);
    2479                 :          1 :         }
    2480                 :          6 :         return;
    2481                 :          1 : }
    2482                 :            : 
    2483                 :            : static int
    2484                 :       3397 : nvmf_ctrlr_get_log_page(struct spdk_nvmf_request *req)
    2485                 :            : {
    2486   [ +  -  +  -  :       3397 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    2487   [ +  -  +  - ]:       3397 :         struct spdk_nvmf_subsystem *subsystem = ctrlr->subsys;
    2488   [ +  -  +  -  :       3397 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    2489   [ +  -  +  -  :       3397 :         struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
                   +  - ]
    2490                 :        116 :         struct spdk_nvme_transport_id cmd_source_trid;
    2491                 :          6 :         uint64_t offset, len;
    2492                 :          6 :         uint32_t rae, numdl, numdu;
    2493                 :          6 :         uint8_t lid;
    2494                 :            : 
    2495   [ +  +  +  -  :       3397 :         if (req->iovcnt < 1) {
                   +  + ]
    2496   [ +  +  +  +  :        717 :                 SPDK_DEBUGLOG(nvmf, "get log command with no buffer\n");
                   +  - ]
    2497   [ +  -  +  -  :        717 :                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    2498   [ +  -  +  -  :        717 :                 response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   +  - ]
    2499                 :        717 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2500                 :            :         }
    2501                 :            : 
    2502   [ +  -  +  -  :       2680 :         offset = (uint64_t)cmd->cdw12 | ((uint64_t)cmd->cdw13 << 32);
          +  -  +  -  +  
                -  +  - ]
    2503         [ +  + ]:       2680 :         if (offset & 3) {
    2504                 :         21 :                 SPDK_ERRLOG("Invalid log page offset 0x%" PRIx64 "\n", offset);
    2505   [ +  -  +  -  :         21 :                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    2506   [ +  -  +  -  :         21 :                 response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   +  - ]
    2507                 :         21 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2508                 :            :         }
    2509                 :            : 
    2510   [ +  -  +  -  :       2659 :         rae = cmd->cdw10_bits.get_log_page.rae;
             +  -  +  - ]
    2511   [ +  -  +  -  :       2659 :         numdl = cmd->cdw10_bits.get_log_page.numdl;
             +  -  +  - ]
    2512   [ +  -  +  -  :       2659 :         numdu = cmd->cdw11_bits.get_log_page.numdu;
             +  -  +  - ]
    2513         [ +  - ]:       2659 :         len = ((numdu << 16) + numdl + (uint64_t)1) * 4;
    2514   [ +  +  +  -  :       2659 :         if (len > req->length) {
                   +  + ]
    2515   [ +  -  +  - ]:         35 :                 SPDK_ERRLOG("Get log page: len (%" PRIu64 ") > buf size (%u)\n",
    2516                 :            :                             len, req->length);
    2517   [ +  -  +  -  :         35 :                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    2518   [ +  -  +  -  :         35 :                 response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   +  - ]
    2519                 :         35 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2520                 :            :         }
    2521                 :            : 
    2522   [ +  -  +  -  :       2624 :         lid = cmd->cdw10_bits.get_log_page.lid;
             +  -  +  - ]
    2523   [ +  +  +  +  :       2624 :         SPDK_DEBUGLOG(nvmf, "Get log page: LID=0x%02X offset=0x%" PRIx64 " len=0x%" PRIx64 " rae=%u\n",
                   +  - ]
    2524                 :            :                       lid, offset, len, rae);
    2525                 :            : 
    2526         [ +  + ]:       2624 :         if (spdk_nvmf_subsystem_is_discovery(subsystem)) {
    2527         [ +  - ]:        346 :                 switch (lid) {
    2528                 :        346 :                 case SPDK_NVME_LOG_DISCOVERY:
    2529   [ -  +  #  #  :        346 :                         if (spdk_nvmf_qpair_get_listen_trid(req->qpair, &cmd_source_trid)) {
                   #  # ]
    2530                 :          0 :                                 SPDK_ERRLOG("Failed to get LOG_DISCOVERY source trid\n");
    2531   [ #  #  #  #  :          0 :                                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    2532   [ #  #  #  #  :          0 :                                 response->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
                   #  # ]
    2533                 :          0 :                                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2534                 :            :                         }
    2535   [ #  #  #  #  :        346 :                         nvmf_get_discovery_log_page(subsystem->tgt, ctrlr->hostnqn, req->iov, req->iovcnt,
          #  #  #  #  #  
                #  #  # ]
    2536                 :          0 :                                                     offset, len, &cmd_source_trid);
    2537         [ +  + ]:        346 :                         if (!rae) {
    2538                 :        279 :                                 nvmf_ctrlr_unmask_aen(ctrlr, SPDK_NVME_ASYNC_EVENT_DISCOVERY_LOG_CHANGE_MASK_BIT);
    2539                 :          0 :                         }
    2540                 :        346 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2541                 :          0 :                 default:
    2542                 :          0 :                         goto invalid_log_page;
    2543                 :            :                 }
    2544                 :            :         } else {
    2545         [ +  + ]:       2278 :                 if (offset > len) {
    2546                 :          4 :                         SPDK_ERRLOG("Get log page: offset (%" PRIu64 ") > len (%" PRIu64 ")\n",
    2547                 :            :                                     offset, len);
    2548   [ +  -  +  -  :          4 :                         response->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    2549   [ +  -  +  -  :          4 :                         response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   +  - ]
    2550                 :          4 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2551                 :            :                 }
    2552                 :            : 
    2553   [ +  +  +  +  :       2274 :                 switch (lid) {
             +  +  +  + ]
    2554                 :         16 :                 case SPDK_NVME_LOG_ERROR:
    2555   [ +  -  +  -  :         17 :                         nvmf_get_error_log_page(ctrlr, req->iov, req->iovcnt, offset, len, rae);
                   +  - ]
    2556                 :         17 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2557                 :       1625 :                 case SPDK_NVME_LOG_HEALTH_INFORMATION:
    2558                 :            :                         /* TODO: actually fill out log page data */
    2559                 :       1625 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2560                 :         13 :                 case SPDK_NVME_LOG_FIRMWARE_SLOT:
    2561   [ #  #  #  #  :         13 :                         nvmf_get_firmware_slot_log_page(req->iov, req->iovcnt, offset, len);
                   #  # ]
    2562                 :         13 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2563                 :         55 :                 case SPDK_NVME_LOG_ASYMMETRIC_NAMESPACE_ACCESS:
    2564   [ +  -  #  #  :         55 :                         if (subsystem->flags.ana_reporting) {
                   #  # ]
    2565   [ #  #  #  #  :         55 :                                 nvmf_get_ana_log_page(ctrlr, req->iov, req->iovcnt, offset, len, rae);
                   #  # ]
    2566                 :         55 :                                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2567                 :            :                         } else {
    2568                 :          0 :                                 goto invalid_log_page;
    2569                 :            :                         }
    2570                 :        415 :                 case SPDK_NVME_LOG_COMMAND_EFFECTS_LOG:
    2571   [ #  #  #  #  :        415 :                         nvmf_get_cmds_and_effects_log_page(ctrlr, req->iov, req->iovcnt, offset, len);
                   #  # ]
    2572                 :        415 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2573                 :        135 :                 case SPDK_NVME_LOG_CHANGED_NS_LIST:
    2574   [ +  -  +  -  :        137 :                         nvmf_get_changed_ns_list_log_page(ctrlr, req->iov, req->iovcnt, offset, len, rae);
                   +  - ]
    2575                 :        137 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2576                 :          0 :                 case SPDK_NVME_LOG_RESERVATION_NOTIFICATION:
    2577   [ #  #  #  #  :          0 :                         nvmf_get_reservation_notification_log_page(ctrlr, req->iov, req->iovcnt, offset, len, rae);
                   #  # ]
    2578                 :          0 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2579                 :          5 :                 default:
    2580                 :         12 :                         goto invalid_log_page;
    2581                 :            :                 }
    2582                 :            :         }
    2583                 :            : 
    2584                 :          5 : invalid_log_page:
    2585   [ +  +  +  +  :         12 :         SPDK_INFOLOG(nvmf, "Unsupported Get Log Page 0x%02X\n", lid);
                   +  - ]
    2586   [ +  -  +  -  :         12 :         response->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    2587   [ +  -  +  -  :         12 :         response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   +  - ]
    2588                 :         12 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2589                 :         65 : }
    2590                 :            : 
    2591                 :            : static struct spdk_nvmf_ns *
    2592                 :       3743 : _nvmf_subsystem_get_ns_safe(struct spdk_nvmf_subsystem *subsystem,
    2593                 :            :                             uint32_t nsid,
    2594                 :            :                             struct spdk_nvme_cpl *rsp)
    2595                 :            : {
    2596                 :         10 :         struct spdk_nvmf_ns *ns;
    2597   [ +  +  +  +  :       3743 :         if (nsid == 0 || nsid > subsystem->max_nsid) {
             +  -  +  + ]
    2598                 :         34 :                 SPDK_ERRLOG("Identify Namespace for invalid NSID %u\n", nsid);
    2599   [ +  -  +  -  :         34 :                 rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    2600   [ +  -  +  -  :         34 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
                   +  - ]
    2601                 :         34 :                 return NULL;
    2602                 :            :         }
    2603                 :            : 
    2604                 :       3709 :         ns = _nvmf_subsystem_get_ns(subsystem, nsid);
    2605   [ +  +  +  +  :       3709 :         if (ns == NULL || ns->bdev == NULL) {
             +  -  -  + ]
    2606                 :            :                 /*
    2607                 :            :                  * Inactive namespaces should return a zero filled data structure.
    2608                 :            :                  * The data buffer is already zeroed by nvmf_ctrlr_process_admin_cmd(),
    2609                 :            :                  * so we can just return early here.
    2610                 :            :                  */
    2611   [ -  +  -  +  :        188 :                 SPDK_DEBUGLOG(nvmf, "Identify Namespace for inactive NSID %u\n", nsid);
                   +  - ]
    2612   [ -  +  -  +  :        188 :                 rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   -  + ]
    2613   [ -  +  -  +  :        188 :                 rsp->status.sc = SPDK_NVME_SC_SUCCESS;
                   -  + ]
    2614                 :        188 :                 return NULL;
    2615                 :            :         }
    2616                 :       3521 :         return ns;
    2617                 :        942 : }
    2618                 :            : 
    2619                 :            : int
    2620                 :       3719 : spdk_nvmf_ctrlr_identify_ns(struct spdk_nvmf_ctrlr *ctrlr,
    2621                 :            :                             struct spdk_nvme_cmd *cmd,
    2622                 :            :                             struct spdk_nvme_cpl *rsp,
    2623                 :            :                             struct spdk_nvme_ns_data *nsdata)
    2624                 :            : {
    2625   [ +  -  +  - ]:       3719 :         struct spdk_nvmf_subsystem *subsystem = ctrlr->subsys;
    2626                 :          6 :         struct spdk_nvmf_ns *ns;
    2627                 :          6 :         uint32_t max_num_blocks, format_index;
    2628                 :          6 :         enum spdk_nvme_ana_state ana_state;
    2629                 :            : 
    2630   [ +  -  +  - ]:       3719 :         ns = _nvmf_subsystem_get_ns_safe(subsystem, cmd->nsid, rsp);
    2631         [ +  + ]:       3719 :         if (ns == NULL) {
    2632                 :        210 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2633                 :            :         }
    2634                 :            : 
    2635   [ +  +  +  -  :       3509 :         nvmf_bdev_ctrlr_identify_ns(ns, nsdata, ctrlr->dif_insert_or_strip);
                   +  - ]
    2636                 :            : 
    2637   [ +  +  +  -  :       3509 :         assert(ctrlr->admin_qpair);
             +  -  #  # ]
    2638                 :            : 
    2639                 :       3509 :         format_index = spdk_nvme_ns_get_format_index(nsdata);
    2640                 :            : 
    2641                 :            :         /* Due to bug in the Linux kernel NVMe driver we have to set noiob no larger than mdts */
    2642   [ +  +  +  -  :       4441 :         max_num_blocks = ctrlr->admin_qpair->transport->opts.max_io_size /
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
    2643   [ +  +  +  -  :       3509 :                          (1U << nsdata->lbaf[format_index].lbads);
          +  -  +  -  +  
                      - ]
    2644   [ +  +  +  -  :       3509 :         if (nsdata->noiob > max_num_blocks) {
                   +  - ]
    2645   [ #  #  #  # ]:         43 :                 nsdata->noiob = max_num_blocks;
    2646                 :          0 :         }
    2647                 :            : 
    2648                 :            :         /* Set NOWS equal to Controller MDTS */
    2649   [ +  +  +  -  :       3509 :         if (nsdata->nsfeat.optperf) {
                   +  + ]
    2650   [ +  -  +  - ]:       3497 :                 nsdata->nows = max_num_blocks - 1;
    2651                 :        930 :         }
    2652                 :            : 
    2653   [ +  +  +  -  :       3509 :         if (subsystem->flags.ana_reporting) {
                   +  - ]
    2654   [ -  +  #  #  :         18 :                 assert(ns->anagrpid - 1 < subsystem->max_nsid);
          #  #  #  #  #  
                #  #  # ]
    2655   [ #  #  #  #  :         18 :                 nsdata->anagrpid = ns->anagrpid;
             #  #  #  # ]
    2656                 :            : 
    2657   [ #  #  #  # ]:         18 :                 ana_state = nvmf_ctrlr_get_ana_state(ctrlr, ns->anagrpid);
    2658   [ +  -  -  + ]:         18 :                 if (ana_state == SPDK_NVME_ANA_INACCESSIBLE_STATE ||
    2659                 :          0 :                     ana_state == SPDK_NVME_ANA_PERSISTENT_LOSS_STATE) {
    2660   [ #  #  #  # ]:          0 :                         nsdata->nuse = 0;
    2661                 :          0 :                 }
    2662                 :          0 :         }
    2663                 :            : 
    2664                 :       3509 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2665                 :        938 : }
    2666                 :            : 
    2667                 :            : static void
    2668                 :       2205 : nvmf_ctrlr_populate_oacs(struct spdk_nvmf_ctrlr *ctrlr,
    2669                 :            :                          struct spdk_nvme_ctrlr_data *cdata)
    2670                 :            : {
    2671   [ +  -  +  -  :       2205 :         cdata->oacs = ctrlr->cdata.oacs;
                   +  - ]
    2672                 :            : 
    2673   [ +  -  +  - ]:       2205 :         cdata->oacs.virtualization_management =
    2674   [ +  -  +  -  :       2205 :                 g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_OPC_VIRTUALIZATION_MANAGEMENT].hdlr != NULL;
             +  -  +  - ]
    2675   [ +  -  +  -  :       2208 :         cdata->oacs.nvme_mi = g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_OPC_NVME_MI_SEND].hdlr != NULL
          +  -  +  -  +  
                -  +  - ]
    2676   [ -  +  -  -  :       2205 :                               && g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_OPC_NVME_MI_RECEIVE].hdlr != NULL;
          #  #  #  #  #  
                      # ]
    2677   [ +  -  +  -  :       2208 :         cdata->oacs.directives = g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_OPC_DIRECTIVE_SEND].hdlr != NULL
          +  -  +  -  +  
                -  +  - ]
    2678   [ -  +  -  -  :       2205 :                                  && g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_OPC_DIRECTIVE_RECEIVE].hdlr != NULL;
          #  #  #  #  #  
                      # ]
    2679   [ +  -  +  - ]:       2205 :         cdata->oacs.device_self_test =
    2680   [ +  -  +  -  :       2205 :                 g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_OPC_DEVICE_SELF_TEST].hdlr != NULL;
             +  -  +  - ]
    2681   [ +  -  +  -  :       2208 :         cdata->oacs.ns_manage = g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_OPC_NS_MANAGEMENT].hdlr != NULL
          +  -  +  -  +  
                -  +  - ]
    2682   [ -  +  -  -  :       2205 :                                 && g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_OPC_NS_ATTACHMENT].hdlr != NULL;
          #  #  #  #  #  
                      # ]
    2683   [ +  -  +  -  :       2208 :         cdata->oacs.firmware = g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_OPC_FIRMWARE_IMAGE_DOWNLOAD].hdlr !=
          +  -  +  -  +  
                -  +  - ]
    2684                 :            :                                NULL
    2685   [ -  +  -  -  :       2205 :                                && g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_OPC_FIRMWARE_COMMIT].hdlr != NULL;
          #  #  #  #  #  
                      # ]
    2686   [ +  -  +  - ]:       2205 :         cdata->oacs.format =
    2687   [ +  -  +  -  :       2205 :                 g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_OPC_FORMAT_NVM].hdlr != NULL;
             +  -  +  - ]
    2688   [ +  -  +  -  :       2208 :         cdata->oacs.security = g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_OPC_SECURITY_SEND].hdlr != NULL
          +  -  +  -  +  
                -  +  - ]
    2689   [ -  +  -  -  :       2205 :                                && g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_OPC_SECURITY_RECEIVE].hdlr != NULL;
          #  #  #  #  #  
                      # ]
    2690   [ +  -  +  -  :       2205 :         cdata->oacs.get_lba_status = g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_OPC_GET_LBA_STATUS].hdlr !=
          +  -  +  -  +  
                -  +  - ]
    2691                 :            :                                      NULL;
    2692                 :       2205 : }
    2693                 :            : 
    2694                 :            : int
    2695                 :       2507 : spdk_nvmf_ctrlr_identify_ctrlr(struct spdk_nvmf_ctrlr *ctrlr, struct spdk_nvme_ctrlr_data *cdata)
    2696                 :            : {
    2697   [ +  -  +  - ]:       2507 :         struct spdk_nvmf_subsystem *subsystem = ctrlr->subsys;
    2698                 :          3 :         struct spdk_nvmf_transport *transport;
    2699                 :            : 
    2700                 :            :         /*
    2701                 :            :          * Common fields for discovery and NVM subsystems
    2702                 :            :          */
    2703   [ +  +  +  -  :       2507 :         assert(ctrlr->admin_qpair);
             +  -  #  # ]
    2704   [ +  -  +  -  :       2507 :         transport = ctrlr->admin_qpair->transport;
             +  -  +  - ]
    2705         [ +  - ]:       2507 :         spdk_strcpy_pad(cdata->fr, FW_VERSION, sizeof(cdata->fr), ' ');
    2706   [ +  +  +  -  :       2507 :         assert((transport->opts.max_io_size % 4096) == 0);
          +  -  +  -  +  
                -  #  # ]
    2707   [ +  -  +  -  :       2507 :         cdata->mdts = spdk_u32log2(transport->opts.max_io_size / 4096);
          +  -  +  -  +  
                -  +  - ]
    2708   [ +  -  +  -  :       2507 :         cdata->cntlid = ctrlr->cntlid;
             +  -  +  - ]
    2709   [ +  -  +  -  :       2507 :         cdata->ver = ctrlr->vcprop.vs;
                   +  - ]
    2710   [ +  -  +  -  :       2507 :         cdata->aerl = ctrlr->cdata.aerl;
          +  -  +  -  +  
                      - ]
    2711   [ +  -  +  - ]:       2507 :         cdata->lpa.edlp = 1;
    2712   [ +  -  +  - ]:       2507 :         cdata->elpe = 127;
    2713   [ +  -  +  -  :       2507 :         cdata->maxcmd = transport->opts.max_queue_depth;
          +  -  +  -  +  
                      - ]
    2714   [ +  -  +  -  :       2507 :         cdata->sgls = ctrlr->cdata.sgls;
                   +  - ]
    2715   [ +  -  +  -  :       2507 :         cdata->fuses = ctrlr->cdata.fuses;
                   +  - ]
    2716   [ +  -  +  - ]:       2507 :         cdata->acwu = 0; /* ACWU is 0-based. */
    2717   [ +  +  +  -  :       2507 :         if (subsystem->flags.ana_reporting) {
                   +  - ]
    2718   [ #  #  #  #  :         10 :                 cdata->mnan = subsystem->max_nsid;
             #  #  #  # ]
    2719                 :          0 :         }
    2720   [ +  -  +  - ]:       2507 :         spdk_strcpy_pad(cdata->subnqn, subsystem->subnqn, sizeof(cdata->subnqn), '\0');
    2721                 :            : 
    2722   [ +  +  +  +  :       2507 :         SPDK_DEBUGLOG(nvmf, "ctrlr data: maxcmd 0x%x\n", cdata->maxcmd);
          +  -  #  #  #  
                      # ]
    2723   [ +  +  +  +  :       2507 :         SPDK_DEBUGLOG(nvmf, "sgls data: 0x%x\n", from_le32(&cdata->sgls));
             +  -  #  # ]
    2724                 :            : 
    2725                 :            : 
    2726         [ +  + ]:       2507 :         if (spdk_nvmf_subsystem_is_discovery(subsystem)) {
    2727                 :            :                 /*
    2728                 :            :                  * NVM Discovery subsystem fields
    2729                 :            :                  */
    2730   [ #  #  #  # ]:        302 :                 cdata->oaes.discovery_log_change_notices = 1;
    2731                 :          0 :         } else {
    2732   [ +  -  +  -  :       2205 :                 cdata->vid = ctrlr->cdata.vid;
          +  -  +  -  +  
                      - ]
    2733   [ +  -  +  -  :       2205 :                 cdata->ssvid = ctrlr->cdata.ssvid;
          +  -  +  -  +  
                      - ]
    2734   [ +  -  +  -  :       2205 :                 cdata->ieee[0] = ctrlr->cdata.ieee[0];
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
    2735   [ +  -  +  -  :       2205 :                 cdata->ieee[1] = ctrlr->cdata.ieee[1];
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
    2736   [ +  -  +  -  :       2205 :                 cdata->ieee[2] = ctrlr->cdata.ieee[2];
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  - ]
    2737                 :            : 
    2738                 :            :                 /*
    2739                 :            :                  * NVM subsystem fields (reserved for discovery subsystems)
    2740                 :            :                  */
    2741         [ +  - ]:       2205 :                 spdk_strcpy_pad(cdata->mn, spdk_nvmf_subsystem_get_mn(subsystem), sizeof(cdata->mn), ' ');
    2742         [ +  - ]:       2205 :                 spdk_strcpy_pad(cdata->sn, spdk_nvmf_subsystem_get_sn(subsystem), sizeof(cdata->sn), ' ');
    2743   [ +  -  +  -  :       2205 :                 cdata->kas = ctrlr->cdata.kas;
          +  -  +  -  +  
                      - ]
    2744                 :            : 
    2745   [ +  -  +  - ]:       2205 :                 cdata->rab = 6;
    2746   [ +  -  +  - ]:       2205 :                 cdata->cmic.multi_port = 1;
    2747   [ +  -  +  - ]:       2205 :                 cdata->cmic.multi_ctrlr = 1;
    2748   [ +  -  +  - ]:       2205 :                 cdata->oaes.ns_attribute_notices = 1;
    2749   [ +  -  +  - ]:       2205 :                 cdata->ctratt.host_id_exhid_supported = 1;
    2750                 :            :                 /* We do not have any actual limitation to the number of abort commands.
    2751                 :            :                  * We follow the recommendation by the NVMe specification.
    2752                 :            :                  */
    2753   [ +  -  +  - ]:       2205 :                 cdata->acl = NVMF_ABORT_COMMAND_LIMIT;
    2754   [ +  -  +  - ]:       2205 :                 cdata->frmw.slot1_ro = 1;
    2755   [ +  -  +  - ]:       2205 :                 cdata->frmw.num_slots = 1;
    2756                 :            : 
    2757   [ +  -  +  - ]:       2205 :                 cdata->lpa.celp = 1; /* Command Effects log page supported */
    2758                 :            : 
    2759   [ +  -  +  - ]:       2205 :                 cdata->sqes.min = 6;
    2760   [ +  -  +  - ]:       2205 :                 cdata->sqes.max = 6;
    2761   [ +  -  +  - ]:       2205 :                 cdata->cqes.min = 4;
    2762   [ +  -  +  - ]:       2205 :                 cdata->cqes.max = 4;
    2763   [ +  -  +  -  :       2205 :                 cdata->nn = subsystem->max_nsid;
             +  -  +  - ]
    2764   [ +  -  +  - ]:       2205 :                 cdata->vwc.present = 1;
    2765   [ +  -  +  - ]:       2205 :                 cdata->vwc.flush_broadcast = SPDK_NVME_FLUSH_BROADCAST_NOT_SUPPORTED;
    2766                 :            : 
    2767   [ +  -  +  -  :       2205 :                 cdata->nvmf_specific = ctrlr->cdata.nvmf_specific;
                   +  - ]
    2768                 :            : 
    2769   [ +  -  +  -  :       2205 :                 cdata->oncs.compare = ctrlr->cdata.oncs.compare;
          +  -  +  -  +  
                      - ]
    2770   [ +  -  +  - ]:       2205 :                 cdata->oncs.dsm = nvmf_ctrlr_dsm_supported(ctrlr);
    2771   [ +  -  +  - ]:       2205 :                 cdata->oncs.write_zeroes = nvmf_ctrlr_write_zeroes_supported(ctrlr);
    2772   [ +  -  +  -  :       2205 :                 cdata->oncs.reservations = ctrlr->cdata.oncs.reservations;
          +  -  +  -  +  
                      - ]
    2773   [ +  -  +  -  :       2205 :                 cdata->oncs.copy = ctrlr->cdata.oncs.copy;
          +  -  +  -  +  
                      - ]
    2774   [ +  -  +  -  :       2205 :                 cdata->ocfs.copy_format0 = cdata->oncs.copy;
             +  -  +  - ]
    2775   [ +  +  +  -  :       2205 :                 if (subsystem->flags.ana_reporting) {
                   +  - ]
    2776                 :            :                         /* Asymmetric Namespace Access Reporting is supported. */
    2777   [ #  #  #  # ]:         10 :                         cdata->cmic.ana_reporting = 1;
    2778   [ #  #  #  # ]:         10 :                         cdata->oaes.ana_change_notices = 1;
    2779                 :            : 
    2780   [ #  #  #  # ]:         10 :                         cdata->anatt = ANA_TRANSITION_TIME_IN_SEC;
    2781                 :            :                         /* ANA Change state is not used, and ANA Persistent Loss state
    2782                 :            :                          * is not supported for now.
    2783                 :            :                          */
    2784   [ #  #  #  # ]:         10 :                         cdata->anacap.ana_optimized_state = 1;
    2785   [ #  #  #  # ]:         10 :                         cdata->anacap.ana_non_optimized_state = 1;
    2786   [ #  #  #  # ]:         10 :                         cdata->anacap.ana_inaccessible_state = 1;
    2787                 :            :                         /* ANAGRPID does not change while namespace is attached to controller */
    2788   [ #  #  #  # ]:         10 :                         cdata->anacap.no_change_anagrpid = 1;
    2789   [ #  #  #  #  :         10 :                         cdata->anagrpmax = subsystem->max_nsid;
             #  #  #  # ]
    2790   [ #  #  #  #  :         10 :                         cdata->nanagrpid = subsystem->max_nsid;
             #  #  #  # ]
    2791                 :          0 :                 }
    2792                 :            : 
    2793                 :       2205 :                 nvmf_ctrlr_populate_oacs(ctrlr, cdata);
    2794                 :            : 
    2795   [ +  +  +  -  :       2205 :                 assert(subsystem->tgt != NULL);
             +  -  #  # ]
    2796   [ +  -  +  -  :       2205 :                 cdata->crdt[0] = subsystem->tgt->crdt[0];
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    2797   [ +  -  +  -  :       2205 :                 cdata->crdt[1] = subsystem->tgt->crdt[1];
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    2798   [ +  -  +  -  :       2205 :                 cdata->crdt[2] = subsystem->tgt->crdt[2];
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    2799                 :            : 
    2800   [ +  +  +  +  :       2205 :                 SPDK_DEBUGLOG(nvmf, "ext ctrlr data: ioccsz 0x%x\n",
          +  -  #  #  #  
                #  #  # ]
    2801                 :            :                               cdata->nvmf_specific.ioccsz);
    2802   [ +  +  +  +  :       2205 :                 SPDK_DEBUGLOG(nvmf, "ext ctrlr data: iorcsz 0x%x\n",
          +  -  #  #  #  
                #  #  # ]
    2803                 :            :                               cdata->nvmf_specific.iorcsz);
    2804   [ +  +  +  +  :       2205 :                 SPDK_DEBUGLOG(nvmf, "ext ctrlr data: icdoff 0x%x\n",
          +  -  #  #  #  
                #  #  # ]
    2805                 :            :                               cdata->nvmf_specific.icdoff);
    2806   [ +  +  +  +  :       2205 :                 SPDK_DEBUGLOG(nvmf, "ext ctrlr data: ctrattr 0x%x\n",
          +  -  #  #  #  
                #  #  # ]
    2807                 :            :                               *(uint8_t *)&cdata->nvmf_specific.ctrattr);
    2808   [ +  +  +  +  :       2205 :                 SPDK_DEBUGLOG(nvmf, "ext ctrlr data: msdbd 0x%x\n",
          +  -  #  #  #  
                #  #  # ]
    2809                 :            :                               cdata->nvmf_specific.msdbd);
    2810                 :            :         }
    2811                 :            : 
    2812                 :       2507 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2813                 :          3 : }
    2814                 :            : 
    2815                 :            : static int
    2816                 :          6 : nvmf_ns_identify_iocs_zns(struct spdk_nvmf_ns *ns,
    2817                 :            :                           struct spdk_nvme_cmd *cmd,
    2818                 :            :                           struct spdk_nvme_cpl *rsp,
    2819                 :            :                           struct spdk_nvme_zns_ns_data *nsdata_zns)
    2820                 :            : {
    2821   [ +  -  +  - ]:          6 :         nsdata_zns->zoc.variable_zone_capacity = 0;
    2822   [ +  -  +  - ]:          6 :         nsdata_zns->zoc.zone_active_excursions = 0;
    2823   [ +  -  +  - ]:          6 :         nsdata_zns->ozcs.read_across_zone_boundaries = 1;
    2824                 :            :         /* Underflowing the zero based mar and mor bdev helper results in the correct
    2825                 :            :            value of FFFFFFFFh. */
    2826   [ +  -  +  -  :          6 :         nsdata_zns->mar = spdk_bdev_get_max_active_zones(ns->bdev) - 1;
             +  -  +  - ]
    2827   [ +  -  +  -  :          6 :         nsdata_zns->mor = spdk_bdev_get_max_open_zones(ns->bdev) - 1;
             +  -  +  - ]
    2828   [ +  -  +  - ]:          6 :         nsdata_zns->rrl = 0;
    2829   [ +  -  +  - ]:          6 :         nsdata_zns->frl = 0;
    2830   [ +  -  +  -  :          6 :         nsdata_zns->lbafe[0].zsze = spdk_bdev_get_zone_size(ns->bdev);
          +  -  +  -  +  
             -  +  -  +  
                      - ]
    2831                 :            : 
    2832   [ +  -  +  -  :          6 :         rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    2833   [ +  -  +  -  :          6 :         rsp->status.sc = SPDK_NVME_SC_SUCCESS;
                   +  - ]
    2834                 :          6 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2835                 :            : }
    2836                 :            : 
    2837                 :            : int
    2838                 :         24 : spdk_nvmf_ns_identify_iocs_specific(struct spdk_nvmf_ctrlr *ctrlr,
    2839                 :            :                                     struct spdk_nvme_cmd *cmd,
    2840                 :            :                                     struct spdk_nvme_cpl *rsp,
    2841                 :            :                                     void *nsdata,
    2842                 :            :                                     size_t nsdata_size)
    2843                 :            : {
    2844   [ +  -  +  -  :         24 :         uint8_t csi = cmd->cdw11_bits.identify.csi;
             +  -  +  - ]
    2845   [ +  -  +  - ]:         24 :         struct spdk_nvmf_subsystem *subsystem = ctrlr->subsys;
    2846   [ +  -  +  - ]:         24 :         struct spdk_nvmf_ns *ns = _nvmf_subsystem_get_ns_safe(subsystem, cmd->nsid, rsp);
    2847                 :            : 
    2848         [ +  + ]:         24 :         memset(nsdata, 0, nsdata_size);
    2849                 :            : 
    2850         [ +  + ]:         24 :         if (ns == NULL) {
    2851   [ +  -  +  -  :         12 :                 rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    2852   [ +  -  +  -  :         12 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
                   +  - ]
    2853                 :         12 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2854                 :            :         }
    2855                 :            : 
    2856         [ +  + ]:         12 :         switch (csi) {
    2857                 :          5 :         case SPDK_NVME_CSI_ZNS:
    2858                 :          6 :                 return nvmf_ns_identify_iocs_zns(ns, cmd, rsp, nsdata);
    2859                 :          5 :         default:
    2860                 :          6 :                 break;
    2861                 :            :         }
    2862                 :            : 
    2863   [ -  +  -  +  :          6 :         SPDK_DEBUGLOG(nvmf,
                   +  - ]
    2864                 :            :                       "Returning zero filled struct for the iocs specific ns "
    2865                 :            :                       "identify command and CSI 0x%02x\n",
    2866                 :            :                       csi);
    2867   [ -  +  -  +  :          6 :         rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   -  + ]
    2868   [ -  +  -  +  :          6 :         rsp->status.sc = SPDK_NVME_SC_SUCCESS;
                   -  + ]
    2869                 :          6 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2870                 :          4 : }
    2871                 :            : 
    2872                 :            : static int
    2873                 :        439 : nvmf_ctrlr_identify_iocs_nvm(struct spdk_nvmf_ctrlr *ctrlr,
    2874                 :            :                              struct spdk_nvme_cmd *cmd,
    2875                 :            :                              struct spdk_nvme_cpl *rsp,
    2876                 :            :                              struct spdk_nvme_nvm_ctrlr_data *cdata_nvm)
    2877                 :            : {
    2878                 :            :         /* The unit of max_write_zeroes_size_kib is KiB.
    2879                 :            :          * The unit of wzsl is the minimum memory page size(2 ^ (12 + CAP.MPSMIN) bytes)
    2880                 :            :          * and is reported as a power of two (2^n).
    2881                 :            :          */
    2882   [ +  +  +  -  :        441 :         cdata_nvm->wzsl = spdk_u64log2(ctrlr->subsys->max_write_zeroes_size_kib >>
          +  -  +  -  +  
             -  +  -  +  
                      - ]
    2883   [ +  -  +  -  :        439 :                                        (2 + ctrlr->vcprop.cap.bits.mpsmin));
          +  -  +  -  +  
                      - ]
    2884                 :            : 
    2885                 :            :         /* The unit of max_discard_size_kib is KiB.
    2886                 :            :          * The dmrsl indicates the maximum number of logical blocks for
    2887                 :            :          * dataset management command.
    2888                 :            :          */
    2889   [ +  -  +  -  :        439 :         cdata_nvm->dmrsl = ctrlr->subsys->max_discard_size_kib << 1;
          +  -  +  -  +  
             -  +  -  +  
                      - ]
    2890   [ +  -  +  - ]:        439 :         cdata_nvm->dmrl = 1;
    2891                 :            : 
    2892   [ +  -  +  -  :        439 :         rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    2893   [ +  -  +  -  :        439 :         rsp->status.sc = SPDK_NVME_SC_SUCCESS;
                   +  - ]
    2894                 :        439 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2895                 :            : }
    2896                 :            : 
    2897                 :            : static int
    2898                 :         24 : nvmf_ctrlr_identify_iocs_zns(struct spdk_nvmf_ctrlr *ctrlr,
    2899                 :            :                              struct spdk_nvme_cmd *cmd,
    2900                 :            :                              struct spdk_nvme_cpl *rsp,
    2901                 :            :                              struct spdk_nvme_zns_ctrlr_data *cdata_zns)
    2902                 :            : {
    2903                 :            :         /* The unit of max_zone_append_size_kib is KiB.
    2904                 :            :         The unit of zasl is the minimum memory page size
    2905                 :            :         (2 ^ (12 + CAP.MPSMIN) KiB)
    2906                 :            :         and is reported as a power of two (2^n). */
    2907   [ +  +  +  -  :         32 :         cdata_zns->zasl = spdk_u64log2(ctrlr->subsys->max_zone_append_size_kib >>
          +  -  +  -  +  
             -  +  -  +  
                      - ]
    2908   [ +  -  +  -  :         24 :                                        (12 + ctrlr->vcprop.cap.bits.mpsmin));
          +  -  +  -  +  
                      - ]
    2909                 :            : 
    2910   [ +  -  +  -  :         24 :         rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    2911   [ +  -  +  -  :         24 :         rsp->status.sc = SPDK_NVME_SC_SUCCESS;
                   +  - ]
    2912                 :         24 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2913                 :            : }
    2914                 :            : 
    2915                 :            : int
    2916                 :        463 : spdk_nvmf_ctrlr_identify_iocs_specific(struct spdk_nvmf_ctrlr *ctrlr,
    2917                 :            :                                        struct spdk_nvme_cmd *cmd,
    2918                 :            :                                        struct spdk_nvme_cpl *rsp,
    2919                 :            :                                        void *cdata,
    2920                 :            :                                        size_t cdata_size)
    2921                 :            : {
    2922   [ +  -  +  -  :        463 :         uint8_t csi = cmd->cdw11_bits.identify.csi;
             +  -  +  - ]
    2923                 :            : 
    2924         [ +  + ]:        463 :         memset(cdata, 0, cdata_size);
    2925                 :            : 
    2926      [ +  +  + ]:        463 :         switch (csi) {
    2927                 :        438 :         case SPDK_NVME_CSI_NVM:
    2928                 :        439 :                 return nvmf_ctrlr_identify_iocs_nvm(ctrlr, cmd, rsp, cdata);
    2929                 :         20 :         case SPDK_NVME_CSI_ZNS:
    2930                 :         24 :                 return nvmf_ctrlr_identify_iocs_zns(ctrlr, cmd, rsp, cdata);
    2931                 :          0 :         default:
    2932                 :          0 :                 break;
    2933                 :            :         }
    2934                 :            : 
    2935   [ #  #  #  #  :          0 :         SPDK_DEBUGLOG(nvmf,
                   #  # ]
    2936                 :            :                       "Returning zero filled struct for the iocs specific ctrlr "
    2937                 :            :                       "identify command and CSI 0x%02x\n",
    2938                 :            :                       csi);
    2939   [ #  #  #  #  :          0 :         rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    2940   [ #  #  #  #  :          0 :         rsp->status.sc = SPDK_NVME_SC_SUCCESS;
                   #  # ]
    2941                 :          0 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2942                 :          5 : }
    2943                 :            : 
    2944                 :            : static int
    2945                 :       2299 : nvmf_ctrlr_identify_active_ns_list(struct spdk_nvmf_subsystem *subsystem,
    2946                 :            :                                    struct spdk_nvme_cmd *cmd,
    2947                 :            :                                    struct spdk_nvme_cpl *rsp,
    2948                 :            :                                    struct spdk_nvme_ns_list *ns_list)
    2949                 :            : {
    2950                 :          0 :         struct spdk_nvmf_ns *ns;
    2951                 :       2299 :         uint32_t count = 0;
    2952                 :            : 
    2953   [ +  +  +  -  :       2299 :         if (cmd->nsid >= 0xfffffffeUL) {
                   -  + ]
    2954   [ #  #  #  # ]:          0 :                 SPDK_ERRLOG("Identify Active Namespace List with invalid NSID %u\n", cmd->nsid);
    2955   [ #  #  #  #  :          0 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
                   #  # ]
    2956                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2957                 :            :         }
    2958                 :            : 
    2959         [ +  + ]:       2299 :         memset(ns_list, 0, sizeof(*ns_list));
    2960                 :            : 
    2961         [ +  + ]:       4534 :         for (ns = spdk_nvmf_subsystem_get_first_ns(subsystem); ns != NULL;
    2962                 :       2235 :              ns = spdk_nvmf_subsystem_get_next_ns(subsystem, ns)) {
    2963   [ +  +  +  -  :       2235 :                 if (ns->opts.nsid <= cmd->nsid) {
          +  -  +  -  +  
                -  -  + ]
    2964                 :          0 :                         continue;
    2965                 :            :                 }
    2966                 :            : 
    2967   [ +  -  +  -  :       2235 :                 ns_list->ns_list[count++] = ns->opts.nsid;
          +  -  +  -  +  
                -  +  - ]
    2968         [ +  + ]:       2235 :                 if (count == SPDK_COUNTOF(ns_list->ns_list)) {
    2969                 :          0 :                         break;
    2970                 :            :                 }
    2971                 :        930 :         }
    2972                 :            : 
    2973                 :       2299 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    2974                 :        930 : }
    2975                 :            : 
    2976                 :            : static void
    2977                 :       6146 : _add_ns_id_desc(void **buf_ptr, size_t *buf_remain,
    2978                 :            :                 enum spdk_nvme_nidt type,
    2979                 :            :                 const void *data, size_t data_size)
    2980                 :            : {
    2981                 :          7 :         struct spdk_nvme_ns_id_desc *desc;
    2982                 :       6146 :         size_t desc_size = sizeof(*desc) + data_size;
    2983                 :            : 
    2984                 :            :         /*
    2985                 :            :          * These should never fail in practice, since all valid NS ID descriptors
    2986                 :            :          * should be defined so that they fit in the available 4096-byte buffer.
    2987                 :            :          */
    2988   [ +  +  #  # ]:       6146 :         assert(data_size > 0);
    2989   [ +  +  #  # ]:       6146 :         assert(data_size <= UINT8_MAX);
    2990   [ +  +  +  -  :       6146 :         assert(desc_size < *buf_remain);
                   #  # ]
    2991   [ +  -  +  -  :       6146 :         if (data_size == 0 || data_size > UINT8_MAX || desc_size > *buf_remain) {
             +  +  -  + ]
    2992                 :          0 :                 return;
    2993                 :            :         }
    2994                 :            : 
    2995         [ +  - ]:       6146 :         desc = *buf_ptr;
    2996   [ +  -  +  - ]:       6146 :         desc->nidt = type;
    2997   [ +  -  +  - ]:       6146 :         desc->nidl = data_size;
    2998   [ +  +  +  +  :       6146 :         memcpy(desc->nid, data, data_size);
                   +  - ]
    2999                 :            : 
    3000         [ +  - ]:       6146 :         *buf_ptr += desc_size;
    3001         [ +  - ]:       6146 :         *buf_remain -= desc_size;
    3002         [ -  + ]:       1867 : }
    3003                 :            : 
    3004                 :            : static int
    3005                 :       3109 : nvmf_ctrlr_identify_ns_id_descriptor_list(
    3006                 :            :         struct spdk_nvmf_subsystem *subsystem,
    3007                 :            :         struct spdk_nvme_cmd *cmd,
    3008                 :            :         struct spdk_nvme_cpl *rsp,
    3009                 :            :         void *id_desc_list, size_t id_desc_list_size)
    3010                 :            : {
    3011                 :          6 :         struct spdk_nvmf_ns *ns;
    3012                 :       3109 :         size_t buf_remain = id_desc_list_size;
    3013                 :       3109 :         void *buf_ptr = id_desc_list;
    3014                 :            : 
    3015   [ +  -  +  - ]:       3109 :         ns = _nvmf_subsystem_get_ns(subsystem, cmd->nsid);
    3016   [ +  +  +  +  :       3109 :         if (ns == NULL || ns->bdev == NULL) {
             +  -  +  - ]
    3017   [ +  -  +  -  :         29 :                 rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    3018   [ +  -  +  -  :         29 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
                   +  - ]
    3019                 :         29 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3020                 :            :         }
    3021                 :            : 
    3022                 :            : #define ADD_ID_DESC(type, data, size) \
    3023                 :            :         do { \
    3024                 :            :                 if (!spdk_mem_all_zero(data, size)) { \
    3025                 :            :                         _add_ns_id_desc(&buf_ptr, &buf_remain, type, data, size); \
    3026                 :            :                 } \
    3027                 :            :         } while (0)
    3028                 :            : 
    3029   [ +  +  +  -  :       3080 :         ADD_ID_DESC(SPDK_NVME_NIDT_EUI64, ns->opts.eui64, sizeof(ns->opts.eui64));
          +  +  +  -  +  
                      - ]
    3030   [ +  +  +  -  :       3080 :         ADD_ID_DESC(SPDK_NVME_NIDT_NGUID, ns->opts.nguid, sizeof(ns->opts.nguid));
          +  +  +  -  +  
                      - ]
    3031   [ +  +  +  -  :       3080 :         ADD_ID_DESC(SPDK_NVME_NIDT_UUID, &ns->opts.uuid, sizeof(ns->opts.uuid));
          +  +  +  -  +  
                      - ]
    3032   [ +  +  +  -  :       3080 :         ADD_ID_DESC(SPDK_NVME_NIDT_CSI, &ns->csi, sizeof(uint8_t));
                   #  # ]
    3033                 :            : 
    3034                 :            :         /*
    3035                 :            :          * The list is automatically 0-terminated, both in the temporary buffer
    3036                 :            :          * used by nvmf_ctrlr_identify(), and the eventual iov destination -
    3037                 :            :          * controller to host buffers in admin commands always get zeroed in
    3038                 :            :          * nvmf_ctrlr_process_admin_cmd().
    3039                 :            :          */
    3040                 :            : 
    3041                 :            : #undef ADD_ID_DESC
    3042                 :            : 
    3043                 :       3080 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3044                 :        936 : }
    3045                 :            : 
    3046                 :            : static int
    3047                 :          0 : nvmf_ctrlr_identify_iocs(struct spdk_nvmf_ctrlr *ctrlr,
    3048                 :            :                          struct spdk_nvme_cmd *cmd,
    3049                 :            :                          struct spdk_nvme_cpl *rsp,
    3050                 :            :                          void *cdata, size_t cdata_size)
    3051                 :            : {
    3052                 :          0 :         struct spdk_nvme_iocs_vector *vector;
    3053                 :          0 :         struct spdk_nvmf_ns *ns;
    3054                 :            : 
    3055         [ #  # ]:          0 :         if (cdata_size < sizeof(struct spdk_nvme_iocs_vector)) {
    3056   [ #  #  #  #  :          0 :                 rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    3057   [ #  #  #  #  :          0 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   #  # ]
    3058                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3059                 :            :         }
    3060                 :            : 
    3061                 :            :         /* For now we only support this command sent to the current
    3062                 :            :          * controller.
    3063                 :            :          */
    3064   [ #  #  #  #  :          0 :         if (cmd->cdw10_bits.identify.cntid != 0xFFFF &&
          #  #  #  #  #  
                #  #  # ]
    3065   [ #  #  #  #  :          0 :             cmd->cdw10_bits.identify.cntid != ctrlr->cntlid) {
          #  #  #  #  #  
                #  #  # ]
    3066   [ #  #  #  #  :          0 :                 rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    3067   [ #  #  #  #  :          0 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   #  # ]
    3068                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3069                 :            :         }
    3070         [ #  # ]:          0 :         memset(cdata, 0, cdata_size);
    3071                 :            : 
    3072                 :          0 :         vector = cdata;
    3073         [ #  # ]:          0 :         vector->nvm = 1;
    3074   [ #  #  #  #  :          0 :         for (ns = spdk_nvmf_subsystem_get_first_ns(ctrlr->subsys); ns != NULL;
                   #  # ]
    3075   [ #  #  #  # ]:          0 :              ns = spdk_nvmf_subsystem_get_next_ns(ctrlr->subsys, ns)) {
    3076   [ #  #  #  #  :          0 :                 if (ns->bdev == NULL) {
                   #  # ]
    3077                 :          0 :                         continue;
    3078                 :            :                 }
    3079   [ #  #  #  #  :          0 :                 if (spdk_bdev_is_zoned(ns->bdev)) {
                   #  # ]
    3080         [ #  # ]:          0 :                         vector->zns = 1;
    3081                 :          0 :                 }
    3082                 :          0 :         }
    3083                 :            : 
    3084   [ #  #  #  #  :          0 :         rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    3085   [ #  #  #  #  :          0 :         rsp->status.sc = SPDK_NVME_SC_SUCCESS;
                   #  # ]
    3086                 :          0 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3087                 :          0 : }
    3088                 :            : 
    3089                 :            : static int
    3090                 :      12790 : nvmf_ctrlr_identify(struct spdk_nvmf_request *req)
    3091                 :            : {
    3092                 :          6 :         uint8_t cns;
    3093   [ +  -  +  -  :      12790 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    3094   [ +  -  +  -  :      12790 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    3095   [ +  -  +  -  :      12790 :         struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
                   +  - ]
    3096   [ +  -  +  - ]:      12790 :         struct spdk_nvmf_subsystem *subsystem = ctrlr->subsys;
    3097                 :      12790 :         int ret = SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3098                 :      12790 :         char tmpbuf[SPDK_NVME_IDENTIFY_BUFLEN] = "";
    3099                 :        427 :         struct spdk_iov_xfer ix;
    3100                 :            : 
    3101   [ +  +  +  +  :      12790 :         if (req->iovcnt < 1 || req->length < SPDK_NVME_IDENTIFY_BUFLEN) {
          +  -  +  -  +  
                -  -  + ]
    3102   [ -  +  -  +  :        740 :                 SPDK_DEBUGLOG(nvmf, "identify command with invalid buffer\n");
                   #  # ]
    3103   [ #  #  #  #  :        740 :                 rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    3104   [ #  #  #  #  :        740 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   #  # ]
    3105                 :        740 :                 return ret;
    3106                 :            :         }
    3107                 :            : 
    3108   [ +  -  +  -  :      12050 :         cns = cmd->cdw10_bits.identify.cns;
             +  -  +  - ]
    3109                 :            : 
    3110   [ +  +  -  + ]:      12050 :         if (spdk_nvmf_subsystem_is_discovery(subsystem) &&
    3111                 :          0 :             cns != SPDK_NVME_IDENTIFY_CTRLR) {
    3112                 :            :                 /* Discovery controllers only support Identify Controller */
    3113                 :          0 :                 goto invalid_cns;
    3114                 :            :         }
    3115                 :            : 
    3116                 :            :         /*
    3117                 :            :          * We must use a temporary buffer: it's entirely possible the out buffer
    3118                 :            :          * is split across more than one IOV.
    3119                 :            :          */
    3120   [ +  -  +  -  :      12050 :         spdk_iov_xfer_init(&ix, req->iov, req->iovcnt);
                   +  - ]
    3121                 :            : 
    3122   [ +  +  +  +  :      12050 :         SPDK_DEBUGLOG(nvmf, "Received identify command with CNS 0x%02x\n", cns);
                   +  - ]
    3123                 :            : 
    3124   [ +  +  +  +  :      12050 :         switch (cns) {
             +  +  -  - ]
    3125                 :       2751 :         case SPDK_NVME_IDENTIFY_NS:
    3126                 :       3683 :                 ret = spdk_nvmf_ctrlr_identify_ns(ctrlr, cmd, rsp, (void *)&tmpbuf);
    3127                 :       3683 :                 break;
    3128                 :       1555 :         case SPDK_NVME_IDENTIFY_CTRLR:
    3129                 :       2485 :                 ret = spdk_nvmf_ctrlr_identify_ctrlr(ctrlr, (void *)&tmpbuf);
    3130                 :       2485 :                 break;
    3131                 :       1369 :         case SPDK_NVME_IDENTIFY_ACTIVE_NS_LIST:
    3132                 :       2299 :                 ret = nvmf_ctrlr_identify_active_ns_list(subsystem, cmd, rsp, (void *)&tmpbuf);
    3133                 :       2299 :                 break;
    3134                 :       2173 :         case SPDK_NVME_IDENTIFY_NS_ID_DESCRIPTOR_LIST:
    3135                 :       4045 :                 ret = nvmf_ctrlr_identify_ns_id_descriptor_list(subsystem, cmd, rsp,
    3136   [ +  -  +  - ]:       3109 :                                 tmpbuf, req->length);
    3137                 :       3109 :                 break;
    3138                 :          0 :         case SPDK_NVME_IDENTIFY_NS_IOCS:
    3139   [ #  #  #  # ]:          0 :                 ret = spdk_nvmf_ns_identify_iocs_specific(ctrlr, cmd, rsp, (void *)&tmpbuf, req->length);
    3140                 :          0 :                 break;
    3141                 :        433 :         case SPDK_NVME_IDENTIFY_CTRLR_IOCS:
    3142   [ #  #  #  # ]:        433 :                 ret = spdk_nvmf_ctrlr_identify_iocs_specific(ctrlr, cmd, rsp, (void *)&tmpbuf, req->length);
    3143                 :        433 :                 break;
    3144                 :          0 :         case SPDK_NVME_IDENTIFY_IOCS:
    3145   [ #  #  #  # ]:          0 :                 ret = nvmf_ctrlr_identify_iocs(ctrlr, cmd, rsp, (void *)&tmpbuf, req->length);
    3146                 :          0 :                 break;
    3147                 :          0 :         default:
    3148                 :         41 :                 goto invalid_cns;
    3149                 :            :         }
    3150                 :            : 
    3151         [ +  + ]:      12009 :         if (ret == SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE) {
    3152                 :      12009 :                 spdk_iov_xfer_from_buf(&ix, tmpbuf, sizeof(tmpbuf));
    3153                 :       3728 :         }
    3154                 :            : 
    3155                 :      12009 :         return ret;
    3156                 :            : 
    3157                 :          0 : invalid_cns:
    3158   [ +  -  +  -  :         41 :         SPDK_DEBUGLOG(nvmf, "Identify command with unsupported CNS 0x%02x\n", cns);
                   +  - ]
    3159   [ +  -  +  -  :         41 :         rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    3160   [ +  -  +  -  :         41 :         rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   +  - ]
    3161                 :         41 :         return ret;
    3162                 :       3769 : }
    3163                 :            : 
    3164                 :            : static bool
    3165                 :      51758 : nvmf_qpair_abort_aer(struct spdk_nvmf_qpair *qpair, uint16_t cid)
    3166                 :            : {
    3167   [ +  -  +  - ]:      51758 :         struct spdk_nvmf_ctrlr *ctrlr = qpair->ctrlr;
    3168                 :          2 :         struct spdk_nvmf_request *req;
    3169                 :          2 :         int i;
    3170                 :            : 
    3171         [ +  + ]:      51758 :         if (!nvmf_qpair_is_admin_queue(qpair)) {
    3172                 :      51741 :                 return false;
    3173                 :            :         }
    3174                 :            : 
    3175   [ +  +  +  -  :         17 :         assert(spdk_get_thread() == ctrlr->thread);
             +  -  #  # ]
    3176                 :            : 
    3177   [ +  -  +  -  :         61 :         for (i = 0; i < ctrlr->nr_aer_reqs; i++) {
             +  +  +  - ]
    3178   [ +  +  -  +  :         56 :                 if (ctrlr->aer_req[i]->cmd->nvme_cmd.cid == cid) {
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  +  
                      + ]
    3179   [ +  +  +  +  :         12 :                         SPDK_DEBUGLOG(nvmf, "Aborting AER request\n");
                   +  - ]
    3180   [ +  -  +  -  :         12 :                         req = ctrlr->aer_req[i];
             +  -  +  - ]
    3181   [ +  -  +  -  :         12 :                         ctrlr->aer_req[i] = NULL;
             +  -  +  - ]
    3182         [ +  - ]:         12 :                         ctrlr->nr_aer_reqs--;
    3183                 :            : 
    3184                 :            :                         /* Move the last req to the aborting position for making aer_reqs
    3185                 :            :                          * in continuous
    3186                 :            :                          */
    3187   [ +  +  +  -  :         12 :                         if (i < ctrlr->nr_aer_reqs) {
                   +  + ]
    3188   [ +  -  +  -  :          6 :                                 ctrlr->aer_req[i] = ctrlr->aer_req[ctrlr->nr_aer_reqs];
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    3189   [ +  -  +  -  :          6 :                                 ctrlr->aer_req[ctrlr->nr_aer_reqs] = NULL;
          +  -  +  -  +  
                -  +  - ]
    3190                 :          1 :                         }
    3191                 :            : 
    3192   [ +  -  +  -  :         12 :                         req->rsp->nvme_cpl.status.sct = SPDK_NVME_SCT_GENERIC;
          +  -  +  -  +  
                -  +  - ]
    3193   [ +  -  +  -  :         12 :                         req->rsp->nvme_cpl.status.sc = SPDK_NVME_SC_ABORTED_BY_REQUEST;
          +  -  +  -  +  
                -  +  - ]
    3194                 :         12 :                         _nvmf_request_complete(req);
    3195                 :         12 :                         return true;
    3196                 :            :                 }
    3197                 :         24 :         }
    3198                 :            : 
    3199                 :          5 :         return false;
    3200                 :          7 : }
    3201                 :            : 
    3202                 :            : void
    3203                 :       2334 : nvmf_qpair_abort_pending_zcopy_reqs(struct spdk_nvmf_qpair *qpair)
    3204                 :            : {
    3205                 :          0 :         struct spdk_nvmf_request *req, *tmp;
    3206                 :            : 
    3207   [ +  +  +  -  :      11253 :         TAILQ_FOREACH_SAFE(req, &qpair->outstanding, link, tmp) {
          +  -  +  +  +  
          -  +  -  +  -  
                   +  + ]
    3208   [ +  +  +  -  :       8919 :                 if (req->zcopy_phase == NVMF_ZCOPY_PHASE_EXECUTE) {
                   +  - ]
    3209                 :            :                         /* Zero-copy requests are kept on the outstanding queue from the moment
    3210                 :            :                          * zcopy_start is sent until a zcopy_end callback is received.  Therefore,
    3211                 :            :                          * we can't remove them from the outstanding queue here, but need to rely on
    3212                 :            :                          * the transport to do a zcopy_end to release their buffers and, in turn,
    3213                 :            :                          * remove them from the queue.
    3214                 :            :                          */
    3215   [ #  #  #  #  :          0 :                         req->rsp->nvme_cpl.status.sct = SPDK_NVME_SCT_GENERIC;
          #  #  #  #  #  
                #  #  # ]
    3216   [ #  #  #  #  :          0 :                         req->rsp->nvme_cpl.status.sc = SPDK_NVME_SC_ABORTED_BY_REQUEST;
          #  #  #  #  #  
                #  #  # ]
    3217                 :          0 :                         nvmf_transport_req_free(req);
    3218                 :          0 :                 }
    3219                 :       3692 :         }
    3220                 :       2334 : }
    3221                 :            : 
    3222                 :            : static void
    3223                 :      51746 : nvmf_qpair_abort_request(struct spdk_nvmf_qpair *qpair, struct spdk_nvmf_request *req)
    3224                 :            : {
    3225   [ +  -  +  -  :      51746 :         uint16_t cid = req->cmd->nvme_cmd.cdw10_bits.abort.cid;
          +  -  +  -  +  
             -  +  -  +  
                      - ]
    3226                 :            : 
    3227         [ -  + ]:      51746 :         if (nvmf_qpair_abort_aer(qpair, cid)) {
    3228   [ #  #  #  #  :          0 :                 SPDK_DEBUGLOG(nvmf, "abort ctrlr=%p sqid=%u cid=%u successful\n",
          #  #  #  #  #  
             #  #  #  #  
                      # ]
    3229                 :            :                               qpair->ctrlr, qpair->qid, cid);
    3230   [ #  #  #  #  :          0 :                 req->rsp->nvme_cpl.cdw0 &= ~1U; /* Command successfully aborted */
          #  #  #  #  #  
                      # ]
    3231                 :            : 
    3232                 :          0 :                 spdk_nvmf_request_complete(req);
    3233                 :          0 :                 return;
    3234                 :            :         }
    3235                 :            : 
    3236                 :      51746 :         nvmf_transport_qpair_abort_request(qpair, req);
    3237         [ #  # ]:          5 : }
    3238                 :            : 
    3239                 :            : static void
    3240                 :      53264 : nvmf_ctrlr_abort_done(struct spdk_io_channel_iter *i, int status)
    3241                 :            : {
    3242                 :      53264 :         struct spdk_nvmf_request *req = spdk_io_channel_iter_get_ctx(i);
    3243                 :            : 
    3244         [ +  + ]:      53264 :         if (status == 0) {
    3245                 :            :                 /* There was no qpair whose ID matches SQID of the abort command.
    3246                 :            :                  * Hence call _nvmf_request_complete() here.
    3247                 :            :                  */
    3248                 :       1518 :                 _nvmf_request_complete(req);
    3249                 :        166 :         }
    3250                 :      53264 : }
    3251                 :            : 
    3252                 :            : static void
    3253                 :      99226 : nvmf_ctrlr_abort_on_pg(struct spdk_io_channel_iter *i)
    3254                 :            : {
    3255                 :      99226 :         struct spdk_nvmf_request *req = spdk_io_channel_iter_get_ctx(i);
    3256                 :      99226 :         struct spdk_io_channel *ch = spdk_io_channel_iter_get_channel(i);
    3257                 :      99226 :         struct spdk_nvmf_poll_group *group = spdk_io_channel_get_ctx(ch);
    3258   [ +  -  +  -  :      99226 :         uint16_t sqid = req->cmd->nvme_cmd.cdw10_bits.abort.sqid;
          +  -  +  -  +  
             -  +  -  +  
                      - ]
    3259                 :          0 :         struct spdk_nvmf_qpair *qpair;
    3260                 :            : 
    3261   [ +  +  +  -  :     144555 :         TAILQ_FOREACH(qpair, &group->qpairs, link) {
          +  -  +  +  +  
             -  +  -  +  
                      - ]
    3262   [ +  -  +  +  :      97075 :                 if (qpair->ctrlr == req->qpair->ctrlr && qpair->qid == sqid) {
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      + ]
    3263                 :            :                         /* Found the qpair */
    3264                 :            : 
    3265                 :      51746 :                         nvmf_qpair_abort_request(qpair, req);
    3266                 :            : 
    3267                 :            :                         /* Return -1 for the status so the iteration across threads stops. */
    3268                 :      51746 :                         spdk_for_each_channel_continue(i, -1);
    3269                 :      51746 :                         return;
    3270                 :            :                 }
    3271                 :        332 :         }
    3272                 :            : 
    3273                 :      47480 :         spdk_for_each_channel_continue(i, 0);
    3274         [ #  # ]:        171 : }
    3275                 :            : 
    3276                 :            : static int
    3277                 :      53264 : nvmf_ctrlr_abort(struct spdk_nvmf_request *req)
    3278                 :            : {
    3279   [ +  -  +  -  :      53264 :         struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
                   +  - ]
    3280                 :            : 
    3281   [ +  -  +  - ]:      53264 :         rsp->cdw0 = 1U; /* Command not aborted */
    3282   [ +  -  +  -  :      53264 :         rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    3283   [ +  -  +  -  :      53264 :         rsp->status.sc = SPDK_NVME_SC_SUCCESS;
                   +  - ]
    3284                 :            : 
    3285                 :            :         /* Send a message to each poll group, searching for this ctrlr, sqid, and command. */
    3286   [ +  -  +  -  :      53264 :         spdk_for_each_channel(req->qpair->ctrlr->subsys->tgt,
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
    3287                 :            :                               nvmf_ctrlr_abort_on_pg,
    3288                 :        171 :                               req,
    3289                 :            :                               nvmf_ctrlr_abort_done
    3290                 :            :                              );
    3291                 :            : 
    3292                 :      53264 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS;
    3293                 :          0 : }
    3294                 :            : 
    3295                 :            : int
    3296                 :      43835 : nvmf_ctrlr_abort_request(struct spdk_nvmf_request *req)
    3297                 :            : {
    3298   [ #  #  #  # ]:      43835 :         struct spdk_nvmf_request *req_to_abort = req->req_to_abort;
    3299                 :          0 :         struct spdk_bdev *bdev;
    3300                 :          0 :         struct spdk_bdev_desc *desc;
    3301                 :          0 :         struct spdk_io_channel *ch;
    3302                 :          0 :         int rc;
    3303                 :            : 
    3304   [ -  +  #  # ]:      43835 :         assert(req_to_abort != NULL);
    3305                 :            : 
    3306   [ -  +  -  -  :      43835 :         if (g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_OPC_ABORT].hdlr &&
          #  #  #  #  #  
                #  #  # ]
    3307   [ #  #  #  # ]:          0 :             nvmf_qpair_is_admin_queue(req_to_abort->qpair)) {
    3308   [ #  #  #  #  :          0 :                 return g_nvmf_custom_admin_cmd_hdlrs[SPDK_NVME_OPC_ABORT].hdlr(req);
          #  #  #  #  #  
                #  #  # ]
    3309                 :            :         }
    3310                 :            : 
    3311   [ #  #  #  #  :      43835 :         rc = spdk_nvmf_request_get_bdev(req_to_abort->cmd->nvme_cmd.nsid, req_to_abort,
          #  #  #  #  #  
                      # ]
    3312                 :            :                                         &bdev, &desc, &ch);
    3313         [ -  + ]:      43835 :         if (rc != 0) {
    3314                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3315                 :            :         }
    3316                 :            : 
    3317                 :      43835 :         return spdk_nvmf_bdev_ctrlr_abort_cmd(bdev, desc, ch, req, req_to_abort);
    3318                 :          0 : }
    3319                 :            : 
    3320                 :            : static int
    3321                 :      31887 : get_features_generic(struct spdk_nvmf_request *req, uint32_t cdw0)
    3322                 :            : {
    3323   [ +  -  +  -  :      31887 :         struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
                   +  - ]
    3324                 :            : 
    3325   [ +  -  +  - ]:      31887 :         rsp->cdw0 = cdw0;
    3326                 :      31887 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3327                 :          1 : }
    3328                 :            : 
    3329                 :            : /* we have to use the typedef in the function declaration to appease astyle. */
    3330                 :            : typedef enum spdk_nvme_path_status_code spdk_nvme_path_status_code_t;
    3331                 :            : 
    3332                 :            : static spdk_nvme_path_status_code_t
    3333                 :        986 : _nvme_ana_state_to_path_status(enum spdk_nvme_ana_state ana_state)
    3334                 :            : {
    3335   [ +  -  -  - ]:        986 :         switch (ana_state) {
    3336                 :        986 :         case SPDK_NVME_ANA_INACCESSIBLE_STATE:
    3337                 :        986 :                 return SPDK_NVME_SC_ASYMMETRIC_ACCESS_INACCESSIBLE;
    3338                 :          0 :         case SPDK_NVME_ANA_PERSISTENT_LOSS_STATE:
    3339                 :          0 :                 return SPDK_NVME_SC_ASYMMETRIC_ACCESS_PERSISTENT_LOSS;
    3340                 :          0 :         case SPDK_NVME_ANA_CHANGE_STATE:
    3341                 :          0 :                 return SPDK_NVME_SC_ASYMMETRIC_ACCESS_TRANSITION;
    3342                 :          0 :         default:
    3343                 :          0 :                 return SPDK_NVME_SC_INTERNAL_PATH_ERROR;
    3344                 :            :         }
    3345                 :          0 : }
    3346                 :            : 
    3347                 :            : static int
    3348                 :      33205 : nvmf_ctrlr_get_features(struct spdk_nvmf_request *req)
    3349                 :            : {
    3350                 :          3 :         uint8_t feature;
    3351   [ +  -  +  -  :      33205 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    3352   [ +  -  +  -  :      33205 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    3353   [ +  -  +  -  :      33205 :         struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
                   +  - ]
    3354                 :          3 :         enum spdk_nvme_ana_state ana_state;
    3355                 :            : 
    3356   [ +  -  +  -  :      33205 :         feature = cmd->cdw10_bits.get_features.fid;
             +  -  +  - ]
    3357                 :            : 
    3358   [ +  +  +  -  :      33205 :         if (spdk_nvmf_subsystem_is_discovery(ctrlr->subsys)) {
                   -  + ]
    3359                 :            :                 /*
    3360                 :            :                  * Features supported by Discovery controller
    3361                 :            :                  */
    3362      [ +  -  - ]:        119 :                 switch (feature) {
    3363                 :        119 :                 case SPDK_NVME_FEAT_KEEP_ALIVE_TIMER:
    3364   [ #  #  #  #  :        119 :                         return get_features_generic(req, ctrlr->feat.keep_alive_timer.raw);
             #  #  #  # ]
    3365                 :          0 :                 case SPDK_NVME_FEAT_ASYNC_EVENT_CONFIGURATION:
    3366   [ #  #  #  #  :          0 :                         return get_features_generic(req, ctrlr->feat.async_event_configuration.raw);
             #  #  #  # ]
    3367                 :          0 :                 default:
    3368   [ #  #  #  #  :          0 :                         SPDK_INFOLOG(nvmf, "Get Features command with unsupported feature ID 0x%02x\n", feature);
                   #  # ]
    3369   [ #  #  #  #  :          0 :                         response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   #  # ]
    3370                 :          0 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3371                 :            :                 }
    3372                 :            :         }
    3373                 :            :         /*
    3374                 :            :          * Process Get Features command for non-discovery controller
    3375                 :            :          */
    3376   [ +  -  +  - ]:      33086 :         ana_state = nvmf_ctrlr_get_ana_state_from_nsid(ctrlr, cmd->nsid);
    3377         [ -  + ]:      33086 :         switch (ana_state) {
    3378                 :          0 :         case SPDK_NVME_ANA_INACCESSIBLE_STATE:
    3379                 :            :         case SPDK_NVME_ANA_PERSISTENT_LOSS_STATE:
    3380                 :            :         case SPDK_NVME_ANA_CHANGE_STATE:
    3381         [ #  # ]:          0 :                 switch (feature) {
    3382                 :          0 :                 case SPDK_NVME_FEAT_ERROR_RECOVERY:
    3383                 :            :                 case SPDK_NVME_FEAT_WRITE_ATOMICITY:
    3384                 :            :                 case SPDK_NVME_FEAT_HOST_RESERVE_MASK:
    3385                 :            :                 case SPDK_NVME_FEAT_HOST_RESERVE_PERSIST:
    3386   [ #  #  #  #  :          0 :                         response->status.sct = SPDK_NVME_SCT_PATH;
                   #  # ]
    3387   [ #  #  #  #  :          0 :                         response->status.sc = _nvme_ana_state_to_path_status(ana_state);
                   #  # ]
    3388                 :          0 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3389                 :          0 :                 default:
    3390                 :          0 :                         break;
    3391                 :            :                 }
    3392                 :          0 :                 break;
    3393                 :      32072 :         default:
    3394                 :      33086 :                 break;
    3395                 :            :         }
    3396                 :            : 
    3397   [ +  +  +  +  :      33086 :         switch (feature) {
          +  +  +  +  +  
          +  +  +  +  +  
                   +  + ]
    3398                 :         17 :         case SPDK_NVME_FEAT_ARBITRATION:
    3399   [ #  #  #  #  :         17 :                 return get_features_generic(req, ctrlr->feat.arbitration.raw);
             #  #  #  # ]
    3400                 :         18 :         case SPDK_NVME_FEAT_POWER_MANAGEMENT:
    3401   [ #  #  #  #  :         18 :                 return get_features_generic(req, ctrlr->feat.power_management.raw);
             #  #  #  # ]
    3402                 :         24 :         case SPDK_NVME_FEAT_TEMPERATURE_THRESHOLD:
    3403                 :         26 :                 return nvmf_ctrlr_get_features_temperature_threshold(req);
    3404                 :         23 :         case SPDK_NVME_FEAT_ERROR_RECOVERY:
    3405   [ +  -  +  -  :         24 :                 return get_features_generic(req, ctrlr->feat.error_recovery.raw);
             +  -  +  - ]
    3406                 :          5 :         case SPDK_NVME_FEAT_VOLATILE_WRITE_CACHE:
    3407   [ #  #  #  #  :          5 :                 return get_features_generic(req, ctrlr->feat.volatile_write_cache.raw);
             #  #  #  # ]
    3408                 :      29917 :         case SPDK_NVME_FEAT_NUMBER_OF_QUEUES:
    3409   [ #  #  #  #  :      29917 :                 return get_features_generic(req, ctrlr->feat.number_of_queues.raw);
             #  #  #  # ]
    3410                 :          9 :         case SPDK_NVME_FEAT_INTERRUPT_COALESCING:
    3411   [ #  #  #  #  :          9 :                 return get_features_generic(req, ctrlr->feat.interrupt_coalescing.raw);
             #  #  #  # ]
    3412                 :          3 :         case SPDK_NVME_FEAT_INTERRUPT_VECTOR_CONFIGURATION:
    3413                 :          3 :                 return nvmf_ctrlr_get_features_interrupt_vector_configuration(req);
    3414                 :          1 :         case SPDK_NVME_FEAT_WRITE_ATOMICITY:
    3415   [ +  -  +  -  :          2 :                 return get_features_generic(req, ctrlr->feat.write_atomicity.raw);
             +  -  +  - ]
    3416                 :          1 :         case SPDK_NVME_FEAT_ASYNC_EVENT_CONFIGURATION:
    3417   [ #  #  #  #  :          1 :                 return get_features_generic(req, ctrlr->feat.async_event_configuration.raw);
             #  #  #  # ]
    3418                 :        845 :         case SPDK_NVME_FEAT_KEEP_ALIVE_TIMER:
    3419   [ +  -  +  -  :       1775 :                 return get_features_generic(req, ctrlr->feat.keep_alive_timer.raw);
             +  -  +  - ]
    3420                 :          0 :         case SPDK_NVME_FEAT_HOST_IDENTIFIER:
    3421                 :          0 :                 return nvmf_ctrlr_get_features_host_identifier(req);
    3422                 :          4 :         case SPDK_NVME_FEAT_HOST_RESERVE_MASK:
    3423                 :          4 :                 return nvmf_ctrlr_get_features_reservation_notification_mask(req);
    3424                 :          2 :         case SPDK_NVME_FEAT_HOST_RESERVE_PERSIST:
    3425                 :          2 :                 return nvmf_ctrlr_get_features_reservation_persistence(req);
    3426                 :          5 :         case SPDK_NVME_FEAT_HOST_BEHAVIOR_SUPPORT:
    3427                 :          5 :                 return nvmf_ctrlr_get_features_host_behavior_support(req);
    3428                 :       1198 :         default:
    3429   [ +  +  +  +  :       1278 :                 SPDK_INFOLOG(nvmf, "Get Features command with unsupported feature ID 0x%02x\n", feature);
                   +  - ]
    3430   [ +  -  +  -  :       1278 :                 response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   +  - ]
    3431                 :       1278 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3432                 :            :         }
    3433                 :       1014 : }
    3434                 :            : 
    3435                 :            : static int
    3436                 :       5971 : nvmf_ctrlr_set_features(struct spdk_nvmf_request *req)
    3437                 :            : {
    3438                 :          5 :         uint8_t feature, save;
    3439   [ +  -  +  -  :       5971 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    3440   [ +  -  +  -  :       5971 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    3441   [ +  -  +  -  :       5971 :         struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
                   +  - ]
    3442                 :          5 :         enum spdk_nvme_ana_state ana_state;
    3443                 :            :         /*
    3444                 :            :          * Features are not saveable by the controller as indicated by
    3445                 :            :          * ONCS field of the Identify Controller data.
    3446                 :            :          * */
    3447   [ +  -  +  -  :       5971 :         save = cmd->cdw10_bits.set_features.sv;
             +  -  +  - ]
    3448         [ +  + ]:       5971 :         if (save) {
    3449   [ +  -  +  -  :        682 :                 response->status.sc = SPDK_NVME_SC_FEATURE_ID_NOT_SAVEABLE;
                   +  - ]
    3450   [ +  -  +  -  :        682 :                 response->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
                   +  - ]
    3451                 :        682 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3452                 :            :         }
    3453                 :            : 
    3454   [ +  -  +  -  :       5289 :         feature = cmd->cdw10_bits.set_features.fid;
             +  -  +  - ]
    3455                 :            : 
    3456   [ +  +  +  -  :       5289 :         if (spdk_nvmf_subsystem_is_discovery(ctrlr->subsys)) {
                   -  + ]
    3457                 :            :                 /*
    3458                 :            :                  * Features supported by Discovery controller
    3459                 :            :                  */
    3460      [ -  +  - ]:        151 :                 switch (feature) {
    3461                 :          0 :                 case SPDK_NVME_FEAT_KEEP_ALIVE_TIMER:
    3462                 :          0 :                         return nvmf_ctrlr_set_features_keep_alive_timer(req);
    3463                 :        151 :                 case SPDK_NVME_FEAT_ASYNC_EVENT_CONFIGURATION:
    3464                 :        151 :                         return nvmf_ctrlr_set_features_async_event_configuration(req);
    3465                 :          0 :                 default:
    3466   [ #  #  #  #  :          0 :                         SPDK_INFOLOG(nvmf, "Set Features command with unsupported feature ID 0x%02x\n", feature);
                   #  # ]
    3467   [ #  #  #  #  :          0 :                         response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   #  # ]
    3468                 :          0 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3469                 :            :                 }
    3470                 :            :         }
    3471                 :            :         /*
    3472                 :            :          * Process Set Features command for non-discovery controller
    3473                 :            :          */
    3474   [ +  -  +  - ]:       5138 :         ana_state = nvmf_ctrlr_get_ana_state_from_nsid(ctrlr, cmd->nsid);
    3475      [ -  +  + ]:       5138 :         switch (ana_state) {
    3476                 :          0 :         case SPDK_NVME_ANA_INACCESSIBLE_STATE:
    3477                 :            :         case SPDK_NVME_ANA_CHANGE_STATE:
    3478   [ #  #  #  #  :          0 :                 if (cmd->nsid == SPDK_NVME_GLOBAL_NS_TAG) {
                   #  # ]
    3479   [ #  #  #  #  :          0 :                         response->status.sct = SPDK_NVME_SCT_PATH;
                   #  # ]
    3480   [ #  #  #  #  :          0 :                         response->status.sc = _nvme_ana_state_to_path_status(ana_state);
                   #  # ]
    3481                 :          0 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3482                 :            :                 } else {
    3483         [ #  # ]:          0 :                         switch (feature) {
    3484                 :          0 :                         case SPDK_NVME_FEAT_ERROR_RECOVERY:
    3485                 :            :                         case SPDK_NVME_FEAT_WRITE_ATOMICITY:
    3486                 :            :                         case SPDK_NVME_FEAT_HOST_RESERVE_MASK:
    3487                 :            :                         case SPDK_NVME_FEAT_HOST_RESERVE_PERSIST:
    3488   [ #  #  #  #  :          0 :                                 response->status.sct = SPDK_NVME_SCT_PATH;
                   #  # ]
    3489   [ #  #  #  #  :          0 :                                 response->status.sc = _nvme_ana_state_to_path_status(ana_state);
                   #  # ]
    3490                 :          0 :                                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3491                 :          0 :                         default:
    3492                 :          0 :                                 break;
    3493                 :            :                         }
    3494                 :            :                 }
    3495                 :          0 :                 break;
    3496                 :          0 :         case SPDK_NVME_ANA_PERSISTENT_LOSS_STATE:
    3497   [ #  #  #  #  :          0 :                 response->status.sct = SPDK_NVME_SCT_PATH;
                   #  # ]
    3498   [ #  #  #  #  :          0 :                 response->status.sc = SPDK_NVME_SC_ASYMMETRIC_ACCESS_PERSISTENT_LOSS;
                   #  # ]
    3499                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3500                 :       3239 :         default:
    3501                 :       5138 :                 break;
    3502                 :            :         }
    3503                 :            : 
    3504   [ +  +  +  +  :       5138 :         switch (feature) {
          +  +  +  +  +  
          +  +  -  +  -  
                      + ]
    3505                 :          0 :         case SPDK_NVME_FEAT_ARBITRATION:
    3506                 :         14 :                 return nvmf_ctrlr_set_features_arbitration(req);
    3507                 :          0 :         case SPDK_NVME_FEAT_POWER_MANAGEMENT:
    3508                 :          4 :                 return nvmf_ctrlr_set_features_power_management(req);
    3509                 :         21 :         case SPDK_NVME_FEAT_TEMPERATURE_THRESHOLD:
    3510                 :         24 :                 return nvmf_ctrlr_set_features_temperature_threshold(req);
    3511                 :         14 :         case SPDK_NVME_FEAT_ERROR_RECOVERY:
    3512                 :         16 :                 return nvmf_ctrlr_set_features_error_recovery(req);
    3513                 :          0 :         case SPDK_NVME_FEAT_VOLATILE_WRITE_CACHE:
    3514                 :          0 :                 return nvmf_ctrlr_set_features_volatile_write_cache(req);
    3515                 :       1248 :         case SPDK_NVME_FEAT_NUMBER_OF_QUEUES:
    3516                 :       2178 :                 return nvmf_ctrlr_set_features_number_of_queues(req);
    3517                 :          3 :         case SPDK_NVME_FEAT_INTERRUPT_COALESCING:
    3518   [ #  #  #  #  :          3 :                 response->status.sct = SPDK_NVME_SCT_COMMAND_SPECIFIC;
                   #  # ]
    3519   [ #  #  #  #  :          3 :                 response->status.sc = SPDK_NVME_SC_FEATURE_NOT_CHANGEABLE;
                   #  # ]
    3520                 :          3 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3521                 :          6 :         case SPDK_NVME_FEAT_WRITE_ATOMICITY:
    3522                 :          6 :                 return nvmf_ctrlr_set_features_write_atomicity(req);
    3523                 :       1254 :         case SPDK_NVME_FEAT_ASYNC_EVENT_CONFIGURATION:
    3524                 :       2184 :                 return nvmf_ctrlr_set_features_async_event_configuration(req);
    3525                 :          2 :         case SPDK_NVME_FEAT_KEEP_ALIVE_TIMER:
    3526                 :          2 :                 return nvmf_ctrlr_set_features_keep_alive_timer(req);
    3527                 :          1 :         case SPDK_NVME_FEAT_HOST_IDENTIFIER:
    3528                 :          1 :                 return nvmf_ctrlr_set_features_host_identifier(req);
    3529                 :          0 :         case SPDK_NVME_FEAT_HOST_RESERVE_MASK:
    3530                 :          0 :                 return nvmf_ctrlr_set_features_reservation_notification_mask(req);
    3531                 :          1 :         case SPDK_NVME_FEAT_HOST_RESERVE_PERSIST:
    3532                 :          1 :                 return nvmf_ctrlr_set_features_reservation_persistence(req);
    3533                 :          0 :         case SPDK_NVME_FEAT_HOST_BEHAVIOR_SUPPORT:
    3534                 :          0 :                 return nvmf_ctrlr_set_features_host_behavior_support(req);
    3535                 :        689 :         default:
    3536   [ -  +  -  +  :        705 :                 SPDK_INFOLOG(nvmf, "Set Features command with unsupported feature ID 0x%02x\n", feature);
                   +  - ]
    3537   [ -  +  -  +  :        705 :                 response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   -  + ]
    3538                 :        705 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3539                 :            :         }
    3540                 :       1947 : }
    3541                 :            : 
    3542                 :            : static int
    3543                 :       3894 : nvmf_ctrlr_keep_alive(struct spdk_nvmf_request *req)
    3544                 :            : {
    3545   [ +  -  +  -  :       3894 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    3546                 :            : 
    3547   [ +  +  +  +  :       3894 :         SPDK_DEBUGLOG(nvmf, "Keep Alive\n");
                   +  - ]
    3548                 :            :         /*
    3549                 :            :          * To handle keep alive just clear or reset the
    3550                 :            :          * ctrlr based keep alive duration counter.
    3551                 :            :          * When added, a separate timer based process
    3552                 :            :          * will monitor if the time since last recorded
    3553                 :            :          * keep alive has exceeded the max duration and
    3554                 :            :          * take appropriate action.
    3555                 :            :          */
    3556   [ +  -  +  - ]:       3894 :         ctrlr->last_keep_alive_tick = spdk_get_ticks();
    3557                 :            : 
    3558                 :       3894 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3559                 :          0 : }
    3560                 :            : 
    3561                 :            : int
    3562                 :     452594 : nvmf_ctrlr_process_admin_cmd(struct spdk_nvmf_request *req)
    3563                 :            : {
    3564   [ +  -  +  -  :     452594 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    3565   [ +  -  +  -  :     452594 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    3566   [ +  -  +  -  :     452594 :         struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
                   +  - ]
    3567                 :         17 :         struct spdk_nvmf_subsystem_poll_group *sgroup;
    3568                 :         17 :         int rc;
    3569                 :            : 
    3570         [ +  + ]:     452594 :         if (ctrlr == NULL) {
    3571                 :          0 :                 SPDK_ERRLOG("Admin command sent before CONNECT\n");
    3572   [ #  #  #  #  :          0 :                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    3573   [ #  #  #  #  :          0 :                 response->status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR;
                   #  # ]
    3574                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3575                 :            :         }
    3576                 :            : 
    3577   [ +  +  +  + ]:     452594 :         if (cmd->opc == SPDK_NVME_OPC_ASYNC_EVENT_REQUEST) {
    3578                 :            :                 /* We do not want to treat AERs as outstanding commands,
    3579                 :            :                  * so decrement mgmt_io_outstanding here to offset
    3580                 :            :                  * the increment that happened prior to this call.
    3581                 :            :                  */
    3582   [ +  -  +  -  :       8568 :                 sgroup = &req->qpair->group->sgroups[ctrlr->subsys->id];
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]
    3583   [ +  +  #  # ]:       8568 :                 assert(sgroup != NULL);
    3584         [ +  - ]:       8568 :                 sgroup->mgmt_io_outstanding--;
    3585                 :       3730 :         }
    3586                 :            : 
    3587   [ +  +  +  -  :     452594 :         assert(spdk_get_thread() == ctrlr->thread);
             +  -  #  # ]
    3588                 :            : 
    3589   [ +  +  -  + ]:     452594 :         if (cmd->fuse != 0) {
    3590                 :            :                 /* Fused admin commands are not supported. */
    3591   [ #  #  #  #  :          0 :                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    3592   [ #  #  #  #  :          0 :                 response->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   #  # ]
    3593                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3594                 :            :         }
    3595                 :            : 
    3596   [ +  +  +  -  :     452594 :         if (ctrlr->vcprop.cc.bits.en != 1) {
          +  -  +  -  -  
                      + ]
    3597                 :          0 :                 SPDK_ERRLOG("Admin command sent to disabled controller\n");
    3598   [ #  #  #  #  :          0 :                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    3599   [ #  #  #  #  :          0 :                 response->status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR;
                   #  # ]
    3600                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3601                 :            :         }
    3602                 :            : 
    3603   [ +  +  +  +  :     452594 :         if (req->iovcnt && spdk_nvme_opc_get_data_transfer(cmd->opc) == SPDK_NVME_DATA_CONTROLLER_TO_HOST) {
          +  +  +  -  +  
                      + ]
    3604   [ +  -  +  -  :      15009 :                 spdk_iov_memset(req->iov, req->iovcnt, 0);
                   +  - ]
    3605                 :       4132 :         }
    3606                 :            : 
    3607   [ +  +  +  -  :     452594 :         if (spdk_nvmf_subsystem_is_discovery(ctrlr->subsys)) {
                   +  - ]
    3608                 :            :                 /* Discovery controllers only support these admin OPS. */
    3609   [ +  -  #  # ]:       1482 :                 switch (cmd->opc) {
    3610                 :       1482 :                 case SPDK_NVME_OPC_IDENTIFY:
    3611                 :            :                 case SPDK_NVME_OPC_GET_LOG_PAGE:
    3612                 :            :                 case SPDK_NVME_OPC_KEEP_ALIVE:
    3613                 :            :                 case SPDK_NVME_OPC_SET_FEATURES:
    3614                 :            :                 case SPDK_NVME_OPC_GET_FEATURES:
    3615                 :            :                 case SPDK_NVME_OPC_ASYNC_EVENT_REQUEST:
    3616                 :       1482 :                         break;
    3617                 :          0 :                 default:
    3618                 :          0 :                         goto invalid_opcode;
    3619                 :            :                 }
    3620                 :          0 :         }
    3621                 :            : 
    3622                 :            :         /* Call a custom adm cmd handler if set. Aborts are handled in a different path (see nvmf_passthru_admin_cmd) */
    3623   [ +  +  +  -  :     452594 :         if (g_nvmf_custom_admin_cmd_hdlrs[cmd->opc].hdlr && cmd->opc != SPDK_NVME_OPC_ABORT) {
          +  -  +  -  +  
          -  +  +  +  -  
                   -  + ]
    3624   [ +  -  +  -  :         22 :                 rc = g_nvmf_custom_admin_cmd_hdlrs[cmd->opc].hdlr(req);
          +  -  +  -  +  
             -  -  +  +  
                      - ]
    3625         [ +  + ]:         22 :                 if (rc >= SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE) {
    3626                 :            :                         /* The handler took care of this command */
    3627                 :         10 :                         return rc;
    3628                 :            :                 }
    3629                 :          0 :         }
    3630                 :            : 
    3631   [ +  +  +  +  :     452584 :         switch (cmd->opc) {
          +  +  +  +  +  
                   +  + ]
    3632                 :       3302 :         case SPDK_NVME_OPC_GET_LOG_PAGE:
    3633                 :       3361 :                 return nvmf_ctrlr_get_log_page(req);
    3634                 :       9021 :         case SPDK_NVME_OPC_IDENTIFY:
    3635                 :      12790 :                 return nvmf_ctrlr_identify(req);
    3636                 :      53093 :         case SPDK_NVME_OPC_ABORT:
    3637                 :      53264 :                 return nvmf_ctrlr_abort(req);
    3638                 :      32176 :         case SPDK_NVME_OPC_GET_FEATURES:
    3639                 :      33187 :                 return nvmf_ctrlr_get_features(req);
    3640                 :       3999 :         case SPDK_NVME_OPC_SET_FEATURES:
    3641                 :       5941 :                 return nvmf_ctrlr_set_features(req);
    3642                 :       4838 :         case SPDK_NVME_OPC_ASYNC_EVENT_REQUEST:
    3643                 :       8568 :                 return nvmf_ctrlr_async_event_request(req);
    3644                 :       2971 :         case SPDK_NVME_OPC_KEEP_ALIVE:
    3645                 :       3894 :                 return nvmf_ctrlr_keep_alive(req);
    3646                 :            : 
    3647                 :       2847 :         case SPDK_NVME_OPC_CREATE_IO_SQ:
    3648                 :            :         case SPDK_NVME_OPC_CREATE_IO_CQ:
    3649                 :            :         case SPDK_NVME_OPC_DELETE_IO_SQ:
    3650                 :            :         case SPDK_NVME_OPC_DELETE_IO_CQ:
    3651                 :            :                 /* Create and Delete I/O CQ/SQ not allowed in NVMe-oF */
    3652                 :       3273 :                 goto invalid_opcode;
    3653                 :            : 
    3654                 :     327730 :         default:
    3655                 :     328306 :                 goto invalid_opcode;
    3656                 :            :         }
    3657                 :            : 
    3658                 :     330577 : invalid_opcode:
    3659   [ +  +  +  +  :     331579 :         SPDK_INFOLOG(nvmf, "Unsupported admin opcode 0x%x\n", cmd->opc);
             +  -  #  # ]
    3660   [ +  -  +  -  :     331579 :         response->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    3661   [ +  -  +  -  :     331579 :         response->status.sc = SPDK_NVME_SC_INVALID_OPCODE;
                   +  - ]
    3662                 :     331579 :         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3663                 :      12608 : }
    3664                 :            : 
    3665                 :            : static int
    3666                 :     103332 : nvmf_ctrlr_process_fabrics_cmd(struct spdk_nvmf_request *req)
    3667                 :            : {
    3668   [ +  -  +  - ]:     103332 :         struct spdk_nvmf_qpair *qpair = req->qpair;
    3669                 :          1 :         struct spdk_nvmf_capsule_cmd *cap_hdr;
    3670                 :            : 
    3671   [ +  -  +  -  :     103332 :         cap_hdr = &req->cmd->nvmf_cmd;
                   +  - ]
    3672                 :            : 
    3673   [ +  +  +  -  :     103332 :         if (qpair->ctrlr == NULL) {
                   +  + ]
    3674                 :            :                 /* No ctrlr established yet; the only valid command is Connect */
    3675   [ +  +  +  -  :      11082 :                 if (cap_hdr->fctype == SPDK_NVMF_FABRIC_COMMAND_CONNECT) {
                   +  + ]
    3676                 :      11076 :                         return nvmf_ctrlr_cmd_connect(req);
    3677                 :            :                 } else {
    3678   [ +  +  +  +  :          6 :                         SPDK_DEBUGLOG(nvmf, "Got fctype 0x%x, expected Connect\n",
          +  -  #  #  #  
                      # ]
    3679                 :            :                                       cap_hdr->fctype);
    3680   [ +  -  +  -  :          6 :                         req->rsp->nvme_cpl.status.sct = SPDK_NVME_SCT_GENERIC;
          +  -  +  -  +  
                -  +  - ]
    3681   [ +  -  +  -  :          6 :                         req->rsp->nvme_cpl.status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR;
          +  -  +  -  +  
                -  +  - ]
    3682                 :          6 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3683                 :            :                 }
    3684         [ +  + ]:      92250 :         } else if (nvmf_qpair_is_admin_queue(qpair)) {
    3685                 :            :                 /*
    3686                 :            :                  * Controller session is established, and this is an admin queue.
    3687                 :            :                  * Disallow Connect and allow other fabrics commands.
    3688                 :            :                  */
    3689   [ +  +  +  -  :      86514 :                 switch (cap_hdr->fctype) {
                -  +  + ]
    3690                 :       3337 :                 case SPDK_NVMF_FABRIC_COMMAND_PROPERTY_SET:
    3691                 :       5228 :                         return nvmf_property_set(req);
    3692                 :      74057 :                 case SPDK_NVMF_FABRIC_COMMAND_PROPERTY_GET:
    3693                 :      80585 :                         return nvmf_property_get(req);
    3694                 :        701 :                 default:
    3695   [ -  +  -  +  :        701 :                         SPDK_DEBUGLOG(nvmf, "unknown fctype 0x%02x\n",
          #  #  #  #  #  
                      # ]
    3696                 :            :                                       cap_hdr->fctype);
    3697   [ #  #  #  #  :        701 :                         req->rsp->nvme_cpl.status.sct = SPDK_NVME_SCT_GENERIC;
          #  #  #  #  #  
                #  #  # ]
    3698   [ #  #  #  #  :        701 :                         req->rsp->nvme_cpl.status.sc = SPDK_NVME_SC_INVALID_OPCODE;
          #  #  #  #  #  
                #  #  # ]
    3699                 :        701 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3700                 :            :                 }
    3701                 :            :         } else {
    3702                 :            :                 /* Controller session is established, and this is an I/O queue */
    3703                 :            :                 /* For now, no I/O-specific Fabrics commands are implemented (other than Connect) */
    3704   [ -  +  -  +  :       5736 :                 SPDK_DEBUGLOG(nvmf, "Unexpected I/O fctype 0x%x\n", cap_hdr->fctype);
          #  #  #  #  #  
                      # ]
    3705   [ #  #  #  #  :       5736 :                 req->rsp->nvme_cpl.status.sct = SPDK_NVME_SCT_GENERIC;
          #  #  #  #  #  
                #  #  # ]
    3706   [ #  #  #  #  :       5736 :                 req->rsp->nvme_cpl.status.sc = SPDK_NVME_SC_INVALID_OPCODE;
          #  #  #  #  #  
                #  #  # ]
    3707                 :       5736 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    3708                 :            :         }
    3709                 :      10347 : }
    3710                 :            : 
    3711                 :            : static inline void
    3712                 :         87 : nvmf_ctrlr_queue_pending_async_event(struct spdk_nvmf_ctrlr *ctrlr,
    3713                 :            :                                      union spdk_nvme_async_event_completion *event)
    3714                 :            : {
    3715                 :          5 :         struct spdk_nvmf_async_event_completion *nvmf_event;
    3716                 :            : 
    3717                 :         87 :         nvmf_event = calloc(1, sizeof(*nvmf_event));
    3718         [ +  + ]:         87 :         if (!nvmf_event) {
    3719                 :          0 :                 SPDK_ERRLOG("Alloc nvmf event failed, ignore the event\n");
    3720                 :          0 :                 return;
    3721                 :            :         }
    3722   [ +  -  +  -  :         87 :         nvmf_event->event.raw = event->raw;
          +  -  +  -  +  
                      - ]
    3723   [ +  -  +  -  :         87 :         STAILQ_INSERT_TAIL(&ctrlr->async_events, nvmf_event, link);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  +  
                      - ]
    3724         [ -  + ]:          5 : }
    3725                 :            : 
    3726                 :            : static inline int
    3727                 :        571 : nvmf_ctrlr_async_event_notification(struct spdk_nvmf_ctrlr *ctrlr,
    3728                 :            :                                     union spdk_nvme_async_event_completion *event)
    3729                 :            : {
    3730                 :          6 :         struct spdk_nvmf_request *req;
    3731                 :          6 :         struct spdk_nvme_cpl *rsp;
    3732                 :            : 
    3733   [ +  +  +  -  :        571 :         assert(spdk_get_thread() == ctrlr->thread);
             +  -  #  # ]
    3734                 :            : 
    3735                 :            :         /* If there is no outstanding AER request, queue the event.  Then
    3736                 :            :          * if an AER is later submitted, this event can be sent as a
    3737                 :            :          * response.
    3738                 :            :          */
    3739   [ +  +  +  -  :        571 :         if (ctrlr->nr_aer_reqs == 0) {
                   +  + ]
    3740                 :         87 :                 nvmf_ctrlr_queue_pending_async_event(ctrlr, event);
    3741                 :         87 :                 return 0;
    3742                 :            :         }
    3743                 :            : 
    3744   [ +  -  +  -  :        484 :         req = ctrlr->aer_req[--ctrlr->nr_aer_reqs];
          +  -  +  -  +  
                      - ]
    3745   [ +  -  +  -  :        484 :         rsp = &req->rsp->nvme_cpl;
                   +  - ]
    3746                 :            : 
    3747   [ +  -  +  -  :        484 :         rsp->cdw0 = event->raw;
             +  -  +  - ]
    3748                 :            : 
    3749                 :        484 :         _nvmf_request_complete(req);
    3750   [ +  -  +  -  :        484 :         ctrlr->aer_req[ctrlr->nr_aer_reqs] = NULL;
          +  -  +  -  +  
                -  +  - ]
    3751                 :            : 
    3752                 :        484 :         return 0;
    3753                 :          6 : }
    3754                 :            : 
    3755                 :            : int
    3756                 :       3688 : nvmf_ctrlr_async_event_ns_notice(struct spdk_nvmf_ctrlr *ctrlr)
    3757                 :            : {
    3758                 :       3688 :         union spdk_nvme_async_event_completion event = {0};
    3759                 :            : 
    3760                 :            :         /* Users may disable the event notification */
    3761   [ +  +  +  -  :       3688 :         if (!ctrlr->feat.async_event_configuration.bits.ns_attr_notice) {
          +  -  +  -  +  
                      - ]
    3762                 :          0 :                 return 0;
    3763                 :            :         }
    3764                 :            : 
    3765         [ +  + ]:       3688 :         if (!nvmf_ctrlr_mask_aen(ctrlr, SPDK_NVME_ASYNC_EVENT_NS_ATTR_CHANGE_MASK_BIT)) {
    3766                 :       3189 :                 return 0;
    3767                 :            :         }
    3768                 :            : 
    3769                 :        499 :         event.bits.async_event_type = SPDK_NVME_ASYNC_EVENT_TYPE_NOTICE;
    3770                 :        499 :         event.bits.async_event_info = SPDK_NVME_ASYNC_EVENT_NS_ATTR_CHANGED;
    3771                 :        499 :         event.bits.log_page_identifier = SPDK_NVME_LOG_CHANGED_NS_LIST;
    3772                 :            : 
    3773                 :        499 :         return nvmf_ctrlr_async_event_notification(ctrlr, &event);
    3774                 :          6 : }
    3775                 :            : 
    3776                 :            : int
    3777                 :       3698 : nvmf_ctrlr_async_event_ana_change_notice(struct spdk_nvmf_ctrlr *ctrlr)
    3778                 :            : {
    3779                 :       3698 :         union spdk_nvme_async_event_completion event = {0};
    3780                 :            : 
    3781                 :            :         /* Users may disable the event notification */
    3782   [ +  +  +  -  :       3698 :         if (!ctrlr->feat.async_event_configuration.bits.ana_change_notice) {
          +  -  +  -  +  
                      - ]
    3783                 :       3652 :                 return 0;
    3784                 :            :         }
    3785                 :            : 
    3786         [ +  + ]:         46 :         if (!nvmf_ctrlr_mask_aen(ctrlr, SPDK_NVME_ASYNC_EVENT_ANA_CHANGE_MASK_BIT)) {
    3787                 :          0 :                 return 0;
    3788                 :            :         }
    3789                 :            : 
    3790                 :         46 :         event.bits.async_event_type = SPDK_NVME_ASYNC_EVENT_TYPE_NOTICE;
    3791                 :         46 :         event.bits.async_event_info = SPDK_NVME_ASYNC_EVENT_ANA_CHANGE;
    3792                 :         46 :         event.bits.log_page_identifier = SPDK_NVME_LOG_ASYMMETRIC_NAMESPACE_ACCESS;
    3793                 :            : 
    3794                 :         46 :         return nvmf_ctrlr_async_event_notification(ctrlr, &event);
    3795                 :          1 : }
    3796                 :            : 
    3797                 :            : void
    3798                 :         18 : nvmf_ctrlr_async_event_reservation_notification(struct spdk_nvmf_ctrlr *ctrlr)
    3799                 :            : {
    3800                 :         18 :         union spdk_nvme_async_event_completion event = {0};
    3801                 :            : 
    3802   [ +  +  +  -  :         18 :         if (!ctrlr->num_avail_log_pages) {
                   +  - ]
    3803                 :          2 :                 return;
    3804                 :            :         }
    3805                 :            : 
    3806         [ +  + ]:         18 :         if (!nvmf_ctrlr_mask_aen(ctrlr, SPDK_NVME_ASYNC_EVENT_RESERVATION_LOG_AVAIL_MASK_BIT)) {
    3807                 :         12 :                 return;
    3808                 :            :         }
    3809                 :            : 
    3810                 :          6 :         event.bits.async_event_type = SPDK_NVME_ASYNC_EVENT_TYPE_IO;
    3811                 :          6 :         event.bits.async_event_info = SPDK_NVME_ASYNC_EVENT_RESERVATION_LOG_AVAIL;
    3812                 :          6 :         event.bits.log_page_identifier = SPDK_NVME_LOG_RESERVATION_NOTIFICATION;
    3813                 :            : 
    3814                 :          6 :         nvmf_ctrlr_async_event_notification(ctrlr, &event);
    3815         [ -  + ]:          3 : }
    3816                 :            : 
    3817                 :            : void
    3818                 :         20 : nvmf_ctrlr_async_event_discovery_log_change_notice(void *ctx)
    3819                 :            : {
    3820                 :         20 :         union spdk_nvme_async_event_completion event = {0};
    3821                 :         20 :         struct spdk_nvmf_ctrlr *ctrlr = ctx;
    3822                 :            : 
    3823                 :            :         /* Users may disable the event notification manually or
    3824                 :            :          * it may not be enabled due to keep alive timeout
    3825                 :            :          * not being set in connect command to discovery controller.
    3826                 :            :          */
    3827   [ +  +  +  -  :         20 :         if (!ctrlr->feat.async_event_configuration.bits.discovery_log_change_notice) {
          +  -  +  -  +  
                      - ]
    3828                 :          0 :                 return;
    3829                 :            :         }
    3830                 :            : 
    3831         [ +  + ]:         20 :         if (!nvmf_ctrlr_mask_aen(ctrlr, SPDK_NVME_ASYNC_EVENT_DISCOVERY_LOG_CHANGE_MASK_BIT)) {
    3832                 :          0 :                 return;
    3833                 :            :         }
    3834                 :            : 
    3835                 :         20 :         event.bits.async_event_type = SPDK_NVME_ASYNC_EVENT_TYPE_NOTICE;
    3836                 :         20 :         event.bits.async_event_info = SPDK_NVME_ASYNC_EVENT_DISCOVERY_LOG_CHANGE;
    3837                 :         20 :         event.bits.log_page_identifier = SPDK_NVME_LOG_DISCOVERY;
    3838                 :            : 
    3839                 :         20 :         nvmf_ctrlr_async_event_notification(ctrlr, &event);
    3840         [ -  + ]:          1 : }
    3841                 :            : 
    3842                 :            : int
    3843                 :          0 : spdk_nvmf_ctrlr_async_event_error_event(struct spdk_nvmf_ctrlr *ctrlr,
    3844                 :            :                                         enum spdk_nvme_async_event_info_error info)
    3845                 :            : {
    3846                 :          0 :         union spdk_nvme_async_event_completion event;
    3847                 :            : 
    3848         [ #  # ]:          0 :         if (!nvmf_ctrlr_mask_aen(ctrlr, SPDK_NVME_ASYNC_EVENT_ERROR_MASK_BIT)) {
    3849                 :          0 :                 return 0;
    3850                 :            :         }
    3851                 :            : 
    3852         [ #  # ]:          0 :         if (info > SPDK_NVME_ASYNC_EVENT_FW_IMAGE_LOAD) {
    3853                 :          0 :                 return 0;
    3854                 :            :         }
    3855                 :            : 
    3856                 :          0 :         event.bits.async_event_type = SPDK_NVME_ASYNC_EVENT_TYPE_ERROR;
    3857                 :          0 :         event.bits.log_page_identifier = SPDK_NVME_LOG_ERROR;
    3858                 :          0 :         event.bits.async_event_info = info;
    3859                 :            : 
    3860                 :          0 :         return nvmf_ctrlr_async_event_notification(ctrlr, &event);
    3861                 :          0 : }
    3862                 :            : 
    3863                 :            : void
    3864                 :       2334 : nvmf_qpair_free_aer(struct spdk_nvmf_qpair *qpair)
    3865                 :            : {
    3866   [ +  -  +  - ]:       2334 :         struct spdk_nvmf_ctrlr *ctrlr = qpair->ctrlr;
    3867                 :          0 :         int i;
    3868                 :            : 
    3869         [ +  + ]:       2334 :         if (!nvmf_qpair_is_admin_queue(qpair)) {
    3870                 :         55 :                 return;
    3871                 :            :         }
    3872                 :            : 
    3873   [ +  +  +  -  :       2279 :         assert(spdk_get_thread() == ctrlr->thread);
             +  -  #  # ]
    3874                 :            : 
    3875   [ +  +  +  -  :      10080 :         for (i = 0; i < ctrlr->nr_aer_reqs; i++) {
             +  +  +  - ]
    3876   [ +  -  +  -  :       7801 :                 spdk_nvmf_request_free(ctrlr->aer_req[i]);
             +  -  +  - ]
    3877   [ +  -  +  -  :       7801 :                 ctrlr->aer_req[i] = NULL;
             +  -  +  - ]
    3878                 :       3692 :         }
    3879                 :            : 
    3880   [ +  -  +  - ]:       2279 :         ctrlr->nr_aer_reqs = 0;
    3881         [ #  # ]:        923 : }
    3882                 :            : 
    3883                 :            : void
    3884                 :         56 : spdk_nvmf_ctrlr_abort_aer(struct spdk_nvmf_ctrlr *ctrlr)
    3885                 :            : {
    3886                 :          0 :         struct spdk_nvmf_request *req;
    3887                 :          0 :         int i;
    3888                 :            : 
    3889   [ +  +  +  -  :         56 :         assert(spdk_get_thread() == ctrlr->thread);
             +  -  #  # ]
    3890                 :            : 
    3891   [ +  +  +  -  :         56 :         if (!ctrlr->nr_aer_reqs) {
                   +  - ]
    3892                 :         10 :                 return;
    3893                 :            :         }
    3894                 :            : 
    3895   [ +  +  +  -  :        218 :         for (i = 0; i < ctrlr->nr_aer_reqs; i++) {
             +  +  +  - ]
    3896   [ +  -  +  -  :        172 :                 req = ctrlr->aer_req[i];
             +  -  +  - ]
    3897                 :            : 
    3898   [ +  -  +  -  :        172 :                 req->rsp->nvme_cpl.status.sct = SPDK_NVME_SCT_GENERIC;
          +  -  +  -  +  
                -  +  - ]
    3899   [ +  -  +  -  :        172 :                 req->rsp->nvme_cpl.status.sc = SPDK_NVME_SC_ABORTED_BY_REQUEST;
          +  -  +  -  +  
                -  +  - ]
    3900                 :        172 :                 _nvmf_request_complete(req);
    3901                 :            : 
    3902   [ +  -  +  -  :        172 :                 ctrlr->aer_req[i] = NULL;
             +  -  +  - ]
    3903                 :         28 :         }
    3904                 :            : 
    3905   [ +  -  +  - ]:         46 :         ctrlr->nr_aer_reqs = 0;
    3906         [ #  # ]:          7 : }
    3907                 :            : 
    3908                 :            : static void
    3909                 :         18 : _nvmf_ctrlr_add_reservation_log(void *ctx)
    3910                 :            : {
    3911                 :         18 :         struct spdk_nvmf_reservation_log *log = (struct spdk_nvmf_reservation_log *)ctx;
    3912   [ +  -  +  - ]:         18 :         struct spdk_nvmf_ctrlr *ctrlr = log->ctrlr;
    3913                 :            : 
    3914         [ +  - ]:         18 :         ctrlr->log_page_count++;
    3915                 :            : 
    3916                 :            :         /* Maximum number of queued log pages is 255 */
    3917   [ +  +  +  -  :         18 :         if (ctrlr->num_avail_log_pages == 0xff) {
                   -  + ]
    3918                 :          0 :                 struct spdk_nvmf_reservation_log *entry;
    3919   [ #  #  #  #  :          0 :                 entry = TAILQ_LAST(&ctrlr->log_head, log_page_head);
          #  #  #  #  #  
                #  #  # ]
    3920   [ #  #  #  #  :          0 :                 entry->log.log_page_count = ctrlr->log_page_count;
          #  #  #  #  #  
                      # ]
    3921                 :          0 :                 free(log);
    3922                 :          0 :                 return;
    3923                 :          0 :         }
    3924                 :            : 
    3925   [ +  -  +  -  :         18 :         log->log.log_page_count = ctrlr->log_page_count;
          +  -  +  -  +  
                      - ]
    3926   [ +  -  +  -  :         18 :         log->log.num_avail_log_pages = ctrlr->num_avail_log_pages++;
             +  -  +  - ]
    3927   [ +  -  +  -  :         18 :         TAILQ_INSERT_TAIL(&ctrlr->log_head, log, link);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
    3928                 :            : 
    3929                 :         18 :         nvmf_ctrlr_async_event_reservation_notification(ctrlr);
    3930         [ -  + ]:          3 : }
    3931                 :            : 
    3932                 :            : void
    3933                 :         36 : nvmf_ctrlr_reservation_notice_log(struct spdk_nvmf_ctrlr *ctrlr,
    3934                 :            :                                   struct spdk_nvmf_ns *ns,
    3935                 :            :                                   enum spdk_nvme_reservation_notification_log_page_type type)
    3936                 :            : {
    3937                 :          6 :         struct spdk_nvmf_reservation_log *log;
    3938                 :            : 
    3939   [ -  +  +  +  :         36 :         switch (type) {
                      + ]
    3940                 :          0 :         case SPDK_NVME_RESERVATION_LOG_PAGE_EMPTY:
    3941                 :          0 :                 return;
    3942                 :         10 :         case SPDK_NVME_REGISTRATION_PREEMPTED:
    3943   [ +  +  +  -  :         12 :                 if (ns->mask & SPDK_NVME_REGISTRATION_PREEMPTED_MASK) {
             +  -  +  + ]
    3944                 :          6 :                         return;
    3945                 :            :                 }
    3946                 :          6 :                 break;
    3947                 :         10 :         case SPDK_NVME_RESERVATION_RELEASED:
    3948   [ +  +  +  -  :         12 :                 if (ns->mask & SPDK_NVME_RESERVATION_RELEASED_MASK) {
             +  -  +  + ]
    3949                 :          6 :                         return;
    3950                 :            :                 }
    3951                 :          6 :                 break;
    3952                 :         10 :         case SPDK_NVME_RESERVATION_PREEMPTED:
    3953   [ +  +  +  -  :         12 :                 if (ns->mask & SPDK_NVME_RESERVATION_PREEMPTED_MASK) {
             +  -  +  + ]
    3954                 :          6 :                         return;
    3955                 :            :                 }
    3956                 :          6 :                 break;
    3957                 :          0 :         default:
    3958                 :          0 :                 return;
    3959                 :            :         }
    3960                 :            : 
    3961                 :         18 :         log = calloc(1, sizeof(*log));
    3962         [ +  + ]:         18 :         if (!log) {
    3963                 :          0 :                 SPDK_ERRLOG("Alloc log page failed, ignore the log\n");
    3964                 :          0 :                 return;
    3965                 :            :         }
    3966   [ +  -  +  - ]:         18 :         log->ctrlr = ctrlr;
    3967   [ +  -  +  -  :         18 :         log->log.type = type;
                   +  - ]
    3968   [ +  -  +  -  :         18 :         log->log.nsid = ns->nsid;
          +  -  +  -  +  
                      - ]
    3969                 :            : 
    3970   [ +  -  +  - ]:         18 :         spdk_thread_send_msg(ctrlr->thread, _nvmf_ctrlr_add_reservation_log, log);
    3971         [ -  + ]:          6 : }
    3972                 :            : 
    3973                 :            : /* Check from subsystem poll group's namespace information data structure */
    3974                 :            : static bool
    3975                 :        168 : nvmf_ns_info_ctrlr_is_registrant(struct spdk_nvmf_subsystem_pg_ns_info *ns_info,
    3976                 :            :                                  struct spdk_nvmf_ctrlr *ctrlr)
    3977                 :            : {
    3978                 :         28 :         uint32_t i;
    3979                 :            : 
    3980         [ +  + ]:       1230 :         for (i = 0; i < SPDK_NVMF_MAX_NUM_REGISTRANTS; i++) {
    3981   [ +  +  +  -  :       1170 :                 if (!spdk_uuid_compare(&ns_info->reg_hostid[i], &ctrlr->hostid)) {
          +  -  +  -  +  
                      + ]
    3982                 :        108 :                         return true;
    3983                 :            :                 }
    3984                 :        177 :         }
    3985                 :            : 
    3986                 :         60 :         return false;
    3987                 :         28 : }
    3988                 :            : 
    3989                 :            : /*
    3990                 :            :  * Check the NVMe command is permitted or not for current controller(Host).
    3991                 :            :  */
    3992                 :            : static int
    3993                 :   23857310 : nvmf_ns_reservation_request_check(struct spdk_nvmf_subsystem_pg_ns_info *ns_info,
    3994                 :            :                                   struct spdk_nvmf_ctrlr *ctrlr,
    3995                 :            :                                   struct spdk_nvmf_request *req)
    3996                 :            : {
    3997   [ +  -  +  -  :   23857310 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    3998   [ +  -  +  - ]:   23857310 :         enum spdk_nvme_reservation_type rtype = ns_info->rtype;
    3999                 :   23857310 :         uint8_t status = SPDK_NVME_SC_SUCCESS;
    4000                 :         38 :         uint8_t racqa;
    4001                 :         38 :         bool is_registrant;
    4002                 :            : 
    4003                 :            :         /* No valid reservation */
    4004         [ +  + ]:   23857310 :         if (!rtype) {
    4005                 :   23857142 :                 return 0;
    4006                 :            :         }
    4007                 :            : 
    4008                 :        168 :         is_registrant = nvmf_ns_info_ctrlr_is_registrant(ns_info, ctrlr);
    4009                 :            :         /* All registrants type and current ctrlr is a valid registrant */
    4010   [ +  +  +  + ]:        196 :         if ((rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE_ALL_REGS ||
    4011         [ +  + ]:         73 :              rtype == SPDK_NVME_RESERVE_EXCLUSIVE_ACCESS_ALL_REGS) && is_registrant) {
    4012                 :         30 :                 return 0;
    4013   [ +  +  +  -  :        138 :         } else if (!spdk_uuid_compare(&ns_info->holder_id, &ctrlr->hostid)) {
                   +  + ]
    4014                 :         24 :                 return 0;
    4015                 :            :         }
    4016                 :            : 
    4017                 :            :         /* Non-holder for current controller */
    4018   [ +  +  +  +  :        114 :         switch (cmd->opc) {
                -  -  + ]
    4019                 :         45 :         case SPDK_NVME_OPC_READ:
    4020                 :            :         case SPDK_NVME_OPC_COMPARE:
    4021         [ +  + ]:         54 :                 if (rtype == SPDK_NVME_RESERVE_EXCLUSIVE_ACCESS) {
    4022                 :          6 :                         status = SPDK_NVME_SC_RESERVATION_CONFLICT;
    4023                 :          6 :                         goto exit;
    4024                 :            :                 }
    4025   [ +  +  +  + ]:         56 :                 if ((rtype == SPDK_NVME_RESERVE_EXCLUSIVE_ACCESS_REG_ONLY ||
    4026         [ +  - ]:         18 :                      rtype == SPDK_NVME_RESERVE_EXCLUSIVE_ACCESS_ALL_REGS) && !is_registrant) {
    4027                 :         12 :                         status = SPDK_NVME_SC_RESERVATION_CONFLICT;
    4028                 :          2 :                 }
    4029                 :         48 :                 break;
    4030                 :         45 :         case SPDK_NVME_OPC_FLUSH:
    4031                 :            :         case SPDK_NVME_OPC_WRITE:
    4032                 :            :         case SPDK_NVME_OPC_WRITE_UNCORRECTABLE:
    4033                 :            :         case SPDK_NVME_OPC_WRITE_ZEROES:
    4034                 :            :         case SPDK_NVME_OPC_DATASET_MANAGEMENT:
    4035   [ +  +  -  + ]:         54 :                 if (rtype == SPDK_NVME_RESERVE_WRITE_EXCLUSIVE ||
    4036                 :          6 :                     rtype == SPDK_NVME_RESERVE_EXCLUSIVE_ACCESS) {
    4037                 :         18 :                         status = SPDK_NVME_SC_RESERVATION_CONFLICT;
    4038                 :         18 :                         goto exit;
    4039                 :            :                 }
    4040   [ +  +  +  + ]:         36 :                 if (!is_registrant) {
    4041                 :         24 :                         status = SPDK_NVME_SC_RESERVATION_CONFLICT;
    4042                 :          4 :                 }
    4043                 :         36 :                 break;
    4044                 :          0 :         case SPDK_NVME_OPC_RESERVATION_ACQUIRE:
    4045   [ #  #  #  #  :          0 :                 racqa = cmd->cdw10_bits.resv_acquire.racqa;
             #  #  #  # ]
    4046         [ #  # ]:          0 :                 if (racqa == SPDK_NVME_RESERVE_ACQUIRE) {
    4047                 :          0 :                         status = SPDK_NVME_SC_RESERVATION_CONFLICT;
    4048                 :          0 :                         goto exit;
    4049                 :            :                 }
    4050   [ #  #  #  # ]:          0 :                 if (!is_registrant) {
    4051                 :          0 :                         status = SPDK_NVME_SC_RESERVATION_CONFLICT;
    4052                 :          0 :                 }
    4053                 :          0 :                 break;
    4054                 :          5 :         case SPDK_NVME_OPC_RESERVATION_RELEASE:
    4055   [ +  +  +  - ]:          6 :                 if (!is_registrant) {
    4056                 :          0 :                         status = SPDK_NVME_SC_RESERVATION_CONFLICT;
    4057                 :          0 :                 }
    4058                 :          6 :                 break;
    4059                 :          0 :         default:
    4060                 :          0 :                 break;
    4061                 :         15 :         }
    4062                 :            : 
    4063                 :         95 : exit:
    4064   [ +  -  +  -  :        114 :         req->rsp->nvme_cpl.status.sct = SPDK_NVME_SCT_GENERIC;
          +  -  +  -  +  
                -  +  - ]
    4065   [ +  -  +  -  :        114 :         req->rsp->nvme_cpl.status.sc = status;
          +  -  +  -  +  
                -  +  - ]
    4066         [ +  + ]:        114 :         if (status == SPDK_NVME_SC_RESERVATION_CONFLICT) {
    4067                 :         60 :                 return -EPERM;
    4068                 :            :         }
    4069                 :            : 
    4070                 :         54 :         return 0;
    4071                 :     143048 : }
    4072                 :            : 
    4073                 :            : static int
    4074                 :       6250 : nvmf_ctrlr_process_io_fused_cmd(struct spdk_nvmf_request *req, struct spdk_bdev *bdev,
    4075                 :            :                                 struct spdk_bdev_desc *desc, struct spdk_io_channel *ch)
    4076                 :            : {
    4077   [ +  -  +  -  :       6250 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    4078   [ +  -  +  -  :       6250 :         struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
                   +  - ]
    4079   [ +  -  +  -  :       6250 :         struct spdk_nvmf_request *first_fused_req = req->qpair->first_fused_req;
          +  -  +  -  +  
                      - ]
    4080                 :          6 :         int rc;
    4081                 :            : 
    4082   [ +  +  +  + ]:       6250 :         if (cmd->fuse == SPDK_NVME_CMD_FUSE_FIRST) {
    4083                 :            :                 /* first fused operation (should be compare) */
    4084         [ -  + ]:       3125 :                 if (first_fused_req != NULL) {
    4085   [ #  #  #  #  :          0 :                         struct spdk_nvme_cpl *fused_response = &first_fused_req->rsp->nvme_cpl;
                   #  # ]
    4086                 :            : 
    4087                 :          0 :                         SPDK_ERRLOG("Wrong sequence of fused operations\n");
    4088                 :            : 
    4089                 :            :                         /* abort req->qpair->first_fused_request and continue with new fused command */
    4090   [ #  #  #  #  :          0 :                         fused_response->status.sc = SPDK_NVME_SC_ABORTED_MISSING_FUSED;
                   #  # ]
    4091   [ #  #  #  #  :          0 :                         fused_response->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    4092                 :          0 :                         _nvmf_request_complete(first_fused_req);
    4093   [ +  +  +  + ]:       3125 :                 } else if (cmd->opc != SPDK_NVME_OPC_COMPARE) {
    4094                 :          6 :                         SPDK_ERRLOG("Wrong op code of fused operations\n");
    4095   [ +  -  +  -  :          6 :                         rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    4096   [ +  -  +  -  :          6 :                         rsp->status.sc = SPDK_NVME_SC_INVALID_OPCODE;
                   +  - ]
    4097                 :          6 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    4098                 :            :                 }
    4099                 :            : 
    4100   [ +  -  +  -  :       3119 :                 req->qpair->first_fused_req = req;
          +  -  +  -  +  
                      - ]
    4101                 :       3119 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS;
    4102   [ +  -  +  - ]:       3125 :         } else if (cmd->fuse == SPDK_NVME_CMD_FUSE_SECOND) {
    4103                 :            :                 /* second fused operation (should be write) */
    4104         [ +  + ]:       3125 :                 if (first_fused_req == NULL) {
    4105                 :          6 :                         SPDK_ERRLOG("Wrong sequence of fused operations\n");
    4106   [ +  -  +  -  :          6 :                         rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    4107   [ +  -  +  -  :          6 :                         rsp->status.sc = SPDK_NVME_SC_ABORTED_MISSING_FUSED;
                   +  - ]
    4108                 :          6 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    4109   [ +  +  +  + ]:       3119 :                 } else if (cmd->opc != SPDK_NVME_OPC_WRITE) {
    4110   [ +  -  +  -  :          6 :                         struct spdk_nvme_cpl *fused_response = &first_fused_req->rsp->nvme_cpl;
                   +  - ]
    4111                 :            : 
    4112                 :          6 :                         SPDK_ERRLOG("Wrong op code of fused operations\n");
    4113                 :            : 
    4114                 :            :                         /* abort req->qpair->first_fused_request and fail current command */
    4115   [ +  -  +  -  :          6 :                         fused_response->status.sc = SPDK_NVME_SC_ABORTED_MISSING_FUSED;
                   +  - ]
    4116   [ +  -  +  -  :          6 :                         fused_response->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    4117                 :          6 :                         _nvmf_request_complete(first_fused_req);
    4118                 :            : 
    4119   [ +  -  +  -  :          6 :                         rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   +  - ]
    4120   [ +  -  +  -  :          6 :                         rsp->status.sc = SPDK_NVME_SC_INVALID_OPCODE;
                   +  - ]
    4121   [ +  -  +  -  :          6 :                         req->qpair->first_fused_req = NULL;
          +  -  +  -  +  
                      - ]
    4122                 :          6 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    4123                 :          1 :                 }
    4124                 :            : 
    4125                 :            :                 /* save request of first command to generate response later */
    4126   [ +  -  +  - ]:       3113 :                 req->first_fused_req = first_fused_req;
    4127   [ +  -  +  -  :       3113 :                 req->first_fused = true;
                   +  - ]
    4128   [ +  -  +  -  :       3113 :                 req->qpair->first_fused_req = NULL;
          +  -  +  -  +  
                      - ]
    4129                 :          1 :         } else {
    4130                 :          0 :                 SPDK_ERRLOG("Invalid fused command fuse field.\n");
    4131   [ #  #  #  #  :          0 :                 rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    4132   [ #  #  #  #  :          0 :                 rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
                   #  # ]
    4133                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    4134                 :            :         }
    4135                 :            : 
    4136   [ +  -  +  - ]:       3113 :         rc = nvmf_bdev_ctrlr_compare_and_write_cmd(bdev, desc, ch, req->first_fused_req, req);
    4137                 :            : 
    4138         [ +  + ]:       3113 :         if (rc == SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE) {
    4139   [ +  -  +  +  :          6 :                 if (spdk_nvme_cpl_is_error(rsp)) {
          +  -  +  -  -  
          +  -  +  -  +  
                   -  + ]
    4140   [ #  #  #  #  :          0 :                         struct spdk_nvme_cpl *fused_response = &first_fused_req->rsp->nvme_cpl;
                   #  # ]
    4141                 :            : 
    4142   [ #  #  #  #  :          0 :                         fused_response->status = rsp->status;
             #  #  #  # ]
    4143   [ #  #  #  #  :          0 :                         rsp->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    4144   [ #  #  #  #  :          0 :                         rsp->status.sc = SPDK_NVME_SC_ABORTED_FAILED_FUSED;
                   #  # ]
    4145                 :            :                         /* Complete first of fused commands. Second will be completed by upper layer */
    4146                 :          0 :                         _nvmf_request_complete(first_fused_req);
    4147   [ #  #  #  # ]:          0 :                         req->first_fused_req = NULL;
    4148   [ #  #  #  #  :          0 :                         req->first_fused = false;
                   #  # ]
    4149                 :          0 :                 }
    4150                 :          1 :         }
    4151                 :            : 
    4152                 :       3113 :         return rc;
    4153                 :          6 : }
    4154                 :            : 
    4155                 :            : bool
    4156                 :   10877912 : nvmf_ctrlr_use_zcopy(struct spdk_nvmf_request *req)
    4157                 :            : {
    4158   [ +  -  +  -  :   10877912 :         struct spdk_nvmf_transport *transport = req->qpair->transport;
             +  -  +  - ]
    4159                 :        271 :         struct spdk_nvmf_ns *ns;
    4160                 :            : 
    4161   [ +  +  +  -  :   10877912 :         assert(req->zcopy_phase == NVMF_ZCOPY_PHASE_NONE);
             +  -  #  # ]
    4162                 :            : 
    4163   [ +  +  +  +  :   10877912 :         if (!transport->opts.zcopy) {
          +  -  +  -  +  
                      + ]
    4164                 :   10138643 :                 return false;
    4165                 :            :         }
    4166                 :            : 
    4167   [ +  +  +  -  :     739269 :         if (nvmf_qpair_is_admin_queue(req->qpair)) {
                   +  + ]
    4168                 :            :                 /* Admin queue */
    4169                 :         51 :                 return false;
    4170                 :            :         }
    4171                 :            : 
    4172   [ +  +  +  -  :     739480 :         if ((req->cmd->nvme_cmd.opc != SPDK_NVME_OPC_WRITE) &&
          +  -  +  -  +  
                +  +  + ]
    4173   [ +  +  +  -  :     452724 :             (req->cmd->nvme_cmd.opc != SPDK_NVME_OPC_READ)) {
             +  -  +  - ]
    4174                 :            :                 /* Not a READ or WRITE command */
    4175                 :       1524 :                 return false;
    4176                 :            :         }
    4177                 :            : 
    4178   [ +  +  +  -  :     737694 :         if (req->cmd->nvme_cmd.fuse != SPDK_NVME_CMD_FUSE_NONE) {
          +  -  +  -  +  
                      + ]
    4179                 :            :                 /* Fused commands dont use zcopy buffers */
    4180                 :          6 :                 return false;
    4181                 :            :         }
    4182                 :            : 
    4183   [ +  -  +  -  :     737688 :         ns = _nvmf_subsystem_get_ns(req->qpair->ctrlr->subsys, req->cmd->nvme_cmd.nsid);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]
    4184   [ +  +  +  -  :     737688 :         if (ns == NULL || ns->bdev == NULL || !ns->zcopy) {
          +  +  +  +  +  
          -  +  -  +  -  
                   +  + ]
    4185                 :         12 :                 return false;
    4186                 :            :         }
    4187                 :            : 
    4188   [ +  -  +  - ]:     737676 :         req->zcopy_phase = NVMF_ZCOPY_PHASE_INIT;
    4189                 :     737676 :         return true;
    4190                 :       4538 : }
    4191                 :            : 
    4192                 :            : void
    4193                 :     840873 : spdk_nvmf_request_zcopy_start(struct spdk_nvmf_request *req)
    4194                 :            : {
    4195   [ +  +  +  -  :     840873 :         assert(req->zcopy_phase == NVMF_ZCOPY_PHASE_INIT);
             +  -  #  # ]
    4196                 :            : 
    4197                 :            :         /* Set iovcnt to be the maximum number of iovs that the ZCOPY can use */
    4198   [ +  -  +  - ]:     840873 :         req->iovcnt = NVMF_REQ_MAX_BUFFERS;
    4199                 :            : 
    4200                 :     840873 :         spdk_nvmf_request_exec(req);
    4201                 :     840873 : }
    4202                 :            : 
    4203                 :            : void
    4204                 :     730126 : spdk_nvmf_request_zcopy_end(struct spdk_nvmf_request *req, bool commit)
    4205                 :            : {
    4206   [ +  +  +  -  :     730126 :         assert(req->zcopy_phase == NVMF_ZCOPY_PHASE_EXECUTE);
             +  -  #  # ]
    4207   [ +  -  +  - ]:     730126 :         req->zcopy_phase = NVMF_ZCOPY_PHASE_END_PENDING;
    4208                 :            : 
    4209         [ +  - ]:     730126 :         nvmf_bdev_ctrlr_zcopy_end(req, commit);
    4210                 :     730126 : }
    4211                 :            : 
    4212                 :            : int
    4213                 :   23858134 : nvmf_ctrlr_process_io_cmd(struct spdk_nvmf_request *req)
    4214                 :            : {
    4215                 :         11 :         uint32_t nsid;
    4216                 :         11 :         struct spdk_nvmf_ns *ns;
    4217                 :         11 :         struct spdk_bdev *bdev;
    4218                 :         11 :         struct spdk_bdev_desc *desc;
    4219                 :         11 :         struct spdk_io_channel *ch;
    4220   [ +  -  +  -  :   23858134 :         struct spdk_nvmf_poll_group *group = req->qpair->group;
             +  -  +  - ]
    4221   [ +  -  +  -  :   23858134 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             +  -  +  - ]
    4222   [ +  -  +  -  :   23858134 :         struct spdk_nvme_cmd *cmd = &req->cmd->nvme_cmd;
                   +  - ]
    4223   [ +  -  +  -  :   23858134 :         struct spdk_nvme_cpl *response = &req->rsp->nvme_cpl;
                   +  - ]
    4224                 :         11 :         struct spdk_nvmf_subsystem_pg_ns_info *ns_info;
    4225                 :         11 :         enum spdk_nvme_ana_state ana_state;
    4226                 :            : 
    4227                 :            :         /* pre-set response details for this command */
    4228   [ +  -  +  -  :   23858134 :         response->status.sc = SPDK_NVME_SC_SUCCESS;
                   +  - ]
    4229   [ +  -  +  - ]:   23858134 :         nsid = cmd->nsid;
    4230                 :            : 
    4231         [ +  + ]:   23858134 :         if (spdk_unlikely(ctrlr == NULL)) {
    4232                 :          6 :                 SPDK_ERRLOG("I/O command sent before CONNECT\n");
    4233   [ -  +  -  +  :          6 :                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   -  + ]
    4234   [ -  +  -  +  :          6 :                 response->status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR;
                   -  + ]
    4235                 :          6 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    4236                 :            :         }
    4237                 :            : 
    4238   [ +  +  +  -  :   23858128 :         if (spdk_unlikely(ctrlr->vcprop.cc.bits.en != 1)) {
          +  -  +  -  -  
                      + ]
    4239                 :          0 :                 SPDK_ERRLOG("I/O command sent to disabled controller\n");
    4240   [ #  #  #  #  :          0 :                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    4241   [ #  #  #  #  :          0 :                 response->status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR;
                   #  # ]
    4242                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    4243                 :            :         }
    4244                 :            : 
    4245   [ +  -  +  - ]:   23858128 :         ns = _nvmf_subsystem_get_ns(ctrlr->subsys, nsid);
    4246   [ +  +  +  +  :   23858128 :         if (spdk_unlikely(ns == NULL || ns->bdev == NULL)) {
             +  -  -  + ]
    4247   [ #  #  #  #  :          0 :                 SPDK_DEBUGLOG(nvmf, "Unsuccessful query for nsid %u\n", cmd->nsid);
          #  #  #  #  #  
                      # ]
    4248   [ #  #  #  #  :          0 :                 response->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
                   #  # ]
    4249   [ #  #  #  #  :          0 :                 response->status.dnr = 1;
                   #  # ]
    4250                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    4251                 :            :         }
    4252                 :            : 
    4253   [ +  -  +  - ]:   23858128 :         ana_state = nvmf_ctrlr_get_ana_state(ctrlr, ns->anagrpid);
    4254   [ +  +  +  + ]:   23858128 :         if (spdk_unlikely(ana_state != SPDK_NVME_ANA_OPTIMIZED_STATE &&
    4255                 :            :                           ana_state != SPDK_NVME_ANA_NON_OPTIMIZED_STATE)) {
    4256   [ -  +  -  +  :        986 :                 SPDK_DEBUGLOG(nvmf, "Fail I/O command due to ANA state %d\n",
                   #  # ]
    4257                 :            :                               ana_state);
    4258   [ #  #  #  #  :        986 :                 response->status.sct = SPDK_NVME_SCT_PATH;
                   #  # ]
    4259   [ #  #  #  #  :        986 :                 response->status.sc = _nvme_ana_state_to_path_status(ana_state);
                   #  # ]
    4260                 :        986 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    4261                 :            :         }
    4262                 :            : 
    4263   [ +  +  +  -  :   23857142 :         if (spdk_likely(ctrlr->listener != NULL)) {
                   -  + ]
    4264                 :   10828874 :                 SPDK_DTRACE_PROBE3_TICKS(nvmf_request_io_exec_path, req,
    4265                 :            :                                          ctrlr->listener->trid->traddr,
    4266                 :            :                                          ctrlr->listener->trid->trsvcid);
    4267                 :     143020 :         }
    4268                 :            : 
    4269                 :            :         /* scan-build falsely reporting dereference of null pointer */
    4270   [ +  -  +  -  :   23857142 :         assert(group != NULL && group->sgroups != NULL);
             +  -  #  # ]
    4271   [ +  -  +  -  :   23857142 :         ns_info = &group->sgroups[ctrlr->subsys->id].ns_info[nsid - 1];
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                      - ]
    4272         [ -  + ]:   23857142 :         if (nvmf_ns_reservation_request_check(ns_info, ctrlr, req)) {
    4273   [ #  #  #  #  :          0 :                 SPDK_DEBUGLOG(nvmf, "Reservation Conflict for nsid %u, opcode %u\n",
          #  #  #  #  #  
                #  #  # ]
    4274                 :            :                               cmd->nsid, cmd->opc);
    4275                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    4276                 :            :         }
    4277                 :            : 
    4278   [ -  +  -  + ]:   23857142 :         bdev = ns->bdev;
    4279   [ -  +  -  + ]:   23857142 :         desc = ns->desc;
    4280   [ -  +  -  + ]:   23857142 :         ch = ns_info->channel;
    4281                 :            : 
    4282   [ +  +  +  + ]:   23857142 :         if (spdk_unlikely(cmd->fuse & SPDK_NVME_CMD_FUSE_MASK)) {
    4283                 :       6250 :                 return nvmf_ctrlr_process_io_fused_cmd(req, bdev, desc, ch);
    4284   [ -  +  -  +  :   23850892 :         } else if (spdk_unlikely(req->qpair->first_fused_req != NULL)) {
          -  +  -  +  -  
                +  -  + ]
    4285   [ #  #  #  #  :          0 :                 struct spdk_nvme_cpl *fused_response = &req->qpair->first_fused_req->rsp->nvme_cpl;
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    4286                 :            : 
    4287                 :          0 :                 SPDK_ERRLOG("Expected second of fused commands - failing first of fused commands\n");
    4288                 :            : 
    4289                 :            :                 /* abort req->qpair->first_fused_request and continue with new command */
    4290   [ #  #  #  #  :          0 :                 fused_response->status.sc = SPDK_NVME_SC_ABORTED_MISSING_FUSED;
                   #  # ]
    4291   [ #  #  #  #  :          0 :                 fused_response->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    4292   [ #  #  #  #  :          0 :                 _nvmf_request_complete(req->qpair->first_fused_req);
          #  #  #  #  #  
                      # ]
    4293   [ #  #  #  #  :          0 :                 req->qpair->first_fused_req = NULL;
          #  #  #  #  #  
                      # ]
    4294                 :          0 :         }
    4295                 :            : 
    4296         [ +  + ]:   23850892 :         if (spdk_nvmf_request_using_zcopy(req)) {
    4297   [ -  +  -  +  :     737640 :                 assert(req->zcopy_phase == NVMF_ZCOPY_PHASE_INIT);
             +  -  #  # ]
    4298                 :     737640 :                 return nvmf_bdev_ctrlr_zcopy_start(bdev, desc, ch, req);
    4299                 :            :         } else {
    4300   [ +  +  +  +  :   23113252 :                 switch (cmd->opc) {
          +  +  +  +  +  
                   -  - ]
    4301                 :   13328605 :                 case SPDK_NVME_OPC_READ:
    4302                 :   13400110 :                         return nvmf_bdev_ctrlr_read_cmd(bdev, desc, ch, req);
    4303                 :    8001519 :                 case SPDK_NVME_OPC_WRITE:
    4304                 :    8073024 :                         return nvmf_bdev_ctrlr_write_cmd(bdev, desc, ch, req);
    4305                 :       5537 :                 case SPDK_NVME_OPC_COMPARE:
    4306                 :       5537 :                         return nvmf_bdev_ctrlr_compare_cmd(bdev, desc, ch, req);
    4307                 :      11824 :                 case SPDK_NVME_OPC_WRITE_ZEROES:
    4308                 :      11824 :                         return nvmf_bdev_ctrlr_write_zeroes_cmd(bdev, desc, ch, req);
    4309                 :       8698 :                 case SPDK_NVME_OPC_FLUSH:
    4310                 :       8698 :                         return nvmf_bdev_ctrlr_flush_cmd(bdev, desc, ch, req);
    4311                 :      46980 :                 case SPDK_NVME_OPC_DATASET_MANAGEMENT:
    4312                 :      46980 :                         return nvmf_bdev_ctrlr_dsm_cmd(bdev, desc, ch, req);
    4313                 :      22685 :                 case SPDK_NVME_OPC_RESERVATION_REGISTER:
    4314                 :            :                 case SPDK_NVME_OPC_RESERVATION_ACQUIRE:
    4315                 :            :                 case SPDK_NVME_OPC_RESERVATION_RELEASE:
    4316                 :            :                 case SPDK_NVME_OPC_RESERVATION_REPORT:
    4317   [ #  #  #  #  :      22685 :                         spdk_thread_send_msg(ctrlr->subsys->thread, nvmf_ns_reservation_request, req);
             #  #  #  # ]
    4318                 :      22685 :                         return SPDK_NVMF_REQUEST_EXEC_STATUS_ASYNCHRONOUS;
    4319                 :       5563 :                 case SPDK_NVME_OPC_COPY:
    4320                 :       5563 :                         return nvmf_bdev_ctrlr_copy_cmd(bdev, desc, ch, req);
    4321                 :    1538831 :                 default:
    4322                 :    1538831 :                         return nvmf_bdev_ctrlr_nvme_passthru_io(bdev, desc, ch, req);
    4323                 :            :                 }
    4324                 :            :         }
    4325                 :     143021 : }
    4326                 :            : 
    4327                 :            : static void
    4328                 :   25241922 : nvmf_qpair_request_cleanup(struct spdk_nvmf_qpair *qpair)
    4329                 :            : {
    4330   [ +  +  +  -  :   25241922 :         if (spdk_unlikely(qpair->state == SPDK_NVMF_QPAIR_DEACTIVATING)) {
                   +  + ]
    4331   [ +  +  +  -  :       8925 :                 assert(qpair->state_cb != NULL);
             +  -  #  # ]
    4332                 :            : 
    4333   [ +  +  +  -  :       8925 :                 if (TAILQ_EMPTY(&qpair->outstanding)) {
             +  -  +  + ]
    4334   [ +  -  +  -  :       2340 :                         qpair->state_cb(qpair->state_cb_arg, 0);
          -  +  +  -  +  
                -  +  - ]
    4335                 :        924 :                 }
    4336                 :       3693 :         }
    4337                 :   25241922 : }
    4338                 :            : 
    4339                 :            : int
    4340                 :       7801 : spdk_nvmf_request_free(struct spdk_nvmf_request *req)
    4341                 :            : {
    4342   [ +  -  +  - ]:       7801 :         struct spdk_nvmf_qpair *qpair = req->qpair;
    4343                 :            : 
    4344   [ +  +  +  -  :       7801 :         TAILQ_REMOVE(&qpair->outstanding, req, link);
          +  -  +  +  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]
    4345         [ +  + ]:       7801 :         if (spdk_unlikely(nvmf_transport_req_free(req))) {
    4346                 :          0 :                 SPDK_ERRLOG("Unable to free transport level request resources.\n");
    4347                 :          0 :         }
    4348                 :            : 
    4349                 :       7801 :         nvmf_qpair_request_cleanup(qpair);
    4350                 :            : 
    4351                 :       7801 :         return 0;
    4352                 :          0 : }
    4353                 :            : 
    4354                 :            : static void
    4355                 :   25234121 : _nvmf_request_complete(void *ctx)
    4356                 :            : {
    4357                 :   25234121 :         struct spdk_nvmf_request *req = ctx;
    4358   [ +  -  +  -  :   25234121 :         struct spdk_nvme_cpl *rsp = &req->rsp->nvme_cpl;
                   +  - ]
    4359                 :         33 :         struct spdk_nvmf_qpair *qpair;
    4360                 :   25234121 :         struct spdk_nvmf_subsystem_poll_group *sgroup = NULL;
    4361                 :         33 :         struct spdk_nvmf_subsystem_pg_ns_info *ns_info;
    4362                 :   25234121 :         bool is_aer = false;
    4363                 :         33 :         uint32_t nsid;
    4364                 :         33 :         bool paused;
    4365                 :         33 :         uint8_t opcode;
    4366                 :            : 
    4367   [ +  -  +  - ]:   25234121 :         rsp->sqid = 0;
    4368   [ +  -  +  -  :   25234121 :         rsp->status.p = 0;
                   +  - ]
    4369   [ +  -  +  -  :   25234121 :         rsp->cid = req->cmd->nvme_cmd.cid;
          +  -  +  -  +  
             -  +  -  +  
                      - ]
    4370   [ +  -  +  -  :   25234121 :         nsid = req->cmd->nvme_cmd.nsid;
          +  -  +  -  +  
                      - ]
    4371   [ +  -  +  -  :   25234121 :         opcode = req->cmd->nvmf_cmd.opcode;
          +  -  +  -  +  
                      - ]
    4372                 :            : 
    4373   [ +  -  +  - ]:   25234121 :         qpair = req->qpair;
    4374   [ +  +  +  -  :   25234121 :         if (spdk_likely(qpair->ctrlr)) {
                   +  + ]
    4375   [ +  -  +  -  :   25233547 :                 sgroup = &qpair->group->sgroups[qpair->ctrlr->subsys->id];
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]
    4376   [ +  +  #  # ]:   25233547 :                 assert(sgroup != NULL);
    4377   [ +  -  +  -  :   25233547 :                 is_aer = req->cmd->nvme_cmd.opc == SPDK_NVME_OPC_ASYNC_EVENT_REQUEST;
             +  -  +  - ]
    4378   [ +  +  +  -  :   25233547 :                 if (spdk_likely(qpair->qid != 0)) {
                   +  + ]
    4379   [ +  -  +  -  :   24699908 :                         qpair->group->stat.completed_nvme_io++;
             +  -  +  - ]
    4380                 :     144711 :                 }
    4381                 :            : 
    4382                 :            :                 /*
    4383                 :            :                  * Set the crd value.
    4384                 :            :                  * If the the IO has any error, and dnr (DoNotRetry) is not 1,
    4385                 :            :                  * and ACRE is enabled, we will set the crd to 1 to select the first CRDT.
    4386                 :            :                  */
    4387   [ +  +  +  +  :   25233547 :                 if (spdk_unlikely(spdk_nvme_cpl_is_error(rsp) &&
          +  +  +  +  +  
          +  +  +  +  +  
          +  -  +  -  +  
          -  +  +  +  -  
          +  -  +  -  +  
             -  +  -  -  
                      + ]
    4388                 :            :                                   rsp->status.dnr == 0 &&
    4389                 :            :                                   qpair->ctrlr->acre_enabled)) {
    4390   [ #  #  #  #  :          0 :                         rsp->status.crd = 1;
                   #  # ]
    4391                 :          0 :                 }
    4392         [ +  + ]:     163607 :         } else if (spdk_unlikely(nvmf_request_is_fabric_connect(req))) {
    4393                 :        562 :                 sgroup = nvmf_subsystem_pg_from_connect_cmd(req);
    4394                 :          8 :         }
    4395                 :            : 
    4396         [ +  + ]:   25234121 :         if (SPDK_DEBUGLOG_FLAG_ENABLED("nvmf")) {
    4397   [ #  #  #  # ]:          0 :                 spdk_nvme_print_completion(qpair->qid, rsp);
    4398                 :          0 :         }
    4399                 :            : 
    4400   [ +  +  +  +  :   25234121 :         switch (req->zcopy_phase) {
             -  +  +  -  
                      + ]
    4401                 :   23603298 :         case NVMF_ZCOPY_PHASE_NONE:
    4402   [ +  +  +  -  :   23766331 :                 TAILQ_REMOVE(&qpair->outstanding, req, link);
          +  -  +  +  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]
    4403                 :   23766331 :                 break;
    4404                 :     737656 :         case NVMF_ZCOPY_PHASE_INIT:
    4405   [ +  +  +  +  :     737664 :                 if (spdk_unlikely(spdk_nvme_cpl_is_error(rsp))) {
          +  -  +  +  +  
          -  +  -  +  -  
                   +  + ]
    4406   [ +  -  +  - ]:       7532 :                         req->zcopy_phase = NVMF_ZCOPY_PHASE_INIT_FAILED;
    4407   [ +  +  +  -  :       7532 :                         TAILQ_REMOVE(&qpair->outstanding, req, link);
          +  -  -  +  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]
    4408                 :          5 :                 } else {
    4409   [ +  -  +  - ]:     730132 :                         req->zcopy_phase = NVMF_ZCOPY_PHASE_EXECUTE;
    4410                 :            :                 }
    4411                 :     737664 :                 break;
    4412                 :          0 :         case NVMF_ZCOPY_PHASE_EXECUTE:
    4413                 :          0 :                 break;
    4414                 :     730124 :         case NVMF_ZCOPY_PHASE_END_PENDING:
    4415   [ +  +  +  -  :     730126 :                 TAILQ_REMOVE(&qpair->outstanding, req, link);
          +  -  -  +  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]
    4416   [ +  -  +  - ]:     730126 :                 req->zcopy_phase = NVMF_ZCOPY_PHASE_COMPLETE;
    4417                 :     730126 :                 break;
    4418                 :          0 :         default:
    4419   [ #  #  #  # ]:          0 :                 SPDK_ERRLOG("Invalid ZCOPY phase %u\n", req->zcopy_phase);
    4420                 :          0 :                 break;
    4421                 :            :         }
    4422                 :            : 
    4423         [ +  + ]:   25234121 :         if (spdk_unlikely(nvmf_transport_req_complete(req))) {
    4424                 :          0 :                 SPDK_ERRLOG("Transport request completion error!\n");
    4425                 :          0 :         }
    4426                 :            : 
    4427                 :            :         /* AER cmd is an exception */
    4428   [ +  +  +  +  :   25234121 :         if (spdk_likely(sgroup && !is_aer)) {
                   +  + ]
    4429   [ +  +  +  + ]:   25225250 :                 if (spdk_unlikely(opcode == SPDK_NVME_OPC_FABRIC ||
    4430                 :            :                                   nvmf_qpair_is_admin_queue(qpair))) {
    4431   [ +  +  +  -  :     547400 :                         assert(sgroup->mgmt_io_outstanding > 0);
             +  -  #  # ]
    4432         [ +  - ]:     547400 :                         sgroup->mgmt_io_outstanding--;
    4433                 :      19232 :                 } else {
    4434   [ +  +  +  -  :   24677857 :                         if (req->zcopy_phase == NVMF_ZCOPY_PHASE_NONE ||
             +  +  +  + ]
    4435   [ +  +  +  -  :    1467784 :                             req->zcopy_phase == NVMF_ZCOPY_PHASE_COMPLETE ||
                   +  + ]
    4436   [ +  +  +  - ]:     737658 :                             req->zcopy_phase == NVMF_ZCOPY_PHASE_INIT_FAILED) {
    4437                 :            :                                 /* End of request */
    4438                 :            : 
    4439                 :            :                                 /* NOTE: This implicitly also checks for 0, since 0 - 1 wraps around to UINT32_MAX. */
    4440   [ +  +  +  -  :   23947718 :                                 if (spdk_likely(nsid - 1 < sgroup->num_ns)) {
                   +  + ]
    4441   [ +  -  +  -  :   23946957 :                                         sgroup->ns_info[nsid - 1].io_outstanding--;
             +  -  +  - ]
    4442                 :     143020 :                                 }
    4443                 :     143776 :                         }
    4444                 :            :                 }
    4445                 :            : 
    4446   [ +  +  +  -  :   25225250 :                 if (spdk_unlikely(sgroup->state == SPDK_NVMF_SUBSYSTEM_PAUSING &&
          +  -  #  #  #  
                #  -  + ]
    4447                 :            :                                   sgroup->mgmt_io_outstanding == 0)) {
    4448                 :      76477 :                         paused = true;
    4449   [ +  +  #  #  :      88881 :                         for (nsid = 0; nsid < sgroup->num_ns; nsid++) {
                   #  # ]
    4450   [ #  #  #  #  :      87656 :                                 ns_info = &sgroup->ns_info[nsid];
                   #  # ]
    4451                 :            : 
    4452   [ +  +  #  #  :      87656 :                                 if (ns_info->state == SPDK_NVMF_SUBSYSTEM_PAUSING &&
             #  #  #  # ]
    4453   [ +  +  #  # ]:      76476 :                                     ns_info->io_outstanding > 0) {
    4454                 :      75252 :                                         paused = false;
    4455                 :      75252 :                                         break;
    4456                 :            :                                 }
    4457                 :          0 :                         }
    4458                 :            : 
    4459   [ +  +  #  # ]:      76477 :                         if (paused) {
    4460   [ #  #  #  # ]:       1225 :                                 sgroup->state = SPDK_NVMF_SUBSYSTEM_PAUSED;
    4461   [ #  #  #  #  :       1225 :                                 sgroup->cb_fn(sgroup->cb_arg, 0);
          #  #  #  #  #  
                #  #  # ]
    4462   [ #  #  #  # ]:       1225 :                                 sgroup->cb_fn = NULL;
    4463   [ #  #  #  # ]:       1225 :                                 sgroup->cb_arg = NULL;
    4464                 :          0 :                         }
    4465                 :          0 :                 }
    4466                 :            : 
    4467                 :     163011 :         }
    4468                 :            : 
    4469                 :   25234121 :         nvmf_qpair_request_cleanup(qpair);
    4470                 :   25234121 : }
    4471                 :            : 
    4472                 :            : int
    4473                 :   22989547 : spdk_nvmf_request_complete(struct spdk_nvmf_request *req)
    4474                 :            : {
    4475   [ +  -  +  - ]:   22989547 :         struct spdk_nvmf_qpair *qpair = req->qpair;
    4476                 :            : 
    4477   [ +  -  +  -  :   22989547 :         spdk_thread_exec_msg(qpair->group->thread, _nvmf_request_complete, req);
             +  -  +  - ]
    4478                 :            : 
    4479                 :   22989547 :         return 0;
    4480                 :         17 : }
    4481                 :            : 
    4482                 :            : void
    4483                 :       1278 : spdk_nvmf_request_exec_fabrics(struct spdk_nvmf_request *req)
    4484                 :            : {
    4485   [ +  -  +  - ]:       1278 :         struct spdk_nvmf_qpair *qpair = req->qpair;
    4486                 :       1278 :         struct spdk_nvmf_subsystem_poll_group *sgroup = NULL;
    4487                 :          0 :         enum spdk_nvmf_request_exec_status status;
    4488                 :            : 
    4489   [ +  +  +  -  :       1278 :         if (qpair->ctrlr) {
                   +  + ]
    4490   [ +  -  +  -  :        940 :                 sgroup = &qpair->group->sgroups[qpair->ctrlr->subsys->id];
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]
    4491         [ +  + ]:        449 :         } else if (spdk_unlikely(nvmf_request_is_fabric_connect(req))) {
    4492                 :        338 :                 sgroup = nvmf_subsystem_pg_from_connect_cmd(req);
    4493                 :         81 :         }
    4494                 :            : 
    4495   [ +  +  #  # ]:       1278 :         assert(sgroup != NULL);
    4496         [ +  - ]:       1278 :         sgroup->mgmt_io_outstanding++;
    4497                 :            : 
    4498                 :            :         /* Place the request on the outstanding list so we can keep track of it */
    4499   [ +  -  +  -  :       1278 :         TAILQ_INSERT_TAIL(&qpair->outstanding, req, link);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
    4500                 :            : 
    4501   [ +  +  +  -  :       1278 :         assert(req->cmd->nvmf_cmd.opcode == SPDK_NVME_OPC_FABRIC);
          +  -  +  -  +  
             -  +  -  #  
                      # ]
    4502                 :       1278 :         status = nvmf_ctrlr_process_fabrics_cmd(req);
    4503                 :            : 
    4504         [ +  + ]:       1278 :         if (status == SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE) {
    4505                 :        940 :                 _nvmf_request_complete(req);
    4506                 :        111 :         }
    4507                 :       1278 : }
    4508                 :            : 
    4509                 :            : static bool
    4510                 :   24618403 : nvmf_check_subsystem_active(struct spdk_nvmf_request *req)
    4511                 :            : {
    4512   [ +  -  +  - ]:   24618403 :         struct spdk_nvmf_qpair *qpair = req->qpair;
    4513                 :   24618403 :         struct spdk_nvmf_subsystem_poll_group *sgroup = NULL;
    4514                 :         15 :         struct spdk_nvmf_subsystem_pg_ns_info *ns_info;
    4515                 :         15 :         uint32_t nsid;
    4516                 :            : 
    4517   [ +  +  +  -  :   24618403 :         if (spdk_likely(qpair->ctrlr)) {
                   +  + ]
    4518   [ +  -  +  -  :   24607639 :                 sgroup = &qpair->group->sgroups[qpair->ctrlr->subsys->id];
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]
    4519   [ +  +  #  # ]:   24607639 :                 assert(sgroup != NULL);
    4520         [ +  + ]:     175442 :         } else if (spdk_unlikely(nvmf_request_is_fabric_connect(req))) {
    4521                 :      10758 :                 sgroup = nvmf_subsystem_pg_from_connect_cmd(req);
    4522                 :       1846 :         }
    4523                 :            : 
    4524                 :            :         /* Check if the subsystem is paused (if there is a subsystem) */
    4525         [ +  + ]:   24618403 :         if (spdk_likely(sgroup != NULL)) {
    4526   [ +  +  +  +  :   24618397 :                 if (spdk_unlikely(req->cmd->nvmf_cmd.opcode == SPDK_NVME_OPC_FABRIC ||
          +  -  +  -  +  
             -  +  +  +  
                      + ]
    4527                 :            :                                   nvmf_qpair_is_admin_queue(qpair))) {
    4528   [ +  +  +  -  :     554681 :                         if (sgroup->state != SPDK_NVMF_SUBSYSTEM_ACTIVE) {
                   -  + ]
    4529                 :            :                                 /* The subsystem is not currently active. Queue this request. */
    4530   [ #  #  #  #  :        141 :                                 TAILQ_INSERT_TAIL(&sgroup->queued, req, link);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
    4531                 :        141 :                                 return false;
    4532                 :            :                         }
    4533         [ +  - ]:     554540 :                         sgroup->mgmt_io_outstanding++;
    4534                 :      22745 :                 } else {
    4535   [ +  -  +  -  :   24063716 :                         nsid = req->cmd->nvme_cmd.nsid;
          +  -  +  -  +  
                      - ]
    4536                 :            : 
    4537                 :            :                         /* NOTE: This implicitly also checks for 0, since 0 - 1 wraps around to UINT32_MAX. */
    4538   [ +  +  +  -  :   24063716 :                         if (spdk_unlikely(nsid - 1 >= sgroup->num_ns)) {
                   +  + ]
    4539   [ +  -  +  -  :        761 :                                 req->rsp->nvme_cpl.status.sct = SPDK_NVME_SCT_GENERIC;
          +  -  +  -  +  
                -  +  - ]
    4540   [ +  -  +  -  :        761 :                                 req->rsp->nvme_cpl.status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
          +  -  +  -  +  
                -  +  - ]
    4541   [ +  -  +  -  :        761 :                                 req->rsp->nvme_cpl.status.dnr = 1;
          +  -  +  -  +  
                -  +  - ]
    4542   [ +  -  +  -  :        761 :                                 TAILQ_INSERT_TAIL(&qpair->outstanding, req, link);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
    4543                 :        761 :                                 _nvmf_request_complete(req);
    4544                 :        761 :                                 return false;
    4545                 :            :                         }
    4546                 :            : 
    4547   [ +  -  +  -  :   24062955 :                         ns_info = &sgroup->ns_info[nsid - 1];
                   +  - ]
    4548   [ +  +  +  -  :   24062955 :                         if (spdk_unlikely(ns_info->channel == NULL)) {
                   +  + ]
    4549                 :            :                                 /* This can can happen if host sends I/O to a namespace that is
    4550                 :            :                                  * in the process of being added, but before the full addition
    4551                 :            :                                  * process is complete.  Report invalid namespace in that case.
    4552                 :            :                                  */
    4553   [ +  -  +  -  :     182281 :                                 req->rsp->nvme_cpl.status.sct = SPDK_NVME_SCT_GENERIC;
          +  -  +  -  +  
                -  +  - ]
    4554   [ +  -  +  -  :     182281 :                                 req->rsp->nvme_cpl.status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
          +  -  +  -  +  
                -  +  - ]
    4555   [ +  -  +  -  :     182281 :                                 req->rsp->nvme_cpl.status.dnr = 1;
          +  -  +  -  +  
                -  +  - ]
    4556   [ +  -  +  -  :     182281 :                                 TAILQ_INSERT_TAIL(&qpair->outstanding, req, link);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
    4557         [ +  - ]:     182281 :                                 ns_info->io_outstanding++;
    4558                 :     182281 :                                 _nvmf_request_complete(req);
    4559                 :     182281 :                                 return false;
    4560                 :            :                         }
    4561                 :            : 
    4562   [ +  +  +  -  :   23880674 :                         if (spdk_unlikely(ns_info->state != SPDK_NVMF_SUBSYSTEM_ACTIVE)) {
                   +  + ]
    4563                 :            :                                 /* The namespace is not currently active. Queue this request. */
    4564   [ +  -  +  -  :     107846 :                                 TAILQ_INSERT_TAIL(&sgroup->queued, req, link);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
    4565                 :     107846 :                                 return false;
    4566                 :            :                         }
    4567                 :            : 
    4568         [ +  - ]:   23772828 :                         ns_info->io_outstanding++;
    4569                 :            :                 }
    4570                 :            : 
    4571   [ +  +  +  -  :   24327368 :                 if (spdk_unlikely(qpair->state != SPDK_NVMF_QPAIR_ACTIVE)) {
                   +  + ]
    4572   [ +  -  +  -  :          6 :                         req->rsp->nvme_cpl.status.sct = SPDK_NVME_SCT_GENERIC;
          +  -  +  -  +  
                -  +  - ]
    4573   [ +  -  +  -  :          6 :                         req->rsp->nvme_cpl.status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR;
          +  -  +  -  +  
                -  +  - ]
    4574   [ +  -  +  -  :          6 :                         TAILQ_INSERT_TAIL(&qpair->outstanding, req, link);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
    4575                 :          6 :                         _nvmf_request_complete(req);
    4576                 :          6 :                         return false;
    4577                 :            :                 }
    4578                 :     165765 :         }
    4579                 :            : 
    4580                 :   24327368 :         return true;
    4581                 :     166525 : }
    4582                 :            : 
    4583                 :            : void
    4584                 :   24618403 : spdk_nvmf_request_exec(struct spdk_nvmf_request *req)
    4585                 :            : {
    4586   [ +  -  +  - ]:   24618403 :         struct spdk_nvmf_qpair *qpair = req->qpair;
    4587   [ +  -  +  - ]:   24618403 :         struct spdk_nvmf_transport *transport = qpair->transport;
    4588                 :         15 :         enum spdk_nvmf_request_exec_status status;
    4589                 :            : 
    4590         [ +  + ]:   24618403 :         if (spdk_unlikely(!nvmf_check_subsystem_active(req))) {
    4591                 :     291035 :                 return;
    4592                 :            :         }
    4593                 :            : 
    4594         [ +  + ]:   24327368 :         if (SPDK_DEBUGLOG_FLAG_ENABLED("nvmf")) {
    4595   [ #  #  #  #  :          0 :                 spdk_nvme_print_command(qpair->qid, &req->cmd->nvme_cmd);
          #  #  #  #  #  
                      # ]
    4596                 :          0 :         }
    4597                 :            : 
    4598                 :            :         /* Place the request on the outstanding list so we can keep track of it */
    4599   [ +  -  +  -  :   24327368 :         TAILQ_INSERT_TAIL(&qpair->outstanding, req, link);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
    4600                 :            : 
    4601   [ +  +  +  +  :   24327368 :         if (spdk_unlikely((req->cmd->nvmf_cmd.opcode == SPDK_NVME_OPC_FABRIC) &&
          +  -  +  -  +  
          -  +  +  +  -  
          +  -  +  -  +  
                -  +  + ]
    4602                 :            :                           spdk_nvme_trtype_is_fabrics(transport->ops->type))) {
    4603                 :     102048 :                 status = nvmf_ctrlr_process_fabrics_cmd(req);
    4604         [ +  + ]:   24235474 :         } else if (spdk_unlikely(nvmf_qpair_is_admin_queue(qpair))) {
    4605                 :     452492 :                 status = nvmf_ctrlr_process_admin_cmd(req);
    4606                 :      12591 :         } else {
    4607                 :   23772828 :                 status = nvmf_ctrlr_process_io_cmd(req);
    4608                 :            :         }
    4609                 :            : 
    4610         [ +  + ]:   24327368 :         if (status == SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE) {
    4611                 :    2058394 :                 _nvmf_request_complete(req);
    4612                 :      17017 :         }
    4613         [ -  + ]:     166525 : }
    4614                 :            : 
    4615                 :            : static bool
    4616                 :     646126 : nvmf_ctrlr_get_dif_ctx(struct spdk_nvmf_ctrlr *ctrlr, struct spdk_nvme_cmd *cmd,
    4617                 :            :                        struct spdk_dif_ctx *dif_ctx)
    4618                 :            : {
    4619                 :          4 :         struct spdk_nvmf_ns *ns;
    4620                 :          4 :         struct spdk_bdev *bdev;
    4621                 :            : 
    4622   [ +  -  -  + ]:     646126 :         if (ctrlr == NULL || cmd == NULL) {
    4623                 :          0 :                 return false;
    4624                 :            :         }
    4625                 :            : 
    4626   [ +  -  +  -  :     646126 :         ns = _nvmf_subsystem_get_ns(ctrlr->subsys, cmd->nsid);
             +  -  +  - ]
    4627   [ +  +  +  +  :     646126 :         if (ns == NULL || ns->bdev == NULL) {
             +  -  -  + ]
    4628                 :         12 :                 return false;
    4629                 :            :         }
    4630                 :            : 
    4631   [ +  -  +  - ]:     646114 :         bdev = ns->bdev;
    4632                 :            : 
    4633   [ +  +  +  + ]:     646114 :         switch (cmd->opc) {
    4634                 :     646107 :         case SPDK_NVME_OPC_READ:
    4635                 :            :         case SPDK_NVME_OPC_WRITE:
    4636                 :            :         case SPDK_NVME_OPC_COMPARE:
    4637                 :     646108 :                 return nvmf_bdev_ctrlr_get_dif_ctx(bdev, cmd, dif_ctx);
    4638                 :          5 :         default:
    4639                 :          6 :                 break;
    4640                 :            :         }
    4641                 :            : 
    4642                 :          6 :         return false;
    4643                 :          4 : }
    4644                 :            : 
    4645                 :            : bool
    4646                 :   22607551 : spdk_nvmf_request_get_dif_ctx(struct spdk_nvmf_request *req, struct spdk_dif_ctx *dif_ctx)
    4647                 :            : {
    4648   [ +  -  +  - ]:   22607551 :         struct spdk_nvmf_qpair *qpair = req->qpair;
    4649   [ +  -  +  - ]:   22607551 :         struct spdk_nvmf_ctrlr *ctrlr = qpair->ctrlr;
    4650                 :            : 
    4651   [ +  +  +  +  :   22607551 :         if (spdk_likely(ctrlr == NULL || !ctrlr->dif_insert_or_strip)) {
          +  +  +  -  +  
                      + ]
    4652                 :   21960726 :                 return false;
    4653                 :            :         }
    4654                 :            : 
    4655   [ +  +  +  -  :     646825 :         if (spdk_unlikely(qpair->state != SPDK_NVMF_QPAIR_ACTIVE)) {
                   +  + ]
    4656                 :          6 :                 return false;
    4657                 :            :         }
    4658                 :            : 
    4659   [ +  +  +  -  :     646819 :         if (spdk_unlikely(req->cmd->nvmf_cmd.opcode == SPDK_NVME_OPC_FABRIC)) {
          +  -  +  -  +  
                -  +  + ]
    4660                 :        276 :                 return false;
    4661                 :            :         }
    4662                 :            : 
    4663         [ +  + ]:     646543 :         if (spdk_unlikely(nvmf_qpair_is_admin_queue(qpair))) {
    4664                 :        417 :                 return false;
    4665                 :            :         }
    4666                 :            : 
    4667   [ +  -  +  -  :     646126 :         return nvmf_ctrlr_get_dif_ctx(ctrlr, &req->cmd->nvme_cmd, dif_ctx);
                   +  - ]
    4668                 :      23456 : }
    4669                 :            : 
    4670                 :            : void
    4671                 :          8 : spdk_nvmf_set_custom_admin_cmd_hdlr(uint8_t opc, spdk_nvmf_custom_cmd_hdlr hdlr)
    4672                 :            : {
    4673   [ +  -  +  -  :          8 :         g_nvmf_custom_admin_cmd_hdlrs[opc].hdlr = hdlr;
             +  -  +  - ]
    4674                 :          8 : }
    4675                 :            : 
    4676                 :            : static int
    4677                 :          0 : nvmf_passthru_admin_cmd_for_bdev_nsid(struct spdk_nvmf_request *req, uint32_t bdev_nsid)
    4678                 :            : {
    4679                 :          0 :         struct spdk_bdev *bdev;
    4680                 :          0 :         struct spdk_bdev_desc *desc;
    4681                 :          0 :         struct spdk_io_channel *ch;
    4682                 :          0 :         struct spdk_nvme_cpl *response = spdk_nvmf_request_get_response(req);
    4683                 :          0 :         int rc;
    4684                 :            : 
    4685                 :          0 :         rc = spdk_nvmf_request_get_bdev(bdev_nsid, req, &bdev, &desc, &ch);
    4686         [ #  # ]:          0 :         if (rc) {
    4687   [ #  #  #  #  :          0 :                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    4688   [ #  #  #  #  :          0 :                 response->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
                   #  # ]
    4689                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    4690                 :            :         }
    4691                 :          0 :         return spdk_nvmf_bdev_ctrlr_nvme_passthru_admin(bdev, desc, ch, req, NULL);
    4692                 :          0 : }
    4693                 :            : 
    4694                 :            : static int
    4695                 :          0 : nvmf_passthru_admin_cmd(struct spdk_nvmf_request *req)
    4696                 :            : {
    4697                 :          0 :         struct spdk_nvme_cmd *cmd = spdk_nvmf_request_get_cmd(req);
    4698                 :          0 :         uint32_t bdev_nsid;
    4699                 :            : 
    4700   [ #  #  #  #  :          0 :         if (g_nvmf_custom_admin_cmd_hdlrs[cmd->opc].nsid != 0) {
          #  #  #  #  #  
                #  #  # ]
    4701   [ #  #  #  #  :          0 :                 bdev_nsid = g_nvmf_custom_admin_cmd_hdlrs[cmd->opc].nsid;
          #  #  #  #  #  
                      # ]
    4702                 :          0 :         } else {
    4703   [ #  #  #  # ]:          0 :                 bdev_nsid = cmd->nsid;
    4704                 :            :         }
    4705                 :            : 
    4706                 :          0 :         return nvmf_passthru_admin_cmd_for_bdev_nsid(req, bdev_nsid);
    4707                 :          0 : }
    4708                 :            : 
    4709                 :            : int
    4710                 :          0 : nvmf_passthru_admin_cmd_for_ctrlr(struct spdk_nvmf_request *req, struct spdk_nvmf_ctrlr *ctrlr)
    4711                 :            : {
    4712                 :          0 :         struct spdk_nvme_cpl *response = spdk_nvmf_request_get_response(req);
    4713                 :          0 :         struct spdk_nvmf_ns *ns;
    4714                 :            : 
    4715   [ #  #  #  # ]:          0 :         ns = spdk_nvmf_subsystem_get_first_ns(ctrlr->subsys);
    4716         [ #  # ]:          0 :         if (ns == NULL) {
    4717                 :            :                 /* Is there a better sc to use here? */
    4718   [ #  #  #  #  :          0 :                 response->status.sct = SPDK_NVME_SCT_GENERIC;
                   #  # ]
    4719   [ #  #  #  #  :          0 :                 response->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
                   #  # ]
    4720                 :          0 :                 return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
    4721                 :            :         }
    4722                 :            : 
    4723   [ #  #  #  # ]:          0 :         return nvmf_passthru_admin_cmd_for_bdev_nsid(req, ns->nsid);
    4724                 :          0 : }
    4725                 :            : 
    4726                 :            : void
    4727                 :          0 : spdk_nvmf_set_passthru_admin_cmd(uint8_t opc, uint32_t forward_nsid)
    4728                 :            : {
    4729   [ #  #  #  #  :          0 :         g_nvmf_custom_admin_cmd_hdlrs[opc].hdlr = nvmf_passthru_admin_cmd;
             #  #  #  # ]
    4730   [ #  #  #  #  :          0 :         g_nvmf_custom_admin_cmd_hdlrs[opc].nsid = forward_nsid;
             #  #  #  # ]
    4731                 :          0 : }
    4732                 :            : 
    4733                 :            : int
    4734                 :      43839 : spdk_nvmf_request_get_bdev(uint32_t nsid, struct spdk_nvmf_request *req,
    4735                 :            :                            struct spdk_bdev **bdev, struct spdk_bdev_desc **desc, struct spdk_io_channel **ch)
    4736                 :            : {
    4737   [ #  #  #  #  :      43839 :         struct spdk_nvmf_ctrlr *ctrlr = req->qpair->ctrlr;
             #  #  #  # ]
    4738                 :          0 :         struct spdk_nvmf_ns *ns;
    4739   [ #  #  #  #  :      43839 :         struct spdk_nvmf_poll_group *group = req->qpair->group;
             #  #  #  # ]
    4740                 :          0 :         struct spdk_nvmf_subsystem_pg_ns_info *ns_info;
    4741                 :            : 
    4742         [ #  # ]:      43839 :         *bdev = NULL;
    4743         [ #  # ]:      43839 :         *desc = NULL;
    4744         [ #  # ]:      43839 :         *ch = NULL;
    4745                 :            : 
    4746   [ #  #  #  # ]:      43839 :         ns = _nvmf_subsystem_get_ns(ctrlr->subsys, nsid);
    4747   [ +  -  -  +  :      43839 :         if (ns == NULL || ns->bdev == NULL) {
             #  #  #  # ]
    4748                 :          0 :                 return -EINVAL;
    4749                 :            :         }
    4750                 :            : 
    4751   [ +  -  +  -  :      43839 :         assert(group != NULL && group->sgroups != NULL);
             #  #  #  # ]
    4752   [ #  #  #  #  :      43839 :         ns_info = &group->sgroups[ctrlr->subsys->id].ns_info[nsid - 1];
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                      # ]
    4753   [ #  #  #  #  :      43839 :         *bdev = ns->bdev;
                   #  # ]
    4754   [ #  #  #  #  :      43839 :         *desc = ns->desc;
                   #  # ]
    4755   [ #  #  #  #  :      43839 :         *ch = ns_info->channel;
                   #  # ]
    4756                 :            : 
    4757                 :      43839 :         return 0;
    4758                 :          0 : }
    4759                 :            : 
    4760                 :          4 : struct spdk_nvmf_ctrlr *spdk_nvmf_request_get_ctrlr(struct spdk_nvmf_request *req)
    4761                 :            : {
    4762   [ #  #  #  #  :          4 :         return req->qpair->ctrlr;
             #  #  #  # ]
    4763                 :            : }
    4764                 :            : 
    4765                 :         16 : struct spdk_nvme_cmd *spdk_nvmf_request_get_cmd(struct spdk_nvmf_request *req)
    4766                 :            : {
    4767   [ #  #  #  #  :         16 :         return &req->cmd->nvme_cmd;
                   #  # ]
    4768                 :            : }
    4769                 :            : 
    4770                 :          4 : struct spdk_nvme_cpl *spdk_nvmf_request_get_response(struct spdk_nvmf_request *req)
    4771                 :            : {
    4772   [ #  #  #  #  :          4 :         return &req->rsp->nvme_cpl;
                   #  # ]
    4773                 :            : }
    4774                 :            : 
    4775                 :          4 : struct spdk_nvmf_subsystem *spdk_nvmf_request_get_subsystem(struct spdk_nvmf_request *req)
    4776                 :            : {
    4777   [ #  #  #  #  :          4 :         return req->qpair->ctrlr->subsys;
          #  #  #  #  #  
                #  #  # ]
    4778                 :            : }
    4779                 :            : 
    4780                 :            : size_t
    4781                 :          4 : spdk_nvmf_request_copy_from_buf(struct spdk_nvmf_request *req,
    4782                 :            :                                 void *buf, size_t buflen)
    4783                 :            : {
    4784                 :          0 :         struct spdk_iov_xfer ix;
    4785                 :            : 
    4786   [ #  #  #  #  :          4 :         spdk_iov_xfer_init(&ix, req->iov, req->iovcnt);
                   #  # ]
    4787                 :          4 :         return spdk_iov_xfer_from_buf(&ix, buf, buflen);
    4788                 :          0 : }
    4789                 :            : 
    4790                 :            : size_t
    4791                 :          4 : spdk_nvmf_request_copy_to_buf(struct spdk_nvmf_request *req,
    4792                 :            :                               void *buf, size_t buflen)
    4793                 :            : {
    4794                 :          0 :         struct spdk_iov_xfer ix;
    4795                 :            : 
    4796   [ #  #  #  #  :          4 :         spdk_iov_xfer_init(&ix, req->iov, req->iovcnt);
                   #  # ]
    4797                 :          4 :         return spdk_iov_xfer_to_buf(&ix, buf, buflen);
    4798                 :          0 : }
    4799                 :            : 
    4800                 :          0 : struct spdk_nvmf_subsystem *spdk_nvmf_ctrlr_get_subsystem(struct spdk_nvmf_ctrlr *ctrlr)
    4801                 :            : {
    4802   [ #  #  #  # ]:          0 :         return ctrlr->subsys;
    4803                 :            : }
    4804                 :            : 
    4805                 :            : uint16_t
    4806                 :          0 : spdk_nvmf_ctrlr_get_id(struct spdk_nvmf_ctrlr *ctrlr)
    4807                 :            : {
    4808   [ #  #  #  # ]:          0 :         return ctrlr->cntlid;
    4809                 :            : }
    4810                 :            : 
    4811                 :          0 : struct spdk_nvmf_request *spdk_nvmf_request_get_req_to_abort(struct spdk_nvmf_request *req)
    4812                 :            : {
    4813   [ #  #  #  # ]:          0 :         return req->req_to_abort;
    4814                 :            : }

Generated by: LCOV version 1.15