4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2017, Intel Corporation.
24 * Use is subject to license terms.
27 * This file is part of Lustre, http://www.lustre.org/
29 * parallel task interface
31 #ifndef __LIBCFS_PTASK_H__
32 #define __LIBCFS_PTASK_H__
34 #include <linux/types.h>
35 #include <linux/bitops.h>
36 #include <linux/kernel.h>
37 #include <linux/cpumask.h>
38 #include <linux/uaccess.h>
39 #include <linux/notifier.h>
40 #include <linux/workqueue.h>
41 #include <linux/completion.h>
43 #include <linux/padata.h>
45 struct padata_priv {};
46 struct padata_instance {};
49 #define PTF_COMPLETE BIT(0)
50 #define PTF_AUTOFREE BIT(1)
51 #define PTF_ORDERED BIT(2)
52 #define PTF_USER_MM BIT(3)
53 #define PTF_ATOMIC BIT(4)
54 #define PTF_RETRY BIT(5)
56 struct cfs_ptask_engine {
57 struct padata_instance *pte_pinst;
58 struct workqueue_struct *pte_wq;
59 struct notifier_block pte_notifier;
64 typedef int (*cfs_ptask_cb_t)(struct cfs_ptask *);
67 struct padata_priv pt_padata;
68 struct completion pt_completion;
70 struct mm_struct *pt_mm;
71 unsigned int pt_flags;
73 cfs_ptask_cb_t pt_cbfunc;
79 struct padata_priv *cfs_ptask2padata(struct cfs_ptask *ptask)
81 return &ptask->pt_padata;
85 struct cfs_ptask *cfs_padata2ptask(struct padata_priv *padata)
87 return container_of(padata, struct cfs_ptask, pt_padata);
91 bool cfs_ptask_need_complete(struct cfs_ptask *ptask)
93 return ptask->pt_flags & PTF_COMPLETE;
97 bool cfs_ptask_is_autofree(struct cfs_ptask *ptask)
99 return ptask->pt_flags & PTF_AUTOFREE;
103 bool cfs_ptask_is_ordered(struct cfs_ptask *ptask)
105 return ptask->pt_flags & PTF_ORDERED;
109 bool cfs_ptask_use_user_mm(struct cfs_ptask *ptask)
111 return ptask->pt_flags & PTF_USER_MM;
115 bool cfs_ptask_is_atomic(struct cfs_ptask *ptask)
117 return ptask->pt_flags & PTF_ATOMIC;
121 bool cfs_ptask_is_retry(struct cfs_ptask *ptask)
123 return ptask->pt_flags & PTF_RETRY;
127 int cfs_ptask_result(struct cfs_ptask *ptask)
129 return ptask->pt_result;
132 struct cfs_ptask_engine *cfs_ptengine_init(const char *, const struct cpumask *);
133 void cfs_ptengine_fini(struct cfs_ptask_engine *);
134 int cfs_ptengine_set_cpumask(struct cfs_ptask_engine *, const struct cpumask *);
135 int cfs_ptengine_weight(struct cfs_ptask_engine *);
137 int cfs_ptask_submit(struct cfs_ptask *, struct cfs_ptask_engine *);
138 int cfs_ptask_wait_for(struct cfs_ptask *);
139 int cfs_ptask_init(struct cfs_ptask *, cfs_ptask_cb_t, void *,
142 #endif /* __LIBCFS_PTASK_H__ */