|
|
5593c8 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
5593c8 |
From: Diego Domingos <diegodo@br.ibm.com>
|
|
|
5593c8 |
Date: Mon, 14 Dec 2020 17:42:45 +0100
|
|
|
5593c8 |
Subject: [PATCH] ieee1275: Avoiding many unecessary open/close
|
|
|
5593c8 |
|
|
|
5593c8 |
Signed-off-by: Diego Domingos <diegodo@br.ibm.com>
|
|
|
5593c8 |
---
|
|
|
5593c8 |
grub-core/disk/ieee1275/ofdisk.c | 64 ++++++++++++++++++++++------------------
|
|
|
5593c8 |
1 file changed, 35 insertions(+), 29 deletions(-)
|
|
|
5593c8 |
|
|
|
5593c8 |
diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
|
|
|
1c6ba0 |
index 03674cb477..ea7f78ac7d 100644
|
|
|
5593c8 |
--- a/grub-core/disk/ieee1275/ofdisk.c
|
|
|
5593c8 |
+++ b/grub-core/disk/ieee1275/ofdisk.c
|
|
|
5593c8 |
@@ -44,7 +44,7 @@ struct ofdisk_hash_ent
|
|
|
5593c8 |
};
|
|
|
5593c8 |
|
|
|
5593c8 |
static grub_err_t
|
|
|
5593c8 |
-grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size,
|
|
|
5593c8 |
+grub_ofdisk_get_block_size (grub_uint32_t *block_size,
|
|
|
5593c8 |
struct ofdisk_hash_ent *op);
|
|
|
5593c8 |
|
|
|
5593c8 |
#define OFDISK_HASH_SZ 8
|
|
|
5593c8 |
@@ -461,6 +461,7 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
|
|
|
5593c8 |
grub_ssize_t actual;
|
|
|
5593c8 |
grub_uint32_t block_size = 0;
|
|
|
5593c8 |
grub_err_t err;
|
|
|
5593c8 |
+ struct ofdisk_hash_ent *op;
|
|
|
5593c8 |
|
|
|
5593c8 |
if (grub_strncmp (name, "ieee1275/", sizeof ("ieee1275/") - 1) != 0)
|
|
|
5593c8 |
return grub_error (GRUB_ERR_UNKNOWN_DEVICE,
|
|
|
5593c8 |
@@ -471,6 +472,35 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
|
|
|
5593c8 |
|
|
|
5593c8 |
grub_dprintf ("disk", "Opening `%s'.\n", devpath);
|
|
|
5593c8 |
|
|
|
5593c8 |
+ op = ofdisk_hash_find (devpath);
|
|
|
5593c8 |
+ if (!op)
|
|
|
5593c8 |
+ op = ofdisk_hash_add (devpath, NULL);
|
|
|
5593c8 |
+ if (!op)
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ grub_free (devpath);
|
|
|
5593c8 |
+ return grub_errno;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ /* Check if the call to open is the same to the last disk already opened */
|
|
|
5593c8 |
+ if (last_devpath && !grub_strcmp(op->open_path,last_devpath))
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ goto finish;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ /* If not, we need to close the previous disk and open the new one */
|
|
|
5593c8 |
+ else {
|
|
|
5593c8 |
+ if (last_ihandle){
|
|
|
5593c8 |
+ grub_ieee1275_close (last_ihandle);
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+ last_ihandle = 0;
|
|
|
5593c8 |
+ last_devpath = NULL;
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ grub_ieee1275_open (op->open_path, &last_ihandle);
|
|
|
5593c8 |
+ if (! last_ihandle)
|
|
|
5593c8 |
+ return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
|
|
|
5593c8 |
+ last_devpath = op->open_path;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+
|
|
|
5593c8 |
if (grub_ieee1275_finddevice (devpath, &dev))
|
|
|
5593c8 |
{
|
|
|
5593c8 |
grub_free (devpath);
|
|
|
5593c8 |
@@ -491,25 +521,18 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
|
|
|
5593c8 |
return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a block device");
|
|
|
5593c8 |
}
|
|
|
5593c8 |
|
|
|
5593c8 |
+
|
|
|
5593c8 |
+ finish:
|
|
|
5593c8 |
/* XXX: There is no property to read the number of blocks. There
|
|
|
5593c8 |
should be a property `#blocks', but it is not there. Perhaps it
|
|
|
5593c8 |
is possible to use seek for this. */
|
|
|
5593c8 |
disk->total_sectors = GRUB_DISK_SIZE_UNKNOWN;
|
|
|
5593c8 |
|
|
|
5593c8 |
{
|
|
|
5593c8 |
- struct ofdisk_hash_ent *op;
|
|
|
5593c8 |
- op = ofdisk_hash_find (devpath);
|
|
|
5593c8 |
- if (!op)
|
|
|
5593c8 |
- op = ofdisk_hash_add (devpath, NULL);
|
|
|
5593c8 |
- if (!op)
|
|
|
5593c8 |
- {
|
|
|
5593c8 |
- grub_free (devpath);
|
|
|
5593c8 |
- return grub_errno;
|
|
|
5593c8 |
- }
|
|
|
5593c8 |
disk->id = (unsigned long) op;
|
|
|
5593c8 |
disk->data = op->open_path;
|
|
|
5593c8 |
|
|
|
5593c8 |
- err = grub_ofdisk_get_block_size (devpath, &block_size, op);
|
|
|
5593c8 |
+ err = grub_ofdisk_get_block_size (&block_size, op);
|
|
|
5593c8 |
if (err)
|
|
|
5593c8 |
{
|
|
|
5593c8 |
grub_free (devpath);
|
|
|
5593c8 |
@@ -532,13 +555,6 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
|
|
|
5593c8 |
static void
|
|
|
5593c8 |
grub_ofdisk_close (grub_disk_t disk)
|
|
|
5593c8 |
{
|
|
|
5593c8 |
- if (disk->data == last_devpath)
|
|
|
5593c8 |
- {
|
|
|
5593c8 |
- if (last_ihandle)
|
|
|
5593c8 |
- grub_ieee1275_close (last_ihandle);
|
|
|
5593c8 |
- last_ihandle = 0;
|
|
|
5593c8 |
- last_devpath = NULL;
|
|
|
5593c8 |
- }
|
|
|
5593c8 |
disk->data = 0;
|
|
|
5593c8 |
}
|
|
|
5593c8 |
|
|
|
5593c8 |
@@ -685,7 +701,7 @@ grub_ofdisk_init (void)
|
|
|
5593c8 |
}
|
|
|
5593c8 |
|
|
|
5593c8 |
static grub_err_t
|
|
|
5593c8 |
-grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size,
|
|
|
5593c8 |
+grub_ofdisk_get_block_size (grub_uint32_t *block_size,
|
|
|
5593c8 |
struct ofdisk_hash_ent *op)
|
|
|
5593c8 |
{
|
|
|
5593c8 |
struct size_args_ieee1275
|
|
|
5593c8 |
@@ -698,16 +714,6 @@ grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size,
|
|
|
5593c8 |
grub_ieee1275_cell_t size2;
|
|
|
5593c8 |
} args_ieee1275;
|
|
|
5593c8 |
|
|
|
5593c8 |
- if (last_ihandle)
|
|
|
5593c8 |
- grub_ieee1275_close (last_ihandle);
|
|
|
5593c8 |
-
|
|
|
5593c8 |
- last_ihandle = 0;
|
|
|
5593c8 |
- last_devpath = NULL;
|
|
|
5593c8 |
-
|
|
|
5593c8 |
- grub_ieee1275_open (device, &last_ihandle);
|
|
|
5593c8 |
- if (! last_ihandle)
|
|
|
5593c8 |
- return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
|
|
|
5593c8 |
-
|
|
|
5593c8 |
*block_size = 0;
|
|
|
5593c8 |
|
|
|
5593c8 |
if (op->block_size_fails >= 2)
|