dm-cache-background-tracker.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (C) 2017 Red Hat. All rights reserved.
  3. *
  4. * This file is released under the GPL.
  5. */
  6. #ifndef DM_CACHE_BACKGROUND_WORK_H
  7. #define DM_CACHE_BACKGROUND_WORK_H
  8. #include <linux/vmalloc.h>
  9. #include "dm-cache-policy.h"
  10. /*----------------------------------------------------------------*/
  11. /*
  12. * The cache policy decides what background work should be performed,
  13. * such as promotions, demotions and writebacks. The core cache target
  14. * is in charge of performing the work, and does so when it sees fit.
  15. *
  16. * The background_tracker acts as a go between. Keeping track of future
  17. * work that the policy has decided upon, and handing (issuing) it to
  18. * the core target when requested.
  19. *
  20. * There is no locking in this, so calls will probably need to be
  21. * protected with a spinlock.
  22. */
  23. struct background_work;
  24. struct background_tracker;
  25. /*
  26. * Create a new tracker, it will not be able to queue more than
  27. * 'max_work' entries.
  28. */
  29. struct background_tracker *btracker_create(unsigned int max_work);
  30. /*
  31. * Destroy the tracker. No issued, but not complete, work should
  32. * exist when this is called. It is fine to have queued but unissued
  33. * work.
  34. */
  35. void btracker_destroy(struct background_tracker *b);
  36. unsigned int btracker_nr_writebacks_queued(struct background_tracker *b);
  37. unsigned int btracker_nr_demotions_queued(struct background_tracker *b);
  38. /*
  39. * Queue some work within the tracker. 'work' should point to the work
  40. * to queue, this will be copied (ownership doesn't pass). If pwork
  41. * is not NULL then it will be set to point to the tracker's internal
  42. * copy of the work.
  43. *
  44. * returns -EINVAL iff the work is already queued. -ENOMEM if the work
  45. * couldn't be queued for another reason.
  46. */
  47. int btracker_queue(struct background_tracker *b,
  48. struct policy_work *work,
  49. struct policy_work **pwork);
  50. /*
  51. * Hands out the next piece of work to be performed.
  52. * Returns -ENODATA if there's no work.
  53. */
  54. int btracker_issue(struct background_tracker *b, struct policy_work **work);
  55. /*
  56. * Informs the tracker that the work has been completed and it may forget
  57. * about it.
  58. */
  59. void btracker_complete(struct background_tracker *b, struct policy_work *op);
  60. /*
  61. * Predicate to see if an origin block is already scheduled for promotion.
  62. */
  63. bool btracker_promotion_already_present(struct background_tracker *b,
  64. dm_oblock_t oblock);
  65. /*----------------------------------------------------------------*/
  66. #endif