tidy up get_hibernate_io_function

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

tidy up get_hibernate_io_function

Jonathan Matthew-4
It's hard to see exactly what the dv->dv_parent->etc. checks are doing.
Before adding sdmmc I'd like to tidy up a bit.

ok?

Index: arch/amd64/amd64/hibernate_machdep.c
===================================================================
RCS file: /cvs/src/sys/arch/amd64/amd64/hibernate_machdep.c,v
retrieving revision 1.39
diff -u -p -u -p -r1.39 hibernate_machdep.c
--- arch/amd64/amd64/hibernate_machdep.c 29 May 2017 12:58:37 -0000 1.39
+++ arch/amd64/amd64/hibernate_machdep.c 10 Feb 2018 04:37:14 -0000
@@ -95,26 +95,32 @@ get_hibernate_io_function(dev_t dev)
  extern int sr_hibernate_io(dev_t dev, daddr_t blkno,
     vaddr_t addr, size_t size, int op, void *page);
  struct device *dv = disk_lookup(&sd_cd, DISKUNIT(dev));
-
+ struct {
+ const char *driver;
+ hibio_fn io_func;
+ } sd_io_funcs[] = {
 #if NAHCI > 0
- if (dv && dv->dv_parent && dv->dv_parent->dv_parent &&
-    strcmp(dv->dv_parent->dv_parent->dv_cfdata->cf_driver->cd_name,
-    "ahci") == 0)
- return ahci_hibernate_io;
+ { "ahci", ahci_hibernate_io },
 #endif
 #if NNVME > 0
- if (dv && dv->dv_parent && dv->dv_parent->dv_parent &&
-    strcmp(dv->dv_parent->dv_parent->dv_cfdata->cf_driver->cd_name,
-    "nvme") == 0)
- return nvme_hibernate_io;
+ { "nvme", nvme_hibernate_io },
 #endif
 #if NSOFTRAID > 0
- if (dv && dv->dv_parent && dv->dv_parent->dv_parent &&
-    strcmp(dv->dv_parent->dv_parent->dv_cfdata->cf_driver->cd_name,
-    "softraid") == 0)
- return sr_hibernate_io;
- }
+ { "softraid", sr_hibernate_io },
 #endif
+ };
+
+ if (dv && dv->dv_parent && dv->dv_parent->dv_parent) {
+ const char *driver = dv->dv_parent->dv_parent->dv_cfdata->
+    cf_driver->cd_name;
+ int i;
+
+ for (i = 0; i < nitems(sd_io_funcs); i++) {
+ if (strcmp(driver, sd_io_funcs[i].driver) == 0)
+ return sd_io_funcs[i].io_func;
+ }
+ }
+ }
 #endif /* NSD > 0 */
  return NULL;
 }
Index: arch/i386/i386/hibernate_machdep.c
===================================================================
RCS file: /cvs/src/sys/arch/i386/i386/hibernate_machdep.c,v
retrieving revision 1.49
diff -u -p -u -p -r1.49 hibernate_machdep.c
--- arch/i386/i386/hibernate_machdep.c 20 May 2016 02:30:41 -0000 1.49
+++ arch/i386/i386/hibernate_machdep.c 10 Feb 2018 04:37:14 -0000
@@ -98,20 +98,29 @@ get_hibernate_io_function(dev_t dev)
  extern int sr_hibernate_io(dev_t dev, daddr_t blkno,
     vaddr_t addr, size_t size, int op, void *page);
  struct device *dv = disk_lookup(&sd_cd, DISKUNIT(dev));
-
+ struct {
+ const char *driver;
+ hibio_fn io_func;
+ } sd_io_funcs[] = {
 #if NAHCI > 0
- if (dv && dv->dv_parent && dv->dv_parent->dv_parent &&
-    strcmp(dv->dv_parent->dv_parent->dv_cfdata->cf_driver->cd_name,
-    "ahci") == 0)
- return ahci_hibernate_io;
+ { "ahci", ahci_hibernate_io },
 #endif
 #if NSOFTRAID > 0
- if (dv && dv->dv_parent && dv->dv_parent->dv_parent &&
-    strcmp(dv->dv_parent->dv_parent->dv_cfdata->cf_driver->cd_name,
-    "softraid") == 0)
- return sr_hibernate_io;
- }
+ { "softraid", sr_hibernate_io },
 #endif
+ };
+
+ if (dv && dv->dv_parent && dv->dv_parent->dv_parent) {
+ const char *driver = dv->dv_parent->dv_parent->dv_cfdata->
+    cf_driver->cd_name;
+ int i;
+
+ for (i = 0; i < nitems(sd_io_funcs); i++) {
+ if (strcmp(driver, sd_io_funcs[i].driver) == 0)
+ return sd_io_funcs[i].io_func;
+ }
+ }
+ }
 #endif /* NSD > 0 */
  return NULL;
 }

Reply | Threaded
Open this post in threaded view
|

Re: tidy up get_hibernate_io_function

