dm-path-selector.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (C) 2003 Sistina Software.
  3. * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
  4. *
  5. * Module Author: Heinz Mauelshagen
  6. *
  7. * This file is released under the GPL.
  8. *
  9. * Path-Selector registration.
  10. */
  11. #ifndef DM_PATH_SELECTOR_H
  12. #define DM_PATH_SELECTOR_H
  13. #include <linux/device-mapper.h>
  14. #include "dm-mpath.h"
  15. /*
  16. * We provide an abstraction for the code that chooses which path
  17. * to send some io down.
  18. */
  19. struct path_selector_type;
  20. struct path_selector {
  21. struct path_selector_type *type;
  22. void *context;
  23. };
  24. /*
  25. * If a path selector uses this flag, a high resolution timer is used
  26. * (via ktime_get_ns) to account for IO start time in BIO-based mpath.
  27. * This improves performance of some path selectors (i.e. HST), in
  28. * exchange for slightly higher overhead when submitting the BIO.
  29. * The extra cost is usually offset by improved path selection for
  30. * some benchmarks.
  31. *
  32. * This has no effect for request-based mpath, since it already uses a
  33. * higher precision timer by default.
  34. */
  35. #define DM_PS_USE_HR_TIMER 0x00000001
  36. #define dm_ps_use_hr_timer(type) ((type)->features & DM_PS_USE_HR_TIMER)
  37. /* Information about a path selector type */
  38. struct path_selector_type {
  39. char *name;
  40. struct module *module;
  41. unsigned int features;
  42. unsigned int table_args;
  43. unsigned int info_args;
  44. /*
  45. * Constructs a path selector object, takes custom arguments
  46. */
  47. int (*create) (struct path_selector *ps, unsigned int argc, char **argv);
  48. void (*destroy) (struct path_selector *ps);
  49. /*
  50. * Add an opaque path object, along with some selector specific
  51. * path args (eg, path priority).
  52. */
  53. int (*add_path) (struct path_selector *ps, struct dm_path *path,
  54. int argc, char **argv, char **error);
  55. /*
  56. * Chooses a path for this io, if no paths are available then
  57. * NULL will be returned.
  58. */
  59. struct dm_path *(*select_path) (struct path_selector *ps,
  60. size_t nr_bytes);
  61. /*
  62. * Notify the selector that a path has failed.
  63. */
  64. void (*fail_path) (struct path_selector *ps, struct dm_path *p);
  65. /*
  66. * Ask selector to reinstate a path.
  67. */
  68. int (*reinstate_path) (struct path_selector *ps, struct dm_path *p);
  69. /*
  70. * Table content based on parameters added in ps_add_path_fn
  71. * or path selector status
  72. */
  73. int (*status) (struct path_selector *ps, struct dm_path *path,
  74. status_type_t type, char *result, unsigned int maxlen);
  75. int (*start_io) (struct path_selector *ps, struct dm_path *path,
  76. size_t nr_bytes);
  77. int (*end_io) (struct path_selector *ps, struct dm_path *path,
  78. size_t nr_bytes, u64 start_time);
  79. };
  80. /* Register a path selector */
  81. int dm_register_path_selector(struct path_selector_type *type);
  82. /* Unregister a path selector */
  83. int dm_unregister_path_selector(struct path_selector_type *type);
  84. /* Returns a registered path selector type */
  85. struct path_selector_type *dm_get_path_selector(const char *name);
  86. /* Releases a path selector */
  87. void dm_put_path_selector(struct path_selector_type *pst);
  88. #endif