dm-path-selector.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2003 Sistina Software.
  4. * Copyright (C) 2004 Red Hat, Inc. All rights reserved.
  5. *
  6. * Module Author: Heinz Mauelshagen
  7. *
  8. * This file is released under the GPL.
  9. *
  10. * Path-Selector registration.
  11. */
  12. #ifndef DM_PATH_SELECTOR_H
  13. #define DM_PATH_SELECTOR_H
  14. #include <linux/device-mapper.h>
  15. #include "dm-mpath.h"
  16. /*
  17. * We provide an abstraction for the code that chooses which path
  18. * to send some io down.
  19. */
  20. struct path_selector_type;
  21. struct path_selector {
  22. struct path_selector_type *type;
  23. void *context;
  24. };
  25. /*
  26. * If a path selector uses this flag, a high resolution timer is used
  27. * (via ktime_get_ns) to account for IO start time in BIO-based mpath.
  28. * This improves performance of some path selectors (i.e. HST), in
  29. * exchange for slightly higher overhead when submitting the BIO.
  30. * The extra cost is usually offset by improved path selection for
  31. * some benchmarks.
  32. *
  33. * This has no effect for request-based mpath, since it already uses a
  34. * higher precision timer by default.
  35. */
  36. #define DM_PS_USE_HR_TIMER 0x00000001
  37. #define dm_ps_use_hr_timer(type) ((type)->features & DM_PS_USE_HR_TIMER)
  38. /* Information about a path selector type */
  39. struct path_selector_type {
  40. char *name;
  41. struct module *module;
  42. unsigned int features;
  43. unsigned int table_args;
  44. unsigned int info_args;
  45. /*
  46. * Constructs a path selector object, takes custom arguments
  47. */
  48. int (*create)(struct path_selector *ps, unsigned int argc, char **argv);
  49. void (*destroy)(struct path_selector *ps);
  50. /*
  51. * Add an opaque path object, along with some selector specific
  52. * path args (eg, path priority).
  53. */
  54. int (*add_path)(struct path_selector *ps, struct dm_path *path,
  55. int argc, char **argv, char **error);
  56. /*
  57. * Chooses a path for this io, if no paths are available then
  58. * NULL will be returned.
  59. */
  60. struct dm_path *(*select_path)(struct path_selector *ps, 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