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