From: Martin Wilck <mwilck@xxxxxxxx> This helper clears all fields of struct path (except pp->udev) that must be re-ininitialized if the path ever is to be used again. Reviewed-by: Benjamin Marzinski <bmarzins@xxxxxxxxxx> Signed-off-by: Martin Wilck <mwilck@xxxxxxxx> --- libmultipath/structs.c | 19 +++++++++++++++++-- libmultipath/structs.h | 1 + libmultipath/structs_vec.c | 9 +-------- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/libmultipath/structs.c b/libmultipath/structs.c index d227ec0..28bf8eb 100644 --- a/libmultipath/structs.c +++ b/libmultipath/structs.c @@ -114,19 +114,34 @@ alloc_path (void) } void -free_path (struct path * pp) +uninitialize_path(struct path *pp) { if (!pp) return; + pp->dmstate = PSTATE_UNDEF; + pp->uid_attribute = NULL; + pp->getuid = NULL; + if (checker_selected(&pp->checker)) checker_put(&pp->checker); if (prio_selected(&pp->prio)) prio_put(&pp->prio); - if (pp->fd >= 0) + if (pp->fd >= 0) { close(pp->fd); + pp->fd = -1; + } +} + +void +free_path (struct path * pp) +{ + if (!pp) + return; + + uninitialize_path(pp); if (pp->udev) { udev_device_unref(pp->udev); diff --git a/libmultipath/structs.h b/libmultipath/structs.h index 917e408..5f45f21 100644 --- a/libmultipath/structs.h +++ b/libmultipath/structs.h @@ -416,6 +416,7 @@ struct host_group { struct path * alloc_path (void); struct pathgroup * alloc_pathgroup (void); struct multipath * alloc_multipath (void); +void uninitialize_path(struct path *pp); void free_path (struct path *); void free_pathvec (vector vec, enum free_path_mode free_paths); void free_pathgroup (struct pathgroup * pgp, enum free_path_mode free_paths); diff --git a/libmultipath/structs_vec.c b/libmultipath/structs_vec.c index 2b7c154..ea84a20 100644 --- a/libmultipath/structs_vec.c +++ b/libmultipath/structs_vec.c @@ -103,14 +103,7 @@ void orphan_path(struct path *pp, const char *reason) pp->mpp->hwe = NULL; } pp->mpp = NULL; - pp->dmstate = PSTATE_UNDEF; - pp->uid_attribute = NULL; - pp->getuid = NULL; - prio_put(&pp->prio); - checker_put(&pp->checker); - if (pp->fd >= 0) - close(pp->fd); - pp->fd = -1; + uninitialize_path(pp); } void orphan_paths(vector pathvec, struct multipath *mpp, const char *reason) -- 2.28.0 -- dm-devel mailing list dm-devel@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/dm-devel