ofdisk: add sas disks to the device list
PATCH v4 1/1 ofdisk: add sas disks to the device list
Same patch with the fix.
--- grub-core/disk/ieee1275/ofdisk.c | 75 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)
grub-core/disk/ieee1275/ofdisk.c +75 -0
@@ -260,6 +260,81 @@ 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_uint16_t table_size; +grub_ieee1275_ihandle_t ihandle; + + buf =grub_malloc (grub_strlen (alias->path) +32 ); +if (!buf) +return ; + bufptr =grub_stpcpy (buf, alias->path); + +/* Power machines documentation specify 672 as maximum SAS disks in +one system. Using a slightly larger value to be safe. */ + table_size =768 ; + table =grub_malloc (table_size *sizeof (grub_uint64_t)); + +if (!table) + { +grub_free (buf); +return ; + } + +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
11.11.2015 16:14, Paulo Flabiano Smorigo пишет:
Quoted 28 lines
Same patch with the fix.
--- grub-core/disk/ieee1275/ofdisk.c | 75 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)grub-core/disk/ieee1275/ofdisk.c +15
-0@@ -260,6 +260,81 @@ 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-core/disk/ieee1275/ofdisk.c dev_iterate (const struct grub_ieee1275_devalias *alias) · line 287
Quoted 10 lines
grub-core/disk/ieee1275/ofdisk.c +10
-0+grub_ieee1275_cell_t catch_result; +grub_ieee1275_cell_t nentries; + } + args; +char *buf, *bufptr, *table; +unsigned i; +grub_uint16_t table_size; +grub_ieee1275_ihandle_t ihandle; + + buf =grub_malloc (grub_strlen (alias->path) +32 );
Actually I liked previous version more :) Magic hidden constants are always error prone.
Quoted 33 lines
grub-core/disk/ieee1275/ofdisk.c +33
-0+if (!buf) +return ; + bufptr =grub_stpcpy (buf, alias->path); + +/* Power machines documentation specify 672 as maximum SAS disks in +one system. Using a slightly larger value to be safe. */ + table_size =768 ; + table =grub_malloc (table_size *sizeof (grub_uint64_t)); + +if (!table) + { +grub_free (buf); +return ; + } + +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-core/disk/ieee1275/ofdisk.c dev_iterate (const struct grub_ieee1275_devalias *alias) · line 330
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);
What about
grub_snprintf (bufptr, sizeof ("/disk@7766554433221100"), ... )
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 )
Yes, that could be an option. phcoder, can I commit using andrei's approach? --
P. F. Smorigo
Quoted 116 lines · Andrei Borzenkov
11.11.2015 16:14, Paulo Flabiano Smorigo пишет:
Quoted 31 lines
Same patch with the fix.
--- grub-core/disk/ieee1275/ofdisk.c | 75 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+)grub-core/disk/ieee1275/ofdisk.c +15
-0@@ -260,6 +260,81 @@ 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-core/disk/ieee1275/ofdisk.c dev_iterate (const struct grub_ieee1275_devalias · line 288
Quoted 10 lines
grub-core/disk/ieee1275/ofdisk.c +10
-0+grub_ieee1275_cell_t catch_result; +grub_ieee1275_cell_t nentries; + } + args; +char *buf, *bufptr, *table; +unsigned i; +grub_uint16_t table_size; +grub_ieee1275_ihandle_t ihandle; + + buf =grub_malloc (grub_strlen (alias->path) +32 );Actually I liked previous version more :) Magic hidden constants are always error prone.
Quoted 33 lines
grub-core/disk/ieee1275/ofdisk.c +33
-0+if (!buf) +return ; + bufptr =grub_stpcpy (buf, alias->path); + +/* Power machines documentation specify 672 as maximum SAS disks in +one system. Using a slightly larger value to be safe. */ + table_size =768 ; + table =grub_malloc (table_size *sizeof (grub_uint64_t)); + +if (!table) + { +grub_free (buf); +return ; + } + +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-core/disk/ieee1275/ofdisk.c dev_iterate (const struct grub_ieee1275_devalias *alias) · line 330
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);What about
grub_snprintf(bufptr, sizeof ("/disk@7766554433221100"), ... )Quoted 10 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 2 lines
&& grub_strcmp (alias->type, "block") == 0)_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
grub-core/disk/ieee1275/ofdisk.c dev_iterate (const struct grub_ieee1275_devalias *alias) · line 330
Quoted 2 lines · Paulo Flabiano Smorigo
grub-core/disk/ieee1275/ofdisk.c +2
-0+ ptr = (grub_uint64_t *) (table +sizeof (grub_uint64_t) * i); +grub_snprintf (bufptr,32 ,"/disk@%" PRIxGRUB_UINT64_T, *ptr);
Please declare table as being grub_uint64_t * and then just use table[i]. This code violates cast-align