LCOV - code coverage report
Current view: top level - spdk/lib/sock - sock.c (source / functions) Hit Total Coverage
Test: Combined Lines: 423 492 86.0 %
Date: 2024-07-12 18:33:17 Functions: 52 54 96.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 231 366 63.1 %

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

Generated by: LCOV version 1.14