grub-probe: improve message when disk cannot be opened
RFC PATCH 1/2 * grub-core/kern/disk.c: don't override grub_errmsg when grub_disk_open fails
In reply to Antonio OspiteIn grub_disk_open() don't override error message when no _valid_ device can be found, instead use the one set from the last function which failed, which is more informative.
The current message "disk not found" discards precious info about the reason of the failure; for instance the disk may exist but cannot be opened because of permissions issues, in this case telling "disk not found" is inaccurate and may mislead the user about the actual cause of the failure.
https://savannah.gnu.org/bugs/?42409
--- grub-core/kern/disk.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
grub-core/kern/disk.c +1 -2
@@ -233,8 +233,7 @@ grub_disk_open (const char *name)if (! dev) { -grub_error (GRUB_ERR_UNKNOWN_DEVICE ,N_ ("disk `%s' not found" ), - name); + grub_errno =GRUB_ERR_UNKNOWN_DEVICE ; goto fail; } if (disk->log_sector_size > GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS
Signature · 1 line
2.9.3
RFC PATCH 2/2 * util/getroot.c: improve error message when a disk cannot be opened
In reply to Antonio OspiteOpening a disk can fail for two reasons:
1. the device does not exist;
2. the device exists but cannot be accessed for some reason.
The current error message assumes always 1. and this can misled users when they look for the actual cause of the failure.
So, reuse the error message from grub_disk_open() instead of always saying "disk does not exist".
https://savannah.gnu.org/bugs/?42409
--- util/getroot.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
util/getroot.c +9 -6
@@ -391,16 +391,19 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev) {/* We already know that the partition exists. Given that we already checked the device map above, we can only get -GRUB_ERR_UNKNOWN_DEVICE at this point if the disk does not exist. -This can happen on Xen, where disk images in the host can be -assigned to devices that have partition-like names in the guest -but are really more like disks. */ +GRUB_ERR_UNKNOWN_DEVICE at this point if the disk does not exist, +or cannot be opened for some reason (e.g. insufficient +permissions). +The first case (the disk does not exist) can happen on Xen, where +disk images in the host can be assigned to devices that have +partition-like names in the guest but are really more like disks. +*/ if (grub_errno ==GRUB_ERR_UNKNOWN_DEVICE ) {char *canon;grub_util_warn - (_ ("disk does not exist, so falling back to partition device %s" ), - os_dev); + (_ ("%s, so falling back to partition device %s" ), + grub_errmsg, os_dev); grub_errno =GRUB_ERR_NONE ; canon =grub_canonicalize_file_name (os_dev);
Signature · 1 line
2.9.3
cover grub-probe: improve message when disk cannot be opened
Hi,
right now when running grub-probe and the disk cannot be opened the error message can be misleading, it always says "disk not found" but in some case the disk may exist but the user has no permissions to open it, see https://savannah.gnu.org/bugs/?42409
The message can be improved by propagating informations about the cause of the failure from the bottom layers.
Please take a look at the patches in this series, I marked them RFC because I am new to grub code and I am not sure that all the error paths set a meaningful message, but I wanted some code to base the discussion on.
Patch 1/2 aims to prevent overriding the error messages from the disk->open() methods called in grub_disk_open().
Patch 2/2 exposes to the user the —now more informative— message from grub_disk_open().
Before these changes I was getting this output when running grub-probe with insufficient permissions:
$ LANG=C ./grub-probe / ./grub-probe: warning: disk does not exist, so falling back to partition device /dev/sda1. ./grub-probe: warning: disk does not exist, so falling back to partition device /dev/sda1. ./grub-probe: warning: disk does not exist, so falling back to partition device /dev/sda1. ./grub-probe: error: disk `hostdisk//dev/sda1' not found.
After the patches the reason of the failure is clearer:
$ LANG=C ./grub-probe / ./grub-probe: warning: cannot open `/dev/sda': Permission denied, so falling back to partition device /dev/sda1. ./grub-probe: warning: cannot open `/dev/sda': Permission denied, so falling back to partition device /dev/sda1. ./grub-probe: warning: cannot open `/dev/sda': Permission denied, so falling back to partition device /dev/sda1. ./grub-probe: error: cannot open `/dev/sda1': Permission denied.
As I said, this is the final effect I am aiming for but I am not 100% sure my solution is complete.
Thanks,
Antonio
Antonio Ospite (2):
* grub-core/kern/disk.c: don't override grub_errmsg when grub_disk_open fails
* util/getroot.c: improve error message when a disk cannot be opened
grub-core/kern/disk.c | 3 +-- util/getroot.c | 15 +++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-)
Signature · 6 lines
Antonio Ospite http://ao2.it A: Because it messes up the order in which people normally read text. See http://en.wikipedia.org/wiki/Posting_style Q: Why is top-posting such a bad thing?
Ping.
two weeks ago I sent the patches referenced in the message below and I haven't received a reply yet.
Maybe sending them in the middle of August was not the best choice. :)
Can anyone please take a look? Thanks.
Ciao,
Antonio
Quoted 56 lines · On Tue, 23 Aug 2016 12:17:26 +0200 Antonio Ospite <[email protected]> wrote:
Hi,
right now when running grub-probe and the disk cannot be opened the error message can be misleading, it always says "disk not found" but in some case the disk may exist but the user has no permissions to open it, see https://savannah.gnu.org/bugs/?42409
The message can be improved by propagating informations about the cause of the failure from the bottom layers.
Please take a look at the patches in this series, I marked them RFC because I am new to grub code and I am not sure that all the error paths set a meaningful message, but I wanted some code to base the discussion on.
Patch 1/2 aims to prevent overriding the error messages from the
disk->open()methods called ingrub_disk_open().Patch 2/2 exposes to the user the —now more informative— message from
grub_disk_open().Before these changes I was getting this output when running grub-probe with insufficient permissions:
$ LANG=C ./grub-probe / ./grub-probe: warning: disk does not exist, so falling back to partition device /dev/sda1. ./grub-probe: warning: disk does not exist, so falling back to partition device /dev/sda1. ./grub-probe: warning: disk does not exist, so falling back to partition device /dev/sda1. ./grub-probe: error: disk `hostdisk//dev/sda1' not found.After the patches the reason of the failure is clearer:
$ LANG=C ./grub-probe / ./grub-probe: warning: cannot open `/dev/sda': Permission denied, so falling back to partition device /dev/sda1. ./grub-probe: warning: cannot open `/dev/sda': Permission denied, so falling back to partition device /dev/sda1. ./grub-probe: warning: cannot open `/dev/sda': Permission denied, so falling back to partition device /dev/sda1. ./grub-probe: error: cannot open `/dev/sda1': Permission denied.As I said, this is the final effect I am aiming for but I am not 100% sure my solution is complete.
Thanks,
AntonioAntonio Ospite (2):
*grub-core/kern/disk.c: don't overridegrub_errmsgwhengrub_disk_openfails
*util/getroot.c: improve error message when a disk cannot be openedgrub-core/kern/disk.c | 3 +-- util/getroot.c | 15 +++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-)
Signature · 6 lines
Antonio Ospite http://ao2.it A: Because it messes up the order in which people normally read text. See http://en.wikipedia.org/wiki/Posting_style Q: Why is top-posting such a bad thing?
Quoted 5 lines · On Mon, 5 Sep 2016 21:40:30 +0200 Antonio Ospite <[email protected]> wrote:
Ping.
two weeks ago I sent the patches referenced in the message below and I haven't received a reply yet.
Hi,
another month has passed, has anyone had a chance to take a look?
As said in the original message quoted below the issue is also described in https://savannah.gnu.org/bugs/?42409
Thanks,
Antonio
Quoted 61 lines
Quoted 56 lines · On Tue, 23 Aug 2016 12:17:26 +0200 Antonio Ospite <[email protected]> wrote:
Hi,
right now when running grub-probe and the disk cannot be opened the error message can be misleading, it always says "disk not found" but in some case the disk may exist but the user has no permissions to open it, see https://savannah.gnu.org/bugs/?42409
The message can be improved by propagating informations about the cause of the failure from the bottom layers.
Please take a look at the patches in this series, I marked them RFC because I am new to grub code and I am not sure that all the error paths set a meaningful message, but I wanted some code to base the discussion on.
Patch 1/2 aims to prevent overriding the error messages from the
disk->open()methods called ingrub_disk_open().Patch 2/2 exposes to the user the —now more informative— message from
grub_disk_open().Before these changes I was getting this output when running grub-probe with insufficient permissions:
$ LANG=C ./grub-probe / ./grub-probe: warning: disk does not exist, so falling back to partition device /dev/sda1. ./grub-probe: warning: disk does not exist, so falling back to partition device /dev/sda1. ./grub-probe: warning: disk does not exist, so falling back to partition device /dev/sda1. ./grub-probe: error: disk `hostdisk//dev/sda1' not found.After the patches the reason of the failure is clearer:
$ LANG=C ./grub-probe / ./grub-probe: warning: cannot open `/dev/sda': Permission denied, so falling back to partition device /dev/sda1. ./grub-probe: warning: cannot open `/dev/sda': Permission denied, so falling back to partition device /dev/sda1. ./grub-probe: warning: cannot open `/dev/sda': Permission denied, so falling back to partition device /dev/sda1. ./grub-probe: error: cannot open `/dev/sda1': Permission denied.As I said, this is the final effect I am aiming for but I am not 100% sure my solution is complete.
Thanks,
AntonioAntonio Ospite (2):
*grub-core/kern/disk.c: don't overridegrub_errmsgwhengrub_disk_openfails
*util/getroot.c: improve error message when a disk cannot be openedgrub-core/kern/disk.c | 3 +-- util/getroot.c | 15 +++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-)
Signature · 7 lines
Antonio Ospite https://ao2.it https://twitter.com/ao2it A: Because it messes up the order in which people normally read text. See http://en.wikipedia.org/wiki/Posting_style Q: Why is top-posting such a bad thing?
Quoted 7 lines · On Tue, 23 Aug 2016 12:17:26 +0200 Antonio Ospite <[email protected]> wrote:
Hi,
right now when running grub-probe and the disk cannot be opened the error message can be misleading, it always says "disk not found" but in some case the disk may exist but the user has no permissions to open it, see https://savannah.gnu.org/bugs/?42409
Ping.
Now that grub 2.02 has been released maybe there is a chance that someone looks at this issue?
The two patches from this thread still apply to the current master branch.
I can resend them if needed.
Thanks,
Antonio
Quoted 49 lines
The message can be improved by propagating informations about the cause of the failure from the bottom layers.
Please take a look at the patches in this series, I marked them RFC because I am new to grub code and I am not sure that all the error paths set a meaningful message, but I wanted some code to base the discussion on.
Patch 1/2 aims to prevent overriding the error messages from the
disk->open()methods called ingrub_disk_open().Patch 2/2 exposes to the user the —now more informative— message from
grub_disk_open().Before these changes I was getting this output when running grub-probe with insufficient permissions:
$ LANG=C ./grub-probe / ./grub-probe: warning: disk does not exist, so falling back to partition device /dev/sda1. ./grub-probe: warning: disk does not exist, so falling back to partition device /dev/sda1. ./grub-probe: warning: disk does not exist, so falling back to partition device /dev/sda1. ./grub-probe: error: disk `hostdisk//dev/sda1' not found.After the patches the reason of the failure is clearer:
$ LANG=C ./grub-probe / ./grub-probe: warning: cannot open `/dev/sda': Permission denied, so falling back to partition device /dev/sda1. ./grub-probe: warning: cannot open `/dev/sda': Permission denied, so falling back to partition device /dev/sda1. ./grub-probe: warning: cannot open `/dev/sda': Permission denied, so falling back to partition device /dev/sda1. ./grub-probe: error: cannot open `/dev/sda1': Permission denied.As I said, this is the final effect I am aiming for but I am not 100% sure my solution is complete.
Thanks,
AntonioAntonio Ospite (2):
*grub-core/kern/disk.c: don't overridegrub_errmsgwhengrub_disk_openfails
*util/getroot.c: improve error message when a disk cannot be openedgrub-core/kern/disk.c | 3 +-- util/getroot.c | 15 +++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-)
Signature · 7 lines
Antonio Ospite https://ao2.it https://twitter.com/ao2it A: Because it messes up the order in which people normally read text. See http://en.wikipedia.org/wiki/Posting_style Q: Why is top-posting such a bad thing?