LCOV - code coverage report
Current view: top level - spdk/lib/sock - sock.c (source / functions) Hit Total Coverage
Test: Combined Lines: 417 469 88.9 %
Date: 2024-07-12 02:17:04 Functions: 50 50 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 229 346 66.2 %

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

Generated by: LCOV version 1.14