Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Sep 2012 07:48:17 +0000 (UTC)
From:      Thomas Quinot <thomas@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r240160 - in stable/8: sbin/geom/class/multipath sys/geom/multipath
Message-ID:  <201209060748.q867mHip083444@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: thomas
Date: Thu Sep  6 07:48:17 2012
New Revision: 240160
URL: http://svn.freebsd.org/changeset/base/240160

Log:
  MFC rev. 239012 to stable/8:
  New command "gmultipath prefer" to force selection of a specified
  provider in an Active/Passive configuration.

Modified:
  stable/8/sbin/geom/class/multipath/geom_multipath.c
  stable/8/sbin/geom/class/multipath/gmultipath.8
  stable/8/sys/geom/multipath/g_multipath.c
Directory Properties:
  stable/8/sbin/geom/class/multipath/   (props changed)
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/boot/   (props changed)
  stable/8/sys/cddl/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/compat/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)
  stable/8/sys/dev/   (props changed)
  stable/8/sys/dev/e1000/   (props changed)
  stable/8/sys/dev/sound/   (props changed)
  stable/8/sys/dev/sound/pci/   (props changed)
  stable/8/sys/dev/virtio/   (props changed)
  stable/8/sys/kern/   (props changed)
  stable/8/sys/sys/   (props changed)
  stable/8/sys/vm/   (props changed)

Modified: stable/8/sbin/geom/class/multipath/geom_multipath.c
==============================================================================
--- stable/8/sbin/geom/class/multipath/geom_multipath.c	Thu Sep  6 07:45:45 2012	(r240159)
+++ stable/8/sbin/geom/class/multipath/geom_multipath.c	Thu Sep  6 07:48:17 2012	(r240160)
@@ -49,6 +49,7 @@ uint32_t version = G_MULTIPATH_VERSION;
 static void mp_main(struct gctl_req *, unsigned int);
 static void mp_label(struct gctl_req *);
 static void mp_clear(struct gctl_req *);
+static void mp_prefer(struct gctl_req *);
 
 struct g_command class_commands[] = {
 	{
@@ -87,6 +88,10 @@ struct g_command class_commands[] = {
 		NULL, "[-v] name prov"
 	},
 	{
+		"prefer", G_FLAG_VERBOSE, mp_main, G_NULL_OPTS,
+		NULL, "[-v] prov ..."
+	},
+	{
 		"fail", G_FLAG_VERBOSE, NULL, G_NULL_OPTS,
 		NULL, "[-v] name prov"
 	},
@@ -131,6 +136,8 @@ mp_main(struct gctl_req *req, unsigned i
 		mp_label(req);
 	} else if (strcmp(name, "clear") == 0) {
 		mp_clear(req);
+	} else if (strcmp(name, "prefer") == 0) {
+		mp_prefer(req);
 	} else {
 		gctl_error(req, "Unknown command: %s.", name);
 	}
@@ -293,3 +300,22 @@ mp_clear(struct gctl_req *req)
 	}
 }
 
+static void
+mp_prefer(struct gctl_req *req)
+{
+	const char *name, *comp, *errstr;
+	int nargs;
+
+	nargs = gctl_get_int(req, "nargs");
+	if (nargs != 2) {
+		gctl_error(req, "Usage: prefer GEOM PROVIDER");
+		return;
+	}
+	name = gctl_get_ascii(req, "arg0");
+	comp = gctl_get_ascii(req, "arg1");
+	errstr = gctl_issue (req);
+	if (errstr != NULL) {
+		fprintf(stderr, "Can't set %s preferred provider to %s: %s.\n",
+		    name, comp, errstr);
+	}
+}

Modified: stable/8/sbin/geom/class/multipath/gmultipath.8
==============================================================================
--- stable/8/sbin/geom/class/multipath/gmultipath.8	Thu Sep  6 07:45:45 2012	(r240159)
+++ stable/8/sbin/geom/class/multipath/gmultipath.8	Thu Sep  6 07:48:17 2012	(r240160)
@@ -66,6 +66,11 @@
 .Op Fl v
 .Ar name
 .Nm
