Do we want a periodic script for a zfs scrub?

Bruce Evans brde at optusnet.com.au
Tue Jun 15 14:56:00 UTC 2010


On Tue, 15 Jun 2010, Stefan Esser wrote:

> Am 15.06.2010 09:53, schrieb Alexander Leidinger:
>> Quoting jhell <jhell at dataix.net> (from Sat, 12 Jun 2010 08:17:18 -0400):
>>
>>> On 06/11/2010 04:42, Alexander Leidinger wrote:
>>> : #!/bin/sh
>>> :
>>> : lastscrub=$(zpool history exports |grep scrub |tail -1 |cut -f1 -d.)
>>> : todayjul=$(date -j -f "%Y-%m-%d" "+%j" $(date "+%Y-%m-%d"))
>>> : scrubjul=$(date -j -f "%Y-%m-%d" "+%j" $lastscrub)
>>> :
>>> : echo $lastscrub Last Scrub From zpool history
>>> : echo $todayjul Today converted to julian
>>> : echo $scrubjul Last scrub converted to julian
>>> :
>>> : expired=$(($todayjul-$scrubjul))
>>>>
>>>> Apart from the fact that we can do this with one $(( ))... what happens
>>>> if/when time_t is extended to 64 bits on 32 bit platforms? Can we get
>>>> into trouble with the shell-arithmetic or not? It depends upon the
>>>> bit-size of the shell integers, and the signedness of them. Jilles (our
>>>> shell maintainer) suggested also to use the seconds since epoch and I
>>>> asked him the same question. I'm waiting for an answer from him.
>>>
>>> I do not think this would be a problem for the script as the script is
>>> relying on date for the conversion except for the subtraction that is
>>> taking place.
>>>
>>> If there was a problem then I would believe it would have to be
>>> corrected in date(1) & possibly sh(1), I could be wrong though.
>>
>> The question is if the integer arithmetic in shell is supposed/allowed
>> to handle 64bit unsigned integers on 32bit machines or not.

Of course it is not required.  It is not required even on 64-bit
machines.  Only signed long integer arithmetic is required in POSIX.1-2001.
signed long may have any size with >= 31 value bits.  Thus only 31
value bits and 1 sign bit are required on all machines.  Longs should
be twice as long as the register width on all machines, so they should
be 64 bits on 32-bit machines and 128 bits on 64-bit machines, but
this is normally broken; normally, 32-bit machines normally have 32-bit
longs with 31 value bits, while 64 bit machines normally have 64-bit
longs with 63 value bits; thus the shell normally handles only 31-bit
unsigned integers on 32-bit machines and 63-bit unsigned integers on
64-bit machines.

time_t may have any arithmetic type in C90/99 or POSIX (with POSIX's
broken representation in POSIX and any representation in C), but it
is normally signed integer, so if it is extended to 64 bits then it
probably wouldn't need 64-bit unsigned integers anyway.

> I extended expr and test (standalone binaries and /bin/sh builtins) to
> handle 64 bit on i386 a looong time ago (and I also added overflow
> checks to all calculations). But then it was decided, that POSIX demands
> 32 bit range on 32 bit machines, so support for 64 bit range was made
> conditional on a switch (expr -e if memory serves me right ...). So yes,
> 64 bit range is available on all platforms.

Hmm, POSIX doesn't require this brokenness for the shell, though it
requires practically equivalent brokenness for all operands and option-
arguments generally: it requires "all" integer arithmetic to use
signed long variables and "all" floating point arithmetic to use double
variables, with Standard C semantics.  signed long may have any size,
but normally has 31 or 63 value bits as above.  It is unclear how a
variable can ever be floating point.  Then it contradicts^Woverrides
"all" with certain extensions for the shell.  However, these extensions
are almost useless since they mainly make a difference when the signed
long arithmetic would overflow, in which case the behaviour is undefined
(?) so it can DTRT using any extension that it wants.

Bruce


More information about the freebsd-fs mailing list