list_entry((ptr)->next, type, member)
/**
+ * list_last_entry - get the last 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_last_entry(ptr, type, member) \
+ list_entry((ptr)->prev, type, member)
+
+/**
* Iterate over a list
* \param pos the iterator
* \param head the list to iterate over
return size;
if (!list_empty(&descr->ud_net_id.udn_net_num_range)) {
- expr = list_entry(descr->ud_net_id.udn_net_num_range.next,
- struct cfs_expr_list, el_link);
+ expr = list_first_entry(&descr->ud_net_id.udn_net_num_range,
+ struct cfs_expr_list, el_link);
range_count = lnet_get_list_len(&expr->el_exprs);
}
/* copy the net information */
if (!list_empty(&nid_descr->ud_net_id.udn_net_num_range)) {
- expr = list_entry(nid_descr->ud_net_id.udn_net_num_range.next,
- struct cfs_expr_list, el_link);
+ expr = list_first_entry(&nid_descr->ud_net_id.udn_net_num_range,
+ struct cfs_expr_list, el_link);
net_expr_count = lnet_get_list_len(&expr->el_exprs);
} else {
net_expr_count = 0;
INIT_LIST_HEAD(&tmp[0]);
INIT_LIST_HEAD(&tmp[1]);
- memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
+ memset(&lnet_stat_result, 0, sizeof(lnet_stat_result));
while (!list_empty(&resultp[idx])) {
if (list_empty(&resultp[1 - idx])) {
- fprintf(stderr, "Group is changed, re-run stat\n");
- break;
- }
+ fprintf(stderr, "Group is changed, re-run stat\n");
+ break;
+ }
- new = list_entry(resultp[idx].next, struct lstcon_rpc_ent,
- rpe_link);
- old = list_entry(resultp[1 - idx].next, struct lstcon_rpc_ent,
- rpe_link);
+ new = list_first_entry(&resultp[idx], struct lstcon_rpc_ent,
+ rpe_link);
+ old = list_first_entry(&resultp[1 - idx], struct lstcon_rpc_ent,
+ rpe_link);
- /* first time get stats result, can't calculate diff */
- if (new->rpe_peer.nid == LNET_NID_ANY)
- break;
+ /* first time get stats result, can't calculate diff */
+ if (new->rpe_peer.nid == LNET_NID_ANY)
+ break;
- if (new->rpe_peer.nid != old->rpe_peer.nid ||
- new->rpe_peer.pid != old->rpe_peer.pid) {
- /* Something wrong. i.e, somebody change the group */
- break;
- }
+ if (new->rpe_peer.nid != old->rpe_peer.nid ||
+ new->rpe_peer.pid != old->rpe_peer.pid) {
+ /* Something wrong. i.e, somebody change the group */
+ break;
+ }
list_move_tail(&new->rpe_link, &tmp[idx]);
list_move_tail(&old->rpe_link, &tmp[1 - idx]);
- if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
- old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
- errcount ++;
- continue;
- }
+ if (new->rpe_rpc_errno != 0 || new->rpe_fwk_errno != 0 ||
+ old->rpe_rpc_errno != 0 || old->rpe_fwk_errno != 0) {
+ errcount++;
+ continue;
+ }
sfwk_new = (struct sfw_counters *)&new->rpe_payload[0];
sfwk_old = (struct sfw_counters *)&old->rpe_payload[0];
lst_reset_rpcent(&srp->srp_result[1 - idx]);
}
- idx = 1 - idx;
+ idx = 1 - idx;
- if (count > 0)
- count--;
- } while (count == -1 || count > 0);
+ if (count > 0)
+ count--;
+ } while (count == -1 || count > 0);
out:
while (!list_empty(&head)) {
- srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
+ srp = list_first_entry(&head, lst_stat_req_param_t, srp_link);
list_del(&srp->srp_link);
- lst_stat_req_param_free(srp);
- }
+ lst_stat_req_param_free(srp);
+ }
- return rc;
+ return rc;
}
int
}
out:
while (!list_empty(&head)) {
- srp = list_entry(head.next, lst_stat_req_param_t, srp_link);
+ srp = list_first_entry(&head, lst_stat_req_param_t, srp_link);
list_del(&srp->srp_link);
- lst_stat_req_param_free(srp);
- }
+ lst_stat_req_param_free(srp);
+ }
- return rc;
+ return rc;
}
int
return ret;
while (!list_empty(&head)) {
- lpi = list_entry(head.next, struct lfs_project_item, lpi_list);
+ lpi = list_first_entry(&head, struct lfs_project_item,
+ lpi_list);
list_del(&lpi->lpi_list);
rc = lfs_project_handle_dir(&head, lpi->lpi_pathname,
phc, func);
if (new == NULL)
return -1;
- last = list_entry(layout->llot_comp_list.prev, typeof(*last),
- llc_list);
+ last = list_last_entry(&layout->llot_comp_list, typeof(*last),
+ llc_list);
list_add_tail(&new->llc_list, &layout->llot_comp_list);
return -1;
}
layout->llot_cur_comp =
- list_entry(comp->llc_list.prev, typeof(*comp), llc_list);
+ list_last_entry(&comp->llc_list, typeof(*comp), llc_list);
if (comp->llc_list.prev == &layout->llot_comp_list)
layout->llot_cur_comp = NULL;
return 1;
}
- head = list_entry(layout->llot_comp_list.next, typeof(*head), llc_list);
- tail = list_entry(layout->llot_comp_list.prev, typeof(*tail), llc_list);
+ head = list_first_entry(&layout->llot_comp_list, typeof(*head),
+ llc_list);
+ tail = list_last_entry(&layout->llot_comp_list, typeof(*tail),
+ llc_list);
switch (pos) {
case LLAPI_LAYOUT_COMP_USE_FIRST:
layout->llot_cur_comp = head;
errno = ENOENT;
return 1;
}
- layout->llot_cur_comp = list_entry(comp->llc_list.next,
- typeof(*comp), llc_list);
+ layout->llot_cur_comp = list_first_entry(&comp->llc_list,
+ typeof(*comp),
+ llc_list);
break;
case LLAPI_LAYOUT_COMP_USE_LAST:
layout->llot_cur_comp = tail;
errno = ENOENT;
return 1;
}
- layout->llot_cur_comp = list_entry(comp->llc_list.prev,
- typeof(*comp), llc_list);
+ layout->llot_cur_comp = list_last_entry(&comp->llc_list,
+ typeof(*comp),
+ llc_list);
break;
default:
errno = EINVAL;
if (!layout->llot_is_composite)
return 0;
- head = list_entry(layout->llot_comp_list.next, typeof(*comp), llc_list);
+ head = list_first_entry(&layout->llot_comp_list, typeof(*comp),
+ llc_list);
if (head == NULL)
return -EINVAL;
if (head->llc_id == 0 && !(head->llc_flags & LCME_FL_INIT))
return -EISDIR;
/* traverse the components from the tail to find the last init one */
- comp = list_entry(layout->llot_comp_list.prev, typeof(*comp), llc_list);
+ comp = list_last_entry(&layout->llot_comp_list, typeof(*comp),
+ llc_list);
while (comp != head) {
if (comp->llc_flags & LCME_FL_INIT)
break;
- comp = list_entry(comp->llc_list.prev, typeof(*comp), llc_list);
+ comp = list_last_entry(&comp->llc_list, typeof(*comp),
+ llc_list);
}
layout->llot_cur_comp = comp;
}
if (comp->llc_list.prev != &layout->llot_comp_list)
- prev = list_entry(comp->llc_list.prev, typeof(*prev),
- llc_list);
+ prev = list_last_entry(&comp->llc_list, typeof(*prev),
+ llc_list);
else
prev = NULL;
if (comp->llc_list.next != &layout->llot_comp_list)
- next = list_entry(comp->llc_list.next, typeof(*next),
- llc_list);
+ next = list_first_entry(&comp->llc_list, typeof(*next),
+ llc_list);
else
next = NULL;
while (i < count) {
struct fid_rec *f;
- f = list_entry(head.lh_list.next, struct fid_rec, fr_link);
+ f = list_first_entry(&head.lh_list, struct fid_rec, fr_link);
rc = lsom_update_one(f);
if (rc == 0) {
list_del_init(&f->fr_link);
* pop the record, start to handle it immediately.
*/
now = time(NULL);
- f = list_entry(head.lh_list.next, struct fid_rec, fr_link);
+ f = list_first_entry(&head.lh_list, struct fid_rec, fr_link);
if (now > ((f->fr_time >> 30) + opt.o_min_age))
count = 1;
}
struct snapshot_target *st;
while (!list_empty(&si->si_mdts_list)) {
- st = list_entry(si->si_mdts_list.next,
- struct snapshot_target, st_list);
+ st = list_first_entry(&si->si_mdts_list,
+ struct snapshot_target, st_list);
list_del(&st->st_list);
free(st->st_host);
free(st->st_fhost);
}
while (!list_empty(&si->si_osts_list)) {
- st = list_entry(si->si_osts_list.next,
- struct snapshot_target, st_list);
+ st = list_first_entry(&si->si_osts_list,
+ struct snapshot_target, st_list);
list_del(&st->st_list);
free(st->st_host);
free(st->st_fhost);
int rc;
int foreign = 0;
- st = list_entry(si->si_osts_list.next, struct snapshot_target,
- st_list);
+ st = list_first_entry(&si->si_osts_list, struct snapshot_target,
+ st_list);
again:
rc = 0;
memset(buf, 0, sizeof(buf));
goto again;
}
while (!list_empty(&list_sub_items)) {
- lsi = list_entry(list_sub_items.next,
- struct list_sub_item, lsi_list);
+ lsi = list_first_entry(&list_sub_items,
+ struct list_sub_item, lsi_list);
list_del(&lsi->lsi_list);
if (!rc) {
si->si_ssname = lsi->lsi_ssname;
ret = 0;
while (!list_empty(&cfg_list) && ret == 0) {
- lce = list_entry(cfg_list.next, struct lustre_cfg_entry,
- lce_list);
+ lce = list_first_entry(&cfg_list, struct lustre_cfg_entry,
+ lce_list);
list_del(&lce->lce_list);
snprintf(filepnm, sizeof(filepnm), "%s/%s", cfg_dir,
lce->lce_name);
closedir(dir);
while (!list_empty(&cfg_list)) {
- lce = list_entry(cfg_list.next, struct lustre_cfg_entry,
- lce_list);
+ lce = list_first_entry(&cfg_list, struct lustre_cfg_entry,
+ lce_list);
list_del(&lce->lce_list);
lustre_cfg_entry_fini(lce);
}