1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
43 # include <liblustre.h>
46 #include <obd_support.h>
47 #include <lustre_import.h>
48 #include <lustre_net.h>
50 #include <lustre_lib.h>
51 #include <lustre/lustre_idl.h>
52 #include <lprocfs_status.h>
54 #if defined(__linux__)
55 #include <linux/obd_class.h>
56 #elif defined(__APPLE__)
57 #include <darwin/obd_class.h>
58 #elif defined(__WINNT__)
59 #include <winnt/obd_class.h>
61 #error Unsupported operating system.
64 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
65 * and resends for avoid deadlocks */
66 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
68 #define OBD_STATFS_PTLRPCD 0x0004 /* requests will be sent via ptlrpcd
69 * instead of a specific set. This
70 * means that we cannot rely on the set
71 * interpret routine to be called.
72 * lov_statfs_fini() must thus be called
73 * by the request interpret routine */
75 #define OBD_FL_PUNCH 0x00000001 /* To indicate it is punch operation */
77 /* OBD Device Declarations */
78 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
79 extern cfs_rwlock_t obd_dev_lock;
81 /* OBD Operations Declarations */
82 extern struct obd_device *class_conn2obd(struct lustre_handle *);
83 extern struct obd_device *class_exp2obd(struct obd_export *);
84 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
86 struct lu_device_type;
89 struct obd_export *class_conn2export(struct lustre_handle *);
90 int class_register_type(struct obd_ops *, struct md_ops *,
91 struct lprocfs_vars *, const char *nm,
92 struct lu_device_type *ldt);
93 int class_unregister_type(const char *nm);
95 struct obd_device *class_newdev(const char *type_name, const char *name);
96 void class_release_dev(struct obd_device *obd);
98 int class_name2dev(const char *name);
99 struct obd_device *class_name2obd(const char *name);
100 int class_uuid2dev(struct obd_uuid *uuid);
101 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
102 void class_obd_list(void);
103 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
104 const char * typ_name,
105 struct obd_uuid *grp_uuid);
106 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
108 struct obd_device * class_num2obd(int num);
110 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
112 char *obd_export_nid2str(struct obd_export *exp);
114 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
115 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
116 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
118 int obd_zombie_impexp_init(void);
119 void obd_zombie_impexp_stop(void);
120 void obd_zombie_impexp_cull(void);
121 void obd_zombie_barrier(void);
122 void obd_exports_barrier(struct obd_device *obd);
123 int kuc_len(int payload_len);
124 struct kuc_hdr * kuc_ptr(void *p);
125 int kuc_ispayload(void *p);
126 void *kuc_alloc(int payload_len, int transport, int type);
127 void kuc_free(void *p, int payload_len);
130 int class_process_config(struct lustre_cfg *lcfg);
131 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
132 struct lustre_cfg *lcfg, void *data);
133 int class_attach(struct lustre_cfg *lcfg);
134 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
135 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
136 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
137 struct obd_device *class_incref(struct obd_device *obd,
138 const char *scope, const void *source);
139 void class_decref(struct obd_device *obd,
140 const char *scope, const void *source);
141 void dump_exports(struct obd_device *obd, int locks);
145 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
147 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
149 memset(lvars, 0, sizeof(*lvars));
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 */
159 /* Passed as data param to class_config_parse_llog */
160 struct config_llog_instance {
163 struct super_block *cfg_sb;
164 struct obd_uuid cfg_uuid;
165 int cfg_last_idx; /* for partial llog processing */
168 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
169 struct config_llog_instance *cfg);
170 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
171 struct config_llog_instance *cfg);
175 CONFIG_T_SPTLRPC = 1,
176 CONFIG_T_RECOVER = 2,
180 /* list of active configuration logs */
181 struct config_llog_data {
182 struct ldlm_res_id cld_resid;
183 struct config_llog_instance cld_cfg;
184 cfs_list_t cld_list_chain;
185 cfs_atomic_t cld_refcount;
186 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
187 struct config_llog_data *cld_recover; /* imperative recover log */
188 struct obd_export *cld_mgcexp;
189 cfs_mutex_t cld_lock;
191 unsigned int cld_stopping:1, /* we were told to stop
193 cld_lostlock:1; /* lock not requeued */
197 struct lustre_profile {
204 struct lustre_profile *class_get_profile(const char * prof);
205 void class_del_profile(const char *prof);
206 void class_del_profiles(void);
208 #if LUSTRE_TRACKS_LOCK_EXP_REFS
210 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
211 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
212 extern void (*class_export_dump_hook)(struct obd_export *);
216 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
217 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
221 #define class_export_rpc_get(exp) \
223 cfs_atomic_inc(&(exp)->exp_rpc_count); \
224 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
225 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
226 class_export_get(exp); \
229 #define class_export_rpc_put(exp) \
231 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
232 cfs_atomic_dec(&(exp)->exp_rpc_count); \
233 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
234 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
235 class_export_put(exp); \
238 #define class_export_lock_get(exp, lock) \
240 cfs_atomic_inc(&(exp)->exp_locks_count); \
241 __class_export_add_lock_ref(exp, lock); \
242 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
243 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
244 class_export_get(exp); \
247 #define class_export_lock_put(exp, lock) \
249 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
250 cfs_atomic_dec(&(exp)->exp_locks_count); \
251 __class_export_del_lock_ref(exp, lock); \
252 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
253 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
254 class_export_put(exp); \
257 #define class_export_cb_get(exp) \
259 cfs_atomic_inc(&(exp)->exp_cb_count); \
260 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
261 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
262 class_export_get(exp); \
265 #define class_export_cb_put(exp) \
267 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
268 cfs_atomic_dec(&(exp)->exp_cb_count); \
269 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
270 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
271 class_export_put(exp); \
275 struct obd_export *class_export_get(struct obd_export *exp);
276 void class_export_put(struct obd_export *exp);
277 struct obd_export *class_new_export(struct obd_device *obddev,
278 struct obd_uuid *cluuid);
279 void class_unlink_export(struct obd_export *exp);
281 struct obd_import *class_import_get(struct obd_import *);
282 void class_import_put(struct obd_import *);
283 struct obd_import *class_new_import(struct obd_device *obd);
284 void class_destroy_import(struct obd_import *exp);
286 struct obd_type *class_search_type(const char *name);
287 struct obd_type *class_get_type(const char *name);
288 void class_put_type(struct obd_type *type);
289 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
290 struct obd_uuid *cluuid);
291 int class_disconnect(struct obd_export *exp);
292 void class_fail_export(struct obd_export *exp);
293 int class_connected_export(struct obd_export *exp);
294 void class_disconnect_exports(struct obd_device *obddev);
295 int class_manual_cleanup(struct obd_device *obd);
296 void class_disconnect_stale_exports(struct obd_device *,
297 int (*test_export)(struct obd_export *));
298 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
300 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
301 (obd->obd_force ? OBD_OPT_FORCE : 0) |
302 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
306 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
308 LASSERT(exp->exp_obd);
309 return exp->exp_obd->u.obt.obt_lut;
312 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
314 LASSERT(obd->u.obt.obt_lut);
315 return &obd->u.obt.obt_lut->lut_lsd;
318 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
319 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
320 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
321 unsigned int ia_valid);
322 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
323 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
324 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
327 #define OBT(dev) (dev)->obd_type
328 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
329 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
330 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
332 /* Ensure obd_setup: used for cleanup which must be called
333 while obd is stopping */
334 #define OBD_CHECK_DEV(obd) \
337 CERROR("NULL device\n"); \
342 /* ensure obd_setup and !obd_stopping */
343 #define OBD_CHECK_DEV_ACTIVE(obd) \
345 OBD_CHECK_DEV(obd); \
346 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
347 CERROR("Device %d not setup\n", \
355 #define OBD_COUNTER_OFFSET(op) \
356 ((offsetof(struct obd_ops, o_ ## op) - \
357 offsetof(struct obd_ops, o_iocontrol)) \
358 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
360 #define OBD_COUNTER_INCREMENT(obdx, op) \
361 if ((obdx)->obd_stats != NULL) { \
362 unsigned int coffset; \
363 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
364 OBD_COUNTER_OFFSET(op); \
365 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
366 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
369 #define EXP_COUNTER_INCREMENT(export, op) \
370 if ((export)->exp_obd->obd_stats != NULL) { \
371 unsigned int coffset; \
372 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
373 OBD_COUNTER_OFFSET(op); \
374 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
375 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
376 if ((export)->exp_nid_stats != NULL && \
377 (export)->exp_nid_stats->nid_stats != NULL) \
378 lprocfs_counter_incr( \
379 (export)->exp_nid_stats->nid_stats, coffset);\
382 #define MD_COUNTER_OFFSET(op) \
383 ((offsetof(struct md_ops, m_ ## op) - \
384 offsetof(struct md_ops, m_getstatus)) \
385 / sizeof(((struct md_ops *)(0))->m_getstatus))
387 #define MD_COUNTER_INCREMENT(obdx, op) \
388 if ((obd)->md_stats != NULL) { \
389 unsigned int coffset; \
390 coffset = (unsigned int)((obdx)->md_cntr_base) + \
391 MD_COUNTER_OFFSET(op); \
392 LASSERT(coffset < (obdx)->md_stats->ls_num); \
393 lprocfs_counter_incr((obdx)->md_stats, coffset); \
396 #define EXP_MD_COUNTER_INCREMENT(export, op) \
397 if ((export)->exp_obd->obd_stats != NULL) { \
398 unsigned int coffset; \
399 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
400 MD_COUNTER_OFFSET(op); \
401 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
402 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
403 if ((export)->exp_md_stats != NULL) \
404 lprocfs_counter_incr( \
405 (export)->exp_md_stats, coffset); \
409 #define OBD_COUNTER_OFFSET(op)
410 #define OBD_COUNTER_INCREMENT(obd, op)
411 #define EXP_COUNTER_INCREMENT(exp, op)
412 #define MD_COUNTER_INCREMENT(obd, op)
413 #define EXP_MD_COUNTER_INCREMENT(exp, op)
416 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
418 /* Always add in ldlm_stats */
419 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
420 ,LPROCFS_STATS_FLAG_NOPERCPU);
421 if (tmp->nid_ldlm_stats == NULL)
424 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
426 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
427 tmp->nid_ldlm_stats);
430 #define OBD_CHECK_MD_OP(obd, op, err) \
432 if (!OBT(obd) || !MDP((obd), op)) { \
434 CERROR("md_" #op ": dev %s/%d no operation\n", \
435 obd->obd_name, obd->obd_minor); \
440 #define EXP_CHECK_MD_OP(exp, op) \
442 if ((exp) == NULL) { \
443 CERROR("obd_" #op ": NULL export\n"); \
446 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
447 CERROR("obd_" #op ": cleaned up obd\n"); \
448 RETURN(-EOPNOTSUPP); \
450 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
451 CERROR("obd_" #op ": dev %s/%d no operation\n", \
452 (exp)->exp_obd->obd_name, \
453 (exp)->exp_obd->obd_minor); \
454 RETURN(-EOPNOTSUPP); \
459 #define OBD_CHECK_DT_OP(obd, op, err) \
461 if (!OBT(obd) || !OBP((obd), op)) { \
463 CERROR("obd_" #op ": dev %d no operation\n", \
469 #define EXP_CHECK_DT_OP(exp, op) \
471 if ((exp) == NULL) { \
472 CERROR("obd_" #op ": NULL export\n"); \
475 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
476 CERROR("obd_" #op ": cleaned up obd\n"); \
477 RETURN(-EOPNOTSUPP); \
479 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
480 CERROR("obd_" #op ": dev %d no operation\n", \
481 (exp)->exp_obd->obd_minor); \
482 RETURN(-EOPNOTSUPP); \
486 #define CTXT_CHECK_OP(ctxt, op, err) \
488 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
490 CERROR("lop_" #op ": dev %d no operation\n", \
491 ctxt->loc_obd->obd_minor); \
496 static inline int class_devno_max(void)
498 return MAX_OBD_DEVICES;
501 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
502 void *key, __u32 *vallen, void *val,
503 struct lov_stripe_md *lsm)
508 EXP_CHECK_DT_OP(exp, get_info);
509 EXP_COUNTER_INCREMENT(exp, get_info);
511 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
515 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
516 void *key, obd_count vallen, void *val,
517 struct ptlrpc_request_set *set)
522 EXP_CHECK_DT_OP(exp, set_info_async);
523 EXP_COUNTER_INCREMENT(exp, set_info_async);
525 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
531 * obd-lu integration.
533 * Functionality is being moved into new lu_device-based layering, but some
534 * pieces of configuration process are still based on obd devices.
536 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
537 * subsume ->o_setup() methods of obd devices they replace. The same for
538 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
539 * result, obd_setup() and obd_process_config() branch and call one XOR
542 * Yet neither lu_device_type_operations::ldto_device_fini() nor
543 * lu_device_type_operations::ldto_device_free() fully implement the
544 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
545 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
548 #define DECLARE_LU_VARS(ldt, d) \
549 struct lu_device_type *ldt; \
552 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
555 DECLARE_LU_VARS(ldt, d);
558 ldt = obd->obd_type->typ_lu;
560 struct lu_context session_ctx;
562 lu_context_init(&session_ctx, LCT_SESSION);
563 session_ctx.lc_thread = NULL;
564 lu_context_enter(&session_ctx);
566 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
568 env.le_ses = &session_ctx;
569 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
578 lu_context_exit(&session_ctx);
579 lu_context_fini(&session_ctx);
582 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
583 OBD_COUNTER_INCREMENT(obd, setup);
584 rc = OBP(obd, setup)(obd, cfg);
589 static inline int obd_precleanup(struct obd_device *obd,
590 enum obd_cleanup_stage cleanup_stage)
593 DECLARE_LU_VARS(ldt, d);
597 ldt = obd->obd_type->typ_lu;
599 if (ldt != NULL && d != NULL) {
600 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
603 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
605 ldt->ldt_ops->ldto_device_fini(&env, d);
610 OBD_CHECK_DT_OP(obd, precleanup, 0);
611 OBD_COUNTER_INCREMENT(obd, precleanup);
613 rc = OBP(obd, precleanup)(obd, cleanup_stage);
617 static inline int obd_cleanup(struct obd_device *obd)
620 DECLARE_LU_VARS(ldt, d);
625 ldt = obd->obd_type->typ_lu;
627 if (ldt != NULL && d != NULL) {
630 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
632 ldt->ldt_ops->ldto_device_free(&env, d);
634 obd->obd_lu_dev = NULL;
637 OBD_CHECK_DT_OP(obd, cleanup, 0);
638 OBD_COUNTER_INCREMENT(obd, cleanup);
640 rc = OBP(obd, cleanup)(obd);
644 static inline void obd_cleanup_client_import(struct obd_device *obd)
648 /* If we set up but never connected, the
649 client import will not have been cleaned. */
650 cfs_down_write(&obd->u.cli.cl_sem);
651 if (obd->u.cli.cl_import) {
652 struct obd_import *imp;
653 imp = obd->u.cli.cl_import;
654 CDEBUG(D_CONFIG, "%s: client import never connected\n",
656 ptlrpc_invalidate_import(imp);
657 if (imp->imp_rq_pool) {
658 ptlrpc_free_rq_pool(imp->imp_rq_pool);
659 imp->imp_rq_pool = NULL;
661 class_destroy_import(imp);
662 obd->u.cli.cl_import = NULL;
664 cfs_up_write(&obd->u.cli.cl_sem);
670 obd_process_config(struct obd_device *obd, int datalen, void *data)
673 DECLARE_LU_VARS(ldt, d);
678 obd->obd_process_conf = 1;
679 ldt = obd->obd_type->typ_lu;
681 if (ldt != NULL && d != NULL) {
684 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
686 rc = d->ld_ops->ldo_process_config(&env, d, data);
690 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
691 rc = OBP(obd, process_config)(obd, datalen, data);
693 OBD_COUNTER_INCREMENT(obd, process_config);
694 obd->obd_process_conf = 0;
699 /* Pack an in-memory MD struct for storage on disk.
700 * Returns +ve size of packed MD (0 for free), or -ve error.
702 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
703 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
704 * If @*disk_tgt == NULL, it will be allocated
706 static inline int obd_packmd(struct obd_export *exp,
707 struct lov_mds_md **disk_tgt,
708 struct lov_stripe_md *mem_src)
713 EXP_CHECK_DT_OP(exp, packmd);
714 EXP_COUNTER_INCREMENT(exp, packmd);
716 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
720 static inline int obd_size_diskmd(struct obd_export *exp,
721 struct lov_stripe_md *mem_src)
723 return obd_packmd(exp, NULL, mem_src);
726 /* helper functions */
727 static inline int obd_alloc_diskmd(struct obd_export *exp,
728 struct lov_mds_md **disk_tgt)
731 LASSERT(*disk_tgt == NULL);
732 return obd_packmd(exp, disk_tgt, NULL);
735 static inline int obd_free_diskmd(struct obd_export *exp,
736 struct lov_mds_md **disk_tgt)
740 return obd_packmd(exp, disk_tgt, NULL);
743 /* Unpack an MD struct from disk to in-memory format.
744 * Returns +ve size of unpacked MD (0 for free), or -ve error.
746 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
747 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
748 * If @*mem_tgt == NULL, it will be allocated
750 static inline int obd_unpackmd(struct obd_export *exp,
751 struct lov_stripe_md **mem_tgt,
752 struct lov_mds_md *disk_src,
758 EXP_CHECK_DT_OP(exp, unpackmd);
759 EXP_COUNTER_INCREMENT(exp, unpackmd);
761 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
765 /* helper functions */
766 static inline int obd_alloc_memmd(struct obd_export *exp,
767 struct lov_stripe_md **mem_tgt)
770 LASSERT(*mem_tgt == NULL);
771 return obd_unpackmd(exp, mem_tgt, NULL, 0);
774 static inline int obd_free_memmd(struct obd_export *exp,
775 struct lov_stripe_md **mem_tgt)
781 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
786 static inline int obd_precreate(struct obd_export *exp)
791 EXP_CHECK_DT_OP(exp, precreate);
792 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
794 rc = OBP(exp->exp_obd, precreate)(exp);
798 static inline int obd_create_async(struct obd_export *exp,
799 struct obd_info *oinfo,
800 struct lov_stripe_md **ea,
801 struct obd_trans_info *oti)
806 EXP_CHECK_DT_OP(exp, create_async);
807 EXP_COUNTER_INCREMENT(exp, create_async);
809 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
813 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
814 struct lov_stripe_md **ea,
815 struct obd_trans_info *oti)
820 EXP_CHECK_DT_OP(exp, create);
821 EXP_COUNTER_INCREMENT(exp, create);
823 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
827 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
828 struct lov_stripe_md *ea,
829 struct obd_trans_info *oti,
830 struct obd_export *md_exp, void *capa)
835 EXP_CHECK_DT_OP(exp, destroy);
836 EXP_COUNTER_INCREMENT(exp, destroy);
838 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
842 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
847 EXP_CHECK_DT_OP(exp, getattr);
848 EXP_COUNTER_INCREMENT(exp, getattr);
850 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
854 static inline int obd_getattr_async(struct obd_export *exp,
855 struct obd_info *oinfo,
856 struct ptlrpc_request_set *set)
861 EXP_CHECK_DT_OP(exp, getattr_async);
862 EXP_COUNTER_INCREMENT(exp, getattr_async);
864 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
868 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
869 struct obd_trans_info *oti)
874 EXP_CHECK_DT_OP(exp, setattr);
875 EXP_COUNTER_INCREMENT(exp, setattr);
877 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
881 /* This performs all the requests set init/wait/destroy actions. */
882 static inline int obd_setattr_rqset(struct obd_export *exp,
883 struct obd_info *oinfo,
884 struct obd_trans_info *oti)
886 struct ptlrpc_request_set *set = NULL;
890 EXP_CHECK_DT_OP(exp, setattr_async);
891 EXP_COUNTER_INCREMENT(exp, setattr_async);
893 set = ptlrpc_prep_set();
897 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
899 rc = ptlrpc_set_wait(set);
900 ptlrpc_set_destroy(set);
904 /* This adds all the requests into @set if @set != NULL, otherwise
905 all requests are sent asynchronously without waiting for response. */
906 static inline int obd_setattr_async(struct obd_export *exp,
907 struct obd_info *oinfo,
908 struct obd_trans_info *oti,
909 struct ptlrpc_request_set *set)
914 EXP_CHECK_DT_OP(exp, setattr_async);
915 EXP_COUNTER_INCREMENT(exp, setattr_async);
917 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
921 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
924 struct obd_device *obd = imp->imp_obd;
928 OBD_CHECK_DEV_ACTIVE(obd);
929 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
930 OBD_COUNTER_INCREMENT(obd, add_conn);
932 rc = OBP(obd, add_conn)(imp, uuid, priority);
936 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
938 struct obd_device *obd = imp->imp_obd;
942 OBD_CHECK_DEV_ACTIVE(obd);
943 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
944 OBD_COUNTER_INCREMENT(obd, del_conn);
946 rc = OBP(obd, del_conn)(imp, uuid);
950 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
952 struct obd_uuid *uuid;
955 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
956 EXP_COUNTER_INCREMENT(exp, get_uuid);
958 uuid = OBP(exp->exp_obd, get_uuid)(exp);
962 /** Create a new /a exp on device /a obd for the uuid /a cluuid
963 * @param exp New export handle
964 * @param d Connect data, supported flags are set, flags also understood
965 * by obd are returned.
967 static inline int obd_connect(const struct lu_env *env,
968 struct obd_export **exp,struct obd_device *obd,
969 struct obd_uuid *cluuid,
970 struct obd_connect_data *data,
974 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
978 OBD_CHECK_DEV_ACTIVE(obd);
979 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
980 OBD_COUNTER_INCREMENT(obd, connect);
982 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
983 /* check that only subset is granted */
984 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
985 data->ocd_connect_flags));
989 static inline int obd_reconnect(const struct lu_env *env,
990 struct obd_export *exp,
991 struct obd_device *obd,
992 struct obd_uuid *cluuid,
993 struct obd_connect_data *d,
997 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
1002 OBD_CHECK_DEV_ACTIVE(obd);
1003 OBD_CHECK_DT_OP(obd, reconnect, 0);
1004 OBD_COUNTER_INCREMENT(obd, reconnect);
1006 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
1007 /* check that only subset is granted */
1008 LASSERT(ergo(d != NULL,
1009 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
1013 static inline int obd_disconnect(struct obd_export *exp)
1018 EXP_CHECK_DT_OP(exp, disconnect);
1019 EXP_COUNTER_INCREMENT(exp, disconnect);
1021 rc = OBP(exp->exp_obd, disconnect)(exp);
1025 static inline int obd_fid_init(struct obd_export *exp)
1030 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
1031 EXP_COUNTER_INCREMENT(exp, fid_init);
1033 rc = OBP(exp->exp_obd, fid_init)(exp);
1037 static inline int obd_fid_fini(struct obd_export *exp)
1042 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
1043 EXP_COUNTER_INCREMENT(exp, fid_fini);
1045 rc = OBP(exp->exp_obd, fid_fini)(exp);
1049 static inline int obd_fid_alloc(struct obd_export *exp,
1051 struct md_op_data *op_data)
1056 EXP_CHECK_DT_OP(exp, fid_alloc);
1057 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1059 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
1063 static inline int obd_fid_delete(struct obd_export *exp,
1064 const struct lu_fid *fid)
1069 EXP_CHECK_DT_OP(exp, fid_delete);
1070 EXP_COUNTER_INCREMENT(exp, fid_delete);
1072 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
1076 static inline int obd_ping(struct obd_export *exp)
1081 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1082 EXP_COUNTER_INCREMENT(exp, ping);
1084 rc = OBP(exp->exp_obd, ping)(exp);
1088 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1093 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1094 OBD_COUNTER_INCREMENT(obd, pool_new);
1096 rc = OBP(obd, pool_new)(obd, poolname);
1100 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1105 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1106 OBD_COUNTER_INCREMENT(obd, pool_del);
1108 rc = OBP(obd, pool_del)(obd, poolname);
1112 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1117 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1118 OBD_COUNTER_INCREMENT(obd, pool_add);
1120 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1124 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1129 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1130 OBD_COUNTER_INCREMENT(obd, pool_rem);
1132 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1136 static inline void obd_getref(struct obd_device *obd)
1139 if (OBT(obd) && OBP(obd, getref)) {
1140 OBD_COUNTER_INCREMENT(obd, getref);
1141 OBP(obd, getref)(obd);
1146 static inline void obd_putref(struct obd_device *obd)
1149 if (OBT(obd) && OBP(obd, putref)) {
1150 OBD_COUNTER_INCREMENT(obd, putref);
1151 OBP(obd, putref)(obd);
1156 static inline int obd_init_export(struct obd_export *exp)
1161 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1162 OBP((exp)->exp_obd, init_export))
1163 rc = OBP(exp->exp_obd, init_export)(exp);
1167 static inline int obd_destroy_export(struct obd_export *exp)
1170 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1171 OBP((exp)->exp_obd, destroy_export))
1172 OBP(exp->exp_obd, destroy_export)(exp);
1176 static inline int obd_extent_calc(struct obd_export *exp,
1177 struct lov_stripe_md *md,
1178 int cmd, obd_off *offset)
1182 EXP_CHECK_DT_OP(exp, extent_calc);
1183 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1187 static inline struct dentry *
1188 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1190 LASSERT(exp->exp_obd);
1192 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1197 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1199 LASSERT(exp->exp_obd);
1200 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1202 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1203 dentry, exp->exp_obd);
1208 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1209 * If the cache is older than @max_age we will get a new value from the
1210 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1211 static inline int obd_statfs_async(struct obd_device *obd,
1212 struct obd_info *oinfo,
1214 struct ptlrpc_request_set *rqset)
1222 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1223 OBD_COUNTER_INCREMENT(obd, statfs);
1225 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1226 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1227 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1228 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1230 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1231 " objects "LPU64"/"LPU64"\n",
1232 obd->obd_name, &obd->obd_osfs,
1233 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1234 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1235 cfs_spin_lock(&obd->obd_osfs_lock);
1236 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1237 cfs_spin_unlock(&obd->obd_osfs_lock);
1238 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1239 if (oinfo->oi_cb_up)
1240 oinfo->oi_cb_up(oinfo, 0);
1245 static inline int obd_statfs_rqset(struct obd_device *obd,
1246 struct obd_statfs *osfs, __u64 max_age,
1249 struct ptlrpc_request_set *set = NULL;
1250 struct obd_info oinfo = { { { 0 } } };
1254 set = ptlrpc_prep_set();
1258 oinfo.oi_osfs = osfs;
1259 oinfo.oi_flags = flags;
1260 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1262 rc = ptlrpc_set_wait(set);
1263 ptlrpc_set_destroy(set);
1267 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1268 * If the cache is older than @max_age we will get a new value from the
1269 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1270 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1271 __u64 max_age, __u32 flags)
1279 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1280 OBD_COUNTER_INCREMENT(obd, statfs);
1282 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1283 obd->obd_osfs_age, max_age);
1284 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1285 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1287 cfs_spin_lock(&obd->obd_osfs_lock);
1288 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1289 obd->obd_osfs_age = cfs_time_current_64();
1290 cfs_spin_unlock(&obd->obd_osfs_lock);
1293 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1294 " objects "LPU64"/"LPU64"\n",
1295 obd->obd_name, &obd->obd_osfs,
1296 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1297 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1298 cfs_spin_lock(&obd->obd_osfs_lock);
1299 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1300 cfs_spin_unlock(&obd->obd_osfs_lock);
1305 static inline int obd_sync_rqset(struct obd_export *exp, struct obd_info *oinfo,
1306 obd_size start, obd_size end)
1308 struct ptlrpc_request_set *set = NULL;
1312 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1313 EXP_COUNTER_INCREMENT(exp, sync);
1315 set = ptlrpc_prep_set();
1319 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1321 rc = ptlrpc_set_wait(set);
1322 ptlrpc_set_destroy(set);
1326 static inline int obd_sync(struct obd_export *exp, struct obd_info *oinfo,
1327 obd_size start, obd_size end,
1328 struct ptlrpc_request_set *set)
1333 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1334 EXP_COUNTER_INCREMENT(exp, sync);
1336 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1340 static inline int obd_punch_rqset(struct obd_export *exp,
1341 struct obd_info *oinfo,
1342 struct obd_trans_info *oti)
1344 struct ptlrpc_request_set *set = NULL;
1348 EXP_CHECK_DT_OP(exp, punch);
1349 EXP_COUNTER_INCREMENT(exp, punch);
1351 set = ptlrpc_prep_set();
1355 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1357 rc = ptlrpc_set_wait(set);
1358 ptlrpc_set_destroy(set);
1362 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1363 struct obd_trans_info *oti,
1364 struct ptlrpc_request_set *rqset)
1369 EXP_CHECK_DT_OP(exp, punch);
1370 EXP_COUNTER_INCREMENT(exp, punch);
1372 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1376 static inline int obd_brw(int cmd, struct obd_export *exp,
1377 struct obd_info *oinfo, obd_count oa_bufs,
1378 struct brw_page *pg, struct obd_trans_info *oti)
1383 EXP_CHECK_DT_OP(exp, brw);
1384 EXP_COUNTER_INCREMENT(exp, brw);
1386 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1387 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1388 "or OBD_BRW_CHECK\n");
1392 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1396 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1397 int objcount, struct obd_ioobj *obj,
1398 struct niobuf_remote *remote, int *pages,
1399 struct niobuf_local *local,
1400 struct obd_trans_info *oti,
1401 struct lustre_capa *capa)
1406 EXP_CHECK_DT_OP(exp, preprw);
1407 EXP_COUNTER_INCREMENT(exp, preprw);
1409 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1410 pages, local, oti, capa);
1414 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1415 int objcount, struct obd_ioobj *obj,
1416 struct niobuf_remote *rnb, int pages,
1417 struct niobuf_local *local,
1418 struct obd_trans_info *oti, int rc)
1422 EXP_CHECK_DT_OP(exp, commitrw);
1423 EXP_COUNTER_INCREMENT(exp, commitrw);
1425 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1426 rnb, pages, local, oti, rc);
1430 static inline int obd_merge_lvb(struct obd_export *exp,
1431 struct lov_stripe_md *lsm,
1432 struct ost_lvb *lvb, int kms_only)
1437 EXP_CHECK_DT_OP(exp, merge_lvb);
1438 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1440 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1444 static inline int obd_adjust_kms(struct obd_export *exp,
1445 struct lov_stripe_md *lsm, obd_off size,
1451 EXP_CHECK_DT_OP(exp, adjust_kms);
1452 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1454 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1458 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1459 int len, void *karg, void *uarg)
1464 EXP_CHECK_DT_OP(exp, iocontrol);
1465 EXP_COUNTER_INCREMENT(exp, iocontrol);
1467 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1471 static inline int obd_enqueue_rqset(struct obd_export *exp,
1472 struct obd_info *oinfo,
1473 struct ldlm_enqueue_info *einfo)
1475 struct ptlrpc_request_set *set = NULL;
1479 EXP_CHECK_DT_OP(exp, enqueue);
1480 EXP_COUNTER_INCREMENT(exp, enqueue);
1482 set = ptlrpc_prep_set();
1486 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1488 rc = ptlrpc_set_wait(set);
1489 ptlrpc_set_destroy(set);
1493 static inline int obd_enqueue(struct obd_export *exp,
1494 struct obd_info *oinfo,
1495 struct ldlm_enqueue_info *einfo,
1496 struct ptlrpc_request_set *set)
1501 EXP_CHECK_DT_OP(exp, enqueue);
1502 EXP_COUNTER_INCREMENT(exp, enqueue);
1504 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1508 static inline int obd_change_cbdata(struct obd_export *exp,
1509 struct lov_stripe_md *lsm,
1510 ldlm_iterator_t it, void *data)
1515 EXP_CHECK_DT_OP(exp, change_cbdata);
1516 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1518 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1522 static inline int obd_find_cbdata(struct obd_export *exp,
1523 struct lov_stripe_md *lsm,
1524 ldlm_iterator_t it, void *data)
1529 EXP_CHECK_DT_OP(exp, find_cbdata);
1530 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1532 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1536 static inline int obd_cancel(struct obd_export *exp,
1537 struct lov_stripe_md *ea, __u32 mode,
1538 struct lustre_handle *lockh)
1543 EXP_CHECK_DT_OP(exp, cancel);
1544 EXP_COUNTER_INCREMENT(exp, cancel);
1546 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1550 static inline int obd_cancel_unused(struct obd_export *exp,
1551 struct lov_stripe_md *ea,
1552 ldlm_cancel_flags_t flags,
1558 EXP_CHECK_DT_OP(exp, cancel_unused);
1559 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1561 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1565 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1566 struct obd_capa *oc, struct obd_client_handle *handle,
1572 EXP_CHECK_DT_OP(exp, pin);
1573 EXP_COUNTER_INCREMENT(exp, pin);
1575 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1579 static inline int obd_unpin(struct obd_export *exp,
1580 struct obd_client_handle *handle, int flag)
1585 EXP_CHECK_DT_OP(exp, unpin);
1586 EXP_COUNTER_INCREMENT(exp, unpin);
1588 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1593 static inline void obd_import_event(struct obd_device *obd,
1594 struct obd_import *imp,
1595 enum obd_import_event event)
1599 CERROR("NULL device\n");
1603 if (obd->obd_set_up && OBP(obd, import_event)) {
1604 OBD_COUNTER_INCREMENT(obd, import_event);
1605 OBP(obd, import_event)(obd, imp, event);
1610 static inline int obd_llog_connect(struct obd_export *exp,
1611 struct llogd_conn_body *body)
1616 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1617 EXP_COUNTER_INCREMENT(exp, llog_connect);
1619 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1624 static inline int obd_notify(struct obd_device *obd,
1625 struct obd_device *watched,
1626 enum obd_notify_event ev,
1633 /* the check for async_recov is a complete hack - I'm hereby
1634 overloading the meaning to also mean "this was called from
1635 mds_postsetup". I know that my mds is able to handle notifies
1636 by this point, and it needs to get them to execute mds_postrecov. */
1637 if (!obd->obd_set_up && !obd->obd_async_recov) {
1638 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1642 if (!OBP(obd, notify)) {
1643 CERROR("obd %s has no notify handler\n", obd->obd_name);
1647 OBD_COUNTER_INCREMENT(obd, notify);
1648 rc = OBP(obd, notify)(obd, watched, ev, data);
1652 static inline int obd_notify_observer(struct obd_device *observer,
1653 struct obd_device *observed,
1654 enum obd_notify_event ev,
1660 struct obd_notify_upcall *onu;
1662 if (observer->obd_observer)
1663 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1667 * Also, call non-obd listener, if any
1669 onu = &observer->obd_upcall;
1670 if (onu->onu_upcall != NULL)
1671 rc2 = onu->onu_upcall(observer, observed, ev,
1672 onu->onu_owner, NULL);
1676 return rc1 ? rc1 : rc2;
1679 static inline int obd_quotacheck(struct obd_export *exp,
1680 struct obd_quotactl *oqctl)
1685 EXP_CHECK_DT_OP(exp, quotacheck);
1686 EXP_COUNTER_INCREMENT(exp, quotacheck);
1688 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1692 static inline int obd_quotactl(struct obd_export *exp,
1693 struct obd_quotactl *oqctl)
1698 EXP_CHECK_DT_OP(exp, quotactl);
1699 EXP_COUNTER_INCREMENT(exp, quotactl);
1701 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1705 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1706 struct quota_adjust_qunit *oqaq,
1707 struct lustre_quota_ctxt *qctxt,
1708 struct ptlrpc_request_set *set)
1710 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1711 struct timeval work_start;
1712 struct timeval work_end;
1718 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1720 cfs_gettimeofday(&work_start);
1722 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1723 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1725 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt, set);
1727 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1729 cfs_gettimeofday(&work_end);
1730 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1731 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1738 static inline int obd_health_check(struct obd_device *obd)
1740 /* returns: 0 on healthy
1741 * >0 on unhealthy + reason code/flag
1742 * however the only suppored reason == 1 right now
1743 * We'll need to define some better reasons
1744 * or flags in the future.
1750 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1751 if (obd == NULL || !OBT(obd)) {
1752 CERROR("cleaned up obd\n");
1753 RETURN(-EOPNOTSUPP);
1755 if (!obd->obd_set_up || obd->obd_stopping)
1757 if (!OBP(obd, health_check))
1760 rc = OBP(obd, health_check)(obd);
1764 static inline int obd_register_observer(struct obd_device *obd,
1765 struct obd_device *observer)
1769 cfs_down_write(&obd->obd_observer_link_sem);
1770 if (obd->obd_observer && observer) {
1771 cfs_up_write(&obd->obd_observer_link_sem);
1774 obd->obd_observer = observer;
1775 cfs_up_write(&obd->obd_observer_link_sem);
1779 static inline int obd_pin_observer(struct obd_device *obd,
1780 struct obd_device **observer)
1783 cfs_down_read(&obd->obd_observer_link_sem);
1784 if (!obd->obd_observer) {
1786 cfs_up_read(&obd->obd_observer_link_sem);
1789 *observer = obd->obd_observer;
1793 static inline int obd_unpin_observer(struct obd_device *obd)
1796 cfs_up_read(&obd->obd_observer_link_sem);
1801 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1802 obd_page_removal_cb_t cb,
1803 obd_pin_extent_cb pin_cb)
1808 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1809 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1811 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1815 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1816 obd_page_removal_cb_t cb)
1821 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1822 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1824 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1828 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1829 obd_lock_cancel_cb cb)
1834 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1835 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1837 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1841 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1842 obd_lock_cancel_cb cb)
1847 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1848 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1850 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1855 /* metadata helpers */
1856 static inline int md_getstatus(struct obd_export *exp,
1857 struct lu_fid *fid, struct obd_capa **pc)
1862 EXP_CHECK_MD_OP(exp, getstatus);
1863 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1864 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1868 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1869 struct ptlrpc_request **request)
1873 EXP_CHECK_MD_OP(exp, getattr);
1874 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1875 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1879 static inline int md_change_cbdata(struct obd_export *exp,
1880 const struct lu_fid *fid,
1881 ldlm_iterator_t it, void *data)
1885 EXP_CHECK_MD_OP(exp, change_cbdata);
1886 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1887 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1891 static inline int md_find_cbdata(struct obd_export *exp,
1892 const struct lu_fid *fid,
1893 ldlm_iterator_t it, void *data)
1897 EXP_CHECK_MD_OP(exp, find_cbdata);
1898 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1899 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1903 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1904 struct md_open_data *mod,
1905 struct ptlrpc_request **request)
1909 EXP_CHECK_MD_OP(exp, close);
1910 EXP_MD_COUNTER_INCREMENT(exp, close);
1911 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1915 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1916 const void *data, int datalen, int mode, __u32 uid,
1917 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1918 struct ptlrpc_request **request)
1922 EXP_CHECK_MD_OP(exp, create);
1923 EXP_MD_COUNTER_INCREMENT(exp, create);
1924 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1925 uid, gid, cap_effective, rdev, request);
1929 static inline int md_done_writing(struct obd_export *exp,
1930 struct md_op_data *op_data,
1931 struct md_open_data *mod)
1935 EXP_CHECK_MD_OP(exp, done_writing);
1936 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1937 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1941 static inline int md_enqueue(struct obd_export *exp,
1942 struct ldlm_enqueue_info *einfo,
1943 struct lookup_intent *it,
1944 struct md_op_data *op_data,
1945 struct lustre_handle *lockh,
1946 void *lmm, int lmmsize,
1947 struct ptlrpc_request **req,
1948 int extra_lock_flags)
1952 EXP_CHECK_MD_OP(exp, enqueue);
1953 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1954 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1955 lmm, lmmsize, req, extra_lock_flags);
1959 static inline int md_getattr_name(struct obd_export *exp,
1960 struct md_op_data *op_data,
1961 struct ptlrpc_request **request)
1965 EXP_CHECK_MD_OP(exp, getattr_name);
1966 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1967 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1971 static inline int md_intent_lock(struct obd_export *exp,
1972 struct md_op_data *op_data, void *lmm,
1973 int lmmsize, struct lookup_intent *it,
1974 int flags, struct ptlrpc_request **reqp,
1975 ldlm_blocking_callback cb_blocking,
1976 int extra_lock_flags)
1980 EXP_CHECK_MD_OP(exp, intent_lock);
1981 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1982 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1983 it, flags, reqp, cb_blocking,
1988 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1989 struct ptlrpc_request **request)
1993 EXP_CHECK_MD_OP(exp, link);
1994 EXP_MD_COUNTER_INCREMENT(exp, link);
1995 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1999 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
2000 const char *old, int oldlen, const char *new,
2001 int newlen, struct ptlrpc_request **request)
2005 EXP_CHECK_MD_OP(exp, rename);
2006 EXP_MD_COUNTER_INCREMENT(exp, rename);
2007 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
2012 static inline int md_is_subdir(struct obd_export *exp,
2013 const struct lu_fid *pfid,
2014 const struct lu_fid *cfid,
2015 struct ptlrpc_request **request)
2019 EXP_CHECK_MD_OP(exp, is_subdir);
2020 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
2021 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
2025 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
2026 void *ea, int ealen, void *ea2, int ea2len,
2027 struct ptlrpc_request **request,
2028 struct md_open_data **mod)
2032 EXP_CHECK_MD_OP(exp, setattr);
2033 EXP_MD_COUNTER_INCREMENT(exp, setattr);
2034 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
2035 ea2, ea2len, request, mod);
2039 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
2040 struct obd_capa *oc, struct ptlrpc_request **request)
2044 EXP_CHECK_MD_OP(exp, sync);
2045 EXP_MD_COUNTER_INCREMENT(exp, sync);
2046 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
2050 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
2051 struct obd_capa *oc, __u64 offset,
2052 struct page **pages, unsigned npages,
2053 struct ptlrpc_request **request)
2057 EXP_CHECK_MD_OP(exp, readpage);
2058 EXP_MD_COUNTER_INCREMENT(exp, readpage);
2059 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, pages, npages,
2064 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
2065 struct ptlrpc_request **request)
2069 EXP_CHECK_MD_OP(exp, unlink);
2070 EXP_MD_COUNTER_INCREMENT(exp, unlink);
2071 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
2075 static inline int md_get_lustre_md(struct obd_export *exp,
2076 struct ptlrpc_request *req,
2077 struct obd_export *dt_exp,
2078 struct obd_export *md_exp,
2079 struct lustre_md *md)
2082 EXP_CHECK_MD_OP(exp, get_lustre_md);
2083 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
2084 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
2087 static inline int md_free_lustre_md(struct obd_export *exp,
2088 struct lustre_md *md)
2091 EXP_CHECK_MD_OP(exp, free_lustre_md);
2092 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
2093 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
2096 static inline int md_setxattr(struct obd_export *exp,
2097 const struct lu_fid *fid, struct obd_capa *oc,
2098 obd_valid valid, const char *name,
2099 const char *input, int input_size,
2100 int output_size, int flags, __u32 suppgid,
2101 struct ptlrpc_request **request)
2104 EXP_CHECK_MD_OP(exp, setxattr);
2105 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
2106 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
2107 input_size, output_size, flags,
2111 static inline int md_getxattr(struct obd_export *exp,
2112 const struct lu_fid *fid, struct obd_capa *oc,
2113 obd_valid valid, const char *name,
2114 const char *input, int input_size,
2115 int output_size, int flags,
2116 struct ptlrpc_request **request)
2119 EXP_CHECK_MD_OP(exp, getxattr);
2120 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
2121 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
2122 input_size, output_size, flags,
2126 static inline int md_set_open_replay_data(struct obd_export *exp,
2127 struct obd_client_handle *och,
2128 struct ptlrpc_request *open_req)
2131 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2132 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2133 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2136 static inline int md_clear_open_replay_data(struct obd_export *exp,
2137 struct obd_client_handle *och)
2140 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2141 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2142 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2145 static inline int md_set_lock_data(struct obd_export *exp,
2146 __u64 *lockh, void *data, __u64 *bits)
2149 EXP_CHECK_MD_OP(exp, set_lock_data);
2150 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2151 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
2154 static inline int md_cancel_unused(struct obd_export *exp,
2155 const struct lu_fid *fid,
2156 ldlm_policy_data_t *policy,
2158 ldlm_cancel_flags_t flags,
2164 EXP_CHECK_MD_OP(exp, cancel_unused);
2165 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2167 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2172 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2173 const struct lu_fid *fid,
2175 ldlm_policy_data_t *policy,
2177 struct lustre_handle *lockh)
2180 EXP_CHECK_MD_OP(exp, lock_match);
2181 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2182 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2183 policy, mode, lockh));
2186 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2187 int def_asize, int cookiesize)
2190 EXP_CHECK_MD_OP(exp, init_ea_size);
2191 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2192 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2196 static inline int md_get_remote_perm(struct obd_export *exp,
2197 const struct lu_fid *fid,
2198 struct obd_capa *oc, __u32 suppgid,
2199 struct ptlrpc_request **request)
2202 EXP_CHECK_MD_OP(exp, get_remote_perm);
2203 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2204 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2208 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2213 EXP_CHECK_MD_OP(exp, renew_capa);
2214 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2215 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2219 static inline int md_unpack_capa(struct obd_export *exp,
2220 struct ptlrpc_request *req,
2221 const struct req_msg_field *field,
2222 struct obd_capa **oc)
2226 EXP_CHECK_MD_OP(exp, unpack_capa);
2227 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2228 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2232 static inline int md_intent_getattr_async(struct obd_export *exp,
2233 struct md_enqueue_info *minfo,
2234 struct ldlm_enqueue_info *einfo)
2238 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2239 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2240 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2244 static inline int md_revalidate_lock(struct obd_export *exp,
2245 struct lookup_intent *it,
2246 struct lu_fid *fid, __u64 *bits)
2250 EXP_CHECK_MD_OP(exp, revalidate_lock);
2251 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2252 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
2257 /* OBD Metadata Support */
2259 extern int obd_init_caches(void);
2260 extern void obd_cleanup_caches(void);
2262 /* support routines */
2263 extern cfs_mem_cache_t *obdo_cachep;
2265 #define OBDO_ALLOC(ptr) \
2267 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, CFS_ALLOC_IO); \
2270 #define OBDO_FREE(ptr) \
2272 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2276 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2278 /* something here */
2281 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2283 /* something here */
2286 /* I'm as embarrassed about this as you are.
2288 * <shaver> // XXX do not look into _superhack with remaining eye
2289 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2290 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2293 extern void obd_sysctl_init (void);
2294 extern void obd_sysctl_clean (void);
2297 typedef __u8 class_uuid_t[16];
2298 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2301 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2302 int class_add_uuid(const char *uuid, __u64 nid);
2303 int class_del_uuid (const char *uuid);
2304 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
2305 void class_init_uuidlist(void);
2306 void class_exit_uuidlist(void);
2309 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2310 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2313 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
2315 #endif /* __LINUX_OBD_CLASS_H */