+.Cm prefer
+.Op Fl v
+.Ar name
+.Ar prov
+.Nm
 .Cm getactive
 .Op Fl v
 .Ar name
@@ -171,7 +176,9 @@ If there are other paths present, new re
 Mark specified provider as a path of the specified multipath device as
 operational, allowing it to handle requests.
 .It Cm rotate
-Change the active provider/path in Active/Passive mode.
+Change the active provider/path to the next available provider in Active/Passive mode.
+.It Cm prefer
+Change the active provider/path to the specified provider in Active/Passive mode.
 .It Cm getactive
 Get the currently active provider(s)/path(s).
 .It Cm destroy

Modified: stable/8/sys/geom/multipath/g_multipath.c
==============================================================================
--- stable/8/sys/geom/multipath/g_multipath.c	Thu Sep  6 07:45:45 2012	(r240159)
+++ stable/8/sys/geom/multipath/g_multipath.c	Thu Sep  6 07:48:17 2012	(r240160)
@@ -847,6 +847,78 @@ g_multipath_ctl_add_name(struct gctl_req
 }
 
 static void
+g_multipath_ctl_prefer(struct gctl_req *req, struct g_class *mp)
+{
+	struct g_geom *gp;
+	struct g_multipath_softc *sc;
+	struct g_consumer *cp;
+	const char *name, *mpname;
+	static const char devpf[6] = "/dev/";
+	int *nargs;
+
+	g_topology_assert();
+
+	mpname = gctl_get_asciiparam(req, "arg0");
+        if (mpname == NULL) {
+                gctl_error(req, "No 'arg0' argument");
+                return;
+        }
+	gp = g_multipath_find_geom(mp, mpname);
+	if (gp == NULL) {
+		gctl_error(req, "Device %s is invalid", mpname);
+		return;
+	}
+	sc = gp->softc;
+
+	nargs = gctl_get_paraml(req, "nargs", sizeof(*nargs));
+	if (nargs == NULL) {
+		gctl_error(req, "No 'nargs' argument");
+		return;
+	}
+	if (*nargs != 2) {
+		gctl_error(req, "missing device");
+		return;
+	}
+
+	name = gctl_get_asciiparam(req, "arg1");
+	if (name == NULL) {
+		gctl_error(req, "No 'arg1' argument");
+		return;
+	}
+	if (strncmp(name, devpf, 5) == 0) {
+		name += 5;
+	}
+
+	LIST_FOREACH(cp, &gp->consumer, consumer) {
+		if (cp->provider != NULL
+                      && strcmp(cp->provider->name, name) == 0)
+		    break;
+	}
+
+	if (cp == NULL) {
+		gctl_error(req, "Provider %s not found", name);
+		return;
+	}
+
+	mtx_lock(&sc->sc_mtx);
+
+	if (cp->index & MP_BAD) {
+		gctl_error(req, "Consumer %s is invalid", name);
+		mtx_unlock(&sc->sc_mtx);
+		return;
+	}
+
+	/* Here when the consumer is present and in good shape */
+
+	sc->sc_active = cp;
+	if (!sc->sc_active_active)
+	    printf("GEOM_MULTIPATH: %s now active path in %s\n",
+		sc->sc_active->provider->name, sc->sc_name);
+
+	mtx_unlock(&sc->sc_mtx);
+}
+
+static void
 g_multipath_ctl_add(struct gctl_req *req, struct g_class *mp)
 {
 	struct g_multipath_softc *sc;
@@ -1276,6 +1348,8 @@ g_multipath_config(struct gctl_req *req,
 		gctl_error(req, "Userland and kernel parts are out of sync");
 	} else if (strcmp(verb, "add") == 0) {
 		g_multipath_ctl_add(req, mp);
+	} else if (strcmp(verb, "prefer") == 0) {
+		g_multipath_ctl_prefer(req, mp);
 	} else if (strcmp(verb, "create") == 0) {
 		g_multipath_ctl_create(req, mp);
 	} else if (strcmp(verb, "configure") == 0) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201209060748.q867mHip083444>