Fix false usage figures for busy SWRAID members (#27)

Create an active Linux Software RAID member which is larger than /dev
virtual file system and GParted will report the usage figure of the /dev
virtual file system for the SWRAID member.

    # df -h /dev
    Filesystem      Size  Used Avail Use% Mounted on
    devtmpfs        732M     0  732M   0% /dev
    # sgdisk -n 1:1M:+1G /dev/sdb
    # mdadm --create --verbose /dev/md1 --level=linear --raid-devices=1 --force /dev/sdb1
    mdadm: Defaulting to version 1.2 metadata
    mdadm: array /dev/md1 started.

GParted reports the usage of /dev/sdb1 as:
    Partition  Mount Point  Size     Used   Unused     Unallocated
    /dev/sdb1  /dev/md1     1.00GiB  0.00B  731.04MiB  292.96MiB

However GParted should have reported the usage as "---" for unknown
because it isn't coded to query the size of the SWRAID member within a
partition.

The fault has been bisected to this commit:
    Extend un/mounting and usage reporting to unsupported file systems (!13)
    95903efb1f

What happens for busy Linux Software RAID array members:
*   GParted_Core::is_busy()
    has custom code to identify busy members.
*   GParted_Core::set_mountpoints()
    has custom code to add the array device name as the "mount point" of
    the member.
*   GParted_Core::set_used_sectors()
    falls into the else not a supported file system (because SWRAID
    doesn't have a derived FileSystem implementation class).
*   GParted_Core::mounted_set_used_sectors()
    is called to get the file system usage of mounted, but unsupported
    file systems, such as UFS and any others.
*   Utils::get_mounted_filesystem_usage()
    is called which queries the kernel using statvfs() and gets the file
    system usage of the /dev virtual file system because the array
    device name will always start /dev.

Fix by ensuring that GParted only asks the kernel for the usage of paths
which it knows are mount points of mounted file systems.  (As read from
/proc/mounts and cached in the Mount_Info module).  Also rename the
method, by inserting "_fs", to mounted_fs_set_used_sectors() to remind
us that it is for mounted *file systems* only.

Closes #27 - GParted may report incorrect usage for SWRAID partitions
             instead of unknown

S
This commit is contained in:
Mike Fleetwood 2018-11-18 12:41:56 +00:00 committed by Curtis Gedak
parent 4b341c8dd9
commit b9d3638a12
2 changed files with 6 additions and 6 deletions

View File

@ -96,7 +96,7 @@ private:
bool set_mountpoints_helper( Partition & partition, const Glib::ustring & path );
bool is_busy( FSType fstype, const Glib::ustring & path );
void set_used_sectors( Partition & partition, PedDisk* lp_disk );
void mounted_set_used_sectors( Partition & partition ) ;
void mounted_fs_set_used_sectors(Partition& partition);
#ifdef HAVE_LIBPARTED_FS_RESIZE
void LP_set_used_sectors( Partition & partition, PedDisk* lp_disk ) ;
#endif

View File

@ -1748,7 +1748,7 @@ void GParted_Core::set_used_sectors( Partition & partition, PedDisk* lp_disk )
p_filesystem->set_used_sectors( partition );
break;
case FS::GPARTED:
mounted_set_used_sectors( partition );
mounted_fs_set_used_sectors( partition );
break;
default:
break;
@ -1830,15 +1830,15 @@ void GParted_Core::set_used_sectors( Partition & partition, PedDisk* lp_disk )
}
else
{
// Set usage of mouted but unsupported file systems
// Set usage of mounted but unsupported file systems.
if ( partition.busy )
mounted_set_used_sectors( partition );
mounted_fs_set_used_sectors(partition);
}
}
void GParted_Core::mounted_set_used_sectors( Partition & partition )
void GParted_Core::mounted_fs_set_used_sectors( Partition & partition )
{
if ( partition .get_mountpoints() .size() > 0 )
if (partition.get_mountpoints().size() > 0 && Mount_Info::is_dev_mounted(partition.get_path()))
{
Byte_Value fs_size ;
Byte_Value fs_free ;