Whamcloud - gitweb
LU-10308 misc: update Intel copyright messages for 2017
[fs/lustre-release.git] / libcfs / include / libcfs / libcfs_ptask.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2017, Intel Corporation.
24  * Use is subject to license terms.
25  */
26 /*
27  * This file is part of Lustre, http://www.lustre.org/
28  *
29  * parallel task interface
30  */
31 #ifndef __LIBCFS_PTASK_H__
32 #define __LIBCFS_PTASK_H__
33
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>
42 #ifdef CONFIG_PADATA
43 #include <linux/padata.h>
44 #else
45 struct padata_priv {};
46 struct padata_instance {};
47 #endif
48
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)
55
56 struct cfs_ptask_engine {
57         struct padata_instance  *pte_pinst;
58         struct workqueue_struct *pte_wq;
59         struct notifier_block    pte_notifier;
60         int                      pte_weight;
61 };
62
63 struct cfs_ptask;
64 typedef int (*cfs_ptask_cb_t)(struct cfs_ptask *);
65
66 struct cfs_ptask {
67         struct padata_priv       pt_padata;
68         struct completion        pt_completion;
69         mm_segment_t             pt_fs;
70         struct mm_struct        *pt_mm;
71         unsigned int             pt_flags;
72         int                      pt_cbcpu;
73         cfs_ptask_cb_t           pt_cbfunc;
74         void                    *pt_cbdata;
75         int                      pt_result;
76 };
77
78 static inline
79 struct padata_priv *cfs_ptask2padata(struct cfs_ptask *ptask)
80 {
81         return &ptask->pt_padata;
82 }
83
84 static inline
85 struct cfs_ptask *cfs_padata2ptask(struct padata_priv *padata)
86 {
87         return container_of(padata, struct cfs_ptask, pt_padata);
88 }
89
90 static inline
91 bool cfs_ptask_need_complete(struct cfs_ptask *ptask)
92 {
93         return ptask->pt_flags & PTF_COMPLETE;
94 }
95
96 static inline
97 bool cfs_ptask_is_autofree(struct cfs_ptask *ptask)
98 {
99         return ptask->pt_flags & PTF_AUTOFREE;
100 }
101
102 static inline
103 bool cfs_ptask_is_ordered(struct cfs_ptask *ptask)
104 {
105         return ptask->pt_flags & PTF_ORDERED;
106 }
107
108 static inline
109 bool cfs_ptask_use_user_mm(struct cfs_ptask *ptask)
110 {
111         return ptask->pt_flags & PTF_USER_MM;
112 }
113
114 static inline
115 bool cfs_ptask_is_atomic(struct cfs_ptask *ptask)
116 {
117         return ptask->pt_flags & PTF_ATOMIC;
118 }
119
120 static inline
121 bool cfs_ptask_is_retry(struct cfs_ptask *ptask)
122 {
123         return ptask->pt_flags & PTF_RETRY;
124 }
125
126 static inline
127 int cfs_ptask_result(struct cfs_ptask *ptask)
128 {
129         return ptask->pt_result;
130 }
131
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 *);
136
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 *,
140                     unsigned int, int);
141
142 #endif /* __LIBCFS_PTASK_H__ */