slow-work.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* Worker thread pool for slow items, such as filesystem lookups or mkdirs
  2. *
  3. * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. *
  11. * See Documentation/slow-work.txt
  12. */
  13. #ifndef _LINUX_SLOW_WORK_H
  14. #define _LINUX_SLOW_WORK_H
  15. #ifdef CONFIG_SLOW_WORK
  16. #include <linux/sysctl.h>
  17. struct slow_work;
  18. /*
  19. * The operations used to support slow work items
  20. */
  21. struct slow_work_ops {
  22. /* owner */
  23. struct module *owner;
  24. /* get a ref on a work item
  25. * - return 0 if successful, -ve if not
  26. */
  27. int (*get_ref)(struct slow_work *work);
  28. /* discard a ref to a work item */
  29. void (*put_ref)(struct slow_work *work);
  30. /* execute a work item */
  31. void (*execute)(struct slow_work *work);
  32. };
  33. /*
  34. * A slow work item
  35. * - A reference is held on the parent object by the thread pool when it is
  36. * queued
  37. */
  38. struct slow_work {
  39. struct module *owner; /* the owning module */
  40. unsigned long flags;
  41. #define SLOW_WORK_PENDING 0 /* item pending (further) execution */
  42. #define SLOW_WORK_EXECUTING 1 /* item currently executing */
  43. #define SLOW_WORK_ENQ_DEFERRED 2 /* item enqueue deferred */
  44. #define SLOW_WORK_VERY_SLOW 3 /* item is very slow */
  45. #define SLOW_WORK_CANCELLING 4 /* item is being cancelled, don't enqueue */
  46. const struct slow_work_ops *ops; /* operations table for this item */
  47. struct list_head link; /* link in queue */
  48. };
  49. /**
  50. * slow_work_init - Initialise a slow work item
  51. * @work: The work item to initialise
  52. * @ops: The operations to use to handle the slow work item
  53. *
  54. * Initialise a slow work item.
  55. */
  56. static inline void slow_work_init(struct slow_work *work,
  57. const struct slow_work_ops *ops)
  58. {
  59. work->flags = 0;
  60. work->ops = ops;
  61. INIT_LIST_HEAD(&work->link);
  62. }
  63. /**
  64. * vslow_work_init - Initialise a very slow work item
  65. * @work: The work item to initialise
  66. * @ops: The operations to use to handle the slow work item
  67. *
  68. * Initialise a very slow work item. This item will be restricted such that
  69. * only a certain number of the pool threads will be able to execute items of
  70. * this type.
  71. */
  72. static inline void vslow_work_init(struct slow_work *work,
  73. const struct slow_work_ops *ops)
  74. {
  75. work->flags = 1 << SLOW_WORK_VERY_SLOW;
  76. work->ops = ops;
  77. INIT_LIST_HEAD(&work->link);
  78. }
  79. extern int slow_work_enqueue(struct slow_work *work);
  80. extern void slow_work_cancel(struct slow_work *work);
  81. extern int slow_work_register_user(struct module *owner);
  82. extern void slow_work_unregister_user(struct module *owner);
  83. #ifdef CONFIG_SYSCTL
  84. extern ctl_table slow_work_sysctls[];
  85. #endif
  86. #endif /* CONFIG_SLOW_WORK */
  87. #endif /* _LINUX_SLOW_WORK_H */