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);
83 allocate one minor number
85 int obd_minor_alloc(void);
87 release allocated minor
89 void obd_minor_release(long minor);
91 return 1 if minor is point to allocated device,
94 int obd_minor_valid(long minor);
96 int obd_hashes_init(void);
97 void obd_hashes_fini(void);
99 struct obd_device *class_newdev(const char *type_name, const char *name,
101 void class_release_dev(struct obd_device *obd);
103 int class_name2dev(const char *name);
104 struct obd_device *class_name2obd(const char *name);
105 int class_uuid2dev(struct obd_uuid *uuid);
106 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
108 void class_obd_list(void);
109 void obd_devlist_first(struct obd_device **pos);
110 void obd_devlist_next(struct obd_device **pos);
111 void obd_devlist_last(struct obd_device *pos);
112 const char *obd_dev_status(struct obd_device *obd);
114 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
115 const char * typ_name,
116 struct obd_uuid *grp_uuid);
117 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
118 struct obd_device **prev);
119 struct obd_device * class_num2obd(__u32 num);
122 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
124 char *obd_export_nid2str(struct obd_export *exp);
126 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
127 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
129 int obd_zombie_impexp_init(void);
130 void obd_zombie_impexp_stop(void);
131 void obd_zombie_impexp_cull(void);
132 void obd_zombie_barrier(void);
133 void obd_exports_barrier(struct obd_device *obd);
134 int kuc_len(int payload_len);
135 struct kuc_hdr * kuc_ptr(void *p);
136 int kuc_ispayload(void *p);
137 void *kuc_alloc(int payload_len, int transport, int type);
138 void kuc_free(void *p, int payload_len);
141 int class_process_config(struct lustre_cfg *lcfg);
142 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
143 struct lustre_cfg *lcfg, void *data);
144 int class_attach(struct lustre_cfg *lcfg);
145 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
146 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
147 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
148 struct obd_device *class_incref(struct obd_device *obd,
149 const char *scope, const void *source);
150 void class_decref(struct obd_device *obd,
151 const char *scope, const void *source);
152 void dump_exports(struct obd_device *obd, int locks);
156 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
158 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
160 memset(lvars, 0, sizeof(*lvars));
164 #define CFG_F_START 0x01 /* Set when we start updating from a log */
165 #define CFG_F_MARKER 0x02 /* We are within a maker */
166 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
167 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
168 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
170 /* Passed as data param to class_config_parse_llog */
171 struct config_llog_instance {
174 struct super_block *cfg_sb;
175 struct obd_uuid cfg_uuid;
176 int cfg_last_idx; /* for partial llog processing */
179 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
180 struct config_llog_instance *cfg);
181 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
182 struct config_llog_instance *cfg);
184 /* list of active configuration logs */
185 struct config_llog_data {
187 struct ldlm_res_id cld_resid;
188 struct config_llog_instance cld_cfg;
189 cfs_list_t cld_list_chain;
190 cfs_atomic_t cld_refcount;
191 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
192 struct obd_export *cld_mgcexp;
193 cfs_mutex_t cld_lock;
194 unsigned int cld_stopping:1, /* we were told to stop
196 cld_lostlock:1, /* lock not requeued */
200 struct lustre_profile {
207 struct lustre_profile *class_get_profile(const char * prof);
208 void class_del_profile(const char *prof);
209 void class_del_profiles(void);
211 #if LUSTRE_TRACKS_LOCK_EXP_REFS
213 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
214 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
215 extern void (*class_export_dump_hook)(struct obd_export *);
219 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
220 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
224 #define class_export_rpc_get(exp) \
226 cfs_atomic_inc(&(exp)->exp_rpc_count); \
227 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
228 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
229 class_export_get(exp); \
232 #define class_export_rpc_put(exp) \
234 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
235 cfs_atomic_dec(&(exp)->exp_rpc_count); \
236 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
237 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
238 class_export_put(exp); \
241 #define class_export_lock_get(exp, lock) \
243 cfs_atomic_inc(&(exp)->exp_locks_count); \
244 __class_export_add_lock_ref(exp, lock); \
245 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
246 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
247 class_export_get(exp); \
250 #define class_export_lock_put(exp, lock) \
252 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
253 cfs_atomic_dec(&(exp)->exp_locks_count); \
254 __class_export_del_lock_ref(exp, lock); \
255 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
256 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
257 class_export_put(exp); \
260 #define class_export_cb_get(exp) \
262 cfs_atomic_inc(&(exp)->exp_cb_count); \
263 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
264 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
265 class_export_get(exp); \
268 #define class_export_cb_put(exp) \
270 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
271 cfs_atomic_dec(&(exp)->exp_cb_count); \
272 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
273 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
274 class_export_put(exp); \
278 struct obd_export *class_export_get(struct obd_export *exp);
279 void class_export_put(struct obd_export *exp);
280 struct obd_export *class_new_export(struct obd_device *obddev,
281 struct obd_uuid *cluuid);
282 void class_unlink_export(struct obd_export *exp);
284 struct obd_import *class_import_get(struct obd_import *);
285 void class_import_put(struct obd_import *);
286 struct obd_import *class_new_import(struct obd_device *obd);
287 void class_destroy_import(struct obd_import *exp);
289 struct obd_type *class_search_type(const char *name);
290 struct obd_type *class_get_type(const char *name);
291 void class_put_type(struct obd_type *type);
292 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
293 struct obd_uuid *cluuid);
294 int class_disconnect(struct obd_export *exp);
295 void class_fail_export(struct obd_export *exp);
296 int class_connected_export(struct obd_export *exp);
297 void class_disconnect_exports(struct obd_device *obddev);
298 int class_manual_cleanup(struct obd_device *obd);
299 void class_disconnect_stale_exports(struct obd_device *,
300 int (*test_export)(struct obd_export *));
301 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
303 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
304 (obd->obd_force ? OBD_OPT_FORCE : 0) |
305 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
309 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
311 LASSERT(exp->exp_obd);
312 return exp->exp_obd->u.obt.obt_lut;
315 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
317 LASSERT(obd->u.obt.obt_lut);
318 return &obd->u.obt.obt_lut->lut_lsd;
321 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
322 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
323 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
324 unsigned int ia_valid);
325 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
326 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
327 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
330 #define OBT(dev) (dev)->obd_type
331 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
332 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
333 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
335 /* Ensure obd_setup: used for cleanup which must be called
336 while obd is stopping */
337 #define OBD_CHECK_DEV(obd) \
340 CERROR("NULL device\n"); \
345 /* ensure obd_setup and !obd_stopping */
346 #define OBD_CHECK_DEV_ACTIVE(obd) \
348 OBD_CHECK_DEV(obd); \
349 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
350 CERROR("Device %d not setup\n", \
358 #define OBD_COUNTER_OFFSET(op) \
359 ((offsetof(struct obd_ops, o_ ## op) - \
360 offsetof(struct obd_ops, o_iocontrol)) \
361 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
363 #define OBD_COUNTER_INCREMENT(obdx, op) \
364 if ((obdx)->obd_stats != NULL) { \
365 unsigned int coffset; \
366 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
367 OBD_COUNTER_OFFSET(op); \
368 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
369 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
372 #define EXP_COUNTER_INCREMENT(export, op) \
373 if ((export)->exp_obd->obd_stats != NULL) { \
374 unsigned int coffset; \
375 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
376 OBD_COUNTER_OFFSET(op); \
377 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
378 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
379 if ((export)->exp_nid_stats != NULL && \
380 (export)->exp_nid_stats->nid_stats != NULL) \
381 lprocfs_counter_incr( \
382 (export)->exp_nid_stats->nid_stats, coffset);\
385 #define MD_COUNTER_OFFSET(op) \
386 ((offsetof(struct md_ops, m_ ## op) - \
387 offsetof(struct md_ops, m_getstatus)) \
388 / sizeof(((struct md_ops *)(0))->m_getstatus))
390 #define MD_COUNTER_INCREMENT(obdx, op) \
391 if ((obd)->md_stats != NULL) { \
392 unsigned int coffset; \
393 coffset = (unsigned int)((obdx)->md_cntr_base) + \
394 MD_COUNTER_OFFSET(op); \
395 LASSERT(coffset < (obdx)->md_stats->ls_num); \
396 lprocfs_counter_incr((obdx)->md_stats, coffset); \
399 #define EXP_MD_COUNTER_INCREMENT(export, op) \
400 if ((export)->exp_obd->obd_stats != NULL) { \
401 unsigned int coffset; \
402 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
403 MD_COUNTER_OFFSET(op); \
404 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
405 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
406 if ((export)->exp_md_stats != NULL) \
407 lprocfs_counter_incr( \
408 (export)->exp_md_stats, coffset); \
412 #define OBD_COUNTER_OFFSET(op)
413 #define OBD_COUNTER_INCREMENT(obd, op)
414 #define EXP_COUNTER_INCREMENT(exp, op)
415 #define MD_COUNTER_INCREMENT(obd, op)
416 #define EXP_MD_COUNTER_INCREMENT(exp, op)
419 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
421 /* Always add in ldlm_stats */
422 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
423 ,LPROCFS_STATS_FLAG_NOPERCPU);
424 if (tmp->nid_ldlm_stats == NULL)
427 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
429 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
430 tmp->nid_ldlm_stats);
433 #define OBD_CHECK_MD_OP(obd, op, err) \
435 if (!OBT(obd) || !MDP((obd), op)) { \
437 CERROR("md_" #op ": dev %s/%d no operation\n", \
438 obd->obd_name, obd->obd_minor); \
443 #define EXP_CHECK_MD_OP(exp, op) \
445 if ((exp) == NULL) { \
446 CERROR("obd_" #op ": NULL export\n"); \
449 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
450 CERROR("obd_" #op ": cleaned up obd\n"); \
451 RETURN(-EOPNOTSUPP); \
453 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
454 CERROR("obd_" #op ": dev %s/%d no operation\n", \
455 (exp)->exp_obd->obd_name, \
456 (exp)->exp_obd->obd_minor); \
457 RETURN(-EOPNOTSUPP); \
462 #define OBD_CHECK_DT_OP(obd, op, err) \
464 if (!OBT(obd) || !OBP((obd), op)) { \
466 CERROR("obd_" #op ": dev %d no operation\n", \
472 #define EXP_CHECK_DT_OP(exp, op) \
474 if ((exp) == NULL) { \
475 CERROR("obd_" #op ": NULL export\n"); \
478 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
479 CERROR("obd_" #op ": cleaned up obd\n"); \
480 RETURN(-EOPNOTSUPP); \
482 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
483 CERROR("obd_" #op ": dev %d no operation\n", \
484 (exp)->exp_obd->obd_minor); \
485 RETURN(-EOPNOTSUPP); \
489 #define CTXT_CHECK_OP(ctxt, op, err) \
491 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
493 CERROR("lop_" #op ": dev %d no operation\n", \
494 ctxt->loc_obd->obd_minor); \
499 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
500 void *key, __u32 *vallen, void *val,
501 struct lov_stripe_md *lsm)
506 EXP_CHECK_DT_OP(exp, get_info);
507 EXP_COUNTER_INCREMENT(exp, get_info);
509 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
513 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
514 void *key, obd_count vallen, void *val,
515 struct ptlrpc_request_set *set)
520 EXP_CHECK_DT_OP(exp, set_info_async);
521 EXP_COUNTER_INCREMENT(exp, set_info_async);
523 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
529 * obd-lu integration.
531 * Functionality is being moved into new lu_device-based layering, but some
532 * pieces of configuration process are still based on obd devices.
534 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
535 * subsume ->o_setup() methods of obd devices they replace. The same for
536 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
537 * result, obd_setup() and obd_process_config() branch and call one XOR
540 * Yet neither lu_device_type_operations::ldto_device_fini() nor
541 * lu_device_type_operations::ldto_device_free() fully implement the
542 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
543 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
546 #define DECLARE_LU_VARS(ldt, d) \
547 struct lu_device_type *ldt; \
550 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
553 DECLARE_LU_VARS(ldt, d);
556 ldt = obd->obd_type->typ_lu;
558 struct lu_context session_ctx;
560 lu_context_init(&session_ctx, LCT_SESSION);
561 session_ctx.lc_thread = NULL;
562 lu_context_enter(&session_ctx);
564 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
566 env.le_ses = &session_ctx;
567 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
576 lu_context_exit(&session_ctx);
577 lu_context_fini(&session_ctx);
580 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
581 OBD_COUNTER_INCREMENT(obd, setup);
582 rc = OBP(obd, setup)(obd, cfg);
587 static inline int obd_precleanup(struct obd_device *obd,
588 enum obd_cleanup_stage cleanup_stage)
591 DECLARE_LU_VARS(ldt, d);
595 ldt = obd->obd_type->typ_lu;
597 if (ldt != NULL && d != NULL) {
598 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
601 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
603 ldt->ldt_ops->ldto_device_fini(&env, d);
608 OBD_CHECK_DT_OP(obd, precleanup, 0);
609 OBD_COUNTER_INCREMENT(obd, precleanup);
611 rc = OBP(obd, precleanup)(obd, cleanup_stage);
615 static inline int obd_cleanup(struct obd_device *obd)
618 DECLARE_LU_VARS(ldt, d);
623 ldt = obd->obd_type->typ_lu;
625 if (ldt != NULL && d != NULL) {
628 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
630 ldt->ldt_ops->ldto_device_free(&env, d);
632 obd->obd_lu_dev = NULL;
635 OBD_CHECK_DT_OP(obd, cleanup, 0);
636 OBD_COUNTER_INCREMENT(obd, cleanup);
638 rc = OBP(obd, cleanup)(obd);
643 obd_process_config(struct obd_device *obd, int datalen, void *data)
646 DECLARE_LU_VARS(ldt, d);
651 obd->obd_process_conf = 1;
652 ldt = obd->obd_type->typ_lu;
654 if (ldt != NULL && d != NULL) {
657 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
659 rc = d->ld_ops->ldo_process_config(&env, d, data);
663 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
664 rc = OBP(obd, process_config)(obd, datalen, data);
666 OBD_COUNTER_INCREMENT(obd, process_config);
667 obd->obd_process_conf = 0;
672 /* Pack an in-memory MD struct for storage on disk.
673 * Returns +ve size of packed MD (0 for free), or -ve error.
675 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
676 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
677 * If @*disk_tgt == NULL, it will be allocated
679 static inline int obd_packmd(struct obd_export *exp,
680 struct lov_mds_md **disk_tgt,
681 struct lov_stripe_md *mem_src)
686 EXP_CHECK_DT_OP(exp, packmd);
687 EXP_COUNTER_INCREMENT(exp, packmd);
689 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
693 static inline int obd_size_diskmd(struct obd_export *exp,
694 struct lov_stripe_md *mem_src)
696 return obd_packmd(exp, NULL, mem_src);
699 /* helper functions */
700 static inline int obd_alloc_diskmd(struct obd_export *exp,
701 struct lov_mds_md **disk_tgt)
704 LASSERT(*disk_tgt == NULL);
705 return obd_packmd(exp, disk_tgt, NULL);
708 static inline int obd_free_diskmd(struct obd_export *exp,
709 struct lov_mds_md **disk_tgt)
713 return obd_packmd(exp, disk_tgt, NULL);
716 /* Unpack an MD struct from disk to in-memory format.
717 * Returns +ve size of unpacked MD (0 for free), or -ve error.
719 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
720 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
721 * If @*mem_tgt == NULL, it will be allocated
723 static inline int obd_unpackmd(struct obd_export *exp,
724 struct lov_stripe_md **mem_tgt,
725 struct lov_mds_md *disk_src,
731 EXP_CHECK_DT_OP(exp, unpackmd);
732 EXP_COUNTER_INCREMENT(exp, unpackmd);
734 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
738 /* helper functions */
739 static inline int obd_alloc_memmd(struct obd_export *exp,
740 struct lov_stripe_md **mem_tgt)
743 LASSERT(*mem_tgt == NULL);
744 return obd_unpackmd(exp, mem_tgt, NULL, 0);
747 static inline int obd_free_memmd(struct obd_export *exp,
748 struct lov_stripe_md **mem_tgt)
754 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
759 static inline int obd_precreate(struct obd_export *exp)
764 EXP_CHECK_DT_OP(exp, precreate);
765 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
767 rc = OBP(exp->exp_obd, precreate)(exp);
771 static inline int obd_create_async(struct obd_export *exp,
772 struct obd_info *oinfo,
773 struct lov_stripe_md **ea,
774 struct obd_trans_info *oti)
779 EXP_CHECK_DT_OP(exp, create_async);
780 EXP_COUNTER_INCREMENT(exp, create_async);
782 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
786 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
787 struct lov_stripe_md **ea,
788 struct obd_trans_info *oti)
793 EXP_CHECK_DT_OP(exp, create);
794 EXP_COUNTER_INCREMENT(exp, create);
796 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
800 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
801 struct lov_stripe_md *ea,
802 struct obd_trans_info *oti,
803 struct obd_export *md_exp, void *capa)
808 EXP_CHECK_DT_OP(exp, destroy);
809 EXP_COUNTER_INCREMENT(exp, destroy);
811 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
815 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
820 EXP_CHECK_DT_OP(exp, getattr);
821 EXP_COUNTER_INCREMENT(exp, getattr);
823 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
827 static inline int obd_getattr_async(struct obd_export *exp,
828 struct obd_info *oinfo,
829 struct ptlrpc_request_set *set)
834 EXP_CHECK_DT_OP(exp, getattr_async);
835 EXP_COUNTER_INCREMENT(exp, getattr_async);
837 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
841 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
842 struct obd_trans_info *oti)
847 EXP_CHECK_DT_OP(exp, setattr);
848 EXP_COUNTER_INCREMENT(exp, setattr);
850 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
854 /* This performs all the requests set init/wait/destroy actions. */
855 static inline int obd_setattr_rqset(struct obd_export *exp,
856 struct obd_info *oinfo,
857 struct obd_trans_info *oti)
859 struct ptlrpc_request_set *set = NULL;
863 EXP_CHECK_DT_OP(exp, setattr_async);
864 EXP_COUNTER_INCREMENT(exp, setattr_async);
866 set = ptlrpc_prep_set();
870 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
872 rc = ptlrpc_set_wait(set);
873 ptlrpc_set_destroy(set);
877 /* This adds all the requests into @set if @set != NULL, otherwise
878 all requests are sent asynchronously without waiting for response. */
879 static inline int obd_setattr_async(struct obd_export *exp,
880 struct obd_info *oinfo,
881 struct obd_trans_info *oti,
882 struct ptlrpc_request_set *set)
887 EXP_CHECK_DT_OP(exp, setattr_async);
888 EXP_COUNTER_INCREMENT(exp, setattr_async);
890 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
894 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
897 struct obd_device *obd = imp->imp_obd;
901 OBD_CHECK_DEV_ACTIVE(obd);
902 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
903 OBD_COUNTER_INCREMENT(obd, add_conn);
905 rc = OBP(obd, add_conn)(imp, uuid, priority);
909 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
911 struct obd_device *obd = imp->imp_obd;
915 OBD_CHECK_DEV_ACTIVE(obd);
916 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
917 OBD_COUNTER_INCREMENT(obd, del_conn);
919 rc = OBP(obd, del_conn)(imp, uuid);
923 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
925 struct obd_uuid *uuid;
928 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
929 EXP_COUNTER_INCREMENT(exp, get_uuid);
931 uuid = OBP(exp->exp_obd, get_uuid)(exp);
935 /** Create a new /a exp on device /a obd for the uuid /a cluuid
936 * @param exp New export handle
937 * @param d Connect data, supported flags are set, flags also understood
938 * by obd are returned.
940 static inline int obd_connect(const struct lu_env *env,
941 struct obd_export **exp,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
951 OBD_CHECK_DEV_ACTIVE(obd);
952 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
953 OBD_COUNTER_INCREMENT(obd, connect);
955 rc = OBP(obd, connect)(env, exp, obd, cluuid, d, localdata);
956 /* check that only subset is granted */
957 LASSERT(ergo(d != NULL,
958 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
962 static inline int obd_reconnect(const struct lu_env *env,
963 struct obd_export *exp,
964 struct obd_device *obd,
965 struct obd_uuid *cluuid,
966 struct obd_connect_data *d,
970 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
975 OBD_CHECK_DEV_ACTIVE(obd);
976 OBD_CHECK_DT_OP(obd, reconnect, 0);
977 OBD_COUNTER_INCREMENT(obd, reconnect);
979 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
980 /* check that only subset is granted */
981 LASSERT(ergo(d != NULL,
982 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
986 static inline int obd_disconnect(struct obd_export *exp)
991 EXP_CHECK_DT_OP(exp, disconnect);
992 EXP_COUNTER_INCREMENT(exp, disconnect);
994 rc = OBP(exp->exp_obd, disconnect)(exp);
998 static inline int obd_fid_init(struct obd_export *exp)
1003 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
1004 EXP_COUNTER_INCREMENT(exp, fid_init);
1006 rc = OBP(exp->exp_obd, fid_init)(exp);
1010 static inline int obd_fid_fini(struct obd_export *exp)
1015 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
1016 EXP_COUNTER_INCREMENT(exp, fid_fini);
1018 rc = OBP(exp->exp_obd, fid_fini)(exp);
1022 static inline int obd_fid_alloc(struct obd_export *exp,
1024 struct md_op_data *op_data)
1029 EXP_CHECK_DT_OP(exp, fid_alloc);
1030 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1032 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
1036 static inline int obd_fid_delete(struct obd_export *exp,
1037 const struct lu_fid *fid)
1042 EXP_CHECK_DT_OP(exp, fid_delete);
1043 EXP_COUNTER_INCREMENT(exp, fid_delete);
1045 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
1049 static inline int obd_ping(struct obd_export *exp)
1054 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1055 EXP_COUNTER_INCREMENT(exp, ping);
1057 rc = OBP(exp->exp_obd, ping)(exp);
1061 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1066 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1067 OBD_COUNTER_INCREMENT(obd, pool_new);
1069 rc = OBP(obd, pool_new)(obd, poolname);
1073 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1078 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1079 OBD_COUNTER_INCREMENT(obd, pool_del);
1081 rc = OBP(obd, pool_del)(obd, poolname);
1085 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1090 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1091 OBD_COUNTER_INCREMENT(obd, pool_add);
1093 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1097 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1102 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1103 OBD_COUNTER_INCREMENT(obd, pool_rem);
1105 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1109 static inline void obd_getref(struct obd_device *obd)
1112 if (OBT(obd) && OBP(obd, getref)) {
1113 OBD_COUNTER_INCREMENT(obd, getref);
1114 OBP(obd, getref)(obd);
1119 static inline void obd_putref(struct obd_device *obd)
1122 if (OBT(obd) && OBP(obd, putref)) {
1123 OBD_COUNTER_INCREMENT(obd, putref);
1124 OBP(obd, putref)(obd);
1129 static inline int obd_init_export(struct obd_export *exp)
1134 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1135 OBP((exp)->exp_obd, init_export))
1136 rc = OBP(exp->exp_obd, init_export)(exp);
1140 static inline int obd_destroy_export(struct obd_export *exp)
1143 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1144 OBP((exp)->exp_obd, destroy_export))
1145 OBP(exp->exp_obd, destroy_export)(exp);
1149 static inline int obd_extent_calc(struct obd_export *exp,
1150 struct lov_stripe_md *md,
1151 int cmd, obd_off *offset)
1155 EXP_CHECK_DT_OP(exp, extent_calc);
1156 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1160 static inline struct dentry *
1161 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1163 LASSERT(exp->exp_obd);
1165 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1170 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1172 LASSERT(exp->exp_obd);
1173 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1175 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1176 dentry, exp->exp_obd);
1181 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1182 * If the cache is older than @max_age we will get a new value from the
1183 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1184 static inline int obd_statfs_async(struct obd_device *obd,
1185 struct obd_info *oinfo,
1187 struct ptlrpc_request_set *rqset)
1195 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1196 OBD_COUNTER_INCREMENT(obd, statfs);
1198 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1199 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1200 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1201 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1203 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1204 " objects "LPU64"/"LPU64"\n",
1205 obd->obd_name, &obd->obd_osfs,
1206 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1207 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1208 cfs_spin_lock(&obd->obd_osfs_lock);
1209 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1210 cfs_spin_unlock(&obd->obd_osfs_lock);
1211 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1212 if (oinfo->oi_cb_up)
1213 oinfo->oi_cb_up(oinfo, 0);
1218 static inline int obd_statfs_rqset(struct obd_device *obd,
1219 struct obd_statfs *osfs, __u64 max_age,
1222 struct ptlrpc_request_set *set = NULL;
1223 struct obd_info oinfo = { { { 0 } } };
1227 set = ptlrpc_prep_set();
1231 oinfo.oi_osfs = osfs;
1232 oinfo.oi_flags = flags;
1233 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1235 rc = ptlrpc_set_wait(set);
1236 ptlrpc_set_destroy(set);
1240 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1241 * If the cache is older than @max_age we will get a new value from the
1242 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1243 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1244 __u64 max_age, __u32 flags)
1252 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1253 OBD_COUNTER_INCREMENT(obd, statfs);
1255 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1256 obd->obd_osfs_age, max_age);
1257 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1258 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1260 cfs_spin_lock(&obd->obd_osfs_lock);
1261 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1262 obd->obd_osfs_age = cfs_time_current_64();
1263 cfs_spin_unlock(&obd->obd_osfs_lock);
1266 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1267 " objects "LPU64"/"LPU64"\n",
1268 obd->obd_name, &obd->obd_osfs,
1269 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1270 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1271 cfs_spin_lock(&obd->obd_osfs_lock);
1272 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1273 cfs_spin_unlock(&obd->obd_osfs_lock);
1278 static inline int obd_sync_rqset(struct obd_export *exp, struct obd_info *oinfo,
1279 obd_size start, obd_size end)
1281 struct ptlrpc_request_set *set = NULL;
1285 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1286 EXP_COUNTER_INCREMENT(exp, sync);
1288 set = ptlrpc_prep_set();
1292 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1294 rc = ptlrpc_set_wait(set);
1295 ptlrpc_set_destroy(set);
1299 static inline int obd_sync(struct obd_export *exp, struct obd_info *oinfo,
1300 obd_size start, obd_size end,
1301 struct ptlrpc_request_set *set)
1306 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1307 EXP_COUNTER_INCREMENT(exp, sync);
1309 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1313 static inline int obd_punch_rqset(struct obd_export *exp,
1314 struct obd_info *oinfo,
1315 struct obd_trans_info *oti)
1317 struct ptlrpc_request_set *set = NULL;
1321 EXP_CHECK_DT_OP(exp, punch);
1322 EXP_COUNTER_INCREMENT(exp, punch);
1324 set = ptlrpc_prep_set();
1328 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1330 rc = ptlrpc_set_wait(set);
1331 ptlrpc_set_destroy(set);
1335 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1336 struct obd_trans_info *oti,
1337 struct ptlrpc_request_set *rqset)
1342 EXP_CHECK_DT_OP(exp, punch);
1343 EXP_COUNTER_INCREMENT(exp, punch);
1345 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1349 static inline int obd_brw(int cmd, struct obd_export *exp,
1350 struct obd_info *oinfo, obd_count oa_bufs,
1351 struct brw_page *pg, struct obd_trans_info *oti)
1356 EXP_CHECK_DT_OP(exp, brw);
1357 EXP_COUNTER_INCREMENT(exp, brw);
1359 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1360 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1361 "or OBD_BRW_CHECK\n");
1365 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1369 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1370 int objcount, struct obd_ioobj *obj,
1371 struct niobuf_remote *remote, int *pages,
1372 struct niobuf_local *local,
1373 struct obd_trans_info *oti,
1374 struct lustre_capa *capa)
1379 EXP_CHECK_DT_OP(exp, preprw);
1380 EXP_COUNTER_INCREMENT(exp, preprw);
1382 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1383 pages, local, oti, capa);
1387 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1388 int objcount, struct obd_ioobj *obj,
1389 struct niobuf_remote *rnb, int pages,
1390 struct niobuf_local *local,
1391 struct obd_trans_info *oti, int rc)
1395 EXP_CHECK_DT_OP(exp, commitrw);
1396 EXP_COUNTER_INCREMENT(exp, commitrw);
1398 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1399 rnb, pages, local, oti, rc);
1403 static inline int obd_merge_lvb(struct obd_export *exp,
1404 struct lov_stripe_md *lsm,
1405 struct ost_lvb *lvb, int kms_only)
1410 EXP_CHECK_DT_OP(exp, merge_lvb);
1411 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1413 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1417 static inline int obd_adjust_kms(struct obd_export *exp,
1418 struct lov_stripe_md *lsm, obd_off size,
1424 EXP_CHECK_DT_OP(exp, adjust_kms);
1425 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1427 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1431 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1432 int len, void *karg, void *uarg)
1437 EXP_CHECK_DT_OP(exp, iocontrol);
1438 EXP_COUNTER_INCREMENT(exp, iocontrol);
1440 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1444 static inline int obd_enqueue_rqset(struct obd_export *exp,
1445 struct obd_info *oinfo,
1446 struct ldlm_enqueue_info *einfo)
1448 struct ptlrpc_request_set *set = NULL;
1452 EXP_CHECK_DT_OP(exp, enqueue);
1453 EXP_COUNTER_INCREMENT(exp, enqueue);
1455 set = ptlrpc_prep_set();
1459 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1461 rc = ptlrpc_set_wait(set);
1462 ptlrpc_set_destroy(set);
1466 static inline int obd_enqueue(struct obd_export *exp,
1467 struct obd_info *oinfo,
1468 struct ldlm_enqueue_info *einfo,
1469 struct ptlrpc_request_set *set)
1474 EXP_CHECK_DT_OP(exp, enqueue);
1475 EXP_COUNTER_INCREMENT(exp, enqueue);
1477 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1481 static inline int obd_change_cbdata(struct obd_export *exp,
1482 struct lov_stripe_md *lsm,
1483 ldlm_iterator_t it, void *data)
1488 EXP_CHECK_DT_OP(exp, change_cbdata);
1489 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1491 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1495 static inline int obd_find_cbdata(struct obd_export *exp,
1496 struct lov_stripe_md *lsm,
1497 ldlm_iterator_t it, void *data)
1502 EXP_CHECK_DT_OP(exp, find_cbdata);
1503 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1505 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1509 static inline int obd_cancel(struct obd_export *exp,
1510 struct lov_stripe_md *ea, __u32 mode,
1511 struct lustre_handle *lockh)
1516 EXP_CHECK_DT_OP(exp, cancel);
1517 EXP_COUNTER_INCREMENT(exp, cancel);
1519 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1523 static inline int obd_cancel_unused(struct obd_export *exp,
1524 struct lov_stripe_md *ea,
1525 ldlm_cancel_flags_t flags,
1531 EXP_CHECK_DT_OP(exp, cancel_unused);
1532 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1534 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1538 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1539 struct obd_capa *oc, struct obd_client_handle *handle,
1545 EXP_CHECK_DT_OP(exp, pin);
1546 EXP_COUNTER_INCREMENT(exp, pin);
1548 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1552 static inline int obd_unpin(struct obd_export *exp,
1553 struct obd_client_handle *handle, int flag)
1558 EXP_CHECK_DT_OP(exp, unpin);
1559 EXP_COUNTER_INCREMENT(exp, unpin);
1561 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1566 static inline void obd_import_event(struct obd_device *obd,
1567 struct obd_import *imp,
1568 enum obd_import_event event)
1572 CERROR("NULL device\n");
1576 if (obd->obd_set_up && OBP(obd, import_event)) {
1577 OBD_COUNTER_INCREMENT(obd, import_event);
1578 OBP(obd, import_event)(obd, imp, event);
1583 static inline int obd_llog_connect(struct obd_export *exp,
1584 struct llogd_conn_body *body)
1589 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1590 EXP_COUNTER_INCREMENT(exp, llog_connect);
1592 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1597 static inline int obd_notify(struct obd_device *obd,
1598 struct obd_device *watched,
1599 enum obd_notify_event ev,
1606 /* the check for async_recov is a complete hack - I'm hereby
1607 overloading the meaning to also mean "this was called from
1608 mds_postsetup". I know that my mds is able to handle notifies
1609 by this point, and it needs to get them to execute mds_postrecov. */
1610 if (!obd->obd_set_up && !obd->obd_async_recov) {
1611 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1615 if (!OBP(obd, notify)) {
1616 CERROR("obd %s has no notify handler\n", obd->obd_name);
1620 OBD_COUNTER_INCREMENT(obd, notify);
1621 rc = OBP(obd, notify)(obd, watched, ev, data);
1625 static inline int obd_notify_observer(struct obd_device *observer,
1626 struct obd_device *observed,
1627 enum obd_notify_event ev,
1633 struct obd_notify_upcall *onu;
1635 if (observer->obd_observer)
1636 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1640 * Also, call non-obd listener, if any
1642 onu = &observer->obd_upcall;
1643 if (onu->onu_upcall != NULL)
1644 rc2 = onu->onu_upcall(observer, observed, ev,
1645 onu->onu_owner, NULL);
1649 return rc1 ? rc1 : rc2;
1652 static inline int obd_quotacheck(struct obd_export *exp,
1653 struct obd_quotactl *oqctl)
1658 EXP_CHECK_DT_OP(exp, quotacheck);
1659 EXP_COUNTER_INCREMENT(exp, quotacheck);
1661 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1665 static inline int obd_quotactl(struct obd_export *exp,
1666 struct obd_quotactl *oqctl)
1671 EXP_CHECK_DT_OP(exp, quotactl);
1672 EXP_COUNTER_INCREMENT(exp, quotactl);
1674 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1678 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1679 struct quota_adjust_qunit *oqaq,
1680 struct lustre_quota_ctxt *qctxt,
1681 struct ptlrpc_request_set *set)
1683 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1684 struct timeval work_start;
1685 struct timeval work_end;
1691 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1693 cfs_gettimeofday(&work_start);
1695 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1696 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1698 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt, set);
1700 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1702 cfs_gettimeofday(&work_end);
1703 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1704 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1711 static inline int obd_health_check(struct obd_device *obd)
1713 /* returns: 0 on healthy
1714 * >0 on unhealthy + reason code/flag
1715 * however the only suppored reason == 1 right now
1716 * We'll need to define some better reasons
1717 * or flags in the future.
1723 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1724 if (obd == NULL || !OBT(obd)) {
1725 CERROR("cleaned up obd\n");
1726 RETURN(-EOPNOTSUPP);
1728 if (!obd->obd_set_up || obd->obd_stopping)
1730 if (!OBP(obd, health_check))
1733 rc = OBP(obd, health_check)(obd);
1737 static inline int obd_register_observer(struct obd_device *obd,
1738 struct obd_device *observer)
1742 cfs_down_write(&obd->obd_observer_link_sem);
1743 if (obd->obd_observer && observer) {
1744 cfs_up_write(&obd->obd_observer_link_sem);
1747 obd->obd_observer = observer;
1748 cfs_up_write(&obd->obd_observer_link_sem);
1752 static inline int obd_pin_observer(struct obd_device *obd,
1753 struct obd_device **observer)
1756 cfs_down_read(&obd->obd_observer_link_sem);
1757 if (!obd->obd_observer) {
1759 cfs_up_read(&obd->obd_observer_link_sem);
1762 *observer = obd->obd_observer;
1766 static inline int obd_unpin_observer(struct obd_device *obd)
1769 cfs_up_read(&obd->obd_observer_link_sem);
1774 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1775 obd_page_removal_cb_t cb,
1776 obd_pin_extent_cb pin_cb)
1781 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1782 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1784 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1788 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1789 obd_page_removal_cb_t cb)
1794 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1795 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1797 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1801 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1802 obd_lock_cancel_cb cb)
1807 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1808 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1810 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1814 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1815 obd_lock_cancel_cb cb)
1820 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1821 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1823 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1828 /* metadata helpers */
1829 static inline int md_getstatus(struct obd_export *exp,
1830 struct lu_fid *fid, struct obd_capa **pc)
1835 EXP_CHECK_MD_OP(exp, getstatus);
1836 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1837 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1841 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1842 struct ptlrpc_request **request)
1846 EXP_CHECK_MD_OP(exp, getattr);
1847 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1848 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1852 static inline int md_change_cbdata(struct obd_export *exp,
1853 const struct lu_fid *fid,
1854 ldlm_iterator_t it, void *data)
1858 EXP_CHECK_MD_OP(exp, change_cbdata);
1859 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1860 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1864 static inline int md_find_cbdata(struct obd_export *exp,
1865 const struct lu_fid *fid,
1866 ldlm_iterator_t it, void *data)
1870 EXP_CHECK_MD_OP(exp, find_cbdata);
1871 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1872 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1876 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1877 struct md_open_data *mod,
1878 struct ptlrpc_request **request)
1882 EXP_CHECK_MD_OP(exp, close);
1883 EXP_MD_COUNTER_INCREMENT(exp, close);
1884 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1888 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1889 const void *data, int datalen, int mode, __u32 uid,
1890 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1891 struct ptlrpc_request **request)
1895 EXP_CHECK_MD_OP(exp, create);
1896 EXP_MD_COUNTER_INCREMENT(exp, create);
1897 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1898 uid, gid, cap_effective, rdev, request);
1902 static inline int md_done_writing(struct obd_export *exp,
1903 struct md_op_data *op_data,
1904 struct md_open_data *mod)
1908 EXP_CHECK_MD_OP(exp, done_writing);
1909 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1910 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1914 static inline int md_enqueue(struct obd_export *exp,
1915 struct ldlm_enqueue_info *einfo,
1916 struct lookup_intent *it,
1917 struct md_op_data *op_data,
1918 struct lustre_handle *lockh,
1919 void *lmm, int lmmsize,
1920 struct ptlrpc_request **req,
1921 int extra_lock_flags)
1925 EXP_CHECK_MD_OP(exp, enqueue);
1926 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1927 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1928 lmm, lmmsize, req, extra_lock_flags);
1932 static inline int md_getattr_name(struct obd_export *exp,
1933 struct md_op_data *op_data,
1934 struct ptlrpc_request **request)
1938 EXP_CHECK_MD_OP(exp, getattr_name);
1939 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1940 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1944 static inline int md_intent_lock(struct obd_export *exp,
1945 struct md_op_data *op_data, void *lmm,
1946 int lmmsize, struct lookup_intent *it,
1947 int flags, struct ptlrpc_request **reqp,
1948 ldlm_blocking_callback cb_blocking,
1949 int extra_lock_flags)
1953 EXP_CHECK_MD_OP(exp, intent_lock);
1954 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1955 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1956 it, flags, reqp, cb_blocking,
1961 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1962 struct ptlrpc_request **request)
1966 EXP_CHECK_MD_OP(exp, link);
1967 EXP_MD_COUNTER_INCREMENT(exp, link);
1968 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1972 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1973 const char *old, int oldlen, const char *new,
1974 int newlen, struct ptlrpc_request **request)
1978 EXP_CHECK_MD_OP(exp, rename);
1979 EXP_MD_COUNTER_INCREMENT(exp, rename);
1980 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1985 static inline int md_is_subdir(struct obd_export *exp,
1986 const struct lu_fid *pfid,
1987 const struct lu_fid *cfid,
1988 struct ptlrpc_request **request)
1992 EXP_CHECK_MD_OP(exp, is_subdir);
1993 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1994 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1998 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1999 void *ea, int ealen, void *ea2, int ea2len,
2000 struct ptlrpc_request **request,
2001 struct md_open_data **mod)
2005 EXP_CHECK_MD_OP(exp, setattr);
2006 EXP_MD_COUNTER_INCREMENT(exp, setattr);
2007 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
2008 ea2, ea2len, request, mod);
2012 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
2013 struct obd_capa *oc, struct ptlrpc_request **request)
2017 EXP_CHECK_MD_OP(exp, sync);
2018 EXP_MD_COUNTER_INCREMENT(exp, sync);
2019 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
2023 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
2024 struct obd_capa *oc, __u64 offset,
2026 struct ptlrpc_request **request)
2030 EXP_CHECK_MD_OP(exp, readpage);
2031 EXP_MD_COUNTER_INCREMENT(exp, readpage);
2032 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
2036 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
2037 struct ptlrpc_request **request)
2041 EXP_CHECK_MD_OP(exp, unlink);
2042 EXP_MD_COUNTER_INCREMENT(exp, unlink);
2043 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
2047 static inline int md_get_lustre_md(struct obd_export *exp,
2048 struct ptlrpc_request *req,
2049 struct obd_export *dt_exp,
2050 struct obd_export *md_exp,
2051 struct lustre_md *md)
2054 EXP_CHECK_MD_OP(exp, get_lustre_md);
2055 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
2056 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
2059 static inline int md_free_lustre_md(struct obd_export *exp,
2060 struct lustre_md *md)
2063 EXP_CHECK_MD_OP(exp, free_lustre_md);
2064 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
2065 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
2068 static inline int md_setxattr(struct obd_export *exp,
2069 const struct lu_fid *fid, struct obd_capa *oc,
2070 obd_valid valid, const char *name,
2071 const char *input, int input_size,
2072 int output_size, int flags, __u32 suppgid,
2073 struct ptlrpc_request **request)
2076 EXP_CHECK_MD_OP(exp, setxattr);
2077 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
2078 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
2079 input_size, output_size, flags,
2083 static inline int md_getxattr(struct obd_export *exp,
2084 const struct lu_fid *fid, struct obd_capa *oc,
2085 obd_valid valid, const char *name,
2086 const char *input, int input_size,
2087 int output_size, int flags,
2088 struct ptlrpc_request **request)
2091 EXP_CHECK_MD_OP(exp, getxattr);
2092 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
2093 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
2094 input_size, output_size, flags,
2098 static inline int md_set_open_replay_data(struct obd_export *exp,
2099 struct obd_client_handle *och,
2100 struct ptlrpc_request *open_req)
2103 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2104 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2105 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2108 static inline int md_clear_open_replay_data(struct obd_export *exp,
2109 struct obd_client_handle *och)
2112 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2113 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2114 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2117 static inline int md_set_lock_data(struct obd_export *exp,
2118 __u64 *lockh, void *data, __u32 *bits)
2121 EXP_CHECK_MD_OP(exp, set_lock_data);
2122 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2123 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
2126 static inline int md_cancel_unused(struct obd_export *exp,
2127 const struct lu_fid *fid,
2128 ldlm_policy_data_t *policy,
2130 ldlm_cancel_flags_t flags,
2136 EXP_CHECK_MD_OP(exp, cancel_unused);
2137 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2139 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2144 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2145 const struct lu_fid *fid,
2147 ldlm_policy_data_t *policy,
2149 struct lustre_handle *lockh)
2152 EXP_CHECK_MD_OP(exp, lock_match);
2153 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2154 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2155 policy, mode, lockh));
2158 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2159 int def_asize, int cookiesize)
2162 EXP_CHECK_MD_OP(exp, init_ea_size);
2163 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2164 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2168 static inline int md_get_remote_perm(struct obd_export *exp,
2169 const struct lu_fid *fid,
2170 struct obd_capa *oc, __u32 suppgid,
2171 struct ptlrpc_request **request)
2174 EXP_CHECK_MD_OP(exp, get_remote_perm);
2175 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2176 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2180 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2185 EXP_CHECK_MD_OP(exp, renew_capa);
2186 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2187 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2191 static inline int md_unpack_capa(struct obd_export *exp,
2192 struct ptlrpc_request *req,
2193 const struct req_msg_field *field,
2194 struct obd_capa **oc)
2198 EXP_CHECK_MD_OP(exp, unpack_capa);
2199 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2200 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2204 static inline int md_intent_getattr_async(struct obd_export *exp,
2205 struct md_enqueue_info *minfo,
2206 struct ldlm_enqueue_info *einfo)
2210 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2211 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2212 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2216 static inline int md_revalidate_lock(struct obd_export *exp,
2217 struct lookup_intent *it,
2222 EXP_CHECK_MD_OP(exp, revalidate_lock);
2223 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2224 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2229 /* OBD Metadata Support */
2231 extern int obd_init_caches(void);
2232 extern void obd_cleanup_caches(void);
2234 /* support routines */
2235 extern cfs_mem_cache_t *obdo_cachep;
2237 #define OBDO_ALLOC(ptr) \
2239 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, CFS_ALLOC_IO); \
2242 #define OBDO_FREE(ptr) \
2244 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2248 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2250 /* something here */
2253 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2255 /* something here */
2258 /* I'm as embarrassed about this as you are.
2260 * <shaver> // XXX do not look into _superhack with remaining eye
2261 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2262 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2265 extern void obd_sysctl_init (void);
2266 extern void obd_sysctl_clean (void);
2269 typedef __u8 class_uuid_t[16];
2270 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2273 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2274 int class_add_uuid(const char *uuid, __u64 nid);
2275 int class_del_uuid (const char *uuid);
2276 void class_init_uuidlist(void);
2277 void class_exit_uuidlist(void);
2280 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2281 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2284 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
2286 #endif /* __LINUX_OBD_CLASS_H */