140786717SDarrick J. Wong /* SPDX-License-Identifier: GPL-2.0-or-later */ 240786717SDarrick J. Wong /* 340786717SDarrick J. Wong * Copyright (C) 2019 Oracle. All Rights Reserved. 440786717SDarrick J. Wong * Author: Darrick J. Wong <darrick.wong@oracle.com> 540786717SDarrick J. Wong */ 640786717SDarrick J. Wong #ifndef __XFS_PWORK_H__ 740786717SDarrick J. Wong #define __XFS_PWORK_H__ 840786717SDarrick J. Wong 940786717SDarrick J. Wong struct xfs_pwork; 1040786717SDarrick J. Wong struct xfs_mount; 1140786717SDarrick J. Wong 1240786717SDarrick J. Wong typedef int (*xfs_pwork_work_fn)(struct xfs_mount *mp, struct xfs_pwork *pwork); 1340786717SDarrick J. Wong 1440786717SDarrick J. Wong /* 1540786717SDarrick J. Wong * Parallel work coordination structure. 1640786717SDarrick J. Wong */ 1740786717SDarrick J. Wong struct xfs_pwork_ctl { 1840786717SDarrick J. Wong struct workqueue_struct *wq; 1940786717SDarrick J. Wong struct xfs_mount *mp; 2040786717SDarrick J. Wong xfs_pwork_work_fn work_fn; 213e5a428bSDarrick J. Wong struct wait_queue_head poll_wait; 223e5a428bSDarrick J. Wong atomic_t nr_work; 2340786717SDarrick J. Wong int error; 2440786717SDarrick J. Wong }; 2540786717SDarrick J. Wong 2640786717SDarrick J. Wong /* 2740786717SDarrick J. Wong * Embed this parallel work control item inside your own work structure, 2840786717SDarrick J. Wong * then queue work with it. 2940786717SDarrick J. Wong */ 3040786717SDarrick J. Wong struct xfs_pwork { 3140786717SDarrick J. Wong struct work_struct work; 3240786717SDarrick J. Wong struct xfs_pwork_ctl *pctl; 3340786717SDarrick J. Wong }; 3440786717SDarrick J. Wong 3540786717SDarrick J. Wong #define XFS_PWORK_SINGLE_THREADED { .pctl = NULL } 3640786717SDarrick J. Wong 3740786717SDarrick J. Wong /* Have we been told to abort? */ 3840786717SDarrick J. Wong static inline bool xfs_pwork_ctl_want_abort(struct xfs_pwork_ctl * pctl)3940786717SDarrick J. Wongxfs_pwork_ctl_want_abort( 4040786717SDarrick J. Wong struct xfs_pwork_ctl *pctl) 4140786717SDarrick J. Wong { 4240786717SDarrick J. Wong return pctl && pctl->error; 4340786717SDarrick J. Wong } 4440786717SDarrick J. Wong 4540786717SDarrick J. Wong /* Have we been told to abort? */ 4640786717SDarrick J. Wong static inline bool xfs_pwork_want_abort(struct xfs_pwork * pwork)4740786717SDarrick J. Wongxfs_pwork_want_abort( 4840786717SDarrick J. Wong struct xfs_pwork *pwork) 4940786717SDarrick J. Wong { 5040786717SDarrick J. Wong return xfs_pwork_ctl_want_abort(pwork->pctl); 5140786717SDarrick J. Wong } 5240786717SDarrick J. Wong 5340786717SDarrick J. Wong int xfs_pwork_init(struct xfs_mount *mp, struct xfs_pwork_ctl *pctl, 54*f83d436aSDarrick J. Wong xfs_pwork_work_fn work_fn, const char *tag); 5540786717SDarrick J. Wong void xfs_pwork_queue(struct xfs_pwork_ctl *pctl, struct xfs_pwork *pwork); 5640786717SDarrick J. Wong int xfs_pwork_destroy(struct xfs_pwork_ctl *pctl); 573e5a428bSDarrick J. Wong void xfs_pwork_poll(struct xfs_pwork_ctl *pctl); 5840786717SDarrick J. Wong 5940786717SDarrick J. Wong #endif /* __XFS_PWORK_H__ */ 60