From 27288f4a5688419631bece7dbcfc1b46fdb5f32e Mon Sep 17 00:00:00 2001 From: Christophe Varoqui Date: Thu, 17 Nov 2005 14:29:06 +0100 Subject: [PATCH] [libmultipath] split free_multipath_attributes() out of free_multipath() Code factorization in update_multipath_strings() From Edward Goggin, EMC, patch-chest --- libmultipath/structs.c | 37 +++++++++++++++++++++++++++---------- libmultipath/structs.h | 1 + multipathd/main.c | 16 +--------------- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/libmultipath/structs.c b/libmultipath/structs.c index 863b29e..09be490 100644 --- a/libmultipath/structs.c +++ b/libmultipath/structs.c @@ -117,8 +117,8 @@ alloc_multipath (void) return mpp; } -void -free_multipath (struct multipath * mpp, int free_paths) +extern void +free_multipath_attributes (struct multipath * mpp) { if (!mpp) return; @@ -126,23 +126,40 @@ free_multipath (struct multipath * mpp, int free_paths) if (mpp->selector && mpp->selector != conf->selector && (!mpp->mpe || (mpp->mpe && mpp->selector != mpp->mpe->selector)) && - (!mpp->hwe || (mpp->hwe && mpp->selector != mpp->hwe->selector))) + (!mpp->hwe || (mpp->hwe && mpp->selector != mpp->hwe->selector))) { FREE(mpp->selector); - - if (mpp->alias && - (!mpp->mpe || (mpp->mpe && mpp->alias != mpp->mpe->alias)) && - (mpp->wwid && mpp->alias != mpp->wwid)) - FREE(mpp->alias); + mpp->selector = NULL; + } if (mpp->features && mpp->features != conf->features && - (!mpp->hwe || (mpp->hwe && mpp->features != mpp->hwe->features))) + (!mpp->hwe || (mpp->hwe && mpp->features != mpp->hwe->features))) { FREE(mpp->features); + mpp->features = NULL; + } if (mpp->hwhandler && mpp->hwhandler != conf->default_hwhandler && - (!mpp->hwe || (mpp->hwe && mpp->hwhandler != mpp->hwe->hwhandler))) + (!mpp->hwe || (mpp->hwe && mpp->hwhandler != mpp->hwe->hwhandler))) { FREE(mpp->hwhandler); + mpp->hwhandler = NULL; + } +} + +void +free_multipath (struct multipath * mpp, int free_paths) +{ + if (!mpp) + return; + + free_multipath_attributes(mpp); + + if (mpp->alias && + (!mpp->mpe || (mpp->mpe && mpp->alias != mpp->mpe->alias)) && + (mpp->wwid && mpp->alias != mpp->wwid)) { + FREE(mpp->alias); + mpp->alias = NULL; + } if (mpp->dmi) FREE(mpp->dmi); diff --git a/libmultipath/structs.h b/libmultipath/structs.h index ba51701..fa5fbad 100644 --- a/libmultipath/structs.h +++ b/libmultipath/structs.h @@ -160,6 +160,7 @@ void free_pathvec (vector vec, int free_paths); void free_pathgroup (struct pathgroup * pgp, int free_paths); void free_pgvec (vector pgvec, int free_paths); void free_multipath (struct multipath *, int free_paths); +void free_multipath_attributes (struct multipath *); void drop_multipath (vector mpvec, char * wwid, int free_paths); void free_multipathvec (vector mpvec, int free_paths); diff --git a/multipathd/main.c b/multipathd/main.c index 8fe88e6..6ad5de1 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -223,21 +223,7 @@ update_multipath_status (struct multipath *mpp) static int update_multipath_strings (struct multipath *mpp, vector pathvec) { - if (mpp->selector) { - FREE(mpp->selector); - mpp->selector = NULL; - } - - if (mpp->features) { - FREE(mpp->features); - mpp->features = NULL; - } - - if (mpp->hwhandler) { - FREE(mpp->hwhandler); - mpp->hwhandler = NULL; - } - + free_multipath_attributes(mpp); free_pgvec(mpp->pg, KEEP_PATHS); mpp->pg = NULL; -- 2.7.4