From thomas@cuivre.fr.eu.org  Sat Aug  4 22:29:50 2012
Return-Path: <thomas@cuivre.fr.eu.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 37B80106564A
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  4 Aug 2012 22:29:50 +0000 (UTC)
	(envelope-from thomas@cuivre.fr.eu.org)
Received: from melamine.cuivre.fr.eu.org (unknown [IPv6:2a01:e35:1392:86e0:224:e8ff:fe3d:60a5])
	by mx1.freebsd.org (Postfix) with ESMTP id B31198FC08
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  4 Aug 2012 22:29:49 +0000 (UTC)
Received: by melamine.cuivre.fr.eu.org (Postfix, from userid 1000)
	id ADAF7382A; Sun,  5 Aug 2012 00:29:48 +0200 (CEST)
Message-Id: <20120804222948.ADAF7382A@melamine.cuivre.fr.eu.org>
Date: Sun,  5 Aug 2012 00:29:48 +0200 (CEST)
From: Thomas Quinot <thomas@cuivre.fr.eu.org>
Reply-To: Thomas Quinot <thomas@cuivre.fr.eu.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: geom_multipath: rotate only considers last 2 valid providers
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         170379
>Category:       kern
>Synopsis:       [geom] geom_multipath: rotate only considers last 2 valid providers
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    thomas
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Aug 04 22:30:01 UTC 2012
>Closed-Date:    Sat Aug 25 10:38:31 UTC 2012
>Last-Modified:  Sat Aug 25 10:40:59 UTC 2012
>Originator:     Thomas Quinot
>Release:        FreeBSD 8.3-STABLE amd64
>Organization:
>Environment:
System: FreeBSD melamine.cuivre.fr.eu.org 8.3-STABLE FreeBSD 8.3-STABLE #4: Sat Jul 14 15:27:47 CEST 2012 thomas@melamine.cuivre.fr.eu.org:/usr/obj/usr/src/sys/GENERIC amd64


	
>Description:
	"gmultipath rotate" only alternates between the last two valid providers,
	instead of rotating over all providers.
>How-To-Repeat:

# gmultipath status
        Name   Status  Components
multipath/mm  OPTIMAL  md3 (ACTIVE)
                       md2 (PASSIVE)
                       md1 (PASSIVE)
                       md0 (PASSIVE)
# gmultipath rotate mm;gml ultipath status mm
        Name   Status  Components
multipath/mm  OPTIMAL  md3 (PASSIVE)
                       md2 (PASSIVE)
                       md1 (PASSIVE)
                       md0 (ACTIVE)
# gmultipath rotate mm;gmultipath status mm
        Name   Status  Components
multipath/mm  OPTIMAL  md3 (PASSIVE)
                       md2 (PASSIVE)
                       md1 (ACTIVE)
                       md0 (PASSIVE)
# gmultipath rotate mm;gmultipath status mm
        Name   Status  Components
multipath/mm  OPTIMAL  md3 (PASSIVE)
                       md2 (PASSIVE)
                       md1 (PASSIVE)
                       md0 (ACTIVE)
# gmultipath rotate mm;gmultipath status mm
        Name   Status  Components
multipath/mm  OPTIMAL  md3 (PASSIVE)
                       md2 (PASSIVE)
                       md1 (ACTIVE)
                       md0 (PASSIVE)

# gmultipath fail mm md0
# gmultipath rotate mm;gmultipath status mm
        Name    Status  Components
multipath/mm  DEGRADED  md3 (PASSIVE)
                        md2 (ACTIVE)
                        md1 (PASSIVE)
                        md0 (FAIL)
# gmultipath rotate mm;gmultipath status mm
        Name    Status  Components
multipath/mm  DEGRADED  md3 (PASSIVE)
                        md2 (PASSIVE)
                        md1 (ACTIVE)
                        md0 (FAIL)
# gmultipath rotate mm;gmultipath status mm
        Name    Status  Components
multipath/mm  DEGRADED  md3 (PASSIVE)
                        md2 (ACTIVE)
                        md1 (PASSIVE)
                        md0 (FAIL)