Mike Larkin
On Sat, Feb 10, 2018 at 02:51:55PM +1000, Jonathan Matthew wrote:
> It's hard to see exactly what the dv->dv_parent->etc. checks are doing.
> Before adding sdmmc I'd like to tidy up a bit.
>
> ok?
>

Reads ok to me, and thanks for the cleanup. ok mlarkin if you didn't
already commit this.

> Index: arch/amd64/amd64/hibernate_machdep.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/amd64/amd64/hibernate_machdep.c,v
> retrieving revision 1.39
> diff -u -p -u -p -r1.39 hibernate_machdep.c
> --- arch/amd64/amd64/hibernate_machdep.c 29 May 2017 12:58:37 -0000 1.39
> +++ arch/amd64/amd64/hibernate_machdep.c 10 Feb 2018 04:37:14 -0000
> @@ -95,26 +95,32 @@ get_hibernate_io_function(dev_t dev)
>   extern int sr_hibernate_io(dev_t dev, daddr_t blkno,
>      vaddr_t addr, size_t size, int op, void *page);
>   struct device *dv = disk_lookup(&sd_cd, DISKUNIT(dev));
> -
> + struct {
> + const char *driver;
> + hibio_fn io_func;
> + } sd_io_funcs[] = {
>  #if NAHCI > 0
> - if (dv && dv->dv_parent && dv->dv_parent->dv_parent &&
> -    strcmp(dv->dv_parent->dv_parent->dv_cfdata->cf_driver->cd_name,
> -    "ahci") == 0)
> - return ahci_hibernate_io;
> + { "ahci", ahci_hibernate_io },
>  #endif
>  #if NNVME > 0
> - if (dv && dv->dv_parent && dv->dv_parent->dv_parent &&
> -    strcmp(dv->dv_parent->dv_parent->dv_cfdata->cf_driver->cd_name,
> -    "nvme") == 0)
> - return nvme_hibernate_io;
> + { "nvme", nvme_hibernate_io },
>  #endif
>  #if NSOFTRAID > 0
> - if (dv && dv->dv_parent && dv->dv_parent->dv_parent &&
> -    strcmp(dv->dv_parent->dv_parent->dv_cfdata->cf_driver->cd_name,
> -    "softraid") == 0)
> - return sr_hibernate_io;
> - }
> + { "softraid", sr_hibernate_io },
>  #endif
> + };
> +
> + if (dv && dv->dv_parent && dv->dv_parent->dv_parent) {
> + const char *driver = dv->dv_parent->dv_parent->dv_cfdata->
> +    cf_driver->cd_name;
> + int i;
> +
> + for (i = 0; i < nitems(sd_io_funcs); i++) {
> + if (strcmp(driver, sd_io_funcs[i].driver) == 0)
> + return sd_io_funcs[i].io_func;
> + }
> + }
> + }
>  #endif /* NSD > 0 */
>   return NULL;
>  }
> Index: arch/i386/i386/hibernate_machdep.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/i386/i386/hibernate_machdep.c,v
> retrieving revision 1.49
> diff -u -p -u -p -r1.49 hibernate_machdep.c
> --- arch/i386/i386/hibernate_machdep.c 20 May 2016 02:30:41 -0000 1.49
> +++ arch/i386/i386/hibernate_machdep.c 10 Feb 2018 04:37:14 -0000
> @@ -98,20 +98,29 @@ get_hibernate_io_function(dev_t dev)
>   extern int sr_hibernate_io(dev_t dev, daddr_t blkno,
>      vaddr_t addr, size_t size, int op, void *page);
>   struct device *dv = disk_lookup(&sd_cd, DISKUNIT(dev));
> -
> + struct {
> + const char *driver;
> + hibio_fn io_func;
> + } sd_io_funcs[] = {
>  #if NAHCI > 0
> - if (dv && dv->dv_parent && dv->dv_parent->dv_parent &&
> -    strcmp(dv->dv_parent->dv_parent->dv_cfdata->cf_driver->cd_name,
> -    "ahci") == 0)
> - return ahci_hibernate_io;
> + { "ahci", ahci_hibernate_io },
>  #endif
>  #if NSOFTRAID > 0
> - if (dv && dv->dv_parent && dv->dv_parent->dv_parent &&
> -    strcmp(dv->dv_parent->dv_parent->dv_cfdata->cf_driver->cd_name,
> -    "softraid") == 0)
> - return sr_hibernate_io;
> - }
> + { "softraid", sr_hibernate_io },
>  #endif
> + };
> +
> + if (dv && dv->dv_parent && dv->dv_parent->dv_parent) {
> + const char *driver = dv->dv_parent->dv_parent->dv_cfdata->
> +    cf_driver->cd_name;
> + int i;
> +
> + for (i = 0; i < nitems(sd_io_funcs); i++) {
> + if (strcmp(driver, sd_io_funcs[i].driver) == 0)
> + return sd_io_funcs[i].io_func;
> + }
> + }
> + }
>  #endif /* NSD > 0 */
>   return NULL;
>  }
>