LCOV - code coverage report
Current view: top level - spdk/lib/sock - sock.c (source / functions) Hit Total Coverage
Test: Combined Lines: 489 574 85.2 %
Date: 2024-11-21 00:46:47 Functions: 47 48 97.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 942 1860 50.6 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2016 Intel Corporation. All rights reserved.
       3                 :            :  *   Copyright (c) 2020 Mellanox Technologies LTD. All rights reserved.
       4                 :            :  *   Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
       5                 :            :  */
       6                 :            : 
       7                 :            : #include "spdk/stdinc.h"
       8                 :            : 
       9                 :            : #include "spdk/sock.h"
      10                 :            : #include "spdk_internal/sock.h"
      11                 :            : #include "spdk/log.h"
      12                 :            : #include "spdk/env.h"
      13                 :            : #include "spdk/util.h"
      14                 :            : 
      15                 :            : #define SPDK_SOCK_DEFAULT_PRIORITY 0
      16                 :            : #define SPDK_SOCK_DEFAULT_ZCOPY true
      17                 :            : #define SPDK_SOCK_DEFAULT_ACK_TIMEOUT 0
      18                 :            : 
      19                 :            : #define SPDK_SOCK_OPTS_FIELD_OK(opts, field) (offsetof(struct spdk_sock_opts, field) + sizeof(opts->field) <= (opts->opts_size))
      20                 :            : 
      21                 :            : static STAILQ_HEAD(, spdk_net_impl) g_net_impls = STAILQ_HEAD_INITIALIZER(g_net_impls);
      22                 :            : static struct spdk_net_impl *g_default_impl;
      23                 :            : 
      24                 :            : struct spdk_sock_placement_id_entry {
      25                 :            :         int placement_id;
      26                 :            :         uint32_t ref;
      27                 :            :         struct spdk_sock_group_impl *group;
      28                 :            :         STAILQ_ENTRY(spdk_sock_placement_id_entry) link;
      29                 :            : };
      30                 :            : 
      31                 :            : static inline struct spdk_sock_group_impl *
      32                 :      28512 : sock_get_group_impl_from_group(struct spdk_sock *sock, struct spdk_sock_group *group)
      33                 :            : {
      34                 :      28512 :         struct spdk_sock_group_impl *group_impl = NULL;
      35                 :            : 
      36   [ +  -  +  -  :      28958 :         STAILQ_FOREACH_FROM(group_impl, &group->group_impls, link) {
          +  -  +  -  -  
          +  +  -  +  -  
                   +  - ]
      37   [ +  +  +  -  :      28958 :                 if (sock->net_impl == group_impl->net_impl) {
          +  -  +  -  +  
                      + ]
      38                 :      28512 :                         return group_impl;
      39                 :            :                 }
      40                 :         11 :         }
      41                 :          0 :         return NULL;
      42                 :       5924 : }
      43                 :            : 
      44                 :            : /* Called under map->mtx lock */
      45                 :            : static struct spdk_sock_placement_id_entry *
      46                 :         44 : _sock_map_entry_alloc(struct spdk_sock_map *map, int placement_id)
      47                 :            : {
      48                 :          7 :         struct spdk_sock_placement_id_entry *entry;
      49                 :            : 
      50                 :         44 :         entry = calloc(1, sizeof(*entry));
      51         [ +  + ]:         44 :         if (!entry) {
      52                 :          0 :                 SPDK_ERRLOG("Cannot allocate an entry for placement_id=%u\n", placement_id);
      53                 :          0 :                 return NULL;
      54                 :            :         }
      55                 :            : 
      56   [ -  +  -  + ]:         44 :         entry->placement_id = placement_id;
      57                 :            : 
      58   [ -  +  -  +  :         44 :         STAILQ_INSERT_TAIL(&map->entries, entry, link);
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
             +  -  +  -  
                      + ]
      59                 :            : 
      60                 :         44 :         return entry;
      61                 :          7 : }
      62                 :            : 
      63                 :            : int
      64                 :         71 : spdk_sock_map_insert(struct spdk_sock_map *map, int placement_id,
      65                 :            :                      struct spdk_sock_group_impl *group)
      66                 :            : {
      67                 :         11 :         struct spdk_sock_placement_id_entry *entry;
      68                 :         71 :         int rc = 0;
      69                 :            : 
      70   [ +  +  +  - ]:         71 :         pthread_mutex_lock(&map->mtx);
      71   [ +  +  +  -  :         80 :         STAILQ_FOREACH(entry, &map->entries, link) {
          +  -  +  +  +  
             -  +  -  +  
                      - ]
      72   [ +  +  +  -  :         44 :                 if (placement_id == entry->placement_id) {
                   +  + ]
      73                 :            :                         /* Can't set group to NULL if it is already not-NULL */
      74         [ +  + ]:         35 :                         if (group == NULL) {
      75   [ #  #  #  # ]:          0 :                                 rc = (entry->group == NULL) ? 0 : -EINVAL;
      76                 :          0 :                                 goto end;
      77                 :            :                         }
      78                 :            : 
      79   [ +  +  +  -  :         35 :                         if (entry->group == NULL) {
                   +  + ]
      80   [ -  +  -  + ]:          6 :                                 entry->group = group;
      81   [ +  +  +  -  :         30 :                         } else if (entry->group != group) {
                   +  + ]
      82                 :         12 :                                 rc = -EINVAL;
      83                 :         12 :                                 goto end;
      84                 :            :                         }
      85                 :            : 
      86         [ +  - ]:         23 :                         entry->ref++;
      87                 :         23 :                         goto end;
      88                 :            :                 }
      89                 :          1 :         }
      90                 :            : 
      91                 :         36 :         entry = _sock_map_entry_alloc(map, placement_id);
      92         [ +  + ]:         36 :         if (entry == NULL) {
      93                 :          0 :                 rc = -ENOMEM;
      94                 :          0 :                 goto end;
      95                 :            :         }
      96         [ +  + ]:         41 :         if (group) {
      97   [ +  -  +  - ]:         30 :                 entry->group = group;
      98         [ +  - ]:         30 :                 entry->ref++;
      99                 :          5 :         }
     100                 :          5 : end:
     101   [ +  +  +  - ]:         71 :         pthread_mutex_unlock(&map->mtx);
     102                 :            : 
     103                 :         82 :         return rc;
     104                 :         11 : }
     105                 :            : 
     106                 :            : void
     107                 :         23 : spdk_sock_map_release(struct spdk_sock_map *map, int placement_id)
     108                 :            : {
     109                 :          3 :         struct spdk_sock_placement_id_entry *entry;
     110                 :            : 
     111   [ +  +  +  - ]:         23 :         pthread_mutex_lock(&map->mtx);
     112   [ +  -  +  -  :         26 :         STAILQ_FOREACH(entry, &map->entries, link) {
          +  -  -  +  #  
             #  #  #  #  
                      # ]
     113   [ +  +  +  -  :         26 :                 if (placement_id == entry->placement_id) {
                   -  + ]
     114   [ +  +  +  -  :         23 :                         assert(entry->ref > 0);
             +  -  #  # ]
     115         [ +  - ]:         23 :                         entry->ref--;
     116                 :            : 
     117   [ +  +  +  -  :         23 :                         if (entry->ref == 0) {
                   +  + ]
     118   [ +  -  +  - ]:         14 :                                 entry->group = NULL;
     119                 :          2 :                         }
     120                 :         23 :                         break;
     121                 :            :                 }
     122                 :          0 :         }
     123                 :            : 
     124   [ +  +  +  - ]:         23 :         pthread_mutex_unlock(&map->mtx);
     125                 :         23 : }
     126                 :            : 
     127                 :            : int
     128                 :         77 : spdk_sock_map_lookup(struct spdk_sock_map *map, int placement_id,
     129                 :            :                      struct spdk_sock_group_impl **group, struct spdk_sock_group_impl *hint)
     130                 :            : {
     131                 :         12 :         struct spdk_sock_placement_id_entry *entry;
     132                 :            : 
     133         [ +  - ]:         77 :         *group = NULL;
     134   [ +  +  +  - ]:         77 :         pthread_mutex_lock(&map->mtx);
     135   [ +  +  +  -  :         86 :         STAILQ_FOREACH(entry, &map->entries, link) {
          +  -  +  +  +  
             -  +  -  +  
                      - ]
     136   [ +  +  +  -  :         72 :                 if (placement_id == entry->placement_id) {
                   +  + ]
     137   [ +  -  +  -  :         63 :                         *group = entry->group;
                   +  - ]
     138   [ +  +  +  + ]:         63 :                         if (*group != NULL) {
     139                 :            :                                 /* Return previously assigned sock_group */
     140   [ +  +  +  - ]:         51 :                                 pthread_mutex_unlock(&map->mtx);
     141                 :         51 :                                 return 0;
     142                 :            :                         }
     143                 :         12 :                         break;
     144                 :            :                 }
     145                 :          1 :         }
     146                 :            : 
     147                 :            :         /* No entry with assigned sock_group, nor hint to use */
     148         [ +  + ]:         26 :         if (hint == NULL) {
     149   [ +  +  +  - ]:         18 :                 pthread_mutex_unlock(&map->mtx);
     150                 :         18 :                 return -EINVAL;
     151                 :            :         }
     152                 :            : 
     153                 :            :         /* Create new entry if there is none with matching placement_id */
     154         [ +  + ]:          8 :         if (entry == NULL) {
     155                 :          8 :                 entry = _sock_map_entry_alloc(map, placement_id);
     156         [ +  + ]:          8 :                 if (entry == NULL) {
     157   [ #  #  #  # ]:          0 :                         pthread_mutex_unlock(&map->mtx);
     158                 :          0 :                         return -ENOMEM;
     159                 :            :                 }
     160                 :          1 :         }
     161                 :            : 
     162   [ +  -  +  - ]:          8 :         entry->group = hint;
     163   [ +  +  +  - ]:          8 :         pthread_mutex_unlock(&map->mtx);
     164                 :            : 
     165                 :          8 :         return 0;
     166                 :         12 : }
     167                 :            : 
     168                 :            : void
     169                 :       2787 : spdk_sock_map_cleanup(struct spdk_sock_map *map)
     170                 :            : {
     171                 :          7 :         struct spdk_sock_placement_id_entry *entry, *tmp;
     172                 :            : 
     173   [ +  +  +  - ]:       2787 :         pthread_mutex_lock(&map->mtx);
     174   [ +  +  +  -  :       2831 :         STAILQ_FOREACH_SAFE(entry, &map->entries, link, tmp) {
          +  -  +  +  +  
          -  +  -  +  -  
                   +  + ]
     175   [ +  -  +  +  :         44 :                 STAILQ_REMOVE(&map->entries, entry, spdk_sock_placement_id_entry, link);
          +  -  -  +  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  +  +  
          -  +  -  +  -  
          +  -  +  -  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
             #  #  #  # ]
     176                 :         44 :                 free(entry);
     177                 :          7 :         }
     178   [ +  +  +  - ]:       2787 :         pthread_mutex_unlock(&map->mtx);
     179                 :       2787 : }
     180                 :            : 
     181                 :            : int
     182                 :         30 : spdk_sock_map_find_free(struct spdk_sock_map *map)
     183                 :            : {
     184                 :          5 :         struct spdk_sock_placement_id_entry *entry;
     185                 :         30 :         int placement_id = -1;
     186                 :            : 
     187   [ +  +  +  - ]:         30 :         pthread_mutex_lock(&map->mtx);
     188   [ +  +  +  -  :         42 :         STAILQ_FOREACH(entry, &map->entries, link) {
          +  -  +  +  +  
             -  +  -  +  
                      - ]
     189   [ +  +  +  -  :         24 :                 if (entry->group == NULL) {
                   +  + ]
     190   [ +  -  +  - ]:         12 :                         placement_id = entry->placement_id;
     191                 :         12 :                         break;
     192                 :            :                 }
     193                 :          2 :         }
     194                 :            : 
     195   [ +  +  +  - ]:         30 :         pthread_mutex_unlock(&map->mtx);
     196                 :            : 
     197                 :         35 :         return placement_id;
     198                 :          5 : }
     199                 :            : 
     200                 :            : int
     201                 :       8384 : spdk_sock_get_optimal_sock_group(struct spdk_sock *sock, struct spdk_sock_group **group,
     202                 :            :                                  struct spdk_sock_group *hint)
     203                 :            : {
     204                 :          2 :         struct spdk_sock_group_impl *group_impl;
     205                 :       8384 :         struct spdk_sock_group_impl *hint_group_impl = NULL;
     206                 :            : 
     207   [ +  +  #  # ]:       8384 :         assert(group != NULL);
     208                 :            : 
     209         [ +  + ]:       8384 :         if (hint != NULL) {
     210                 :       8384 :                 hint_group_impl = sock_get_group_impl_from_group(sock, hint);
     211         [ +  + ]:       8384 :                 if (hint_group_impl == NULL) {
     212                 :          0 :                         return -EINVAL;
     213                 :            :                 }
     214                 :       1972 :         }
     215                 :            : 
     216   [ +  -  +  -  :       8384 :         group_impl = sock->net_impl->group_impl_get_optimal(sock, hint_group_impl);
          +  -  +  -  -  
                +  +  - ]
     217                 :            : 
     218         [ +  + ]:       8384 :         if (group_impl) {
     219   [ #  #  #  #  :          3 :                 *group = group_impl->group;
                   #  # ]
     220                 :          0 :         }
     221                 :            : 
     222                 :       8384 :         return 0;
     223                 :       1972 : }
     224                 :            : 
     225                 :            : int
     226                 :       8971 : spdk_sock_getaddr(struct spdk_sock *sock, char *saddr, int slen, uint16_t *sport,
     227                 :            :                   char *caddr, int clen, uint16_t *cport)
     228                 :            : {
     229   [ +  -  +  -  :       8971 :         return sock->net_impl->getaddr(sock, saddr, slen, sport, caddr, clen, cport);
          +  -  +  -  -  
                +  +  - ]
     230                 :            : }
     231                 :            : 
     232                 :            : const char *
     233                 :        600 : spdk_sock_get_impl_name(struct spdk_sock *sock)
     234                 :            : {
     235   [ #  #  #  #  :        600 :         return sock->net_impl->name;
             #  #  #  # ]
     236                 :            : }
     237                 :            : 
     238                 :            : void
     239                 :      45015 : spdk_sock_get_default_opts(struct spdk_sock_opts *opts)
     240                 :            : {
     241   [ +  +  #  # ]:      45015 :         assert(opts);
     242                 :            : 
     243   [ +  +  +  -  :      45015 :         if (SPDK_SOCK_OPTS_FIELD_OK(opts, priority)) {
                   +  + ]
     244   [ +  -  +  - ]:      45003 :                 opts->priority = SPDK_SOCK_DEFAULT_PRIORITY;
     245                 :       4028 :         }
     246                 :            : 
     247   [ +  +  +  -  :      45015 :         if (SPDK_SOCK_OPTS_FIELD_OK(opts, zcopy)) {
                   +  + ]
     248   [ +  -  +  - ]:      45003 :                 opts->zcopy = SPDK_SOCK_DEFAULT_ZCOPY;
     249                 :       4028 :         }
     250                 :            : 
     251   [ +  +  +  -  :      45015 :         if (SPDK_SOCK_OPTS_FIELD_OK(opts, ack_timeout)) {
                   +  + ]
     252   [ +  -  +  - ]:      45003 :                 opts->ack_timeout = SPDK_SOCK_DEFAULT_ACK_TIMEOUT;
     253                 :       4028 :         }
     254                 :            : 
     255   [ +  +  +  -  :      45015 :         if (SPDK_SOCK_OPTS_FIELD_OK(opts, impl_opts)) {
                   +  + ]
     256   [ +  -  +  - ]:      45003 :                 opts->impl_opts = NULL;
     257                 :       4028 :         }
     258                 :            : 
     259   [ +  +  +  -  :      45015 :         if (SPDK_SOCK_OPTS_FIELD_OK(opts, impl_opts_size)) {
                   +  + ]
     260   [ +  -  +  - ]:      45003 :                 opts->impl_opts_size = 0;
     261                 :       4028 :         }
     262                 :      45015 : }
     263                 :            : 
     264                 :            : /*
     265                 :            :  * opts The opts allocated in the current library.
     266                 :            :  * opts_user The opts passed by the caller.
     267                 :            :  * */
     268                 :            : static void
     269                 :      28241 : sock_init_opts(struct spdk_sock_opts *opts, struct spdk_sock_opts *opts_user)
     270                 :            : {
     271   [ +  +  #  # ]:      28241 :         assert(opts);
     272   [ +  +  #  # ]:      28241 :         assert(opts_user);
     273                 :            : 
     274   [ +  -  +  - ]:      28241 :         opts->opts_size = sizeof(*opts);
     275                 :      28241 :         spdk_sock_get_default_opts(opts);
     276                 :            : 
     277                 :            :         /* reset the size according to the user */
     278   [ +  -  +  -  :      28241 :         opts->opts_size = opts_user->opts_size;
             +  -  +  - ]
     279   [ +  -  +  -  :      28241 :         if (SPDK_SOCK_OPTS_FIELD_OK(opts, priority)) {
                   -  + ]
     280   [ +  -  +  -  :      28241 :                 opts->priority = opts_user->priority;
             +  -  +  - ]
     281                 :       2013 :         }
     282                 :            : 
     283   [ +  -  +  -  :      28241 :         if (SPDK_SOCK_OPTS_FIELD_OK(opts, zcopy)) {
                   -  + ]
     284   [ +  +  +  -  :      28241 :                 opts->zcopy = opts_user->zcopy;
          +  -  +  -  +  
                      - ]
     285                 :       2013 :         }
     286                 :            : 
     287   [ +  -  +  -  :      28241 :         if (SPDK_SOCK_OPTS_FIELD_OK(opts, ack_timeout)) {
                   -  + ]
     288   [ +  -  +  -  :      28241 :                 opts->ack_timeout = opts_user->ack_timeout;
             +  -  +  - ]
     289                 :       2013 :         }
     290                 :            : 
     291   [ +  -  +  -  :      28241 :         if (SPDK_SOCK_OPTS_FIELD_OK(opts, impl_opts)) {
                   -  + ]
     292   [ +  -  +  -  :      28241 :                 opts->impl_opts = opts_user->impl_opts;
             +  -  +  - ]
     293                 :       2013 :         }
     294                 :            : 
     295   [ +  -  +  -  :      28241 :         if (SPDK_SOCK_OPTS_FIELD_OK(opts, impl_opts)) {
                   -  + ]
     296   [ +  -  +  -  :      28241 :                 opts->impl_opts_size = opts_user->impl_opts_size;
             +  -  +  - ]
     297                 :       2013 :         }
     298                 :      28241 : }
     299                 :            : 
     300                 :            : struct spdk_sock *
     301                 :         50 : spdk_sock_connect(const char *ip, int port, const char *impl_name)
     302                 :            : {
     303                 :         40 :         struct spdk_sock_opts opts;
     304                 :            : 
     305                 :         50 :         opts.opts_size = sizeof(opts);
     306                 :         50 :         spdk_sock_get_default_opts(&opts);
     307                 :         58 :         return spdk_sock_connect_ext(ip, port, impl_name, &opts);
     308                 :          8 : }
     309                 :            : 
     310                 :            : struct spdk_sock *
     311                 :      16367 : spdk_sock_connect_ext(const char *ip, int port, const char *_impl_name, struct spdk_sock_opts *opts)
     312                 :            : {
     313                 :      16367 :         struct spdk_net_impl *impl = NULL;
     314                 :         10 :         struct spdk_sock *sock;
     315                 :        153 :         struct spdk_sock_opts opts_local;
     316                 :      16367 :         const char *impl_name = NULL;
     317                 :            : 
     318         [ +  + ]:      16367 :         if (opts == NULL) {
     319                 :          0 :                 SPDK_ERRLOG("the opts should not be NULL pointer\n");
     320                 :          0 :                 return NULL;
     321                 :            :         }
     322                 :            : 
     323         [ +  + ]:      16367 :         if (_impl_name) {
     324                 :        139 :                 impl_name = _impl_name;
     325         [ -  + ]:      16238 :         } else if (g_default_impl) {
     326   [ #  #  #  # ]:          0 :                 impl_name = g_default_impl->name;
     327                 :          0 :         }
     328                 :            : 
     329   [ +  +  +  +  :      39484 :         STAILQ_FOREACH_FROM(impl, &g_net_impls, link) {
          +  -  +  -  +  
                      - ]
     330   [ +  +  +  +  :      28007 :                 if (impl_name && strncmp(impl_name, impl->name, strlen(impl->name) + 1)) {
          +  +  +  +  +  
          +  +  -  +  -  
             +  -  +  + ]
     331                 :        149 :                         continue;
     332                 :            :                 }
     333                 :            : 
     334   [ +  +  +  +  :      27858 :                 SPDK_DEBUGLOG(sock, "Creating a client socket using impl %s\n", impl->name);
          +  -  #  #  #  
                      # ]
     335                 :      27858 :                 sock_init_opts(&opts_local, opts);
     336   [ +  -  +  -  :      27858 :                 sock = impl->connect(ip, port, &opts_local);
             -  +  +  - ]
     337         [ +  + ]:      27858 :                 if (sock != NULL) {
     338                 :            :                         /* Copy the contents, both the two structures are the same ABI version */
     339   [ +  +  +  -  :       4890 :                         memcpy(&sock->opts, &opts_local, sizeof(sock->opts));
                   +  - ]
     340                 :            :                         /* Clear out impl_opts to make sure we don't keep reference to a dangling
     341                 :            :                          * pointer */
     342   [ +  -  +  -  :       4890 :                         sock->opts.impl_opts = NULL;
                   +  - ]
     343   [ +  -  +  - ]:       4890 :                         sock->net_impl = impl;
     344   [ +  -  +  -  :       4890 :                         TAILQ_INIT(&sock->queued_reqs);
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     345   [ +  -  +  -  :       4890 :                         TAILQ_INIT(&sock->pending_reqs);
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     346                 :            : 
     347                 :       4890 :                         return sock;
     348                 :            :                 }
     349                 :          0 :         }
     350                 :            : 
     351                 :      11477 :         return NULL;
     352                 :       1980 : }
     353                 :            : 
     354                 :            : struct spdk_sock *
     355                 :         90 : spdk_sock_listen(const char *ip, int port, const char *impl_name)
     356                 :            : {
     357                 :         30 :         struct spdk_sock_opts opts;
     358                 :            : 
     359                 :         90 :         opts.opts_size = sizeof(opts);
     360                 :         90 :         spdk_sock_get_default_opts(&opts);
     361                 :         96 :         return spdk_sock_listen_ext(ip, port, impl_name, &opts);
     362                 :          6 : }
     363                 :            : 
     364                 :            : struct spdk_sock *
     365                 :        383 : spdk_sock_listen_ext(const char *ip, int port, const char *_impl_name, struct spdk_sock_opts *opts)
     366                 :            : {
     367                 :        383 :         struct spdk_net_impl *impl = NULL;
     368                 :          8 :         struct spdk_sock *sock;
     369                 :         60 :         struct spdk_sock_opts opts_local;
     370                 :        383 :         const char *impl_name = NULL;
     371                 :            : 
     372         [ +  + ]:        383 :         if (opts == NULL) {
     373                 :          0 :                 SPDK_ERRLOG("the opts should not be NULL pointer\n");
     374                 :          0 :                 return NULL;
     375                 :            :         }
     376                 :            : 
     377         [ +  + ]:        383 :         if (_impl_name) {
     378                 :         72 :                 impl_name = _impl_name;
     379         [ -  + ]:        319 :         } else if (g_default_impl) {
     380   [ #  #  #  # ]:          0 :                 impl_name = g_default_impl->name;
     381                 :          0 :         }
     382                 :            : 
     383   [ +  +  +  -  :        449 :         STAILQ_FOREACH_FROM(impl, &g_net_impls, link) {
          +  -  +  -  +  
                      - ]
     384   [ +  +  +  +  :        449 :                 if (impl_name && strncmp(impl_name, impl->name, strlen(impl->name) + 1)) {
          +  +  +  +  +  
          +  +  -  +  -  
             +  -  +  + ]
     385                 :         66 :                         continue;
     386                 :            :                 }
     387                 :            : 
     388   [ +  +  +  +  :        383 :                 SPDK_DEBUGLOG(sock, "Creating a listening socket using impl %s\n", impl->name);
          +  -  #  #  #  
                      # ]
     389                 :        383 :                 sock_init_opts(&opts_local, opts);
     390   [ +  -  +  -  :        383 :                 sock = impl->listen(ip, port, &opts_local);
             -  +  +  - ]
     391         [ +  + ]:        383 :                 if (sock != NULL) {
     392                 :            :                         /* Copy the contents, both the two structures are the same ABI version */
     393   [ +  +  +  -  :        383 :                         memcpy(&sock->opts, &opts_local, sizeof(sock->opts));
                   +  - ]
     394                 :            :                         /* Clear out impl_opts to make sure we don't keep reference to a dangling
     395                 :            :                          * pointer */
     396   [ +  -  +  -  :        383 :                         sock->opts.impl_opts = NULL;
                   +  - ]
     397   [ +  -  +  - ]:        383 :                         sock->net_impl = impl;
     398                 :            :                         /* Don't need to initialize the request queues for listen
     399                 :            :                          * sockets. */
     400                 :        383 :                         return sock;
     401                 :            :                 }
     402                 :          0 :         }
     403                 :            : 
     404                 :          0 :         return NULL;
     405                 :         33 : }
     406                 :            : 
     407                 :            : struct spdk_sock *
     408                 :    2450758 : spdk_sock_accept(struct spdk_sock *sock)
     409                 :            : {
     410                 :         13 :         struct spdk_sock *new_sock;
     411                 :            : 
     412   [ +  -  +  -  :    2450758 :         new_sock = sock->net_impl->accept(sock);
          +  -  +  -  -  
                +  +  - ]
     413         [ +  + ]:    2450758 :         if (new_sock != NULL) {
     414                 :            :                 /* Inherit the opts from the "accept sock" */
     415   [ +  -  +  - ]:       9007 :                 new_sock->opts = sock->opts;
     416   [ +  +  +  +  :       9007 :                 memcpy(&new_sock->opts, &sock->opts, sizeof(new_sock->opts));
             +  -  +  - ]
     417   [ +  -  +  -  :       9007 :                 new_sock->net_impl = sock->net_impl;
             +  -  +  - ]
     418   [ +  -  +  -  :       9007 :                 TAILQ_INIT(&new_sock->queued_reqs);
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     419   [ +  -  +  -  :       9007 :                 TAILQ_INIT(&new_sock->pending_reqs);
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     420                 :       1979 :         }
     421                 :            : 
     422                 :    2450771 :         return new_sock;
     423                 :         13 : }
     424                 :            : 
     425                 :            : int
     426                 :      25768 : spdk_sock_close(struct spdk_sock **_sock)
     427                 :            : {
     428         [ +  - ]:      25768 :         struct spdk_sock *sock = *_sock;
     429                 :            : 
     430         [ +  + ]:      25768 :         if (sock == NULL) {
     431         [ #  # ]:      11464 :                 errno = EBADF;
     432                 :      11464 :                 return -1;
     433                 :            :         }
     434                 :            : 
     435   [ +  +  +  -  :      14304 :         if (sock->cb_fn != NULL) {
                   +  + ]
     436                 :            :                 /* This sock is still part of a sock_group. */
     437         [ +  - ]:         12 :                 errno = EBUSY;
     438                 :         12 :                 return -1;
     439                 :            :         }
     440                 :            : 
     441                 :            :         /* Beyond this point the socket is considered closed. */
     442         [ +  - ]:      14292 :         *_sock = NULL;
     443                 :            : 
     444   [ +  -  +  - ]:      14292 :         sock->flags.closed = true;
     445                 :            : 
     446   [ +  +  +  -  :      14292 :         if (sock->cb_cnt > 0) {
                   +  + ]
     447                 :            :                 /* Let the callback unwind before destroying the socket */
     448                 :         12 :                 return 0;
     449                 :            :         }
     450                 :            : 
     451                 :      14280 :         spdk_sock_abort_requests(sock);
     452                 :            : 
     453   [ +  -  +  -  :      14280 :         return sock->net_impl->close(sock);
          +  -  +  -  -  
                +  +  - ]
     454                 :       3995 : }
     455                 :            : 
     456                 :            : ssize_t
     457                 :  354946515 : spdk_sock_recv(struct spdk_sock *sock, void *buf, size_t len)
     458                 :            : {
     459   [ +  +  +  +  :  354946515 :         if (sock == NULL || sock->flags.closed) {
             +  -  +  + ]
     460         [ #  # ]:        910 :                 errno = EBADF;
     461                 :          0 :                 return -1;
     462                 :            :         }
     463                 :            : 
     464   [ +  -  +  -  :  354945605 :         return sock->net_impl->recv(sock, buf, len);
          +  -  +  -  +  
                +  +  - ]
     465                 :    1401221 : }
     466                 :            : 
     467                 :            : ssize_t
     468                 :    3244178 : spdk_sock_readv(struct spdk_sock *sock, struct iovec *iov, int iovcnt)
     469                 :            : {
     470   [ +  -  +  +  :    3244178 :         if (sock == NULL || sock->flags.closed) {
             +  -  +  - ]
     471         [ #  # ]:          0 :                 errno = EBADF;
     472                 :          0 :                 return -1;
     473                 :            :         }
     474                 :            : 
     475   [ +  -  +  -  :    3244178 :         return sock->net_impl->readv(sock, iov, iovcnt);
          +  -  +  -  -  
                +  +  - ]
     476                 :          4 : }
     477                 :            : 
     478                 :            : ssize_t
     479                 :        544 : spdk_sock_writev(struct spdk_sock *sock, struct iovec *iov, int iovcnt)
     480                 :            : {
     481   [ +  -  +  +  :        544 :         if (sock == NULL || sock->flags.closed) {
             +  -  +  - ]
     482         [ #  # ]:          0 :                 errno = EBADF;
     483                 :          0 :                 return -1;
     484                 :            :         }
     485                 :            : 
     486   [ +  -  +  -  :        544 :         return sock->net_impl->writev(sock, iov, iovcnt);
          +  -  +  -  -  
                +  +  - ]
     487                 :         10 : }
     488                 :            : 
     489                 :            : void
     490                 :   64592977 : spdk_sock_writev_async(struct spdk_sock *sock, struct spdk_sock_request *req)
     491                 :            : {
     492   [ +  +  +  -  :   64592977 :         assert(req->cb_fn != NULL);
             +  -  #  # ]
     493                 :            : 
     494   [ +  -  +  +  :   64592977 :         if (sock == NULL || sock->flags.closed) {
             +  -  -  + ]
     495   [ #  #  #  #  :          0 :                 req->cb_fn(req->cb_arg, -EBADF);
          #  #  #  #  #  
                #  #  # ]
     496                 :          0 :                 return;
     497                 :            :         }
     498                 :            : 
     499   [ +  -  +  -  :   64592977 :         sock->net_impl->writev_async(sock, req);
          +  -  +  -  -  
                +  +  - ]
     500                 :      54525 : }
     501                 :            : 
     502                 :            : int
     503                 :         35 : spdk_sock_recv_next(struct spdk_sock *sock, void **buf, void **ctx)
     504                 :            : {
     505   [ +  -  -  +  :         35 :         if (sock == NULL || sock->flags.closed) {
             #  #  #  # ]
     506         [ #  # ]:          0 :                 errno = EBADF;
     507                 :          0 :                 return -1;
     508                 :            :         }
     509                 :            : 
     510   [ -  +  #  #  :         35 :         if (sock->group_impl == NULL) {
                   #  # ]
     511         [ #  # ]:          0 :                 errno = ENOTSUP;
     512                 :          0 :                 return -1;
     513                 :            :         }
     514                 :            : 
     515   [ #  #  #  #  :         35 :         return sock->net_impl->recv_next(sock, buf, ctx);
          #  #  #  #  #  
                #  #  # ]
     516                 :          0 : }
     517                 :            : 
     518                 :            : int
     519                 :   31341900 : spdk_sock_flush(struct spdk_sock *sock)
     520                 :            : {
     521   [ +  +  +  +  :   31341900 :         if (sock == NULL || sock->flags.closed) {
             +  -  +  + ]
     522         [ +  - ]:        504 :                 errno = EBADF;
     523                 :        490 :                 return -1;
     524                 :            :         }
     525                 :            : 
     526   [ +  -  +  -  :   31341396 :         return sock->net_impl->flush(sock);
          +  -  +  -  +  
                +  +  - ]
     527                 :    1265874 : }
     528                 :            : 
     529                 :            : int
     530                 :       8949 : spdk_sock_set_recvlowat(struct spdk_sock *sock, int nbytes)
     531                 :            : {
     532   [ +  -  +  -  :       8949 :         return sock->net_impl->set_recvlowat(sock, nbytes);
          +  -  +  -  -  
                +  +  - ]
     533                 :            : }
     534                 :            : 
     535                 :            : int
     536                 :      16854 : spdk_sock_set_recvbuf(struct spdk_sock *sock, int sz)
     537                 :            : {
     538   [ +  -  +  -  :      16854 :         return sock->net_impl->set_recvbuf(sock, sz);
          +  -  +  -  -  
                +  +  - ]
     539                 :            : }
     540                 :            : 
     541                 :            : int
     542                 :         12 : spdk_sock_set_sendbuf(struct spdk_sock *sock, int sz)
     543                 :            : {
     544   [ +  -  +  -  :         12 :         return sock->net_impl->set_sendbuf(sock, sz);
          +  -  +  -  -  
                +  +  - ]
     545                 :            : }
     546                 :            : 
     547                 :            : bool
     548                 :         12 : spdk_sock_is_ipv6(struct spdk_sock *sock)
     549                 :            : {
     550   [ +  -  +  -  :         12 :         return sock->net_impl->is_ipv6(sock);
          +  -  +  -  -  
                +  +  - ]
     551                 :            : }
     552                 :            : 
     553                 :            : bool
     554                 :      10950 : spdk_sock_is_ipv4(struct spdk_sock *sock)
     555                 :            : {
     556   [ +  -  +  -  :      10950 :         return sock->net_impl->is_ipv4(sock);
          +  -  +  -  -  
                +  +  - ]
     557                 :            : }
     558                 :            : 
     559                 :            : bool
     560                 :     355618 : spdk_sock_is_connected(struct spdk_sock *sock)
     561                 :            : {
     562   [ +  -  +  -  :     355618 :         return sock->net_impl->is_connected(sock);
          +  -  +  -  -  
                +  +  - ]
     563                 :            : }
     564                 :            : 
     565                 :            : struct spdk_sock_group *
     566                 :       1792 : spdk_sock_group_create(void *ctx)
     567                 :            : {
     568                 :       1792 :         struct spdk_net_impl *impl = NULL;
     569                 :          6 :         struct spdk_sock_group *group;
     570                 :          6 :         struct spdk_sock_group_impl *group_impl;
     571                 :            : 
     572                 :       1792 :         group = calloc(1, sizeof(*group));
     573         [ +  + ]:       1792 :         if (group == NULL) {
     574                 :          0 :                 return NULL;
     575                 :            :         }
     576                 :            : 
     577   [ +  -  +  -  :       1792 :         STAILQ_INIT(&group->group_impls);
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     578   [ +  -  +  -  :       1792 :         STAILQ_INIT(&group->pool);
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     579                 :            : 
     580   [ +  +  +  +  :       5711 :         STAILQ_FOREACH_FROM(impl, &g_net_impls, link) {
          +  -  +  -  +  
                      - ]
     581   [ +  -  +  -  :       3919 :                 group_impl = impl->group_impl_create();
             -  +  +  - ]
     582         [ +  + ]:       3919 :                 if (group_impl != NULL) {
     583   [ +  -  +  -  :       3919 :                         STAILQ_INSERT_TAIL(&group->group_impls, group_impl, link);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
             -  +  -  +  
                      - ]
     584   [ +  -  +  -  :       3919 :                         TAILQ_INIT(&group_impl->socks);
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     585   [ +  -  +  - ]:       3919 :                         group_impl->net_impl = impl;
     586   [ +  -  +  - ]:       3919 :                         group_impl->group = group;
     587                 :        120 :                 }
     588                 :        120 :         }
     589                 :            : 
     590   [ +  -  +  - ]:       1792 :         group->ctx = ctx;
     591                 :            : 
     592                 :       1792 :         return group;
     593                 :         57 : }
     594                 :            : 
     595                 :            : void *
     596                 :       8384 : spdk_sock_group_get_ctx(struct spdk_sock_group *group)
     597                 :            : {
     598         [ +  + ]:       8384 :         if (group == NULL) {
     599                 :          6 :                 return NULL;
     600                 :            :         }
     601                 :            : 
     602   [ +  -  +  - ]:       8378 :         return group->ctx;
     603                 :       1972 : }
     604                 :            : 
     605                 :            : int
     606                 :      10088 : spdk_sock_group_add_sock(struct spdk_sock_group *group, struct spdk_sock *sock,
     607                 :            :                          spdk_sock_cb cb_fn, void *cb_arg)
     608                 :            : {
     609                 :      10088 :         struct spdk_sock_group_impl *group_impl = NULL;
     610                 :         10 :         int rc;
     611                 :            : 
     612         [ +  + ]:      10088 :         if (cb_fn == NULL) {
     613         [ +  - ]:         12 :                 errno = EINVAL;
     614                 :         12 :                 return -1;
     615                 :            :         }
     616                 :            : 
     617   [ +  +  +  -  :      10076 :         if (sock->group_impl != NULL) {
                   +  + ]
     618                 :            :                 /*
     619                 :            :                  * This sock is already part of a sock_group.
     620                 :            :                  */
     621         [ +  - ]:         12 :                 errno = EINVAL;
     622                 :         12 :                 return -1;
     623                 :            :         }
     624                 :            : 
     625                 :      10064 :         group_impl = sock_get_group_impl_from_group(sock, group);
     626         [ +  + ]:      10064 :         if (group_impl == NULL) {
     627         [ #  # ]:          0 :                 errno = EINVAL;
     628                 :          0 :                 return -1;
     629                 :            :         }
     630                 :            : 
     631   [ +  -  +  -  :      10064 :         rc = group_impl->net_impl->group_impl_add_sock(group_impl, sock);
          +  -  +  -  -  
                +  +  - ]
     632         [ +  + ]:      10064 :         if (rc != 0) {
     633                 :          0 :                 return rc;
     634                 :            :         }
     635                 :            : 
     636   [ +  -  +  -  :      10064 :         TAILQ_INSERT_TAIL(&group_impl->socks, sock, link);
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     637   [ +  -  +  - ]:      10064 :         sock->group_impl = group_impl;
     638   [ +  -  +  - ]:      10064 :         sock->cb_fn = cb_fn;
     639   [ +  -  +  - ]:      10064 :         sock->cb_arg = cb_arg;
     640                 :            : 
     641                 :      10064 :         return 0;
     642                 :       1980 : }
     643                 :            : 
     644                 :            : int
     645                 :      10064 : spdk_sock_group_remove_sock(struct spdk_sock_group *group, struct spdk_sock *sock)
     646                 :            : {
     647                 :      10064 :         struct spdk_sock_group_impl *group_impl = NULL;
     648                 :          6 :         int rc;
     649                 :            : 
     650                 :      10064 :         group_impl = sock_get_group_impl_from_group(sock, group);
     651         [ +  + ]:      10064 :         if (group_impl == NULL) {
     652         [ #  # ]:          0 :                 errno = EINVAL;
     653                 :          0 :                 return -1;
     654                 :            :         }
     655                 :            : 
     656   [ +  +  +  -  :      10064 :         assert(group_impl == sock->group_impl);
             +  -  #  # ]
     657                 :            : 
     658   [ +  -  +  -  :      10064 :         rc = group_impl->net_impl->group_impl_remove_sock(group_impl, sock);
          +  -  +  -  -  
                +  +  - ]
     659         [ +  + ]:      10064 :         if (rc == 0) {
     660   [ +  +  +  -  :      10064 :                 TAILQ_REMOVE(&group_impl->socks, sock, link);
          +  -  +  +  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
          -  +  -  +  -  
          +  -  +  -  +  
                -  +  - ]
     661   [ +  -  +  - ]:      10064 :                 sock->group_impl = NULL;
     662   [ +  -  +  - ]:      10064 :                 sock->cb_fn = NULL;
     663   [ +  -  +  - ]:      10064 :                 sock->cb_arg = NULL;
     664                 :       1976 :         }
     665                 :            : 
     666                 :      10064 :         return rc;
     667                 :       1976 : }
     668                 :            : 
     669                 :            : int
     670                 :         39 : spdk_sock_group_provide_buf(struct spdk_sock_group *group, void *buf, size_t len, void *ctx)
     671                 :            : {
     672                 :          0 :         struct spdk_sock_group_provided_buf *provided;
     673                 :            : 
     674                 :         39 :         provided = (struct spdk_sock_group_provided_buf *)buf;
     675                 :            : 
     676   [ #  #  #  # ]:         39 :         provided->len = len;
     677   [ #  #  #  # ]:         39 :         provided->ctx = ctx;
     678   [ +  -  #  #  :         39 :         STAILQ_INSERT_HEAD(&group->pool, provided, link);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                      # ]
     679                 :            : 
     680                 :         39 :         return 0;
     681                 :          0 : }
     682                 :            : 
     683                 :            : size_t
     684                 :         35 : spdk_sock_group_get_buf(struct spdk_sock_group *group, void **buf, void **ctx)
     685                 :            : {
     686                 :          0 :         struct spdk_sock_group_provided_buf *provided;
     687                 :            : 
     688   [ #  #  #  #  :         35 :         provided = STAILQ_FIRST(&group->pool);
                   #  # ]
     689         [ -  + ]:         35 :         if (provided == NULL) {
     690         [ #  # ]:          0 :                 *buf = NULL;
     691                 :          0 :                 return 0;
     692                 :            :         }
     693   [ +  -  #  #  :         35 :         STAILQ_REMOVE_HEAD(&group->pool, link);
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                      # ]
     694                 :            : 
     695         [ #  # ]:         35 :         *buf = provided;
     696   [ #  #  #  #  :         35 :         *ctx = provided->ctx;
                   #  # ]
     697   [ #  #  #  # ]:         35 :         return provided->len;
     698                 :          0 : }
     699                 :            : 
     700                 :            : int
     701                 :  871132237 : spdk_sock_group_poll(struct spdk_sock_group *group)
     702                 :            : {
     703                 :  871132237 :         return spdk_sock_group_poll_count(group, MAX_EVENTS_PER_POLL);
     704                 :            : }
     705                 :            : 
     706                 :            : static int
     707                 : 1868669417 : sock_group_impl_poll_count(struct spdk_sock_group_impl *group_impl,
     708                 :            :                            struct spdk_sock_group *group,
     709                 :            :                            int max_events)
     710                 :            : {
     711                 :   86851333 :         struct spdk_sock *socks[MAX_EVENTS_PER_POLL];
     712                 :         27 :         int num_events, i;
     713                 :            : 
     714   [ +  +  +  -  : 1868669417 :         if (TAILQ_EMPTY(&group_impl->socks)) {
             +  -  +  + ]
     715                 : 1022195950 :                 return 0;
     716                 :            :         }
     717                 :            : 
     718   [ +  -  +  -  :  846473467 :         num_events = group_impl->net_impl->group_impl_poll(group_impl, max_events, socks);
          +  -  +  -  -  
                +  +  - ]
     719         [ +  + ]:  846473467 :         if (num_events == -1) {
     720                 :          0 :                 return -1;
     721                 :            :         }
     722                 :            : 
     723   [ +  +  +  - ]: 1039820134 :         for (i = 0; i < num_events; i++) {
     724   [ +  -  +  -  :  193346667 :                 struct spdk_sock *sock = socks[i];
                   +  - ]
     725   [ +  +  +  -  :  193346667 :                 assert(sock->cb_fn != NULL);
             +  -  #  # ]
     726   [ +  -  +  -  :  193346667 :                 sock->cb_fn(sock->cb_arg, group, sock);
          -  +  +  -  +  
                -  +  - ]
     727                 :      23036 :         }
     728                 :            : 
     729                 :  846473467 :         return num_events;
     730                 :    1231589 : }
     731                 :            : 
     732                 :            : int
     733                 :  871132261 : spdk_sock_group_poll_count(struct spdk_sock_group *group, int max_events)
     734                 :            : {
     735                 :  871132261 :         struct spdk_sock_group_impl *group_impl = NULL;
     736                 :  871132261 :         int rc, num_events = 0;
     737                 :            : 
     738         [ +  + ]:  871132261 :         if (max_events < 1) {
     739         [ #  # ]:          0 :                 errno = -EINVAL;
     740                 :          0 :                 return -1;
     741                 :            :         }
     742                 :            : 
     743                 :            :         /*
     744                 :            :          * Only poll for up to 32 events at a time - if more events are pending,
     745                 :            :          *  the next call to this function will reap them.
     746                 :            :          */
     747         [ +  + ]:  871132261 :         if (max_events > MAX_EVENTS_PER_POLL) {
     748                 :          0 :                 max_events = MAX_EVENTS_PER_POLL;
     749                 :          0 :         }
     750                 :            : 
     751   [ +  -  +  +  : 2739801678 :         STAILQ_FOREACH_FROM(group_impl, &group->group_impls, link) {
          +  -  +  -  +  
          +  +  -  +  -  
                   +  - ]
     752                 : 1868669417 :                 rc = sock_group_impl_poll_count(group_impl, group, max_events);
     753         [ -  + ]: 1868669417 :                 if (rc < 0) {
     754                 :          0 :                         num_events = -1;
     755   [ #  #  #  #  :          0 :                         SPDK_ERRLOG("group_impl_poll_count for net(%s) failed\n",
             #  #  #  # ]
     756                 :            :                                     group_impl->net_impl->name);
     757         [ +  + ]: 1868669417 :                 } else if (num_events >= 0) {
     758         [ +  - ]: 1868669417 :                         num_events += rc;
     759                 :    1231589 :                 }
     760                 :    1231589 :         }
     761                 :            : 
     762                 :  871132261 :         return num_events;
     763                 :     615790 : }
     764                 :            : 
     765                 :            : int
     766                 :       1820 : spdk_sock_group_close(struct spdk_sock_group **group)
     767                 :            : {
     768                 :       1820 :         struct spdk_sock_group_impl *group_impl = NULL, *tmp;
     769                 :          8 :         int rc;
     770                 :            : 
     771   [ +  +  +  - ]:       1820 :         if (*group == NULL) {
     772         [ #  # ]:         16 :                 errno = EBADF;
     773                 :         16 :                 return -1;
     774                 :            :         }
     775                 :            : 
     776   [ +  +  +  -  :       5729 :         STAILQ_FOREACH_SAFE(group_impl, &(*group)->group_impls, link, tmp) {
          +  -  +  -  +  
          +  +  -  +  -  
             +  -  +  + ]
     777   [ +  +  +  -  :       3937 :                 if (!TAILQ_EMPTY(&group_impl->socks)) {
             +  -  +  + ]
     778         [ -  + ]:         12 :                         errno = EBUSY;
     779                 :         12 :                         return -1;
     780                 :            :                 }
     781                 :        121 :         }
     782                 :            : 
     783   [ +  +  +  -  :       5711 :         STAILQ_FOREACH_SAFE(group_impl, &(*group)->group_impls, link, tmp) {
          +  -  +  -  +  
          +  +  -  +  -  
             +  -  +  + ]
     784   [ +  -  +  -  :       3919 :                 rc = group_impl->net_impl->group_impl_close(group_impl);
          +  -  +  -  -  
                +  +  - ]
     785         [ +  + ]:       3919 :                 if (rc != 0) {
     786                 :          0 :                         SPDK_ERRLOG("group_impl_close for net failed\n");
     787                 :          0 :                 }
     788                 :        120 :         }
     789                 :            : 
     790         [ +  - ]:       1792 :         free(*group);
     791         [ +  - ]:       1792 :         *group = NULL;
     792                 :            : 
     793                 :       1792 :         return 0;
     794                 :         59 : }
     795                 :            : 
     796                 :            : static inline struct spdk_net_impl *
     797                 :        375 : sock_get_impl_by_name(const char *impl_name)
     798                 :            : {
     799                 :         16 :         struct spdk_net_impl *impl;
     800                 :            : 
     801   [ +  +  #  # ]:        375 :         assert(impl_name != NULL);
     802   [ +  -  +  -  :        736 :         STAILQ_FOREACH(impl, &g_net_impls, link) {
             +  -  +  - ]
     803   [ +  +  +  +  :        736 :                 if (0 == strcmp(impl_name, impl->name)) {
          +  +  +  -  +  
                      + ]
     804                 :        375 :                         return impl;
     805                 :            :                 }
     806                 :         13 :         }
     807                 :            : 
     808                 :          0 :         return NULL;
     809                 :         16 : }
     810                 :            : 
     811                 :            : int
     812                 :        281 : spdk_sock_impl_get_opts(const char *impl_name, struct spdk_sock_impl_opts *opts, size_t *len)
     813                 :            : {
     814                 :         14 :         struct spdk_net_impl *impl;
     815                 :            : 
     816   [ +  -  +  +  :        281 :         if (!impl_name || !opts || !len) {
                   +  + ]
     817         [ +  - ]:         24 :                 errno = EINVAL;
     818                 :         24 :                 return -1;
     819                 :            :         }
     820                 :            : 
     821                 :        257 :         impl = sock_get_impl_by_name(impl_name);
     822         [ +  + ]:        257 :         if (!impl) {
     823         [ #  # ]:          0 :                 errno = EINVAL;
     824                 :          0 :                 return -1;
     825                 :            :         }
     826                 :            : 
     827   [ +  +  +  -  :        257 :         if (!impl->get_opts) {
                   +  + ]
     828         [ +  - ]:          6 :                 errno = ENOTSUP;
     829                 :          6 :                 return -1;
     830                 :            :         }
     831                 :            : 
     832   [ +  -  +  -  :        251 :         return impl->get_opts(opts, len);
             -  +  -  + ]
     833                 :         14 : }
     834                 :            : 
     835                 :            : int
     836                 :        112 : spdk_sock_impl_set_opts(const char *impl_name, const struct spdk_sock_impl_opts *opts, size_t len)
     837                 :            : {
     838                 :          6 :         struct spdk_net_impl *impl;
     839                 :            : 
     840   [ +  -  +  + ]:        112 :         if (!impl_name || !opts) {
     841         [ +  - ]:         12 :                 errno = EINVAL;
     842                 :         12 :                 return -1;
     843                 :            :         }
     844                 :            : 
     845                 :        100 :         impl = sock_get_impl_by_name(impl_name);
     846         [ +  + ]:        100 :         if (!impl) {
     847         [ #  # ]:          0 :                 errno = EINVAL;
     848                 :          0 :                 return -1;
     849                 :            :         }
     850                 :            : 
     851   [ +  +  +  -  :        100 :         if (!impl->set_opts) {
                   +  + ]
     852         [ +  - ]:          6 :                 errno = ENOTSUP;
     853                 :          6 :                 return -1;
     854                 :            :         }
     855                 :            : 
     856   [ +  -  +  -  :         94 :         return impl->set_opts(opts, len);
             -  +  -  + ]
     857                 :          6 : }
     858                 :            : 
     859                 :            : void
     860                 :         88 : spdk_sock_write_config_json(struct spdk_json_write_ctx *w)
     861                 :            : {
     862                 :          0 :         struct spdk_net_impl *impl;
     863                 :         32 :         struct spdk_sock_impl_opts opts;
     864                 :         32 :         size_t len;
     865                 :            : 
     866   [ -  +  #  # ]:         88 :         assert(w != NULL);
     867                 :            : 
     868                 :         88 :         spdk_json_write_array_begin(w);
     869                 :            : 
     870         [ -  + ]:         88 :         if (g_default_impl) {
     871                 :          0 :                 spdk_json_write_object_begin(w);
     872                 :          0 :                 spdk_json_write_named_string(w, "method", "sock_set_default_impl");
     873                 :          0 :                 spdk_json_write_named_object_begin(w, "params");
     874   [ #  #  #  # ]:          0 :                 spdk_json_write_named_string(w, "impl_name", g_default_impl->name);
     875                 :          0 :                 spdk_json_write_object_end(w);
     876                 :          0 :                 spdk_json_write_object_end(w);
     877                 :          0 :         }
     878                 :            : 
     879   [ +  +  #  #  :        276 :         STAILQ_FOREACH(impl, &g_net_impls, link) {
             #  #  #  # ]
     880   [ -  +  #  #  :        188 :                 if (!impl->get_opts) {
                   #  # ]
     881                 :          0 :                         continue;
     882                 :            :                 }
     883                 :            : 
     884                 :        188 :                 len = sizeof(opts);
     885   [ +  -  #  #  :        188 :                 if (impl->get_opts(&opts, &len) == 0) {
          #  #  #  #  #  
                      # ]
     886                 :        188 :                         spdk_json_write_object_begin(w);
     887                 :        188 :                         spdk_json_write_named_string(w, "method", "sock_impl_set_options");
     888                 :        188 :                         spdk_json_write_named_object_begin(w, "params");
     889   [ #  #  #  # ]:        188 :                         spdk_json_write_named_string(w, "impl_name", impl->name);
     890                 :        188 :                         spdk_json_write_named_uint32(w, "recv_buf_size", opts.recv_buf_size);
     891         [ #  # ]:        188 :                         spdk_json_write_named_uint32(w, "send_buf_size", opts.send_buf_size);
     892   [ -  +  #  # ]:        188 :                         spdk_json_write_named_bool(w, "enable_recv_pipe", opts.enable_recv_pipe);
     893   [ -  +  #  # ]:        188 :                         spdk_json_write_named_bool(w, "enable_quickack", opts.enable_quickack);
     894         [ #  # ]:        188 :                         spdk_json_write_named_uint32(w, "enable_placement_id", opts.enable_placement_id);
     895   [ -  +  #  # ]:        188 :                         spdk_json_write_named_bool(w, "enable_zerocopy_send_server", opts.enable_zerocopy_send_server);
     896         [ -  + ]:        188 :                         spdk_json_write_named_bool(w, "enable_zerocopy_send_client", opts.enable_zerocopy_send_client);
     897         [ #  # ]:        188 :                         spdk_json_write_named_uint32(w, "zerocopy_threshold", opts.zerocopy_threshold);
     898         [ #  # ]:        188 :                         spdk_json_write_named_uint32(w, "tls_version", opts.tls_version);
     899   [ -  +  #  # ]:        188 :                         spdk_json_write_named_bool(w, "enable_ktls", opts.enable_ktls);
     900                 :        188 :                         spdk_json_write_object_end(w);
     901                 :        188 :                         spdk_json_write_object_end(w);
     902                 :          0 :                 } else {
     903   [ #  #  #  # ]:          0 :                         SPDK_ERRLOG("Failed to get socket options for socket implementation %s\n", impl->name);
     904                 :            :                 }
     905                 :          0 :         }
     906                 :            : 
     907                 :         88 :         spdk_json_write_array_end(w);
     908                 :         88 : }
     909                 :            : 
     910                 :            : void
     911                 :       5146 : spdk_net_impl_register(struct spdk_net_impl *impl, int priority)
     912                 :            : {
     913                 :          3 :         struct spdk_net_impl *cur, *prev;
     914                 :            : 
     915   [ +  -  +  - ]:       5146 :         impl->priority = priority;
     916                 :       5146 :         prev = NULL;
     917   [ +  +  +  -  :       8253 :         STAILQ_FOREACH(cur, &g_net_impls, link) {
             +  -  +  - ]
     918   [ +  +  +  -  :       3113 :                 if (impl->priority > cur->priority) {
          +  -  +  -  +  
                      + ]
     919                 :          6 :                         break;
     920                 :            :                 }
     921                 :       3107 :                 prev = cur;
     922                 :         57 :         }
     923                 :            : 
     924         [ +  + ]:       5146 :         if (prev) {
     925   [ +  -  +  -  :       2749 :                 STAILQ_INSERT_AFTER(&g_net_impls, prev, impl, link);
          +  -  +  -  +  
          -  +  -  -  +  
          +  -  +  -  +  
          -  +  -  +  -  
                   +  - ]
     926                 :         57 :         } else {
     927   [ +  +  +  -  :       2397 :                 STAILQ_INSERT_HEAD(&g_net_impls, impl, link);
          +  -  +  +  +  
             -  +  -  +  
                      - ]
     928                 :            :         }
     929                 :       5146 : }
     930                 :            : 
     931                 :            : int
     932                 :         30 : spdk_sock_set_default_impl(const char *impl_name)
     933                 :            : {
     934                 :          4 :         struct spdk_net_impl *impl;
     935                 :            : 
     936         [ +  + ]:         30 :         if (!impl_name) {
     937         [ +  - ]:         12 :                 errno = EINVAL;
     938                 :         12 :                 return -1;
     939                 :            :         }
     940                 :            : 
     941                 :         18 :         impl = sock_get_impl_by_name(impl_name);
     942         [ +  + ]:         18 :         if (!impl) {
     943         [ #  # ]:          0 :                 errno = EINVAL;
     944                 :          0 :                 return -1;
     945                 :            :         }
     946                 :            : 
     947         [ +  + ]:         18 :         if (impl == g_default_impl) {
     948                 :          0 :                 return 0;
     949                 :            :         }
     950                 :            : 
     951         [ +  + ]:         18 :         if (g_default_impl) {
     952   [ +  +  +  +  :          6 :                 SPDK_DEBUGLOG(sock, "Change the default sock impl from %s to %s\n", g_default_impl->name,
          +  -  #  #  #  
             #  #  #  #  
                      # ]
     953                 :            :                               impl->name);
     954                 :          1 :         } else {
     955   [ +  +  +  +  :         12 :                 SPDK_DEBUGLOG(sock, "Set default sock implementation to %s\n", impl_name);
                   +  - ]
     956                 :            :         }
     957                 :            : 
     958                 :         18 :         g_default_impl = impl;
     959                 :            : 
     960                 :         18 :         return 0;
     961                 :          4 : }
     962                 :            : 
     963                 :            : const char *
     964                 :          0 : spdk_sock_get_default_impl(void)
     965                 :            : {
     966                 :          0 :         struct spdk_net_impl *impl = NULL;
     967                 :            : 
     968         [ #  # ]:          0 :         if (g_default_impl) {
     969   [ #  #  #  # ]:          0 :                 return g_default_impl->name;
     970                 :            :         }
     971                 :            : 
     972                 :          0 :         impl = STAILQ_FIRST(&g_net_impls);
     973         [ #  # ]:          0 :         if (impl) {
     974   [ #  #  #  # ]:          0 :                 return impl->name;
     975                 :            :         }
     976                 :            : 
     977                 :          0 :         return NULL;
     978                 :          0 : }
     979                 :            : 
     980                 :       2426 : SPDK_LOG_REGISTER_COMPONENT(sock)

Generated by: LCOV version 1.14