Remove extra execution of blkid for whole disk devices (#131)

On Fedora 31 with this simple disk layout where both sdb and sdc are
completely empty:
    # lsblk -o name,maj:min,rm,size,ro,type,fstype,label,mountpoint
    NAME            MAJ:MIN RM  SIZE RO TYPE FSTYPE      LABEL MOUNTPOINT
    sda               8:0    0   20G  0 disk
    |-sda1            8:1    0    1G  0 part ext4              /boot
    \-sda2            8:2    0   19G  0 part LVM2_member
      |-fedora-root 253:0    0   17G  0 lvm  ext4              /
      \-fedora-swap 253:1    0    2G  0 lvm  swap              [SWAP]
    sdb               8:16   0    8G  0 disk
    sdc               8:32   0    8G  0 disk
    sr0              11:0    1 1024M  0 rom
    # blkid /dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdc
    /dev/sda: PTUUID="5012fb1f" PTTYPE="dos"
    /dev/sda1: UUID="3cd48816-7817-4636-9fec-5f1afe76c1b2" TYPE="ext4" PARTUUID="5012fb1f-01"
    /dev/sda2: UUID="PH94ej-C8xU-bnMJ-UIh8-ZimI-4B7f-dHlZxh" TYPE="LVM2_member" PARTUUID="5012fb1f-02"

Stracing GParted shows extra executions of blkid:
    # strace -f -q -bexecve -eexecve ./gpartedbin 2>&1 1> /dev/null | egrep -v 'ENOENT|SIGCHLD'
    ...
    [pid  7659] execve("/usr/sbin/blkid", ["blkid", "/dev/sda", "/dev/sda1", "/dev/sda2", "/dev/sdb", "/dev/sdc"], 0x1d300f0 /* 32 vars */ <detached ...>
    [pid  7660] execve("/usr/sbin/blkid", ["blkid", "/dev/sdb"], 0x1d300f0 /* 32 vars */ <detached ...>
    [pid  7661] execve("/usr/sbin/blkid", ["blkid", "/dev/sdc"], 0x1d300f0 /* 32 vars */ <detached ...>
    ...

blkid is only run again for sdb and sdc, not sda, because blkid didn't
report anything for them from the first execution.  GParted needs blkid
identification of whole disk devices to ensure that ISO9660 images on
whole disk devices are correctly identified [1].  Now the first run of
blkid passes all the device names, so this additional execution of blkid
won't get any extra information and is redundant.  Therefore remove this
unnecessary code.

[1] b2190372d0
    Ensure blkid FS_Info cache has entries for all whole disk devices
    (#771244)

Closes #131 - GParted hangs when non-named device is hung
This commit is contained in:
Mike Fleetwood 2021-01-24 16:19:55 +00:00 committed by Curtis Gedak
parent 8b35892ea5
commit 416027de64
1 changed files with 3 additions and 17 deletions

View File

@ -14,9 +14,9 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "FS_Info.h"
#include "BlockSpecial.h"
#include "Proc_Partitions_Info.h"
#include "Utils.h"
#include <glibmm/ustring.h>
@ -24,6 +24,7 @@
#include <glibmm/shell.h>
#include <vector>
namespace GParted
{
@ -208,25 +209,10 @@ const FS_Entry & FS_Info::get_cache_entry_by_path( const Glib::ustring & path )
void FS_Info::load_fs_info_cache(const std::vector<Glib::ustring>& paths)
{
fs_info_cache.clear();
// Run "blkid" and load entries into the cache.
run_blkid_load_cache(paths);
// (#771244) Ensure the cache has entries for all whole disk devices, even if
// those entries are blank. Needed so that an ISO9660 image stored on a whole
// disk device is detected before any embedded partitions within the image.
const BlockSpecial empty_bs = BlockSpecial();
std::vector<Glib::ustring> all_devices = Proc_Partitions_Info::get_device_paths();
for ( unsigned int i = 0 ; i < all_devices.size() ; i ++ )
{
const FS_Entry & fs_entry = get_cache_entry_by_path( all_devices[i] );
if ( fs_entry.path == empty_bs )
{
// Run "blkid PATH" and load entry into cache for missing entries.
load_fs_info_cache_extra_for_path( all_devices[i] );
}
}
}
void FS_Info::load_fs_info_cache_extra_for_path( const Glib::ustring & path )
{
std::vector<Glib::ustring> one_path;