xfs_pwork.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2019 Oracle. All Rights Reserved.
  4. * Author: Darrick J. Wong <darrick.wong@oracle.com>
  5. */
  6. #ifndef __XFS_PWORK_H__
  7. #define __XFS_PWORK_H__
  8. struct xfs_pwork;
  9. struct xfs_mount;
  10. typedef int (*xfs_pwork_work_fn)(struct xfs_mount *mp, struct xfs_pwork *pwork);
  11. /*
  12. * Parallel work coordination structure.
  13. */
  14. struct xfs_pwork_ctl {
  15. struct workqueue_struct *wq;
  16. struct xfs_mount *mp;
  17. xfs_pwork_work_fn work_fn;
  18. struct wait_queue_head poll_wait;
  19. atomic_t nr_work;
  20. int error;
  21. };
  22. /*
  23. * Embed this parallel work control item inside your own work structure,
  24. * then queue work with it.
  25. */
  26. struct xfs_pwork {
  27. struct work_struct work;
  28. struct xfs_pwork_ctl *pctl;
  29. };
  30. #define XFS_PWORK_SINGLE_THREADED { .pctl = NULL }
  31. /* Have we been told to abort? */
  32. static inline bool
  33. xfs_pwork_ctl_want_abort(
  34. struct xfs_pwork_ctl *pctl)
  35. {
  36. return pctl && pctl->error;
  37. }
  38. /* Have we been told to abort? */
  39. static inline bool
  40. xfs_pwork_want_abort(
  41. struct xfs_pwork *pwork)
  42. {
  43. return xfs_pwork_ctl_want_abort(pwork->pctl);
  44. }
  45. int xfs_pwork_init(struct xfs_mount *mp, struct xfs_pwork_ctl *pctl,
  46. xfs_pwork_work_fn work_fn, const char *tag,
  47. unsigned int nr_threads);
  48. void xfs_pwork_queue(struct xfs_pwork_ctl *pctl, struct xfs_pwork *pwork);
  49. int xfs_pwork_destroy(struct xfs_pwork_ctl *pctl);
  50. void xfs_pwork_poll(struct xfs_pwork_ctl *pctl);
  51. unsigned int xfs_pwork_guess_datadev_parallelism(struct xfs_mount *mp);
  52. #endif /* __XFS_PWORK_H__ */