nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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