hostdisk: Fix linux disk cache workaround on multipath disks
PATCH 1/1 hostdisk: Fix linux disk cache workaround on multipath disks
In hostdisk.c::grub_util_fd_open_device, there's a workaround to linux disk cache described below.
"Linux has a bug that the disk cache for a whole disk is not consistent with the one for a partition of the disk."
The workaround will result in using the partition device for writing the image of which the address offset is calculated to be within it's range, to avoid the cache problem of the whole disk device.
This patch fixed the linux disk cache workaround not being effective for multipath/dm device because its partition device cannot be correctly determined by grub_hostdisk_linux_find_partition function.
--- grub-core/osdep/linux/hostdisk.c | 6 ++++++ 1 file changed, 6 insertions(+)
grub-core/osdep/linux/hostdisk.c +6 -0
@@ -263,6 +263,12 @@ grub_hostdisk_linux_find_partition (char *dev, grub_disk_addr_t sector) p = real_dev + len; format ="-part%d" ; } +else if (strncmp (real_dev,"/dev/dm-" , +sizeof ("/dev/dm-" ) -1 ) ==0 ) + { + p = real_dev + len -1 ; + format ="%d" ; + }else if (real_dev[len -1 ] >='0' && real_dev[len -1 ] <='9' ) { p = real_dev + len;
Signature · 1 line
2.13.6
Quoted 1 line · Michael Chang
In
hostdisk.c::grub_util_fd_open_device, there's a workaround to linux disk
s#hostdisk.c::grub_util_fd_open_device#grub-core/osdep/linux/hostdisk.c:grub_util_fd_open_device()#
Quoted 6 lines
cache described below.
"Linux has a bug that the disk cache for a whole disk is not consistent with the one for a partition of the disk."
The workaround will result in using the partition device for writing the image
Which workaround are you referring to?
Quoted 2 lines
of which the address offset is calculated to be within it's range, to avoid the cache problem of the whole disk device.
This sentence is convoluted. Please fix this.
Quoted 1 line
This patch fixed the linux disk cache workaround not being effective for
s/fixed/fixes/
Quoted 2 lines
multipath/dm device because its partition device cannot be correctly determined by
grub_hostdisk_linux_find_partitionfunction.
In general I am not happy with the commit message. It is difficult to understand where the problem is and why and how it is fixed.
And lack of SOB...
Daniel
Quoted 4 lines · Daniel Kiper
Quoted 1 line · Michael Chang
In
hostdisk.c::grub_util_fd_open_device, there's a workaround to linux disks#hostdisk.c::grub_util_fd_open_device#grub-core/osdep/linux/hostdisk.c:grub_util_fd_open_device()#
OK.
Quoted 9 lines
Quoted 7 lines
cache described below.
"Linux has a bug that the disk cache for a whole disk is not consistent with the one for a partition of the disk."
The workaround will result in using the partition device for writing the image
Which workaround are you referring to?
There's a comment in grub-core/osdep/linux/hostdisk.c::grub_util_fd_open_device() that stats "Linux has a bug ..." that we cannot use whole disk offset writing into a partition device since it does not reliably work that the data may be lost.
/* Linux has a bug that the disk cache for a whole disk is not consistent
with the one for a partition of the disk. */
{
....}
And as the input argument of grub_util_fd_open_device() is using address in unit of sector size offset from the "disk", and in a bid to avoid Linux disk cache inconsistency problem here grub translates the address again into the address offset from partition that have enclosed it and then use that partition device instead of disk device.
Quoted 4 lines
Quoted 3 lines
of which the address offset is calculated to be within it's range, to avoid the cache problem of the whole disk device.
Quoted 8 lines
This sentence is convoluted. Please fix this.
Quoted 1 line
This patch fixed the linux disk cache workaround not being effective for
s/fixed/fixes/
OK.
Quoted 3 lines
Quoted 3 lines
multipath/dm device because its partition device cannot be correctly determined by
grub_hostdisk_linux_find_partitionfunction.
The grub_hostdisk_linux_find_partition() does the trick for finding the partition device for a given partition start address and will be used in place of whole disk device.
Quoted 3 lines
In general I am not happy with the commit message. It is difficult to understand where the problem is and why and how it is fixed.
The problem we encountered was that installing grub into multipath disk partition didn't work reliably. And after debugging it boiled down to the disk cache problem described above as strace result shown it was using whole disk device. We then took another step forward in finding out the cause was missing "/dev/dm-" name scheme handling in grub_hostdisk_linux_find_partition(). After applying the fix the problem got fixed and we would like to have this fixing patch upstreamed as it looks good material to be.
Quoted 2 lines
And lack of SOB...
Sorry. I will add SOB in later version.
Thanks,
Michael
Quoted 7 lines
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel