All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Snowberg <eric.snowberg@oracle.com>
To: grub-devel@gnu.org
To: eric.snowberg@oracle.com
Cc: Eric Snowberg <eric.snowberg@oracle.com>
Subject: [PATCH 3/3] ieee1275: ofdisk - don't continue to query block-size after we have it
Date: Mon, 26 Oct 2015 17:43:38 -0400	[thread overview]
Message-ID: <0c372888b3d2eff761c27e1d133bd9858d0267f9.1445895272.git.eric.snowberg@oracle.com> (raw)
In-Reply-To: <1671671c705298f7d6e8c7e79805564b3b662548.1445895272.git.eric.snowberg@oracle.com>
In-Reply-To: <1671671c705298f7d6e8c7e79805564b3b662548.1445895272.git.eric.snowberg@oracle.com>

Within commit: 87ec3b7fa9061f470616ed927fc140e995831c00 - "Don't continue
to query block-size if disk doesn't have it.”  Disks that returned 0 to the
block-size query, still get queried every time.

Fix logic in grub_ofdisk_get_block_size so the block size is not requested
upon each open since it will not change.

Signed-off-by: Eric Snowberg <eric.snowberg@oracle.com>
---
 grub-core/disk/ieee1275/ofdisk.c |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
index 297f058..a75ea51 100644
--- a/grub-core/disk/ieee1275/ofdisk.c
+++ b/grub-core/disk/ieee1275/ofdisk.c
@@ -35,7 +35,8 @@ struct ofdisk_hash_ent
   char *grub_devpath;
   int is_boot;
   int is_removable;
-  int block_size_fails;
+  int block_size_retries;
+  grub_uint32_t block_size;
   /* Pointer to shortest available name on nodes representing canonical names,
      otherwise NULL.  */
   const char *shortest;
@@ -446,7 +447,17 @@ grub_ofdisk_open (const char *name, grub_disk_t disk)
       disk->log_sector_size = 9;
   }
 
+  if (last_ihandle)
+    grub_ieee1275_close (last_ihandle);
+
+  last_ihandle = 0;
+  last_devpath = NULL;
+  grub_ieee1275_open (devpath, &last_ihandle);
   grub_free (devpath);
+
+  if (! last_ihandle)
+    return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
+
   return 0;
 }
 
@@ -619,6 +630,12 @@ grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size,
       grub_ieee1275_cell_t size2;
     } args_ieee1275;
 
+  if ((op->block_size_retries >= 2) || (op->block_size > 0))
+    {
+      *block_size = op->block_size;
+      return GRUB_ERR_NONE;
+    }
+
   if (last_ihandle)
     grub_ieee1275_close (last_ihandle);
 
@@ -630,9 +647,7 @@ grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size,
     return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "can't open device");
 
   *block_size = 0;
-
-  if (op->block_size_fails >= 2)
-    return GRUB_ERR_NONE;
+  op->block_size_retries++;
 
   INIT_IEEE1275_COMMON (&args_ieee1275.common, "call-method", 2, 2);
   args_ieee1275.method = (grub_ieee1275_cell_t) "block-size";
@@ -642,21 +657,22 @@ grub_ofdisk_get_block_size (const char *device, grub_uint32_t *block_size,
   if (IEEE1275_CALL_ENTRY_FN (&args_ieee1275) == -1)
     {
       grub_dprintf ("disk", "can't get block size: failed call-method\n");
-      op->block_size_fails++;
     }
   else if (args_ieee1275.result)
     {
       grub_dprintf ("disk", "can't get block size: %lld\n",
 		    (long long) args_ieee1275.result);
-      op->block_size_fails++;
     }
   else if (args_ieee1275.size1
 	   && !(args_ieee1275.size1 & (args_ieee1275.size1 - 1))
 	   && args_ieee1275.size1 >= 512 && args_ieee1275.size1 <= 16384)
     {
-      op->block_size_fails = 0;
+      op->block_size = args_ieee1275.size1;
       *block_size = args_ieee1275.size1;
     }
 
+  grub_ieee1275_close (last_ihandle);
+  last_ihandle = 0;
+
   return 0;
 }
-- 
1.7.1



  parent reply	other threads:[~2015-10-26 21:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-26 21:43 [PATCH 1/3] ieee1275: ofdisk dangling pointer Eric Snowberg
2015-10-26 21:43 ` [PATCH 2/3] ieee1275: ofdisk memory leak Eric Snowberg
2015-10-26 22:03   ` Vladimir 'φ-coder/phcoder' Serbinenko
2015-10-26 21:43 ` Eric Snowberg [this message]
2015-10-26 22:02   ` [PATCH 3/3] ieee1275: ofdisk - don't continue to query block-size after we have it Vladimir 'φ-coder/phcoder' Serbinenko
2015-11-10  8:01     ` Andrei Borzenkov
2015-11-10 17:45       ` Eric Snowberg
2015-10-26 22:03 ` [PATCH 1/3] ieee1275: ofdisk dangling pointer Vladimir 'φ-coder/phcoder' Serbinenko
2015-10-29 14:48 ` Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0c372888b3d2eff761c27e1d133bd9858d0267f9.1445895272.git.eric.snowberg@oracle.com \
    --to=eric.snowberg@oracle.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.