Whamcloud - gitweb
LU-7148 osc: Remove remains of osc_ast_guard
[fs/lustre-release.git] / lustre / osc / osc_internal.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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2015, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef OSC_INTERNAL_H
38 #define OSC_INTERNAL_H
39
40 #define OAP_MAGIC 8675309
41
42 extern atomic_t osc_pool_req_count;
43 extern unsigned int osc_reqpool_maxreqcount;
44 extern struct ptlrpc_request_pool *osc_rq_pool;
45
46 struct lu_env;
47
48 enum async_flags {
49         ASYNC_READY = 0x1, /* ap_make_ready will not be called before this
50                               page is added to an rpc */
51         ASYNC_URGENT = 0x2, /* page must be put into an RPC before return */
52         ASYNC_COUNT_STABLE = 0x4, /* ap_refresh_count will not be called
53                                      to give the caller a chance to update
54                                      or cancel the size of the io */
55         ASYNC_HP = 0x10,
56 };
57
58 struct osc_async_page {
59         int                     oap_magic;
60         unsigned short          oap_cmd;
61         unsigned short          oap_interrupted:1;
62
63         struct list_head        oap_pending_item;
64         struct list_head        oap_rpc_item;
65
66         loff_t                  oap_obj_off;
67         unsigned                oap_page_off;
68         enum async_flags        oap_async_flags;
69
70         struct brw_page         oap_brw_page;
71
72         struct ptlrpc_request   *oap_request;
73         struct client_obd       *oap_cli;
74         struct osc_object       *oap_obj;
75
76         spinlock_t               oap_lock;
77 };
78
79 #define oap_page        oap_brw_page.pg
80 #define oap_count       oap_brw_page.count
81 #define oap_brw_flags   oap_brw_page.flag
82
83 static inline struct osc_async_page *brw_page2oap(struct brw_page *pga)
84 {
85         return (struct osc_async_page *)container_of(pga, struct osc_async_page,
86                                                      oap_brw_page);
87 }
88
89 struct osc_cache_waiter {
90         struct list_head        ocw_entry;
91         wait_queue_head_t       ocw_waitq;
92         struct osc_async_page  *ocw_oap;
93         int                     ocw_grant;
94         int                     ocw_rc;
95 };
96
97 void osc_wake_cache_waiters(struct client_obd *cli);
98 int osc_shrink_grant_to_target(struct client_obd *cli, __u64 target_bytes);
99 void osc_update_next_shrink(struct client_obd *cli);
100
101 /*
102  * cl integration.
103  */
104 #include <cl_object.h>
105
106 extern struct ptlrpc_request_set *PTLRPCD_SET;
107
108 typedef int (*osc_enqueue_upcall_f)(void *cookie, struct lustre_handle *lockh,
109                                     int rc);
110
111 int osc_enqueue_base(struct obd_export *exp, struct ldlm_res_id *res_id,
112                      __u64 *flags, union ldlm_policy_data *policy,
113                      struct ost_lvb *lvb, int kms_valid,
114                      osc_enqueue_upcall_f upcall,
115                      void *cookie, struct ldlm_enqueue_info *einfo,
116                      struct ptlrpc_request_set *rqset, int async, int agl);
117
118 int osc_match_base(struct obd_export *exp, struct ldlm_res_id *res_id,
119                    __u32 type, union ldlm_policy_data *policy, __u32 mode,
120                    __u64 *flags, void *data, struct lustre_handle *lockh,
121                    int unref);
122
123 int osc_setattr_async(struct obd_export *exp, struct obdo *oa,
124                       obd_enqueue_update_f upcall, void *cookie,
125                       struct ptlrpc_request_set *rqset);
126 int osc_punch_base(struct obd_export *exp, struct obdo *oa,
127                    obd_enqueue_update_f upcall, void *cookie,
128                    struct ptlrpc_request_set *rqset);
129 int osc_sync_base(struct osc_object *obj, struct obdo *oa,
130                   obd_enqueue_update_f upcall, void *cookie,
131                   struct ptlrpc_request_set *rqset);
132
133 int osc_process_config_base(struct obd_device *obd, struct lustre_cfg *cfg);
134 int osc_build_rpc(const struct lu_env *env, struct client_obd *cli,
135                   struct list_head *ext_list, int cmd);
136 long osc_lru_shrink(const struct lu_env *env, struct client_obd *cli,
137                    long target, bool force);
138 unsigned long osc_lru_reserve(struct client_obd *cli, unsigned long npages);
139 void osc_lru_unreserve(struct client_obd *cli, unsigned long npages);
140
141 extern struct lu_kmem_descr osc_caches[];
142
143 unsigned long osc_ldlm_weigh_ast(struct ldlm_lock *dlmlock);
144
145 int osc_cleanup(struct obd_device *obd);
146 int osc_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
147
148 #ifdef CONFIG_PROC_FS
149 extern struct lprocfs_vars lprocfs_osc_obd_vars[];
150 int lproc_osc_attach_seqstat(struct obd_device *dev);
151 #else
152 static inline int lproc_osc_attach_seqstat(struct obd_device *dev) {return 0;}
153 #endif
154
155 extern struct lu_device_type osc_device_type;
156
157 static inline int osc_recoverable_error(int rc)
158 {
159         return (rc == -EIO || rc == -EROFS || rc == -ENOMEM ||
160                 rc == -EAGAIN || rc == -EINPROGRESS);
161 }
162
163 static inline unsigned long rpcs_in_flight(struct client_obd *cli)
164 {
165         return cli->cl_r_in_flight + cli->cl_w_in_flight;
166 }
167
168 static inline char *cli_name(struct client_obd *cli)
169 {
170         return cli->cl_import->imp_obd->obd_name;
171 }
172
173 #ifndef min_t
174 #define min_t(type,x,y) \
175         ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
176 #endif
177
178 struct osc_device {
179         struct cl_device    od_cl;
180         struct obd_export  *od_exp;
181
182         /* Write stats is actually protected by client_obd's lock. */
183         struct osc_stats {
184                 uint64_t     os_lockless_writes;          /* by bytes */
185                 uint64_t     os_lockless_reads;           /* by bytes */
186                 uint64_t     os_lockless_truncates;       /* by times */
187         } od_stats;
188
189         /* configuration item(s) */
190         int                 od_contention_time;
191         int                 od_lockless_truncate;
192 };
193
194 static inline struct osc_device *obd2osc_dev(const struct obd_device *d)
195 {
196         return container_of0(d->obd_lu_dev, struct osc_device, od_cl.cd_lu_dev);
197 }
198
199 extern struct kmem_cache *osc_quota_kmem;
200 struct osc_quota_info {
201         /** linkage for quota hash table */
202         struct hlist_node oqi_hash;
203         u32               oqi_id;
204 };
205
206 struct osc_async_args {
207         struct obd_info *aa_oi;
208 };
209
210 int osc_quota_setup(struct obd_device *obd);
211 int osc_quota_cleanup(struct obd_device *obd);
212 int osc_quota_setdq(struct client_obd *cli, const unsigned int qid[],
213                     u64 valid, u32 flags);
214 int osc_quota_chkdq(struct client_obd *cli, const unsigned int qid[]);
215 int osc_quotactl(struct obd_device *unused, struct obd_export *exp,
216                  struct obd_quotactl *oqctl);
217 void osc_inc_unstable_pages(struct ptlrpc_request *req);
218 void osc_dec_unstable_pages(struct ptlrpc_request *req);
219 bool osc_over_unstable_soft_limit(struct client_obd *cli);
220 /**
221  * Bit flags for osc_dlm_lock_at_pageoff().
222  */
223 enum osc_dap_flags {
224         /**
225          * Just check if the desired lock exists, it won't hold reference
226          * count on lock.
227          */
228         OSC_DAP_FL_TEST_LOCK = 1 << 0,
229         /**
230          * Return the lock even if it is being canceled.
231          */
232         OSC_DAP_FL_CANCELING = 1 << 1
233 };
234 struct ldlm_lock *osc_dlmlock_at_pgoff(const struct lu_env *env,
235                                        struct osc_object *obj, pgoff_t index,
236                                        enum osc_dap_flags flags);
237 void osc_pack_req_body(struct ptlrpc_request *req, struct obdo *oa);
238 int osc_object_invalidate(const struct lu_env *env, struct osc_object *osc);
239
240 /** osc shrink list to link all osc client obd */
241 extern struct list_head osc_shrink_list;
242 /** spin lock to protect osc_shrink_list */
243 extern spinlock_t osc_shrink_lock;
244 extern unsigned long osc_cache_shrink_count(struct shrinker *sk,
245                                             struct shrink_control *sc);
246 extern unsigned long osc_cache_shrink_scan(struct shrinker *sk,
247                                            struct shrink_control *sc);
248
249 #endif /* OSC_INTERNAL_H */