Commit | Line | Data |
---|---|---|
d7e09d03 PT |
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 | |
6a5b99a4 | 18 | * http://www.gnu.org/licenses/gpl-2.0.html |
d7e09d03 | 19 | * |
d7e09d03 PT |
20 | * GPL HEADER END |
21 | */ | |
22 | /* | |
23 | * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. | |
24 | * Use is subject to license terms. | |
25 | * | |
1dc563a6 | 26 | * Copyright (c) 2011, 2015, Intel Corporation. |
d7e09d03 PT |
27 | */ |
28 | /* | |
29 | * This file is part of Lustre, http://www.lustre.org/ | |
30 | * Lustre is a trademark of Sun Microsystems, Inc. | |
31 | */ | |
32 | #ifndef __CLASS_OBD_H | |
33 | #define __CLASS_OBD_H | |
34 | ||
1accaadf GKH |
35 | #include "obd_support.h" |
36 | #include "lustre_import.h" | |
37 | #include "lustre_net.h" | |
38 | #include "obd.h" | |
39 | #include "lustre_lib.h" | |
40 | #include "lustre/lustre_idl.h" | |
41 | #include "lprocfs_status.h" | |
d7e09d03 | 42 | |
d7e09d03 | 43 | #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay |
c56e256d OD |
44 | * and resends for avoid deadlocks |
45 | */ | |
d7e09d03 | 46 | #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update |
c56e256d OD |
47 | * obd_osfs_age |
48 | */ | |
d7e09d03 PT |
49 | #define OBD_STATFS_PTLRPCD 0x0004 /* requests will be sent via ptlrpcd |
50 | * instead of a specific set. This | |
51 | * means that we cannot rely on the set | |
52 | * interpret routine to be called. | |
53 | * lov_statfs_fini() must thus be called | |
c56e256d OD |
54 | * by the request interpret routine |
55 | */ | |
d7e09d03 | 56 | #define OBD_STATFS_FOR_MDT0 0x0008 /* The statfs is only for retrieving |
c56e256d OD |
57 | * information from MDT0. |
58 | */ | |
d7e09d03 PT |
59 | |
60 | /* OBD Device Declarations */ | |
61 | extern struct obd_device *obd_devs[MAX_OBD_DEVICES]; | |
62 | extern rwlock_t obd_dev_lock; | |
63 | ||
64 | /* OBD Operations Declarations */ | |
8150a97f JP |
65 | struct obd_device *class_exp2obd(struct obd_export *); |
66 | int class_handle_ioctl(unsigned int cmd, unsigned long arg); | |
67 | int lustre_get_jobid(char *jobid); | |
d7e09d03 PT |
68 | |
69 | struct lu_device_type; | |
70 | ||
71 | /* genops.c */ | |
826ad46d | 72 | extern struct list_head obd_types; |
d7e09d03 PT |
73 | struct obd_export *class_conn2export(struct lustre_handle *); |
74 | int class_register_type(struct obd_ops *, struct md_ops *, | |
2962b440 | 75 | const char *nm, struct lu_device_type *ldt); |
d7e09d03 PT |
76 | int class_unregister_type(const char *nm); |
77 | ||
78 | struct obd_device *class_newdev(const char *type_name, const char *name); | |
79 | void class_release_dev(struct obd_device *obd); | |
80 | ||
81 | int class_name2dev(const char *name); | |
82 | struct obd_device *class_name2obd(const char *name); | |
83 | int class_uuid2dev(struct obd_uuid *uuid); | |
aff9d8e8 | 84 | struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid, |
10457d4b OD |
85 | const char *typ_name, |
86 | struct obd_uuid *grp_uuid); | |
aff9d8e8 | 87 | struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid, |
10457d4b | 88 | int *next); |
aff9d8e8 | 89 | struct obd_device *class_num2obd(int num); |
d7e09d03 PT |
90 | |
91 | int class_notify_sptlrpc_conf(const char *fsname, int namelen); | |
92 | ||
d7e09d03 PT |
93 | int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep); |
94 | ||
95 | int obd_zombie_impexp_init(void); | |
96 | void obd_zombie_impexp_stop(void); | |
d7e09d03 | 97 | void obd_zombie_barrier(void); |
d7e09d03 | 98 | |
1d5d5ec1 FY |
99 | int obd_get_request_slot(struct client_obd *cli); |
100 | void obd_put_request_slot(struct client_obd *cli); | |
101 | __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli); | |
102 | int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max); | |
103 | ||
d7e09d03 PT |
104 | struct llog_handle; |
105 | struct llog_rec_hdr; | |
106 | typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *, | |
107 | struct llog_rec_hdr *, void *); | |
108 | /* obd_config.c */ | |
d7e09d03 PT |
109 | int class_process_config(struct lustre_cfg *lcfg); |
110 | int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars, | |
111 | struct lustre_cfg *lcfg, void *data); | |
d7e09d03 PT |
112 | struct obd_device *class_incref(struct obd_device *obd, |
113 | const char *scope, const void *source); | |
114 | void class_decref(struct obd_device *obd, | |
115 | const char *scope, const void *source); | |
d7e09d03 PT |
116 | int class_config_llog_handler(const struct lu_env *env, |
117 | struct llog_handle *handle, | |
118 | struct llog_rec_hdr *rec, void *data); | |
d7e09d03 PT |
119 | int class_add_uuid(const char *uuid, __u64 nid); |
120 | ||
121 | /*obdecho*/ | |
8150a97f | 122 | void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars); |
d7e09d03 PT |
123 | |
124 | #define CFG_F_START 0x01 /* Set when we start updating from a log */ | |
125 | #define CFG_F_MARKER 0x02 /* We are within a maker */ | |
126 | #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */ | |
127 | #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */ | |
128 | #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */ | |
129 | ||
130 | /* Passed as data param to class_config_parse_llog */ | |
131 | struct config_llog_instance { | |
132 | char *cfg_obdname; | |
133 | void *cfg_instance; | |
134 | struct super_block *cfg_sb; | |
135 | struct obd_uuid cfg_uuid; | |
136 | llog_cb_t cfg_callback; | |
137 | int cfg_last_idx; /* for partial llog processing */ | |
138 | int cfg_flags; | |
139 | }; | |
c9f6bb96 | 140 | |
d7e09d03 PT |
141 | int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt, |
142 | char *name, struct config_llog_instance *cfg); | |
d7e09d03 PT |
143 | enum { |
144 | CONFIG_T_CONFIG = 0, | |
145 | CONFIG_T_SPTLRPC = 1, | |
146 | CONFIG_T_RECOVER = 2, | |
7d4bae45 AB |
147 | CONFIG_T_PARAMS = 3, |
148 | CONFIG_T_MAX = 4 | |
d7e09d03 PT |
149 | }; |
150 | ||
7d4bae45 AB |
151 | #define PARAMS_FILENAME "params" |
152 | #define LCTL_UPCALL "lctl" | |
153 | ||
d7e09d03 PT |
154 | /* list of active configuration logs */ |
155 | struct config_llog_data { | |
156 | struct ldlm_res_id cld_resid; | |
157 | struct config_llog_instance cld_cfg; | |
158 | struct list_head cld_list_chain; | |
159 | atomic_t cld_refcount; | |
160 | struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */ | |
7d4bae45 AB |
161 | struct config_llog_data *cld_params; /* common parameters log */ |
162 | struct config_llog_data *cld_recover;/* imperative recover log */ | |
d7e09d03 PT |
163 | struct obd_export *cld_mgcexp; |
164 | struct mutex cld_lock; | |
165 | int cld_type; | |
166 | unsigned int cld_stopping:1, /* we were told to stop | |
c56e256d OD |
167 | * watching |
168 | */ | |
169 | cld_lostlock:1; /* lock not requeued */ | |
d7e09d03 PT |
170 | char cld_logname[0]; |
171 | }; | |
172 | ||
173 | struct lustre_profile { | |
174 | struct list_head lp_list; | |
175 | char *lp_profile; | |
176 | char *lp_dt; | |
177 | char *lp_md; | |
178 | }; | |
179 | ||
aff9d8e8 | 180 | struct lustre_profile *class_get_profile(const char *prof); |
d7e09d03 PT |
181 | void class_del_profile(const char *prof); |
182 | void class_del_profiles(void); | |
183 | ||
184 | #if LUSTRE_TRACKS_LOCK_EXP_REFS | |
185 | ||
186 | void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *); | |
187 | void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *); | |
188 | extern void (*class_export_dump_hook)(struct obd_export *); | |
189 | ||
190 | #else | |
191 | ||
a58a38ac GD |
192 | #define __class_export_add_lock_ref(exp, lock) do {} while (0) |
193 | #define __class_export_del_lock_ref(exp, lock) do {} while (0) | |
d7e09d03 PT |
194 | |
195 | #endif | |
196 | ||
a1d825e9 KS |
197 | /* genops.c */ |
198 | struct obd_export *class_export_get(struct obd_export *exp); | |
199 | void class_export_put(struct obd_export *exp); | |
200 | struct obd_export *class_new_export(struct obd_device *obddev, | |
10457d4b | 201 | struct obd_uuid *cluuid); |
a1d825e9 KS |
202 | void class_unlink_export(struct obd_export *exp); |
203 | ||
204 | struct obd_import *class_import_get(struct obd_import *); | |
205 | void class_import_put(struct obd_import *); | |
206 | struct obd_import *class_new_import(struct obd_device *obd); | |
207 | void class_destroy_import(struct obd_import *exp); | |
208 | ||
209 | void class_put_type(struct obd_type *type); | |
210 | int class_connect(struct lustre_handle *conn, struct obd_device *obd, | |
10457d4b | 211 | struct obd_uuid *cluuid); |
a1d825e9 KS |
212 | int class_disconnect(struct obd_export *exp); |
213 | void class_fail_export(struct obd_export *exp); | |
214 | int class_manual_cleanup(struct obd_device *obd); | |
215 | ||
28b9d6f1 SA |
216 | static inline void class_export_rpc_inc(struct obd_export *exp) |
217 | { | |
218 | atomic_inc(&(exp)->exp_rpc_count); | |
219 | CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", | |
220 | (exp), atomic_read(&(exp)->exp_rpc_count)); | |
221 | } | |
d7e09d03 | 222 | |
5fb0acb4 SA |
223 | static inline void class_export_rpc_dec(struct obd_export *exp) |
224 | { | |
225 | LASSERT_ATOMIC_POS(&exp->exp_rpc_count); | |
226 | atomic_dec(&(exp)->exp_rpc_count); | |
227 | CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", | |
228 | (exp), atomic_read(&(exp)->exp_rpc_count)); | |
229 | } | |
d7e09d03 | 230 | |
edc6a40e KS |
231 | static inline struct obd_export *class_export_lock_get(struct obd_export *exp, |
232 | struct ldlm_lock *lock) | |
233 | { | |
234 | atomic_inc(&(exp)->exp_locks_count); | |
235 | __class_export_add_lock_ref(exp, lock); | |
236 | CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", | |
237 | (exp), atomic_read(&(exp)->exp_locks_count)); | |
238 | return class_export_get(exp); | |
239 | } | |
d7e09d03 | 240 | |
d811ed69 KS |
241 | static inline void class_export_lock_put(struct obd_export *exp, |
242 | struct ldlm_lock *lock) | |
243 | { | |
244 | LASSERT_ATOMIC_POS(&exp->exp_locks_count); | |
245 | atomic_dec(&(exp)->exp_locks_count); | |
246 | __class_export_del_lock_ref(exp, lock); | |
247 | CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", | |
248 | (exp), atomic_read(&(exp)->exp_locks_count)); | |
249 | class_export_put(exp); | |
250 | } | |
d7e09d03 | 251 | |
d7e09d03 PT |
252 | static inline enum obd_option exp_flags_from_obd(struct obd_device *obd) |
253 | { | |
254 | return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) | | |
255 | (obd->obd_force ? OBD_OPT_FORCE : 0) | | |
d7e09d03 PT |
256 | 0); |
257 | } | |
258 | ||
a15b2225 KS |
259 | static inline int lprocfs_climp_check(struct obd_device *obd) |
260 | { | |
261 | down_read(&(obd)->u.cli.cl_sem); | |
262 | if (!(obd)->u.cli.cl_import) { | |
263 | up_read(&(obd)->u.cli.cl_sem); | |
264 | return -ENODEV; | |
265 | } | |
266 | return 0; | |
267 | } | |
268 | ||
616331c3 JH |
269 | struct inode; |
270 | struct lu_attr; | |
271 | struct obdo; | |
58c78cd2 | 272 | void obdo_refresh_inode(struct inode *dst, const struct obdo *src, u32 valid); |
d7e09d03 | 273 | |
58c78cd2 JH |
274 | void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj); |
275 | void md_from_obdo(struct md_op_data *op_data, const struct obdo *oa, u32 valid); | |
d7e09d03 PT |
276 | |
277 | #define OBT(dev) (dev)->obd_type | |
a13b1f32 | 278 | #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->op |
df18a80a | 279 | #define MDP(dev, op) (dev)->obd_type->typ_md_ops->op |
d7e09d03 PT |
280 | #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op |
281 | ||
282 | /* Ensure obd_setup: used for cleanup which must be called | |
c56e256d OD |
283 | * while obd is stopping |
284 | */ | |
4ca1b8fb AM |
285 | static inline int obd_check_dev(struct obd_device *obd) |
286 | { | |
287 | if (!obd) { | |
288 | CERROR("NULL device\n"); | |
289 | return -ENODEV; | |
290 | } | |
291 | return 0; | |
292 | } | |
293 | ||
d7e09d03 | 294 | /* ensure obd_setup and !obd_stopping */ |
f36b6553 AM |
295 | static inline int obd_check_dev_active(struct obd_device *obd) |
296 | { | |
297 | int rc; | |
298 | ||
299 | rc = obd_check_dev(obd); | |
300 | if (rc) | |
301 | return rc; | |
302 | if (!obd->obd_set_up || obd->obd_stopping) { | |
303 | CERROR("Device %d not setup\n", obd->obd_minor); | |
304 | return -ENODEV; | |
305 | } | |
306 | return rc; | |
307 | } | |
d7e09d03 | 308 | |
d7e09d03 | 309 | #define OBD_COUNTER_OFFSET(op) \ |
a13b1f32 DC |
310 | ((offsetof(struct obd_ops, op) - \ |
311 | offsetof(struct obd_ops, iocontrol)) \ | |
312 | / sizeof(((struct obd_ops *)(0))->iocontrol)) | |
d7e09d03 PT |
313 | |
314 | #define OBD_COUNTER_INCREMENT(obdx, op) \ | |
d2a13989 | 315 | if ((obdx)->obd_stats) { \ |
d7e09d03 PT |
316 | unsigned int coffset; \ |
317 | coffset = (unsigned int)((obdx)->obd_cntr_base) + \ | |
318 | OBD_COUNTER_OFFSET(op); \ | |
319 | LASSERT(coffset < (obdx)->obd_stats->ls_num); \ | |
320 | lprocfs_counter_incr((obdx)->obd_stats, coffset); \ | |
321 | } | |
322 | ||
323 | #define EXP_COUNTER_INCREMENT(export, op) \ | |
d2a13989 | 324 | if ((export)->exp_obd->obd_stats) { \ |
d7e09d03 PT |
325 | unsigned int coffset; \ |
326 | coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \ | |
327 | OBD_COUNTER_OFFSET(op); \ | |
328 | LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \ | |
329 | lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \ | |
d7e09d03 PT |
330 | } |
331 | ||
332 | #define MD_COUNTER_OFFSET(op) \ | |
df18a80a DC |
333 | ((offsetof(struct md_ops, op) - \ |
334 | offsetof(struct md_ops, getstatus)) \ | |
335 | / sizeof(((struct md_ops *)(0))->getstatus)) | |
d7e09d03 PT |
336 | |
337 | #define MD_COUNTER_INCREMENT(obdx, op) \ | |
d2a13989 | 338 | if ((obd)->md_stats) { \ |
d7e09d03 PT |
339 | unsigned int coffset; \ |
340 | coffset = (unsigned int)((obdx)->md_cntr_base) + \ | |
341 | MD_COUNTER_OFFSET(op); \ | |
342 | LASSERT(coffset < (obdx)->md_stats->ls_num); \ | |
343 | lprocfs_counter_incr((obdx)->md_stats, coffset); \ | |
344 | } | |
345 | ||
346 | #define EXP_MD_COUNTER_INCREMENT(export, op) \ | |
d2a13989 | 347 | if ((export)->exp_obd->obd_stats) { \ |
d7e09d03 PT |
348 | unsigned int coffset; \ |
349 | coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \ | |
350 | MD_COUNTER_OFFSET(op); \ | |
351 | LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \ | |
352 | lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \ | |
d2a13989 | 353 | if ((export)->exp_md_stats) \ |
d7e09d03 PT |
354 | lprocfs_counter_incr( \ |
355 | (export)->exp_md_stats, coffset); \ | |
356 | } | |
357 | ||
d7e09d03 PT |
358 | #define EXP_CHECK_MD_OP(exp, op) \ |
359 | do { \ | |
d2a13989 | 360 | if (!(exp)) { \ |
d7e09d03 | 361 | CERROR("obd_" #op ": NULL export\n"); \ |
0a3bdb00 | 362 | return -ENODEV; \ |
d7e09d03 | 363 | } \ |
d2a13989 | 364 | if (!(exp)->exp_obd || !OBT((exp)->exp_obd)) { \ |
d7e09d03 | 365 | CERROR("obd_" #op ": cleaned up obd\n"); \ |
0a3bdb00 | 366 | return -EOPNOTSUPP; \ |
d7e09d03 PT |
367 | } \ |
368 | if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \ | |
369 | CERROR("obd_" #op ": dev %s/%d no operation\n", \ | |
370 | (exp)->exp_obd->obd_name, \ | |
371 | (exp)->exp_obd->obd_minor); \ | |
0a3bdb00 | 372 | return -EOPNOTSUPP; \ |
d7e09d03 PT |
373 | } \ |
374 | } while (0) | |
375 | ||
d7e09d03 PT |
376 | #define OBD_CHECK_DT_OP(obd, op, err) \ |
377 | do { \ | |
378 | if (!OBT(obd) || !OBP((obd), op)) { \ | |
379 | if (err) \ | |
380 | CERROR("obd_" #op ": dev %d no operation\n", \ | |
381 | obd->obd_minor); \ | |
0a3bdb00 | 382 | return err; \ |
d7e09d03 PT |
383 | } \ |
384 | } while (0) | |
385 | ||
386 | #define EXP_CHECK_DT_OP(exp, op) \ | |
387 | do { \ | |
d2a13989 | 388 | if (!(exp)) { \ |
d7e09d03 | 389 | CERROR("obd_" #op ": NULL export\n"); \ |
0a3bdb00 | 390 | return -ENODEV; \ |
d7e09d03 | 391 | } \ |
d2a13989 | 392 | if (!(exp)->exp_obd || !OBT((exp)->exp_obd)) { \ |
d7e09d03 | 393 | CERROR("obd_" #op ": cleaned up obd\n"); \ |
0a3bdb00 | 394 | return -EOPNOTSUPP; \ |
d7e09d03 PT |
395 | } \ |
396 | if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \ | |
397 | CERROR("obd_" #op ": dev %d no operation\n", \ | |
398 | (exp)->exp_obd->obd_minor); \ | |
0a3bdb00 | 399 | return -EOPNOTSUPP; \ |
d7e09d03 PT |
400 | } \ |
401 | } while (0) | |
402 | ||
403 | #define CTXT_CHECK_OP(ctxt, op, err) \ | |
404 | do { \ | |
405 | if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \ | |
406 | if (err) \ | |
407 | CERROR("lop_" #op ": dev %d no operation\n", \ | |
408 | ctxt->loc_obd->obd_minor); \ | |
0a3bdb00 | 409 | return err; \ |
d7e09d03 PT |
410 | } \ |
411 | } while (0) | |
412 | ||
413 | static inline int class_devno_max(void) | |
414 | { | |
415 | return MAX_OBD_DEVICES; | |
416 | } | |
417 | ||
418 | static inline int obd_get_info(const struct lu_env *env, | |
419 | struct obd_export *exp, __u32 keylen, | |
420 | void *key, __u32 *vallen, void *val, | |
421 | struct lov_stripe_md *lsm) | |
422 | { | |
423 | int rc; | |
d7e09d03 PT |
424 | |
425 | EXP_CHECK_DT_OP(exp, get_info); | |
426 | EXP_COUNTER_INCREMENT(exp, get_info); | |
427 | ||
428 | rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val, | |
429 | lsm); | |
0a3bdb00 | 430 | return rc; |
d7e09d03 PT |
431 | } |
432 | ||
433 | static inline int obd_set_info_async(const struct lu_env *env, | |
21aef7d9 OD |
434 | struct obd_export *exp, u32 keylen, |
435 | void *key, u32 vallen, void *val, | |
d7e09d03 PT |
436 | struct ptlrpc_request_set *set) |
437 | { | |
438 | int rc; | |
d7e09d03 PT |
439 | |
440 | EXP_CHECK_DT_OP(exp, set_info_async); | |
441 | EXP_COUNTER_INCREMENT(exp, set_info_async); | |
442 | ||
443 | rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen, | |
444 | val, set); | |
0a3bdb00 | 445 | return rc; |
d7e09d03 PT |
446 | } |
447 | ||
448 | /* | |
449 | * obd-lu integration. | |
450 | * | |
451 | * Functionality is being moved into new lu_device-based layering, but some | |
452 | * pieces of configuration process are still based on obd devices. | |
453 | * | |
454 | * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully | |
455 | * subsume ->o_setup() methods of obd devices they replace. The same for | |
456 | * lu_device_operations::ldo_process_config() and ->o_process_config(). As a | |
457 | * result, obd_setup() and obd_process_config() branch and call one XOR | |
458 | * another. | |
459 | * | |
460 | * Yet neither lu_device_type_operations::ldto_device_fini() nor | |
461 | * lu_device_type_operations::ldto_device_free() fully implement the | |
462 | * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence, | |
463 | * obd_precleanup() and obd_cleanup() call both lu_device and obd operations. | |
464 | */ | |
465 | ||
466 | #define DECLARE_LU_VARS(ldt, d) \ | |
467 | struct lu_device_type *ldt; \ | |
468 | struct lu_device *d | |
469 | ||
470 | static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg) | |
471 | { | |
472 | int rc; | |
473 | DECLARE_LU_VARS(ldt, d); | |
d7e09d03 PT |
474 | |
475 | ldt = obd->obd_type->typ_lu; | |
d2a13989 | 476 | if (ldt) { |
d7e09d03 PT |
477 | struct lu_context session_ctx; |
478 | struct lu_env env; | |
50ffcb7e | 479 | |
7f937beb | 480 | lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION); |
d7e09d03 PT |
481 | session_ctx.lc_thread = NULL; |
482 | lu_context_enter(&session_ctx); | |
483 | ||
484 | rc = lu_env_init(&env, ldt->ldt_ctx_tags); | |
485 | if (rc == 0) { | |
486 | env.le_ses = &session_ctx; | |
487 | d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg); | |
488 | lu_env_fini(&env); | |
489 | if (!IS_ERR(d)) { | |
490 | obd->obd_lu_dev = d; | |
491 | d->ld_obd = obd; | |
492 | rc = 0; | |
da5ecb4d | 493 | } else { |
d7e09d03 | 494 | rc = PTR_ERR(d); |
da5ecb4d | 495 | } |
d7e09d03 PT |
496 | } |
497 | lu_context_exit(&session_ctx); | |
498 | lu_context_fini(&session_ctx); | |
499 | ||
500 | } else { | |
501 | OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP); | |
502 | OBD_COUNTER_INCREMENT(obd, setup); | |
503 | rc = OBP(obd, setup)(obd, cfg); | |
504 | } | |
0a3bdb00 | 505 | return rc; |
d7e09d03 PT |
506 | } |
507 | ||
508 | static inline int obd_precleanup(struct obd_device *obd, | |
509 | enum obd_cleanup_stage cleanup_stage) | |
510 | { | |
511 | int rc; | |
512 | DECLARE_LU_VARS(ldt, d); | |
d7e09d03 | 513 | |
4ca1b8fb AM |
514 | rc = obd_check_dev(obd); |
515 | if (rc) | |
516 | return rc; | |
d7e09d03 PT |
517 | ldt = obd->obd_type->typ_lu; |
518 | d = obd->obd_lu_dev; | |
d2a13989 | 519 | if (ldt && d) { |
d7e09d03 PT |
520 | if (cleanup_stage == OBD_CLEANUP_EXPORTS) { |
521 | struct lu_env env; | |
522 | ||
523 | rc = lu_env_init(&env, ldt->ldt_ctx_tags); | |
524 | if (rc == 0) { | |
525 | ldt->ldt_ops->ldto_device_fini(&env, d); | |
526 | lu_env_fini(&env); | |
527 | } | |
528 | } | |
529 | } | |
530 | OBD_CHECK_DT_OP(obd, precleanup, 0); | |
531 | OBD_COUNTER_INCREMENT(obd, precleanup); | |
532 | ||
533 | rc = OBP(obd, precleanup)(obd, cleanup_stage); | |
0a3bdb00 | 534 | return rc; |
d7e09d03 PT |
535 | } |
536 | ||
537 | static inline int obd_cleanup(struct obd_device *obd) | |
538 | { | |
539 | int rc; | |
540 | DECLARE_LU_VARS(ldt, d); | |
d7e09d03 | 541 | |
4ca1b8fb AM |
542 | rc = obd_check_dev(obd); |
543 | if (rc) | |
544 | return rc; | |
d7e09d03 PT |
545 | |
546 | ldt = obd->obd_type->typ_lu; | |
547 | d = obd->obd_lu_dev; | |
d2a13989 | 548 | if (ldt && d) { |
d7e09d03 PT |
549 | struct lu_env env; |
550 | ||
551 | rc = lu_env_init(&env, ldt->ldt_ctx_tags); | |
552 | if (rc == 0) { | |
553 | ldt->ldt_ops->ldto_device_free(&env, d); | |
554 | lu_env_fini(&env); | |
555 | obd->obd_lu_dev = NULL; | |
556 | } | |
557 | } | |
558 | OBD_CHECK_DT_OP(obd, cleanup, 0); | |
559 | OBD_COUNTER_INCREMENT(obd, cleanup); | |
560 | ||
561 | rc = OBP(obd, cleanup)(obd); | |
0a3bdb00 | 562 | return rc; |
d7e09d03 PT |
563 | } |
564 | ||
565 | static inline void obd_cleanup_client_import(struct obd_device *obd) | |
566 | { | |
d7e09d03 | 567 | /* If we set up but never connected, the |
c56e256d OD |
568 | * client import will not have been cleaned. |
569 | */ | |
d7e09d03 PT |
570 | down_write(&obd->u.cli.cl_sem); |
571 | if (obd->u.cli.cl_import) { | |
572 | struct obd_import *imp; | |
50ffcb7e | 573 | |
d7e09d03 PT |
574 | imp = obd->u.cli.cl_import; |
575 | CDEBUG(D_CONFIG, "%s: client import never connected\n", | |
576 | obd->obd_name); | |
577 | ptlrpc_invalidate_import(imp); | |
d7e09d03 PT |
578 | client_destroy_import(imp); |
579 | obd->u.cli.cl_import = NULL; | |
580 | } | |
581 | up_write(&obd->u.cli.cl_sem); | |
d7e09d03 PT |
582 | } |
583 | ||
584 | static inline int | |
585 | obd_process_config(struct obd_device *obd, int datalen, void *data) | |
586 | { | |
587 | int rc; | |
588 | DECLARE_LU_VARS(ldt, d); | |
d7e09d03 | 589 | |
4ca1b8fb AM |
590 | rc = obd_check_dev(obd); |
591 | if (rc) | |
592 | return rc; | |
d7e09d03 PT |
593 | |
594 | obd->obd_process_conf = 1; | |
595 | ldt = obd->obd_type->typ_lu; | |
596 | d = obd->obd_lu_dev; | |
d2a13989 | 597 | if (ldt && d) { |
d7e09d03 PT |
598 | struct lu_env env; |
599 | ||
600 | rc = lu_env_init(&env, ldt->ldt_ctx_tags); | |
601 | if (rc == 0) { | |
602 | rc = d->ld_ops->ldo_process_config(&env, d, data); | |
603 | lu_env_fini(&env); | |
604 | } | |
605 | } else { | |
606 | OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP); | |
607 | rc = OBP(obd, process_config)(obd, datalen, data); | |
608 | } | |
609 | OBD_COUNTER_INCREMENT(obd, process_config); | |
610 | obd->obd_process_conf = 0; | |
611 | ||
0a3bdb00 | 612 | return rc; |
d7e09d03 PT |
613 | } |
614 | ||
615 | /* Pack an in-memory MD struct for storage on disk. | |
616 | * Returns +ve size of packed MD (0 for free), or -ve error. | |
617 | * | |
618 | * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL). | |
619 | * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed. | |
620 | * If @*disk_tgt == NULL, it will be allocated | |
621 | */ | |
622 | static inline int obd_packmd(struct obd_export *exp, | |
623 | struct lov_mds_md **disk_tgt, | |
624 | struct lov_stripe_md *mem_src) | |
625 | { | |
626 | int rc; | |
d7e09d03 PT |
627 | |
628 | EXP_CHECK_DT_OP(exp, packmd); | |
629 | EXP_COUNTER_INCREMENT(exp, packmd); | |
630 | ||
631 | rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src); | |
0a3bdb00 | 632 | return rc; |
d7e09d03 PT |
633 | } |
634 | ||
635 | static inline int obd_size_diskmd(struct obd_export *exp, | |
636 | struct lov_stripe_md *mem_src) | |
637 | { | |
638 | return obd_packmd(exp, NULL, mem_src); | |
639 | } | |
640 | ||
d7e09d03 PT |
641 | static inline int obd_free_diskmd(struct obd_export *exp, |
642 | struct lov_mds_md **disk_tgt) | |
643 | { | |
644 | LASSERT(disk_tgt); | |
645 | LASSERT(*disk_tgt); | |
646 | /* | |
647 | * LU-2590, for caller's convenience, *disk_tgt could be host | |
648 | * endianness, it needs swab to LE if necessary, while just | |
649 | * lov_mds_md header needs it for figuring out how much memory | |
650 | * needs to be freed. | |
651 | */ | |
652 | if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) && | |
653 | (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) || | |
654 | ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3))) | |
655 | lustre_swab_lov_mds_md(*disk_tgt); | |
656 | return obd_packmd(exp, disk_tgt, NULL); | |
657 | } | |
658 | ||
659 | /* Unpack an MD struct from disk to in-memory format. | |
660 | * Returns +ve size of unpacked MD (0 for free), or -ve error. | |
661 | * | |
662 | * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL). | |
663 | * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed. | |
664 | * If @*mem_tgt == NULL, it will be allocated | |
665 | */ | |
666 | static inline int obd_unpackmd(struct obd_export *exp, | |
667 | struct lov_stripe_md **mem_tgt, | |
668 | struct lov_mds_md *disk_src, | |
669 | int disk_len) | |
670 | { | |
671 | int rc; | |
d7e09d03 PT |
672 | |
673 | EXP_CHECK_DT_OP(exp, unpackmd); | |
674 | EXP_COUNTER_INCREMENT(exp, unpackmd); | |
675 | ||
676 | rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len); | |
0a3bdb00 | 677 | return rc; |
d7e09d03 PT |
678 | } |
679 | ||
680 | /* helper functions */ | |
681 | static inline int obd_alloc_memmd(struct obd_export *exp, | |
682 | struct lov_stripe_md **mem_tgt) | |
683 | { | |
684 | LASSERT(mem_tgt); | |
d2a13989 | 685 | LASSERT(!*mem_tgt); |
d7e09d03 PT |
686 | return obd_unpackmd(exp, mem_tgt, NULL, 0); |
687 | } | |
688 | ||
689 | static inline int obd_free_memmd(struct obd_export *exp, | |
690 | struct lov_stripe_md **mem_tgt) | |
691 | { | |
692 | int rc; | |
693 | ||
694 | LASSERT(mem_tgt); | |
695 | LASSERT(*mem_tgt); | |
696 | rc = obd_unpackmd(exp, mem_tgt, NULL, 0); | |
697 | *mem_tgt = NULL; | |
698 | return rc; | |
699 | } | |
700 | ||
d7e09d03 PT |
701 | static inline int obd_create(const struct lu_env *env, struct obd_export *exp, |
702 | struct obdo *obdo, struct lov_stripe_md **ea, | |
703 | struct obd_trans_info *oti) | |
704 | { | |
705 | int rc; | |
d7e09d03 PT |
706 | |
707 | EXP_CHECK_DT_OP(exp, create); | |
708 | EXP_COUNTER_INCREMENT(exp, create); | |
709 | ||
710 | rc = OBP(exp->exp_obd, create)(env, exp, obdo, ea, oti); | |
0a3bdb00 | 711 | return rc; |
d7e09d03 PT |
712 | } |
713 | ||
714 | static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp, | |
715 | struct obdo *obdo, struct lov_stripe_md *ea, | |
716 | struct obd_trans_info *oti, | |
ef2e0f55 | 717 | struct obd_export *md_exp) |
d7e09d03 PT |
718 | { |
719 | int rc; | |
d7e09d03 PT |
720 | |
721 | EXP_CHECK_DT_OP(exp, destroy); | |
722 | EXP_COUNTER_INCREMENT(exp, destroy); | |
723 | ||
ef2e0f55 | 724 | rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp); |
0a3bdb00 | 725 | return rc; |
d7e09d03 PT |
726 | } |
727 | ||
728 | static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp, | |
729 | struct obd_info *oinfo) | |
730 | { | |
731 | int rc; | |
d7e09d03 PT |
732 | |
733 | EXP_CHECK_DT_OP(exp, getattr); | |
734 | EXP_COUNTER_INCREMENT(exp, getattr); | |
735 | ||
736 | rc = OBP(exp->exp_obd, getattr)(env, exp, oinfo); | |
0a3bdb00 | 737 | return rc; |
d7e09d03 PT |
738 | } |
739 | ||
740 | static inline int obd_getattr_async(struct obd_export *exp, | |
741 | struct obd_info *oinfo, | |
742 | struct ptlrpc_request_set *set) | |
743 | { | |
744 | int rc; | |
d7e09d03 PT |
745 | |
746 | EXP_CHECK_DT_OP(exp, getattr_async); | |
747 | EXP_COUNTER_INCREMENT(exp, getattr_async); | |
748 | ||
749 | rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set); | |
0a3bdb00 | 750 | return rc; |
d7e09d03 PT |
751 | } |
752 | ||
753 | static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp, | |
754 | struct obd_info *oinfo, | |
755 | struct obd_trans_info *oti) | |
756 | { | |
757 | int rc; | |
d7e09d03 PT |
758 | |
759 | EXP_CHECK_DT_OP(exp, setattr); | |
760 | EXP_COUNTER_INCREMENT(exp, setattr); | |
761 | ||
762 | rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti); | |
0a3bdb00 | 763 | return rc; |
d7e09d03 PT |
764 | } |
765 | ||
766 | /* This performs all the requests set init/wait/destroy actions. */ | |
767 | static inline int obd_setattr_rqset(struct obd_export *exp, | |
768 | struct obd_info *oinfo, | |
769 | struct obd_trans_info *oti) | |
770 | { | |
771 | struct ptlrpc_request_set *set = NULL; | |
772 | int rc; | |
d7e09d03 PT |
773 | |
774 | EXP_CHECK_DT_OP(exp, setattr_async); | |
775 | EXP_COUNTER_INCREMENT(exp, setattr_async); | |
776 | ||
777 | set = ptlrpc_prep_set(); | |
d2a13989 | 778 | if (!set) |
0a3bdb00 | 779 | return -ENOMEM; |
d7e09d03 PT |
780 | |
781 | rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set); | |
782 | if (rc == 0) | |
783 | rc = ptlrpc_set_wait(set); | |
784 | ptlrpc_set_destroy(set); | |
0a3bdb00 | 785 | return rc; |
d7e09d03 PT |
786 | } |
787 | ||
788 | /* This adds all the requests into @set if @set != NULL, otherwise | |
c56e256d OD |
789 | * all requests are sent asynchronously without waiting for response. |
790 | */ | |
d7e09d03 PT |
791 | static inline int obd_setattr_async(struct obd_export *exp, |
792 | struct obd_info *oinfo, | |
793 | struct obd_trans_info *oti, | |
794 | struct ptlrpc_request_set *set) | |
795 | { | |
796 | int rc; | |
d7e09d03 PT |
797 | |
798 | EXP_CHECK_DT_OP(exp, setattr_async); | |
799 | EXP_COUNTER_INCREMENT(exp, setattr_async); | |
800 | ||
801 | rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set); | |
0a3bdb00 | 802 | return rc; |
d7e09d03 PT |
803 | } |
804 | ||
805 | static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid, | |
806 | int priority) | |
807 | { | |
808 | struct obd_device *obd = imp->imp_obd; | |
809 | int rc; | |
d7e09d03 | 810 | |
f36b6553 AM |
811 | rc = obd_check_dev_active(obd); |
812 | if (rc) | |
813 | return rc; | |
d7e09d03 PT |
814 | OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP); |
815 | OBD_COUNTER_INCREMENT(obd, add_conn); | |
816 | ||
817 | rc = OBP(obd, add_conn)(imp, uuid, priority); | |
0a3bdb00 | 818 | return rc; |
d7e09d03 PT |
819 | } |
820 | ||
821 | static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid) | |
822 | { | |
823 | struct obd_device *obd = imp->imp_obd; | |
824 | int rc; | |
d7e09d03 | 825 | |
f36b6553 AM |
826 | rc = obd_check_dev_active(obd); |
827 | if (rc) | |
828 | return rc; | |
d7e09d03 PT |
829 | OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP); |
830 | OBD_COUNTER_INCREMENT(obd, del_conn); | |
831 | ||
832 | rc = OBP(obd, del_conn)(imp, uuid); | |
0a3bdb00 | 833 | return rc; |
d7e09d03 PT |
834 | } |
835 | ||
836 | static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp) | |
837 | { | |
838 | struct obd_uuid *uuid; | |
d7e09d03 PT |
839 | |
840 | OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL); | |
841 | EXP_COUNTER_INCREMENT(exp, get_uuid); | |
842 | ||
843 | uuid = OBP(exp->exp_obd, get_uuid)(exp); | |
0a3bdb00 | 844 | return uuid; |
d7e09d03 PT |
845 | } |
846 | ||
847 | /** Create a new /a exp on device /a obd for the uuid /a cluuid | |
848 | * @param exp New export handle | |
849 | * @param d Connect data, supported flags are set, flags also understood | |
850 | * by obd are returned. | |
851 | */ | |
852 | static inline int obd_connect(const struct lu_env *env, | |
1d8cb70c | 853 | struct obd_export **exp, struct obd_device *obd, |
d7e09d03 PT |
854 | struct obd_uuid *cluuid, |
855 | struct obd_connect_data *data, | |
856 | void *localdata) | |
857 | { | |
858 | int rc; | |
859 | __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition | |
c56e256d OD |
860 | * check |
861 | */ | |
d7e09d03 | 862 | |
f36b6553 AM |
863 | rc = obd_check_dev_active(obd); |
864 | if (rc) | |
865 | return rc; | |
d7e09d03 PT |
866 | OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP); |
867 | OBD_COUNTER_INCREMENT(obd, connect); | |
868 | ||
869 | rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata); | |
870 | /* check that only subset is granted */ | |
d2a13989 | 871 | LASSERT(ergo(data, (data->ocd_connect_flags & ocf) == |
d7e09d03 | 872 | data->ocd_connect_flags)); |
0a3bdb00 | 873 | return rc; |
d7e09d03 PT |
874 | } |
875 | ||
876 | static inline int obd_reconnect(const struct lu_env *env, | |
877 | struct obd_export *exp, | |
878 | struct obd_device *obd, | |
879 | struct obd_uuid *cluuid, | |
880 | struct obd_connect_data *d, | |
881 | void *localdata) | |
882 | { | |
883 | int rc; | |
c56e256d | 884 | __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */ |
d7e09d03 | 885 | |
f36b6553 AM |
886 | rc = obd_check_dev_active(obd); |
887 | if (rc) | |
888 | return rc; | |
d7e09d03 PT |
889 | OBD_CHECK_DT_OP(obd, reconnect, 0); |
890 | OBD_COUNTER_INCREMENT(obd, reconnect); | |
891 | ||
892 | rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata); | |
893 | /* check that only subset is granted */ | |
d2a13989 | 894 | LASSERT(ergo(d, (d->ocd_connect_flags & ocf) == d->ocd_connect_flags)); |
0a3bdb00 | 895 | return rc; |
d7e09d03 PT |
896 | } |
897 | ||
898 | static inline int obd_disconnect(struct obd_export *exp) | |
899 | { | |
900 | int rc; | |
d7e09d03 PT |
901 | |
902 | EXP_CHECK_DT_OP(exp, disconnect); | |
903 | EXP_COUNTER_INCREMENT(exp, disconnect); | |
904 | ||
905 | rc = OBP(exp->exp_obd, disconnect)(exp); | |
0a3bdb00 | 906 | return rc; |
d7e09d03 PT |
907 | } |
908 | ||
909 | static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp, | |
910 | enum lu_cli_type type) | |
911 | { | |
912 | int rc; | |
d7e09d03 PT |
913 | |
914 | OBD_CHECK_DT_OP(obd, fid_init, 0); | |
915 | OBD_COUNTER_INCREMENT(obd, fid_init); | |
916 | ||
917 | rc = OBP(obd, fid_init)(obd, exp, type); | |
0a3bdb00 | 918 | return rc; |
d7e09d03 PT |
919 | } |
920 | ||
921 | static inline int obd_fid_fini(struct obd_device *obd) | |
922 | { | |
923 | int rc; | |
d7e09d03 PT |
924 | |
925 | OBD_CHECK_DT_OP(obd, fid_fini, 0); | |
926 | OBD_COUNTER_INCREMENT(obd, fid_fini); | |
927 | ||
928 | rc = OBP(obd, fid_fini)(obd); | |
0a3bdb00 | 929 | return rc; |
d7e09d03 PT |
930 | } |
931 | ||
8f18c8a4 | 932 | static inline int obd_fid_alloc(const struct lu_env *env, |
933 | struct obd_export *exp, | |
d7e09d03 PT |
934 | struct lu_fid *fid, |
935 | struct md_op_data *op_data) | |
936 | { | |
937 | int rc; | |
d7e09d03 PT |
938 | |
939 | EXP_CHECK_DT_OP(exp, fid_alloc); | |
940 | EXP_COUNTER_INCREMENT(exp, fid_alloc); | |
941 | ||
8f18c8a4 | 942 | rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data); |
0a3bdb00 | 943 | return rc; |
d7e09d03 PT |
944 | } |
945 | ||
d7e09d03 PT |
946 | static inline int obd_pool_new(struct obd_device *obd, char *poolname) |
947 | { | |
948 | int rc; | |
d7e09d03 PT |
949 | |
950 | OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP); | |
951 | OBD_COUNTER_INCREMENT(obd, pool_new); | |
952 | ||
953 | rc = OBP(obd, pool_new)(obd, poolname); | |
0a3bdb00 | 954 | return rc; |
d7e09d03 PT |
955 | } |
956 | ||
957 | static inline int obd_pool_del(struct obd_device *obd, char *poolname) | |
958 | { | |
959 | int rc; | |
d7e09d03 PT |
960 | |
961 | OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP); | |
962 | OBD_COUNTER_INCREMENT(obd, pool_del); | |
963 | ||
964 | rc = OBP(obd, pool_del)(obd, poolname); | |
0a3bdb00 | 965 | return rc; |
d7e09d03 PT |
966 | } |
967 | ||
968 | static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname) | |
969 | { | |
970 | int rc; | |
d7e09d03 PT |
971 | |
972 | OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP); | |
973 | OBD_COUNTER_INCREMENT(obd, pool_add); | |
974 | ||
975 | rc = OBP(obd, pool_add)(obd, poolname, ostname); | |
0a3bdb00 | 976 | return rc; |
d7e09d03 PT |
977 | } |
978 | ||
979 | static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname) | |
980 | { | |
981 | int rc; | |
d7e09d03 PT |
982 | |
983 | OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP); | |
984 | OBD_COUNTER_INCREMENT(obd, pool_rem); | |
985 | ||
986 | rc = OBP(obd, pool_rem)(obd, poolname, ostname); | |
0a3bdb00 | 987 | return rc; |
d7e09d03 PT |
988 | } |
989 | ||
990 | static inline void obd_getref(struct obd_device *obd) | |
991 | { | |
d7e09d03 PT |
992 | if (OBT(obd) && OBP(obd, getref)) { |
993 | OBD_COUNTER_INCREMENT(obd, getref); | |
994 | OBP(obd, getref)(obd); | |
995 | } | |
d7e09d03 PT |
996 | } |
997 | ||
998 | static inline void obd_putref(struct obd_device *obd) | |
999 | { | |
d7e09d03 PT |
1000 | if (OBT(obd) && OBP(obd, putref)) { |
1001 | OBD_COUNTER_INCREMENT(obd, putref); | |
1002 | OBP(obd, putref)(obd); | |
1003 | } | |
d7e09d03 PT |
1004 | } |
1005 | ||
1006 | static inline int obd_init_export(struct obd_export *exp) | |
1007 | { | |
1008 | int rc = 0; | |
1009 | ||
d2a13989 | 1010 | if ((exp)->exp_obd && OBT((exp)->exp_obd) && |
d7e09d03 PT |
1011 | OBP((exp)->exp_obd, init_export)) |
1012 | rc = OBP(exp->exp_obd, init_export)(exp); | |
0a3bdb00 | 1013 | return rc; |
d7e09d03 PT |
1014 | } |
1015 | ||
1016 | static inline int obd_destroy_export(struct obd_export *exp) | |
1017 | { | |
d2a13989 | 1018 | if ((exp)->exp_obd && OBT((exp)->exp_obd) && |
d7e09d03 PT |
1019 | OBP((exp)->exp_obd, destroy_export)) |
1020 | OBP(exp->exp_obd, destroy_export)(exp); | |
0a3bdb00 | 1021 | return 0; |
d7e09d03 PT |
1022 | } |
1023 | ||
d7e09d03 PT |
1024 | /* @max_age is the oldest time in jiffies that we accept using a cached data. |
1025 | * If the cache is older than @max_age we will get a new value from the | |
c56e256d OD |
1026 | * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. |
1027 | */ | |
d7e09d03 PT |
1028 | static inline int obd_statfs_async(struct obd_export *exp, |
1029 | struct obd_info *oinfo, | |
1030 | __u64 max_age, | |
1031 | struct ptlrpc_request_set *rqset) | |
1032 | { | |
1033 | int rc = 0; | |
1034 | struct obd_device *obd; | |
d7e09d03 | 1035 | |
d2a13989 | 1036 | if (!exp || !exp->exp_obd) |
0a3bdb00 | 1037 | return -EINVAL; |
d7e09d03 PT |
1038 | |
1039 | obd = exp->exp_obd; | |
1040 | OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP); | |
1041 | OBD_COUNTER_INCREMENT(obd, statfs); | |
1042 | ||
b0f5aad5 | 1043 | CDEBUG(D_SUPER, "%s: osfs %p age %llu, max_age %llu\n", |
d7e09d03 PT |
1044 | obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age); |
1045 | if (cfs_time_before_64(obd->obd_osfs_age, max_age)) { | |
1046 | rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset); | |
1047 | } else { | |
1d8cb70c GD |
1048 | CDEBUG(D_SUPER, |
1049 | "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n", | |
d7e09d03 PT |
1050 | obd->obd_name, &obd->obd_osfs, |
1051 | obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks, | |
1052 | obd->obd_osfs.os_ffree, obd->obd_osfs.os_files); | |
1053 | spin_lock(&obd->obd_osfs_lock); | |
1054 | memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs)); | |
1055 | spin_unlock(&obd->obd_osfs_lock); | |
1056 | oinfo->oi_flags |= OBD_STATFS_FROM_CACHE; | |
1057 | if (oinfo->oi_cb_up) | |
1058 | oinfo->oi_cb_up(oinfo, 0); | |
1059 | } | |
0a3bdb00 | 1060 | return rc; |
d7e09d03 PT |
1061 | } |
1062 | ||
1063 | static inline int obd_statfs_rqset(struct obd_export *exp, | |
1064 | struct obd_statfs *osfs, __u64 max_age, | |
1065 | __u32 flags) | |
1066 | { | |
1067 | struct ptlrpc_request_set *set = NULL; | |
45efd655 | 1068 | struct obd_info oinfo = { }; |
d7e09d03 | 1069 | int rc = 0; |
d7e09d03 PT |
1070 | |
1071 | set = ptlrpc_prep_set(); | |
d2a13989 | 1072 | if (!set) |
0a3bdb00 | 1073 | return -ENOMEM; |
d7e09d03 PT |
1074 | |
1075 | oinfo.oi_osfs = osfs; | |
1076 | oinfo.oi_flags = flags; | |
1077 | rc = obd_statfs_async(exp, &oinfo, max_age, set); | |
1078 | if (rc == 0) | |
1079 | rc = ptlrpc_set_wait(set); | |
1080 | ptlrpc_set_destroy(set); | |
0a3bdb00 | 1081 | return rc; |
d7e09d03 PT |
1082 | } |
1083 | ||
1084 | /* @max_age is the oldest time in jiffies that we accept using a cached data. | |
1085 | * If the cache is older than @max_age we will get a new value from the | |
c56e256d OD |
1086 | * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. |
1087 | */ | |
d7e09d03 PT |
1088 | static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp, |
1089 | struct obd_statfs *osfs, __u64 max_age, | |
1090 | __u32 flags) | |
1091 | { | |
1092 | int rc = 0; | |
1093 | struct obd_device *obd = exp->exp_obd; | |
d7e09d03 | 1094 | |
d2a13989 | 1095 | if (!obd) |
0a3bdb00 | 1096 | return -EINVAL; |
d7e09d03 PT |
1097 | |
1098 | OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP); | |
1099 | OBD_COUNTER_INCREMENT(obd, statfs); | |
1100 | ||
b0f5aad5 | 1101 | CDEBUG(D_SUPER, "osfs %llu, max_age %llu\n", |
d7e09d03 PT |
1102 | obd->obd_osfs_age, max_age); |
1103 | if (cfs_time_before_64(obd->obd_osfs_age, max_age)) { | |
1104 | rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags); | |
1105 | if (rc == 0) { | |
1106 | spin_lock(&obd->obd_osfs_lock); | |
1107 | memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs)); | |
1108 | obd->obd_osfs_age = cfs_time_current_64(); | |
1109 | spin_unlock(&obd->obd_osfs_lock); | |
1110 | } | |
1111 | } else { | |
b0f5aad5 | 1112 | CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n", |
d7e09d03 PT |
1113 | obd->obd_name, &obd->obd_osfs, |
1114 | obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks, | |
1115 | obd->obd_osfs.os_ffree, obd->obd_osfs.os_files); | |
1116 | spin_lock(&obd->obd_osfs_lock); | |
1117 | memcpy(osfs, &obd->obd_osfs, sizeof(*osfs)); | |
1118 | spin_unlock(&obd->obd_osfs_lock); | |
1119 | } | |
0a3bdb00 | 1120 | return rc; |
d7e09d03 PT |
1121 | } |
1122 | ||
d7e09d03 PT |
1123 | static inline int obd_preprw(const struct lu_env *env, int cmd, |
1124 | struct obd_export *exp, struct obdo *oa, | |
1125 | int objcount, struct obd_ioobj *obj, | |
1126 | struct niobuf_remote *remote, int *pages, | |
1127 | struct niobuf_local *local, | |
ef2e0f55 | 1128 | struct obd_trans_info *oti) |
d7e09d03 PT |
1129 | { |
1130 | int rc; | |
d7e09d03 PT |
1131 | |
1132 | EXP_CHECK_DT_OP(exp, preprw); | |
1133 | EXP_COUNTER_INCREMENT(exp, preprw); | |
1134 | ||
1135 | rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote, | |
ef2e0f55 | 1136 | pages, local, oti); |
0a3bdb00 | 1137 | return rc; |
d7e09d03 PT |
1138 | } |
1139 | ||
1140 | static inline int obd_commitrw(const struct lu_env *env, int cmd, | |
1141 | struct obd_export *exp, struct obdo *oa, | |
1142 | int objcount, struct obd_ioobj *obj, | |
1143 | struct niobuf_remote *rnb, int pages, | |
1144 | struct niobuf_local *local, | |
1145 | struct obd_trans_info *oti, int rc) | |
1146 | { | |
d7e09d03 PT |
1147 | EXP_CHECK_DT_OP(exp, commitrw); |
1148 | EXP_COUNTER_INCREMENT(exp, commitrw); | |
1149 | ||
1150 | rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj, | |
1151 | rnb, pages, local, oti, rc); | |
0a3bdb00 | 1152 | return rc; |
d7e09d03 PT |
1153 | } |
1154 | ||
d7e09d03 | 1155 | static inline int obd_adjust_kms(struct obd_export *exp, |
21aef7d9 | 1156 | struct lov_stripe_md *lsm, u64 size, |
d7e09d03 PT |
1157 | int shrink) |
1158 | { | |
1159 | int rc; | |
d7e09d03 PT |
1160 | |
1161 | EXP_CHECK_DT_OP(exp, adjust_kms); | |
1162 | EXP_COUNTER_INCREMENT(exp, adjust_kms); | |
1163 | ||
1164 | rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink); | |
0a3bdb00 | 1165 | return rc; |
d7e09d03 PT |
1166 | } |
1167 | ||
1168 | static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp, | |
e09bee34 | 1169 | int len, void *karg, void __user *uarg) |
d7e09d03 PT |
1170 | { |
1171 | int rc; | |
d7e09d03 PT |
1172 | |
1173 | EXP_CHECK_DT_OP(exp, iocontrol); | |
1174 | EXP_COUNTER_INCREMENT(exp, iocontrol); | |
1175 | ||
1176 | rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg); | |
0a3bdb00 | 1177 | return rc; |
d7e09d03 PT |
1178 | } |
1179 | ||
d7e09d03 PT |
1180 | static inline void obd_import_event(struct obd_device *obd, |
1181 | struct obd_import *imp, | |
1182 | enum obd_import_event event) | |
1183 | { | |
d7e09d03 PT |
1184 | if (!obd) { |
1185 | CERROR("NULL device\n"); | |
d7e09d03 PT |
1186 | return; |
1187 | } | |
1188 | if (obd->obd_set_up && OBP(obd, import_event)) { | |
1189 | OBD_COUNTER_INCREMENT(obd, import_event); | |
1190 | OBP(obd, import_event)(obd, imp, event); | |
1191 | } | |
d7e09d03 PT |
1192 | } |
1193 | ||
d7e09d03 PT |
1194 | static inline int obd_notify(struct obd_device *obd, |
1195 | struct obd_device *watched, | |
1196 | enum obd_notify_event ev, | |
1197 | void *data) | |
1198 | { | |
1199 | int rc; | |
29aaf496 | 1200 | |
4ca1b8fb AM |
1201 | rc = obd_check_dev(obd); |
1202 | if (rc) | |
1203 | return rc; | |
d7e09d03 | 1204 | |
58c78cd2 | 1205 | if (!obd->obd_set_up) { |
d7e09d03 | 1206 | CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name); |
0a3bdb00 | 1207 | return -EINVAL; |
d7e09d03 PT |
1208 | } |
1209 | ||
1210 | if (!OBP(obd, notify)) { | |
1211 | CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name); | |
0a3bdb00 | 1212 | return -ENOSYS; |
d7e09d03 PT |
1213 | } |
1214 | ||
1215 | OBD_COUNTER_INCREMENT(obd, notify); | |
1216 | rc = OBP(obd, notify)(obd, watched, ev, data); | |
0a3bdb00 | 1217 | return rc; |
d7e09d03 PT |
1218 | } |
1219 | ||
1220 | static inline int obd_notify_observer(struct obd_device *observer, | |
1221 | struct obd_device *observed, | |
1222 | enum obd_notify_event ev, | |
1223 | void *data) | |
1224 | { | |
1225 | int rc1; | |
1226 | int rc2; | |
1227 | ||
1228 | struct obd_notify_upcall *onu; | |
1229 | ||
1230 | if (observer->obd_observer) | |
1231 | rc1 = obd_notify(observer->obd_observer, observed, ev, data); | |
1232 | else | |
1233 | rc1 = 0; | |
1234 | /* | |
1235 | * Also, call non-obd listener, if any | |
1236 | */ | |
1237 | onu = &observer->obd_upcall; | |
d2a13989 | 1238 | if (onu->onu_upcall) |
d7e09d03 PT |
1239 | rc2 = onu->onu_upcall(observer, observed, ev, |
1240 | onu->onu_owner, NULL); | |
1241 | else | |
1242 | rc2 = 0; | |
1243 | ||
1244 | return rc1 ? rc1 : rc2; | |
1245 | } | |
1246 | ||
1247 | static inline int obd_quotacheck(struct obd_export *exp, | |
1248 | struct obd_quotactl *oqctl) | |
1249 | { | |
1250 | int rc; | |
d7e09d03 PT |
1251 | |
1252 | EXP_CHECK_DT_OP(exp, quotacheck); | |
1253 | EXP_COUNTER_INCREMENT(exp, quotacheck); | |
1254 | ||
1255 | rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl); | |
0a3bdb00 | 1256 | return rc; |
d7e09d03 PT |
1257 | } |
1258 | ||
1259 | static inline int obd_quotactl(struct obd_export *exp, | |
1260 | struct obd_quotactl *oqctl) | |
1261 | { | |
1262 | int rc; | |
d7e09d03 PT |
1263 | |
1264 | EXP_CHECK_DT_OP(exp, quotactl); | |
1265 | EXP_COUNTER_INCREMENT(exp, quotactl); | |
1266 | ||
1267 | rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl); | |
0a3bdb00 | 1268 | return rc; |
d7e09d03 PT |
1269 | } |
1270 | ||
1271 | static inline int obd_health_check(const struct lu_env *env, | |
1272 | struct obd_device *obd) | |
1273 | { | |
1274 | /* returns: 0 on healthy | |
1275 | * >0 on unhealthy + reason code/flag | |
bd9070cb | 1276 | * however the only supported reason == 1 right now |
d7e09d03 PT |
1277 | * We'll need to define some better reasons |
1278 | * or flags in the future. | |
1279 | * <0 on error | |
1280 | */ | |
1281 | int rc; | |
d7e09d03 PT |
1282 | |
1283 | /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */ | |
d2a13989 | 1284 | if (!obd || !OBT(obd)) { |
d7e09d03 | 1285 | CERROR("cleaned up obd\n"); |
0a3bdb00 | 1286 | return -EOPNOTSUPP; |
d7e09d03 PT |
1287 | } |
1288 | if (!obd->obd_set_up || obd->obd_stopping) | |
0a3bdb00 | 1289 | return 0; |
d7e09d03 | 1290 | if (!OBP(obd, health_check)) |
0a3bdb00 | 1291 | return 0; |
d7e09d03 PT |
1292 | |
1293 | rc = OBP(obd, health_check)(env, obd); | |
0a3bdb00 | 1294 | return rc; |
d7e09d03 PT |
1295 | } |
1296 | ||
1297 | static inline int obd_register_observer(struct obd_device *obd, | |
1298 | struct obd_device *observer) | |
1299 | { | |
4ca1b8fb AM |
1300 | int rc; |
1301 | ||
1302 | rc = obd_check_dev(obd); | |
1303 | if (rc) | |
1304 | return rc; | |
d7e09d03 PT |
1305 | down_write(&obd->obd_observer_link_sem); |
1306 | if (obd->obd_observer && observer) { | |
1307 | up_write(&obd->obd_observer_link_sem); | |
0a3bdb00 | 1308 | return -EALREADY; |
d7e09d03 PT |
1309 | } |
1310 | obd->obd_observer = observer; | |
1311 | up_write(&obd->obd_observer_link_sem); | |
0a3bdb00 | 1312 | return 0; |
d7e09d03 PT |
1313 | } |
1314 | ||
d7e09d03 | 1315 | /* metadata helpers */ |
ef2e0f55 | 1316 | static inline int md_getstatus(struct obd_export *exp, struct lu_fid *fid) |
d7e09d03 PT |
1317 | { |
1318 | int rc; | |
d7e09d03 PT |
1319 | |
1320 | EXP_CHECK_MD_OP(exp, getstatus); | |
1321 | EXP_MD_COUNTER_INCREMENT(exp, getstatus); | |
ef2e0f55 | 1322 | rc = MDP(exp->exp_obd, getstatus)(exp, fid); |
0a3bdb00 | 1323 | return rc; |
d7e09d03 PT |
1324 | } |
1325 | ||
1326 | static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data, | |
1327 | struct ptlrpc_request **request) | |
1328 | { | |
1329 | int rc; | |
29aaf496 | 1330 | |
d7e09d03 PT |
1331 | EXP_CHECK_MD_OP(exp, getattr); |
1332 | EXP_MD_COUNTER_INCREMENT(exp, getattr); | |
1333 | rc = MDP(exp->exp_obd, getattr)(exp, op_data, request); | |
0a3bdb00 | 1334 | return rc; |
d7e09d03 PT |
1335 | } |
1336 | ||
1337 | static inline int md_null_inode(struct obd_export *exp, | |
10457d4b | 1338 | const struct lu_fid *fid) |
d7e09d03 PT |
1339 | { |
1340 | int rc; | |
29aaf496 | 1341 | |
d7e09d03 PT |
1342 | EXP_CHECK_MD_OP(exp, null_inode); |
1343 | EXP_MD_COUNTER_INCREMENT(exp, null_inode); | |
1344 | rc = MDP(exp->exp_obd, null_inode)(exp, fid); | |
0a3bdb00 | 1345 | return rc; |
d7e09d03 PT |
1346 | } |
1347 | ||
d7e09d03 PT |
1348 | static inline int md_close(struct obd_export *exp, struct md_op_data *op_data, |
1349 | struct md_open_data *mod, | |
1350 | struct ptlrpc_request **request) | |
1351 | { | |
1352 | int rc; | |
29aaf496 | 1353 | |
d7e09d03 PT |
1354 | EXP_CHECK_MD_OP(exp, close); |
1355 | EXP_MD_COUNTER_INCREMENT(exp, close); | |
1356 | rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request); | |
0a3bdb00 | 1357 | return rc; |
d7e09d03 PT |
1358 | } |
1359 | ||
1360 | static inline int md_create(struct obd_export *exp, struct md_op_data *op_data, | |
1361 | const void *data, int datalen, int mode, __u32 uid, | |
1362 | __u32 gid, cfs_cap_t cap_effective, __u64 rdev, | |
1363 | struct ptlrpc_request **request) | |
1364 | { | |
1365 | int rc; | |
29aaf496 | 1366 | |
d7e09d03 PT |
1367 | EXP_CHECK_MD_OP(exp, create); |
1368 | EXP_MD_COUNTER_INCREMENT(exp, create); | |
1369 | rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode, | |
1370 | uid, gid, cap_effective, rdev, request); | |
0a3bdb00 | 1371 | return rc; |
d7e09d03 PT |
1372 | } |
1373 | ||
1374 | static inline int md_done_writing(struct obd_export *exp, | |
1375 | struct md_op_data *op_data, | |
1376 | struct md_open_data *mod) | |
1377 | { | |
1378 | int rc; | |
29aaf496 | 1379 | |
d7e09d03 PT |
1380 | EXP_CHECK_MD_OP(exp, done_writing); |
1381 | EXP_MD_COUNTER_INCREMENT(exp, done_writing); | |
1382 | rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod); | |
0a3bdb00 | 1383 | return rc; |
d7e09d03 PT |
1384 | } |
1385 | ||
1386 | static inline int md_enqueue(struct obd_export *exp, | |
1387 | struct ldlm_enqueue_info *einfo, | |
70a251f6 | 1388 | const ldlm_policy_data_t *policy, |
d7e09d03 PT |
1389 | struct lookup_intent *it, |
1390 | struct md_op_data *op_data, | |
1391 | struct lustre_handle *lockh, | |
875332d4 | 1392 | __u64 extra_lock_flags) |
d7e09d03 PT |
1393 | { |
1394 | int rc; | |
29aaf496 | 1395 | |
d7e09d03 PT |
1396 | EXP_CHECK_MD_OP(exp, enqueue); |
1397 | EXP_MD_COUNTER_INCREMENT(exp, enqueue); | |
70a251f6 JH |
1398 | rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, it, op_data, lockh, |
1399 | extra_lock_flags); | |
0a3bdb00 | 1400 | return rc; |
d7e09d03 PT |
1401 | } |
1402 | ||
1403 | static inline int md_getattr_name(struct obd_export *exp, | |
1404 | struct md_op_data *op_data, | |
1405 | struct ptlrpc_request **request) | |
1406 | { | |
1407 | int rc; | |
29aaf496 | 1408 | |
d7e09d03 PT |
1409 | EXP_CHECK_MD_OP(exp, getattr_name); |
1410 | EXP_MD_COUNTER_INCREMENT(exp, getattr_name); | |
1411 | rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request); | |
0a3bdb00 | 1412 | return rc; |
d7e09d03 PT |
1413 | } |
1414 | ||
1415 | static inline int md_intent_lock(struct obd_export *exp, | |
70a251f6 JH |
1416 | struct md_op_data *op_data, |
1417 | struct lookup_intent *it, | |
1418 | struct ptlrpc_request **reqp, | |
d7e09d03 PT |
1419 | ldlm_blocking_callback cb_blocking, |
1420 | __u64 extra_lock_flags) | |
1421 | { | |
1422 | int rc; | |
29aaf496 | 1423 | |
d7e09d03 PT |
1424 | EXP_CHECK_MD_OP(exp, intent_lock); |
1425 | EXP_MD_COUNTER_INCREMENT(exp, intent_lock); | |
70a251f6 JH |
1426 | rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, |
1427 | cb_blocking, extra_lock_flags); | |
0a3bdb00 | 1428 | return rc; |
d7e09d03 PT |
1429 | } |
1430 | ||
1431 | static inline int md_link(struct obd_export *exp, struct md_op_data *op_data, | |
1432 | struct ptlrpc_request **request) | |
1433 | { | |
1434 | int rc; | |
29aaf496 | 1435 | |
d7e09d03 PT |
1436 | EXP_CHECK_MD_OP(exp, link); |
1437 | EXP_MD_COUNTER_INCREMENT(exp, link); | |
1438 | rc = MDP(exp->exp_obd, link)(exp, op_data, request); | |
0a3bdb00 | 1439 | return rc; |
d7e09d03 PT |
1440 | } |
1441 | ||
1442 | static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data, | |
1443 | const char *old, int oldlen, const char *new, | |
1444 | int newlen, struct ptlrpc_request **request) | |
1445 | { | |
1446 | int rc; | |
29aaf496 | 1447 | |
d7e09d03 PT |
1448 | EXP_CHECK_MD_OP(exp, rename); |
1449 | EXP_MD_COUNTER_INCREMENT(exp, rename); | |
1450 | rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new, | |
1451 | newlen, request); | |
0a3bdb00 | 1452 | return rc; |
d7e09d03 PT |
1453 | } |
1454 | ||
d7e09d03 PT |
1455 | static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data, |
1456 | void *ea, int ealen, void *ea2, int ea2len, | |
1457 | struct ptlrpc_request **request, | |
1458 | struct md_open_data **mod) | |
1459 | { | |
1460 | int rc; | |
29aaf496 | 1461 | |
d7e09d03 PT |
1462 | EXP_CHECK_MD_OP(exp, setattr); |
1463 | EXP_MD_COUNTER_INCREMENT(exp, setattr); | |
1464 | rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, | |
1465 | ea2, ea2len, request, mod); | |
0a3bdb00 | 1466 | return rc; |
d7e09d03 PT |
1467 | } |
1468 | ||
1469 | static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid, | |
ef2e0f55 | 1470 | struct ptlrpc_request **request) |
d7e09d03 PT |
1471 | { |
1472 | int rc; | |
29aaf496 | 1473 | |
d7e09d03 PT |
1474 | EXP_CHECK_MD_OP(exp, sync); |
1475 | EXP_MD_COUNTER_INCREMENT(exp, sync); | |
ef2e0f55 | 1476 | rc = MDP(exp->exp_obd, sync)(exp, fid, request); |
0a3bdb00 | 1477 | return rc; |
d7e09d03 PT |
1478 | } |
1479 | ||
049e215e | 1480 | static inline int md_read_page(struct obd_export *exp, |
1481 | struct md_op_data *op_data, | |
1482 | struct md_callback *cb_op, | |
1483 | __u64 hash_offset, | |
1484 | struct page **ppage) | |
1485 | { | |
1486 | int rc; | |
1487 | ||
1488 | EXP_CHECK_MD_OP(exp, read_page); | |
1489 | EXP_MD_COUNTER_INCREMENT(exp, read_page); | |
1490 | rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset, | |
1491 | ppage); | |
1492 | return rc; | |
1493 | } | |
1494 | ||
d7e09d03 PT |
1495 | static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data, |
1496 | struct ptlrpc_request **request) | |
1497 | { | |
1498 | int rc; | |
29aaf496 | 1499 | |
d7e09d03 PT |
1500 | EXP_CHECK_MD_OP(exp, unlink); |
1501 | EXP_MD_COUNTER_INCREMENT(exp, unlink); | |
1502 | rc = MDP(exp->exp_obd, unlink)(exp, op_data, request); | |
0a3bdb00 | 1503 | return rc; |
d7e09d03 PT |
1504 | } |
1505 | ||
1506 | static inline int md_get_lustre_md(struct obd_export *exp, | |
1507 | struct ptlrpc_request *req, | |
1508 | struct obd_export *dt_exp, | |
1509 | struct obd_export *md_exp, | |
1510 | struct lustre_md *md) | |
1511 | { | |
d7e09d03 PT |
1512 | EXP_CHECK_MD_OP(exp, get_lustre_md); |
1513 | EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md); | |
0a3bdb00 | 1514 | return MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md); |
d7e09d03 PT |
1515 | } |
1516 | ||
1517 | static inline int md_free_lustre_md(struct obd_export *exp, | |
1518 | struct lustre_md *md) | |
1519 | { | |
d7e09d03 PT |
1520 | EXP_CHECK_MD_OP(exp, free_lustre_md); |
1521 | EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md); | |
0a3bdb00 | 1522 | return MDP(exp->exp_obd, free_lustre_md)(exp, md); |
d7e09d03 PT |
1523 | } |
1524 | ||
2de35386 | 1525 | static inline int md_update_lsm_md(struct obd_export *exp, |
1526 | struct lmv_stripe_md *lsm, | |
1527 | struct mdt_body *body, | |
1528 | ldlm_blocking_callback cb) | |
1529 | { | |
1530 | EXP_CHECK_MD_OP(exp, update_lsm_md); | |
1531 | EXP_MD_COUNTER_INCREMENT(exp, update_lsm_md); | |
1532 | return MDP(exp->exp_obd, update_lsm_md)(exp, lsm, body, cb); | |
1533 | } | |
1534 | ||
1535 | static inline int md_merge_attr(struct obd_export *exp, | |
1536 | const struct lmv_stripe_md *lsm, | |
1537 | struct cl_attr *attr) | |
1538 | { | |
1539 | EXP_CHECK_MD_OP(exp, merge_attr); | |
1540 | EXP_MD_COUNTER_INCREMENT(exp, merge_attr); | |
1541 | return MDP(exp->exp_obd, merge_attr)(exp, lsm, attr); | |
1542 | } | |
1543 | ||
ef2e0f55 | 1544 | static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid, |
21aef7d9 | 1545 | u64 valid, const char *name, |
d7e09d03 PT |
1546 | const char *input, int input_size, |
1547 | int output_size, int flags, __u32 suppgid, | |
1548 | struct ptlrpc_request **request) | |
1549 | { | |
d7e09d03 PT |
1550 | EXP_CHECK_MD_OP(exp, setxattr); |
1551 | EXP_MD_COUNTER_INCREMENT(exp, setxattr); | |
ef2e0f55 | 1552 | return MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input, |
d7e09d03 | 1553 | input_size, output_size, flags, |
0a3bdb00 | 1554 | suppgid, request); |
d7e09d03 PT |
1555 | } |
1556 | ||
ef2e0f55 | 1557 | static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid, |
21aef7d9 | 1558 | u64 valid, const char *name, |
d7e09d03 PT |
1559 | const char *input, int input_size, |
1560 | int output_size, int flags, | |
1561 | struct ptlrpc_request **request) | |
1562 | { | |
d7e09d03 PT |
1563 | EXP_CHECK_MD_OP(exp, getxattr); |
1564 | EXP_MD_COUNTER_INCREMENT(exp, getxattr); | |
ef2e0f55 | 1565 | return MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input, |
d7e09d03 | 1566 | input_size, output_size, flags, |
0a3bdb00 | 1567 | request); |
d7e09d03 PT |
1568 | } |
1569 | ||
1570 | static inline int md_set_open_replay_data(struct obd_export *exp, | |
1571 | struct obd_client_handle *och, | |
63d42578 | 1572 | struct lookup_intent *it) |
d7e09d03 | 1573 | { |
d7e09d03 PT |
1574 | EXP_CHECK_MD_OP(exp, set_open_replay_data); |
1575 | EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data); | |
63d42578 | 1576 | return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it); |
d7e09d03 PT |
1577 | } |
1578 | ||
1579 | static inline int md_clear_open_replay_data(struct obd_export *exp, | |
1580 | struct obd_client_handle *och) | |
1581 | { | |
d7e09d03 PT |
1582 | EXP_CHECK_MD_OP(exp, clear_open_replay_data); |
1583 | EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data); | |
0a3bdb00 | 1584 | return MDP(exp->exp_obd, clear_open_replay_data)(exp, och); |
d7e09d03 PT |
1585 | } |
1586 | ||
1587 | static inline int md_set_lock_data(struct obd_export *exp, | |
bc30c172 JH |
1588 | const struct lustre_handle *lockh, |
1589 | void *data, __u64 *bits) | |
d7e09d03 | 1590 | { |
d7e09d03 PT |
1591 | EXP_CHECK_MD_OP(exp, set_lock_data); |
1592 | EXP_MD_COUNTER_INCREMENT(exp, set_lock_data); | |
0a3bdb00 | 1593 | return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits); |
d7e09d03 PT |
1594 | } |
1595 | ||
1596 | static inline int md_cancel_unused(struct obd_export *exp, | |
1597 | const struct lu_fid *fid, | |
1598 | ldlm_policy_data_t *policy, | |
52ee0d20 | 1599 | enum ldlm_mode mode, |
f833ee42 | 1600 | enum ldlm_cancel_flags flags, |
d7e09d03 PT |
1601 | void *opaque) |
1602 | { | |
1603 | int rc; | |
d7e09d03 PT |
1604 | |
1605 | EXP_CHECK_MD_OP(exp, cancel_unused); | |
1606 | EXP_MD_COUNTER_INCREMENT(exp, cancel_unused); | |
1607 | ||
1608 | rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode, | |
1609 | flags, opaque); | |
0a3bdb00 | 1610 | return rc; |
d7e09d03 PT |
1611 | } |
1612 | ||
52ee0d20 OD |
1613 | static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags, |
1614 | const struct lu_fid *fid, | |
1615 | enum ldlm_type type, | |
1616 | ldlm_policy_data_t *policy, | |
1617 | enum ldlm_mode mode, | |
1618 | struct lustre_handle *lockh) | |
d7e09d03 | 1619 | { |
d7e09d03 PT |
1620 | EXP_CHECK_MD_OP(exp, lock_match); |
1621 | EXP_MD_COUNTER_INCREMENT(exp, lock_match); | |
0a3bdb00 GKH |
1622 | return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type, |
1623 | policy, mode, lockh); | |
d7e09d03 PT |
1624 | } |
1625 | ||
1626 | static inline int md_init_ea_size(struct obd_export *exp, int easize, | |
44779340 BB |
1627 | int def_asize, int cookiesize, |
1628 | int def_cookiesize) | |
d7e09d03 | 1629 | { |
d7e09d03 PT |
1630 | EXP_CHECK_MD_OP(exp, init_ea_size); |
1631 | EXP_MD_COUNTER_INCREMENT(exp, init_ea_size); | |
0a3bdb00 | 1632 | return MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize, |
44779340 | 1633 | cookiesize, def_cookiesize); |
d7e09d03 PT |
1634 | } |
1635 | ||
d7e09d03 PT |
1636 | static inline int md_intent_getattr_async(struct obd_export *exp, |
1637 | struct md_enqueue_info *minfo, | |
1638 | struct ldlm_enqueue_info *einfo) | |
1639 | { | |
1640 | int rc; | |
29aaf496 | 1641 | |
d7e09d03 PT |
1642 | EXP_CHECK_MD_OP(exp, intent_getattr_async); |
1643 | EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async); | |
1644 | rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo); | |
0a3bdb00 | 1645 | return rc; |
d7e09d03 PT |
1646 | } |
1647 | ||
1648 | static inline int md_revalidate_lock(struct obd_export *exp, | |
1649 | struct lookup_intent *it, | |
1650 | struct lu_fid *fid, __u64 *bits) | |
1651 | { | |
1652 | int rc; | |
29aaf496 | 1653 | |
d7e09d03 PT |
1654 | EXP_CHECK_MD_OP(exp, revalidate_lock); |
1655 | EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock); | |
1656 | rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits); | |
0a3bdb00 | 1657 | return rc; |
d7e09d03 PT |
1658 | } |
1659 | ||
a609c393 | 1660 | static inline int md_get_fid_from_lsm(struct obd_export *exp, |
1661 | const struct lmv_stripe_md *lsm, | |
1662 | const char *name, int namelen, | |
1663 | struct lu_fid *fid) | |
1664 | { | |
1665 | int rc; | |
1666 | ||
1667 | EXP_CHECK_MD_OP(exp, get_fid_from_lsm); | |
1668 | EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm); | |
1669 | rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid); | |
1670 | return rc; | |
1671 | } | |
1672 | ||
d7e09d03 PT |
1673 | /* OBD Metadata Support */ |
1674 | ||
8150a97f JP |
1675 | int obd_init_caches(void); |
1676 | void obd_cleanup_caches(void); | |
d7e09d03 PT |
1677 | |
1678 | /* support routines */ | |
1679 | extern struct kmem_cache *obdo_cachep; | |
1680 | ||
d7e09d03 PT |
1681 | typedef int (*register_lwp_cb)(void *data); |
1682 | ||
1683 | struct lwp_register_item { | |
1684 | struct obd_export **lri_exp; | |
1685 | register_lwp_cb lri_cb_func; | |
1686 | void *lri_cb_data; | |
1687 | struct list_head lri_list; | |
1688 | char lri_name[MTI_NAME_MAXLEN]; | |
1689 | }; | |
1690 | ||
1691 | /* I'm as embarrassed about this as you are. | |
1692 | * | |
1693 | * <shaver> // XXX do not look into _superhack with remaining eye | |
c56e256d OD |
1694 | * <shaver> // XXX if this were any uglier, I'd get my own show on MTV |
1695 | */ | |
d7e09d03 PT |
1696 | extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c); |
1697 | ||
1698 | /* obd_mount.c */ | |
1699 | ||
1700 | /* sysctl.c */ | |
8150a97f | 1701 | int obd_sysctl_init(void); |
d7e09d03 PT |
1702 | |
1703 | /* uuid.c */ | |
1704 | typedef __u8 class_uuid_t[16]; | |
1705 | void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out); | |
1706 | ||
1707 | /* lustre_peer.c */ | |
1708 | int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index); | |
1709 | int class_add_uuid(const char *uuid, __u64 nid); | |
10457d4b | 1710 | int class_del_uuid(const char *uuid); |
d7e09d03 PT |
1711 | int class_check_uuid(struct obd_uuid *uuid, __u64 nid); |
1712 | void class_init_uuidlist(void); | |
1713 | void class_exit_uuidlist(void); | |
1714 | ||
76133e66 OD |
1715 | /* class_obd.c */ |
1716 | extern char obd_jobid_node[]; | |
9ee941df HM |
1717 | extern struct miscdevice obd_psdev; |
1718 | extern spinlock_t obd_types_lock; | |
76133e66 | 1719 | |
d7e09d03 PT |
1720 | /* prng.c */ |
1721 | #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t)) | |
1722 | ||
c948390f GP |
1723 | /* root squash info */ |
1724 | struct rw_semaphore; | |
1725 | struct root_squash_info { | |
1726 | uid_t rsi_uid; | |
1727 | gid_t rsi_gid; | |
1728 | struct list_head rsi_nosquash_nids; | |
1729 | struct rw_semaphore rsi_sem; | |
1730 | }; | |
1731 | ||
d7e09d03 | 1732 | #endif /* __LINUX_OBD_CLASS_H */ |