Skip to contentSkip to conversation

ofdisk: add sas disks to the device list

PATCH Superseded Paulo Flabiano Smorigo 4 participants 5 messages Nov 9, 2015

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ofdisk: add sas disks to the device list

All SAS disks attached will be added to the device list. This is the second version of a patch that I send a while ago [1].

[1] https://lists.gnu.org/archive/html/grub-devel/2015-08/msg00000.html

---
 grub-core/disk/ieee1275/ofdisk.c | 76 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
grub-core/disk/ieee1275/ofdisk.c +76 -0
index 297f058..afec9ba 100644
@@ -260,6 +260,82 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
       grub_free (buf);
       return;
     }
+  else if (grub_strcmp (alias->type, "sas_ioa") == 0)
+    {
+      /* The method returns the number of disks and a table where
+       * each ID is 64-bit long. Example of sas paths:
+       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@c05db70800
+       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@a05db70800
+       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@805db70800 */
+
+      struct sas_children
+        {
+          struct grub_ieee1275_common_hdr common;
+          grub_ieee1275_cell_t method;
+          grub_ieee1275_cell_t ihandle;
+          grub_ieee1275_cell_t max;
+          grub_ieee1275_cell_t table;
+          grub_ieee1275_cell_t catch_result;
+          grub_ieee1275_cell_t nentries;
+        }
+      args;
+      char *buf, *bufptr, *table;
+      unsigned i;
+      grub_uint32_t table_size;
+      grub_ieee1275_ihandle_t ihandle;
+
+      buf = grub_malloc (grub_strlen (alias->path)
+                         + sizeof ("/disk@7766554433221100"));
+      if (!buf)
+        return;
+
+      /* 64 entries should be enough */
+      table_size = sizeof (grub_uint64_t) * 64;
+      table = grub_malloc (table_size);
+
+      if (!table)
+        {
+          grub_free (buf);
+          return;
+        }
+
+      bufptr = grub_stpcpy (buf, alias->path);
+
+      if (grub_ieee1275_open (alias->path, &ihandle))
+        {
+          grub_free (buf);
+          grub_free (table);
+          return;
+        }
+
+      INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2);
+      args.method = (grub_ieee1275_cell_t) "get-sas-children";
+      args.ihandle = ihandle;
+      args.max = table_size;
+      args.table = (grub_ieee1275_cell_t) table;
+      args.catch_result = 0;
+      args.nentries = 0;
+
+      if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
+        {
+          grub_ieee1275_close (ihandle);
+          grub_free (table);
+          grub_free (buf);
+          return;
+        }
+
+      grub_uint64_t *ptr;
+      for (i = 0; i < args.nentries; i++)
+        {
+          ptr = (grub_uint64_t *) (table + sizeof (grub_uint64_t) * i);
+          grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, *ptr);
+          dev_iterate_real (buf, buf);
+        }
+
+      grub_ieee1275_close (ihandle);
+      grub_free (table);
+      grub_free (buf);
+    }
 
   if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)
       && grub_strcmp (alias->type, "block") == 0)
Signature · 1 line
2.1.0
#1 lore raw

09.11.2015 04:29, Paulo Flabiano Smorigo пишет:

Quoted 14 lines

All SAS disks attached will be added to the device list. This is the second version of a patch that I send a while ago [1].

[1] https://lists.gnu.org/archive/html/grub-devel/2015-08/msg00000.html

---
  grub-core/disk/ieee1275/ofdisk.c | 76 ++++++++++++++++++++++++++++++++++++++++
  1 file changed, 76 insertions(+)
grub-core/disk/ieee1275/ofdisk.c +0 -0
index 297f058..afec9ba 100644

grub-core/disk/ieee1275/ofdisk.c dev_iterate (const struct grub_ieee1275_devalias *alias) · line 269

Quoted 10 lines
grub-core/disk/ieee1275/ofdisk.c +7 -0
@@ -260,6 +260,82 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
        grub_free (buf);
        return;
      }
