LCOV - code coverage report
Current view: top level - spdk/lib/scsi - dev.c (source / functions) Hit Total Coverage
Test: Combined Lines: 236 271 87.1 %
Date: 2024-11-18 22:20:41 Functions: 24 24 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 340 712 47.8 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
       3                 :            :  *   Copyright (C) 2016 Intel Corporation.
       4                 :            :  *   All rights reserved.
       5                 :            :  */
       6                 :            : 
       7                 :            : #include "scsi_internal.h"
       8                 :            : 
       9                 :            : static struct spdk_scsi_dev g_devs[SPDK_SCSI_MAX_DEVS];
      10                 :            : 
      11                 :            : struct spdk_scsi_dev *
      12                 :        134 : scsi_dev_get_list(void)
      13                 :            : {
      14                 :        134 :         return g_devs;
      15                 :            : }
      16                 :            : 
      17                 :            : static struct spdk_scsi_dev *
      18                 :        251 : allocate_dev(void)
      19                 :            : {
      20                 :          5 :         struct spdk_scsi_dev *dev;
      21                 :          5 :         int i;
      22                 :            : 
      23   [ +  -  +  - ]:       1602 :         for (i = 0; i < SPDK_SCSI_MAX_DEVS; i++) {
      24   [ +  -  +  - ]:       1602 :                 dev = &g_devs[i];
      25   [ +  +  +  -  :       1602 :                 if (!dev->is_allocated) {
                   +  + ]
      26         [ -  + ]:        251 :                         memset(dev, 0, sizeof(*dev));
      27   [ -  +  -  + ]:        251 :                         dev->id = i;
      28   [ -  +  -  + ]:        251 :                         dev->is_allocated = 1;
      29   [ -  +  -  +  :        251 :                         TAILQ_INIT(&dev->luns);
          -  +  -  +  -  
          +  -  +  -  +  
                   -  + ]
      30                 :        251 :                         return dev;
      31                 :            :                 }
      32                 :         10 :         }
      33                 :            : 
      34                 :          0 :         return NULL;
      35                 :          5 : }
      36                 :            : 
      37                 :            : static void
      38                 :        233 : free_dev(struct spdk_scsi_dev *dev)
      39                 :            : {
      40   [ +  +  +  -  :        233 :         assert(dev->is_allocated == 1);
             +  -  #  # ]
      41   [ +  +  +  +  :        233 :         assert(dev->removed == true);
          +  -  +  -  #  
                      # ]
      42                 :            : 
      43   [ +  -  +  - ]:        233 :         dev->is_allocated = 0;
      44                 :            : 
      45   [ +  +  +  -  :        233 :         if (dev->remove_cb) {
                   +  - ]
      46   [ #  #  #  #  :        158 :                 dev->remove_cb(dev->remove_ctx, 0);
          #  #  #  #  #  
                #  #  # ]
      47   [ #  #  #  # ]:        158 :                 dev->remove_cb = NULL;
      48                 :          0 :         }
      49                 :        233 : }
      50                 :            : 
      51                 :            : void
      52                 :        287 : spdk_scsi_dev_destruct(struct spdk_scsi_dev *dev,
      53                 :            :                        spdk_scsi_dev_destruct_cb_t cb_fn, void *cb_arg)
      54                 :            : {
      55                 :         11 :         struct spdk_scsi_lun *lun, *tmp_lun;
      56                 :            : 
      57         [ +  + ]:        287 :         if (dev == NULL) {
      58         [ +  + ]:          6 :                 if (cb_fn) {
      59   [ #  #  #  # ]:          0 :                         cb_fn(cb_arg, -EINVAL);
      60                 :          0 :                 }
      61                 :          6 :                 return;
      62                 :            :         }
      63                 :            : 
      64   [ +  +  +  +  :        281 :         if (dev->removed) {
             +  -  -  + ]
      65         [ #  # ]:          0 :                 if (cb_fn) {
      66   [ #  #  #  # ]:          0 :                         cb_fn(cb_arg, -EINVAL);
      67                 :          0 :                 }
      68                 :          0 :                 return;
      69                 :            :         }
      70                 :            : 
      71   [ +  -  +  - ]:        281 :         dev->removed = true;
      72   [ +  -  +  - ]:        281 :         dev->remove_cb = cb_fn;
      73   [ +  -  +  - ]:        281 :         dev->remove_ctx = cb_arg;
      74                 :            : 
      75   [ +  +  +  -  :        281 :         if (TAILQ_EMPTY(&dev->luns)) {
             +  -  +  + ]
      76                 :         90 :                 free_dev(dev);
      77                 :         90 :                 return;
      78                 :            :         }
      79                 :            : 
      80   [ +  +  +  -  :        586 :         TAILQ_FOREACH_SAFE(lun, &dev->luns, tailq, tmp_lun) {
          +  -  +  +  +  
          -  +  -  +  -  
                   +  + ]
      81                 :            :                 /*
      82                 :            :                  * LUN will remove itself from this dev when all outstanding IO
      83                 :            :                  * is done. When no more LUNs, dev will be deleted.
      84                 :            :                  */
      85                 :        395 :                 scsi_lun_destruct(lun);
      86                 :         11 :         }
      87         [ -  + ]:         11 : }
      88                 :            : 
      89                 :            : /*
      90                 :            :  * Search the lowest free LUN ID if the LUN ID is default, or check if the LUN ID is free otherwise,
      91                 :            :  * and also return the LUN which comes just before where we want to insert an new LUN.
      92                 :            :  */
      93                 :            : static int
      94                 :        625 : scsi_dev_find_free_lun(struct spdk_scsi_dev *dev, int lun_id,
      95                 :            :                        struct spdk_scsi_lun **prev_lun)
      96                 :            : {
      97                 :        625 :         struct spdk_scsi_lun *lun, *_prev_lun = NULL;
      98                 :            : 
      99         [ +  + ]:        625 :         if (prev_lun == NULL) {
     100                 :          0 :                 return -EINVAL;
     101                 :            :         }
     102                 :            : 
     103         [ +  + ]:        625 :         if (lun_id == -1) {
     104                 :         54 :                 lun_id = 0;
     105                 :            : 
     106   [ +  +  -  +  :       6390 :                 TAILQ_FOREACH(lun, &dev->luns, tailq) {
          -  +  +  +  +  
             -  +  -  +  
                      - ]
     107   [ +  +  +  -  :       6366 :                         if (lun->id > lun_id) {
                   +  + ]
     108                 :         30 :                                 break;
     109                 :            :                         }
     110   [ +  -  +  -  :       6336 :                         lun_id = lun->id + 1;
                   +  - ]
     111                 :       6336 :                         _prev_lun = lun;
     112                 :       1056 :                 }
     113                 :            : 
     114         [ +  + ]:         54 :                 if (lun_id >= SPDK_SCSI_DEV_MAX_LUN) {
     115                 :         12 :                         return -ENOSPC;
     116                 :            :                 }
     117                 :          7 :         } else {
     118   [ +  +  +  -  :       6759 :                 TAILQ_FOREACH(lun, &dev->luns, tailq) {
          +  -  +  +  +  
             -  +  -  +  
                      - ]
     119   [ +  +  +  -  :       6278 :                         if (lun->id == lun_id) {
                   +  + ]
     120                 :         36 :                                 return -EEXIST;
     121   [ +  +  +  -  :       6242 :                         } else if (lun->id > lun_id) {
                   +  + ]
     122                 :         54 :                                 break;
     123                 :            :                         }
     124                 :       6188 :                         _prev_lun = lun;
     125                 :        880 :                 }
     126                 :            :         }
     127                 :            : 
     128         [ +  - ]:        577 :         *prev_lun = _prev_lun;
     129                 :        577 :         return 0;
     130                 :         36 : }
     131                 :            : 
     132                 :            : int
     133                 :         34 : spdk_scsi_dev_add_lun(struct spdk_scsi_dev *dev, const char *bdev_name, int lun_id,
     134                 :            :                       void (*hotremove_cb)(const struct spdk_scsi_lun *, void *),
     135                 :            :                       void *hotremove_ctx)
     136                 :            : {
     137                 :         39 :         return spdk_scsi_dev_add_lun_ext(dev, bdev_name, lun_id,
     138                 :            :                                          NULL, NULL,
     139                 :          5 :                                          hotremove_cb, hotremove_ctx);
     140                 :            : }
     141                 :            : 
     142                 :            : int
     143                 :        487 : spdk_scsi_dev_add_lun_ext(struct spdk_scsi_dev *dev, const char *bdev_name, int lun_id,
     144                 :            :                           void (*resize_cb)(const struct spdk_scsi_lun *, void *),
     145                 :            :                           void *resize_ctx,
     146                 :            :                           void (*hotremove_cb)(const struct spdk_scsi_lun *, void *),
     147                 :            :                           void *hotremove_ctx)
     148                 :            : {
     149                 :        487 :         struct spdk_scsi_lun *lun, *prev_lun = NULL;
     150                 :         13 :         int rc;
     151                 :            : 
     152         [ -  + ]:        487 :         if (lun_id >= SPDK_SCSI_DEV_MAX_LUN) {
     153                 :          0 :                 SPDK_ERRLOG("LUN ID %d is more than the maximum.\n", lun_id);
     154                 :          0 :                 return -1;
     155                 :            :         }
     156                 :            : 
     157                 :        487 :         rc = scsi_dev_find_free_lun(dev, lun_id, &prev_lun);
     158         [ +  + ]:        487 :         if (rc != 0) {
     159         [ -  + ]:          6 :                 SPDK_ERRLOG("%s\n", rc == -EEXIST ? "LUN ID is duplicated" : "Free LUN ID is not found");
     160                 :          6 :                 return rc;
     161                 :            :         }
     162                 :            : 
     163                 :        481 :         lun = scsi_lun_construct(bdev_name, resize_cb, resize_ctx, hotremove_cb, hotremove_ctx);
     164         [ +  + ]:        481 :         if (lun == NULL) {
     165                 :          7 :                 return -1;
     166                 :            :         }
     167                 :            : 
     168   [ +  -  +  - ]:        474 :         lun->dev = dev;
     169                 :            : 
     170         [ +  + ]:        474 :         if (lun_id != -1) {
     171   [ +  -  +  - ]:        468 :                 lun->id = lun_id;
     172         [ +  + ]:         16 :         } else if (prev_lun == NULL) {
     173   [ -  +  -  + ]:          6 :                 lun->id = 0;
     174                 :          1 :         } else {
     175   [ #  #  #  #  :          0 :                 lun->id = prev_lun->id + 1;
          #  #  #  #  #  
                      # ]
     176                 :            :         }
     177                 :            : 
     178         [ +  + ]:        474 :         if (prev_lun == NULL) {
     179   [ +  +  +  -  :        274 :                 TAILQ_INSERT_HEAD(&dev->luns, lun, tailq);
          +  -  +  -  +  
          -  +  -  +  +  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  -  +  -  +  
          -  +  -  +  -  
          +  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     180                 :          9 :         } else {
     181   [ +  +  +  -  :        200 :                 TAILQ_INSERT_AFTER(&dev->luns, prev_lun, lun, tailq);
          +  -  +  -  +  
          -  +  -  -  +  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     182                 :            :         }
     183                 :        474 :         return 0;
     184                 :         13 : }
     185                 :            : 
     186                 :            : void
     187                 :        408 : spdk_scsi_dev_delete_lun(struct spdk_scsi_dev *dev,
     188                 :            :                          struct spdk_scsi_lun *lun)
     189                 :            : {
     190   [ +  +  #  #  :        408 :         TAILQ_REMOVE(&dev->luns, lun, tailq);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
     191                 :            : 
     192   [ -  +  +  +  :        408 :         if (dev->removed && TAILQ_EMPTY(&dev->luns)) {
          +  +  #  #  #  
          #  #  #  #  #  
                   #  # ]
     193                 :        143 :                 free_dev(dev);
     194                 :          0 :         }
     195                 :        408 : }
     196                 :            : 
     197                 :        212 : struct spdk_scsi_dev *spdk_scsi_dev_construct(const char *name, const char *bdev_name_list[],
     198                 :            :                 int *lun_id_list, int num_luns, uint8_t protocol_id,
     199                 :            :                 void (*hotremove_cb)(const struct spdk_scsi_lun *, void *),
     200                 :            :                 void *hotremove_ctx)
     201                 :            : {
     202                 :        221 :         return spdk_scsi_dev_construct_ext(name, bdev_name_list, lun_id_list,
     203                 :          9 :                                            num_luns, protocol_id,
     204                 :            :                                            NULL, NULL,
     205                 :          9 :                                            hotremove_cb, hotremove_ctx);
     206                 :            : }
     207                 :            : 
     208                 :        275 : struct spdk_scsi_dev *spdk_scsi_dev_construct_ext(const char *name, const char *bdev_name_list[],
     209                 :            :                 int *lun_id_list, int num_luns, uint8_t protocol_id,
     210                 :            :                 void (*resize_cb)(const struct spdk_scsi_lun *, void *),
     211                 :            :                 void *resize_ctx,
     212                 :            :                 void (*hotremove_cb)(const struct spdk_scsi_lun *, void *),
     213                 :            :                 void *hotremove_ctx)
     214                 :            : {
     215                 :          9 :         struct spdk_scsi_dev *dev;
     216                 :          9 :         size_t name_len;
     217                 :          9 :         bool found_lun_0;
     218                 :          9 :         int i, rc;
     219                 :            : 
     220         [ +  + ]:        275 :         name_len = strlen(name);
     221         [ +  + ]:        275 :         if (name_len > sizeof(dev->name) - 1) {
     222                 :          6 :                 SPDK_ERRLOG("device %s: name longer than maximum allowed length %zu\n",
     223                 :            :                             name, sizeof(dev->name) - 1);
     224                 :          6 :                 return NULL;
     225                 :            :         }
     226                 :            : 
     227         [ +  + ]:        269 :         if (num_luns == 0) {
     228                 :          6 :                 SPDK_ERRLOG("device %s: no LUNs specified\n", name);
     229                 :          6 :                 return NULL;
     230                 :            :         }
     231                 :            : 
     232                 :        263 :         found_lun_0 = false;
     233   [ +  +  +  - ]:        275 :         for (i = 0; i < num_luns; i++) {
     234   [ +  +  +  -  :        269 :                 if (lun_id_list[i] == 0) {
                   +  + ]
     235                 :        257 :                         found_lun_0 = true;
     236                 :        257 :                         break;
     237                 :            :                 }
     238                 :          2 :         }
     239                 :            : 
     240   [ +  +  +  + ]:        263 :         if (!found_lun_0) {
     241                 :          6 :                 SPDK_ERRLOG("device %s: no LUN 0 specified\n", name);
     242                 :          6 :                 return NULL;
     243                 :            :         }
     244                 :            : 
     245   [ +  +  +  - ]:        710 :         for (i = 0; i < num_luns; i++) {
     246   [ +  +  +  -  :        459 :                 if (bdev_name_list[i] == NULL) {
                   +  + ]
     247   [ +  -  +  - ]:          6 :                         SPDK_ERRLOG("NULL spdk_scsi_lun for LUN %d\n",
     248                 :            :                                     lun_id_list[i]);
     249                 :          6 :                         return NULL;
     250                 :            :                 }
     251                 :          8 :         }
     252                 :            : 
     253                 :        251 :         dev = allocate_dev();
     254         [ +  + ]:        251 :         if (dev == NULL) {
     255                 :          0 :                 return NULL;
     256                 :            :         }
     257                 :            : 
     258   [ -  +  -  +  :        251 :         memcpy(dev->name, name, name_len + 1);
                   -  + ]
     259                 :            : 
     260   [ -  +  -  + ]:        251 :         dev->num_ports = 0;
     261   [ -  +  -  + ]:        251 :         dev->protocol_id = protocol_id;
     262                 :            : 
     263   [ +  +  +  - ]:        703 :         for (i = 0; i < num_luns; i++) {
     264   [ +  -  +  -  :        453 :                 rc = spdk_scsi_dev_add_lun_ext(dev, bdev_name_list[i], lun_id_list[i],
             +  -  +  - ]
     265                 :          8 :                                                resize_cb, resize_ctx,
     266                 :          8 :                                                hotremove_cb, hotremove_ctx);
     267         [ +  + ]:        453 :                 if (rc < 0) {
     268                 :          1 :                         spdk_scsi_dev_destruct(dev, NULL, NULL);
     269                 :          1 :                         return NULL;
     270                 :            :                 }
     271                 :          8 :         }
     272                 :            : 
     273                 :        250 :         return dev;
     274                 :          9 : }
     275                 :            : 
     276                 :            : void
     277                 :         22 : spdk_scsi_dev_queue_mgmt_task(struct spdk_scsi_dev *dev,
     278                 :            :                               struct spdk_scsi_task *task)
     279                 :            : {
     280   [ +  +  #  # ]:         22 :         assert(task != NULL);
     281                 :            : 
     282   [ +  -  +  - ]:         22 :         scsi_lun_execute_mgmt_task(task->lun, task);
     283                 :         22 : }
     284                 :            : 
     285                 :            : void
     286                 :   28775830 : spdk_scsi_dev_queue_task(struct spdk_scsi_dev *dev,
     287                 :            :                          struct spdk_scsi_task *task)
     288                 :            : {
     289   [ +  +  #  # ]:   28775830 :         assert(task != NULL);
     290                 :            : 
     291   [ +  -  +  - ]:   28775830 :         scsi_lun_execute_task(task->lun, task);
     292                 :   28775830 : }
     293                 :            : 
     294                 :            : static struct spdk_scsi_port *
     295                 :        258 : scsi_dev_find_free_port(struct spdk_scsi_dev *dev)
     296                 :            : {
     297                 :          6 :         int i;
     298                 :            : 
     299   [ +  -  +  - ]:        266 :         for (i = 0; i < SPDK_SCSI_DEV_MAX_PORTS; i++) {
     300   [ +  +  +  -  :        266 :                 if (!dev->port[i].is_used) {
          +  -  +  -  +  
                -  +  + ]
     301   [ -  +  -  +  :        258 :                         return &dev->port[i];
                   -  + ]
     302                 :            :                 }
     303                 :          1 :         }
     304                 :            : 
     305                 :          0 :         return NULL;
     306                 :          6 : }
     307                 :            : 
     308                 :            : int
     309                 :        270 : spdk_scsi_dev_add_port(struct spdk_scsi_dev *dev, uint64_t id, const char *name)
     310                 :            : {
     311                 :          8 :         struct spdk_scsi_port *port;
     312                 :          8 :         int rc;
     313                 :            : 
     314   [ +  +  +  -  :        270 :         if (dev->num_ports == SPDK_SCSI_DEV_MAX_PORTS) {
                   +  + ]
     315                 :          6 :                 SPDK_ERRLOG("device already has %d ports\n", SPDK_SCSI_DEV_MAX_PORTS);
     316                 :          6 :                 return -1;
     317                 :            :         }
     318                 :            : 
     319                 :        264 :         port = spdk_scsi_dev_find_port_by_id(dev, id);
     320         [ +  + ]:        264 :         if (port != NULL) {
     321                 :          6 :                 SPDK_ERRLOG("device already has port(%" PRIu64 ")\n", id);
     322                 :          6 :                 return -1;
     323                 :            :         }
     324                 :            : 
     325                 :        258 :         port = scsi_dev_find_free_port(dev);
     326         [ +  + ]:        258 :         if (port == NULL) {
     327         [ #  # ]:          0 :                 assert(false);
     328                 :            :                 return -1;
     329                 :            :         }
     330                 :            : 
     331   [ +  -  +  - ]:        258 :         rc = scsi_port_construct(port, id, dev->num_ports, name);
     332         [ +  + ]:        258 :         if (rc != 0) {
     333                 :          6 :                 return rc;
     334                 :            :         }
     335                 :            : 
     336   [ +  -  +  - ]:        252 :         dev->num_ports++;
     337                 :        252 :         return 0;
     338                 :          8 : }
     339                 :            : 
     340                 :            : int
     341                 :        160 : spdk_scsi_dev_delete_port(struct spdk_scsi_dev *dev, uint64_t id)
     342                 :            : {
     343                 :          0 :         struct spdk_scsi_port *port;
     344                 :            : 
     345                 :        160 :         port = spdk_scsi_dev_find_port_by_id(dev, id);
     346         [ -  + ]:        160 :         if (port == NULL) {
     347                 :          0 :                 SPDK_ERRLOG("device does not have specified port(%" PRIu64 ")\n", id);
     348                 :          0 :                 return -1;
     349                 :            :         }
     350                 :            : 
     351                 :        160 :         scsi_port_destruct(port);
     352                 :            : 
     353   [ #  #  #  # ]:        160 :         dev->num_ports--;
     354                 :            : 
     355                 :        160 :         return 0;
     356                 :          0 : }
     357                 :            : 
     358                 :            : struct spdk_scsi_port *
     359                 :    5588976 : spdk_scsi_dev_find_port_by_id(struct spdk_scsi_dev *dev, uint64_t id)
     360                 :            : {
     361                 :         10 :         int i;
     362                 :            : 
     363   [ +  +  +  - ]:    5590058 :         for (i = 0; i < SPDK_SCSI_DEV_MAX_PORTS; i++) {
     364   [ +  +  +  -  :    5589788 :                 if (!dev->port[i].is_used) {
          +  -  +  -  +  
                -  +  + ]
     365                 :       1066 :                         continue;
     366                 :            :                 }
     367   [ +  +  +  -  :    5588722 :                 if (dev->port[i].id == id) {
          +  -  +  -  +  
                -  +  + ]
     368   [ +  -  +  -  :    5588706 :                         return &dev->port[i];
                   +  - ]
     369                 :            :                 }
     370                 :          2 :         }
     371                 :            : 
     372                 :            :         /* No matching port found. */
     373                 :        270 :         return NULL;
     374                 :         10 : }
     375                 :            : 
     376                 :            : void
     377                 :         63 : spdk_scsi_dev_free_io_channels(struct spdk_scsi_dev *dev)
     378                 :            : {
     379                 :          0 :         struct spdk_scsi_lun *lun, *tmp_lun;
     380                 :            : 
     381   [ +  +  #  #  :        126 :         TAILQ_FOREACH_SAFE(lun, &dev->luns, tailq, tmp_lun) {
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     382                 :         63 :                 scsi_lun_free_io_channel(lun);
     383                 :          0 :         }
     384                 :         63 : }
     385                 :            : 
     386                 :            : int
     387                 :         63 : spdk_scsi_dev_allocate_io_channels(struct spdk_scsi_dev *dev)
     388                 :            : {
     389                 :          0 :         struct spdk_scsi_lun *lun, *tmp_lun;
     390                 :          0 :         int rc;
     391                 :            : 
     392   [ +  +  #  #  :        126 :         TAILQ_FOREACH_SAFE(lun, &dev->luns, tailq, tmp_lun) {
          #  #  #  #  #  
          #  #  #  #  #  
                   #  # ]
     393                 :         63 :                 rc = scsi_lun_allocate_io_channel(lun);
     394         [ -  + ]:         63 :                 if (rc < 0) {
     395                 :          0 :                         spdk_scsi_dev_free_io_channels(dev);
     396                 :          0 :                         return -1;
     397                 :            :                 }
     398                 :          0 :         }
     399                 :            : 
     400                 :         63 :         return 0;
     401                 :          0 : }
     402                 :            : 
     403                 :            : const char *
     404                 :        760 : spdk_scsi_dev_get_name(const struct spdk_scsi_dev *dev)
     405                 :            : {
     406         [ #  # ]:        760 :         return dev->name;
     407                 :            : }
     408                 :            : 
     409                 :            : int
     410                 :        600 : spdk_scsi_dev_get_id(const struct spdk_scsi_dev *dev)
     411                 :            : {
     412   [ #  #  #  # ]:        600 :         return dev->id;
     413                 :            : }
     414                 :            : 
     415                 :            : struct spdk_scsi_lun *
     416                 :   65493840 : spdk_scsi_dev_get_lun(struct spdk_scsi_dev *dev, int lun_id)
     417                 :            : {
     418                 :          0 :         struct spdk_scsi_lun *lun;
     419                 :            : 
     420   [ +  +  #  #  :   87890088 :         TAILQ_FOREACH(lun, &dev->luns, tailq) {
          #  #  #  #  #  
             #  #  #  #  
                      # ]
     421   [ +  +  #  #  :   87803284 :                 if (lun->id == lun_id) {
                   #  # ]
     422         [ +  + ]:   65407036 :                         if (!spdk_scsi_lun_is_removing(lun)) {
     423                 :   65407030 :                                 return lun;
     424                 :            :                         } else {
     425                 :          6 :                                 return NULL;
     426                 :            :                         }
     427                 :            :                 }
     428                 :          0 :         }
     429                 :            : 
     430                 :      86804 :         return NULL;
     431                 :          0 : }
     432                 :            : 
     433                 :            : struct spdk_scsi_lun *
     434                 :       1355 : spdk_scsi_dev_get_first_lun(struct spdk_scsi_dev *dev)
     435                 :            : {
     436                 :          1 :         struct spdk_scsi_lun *lun;
     437                 :            : 
     438   [ +  -  +  -  :       1355 :         TAILQ_FOREACH(lun, &dev->luns, tailq) {
          +  -  +  -  #  
             #  #  #  #  
                      # ]
     439         [ +  + ]:       1355 :                 if (!spdk_scsi_lun_is_removing(lun)) {
     440                 :       1355 :                         return lun;
     441                 :            :                 }
     442                 :          0 :         }
     443                 :            : 
     444                 :          0 :         return NULL;
     445                 :          1 : }
     446                 :            : 
     447                 :            : struct spdk_scsi_lun *
     448                 :       1803 : spdk_scsi_dev_get_next_lun(struct spdk_scsi_lun *prev_lun)
     449                 :            : {
     450                 :          3 :         struct spdk_scsi_dev *dev;
     451                 :          3 :         struct spdk_scsi_lun *lun;
     452                 :            : 
     453         [ +  + ]:       1803 :         if (prev_lun == NULL) {
     454                 :          0 :                 return NULL;
     455                 :            :         }
     456                 :            : 
     457   [ +  -  +  - ]:       1803 :         dev = prev_lun->dev;
     458                 :            : 
     459   [ +  -  +  -  :       1803 :         lun = TAILQ_NEXT(prev_lun, tailq);
                   +  - ]
     460         [ +  + ]:       1803 :         if (lun == NULL) {
     461                 :       1355 :                 return NULL;
     462                 :            :         }
     463                 :            : 
     464   [ -  +  +  -  :        448 :         TAILQ_FOREACH_FROM(lun, &dev->luns, tailq) {
          #  #  #  #  -  
          +  #  #  #  #  
                   #  # ]
     465         [ +  + ]:        448 :                 if (!spdk_scsi_lun_is_removing(lun)) {
     466                 :        448 :                         break;
     467                 :            :                 }
     468                 :          0 :         }
     469                 :            : 
     470                 :        448 :         return lun;
     471                 :          3 : }
     472                 :            : 
     473                 :            : bool
     474                 :        570 : spdk_scsi_dev_has_pending_tasks(const struct spdk_scsi_dev *dev,
     475                 :            :                                 const struct spdk_scsi_port *initiator_port)
     476                 :            : {
     477                 :          7 :         struct spdk_scsi_lun *lun;
     478                 :            : 
     479   [ +  +  +  -  :       1280 :         TAILQ_FOREACH(lun, &dev->luns, tailq) {
          +  -  +  +  +  
             -  +  -  +  
                      - ]
     480   [ +  +  +  + ]:       1459 :                 if (scsi_lun_has_pending_tasks(lun, initiator_port) ||
     481                 :        722 :                     scsi_lun_has_pending_mgmt_tasks(lun, initiator_port)) {
     482                 :         30 :                         return true;
     483                 :            :                 }
     484                 :          1 :         }
     485                 :            : 
     486                 :        540 :         return false;
     487                 :          7 : }

Generated by: LCOV version 1.15