Bug #1771

Apparent size reported instead of real disk size in datastore/libfs.sh

Added by Simon Boulet about 8 years ago. Updated about 8 years ago.

Status:ClosedStart date:02/19/2013
Priority:NormalDue date:
Assignee:Ruben S. Montero% Done:


Target version:-
Resolution:worksforme Pull request:
Affected Versions:OpenNebula 3.8


While investigating for #1770, I came across a difference in the size reported by the libfs.sh fs_size function and the real size (as reported by "du"):

root@OpenNebula-Test:~# source /var/lib/one/remotes/datastore/libfs.sh && fs_size /var/lib/one/datastores/1/7cdbf23f732b0de66a7ea91770fcbf27

root@OpenNebula-Test:~# du -sm /var/lib/one/datastores/1/7cdbf23f732b0de66a7ea91770fcbf27
627 /var/lib/one/datastores/1/7cdbf23f732b0de66a7ea91770fcbf27

As you can see, the OpenNebula fs_size function is reporting 575 MB, whereas du is reporting 627 MB.

After digging the problem I realized that the fs_size is using "du -sb" to obtain the size, which reports size in bytes, but also report as the "apparent size" (without taking the underlying file system "block size" into account, see man du for --apparent-size).

Replacing "du -sb" with "du -sB1":

root@OpenNebula-Test:~# du -sb /var/lib/one/datastores/1/7cdbf23f732b0de66a7ea91770fcbf27
602777921 /var/lib/one/datastores/1/7cdbf23f732b0de66a7ea91770fcbf27

root@OpenNebula-Test:~# du -sB1 /var/lib/one/datastores/1/7cdbf23f732b0de66a7ea91770fcbf27
656990208 /var/lib/one/datastores/1/7cdbf23f732b0de66a7ea91770fcbf27

Is there any particular reason for reporting "apparent size" (du -sb) instead of reporting the real size in bytes (du -sB1)


#1 Updated by Ruben S. Montero about 8 years ago

  • Status changed from New to Closed
  • Assignee set to Ruben S. Montero
  • Resolution set to worksforme


Using apparent-size will add an error up to the block size in the file-system. However, it will deal with sparse-files. So for example, let say that you want to register a 1GB image, as follows:

> dd bs=1 seek=1GiB if=/dev/null of=big
0+0 records in
0+0 records out
0 bytes (0 B) copied, 0.000127876 s, 0.0 kB/s
> du -sb big
1073741824    big
> du -sB1 big
0    big

OpenNebula will consider the file as empty (you'll bypass any quota). Nowadays, sparse files are handled by any FS, so it is safer to use the apparent size (although you may loose some blocks when computing sizes)

Also available in: Atom PDF