Re: gmirror provider name limit [Was: Re: geom_label: gpt/labelname for gmirror provider?]

From: Dimitry Andric <dimitry_at_andric.com>
Date: Wed, 29 Jul 2009 22:30:19 +0200
On 2009-07-28 22:59, Marius Nünnerich wrote:
> The current size of the gmirror metadata is 135 bytes so a
> providername of 64 would easily fit but I'm not sure it's worth the
> hassle. Maybe one could include it if/when there is a new version.
> Anyway till then it should be documented and there should be an error
> message from the utils which create the mirror (and the other setups).

Please try the following patch, to enable an error message, in case any
of the providers' names exceeds the maximum length.  It should be enough
to do "cd /usr/src/sbin/geom && make && sudo make install".

I'm not very good at manpages, though... any takers? :)


Index: sbin/geom/class/raid3/geom_raid3.c
===================================================================
--- sbin/geom/class/raid3/geom_raid3.c	(revision 195939)
+++ sbin/geom/class/raid3/geom_raid3.c	(working copy)
_at__at_ -184,6 +184,8 _at__at_ raid3_label(struct gctl_req *req)
 		return;
 	}
 	hardcode = gctl_get_int(req, "hardcode");
+	if (hardcode && gctl_check_provider(req, sizeof(md.md_provider)))
+		return;
 
 	/*
 	 * Calculate sectorsize by finding least common multiple from
Index: sbin/geom/class/shsec/geom_shsec.c
===================================================================
--- sbin/geom/class/shsec/geom_shsec.c	(revision 195939)
+++ sbin/geom/class/shsec/geom_shsec.c	(working copy)
_at__at_ -116,6 +116,8 _at__at_ shsec_label(struct gctl_req *req)
 		return;
 	}
 	hardcode = gctl_get_int(req, "hardcode");
+	if (hardcode && gctl_check_provider(req, sizeof(md.md_provider)))
+		return;
 
 	/*
 	 * Clear last sector first to spoil all components if device exists.
Index: sbin/geom/class/stripe/geom_stripe.c
===================================================================
--- sbin/geom/class/stripe/geom_stripe.c	(revision 195939)
+++ sbin/geom/class/stripe/geom_stripe.c	(working copy)
_at__at_ -134,6 +134,8 _at__at_ stripe_label(struct gctl_req *req)
 		return;
 	}
 	hardcode = gctl_get_int(req, "hardcode");
+	if (hardcode && gctl_check_provider(req, sizeof(md.md_provider)))
+		return;
 
 	/*
 	 * Clear last sector first to spoil all components if device exists.
Index: sbin/geom/class/concat/geom_concat.c
===================================================================
--- sbin/geom/class/concat/geom_concat.c	(revision 195939)
+++ sbin/geom/class/concat/geom_concat.c	(working copy)
_at__at_ -123,6 +123,8 _at__at_ concat_label(struct gctl_req *req)
 		return;
 	}
 	hardcode = gctl_get_int(req, "hardcode");
+	if (hardcode && gctl_check_provider(req, sizeof(md.md_provider)))
+		return;
 
 	/*
 	 * Clear last sector first to spoil all components if device exists.
Index: sbin/geom/class/journal/geom_journal.c
===================================================================
--- sbin/geom/class/journal/geom_journal.c	(revision 195939)
+++ sbin/geom/class/journal/geom_journal.c	(working copy)
_at__at_ -164,6 +164,9 _at__at_ journal_label(struct gctl_req *req)
 		return;
 	}
 
+	if (hardcode && gctl_check_provider(req, sizeof(md.md_provider)))
+		return;
+
 	/* Verify the given providers. */
 	for (i = 0; i < nargs; i++) {
 		str = gctl_get_ascii(req, "arg%d", i);
Index: sbin/geom/class/mirror/geom_mirror.c
===================================================================
--- sbin/geom/class/mirror/geom_mirror.c	(revision 195939)
+++ sbin/geom/class/mirror/geom_mirror.c	(working copy)
_at__at_ -190,6 +190,8 _at__at_ mirror_label(struct gctl_req *req)
 	if (gctl_get_int(req, "nofailsync"))
 		md.md_mflags |= G_MIRROR_DEVICE_FLAG_NOFAILSYNC;
 	hardcode = gctl_get_int(req, "hardcode");
+	if (hardcode && gctl_check_provider(req, sizeof(md.md_provider)))
+		return;
 
 	/*
 	 * Calculate sectorsize by finding least common multiple from
Index: sbin/geom/misc/subr.h
===================================================================
--- sbin/geom/misc/subr.h	(revision 195939)
+++ sbin/geom/misc/subr.h	(working copy)
_at__at_ -49,5 +49,6 _at__at_ int gctl_change_param(struct gctl_req *req, const
     const void *value);
 int gctl_delete_param(struct gctl_req *req, const char *name);
 int gctl_has_param(struct gctl_req *req, const char *name);
+int gctl_check_provider(struct gctl_req *req, size_t size);
 
 #endif	/* !_SUBR_H_ */
Index: sbin/geom/misc/subr.c
===================================================================
--- sbin/geom/misc/subr.c	(revision 195939)
+++ sbin/geom/misc/subr.c	(working copy)
_at__at_ -458,3 +458,24 _at__at_ gctl_has_param(struct gctl_req *req, const char *n
 	}
 	return (0);
 }
+
+int
+gctl_check_provider(struct gctl_req *req, size_t size)
+{
+	const char *str;
+	int i, nargs;
+
+	nargs = gctl_get_int(req, "nargs");
+
+	for (i = 1; i < nargs; i++) {
+		str = gctl_get_ascii(req, "arg%d", i);
+		if (strncmp(str, _PATH_DEV, strlen(_PATH_DEV)) == 0)
+			str += strlen(_PATH_DEV);
+		if (strlen(str) > size - 1) {
+			gctl_error(req, "Provider name '%s' too long (max %zu "
+			    "chars).", str, size - 1);
+			return (ENAMETOOLONG);
+		}
+	}
+	return (0);
+}
Received on Wed Jul 29 2009 - 18:30:20 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:52 UTC