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 | |
18 | * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf | |
19 | * | |
20 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
21 | * CA 95054 USA or visit www.sun.com if you need additional information or | |
22 | * have any questions. | |
23 | * | |
24 | * GPL HEADER END | |
25 | */ | |
26 | /* | |
27 | * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. | |
28 | * Use is subject to license terms. | |
29 | * | |
30 | * Copyright (c) 2011, 2012, Intel Corporation. | |
31 | */ | |
32 | /* | |
33 | * This file is part of Lustre, http://www.lustre.org/ | |
34 | * Lustre is a trademark of Sun Microsystems, Inc. | |
35 | */ | |
36 | #ifndef __CLASS_OBD_H | |
37 | #define __CLASS_OBD_H | |
38 | ||
1accaadf GKH |
39 | #include "obd_support.h" |
40 | #include "lustre_import.h" | |
41 | #include "lustre_net.h" | |
42 | #include "obd.h" | |
43 | #include "lustre_lib.h" | |
44 | #include "lustre/lustre_idl.h" | |
45 | #include "lprocfs_status.h" | |
d7e09d03 | 46 | |
d7e09d03 PT |
47 | #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay |
48 | * and resends for avoid deadlocks */ | |
49 | #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update | |
50 | * obd_osfs_age */ | |
51 | #define OBD_STATFS_PTLRPCD 0x0004 /* requests will be sent via ptlrpcd | |
52 | * instead of a specific set. This | |
53 | * means that we cannot rely on the set | |
54 | * interpret routine to be called. | |
55 | * lov_statfs_fini() must thus be called | |
56 | * by the request interpret routine */ | |
57 | #define OBD_STATFS_FOR_MDT0 0x0008 /* The statfs is only for retrieving | |
58 | * information from MDT0. */ | |
59 | #define OBD_FL_PUNCH 0x00000001 /* To indicate it is punch operation */ | |
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 GD |
85 | struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid, |
86 | const char *typ_name, | |
d7e09d03 | 87 | struct obd_uuid *grp_uuid); |
aff9d8e8 | 88 | struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid, |
d7e09d03 | 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 PT |
99 | |
100 | struct llog_handle; | |
101 | struct llog_rec_hdr; | |
102 | typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *, | |
103 | struct llog_rec_hdr *, void *); | |
104 | /* obd_config.c */ | |
d7e09d03 PT |
105 | int class_process_config(struct lustre_cfg *lcfg); |
106 | int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars, | |
107 | struct lustre_cfg *lcfg, void *data); | |
d7e09d03 PT |
108 | struct obd_device *class_incref(struct obd_device *obd, |
109 | const char *scope, const void *source); | |
110 | void class_decref(struct obd_device *obd, | |
111 | const char *scope, const void *source); | |
d7e09d03 PT |
112 | int class_config_llog_handler(const struct lu_env *env, |
113 | struct llog_handle *handle, | |
114 | struct llog_rec_hdr *rec, void *data); | |
d7e09d03 PT |
115 | int class_add_uuid(const char *uuid, __u64 nid); |
116 | ||
117 | /*obdecho*/ | |
8150a97f | 118 | void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars); |
d7e09d03 PT |
119 | |
120 | #define CFG_F_START 0x01 /* Set when we start updating from a log */ | |
121 | #define CFG_F_MARKER 0x02 /* We are within a maker */ | |
122 | #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */ | |
123 | #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */ | |
124 | #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */ | |
125 | ||
126 | /* Passed as data param to class_config_parse_llog */ | |
127 | struct config_llog_instance { | |
128 | char *cfg_obdname; | |
129 | void *cfg_instance; | |
130 | struct super_block *cfg_sb; | |
131 | struct obd_uuid cfg_uuid; | |
132 | llog_cb_t cfg_callback; | |
133 | int cfg_last_idx; /* for partial llog processing */ | |
134 | int cfg_flags; | |
135 | }; | |
c9f6bb96 | 136 | |
d7e09d03 PT |
137 | int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt, |
138 | char *name, struct config_llog_instance *cfg); | |
d7e09d03 PT |
139 | enum { |
140 | CONFIG_T_CONFIG = 0, | |
141 | CONFIG_T_SPTLRPC = 1, | |
142 | CONFIG_T_RECOVER = 2, | |
7d4bae45 AB |
143 | CONFIG_T_PARAMS = 3, |
144 | CONFIG_T_MAX = 4 | |
d7e09d03 PT |
145 | }; |
146 | ||
7d4bae45 AB |
147 | #define PARAMS_FILENAME "params" |
148 | #define LCTL_UPCALL "lctl" | |
149 | ||
d7e09d03 PT |
150 | /* list of active configuration logs */ |
151 | struct config_llog_data { | |
152 | struct ldlm_res_id cld_resid; | |
153 | struct config_llog_instance cld_cfg; | |
154 | struct list_head cld_list_chain; | |
155 | atomic_t cld_refcount; | |
156 | struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */ | |
7d4bae45 AB |
157 | struct config_llog_data *cld_params; /* common parameters log */ |
158 | struct config_llog_data *cld_recover;/* imperative recover log */ | |
d7e09d03 PT |
159 | struct obd_export *cld_mgcexp; |
160 | struct mutex cld_lock; | |
161 | int cld_type; | |
162 | unsigned int cld_stopping:1, /* we were told to stop | |
163 | * watching */ | |
164 | cld_lostlock:1; /* lock not requeued */ | |
165 | char cld_logname[0]; | |
166 | }; | |
167 | ||
168 | struct lustre_profile { | |
169 | struct list_head lp_list; | |
170 | char *lp_profile; | |
171 | char *lp_dt; | |
172 | char *lp_md; | |
173 | }; | |
174 | ||
aff9d8e8 | 175 | struct lustre_profile *class_get_profile(const char *prof); |
d7e09d03 PT |
176 | void class_del_profile(const char *prof); |
177 | void class_del_profiles(void); | |
178 | ||
179 | #if LUSTRE_TRACKS_LOCK_EXP_REFS | |
180 | ||
181 | void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *); | |
182 | void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *); | |
183 | extern void (*class_export_dump_hook)(struct obd_export *); | |
184 | ||
185 | #else | |
186 | ||
a58a38ac GD |
187 | #define __class_export_add_lock_ref(exp, lock) do {} while (0) |
188 | #define __class_export_del_lock_ref(exp, lock) do {} while (0) | |
d7e09d03 PT |
189 | |
190 | #endif | |
191 | ||
a1d825e9 KS |
192 | /* genops.c */ |
193 | struct obd_export *class_export_get(struct obd_export *exp); | |
194 | void class_export_put(struct obd_export *exp); | |
195 | struct obd_export *class_new_export(struct obd_device *obddev, | |
196 | struct obd_uuid *cluuid); | |
197 | void class_unlink_export(struct obd_export *exp); | |
198 | ||
199 | struct obd_import *class_import_get(struct obd_import *); | |
200 | void class_import_put(struct obd_import *); | |
201 | struct obd_import *class_new_import(struct obd_device *obd); | |
202 | void class_destroy_import(struct obd_import *exp); | |
203 | ||
204 | void class_put_type(struct obd_type *type); | |
205 | int class_connect(struct lustre_handle *conn, struct obd_device *obd, | |
206 | struct obd_uuid *cluuid); | |
207 | int class_disconnect(struct obd_export *exp); | |
208 | void class_fail_export(struct obd_export *exp); | |
209 | int class_manual_cleanup(struct obd_device *obd); | |
210 | ||
28b9d6f1 SA |
211 | static inline void class_export_rpc_inc(struct obd_export *exp) |
212 | { | |
213 | atomic_inc(&(exp)->exp_rpc_count); | |
214 | CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", | |
215 | (exp), atomic_read(&(exp)->exp_rpc_count)); | |
216 | } | |
d7e09d03 | 217 | |
5fb0acb4 SA |
218 | static inline void class_export_rpc_dec(struct obd_export *exp) |
219 | { | |
220 | LASSERT_ATOMIC_POS(&exp->exp_rpc_count); | |
221 | atomic_dec(&(exp)->exp_rpc_count); | |
222 | CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", | |
223 | (exp), atomic_read(&(exp)->exp_rpc_count)); | |
224 | } | |
d7e09d03 | 225 | |
edc6a40e KS |
226 | static inline struct obd_export *class_export_lock_get(struct obd_export *exp, |
227 | struct ldlm_lock *lock) | |
228 | { | |
229 | atomic_inc(&(exp)->exp_locks_count); | |
230 | __class_export_add_lock_ref(exp, lock); | |
231 | CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", | |
232 | (exp), atomic_read(&(exp)->exp_locks_count)); | |
233 | return class_export_get(exp); | |
234 | } | |
d7e09d03 | 235 | |
d811ed69 KS |
236 | static inline void class_export_lock_put(struct obd_export *exp, |
237 | struct ldlm_lock *lock) | |
238 | { | |
239 | LASSERT_ATOMIC_POS(&exp->exp_locks_count); | |
240 | atomic_dec(&(exp)->exp_locks_count); | |
241 | __class_export_del_lock_ref(exp, lock); | |
242 | CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", | |
243 | (exp), atomic_read(&(exp)->exp_locks_count)); | |
244 | class_export_put(exp); | |
245 | } | |
d7e09d03 PT |
246 | |
247 | #define class_export_cb_get(exp) \ | |
248 | ({ \ | |
249 | atomic_inc(&(exp)->exp_cb_count); \ | |
250 | CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\ | |
251 | (exp), atomic_read(&(exp)->exp_cb_count)); \ | |
252 | class_export_get(exp); \ | |
253 | }) | |
254 | ||
255 | #define class_export_cb_put(exp) \ | |
256 | ({ \ | |
257 | LASSERT_ATOMIC_POS(&exp->exp_cb_count); \ | |
258 | atomic_dec(&(exp)->exp_cb_count); \ | |
259 | CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\ | |
260 | (exp), atomic_read(&(exp)->exp_cb_count)); \ | |
261 | class_export_put(exp); \ | |
262 | }) | |
263 | ||
d7e09d03 PT |
264 | static inline enum obd_option exp_flags_from_obd(struct obd_device *obd) |
265 | { | |
266 | return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) | | |
267 | (obd->obd_force ? OBD_OPT_FORCE : 0) | | |
d7e09d03 PT |
268 | 0); |
269 | } | |
270 | ||
616331c3 JH |
271 | struct inode; |
272 | struct lu_attr; | |
273 | struct obdo; | |
616331c3 | 274 | void obdo_refresh_inode(struct inode *dst, struct obdo *src, u32 valid); |
d7e09d03 | 275 | |
d7e09d03 | 276 | void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj); |
21aef7d9 | 277 | void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, u32 valid); |
d7e09d03 PT |
278 | |
279 | #define OBT(dev) (dev)->obd_type | |
280 | #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op | |
281 | #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op | |
282 | #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op | |
283 | ||
284 | /* Ensure obd_setup: used for cleanup which must be called | |
285 | while obd is stopping */ | |
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 PT |
310 | #define OBD_COUNTER_OFFSET(op) \ |
311 | ((offsetof(struct obd_ops, o_ ## op) - \ | |
312 | offsetof(struct obd_ops, o_iocontrol)) \ | |
313 | / sizeof(((struct obd_ops *)(0))->o_iocontrol)) | |
314 | ||
315 | #define OBD_COUNTER_INCREMENT(obdx, op) \ | |
316 | if ((obdx)->obd_stats != NULL) { \ | |
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) \ | |
325 | if ((export)->exp_obd->obd_stats != NULL) { \ | |
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) \ | |
334 | ((offsetof(struct md_ops, m_ ## op) - \ | |
335 | offsetof(struct md_ops, m_getstatus)) \ | |
336 | / sizeof(((struct md_ops *)(0))->m_getstatus)) | |
337 | ||
338 | #define MD_COUNTER_INCREMENT(obdx, op) \ | |
339 | if ((obd)->md_stats != NULL) { \ | |
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) \ | |
348 | if ((export)->exp_obd->obd_stats != NULL) { \ | |
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); \ | |
354 | if ((export)->exp_md_stats != NULL) \ | |
355 | lprocfs_counter_incr( \ | |
356 | (export)->exp_md_stats, coffset); \ | |
357 | } | |
358 | ||
d7e09d03 PT |
359 | #define EXP_CHECK_MD_OP(exp, op) \ |
360 | do { \ | |
361 | if ((exp) == NULL) { \ | |
362 | CERROR("obd_" #op ": NULL export\n"); \ | |
0a3bdb00 | 363 | return -ENODEV; \ |
d7e09d03 PT |
364 | } \ |
365 | if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \ | |
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 { \ | |
389 | if ((exp) == NULL) { \ | |
390 | CERROR("obd_" #op ": NULL export\n"); \ | |
0a3bdb00 | 391 | return -ENODEV; \ |
d7e09d03 PT |
392 | } \ |
393 | if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \ | |
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; | |
477 | if (ldt != NULL) { | |
478 | struct lu_context session_ctx; | |
479 | struct lu_env env; | |
50ffcb7e | 480 | |
d7e09d03 PT |
481 | lu_context_init(&session_ctx, LCT_SESSION); |
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; | |
494 | } else | |
495 | rc = PTR_ERR(d); | |
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; | |
519 | if (ldt != NULL && d != NULL) { | |
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; | |
548 | if (ldt != NULL && d != NULL) { | |
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 PT |
567 | /* If we set up but never connected, the |
568 | client import will not have been cleaned. */ | |
569 | down_write(&obd->u.cli.cl_sem); | |
570 | if (obd->u.cli.cl_import) { | |
571 | struct obd_import *imp; | |
50ffcb7e | 572 | |
d7e09d03 PT |
573 | imp = obd->u.cli.cl_import; |
574 | CDEBUG(D_CONFIG, "%s: client import never connected\n", | |
575 | obd->obd_name); | |
576 | ptlrpc_invalidate_import(imp); | |
d7e09d03 PT |
577 | client_destroy_import(imp); |
578 | obd->u.cli.cl_import = NULL; | |
579 | } | |
580 | up_write(&obd->u.cli.cl_sem); | |
d7e09d03 PT |
581 | } |
582 | ||
583 | static inline int | |
584 | obd_process_config(struct obd_device *obd, int datalen, void *data) | |
585 | { | |
586 | int rc; | |
587 | DECLARE_LU_VARS(ldt, d); | |
d7e09d03 | 588 | |
4ca1b8fb AM |
589 | rc = obd_check_dev(obd); |
590 | if (rc) | |
591 | return rc; | |
d7e09d03 PT |
592 | |
593 | obd->obd_process_conf = 1; | |
594 | ldt = obd->obd_type->typ_lu; | |
595 | d = obd->obd_lu_dev; | |
596 | if (ldt != NULL && d != NULL) { | |
597 | struct lu_env env; | |
598 | ||
599 | rc = lu_env_init(&env, ldt->ldt_ctx_tags); | |
600 | if (rc == 0) { | |
601 | rc = d->ld_ops->ldo_process_config(&env, d, data); | |
602 | lu_env_fini(&env); | |
603 | } | |
604 | } else { | |
605 | OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP); | |
606 | rc = OBP(obd, process_config)(obd, datalen, data); | |
607 | } | |
608 | OBD_COUNTER_INCREMENT(obd, process_config); | |
609 | obd->obd_process_conf = 0; | |
610 | ||
0a3bdb00 | 611 | return rc; |
d7e09d03 PT |
612 | } |
613 | ||
614 | /* Pack an in-memory MD struct for storage on disk. | |
615 | * Returns +ve size of packed MD (0 for free), or -ve error. | |
616 | * | |
617 | * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL). | |
618 | * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed. | |
619 | * If @*disk_tgt == NULL, it will be allocated | |
620 | */ | |
621 | static inline int obd_packmd(struct obd_export *exp, | |
622 | struct lov_mds_md **disk_tgt, | |
623 | struct lov_stripe_md *mem_src) | |
624 | { | |
625 | int rc; | |
d7e09d03 PT |
626 | |
627 | EXP_CHECK_DT_OP(exp, packmd); | |
628 | EXP_COUNTER_INCREMENT(exp, packmd); | |
629 | ||
630 | rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src); | |
0a3bdb00 | 631 | return rc; |
d7e09d03 PT |
632 | } |
633 | ||
634 | static inline int obd_size_diskmd(struct obd_export *exp, | |
635 | struct lov_stripe_md *mem_src) | |
636 | { | |
637 | return obd_packmd(exp, NULL, mem_src); | |
638 | } | |
639 | ||
d7e09d03 PT |
640 | static inline int obd_free_diskmd(struct obd_export *exp, |
641 | struct lov_mds_md **disk_tgt) | |
642 | { | |
643 | LASSERT(disk_tgt); | |
644 | LASSERT(*disk_tgt); | |
645 | /* | |
646 | * LU-2590, for caller's convenience, *disk_tgt could be host | |
647 | * endianness, it needs swab to LE if necessary, while just | |
648 | * lov_mds_md header needs it for figuring out how much memory | |
649 | * needs to be freed. | |
650 | */ | |
651 | if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) && | |
652 | (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) || | |
653 | ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3))) | |
654 | lustre_swab_lov_mds_md(*disk_tgt); | |
655 | return obd_packmd(exp, disk_tgt, NULL); | |
656 | } | |
657 | ||
658 | /* Unpack an MD struct from disk to in-memory format. | |
659 | * Returns +ve size of unpacked MD (0 for free), or -ve error. | |
660 | * | |
661 | * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL). | |
662 | * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed. | |
663 | * If @*mem_tgt == NULL, it will be allocated | |
664 | */ | |
665 | static inline int obd_unpackmd(struct obd_export *exp, | |
666 | struct lov_stripe_md **mem_tgt, | |
667 | struct lov_mds_md *disk_src, | |
668 | int disk_len) | |
669 | { | |
670 | int rc; | |
d7e09d03 PT |
671 | |
672 | EXP_CHECK_DT_OP(exp, unpackmd); | |
673 | EXP_COUNTER_INCREMENT(exp, unpackmd); | |
674 | ||
675 | rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len); | |
0a3bdb00 | 676 | return rc; |
d7e09d03 PT |
677 | } |
678 | ||
679 | /* helper functions */ | |
680 | static inline int obd_alloc_memmd(struct obd_export *exp, | |
681 | struct lov_stripe_md **mem_tgt) | |
682 | { | |
683 | LASSERT(mem_tgt); | |
684 | LASSERT(*mem_tgt == NULL); | |
685 | return obd_unpackmd(exp, mem_tgt, NULL, 0); | |
686 | } | |
687 | ||
688 | static inline int obd_free_memmd(struct obd_export *exp, | |
689 | struct lov_stripe_md **mem_tgt) | |
690 | { | |
691 | int rc; | |
692 | ||
693 | LASSERT(mem_tgt); | |
694 | LASSERT(*mem_tgt); | |
695 | rc = obd_unpackmd(exp, mem_tgt, NULL, 0); | |
696 | *mem_tgt = NULL; | |
697 | return rc; | |
698 | } | |
699 | ||
d7e09d03 PT |
700 | static inline int obd_create(const struct lu_env *env, struct obd_export *exp, |
701 | struct obdo *obdo, struct lov_stripe_md **ea, | |
702 | struct obd_trans_info *oti) | |
703 | { | |
704 | int rc; | |
d7e09d03 PT |
705 | |
706 | EXP_CHECK_DT_OP(exp, create); | |
707 | EXP_COUNTER_INCREMENT(exp, create); | |
708 | ||
709 | rc = OBP(exp->exp_obd, create)(env, exp, obdo, ea, oti); | |
0a3bdb00 | 710 | return rc; |
d7e09d03 PT |
711 | } |
712 | ||
713 | static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp, | |
714 | struct obdo *obdo, struct lov_stripe_md *ea, | |
715 | struct obd_trans_info *oti, | |
ef2e0f55 | 716 | struct obd_export *md_exp) |
d7e09d03 PT |
717 | { |
718 | int rc; | |
d7e09d03 PT |
719 | |
720 | EXP_CHECK_DT_OP(exp, destroy); | |
721 | EXP_COUNTER_INCREMENT(exp, destroy); | |
722 | ||
ef2e0f55 | 723 | rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp); |
0a3bdb00 | 724 | return rc; |
d7e09d03 PT |
725 | } |
726 | ||
727 | static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp, | |
728 | struct obd_info *oinfo) | |
729 | { | |
730 | int rc; | |
d7e09d03 PT |
731 | |
732 | EXP_CHECK_DT_OP(exp, getattr); | |
733 | EXP_COUNTER_INCREMENT(exp, getattr); | |
734 | ||
735 | rc = OBP(exp->exp_obd, getattr)(env, exp, oinfo); | |
0a3bdb00 | 736 | return rc; |
d7e09d03 PT |
737 | } |
738 | ||
739 | static inline int obd_getattr_async(struct obd_export *exp, | |
740 | struct obd_info *oinfo, | |
741 | struct ptlrpc_request_set *set) | |
742 | { | |
743 | int rc; | |
d7e09d03 PT |
744 | |
745 | EXP_CHECK_DT_OP(exp, getattr_async); | |
746 | EXP_COUNTER_INCREMENT(exp, getattr_async); | |
747 | ||
748 | rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set); | |
0a3bdb00 | 749 | return rc; |
d7e09d03 PT |
750 | } |
751 | ||
752 | static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp, | |
753 | struct obd_info *oinfo, | |
754 | struct obd_trans_info *oti) | |
755 | { | |
756 | int rc; | |
d7e09d03 PT |
757 | |
758 | EXP_CHECK_DT_OP(exp, setattr); | |
759 | EXP_COUNTER_INCREMENT(exp, setattr); | |
760 | ||
761 | rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti); | |
0a3bdb00 | 762 | return rc; |
d7e09d03 PT |
763 | } |
764 | ||
765 | /* This performs all the requests set init/wait/destroy actions. */ | |
766 | static inline int obd_setattr_rqset(struct obd_export *exp, | |
767 | struct obd_info *oinfo, | |
768 | struct obd_trans_info *oti) | |
769 | { | |
770 | struct ptlrpc_request_set *set = NULL; | |
771 | int rc; | |
d7e09d03 PT |
772 | |
773 | EXP_CHECK_DT_OP(exp, setattr_async); | |
774 | EXP_COUNTER_INCREMENT(exp, setattr_async); | |
775 | ||
776 | set = ptlrpc_prep_set(); | |
777 | if (set == NULL) | |
0a3bdb00 | 778 | return -ENOMEM; |
d7e09d03 PT |
779 | |
780 | rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set); | |
781 | if (rc == 0) | |
782 | rc = ptlrpc_set_wait(set); | |
783 | ptlrpc_set_destroy(set); | |
0a3bdb00 | 784 | return rc; |
d7e09d03 PT |
785 | } |
786 | ||
787 | /* This adds all the requests into @set if @set != NULL, otherwise | |
788 | all requests are sent asynchronously without waiting for response. */ | |
789 | static inline int obd_setattr_async(struct obd_export *exp, | |
790 | struct obd_info *oinfo, | |
791 | struct obd_trans_info *oti, | |
792 | struct ptlrpc_request_set *set) | |
793 | { | |
794 | int rc; | |
d7e09d03 PT |
795 | |
796 | EXP_CHECK_DT_OP(exp, setattr_async); | |
797 | EXP_COUNTER_INCREMENT(exp, setattr_async); | |
798 | ||
799 | rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set); | |
0a3bdb00 | 800 | return rc; |
d7e09d03 PT |
801 | } |
802 | ||
803 | static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid, | |
804 | int priority) | |
805 | { | |
806 | struct obd_device *obd = imp->imp_obd; | |
807 | int rc; | |
d7e09d03 | 808 | |
f36b6553 AM |
809 | rc = obd_check_dev_active(obd); |
810 | if (rc) | |
811 | return rc; | |
d7e09d03 PT |
812 | OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP); |
813 | OBD_COUNTER_INCREMENT(obd, add_conn); | |
814 | ||
815 | rc = OBP(obd, add_conn)(imp, uuid, priority); | |
0a3bdb00 | 816 | return rc; |
d7e09d03 PT |
817 | } |
818 | ||
819 | static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid) | |
820 | { | |
821 | struct obd_device *obd = imp->imp_obd; | |
822 | int rc; | |
d7e09d03 | 823 | |
f36b6553 AM |
824 | rc = obd_check_dev_active(obd); |
825 | if (rc) | |
826 | return rc; | |
d7e09d03 PT |
827 | OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP); |
828 | OBD_COUNTER_INCREMENT(obd, del_conn); | |
829 | ||
830 | rc = OBP(obd, del_conn)(imp, uuid); | |
0a3bdb00 | 831 | return rc; |
d7e09d03 PT |
832 | } |
833 | ||
834 | static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp) | |
835 | { | |
836 | struct obd_uuid *uuid; | |
d7e09d03 PT |
837 | |
838 | OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL); | |
839 | EXP_COUNTER_INCREMENT(exp, get_uuid); | |
840 | ||
841 | uuid = OBP(exp->exp_obd, get_uuid)(exp); | |
0a3bdb00 | 842 | return uuid; |
d7e09d03 PT |
843 | } |
844 | ||
845 | /** Create a new /a exp on device /a obd for the uuid /a cluuid | |
846 | * @param exp New export handle | |
847 | * @param d Connect data, supported flags are set, flags also understood | |
848 | * by obd are returned. | |
849 | */ | |
850 | static inline int obd_connect(const struct lu_env *env, | |
1d8cb70c | 851 | struct obd_export **exp, struct obd_device *obd, |
d7e09d03 PT |
852 | struct obd_uuid *cluuid, |
853 | struct obd_connect_data *data, | |
854 | void *localdata) | |
855 | { | |
856 | int rc; | |
857 | __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition | |
858 | * check */ | |
d7e09d03 | 859 | |
f36b6553 AM |
860 | rc = obd_check_dev_active(obd); |
861 | if (rc) | |
862 | return rc; | |
d7e09d03 PT |
863 | OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP); |
864 | OBD_COUNTER_INCREMENT(obd, connect); | |
865 | ||
866 | rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata); | |
867 | /* check that only subset is granted */ | |
868 | LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) == | |
869 | data->ocd_connect_flags)); | |
0a3bdb00 | 870 | return rc; |
d7e09d03 PT |
871 | } |
872 | ||
873 | static inline int obd_reconnect(const struct lu_env *env, | |
874 | struct obd_export *exp, | |
875 | struct obd_device *obd, | |
876 | struct obd_uuid *cluuid, | |
877 | struct obd_connect_data *d, | |
878 | void *localdata) | |
879 | { | |
880 | int rc; | |
881 | __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition | |
882 | * check */ | |
883 | ||
f36b6553 AM |
884 | rc = obd_check_dev_active(obd); |
885 | if (rc) | |
886 | return rc; | |
d7e09d03 PT |
887 | OBD_CHECK_DT_OP(obd, reconnect, 0); |
888 | OBD_COUNTER_INCREMENT(obd, reconnect); | |
889 | ||
890 | rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata); | |
891 | /* check that only subset is granted */ | |
892 | LASSERT(ergo(d != NULL, | |
893 | (d->ocd_connect_flags & ocf) == d->ocd_connect_flags)); | |
0a3bdb00 | 894 | return rc; |
d7e09d03 PT |
895 | } |
896 | ||
897 | static inline int obd_disconnect(struct obd_export *exp) | |
898 | { | |
899 | int rc; | |
d7e09d03 PT |
900 | |
901 | EXP_CHECK_DT_OP(exp, disconnect); | |
902 | EXP_COUNTER_INCREMENT(exp, disconnect); | |
903 | ||
904 | rc = OBP(exp->exp_obd, disconnect)(exp); | |
0a3bdb00 | 905 | return rc; |
d7e09d03 PT |
906 | } |
907 | ||
908 | static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp, | |
909 | enum lu_cli_type type) | |
910 | { | |
911 | int rc; | |
d7e09d03 PT |
912 | |
913 | OBD_CHECK_DT_OP(obd, fid_init, 0); | |
914 | OBD_COUNTER_INCREMENT(obd, fid_init); | |
915 | ||
916 | rc = OBP(obd, fid_init)(obd, exp, type); | |
0a3bdb00 | 917 | return rc; |
d7e09d03 PT |
918 | } |
919 | ||
920 | static inline int obd_fid_fini(struct obd_device *obd) | |
921 | { | |
922 | int rc; | |
d7e09d03 PT |
923 | |
924 | OBD_CHECK_DT_OP(obd, fid_fini, 0); | |
925 | OBD_COUNTER_INCREMENT(obd, fid_fini); | |
926 | ||
927 | rc = OBP(obd, fid_fini)(obd); | |
0a3bdb00 | 928 | return rc; |
d7e09d03 PT |
929 | } |
930 | ||
931 | static inline int obd_fid_alloc(struct obd_export *exp, | |
932 | struct lu_fid *fid, | |
933 | struct md_op_data *op_data) | |
934 | { | |
935 | int rc; | |
d7e09d03 PT |
936 | |
937 | EXP_CHECK_DT_OP(exp, fid_alloc); | |
938 | EXP_COUNTER_INCREMENT(exp, fid_alloc); | |
939 | ||
940 | rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data); | |
0a3bdb00 | 941 | return rc; |
d7e09d03 PT |
942 | } |
943 | ||
d7e09d03 PT |
944 | static inline int obd_pool_new(struct obd_device *obd, char *poolname) |
945 | { | |
946 | int rc; | |
d7e09d03 PT |
947 | |
948 | OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP); | |
949 | OBD_COUNTER_INCREMENT(obd, pool_new); | |
950 | ||
951 | rc = OBP(obd, pool_new)(obd, poolname); | |
0a3bdb00 | 952 | return rc; |
d7e09d03 PT |
953 | } |
954 | ||
955 | static inline int obd_pool_del(struct obd_device *obd, char *poolname) | |
956 | { | |
957 | int rc; | |
d7e09d03 PT |
958 | |
959 | OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP); | |
960 | OBD_COUNTER_INCREMENT(obd, pool_del); | |
961 | ||
962 | rc = OBP(obd, pool_del)(obd, poolname); | |
0a3bdb00 | 963 | return rc; |
d7e09d03 PT |
964 | } |
965 | ||
966 | static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname) | |
967 | { | |
968 | int rc; | |
d7e09d03 PT |
969 | |
970 | OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP); | |
971 | OBD_COUNTER_INCREMENT(obd, pool_add); | |
972 | ||
973 | rc = OBP(obd, pool_add)(obd, poolname, ostname); | |
0a3bdb00 | 974 | return rc; |
d7e09d03 PT |
975 | } |
976 | ||
977 | static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname) | |
978 | { | |
979 | int rc; | |
d7e09d03 PT |
980 | |
981 | OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP); | |
982 | OBD_COUNTER_INCREMENT(obd, pool_rem); | |
983 | ||
984 | rc = OBP(obd, pool_rem)(obd, poolname, ostname); | |
0a3bdb00 | 985 | return rc; |
d7e09d03 PT |
986 | } |
987 | ||
988 | static inline void obd_getref(struct obd_device *obd) | |
989 | { | |
d7e09d03 PT |
990 | if (OBT(obd) && OBP(obd, getref)) { |
991 | OBD_COUNTER_INCREMENT(obd, getref); | |
992 | OBP(obd, getref)(obd); | |
993 | } | |
d7e09d03 PT |
994 | } |
995 | ||
996 | static inline void obd_putref(struct obd_device *obd) | |
997 | { | |
d7e09d03 PT |
998 | if (OBT(obd) && OBP(obd, putref)) { |
999 | OBD_COUNTER_INCREMENT(obd, putref); | |
1000 | OBP(obd, putref)(obd); | |
1001 | } | |
d7e09d03 PT |
1002 | } |
1003 | ||
1004 | static inline int obd_init_export(struct obd_export *exp) | |
1005 | { | |
1006 | int rc = 0; | |
1007 | ||
d7e09d03 PT |
1008 | if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) && |
1009 | OBP((exp)->exp_obd, init_export)) | |
1010 | rc = OBP(exp->exp_obd, init_export)(exp); | |
0a3bdb00 | 1011 | return rc; |
d7e09d03 PT |
1012 | } |
1013 | ||
1014 | static inline int obd_destroy_export(struct obd_export *exp) | |
1015 | { | |
d7e09d03 PT |
1016 | if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) && |
1017 | OBP((exp)->exp_obd, destroy_export)) | |
1018 | OBP(exp->exp_obd, destroy_export)(exp); | |
0a3bdb00 | 1019 | return 0; |
d7e09d03 PT |
1020 | } |
1021 | ||
d7e09d03 PT |
1022 | /* @max_age is the oldest time in jiffies that we accept using a cached data. |
1023 | * If the cache is older than @max_age we will get a new value from the | |
1024 | * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */ | |
1025 | static inline int obd_statfs_async(struct obd_export *exp, | |
1026 | struct obd_info *oinfo, | |
1027 | __u64 max_age, | |
1028 | struct ptlrpc_request_set *rqset) | |
1029 | { | |
1030 | int rc = 0; | |
1031 | struct obd_device *obd; | |
d7e09d03 PT |
1032 | |
1033 | if (exp == NULL || exp->exp_obd == NULL) | |
0a3bdb00 | 1034 | return -EINVAL; |
d7e09d03 PT |
1035 | |
1036 | obd = exp->exp_obd; | |
1037 | OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP); | |
1038 | OBD_COUNTER_INCREMENT(obd, statfs); | |
1039 | ||
b0f5aad5 | 1040 | CDEBUG(D_SUPER, "%s: osfs %p age %llu, max_age %llu\n", |
d7e09d03 PT |
1041 | obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age); |
1042 | if (cfs_time_before_64(obd->obd_osfs_age, max_age)) { | |
1043 | rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset); | |
1044 | } else { | |
1d8cb70c GD |
1045 | CDEBUG(D_SUPER, |
1046 | "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n", | |
d7e09d03 PT |
1047 | obd->obd_name, &obd->obd_osfs, |
1048 | obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks, | |
1049 | obd->obd_osfs.os_ffree, obd->obd_osfs.os_files); | |
1050 | spin_lock(&obd->obd_osfs_lock); | |
1051 | memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs)); | |
1052 | spin_unlock(&obd->obd_osfs_lock); | |
1053 | oinfo->oi_flags |= OBD_STATFS_FROM_CACHE; | |
1054 | if (oinfo->oi_cb_up) | |
1055 | oinfo->oi_cb_up(oinfo, 0); | |
1056 | } | |
0a3bdb00 | 1057 | return rc; |
d7e09d03 PT |
1058 | } |
1059 | ||
1060 | static inline int obd_statfs_rqset(struct obd_export *exp, | |
1061 | struct obd_statfs *osfs, __u64 max_age, | |
1062 | __u32 flags) | |
1063 | { | |
1064 | struct ptlrpc_request_set *set = NULL; | |
45efd655 | 1065 | struct obd_info oinfo = { }; |
d7e09d03 | 1066 | int rc = 0; |
d7e09d03 PT |
1067 | |
1068 | set = ptlrpc_prep_set(); | |
1069 | if (set == NULL) | |
0a3bdb00 | 1070 | return -ENOMEM; |
d7e09d03 PT |
1071 | |
1072 | oinfo.oi_osfs = osfs; | |
1073 | oinfo.oi_flags = flags; | |
1074 | rc = obd_statfs_async(exp, &oinfo, max_age, set); | |
1075 | if (rc == 0) | |
1076 | rc = ptlrpc_set_wait(set); | |
1077 | ptlrpc_set_destroy(set); | |
0a3bdb00 | 1078 | return rc; |
d7e09d03 PT |
1079 | } |
1080 | ||
1081 | /* @max_age is the oldest time in jiffies that we accept using a cached data. | |
1082 | * If the cache is older than @max_age we will get a new value from the | |
1083 | * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */ | |
1084 | static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp, | |
1085 | struct obd_statfs *osfs, __u64 max_age, | |
1086 | __u32 flags) | |
1087 | { | |
1088 | int rc = 0; | |
1089 | struct obd_device *obd = exp->exp_obd; | |
d7e09d03 PT |
1090 | |
1091 | if (obd == NULL) | |
0a3bdb00 | 1092 | return -EINVAL; |
d7e09d03 PT |
1093 | |
1094 | OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP); | |
1095 | OBD_COUNTER_INCREMENT(obd, statfs); | |
1096 | ||
b0f5aad5 | 1097 | CDEBUG(D_SUPER, "osfs %llu, max_age %llu\n", |
d7e09d03 PT |
1098 | obd->obd_osfs_age, max_age); |
1099 | if (cfs_time_before_64(obd->obd_osfs_age, max_age)) { | |
1100 | rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags); | |
1101 | if (rc == 0) { | |
1102 | spin_lock(&obd->obd_osfs_lock); | |
1103 | memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs)); | |
1104 | obd->obd_osfs_age = cfs_time_current_64(); | |
1105 | spin_unlock(&obd->obd_osfs_lock); | |
1106 | } | |
1107 | } else { | |
b0f5aad5 | 1108 | CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n", |
d7e09d03 PT |
1109 | obd->obd_name, &obd->obd_osfs, |
1110 | obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks, | |
1111 | obd->obd_osfs.os_ffree, obd->obd_osfs.os_files); | |
1112 | spin_lock(&obd->obd_osfs_lock); | |
1113 | memcpy(osfs, &obd->obd_osfs, sizeof(*osfs)); | |
1114 | spin_unlock(&obd->obd_osfs_lock); | |
1115 | } | |
0a3bdb00 | 1116 | return rc; |
d7e09d03 PT |
1117 | } |
1118 | ||
d7e09d03 PT |
1119 | static inline int obd_preprw(const struct lu_env *env, int cmd, |
1120 | struct obd_export *exp, struct obdo *oa, | |
1121 | int objcount, struct obd_ioobj *obj, | |
1122 | struct niobuf_remote *remote, int *pages, | |
1123 | struct niobuf_local *local, | |
ef2e0f55 | 1124 | struct obd_trans_info *oti) |
d7e09d03 PT |
1125 | { |
1126 | int rc; | |
d7e09d03 PT |
1127 | |
1128 | EXP_CHECK_DT_OP(exp, preprw); | |
1129 | EXP_COUNTER_INCREMENT(exp, preprw); | |
1130 | ||
1131 | rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote, | |
ef2e0f55 | 1132 | pages, local, oti); |
0a3bdb00 | 1133 | return rc; |
d7e09d03 PT |
1134 | } |
1135 | ||
1136 | static inline int obd_commitrw(const struct lu_env *env, int cmd, | |
1137 | struct obd_export *exp, struct obdo *oa, | |
1138 | int objcount, struct obd_ioobj *obj, | |
1139 | struct niobuf_remote *rnb, int pages, | |
1140 | struct niobuf_local *local, | |
1141 | struct obd_trans_info *oti, int rc) | |
1142 | { | |
d7e09d03 PT |
1143 | EXP_CHECK_DT_OP(exp, commitrw); |
1144 | EXP_COUNTER_INCREMENT(exp, commitrw); | |
1145 | ||
1146 | rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj, | |
1147 | rnb, pages, local, oti, rc); | |
0a3bdb00 | 1148 | return rc; |
d7e09d03 PT |
1149 | } |
1150 | ||
d7e09d03 | 1151 | static inline int obd_adjust_kms(struct obd_export *exp, |
21aef7d9 | 1152 | struct lov_stripe_md *lsm, u64 size, |
d7e09d03 PT |
1153 | int shrink) |
1154 | { | |
1155 | int rc; | |
d7e09d03 PT |
1156 | |
1157 | EXP_CHECK_DT_OP(exp, adjust_kms); | |
1158 | EXP_COUNTER_INCREMENT(exp, adjust_kms); | |
1159 | ||
1160 | rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink); | |
0a3bdb00 | 1161 | return rc; |
d7e09d03 PT |
1162 | } |
1163 | ||
1164 | static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp, | |
1165 | int len, void *karg, void *uarg) | |
1166 | { | |
1167 | int rc; | |
d7e09d03 PT |
1168 | |
1169 | EXP_CHECK_DT_OP(exp, iocontrol); | |
1170 | EXP_COUNTER_INCREMENT(exp, iocontrol); | |
1171 | ||
1172 | rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg); | |
0a3bdb00 | 1173 | return rc; |
d7e09d03 PT |
1174 | } |
1175 | ||
d7e09d03 PT |
1176 | static inline int obd_find_cbdata(struct obd_export *exp, |
1177 | struct lov_stripe_md *lsm, | |
1178 | ldlm_iterator_t it, void *data) | |
1179 | { | |
1180 | int rc; | |
d7e09d03 PT |
1181 | |
1182 | EXP_CHECK_DT_OP(exp, find_cbdata); | |
1183 | EXP_COUNTER_INCREMENT(exp, find_cbdata); | |
1184 | ||
1185 | rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data); | |
0a3bdb00 | 1186 | return rc; |
d7e09d03 PT |
1187 | } |
1188 | ||
d7e09d03 PT |
1189 | static inline void obd_import_event(struct obd_device *obd, |
1190 | struct obd_import *imp, | |
1191 | enum obd_import_event event) | |
1192 | { | |
d7e09d03 PT |
1193 | if (!obd) { |
1194 | CERROR("NULL device\n"); | |
d7e09d03 PT |
1195 | return; |
1196 | } | |
1197 | if (obd->obd_set_up && OBP(obd, import_event)) { | |
1198 | OBD_COUNTER_INCREMENT(obd, import_event); | |
1199 | OBP(obd, import_event)(obd, imp, event); | |
1200 | } | |
d7e09d03 PT |
1201 | } |
1202 | ||
d7e09d03 PT |
1203 | static inline int obd_notify(struct obd_device *obd, |
1204 | struct obd_device *watched, | |
1205 | enum obd_notify_event ev, | |
1206 | void *data) | |
1207 | { | |
1208 | int rc; | |
29aaf496 | 1209 | |
4ca1b8fb AM |
1210 | rc = obd_check_dev(obd); |
1211 | if (rc) | |
1212 | return rc; | |
d7e09d03 PT |
1213 | |
1214 | /* the check for async_recov is a complete hack - I'm hereby | |
1215 | overloading the meaning to also mean "this was called from | |
1216 | mds_postsetup". I know that my mds is able to handle notifies | |
1217 | by this point, and it needs to get them to execute mds_postrecov. */ | |
1218 | if (!obd->obd_set_up && !obd->obd_async_recov) { | |
1219 | CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name); | |
0a3bdb00 | 1220 | return -EINVAL; |
d7e09d03 PT |
1221 | } |
1222 | ||
1223 | if (!OBP(obd, notify)) { | |
1224 | CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name); | |
0a3bdb00 | 1225 | return -ENOSYS; |
d7e09d03 PT |
1226 | } |
1227 | ||
1228 | OBD_COUNTER_INCREMENT(obd, notify); | |
1229 | rc = OBP(obd, notify)(obd, watched, ev, data); | |
0a3bdb00 | 1230 | return rc; |
d7e09d03 PT |
1231 | } |
1232 | ||
1233 | static inline int obd_notify_observer(struct obd_device *observer, | |
1234 | struct obd_device *observed, | |
1235 | enum obd_notify_event ev, | |
1236 | void *data) | |
1237 | { | |
1238 | int rc1; | |
1239 | int rc2; | |
1240 | ||
1241 | struct obd_notify_upcall *onu; | |
1242 | ||
1243 | if (observer->obd_observer) | |
1244 | rc1 = obd_notify(observer->obd_observer, observed, ev, data); | |
1245 | else | |
1246 | rc1 = 0; | |
1247 | /* | |
1248 | * Also, call non-obd listener, if any | |
1249 | */ | |
1250 | onu = &observer->obd_upcall; | |
1251 | if (onu->onu_upcall != NULL) | |
1252 | rc2 = onu->onu_upcall(observer, observed, ev, | |
1253 | onu->onu_owner, NULL); | |
1254 | else | |
1255 | rc2 = 0; | |
1256 | ||
1257 | return rc1 ? rc1 : rc2; | |
1258 | } | |
1259 | ||
1260 | static inline int obd_quotacheck(struct obd_export *exp, | |
1261 | struct obd_quotactl *oqctl) | |
1262 | { | |
1263 | int rc; | |
d7e09d03 PT |
1264 | |
1265 | EXP_CHECK_DT_OP(exp, quotacheck); | |
1266 | EXP_COUNTER_INCREMENT(exp, quotacheck); | |
1267 | ||
1268 | rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl); | |
0a3bdb00 | 1269 | return rc; |
d7e09d03 PT |
1270 | } |
1271 | ||
1272 | static inline int obd_quotactl(struct obd_export *exp, | |
1273 | struct obd_quotactl *oqctl) | |
1274 | { | |
1275 | int rc; | |
d7e09d03 PT |
1276 | |
1277 | EXP_CHECK_DT_OP(exp, quotactl); | |
1278 | EXP_COUNTER_INCREMENT(exp, quotactl); | |
1279 | ||
1280 | rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl); | |
0a3bdb00 | 1281 | return rc; |
d7e09d03 PT |
1282 | } |
1283 | ||
1284 | static inline int obd_health_check(const struct lu_env *env, | |
1285 | struct obd_device *obd) | |
1286 | { | |
1287 | /* returns: 0 on healthy | |
1288 | * >0 on unhealthy + reason code/flag | |
bd9070cb | 1289 | * however the only supported reason == 1 right now |
d7e09d03 PT |
1290 | * We'll need to define some better reasons |
1291 | * or flags in the future. | |
1292 | * <0 on error | |
1293 | */ | |
1294 | int rc; | |
d7e09d03 PT |
1295 | |
1296 | /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */ | |
1297 | if (obd == NULL || !OBT(obd)) { | |
1298 | CERROR("cleaned up obd\n"); | |
0a3bdb00 | 1299 | return -EOPNOTSUPP; |
d7e09d03 PT |
1300 | } |
1301 | if (!obd->obd_set_up || obd->obd_stopping) | |
0a3bdb00 | 1302 | return 0; |
d7e09d03 | 1303 | if (!OBP(obd, health_check)) |
0a3bdb00 | 1304 | return 0; |
d7e09d03 PT |
1305 | |
1306 | rc = OBP(obd, health_check)(env, obd); | |
0a3bdb00 | 1307 | return rc; |
d7e09d03 PT |
1308 | } |
1309 | ||
1310 | static inline int obd_register_observer(struct obd_device *obd, | |
1311 | struct obd_device *observer) | |
1312 | { | |
4ca1b8fb AM |
1313 | int rc; |
1314 | ||
1315 | rc = obd_check_dev(obd); | |
1316 | if (rc) | |
1317 | return rc; | |
d7e09d03 PT |
1318 | down_write(&obd->obd_observer_link_sem); |
1319 | if (obd->obd_observer && observer) { | |
1320 | up_write(&obd->obd_observer_link_sem); | |
0a3bdb00 | 1321 | return -EALREADY; |
d7e09d03 PT |
1322 | } |
1323 | obd->obd_observer = observer; | |
1324 | up_write(&obd->obd_observer_link_sem); | |
0a3bdb00 | 1325 | return 0; |
d7e09d03 PT |
1326 | } |
1327 | ||
d7e09d03 PT |
1328 | #if 0 |
1329 | static inline int obd_register_page_removal_cb(struct obd_export *exp, | |
1330 | obd_page_removal_cb_t cb, | |
1331 | obd_pin_extent_cb pin_cb) | |
1332 | { | |
1333 | int rc; | |
d7e09d03 PT |
1334 | |
1335 | OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0); | |
1336 | OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb); | |
1337 | ||
1338 | rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb); | |
0a3bdb00 | 1339 | return rc; |
d7e09d03 PT |
1340 | } |
1341 | ||
1342 | static inline int obd_unregister_page_removal_cb(struct obd_export *exp, | |
1343 | obd_page_removal_cb_t cb) | |
1344 | { | |
1345 | int rc; | |
d7e09d03 PT |
1346 | |
1347 | OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0); | |
1348 | OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb); | |
1349 | ||
1350 | rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb); | |
0a3bdb00 | 1351 | return rc; |
d7e09d03 PT |
1352 | } |
1353 | ||
1354 | static inline int obd_register_lock_cancel_cb(struct obd_export *exp, | |
1355 | obd_lock_cancel_cb cb) | |
1356 | { | |
1357 | int rc; | |
d7e09d03 PT |
1358 | |
1359 | OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0); | |
1360 | OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb); | |
1361 | ||
1362 | rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb); | |
0a3bdb00 | 1363 | return rc; |
d7e09d03 PT |
1364 | } |
1365 | ||
1366 | static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp, | |
1367 | obd_lock_cancel_cb cb) | |
1368 | { | |
1369 | int rc; | |
d7e09d03 PT |
1370 | |
1371 | OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0); | |
1372 | OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb); | |
1373 | ||
1374 | rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb); | |
0a3bdb00 | 1375 | return rc; |
d7e09d03 PT |
1376 | } |
1377 | #endif | |
1378 | ||
1379 | /* metadata helpers */ | |
ef2e0f55 | 1380 | static inline int md_getstatus(struct obd_export *exp, struct lu_fid *fid) |
d7e09d03 PT |
1381 | { |
1382 | int rc; | |
d7e09d03 PT |
1383 | |
1384 | EXP_CHECK_MD_OP(exp, getstatus); | |
1385 | EXP_MD_COUNTER_INCREMENT(exp, getstatus); | |
ef2e0f55 | 1386 | rc = MDP(exp->exp_obd, getstatus)(exp, fid); |
0a3bdb00 | 1387 | return rc; |
d7e09d03 PT |
1388 | } |
1389 | ||
1390 | static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data, | |
1391 | struct ptlrpc_request **request) | |
1392 | { | |
1393 | int rc; | |
29aaf496 | 1394 | |
d7e09d03 PT |
1395 | EXP_CHECK_MD_OP(exp, getattr); |
1396 | EXP_MD_COUNTER_INCREMENT(exp, getattr); | |
1397 | rc = MDP(exp->exp_obd, getattr)(exp, op_data, request); | |
0a3bdb00 | 1398 | return rc; |
d7e09d03 PT |
1399 | } |
1400 | ||
1401 | static inline int md_null_inode(struct obd_export *exp, | |
1402 | const struct lu_fid *fid) | |
1403 | { | |
1404 | int rc; | |
29aaf496 | 1405 | |
d7e09d03 PT |
1406 | EXP_CHECK_MD_OP(exp, null_inode); |
1407 | EXP_MD_COUNTER_INCREMENT(exp, null_inode); | |
1408 | rc = MDP(exp->exp_obd, null_inode)(exp, fid); | |
0a3bdb00 | 1409 | return rc; |
d7e09d03 PT |
1410 | } |
1411 | ||
1412 | static inline int md_find_cbdata(struct obd_export *exp, | |
1413 | const struct lu_fid *fid, | |
1414 | ldlm_iterator_t it, void *data) | |
1415 | { | |
1416 | int rc; | |
29aaf496 | 1417 | |
d7e09d03 PT |
1418 | EXP_CHECK_MD_OP(exp, find_cbdata); |
1419 | EXP_MD_COUNTER_INCREMENT(exp, find_cbdata); | |
1420 | rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data); | |
0a3bdb00 | 1421 | return rc; |
d7e09d03 PT |
1422 | } |
1423 | ||
1424 | static inline int md_close(struct obd_export *exp, struct md_op_data *op_data, | |
1425 | struct md_open_data *mod, | |
1426 | struct ptlrpc_request **request) | |
1427 | { | |
1428 | int rc; | |
29aaf496 | 1429 | |
d7e09d03 PT |
1430 | EXP_CHECK_MD_OP(exp, close); |
1431 | EXP_MD_COUNTER_INCREMENT(exp, close); | |
1432 | rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request); | |
0a3bdb00 | 1433 | return rc; |
d7e09d03 PT |
1434 | } |
1435 | ||
1436 | static inline int md_create(struct obd_export *exp, struct md_op_data *op_data, | |
1437 | const void *data, int datalen, int mode, __u32 uid, | |
1438 | __u32 gid, cfs_cap_t cap_effective, __u64 rdev, | |
1439 | struct ptlrpc_request **request) | |
1440 | { | |
1441 | int rc; | |
29aaf496 | 1442 | |
d7e09d03 PT |
1443 | EXP_CHECK_MD_OP(exp, create); |
1444 | EXP_MD_COUNTER_INCREMENT(exp, create); | |
1445 | rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode, | |
1446 | uid, gid, cap_effective, rdev, request); | |
0a3bdb00 | 1447 | return rc; |
d7e09d03 PT |
1448 | } |
1449 | ||
1450 | static inline int md_done_writing(struct obd_export *exp, | |
1451 | struct md_op_data *op_data, | |
1452 | struct md_open_data *mod) | |
1453 | { | |
1454 | int rc; | |
29aaf496 | 1455 | |
d7e09d03 PT |
1456 | EXP_CHECK_MD_OP(exp, done_writing); |
1457 | EXP_MD_COUNTER_INCREMENT(exp, done_writing); | |
1458 | rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod); | |
0a3bdb00 | 1459 | return rc; |
d7e09d03 PT |
1460 | } |
1461 | ||
1462 | static inline int md_enqueue(struct obd_export *exp, | |
1463 | struct ldlm_enqueue_info *einfo, | |
1464 | struct lookup_intent *it, | |
1465 | struct md_op_data *op_data, | |
1466 | struct lustre_handle *lockh, | |
1467 | void *lmm, int lmmsize, | |
1468 | struct ptlrpc_request **req, | |
875332d4 | 1469 | __u64 extra_lock_flags) |
d7e09d03 PT |
1470 | { |
1471 | int rc; | |
29aaf496 | 1472 | |
d7e09d03 PT |
1473 | EXP_CHECK_MD_OP(exp, enqueue); |
1474 | EXP_MD_COUNTER_INCREMENT(exp, enqueue); | |
1475 | rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh, | |
1476 | lmm, lmmsize, req, extra_lock_flags); | |
0a3bdb00 | 1477 | return rc; |
d7e09d03 PT |
1478 | } |
1479 | ||
1480 | static inline int md_getattr_name(struct obd_export *exp, | |
1481 | struct md_op_data *op_data, | |
1482 | struct ptlrpc_request **request) | |
1483 | { | |
1484 | int rc; | |
29aaf496 | 1485 | |
d7e09d03 PT |
1486 | EXP_CHECK_MD_OP(exp, getattr_name); |
1487 | EXP_MD_COUNTER_INCREMENT(exp, getattr_name); | |
1488 | rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request); | |
0a3bdb00 | 1489 | return rc; |
d7e09d03 PT |
1490 | } |
1491 | ||
1492 | static inline int md_intent_lock(struct obd_export *exp, | |
1493 | struct md_op_data *op_data, void *lmm, | |
1494 | int lmmsize, struct lookup_intent *it, | |
1495 | int lookup_flags, struct ptlrpc_request **reqp, | |
1496 | ldlm_blocking_callback cb_blocking, | |
1497 | __u64 extra_lock_flags) | |
1498 | { | |
1499 | int rc; | |
29aaf496 | 1500 | |
d7e09d03 PT |
1501 | EXP_CHECK_MD_OP(exp, intent_lock); |
1502 | EXP_MD_COUNTER_INCREMENT(exp, intent_lock); | |
1503 | rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize, | |
1504 | it, lookup_flags, reqp, cb_blocking, | |
1505 | extra_lock_flags); | |
0a3bdb00 | 1506 | return rc; |
d7e09d03 PT |
1507 | } |
1508 | ||
1509 | static inline int md_link(struct obd_export *exp, struct md_op_data *op_data, | |
1510 | struct ptlrpc_request **request) | |
1511 | { | |
1512 | int rc; | |
29aaf496 | 1513 | |
d7e09d03 PT |
1514 | EXP_CHECK_MD_OP(exp, link); |
1515 | EXP_MD_COUNTER_INCREMENT(exp, link); | |
1516 | rc = MDP(exp->exp_obd, link)(exp, op_data, request); | |
0a3bdb00 | 1517 | return rc; |
d7e09d03 PT |
1518 | } |
1519 | ||
1520 | static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data, | |
1521 | const char *old, int oldlen, const char *new, | |
1522 | int newlen, struct ptlrpc_request **request) | |
1523 | { | |
1524 | int rc; | |
29aaf496 | 1525 | |
d7e09d03 PT |
1526 | EXP_CHECK_MD_OP(exp, rename); |
1527 | EXP_MD_COUNTER_INCREMENT(exp, rename); | |
1528 | rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new, | |
1529 | newlen, request); | |
0a3bdb00 | 1530 | return rc; |
d7e09d03 PT |
1531 | } |
1532 | ||
1533 | static inline int md_is_subdir(struct obd_export *exp, | |
1534 | const struct lu_fid *pfid, | |
1535 | const struct lu_fid *cfid, | |
1536 | struct ptlrpc_request **request) | |
1537 | { | |
1538 | int rc; | |
29aaf496 | 1539 | |
d7e09d03 PT |
1540 | EXP_CHECK_MD_OP(exp, is_subdir); |
1541 | EXP_MD_COUNTER_INCREMENT(exp, is_subdir); | |
1542 | rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request); | |
0a3bdb00 | 1543 | return rc; |
d7e09d03 PT |
1544 | } |
1545 | ||
1546 | static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data, | |
1547 | void *ea, int ealen, void *ea2, int ea2len, | |
1548 | struct ptlrpc_request **request, | |
1549 | struct md_open_data **mod) | |
1550 | { | |
1551 | int rc; | |
29aaf496 | 1552 | |
d7e09d03 PT |
1553 | EXP_CHECK_MD_OP(exp, setattr); |
1554 | EXP_MD_COUNTER_INCREMENT(exp, setattr); | |
1555 | rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, | |
1556 | ea2, ea2len, request, mod); | |
0a3bdb00 | 1557 | return rc; |
d7e09d03 PT |
1558 | } |
1559 | ||
1560 | static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid, | |
ef2e0f55 | 1561 | struct ptlrpc_request **request) |
d7e09d03 PT |
1562 | { |
1563 | int rc; | |
29aaf496 | 1564 | |
d7e09d03 PT |
1565 | EXP_CHECK_MD_OP(exp, sync); |
1566 | EXP_MD_COUNTER_INCREMENT(exp, sync); | |
ef2e0f55 | 1567 | rc = MDP(exp->exp_obd, sync)(exp, fid, request); |
0a3bdb00 | 1568 | return rc; |
d7e09d03 PT |
1569 | } |
1570 | ||
1571 | static inline int md_readpage(struct obd_export *exp, struct md_op_data *opdata, | |
1572 | struct page **pages, | |
1573 | struct ptlrpc_request **request) | |
1574 | { | |
1575 | int rc; | |
29aaf496 | 1576 | |
d7e09d03 PT |
1577 | EXP_CHECK_MD_OP(exp, readpage); |
1578 | EXP_MD_COUNTER_INCREMENT(exp, readpage); | |
1579 | rc = MDP(exp->exp_obd, readpage)(exp, opdata, pages, request); | |
0a3bdb00 | 1580 | return rc; |
d7e09d03 PT |
1581 | } |
1582 | ||
1583 | static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data, | |
1584 | struct ptlrpc_request **request) | |
1585 | { | |
1586 | int rc; | |
29aaf496 | 1587 | |
d7e09d03 PT |
1588 | EXP_CHECK_MD_OP(exp, unlink); |
1589 | EXP_MD_COUNTER_INCREMENT(exp, unlink); | |
1590 | rc = MDP(exp->exp_obd, unlink)(exp, op_data, request); | |
0a3bdb00 | 1591 | return rc; |
d7e09d03 PT |
1592 | } |
1593 | ||
1594 | static inline int md_get_lustre_md(struct obd_export *exp, | |
1595 | struct ptlrpc_request *req, | |
1596 | struct obd_export *dt_exp, | |
1597 | struct obd_export *md_exp, | |
1598 | struct lustre_md *md) | |
1599 | { | |
d7e09d03 PT |
1600 | EXP_CHECK_MD_OP(exp, get_lustre_md); |
1601 | EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md); | |
0a3bdb00 | 1602 | return MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md); |
d7e09d03 PT |
1603 | } |
1604 | ||
1605 | static inline int md_free_lustre_md(struct obd_export *exp, | |
1606 | struct lustre_md *md) | |
1607 | { | |
d7e09d03 PT |
1608 | EXP_CHECK_MD_OP(exp, free_lustre_md); |
1609 | EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md); | |
0a3bdb00 | 1610 | return MDP(exp->exp_obd, free_lustre_md)(exp, md); |
d7e09d03 PT |
1611 | } |
1612 | ||
ef2e0f55 | 1613 | static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid, |
21aef7d9 | 1614 | u64 valid, const char *name, |
d7e09d03 PT |
1615 | const char *input, int input_size, |
1616 | int output_size, int flags, __u32 suppgid, | |
1617 | struct ptlrpc_request **request) | |
1618 | { | |
d7e09d03 PT |
1619 | EXP_CHECK_MD_OP(exp, setxattr); |
1620 | EXP_MD_COUNTER_INCREMENT(exp, setxattr); | |
ef2e0f55 | 1621 | return MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input, |
d7e09d03 | 1622 | input_size, output_size, flags, |
0a3bdb00 | 1623 | suppgid, request); |
d7e09d03 PT |
1624 | } |
1625 | ||
ef2e0f55 | 1626 | static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid, |
21aef7d9 | 1627 | u64 valid, const char *name, |
d7e09d03 PT |
1628 | const char *input, int input_size, |
1629 | int output_size, int flags, | |
1630 | struct ptlrpc_request **request) | |
1631 | { | |
d7e09d03 PT |
1632 | EXP_CHECK_MD_OP(exp, getxattr); |
1633 | EXP_MD_COUNTER_INCREMENT(exp, getxattr); | |
ef2e0f55 | 1634 | return MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input, |
d7e09d03 | 1635 | input_size, output_size, flags, |
0a3bdb00 | 1636 | request); |
d7e09d03 PT |
1637 | } |
1638 | ||
1639 | static inline int md_set_open_replay_data(struct obd_export *exp, | |
1640 | struct obd_client_handle *och, | |
63d42578 | 1641 | struct lookup_intent *it) |
d7e09d03 | 1642 | { |
d7e09d03 PT |
1643 | EXP_CHECK_MD_OP(exp, set_open_replay_data); |
1644 | EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data); | |
63d42578 | 1645 | return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it); |
d7e09d03 PT |
1646 | } |
1647 | ||
1648 | static inline int md_clear_open_replay_data(struct obd_export *exp, | |
1649 | struct obd_client_handle *och) | |
1650 | { | |
d7e09d03 PT |
1651 | EXP_CHECK_MD_OP(exp, clear_open_replay_data); |
1652 | EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data); | |
0a3bdb00 | 1653 | return MDP(exp->exp_obd, clear_open_replay_data)(exp, och); |
d7e09d03 PT |
1654 | } |
1655 | ||
1656 | static inline int md_set_lock_data(struct obd_export *exp, | |
1657 | __u64 *lockh, void *data, __u64 *bits) | |
1658 | { | |
d7e09d03 PT |
1659 | EXP_CHECK_MD_OP(exp, set_lock_data); |
1660 | EXP_MD_COUNTER_INCREMENT(exp, set_lock_data); | |
0a3bdb00 | 1661 | return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits); |
d7e09d03 PT |
1662 | } |
1663 | ||
1664 | static inline int md_cancel_unused(struct obd_export *exp, | |
1665 | const struct lu_fid *fid, | |
1666 | ldlm_policy_data_t *policy, | |
1667 | ldlm_mode_t mode, | |
1668 | ldlm_cancel_flags_t flags, | |
1669 | void *opaque) | |
1670 | { | |
1671 | int rc; | |
d7e09d03 PT |
1672 | |
1673 | EXP_CHECK_MD_OP(exp, cancel_unused); | |
1674 | EXP_MD_COUNTER_INCREMENT(exp, cancel_unused); | |
1675 | ||
1676 | rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode, | |
1677 | flags, opaque); | |
0a3bdb00 | 1678 | return rc; |
d7e09d03 PT |
1679 | } |
1680 | ||
1681 | static inline ldlm_mode_t md_lock_match(struct obd_export *exp, __u64 flags, | |
1682 | const struct lu_fid *fid, | |
1683 | ldlm_type_t type, | |
1684 | ldlm_policy_data_t *policy, | |
1685 | ldlm_mode_t mode, | |
1686 | struct lustre_handle *lockh) | |
1687 | { | |
d7e09d03 PT |
1688 | EXP_CHECK_MD_OP(exp, lock_match); |
1689 | EXP_MD_COUNTER_INCREMENT(exp, lock_match); | |
0a3bdb00 GKH |
1690 | return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type, |
1691 | policy, mode, lockh); | |
d7e09d03 PT |
1692 | } |
1693 | ||
1694 | static inline int md_init_ea_size(struct obd_export *exp, int easize, | |
44779340 BB |
1695 | int def_asize, int cookiesize, |
1696 | int def_cookiesize) | |
d7e09d03 | 1697 | { |
d7e09d03 PT |
1698 | EXP_CHECK_MD_OP(exp, init_ea_size); |
1699 | EXP_MD_COUNTER_INCREMENT(exp, init_ea_size); | |
0a3bdb00 | 1700 | return MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize, |
44779340 | 1701 | cookiesize, def_cookiesize); |
d7e09d03 PT |
1702 | } |
1703 | ||
1704 | static inline int md_get_remote_perm(struct obd_export *exp, | |
ef2e0f55 | 1705 | const struct lu_fid *fid, __u32 suppgid, |
d7e09d03 PT |
1706 | struct ptlrpc_request **request) |
1707 | { | |
d7e09d03 PT |
1708 | EXP_CHECK_MD_OP(exp, get_remote_perm); |
1709 | EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm); | |
ef2e0f55 | 1710 | return MDP(exp->exp_obd, get_remote_perm)(exp, fid, suppgid, |
0a3bdb00 | 1711 | request); |
d7e09d03 PT |
1712 | } |
1713 | ||
d7e09d03 PT |
1714 | static inline int md_intent_getattr_async(struct obd_export *exp, |
1715 | struct md_enqueue_info *minfo, | |
1716 | struct ldlm_enqueue_info *einfo) | |
1717 | { | |
1718 | int rc; | |
29aaf496 | 1719 | |
d7e09d03 PT |
1720 | EXP_CHECK_MD_OP(exp, intent_getattr_async); |
1721 | EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async); | |
1722 | rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo); | |
0a3bdb00 | 1723 | return rc; |
d7e09d03 PT |
1724 | } |
1725 | ||
1726 | static inline int md_revalidate_lock(struct obd_export *exp, | |
1727 | struct lookup_intent *it, | |
1728 | struct lu_fid *fid, __u64 *bits) | |
1729 | { | |
1730 | int rc; | |
29aaf496 | 1731 | |
d7e09d03 PT |
1732 | EXP_CHECK_MD_OP(exp, revalidate_lock); |
1733 | EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock); | |
1734 | rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits); | |
0a3bdb00 | 1735 | return rc; |
d7e09d03 PT |
1736 | } |
1737 | ||
d7e09d03 PT |
1738 | /* OBD Metadata Support */ |
1739 | ||
8150a97f JP |
1740 | int obd_init_caches(void); |
1741 | void obd_cleanup_caches(void); | |
d7e09d03 PT |
1742 | |
1743 | /* support routines */ | |
1744 | extern struct kmem_cache *obdo_cachep; | |
1745 | ||
1746 | #define OBDO_ALLOC(ptr) \ | |
1747 | do { \ | |
0be19afa | 1748 | OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \ |
a58a38ac | 1749 | } while (0) |
d7e09d03 PT |
1750 | |
1751 | #define OBDO_FREE(ptr) \ | |
1752 | do { \ | |
1753 | OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \ | |
a58a38ac | 1754 | } while (0) |
d7e09d03 | 1755 | |
d7e09d03 PT |
1756 | static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid) |
1757 | { | |
1758 | /* something here */ | |
1759 | } | |
1760 | ||
1761 | static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa) | |
1762 | { | |
1763 | /* something here */ | |
1764 | } | |
1765 | ||
1766 | typedef int (*register_lwp_cb)(void *data); | |
1767 | ||
1768 | struct lwp_register_item { | |
1769 | struct obd_export **lri_exp; | |
1770 | register_lwp_cb lri_cb_func; | |
1771 | void *lri_cb_data; | |
1772 | struct list_head lri_list; | |
1773 | char lri_name[MTI_NAME_MAXLEN]; | |
1774 | }; | |
1775 | ||
1776 | /* I'm as embarrassed about this as you are. | |
1777 | * | |
1778 | * <shaver> // XXX do not look into _superhack with remaining eye | |
1779 | * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */ | |
1780 | extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c); | |
1781 | ||
1782 | /* obd_mount.c */ | |
1783 | ||
1784 | /* sysctl.c */ | |
8150a97f | 1785 | int obd_sysctl_init(void); |
d7e09d03 PT |
1786 | |
1787 | /* uuid.c */ | |
1788 | typedef __u8 class_uuid_t[16]; | |
1789 | void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out); | |
1790 | ||
1791 | /* lustre_peer.c */ | |
1792 | int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index); | |
1793 | int class_add_uuid(const char *uuid, __u64 nid); | |
1794 | int class_del_uuid (const char *uuid); | |
1795 | int class_check_uuid(struct obd_uuid *uuid, __u64 nid); | |
1796 | void class_init_uuidlist(void); | |
1797 | void class_exit_uuidlist(void); | |
1798 | ||
76133e66 OD |
1799 | /* class_obd.c */ |
1800 | extern char obd_jobid_node[]; | |
9ee941df HM |
1801 | extern struct miscdevice obd_psdev; |
1802 | extern spinlock_t obd_types_lock; | |
76133e66 | 1803 | |
d7e09d03 PT |
1804 | /* prng.c */ |
1805 | #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t)) | |
1806 | ||
1807 | #endif /* __LINUX_OBD_CLASS_H */ |