blob: 3204daa51b955734e10cea7be5f7df24824814de [file] [log] [blame]
David Sterba9888c342018-04-03 19:16:55 +02001/* SPDX-License-Identifier: GPL-2.0 */
Chris Mason8b712842008-06-11 16:50:36 -04002/*
3 * Copyright (C) 2007 Oracle. All rights reserved.
Qu Wenruo08a9ff32014-02-28 10:46:03 +08004 * Copyright (C) 2014 Fujitsu. All rights reserved.
Chris Mason8b712842008-06-11 16:50:36 -04005 */
6
David Sterba9888c342018-04-03 19:16:55 +02007#ifndef BTRFS_ASYNC_THREAD_H
8#define BTRFS_ASYNC_THREAD_H
9
Liu Bo9e0af232014-08-15 23:36:53 +080010#include <linux/workqueue.h>
Chris Mason8b712842008-06-11 16:50:36 -040011
Jeff Mahoneycb001092016-06-09 16:22:11 -040012struct btrfs_fs_info;
Qu Wenruod458b052014-02-28 10:46:19 +080013struct btrfs_workqueue;
Qu Wenruo1ca08972014-02-28 10:46:04 +080014/* Internal use only */
Qu Wenruod458b052014-02-28 10:46:19 +080015struct __btrfs_workqueue;
Qu Wenruo6db89142014-03-06 04:19:50 +000016struct btrfs_work;
17typedef void (*btrfs_func_t)(struct btrfs_work *arg);
Liu Bo9e0af232014-08-15 23:36:53 +080018typedef void (*btrfs_work_func_t)(struct work_struct *arg);
Qu Wenruo08a9ff32014-02-28 10:46:03 +080019
Qu Wenruod458b052014-02-28 10:46:19 +080020struct btrfs_work {
Qu Wenruo6db89142014-03-06 04:19:50 +000021 btrfs_func_t func;
22 btrfs_func_t ordered_func;
23 btrfs_func_t ordered_free;
Qu Wenruo08a9ff32014-02-28 10:46:03 +080024
25 /* Don't touch things below */
26 struct work_struct normal_work;
27 struct list_head ordered_list;
Qu Wenruod458b052014-02-28 10:46:19 +080028 struct __btrfs_workqueue *wq;
Qu Wenruo08a9ff32014-02-28 10:46:03 +080029 unsigned long flags;
30};
31
Jeff Mahoneycb001092016-06-09 16:22:11 -040032struct btrfs_workqueue *btrfs_alloc_workqueue(struct btrfs_fs_info *fs_info,
33 const char *name,
David Sterba6f011052015-02-16 18:34:01 +010034 unsigned int flags,
Qu Wenruoc6dd6ea2015-08-20 09:30:39 +080035 int limit_active,
Qu Wenruo6db89142014-03-06 04:19:50 +000036 int thresh);
Omar Sandovala0cac0e2019-09-16 11:30:57 -070037void btrfs_init_work(struct btrfs_work *work, btrfs_func_t func,
38 btrfs_func_t ordered_func, btrfs_func_t ordered_free);
Qu Wenruod458b052014-02-28 10:46:19 +080039void btrfs_queue_work(struct btrfs_workqueue *wq,
40 struct btrfs_work *work);
41void btrfs_destroy_workqueue(struct btrfs_workqueue *wq);
42void btrfs_workqueue_set_max(struct btrfs_workqueue *wq, int max);
43void btrfs_set_work_high_priority(struct btrfs_work *work);
David Sterbae1f60a62019-10-01 19:57:39 +020044struct btrfs_fs_info * __pure btrfs_work_owner(const struct btrfs_work *work);
45struct btrfs_fs_info * __pure btrfs_workqueue_owner(const struct __btrfs_workqueue *wq);
Jeff Mahoney9a35b632017-06-28 21:56:54 -060046bool btrfs_workqueue_normal_congested(const struct btrfs_workqueue *wq);
Filipe Mananaf0cc2cd2020-02-28 13:04:36 +000047void btrfs_flush_workqueue(struct btrfs_workqueue *wq);
David Sterba9888c342018-04-03 19:16:55 +020048
Chris Mason8b712842008-06-11 16:50:36 -040049#endif