gparted/include
Mike Fleetwood 3d1b2921a6 Only explicitly flush devices when using libparted < 3.2 (#259)
During device probing GParted always explicitly calls ped_device_sync()
to flush the caches for coherency between the whole disk device and the
partition devices [1].  As the GParted_Core::flush_device() comment
explains, since v3.1.61-gfb99ba5 [2], libparted flushes the devices
every time a device is opened [3], so also explicitly doing this in
GParted is unnecessary.  Therefore stop explicitly flushing the devices
in GParted, except when using libparted 3.1 and older which doesn't do
it itself.

The ped_device_open() and ped_device_close() needed for the
ped_device_sync() is also a trigger of device changes and udev rule
execution performing LVM Volume Group activation, because libparted
opens the device read-write [4].  This is another reason to remove it
when possible.  However even when eliminated it does not solve the issue
of LVM VG activation because other triggers remain.  Do want this change
first though so that the sequence of libparted calls isn't changed
immediately after documenting them and fixing the issue and so that
there is no doubt that this change doesn't fix the issue.

Removing this extra device flush saves a little bit of time, depending
on the speed of the drive and number of partitions.  Sample savings on
my desktop:
    Drive type and partitions       Saving (seconds)
    -----------------------------   ----------------
    fast SSD with 3 partitions      0.05
    slow SSD with 12 partitions     0.27
    HDD with 1 partition            0.05
    VHDD in VM with 1 partition     0.14
    VHDD in VM with 10 partitions   0.58

Also the settle_device() call in flush_device() needs to be kept to wait
for device changes and udev rule execution whether it is GParted
explicitly flushing the device or just libparted automatically doing it
for cache coherency in ped_device_get().  This is because:
1.  Libparted <= 3.2 opens the whole disk device read-write for
    ped_device_get() [5].  (This was changed with parted
    v3.2.26-g44d5ae0 [6] to open the whole disk device read-only).
2.  Libparted up to and including the latest 3.6 release still opens all
    partition devices read-write for ped_device_get() [7].
3.  A whole disk device FAT32 file system looks enough like a partition
    table that both the Linux kernel and libparted think it is
    partitioned:
        # mkfs.fat -F32 /dev/sdb
        mkfs.fat 4.2 (2021-01-31)
        # grep sdb /proc/partitions
           8       16    8388608 sdb
           8       17    8388607 sdb1
        # parted /dev/sdb print
        Model: ATA VBOX HARDDISK (scsi)
        Disk /dev/sdb: 8590MB
        Sector size (logical/physical): 512B/512B
        Partition Table: loop
        Disk Flags:

        Number  Start  End        Size       File system  Flags
         1      0s     16777215s  16777216s  fat32

So the ped_device_get() call on a whole disk device FAT32 file system
still triggers device change and udev rule execution which needs to be
waited for, as this is exactly the case fixed previously by commit:
    1382e0b828
    Wait for udev change on /dev/DISK when querying whole device FS (!46)

[1] 3bea067596
    Flush devices when scanning to prevent reading stale signatures (#723842)
[2] Revert "linux-commit: do not unnecessarily open partition device nodes"
    http://git.savannah.gnu.org/cgit/parted.git/commit/?id=fb99ba5ebd0dc34204fc9f1014131d5d494805bc
[3] parted libparted/arch/linux.c:_device_open()
    https://git.savannah.gnu.org/cgit/parted.git/tree/libparted/arch/linux.c?h=v3.6#n1752
        1709 static int
        1710 linux_open (PedDevice* dev)
        1711 {
        1712     return _device_open (dev, RW_MODE);
        1713 }
        1714
        1715 static int
        1716 _device_open (PedDevice* dev, int flags)
        ...
        1752     _flush_cache (dev);

[4] parted libparted/device.c:ped_device_open() v3.6
    https://git.savannah.gnu.org/cgit/parted.git/tree/libparted/device.c?h=v3.6#n226
    parted libparted/arch/linux.c v3.6
    https://git.savannah.gnu.org/cgit/parted.git/tree/libparted/arch/linux.c?h=v3.6
        ped_device_open(...)
            ped_architecture->dev_ops->open(...) = linux_open(...)
                _device_open(..., RW_MODE)
                    open(..., O_RDWR)

[5] parted libparted/device.c:ped_device_get() v3.2
    https://git.savannah.gnu.org/cgit/parted.git/tree/libparted/device.c?h=v3.2#n149
    parted libparted/arch/linux.c v3.2
    https://git.savannah.gnu.org/cgit/parted.git/tree/libparted/arch/linux.c?h=v3.2
        ped_device_get(...)
            ped_architecture->dev_ops->_new(...) = linux_new()
                init_ide(...)
                init_scsi(...)
                init_generic(...)
                    ped_device_open(...)
                        ped_architecture->dev_ops->open(...) = linux_open(...)
                            open(..., O_RDWR)
[6] libparted: Use read only when probing devices on linux (#1245144)
    http://git.savannah.gnu.org/cgit/parted.git/commit/?id=44d5ae0115c4ecfe3158748309e9912c5aede92d
[7] parted libparted/arch/linux.v v3.6
    http://git.savannah.gnu.org/cgit/parted.git/tree/libparted/arch/linux.c?h=v3.6#n1660
        1660 static void
        1661 _flush_cache (PedDevice* dev)
        ...
        1673     for (i = 1; i < lpn; i++) {
        ...
        1680         if (!_partition_is_mounted_by_path(name)) {
        1681             fd = open (name, WR_MODE, 0);

Closes #259 - Trying to deactivate LVM PV fails
2024-09-14 08:44:43 +00:00
..
BCache_Info.h Show bcache device as mount point of registered backing device (#183) 2022-03-01 16:58:46 +00:00
BlockSpecial.h Pre-populate BlockSpecial cache while reading /proc/partitions (#767842) 2016-08-06 09:47:58 -06:00
CopyBlocks.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
DMRaid.h Make 4 internally used only DMRaid methods private 2019-12-02 16:35:22 +00:00
Device.h Return and use constant reference from Device::get_path() (!94) 2021-11-16 16:08:17 +00:00
DialogFeatures.h White space tidy-up some of DialogFeatures 2021-07-30 16:12:24 +00:00
DialogManageFlags.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
DialogPasswordEntry.h Report this LUKS passphrase request reason as resize (#59) 2021-04-25 15:49:35 +00:00
Dialog_Base_Partition.h Make MB_Needed_for_Boot_Record() a static member function 2021-10-27 15:04:20 +00:00
Dialog_Disklabel.h Ensure icon sizes (#39) 2019-04-06 11:42:28 +01:00
Dialog_FileSystem_Label.h Simplify from Gtk::Table to HBox in FileSystem Label dialog 2018-06-18 10:15:33 -06:00
Dialog_Partition_Copy.h Pass the current device down to Dialog_Base_Partition class (#48) 2019-06-11 15:55:02 +00:00
Dialog_Partition_Info.h Use Gtk::Grid for Dialog_Partition_Info (!25) 2019-04-27 12:03:05 +01:00
Dialog_Partition_Name.h Simplify from Gtk::Table to HBox in Partition Name dialog 2018-06-18 10:15:33 -06:00
Dialog_Partition_New.h Rename member variable to default_fs 2021-03-04 16:55:06 +00:00
Dialog_Partition_Resize_Move.h Pass the current device down to Dialog_Base_Partition class (#48) 2019-06-11 15:55:02 +00:00
Dialog_Progress.h Rename Dialog_Progress member variable to m_curr_op 2019-04-11 10:06:36 -06:00
DrawingAreaVisualDisk.h Use Gdk::RGBA (!25) 2019-04-27 12:03:04 +01:00
FS_Info.h Make FS_Info (blkid) cache incrementally loadable (#148) 2021-04-03 17:02:04 +00:00
FileSystem.h Remove now unused T, N & S FileSystem member variables (!119) 2023-10-29 15:50:43 +00:00
Frame_Resizer_Base.h Use Gdk::RGBA (!25) 2019-04-27 12:03:04 +01:00
Frame_Resizer_Extended.h Put Frame_Resizer_{Base,Extended} modules into GParted namespace (!20) 2018-11-26 17:56:32 +00:00
GParted_Core.h Only explicitly flush devices when using libparted < 3.2 (#259) 2024-09-14 08:44:43 +00:00
HBoxOperations.h Use Gtk::Box for HBoxOperations (!25) 2019-04-27 12:03:04 +01:00
LUKS_Info.h Capture LUKS mapping master encryption key location (#59) 2021-04-25 15:49:35 +00:00
LVM2_PV_Info.h Return and use constant reference from LVM2_PV_Info::get_vg_name() (!94) 2021-11-16 16:08:17 +00:00
Makefile.am Add bcachefs creation (!123) 2024-09-11 15:25:17 +00:00
MenuHelpers.h prepare-for-gtk3: Prepare for removal of Gtk::Menu_Helpers::Element (#7) 2019-02-11 08:57:18 +00:00
Mount_Info.h Constify string parameters to add_mountpoint_entry() 2022-05-31 17:04:10 +00:00
Operation.h Remove final namespace qualifiers from use of GParted's own enums 2024-02-08 16:19:20 +00:00
OperationChangeUUID.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OperationCheck.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OperationCopy.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OperationCreate.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OperationDelete.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OperationDetail.h Return const reference from OperationDetail::get_progressbar() 2023-06-17 16:13:23 +00:00
OperationFormat.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OperationLabelFileSystem.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OperationNamePartition.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OperationResizeMove.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
OptionComboBox.h modern-gtk2: Delay construction of Gtk::TreeModel* objects (!17) 2018-11-12 21:50:42 +00:00
Partition.h Briefly comment STAT_* enumerators 2023-04-27 15:54:01 +00:00
PartitionLUKS.h Rename enum FILESYSTEM to FSType 2018-01-28 10:09:35 -07:00
PartitionVector.h Create and use general find_extended_partition() function 2017-01-14 08:49:58 -07:00
PasswordRAMStore.h Change to insert or replace PasswordRAMStore::store() interface (#795617) 2018-04-30 09:10:48 -06:00
PipeCapture.h Refactor ::OnReadable() creating get_utf8_char_validated() (#136) 2021-02-22 16:14:35 +00:00
Proc_Partitions_Info.h Read partition names from /proc/partitions too (#131) 2021-02-10 16:30:13 +00:00
ProgressBar.h Return constant reference from ProgressBar::get_text() 2023-06-17 16:13:23 +00:00
SWRaid_Info.h Return and use constant reference from SWRaid_Info::get_label() (!94) 2021-11-16 16:08:17 +00:00
SupportedFileSystems.h Split FILESYSTEMS and FILESYSTEM_MAP into separate module (!49) 2019-11-09 17:18:34 +00:00
TreeView_Detail.h Remove unneeded #include <vector> from TreeView_Detail.h 2020-09-18 16:00:44 +00:00
Utils.h Add bcachefs detection (!123) 2024-09-11 15:25:17 +00:00
Win_GParted.h Remove Attempt Data Rescue and use of gpart (!118) 2023-10-04 16:03:09 +00:00
bcachefs.h Add bcachefs checking (!123) 2024-09-11 15:25:17 +00:00
btrfs.h Use btrfs filesystem show --raw to read usage (!105) 2022-08-25 15:41:31 +00:00
exfat.h Add support for updating the exFAT UUID (!67) 2021-02-17 17:16:48 +00:00
ext2.h Prefix ext2 member variables with m_ and initialise all POD members 2024-08-10 10:03:37 +00:00
f2fs.h Enhance F2FS support (!29) 2019-03-26 08:08:10 +00:00
fat16.h Rename fat16 member variable to m_specific_fstype 2024-08-10 10:03:37 +00:00
hfs.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
hfsplus.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
i18n.h Drop compose subdir (#46) 2019-03-27 16:45:22 +00:00
jfs.h Stop providing a default for FileSystem::resize() fill_partition argument 2016-12-12 13:15:34 -07:00
linux_swap.h Make get_custom_text() and get_generic_text() return by reference 2018-06-18 10:15:33 -06:00
luks.h Make get_custom_text() and get_generic_text() return by reference 2018-06-18 10:15:33 -06:00
lvm2_pv.h Make get_custom_text() and get_generic_text() return by reference 2018-06-18 10:15:33 -06:00
minix.h Add support for minix file system (!12) 2018-08-24 20:22:08 +01:00
nilfs2.h Stop providing a default for FileSystem::resize() fill_partition argument 2016-12-12 13:15:34 -07:00
ntfs.h Rework scope of fat16:: and ntfs::Change_UUID_Warning vectors 2018-06-18 14:47:17 -06:00
reiser4.h Remove "../include/" from GParted header #includes 2016-12-12 13:15:34 -07:00
reiserfs.h Stop providing a default for FileSystem::resize() fill_partition argument 2016-12-12 13:15:34 -07:00
udf.h Rename udf member variable to m_old_mkudffs 2024-08-10 10:03:37 +00:00
xfs.h Prefix xfs member variables with m_ and initialise POD member 2024-08-10 10:03:37 +00:00