+  else if (grub_strcmp (alias->type, "sas_ioa") == 0)
+    {
+      /* The method returns the number of disks and a table where
+       * each ID is 64-bit long. Example of sas paths:
+       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@c05db70800
+       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@a05db70800
+       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@805db70800 */

Did you omit last 3 bytes on purpose?

Out of curiosity - is it really true that SAS address is written backwards (at least, I assume this is SAS address)?

Quoted 73 lines
grub-core/disk/ieee1275/ofdisk.c +69 -0
+
+      struct sas_children
+        {
+          struct grub_ieee1275_common_hdr common;
+          grub_ieee1275_cell_t method;
+          grub_ieee1275_cell_t ihandle;
+          grub_ieee1275_cell_t max;
+          grub_ieee1275_cell_t table;
+          grub_ieee1275_cell_t catch_result;
+          grub_ieee1275_cell_t nentries;
+        }
+      args;
+      char *buf, *bufptr, *table;
+      unsigned i;
+      grub_uint32_t table_size;
+      grub_ieee1275_ihandle_t ihandle;
+
+      buf = grub_malloc (grub_strlen (alias->path)
+                         + sizeof ("/disk@7766554433221100"));
+      if (!buf)
+        return;
+
+      /* 64 entries should be enough */
+      table_size = sizeof (grub_uint64_t) * 64;
+      table = grub_malloc (table_size);
+
+      if (!table)
+        {
+          grub_free (buf);
+          return;
+        }
+
+      bufptr = grub_stpcpy (buf, alias->path);
+
+      if (grub_ieee1275_open (alias->path, &ihandle))
+        {
+          grub_free (buf);
+          grub_free (table);
+          return;
+        }
+
+      INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2);
+      args.method = (grub_ieee1275_cell_t) "get-sas-children";
+      args.ihandle = ihandle;
+      args.max = table_size;
+      args.table = (grub_ieee1275_cell_t) table;
+      args.catch_result = 0;
+      args.nentries = 0;
+
+      if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
+        {
+          grub_ieee1275_close (ihandle);
+          grub_free (table);
+          grub_free (buf);
+          return;
+        }
+
+      grub_uint64_t *ptr;
+      for (i = 0; i < args.nentries; i++)
+        {
+          ptr = (grub_uint64_t *) (table + sizeof (grub_uint64_t) * i);
+          grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, *ptr);
+          dev_iterate_real (buf, buf);
+        }
+
+      grub_ieee1275_close (ihandle);
+      grub_free (table);
+      grub_free (buf);
+    }
 
    if (!grub_ieee1275_test_flag (GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)
        && grub_strcmp (alias->type, "block") == 0)
#2 lore raw
Quoted 34 lines · Andrei Borzenkov

09.11.2015 04:29, Paulo Flabiano Smorigo пишет:

Quoted 19 lines

All SAS disks attached will be added to the device list. This is the second
version of a patch that I send a while ago [1].

[1] https://lists.gnu.org/archive/html/grub-devel/2015-08/msg00000.html

---
  grub-core/disk/ieee1275/ofdisk.c | 76
++++++++++++++++++++++++++++++++++++++++
  1 file changed, 76 insertions(+)
grub-core/disk/ieee1275/ofdisk.c +0 -0
index 297f058..afec9ba 100644
@@ -260,6 +260,82 @@ dev_iterate (const struct grub_ieee1275_devalias
 *alias)

grub-core/disk/ieee1275/ofdisk.c dev_iterate (const struct grub_ieee1275_devalias · line 270

Quoted 10 lines
grub-core/disk/ieee1275/ofdisk.c +7 -0
        grub_free (buf);
        return;
      }
