git: 8ef5016f73b9 - main - libsa/zfs: simplify vdev_find_previous()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 20 Aug 2025 14:53:40 UTC
The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=8ef5016f73b9a4db8ee7b268bd27bb7246c84960 commit 8ef5016f73b9a4db8ee7b268bd27bb7246c84960 Author: Gleb Smirnoff <glebius@FreeBSD.org> AuthorDate: 2025-08-20 14:51:14 +0000 Commit: Gleb Smirnoff <glebius@FreeBSD.org> CommitDate: 2025-08-20 14:51:14 +0000 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 --- stand/libsa/zfs/zfsimpl.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/stand/libsa/zfs/zfsimpl.c b/stand/libsa/zfs/zfsimpl.c index 4bfb7d4179fb..d923abeee56e 100644 --- a/stand/libsa/zfs/zfsimpl.c +++ b/stand/libsa/zfs/zfsimpl.c @@ -1035,22 +1035,19 @@ vdev_init(uint64_t guid, const nvlist_t *nvlist, vdev_t **vdevp) * STAILQ_INSERT_AFTER. */ static vdev_t * -vdev_find_previous(vdev_t *top_vdev, vdev_t *vdev) +vdev_find_previous(vdev_t *top_vdev, uint64_t id) { vdev_t *v, *previous; - if (STAILQ_EMPTY(&top_vdev->v_children)) - return (NULL); - previous = NULL; STAILQ_FOREACH(v, &top_vdev->v_children, v_childlink) { - if (v->v_id > vdev->v_id) + if (v->v_id > id) return (previous); - if (v->v_id == vdev->v_id) + if (v->v_id == id) return (v); - if (v->v_id < vdev->v_id) + if (v->v_id < id) previous = v; } return (previous); @@ -1085,7 +1082,7 @@ vdev_insert(vdev_t *top_vdev, vdev_t *vdev) * so we can use either STAILQ_INSERT_HEAD or STAILQ_INSERT_AFTER * as STAILQ does not have insert before. */ - previous = vdev_find_previous(top_vdev, vdev); + previous = vdev_find_previous(top_vdev, vdev->v_id); if (previous == NULL) { STAILQ_INSERT_HEAD(&top_vdev->v_children, vdev, v_childlink);