Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 03 Apr 2007 10:33:12 -0500
From:      Eric Anderson <anderson@freebsd.org>
To:        Pawel Jakub Dawidek <pjd@freebsd.org>
Cc:        freebsd-current@freebsd.org
Subject:   Re: geom_journal panic: wrong offset 500107860990 for sectorsize 512 - RESOLVED
Message-ID:  <461273B8.3050106@freebsd.org>
In-Reply-To: <20070403110426.GD40062@garage.freebsd.pl>
References:  <460FDEF2.2060203@centtech.com> <20070401180125.GE25661@garage.freebsd.pl> <46119C4B.3020200@centtech.com> <4611DE78.7050405@freebsd.org> <20070403110426.GD40062@garage.freebsd.pl>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------000108020003090802050502
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

On 04/03/07 06:04, Pawel Jakub Dawidek wrote:
> On Mon, Apr 02, 2007 at 11:56:24PM -0500, Eric Anderson wrote:
>> Here is a patch that adds that functionality.  Can be found here:
>>
>> http://www.googlebit.com/freebsd/patches/gjournal_size_expression.patch
>>
>> and attached.
> 
> Thanks for the patch. I'd prefer to have such functionality as a part of
> libutil. Simlar to humanize_number(3), but the other way around.
> Some comments below.

Like this:

http://www.googlebit.com/freebsd/patches/libutil-unhumanized.patch
(and attached)

>> + * Convert an expression of the following forms to a uintmax_t.
>> + * 	1) A positive decimal number.
>> + *	2) A positive decimal number followed by a 'b' or 'B' (mult by 512).
> 
> Why? If I give '-s 1024B' it means I want 1024 bytes, not 1024*512
> bytes. I would multiply by 512 if I receive number of sectors or
> something. My suggestion is to accept 'b' and 'B', but ignore it (or
> multiply by 1).

Yes, true.  B should mean bytes, not blocks.. [FIXED]

>> + *	3) A positive decimal number followed by a 'k' or 'K' (mult by 1 << 10).
>> + *	4) A positive decimal number followed by a 'm' or 'M' (mult by 1 << 20).
>> + *	5) A positive decimal number followed by a 'g' or 'G' (mult by 1 << 30).
> 
> I'd add 't' and 'T' as well.

[ADDED]

>> + *	5) A positive decimal number followed by a 'w' or 'W' (mult by sizeof int).
> 
> I suggest dropping it, I don't really see a use for it...

[REMOVED]

New gjournal patch is here:
http://www.googlebit.com/freebsd/patches/gjournal_size_expression-libutil.patch
(and attached)

It now also needs the libutil patch above.  The man page for the 
unhumanize_number function is crude, so it should be looked over also.

Comments please!!


Eric



--------------000108020003090802050502
Content-Type: text/x-patch;
 name="gjournal_size_expression-libutil.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="gjournal_size_expression-libutil.patch"

Index: class/journal/Makefile
===================================================================
RCS file: /alt/ncvs/src/sbin/geom/class/journal/Makefile,v
retrieving revision 1.2
diff -u -r1.2 Makefile
--- class/journal/Makefile	10 Feb 2007 17:59:46 -0000	1.2
+++ class/journal/Makefile	3 Apr 2007 12:41:17 -0000
@@ -6,7 +6,7 @@
 SRCS+=	geom_journal_ufs.c
 
 DPADD=	${LIBMD} ${LIBUFS}
-LDADD=	-lmd -lufs
+LDADD=	-lmd -lufs -lutil
 
 CFLAGS+=-I${.CURDIR}/../../../../sys
 
Index: class/journal/geom_journal.c
===================================================================
RCS file: /alt/ncvs/src/sbin/geom/class/journal/geom_journal.c,v
retrieving revision 1.2
diff -u -r1.2 geom_journal.c
--- class/journal/geom_journal.c	1 Nov 2006 09:22:33 -0000	1.2
+++ class/journal/geom_journal.c	3 Apr 2007 04:49:28 -0000
@@ -66,7 +66,7 @@
 		{ 'c', "checksum", NULL, G_TYPE_BOOL },
 		{ 'f', "force", NULL, G_TYPE_BOOL },
 		{ 'h', "hardcode", NULL, G_TYPE_BOOL },