+  else if (grub_strcmp (alias->type, "sas_ioa") == 0)
+    {
+      /* The method returns the number of disks and a table where
+       * each ID is 64-bit long. Example of sas paths:
+       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@c05db70800
+       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@a05db70800
+       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@805db70800 */

Did you omit last 3 bytes on purpose?

Quoted 2 lines

Out of curiosity - is it really true that SAS address is written backwards (at least, I assume this is SAS address)?

The 3 missing bytes are leading zeros that it's not used in the path.

This is the table that I got:

000000 00 00 00 c0 5d b7 08 00 00 00 00 a0 5d b7 08 00 000010 00 00 00 80 5d b7 08 00 00 00 00 60 5d b7 08 00 000020 00 00 00 40 5d b7 08 00 00 00 00 20 5d b7 08 00 000030 50 05 07 60 64 79 f9 01 00 00 00 00 00 00 00 00 000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
...

It's not backwards, each address has a space between them. It's exactly 128GB:

Quoted 1 line

grub-core/disk/ieee1275/ofdisk.c dev_iterate (const struct grub_ieee1275_devalias · line 271

Quoted 1 line
grub-core/disk/ieee1275/ofdisk.c +0 -0
 > (0xc05db70800-0xa05db70800)/(1024.**3)

128.0

Quoted 82 lines
Quoted 72 lines
grub-core/disk/ieee1275/ofdisk.c +69 -0
+
+      struct sas_children
+        {
+          struct grub_ieee1275_common_hdr common;
+          grub_ieee1275_cell_t method;
+          grub_ieee1275_cell_t ihandle;
+          grub_ieee1275_cell_t max;
+          grub_ieee1275_cell_t table;
+          grub_ieee1275_cell_t catch_result;
+          grub_ieee1275_cell_t nentries;
+        }
+      args;
+      char *buf, *bufptr, *table;
+      unsigned i;
+      grub_uint32_t table_size;
+      grub_ieee1275_ihandle_t ihandle;
+
+      buf = grub_malloc (grub_strlen (alias->path)
+                         + sizeof ("/disk@7766554433221100"));
+      if (!buf)
+        return;
+
+      /* 64 entries should be enough */
+      table_size = sizeof (grub_uint64_t) * 64;
+      table = grub_malloc (table_size);
+
+      if (!table)
+        {
+          grub_free (buf);
+          return;
+        }
+
+      bufptr = grub_stpcpy (buf, alias->path);
+
+      if (grub_ieee1275_open (alias->path, &ihandle))
+        {
+          grub_free (buf);
+          grub_free (table);
+          return;
+        }
+
+      INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2);
+      args.method = (grub_ieee1275_cell_t) "get-sas-children";
+      args.ihandle = ihandle;
+      args.max = table_size;
+      args.table = (grub_ieee1275_cell_t) table;
+      args.catch_result = 0;
+      args.nentries = 0;
+
+      if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
+        {
+          grub_ieee1275_close (ihandle);
+          grub_free (table);
+          grub_free (buf);
+          return;
+        }
+
+      grub_uint64_t *ptr;
+      for (i = 0; i < args.nentries; i++)
+        {
+          ptr = (grub_uint64_t *) (table + sizeof (grub_uint64_t) * i);
+          grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, *ptr);
+          dev_iterate_real (buf, buf);
+        }
+
+      grub_ieee1275_close (ihandle);
+      grub_free (table);
+      grub_free (buf);
+    }
 
Quoted 4 lines
    if (!grub_ieee1275_test_flag
(GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)
        && grub_strcmp (alias->type, "block") == 0)

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#3 lore raw
In reply to Paulo Flabiano Smorigo
Quoted 2 lines · Paulo Flabiano Smorigo

All SAS disks attached will be added to the device list. This is the

second

Quoted 6 lines

version of a patch that I send a while ago [1].

[1] https://lists.gnu.org/archive/html/grub-devel/2015-08/msg00000.html

---
 grub-core/disk/ieee1275/ofdisk.c | 76

++++++++++++++++++++++++++++++++++++++++

Review

Quoted 3 lines
 1 file changed, 76 insertions(+)
(quoted diff) +0 -0

b/grub-core/disk/ieee1275/ofdisk.c

grub-core/disk/ieee1275/ofdisk.c dev_iterate (const struct grub_ieee1275_devalias

Quoted 4 lines

index 297f058..afec9ba 100644

grub-core/disk/ieee1275/ofdisk.c +0 -0
@@ -260,6 +260,82 @@ dev_iterate (const struct grub_ieee1275_devalias

*alias)

Quoted 23 lines
grub-core/disk/ieee1275/ofdisk.c +20 -0
       grub_free (buf);
       return;
     }
