[libmultipath] split free_multipath_attributes() out of free_multipath()
authorChristophe Varoqui <root@xa-s05.(none)>
Thu, 17 Nov 2005 13:29:06 +0000 (14:29 +0100)
committerChristophe Varoqui <root@xa-s05.(none)>
Thu, 17 Nov 2005 13:29:06 +0000 (14:29 +0100)
Code factorization in update_multipath_strings()
From Edward Goggin, EMC, patch-chest

libmultipath/structs.c
libmultipath/structs.h
multipathd/main.c

index 863b29e..09be490 100644 (file)
@@ -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);
index ba51701..fa5fbad 100644 (file)
@@ -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);
 
index 8fe88e6..6ad5de1 100644 (file)
@@ -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;