[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: 4.8.2: device/sysdep_LINUX.c
From: |
Aaron Scamehorn |
Subject: |
RE: 4.8.2: device/sysdep_LINUX.c |
Date: |
Mon, 20 Nov 2006 11:51:08 -0600 |
Hi Martin,
I don't think your assumption about f_bsize == f_frsize is valid. And
if it is, what is the point of multiplying by (usage.f_frsize /
usage.f_bsize), which is always 1?
I don't see anything in the POSIX docs for statvfs stating that this
math is necessary, nor that f_bsize == f_frsize is a rule.
I didn't see anything in the GNU coreutils package (df, du, stat, etc)
doing this math either.
One place that this assumption breaks is for an nfs mounted partition;
The default blocksize is 8K, usually larger (32K).
Please look at the attached test program, and it's associated output.
I think you'll see that statvfs is ultimately making the same system
call that statfs does (as evidenced by the strace output), which gives
you the proper f_blocks without any additional math necessary.
Thanks,
Aaron
-----Original Message-----
From: address@hidden
[mailto:address@hidden On
Behalf Of Martin Pala
Sent: Friday, November 17, 2006 4:28 PM
To: The monit developer list
Subject: Re: 4.8.2: device/sysdep_LINUX.c
Hi,
the blocks size is computed according to statvfs structure description
(see 'man statvfs'):
--8<--
struct statvfs {
unsigned long f_bsize; /* file system block size */
unsigned long f_frsize; /* fragment size */
fsblkcnt_t f_blocks; /* size of fs in f_frsize units
*/
fsblkcnt_t f_bfree; /* # free blocks */
fsblkcnt_t f_bavail; /* # free blocks for non-root */
fsfilcnt_t f_files; /* # inodes */
fsfilcnt_t f_ffree; /* # free inodes */
fsfilcnt_t f_favail; /* # free inodes for non-root */
unsigned long f_fsid; /* file system ID */
unsigned long f_flag; /* mount flags */
unsigned long f_namemax; /* maximum filename length */
};
--8<--
f_blocks has to be recomputed this way since it describes the number of
fragments, not blocks (the f_bsize and f_frsize match on all linuxes
which i ever saw even with different block sizes).
Martin
Aaron Scamehorn wrote:
> Hello,
>
> In device_usage_sysdep:
>
> I'm not quite sure what the following is supposed to be calculating:
>
> inf->f_blocks= usage.f_blocks * usage.f_frsize /
usage.f_bsize;
>
>
> I think you're incorrectly mixing block size & fragment sizes. I
> don't think they have anything to do with each other.
>
> You're probably just getting lucky, because your f_frsize & f_bsize
> both = 4K.
>
> However, on large filesystems, where f_bsize might be 32K, you'll get
> crazy usage numbers.
>
> I think you just want:
>
> inf->f_blocks= usage.f_blocks ;
>
>
> Thanks,
> Aaron
>
>
> 25 if(statvfs( dir, &usage) != 0) {
> (gdb) n
> (gdb) print usage
> $1 = {f_bsize = 32768, f_frsize = 4096, f_blocks = 8811322, f_bfree =
> 8053030, f_bavail = 7605440,
> f_files = 35815424, f_ffree = 35800806, f_favail = 35800806, f_fsid
> = 0, __f_unused = 0, f_flag = 0,
> f_namemax = 255, __f_spare = {0, 0, 0, 0, 0, 0}}
>
>
> _______________________________________________
> monit-dev mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/monit-dev
_______________________________________________
monit-dev mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/monit-dev
statfs.c
Description: statfs.c
output.txt
Description: output.txt