Patch to allow gmirror to set priority of a disk

Pawel Jakub Dawidek pjd at FreeBSD.org
Sat Sep 5 20:36:00 UTC 2009


On Sat, Sep 05, 2009 at 10:25:05PM +0200, Mel Flynn wrote:
> On Saturday 05 September 2009 21:22:51 Pawel Jakub Dawidek wrote:
> 
> > And tech core geom(8) utility to split usage based on \n.
> > usage_command() function from sbin/geom/core/geom.c would have to be
> > modified. If you agree with this idea, would you also like to work on
> > this?
> 
> Yes and see attached. Since utility exists after displaying usage, I didn't 
> take the trouble of freeing ptr, but if this is preferred then I'll add the 
> line.

I think it would be good to free memory just to make it elegant.

> % geom mirror foo
> geom: Unknown command: foo.
> usage: geom mirror activate [-v] name prov ...
>        geom mirror clear [-v] prov ...
>        geom mirror configure[-adfFhnv] [-b balance] [-s slice] name
>        geom mirror configure -p priority name prov
> 
> -- 
> Mel

> Index: sbin/geom/core/geom.c
> ===================================================================
> --- sbin/geom/core/geom.c	(revision 196868)
> +++ sbin/geom/core/geom.c	(working copy)
> @@ -98,11 +98,23 @@
>  	struct g_option *opt;
>  	unsigned i;
>  
> -	fprintf(stderr, "%s %s %s", prefix, comm, cmd->gc_name);
>  	if (cmd->gc_usage != NULL) {
> -		fprintf(stderr, " %s\n", cmd->gc_usage);
> +		char *pos, *ptr;
> +
> +		ptr = strdup(cmd->gc_usage);
> +		while ((pos = strchr(ptr, '\n')) != NULL) {

Wouldn't it be easier to use strsep(3)?

> +			*pos = '\0';
> +			fprintf(stderr, "%s %s %s", prefix, comm, cmd->gc_name);
> +			fprintf(stderr, "%s\n", ptr);

Why to split this into two fprintfs? There is also space missing before %s.

> +			ptr = pos + 1;
> +		}
> +		/* Tail or no \n at all */
> +		fprintf(stderr, "%s %s %s", prefix, comm, cmd->gc_name);
> +		fprintf(stderr, " %s\n", ptr);
>  		return;
>  	}
> +
> +	fprintf(stderr, "%s %s %s", prefix, comm, cmd->gc_name);
>  	if ((cmd->gc_flags & G_FLAG_VERBOSE) != 0)
>  		fprintf(stderr, " [-v]");
>  	for (i = 0; ; i++) {

With strsep(3) it would look like this:

  	if (cmd->gc_usage != NULL) {
		char *cur, *ptr, *tofree;

		tofree = ptr = strdup(cmd->gc_usage);
		while ((cur = strsep(&ptr, "\n")) != NULL) {
			if (*cur == '\0')
				continue;
			fprintf(stderr, "%s %s %s %s\n", prefix, comm,
			    cmd->gc_name, cur);
		}
		free(tofree);
		return;
	}

-- 
Pawel Jakub Dawidek                       http://www.wheel.pl
pjd at FreeBSD.org                           http://www.FreeBSD.org
FreeBSD committer                         Am I Evil? Yes, I Am!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-fs/attachments/20090905/f1631f7e/attachment.pgp


More information about the freebsd-fs mailing list