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 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
40 # include <liblustre.h>
43 #include <obd_support.h>
44 #include <lustre_import.h>
45 #include <lustre_net.h>
47 #include <lustre_lib.h>
48 #include <lustre/lustre_idl.h>
49 #include <lprocfs_status.h>
51 #if defined(__linux__)
52 #include <linux/obd_class.h>
53 #elif defined(__APPLE__)
54 #include <darwin/obd_class.h>
55 #elif defined(__WINNT__)
56 #include <winnt/obd_class.h>
58 #error Unsupported operating system.
61 /* OBD Device Declarations */
62 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
63 extern cfs_spinlock_t obd_dev_lock;
65 /* OBD Operations Declarations */
66 extern struct obd_device *class_conn2obd(struct lustre_handle *);
67 extern struct obd_device *class_exp2obd(struct obd_export *);
68 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
70 struct lu_device_type;
73 struct obd_export *class_conn2export(struct lustre_handle *);
74 int class_register_type(struct obd_ops *, struct md_ops *,
75 struct lprocfs_vars *, const char *nm,
76 struct lu_device_type *ldt);
77 int class_unregister_type(const char *nm);
79 struct obd_device *class_newdev(const char *type_name, const char *name);
80 void class_release_dev(struct obd_device *obd);
82 int class_name2dev(const char *name);
83 struct obd_device *class_name2obd(const char *name);
84 int class_uuid2dev(struct obd_uuid *uuid);
85 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
86 void class_obd_list(void);
87 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
88 const char * typ_name,
89 struct obd_uuid *grp_uuid);
90 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
92 struct obd_device * class_num2obd(int num);
94 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
96 char *obd_export_nid2str(struct obd_export *exp);
98 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
99 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
101 int obd_zombie_impexp_init(void);
102 void obd_zombie_impexp_stop(void);
103 void obd_zombie_impexp_cull(void);
104 void obd_zombie_barrier(void);
105 void obd_exports_barrier(struct obd_device *obd);
106 int kuc_len(int payload_len);
107 struct kuc_hdr * kuc_ptr(void *p);
108 int kuc_ispayload(void *p);
109 void *kuc_alloc(int payload_len, int transport, int type);
110 void kuc_free(void *p, int payload_len);
113 int class_process_config(struct lustre_cfg *lcfg);
114 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
115 struct lustre_cfg *lcfg, void *data);
116 int class_attach(struct lustre_cfg *lcfg);
117 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
118 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
119 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
120 struct obd_device *class_incref(struct obd_device *obd,
121 const char *scope, const void *source);
122 void class_decref(struct obd_device *obd,
123 const char *scope, const void *source);
124 void dump_exports(struct obd_device *obd, int locks);
128 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
130 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
132 memset(lvars, 0, sizeof(*lvars));
136 #define CFG_F_START 0x01 /* Set when we start updating from a log */
137 #define CFG_F_MARKER 0x02 /* We are within a maker */
138 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
139 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
140 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
142 /* Passed as data param to class_config_parse_llog */
143 struct config_llog_instance {
146 struct super_block *cfg_sb;
147 struct obd_uuid cfg_uuid;
148 int cfg_last_idx; /* for partial llog processing */
151 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
152 struct config_llog_instance *cfg);
153 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
154 struct config_llog_instance *cfg);
156 /* list of active configuration logs */
157 struct config_llog_data {
159 struct ldlm_res_id cld_resid;
160 struct config_llog_instance cld_cfg;
161 cfs_list_t cld_list_chain;
162 cfs_atomic_t cld_refcount;
163 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
164 struct obd_export *cld_mgcexp;
165 cfs_mutex_t cld_lock;
166 unsigned int cld_stopping:1, /* we were told to stop
168 cld_lostlock:1, /* lock not requeued */
172 struct lustre_profile {
179 struct lustre_profile *class_get_profile(const char * prof);
180 void class_del_profile(const char *prof);
181 void class_del_profiles(void);
183 #if LUSTRE_TRACKS_LOCK_EXP_REFS
185 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
186 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
187 extern void (*class_export_dump_hook)(struct obd_export *);
191 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
192 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
196 #define class_export_rpc_get(exp) \
198 cfs_atomic_inc(&(exp)->exp_rpc_count); \
199 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
200 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
201 class_export_get(exp); \
204 #define class_export_rpc_put(exp) \
206 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
207 cfs_atomic_dec(&(exp)->exp_rpc_count); \
208 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
209 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
210 class_export_put(exp); \
213 #define class_export_lock_get(exp, lock) \
215 cfs_atomic_inc(&(exp)->exp_locks_count); \
216 __class_export_add_lock_ref(exp, lock); \
217 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
218 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
219 class_export_get(exp); \
222 #define class_export_lock_put(exp, lock) \
224 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
225 cfs_atomic_dec(&(exp)->exp_locks_count); \
226 __class_export_del_lock_ref(exp, lock); \
227 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
228 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
229 class_export_put(exp); \
232 #define class_export_cb_get(exp) \
234 cfs_atomic_inc(&(exp)->exp_cb_count); \
235 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
236 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
237 class_export_get(exp); \
240 #define class_export_cb_put(exp) \
242 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
243 cfs_atomic_dec(&(exp)->exp_cb_count); \
244 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
245 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
246 class_export_put(exp); \
250 struct obd_export *class_export_get(struct obd_export *exp);
251 void class_export_put(struct obd_export *exp);
252 struct obd_export *class_new_export(struct obd_device *obddev,
253 struct obd_uuid *cluuid);
254 void class_unlink_export(struct obd_export *exp);
256 struct obd_import *class_import_get(struct obd_import *);
257 void class_import_put(struct obd_import *);
258 struct obd_import *class_new_import(struct obd_device *obd);
259 void class_destroy_import(struct obd_import *exp);
261 struct obd_type *class_search_type(const char *name);
262 struct obd_type *class_get_type(const char *name);
263 void class_put_type(struct obd_type *type);
264 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
265 struct obd_uuid *cluuid);
266 int class_disconnect(struct obd_export *exp);
267 void class_fail_export(struct obd_export *exp);
268 int class_connected_export(struct obd_export *exp);
269 void class_disconnect_exports(struct obd_device *obddev);
270 int class_manual_cleanup(struct obd_device *obd);
271 void class_disconnect_stale_exports(struct obd_device *,
272 int (*test_export)(struct obd_export *));
273 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
275 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
276 (obd->obd_force ? OBD_OPT_FORCE : 0) |
277 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
281 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
283 LASSERT(exp->exp_obd);
284 return exp->exp_obd->u.obt.obt_lut;
287 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
289 LASSERT(obd->u.obt.obt_lut);
290 return &obd->u.obt.obt_lut->lut_lsd;
293 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
294 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
295 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
296 unsigned int ia_valid);
297 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
298 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
299 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
302 #define OBT(dev) (dev)->obd_type
303 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
304 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
305 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
307 /* Ensure obd_setup: used for cleanup which must be called
308 while obd is stopping */
309 #define OBD_CHECK_DEV(obd) \
312 CERROR("NULL device\n"); \
317 /* ensure obd_setup and !obd_stopping */
318 #define OBD_CHECK_DEV_ACTIVE(obd) \
320 OBD_CHECK_DEV(obd); \
321 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
322 CERROR("Device %d not setup\n", \
330 #define OBD_COUNTER_OFFSET(op) \
331 ((offsetof(struct obd_ops, o_ ## op) - \
332 offsetof(struct obd_ops, o_iocontrol)) \
333 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
335 #define OBD_COUNTER_INCREMENT(obdx, op) \
336 if ((obdx)->obd_stats != NULL) { \
337 unsigned int coffset; \
338 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
339 OBD_COUNTER_OFFSET(op); \
340 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
341 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
344 #define EXP_COUNTER_INCREMENT(export, op) \
345 if ((export)->exp_obd->obd_stats != NULL) { \
346 unsigned int coffset; \
347 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
348 OBD_COUNTER_OFFSET(op); \
349 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
350 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
351 if ((export)->exp_nid_stats != NULL && \
352 (export)->exp_nid_stats->nid_stats != NULL) \
353 lprocfs_counter_incr( \
354 (export)->exp_nid_stats->nid_stats, coffset);\
357 #define MD_COUNTER_OFFSET(op) \
358 ((offsetof(struct md_ops, m_ ## op) - \
359 offsetof(struct md_ops, m_getstatus)) \
360 / sizeof(((struct md_ops *)(0))->m_getstatus))
362 #define MD_COUNTER_INCREMENT(obdx, op) \
363 if ((obd)->md_stats != NULL) { \
364 unsigned int coffset; \
365 coffset = (unsigned int)((obdx)->md_cntr_base) + \
366 MD_COUNTER_OFFSET(op); \
367 LASSERT(coffset < (obdx)->md_stats->ls_num); \
368 lprocfs_counter_incr((obdx)->md_stats, coffset); \
371 #define EXP_MD_COUNTER_INCREMENT(export, op) \
372 if ((export)->exp_obd->obd_stats != NULL) { \
373 unsigned int coffset; \
374 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
375 MD_COUNTER_OFFSET(op); \
376 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
377 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
378 if ((export)->exp_md_stats != NULL) \
379 lprocfs_counter_incr( \
380 (export)->exp_md_stats, coffset); \
384 #define OBD_COUNTER_OFFSET(op)
385 #define OBD_COUNTER_INCREMENT(obd, op)
386 #define EXP_COUNTER_INCREMENT(exp, op)
387 #define MD_COUNTER_INCREMENT(obd, op)
388 #define EXP_MD_COUNTER_INCREMENT(exp, op)
391 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
393 /* Always add in ldlm_stats */
394 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
395 ,LPROCFS_STATS_FLAG_NOPERCPU);
396 if (tmp->nid_ldlm_stats == NULL)
399 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
401 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
402 tmp->nid_ldlm_stats);
405 #define OBD_CHECK_MD_OP(obd, op, err) \
407 if (!OBT(obd) || !MDP((obd), op)) { \
409 CERROR("md_" #op ": dev %s/%d no operation\n", \
410 obd->obd_name, obd->obd_minor); \
415 #define EXP_CHECK_MD_OP(exp, op) \
417 if ((exp) == NULL) { \
418 CERROR("obd_" #op ": NULL export\n"); \
421 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
422 CERROR("obd_" #op ": cleaned up obd\n"); \
423 RETURN(-EOPNOTSUPP); \
425 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
426 CERROR("obd_" #op ": dev %s/%d no operation\n", \
427 (exp)->exp_obd->obd_name, \
428 (exp)->exp_obd->obd_minor); \
429 RETURN(-EOPNOTSUPP); \
434 #define OBD_CHECK_DT_OP(obd, op, err) \
436 if (!OBT(obd) || !OBP((obd), op)) { \
438 CERROR("obd_" #op ": dev %d no operation\n", \
444 #define EXP_CHECK_DT_OP(exp, op) \
446 if ((exp) == NULL) { \
447 CERROR("obd_" #op ": NULL export\n"); \
450 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
451 CERROR("obd_" #op ": cleaned up obd\n"); \
452 RETURN(-EOPNOTSUPP); \
454 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
455 CERROR("obd_" #op ": dev %d no operation\n", \
456 (exp)->exp_obd->obd_minor); \
457 RETURN(-EOPNOTSUPP); \
461 #define CTXT_CHECK_OP(ctxt, op, err) \
463 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
465 CERROR("lop_" #op ": dev %d no operation\n", \
466 ctxt->loc_obd->obd_minor); \
471 static inline int class_devno_max(void)
473 return MAX_OBD_DEVICES;
476 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
477 void *key, __u32 *vallen, void *val,
478 struct lov_stripe_md *lsm)
483 EXP_CHECK_DT_OP(exp, get_info);
484 EXP_COUNTER_INCREMENT(exp, get_info);
486 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
490 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
491 void *key, obd_count vallen, void *val,
492 struct ptlrpc_request_set *set)
497 EXP_CHECK_DT_OP(exp, set_info_async);
498 EXP_COUNTER_INCREMENT(exp, set_info_async);
500 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
506 * obd-lu integration.
508 * Functionality is being moved into new lu_device-based layering, but some
509 * pieces of configuration process are still based on obd devices.
511 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
512 * subsume ->o_setup() methods of obd devices they replace. The same for
513 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
514 * result, obd_setup() and obd_process_config() branch and call one XOR
517 * Yet neither lu_device_type_operations::ldto_device_fini() nor
518 * lu_device_type_operations::ldto_device_free() fully implement the
519 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
520 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
523 #define DECLARE_LU_VARS(ldt, d) \
524 struct lu_device_type *ldt; \
527 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
530 DECLARE_LU_VARS(ldt, d);
533 ldt = obd->obd_type->typ_lu;
535 struct lu_context session_ctx;
537 lu_context_init(&session_ctx, LCT_SESSION);
538 session_ctx.lc_thread = NULL;
539 lu_context_enter(&session_ctx);
541 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
543 env.le_ses = &session_ctx;
544 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
553 lu_context_exit(&session_ctx);
554 lu_context_fini(&session_ctx);
557 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
558 OBD_COUNTER_INCREMENT(obd, setup);
559 rc = OBP(obd, setup)(obd, cfg);
564 static inline int obd_precleanup(struct obd_device *obd,
565 enum obd_cleanup_stage cleanup_stage)
568 DECLARE_LU_VARS(ldt, d);
572 ldt = obd->obd_type->typ_lu;
574 if (ldt != NULL && d != NULL) {
575 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
578 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
580 ldt->ldt_ops->ldto_device_fini(&env, d);
585 OBD_CHECK_DT_OP(obd, precleanup, 0);
586 OBD_COUNTER_INCREMENT(obd, precleanup);
588 rc = OBP(obd, precleanup)(obd, cleanup_stage);
592 static inline int obd_cleanup(struct obd_device *obd)
595 DECLARE_LU_VARS(ldt, d);
600 ldt = obd->obd_type->typ_lu;
602 if (ldt != NULL && d != NULL) {
605 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
607 ldt->ldt_ops->ldto_device_free(&env, d);
609 obd->obd_lu_dev = NULL;
612 OBD_CHECK_DT_OP(obd, cleanup, 0);
613 OBD_COUNTER_INCREMENT(obd, cleanup);
615 rc = OBP(obd, cleanup)(obd);
620 obd_process_config(struct obd_device *obd, int datalen, void *data)
623 DECLARE_LU_VARS(ldt, d);
628 obd->obd_process_conf = 1;
629 ldt = obd->obd_type->typ_lu;
631 if (ldt != NULL && d != NULL) {
634 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
636 rc = d->ld_ops->ldo_process_config(&env, d, data);
640 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
641 rc = OBP(obd, process_config)(obd, datalen, data);
643 OBD_COUNTER_INCREMENT(obd, process_config);
644 obd->obd_process_conf = 0;
649 /* Pack an in-memory MD struct for storage on disk.
650 * Returns +ve size of packed MD (0 for free), or -ve error.
652 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
653 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
654 * If @*disk_tgt == NULL, it will be allocated
656 static inline int obd_packmd(struct obd_export *exp,
657 struct lov_mds_md **disk_tgt,
658 struct lov_stripe_md *mem_src)
663 EXP_CHECK_DT_OP(exp, packmd);
664 EXP_COUNTER_INCREMENT(exp, packmd);
666 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
670 static inline int obd_size_diskmd(struct obd_export *exp,
671 struct lov_stripe_md *mem_src)
673 return obd_packmd(exp, NULL, mem_src);
676 /* helper functions */
677 static inline int obd_alloc_diskmd(struct obd_export *exp,
678 struct lov_mds_md **disk_tgt)
681 LASSERT(*disk_tgt == NULL);
682 return obd_packmd(exp, disk_tgt, NULL);
685 static inline int obd_free_diskmd(struct obd_export *exp,
686 struct lov_mds_md **disk_tgt)
690 return obd_packmd(exp, disk_tgt, NULL);
693 /* Unpack an MD struct from disk to in-memory format.
694 * Returns +ve size of unpacked MD (0 for free), or -ve error.
696 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
697 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
698 * If @*mem_tgt == NULL, it will be allocated
700 static inline int obd_unpackmd(struct obd_export *exp,
701 struct lov_stripe_md **mem_tgt,
702 struct lov_mds_md *disk_src,
708 EXP_CHECK_DT_OP(exp, unpackmd);
709 EXP_COUNTER_INCREMENT(exp, unpackmd);
711 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
715 /* helper functions */
716 static inline int obd_alloc_memmd(struct obd_export *exp,
717 struct lov_stripe_md **mem_tgt)
720 LASSERT(*mem_tgt == NULL);
721 return obd_unpackmd(exp, mem_tgt, NULL, 0);
724 static inline int obd_free_memmd(struct obd_export *exp,
725 struct lov_stripe_md **mem_tgt)
731 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
736 static inline int obd_precreate(struct obd_export *exp)
741 EXP_CHECK_DT_OP(exp, precreate);
742 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
744 rc = OBP(exp->exp_obd, precreate)(exp);
748 static inline int obd_create_async(struct obd_export *exp,
749 struct obd_info *oinfo,
750 struct lov_stripe_md **ea,
751 struct obd_trans_info *oti)
756 EXP_CHECK_DT_OP(exp, create_async);
757 EXP_COUNTER_INCREMENT(exp, create_async);
759 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
763 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
764 struct lov_stripe_md **ea,
765 struct obd_trans_info *oti)
770 EXP_CHECK_DT_OP(exp, create);
771 EXP_COUNTER_INCREMENT(exp, create);
773 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
777 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
778 struct lov_stripe_md *ea,
779 struct obd_trans_info *oti,
780 struct obd_export *md_exp, void *capa)
785 EXP_CHECK_DT_OP(exp, destroy);
786 EXP_COUNTER_INCREMENT(exp, destroy);
788 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
792 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
797 EXP_CHECK_DT_OP(exp, getattr);
798 EXP_COUNTER_INCREMENT(exp, getattr);
800 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
804 static inline int obd_getattr_async(struct obd_export *exp,
805 struct obd_info *oinfo,
806 struct ptlrpc_request_set *set)
811 EXP_CHECK_DT_OP(exp, getattr_async);
812 EXP_COUNTER_INCREMENT(exp, getattr_async);
814 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
818 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
819 struct obd_trans_info *oti)
824 EXP_CHECK_DT_OP(exp, setattr);
825 EXP_COUNTER_INCREMENT(exp, setattr);
827 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
831 /* This performs all the requests set init/wait/destroy actions. */
832 static inline int obd_setattr_rqset(struct obd_export *exp,
833 struct obd_info *oinfo,
834 struct obd_trans_info *oti)
836 struct ptlrpc_request_set *set = NULL;
840 EXP_CHECK_DT_OP(exp, setattr_async);
841 EXP_COUNTER_INCREMENT(exp, setattr_async);
843 set = ptlrpc_prep_set();
847 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
849 rc = ptlrpc_set_wait(set);
850 ptlrpc_set_destroy(set);
854 /* This adds all the requests into @set if @set != NULL, otherwise
855 all requests are sent asynchronously without waiting for response. */
856 static inline int obd_setattr_async(struct obd_export *exp,
857 struct obd_info *oinfo,
858 struct obd_trans_info *oti,
859 struct ptlrpc_request_set *set)
864 EXP_CHECK_DT_OP(exp, setattr_async);
865 EXP_COUNTER_INCREMENT(exp, setattr_async);
867 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
871 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
874 struct obd_device *obd = imp->imp_obd;
878 OBD_CHECK_DEV_ACTIVE(obd);
879 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
880 OBD_COUNTER_INCREMENT(obd, add_conn);
882 rc = OBP(obd, add_conn)(imp, uuid, priority);
886 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
888 struct obd_device *obd = imp->imp_obd;
892 OBD_CHECK_DEV_ACTIVE(obd);
893 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
894 OBD_COUNTER_INCREMENT(obd, del_conn);
896 rc = OBP(obd, del_conn)(imp, uuid);
900 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
902 struct obd_uuid *uuid;
905 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
906 EXP_COUNTER_INCREMENT(exp, get_uuid);
908 uuid = OBP(exp->exp_obd, get_uuid)(exp);
912 /** Create a new /a exp on device /a obd for the uuid /a cluuid
913 * @param exp New export handle
914 * @param d Connect data, supported flags are set, flags also understood
915 * by obd are returned.
917 static inline int obd_connect(const struct lu_env *env,
918 struct obd_export **exp,struct obd_device *obd,
919 struct obd_uuid *cluuid,
920 struct obd_connect_data *d,
924 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
928 OBD_CHECK_DEV_ACTIVE(obd);
929 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
930 OBD_COUNTER_INCREMENT(obd, connect);
932 rc = OBP(obd, connect)(env, exp, obd, cluuid, d, localdata);
933 /* check that only subset is granted */
934 LASSERT(ergo(d != NULL,
935 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
939 static inline int obd_reconnect(const struct lu_env *env,
940 struct obd_export *exp,
941 struct obd_device *obd,
942 struct obd_uuid *cluuid,
943 struct obd_connect_data *d,
947 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
952 OBD_CHECK_DEV_ACTIVE(obd);
953 OBD_CHECK_DT_OP(obd, reconnect, 0);
954 OBD_COUNTER_INCREMENT(obd, reconnect);
956 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
957 /* check that only subset is granted */
958 LASSERT(ergo(d != NULL,
959 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
963 static inline int obd_disconnect(struct obd_export *exp)
968 EXP_CHECK_DT_OP(exp, disconnect);
969 EXP_COUNTER_INCREMENT(exp, disconnect);
971 rc = OBP(exp->exp_obd, disconnect)(exp);
975 static inline int obd_fid_init(struct obd_export *exp)
980 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
981 EXP_COUNTER_INCREMENT(exp, fid_init);
983 rc = OBP(exp->exp_obd, fid_init)(exp);
987 static inline int obd_fid_fini(struct obd_export *exp)
992 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
993 EXP_COUNTER_INCREMENT(exp, fid_fini);
995 rc = OBP(exp->exp_obd, fid_fini)(exp);
999 static inline int obd_fid_alloc(struct obd_export *exp,
1001 struct md_op_data *op_data)
1006 EXP_CHECK_DT_OP(exp, fid_alloc);
1007 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1009 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
1013 static inline int obd_fid_delete(struct obd_export *exp,
1014 const struct lu_fid *fid)
1019 EXP_CHECK_DT_OP(exp, fid_delete);
1020 EXP_COUNTER_INCREMENT(exp, fid_delete);
1022 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
1026 static inline int obd_ping(struct obd_export *exp)
1031 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1032 EXP_COUNTER_INCREMENT(exp, ping);
1034 rc = OBP(exp->exp_obd, ping)(exp);
1038 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1043 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1044 OBD_COUNTER_INCREMENT(obd, pool_new);
1046 rc = OBP(obd, pool_new)(obd, poolname);
1050 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1055 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1056 OBD_COUNTER_INCREMENT(obd, pool_del);
1058 rc = OBP(obd, pool_del)(obd, poolname);
1062 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1067 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1068 OBD_COUNTER_INCREMENT(obd, pool_add);
1070 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1074 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1079 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1080 OBD_COUNTER_INCREMENT(obd, pool_rem);
1082 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1086 static inline void obd_getref(struct obd_device *obd)
1089 if (OBT(obd) && OBP(obd, getref)) {
1090 OBD_COUNTER_INCREMENT(obd, getref);
1091 OBP(obd, getref)(obd);
1096 static inline void obd_putref(struct obd_device *obd)
1099 if (OBT(obd) && OBP(obd, putref)) {
1100 OBD_COUNTER_INCREMENT(obd, putref);
1101 OBP(obd, putref)(obd);
1106 static inline int obd_init_export(struct obd_export *exp)
1111 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1112 OBP((exp)->exp_obd, init_export))
1113 rc = OBP(exp->exp_obd, init_export)(exp);
1117 static inline int obd_destroy_export(struct obd_export *exp)
1120 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1121 OBP((exp)->exp_obd, destroy_export))
1122 OBP(exp->exp_obd, destroy_export)(exp);
1126 static inline int obd_extent_calc(struct obd_export *exp,
1127 struct lov_stripe_md *md,
1128 int cmd, obd_off *offset)
1132 EXP_CHECK_DT_OP(exp, extent_calc);
1133 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1137 static inline struct dentry *
1138 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1140 LASSERT(exp->exp_obd);
1142 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1147 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1149 LASSERT(exp->exp_obd);
1150 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1152 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1153 dentry, exp->exp_obd);
1158 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1159 * If the cache is older than @max_age we will get a new value from the
1160 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1161 static inline int obd_statfs_async(struct obd_device *obd,
1162 struct obd_info *oinfo,
1164 struct ptlrpc_request_set *rqset)
1172 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1173 OBD_COUNTER_INCREMENT(obd, statfs);
1175 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1176 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1177 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1178 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1180 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1181 " objects "LPU64"/"LPU64"\n",
1182 obd->obd_name, &obd->obd_osfs,
1183 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1184 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1185 cfs_spin_lock(&obd->obd_osfs_lock);
1186 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1187 cfs_spin_unlock(&obd->obd_osfs_lock);
1188 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1189 if (oinfo->oi_cb_up)
1190 oinfo->oi_cb_up(oinfo, 0);
1195 static inline int obd_statfs_rqset(struct obd_device *obd,
1196 struct obd_statfs *osfs, __u64 max_age,
1199 struct ptlrpc_request_set *set = NULL;
1200 struct obd_info oinfo = { { { 0 } } };
1204 set = ptlrpc_prep_set();
1208 oinfo.oi_osfs = osfs;
1209 oinfo.oi_flags = flags;
1210 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1212 rc = ptlrpc_set_wait(set);
1213 ptlrpc_set_destroy(set);
1217 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1218 * If the cache is older than @max_age we will get a new value from the
1219 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1220 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1221 __u64 max_age, __u32 flags)
1229 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1230 OBD_COUNTER_INCREMENT(obd, statfs);
1232 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1233 obd->obd_osfs_age, max_age);
1234 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1235 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1237 cfs_spin_lock(&obd->obd_osfs_lock);
1238 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1239 obd->obd_osfs_age = cfs_time_current_64();
1240 cfs_spin_unlock(&obd->obd_osfs_lock);
1243 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1244 " objects "LPU64"/"LPU64"\n",
1245 obd->obd_name, &obd->obd_osfs,
1246 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1247 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1248 cfs_spin_lock(&obd->obd_osfs_lock);
1249 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1250 cfs_spin_unlock(&obd->obd_osfs_lock);
1255 static inline int obd_sync_rqset(struct obd_export *exp, struct obd_info *oinfo,
1256 obd_size start, obd_size end)
1258 struct ptlrpc_request_set *set = NULL;
1262 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1263 EXP_COUNTER_INCREMENT(exp, sync);
1265 set = ptlrpc_prep_set();
1269 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1271 rc = ptlrpc_set_wait(set);
1272 ptlrpc_set_destroy(set);
1276 static inline int obd_sync(struct obd_export *exp, struct obd_info *oinfo,
1277 obd_size start, obd_size end,
1278 struct ptlrpc_request_set *set)
1283 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1284 EXP_COUNTER_INCREMENT(exp, sync);
1286 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1290 static inline int obd_punch_rqset(struct obd_export *exp,
1291 struct obd_info *oinfo,
1292 struct obd_trans_info *oti)
1294 struct ptlrpc_request_set *set = NULL;
1298 EXP_CHECK_DT_OP(exp, punch);
1299 EXP_COUNTER_INCREMENT(exp, punch);
1301 set = ptlrpc_prep_set();
1305 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1307 rc = ptlrpc_set_wait(set);
1308 ptlrpc_set_destroy(set);
1312 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1313 struct obd_trans_info *oti,
1314 struct ptlrpc_request_set *rqset)
1319 EXP_CHECK_DT_OP(exp, punch);
1320 EXP_COUNTER_INCREMENT(exp, punch);
1322 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1326 static inline int obd_brw(int cmd, struct obd_export *exp,
1327 struct obd_info *oinfo, obd_count oa_bufs,
1328 struct brw_page *pg, struct obd_trans_info *oti)
1333 EXP_CHECK_DT_OP(exp, brw);
1334 EXP_COUNTER_INCREMENT(exp, brw);
1336 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1337 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1338 "or OBD_BRW_CHECK\n");
1342 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1346 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1347 int objcount, struct obd_ioobj *obj,
1348 struct niobuf_remote *remote, int *pages,
1349 struct niobuf_local *local,
1350 struct obd_trans_info *oti,
1351 struct lustre_capa *capa)
1356 EXP_CHECK_DT_OP(exp, preprw);
1357 EXP_COUNTER_INCREMENT(exp, preprw);
1359 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1360 pages, local, oti, capa);
1364 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1365 int objcount, struct obd_ioobj *obj,
1366 struct niobuf_remote *rnb, int pages,
1367 struct niobuf_local *local,
1368 struct obd_trans_info *oti, int rc)
1372 EXP_CHECK_DT_OP(exp, commitrw);
1373 EXP_COUNTER_INCREMENT(exp, commitrw);
1375 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1376 rnb, pages, local, oti, rc);
1380 static inline int obd_merge_lvb(struct obd_export *exp,
1381 struct lov_stripe_md *lsm,
1382 struct ost_lvb *lvb, int kms_only)
1387 EXP_CHECK_DT_OP(exp, merge_lvb);
1388 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1390 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1394 static inline int obd_adjust_kms(struct obd_export *exp,
1395 struct lov_stripe_md *lsm, obd_off size,
1401 EXP_CHECK_DT_OP(exp, adjust_kms);
1402 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1404 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1408 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1409 int len, void *karg, void *uarg)
1414 EXP_CHECK_DT_OP(exp, iocontrol);
1415 EXP_COUNTER_INCREMENT(exp, iocontrol);
1417 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1421 static inline int obd_enqueue_rqset(struct obd_export *exp,
1422 struct obd_info *oinfo,
1423 struct ldlm_enqueue_info *einfo)
1425 struct ptlrpc_request_set *set = NULL;
1429 EXP_CHECK_DT_OP(exp, enqueue);
1430 EXP_COUNTER_INCREMENT(exp, enqueue);
1432 set = ptlrpc_prep_set();
1436 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1438 rc = ptlrpc_set_wait(set);
1439 ptlrpc_set_destroy(set);
1443 static inline int obd_enqueue(struct obd_export *exp,
1444 struct obd_info *oinfo,
1445 struct ldlm_enqueue_info *einfo,
1446 struct ptlrpc_request_set *set)
1451 EXP_CHECK_DT_OP(exp, enqueue);
1452 EXP_COUNTER_INCREMENT(exp, enqueue);
1454 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1458 static inline int obd_change_cbdata(struct obd_export *exp,
1459 struct lov_stripe_md *lsm,
1460 ldlm_iterator_t it, void *data)
1465 EXP_CHECK_DT_OP(exp, change_cbdata);
1466 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1468 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1472 static inline int obd_find_cbdata(struct obd_export *exp,
1473 struct lov_stripe_md *lsm,
1474 ldlm_iterator_t it, void *data)
1479 EXP_CHECK_DT_OP(exp, find_cbdata);
1480 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1482 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1486 static inline int obd_cancel(struct obd_export *exp,
1487 struct lov_stripe_md *ea, __u32 mode,
1488 struct lustre_handle *lockh)
1493 EXP_CHECK_DT_OP(exp, cancel);
1494 EXP_COUNTER_INCREMENT(exp, cancel);
1496 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1500 static inline int obd_cancel_unused(struct obd_export *exp,
1501 struct lov_stripe_md *ea,
1502 ldlm_cancel_flags_t flags,
1508 EXP_CHECK_DT_OP(exp, cancel_unused);
1509 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1511 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1515 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1516 struct obd_capa *oc, struct obd_client_handle *handle,
1522 EXP_CHECK_DT_OP(exp, pin);
1523 EXP_COUNTER_INCREMENT(exp, pin);
1525 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1529 static inline int obd_unpin(struct obd_export *exp,
1530 struct obd_client_handle *handle, int flag)
1535 EXP_CHECK_DT_OP(exp, unpin);
1536 EXP_COUNTER_INCREMENT(exp, unpin);
1538 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1543 static inline void obd_import_event(struct obd_device *obd,
1544 struct obd_import *imp,
1545 enum obd_import_event event)
1549 CERROR("NULL device\n");
1553 if (obd->obd_set_up && OBP(obd, import_event)) {
1554 OBD_COUNTER_INCREMENT(obd, import_event);
1555 OBP(obd, import_event)(obd, imp, event);
1560 static inline int obd_llog_connect(struct obd_export *exp,
1561 struct llogd_conn_body *body)
1566 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1567 EXP_COUNTER_INCREMENT(exp, llog_connect);
1569 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1574 static inline int obd_notify(struct obd_device *obd,
1575 struct obd_device *watched,
1576 enum obd_notify_event ev,
1583 /* the check for async_recov is a complete hack - I'm hereby
1584 overloading the meaning to also mean "this was called from
1585 mds_postsetup". I know that my mds is able to handle notifies
1586 by this point, and it needs to get them to execute mds_postrecov. */
1587 if (!obd->obd_set_up && !obd->obd_async_recov) {
1588 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1592 if (!OBP(obd, notify)) {
1593 CERROR("obd %s has no notify handler\n", obd->obd_name);
1597 OBD_COUNTER_INCREMENT(obd, notify);
1598 rc = OBP(obd, notify)(obd, watched, ev, data);
1602 static inline int obd_notify_observer(struct obd_device *observer,
1603 struct obd_device *observed,
1604 enum obd_notify_event ev,
1610 struct obd_notify_upcall *onu;
1612 if (observer->obd_observer)
1613 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1617 * Also, call non-obd listener, if any
1619 onu = &observer->obd_upcall;
1620 if (onu->onu_upcall != NULL)
1621 rc2 = onu->onu_upcall(observer, observed, ev,
1622 onu->onu_owner, NULL);
1626 return rc1 ? rc1 : rc2;
1629 static inline int obd_quotacheck(struct obd_export *exp,
1630 struct obd_quotactl *oqctl)
1635 EXP_CHECK_DT_OP(exp, quotacheck);
1636 EXP_COUNTER_INCREMENT(exp, quotacheck);
1638 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1642 static inline int obd_quotactl(struct obd_export *exp,
1643 struct obd_quotactl *oqctl)
1648 EXP_CHECK_DT_OP(exp, quotactl);
1649 EXP_COUNTER_INCREMENT(exp, quotactl);
1651 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1655 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1656 struct quota_adjust_qunit *oqaq,
1657 struct lustre_quota_ctxt *qctxt,
1658 struct ptlrpc_request_set *set)
1660 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1661 struct timeval work_start;
1662 struct timeval work_end;
1668 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1670 cfs_gettimeofday(&work_start);
1672 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1673 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1675 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt, set);
1677 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1679 cfs_gettimeofday(&work_end);
1680 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1681 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1688 static inline int obd_health_check(struct obd_device *obd)
1690 /* returns: 0 on healthy
1691 * >0 on unhealthy + reason code/flag
1692 * however the only suppored reason == 1 right now
1693 * We'll need to define some better reasons
1694 * or flags in the future.
1700 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1701 if (obd == NULL || !OBT(obd)) {
1702 CERROR("cleaned up obd\n");
1703 RETURN(-EOPNOTSUPP);
1705 if (!obd->obd_set_up || obd->obd_stopping)
1707 if (!OBP(obd, health_check))
1710 rc = OBP(obd, health_check)(obd);
1714 static inline int obd_register_observer(struct obd_device *obd,
1715 struct obd_device *observer)
1719 cfs_down_write(&obd->obd_observer_link_sem);
1720 if (obd->obd_observer && observer) {
1721 cfs_up_write(&obd->obd_observer_link_sem);
1724 obd->obd_observer = observer;
1725 cfs_up_write(&obd->obd_observer_link_sem);
1729 static inline int obd_pin_observer(struct obd_device *obd,
1730 struct obd_device **observer)
1733 cfs_down_read(&obd->obd_observer_link_sem);
1734 if (!obd->obd_observer) {
1736 cfs_up_read(&obd->obd_observer_link_sem);
1739 *observer = obd->obd_observer;
1743 static inline int obd_unpin_observer(struct obd_device *obd)
1746 cfs_up_read(&obd->obd_observer_link_sem);
1751 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1752 obd_page_removal_cb_t cb,
1753 obd_pin_extent_cb pin_cb)
1758 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1759 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1761 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1765 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1766 obd_page_removal_cb_t cb)
1771 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1772 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1774 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1778 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1779 obd_lock_cancel_cb cb)
1784 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1785 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1787 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1791 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1792 obd_lock_cancel_cb cb)
1797 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1798 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1800 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1805 /* metadata helpers */
1806 static inline int md_getstatus(struct obd_export *exp,
1807 struct lu_fid *fid, struct obd_capa **pc)
1812 EXP_CHECK_MD_OP(exp, getstatus);
1813 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1814 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1818 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1819 struct ptlrpc_request **request)
1823 EXP_CHECK_MD_OP(exp, getattr);
1824 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1825 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1829 static inline int md_change_cbdata(struct obd_export *exp,
1830 const struct lu_fid *fid,
1831 ldlm_iterator_t it, void *data)
1835 EXP_CHECK_MD_OP(exp, change_cbdata);
1836 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1837 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1841 static inline int md_find_cbdata(struct obd_export *exp,
1842 const struct lu_fid *fid,
1843 ldlm_iterator_t it, void *data)
1847 EXP_CHECK_MD_OP(exp, find_cbdata);
1848 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1849 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1853 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1854 struct md_open_data *mod,
1855 struct ptlrpc_request **request)
1859 EXP_CHECK_MD_OP(exp, close);
1860 EXP_MD_COUNTER_INCREMENT(exp, close);
1861 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1865 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1866 const void *data, int datalen, int mode, __u32 uid,
1867 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1868 struct ptlrpc_request **request)
1872 EXP_CHECK_MD_OP(exp, create);
1873 EXP_MD_COUNTER_INCREMENT(exp, create);
1874 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1875 uid, gid, cap_effective, rdev, request);
1879 static inline int md_done_writing(struct obd_export *exp,
1880 struct md_op_data *op_data,
1881 struct md_open_data *mod)
1885 EXP_CHECK_MD_OP(exp, done_writing);
1886 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1887 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1891 static inline int md_enqueue(struct obd_export *exp,
1892 struct ldlm_enqueue_info *einfo,
1893 struct lookup_intent *it,
1894 struct md_op_data *op_data,
1895 struct lustre_handle *lockh,
1896 void *lmm, int lmmsize,
1897 struct ptlrpc_request **req,
1898 int extra_lock_flags)
1902 EXP_CHECK_MD_OP(exp, enqueue);
1903 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1904 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1905 lmm, lmmsize, req, extra_lock_flags);
1909 static inline int md_getattr_name(struct obd_export *exp,
1910 struct md_op_data *op_data,
1911 struct ptlrpc_request **request)
1915 EXP_CHECK_MD_OP(exp, getattr_name);
1916 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1917 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1921 static inline int md_intent_lock(struct obd_export *exp,
1922 struct md_op_data *op_data, void *lmm,
1923 int lmmsize, struct lookup_intent *it,
1924 int flags, struct ptlrpc_request **reqp,
1925 ldlm_blocking_callback cb_blocking,
1926 int extra_lock_flags)
1930 EXP_CHECK_MD_OP(exp, intent_lock);
1931 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1932 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1933 it, flags, reqp, cb_blocking,
1938 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1939 struct ptlrpc_request **request)
1943 EXP_CHECK_MD_OP(exp, link);
1944 EXP_MD_COUNTER_INCREMENT(exp, link);
1945 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1949 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1950 const char *old, int oldlen, const char *new,
1951 int newlen, struct ptlrpc_request **request)
1955 EXP_CHECK_MD_OP(exp, rename);
1956 EXP_MD_COUNTER_INCREMENT(exp, rename);
1957 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1962 static inline int md_is_subdir(struct obd_export *exp,
1963 const struct lu_fid *pfid,
1964 const struct lu_fid *cfid,
1965 struct ptlrpc_request **request)
1969 EXP_CHECK_MD_OP(exp, is_subdir);
1970 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1971 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1975 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1976 void *ea, int ealen, void *ea2, int ea2len,
1977 struct ptlrpc_request **request,
1978 struct md_open_data **mod)
1982 EXP_CHECK_MD_OP(exp, setattr);
1983 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1984 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1985 ea2, ea2len, request, mod);
1989 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1990 struct obd_capa *oc, struct ptlrpc_request **request)
1994 EXP_CHECK_MD_OP(exp, sync);
1995 EXP_MD_COUNTER_INCREMENT(exp, sync);
1996 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
2000 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
2001 struct obd_capa *oc, __u64 offset,
2003 struct ptlrpc_request **request)
2007 EXP_CHECK_MD_OP(exp, readpage);
2008 EXP_MD_COUNTER_INCREMENT(exp, readpage);
2009 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
2013 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
2014 struct ptlrpc_request **request)
2018 EXP_CHECK_MD_OP(exp, unlink);
2019 EXP_MD_COUNTER_INCREMENT(exp, unlink);
2020 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
2024 static inline int md_get_lustre_md(struct obd_export *exp,
2025 struct ptlrpc_request *req,
2026 struct obd_export *dt_exp,
2027 struct obd_export *md_exp,
2028 struct lustre_md *md)
2031 EXP_CHECK_MD_OP(exp, get_lustre_md);
2032 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
2033 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
2036 static inline int md_free_lustre_md(struct obd_export *exp,
2037 struct lustre_md *md)
2040 EXP_CHECK_MD_OP(exp, free_lustre_md);
2041 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
2042 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
2045 static inline int md_setxattr(struct obd_export *exp,
2046 const struct lu_fid *fid, struct obd_capa *oc,
2047 obd_valid valid, const char *name,
2048 const char *input, int input_size,
2049 int output_size, int flags, __u32 suppgid,
2050 struct ptlrpc_request **request)
2053 EXP_CHECK_MD_OP(exp, setxattr);
2054 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
2055 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
2056 input_size, output_size, flags,
2060 static inline int md_getxattr(struct obd_export *exp,
2061 const struct lu_fid *fid, struct obd_capa *oc,
2062 obd_valid valid, const char *name,
2063 const char *input, int input_size,
2064 int output_size, int flags,
2065 struct ptlrpc_request **request)
2068 EXP_CHECK_MD_OP(exp, getxattr);
2069 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
2070 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
2071 input_size, output_size, flags,
2075 static inline int md_set_open_replay_data(struct obd_export *exp,
2076 struct obd_client_handle *och,
2077 struct ptlrpc_request *open_req)
2080 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2081 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2082 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2085 static inline int md_clear_open_replay_data(struct obd_export *exp,
2086 struct obd_client_handle *och)
2089 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2090 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2091 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2094 static inline int md_set_lock_data(struct obd_export *exp,
2095 __u64 *lockh, void *data, __u32 *bits)
2098 EXP_CHECK_MD_OP(exp, set_lock_data);
2099 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2100 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
2103 static inline int md_cancel_unused(struct obd_export *exp,
2104 const struct lu_fid *fid,
2105 ldlm_policy_data_t *policy,
2107 ldlm_cancel_flags_t flags,
2113 EXP_CHECK_MD_OP(exp, cancel_unused);
2114 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2116 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2121 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2122 const struct lu_fid *fid,
2124 ldlm_policy_data_t *policy,
2126 struct lustre_handle *lockh)
2129 EXP_CHECK_MD_OP(exp, lock_match);
2130 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2131 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2132 policy, mode, lockh));
2135 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2136 int def_asize, int cookiesize)
2139 EXP_CHECK_MD_OP(exp, init_ea_size);
2140 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2141 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2145 static inline int md_get_remote_perm(struct obd_export *exp,
2146 const struct lu_fid *fid,
2147 struct obd_capa *oc, __u32 suppgid,
2148 struct ptlrpc_request **request)
2151 EXP_CHECK_MD_OP(exp, get_remote_perm);
2152 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2153 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2157 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2162 EXP_CHECK_MD_OP(exp, renew_capa);
2163 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2164 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2168 static inline int md_unpack_capa(struct obd_export *exp,
2169 struct ptlrpc_request *req,
2170 const struct req_msg_field *field,
2171 struct obd_capa **oc)
2175 EXP_CHECK_MD_OP(exp, unpack_capa);
2176 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2177 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2181 static inline int md_intent_getattr_async(struct obd_export *exp,
2182 struct md_enqueue_info *minfo,
2183 struct ldlm_enqueue_info *einfo)
2187 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2188 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2189 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2193 static inline int md_revalidate_lock(struct obd_export *exp,
2194 struct lookup_intent *it,
2199 EXP_CHECK_MD_OP(exp, revalidate_lock);
2200 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2201 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2206 /* OBD Metadata Support */
2208 extern int obd_init_caches(void);
2209 extern void obd_cleanup_caches(void);
2211 /* support routines */
2212 extern cfs_mem_cache_t *obdo_cachep;
2214 #define OBDO_ALLOC(ptr) \
2216 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, CFS_ALLOC_IO); \
2219 #define OBDO_FREE(ptr) \
2221 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2225 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2227 /* something here */
2230 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2232 /* something here */
2235 /* I'm as embarrassed about this as you are.
2237 * <shaver> // XXX do not look into _superhack with remaining eye
2238 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2239 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2242 extern void obd_sysctl_init (void);
2243 extern void obd_sysctl_clean (void);
2246 typedef __u8 class_uuid_t[16];
2247 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2250 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2251 int class_add_uuid(const char *uuid, __u64 nid);
2252 int class_del_uuid (const char *uuid);
2253 void class_init_uuidlist(void);
2254 void class_exit_uuidlist(void);
2257 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2258 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2261 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
2263 #endif /* __LINUX_OBD_CLASS_H */