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 /* OBD Device Declarations */
65 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
66 extern cfs_spinlock_t obd_dev_lock;
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);
73 struct lu_device_type;
76 struct obd_export *class_conn2export(struct lustre_handle *);
77 int class_register_type(struct obd_ops *, struct md_ops *,
78 struct lprocfs_vars *, const char *nm,
79 struct lu_device_type *ldt);
80 int class_unregister_type(const char *nm);
82 struct obd_device *class_newdev(const char *type_name, const char *name);
83 void class_release_dev(struct obd_device *obd);
85 int class_name2dev(const char *name);
86 struct obd_device *class_name2obd(const char *name);
87 int class_uuid2dev(struct obd_uuid *uuid);
88 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
89 void class_obd_list(void);
90 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
91 const char * typ_name,
92 struct obd_uuid *grp_uuid);
93 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
95 struct obd_device * class_num2obd(int num);
97 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
99 char *obd_export_nid2str(struct obd_export *exp);
101 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
102 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
104 int obd_zombie_impexp_init(void);
105 void obd_zombie_impexp_stop(void);
106 void obd_zombie_impexp_cull(void);
107 void obd_zombie_barrier(void);
108 void obd_exports_barrier(struct obd_device *obd);
109 int kuc_len(int payload_len);
110 struct kuc_hdr * kuc_ptr(void *p);
111 int kuc_ispayload(void *p);
112 void *kuc_alloc(int payload_len, int transport, int type);
113 void kuc_free(void *p, int payload_len);
116 int class_process_config(struct lustre_cfg *lcfg);
117 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
118 struct lustre_cfg *lcfg, void *data);
119 int class_attach(struct lustre_cfg *lcfg);
120 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
121 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
122 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
123 struct obd_device *class_incref(struct obd_device *obd,
124 const char *scope, const void *source);
125 void class_decref(struct obd_device *obd,
126 const char *scope, const void *source);
127 void dump_exports(struct obd_device *obd, int locks);
131 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
133 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
135 memset(lvars, 0, sizeof(*lvars));
139 #define CFG_F_START 0x01 /* Set when we start updating from a log */
140 #define CFG_F_MARKER 0x02 /* We are within a maker */
141 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
142 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
143 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
145 /* Passed as data param to class_config_parse_llog */
146 struct config_llog_instance {
149 struct super_block *cfg_sb;
150 struct obd_uuid cfg_uuid;
151 int cfg_last_idx; /* for partial llog processing */
154 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
155 struct config_llog_instance *cfg);
156 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
157 struct config_llog_instance *cfg);
159 /* list of active configuration logs */
160 struct config_llog_data {
162 struct ldlm_res_id cld_resid;
163 struct config_llog_instance cld_cfg;
164 cfs_list_t cld_list_chain;
165 cfs_atomic_t cld_refcount;
166 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
167 struct obd_export *cld_mgcexp;
168 cfs_mutex_t cld_lock;
169 unsigned int cld_stopping:1, /* we were told to stop
171 cld_lostlock:1, /* lock not requeued */
175 struct lustre_profile {
182 struct lustre_profile *class_get_profile(const char * prof);
183 void class_del_profile(const char *prof);
184 void class_del_profiles(void);
186 #if LUSTRE_TRACKS_LOCK_EXP_REFS
188 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
189 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
190 extern void (*class_export_dump_hook)(struct obd_export *);
194 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
195 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
199 #define class_export_rpc_get(exp) \
201 cfs_atomic_inc(&(exp)->exp_rpc_count); \
202 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
203 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
204 class_export_get(exp); \
207 #define class_export_rpc_put(exp) \
209 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
210 cfs_atomic_dec(&(exp)->exp_rpc_count); \
211 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
212 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
213 class_export_put(exp); \
216 #define class_export_lock_get(exp, lock) \
218 cfs_atomic_inc(&(exp)->exp_locks_count); \
219 __class_export_add_lock_ref(exp, lock); \
220 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
221 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
222 class_export_get(exp); \
225 #define class_export_lock_put(exp, lock) \
227 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
228 cfs_atomic_dec(&(exp)->exp_locks_count); \
229 __class_export_del_lock_ref(exp, lock); \
230 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
231 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
232 class_export_put(exp); \
235 #define class_export_cb_get(exp) \
237 cfs_atomic_inc(&(exp)->exp_cb_count); \
238 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
239 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
240 class_export_get(exp); \
243 #define class_export_cb_put(exp) \
245 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
246 cfs_atomic_dec(&(exp)->exp_cb_count); \
247 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
248 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
249 class_export_put(exp); \
253 struct obd_export *class_export_get(struct obd_export *exp);
254 void class_export_put(struct obd_export *exp);
255 struct obd_export *class_new_export(struct obd_device *obddev,
256 struct obd_uuid *cluuid);
257 void class_unlink_export(struct obd_export *exp);
259 struct obd_import *class_import_get(struct obd_import *);
260 void class_import_put(struct obd_import *);
261 struct obd_import *class_new_import(struct obd_device *obd);
262 void class_destroy_import(struct obd_import *exp);
264 struct obd_type *class_search_type(const char *name);
265 struct obd_type *class_get_type(const char *name);
266 void class_put_type(struct obd_type *type);
267 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
268 struct obd_uuid *cluuid);
269 int class_disconnect(struct obd_export *exp);
270 void class_fail_export(struct obd_export *exp);
271 int class_connected_export(struct obd_export *exp);
272 void class_disconnect_exports(struct obd_device *obddev);
273 int class_manual_cleanup(struct obd_device *obd);
274 void class_disconnect_stale_exports(struct obd_device *,
275 int (*test_export)(struct obd_export *));
276 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
278 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
279 (obd->obd_force ? OBD_OPT_FORCE : 0) |
280 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
284 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
286 LASSERT(exp->exp_obd);
287 return exp->exp_obd->u.obt.obt_lut;
290 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
292 LASSERT(obd->u.obt.obt_lut);
293 return &obd->u.obt.obt_lut->lut_lsd;
296 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
297 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
298 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
299 unsigned int ia_valid);
300 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
301 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
302 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
305 #define OBT(dev) (dev)->obd_type
306 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
307 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
308 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
310 /* Ensure obd_setup: used for cleanup which must be called
311 while obd is stopping */
312 #define OBD_CHECK_DEV(obd) \
315 CERROR("NULL device\n"); \
320 /* ensure obd_setup and !obd_stopping */
321 #define OBD_CHECK_DEV_ACTIVE(obd) \
323 OBD_CHECK_DEV(obd); \
324 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
325 CERROR("Device %d not setup\n", \
333 #define OBD_COUNTER_OFFSET(op) \
334 ((offsetof(struct obd_ops, o_ ## op) - \
335 offsetof(struct obd_ops, o_iocontrol)) \
336 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
338 #define OBD_COUNTER_INCREMENT(obdx, op) \
339 if ((obdx)->obd_stats != NULL) { \
340 unsigned int coffset; \
341 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
342 OBD_COUNTER_OFFSET(op); \
343 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
344 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
347 #define EXP_COUNTER_INCREMENT(export, op) \
348 if ((export)->exp_obd->obd_stats != NULL) { \
349 unsigned int coffset; \
350 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
351 OBD_COUNTER_OFFSET(op); \
352 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
353 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
354 if ((export)->exp_nid_stats != NULL && \
355 (export)->exp_nid_stats->nid_stats != NULL) \
356 lprocfs_counter_incr( \
357 (export)->exp_nid_stats->nid_stats, coffset);\
360 #define MD_COUNTER_OFFSET(op) \
361 ((offsetof(struct md_ops, m_ ## op) - \
362 offsetof(struct md_ops, m_getstatus)) \
363 / sizeof(((struct md_ops *)(0))->m_getstatus))
365 #define MD_COUNTER_INCREMENT(obdx, op) \
366 if ((obd)->md_stats != NULL) { \
367 unsigned int coffset; \
368 coffset = (unsigned int)((obdx)->md_cntr_base) + \
369 MD_COUNTER_OFFSET(op); \
370 LASSERT(coffset < (obdx)->md_stats->ls_num); \
371 lprocfs_counter_incr((obdx)->md_stats, coffset); \
374 #define EXP_MD_COUNTER_INCREMENT(export, op) \
375 if ((export)->exp_obd->obd_stats != NULL) { \
376 unsigned int coffset; \
377 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
378 MD_COUNTER_OFFSET(op); \
379 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
380 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
381 if ((export)->exp_md_stats != NULL) \
382 lprocfs_counter_incr( \
383 (export)->exp_md_stats, coffset); \
387 #define OBD_COUNTER_OFFSET(op)
388 #define OBD_COUNTER_INCREMENT(obd, op)
389 #define EXP_COUNTER_INCREMENT(exp, op)
390 #define MD_COUNTER_INCREMENT(obd, op)
391 #define EXP_MD_COUNTER_INCREMENT(exp, op)
394 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
396 /* Always add in ldlm_stats */
397 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
398 ,LPROCFS_STATS_FLAG_NOPERCPU);
399 if (tmp->nid_ldlm_stats == NULL)
402 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
404 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
405 tmp->nid_ldlm_stats);
408 #define OBD_CHECK_MD_OP(obd, op, err) \
410 if (!OBT(obd) || !MDP((obd), op)) { \
412 CERROR("md_" #op ": dev %s/%d no operation\n", \
413 obd->obd_name, obd->obd_minor); \
418 #define EXP_CHECK_MD_OP(exp, op) \
420 if ((exp) == NULL) { \
421 CERROR("obd_" #op ": NULL export\n"); \
424 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
425 CERROR("obd_" #op ": cleaned up obd\n"); \
426 RETURN(-EOPNOTSUPP); \
428 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
429 CERROR("obd_" #op ": dev %s/%d no operation\n", \
430 (exp)->exp_obd->obd_name, \
431 (exp)->exp_obd->obd_minor); \
432 RETURN(-EOPNOTSUPP); \
437 #define OBD_CHECK_DT_OP(obd, op, err) \
439 if (!OBT(obd) || !OBP((obd), op)) { \
441 CERROR("obd_" #op ": dev %d no operation\n", \
447 #define EXP_CHECK_DT_OP(exp, op) \
449 if ((exp) == NULL) { \
450 CERROR("obd_" #op ": NULL export\n"); \
453 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
454 CERROR("obd_" #op ": cleaned up obd\n"); \
455 RETURN(-EOPNOTSUPP); \
457 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
458 CERROR("obd_" #op ": dev %d no operation\n", \
459 (exp)->exp_obd->obd_minor); \
460 RETURN(-EOPNOTSUPP); \
464 #define CTXT_CHECK_OP(ctxt, op, err) \
466 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
468 CERROR("lop_" #op ": dev %d no operation\n", \
469 ctxt->loc_obd->obd_minor); \
474 static inline int class_devno_max(void)
476 return MAX_OBD_DEVICES;
479 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
480 void *key, __u32 *vallen, void *val,
481 struct lov_stripe_md *lsm)
486 EXP_CHECK_DT_OP(exp, get_info);
487 EXP_COUNTER_INCREMENT(exp, get_info);
489 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
493 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
494 void *key, obd_count vallen, void *val,
495 struct ptlrpc_request_set *set)
500 EXP_CHECK_DT_OP(exp, set_info_async);
501 EXP_COUNTER_INCREMENT(exp, set_info_async);
503 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
509 * obd-lu integration.
511 * Functionality is being moved into new lu_device-based layering, but some
512 * pieces of configuration process are still based on obd devices.
514 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
515 * subsume ->o_setup() methods of obd devices they replace. The same for
516 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
517 * result, obd_setup() and obd_process_config() branch and call one XOR
520 * Yet neither lu_device_type_operations::ldto_device_fini() nor
521 * lu_device_type_operations::ldto_device_free() fully implement the
522 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
523 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
526 #define DECLARE_LU_VARS(ldt, d) \
527 struct lu_device_type *ldt; \
530 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
533 DECLARE_LU_VARS(ldt, d);
536 ldt = obd->obd_type->typ_lu;
538 struct lu_context session_ctx;
540 lu_context_init(&session_ctx, LCT_SESSION);
541 session_ctx.lc_thread = NULL;
542 lu_context_enter(&session_ctx);
544 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
546 env.le_ses = &session_ctx;
547 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
556 lu_context_exit(&session_ctx);
557 lu_context_fini(&session_ctx);
560 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
561 OBD_COUNTER_INCREMENT(obd, setup);
562 rc = OBP(obd, setup)(obd, cfg);
567 static inline int obd_precleanup(struct obd_device *obd,
568 enum obd_cleanup_stage cleanup_stage)
571 DECLARE_LU_VARS(ldt, d);
575 ldt = obd->obd_type->typ_lu;
577 if (ldt != NULL && d != NULL) {
578 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
581 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
583 ldt->ldt_ops->ldto_device_fini(&env, d);
588 OBD_CHECK_DT_OP(obd, precleanup, 0);
589 OBD_COUNTER_INCREMENT(obd, precleanup);
591 rc = OBP(obd, precleanup)(obd, cleanup_stage);
595 static inline int obd_cleanup(struct obd_device *obd)
598 DECLARE_LU_VARS(ldt, d);
603 ldt = obd->obd_type->typ_lu;
605 if (ldt != NULL && d != NULL) {
608 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
610 ldt->ldt_ops->ldto_device_free(&env, d);
612 obd->obd_lu_dev = NULL;
615 OBD_CHECK_DT_OP(obd, cleanup, 0);
616 OBD_COUNTER_INCREMENT(obd, cleanup);
618 rc = OBP(obd, cleanup)(obd);
623 obd_process_config(struct obd_device *obd, int datalen, void *data)
626 DECLARE_LU_VARS(ldt, d);
631 obd->obd_process_conf = 1;
632 ldt = obd->obd_type->typ_lu;
634 if (ldt != NULL && d != NULL) {
637 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
639 rc = d->ld_ops->ldo_process_config(&env, d, data);
643 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
644 rc = OBP(obd, process_config)(obd, datalen, data);
646 OBD_COUNTER_INCREMENT(obd, process_config);
647 obd->obd_process_conf = 0;
652 /* Pack an in-memory MD struct for storage on disk.
653 * Returns +ve size of packed MD (0 for free), or -ve error.
655 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
656 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
657 * If @*disk_tgt == NULL, it will be allocated
659 static inline int obd_packmd(struct obd_export *exp,
660 struct lov_mds_md **disk_tgt,
661 struct lov_stripe_md *mem_src)
666 EXP_CHECK_DT_OP(exp, packmd);
667 EXP_COUNTER_INCREMENT(exp, packmd);
669 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
673 static inline int obd_size_diskmd(struct obd_export *exp,
674 struct lov_stripe_md *mem_src)
676 return obd_packmd(exp, NULL, mem_src);
679 /* helper functions */
680 static inline int obd_alloc_diskmd(struct obd_export *exp,
681 struct lov_mds_md **disk_tgt)
684 LASSERT(*disk_tgt == NULL);
685 return obd_packmd(exp, disk_tgt, NULL);
688 static inline int obd_free_diskmd(struct obd_export *exp,
689 struct lov_mds_md **disk_tgt)
693 return obd_packmd(exp, disk_tgt, NULL);
696 /* Unpack an MD struct from disk to in-memory format.
697 * Returns +ve size of unpacked MD (0 for free), or -ve error.
699 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
700 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
701 * If @*mem_tgt == NULL, it will be allocated
703 static inline int obd_unpackmd(struct obd_export *exp,
704 struct lov_stripe_md **mem_tgt,
705 struct lov_mds_md *disk_src,
711 EXP_CHECK_DT_OP(exp, unpackmd);
712 EXP_COUNTER_INCREMENT(exp, unpackmd);
714 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
718 /* helper functions */
719 static inline int obd_alloc_memmd(struct obd_export *exp,
720 struct lov_stripe_md **mem_tgt)
723 LASSERT(*mem_tgt == NULL);
724 return obd_unpackmd(exp, mem_tgt, NULL, 0);
727 static inline int obd_free_memmd(struct obd_export *exp,
728 struct lov_stripe_md **mem_tgt)
734 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
739 static inline int obd_precreate(struct obd_export *exp)
744 EXP_CHECK_DT_OP(exp, precreate);
745 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
747 rc = OBP(exp->exp_obd, precreate)(exp);
751 static inline int obd_create_async(struct obd_export *exp,
752 struct obd_info *oinfo,
753 struct lov_stripe_md **ea,
754 struct obd_trans_info *oti)
759 EXP_CHECK_DT_OP(exp, create_async);
760 EXP_COUNTER_INCREMENT(exp, create_async);
762 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
766 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
767 struct lov_stripe_md **ea,
768 struct obd_trans_info *oti)
773 EXP_CHECK_DT_OP(exp, create);
774 EXP_COUNTER_INCREMENT(exp, create);
776 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
780 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
781 struct lov_stripe_md *ea,
782 struct obd_trans_info *oti,
783 struct obd_export *md_exp, void *capa)
788 EXP_CHECK_DT_OP(exp, destroy);
789 EXP_COUNTER_INCREMENT(exp, destroy);
791 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
795 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
800 EXP_CHECK_DT_OP(exp, getattr);
801 EXP_COUNTER_INCREMENT(exp, getattr);
803 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
807 static inline int obd_getattr_async(struct obd_export *exp,
808 struct obd_info *oinfo,
809 struct ptlrpc_request_set *set)
814 EXP_CHECK_DT_OP(exp, getattr_async);
815 EXP_COUNTER_INCREMENT(exp, getattr_async);
817 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
821 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
822 struct obd_trans_info *oti)
827 EXP_CHECK_DT_OP(exp, setattr);
828 EXP_COUNTER_INCREMENT(exp, setattr);
830 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
834 /* This performs all the requests set init/wait/destroy actions. */
835 static inline int obd_setattr_rqset(struct obd_export *exp,
836 struct obd_info *oinfo,
837 struct obd_trans_info *oti)
839 struct ptlrpc_request_set *set = NULL;
843 EXP_CHECK_DT_OP(exp, setattr_async);
844 EXP_COUNTER_INCREMENT(exp, setattr_async);
846 set = ptlrpc_prep_set();
850 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
852 rc = ptlrpc_set_wait(set);
853 ptlrpc_set_destroy(set);
857 /* This adds all the requests into @set if @set != NULL, otherwise
858 all requests are sent asynchronously without waiting for response. */
859 static inline int obd_setattr_async(struct obd_export *exp,
860 struct obd_info *oinfo,
861 struct obd_trans_info *oti,
862 struct ptlrpc_request_set *set)
867 EXP_CHECK_DT_OP(exp, setattr_async);
868 EXP_COUNTER_INCREMENT(exp, setattr_async);
870 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
874 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
877 struct obd_device *obd = imp->imp_obd;
881 OBD_CHECK_DEV_ACTIVE(obd);
882 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
883 OBD_COUNTER_INCREMENT(obd, add_conn);
885 rc = OBP(obd, add_conn)(imp, uuid, priority);
889 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
891 struct obd_device *obd = imp->imp_obd;
895 OBD_CHECK_DEV_ACTIVE(obd);
896 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
897 OBD_COUNTER_INCREMENT(obd, del_conn);
899 rc = OBP(obd, del_conn)(imp, uuid);
903 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
905 struct obd_uuid *uuid;
908 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
909 EXP_COUNTER_INCREMENT(exp, get_uuid);
911 uuid = OBP(exp->exp_obd, get_uuid)(exp);
915 /** Create a new /a exp on device /a obd for the uuid /a cluuid
916 * @param exp New export handle
917 * @param d Connect data, supported flags are set, flags also understood
918 * by obd are returned.
920 static inline int obd_connect(const struct lu_env *env,
921 struct obd_export **exp,struct obd_device *obd,
922 struct obd_uuid *cluuid,
923 struct obd_connect_data *d,
927 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
931 OBD_CHECK_DEV_ACTIVE(obd);
932 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
933 OBD_COUNTER_INCREMENT(obd, connect);
935 rc = OBP(obd, connect)(env, exp, obd, cluuid, d, localdata);
936 /* check that only subset is granted */
937 LASSERT(ergo(d != NULL,
938 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
942 static inline int obd_reconnect(const struct lu_env *env,
943 struct obd_export *exp,
944 struct obd_device *obd,
945 struct obd_uuid *cluuid,
946 struct obd_connect_data *d,
950 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
955 OBD_CHECK_DEV_ACTIVE(obd);
956 OBD_CHECK_DT_OP(obd, reconnect, 0);
957 OBD_COUNTER_INCREMENT(obd, reconnect);
959 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
960 /* check that only subset is granted */
961 LASSERT(ergo(d != NULL,
962 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
966 static inline int obd_disconnect(struct obd_export *exp)
971 EXP_CHECK_DT_OP(exp, disconnect);
972 EXP_COUNTER_INCREMENT(exp, disconnect);
974 rc = OBP(exp->exp_obd, disconnect)(exp);
978 static inline int obd_fid_init(struct obd_export *exp)
983 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
984 EXP_COUNTER_INCREMENT(exp, fid_init);
986 rc = OBP(exp->exp_obd, fid_init)(exp);
990 static inline int obd_fid_fini(struct obd_export *exp)
995 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
996 EXP_COUNTER_INCREMENT(exp, fid_fini);
998 rc = OBP(exp->exp_obd, fid_fini)(exp);
1002 static inline int obd_fid_alloc(struct obd_export *exp,
1004 struct md_op_data *op_data)
1009 EXP_CHECK_DT_OP(exp, fid_alloc);
1010 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1012 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
1016 static inline int obd_fid_delete(struct obd_export *exp,
1017 const struct lu_fid *fid)
1022 EXP_CHECK_DT_OP(exp, fid_delete);
1023 EXP_COUNTER_INCREMENT(exp, fid_delete);
1025 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
1029 static inline int obd_ping(struct obd_export *exp)
1034 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1035 EXP_COUNTER_INCREMENT(exp, ping);
1037 rc = OBP(exp->exp_obd, ping)(exp);
1041 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1046 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1047 OBD_COUNTER_INCREMENT(obd, pool_new);
1049 rc = OBP(obd, pool_new)(obd, poolname);
1053 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1058 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1059 OBD_COUNTER_INCREMENT(obd, pool_del);
1061 rc = OBP(obd, pool_del)(obd, poolname);
1065 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1070 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1071 OBD_COUNTER_INCREMENT(obd, pool_add);
1073 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1077 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1082 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1083 OBD_COUNTER_INCREMENT(obd, pool_rem);
1085 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1089 static inline void obd_getref(struct obd_device *obd)
1092 if (OBT(obd) && OBP(obd, getref)) {
1093 OBD_COUNTER_INCREMENT(obd, getref);
1094 OBP(obd, getref)(obd);
1099 static inline void obd_putref(struct obd_device *obd)
1102 if (OBT(obd) && OBP(obd, putref)) {
1103 OBD_COUNTER_INCREMENT(obd, putref);
1104 OBP(obd, putref)(obd);
1109 static inline int obd_init_export(struct obd_export *exp)
1114 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1115 OBP((exp)->exp_obd, init_export))
1116 rc = OBP(exp->exp_obd, init_export)(exp);
1120 static inline int obd_destroy_export(struct obd_export *exp)
1123 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1124 OBP((exp)->exp_obd, destroy_export))
1125 OBP(exp->exp_obd, destroy_export)(exp);
1129 static inline int obd_extent_calc(struct obd_export *exp,
1130 struct lov_stripe_md *md,
1131 int cmd, obd_off *offset)
1135 EXP_CHECK_DT_OP(exp, extent_calc);
1136 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1140 static inline struct dentry *
1141 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1143 LASSERT(exp->exp_obd);
1145 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1150 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1152 LASSERT(exp->exp_obd);
1153 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1155 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1156 dentry, exp->exp_obd);
1161 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1162 * If the cache is older than @max_age we will get a new value from the
1163 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1164 static inline int obd_statfs_async(struct obd_device *obd,
1165 struct obd_info *oinfo,
1167 struct ptlrpc_request_set *rqset)
1175 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1176 OBD_COUNTER_INCREMENT(obd, statfs);
1178 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1179 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1180 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1181 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1183 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1184 " objects "LPU64"/"LPU64"\n",
1185 obd->obd_name, &obd->obd_osfs,
1186 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1187 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1188 cfs_spin_lock(&obd->obd_osfs_lock);
1189 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1190 cfs_spin_unlock(&obd->obd_osfs_lock);
1191 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1192 if (oinfo->oi_cb_up)
1193 oinfo->oi_cb_up(oinfo, 0);
1198 static inline int obd_statfs_rqset(struct obd_device *obd,
1199 struct obd_statfs *osfs, __u64 max_age,
1202 struct ptlrpc_request_set *set = NULL;
1203 struct obd_info oinfo = { { { 0 } } };
1207 set = ptlrpc_prep_set();
1211 oinfo.oi_osfs = osfs;
1212 oinfo.oi_flags = flags;
1213 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1215 rc = ptlrpc_set_wait(set);
1216 ptlrpc_set_destroy(set);
1220 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1221 * If the cache is older than @max_age we will get a new value from the
1222 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1223 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1224 __u64 max_age, __u32 flags)
1232 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1233 OBD_COUNTER_INCREMENT(obd, statfs);
1235 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1236 obd->obd_osfs_age, max_age);
1237 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1238 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1240 cfs_spin_lock(&obd->obd_osfs_lock);
1241 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1242 obd->obd_osfs_age = cfs_time_current_64();
1243 cfs_spin_unlock(&obd->obd_osfs_lock);
1246 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1247 " objects "LPU64"/"LPU64"\n",
1248 obd->obd_name, &obd->obd_osfs,
1249 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1250 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1251 cfs_spin_lock(&obd->obd_osfs_lock);
1252 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1253 cfs_spin_unlock(&obd->obd_osfs_lock);
1258 static inline int obd_sync_rqset(struct obd_export *exp, struct obd_info *oinfo,
1259 obd_size start, obd_size end)
1261 struct ptlrpc_request_set *set = NULL;
1265 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1266 EXP_COUNTER_INCREMENT(exp, sync);
1268 set = ptlrpc_prep_set();
1272 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1274 rc = ptlrpc_set_wait(set);
1275 ptlrpc_set_destroy(set);
1279 static inline int obd_sync(struct obd_export *exp, struct obd_info *oinfo,
1280 obd_size start, obd_size end,
1281 struct ptlrpc_request_set *set)
1286 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1287 EXP_COUNTER_INCREMENT(exp, sync);
1289 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1293 static inline int obd_punch_rqset(struct obd_export *exp,
1294 struct obd_info *oinfo,
1295 struct obd_trans_info *oti)
1297 struct ptlrpc_request_set *set = NULL;
1301 EXP_CHECK_DT_OP(exp, punch);
1302 EXP_COUNTER_INCREMENT(exp, punch);
1304 set = ptlrpc_prep_set();
1308 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1310 rc = ptlrpc_set_wait(set);
1311 ptlrpc_set_destroy(set);
1315 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1316 struct obd_trans_info *oti,
1317 struct ptlrpc_request_set *rqset)
1322 EXP_CHECK_DT_OP(exp, punch);
1323 EXP_COUNTER_INCREMENT(exp, punch);
1325 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1329 static inline int obd_brw(int cmd, struct obd_export *exp,
1330 struct obd_info *oinfo, obd_count oa_bufs,
1331 struct brw_page *pg, struct obd_trans_info *oti)
1336 EXP_CHECK_DT_OP(exp, brw);
1337 EXP_COUNTER_INCREMENT(exp, brw);
1339 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1340 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1341 "or OBD_BRW_CHECK\n");
1345 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1349 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1350 int objcount, struct obd_ioobj *obj,
1351 struct niobuf_remote *remote, int *pages,
1352 struct niobuf_local *local,
1353 struct obd_trans_info *oti,
1354 struct lustre_capa *capa)
1359 EXP_CHECK_DT_OP(exp, preprw);
1360 EXP_COUNTER_INCREMENT(exp, preprw);
1362 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1363 pages, local, oti, capa);
1367 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1368 int objcount, struct obd_ioobj *obj,
1369 struct niobuf_remote *rnb, int pages,
1370 struct niobuf_local *local,
1371 struct obd_trans_info *oti, int rc)
1375 EXP_CHECK_DT_OP(exp, commitrw);
1376 EXP_COUNTER_INCREMENT(exp, commitrw);
1378 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1379 rnb, pages, local, oti, rc);
1383 static inline int obd_merge_lvb(struct obd_export *exp,
1384 struct lov_stripe_md *lsm,
1385 struct ost_lvb *lvb, int kms_only)
1390 EXP_CHECK_DT_OP(exp, merge_lvb);
1391 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1393 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1397 static inline int obd_adjust_kms(struct obd_export *exp,
1398 struct lov_stripe_md *lsm, obd_off size,
1404 EXP_CHECK_DT_OP(exp, adjust_kms);
1405 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1407 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1411 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1412 int len, void *karg, void *uarg)
1417 EXP_CHECK_DT_OP(exp, iocontrol);
1418 EXP_COUNTER_INCREMENT(exp, iocontrol);
1420 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1424 static inline int obd_enqueue_rqset(struct obd_export *exp,
1425 struct obd_info *oinfo,
1426 struct ldlm_enqueue_info *einfo)
1428 struct ptlrpc_request_set *set = NULL;
1432 EXP_CHECK_DT_OP(exp, enqueue);
1433 EXP_COUNTER_INCREMENT(exp, enqueue);
1435 set = ptlrpc_prep_set();
1439 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1441 rc = ptlrpc_set_wait(set);
1442 ptlrpc_set_destroy(set);
1446 static inline int obd_enqueue(struct obd_export *exp,
1447 struct obd_info *oinfo,
1448 struct ldlm_enqueue_info *einfo,
1449 struct ptlrpc_request_set *set)
1454 EXP_CHECK_DT_OP(exp, enqueue);
1455 EXP_COUNTER_INCREMENT(exp, enqueue);
1457 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1461 static inline int obd_change_cbdata(struct obd_export *exp,
1462 struct lov_stripe_md *lsm,
1463 ldlm_iterator_t it, void *data)
1468 EXP_CHECK_DT_OP(exp, change_cbdata);
1469 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1471 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1475 static inline int obd_find_cbdata(struct obd_export *exp,
1476 struct lov_stripe_md *lsm,
1477 ldlm_iterator_t it, void *data)
1482 EXP_CHECK_DT_OP(exp, find_cbdata);
1483 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1485 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1489 static inline int obd_cancel(struct obd_export *exp,
1490 struct lov_stripe_md *ea, __u32 mode,
1491 struct lustre_handle *lockh)
1496 EXP_CHECK_DT_OP(exp, cancel);
1497 EXP_COUNTER_INCREMENT(exp, cancel);
1499 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1503 static inline int obd_cancel_unused(struct obd_export *exp,
1504 struct lov_stripe_md *ea,
1505 ldlm_cancel_flags_t flags,
1511 EXP_CHECK_DT_OP(exp, cancel_unused);
1512 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1514 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1518 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1519 struct obd_capa *oc, struct obd_client_handle *handle,
1525 EXP_CHECK_DT_OP(exp, pin);
1526 EXP_COUNTER_INCREMENT(exp, pin);
1528 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1532 static inline int obd_unpin(struct obd_export *exp,
1533 struct obd_client_handle *handle, int flag)
1538 EXP_CHECK_DT_OP(exp, unpin);
1539 EXP_COUNTER_INCREMENT(exp, unpin);
1541 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1546 static inline void obd_import_event(struct obd_device *obd,
1547 struct obd_import *imp,
1548 enum obd_import_event event)
1552 CERROR("NULL device\n");
1556 if (obd->obd_set_up && OBP(obd, import_event)) {
1557 OBD_COUNTER_INCREMENT(obd, import_event);
1558 OBP(obd, import_event)(obd, imp, event);
1563 static inline int obd_llog_connect(struct obd_export *exp,
1564 struct llogd_conn_body *body)
1569 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1570 EXP_COUNTER_INCREMENT(exp, llog_connect);
1572 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1577 static inline int obd_notify(struct obd_device *obd,
1578 struct obd_device *watched,
1579 enum obd_notify_event ev,
1586 /* the check for async_recov is a complete hack - I'm hereby
1587 overloading the meaning to also mean "this was called from
1588 mds_postsetup". I know that my mds is able to handle notifies
1589 by this point, and it needs to get them to execute mds_postrecov. */
1590 if (!obd->obd_set_up && !obd->obd_async_recov) {
1591 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1595 if (!OBP(obd, notify)) {
1596 CERROR("obd %s has no notify handler\n", obd->obd_name);
1600 OBD_COUNTER_INCREMENT(obd, notify);
1601 rc = OBP(obd, notify)(obd, watched, ev, data);
1605 static inline int obd_notify_observer(struct obd_device *observer,
1606 struct obd_device *observed,
1607 enum obd_notify_event ev,
1613 struct obd_notify_upcall *onu;
1615 if (observer->obd_observer)
1616 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1620 * Also, call non-obd listener, if any
1622 onu = &observer->obd_upcall;
1623 if (onu->onu_upcall != NULL)
1624 rc2 = onu->onu_upcall(observer, observed, ev,
1625 onu->onu_owner, NULL);
1629 return rc1 ? rc1 : rc2;
1632 static inline int obd_quotacheck(struct obd_export *exp,
1633 struct obd_quotactl *oqctl)
1638 EXP_CHECK_DT_OP(exp, quotacheck);
1639 EXP_COUNTER_INCREMENT(exp, quotacheck);
1641 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1645 static inline int obd_quotactl(struct obd_export *exp,
1646 struct obd_quotactl *oqctl)
1651 EXP_CHECK_DT_OP(exp, quotactl);
1652 EXP_COUNTER_INCREMENT(exp, quotactl);
1654 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1658 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1659 struct quota_adjust_qunit *oqaq,
1660 struct lustre_quota_ctxt *qctxt,
1661 struct ptlrpc_request_set *set)
1663 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1664 struct timeval work_start;
1665 struct timeval work_end;
1671 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1673 cfs_gettimeofday(&work_start);
1675 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1676 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1678 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt, set);
1680 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1682 cfs_gettimeofday(&work_end);
1683 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1684 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1691 static inline int obd_health_check(struct obd_device *obd)
1693 /* returns: 0 on healthy
1694 * >0 on unhealthy + reason code/flag
1695 * however the only suppored reason == 1 right now
1696 * We'll need to define some better reasons
1697 * or flags in the future.
1703 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1704 if (obd == NULL || !OBT(obd)) {
1705 CERROR("cleaned up obd\n");
1706 RETURN(-EOPNOTSUPP);
1708 if (!obd->obd_set_up || obd->obd_stopping)
1710 if (!OBP(obd, health_check))
1713 rc = OBP(obd, health_check)(obd);
1717 static inline int obd_register_observer(struct obd_device *obd,
1718 struct obd_device *observer)
1722 cfs_down_write(&obd->obd_observer_link_sem);
1723 if (obd->obd_observer && observer) {
1724 cfs_up_write(&obd->obd_observer_link_sem);
1727 obd->obd_observer = observer;
1728 cfs_up_write(&obd->obd_observer_link_sem);
1732 static inline int obd_pin_observer(struct obd_device *obd,
1733 struct obd_device **observer)
1736 cfs_down_read(&obd->obd_observer_link_sem);
1737 if (!obd->obd_observer) {
1739 cfs_up_read(&obd->obd_observer_link_sem);
1742 *observer = obd->obd_observer;
1746 static inline int obd_unpin_observer(struct obd_device *obd)
1749 cfs_up_read(&obd->obd_observer_link_sem);
1754 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1755 obd_page_removal_cb_t cb,
1756 obd_pin_extent_cb pin_cb)
1761 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1762 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1764 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1768 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1769 obd_page_removal_cb_t cb)
1774 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1775 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1777 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1781 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1782 obd_lock_cancel_cb cb)
1787 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1788 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1790 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1794 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1795 obd_lock_cancel_cb cb)
1800 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1801 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1803 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1808 /* metadata helpers */
1809 static inline int md_getstatus(struct obd_export *exp,
1810 struct lu_fid *fid, struct obd_capa **pc)
1815 EXP_CHECK_MD_OP(exp, getstatus);
1816 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1817 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1821 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1822 struct ptlrpc_request **request)
1826 EXP_CHECK_MD_OP(exp, getattr);
1827 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1828 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1832 static inline int md_change_cbdata(struct obd_export *exp,
1833 const struct lu_fid *fid,
1834 ldlm_iterator_t it, void *data)
1838 EXP_CHECK_MD_OP(exp, change_cbdata);
1839 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1840 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1844 static inline int md_find_cbdata(struct obd_export *exp,
1845 const struct lu_fid *fid,
1846 ldlm_iterator_t it, void *data)
1850 EXP_CHECK_MD_OP(exp, find_cbdata);
1851 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1852 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1856 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1857 struct md_open_data *mod,
1858 struct ptlrpc_request **request)
1862 EXP_CHECK_MD_OP(exp, close);
1863 EXP_MD_COUNTER_INCREMENT(exp, close);
1864 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1868 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1869 const void *data, int datalen, int mode, __u32 uid,
1870 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1871 struct ptlrpc_request **request)
1875 EXP_CHECK_MD_OP(exp, create);
1876 EXP_MD_COUNTER_INCREMENT(exp, create);
1877 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1878 uid, gid, cap_effective, rdev, request);
1882 static inline int md_done_writing(struct obd_export *exp,
1883 struct md_op_data *op_data,
1884 struct md_open_data *mod)
1888 EXP_CHECK_MD_OP(exp, done_writing);
1889 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1890 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1894 static inline int md_enqueue(struct obd_export *exp,
1895 struct ldlm_enqueue_info *einfo,
1896 struct lookup_intent *it,
1897 struct md_op_data *op_data,
1898 struct lustre_handle *lockh,
1899 void *lmm, int lmmsize,
1900 struct ptlrpc_request **req,
1901 int extra_lock_flags)
1905 EXP_CHECK_MD_OP(exp, enqueue);
1906 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1907 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1908 lmm, lmmsize, req, extra_lock_flags);
1912 static inline int md_getattr_name(struct obd_export *exp,
1913 struct md_op_data *op_data,
1914 struct ptlrpc_request **request)
1918 EXP_CHECK_MD_OP(exp, getattr_name);
1919 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1920 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1924 static inline int md_intent_lock(struct obd_export *exp,
1925 struct md_op_data *op_data, void *lmm,
1926 int lmmsize, struct lookup_intent *it,
1927 int flags, struct ptlrpc_request **reqp,
1928 ldlm_blocking_callback cb_blocking,
1929 int extra_lock_flags)
1933 EXP_CHECK_MD_OP(exp, intent_lock);
1934 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1935 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1936 it, flags, reqp, cb_blocking,
1941 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1942 struct ptlrpc_request **request)
1946 EXP_CHECK_MD_OP(exp, link);
1947 EXP_MD_COUNTER_INCREMENT(exp, link);
1948 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1952 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1953 const char *old, int oldlen, const char *new,
1954 int newlen, struct ptlrpc_request **request)
1958 EXP_CHECK_MD_OP(exp, rename);
1959 EXP_MD_COUNTER_INCREMENT(exp, rename);
1960 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1965 static inline int md_is_subdir(struct obd_export *exp,
1966 const struct lu_fid *pfid,
1967 const struct lu_fid *cfid,
1968 struct ptlrpc_request **request)
1972 EXP_CHECK_MD_OP(exp, is_subdir);
1973 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1974 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1978 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1979 void *ea, int ealen, void *ea2, int ea2len,
1980 struct ptlrpc_request **request,
1981 struct md_open_data **mod)
1985 EXP_CHECK_MD_OP(exp, setattr);
1986 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1987 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1988 ea2, ea2len, request, mod);
1992 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1993 struct obd_capa *oc, struct ptlrpc_request **request)
1997 EXP_CHECK_MD_OP(exp, sync);
1998 EXP_MD_COUNTER_INCREMENT(exp, sync);
1999 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
2003 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
2004 struct obd_capa *oc, __u64 offset,
2005 struct page **pages, unsigned npages,
2006 struct ptlrpc_request **request)
2010 EXP_CHECK_MD_OP(exp, readpage);
2011 EXP_MD_COUNTER_INCREMENT(exp, readpage);
2012 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, pages, npages,
2017 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
2018 struct ptlrpc_request **request)
2022 EXP_CHECK_MD_OP(exp, unlink);
2023 EXP_MD_COUNTER_INCREMENT(exp, unlink);
2024 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
2028 static inline int md_get_lustre_md(struct obd_export *exp,
2029 struct ptlrpc_request *req,
2030 struct obd_export *dt_exp,
2031 struct obd_export *md_exp,
2032 struct lustre_md *md)
2035 EXP_CHECK_MD_OP(exp, get_lustre_md);
2036 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
2037 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
2040 static inline int md_free_lustre_md(struct obd_export *exp,
2041 struct lustre_md *md)
2044 EXP_CHECK_MD_OP(exp, free_lustre_md);
2045 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
2046 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
2049 static inline int md_setxattr(struct obd_export *exp,
2050 const struct lu_fid *fid, struct obd_capa *oc,
2051 obd_valid valid, const char *name,
2052 const char *input, int input_size,
2053 int output_size, int flags, __u32 suppgid,
2054 struct ptlrpc_request **request)
2057 EXP_CHECK_MD_OP(exp, setxattr);
2058 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
2059 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
2060 input_size, output_size, flags,
2064 static inline int md_getxattr(struct obd_export *exp,
2065 const struct lu_fid *fid, struct obd_capa *oc,
2066 obd_valid valid, const char *name,
2067 const char *input, int input_size,
2068 int output_size, int flags,
2069 struct ptlrpc_request **request)
2072 EXP_CHECK_MD_OP(exp, getxattr);
2073 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
2074 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
2075 input_size, output_size, flags,
2079 static inline int md_set_open_replay_data(struct obd_export *exp,
2080 struct obd_client_handle *och,
2081 struct ptlrpc_request *open_req)
2084 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2085 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2086 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2089 static inline int md_clear_open_replay_data(struct obd_export *exp,
2090 struct obd_client_handle *och)
2093 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2094 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2095 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2098 static inline int md_set_lock_data(struct obd_export *exp,
2099 __u64 *lockh, void *data, __u32 *bits)
2102 EXP_CHECK_MD_OP(exp, set_lock_data);
2103 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2104 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
2107 static inline int md_cancel_unused(struct obd_export *exp,
2108 const struct lu_fid *fid,
2109 ldlm_policy_data_t *policy,
2111 ldlm_cancel_flags_t flags,
2117 EXP_CHECK_MD_OP(exp, cancel_unused);
2118 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2120 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2125 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2126 const struct lu_fid *fid,
2128 ldlm_policy_data_t *policy,
2130 struct lustre_handle *lockh)
2133 EXP_CHECK_MD_OP(exp, lock_match);
2134 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2135 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2136 policy, mode, lockh));
2139 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2140 int def_asize, int cookiesize)
2143 EXP_CHECK_MD_OP(exp, init_ea_size);
2144 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2145 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2149 static inline int md_get_remote_perm(struct obd_export *exp,
2150 const struct lu_fid *fid,
2151 struct obd_capa *oc, __u32 suppgid,
2152 struct ptlrpc_request **request)
2155 EXP_CHECK_MD_OP(exp, get_remote_perm);
2156 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2157 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2161 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2166 EXP_CHECK_MD_OP(exp, renew_capa);
2167 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2168 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2172 static inline int md_unpack_capa(struct obd_export *exp,
2173 struct ptlrpc_request *req,
2174 const struct req_msg_field *field,
2175 struct obd_capa **oc)
2179 EXP_CHECK_MD_OP(exp, unpack_capa);
2180 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2181 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2185 static inline int md_intent_getattr_async(struct obd_export *exp,
2186 struct md_enqueue_info *minfo,
2187 struct ldlm_enqueue_info *einfo)
2191 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2192 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2193 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2197 static inline int md_revalidate_lock(struct obd_export *exp,
2198 struct lookup_intent *it,
2203 EXP_CHECK_MD_OP(exp, revalidate_lock);
2204 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2205 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2210 /* OBD Metadata Support */
2212 extern int obd_init_caches(void);
2213 extern void obd_cleanup_caches(void);
2215 /* support routines */
2216 extern cfs_mem_cache_t *obdo_cachep;
2218 #define OBDO_ALLOC(ptr) \
2220 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, CFS_ALLOC_IO); \
2223 #define OBDO_FREE(ptr) \
2225 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2229 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2231 /* something here */
2234 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2236 /* something here */
2239 /* I'm as embarrassed about this as you are.
2241 * <shaver> // XXX do not look into _superhack with remaining eye
2242 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2243 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2246 extern void obd_sysctl_init (void);
2247 extern void obd_sysctl_clean (void);
2250 typedef __u8 class_uuid_t[16];
2251 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2254 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2255 int class_add_uuid(const char *uuid, __u64 nid);
2256 int class_del_uuid (const char *uuid);
2257 void class_init_uuidlist(void);
2258 void class_exit_uuidlist(void);
2261 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2262 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2265 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
2267 #endif /* __LINUX_OBD_CLASS_H */