>Fix:

Index: sys/geom/multipath/g_multipath.c
===================================================================
--- g_multipath.c	(rvision 239012)
+++ g_multipath.c	(copie de travail)
@@ -590,19 +590,26 @@
 static int
 g_multipath_rotate(struct g_geom *gp)
 {
-	struct g_consumer *lcp;
+	struct g_consumer *lcp, *first_good_cp = NULL;
 	struct g_multipath_softc *sc = gp->softc;
+	int active_cp_seen = 0;
 
 	g_topology_assert();
 	if (sc == NULL)
 		return (ENXIO);
 	LIST_FOREACH(lcp, &gp->consumer, consumer) {
 		if ((lcp->index & MP_BAD) == 0) {
-			if (sc->sc_active != lcp)
+			if (first_good_cp == NULL)
+				first_good_cp = lcp;
+			if (active_cp_seen)
 				break;
 		}
+		if (sc->sc_active == lcp)
+			active_cp_seen = 1;
 	}
-	if (lcp) {
+	if (lcp == NULL && first_good_cp != NULL)
+		lcp = first_good_cp;
+	if (lcp && lcp != sc->sc_active) {
 		sc->sc_active = lcp;
 		if (sc->sc_active_active != 1)
 			printf("GEOM_MULTIPATH: %s is now active path in %s\n",


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-geom 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Aug 4 23:48:05 UTC 2012 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=170379 
State-Changed-From-To: open->closed 
State-Changed-By: thomas 
State-Changed-When: Sat Aug 25 10:37:30 UTC 2012 
State-Changed-Why:  
Fixed in rev. 239673 


Responsible-Changed-From-To: freebsd-geom->thomas 
Responsible-Changed-By: thomas 
Responsible-Changed-When: Sat Aug 25 10:37:30 UTC 2012 
Responsible-Changed-Why:  
I'll take this one over. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=170379 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/170379: commit references a PR
Date: Sat, 25 Aug 2012 10:36:46 +0000 (UTC)

 Author: thomas
 Date: Sat Aug 25 10:36:31 2012
 New Revision: 239673
 URL: http://svn.freebsd.org/changeset/base/239673
 
 Log:
   (g_multipath_rotate): Fix algorithm so that it does rotate over all good
   providers, not just the last two.
   
   PR:		kern/170379
   Reviewed by:	mav
   MFC after:	2 weeks
 
 Modified:
   head/sys/geom/multipath/g_multipath.c
 
 Modified: head/sys/geom/multipath/g_multipath.c
 ==============================================================================
 --- head/sys/geom/multipath/g_multipath.c	Sat Aug 25 09:26:37 2012	(r239672)
 +++ head/sys/geom/multipath/g_multipath.c	Sat Aug 25 10:36:31 2012	(r239673)
 @@ -590,19 +590,26 @@ g_multipath_destroy_geom(struct gctl_req
  static int
  g_multipath_rotate(struct g_geom *gp)
  {
 -	struct g_consumer *lcp;
 +	struct g_consumer *lcp, *first_good_cp = NULL;
  	struct g_multipath_softc *sc = gp->softc;
 +	int active_cp_seen = 0;
  
  	g_topology_assert();
  	if (sc == NULL)
  		return (ENXIO);
  	LIST_FOREACH(lcp, &gp->consumer, consumer) {
  		if ((lcp->index & MP_BAD) == 0) {
 -			if (sc->sc_active != lcp)
 +			if (first_good_cp == NULL)
 +				first_good_cp = lcp;
 +			if (active_cp_seen)
  				break;
  		}
 +		if (sc->sc_active == lcp)
 +			active_cp_seen = 1;
  	}
 -	if (lcp) {
 +	if (lcp == NULL)
 +		lcp = first_good_cp;
 +	if (lcp && lcp != sc->sc_active) {
  		sc->sc_active = lcp;
  		if (sc->sc_active_active != 1)
  			printf("GEOM_MULTIPATH: %s is now active path in %s\n",
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
