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(struct obd_export *exp, struct obdo *oa,
1279 struct lov_stripe_md *ea, obd_size start,
1280 obd_size end, void *capa)
1285 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1286 EXP_COUNTER_INCREMENT(exp, sync);
1288 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1292 static inline int obd_punch_rqset(struct obd_export *exp,
1293 struct obd_info *oinfo,
1294 struct obd_trans_info *oti)
1296 struct ptlrpc_request_set *set = NULL;
1300 EXP_CHECK_DT_OP(exp, punch);
1301 EXP_COUNTER_INCREMENT(exp, punch);
1303 set = ptlrpc_prep_set();
1307 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1309 rc = ptlrpc_set_wait(set);
1310 ptlrpc_set_destroy(set);
1314 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1315 struct obd_trans_info *oti,
1316 struct ptlrpc_request_set *rqset)
1321 EXP_CHECK_DT_OP(exp, punch);
1322 EXP_COUNTER_INCREMENT(exp, punch);
1324 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1328 static inline int obd_brw(int cmd, struct obd_export *exp,
1329 struct obd_info *oinfo, obd_count oa_bufs,
1330 struct brw_page *pg, struct obd_trans_info *oti)
1335 EXP_CHECK_DT_OP(exp, brw);
1336 EXP_COUNTER_INCREMENT(exp, brw);
1338 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1339 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1340 "or OBD_BRW_CHECK\n");
1344 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1348 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1349 int objcount, struct obd_ioobj *obj,
1350 struct niobuf_remote *remote, int *pages,
1351 struct niobuf_local *local,
1352 struct obd_trans_info *oti,
1353 struct lustre_capa *capa)
1358 EXP_CHECK_DT_OP(exp, preprw);
1359 EXP_COUNTER_INCREMENT(exp, preprw);
1361 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1362 pages, local, oti, capa);
1366 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1367 int objcount, struct obd_ioobj *obj,
1368 struct niobuf_remote *rnb, int pages,
1369 struct niobuf_local *local,
1370 struct obd_trans_info *oti, int rc)
1374 EXP_CHECK_DT_OP(exp, commitrw);
1375 EXP_COUNTER_INCREMENT(exp, commitrw);
1377 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1378 rnb, pages, local, oti, rc);
1382 static inline int obd_merge_lvb(struct obd_export *exp,
1383 struct lov_stripe_md *lsm,
1384 struct ost_lvb *lvb, int kms_only)
1389 EXP_CHECK_DT_OP(exp, merge_lvb);
1390 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1392 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1396 static inline int obd_adjust_kms(struct obd_export *exp,
1397 struct lov_stripe_md *lsm, obd_off size,
1403 EXP_CHECK_DT_OP(exp, adjust_kms);
1404 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1406 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1410 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1411 int len, void *karg, void *uarg)
1416 EXP_CHECK_DT_OP(exp, iocontrol);
1417 EXP_COUNTER_INCREMENT(exp, iocontrol);
1419 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1423 static inline int obd_enqueue_rqset(struct obd_export *exp,
1424 struct obd_info *oinfo,
1425 struct ldlm_enqueue_info *einfo)
1427 struct ptlrpc_request_set *set = NULL;
1431 EXP_CHECK_DT_OP(exp, enqueue);
1432 EXP_COUNTER_INCREMENT(exp, enqueue);
1434 set = ptlrpc_prep_set();
1438 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1440 rc = ptlrpc_set_wait(set);
1441 ptlrpc_set_destroy(set);
1445 static inline int obd_enqueue(struct obd_export *exp,
1446 struct obd_info *oinfo,
1447 struct ldlm_enqueue_info *einfo,
1448 struct ptlrpc_request_set *set)
1453 EXP_CHECK_DT_OP(exp, enqueue);
1454 EXP_COUNTER_INCREMENT(exp, enqueue);
1456 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1460 static inline int obd_change_cbdata(struct obd_export *exp,
1461 struct lov_stripe_md *lsm,
1462 ldlm_iterator_t it, void *data)
1467 EXP_CHECK_DT_OP(exp, change_cbdata);
1468 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1470 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1474 static inline int obd_find_cbdata(struct obd_export *exp,
1475 struct lov_stripe_md *lsm,
1476 ldlm_iterator_t it, void *data)
1481 EXP_CHECK_DT_OP(exp, find_cbdata);
1482 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1484 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1488 static inline int obd_cancel(struct obd_export *exp,
1489 struct lov_stripe_md *ea, __u32 mode,
1490 struct lustre_handle *lockh)
1495 EXP_CHECK_DT_OP(exp, cancel);
1496 EXP_COUNTER_INCREMENT(exp, cancel);
1498 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1502 static inline int obd_cancel_unused(struct obd_export *exp,
1503 struct lov_stripe_md *ea,
1504 ldlm_cancel_flags_t flags,
1510 EXP_CHECK_DT_OP(exp, cancel_unused);
1511 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1513 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1517 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1518 struct obd_capa *oc, struct obd_client_handle *handle,
1524 EXP_CHECK_DT_OP(exp, pin);
1525 EXP_COUNTER_INCREMENT(exp, pin);
1527 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1531 static inline int obd_unpin(struct obd_export *exp,
1532 struct obd_client_handle *handle, int flag)
1537 EXP_CHECK_DT_OP(exp, unpin);
1538 EXP_COUNTER_INCREMENT(exp, unpin);
1540 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1545 static inline void obd_import_event(struct obd_device *obd,
1546 struct obd_import *imp,
1547 enum obd_import_event event)
1551 CERROR("NULL device\n");
1555 if (obd->obd_set_up && OBP(obd, import_event)) {
1556 OBD_COUNTER_INCREMENT(obd, import_event);
1557 OBP(obd, import_event)(obd, imp, event);
1562 static inline int obd_llog_connect(struct obd_export *exp,
1563 struct llogd_conn_body *body)
1568 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1569 EXP_COUNTER_INCREMENT(exp, llog_connect);
1571 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1576 static inline int obd_notify(struct obd_device *obd,
1577 struct obd_device *watched,
1578 enum obd_notify_event ev,
1585 /* the check for async_recov is a complete hack - I'm hereby
1586 overloading the meaning to also mean "this was called from
1587 mds_postsetup". I know that my mds is able to handle notifies
1588 by this point, and it needs to get them to execute mds_postrecov. */
1589 if (!obd->obd_set_up && !obd->obd_async_recov) {
1590 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1594 if (!OBP(obd, notify)) {
1595 CERROR("obd %s has no notify handler\n", obd->obd_name);
1599 OBD_COUNTER_INCREMENT(obd, notify);
1600 rc = OBP(obd, notify)(obd, watched, ev, data);
1604 static inline int obd_notify_observer(struct obd_device *observer,
1605 struct obd_device *observed,
1606 enum obd_notify_event ev,
1612 struct obd_notify_upcall *onu;
1614 if (observer->obd_observer)
1615 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1619 * Also, call non-obd listener, if any
1621 onu = &observer->obd_upcall;
1622 if (onu->onu_upcall != NULL)
1623 rc2 = onu->onu_upcall(observer, observed, ev,
1624 onu->onu_owner, NULL);
1628 return rc1 ? rc1 : rc2;
1631 static inline int obd_quotacheck(struct obd_export *exp,
1632 struct obd_quotactl *oqctl)
1637 EXP_CHECK_DT_OP(exp, quotacheck);
1638 EXP_COUNTER_INCREMENT(exp, quotacheck);
1640 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1644 static inline int obd_quotactl(struct obd_export *exp,
1645 struct obd_quotactl *oqctl)
1650 EXP_CHECK_DT_OP(exp, quotactl);
1651 EXP_COUNTER_INCREMENT(exp, quotactl);
1653 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1657 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1658 struct quota_adjust_qunit *oqaq,
1659 struct lustre_quota_ctxt *qctxt,
1660 struct ptlrpc_request_set *set)
1662 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1663 struct timeval work_start;
1664 struct timeval work_end;
1670 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1672 cfs_gettimeofday(&work_start);
1674 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1675 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1677 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt, set);
1679 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1681 cfs_gettimeofday(&work_end);
1682 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1683 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1690 static inline int obd_health_check(struct obd_device *obd)
1692 /* returns: 0 on healthy
1693 * >0 on unhealthy + reason code/flag
1694 * however the only suppored reason == 1 right now
1695 * We'll need to define some better reasons
1696 * or flags in the future.
1702 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1703 if (obd == NULL || !OBT(obd)) {
1704 CERROR("cleaned up obd\n");
1705 RETURN(-EOPNOTSUPP);
1707 if (!obd->obd_set_up || obd->obd_stopping)
1709 if (!OBP(obd, health_check))
1712 rc = OBP(obd, health_check)(obd);
1716 static inline int obd_register_observer(struct obd_device *obd,
1717 struct obd_device *observer)
1721 cfs_down_write(&obd->obd_observer_link_sem);
1722 if (obd->obd_observer && observer) {
1723 cfs_up_write(&obd->obd_observer_link_sem);
1726 obd->obd_observer = observer;
1727 cfs_up_write(&obd->obd_observer_link_sem);
1731 static inline int obd_pin_observer(struct obd_device *obd,
1732 struct obd_device **observer)
1735 cfs_down_read(&obd->obd_observer_link_sem);
1736 if (!obd->obd_observer) {
1738 cfs_up_read(&obd->obd_observer_link_sem);
1741 *observer = obd->obd_observer;
1745 static inline int obd_unpin_observer(struct obd_device *obd)
1748 cfs_up_read(&obd->obd_observer_link_sem);
1753 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1754 obd_page_removal_cb_t cb,
1755 obd_pin_extent_cb pin_cb)
1760 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1761 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1763 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1767 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1768 obd_page_removal_cb_t cb)
1773 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1774 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1776 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1780 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1781 obd_lock_cancel_cb cb)
1786 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1787 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1789 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1793 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1794 obd_lock_cancel_cb cb)
1799 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1800 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1802 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1807 /* metadata helpers */
1808 static inline int md_getstatus(struct obd_export *exp,
1809 struct lu_fid *fid, struct obd_capa **pc)
1814 EXP_CHECK_MD_OP(exp, getstatus);
1815 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1816 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1820 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1821 struct ptlrpc_request **request)
1825 EXP_CHECK_MD_OP(exp, getattr);
1826 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1827 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1831 static inline int md_change_cbdata(struct obd_export *exp,
1832 const struct lu_fid *fid,
1833 ldlm_iterator_t it, void *data)
1837 EXP_CHECK_MD_OP(exp, change_cbdata);
1838 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1839 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1843 static inline int md_find_cbdata(struct obd_export *exp,
1844 const struct lu_fid *fid,
1845 ldlm_iterator_t it, void *data)
1849 EXP_CHECK_MD_OP(exp, find_cbdata);
1850 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1851 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1855 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1856 struct md_open_data *mod,
1857 struct ptlrpc_request **request)
1861 EXP_CHECK_MD_OP(exp, close);
1862 EXP_MD_COUNTER_INCREMENT(exp, close);
1863 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1867 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1868 const void *data, int datalen, int mode, __u32 uid,
1869 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1870 struct ptlrpc_request **request)
1874 EXP_CHECK_MD_OP(exp, create);
1875 EXP_MD_COUNTER_INCREMENT(exp, create);
1876 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1877 uid, gid, cap_effective, rdev, request);
1881 static inline int md_done_writing(struct obd_export *exp,
1882 struct md_op_data *op_data,
1883 struct md_open_data *mod)
1887 EXP_CHECK_MD_OP(exp, done_writing);
1888 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1889 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1893 static inline int md_enqueue(struct obd_export *exp,
1894 struct ldlm_enqueue_info *einfo,
1895 struct lookup_intent *it,
1896 struct md_op_data *op_data,
1897 struct lustre_handle *lockh,
1898 void *lmm, int lmmsize,
1899 struct ptlrpc_request **req,
1900 int extra_lock_flags)
1904 EXP_CHECK_MD_OP(exp, enqueue);
1905 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1906 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1907 lmm, lmmsize, req, extra_lock_flags);
1911 static inline int md_getattr_name(struct obd_export *exp,
1912 struct md_op_data *op_data,
1913 struct ptlrpc_request **request)
1917 EXP_CHECK_MD_OP(exp, getattr_name);
1918 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1919 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1923 static inline int md_intent_lock(struct obd_export *exp,
1924 struct md_op_data *op_data, void *lmm,
1925 int lmmsize, struct lookup_intent *it,
1926 int flags, struct ptlrpc_request **reqp,
1927 ldlm_blocking_callback cb_blocking,
1928 int extra_lock_flags)
1932 EXP_CHECK_MD_OP(exp, intent_lock);
1933 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1934 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1935 it, flags, reqp, cb_blocking,
1940 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1941 struct ptlrpc_request **request)
1945 EXP_CHECK_MD_OP(exp, link);
1946 EXP_MD_COUNTER_INCREMENT(exp, link);
1947 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1951 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1952 const char *old, int oldlen, const char *new,
1953 int newlen, struct ptlrpc_request **request)
1957 EXP_CHECK_MD_OP(exp, rename);
1958 EXP_MD_COUNTER_INCREMENT(exp, rename);
1959 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1964 static inline int md_is_subdir(struct obd_export *exp,
1965 const struct lu_fid *pfid,
1966 const struct lu_fid *cfid,
1967 struct ptlrpc_request **request)
1971 EXP_CHECK_MD_OP(exp, is_subdir);
1972 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1973 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1977 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1978 void *ea, int ealen, void *ea2, int ea2len,
1979 struct ptlrpc_request **request,
1980 struct md_open_data **mod)
1984 EXP_CHECK_MD_OP(exp, setattr);
1985 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1986 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1987 ea2, ea2len, request, mod);
1991 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1992 struct obd_capa *oc, struct ptlrpc_request **request)
1996 EXP_CHECK_MD_OP(exp, sync);
1997 EXP_MD_COUNTER_INCREMENT(exp, sync);
1998 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
2002 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
2003 struct obd_capa *oc, __u64 offset,
2005 struct ptlrpc_request **request)
2009 EXP_CHECK_MD_OP(exp, readpage);
2010 EXP_MD_COUNTER_INCREMENT(exp, readpage);
2011 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
2015 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
2016 struct ptlrpc_request **request)
2020 EXP_CHECK_MD_OP(exp, unlink);
2021 EXP_MD_COUNTER_INCREMENT(exp, unlink);
2022 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
2026 static inline int md_get_lustre_md(struct obd_export *exp,
2027 struct ptlrpc_request *req,
2028 struct obd_export *dt_exp,
2029 struct obd_export *md_exp,
2030 struct lustre_md *md)
2033 EXP_CHECK_MD_OP(exp, get_lustre_md);
2034 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
2035 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
2038 static inline int md_free_lustre_md(struct obd_export *exp,
2039 struct lustre_md *md)
2042 EXP_CHECK_MD_OP(exp, free_lustre_md);
2043 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
2044 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
2047 static inline int md_setxattr(struct obd_export *exp,
2048 const struct lu_fid *fid, struct obd_capa *oc,
2049 obd_valid valid, const char *name,
2050 const char *input, int input_size,
2051 int output_size, int flags, __u32 suppgid,
2052 struct ptlrpc_request **request)
2055 EXP_CHECK_MD_OP(exp, setxattr);
2056 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
2057 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
2058 input_size, output_size, flags,
2062 static inline int md_getxattr(struct obd_export *exp,
2063 const struct lu_fid *fid, struct obd_capa *oc,
2064 obd_valid valid, const char *name,
2065 const char *input, int input_size,
2066 int output_size, int flags,
2067 struct ptlrpc_request **request)
2070 EXP_CHECK_MD_OP(exp, getxattr);
2071 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
2072 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
2073 input_size, output_size, flags,
2077 static inline int md_set_open_replay_data(struct obd_export *exp,
2078 struct obd_client_handle *och,
2079 struct ptlrpc_request *open_req)
2082 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2083 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2084 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2087 static inline int md_clear_open_replay_data(struct obd_export *exp,
2088 struct obd_client_handle *och)
2091 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2092 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2093 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2096 static inline int md_set_lock_data(struct obd_export *exp,
2097 __u64 *lockh, void *data, __u32 *bits)
2100 EXP_CHECK_MD_OP(exp, set_lock_data);
2101 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2102 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
2105 static inline int md_cancel_unused(struct obd_export *exp,
2106 const struct lu_fid *fid,
2107 ldlm_policy_data_t *policy,
2109 ldlm_cancel_flags_t flags,
2115 EXP_CHECK_MD_OP(exp, cancel_unused);
2116 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2118 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2123 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2124 const struct lu_fid *fid,
2126 ldlm_policy_data_t *policy,
2128 struct lustre_handle *lockh)
2131 EXP_CHECK_MD_OP(exp, lock_match);
2132 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2133 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2134 policy, mode, lockh));
2137 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2138 int def_asize, int cookiesize)
2141 EXP_CHECK_MD_OP(exp, init_ea_size);
2142 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2143 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2147 static inline int md_get_remote_perm(struct obd_export *exp,
2148 const struct lu_fid *fid,
2149 struct obd_capa *oc, __u32 suppgid,
2150 struct ptlrpc_request **request)
2153 EXP_CHECK_MD_OP(exp, get_remote_perm);
2154 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2155 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2159 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2164 EXP_CHECK_MD_OP(exp, renew_capa);
2165 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2166 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2170 static inline int md_unpack_capa(struct obd_export *exp,
2171 struct ptlrpc_request *req,
2172 const struct req_msg_field *field,
2173 struct obd_capa **oc)
2177 EXP_CHECK_MD_OP(exp, unpack_capa);
2178 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2179 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2183 static inline int md_intent_getattr_async(struct obd_export *exp,
2184 struct md_enqueue_info *minfo,
2185 struct ldlm_enqueue_info *einfo)
2189 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2190 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2191 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2195 static inline int md_revalidate_lock(struct obd_export *exp,
2196 struct lookup_intent *it,
2201 EXP_CHECK_MD_OP(exp, revalidate_lock);
2202 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2203 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2208 /* OBD Metadata Support */
2210 extern int obd_init_caches(void);
2211 extern void obd_cleanup_caches(void);
2213 /* support routines */
2214 extern cfs_mem_cache_t *obdo_cachep;
2216 #define OBDO_ALLOC(ptr) \
2218 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, CFS_ALLOC_IO); \
2221 #define OBDO_FREE(ptr) \
2223 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2227 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2229 /* something here */
2232 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2234 /* something here */
2237 /* I'm as embarrassed about this as you are.
2239 * <shaver> // XXX do not look into _superhack with remaining eye
2240 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2241 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2244 extern void obd_sysctl_init (void);
2245 extern void obd_sysctl_clean (void);
2248 typedef __u8 class_uuid_t[16];
2249 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2252 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2253 int class_add_uuid(const char *uuid, __u64 nid);
2254 int class_del_uuid (const char *uuid);
2255 void class_init_uuidlist(void);
2256 void class_exit_uuidlist(void);
2259 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2260 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2263 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
2265 #endif /* __LINUX_OBD_CLASS_H */