-		{ 's', "jsize", &default_jsize, G_TYPE_NUMBER },
+		{ 's', "jsize", &default_jsize, G_TYPE_STRING },
 		G_OPT_SENTINEL
 	    },
 	    "[-cfhv] [-s jsize] dataprov [jprov]"
@@ -174,7 +174,7 @@
 	}
 
 	data = gctl_get_ascii(req, "arg0");
-	jsize = gctl_get_intmax(req, "jsize");
+	jsize = gctl_get_numexpr(req, "jsize");
 	journal = NULL;
 	switch (nargs) {
 	case 1:
Index: misc/subr.c
===================================================================
RCS file: /alt/ncvs/src/sbin/geom/misc/subr.c,v
retrieving revision 1.7
diff -u -r1.7 subr.c
--- misc/subr.c	25 Jan 2007 11:35:27 -0000	1.7
+++ misc/subr.c	3 Apr 2007 13:10:41 -0000
@@ -42,6 +42,7 @@
 #include <unistd.h>
 #include <assert.h>
 #include <libgeom.h>
+#include <libutil.h>
 
 #include "misc/subr.h"
 
@@ -377,6 +378,21 @@
 	return (*p);
 }
 
+intmax_t
+gctl_get_numexpr(struct gctl_req *req, const char *pfmt, ...)
+{
+	char *val;
+	int64_t num;
+	va_list ap;
+
+	va_start(ap, pfmt);
+	val = gctl_get_param(req, 0, pfmt, ap);
+
+	num = unhumanize_number((char *)val);
+printf("was: %s now: %jd\n", val, num);
+	return (num);
+}
+
 const char *
 gctl_get_ascii(struct gctl_req *req, const char *pfmt, ...)
 {
Index: misc/subr.h
===================================================================
RCS file: /alt/ncvs/src/sbin/geom/misc/subr.h,v
retrieving revision 1.8
diff -u -r1.8 subr.h
--- misc/subr.h	25 Jan 2007 11:35:27 -0000	1.8
+++ misc/subr.h	3 Apr 2007 04:21:36 -0000
@@ -44,6 +44,7 @@
 void gctl_error(struct gctl_req *req, const char *error, ...) __printflike(2, 3);
 int gctl_get_int(struct gctl_req *req, const char *pfmt, ...) __printflike(2, 3);
 intmax_t gctl_get_intmax(struct gctl_req *req, const char *pfmt, ...) __printflike(2, 3);
+intmax_t gctl_get_numexpr(struct gctl_req *req, const char *pfmt, ...) __printflike(2, 3);
 const char *gctl_get_ascii(struct gctl_req *req, const char *pfmt, ...) __printflike(2, 3);
 int gctl_change_param(struct gctl_req *req, const char *name, int len,
     const void *value);

--------------000108020003090802050502
Content-Type: text/x-patch;
 name="libutil-unhumanized.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="libutil-unhumanized.patch"

Index: Makefile
===================================================================
RCS file: /alt/ncvs/src/lib/libutil/Makefile,v
retrieving revision 1.63
diff -u -r1.63 Makefile
--- Makefile	27 Jul 2006 12:36:46 -0000	1.63
+++ Makefile	3 Apr 2007 13:34:31 -0000
@@ -12,7 +12,7 @@
 	login_auth.c login_cap.c login_class.c login_crypt.c login_ok.c \
 	login_times.c login_tty.c logout.c logwtmp.c \
 	pidfile.c property.c pty.c pw_util.c realhostname.c stub.c \
-	trimdomain.c uucplock.c
+	trimdomain.c unhumanize_number.c uucplock.c
 INCS=	libutil.h login_cap.h
 
 CFLAGS+= -DLIBC_SCCS
@@ -27,7 +27,7 @@
 	login_cap.3 login_class.3 login_times.3 login_ok.3 \
 	_secure_path.3 uucplock.3 property.3 auth.3 realhostname.3 \
 	realhostname_sa.3 trimdomain.3 fparseln.3 humanize_number.3 \
-	pidfile.3
+	unhumanize_number.3 pidfile.3
 MAN+=	login.conf.5 auth.conf.5
 MLINKS+= kld.3 kld_isloaded.3 kld.3 kld_load.3
 MLINKS+= property.3 properties_read.3  property.3 properties_free.3
Index: libutil.h
===================================================================
RCS file: /alt/ncvs/src/lib/libutil/libutil.h,v
retrieving revision 1.42
diff -u -r1.42 libutil.h
--- libutil.h	18 Feb 2006 11:25:28 -0000	1.42
+++ libutil.h	3 Apr 2007 13:05:16 -0000
@@ -81,6 +81,7 @@
 		     struct termios *_termp, struct winsize *_winp);
 int	humanize_number(char *_buf, size_t _len, int64_t _number,
 	    const char *_suffix, int _scale, int _flags);
