Skip to content

Commit

Permalink
change libspl list member names to match kernel
Browse files Browse the repository at this point in the history
This aids in debugging, so that we can use the same infrastructure to
walk zfs's list_t in the kernel module and in the userland libraries
(e.g. when debugging ztest).

Reviewed-by: Serapheim Dimitropoulos <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Matthew Ahrens <[email protected]>
Closes openzfs#10236
  • Loading branch information
ahrens authored Apr 23, 2020
1 parent 196bee4 commit 5d4ed96
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 41 deletions.
4 changes: 2 additions & 2 deletions lib/libspl/include/sys/list_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ extern "C" {
#endif

struct list_node {
struct list_node *list_next;
struct list_node *list_prev;
struct list_node *next;
struct list_node *prev;
};

struct list {
Expand Down
77 changes: 38 additions & 39 deletions lib/libspl/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@

#define list_d2l(a, obj) ((list_node_t *)(((char *)obj) + (a)->list_offset))
#define list_object(a, node) ((void *)(((char *)node) - (a)->list_offset))
#define list_empty(a) ((a)->list_head.list_next == &(a)->list_head)
#define list_empty(a) ((a)->list_head.next == &(a)->list_head)

#define list_insert_after_node(list, node, object) { \
list_node_t *lnew = list_d2l(list, object); \
lnew->list_prev = (node); \
lnew->list_next = (node)->list_next; \
(node)->list_next->list_prev = lnew; \
(node)->list_next = lnew; \
lnew->prev = (node); \
lnew->next = (node)->next; \
(node)->next->prev = lnew; \
(node)->next = lnew; \
}

#define list_insert_before_node(list, node, object) { \
list_node_t *lnew = list_d2l(list, object); \
lnew->list_next = (node); \
lnew->list_prev = (node)->list_prev; \
(node)->list_prev->list_next = lnew; \
(node)->list_prev = lnew; \
lnew->next = (node); \
lnew->prev = (node)->prev; \
(node)->prev->next = lnew; \
(node)->prev = lnew; \
}

#define list_remove_node(node) \
(node)->list_prev->list_next = (node)->list_next; \
(node)->list_next->list_prev = (node)->list_prev; \
(node)->list_next = (node)->list_prev = NULL
(node)->prev->next = (node)->next; \
(node)->next->prev = (node)->prev; \
(node)->next = (node)->prev = NULL

void
list_create(list_t *list, size_t size, size_t offset)
Expand All @@ -67,8 +67,7 @@ list_create(list_t *list, size_t size, size_t offset)

list->list_size = size;
list->list_offset = offset;
list->list_head.list_next = list->list_head.list_prev =
&list->list_head;
list->list_head.next = list->list_head.prev = &list->list_head;
}

void
Expand All @@ -77,10 +76,10 @@ list_destroy(list_t *list)
list_node_t *node = &list->list_head;

ASSERT(list);
ASSERT(list->list_head.list_next == node);
ASSERT(list->list_head.list_prev == node);
ASSERT(list->list_head.next == node);
ASSERT(list->list_head.prev == node);

node->list_next = node->list_prev = NULL;
node->next = node->prev = NULL;
}

void
Expand Down Expand Up @@ -124,14 +123,14 @@ list_remove(list_t *list, void *object)
{
list_node_t *lold = list_d2l(list, object);
ASSERT(!list_empty(list));
ASSERT(lold->list_next != NULL);
ASSERT(lold->next != NULL);
list_remove_node(lold);
}

void *
list_remove_head(list_t *list)
{
list_node_t *head = list->list_head.list_next;
list_node_t *head = list->list_head.next;
if (head == &list->list_head)
return (NULL);
list_remove_node(head);
Expand All @@ -141,7 +140,7 @@ list_remove_head(list_t *list)
void *
list_remove_tail(list_t *list)
{
list_node_t *tail = list->list_head.list_prev;
list_node_t *tail = list->list_head.prev;
if (tail == &list->list_head)
return (NULL);
list_remove_node(tail);
Expand All @@ -153,24 +152,24 @@ list_head(list_t *list)
{
if (list_empty(list))
return (NULL);
return (list_object(list, list->list_head.list_next));
return (list_object(list, list->list_head.next));
}

void *
list_tail(list_t *list)
{
if (list_empty(list))
return (NULL);
return (list_object(list, list->list_head.list_prev));
return (list_object(list, list->list_head.prev));
}

void *
list_next(list_t *list, void *object)
{
list_node_t *node = list_d2l(list, object);

if (node->list_next != &list->list_head)
return (list_object(list, node->list_next));
if (node->next != &list->list_head)
return (list_object(list, node->next));

return (NULL);
}
Expand All @@ -180,8 +179,8 @@ list_prev(list_t *list, void *object)
{
list_node_t *node = list_d2l(list, object);

if (node->list_prev != &list->list_head)
return (list_object(list, node->list_prev));
if (node->prev != &list->list_head)
return (list_object(list, node->prev));

return (NULL);
}
Expand All @@ -201,13 +200,13 @@ list_move_tail(list_t *dst, list_t *src)
if (list_empty(src))
return;

dstnode->list_prev->list_next = srcnode->list_next;
srcnode->list_next->list_prev = dstnode->list_prev;
dstnode->list_prev = srcnode->list_prev;
srcnode->list_prev->list_next = dstnode;
dstnode->prev->next = srcnode->next;
srcnode->next->prev = dstnode->prev;
dstnode->prev = srcnode->prev;
srcnode->prev->next = dstnode;

/* empty src list */
srcnode->list_next = srcnode->list_prev = srcnode;
srcnode->next = srcnode->prev = srcnode;
}

void
Expand All @@ -216,24 +215,24 @@ list_link_replace(list_node_t *lold, list_node_t *lnew)
ASSERT(list_link_active(lold));
ASSERT(!list_link_active(lnew));

lnew->list_next = lold->list_next;
lnew->list_prev = lold->list_prev;
lold->list_prev->list_next = lnew;
lold->list_next->list_prev = lnew;
lold->list_next = lold->list_prev = NULL;
lnew->next = lold->next;
lnew->prev = lold->prev;
lold->prev->next = lnew;
lold->next->prev = lnew;
lold->next = lold->prev = NULL;
}

void
list_link_init(list_node_t *ln)
{
ln->list_next = NULL;
ln->list_prev = NULL;
ln->next = NULL;
ln->prev = NULL;
}

int
list_link_active(list_node_t *ln)
{
return (ln->list_next != NULL);
return (ln->next != NULL);
}

int
Expand Down

0 comments on commit 5d4ed96

Please sign in to comment.