diskfilter: use nodes in logical volume's segment as member device
PATCH 1/1 diskfilter: use nodes in logical volume's segment as member device
Currently the grub_diskfilter_memberlist function returns all physical volumes added to a volume group to which a logical volume (LV) belongs. However this is suboptimal as it doesn't fit the intended behavior of returning underlying devices that make up the LV. To give a clear picture, the result should be identical to running commands below to display the logical volumes with underlying physical volumes in use.
lvs -o +devices /dev/system/root lvdisplay --maps /dev/system/root
This change is required if any part of the PV not used by root LV is encrypted. Using this lvm setup as an example:
localhost:~ # lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 20G 0 disk
├─vda1 253:1 0 8M 0 part
└─vda2 253:2 0 20G 0 part
├─system-swap 254:0 0 1.4G 0 lvm [SWAP]
└─system-root 254:1 0 18.6G 0 lvm /
vdb 253:16 0 10M 0 disk
└─data 254:2 0 8M 0 crypt
└─system-data 254:3 0 4M 0 lvm /dataRunning grub-install would end up with error because "system" VG contains /dev/vdb which is encrypted.
error: attempt to install to encrypted disk without cryptodisk enabled. Set GRUB_ENABLE_CRYPTODISK=y' in file /etc/default/grub'.
Certainly we can enable GRUB_ENABLE_CRYPTODISK=y and move on, but that is not always acceptable since the server may need to boot unattended, in addition typing passphase for every system startup can be a big hassle of which most users would like to avoid.
This patch solves the problem by returning physical volumes, /dev/vda2, rightly used by system-root in the example above, thus changing how grub-install perceives the underlying block device to boot and avoids the error from happening.
--- grub-core/disk/diskfilter.c | 44 +++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 17 deletions(-)
grub-core/disk/diskfilter.c +27 -17
@@ -300,6 +300,8 @@ grub_diskfilter_memberlist (grub_disk_t disk)grub_disk_dev_t p;struct grub_diskfilter_vg *vg;struct grub_diskfilter_lv *lv2 =NULL ; +struct grub_diskfilter_segment *seg; +unsigned int i, j;if (!lv->vg->pvs)return NULL ;
@@ -331,25 +333,33 @@ grub_diskfilter_memberlist (grub_disk_t disk) } } -for (pv = lv->vg->pvs; pv; pv = pv->next) - { -if (!pv->disk) +for (i =0 , seg = lv->segments; i < lv->segment_count; i++, seg++) +for (j =0 ; j < seg->node_count; ++j) +if ((pv = seg->nodes[j].pv)) { -/* TRANSLATORS: This message kicks in during the detection of -which modules needs to be included in core image. This happens -in the case of degraded RAID and means that autodetection may -fail to include some of modules. It's an installation time -message, not runtime message. */ -grub_util_warn (_ ("Couldn't find physical volume `%s'." -" Some modules may be missing from core image." ), - pv->name); -continue ; + +if (!pv->disk) + { +/* TRANSLATORS: This message kicks in during the detection of +which modules needs to be included in core image. This happens +in the case of degraded RAID and means that autodetection may +fail to include some of modules. It's an installation time +message, not runtime message. */ +grub_util_warn (_ ("Couldn't find physical volume `%s'." +" Some modules may be missing from core image." ), + pv->name); +continue ; + } + +for (tmp = list; tmp; tmp = tmp->next) +if (grub_strcmp (tmp->disk->name, pv->disk->name) ==0 ) +continue ; + + tmp =grub_malloc (sizeof (*tmp)); + tmp->disk = pv->disk; + tmp->next = list; + list = tmp; } - tmp =grub_malloc (sizeof (*tmp)); - tmp->disk = pv->disk; - tmp->next = list; - list = tmp; - }return list; }
Signature · 1 line
2.31.1
Quoted 9 lines · Michael Chang via Grub-devel
Currently the
grub_diskfilter_memberlistfunction returns all physical volumes added to a volume group to which a logical volume (LV) belongs. However this is suboptimal as it doesn't fit the intended behavior of returning underlying devices that make up the LV. To give a clear picture, the result should be identical to running commands below to display the logical volumes with underlying physical volumes in use.lvs -o +devices /dev/system/root lvdisplay --maps /dev/system/root
May I ask you to provide output from these two commands too? Additionally, I think it would be useful to have output from "pvs" and "lvs" commands in the commit message. I know "lsblk" shows you most information but I think both "pvs" and "lvs" are giving more readable output.
Quoted 14 lines
This change is required if any part of the PV not used by root LV is encrypted. Using this lvm setup as an example:
localhost:~ # lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTvda 253:0 0 20G 0 disk ├─vda1 253:1 0 8M 0 part └─vda2 253:2 0 20G 0 part ├─system-swap 254:0 0 1.4G 0 lvm [SWAP] └─system-root 254:1 0 18.6G 0 lvm / vdb 253:16 0 10M 0 disk └─data 254:2 0 8M 0 crypt └─system-data 254:3 0 4M 0 lvm /data
Quoted 8 lines
Running grub-install would end up with error because "system" VG contains
/dev/vdbwhich is encrypted.error: attempt to install to encrypted disk without cryptodisk enabled. Set
GRUB_ENABLE_CRYPTODISK=y' in file/etc/default/grub'.Certainly we can enable GRUB_ENABLE_CRYPTODISK=y and move on, but that is not always acceptable since the server may need to boot unattended,
s/,/./
Quoted 1 line
in addition typing passphase for every system startup can be a big
s/in addition/Additionally,/
Quoted 27 lines
hassle of which most users would like to avoid.
This patch solves the problem by returning physical volumes,
/dev/vda2, rightly used by system-root in the example above, thus changing how grub-install perceives the underlying block device to boot and avoids the error from happening.Signed-off-by Michael Chang <[email protected]>Tested-by Olav Reinert <[email protected]>--- grub-core/disk/diskfilter.c | 44 +++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 17 deletions(-)grub-core/disk/diskfilter.c +2
-0@@ -300,6 +300,8 @@ grub_diskfilter_memberlist (grub_disk_t disk)grub_disk_dev_t p;struct grub_diskfilter_vg *vg;struct grub_diskfilter_lv *lv2 =NULL ; +struct grub_diskfilter_segment *seg; +unsigned int i, j;if (!lv->vg->pvs)return NULL ;
grub-core/disk/diskfilter.c grub_diskfilter_memberlist (grub_disk_t disk) · line 337
Quoted 8 lines
grub-core/disk/diskfilter.c +2
-3@@ -331,25 +333,33 @@ grub_diskfilter_memberlist (grub_disk_t disk) } } -for (pv = lv->vg->pvs; pv; pv = pv->next) - { -if (!pv->disk) +for (i =0 , seg = lv->segments; i < lv->segment_count; i++, seg++) +for (j =0 ; j < seg->node_count; ++j)
s/=0/= 0/
grub-core/disk/diskfilter.c grub_diskfilter_memberlist (grub_disk_t disk) · line 338
Quoted 1 line
grub-core/disk/diskfilter.c +1
-0+if ((pv = seg->nodes[j].pv))
if (seg->nodes[j].pv != NULL)
...and then later...
pv = seg->nodes[j].pv
Quoted 8 lines
grub-core/disk/diskfilter.c +0
-7{ -/* TRANSLATORS: This message kicks in during the detection of -which modules needs to be included in core image. This happens -in the case of degraded RAID and means that autodetection may -fail to include some of modules. It's an installation time -message, not runtime message. */ - grub_util_warn (_("Couldn't find physical volume `%s'." - " Some modules may be missing from core image."),
grub-core/disk/diskfilter.c grub_diskfilter_memberlist (grub_disk_t disk) · line 347
Quoted 10 lines
grub-core/disk/diskfilter.c +8
-2- pv->name); -continue ; + +if (!pv->disk) + { +/* TRANSLATORS: This message kicks in during the detection of +which modules needs to be included in core image. This happens +in the case of degraded RAID and means that autodetection may +fail to include some of modules. It's an installation time +message, not runtime message. */
Please fix this comment formatting if you move it.
grub-core/disk/diskfilter.c grub_diskfilter_memberlist (grub_disk_t disk) · line 354
Quoted 7 lines
grub-core/disk/diskfilter.c +7
-0+grub_util_warn (_ ("Couldn't find physical volume `%s'." +" Some modules may be missing from core image." ), + pv->name); +continue ; + } + +for (tmp = list; tmp; tmp = tmp->next)
tmp != NULL please...
grub-core/disk/diskfilter.c grub_diskfilter_memberlist (grub_disk_t disk) · line 355
Quoted 1 line
grub-core/disk/diskfilter.c +1
-0+if (grub_strcmp (tmp->disk->name, pv->disk->name) ==0 )
!grub_strcmp() instead of grub_strcmp() == 0
grub-core/disk/diskfilter.c grub_diskfilter_memberlist (grub_disk_t disk) · line 356
Quoted 1 line
grub-core/disk/diskfilter.c +1
-0+continue ;
I know what you mean but this "continue" does not make much sense here...
grub-core/disk/diskfilter.c grub_diskfilter_memberlist (grub_disk_t disk) · line 358
Quoted 2 lines
grub-core/disk/diskfilter.c +2
-0+ + tmp =grub_malloc (sizeof (*tmp));
Please do not ignore grub_malloc() failures.
Daniel
Quoted 8 lines · Daniel Kiper
Quoted 7 lines · Michael Chang via Grub-devel
Currently the
grub_diskfilter_memberlistfunction returns all physical volumes added to a volume group to which a logical volume (LV) belongs. However this is suboptimal as it doesn't fit the intended behavior of returning underlying devices that make up the LV. To give a clear picture, the result should be identical to running commands below to display the logical volumes with underlying physical volumes in use.
Quoted 7 lines
Quoted 2 lines
lvs -o +devices /dev/system/root lvdisplay --maps /dev/system/rootMay I ask you to provide output from these two commands too? Additionally, I think it would be useful to have output from "pvs" and "lvs" commands in the commit message. I know "lsblk" shows you most information but I think both "pvs" and "lvs" are giving more readable output.
It sounds good as that helps better understanding. I'll add these information to next version.
Quoted 18 lines
Quoted 18 lines
This change is required if any part of the PV not used by root LV is encrypted. Using this lvm setup as an example:
localhost:~ # lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTvda 253:0 0 20G 0 disk ├─vda1 253:1 0 8M 0 part └─vda2 253:2 0 20G 0 part ├─system-swap 254:0 0 1.4G 0 lvm [SWAP] └─system-root 254:1 0 18.6G 0 lvm / vdb 253:16 0 10M 0 disk └─data 254:2 0 8M 0 crypt └─system-data 254:3 0 4M 0 lvm /dataRunning grub-install would end up with error because "system" VG contains
/dev/vdbwhich is encrypted.
Quoted 7 lines
Quoted 5 lines
error: attempt to install to encrypted disk without cryptodisk enabled. Set
GRUB_ENABLE_CRYPTODISK=y' in file/etc/default/grub'.Certainly we can enable GRUB_ENABLE_CRYPTODISK=y and move on, but that is not always acceptable since the server may need to boot unattended,
s/,/./
OK.
Quoted 4 lines
Quoted 2 lines
in addition typing passphase for every system startup can be a big
s/in addition/Additionally,/
OK.
Quoted 31 lines
Quoted 31 lines
hassle of which most users would like to avoid.
This patch solves the problem by returning physical volumes,
/dev/vda2, rightly used by system-root in the example above, thus changing how grub-install perceives the underlying block device to boot and avoids the error from happening.Signed-off-by Michael Chang <[email protected]>Tested-by Olav Reinert <[email protected]>--- grub-core/disk/diskfilter.c | 44 +++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 17 deletions(-)grub-core/disk/diskfilter.c +2
-0@@ -300,6 +300,8 @@ grub_diskfilter_memberlist (grub_disk_t disk)grub_disk_dev_t p;struct grub_diskfilter_vg *vg;struct grub_diskfilter_lv *lv2 =NULL ; +struct grub_diskfilter_segment *seg; +unsigned int i, j;if (!lv->vg->pvs)return NULL ;@@ -331,25 +333,33 @@ grub_diskfilter_memberlist (grub_disk_t disk) } }
Quoted 7 lines
grub-core/disk/diskfilter.c grub_diskfilter_memberlist (grub_disk_t disk) · line 337
Quoted 5 lines
grub-core/disk/diskfilter.c +2
-3-for (pv = lv->vg->pvs; pv; pv = pv->next) - { -if (!pv->disk) +for (i =0 , seg = lv->segments; i < lv->segment_count; i++, seg++) +for (j =0 ; j < seg->node_count; ++j)s/=0/= 0/
OK.
Quoted 8 lines
grub-core/disk/diskfilter.c grub_diskfilter_memberlist (grub_disk_t disk) · line 338
Quoted 2 lines
grub-core/disk/diskfilter.c +1
-0+if ((pv = seg->nodes[j].pv))if (seg->nodes[j].pv != NULL)
...and then later...
pv = seg->nodes[j].pv
OK.
Quoted 13 lines
Quoted 13 lines
grub-core/disk/diskfilter.c +2
-9{ -/* TRANSLATORS: This message kicks in during the detection of -which modules needs to be included in core image. This happens -in the case of degraded RAID and means that autodetection may -fail to include some of modules. It's an installation time -message, not runtime message. */ -grub_util_warn (_ ("Couldn't find physical volume `%s'." -" Some modules may be missing from core image." ), - pv->name); -continue ; + +if (!pv->disk)
Quoted 8 lines
grub-core/disk/diskfilter.c grub_diskfilter_memberlist (grub_disk_t disk) · line 347
Quoted 6 lines
grub-core/disk/diskfilter.c +6
-0+ { +/* TRANSLATORS: This message kicks in during the detection of +which modules needs to be included in core image. This happens +in the case of degraded RAID and means that autodetection may +fail to include some of modules. It's an installation time +message, not runtime message. */ Please fix this comment formatting if you move it.
May I ask what is wrong as it looks good to the indention that has been adjusted to the new place ?
Quoted 10 lines
grub-core/disk/diskfilter.c grub_diskfilter_memberlist (grub_disk_t disk) · line 354
Quoted 8 lines
grub-core/disk/diskfilter.c +7
-0+grub_util_warn (_ ("Couldn't find physical volume `%s'." +" Some modules may be missing from core image." ), + pv->name); +continue ; + } + +for (tmp = list; tmp; tmp = tmp->next)tmp != NULL please...
OK.
Quoted 4 lines
grub-core/disk/diskfilter.c grub_diskfilter_memberlist (grub_disk_t disk) · line 355
Quoted 2 lines
grub-core/disk/diskfilter.c +1
-0+if (grub_strcmp (tmp->disk->name, pv->disk->name) ==0 )!grub_strcmp() instead of
grub_strcmp()== 0
OK.
Well. It appears "grub_strcmp() == 0" more popular as it has more grep hits . But I am fine in doing either way. :)
grep -R '!grub_strcmp' | wc -l
26
grep -R 'grub_strcmp.*== 0' | wc -l
385
Quoted 4 lines
grub-core/disk/diskfilter.c grub_diskfilter_memberlist (grub_disk_t disk) · line 356
Quoted 2 lines
grub-core/disk/diskfilter.c +1
-0+continue ;I know what you mean but this "continue" does not make much sense here...
Indeed this looks bogus. I will fix this in next version.
Quoted 5 lines
grub-core/disk/diskfilter.c grub_diskfilter_memberlist (grub_disk_t disk) · line 358
Quoted 3 lines
grub-core/disk/diskfilter.c +2
-0+ + tmp =grub_malloc (sizeof (*tmp));Please do not ignore
grub_malloc()failures.
OK.
Thanks a lot for review.
Michael
Quoted 7 lines
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel