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