staging: lustre: Fix typo in lustre/include part2
[deliverable/linux.git] / drivers / staging / lustre / lustre / include / obd_class.h
1 /*
2 * GPL HEADER START
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 *
24 * GPL HEADER END
25 */
26 /*
27 * Copyright (c) 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
39
40 #include <obd_support.h>
41 #include <lustre_import.h>
42 #include <lustre_net.h>
43 #include <obd.h>
44 #include <lustre_lib.h>
45 #include <lustre/lustre_idl.h>
46 #include <lprocfs_status.h>
47
48 #include <linux/obd_class.h>
49
50 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
51 * and resends for avoid deadlocks */
52 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
53 * obd_osfs_age */
54 #define OBD_STATFS_PTLRPCD 0x0004 /* requests will be sent via ptlrpcd
55 * instead of a specific set. This
56 * means that we cannot rely on the set
57 * interpret routine to be called.
58 * lov_statfs_fini() must thus be called
59 * by the request interpret routine */
60 #define OBD_STATFS_FOR_MDT0 0x0008 /* The statfs is only for retrieving
61 * information from MDT0. */
62 #define OBD_FL_PUNCH 0x00000001 /* To indicate it is punch operation */
63
64 /* OBD Device Declarations */
65 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
66 extern rwlock_t obd_dev_lock;
67
68 /* OBD Operations Declarations */
69 extern struct obd_device *class_conn2obd(struct lustre_handle *);
70 extern struct obd_device *class_exp2obd(struct obd_export *);
71 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
72 extern int lustre_get_jobid(char *jobid);
73
74 struct lu_device_type;
75
76 /* genops.c */
77 struct obd_export *class_conn2export(struct lustre_handle *);
78 int class_register_type(struct obd_ops *, struct md_ops *,
79 struct lprocfs_vars *, const char *nm,
80 struct lu_device_type *ldt);
81 int class_unregister_type(const char *nm);
82
83 struct obd_device *class_newdev(const char *type_name, const char *name);
84 void class_release_dev(struct obd_device *obd);
85
86 int class_name2dev(const char *name);
87 struct obd_device *class_name2obd(const char *name);
88 int class_uuid2dev(struct obd_uuid *uuid);
89 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
90 void class_obd_list(void);
91 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
92 const char * typ_name,
93 struct obd_uuid *grp_uuid);
94 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
95 int *next);
96 struct obd_device * class_num2obd(int num);
97 int get_devices_count(void);
98
99 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
100
101 char *obd_export_nid2str(struct obd_export *exp);
102
103 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
104 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
105 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
106
107 int obd_zombie_impexp_init(void);
108 void obd_zombie_impexp_stop(void);
109 void obd_zombie_impexp_cull(void);
110 void obd_zombie_barrier(void);
111 void obd_exports_barrier(struct obd_device *obd);
112 int kuc_len(int payload_len);
113 struct kuc_hdr * kuc_ptr(void *p);
114 int kuc_ispayload(void *p);
115 void *kuc_alloc(int payload_len, int transport, int type);
116 void kuc_free(void *p, int payload_len);
117
118 struct llog_handle;
119 struct llog_rec_hdr;
120 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
121 struct llog_rec_hdr *, void *);
122 /* obd_config.c */
123 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
124 const char *new_name);
125 int class_process_config(struct lustre_cfg *lcfg);
126 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
127 struct lustre_cfg *lcfg, void *data);
128 int class_attach(struct lustre_cfg *lcfg);
129 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
130 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
131 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
132 struct obd_device *class_incref(struct obd_device *obd,
133 const char *scope, const void *source);
134 void class_decref(struct obd_device *obd,
135 const char *scope, const void *source);
136 void dump_exports(struct obd_device *obd, int locks);
137 int class_config_llog_handler(const struct lu_env *env,
138 struct llog_handle *handle,
139 struct llog_rec_hdr *rec, void *data);
140 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
141 int class_add_uuid(const char *uuid, __u64 nid);
142
143 /*obdecho*/
144 #ifdef LPROCFS
145 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
146 #else
147 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
148 {
149 memset(lvars, 0, sizeof(*lvars));
150 }
151 #endif
152
153 #define CFG_F_START 0x01 /* Set when we start updating from a log */
154 #define CFG_F_MARKER 0x02 /* We are within a maker */
155 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
156 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
157 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
158
159 /* Passed as data param to class_config_parse_llog */
160 struct config_llog_instance {
161 char *cfg_obdname;
162 void *cfg_instance;
163 struct super_block *cfg_sb;
164 struct obd_uuid cfg_uuid;
165 llog_cb_t cfg_callback;
166 int cfg_last_idx; /* for partial llog processing */
167 int cfg_flags;
168 };
169 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
170 char *name, struct config_llog_instance *cfg);
171 int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
172 char *name, struct config_llog_instance *cfg);
173
174 enum {
175 CONFIG_T_CONFIG = 0,
176 CONFIG_T_SPTLRPC = 1,
177 CONFIG_T_RECOVER = 2,
178 CONFIG_T_PARAMS = 3,
179 CONFIG_T_MAX = 4
180 };
181
182 #define PARAMS_FILENAME "params"
183 #define LCTL_UPCALL "lctl"
184
185 /* list of active configuration logs */
186 struct config_llog_data {
187 struct ldlm_res_id cld_resid;
188 struct config_llog_instance cld_cfg;
189 struct list_head cld_list_chain;
190 atomic_t cld_refcount;
191 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
192 struct config_llog_data *cld_params; /* common parameters log */
193 struct config_llog_data *cld_recover;/* imperative recover log */
194 struct obd_export *cld_mgcexp;
195 struct mutex cld_lock;
196 int cld_type;
197 unsigned int cld_stopping:1, /* we were told to stop
198 * watching */
199 cld_lostlock:1; /* lock not requeued */
200 char cld_logname[0];
201 };
202
203 struct lustre_profile {
204 struct list_head lp_list;
205 char *lp_profile;
206 char *lp_dt;
207 char *lp_md;
208 };
209
210 struct lustre_profile *class_get_profile(const char * prof);
211 void class_del_profile(const char *prof);
212 void class_del_profiles(void);
213
214 #if LUSTRE_TRACKS_LOCK_EXP_REFS
215
216 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
217 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
218 extern void (*class_export_dump_hook)(struct obd_export *);
219
220 #else
221
222 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
223 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
224
225 #endif
226
227 #define class_export_rpc_inc(exp) \
228 ({ \
229 atomic_inc(&(exp)->exp_rpc_count); \
230 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
231 (exp), atomic_read(&(exp)->exp_rpc_count)); \
232 })
233
234 #define class_export_rpc_dec(exp) \
235 ({ \
236 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
237 atomic_dec(&(exp)->exp_rpc_count); \
238 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
239 (exp), atomic_read(&(exp)->exp_rpc_count)); \
240 })
241
242 #define class_export_lock_get(exp, lock) \
243 ({ \
244 atomic_inc(&(exp)->exp_locks_count); \
245 __class_export_add_lock_ref(exp, lock); \
246 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
247 (exp), atomic_read(&(exp)->exp_locks_count)); \
248 class_export_get(exp); \
249 })
250
251 #define class_export_lock_put(exp, lock) \
252 ({ \
253 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
254 atomic_dec(&(exp)->exp_locks_count); \
255 __class_export_del_lock_ref(exp, lock); \
256 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
257 (exp), atomic_read(&(exp)->exp_locks_count)); \
258 class_export_put(exp); \
259 })
260
261 #define class_export_cb_get(exp) \
262 ({ \
263 atomic_inc(&(exp)->exp_cb_count); \
264 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
265 (exp), atomic_read(&(exp)->exp_cb_count)); \
266 class_export_get(exp); \
267 })
268
269 #define class_export_cb_put(exp) \
270 ({ \
271 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
272 atomic_dec(&(exp)->exp_cb_count); \
273 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
274 (exp), atomic_read(&(exp)->exp_cb_count)); \
275 class_export_put(exp); \
276 })
277
278 /* genops.c */
279 struct obd_export *class_export_get(struct obd_export *exp);
280 void class_export_put(struct obd_export *exp);
281 struct obd_export *class_new_export(struct obd_device *obddev,
282 struct obd_uuid *cluuid);
283 void class_unlink_export(struct obd_export *exp);
284
285 struct obd_import *class_import_get(struct obd_import *);
286 void class_import_put(struct obd_import *);
287 struct obd_import *class_new_import(struct obd_device *obd);
288 void class_destroy_import(struct obd_import *exp);
289
290 struct obd_type *class_search_type(const char *name);
291 struct obd_type *class_get_type(const char *name);
292 void class_put_type(struct obd_type *type);
293 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
294 struct obd_uuid *cluuid);
295 int class_disconnect(struct obd_export *exp);
296 void class_fail_export(struct obd_export *exp);
297 int class_connected_export(struct obd_export *exp);
298 void class_disconnect_exports(struct obd_device *obddev);
299 int class_manual_cleanup(struct obd_device *obd);
300 void class_disconnect_stale_exports(struct obd_device *,
301 int (*test_export)(struct obd_export *));
302 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
303 {
304 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
305 (obd->obd_force ? OBD_OPT_FORCE : 0) |
306 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
307 0);
308 }
309
310
311 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
312 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
313 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
314 unsigned int ia_valid);
315 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
316 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
317 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
318 unsigned int valid);
319
320 void obdo_cpu_to_le(struct obdo *dobdo, struct obdo *sobdo);
321 void obdo_le_to_cpu(struct obdo *dobdo, struct obdo *sobdo);
322
323 #define OBT(dev) (dev)->obd_type
324 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
325 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
326 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
327
328 /* Ensure obd_setup: used for cleanup which must be called
329 while obd is stopping */
330 #define OBD_CHECK_DEV(obd) \
331 do { \
332 if (!(obd)) { \
333 CERROR("NULL device\n"); \
334 return -ENODEV; \
335 } \
336 } while (0)
337
338 /* ensure obd_setup and !obd_stopping */
339 #define OBD_CHECK_DEV_ACTIVE(obd) \
340 do { \
341 OBD_CHECK_DEV(obd); \
342 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
343 CERROR("Device %d not setup\n", \
344 (obd)->obd_minor); \
345 return -ENODEV; \
346 } \
347 } while (0)
348
349
350 #ifdef LPROCFS
351 #define OBD_COUNTER_OFFSET(op) \
352 ((offsetof(struct obd_ops, o_ ## op) - \
353 offsetof(struct obd_ops, o_iocontrol)) \
354 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
355
356 #define OBD_COUNTER_INCREMENT(obdx, op) \
357 if ((obdx)->obd_stats != NULL) { \
358 unsigned int coffset; \
359 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
360 OBD_COUNTER_OFFSET(op); \
361 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
362 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
363 }
364
365 #define EXP_COUNTER_INCREMENT(export, op) \
366 if ((export)->exp_obd->obd_stats != NULL) { \
367 unsigned int coffset; \
368 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
369 OBD_COUNTER_OFFSET(op); \
370 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
371 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
372 if ((export)->exp_nid_stats != NULL && \
373 (export)->exp_nid_stats->nid_stats != NULL) \
374 lprocfs_counter_incr( \
375 (export)->exp_nid_stats->nid_stats, coffset);\
376 }
377
378 #define MD_COUNTER_OFFSET(op) \
379 ((offsetof(struct md_ops, m_ ## op) - \
380 offsetof(struct md_ops, m_getstatus)) \
381 / sizeof(((struct md_ops *)(0))->m_getstatus))
382
383 #define MD_COUNTER_INCREMENT(obdx, op) \
384 if ((obd)->md_stats != NULL) { \
385 unsigned int coffset; \
386 coffset = (unsigned int)((obdx)->md_cntr_base) + \
387 MD_COUNTER_OFFSET(op); \
388 LASSERT(coffset < (obdx)->md_stats->ls_num); \
389 lprocfs_counter_incr((obdx)->md_stats, coffset); \
390 }
391
392 #define EXP_MD_COUNTER_INCREMENT(export, op) \
393 if ((export)->exp_obd->obd_stats != NULL) { \
394 unsigned int coffset; \
395 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
396 MD_COUNTER_OFFSET(op); \
397 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
398 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
399 if ((export)->exp_md_stats != NULL) \
400 lprocfs_counter_incr( \
401 (export)->exp_md_stats, coffset); \
402 }
403
404 #else
405 #define OBD_COUNTER_OFFSET(op)
406 #define OBD_COUNTER_INCREMENT(obd, op)
407 #define EXP_COUNTER_INCREMENT(exp, op)
408 #define MD_COUNTER_INCREMENT(obd, op)
409 #define EXP_MD_COUNTER_INCREMENT(exp, op)
410 #endif
411
412 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
413 {
414 /* Always add in ldlm_stats */
415 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
416 ,LPROCFS_STATS_FLAG_NOPERCPU);
417 if (tmp->nid_ldlm_stats == NULL)
418 return -ENOMEM;
419
420 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
421
422 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
423 tmp->nid_ldlm_stats);
424 }
425
426 #define OBD_CHECK_MD_OP(obd, op, err) \
427 do { \
428 if (!OBT(obd) || !MDP((obd), op)) { \
429 if (err) \
430 CERROR("md_" #op ": dev %s/%d no operation\n", \
431 obd->obd_name, obd->obd_minor); \
432 return err; \
433 } \
434 } while (0)
435
436 #define EXP_CHECK_MD_OP(exp, op) \
437 do { \
438 if ((exp) == NULL) { \
439 CERROR("obd_" #op ": NULL export\n"); \
440 return -ENODEV; \
441 } \
442 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
443 CERROR("obd_" #op ": cleaned up obd\n"); \
444 return -EOPNOTSUPP; \
445 } \
446 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
447 CERROR("obd_" #op ": dev %s/%d no operation\n", \
448 (exp)->exp_obd->obd_name, \
449 (exp)->exp_obd->obd_minor); \
450 return -EOPNOTSUPP; \
451 } \
452 } while (0)
453
454
455 #define OBD_CHECK_DT_OP(obd, op, err) \
456 do { \
457 if (!OBT(obd) || !OBP((obd), op)) { \
458 if (err) \
459 CERROR("obd_" #op ": dev %d no operation\n", \
460 obd->obd_minor); \
461 return err; \
462 } \
463 } while (0)
464
465 #define EXP_CHECK_DT_OP(exp, op) \
466 do { \
467 if ((exp) == NULL) { \
468 CERROR("obd_" #op ": NULL export\n"); \
469 return -ENODEV; \
470 } \
471 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
472 CERROR("obd_" #op ": cleaned up obd\n"); \
473 return -EOPNOTSUPP; \
474 } \
475 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
476 CERROR("obd_" #op ": dev %d no operation\n", \
477 (exp)->exp_obd->obd_minor); \
478 return -EOPNOTSUPP; \
479 } \
480 } while (0)
481
482 #define CTXT_CHECK_OP(ctxt, op, err) \
483 do { \
484 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
485 if (err) \
486 CERROR("lop_" #op ": dev %d no operation\n", \
487 ctxt->loc_obd->obd_minor); \
488 return err; \
489 } \
490 } while (0)
491
492 static inline int class_devno_max(void)
493 {
494 return MAX_OBD_DEVICES;
495 }
496
497 static inline int obd_get_info(const struct lu_env *env,
498 struct obd_export *exp, __u32 keylen,
499 void *key, __u32 *vallen, void *val,
500 struct lov_stripe_md *lsm)
501 {
502 int rc;
503
504 EXP_CHECK_DT_OP(exp, get_info);
505 EXP_COUNTER_INCREMENT(exp, get_info);
506
507 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val,
508 lsm);
509 return rc;
510 }
511
512 static inline int obd_set_info_async(const struct lu_env *env,
513 struct obd_export *exp, obd_count keylen,
514 void *key, obd_count vallen, void *val,
515 struct ptlrpc_request_set *set)
516 {
517 int rc;
518
519 EXP_CHECK_DT_OP(exp, set_info_async);
520 EXP_COUNTER_INCREMENT(exp, set_info_async);
521
522 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
523 val, set);
524 return rc;
525 }
526
527 /*
528 * obd-lu integration.
529 *
530 * Functionality is being moved into new lu_device-based layering, but some
531 * pieces of configuration process are still based on obd devices.
532 *
533 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
534 * subsume ->o_setup() methods of obd devices they replace. The same for
535 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
536 * result, obd_setup() and obd_process_config() branch and call one XOR
537 * another.
538 *
539 * Yet neither lu_device_type_operations::ldto_device_fini() nor
540 * lu_device_type_operations::ldto_device_free() fully implement the
541 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
542 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
543 */
544
545 #define DECLARE_LU_VARS(ldt, d) \
546 struct lu_device_type *ldt; \
547 struct lu_device *d
548
549 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
550 {
551 int rc;
552 DECLARE_LU_VARS(ldt, d);
553
554 ldt = obd->obd_type->typ_lu;
555 if (ldt != NULL) {
556 struct lu_context session_ctx;
557 struct lu_env env;
558 lu_context_init(&session_ctx, LCT_SESSION);
559 session_ctx.lc_thread = NULL;
560 lu_context_enter(&session_ctx);
561
562 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
563 if (rc == 0) {
564 env.le_ses = &session_ctx;
565 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
566 lu_env_fini(&env);
567 if (!IS_ERR(d)) {
568 obd->obd_lu_dev = d;
569 d->ld_obd = obd;
570 rc = 0;
571 } else
572 rc = PTR_ERR(d);
573 }
574 lu_context_exit(&session_ctx);
575 lu_context_fini(&session_ctx);
576
577 } else {
578 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
579 OBD_COUNTER_INCREMENT(obd, setup);
580 rc = OBP(obd, setup)(obd, cfg);
581 }
582 return rc;
583 }
584
585 static inline int obd_precleanup(struct obd_device *obd,
586 enum obd_cleanup_stage cleanup_stage)
587 {
588 int rc;
589 DECLARE_LU_VARS(ldt, d);
590
591 OBD_CHECK_DEV(obd);
592 ldt = obd->obd_type->typ_lu;
593 d = obd->obd_lu_dev;
594 if (ldt != NULL && d != NULL) {
595 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
596 struct lu_env env;
597
598 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
599 if (rc == 0) {
600 ldt->ldt_ops->ldto_device_fini(&env, d);
601 lu_env_fini(&env);
602 }
603 }
604 }
605 OBD_CHECK_DT_OP(obd, precleanup, 0);
606 OBD_COUNTER_INCREMENT(obd, precleanup);
607
608 rc = OBP(obd, precleanup)(obd, cleanup_stage);
609 return rc;
610 }
611
612 static inline int obd_cleanup(struct obd_device *obd)
613 {
614 int rc;
615 DECLARE_LU_VARS(ldt, d);
616
617 OBD_CHECK_DEV(obd);
618
619 ldt = obd->obd_type->typ_lu;
620 d = obd->obd_lu_dev;
621 if (ldt != NULL && d != NULL) {
622 struct lu_env env;
623
624 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
625 if (rc == 0) {
626 ldt->ldt_ops->ldto_device_free(&env, d);
627 lu_env_fini(&env);
628 obd->obd_lu_dev = NULL;
629 }
630 }
631 OBD_CHECK_DT_OP(obd, cleanup, 0);
632 OBD_COUNTER_INCREMENT(obd, cleanup);
633
634 rc = OBP(obd, cleanup)(obd);
635 return rc;
636 }
637
638 static inline void obd_cleanup_client_import(struct obd_device *obd)
639 {
640 /* If we set up but never connected, the
641 client import will not have been cleaned. */
642 down_write(&obd->u.cli.cl_sem);
643 if (obd->u.cli.cl_import) {
644 struct obd_import *imp;
645 imp = obd->u.cli.cl_import;
646 CDEBUG(D_CONFIG, "%s: client import never connected\n",
647 obd->obd_name);
648 ptlrpc_invalidate_import(imp);
649 if (imp->imp_rq_pool) {
650 ptlrpc_free_rq_pool(imp->imp_rq_pool);
651 imp->imp_rq_pool = NULL;
652 }
653 client_destroy_import(imp);
654 obd->u.cli.cl_import = NULL;
655 }
656 up_write(&obd->u.cli.cl_sem);
657 }
658
659 static inline int
660 obd_process_config(struct obd_device *obd, int datalen, void *data)
661 {
662 int rc;
663 DECLARE_LU_VARS(ldt, d);
664
665 OBD_CHECK_DEV(obd);
666
667 obd->obd_process_conf = 1;
668 ldt = obd->obd_type->typ_lu;
669 d = obd->obd_lu_dev;
670 if (ldt != NULL && d != NULL) {
671 struct lu_env env;
672
673 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
674 if (rc == 0) {
675 rc = d->ld_ops->ldo_process_config(&env, d, data);
676 lu_env_fini(&env);
677 }
678 } else {
679 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
680 rc = OBP(obd, process_config)(obd, datalen, data);
681 }
682 OBD_COUNTER_INCREMENT(obd, process_config);
683 obd->obd_process_conf = 0;
684
685 return rc;
686 }
687
688 /* Pack an in-memory MD struct for storage on disk.
689 * Returns +ve size of packed MD (0 for free), or -ve error.
690 *
691 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
692 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
693 * If @*disk_tgt == NULL, it will be allocated
694 */
695 static inline int obd_packmd(struct obd_export *exp,
696 struct lov_mds_md **disk_tgt,
697 struct lov_stripe_md *mem_src)
698 {
699 int rc;
700
701 EXP_CHECK_DT_OP(exp, packmd);
702 EXP_COUNTER_INCREMENT(exp, packmd);
703
704 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
705 return rc;
706 }
707
708 static inline int obd_size_diskmd(struct obd_export *exp,
709 struct lov_stripe_md *mem_src)
710 {
711 return obd_packmd(exp, NULL, mem_src);
712 }
713
714 /* helper functions */
715 static inline int obd_alloc_diskmd(struct obd_export *exp,
716 struct lov_mds_md **disk_tgt)
717 {
718 LASSERT(disk_tgt);
719 LASSERT(*disk_tgt == NULL);
720 return obd_packmd(exp, disk_tgt, NULL);
721 }
722
723 static inline int obd_free_diskmd(struct obd_export *exp,
724 struct lov_mds_md **disk_tgt)
725 {
726 LASSERT(disk_tgt);
727 LASSERT(*disk_tgt);
728 /*
729 * LU-2590, for caller's convenience, *disk_tgt could be host
730 * endianness, it needs swab to LE if necessary, while just
731 * lov_mds_md header needs it for figuring out how much memory
732 * needs to be freed.
733 */
734 if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
735 (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) ||
736 ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3)))
737 lustre_swab_lov_mds_md(*disk_tgt);
738 return obd_packmd(exp, disk_tgt, NULL);
739 }
740
741 /* Unpack an MD struct from disk to in-memory format.
742 * Returns +ve size of unpacked MD (0 for free), or -ve error.
743 *
744 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
745 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
746 * If @*mem_tgt == NULL, it will be allocated
747 */
748 static inline int obd_unpackmd(struct obd_export *exp,
749 struct lov_stripe_md **mem_tgt,
750 struct lov_mds_md *disk_src,
751 int disk_len)
752 {
753 int rc;
754
755 EXP_CHECK_DT_OP(exp, unpackmd);
756 EXP_COUNTER_INCREMENT(exp, unpackmd);
757
758 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
759 return rc;
760 }
761
762 /* helper functions */
763 static inline int obd_alloc_memmd(struct obd_export *exp,
764 struct lov_stripe_md **mem_tgt)
765 {
766 LASSERT(mem_tgt);
767 LASSERT(*mem_tgt == NULL);
768 return obd_unpackmd(exp, mem_tgt, NULL, 0);
769 }
770
771 static inline int obd_free_memmd(struct obd_export *exp,
772 struct lov_stripe_md **mem_tgt)
773 {
774 int rc;
775
776 LASSERT(mem_tgt);
777 LASSERT(*mem_tgt);
778 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
779 *mem_tgt = NULL;
780 return rc;
781 }
782
783 static inline int obd_precreate(struct obd_export *exp)
784 {
785 int rc;
786
787 EXP_CHECK_DT_OP(exp, precreate);
788 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
789
790 rc = OBP(exp->exp_obd, precreate)(exp);
791 return rc;
792 }
793
794 static inline int obd_create_async(struct obd_export *exp,
795 struct obd_info *oinfo,
796 struct lov_stripe_md **ea,
797 struct obd_trans_info *oti)
798 {
799 int rc;
800
801 EXP_CHECK_DT_OP(exp, create_async);
802 EXP_COUNTER_INCREMENT(exp, create_async);
803
804 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
805 return rc;
806 }
807
808 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
809 struct obdo *obdo, struct lov_stripe_md **ea,
810 struct obd_trans_info *oti)
811 {
812 int rc;
813
814 EXP_CHECK_DT_OP(exp, create);
815 EXP_COUNTER_INCREMENT(exp, create);
816
817 rc = OBP(exp->exp_obd, create)(env, exp, obdo, ea, oti);
818 return rc;
819 }
820
821 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
822 struct obdo *obdo, struct lov_stripe_md *ea,
823 struct obd_trans_info *oti,
824 struct obd_export *md_exp, void *capa)
825 {
826 int rc;
827
828 EXP_CHECK_DT_OP(exp, destroy);
829 EXP_COUNTER_INCREMENT(exp, destroy);
830
831 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp, capa);
832 return rc;
833 }
834
835 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
836 struct obd_info *oinfo)
837 {
838 int rc;
839
840 EXP_CHECK_DT_OP(exp, getattr);
841 EXP_COUNTER_INCREMENT(exp, getattr);
842
843 rc = OBP(exp->exp_obd, getattr)(env, exp, oinfo);
844 return rc;
845 }
846
847 static inline int obd_getattr_async(struct obd_export *exp,
848 struct obd_info *oinfo,
849 struct ptlrpc_request_set *set)
850 {
851 int rc;
852
853 EXP_CHECK_DT_OP(exp, getattr_async);
854 EXP_COUNTER_INCREMENT(exp, getattr_async);
855
856 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
857 return rc;
858 }
859
860 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
861 struct obd_info *oinfo,
862 struct obd_trans_info *oti)
863 {
864 int rc;
865
866 EXP_CHECK_DT_OP(exp, setattr);
867 EXP_COUNTER_INCREMENT(exp, setattr);
868
869 rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti);
870 return rc;
871 }
872
873 /* This performs all the requests set init/wait/destroy actions. */
874 static inline int obd_setattr_rqset(struct obd_export *exp,
875 struct obd_info *oinfo,
876 struct obd_trans_info *oti)
877 {
878 struct ptlrpc_request_set *set = NULL;
879 int rc;
880
881 EXP_CHECK_DT_OP(exp, setattr_async);
882 EXP_COUNTER_INCREMENT(exp, setattr_async);
883
884 set = ptlrpc_prep_set();
885 if (set == NULL)
886 return -ENOMEM;
887
888 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
889 if (rc == 0)
890 rc = ptlrpc_set_wait(set);
891 ptlrpc_set_destroy(set);
892 return rc;
893 }
894
895 /* This adds all the requests into @set if @set != NULL, otherwise
896 all requests are sent asynchronously without waiting for response. */
897 static inline int obd_setattr_async(struct obd_export *exp,
898 struct obd_info *oinfo,
899 struct obd_trans_info *oti,
900 struct ptlrpc_request_set *set)
901 {
902 int rc;
903
904 EXP_CHECK_DT_OP(exp, setattr_async);
905 EXP_COUNTER_INCREMENT(exp, setattr_async);
906
907 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
908 return rc;
909 }
910
911 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
912 int priority)
913 {
914 struct obd_device *obd = imp->imp_obd;
915 int rc;
916
917 OBD_CHECK_DEV_ACTIVE(obd);
918 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
919 OBD_COUNTER_INCREMENT(obd, add_conn);
920
921 rc = OBP(obd, add_conn)(imp, uuid, priority);
922 return rc;
923 }
924
925 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
926 {
927 struct obd_device *obd = imp->imp_obd;
928 int rc;
929
930 OBD_CHECK_DEV_ACTIVE(obd);
931 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
932 OBD_COUNTER_INCREMENT(obd, del_conn);
933
934 rc = OBP(obd, del_conn)(imp, uuid);
935 return rc;
936 }
937
938 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
939 {
940 struct obd_uuid *uuid;
941
942 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
943 EXP_COUNTER_INCREMENT(exp, get_uuid);
944
945 uuid = OBP(exp->exp_obd, get_uuid)(exp);
946 return uuid;
947 }
948
949 /** Create a new /a exp on device /a obd for the uuid /a cluuid
950 * @param exp New export handle
951 * @param d Connect data, supported flags are set, flags also understood
952 * by obd are returned.
953 */
954 static inline int obd_connect(const struct lu_env *env,
955 struct obd_export **exp,struct obd_device *obd,
956 struct obd_uuid *cluuid,
957 struct obd_connect_data *data,
958 void *localdata)
959 {
960 int rc;
961 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
962 * check */
963
964 OBD_CHECK_DEV_ACTIVE(obd);
965 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
966 OBD_COUNTER_INCREMENT(obd, connect);
967
968 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
969 /* check that only subset is granted */
970 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
971 data->ocd_connect_flags));
972 return rc;
973 }
974
975 static inline int obd_reconnect(const struct lu_env *env,
976 struct obd_export *exp,
977 struct obd_device *obd,
978 struct obd_uuid *cluuid,
979 struct obd_connect_data *d,
980 void *localdata)
981 {
982 int rc;
983 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
984 * check */
985
986 OBD_CHECK_DEV_ACTIVE(obd);
987 OBD_CHECK_DT_OP(obd, reconnect, 0);
988 OBD_COUNTER_INCREMENT(obd, reconnect);
989
990 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
991 /* check that only subset is granted */
992 LASSERT(ergo(d != NULL,
993 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
994 return rc;
995 }
996
997 static inline int obd_disconnect(struct obd_export *exp)
998 {
999 int rc;
1000
1001 EXP_CHECK_DT_OP(exp, disconnect);
1002 EXP_COUNTER_INCREMENT(exp, disconnect);
1003
1004 rc = OBP(exp->exp_obd, disconnect)(exp);
1005 return rc;
1006 }
1007
1008 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
1009 enum lu_cli_type type)
1010 {
1011 int rc;
1012
1013 OBD_CHECK_DT_OP(obd, fid_init, 0);
1014 OBD_COUNTER_INCREMENT(obd, fid_init);
1015
1016 rc = OBP(obd, fid_init)(obd, exp, type);
1017 return rc;
1018 }
1019
1020 static inline int obd_fid_fini(struct obd_device *obd)
1021 {
1022 int rc;
1023
1024 OBD_CHECK_DT_OP(obd, fid_fini, 0);
1025 OBD_COUNTER_INCREMENT(obd, fid_fini);
1026
1027 rc = OBP(obd, fid_fini)(obd);
1028 return rc;
1029 }
1030
1031 static inline int obd_fid_alloc(struct obd_export *exp,
1032 struct lu_fid *fid,
1033 struct md_op_data *op_data)
1034 {
1035 int rc;
1036
1037 EXP_CHECK_DT_OP(exp, fid_alloc);
1038 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1039
1040 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
1041 return rc;
1042 }
1043
1044 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
1045 {
1046 int rc;
1047
1048 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1049 EXP_COUNTER_INCREMENT(exp, ping);
1050
1051 rc = OBP(exp->exp_obd, ping)(env, exp);
1052 return rc;
1053 }
1054
1055 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1056 {
1057 int rc;
1058
1059 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1060 OBD_COUNTER_INCREMENT(obd, pool_new);
1061
1062 rc = OBP(obd, pool_new)(obd, poolname);
1063 return rc;
1064 }
1065
1066 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1067 {
1068 int rc;
1069
1070 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1071 OBD_COUNTER_INCREMENT(obd, pool_del);
1072
1073 rc = OBP(obd, pool_del)(obd, poolname);
1074 return rc;
1075 }
1076
1077 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1078 {
1079 int rc;
1080
1081 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1082 OBD_COUNTER_INCREMENT(obd, pool_add);
1083
1084 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1085 return rc;
1086 }
1087
1088 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1089 {
1090 int rc;
1091
1092 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1093 OBD_COUNTER_INCREMENT(obd, pool_rem);
1094
1095 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1096 return rc;
1097 }
1098
1099 static inline void obd_getref(struct obd_device *obd)
1100 {
1101 if (OBT(obd) && OBP(obd, getref)) {
1102 OBD_COUNTER_INCREMENT(obd, getref);
1103 OBP(obd, getref)(obd);
1104 }
1105 }
1106
1107 static inline void obd_putref(struct obd_device *obd)
1108 {
1109 if (OBT(obd) && OBP(obd, putref)) {
1110 OBD_COUNTER_INCREMENT(obd, putref);
1111 OBP(obd, putref)(obd);
1112 }
1113 }
1114
1115 static inline int obd_init_export(struct obd_export *exp)
1116 {
1117 int rc = 0;
1118
1119 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1120 OBP((exp)->exp_obd, init_export))
1121 rc = OBP(exp->exp_obd, init_export)(exp);
1122 return rc;
1123 }
1124
1125 static inline int obd_destroy_export(struct obd_export *exp)
1126 {
1127 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1128 OBP((exp)->exp_obd, destroy_export))
1129 OBP(exp->exp_obd, destroy_export)(exp);
1130 return 0;
1131 }
1132
1133 static inline int obd_extent_calc(struct obd_export *exp,
1134 struct lov_stripe_md *md,
1135 int cmd, obd_off *offset)
1136 {
1137 int rc;
1138
1139 EXP_CHECK_DT_OP(exp, extent_calc);
1140 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1141 return rc;
1142 }
1143
1144 static inline struct dentry *
1145 obd_lvfs_fid2dentry(struct obd_export *exp, struct ost_id *oi, __u32 gen)
1146 {
1147 struct lvfs_run_ctxt *ctxt = &exp->exp_obd->obd_lvfs_ctxt;
1148 LASSERT(exp->exp_obd);
1149
1150 return ctxt->cb_ops.l_fid2dentry(ostid_id(oi), gen, ostid_seq(oi),
1151 exp->exp_obd);
1152 }
1153
1154 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1155 * If the cache is older than @max_age we will get a new value from the
1156 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1157 static inline int obd_statfs_async(struct obd_export *exp,
1158 struct obd_info *oinfo,
1159 __u64 max_age,
1160 struct ptlrpc_request_set *rqset)
1161 {
1162 int rc = 0;
1163 struct obd_device *obd;
1164
1165 if (exp == NULL || exp->exp_obd == NULL)
1166 return -EINVAL;
1167
1168 obd = exp->exp_obd;
1169 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1170 OBD_COUNTER_INCREMENT(obd, statfs);
1171
1172 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1173 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1174 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1175 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1176 } else {
1177 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1178 " objects "LPU64"/"LPU64"\n",
1179 obd->obd_name, &obd->obd_osfs,
1180 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1181 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1182 spin_lock(&obd->obd_osfs_lock);
1183 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1184 spin_unlock(&obd->obd_osfs_lock);
1185 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1186 if (oinfo->oi_cb_up)
1187 oinfo->oi_cb_up(oinfo, 0);
1188 }
1189 return rc;
1190 }
1191
1192 static inline int obd_statfs_rqset(struct obd_export *exp,
1193 struct obd_statfs *osfs, __u64 max_age,
1194 __u32 flags)
1195 {
1196 struct ptlrpc_request_set *set = NULL;
1197 struct obd_info oinfo = { { { 0 } } };
1198 int rc = 0;
1199
1200 set = ptlrpc_prep_set();
1201 if (set == NULL)
1202 return -ENOMEM;
1203
1204 oinfo.oi_osfs = osfs;
1205 oinfo.oi_flags = flags;
1206 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1207 if (rc == 0)
1208 rc = ptlrpc_set_wait(set);
1209 ptlrpc_set_destroy(set);
1210 return rc;
1211 }
1212
1213 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1214 * If the cache is older than @max_age we will get a new value from the
1215 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1216 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1217 struct obd_statfs *osfs, __u64 max_age,
1218 __u32 flags)
1219 {
1220 int rc = 0;
1221 struct obd_device *obd = exp->exp_obd;
1222
1223 if (obd == NULL)
1224 return -EINVAL;
1225
1226 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1227 OBD_COUNTER_INCREMENT(obd, statfs);
1228
1229 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1230 obd->obd_osfs_age, max_age);
1231 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1232 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1233 if (rc == 0) {
1234 spin_lock(&obd->obd_osfs_lock);
1235 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1236 obd->obd_osfs_age = cfs_time_current_64();
1237 spin_unlock(&obd->obd_osfs_lock);
1238 }
1239 } else {
1240 CDEBUG(D_SUPER, "%s: use %p cache blocks "LPU64"/"LPU64
1241 " objects "LPU64"/"LPU64"\n",
1242 obd->obd_name, &obd->obd_osfs,
1243 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1244 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1245 spin_lock(&obd->obd_osfs_lock);
1246 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1247 spin_unlock(&obd->obd_osfs_lock);
1248 }
1249 return rc;
1250 }
1251
1252 static inline int obd_sync_rqset(struct obd_export *exp, struct obd_info *oinfo,
1253 obd_size start, obd_size end)
1254 {
1255 struct ptlrpc_request_set *set = NULL;
1256 int rc;
1257
1258 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1259 EXP_COUNTER_INCREMENT(exp, sync);
1260
1261 set = ptlrpc_prep_set();
1262 if (set == NULL)
1263 return -ENOMEM;
1264
1265 rc = OBP(exp->exp_obd, sync)(NULL, exp, oinfo, start, end, set);
1266 if (rc == 0)
1267 rc = ptlrpc_set_wait(set);
1268 ptlrpc_set_destroy(set);
1269 return rc;
1270 }
1271
1272 static inline int obd_sync(const struct lu_env *env, struct obd_export *exp,
1273 struct obd_info *oinfo, obd_size start, obd_size end,
1274 struct ptlrpc_request_set *set)
1275 {
1276 int rc;
1277
1278 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1279 EXP_COUNTER_INCREMENT(exp, sync);
1280
1281 rc = OBP(exp->exp_obd, sync)(env, exp, oinfo, start, end, set);
1282 return rc;
1283 }
1284
1285 static inline int obd_punch_rqset(struct obd_export *exp,
1286 struct obd_info *oinfo,
1287 struct obd_trans_info *oti)
1288 {
1289 struct ptlrpc_request_set *set = NULL;
1290 int rc;
1291
1292 EXP_CHECK_DT_OP(exp, punch);
1293 EXP_COUNTER_INCREMENT(exp, punch);
1294
1295 set = ptlrpc_prep_set();
1296 if (set == NULL)
1297 return -ENOMEM;
1298
1299 rc = OBP(exp->exp_obd, punch)(NULL, exp, oinfo, oti, set);
1300 if (rc == 0)
1301 rc = ptlrpc_set_wait(set);
1302 ptlrpc_set_destroy(set);
1303 return rc;
1304 }
1305
1306 static inline int obd_punch(const struct lu_env *env, struct obd_export *exp,
1307 struct obd_info *oinfo, struct obd_trans_info *oti,
1308 struct ptlrpc_request_set *rqset)
1309 {
1310 int rc;
1311
1312 EXP_CHECK_DT_OP(exp, punch);
1313 EXP_COUNTER_INCREMENT(exp, punch);
1314
1315 rc = OBP(exp->exp_obd, punch)(env, exp, oinfo, oti, rqset);
1316 return rc;
1317 }
1318
1319 static inline int obd_brw(int cmd, struct obd_export *exp,
1320 struct obd_info *oinfo, obd_count oa_bufs,
1321 struct brw_page *pg, struct obd_trans_info *oti)
1322 {
1323 int rc;
1324
1325 EXP_CHECK_DT_OP(exp, brw);
1326 EXP_COUNTER_INCREMENT(exp, brw);
1327
1328 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1329 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1330 "or OBD_BRW_CHECK\n");
1331 LBUG();
1332 }
1333
1334 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1335 return rc;
1336 }
1337
1338 static inline int obd_preprw(const struct lu_env *env, int cmd,
1339 struct obd_export *exp, struct obdo *oa,
1340 int objcount, struct obd_ioobj *obj,
1341 struct niobuf_remote *remote, int *pages,
1342 struct niobuf_local *local,
1343 struct obd_trans_info *oti,
1344 struct lustre_capa *capa)
1345 {
1346 int rc;
1347
1348 EXP_CHECK_DT_OP(exp, preprw);
1349 EXP_COUNTER_INCREMENT(exp, preprw);
1350
1351 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1352 pages, local, oti, capa);
1353 return rc;
1354 }
1355
1356 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1357 struct obd_export *exp, struct obdo *oa,
1358 int objcount, struct obd_ioobj *obj,
1359 struct niobuf_remote *rnb, int pages,
1360 struct niobuf_local *local,
1361 struct obd_trans_info *oti, int rc)
1362 {
1363 EXP_CHECK_DT_OP(exp, commitrw);
1364 EXP_COUNTER_INCREMENT(exp, commitrw);
1365
1366 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1367 rnb, pages, local, oti, rc);
1368 return rc;
1369 }
1370
1371 static inline int obd_merge_lvb(struct obd_export *exp,
1372 struct lov_stripe_md *lsm,
1373 struct ost_lvb *lvb, int kms_only)
1374 {
1375 int rc;
1376
1377 EXP_CHECK_DT_OP(exp, merge_lvb);
1378 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1379
1380 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1381 return rc;
1382 }
1383
1384 static inline int obd_adjust_kms(struct obd_export *exp,
1385 struct lov_stripe_md *lsm, obd_off size,
1386 int shrink)
1387 {
1388 int rc;
1389
1390 EXP_CHECK_DT_OP(exp, adjust_kms);
1391 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1392
1393 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1394 return rc;
1395 }
1396
1397 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1398 int len, void *karg, void *uarg)
1399 {
1400 int rc;
1401
1402 EXP_CHECK_DT_OP(exp, iocontrol);
1403 EXP_COUNTER_INCREMENT(exp, iocontrol);
1404
1405 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1406 return rc;
1407 }
1408
1409 static inline int obd_enqueue_rqset(struct obd_export *exp,
1410 struct obd_info *oinfo,
1411 struct ldlm_enqueue_info *einfo)
1412 {
1413 struct ptlrpc_request_set *set = NULL;
1414 int rc;
1415
1416 EXP_CHECK_DT_OP(exp, enqueue);
1417 EXP_COUNTER_INCREMENT(exp, enqueue);
1418
1419 set = ptlrpc_prep_set();
1420 if (set == NULL)
1421 return -ENOMEM;
1422
1423 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1424 if (rc == 0)
1425 rc = ptlrpc_set_wait(set);
1426 ptlrpc_set_destroy(set);
1427 return rc;
1428 }
1429
1430 static inline int obd_enqueue(struct obd_export *exp,
1431 struct obd_info *oinfo,
1432 struct ldlm_enqueue_info *einfo,
1433 struct ptlrpc_request_set *set)
1434 {
1435 int rc;
1436
1437 EXP_CHECK_DT_OP(exp, enqueue);
1438 EXP_COUNTER_INCREMENT(exp, enqueue);
1439
1440 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1441 return rc;
1442 }
1443
1444 static inline int obd_change_cbdata(struct obd_export *exp,
1445 struct lov_stripe_md *lsm,
1446 ldlm_iterator_t it, void *data)
1447 {
1448 int rc;
1449
1450 EXP_CHECK_DT_OP(exp, change_cbdata);
1451 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1452
1453 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1454 return rc;
1455 }
1456
1457 static inline int obd_find_cbdata(struct obd_export *exp,
1458 struct lov_stripe_md *lsm,
1459 ldlm_iterator_t it, void *data)
1460 {
1461 int rc;
1462
1463 EXP_CHECK_DT_OP(exp, find_cbdata);
1464 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1465
1466 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1467 return rc;
1468 }
1469
1470 static inline int obd_cancel(struct obd_export *exp,
1471 struct lov_stripe_md *ea, __u32 mode,
1472 struct lustre_handle *lockh)
1473 {
1474 int rc;
1475
1476 EXP_CHECK_DT_OP(exp, cancel);
1477 EXP_COUNTER_INCREMENT(exp, cancel);
1478
1479 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1480 return rc;
1481 }
1482
1483 static inline int obd_cancel_unused(struct obd_export *exp,
1484 struct lov_stripe_md *ea,
1485 ldlm_cancel_flags_t flags,
1486 void *opaque)
1487 {
1488 int rc;
1489
1490 EXP_CHECK_DT_OP(exp, cancel_unused);
1491 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1492
1493 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1494 return rc;
1495 }
1496
1497 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1498 struct obd_capa *oc, struct obd_client_handle *handle,
1499 int flag)
1500 {
1501 int rc;
1502
1503 EXP_CHECK_DT_OP(exp, pin);
1504 EXP_COUNTER_INCREMENT(exp, pin);
1505
1506 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1507 return rc;
1508 }
1509
1510 static inline int obd_unpin(struct obd_export *exp,
1511 struct obd_client_handle *handle, int flag)
1512 {
1513 int rc;
1514
1515 EXP_CHECK_DT_OP(exp, unpin);
1516 EXP_COUNTER_INCREMENT(exp, unpin);
1517
1518 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1519 return rc;
1520 }
1521
1522
1523 static inline void obd_import_event(struct obd_device *obd,
1524 struct obd_import *imp,
1525 enum obd_import_event event)
1526 {
1527 if (!obd) {
1528 CERROR("NULL device\n");
1529 return;
1530 }
1531 if (obd->obd_set_up && OBP(obd, import_event)) {
1532 OBD_COUNTER_INCREMENT(obd, import_event);
1533 OBP(obd, import_event)(obd, imp, event);
1534 }
1535 }
1536
1537 static inline int obd_llog_connect(struct obd_export *exp,
1538 struct llogd_conn_body *body)
1539 {
1540 int rc;
1541
1542 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1543 EXP_COUNTER_INCREMENT(exp, llog_connect);
1544
1545 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1546 return rc;
1547 }
1548
1549
1550 static inline int obd_notify(struct obd_device *obd,
1551 struct obd_device *watched,
1552 enum obd_notify_event ev,
1553 void *data)
1554 {
1555 int rc;
1556
1557 OBD_CHECK_DEV(obd);
1558
1559 /* the check for async_recov is a complete hack - I'm hereby
1560 overloading the meaning to also mean "this was called from
1561 mds_postsetup". I know that my mds is able to handle notifies
1562 by this point, and it needs to get them to execute mds_postrecov. */
1563 if (!obd->obd_set_up && !obd->obd_async_recov) {
1564 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1565 return -EINVAL;
1566 }
1567
1568 if (!OBP(obd, notify)) {
1569 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1570 return -ENOSYS;
1571 }
1572
1573 OBD_COUNTER_INCREMENT(obd, notify);
1574 rc = OBP(obd, notify)(obd, watched, ev, data);
1575 return rc;
1576 }
1577
1578 static inline int obd_notify_observer(struct obd_device *observer,
1579 struct obd_device *observed,
1580 enum obd_notify_event ev,
1581 void *data)
1582 {
1583 int rc1;
1584 int rc2;
1585
1586 struct obd_notify_upcall *onu;
1587
1588 if (observer->obd_observer)
1589 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1590 else
1591 rc1 = 0;
1592 /*
1593 * Also, call non-obd listener, if any
1594 */
1595 onu = &observer->obd_upcall;
1596 if (onu->onu_upcall != NULL)
1597 rc2 = onu->onu_upcall(observer, observed, ev,
1598 onu->onu_owner, NULL);
1599 else
1600 rc2 = 0;
1601
1602 return rc1 ? rc1 : rc2;
1603 }
1604
1605 static inline int obd_quotacheck(struct obd_export *exp,
1606 struct obd_quotactl *oqctl)
1607 {
1608 int rc;
1609
1610 EXP_CHECK_DT_OP(exp, quotacheck);
1611 EXP_COUNTER_INCREMENT(exp, quotacheck);
1612
1613 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1614 return rc;
1615 }
1616
1617 static inline int obd_quotactl(struct obd_export *exp,
1618 struct obd_quotactl *oqctl)
1619 {
1620 int rc;
1621
1622 EXP_CHECK_DT_OP(exp, quotactl);
1623 EXP_COUNTER_INCREMENT(exp, quotactl);
1624
1625 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1626 return rc;
1627 }
1628
1629 static inline int obd_health_check(const struct lu_env *env,
1630 struct obd_device *obd)
1631 {
1632 /* returns: 0 on healthy
1633 * >0 on unhealthy + reason code/flag
1634 * however the only supported reason == 1 right now
1635 * We'll need to define some better reasons
1636 * or flags in the future.
1637 * <0 on error
1638 */
1639 int rc;
1640
1641 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1642 if (obd == NULL || !OBT(obd)) {
1643 CERROR("cleaned up obd\n");
1644 return -EOPNOTSUPP;
1645 }
1646 if (!obd->obd_set_up || obd->obd_stopping)
1647 return 0;
1648 if (!OBP(obd, health_check))
1649 return 0;
1650
1651 rc = OBP(obd, health_check)(env, obd);
1652 return rc;
1653 }
1654
1655 static inline int obd_register_observer(struct obd_device *obd,
1656 struct obd_device *observer)
1657 {
1658 OBD_CHECK_DEV(obd);
1659 down_write(&obd->obd_observer_link_sem);
1660 if (obd->obd_observer && observer) {
1661 up_write(&obd->obd_observer_link_sem);
1662 return -EALREADY;
1663 }
1664 obd->obd_observer = observer;
1665 up_write(&obd->obd_observer_link_sem);
1666 return 0;
1667 }
1668
1669 static inline int obd_pin_observer(struct obd_device *obd,
1670 struct obd_device **observer)
1671 {
1672 down_read(&obd->obd_observer_link_sem);
1673 if (!obd->obd_observer) {
1674 *observer = NULL;
1675 up_read(&obd->obd_observer_link_sem);
1676 return -ENOENT;
1677 }
1678 *observer = obd->obd_observer;
1679 return 0;
1680 }
1681
1682 static inline int obd_unpin_observer(struct obd_device *obd)
1683 {
1684 up_read(&obd->obd_observer_link_sem);
1685 return 0;
1686 }
1687
1688 #if 0
1689 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1690 obd_page_removal_cb_t cb,
1691 obd_pin_extent_cb pin_cb)
1692 {
1693 int rc;
1694
1695 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1696 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1697
1698 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1699 return rc;
1700 }
1701
1702 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1703 obd_page_removal_cb_t cb)
1704 {
1705 int rc;
1706
1707 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1708 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1709
1710 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1711 return rc;
1712 }
1713
1714 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1715 obd_lock_cancel_cb cb)
1716 {
1717 int rc;
1718
1719 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1720 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1721
1722 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1723 return rc;
1724 }
1725
1726 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1727 obd_lock_cancel_cb cb)
1728 {
1729 int rc;
1730
1731 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1732 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1733
1734 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1735 return rc;
1736 }
1737 #endif
1738
1739 /* metadata helpers */
1740 static inline int md_getstatus(struct obd_export *exp,
1741 struct lu_fid *fid, struct obd_capa **pc)
1742 {
1743 int rc;
1744
1745 EXP_CHECK_MD_OP(exp, getstatus);
1746 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1747 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1748 return rc;
1749 }
1750
1751 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1752 struct ptlrpc_request **request)
1753 {
1754 int rc;
1755
1756 EXP_CHECK_MD_OP(exp, getattr);
1757 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1758 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1759 return rc;
1760 }
1761
1762 static inline int md_null_inode(struct obd_export *exp,
1763 const struct lu_fid *fid)
1764 {
1765 int rc;
1766
1767 EXP_CHECK_MD_OP(exp, null_inode);
1768 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1769 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1770 return rc;
1771 }
1772
1773 static inline int md_find_cbdata(struct obd_export *exp,
1774 const struct lu_fid *fid,
1775 ldlm_iterator_t it, void *data)
1776 {
1777 int rc;
1778
1779 EXP_CHECK_MD_OP(exp, find_cbdata);
1780 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1781 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1782 return rc;
1783 }
1784
1785 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1786 struct md_open_data *mod,
1787 struct ptlrpc_request **request)
1788 {
1789 int rc;
1790
1791 EXP_CHECK_MD_OP(exp, close);
1792 EXP_MD_COUNTER_INCREMENT(exp, close);
1793 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1794 return rc;
1795 }
1796
1797 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1798 const void *data, int datalen, int mode, __u32 uid,
1799 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1800 struct ptlrpc_request **request)
1801 {
1802 int rc;
1803
1804 EXP_CHECK_MD_OP(exp, create);
1805 EXP_MD_COUNTER_INCREMENT(exp, create);
1806 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1807 uid, gid, cap_effective, rdev, request);
1808 return rc;
1809 }
1810
1811 static inline int md_done_writing(struct obd_export *exp,
1812 struct md_op_data *op_data,
1813 struct md_open_data *mod)
1814 {
1815 int rc;
1816
1817 EXP_CHECK_MD_OP(exp, done_writing);
1818 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1819 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1820 return rc;
1821 }
1822
1823 static inline int md_enqueue(struct obd_export *exp,
1824 struct ldlm_enqueue_info *einfo,
1825 struct lookup_intent *it,
1826 struct md_op_data *op_data,
1827 struct lustre_handle *lockh,
1828 void *lmm, int lmmsize,
1829 struct ptlrpc_request **req,
1830 int extra_lock_flags)
1831 {
1832 int rc;
1833
1834 EXP_CHECK_MD_OP(exp, enqueue);
1835 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1836 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1837 lmm, lmmsize, req, extra_lock_flags);
1838 return rc;
1839 }
1840
1841 static inline int md_getattr_name(struct obd_export *exp,
1842 struct md_op_data *op_data,
1843 struct ptlrpc_request **request)
1844 {
1845 int rc;
1846
1847 EXP_CHECK_MD_OP(exp, getattr_name);
1848 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1849 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1850 return rc;
1851 }
1852
1853 static inline int md_intent_lock(struct obd_export *exp,
1854 struct md_op_data *op_data, void *lmm,
1855 int lmmsize, struct lookup_intent *it,
1856 int lookup_flags, struct ptlrpc_request **reqp,
1857 ldlm_blocking_callback cb_blocking,
1858 __u64 extra_lock_flags)
1859 {
1860 int rc;
1861
1862 EXP_CHECK_MD_OP(exp, intent_lock);
1863 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1864 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1865 it, lookup_flags, reqp, cb_blocking,
1866 extra_lock_flags);
1867 return rc;
1868 }
1869
1870 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1871 struct ptlrpc_request **request)
1872 {
1873 int rc;
1874
1875 EXP_CHECK_MD_OP(exp, link);
1876 EXP_MD_COUNTER_INCREMENT(exp, link);
1877 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1878 return rc;
1879 }
1880
1881 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1882 const char *old, int oldlen, const char *new,
1883 int newlen, struct ptlrpc_request **request)
1884 {
1885 int rc;
1886
1887 EXP_CHECK_MD_OP(exp, rename);
1888 EXP_MD_COUNTER_INCREMENT(exp, rename);
1889 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1890 newlen, request);
1891 return rc;
1892 }
1893
1894 static inline int md_is_subdir(struct obd_export *exp,
1895 const struct lu_fid *pfid,
1896 const struct lu_fid *cfid,
1897 struct ptlrpc_request **request)
1898 {
1899 int rc;
1900
1901 EXP_CHECK_MD_OP(exp, is_subdir);
1902 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1903 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1904 return rc;
1905 }
1906
1907 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1908 void *ea, int ealen, void *ea2, int ea2len,
1909 struct ptlrpc_request **request,
1910 struct md_open_data **mod)
1911 {
1912 int rc;
1913
1914 EXP_CHECK_MD_OP(exp, setattr);
1915 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1916 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1917 ea2, ea2len, request, mod);
1918 return rc;
1919 }
1920
1921 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1922 struct obd_capa *oc, struct ptlrpc_request **request)
1923 {
1924 int rc;
1925
1926 EXP_CHECK_MD_OP(exp, sync);
1927 EXP_MD_COUNTER_INCREMENT(exp, sync);
1928 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1929 return rc;
1930 }
1931
1932 static inline int md_readpage(struct obd_export *exp, struct md_op_data *opdata,
1933 struct page **pages,
1934 struct ptlrpc_request **request)
1935 {
1936 int rc;
1937
1938 EXP_CHECK_MD_OP(exp, readpage);
1939 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1940 rc = MDP(exp->exp_obd, readpage)(exp, opdata, pages, request);
1941 return rc;
1942 }
1943
1944 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1945 struct ptlrpc_request **request)
1946 {
1947 int rc;
1948
1949 EXP_CHECK_MD_OP(exp, unlink);
1950 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1951 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1952 return rc;
1953 }
1954
1955 static inline int md_get_lustre_md(struct obd_export *exp,
1956 struct ptlrpc_request *req,
1957 struct obd_export *dt_exp,
1958 struct obd_export *md_exp,
1959 struct lustre_md *md)
1960 {
1961 EXP_CHECK_MD_OP(exp, get_lustre_md);
1962 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1963 return MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md);
1964 }
1965
1966 static inline int md_free_lustre_md(struct obd_export *exp,
1967 struct lustre_md *md)
1968 {
1969 EXP_CHECK_MD_OP(exp, free_lustre_md);
1970 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1971 return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1972 }
1973
1974 static inline int md_setxattr(struct obd_export *exp,
1975 const struct lu_fid *fid, struct obd_capa *oc,
1976 obd_valid valid, const char *name,
1977 const char *input, int input_size,
1978 int output_size, int flags, __u32 suppgid,
1979 struct ptlrpc_request **request)
1980 {
1981 EXP_CHECK_MD_OP(exp, setxattr);
1982 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1983 return MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1984 input_size, output_size, flags,
1985 suppgid, request);
1986 }
1987
1988 static inline int md_getxattr(struct obd_export *exp,
1989 const struct lu_fid *fid, struct obd_capa *oc,
1990 obd_valid valid, const char *name,
1991 const char *input, int input_size,
1992 int output_size, int flags,
1993 struct ptlrpc_request **request)
1994 {
1995 EXP_CHECK_MD_OP(exp, getxattr);
1996 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1997 return MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1998 input_size, output_size, flags,
1999 request);
2000 }
2001
2002 static inline int md_set_open_replay_data(struct obd_export *exp,
2003 struct obd_client_handle *och,
2004 struct lookup_intent *it)
2005 {
2006 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2007 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2008 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
2009 }
2010
2011 static inline int md_clear_open_replay_data(struct obd_export *exp,
2012 struct obd_client_handle *och)
2013 {
2014 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2015 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2016 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
2017 }
2018
2019 static inline int md_set_lock_data(struct obd_export *exp,
2020 __u64 *lockh, void *data, __u64 *bits)
2021 {
2022 EXP_CHECK_MD_OP(exp, set_lock_data);
2023 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2024 return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
2025 }
2026
2027 static inline int md_cancel_unused(struct obd_export *exp,
2028 const struct lu_fid *fid,
2029 ldlm_policy_data_t *policy,
2030 ldlm_mode_t mode,
2031 ldlm_cancel_flags_t flags,
2032 void *opaque)
2033 {
2034 int rc;
2035
2036 EXP_CHECK_MD_OP(exp, cancel_unused);
2037 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2038
2039 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2040 flags, opaque);
2041 return rc;
2042 }
2043
2044 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, __u64 flags,
2045 const struct lu_fid *fid,
2046 ldlm_type_t type,
2047 ldlm_policy_data_t *policy,
2048 ldlm_mode_t mode,
2049 struct lustre_handle *lockh)
2050 {
2051 EXP_CHECK_MD_OP(exp, lock_match);
2052 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2053 return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2054 policy, mode, lockh);
2055 }
2056
2057 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2058 int def_asize, int cookiesize)
2059 {
2060 EXP_CHECK_MD_OP(exp, init_ea_size);
2061 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2062 return MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2063 cookiesize);
2064 }
2065
2066 static inline int md_get_remote_perm(struct obd_export *exp,
2067 const struct lu_fid *fid,
2068 struct obd_capa *oc, __u32 suppgid,
2069 struct ptlrpc_request **request)
2070 {
2071 EXP_CHECK_MD_OP(exp, get_remote_perm);
2072 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2073 return MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2074 request);
2075 }
2076
2077 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2078 renew_capa_cb_t cb)
2079 {
2080 int rc;
2081
2082 EXP_CHECK_MD_OP(exp, renew_capa);
2083 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2084 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2085 return rc;
2086 }
2087
2088 static inline int md_unpack_capa(struct obd_export *exp,
2089 struct ptlrpc_request *req,
2090 const struct req_msg_field *field,
2091 struct obd_capa **oc)
2092 {
2093 int rc;
2094
2095 EXP_CHECK_MD_OP(exp, unpack_capa);
2096 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2097 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2098 return rc;
2099 }
2100
2101 static inline int md_intent_getattr_async(struct obd_export *exp,
2102 struct md_enqueue_info *minfo,
2103 struct ldlm_enqueue_info *einfo)
2104 {
2105 int rc;
2106
2107 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2108 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2109 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2110 return rc;
2111 }
2112
2113 static inline int md_revalidate_lock(struct obd_export *exp,
2114 struct lookup_intent *it,
2115 struct lu_fid *fid, __u64 *bits)
2116 {
2117 int rc;
2118
2119 EXP_CHECK_MD_OP(exp, revalidate_lock);
2120 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2121 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
2122 return rc;
2123 }
2124
2125
2126 /* OBD Metadata Support */
2127
2128 extern int obd_init_caches(void);
2129 extern void obd_cleanup_caches(void);
2130
2131 /* support routines */
2132 extern struct kmem_cache *obdo_cachep;
2133
2134 #define OBDO_ALLOC(ptr) \
2135 do { \
2136 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, __GFP_IO); \
2137 } while(0)
2138
2139 #define OBDO_FREE(ptr) \
2140 do { \
2141 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2142 } while(0)
2143
2144
2145 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2146 {
2147 /* something here */
2148 }
2149
2150 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2151 {
2152 /* something here */
2153 }
2154
2155 typedef int (*register_lwp_cb)(void *data);
2156
2157 struct lwp_register_item {
2158 struct obd_export **lri_exp;
2159 register_lwp_cb lri_cb_func;
2160 void *lri_cb_data;
2161 struct list_head lri_list;
2162 char lri_name[MTI_NAME_MAXLEN];
2163 };
2164
2165 /* I'm as embarrassed about this as you are.
2166 *
2167 * <shaver> // XXX do not look into _superhack with remaining eye
2168 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2169 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2170
2171 /* obd_mount.c */
2172
2173 /* sysctl.c */
2174 extern void obd_sysctl_init (void);
2175 extern void obd_sysctl_clean (void);
2176
2177 /* uuid.c */
2178 typedef __u8 class_uuid_t[16];
2179 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2180
2181 /* lustre_peer.c */
2182 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2183 int class_add_uuid(const char *uuid, __u64 nid);
2184 int class_del_uuid (const char *uuid);
2185 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
2186 void class_init_uuidlist(void);
2187 void class_exit_uuidlist(void);
2188
2189 /* mea.c */
2190 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2191 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2192
2193 /* prng.c */
2194 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
2195
2196 #endif /* __LINUX_OBD_CLASS_H */
This page took 0.078385 seconds and 5 git commands to generate.