dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0325-ieee1275-Avoiding-many-unecessary-open-close.patch

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