LCOV - code coverage report
Current view: top level - spdk/lib/scsi - port.c (source / functions) Hit Total Coverage
Test: Combined Lines: 37 44 84.1 %
Date: 2024-07-11 05:51:35 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 13 20 65.0 %

           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                 :            : #include "spdk/endian.h"
      10                 :            : 
      11                 :            : struct spdk_scsi_port *
      12                 :        555 : spdk_scsi_port_create(uint64_t id, uint16_t index, const char *name)
      13                 :            : {
      14                 :          0 :         struct spdk_scsi_port *port;
      15                 :            : 
      16                 :        555 :         port = calloc(1, sizeof(struct spdk_scsi_port));
      17                 :            : 
      18         [ -  + ]:        555 :         if (!port) {
      19                 :          0 :                 return NULL;
      20                 :            :         }
      21                 :            : 
      22         [ -  + ]:        555 :         if (scsi_port_construct(port, id, index, name) != 0) {
      23                 :          0 :                 spdk_scsi_port_free(&port);
      24                 :          0 :                 return NULL;
      25                 :            :         }
      26                 :            : 
      27                 :        555 :         return port;
      28                 :            : }
      29                 :            : 
      30                 :            : void
      31                 :        555 : spdk_scsi_port_free(struct spdk_scsi_port **pport)
      32                 :            : {
      33                 :            :         struct spdk_scsi_port *port;
      34                 :            : 
      35         [ -  + ]:        555 :         if (!pport) {
      36                 :          0 :                 return;
      37                 :            :         }
      38                 :            : 
      39                 :        555 :         port = *pport;
      40                 :        555 :         *pport = NULL;
      41                 :        555 :         free(port);
      42                 :            : }
      43                 :            : 
      44                 :            : int
      45                 :        981 : scsi_port_construct(struct spdk_scsi_port *port, uint64_t id, uint16_t index,
      46                 :            :                     const char *name)
      47                 :            : {
      48   [ +  +  +  + ]:        981 :         if (strlen(name) >= sizeof(port->name)) {
      49                 :          6 :                 SPDK_ERRLOG("port name too long\n");
      50                 :          6 :                 return -1;
      51                 :            :         }
      52                 :            : 
      53                 :        975 :         port->is_used = 1;
      54                 :        975 :         port->id = id;
      55                 :        975 :         port->index = index;
      56                 :        975 :         snprintf(port->name, sizeof(port->name), "%s", name);
      57                 :        975 :         return 0;
      58                 :            : }
      59                 :            : 
      60                 :            : void
      61                 :        160 : scsi_port_destruct(struct spdk_scsi_port *port)
      62                 :            : {
      63         [ -  + ]:        160 :         memset(port, 0, sizeof(struct spdk_scsi_port));
      64                 :        160 : }
      65                 :            : 
      66                 :            : const char *
      67                 :       1208 : spdk_scsi_port_get_name(const struct spdk_scsi_port *port)
      68                 :            : {
      69                 :       1208 :         return port->name;
      70                 :            : }
      71                 :            : 
      72                 :            : /*
      73                 :            :  * spc3r23 7.5.4.6 iSCSI initiator port TransportID,
      74                 :            :  * using code format 0x01.
      75                 :            :  */
      76                 :            : void
      77                 :        723 : spdk_scsi_port_set_iscsi_transport_id(struct spdk_scsi_port *port, char *iscsi_name,
      78                 :            :                                       uint64_t isid)
      79                 :            : {
      80                 :            :         struct spdk_scsi_iscsi_transport_id *data;
      81                 :            :         uint32_t len;
      82                 :            :         char *name;
      83                 :            : 
      84         [ -  + ]:        723 :         memset(port->transport_id, 0, sizeof(port->transport_id));
      85                 :        723 :         port->transport_id_len = 0;
      86                 :            : 
      87                 :        723 :         data = (struct spdk_scsi_iscsi_transport_id *)port->transport_id;
      88                 :            : 
      89                 :        723 :         data->protocol_id = (uint8_t)SPDK_SPC_PROTOCOL_IDENTIFIER_ISCSI;
      90                 :        723 :         data->format = 0x1;
      91                 :            : 
      92                 :        723 :         name = data->name;
      93         [ -  + ]:        723 :         len = snprintf(name, SPDK_SCSI_MAX_TRANSPORT_ID_LENGTH - sizeof(*data),
      94                 :            :                        "%s,i,0x%12.12" PRIx64, iscsi_name, isid);
      95                 :            :         do {
      96                 :       2722 :                 name[len++] = '\0';
      97         [ +  + ]:       2722 :         } while (len & 3);
      98                 :            : 
      99         [ -  + ]:        723 :         if (len < 20) {
     100                 :          0 :                 SPDK_ERRLOG("The length of Transport ID should >= 20 bytes\n");
     101                 :          0 :                 return;
     102                 :            :         }
     103                 :            : 
     104                 :        723 :         to_be16(&data->additional_len, len);
     105                 :        723 :         port->transport_id_len = len + sizeof(*data);
     106                 :            : }

Generated by: LCOV version 1.14