Skip to content

Commit 8ef5016

Browse files
committed
libsa/zfs: simplify vdev_find_previous()
An empty list case is properly covered by the cycle. Don't pass pointer to vdev being looked up, pass just id. Reviewed by: mav, imp Differential Revision: https://reviews.freebsd.org/D51911
1 parent de05555 commit 8ef5016

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

stand/libsa/zfs/zfsimpl.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,22 +1035,19 @@ vdev_init(uint64_t guid, const nvlist_t *nvlist, vdev_t **vdevp)
10351035
* STAILQ_INSERT_AFTER.
10361036
*/
10371037
static vdev_t *
1038-
vdev_find_previous(vdev_t *top_vdev, vdev_t *vdev)
1038+
vdev_find_previous(vdev_t *top_vdev, uint64_t id)
10391039
{
10401040
vdev_t *v, *previous;
10411041

1042-
if (STAILQ_EMPTY(&top_vdev->v_children))
1043-
return (NULL);
1044-
10451042
previous = NULL;
10461043
STAILQ_FOREACH(v, &top_vdev->v_children, v_childlink) {
1047-
if (v->v_id > vdev->v_id)
1044+
if (v->v_id > id)
10481045
return (previous);
10491046

1050-
if (v->v_id == vdev->v_id)
1047+
if (v->v_id == id)
10511048
return (v);
10521049

1053-
if (v->v_id < vdev->v_id)
1050+
if (v->v_id < id)
10541051
previous = v;
10551052
}
10561053
return (previous);
@@ -1085,7 +1082,7 @@ vdev_insert(vdev_t *top_vdev, vdev_t *vdev)
10851082
* so we can use either STAILQ_INSERT_HEAD or STAILQ_INSERT_AFTER
10861083
* as STAILQ does not have insert before.
10871084
*/
1088-
previous = vdev_find_previous(top_vdev, vdev);
1085+
previous = vdev_find_previous(top_vdev, vdev->v_id);
10891086

10901087
if (previous == NULL) {
10911088
STAILQ_INSERT_HEAD(&top_vdev->v_children, vdev, v_childlink);

0 commit comments

Comments
 (0)