Bug 1525262

Summary: virt-df displays zeros for filesystems with block size =512
Product: Red Hat Enterprise Linux 7 Reporter: Richard W.M. Jones <rjones>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.5CC: ptoscano, rjones, stenavin, xchen
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libguestfs-1.38.0-1.el7 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: 1525241 Environment:
Last Closed: 2018-10-30 07:45:24 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1525241, 1551055    
Bug Blocks:    

Description Richard W.M. Jones 2017-12-12 22:25:17 UTC
+++ This bug was initially created as a clone of Bug #1525241 +++

Description of problem:

Call virt-df for disk image which contains filesystem with block size = 512 bytes. virt-df shows zeroes for such filesystems in all numeric fields (except Use%). But everything is OK if you call it with --human-readable option.

Version-Release number of selected component (if applicable):

Any. Tested on 1.36.10 Fedora 25 and 1.36.11 CentOS 6.

How reproducible:

virt-df -a disk.qcow2

Actual results:

Filesystem                           1K-blocks       Used  Available  Use%
disk.qcow2:/dev/sda1                         0          0          0    1%

Expected results:

Filesystem                           1K-blocks       Used  Available  Use%
disk.qcow2:/dev/sda1                     99800          1      99800    1%

Additional info:

statvfs:

bsize: 512
blocks: 199600
bfree: 199599

Here is a root of the issue: https://github.com/libguestfs/libguestfs/blob/master/df/output.c#L112

--- Additional comment from Richard W.M. Jones on 2017-12-12 16:29:47 EST ---

Can reproduce the same with virt-df 1.37.34fedora=28,release=3.fc28,libvirt

--- Additional comment from Richard W.M. Jones on 2017-12-12 16:33:13 EST ---

Relevant part of the trace output is:

libguestfs: trace: statvfs "/"
libguestfs: trace: statvfs = <struct guestfs_statvfs = bsize: 512, frsize: 512, blocks: 199600, bfree: 199599, bavail: 199599, files: 0, ffree: 0, favail: 0, fsid: 2049, flag: 4097, namemax: 1530, >

Note that bsize = 512, therefore factor = bsize / 1024 = 0, so
everything is multiplied by zero resulting in:

image:/dev/sda1                              0          0          0    1%

--- Additional comment from Richard W.M. Jones on 2017-12-12 17:24:07 EST ---

Patch posted:

https://www.redhat.com/archives/libguestfs/2017-December/msg00051.html

Comment 2 Xianghua Chen 2017-12-14 08:04:36 UTC
I can't reproduce it with:
libguestfs-1.36.10-4.el7.x86_64

Could you help to check the steps:
#  qemu-img create -f qcow2 fstest.qcow2 100M
# guestfish -a fstest.qcow2 
><fs> run
><fs> part-disk /dev/sda mbr
><fs> mkfs fat /dev/sda1 blocksize:512
><fs> list-filesystems
/dev/sda1: vfat
><fs> blockdev-getbsz /dev/sda1
512
><fs>  quit

[root@dhcp-66-71-68 ~]# virt-df  -a fstest.qcow2 
Filesystem                           1K-blocks       Used  Available  Use%
fstest.qcow2:/dev/sda1                  102056          0     102056    0%

Anything that I misunderstand ? Thank you !

Comment 3 Richard W.M. Jones 2017-12-14 08:59:11 UTC
You need to have ’bsize’ < 1024 to see the bug.  In the case
above the blocksize is 2048:

><fs> part-disk /dev/sda mbr
><fs> mkfs fat /dev/sda1 blocksize:512
><fs> list-filesystems 
/dev/sda1: vfat
><fs> mount /dev/sda1 /
><fs> statvfs /
bsize: 2048            <-----
[...]

In the original bug there is an attached filesystem which demonstrates
the problem, and it's probably easiest just to use that:

https://bugzilla.redhat.com/show_bug.cgi?id=1525241#c0

