Hi, On Wed, 25 May 2016, Stefan Hundhammer wrote:
Brainstorming approach #4: Add read-only mode to parted =======================================================
"parted -l", which we are using in this situation, should already be a read-only operation. Unfortunately, strace shows that this is not the case: It starts with opening the disk device read-only, reads information, closes it - and then for whatever reason opens it again read-write which triggers the code that sends the ioctl() to make the kernel re-read the partition table.
That's of course stupid of parted.
We consider that a bug (https://bugzilla.suse.com/show_bug.cgi?id=979275), but it does not seem to be easy to fix. Any contribution to that would be very welcome.
See attached, fixes the bug by always opening read-only and lazily switching to read-write only when necessary (i.e. a write or flush operation occurs). No libparted API changes, purely internal to the linux "backend". I think I got all places where _ensure_read_write must be called, if you hit problems it should be easy to diagnose, because a forgotten call will lead to obvious errors for using a write on a read-only FD, so should be easy to diagnose and add. (also contains a local fix when not using blkid) Ciao, Michael.