+int64_t unhumanize_number(char *_buf);
 const char *uu_lockerr(int _uu_lockresult);
 int	uu_lock(const char *_ttyname);
 int	uu_unlock(const char *_ttyname);
--- /dev/null	Tue Apr  3 10:24:54 2007
+++ unhumanize_number.c	Tue Apr  3 08:10:34 2007
@@ -0,0 +1,91 @@
+/*-
+ * Copyright (c) 2007
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+
+#include <sys/types.h>
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <locale.h>
+#include <libutil.h>
+
+
+/*
+ * Convert an expression of the following forms to a int64_t.
+ * 	1) A positive decimal number.
+ *	2) A positive decimal number followed by a 'b' or 'B' (mult by 1).
+ *	3) A positive decimal number followed by a 'k' or 'K' (mult by 1 << 10).
+ *	4) A positive decimal number followed by a 'm' or 'M' (mult by 1 << 20).
+ *	5) A positive decimal number followed by a 'g' or 'G' (mult by 1 << 30).
+ *	6) A positive decimal number followed by a 't' or 'T' (mult by 1 << 40).
+ */
+int64_t
+unhumanize_number(char *val)
+{
+	int64_t *prevnum, number;
+	int64_t mult;
+	char *expr;
+
+	number = strtoumax(val, &expr, 0);
+
+	if (expr == val)			/* No valid digits. */
+		printf("illegal numeric value\n");
+
+	mult = 0;
+	switch (*expr) {
+	case 'B':
+	case 'b':
+		mult = 1;
+		break;
+	case 'K':
+	case 'k':
+		mult = 1 << 10;
+		break;
+	case 'M':
+	case 'm':
+		mult = 1 << 20;
+		break;
+	case 'G':
+	case 'g':
+		mult = 1 << 30;
+		break;
+	case 'T':
+	case 't':
+		mult = 1 << 30;
+		mult *= 1024;
+		break;
+	default:
+		;
+	}
+
+	if (mult != 0) {
+		number *= mult;
+	}
+
+	return (number);
+}
--- /dev/null	Tue Apr  3 10:24:54 2007
+++ unhumanize_number.3	Tue Apr  3 08:35:18 2007
@@ -0,0 +1,50 @@
+.\"
+.\"
+.Dd April 3, 2007
+.Dt UNHUMANIZE_NUMBER 3
+.Os
+.Sh NAME
+.Nm unhumanize_number
+.Nd format a number from human readable form
+.Sh LIBRARY
+.Lb libutil
+.Sh SYNOPSIS
+.In libutil.h
+.Ft int64_t
+.Fo unhumanize_number
+.Fa "char *buf"
+.Fc
+.Sh DESCRIPTION
+The
+.Fn unhumanize_number
+function unformats the 
+.Fa buffer .
+and returns a signed 64-bit quantity.
+.Pp
+The
+.Fn unhumanize_number
+function
+follows the SI power of two convention.
+.Pp
+The prefixes are:
+.Bl -column "Prefix" "Description" "1000000000000000000" -offset indent
+.It Sy "Prefix" Ta Sy "Description" Ta Sy "Multiplier"
+.It Li k Ta No kilo Ta 1024
+.It Li M Ta No mega Ta 1048576
+.It Li G Ta No giga Ta 1073741824
+.It Li T Ta No tera Ta 1099511627776
+.It Li P Ta No peta Ta 1125899906842624
+.It Li E Ta No exa Ta 1152921504606846976
+.El
+
+.Sh RETURN VALUES
+The
+.Fn unhumanize_number
+function returns the number calculated from the suffix appended
+to the
+.Fa buffer
+.Sh HISTORY
+The
+.Fn unhumanize_number
+function first appeared in
+.Fx 7.0 .

--------------000108020003090802050502--



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