Comment 4 Xianghua Chen 2017-12-15 02:49:31 UTC
(In reply to Richard W.M. Jones from comment #3)
> You need to have ’bsize’ < 1024 to see the bug.  In the case
> above the blocksize is 2048:
> 
> ><fs> part-disk /dev/sda mbr
> ><fs> mkfs fat /dev/sda1 blocksize:512
> ><fs> list-filesystems 
> /dev/sda1: vfat
> ><fs> mount /dev/sda1 /
> ><fs> statvfs /
> bsize: 2048            <-----
> [...]
> 
> In the original bug there is an attached filesystem which demonstrates
> the problem, and it's probably easiest just to use that:
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=1525241#c0

Thank you very much, I've reproduced it with the attached filesystem, but I still want to know how did you set bsize to 512?

I thought "mkfs fat /dev/sda1 blocksize:512" did this thing, but actually it didn't.

Comment 5 Xianghua Chen 2017-12-15 02:52:28 UTC
Reproduced with package:
libguestfs-1.36.10-4.el7.x86_64

1. Download the filesystem attached in: 
https://bugzilla.redhat.com/show_bug.cgi?id=1525241#c0
2. 
# guestfish -a disk.qcow2
><fs> run
><fs> mount /dev/sda1 /
><fs> statvfs /
bsize: 512
frsize: 512
blocks: 199600
bfree: 199599
bavail: 199599
files: 0
ffree: 0
favail: 0
fsid: 2049
flag: 4096
namemax: 1530
><fs> exit
3. 
# virt-df -a disk.qcow2 
Filesystem                           1K-blocks       Used  Available  Use%
disk.qcow2:/dev/sda1                         0          0          0    1%

The 1K-blocks is 0 , which is wrong.

Comment 6 Richard W.M. Jones 2017-12-18 10:22:32 UTC
(In reply to Xianghua Chen from comment #4)
> Thank you very much, I've reproduced it with the attached filesystem, but I
> still want to know how did you set bsize to 512?
> 
> I thought "mkfs fat /dev/sda1 blocksize:512" did this thing, but actually it
> didn't.

This is a bug: https://bugzilla.redhat.com/show_bug.cgi?id=1527003

Comment 7 Mykola Ivanets 2017-12-18 12:05:12 UTC
(In reply to Xianghua Chen from comment #4)
> ... but I still want to know how did you set bsize to 512?

For example:

1. qemu-img create -f raw fat.raw 100M
2. losetup /dev/loop0 fat.raw
3. fdisk /dev/loop0 <<EOF
o
n




w
EOF
4. mkfs.fat /dev/loop0p1 -s 1 -S 512 -F 32
5. guestfish --ro -a fat.raw <<EOF
run
mount /dev/sda1 /
statvfs /
EOF

Output:
bsize: 512
frsize: 512
...

Comment 8 Pino Toscano 2018-01-17 17:19:10 UTC
This was fixed upstream with commit
d3afdb6e3edbfe031aac86c14df60c530781ace5
which is in libguestfs >= 1.37.36.

Comment 10 Xianghua Chen 2018-04-25 02:39:20 UTC
Verified with package:
libguestfs-1.38.0-1.el7.x86_64

Steps:
1. Create a image with block size smaller than 1K
# qemu-img create -f raw fat.raw 100M
# losetup /dev/loop0 fat.raw
# fdisk /dev/loop0 <<EOF
o
n




w
EOF
# mkfs.fat /dev/loop0 -s 1 -S 512 -F 32
# guestfish --ro -a fat.raw <<EOF
run
mount /dev/sda /
statvfs /
EOF

Output:
bsize: 512
frsize: 512
blocks: 201616
bfree: 201615
bavail: 201615
files: 0
ffree: 0
favail: 0
fsid: 2048
flag: 4096
namemax: 1530

2. 
# virt-df -a disk.qcow2 
Filesystem                           1K-blocks       Used  Available  Use%
fat.raw:/dev/sda                        100808          0     100807    1%

So verified.

Comment 12 errata-xmlrpc 2018-10-30 07:45:24 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHEA-2018:3021