((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
/**
+ * list_first_entry - get the first element from a list
+ * \param ptr the list head to take the element from.
+ * \param type the type of the struct this is embedded in.
+ * \param member the name of the list_head within the struct.
+ *
+ * Note, that list is expected to be not empty.
+ */
+#define list_first_entry(ptr, type, member) \
+ list_entry((ptr)->next, type, member)
+
+/**
* Iterate over a list
* \param pos the iterator
* \param head the list to iterate over
* \param member the name of the list_struct within the struct.
*/
#define list_for_each_entry(pos, head, member) \
- for (pos = list_entry((head)->next, typeof(*pos), member), \
+ for (pos = list_first_entry((head), typeof(*pos), member), \
prefetch(pos->member.next); \
&pos->member != (head); \
pos = list_entry(pos->member.next, typeof(*pos), member), \
* \param member the name of the list_struct within the struct.
*/
#define list_for_each_entry_safe(pos, n, head, member) \
- for (pos = list_entry((head)->next, typeof(*pos), member), \
+ for (pos = list_first_entry((head), typeof(*pos), member), \
n = list_entry(pos->member.next, typeof(*pos), member); \
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, typeof(*n), member))
struct cfs_expr_list *el;
while (!list_empty(list)) {
- el = list_entry(list->next,
- struct cfs_expr_list, el_link);
+ el = list_first_entry(list,
+ struct cfs_expr_list, el_link);
list_del(&el->el_link);
cfs_expr_list_free(el);
}
struct cfs_expr_list *octet_el;
int idx = count - 1;
- octet_el = list_entry(ip_addr_expr->next, typeof(*octet_el), el_link);
+ octet_el = list_first_entry(ip_addr_expr, typeof(*octet_el), el_link);
(void) cfs_ip_addr_range_gen_recurse(ip_list, &idx, 3, 0, &octet_el->el_link, octet_el);
struct cfs_expr_list *el;
assert(!list_empty(numaddr));
- el = list_entry(numaddr->next, struct cfs_expr_list, el_link);
+ el = list_first_entry(numaddr, struct cfs_expr_list, el_link);
return cfs_expr_list_match(addr, el);
}
while (!list_empty(list)) {
struct addrrange *ar;
- ar = list_entry(list->next, struct addrrange, ar_link);
+ ar = list_first_entry(list, struct addrrange, ar_link);
cfs_expr_list_free_list(&ar->ar_numaddr_ranges);
list_del(&ar->ar_link);
char max_addr_str[IPSTRING_LENGTH];
int rc;
- first_nidrange = list_entry(nidlist->next, struct nidrange, nr_link);
+ first_nidrange = list_first_entry(nidlist, struct nidrange, nr_link);
netnum = first_nidrange->nr_netnum;
nf = first_nidrange->nr_netstrfns;
struct cfs_expr_list *el;
while (!list_empty(list)) {
- el = list_entry(list->next,
- struct cfs_expr_list, el_link);
+ el = list_first_entry(list,
+ struct cfs_expr_list, el_link);
list_del(&el->el_link);
cfs_expr_list_free(el);
}
while (!list_empty(resendq)) {
struct lnet_peer_ni *lpni;
- msg = list_entry(resendq->next, struct lnet_msg,
- msg_list);
+ msg = list_first_entry(resendq, struct lnet_msg,
+ msg_list);
list_del_init(&msg->msg_list);
break;
while (!list_empty(q)) {
- buf = list_entry(q->next,
- struct srpc_buffer,
- buf_list);
+ buf = list_first_entry(q,
+ struct srpc_buffer,
+ buf_list);
list_del(&buf->buf_list);
LIBCFS_FREE(buf, sizeof(*buf));
}
struct stt_timer *timer;
while (!list_empty(slot)) {
- timer = list_entry(slot->next, struct stt_timer, stt_list);
+ timer = list_first_entry(slot, struct stt_timer, stt_list);
if (timer->stt_expires > now)
break;
struct cYAML *obj = NULL;
if (!list_empty(list)) {
- pop = list_entry(list->next, struct cYAML_ll, list);
+ pop = list_first_entry(list, struct cYAML_ll, list);
obj = pop->obj;
if (print_info != NULL)
struct lstcon_rpc_ent *ent;
while (!list_empty(head)) {
- ent = list_entry(head->next, struct lstcon_rpc_ent, rpe_link);
+ ent = list_first_entry(head, struct lstcon_rpc_ent, rpe_link);
list_del(&ent->rpe_link);
free(ent);
* the target. Else retreive the next target entry.
*/
if (target->ft_chain.next == &fld->lcf_targets)
- target = list_entry(target->ft_chain.next->next,
- struct lu_fld_target, ft_chain);
+ target = list_first_entry(target->ft_chain.next,
+ struct lu_fld_target,
+ ft_chain);
else
target = list_entry(target->ft_chain.next,
struct lu_fld_target,
if (list_empty(head) || !(mask & (1 << i)))
continue;
- node = list_entry(head->next, struct ldlm_ibits_node,
- lin_link[i]);
+ node = list_first_entry(head, struct ldlm_ibits_node,
+ lin_link[i]);
pending = node->lock;
LDLM_DEBUG(pending, "Reprocessing lock from queue %d", i);
struct obd_export *export;
struct ldlm_lock *lock;
- lock = list_entry(expired->next, struct ldlm_lock,
- l_pending_chain);
+ lock = list_first_entry(expired, struct ldlm_lock,
+ l_pending_chain);
if ((void *)lock < LP_POISON + PAGE_SIZE &&
(void *)lock >= LP_POISON) {
spin_unlock_bh(&waiting_locks_spinlock);
__u32 *gen;
if (com->lc_type == LFSCK_TYPE_LAYOUT) {
- ltd = list_entry(phase_head->next,
- struct lfsck_tgt_desc,
- ltd_layout_phase_list);
+ ltd = list_first_entry(phase_head,
+ struct lfsck_tgt_desc,
+ ltd_layout_phase_list);
phase_list = <d->ltd_layout_phase_list;
gen = <d->ltd_layout_gen;
} else {
- ltd = list_entry(phase_head->next,
- struct lfsck_tgt_desc,
- ltd_namespace_phase_list);
+ ltd = list_first_entry(phase_head,
+ struct lfsck_tgt_desc,
+ ltd_namespace_phase_list);
phase_list = <d->ltd_namespace_phase_list;
gen = <d->ltd_namespace_gen;
}
spin_lock(<ds->ltd_lock);
while (!list_empty(phase_head)) {
if (com->lc_type == LFSCK_TYPE_LAYOUT) {
- ltd = list_entry(phase_head->next,
- struct lfsck_tgt_desc,
- ltd_layout_list);
+ ltd = list_first_entry(phase_head,
+ struct lfsck_tgt_desc,
+ ltd_layout_list);
if (!list_empty(<d->ltd_layout_phase_list))
list_del_init(
<d->ltd_layout_phase_list);
list_del_init(<d->ltd_layout_list);
} else {
- ltd = list_entry(phase_head->next,
- struct lfsck_tgt_desc,
- ltd_namespace_list);
+ ltd = list_first_entry(phase_head,
+ struct lfsck_tgt_desc,
+ ltd_namespace_list);
if (!list_empty(<d->ltd_namespace_phase_list))
list_del_init(
<d->ltd_namespace_phase_list);
scan:
spin_lock(lock);
while (!list_empty(head)) {
- libu = list_entry(head->next,
- struct lustre_index_backup_unit, libu_link);
+ libu = list_first_entry(head,
+ struct lustre_index_backup_unit,
+ libu_link);
list_del_init(&libu->libu_link);
spin_unlock(lock);
uint64_t oid;
while (!list_empty(list)) {
- obj = list_entry(list->next,
- struct osd_object, oo_unlinked_linkage);
+ obj = list_first_entry(list,
+ struct osd_object, oo_unlinked_linkage);
LASSERT(obj->oo_dn != NULL);
oid = obj->oo_dn->dn_object;