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