+  else if (grub_strcmp (alias->type, "sas_ioa") == 0)
+    {
+      /* The method returns the number of disks and a table where
+       * each ID is 64-bit long. Example of sas paths:
+       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@c05db70800
+       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@a05db70800
+       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@805db70800 */
+
+      struct sas_children
+        {
+          struct grub_ieee1275_common_hdr common;
+          grub_ieee1275_cell_t method;
+          grub_ieee1275_cell_t ihandle;
+          grub_ieee1275_cell_t max;
+          grub_ieee1275_cell_t table;
+          grub_ieee1275_cell_t catch_result;
+          grub_ieee1275_cell_t nentries;
+        }
+      args;
+      char *buf, *bufptr, *table;

grub-core/disk/ieee1275/ofdisk.c dev_iterate (const struct grub_ieee1275_devalias *alias) · line 292

Quoted 10 lines
grub-core/disk/ieee1275/ofdisk.c +10 -0
+      unsigned i;
+      grub_uint32_t table_size;
+      grub_ieee1275_ihandle_t ihandle;
+
+      buf = grub_malloc (grub_strlen (alias->path)
+                         + sizeof ("/disk@7766554433221100"));
+      if (!buf)
+        return;
+
+      /* 64 entries should be enough */

Why? Sounds like an arbitrary limit. What does OF call return when it's not true? Does it set nentries to total or to how much it has really provided?

Quoted 12 lines
grub-core/disk/ieee1275/ofdisk.c +12 -0
+      table_size = sizeof (grub_uint64_t) * 64;
+      table = grub_malloc (table_size);
+
+      if (!table)
+        {
+          grub_free (buf);
+          return;
+        }
+
+      bufptr = grub_stpcpy (buf, alias->path);
+
+      if (grub_ieee1275_open (alias->path, &ihandle))

grub-core/disk/ieee1275/ofdisk.c dev_iterate (const struct grub_ieee1275_devalias *alias) · line 314

Quoted 10 lines
grub-core/disk/ieee1275/ofdisk.c +10 -0
+        {
+          grub_free (buf);
+          grub_free (table);
+          return;
+        }
+
+      INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2);
+      args.method = (grub_ieee1275_cell_t) "get-sas-children";
+      args.ihandle = ihandle;
+      args.max = table_size;

Please double check that this field is in bytes.

Quoted 7 lines
grub-core/disk/ieee1275/ofdisk.c +7 -0
+      args.table = (grub_ieee1275_cell_t) table;
+      args.catch_result = 0;
+      args.nentries = 0;
+
+      if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
+        {
+          grub_ieee1275_close (ihandle);

grub-core/disk/ieee1275/ofdisk.c dev_iterate (const struct grub_ieee1275_devalias *alias) · line 331

Quoted 10 lines
grub-core/disk/ieee1275/ofdisk.c +10 -0
+          grub_free (table);
+          grub_free (buf);
+          return;
+        }
+
+      grub_uint64_t *ptr;
+      for (i = 0; i < args.nentries; i++)
+        {
+          ptr = (grub_uint64_t *) (table + sizeof (grub_uint64_t) * i);
+          grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, *ptr);

This 32 doesn't match the above allocation.

grub-core/disk/ieee1275/ofdisk.c dev_iterate (const struct grub_ieee1275_devalias *alias)

Quoted 9 lines
grub-core/disk/ieee1275/ofdisk.c +7 -0
+          dev_iterate_real (buf, buf);
+        }
+
+      grub_ieee1275_close (ihandle);
+      grub_free (table);
+      grub_free (buf);
+    }
 
   if (!grub_ieee1275_test_flag

(GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)

Quoted 9 lines
grub-core/disk/ieee1275/ofdisk.c +0 -1
       && grub_strcmp (alias->type, "block") == 0)
--

2.1.0

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#4 lore raw
Quoted 49 lines · Vladimir 'phcoder' Serbinenko
Quoted 46 lines · Paulo Flabiano Smorigo

All SAS disks attached will be added to the device list. This is the second
version of a patch that I send a while ago [1].

[1] https://lists.gnu.org/archive/html/grub-devel/2015-08/msg00000.html

---
 grub-core/disk/ieee1275/ofdisk.c | 76
++++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
grub-core/disk/ieee1275/ofdisk.c +24 -0
index 297f058..afec9ba 100644
@@ -260,6 +260,82 @@ dev_iterate (const struct grub_ieee1275_devalias
 *alias)
       grub_free (buf);
       return;
     }
