MCPcopy Create free account
hub / github.com/F-Stack/f-stack / abd_get_offset_impl

Function abd_get_offset_impl

freebsd/contrib/openzfs/module/zfs/abd.c:522–565  ·  view source on GitHub ↗

* Allocate a new ABD to point to offset off of sabd. It shares the underlying * buffer data with sabd. Use abd_put() to free. sabd must not be freed while * any derived ABDs exist. */

Source from the content-addressed store, hash-verified

520 * any derived ABDs exist.
521 */
522static abd_t *
523abd_get_offset_impl(abd_t *sabd, size_t off, size_t size)
524{
525 abd_t *abd = NULL;
526
527 abd_verify(sabd);
528 ASSERT3U(off, <=, sabd->abd_size);
529
530 if (abd_is_linear(sabd)) {
531 abd = abd_alloc_struct(0);
532
533 /*
534 * Even if this buf is filesystem metadata, we only track that
535 * if we own the underlying data buffer, which is not true in
536 * this case. Therefore, we don't ever use ABD_FLAG_META here.
537 */
538 abd->abd_flags = ABD_FLAG_LINEAR;
539
540 ABD_LINEAR_BUF(abd) = (char *)ABD_LINEAR_BUF(sabd) + off;
541 } else if (abd_is_gang(sabd)) {
542 size_t left = size;
543 abd = abd_alloc_gang_abd();
544 abd->abd_flags &= ~ABD_FLAG_OWNER;
545 for (abd_t *cabd = abd_gang_get_offset(sabd, &off);
546 cabd != NULL && left > 0;
547 cabd = list_next(&ABD_GANG(sabd).abd_gang_chain, cabd)) {
548 int csize = MIN(left, cabd->abd_size - off);
549
550 abd_t *nabd = abd_get_offset_impl(cabd, off, csize);
551 abd_gang_add(abd, nabd, B_FALSE);
552 left -= csize;
553 off = 0;
554 }
555 ASSERT3U(left, ==, 0);
556 } else {
557 abd = abd_get_offset_scatter(sabd, off);
558 }
559
560 abd->abd_size = size;
561 abd->abd_parent = sabd;
562 zfs_refcount_create(&abd->abd_children);
563 (void) zfs_refcount_add_many(&sabd->abd_children, abd->abd_size, abd);
564 return (abd);
565}
566
567abd_t *
568abd_get_offset(abd_t *sabd, size_t off)

Callers 2

abd_get_offsetFunction · 0.85
abd_get_offset_sizeFunction · 0.85

Calls 11

abd_verifyFunction · 0.85
abd_is_linearFunction · 0.85
abd_is_gangFunction · 0.85
abd_alloc_gang_abdFunction · 0.85
abd_gang_get_offsetFunction · 0.85
abd_gang_addFunction · 0.85
zfs_refcount_createFunction · 0.85
zfs_refcount_add_manyFunction · 0.85
abd_alloc_structFunction · 0.50
list_nextFunction · 0.50
abd_get_offset_scatterFunction · 0.50

Tested by

no test coverage detected