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