+  else if (grub_strcmp (alias->type, "sas_ioa") == 0)
+    {
+      /* The method returns the number of disks and a table where
+       * each ID is 64-bit long. Example of sas paths:
+       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@c05db70800
+       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@a05db70800
+       *  /pci@80000002000001f/pci1014,034A@0/sas/disk@805db70800 */
+
+      struct sas_children
+        {
+          struct grub_ieee1275_common_hdr common;
+          grub_ieee1275_cell_t method;
+          grub_ieee1275_cell_t ihandle;
+          grub_ieee1275_cell_t max;
+          grub_ieee1275_cell_t table;
+          grub_ieee1275_cell_t catch_result;
+          grub_ieee1275_cell_t nentries;
+        }
+      args;
+      char *buf, *bufptr, *table;
+      unsigned i;
+      grub_uint32_t table_size;
+      grub_ieee1275_ihandle_t ihandle;
+
Quoted 8 lines

grub-core/disk/ieee1275/ofdisk.c dev_iterate (const struct grub_ieee1275_devalias *alias) · line 292

Quoted 6 lines
grub-core/disk/ieee1275/ofdisk.c +6 -0
+      buf = grub_malloc (grub_strlen (alias->path)
+                         + sizeof ("/disk@7766554433221100"));
+      if (!buf)
+        return;
+
+      /* 64 entries should be enough */

Why? Sounds like an arbitrary limit. What does OF call return when it's not true? Does it set nentries to total or to how much it has really provided?

Asked the Open firmware development team...

The maximum value for max is 0xffff but this is a very high number IMHO.

About the limit, if there are more entries than will fit in the buffer provided, you will only get up to that number. The return value is the number in the buffer.

I tested here using max = 4 and nentries was 4. The table only had 4 entries as well.

Quoted 15 lines
Quoted 15 lines
grub-core/disk/ieee1275/ofdisk.c +15 -0
+      table_size = sizeof (grub_uint64_t) * 64;
+      table = grub_malloc (table_size);
+
+      if (!table)
+        {
+          grub_free (buf);
+          return;
+        }
+
+      bufptr = grub_stpcpy (buf, alias->path);
+
+      if (grub_ieee1275_open (alias->path, &ihandle))
+        {
+          grub_free (buf);
+          grub_free (table);
Quoted 8 lines

grub-core/disk/ieee1275/ofdisk.c dev_iterate (const struct grub_ieee1275_devalias *alias) · line 314

Quoted 7 lines
grub-core/disk/ieee1275/ofdisk.c +7 -0
+          return;
+        }
+
+      INIT_IEEE1275_COMMON (&args.common, "call-method", 4, 2);
+      args.method = (grub_ieee1275_cell_t) "get-sas-children";
+      args.ihandle = ihandle;
+      args.max = table_size;

Please double check that this field is in bytes.

My fault. it's entries, not bytes. Will fix it.

Quoted 10 lines
Quoted 10 lines
grub-core/disk/ieee1275/ofdisk.c +10 -0
+      args.table = (grub_ieee1275_cell_t) table;
+      args.catch_result = 0;
+      args.nentries = 0;
+
+      if (IEEE1275_CALL_ENTRY_FN (&args) == -1)
+        {
+          grub_ieee1275_close (ihandle);
+          grub_free (table);
+          grub_free (buf);
+          return;
Quoted 8 lines

grub-core/disk/ieee1275/ofdisk.c dev_iterate (const struct grub_ieee1275_devalias *alias) · line 331

Quoted 7 lines
grub-core/disk/ieee1275/ofdisk.c +7 -0
+        }
+
+      grub_uint64_t *ptr;
+      for (i = 0; i < args.nentries; i++)
+        {
+          ptr = (grub_uint64_t *) (table + sizeof (grub_uint64_t) * i);
+          grub_snprintf (bufptr, 32, "/disk@%" PRIxGRUB_UINT64_T, *ptr);

This 32 doesn't match the above allocation.

Ok.

Quoted 26 lines
Quoted 11 lines
grub-core/disk/ieee1275/ofdisk.c +7 -0
+          dev_iterate_real (buf, buf);
+        }
+
+      grub_ieee1275_close (ihandle);
+      grub_free (table);
+      grub_free (buf);
+    }
 
   if (!grub_ieee1275_test_flag

(GRUB_IEEE1275_FLAG_NO_TREE_SCANNING_FOR_DISKS)

       && grub_strcmp (alias->type, "block") == 0)
Quoted 8 lines

--
2.1.0

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel