1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
43 # include <liblustre.h>
46 #include <obd_support.h>
47 #include <lustre_import.h>
48 #include <lustre_net.h>
50 #include <lustre_lib.h>
51 #include <lustre/lustre_idl.h>
52 #include <lprocfs_status.h>
54 #if defined(__linux__)
55 #include <linux/obd_class.h>
56 #elif defined(__APPLE__)
57 #include <darwin/obd_class.h>
58 #elif defined(__WINNT__)
59 #include <winnt/obd_class.h>
61 #error Unsupported operating system.
64 /* OBD Device Declarations */
65 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
66 extern cfs_rwlock_t obd_dev_lock;
68 /* OBD Operations Declarations */
69 extern struct obd_device *class_conn2obd(struct lustre_handle *);
70 extern struct obd_device *class_exp2obd(struct obd_export *);
71 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
73 struct lu_device_type;
76 struct obd_export *class_conn2export(struct lustre_handle *);
77 int class_register_type(struct obd_ops *, struct md_ops *,
78 struct lprocfs_vars *, const char *nm,
79 struct lu_device_type *ldt);
80 int class_unregister_type(const char *nm);
82 struct obd_device *class_newdev(const char *type_name, const char *name);
83 void class_release_dev(struct obd_device *obd);
85 int class_name2dev(const char *name);
86 struct obd_device *class_name2obd(const char *name);
87 int class_uuid2dev(struct obd_uuid *uuid);
88 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
89 void class_obd_list(void);
90 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
91 const char * typ_name,
92 struct obd_uuid *grp_uuid);
93 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
95 struct obd_device * class_num2obd(int num);
97 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
99 char *obd_export_nid2str(struct obd_export *exp);
101 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
102 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
103 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
105 int obd_zombie_impexp_init(void);
106 void obd_zombie_impexp_stop(void);
107 void obd_zombie_impexp_cull(void);
108 void obd_zombie_barrier(void);
109 void obd_exports_barrier(struct obd_device *obd);
110 int kuc_len(int payload_len);
111 struct kuc_hdr * kuc_ptr(void *p);
112 int kuc_ispayload(void *p);
113 void *kuc_alloc(int payload_len, int transport, int type);
114 void kuc_free(void *p, int payload_len);
117 int class_process_config(struct lustre_cfg *lcfg);
118 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
119 struct lustre_cfg *lcfg, void *data);
120 int class_attach(struct lustre_cfg *lcfg);
121 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
122 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
123 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
124 struct obd_device *class_incref(struct obd_device *obd,
125 const char *scope, const void *source);
126 void class_decref(struct obd_device *obd,
127 const char *scope, const void *source);
128 void dump_exports(struct obd_device *obd, int locks);
132 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
134 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
136 memset(lvars, 0, sizeof(*lvars));
140 #define CFG_F_START 0x01 /* Set when we start updating from a log */
141 #define CFG_F_MARKER 0x02 /* We are within a maker */
142 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
143 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
144 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
146 /* Passed as data param to class_config_parse_llog */
147 struct config_llog_instance {
150 struct super_block *cfg_sb;
151 struct obd_uuid cfg_uuid;
152 int cfg_last_idx; /* for partial llog processing */
155 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
156 struct config_llog_instance *cfg);
157 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
158 struct config_llog_instance *cfg);
160 /* list of active configuration logs */
161 struct config_llog_data {
163 struct ldlm_res_id cld_resid;
164 struct config_llog_instance cld_cfg;
165 cfs_list_t cld_list_chain;
166 cfs_atomic_t cld_refcount;
167 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
168 struct obd_export *cld_mgcexp;
169 cfs_mutex_t cld_lock;
170 unsigned int cld_stopping:1, /* we were told to stop
172 cld_lostlock:1, /* lock not requeued */
176 struct lustre_profile {
183 struct lustre_profile *class_get_profile(const char * prof);
184 void class_del_profile(const char *prof);
185 void class_del_profiles(void);
187 #if LUSTRE_TRACKS_LOCK_EXP_REFS
189 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
190 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
191 extern void (*class_export_dump_hook)(struct obd_export *);
195 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
196 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
200 #define class_export_rpc_get(exp) \
202 cfs_atomic_inc(&(exp)->exp_rpc_count); \
203 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
204 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
205 class_export_get(exp); \
208 #define class_export_rpc_put(exp) \
210 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
211 cfs_atomic_dec(&(exp)->exp_rpc_count); \
212 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
213 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
214 class_export_put(exp); \
217 #define class_export_lock_get(exp, lock) \
219 cfs_atomic_inc(&(exp)->exp_locks_count); \
220 __class_export_add_lock_ref(exp, lock); \
221 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
222 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
223 class_export_get(exp); \
226 #define class_export_lock_put(exp, lock) \
228 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
229 cfs_atomic_dec(&(exp)->exp_locks_count); \
230 __class_export_del_lock_ref(exp, lock); \
231 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
232 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
233 class_export_put(exp); \
236 #define class_export_cb_get(exp) \
238 cfs_atomic_inc(&(exp)->exp_cb_count); \
239 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
240 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
241 class_export_get(exp); \
244 #define class_export_cb_put(exp) \
246 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
247 cfs_atomic_dec(&(exp)->exp_cb_count); \
248 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
249 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
250 class_export_put(exp); \
254 struct obd_export *class_export_get(struct obd_export *exp);
255 void class_export_put(struct obd_export *exp);
256 struct obd_export *class_new_export(struct obd_device *obddev,
257 struct obd_uuid *cluuid);
258 void class_unlink_export(struct obd_export *exp);
260 struct obd_import *class_import_get(struct obd_import *);
261 void class_import_put(struct obd_import *);
262 struct obd_import *class_new_import(struct obd_device *obd);
263 void class_destroy_import(struct obd_import *exp);
265 struct obd_type *class_search_type(const char *name);
266 struct obd_type *class_get_type(const char *name);
267 void class_put_type(struct obd_type *type);
268 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
269 struct obd_uuid *cluuid);
270 int class_disconnect(struct obd_export *exp);
271 void class_fail_export(struct obd_export *exp);
272 int class_connected_export(struct obd_export *exp);
273 void class_disconnect_exports(struct obd_device *obddev);
274 int class_manual_cleanup(struct obd_device *obd);
275 void class_disconnect_stale_exports(struct obd_device *,
276 int (*test_export)(struct obd_export *));
277 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
279 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
280 (obd->obd_force ? OBD_OPT_FORCE : 0) |
281 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
285 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
287 LASSERT(exp->exp_obd);
288 return exp->exp_obd->u.obt.obt_lut;
291 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
293 LASSERT(obd->u.obt.obt_lut);
294 return &obd->u.obt.obt_lut->lut_lsd;
297 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
298 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
299 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
300 unsigned int ia_valid);
301 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
302 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
303 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
306 #define OBT(dev) (dev)->obd_type
307 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
308 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
309 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
311 /* Ensure obd_setup: used for cleanup which must be called
312 while obd is stopping */
313 #define OBD_CHECK_DEV(obd) \
316 CERROR("NULL device\n"); \
321 /* ensure obd_setup and !obd_stopping */
322 #define OBD_CHECK_DEV_ACTIVE(obd) \
324 OBD_CHECK_DEV(obd); \
325 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
326 CERROR("Device %d not setup\n", \
334 #define OBD_COUNTER_OFFSET(op) \
335 ((offsetof(struct obd_ops, o_ ## op) - \
336 offsetof(struct obd_ops, o_iocontrol)) \
337 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
339 #define OBD_COUNTER_INCREMENT(obdx, op) \
340 if ((obdx)->obd_stats != NULL) { \
341 unsigned int coffset; \
342 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
343 OBD_COUNTER_OFFSET(op); \
344 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
345 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
348 #define EXP_COUNTER_INCREMENT(export, op) \
349 if ((export)->exp_obd->obd_stats != NULL) { \
350 unsigned int coffset; \
351 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
352 OBD_COUNTER_OFFSET(op); \
353 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
354 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
355 if ((export)->exp_nid_stats != NULL && \
356 (export)->exp_nid_stats->nid_stats != NULL) \
357 lprocfs_counter_incr( \
358 (export)->exp_nid_stats->nid_stats, coffset);\
361 #define MD_COUNTER_OFFSET(op) \
362 ((offsetof(struct md_ops, m_ ## op) - \
363 offsetof(struct md_ops, m_getstatus)) \
364 / sizeof(((struct md_ops *)(0))->m_getstatus))
366 #define MD_COUNTER_INCREMENT(obdx, op) \
367 if ((obd)->md_stats != NULL) { \
368 unsigned int coffset; \
369 coffset = (unsigned int)((obdx)->md_cntr_base) + \
370 MD_COUNTER_OFFSET(op); \
371 LASSERT(coffset < (obdx)->md_stats->ls_num); \
372 lprocfs_counter_incr((obdx)->md_stats, coffset); \
375 #define EXP_MD_COUNTER_INCREMENT(export, op) \
376 if ((export)->exp_obd->obd_stats != NULL) { \
377 unsigned int coffset; \
378 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
379 MD_COUNTER_OFFSET(op); \
380 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
381 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
382 if ((export)->exp_md_stats != NULL) \
383 lprocfs_counter_incr( \
384 (export)->exp_md_stats, coffset); \
388 #define OBD_COUNTER_OFFSET(op)
389 #define OBD_COUNTER_INCREMENT(obd, op)
390 #define EXP_COUNTER_INCREMENT(exp, op)
391 #define MD_COUNTER_INCREMENT(obd, op)
392 #define EXP_MD_COUNTER_INCREMENT(exp, op)
395 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
397 /* Always add in ldlm_stats */
398 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
399 ,LPROCFS_STATS_FLAG_NOPERCPU);
400 if (tmp->nid_ldlm_stats == NULL)
403 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
405 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
406 tmp->nid_ldlm_stats);
409 #define OBD_CHECK_MD_OP(obd, op, err) \
411 if (!OBT(obd) || !MDP((obd), op)) { \
413 CERROR("md_" #op ": dev %s/%d no operation\n", \
414 obd->obd_name, obd->obd_minor); \
419 #define EXP_CHECK_MD_OP(exp, op) \
421 if ((exp) == NULL) { \
422 CERROR("obd_" #op ": NULL export\n"); \
425 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
426 CERROR("obd_" #op ": cleaned up obd\n"); \
427 RETURN(-EOPNOTSUPP); \
429 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
430 CERROR("obd_" #op ": dev %s/%d no operation\n", \
431 (exp)->exp_obd->obd_name, \
432 (exp)->exp_obd->obd_minor); \
433 RETURN(-EOPNOTSUPP); \
438 #define OBD_CHECK_DT_OP(obd, op, err) \
440 if (!OBT(obd) || !OBP((obd), op)) { \
442 CERROR("obd_" #op ": dev %d no operation\n", \
448 #define EXP_CHECK_DT_OP(exp, op) \
450 if ((exp) == NULL) { \
451 CERROR("obd_" #op ": NULL export\n"); \
454 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
455 CERROR("obd_" #op ": cleaned up obd\n"); \
456 RETURN(-EOPNOTSUPP); \
458 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
459 CERROR("obd_" #op ": dev %d no operation\n", \
460 (exp)->exp_obd->obd_minor); \
461 RETURN(-EOPNOTSUPP); \
465 #define CTXT_CHECK_OP(ctxt, op, err) \
467 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
469 CERROR("lop_" #op ": dev %d no operation\n", \
470 ctxt->loc_obd->obd_minor); \
475 static inline int class_devno_max(void)
477 return MAX_OBD_DEVICES;
480 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
481 void *key, __u32 *vallen, void *val,
482 struct lov_stripe_md *lsm)
487 EXP_CHECK_DT_OP(exp, get_info);
488 EXP_COUNTER_INCREMENT(exp, get_info);
490 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
494 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
495 void *key, obd_count vallen, void *val,
496 struct ptlrpc_request_set *set)
501 EXP_CHECK_DT_OP(exp, set_info_async);
502 EXP_COUNTER_INCREMENT(exp, set_info_async);
504 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
510 * obd-lu integration.
512 * Functionality is being moved into new lu_device-based layering, but some
513 * pieces of configuration process are still based on obd devices.
515 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
516 * subsume ->o_setup() methods of obd devices they replace. The same for
517 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
518 * result, obd_setup() and obd_process_config() branch and call one XOR
521 * Yet neither lu_device_type_operations::ldto_device_fini() nor
522 * lu_device_type_operations::ldto_device_free() fully implement the
523 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
524 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
527 #define DECLARE_LU_VARS(ldt, d) \
528 struct lu_device_type *ldt; \
531 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
534 DECLARE_LU_VARS(ldt, d);
537 ldt = obd->obd_type->typ_lu;
539 struct lu_context session_ctx;
541 lu_context_init(&session_ctx, LCT_SESSION);
542 session_ctx.lc_thread = NULL;
543 lu_context_enter(&session_ctx);
545 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
547 env.le_ses = &session_ctx;
548 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
557 lu_context_exit(&session_ctx);
558 lu_context_fini(&session_ctx);
561 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
562 OBD_COUNTER_INCREMENT(obd, setup);
563 rc = OBP(obd, setup)(obd, cfg);
568 static inline int obd_precleanup(struct obd_device *obd,
569 enum obd_cleanup_stage cleanup_stage)
572 DECLARE_LU_VARS(ldt, d);
576 ldt = obd->obd_type->typ_lu;
578 if (ldt != NULL && d != NULL) {
579 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
582 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
584 ldt->ldt_ops->ldto_device_fini(&env, d);
589 OBD_CHECK_DT_OP(obd, precleanup, 0);
590 OBD_COUNTER_INCREMENT(obd, precleanup);
592 rc = OBP(obd, precleanup)(obd, cleanup_stage);
596 static inline int obd_cleanup(struct obd_device *obd)
599 DECLARE_LU_VARS(ldt, d);
604 ldt = obd->obd_type->typ_lu;
606 if (ldt != NULL && d != NULL) {
609 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
611 ldt->ldt_ops->ldto_device_free(&env, d);
613 obd->obd_lu_dev = NULL;
616 OBD_CHECK_DT_OP(obd, cleanup, 0);
617 OBD_COUNTER_INCREMENT(obd, cleanup);
619 rc = OBP(obd, cleanup)(obd);
623 static inline void obd_cleanup_client_import(struct obd_device *obd)
627 /* If we set up but never connected, the
628 client import will not have been cleaned. */
629 cfs_down_write(&obd->u.cli.cl_sem);
630 if (obd->u.cli.cl_import) {
631 struct obd_import *imp;
632 imp = obd->u.cli.cl_import;
633 CDEBUG(D_CONFIG, "%s: client import never connected\n",
635 ptlrpc_invalidate_import(imp);
636 if (imp->imp_rq_pool) {
637 ptlrpc_free_rq_pool(imp->imp_rq_pool);
638 imp->imp_rq_pool = NULL;
640 class_destroy_import(imp);
641 obd->u.cli.cl_import = NULL;
643 cfs_up_write(&obd->u.cli.cl_sem);
649 obd_process_config(struct obd_device *obd, int datalen, void *data)
652 DECLARE_LU_VARS(ldt, d);
657 obd->obd_process_conf = 1;
658 ldt = obd->obd_type->typ_lu;
660 if (ldt != NULL && d != NULL) {
663 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
665 rc = d->ld_ops->ldo_process_config(&env, d, data);
669 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
670 rc = OBP(obd, process_config)(obd, datalen, data);
672 OBD_COUNTER_INCREMENT(obd, process_config);
673 obd->obd_process_conf = 0;
678 /* Pack an in-memory MD struct for storage on disk.
679 * Returns +ve size of packed MD (0 for free), or -ve error.
681 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
682 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
683 * If @*disk_tgt == NULL, it will be allocated
685 static inline int obd_packmd(struct obd_export *exp,
686 struct lov_mds_md **disk_tgt,
687 struct lov_stripe_md *mem_src)
692 EXP_CHECK_DT_OP(exp, packmd);
693 EXP_COUNTER_INCREMENT(exp, packmd);
695 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
699 static inline int obd_size_diskmd(struct obd_export *exp,
700 struct lov_stripe_md *mem_src)
702 return obd_packmd(exp, NULL, mem_src);
705 /* helper functions */
706 static inline int obd_alloc_diskmd(struct obd_export *exp,
707 struct lov_mds_md **disk_tgt)
710 LASSERT(*disk_tgt == NULL);
711 return obd_packmd(exp, disk_tgt, NULL);
714 static inline int obd_free_diskmd(struct obd_export *exp,
715 struct lov_mds_md **disk_tgt)
719 return obd_packmd(exp, disk_tgt, NULL);
722 /* Unpack an MD struct from disk to in-memory format.
723 * Returns +ve size of unpacked MD (0 for free), or -ve error.
725 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
726 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
727 * If @*mem_tgt == NULL, it will be allocated
729 static inline int obd_unpackmd(struct obd_export *exp,
730 struct lov_stripe_md **mem_tgt,
731 struct lov_mds_md *disk_src,
737 EXP_CHECK_DT_OP(exp, unpackmd);
738 EXP_COUNTER_INCREMENT(exp, unpackmd);
740 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
744 /* helper functions */
745 static inline int obd_alloc_memmd(struct obd_export *exp,
746 struct lov_stripe_md **mem_tgt)
749 LASSERT(*mem_tgt == NULL);
750 return obd_unpackmd(exp, mem_tgt, NULL, 0);
753 static inline int obd_free_memmd(struct obd_export *exp,
754 struct lov_stripe_md **mem_tgt)
760 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
765 static inline int obd_precreate(struct obd_export *exp)
770 EXP_CHECK_DT_OP(exp, precreate);
771 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
773 rc = OBP(exp->exp_obd, precreate)(exp);
777 static inline int obd_create_async(struct obd_export *exp,
778 struct obd_info *oinfo,
779 struct lov_stripe_md **ea,
780 struct obd_trans_info *oti)
785 EXP_CHECK_DT_OP(exp, create_async);
786 EXP_COUNTER_INCREMENT(exp, create_async);
788 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
792 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
793 struct lov_stripe_md **ea,
794 struct obd_trans_info *oti)
799 EXP_CHECK_DT_OP(exp, create);
800 EXP_COUNTER_INCREMENT(exp, create);
802 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
806 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
807 struct lov_stripe_md *ea,
808 struct obd_trans_info *oti,
809 struct obd_export *md_exp, void *capa)
814 EXP_CHECK_DT_OP(exp, destroy);
815 EXP_COUNTER_INCREMENT(exp, destroy);
817 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
821 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
826 EXP_CHECK_DT_OP(exp, getattr);
827 EXP_COUNTER_INCREMENT(exp, getattr);
829 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
833 static inline int obd_getattr_async(struct obd_export *exp,
834 struct obd_info *oinfo,
835 struct ptlrpc_request_set *set)
840 EXP_CHECK_DT_OP(exp, getattr_async);
841 EXP_COUNTER_INCREMENT(exp, getattr_async);
843 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
847 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
848 struct obd_trans_info *oti)
853 EXP_CHECK_DT_OP(exp, setattr);
854 EXP_COUNTER_INCREMENT(exp, setattr);
856 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
860 /* This performs all the requests set init/wait/destroy actions. */
861 static inline int obd_setattr_rqset(struct obd_export *exp,
862 struct obd_info *oinfo,
863 struct obd_trans_info *oti)
865 struct ptlrpc_request_set *set = NULL;
869 EXP_CHECK_DT_OP(exp, setattr_async);
870 EXP_COUNTER_INCREMENT(exp, setattr_async);
872 set = ptlrpc_prep_set();
876 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
878 rc = ptlrpc_set_wait(set);
879 ptlrpc_set_destroy(set);
883 /* This adds all the requests into @set if @set != NULL, otherwise
884 all requests are sent asynchronously without waiting for response. */
885 static inline int obd_setattr_async(struct obd_export *exp,
886 struct obd_info *oinfo,
887 struct obd_trans_info *oti,
888 struct ptlrpc_request_set *set)
893 EXP_CHECK_DT_OP(exp, setattr_async);
894 EXP_COUNTER_INCREMENT(exp, setattr_async);
896 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
900 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
903 struct obd_device *obd = imp->imp_obd;
907 OBD_CHECK_DEV_ACTIVE(obd);
908 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
909 OBD_COUNTER_INCREMENT(obd, add_conn);
911 rc = OBP(obd, add_conn)(imp, uuid, priority);
915 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
917 struct obd_device *obd = imp->imp_obd;
921 OBD_CHECK_DEV_ACTIVE(obd);
922 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
923 OBD_COUNTER_INCREMENT(obd, del_conn);
925 rc = OBP(obd, del_conn)(imp, uuid);
929 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
931 struct obd_uuid *uuid;
934 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
935 EXP_COUNTER_INCREMENT(exp, get_uuid);
937 uuid = OBP(exp->exp_obd, get_uuid)(exp);
941 /** Create a new /a exp on device /a obd for the uuid /a cluuid
942 * @param exp New export handle
943 * @param d Connect data, supported flags are set, flags also understood
944 * by obd are returned.
946 static inline int obd_connect(const struct lu_env *env,
947 struct obd_export **exp,struct obd_device *obd,
948 struct obd_uuid *cluuid,
949 struct obd_connect_data *data,
953 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
957 OBD_CHECK_DEV_ACTIVE(obd);
958 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
959 OBD_COUNTER_INCREMENT(obd, connect);
961 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
962 /* check that only subset is granted */
963 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
964 data->ocd_connect_flags));
968 static inline int obd_reconnect(const struct lu_env *env,
969 struct obd_export *exp,
970 struct obd_device *obd,
971 struct obd_uuid *cluuid,
972 struct obd_connect_data *d,
976 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
981 OBD_CHECK_DEV_ACTIVE(obd);
982 OBD_CHECK_DT_OP(obd, reconnect, 0);
983 OBD_COUNTER_INCREMENT(obd, reconnect);
985 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
986 /* check that only subset is granted */
987 LASSERT(ergo(d != NULL,
988 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
992 static inline int obd_disconnect(struct obd_export *exp)
997 EXP_CHECK_DT_OP(exp, disconnect);
998 EXP_COUNTER_INCREMENT(exp, disconnect);
1000 rc = OBP(exp->exp_obd, disconnect)(exp);
1004 static inline int obd_fid_init(struct obd_export *exp)
1009 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
1010 EXP_COUNTER_INCREMENT(exp, fid_init);
1012 rc = OBP(exp->exp_obd, fid_init)(exp);
1016 static inline int obd_fid_fini(struct obd_export *exp)
1021 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
1022 EXP_COUNTER_INCREMENT(exp, fid_fini);
1024 rc = OBP(exp->exp_obd, fid_fini)(exp);
1028 static inline int obd_fid_alloc(struct obd_export *exp,
1030 struct md_op_data *op_data)
1035 EXP_CHECK_DT_OP(exp, fid_alloc);
1036 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1038 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
1042 static inline int obd_fid_delete(struct obd_export *exp,
1043 const struct lu_fid *fid)
1048 EXP_CHECK_DT_OP(exp, fid_delete);
1049 EXP_COUNTER_INCREMENT(exp, fid_delete);
1051 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
1055 static inline int obd_ping(struct obd_export *exp)
1060 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1061 EXP_COUNTER_INCREMENT(exp, ping);
1063 rc = OBP(exp->exp_obd, ping)(exp);
1067 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1072 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1073 OBD_COUNTER_INCREMENT(obd, pool_new);
1075 rc = OBP(obd, pool_new)(obd, poolname);
1079 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1084 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1085 OBD_COUNTER_INCREMENT(obd, pool_del);
1087 rc = OBP(obd, pool_del)(obd, poolname);
1091 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1096 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1097 OBD_COUNTER_INCREMENT(obd, pool_add);
1099 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1103 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1108 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1109 OBD_COUNTER_INCREMENT(obd, pool_rem);
1111 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1115 static inline void obd_getref(struct obd_device *obd)
1118 if (OBT(obd) && OBP(obd, getref)) {
1119 OBD_COUNTER_INCREMENT(obd, getref);
1120 OBP(obd, getref)(obd);
1125 static inline void obd_putref(struct obd_device *obd)
1128 if (OBT(obd) && OBP(obd, putref)) {
1129 OBD_COUNTER_INCREMENT(obd, putref);
1130 OBP(obd, putref)(obd);
1135 static inline int obd_init_export(struct obd_export *exp)
1140 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1141 OBP((exp)->exp_obd, init_export))
1142 rc = OBP(exp->exp_obd, init_export)(exp);
1146 static inline int obd_destroy_export(struct obd_export *exp)
1149 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1150 OBP((exp)->exp_obd, destroy_export))
1151 OBP(exp->exp_obd, destroy_export)(exp);
1155 static inline int obd_extent_calc(struct obd_export *exp,
1156 struct lov_stripe_md *md,
1157 int cmd, obd_off *offset)
1161 EXP_CHECK_DT_OP(exp, extent_calc);
1162 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1166 static inline struct dentry *
1167 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1169 LASSERT(exp->exp_obd);
1171 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1176 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1178 LASSERT(exp->exp_obd);
1179 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1181 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1182 dentry, exp->exp_obd);
1187 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1188 * If the cache is older than @max_age we will get a new value from the
1189 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1190 static inline int obd_statfs_async(struct obd_device *obd,
1191 struct obd_info *oinfo,
1193 struct ptlrpc_request_set *rqset)
1201 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1202 OBD_COUNTER_INCREMENT(obd, statfs);
1204 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1205 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1206 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1207 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1209 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1210 " objects "LPU64"/"LPU64"\n",
1211 obd->obd_name, &obd->obd_osfs,
1212 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1213 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1214 cfs_spin_lock(&obd->obd_osfs_lock);
1215 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1216 cfs_spin_unlock(&obd->obd_osfs_lock);
1217 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1218 if (oinfo->oi_cb_up)
1219 oinfo->oi_cb_up(oinfo, 0);
1224 static inline int obd_statfs_rqset(struct obd_device *obd,
1225 struct obd_statfs *osfs, __u64 max_age,
1228 struct ptlrpc_request_set *set = NULL;
1229 struct obd_info oinfo = { { { 0 } } };
1233 set = ptlrpc_prep_set();
1237 oinfo.oi_osfs = osfs;
1238 oinfo.oi_flags = flags;
1239 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1241 rc = ptlrpc_set_wait(set);
1242 ptlrpc_set_destroy(set);
1246 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1247 * If the cache is older than @max_age we will get a new value from the
1248 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1249 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1250 __u64 max_age, __u32 flags)
1258 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1259 OBD_COUNTER_INCREMENT(obd, statfs);
1261 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1262 obd->obd_osfs_age, max_age);
1263 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1264 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1266 cfs_spin_lock(&obd->obd_osfs_lock);
1267 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1268 obd->obd_osfs_age = cfs_time_current_64();
1269 cfs_spin_unlock(&obd->obd_osfs_lock);
1272 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1273 " objects "LPU64"/"LPU64"\n",
1274 obd->obd_name, &obd->obd_osfs,
1275 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1276 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1277 cfs_spin_lock(&obd->obd_osfs_lock);
1278 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1279 cfs_spin_unlock(&obd->obd_osfs_lock);
1284 static inline int obd_sync_rqset(struct obd_export *exp, struct obd_info *oinfo,
1285 obd_size start, obd_size end)
1287 struct ptlrpc_request_set *set = NULL;
1291 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1292 EXP_COUNTER_INCREMENT(exp, sync);
1294 set = ptlrpc_prep_set();
1298 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1300 rc = ptlrpc_set_wait(set);
1301 ptlrpc_set_destroy(set);
1305 static inline int obd_sync(struct obd_export *exp, struct obd_info *oinfo,
1306 obd_size start, obd_size end,
1307 struct ptlrpc_request_set *set)
1312 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1313 EXP_COUNTER_INCREMENT(exp, sync);
1315 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1319 static inline int obd_punch_rqset(struct obd_export *exp,
1320 struct obd_info *oinfo,
1321 struct obd_trans_info *oti)
1323 struct ptlrpc_request_set *set = NULL;
1327 EXP_CHECK_DT_OP(exp, punch);
1328 EXP_COUNTER_INCREMENT(exp, punch);
1330 set = ptlrpc_prep_set();
1334 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1336 rc = ptlrpc_set_wait(set);
1337 ptlrpc_set_destroy(set);
1341 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1342 struct obd_trans_info *oti,
1343 struct ptlrpc_request_set *rqset)
1348 EXP_CHECK_DT_OP(exp, punch);
1349 EXP_COUNTER_INCREMENT(exp, punch);
1351 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1355 static inline int obd_brw(int cmd, struct obd_export *exp,
1356 struct obd_info *oinfo, obd_count oa_bufs,
1357 struct brw_page *pg, struct obd_trans_info *oti)
1362 EXP_CHECK_DT_OP(exp, brw);
1363 EXP_COUNTER_INCREMENT(exp, brw);
1365 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1366 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1367 "or OBD_BRW_CHECK\n");
1371 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1375 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1376 int objcount, struct obd_ioobj *obj,
1377 struct niobuf_remote *remote, int *pages,
1378 struct niobuf_local *local,
1379 struct obd_trans_info *oti,
1380 struct lustre_capa *capa)
1385 EXP_CHECK_DT_OP(exp, preprw);
1386 EXP_COUNTER_INCREMENT(exp, preprw);
1388 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1389 pages, local, oti, capa);
1393 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1394 int objcount, struct obd_ioobj *obj,
1395 struct niobuf_remote *rnb, int pages,
1396 struct niobuf_local *local,
1397 struct obd_trans_info *oti, int rc)
1401 EXP_CHECK_DT_OP(exp, commitrw);
1402 EXP_COUNTER_INCREMENT(exp, commitrw);
1404 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1405 rnb, pages, local, oti, rc);
1409 static inline int obd_merge_lvb(struct obd_export *exp,
1410 struct lov_stripe_md *lsm,
1411 struct ost_lvb *lvb, int kms_only)
1416 EXP_CHECK_DT_OP(exp, merge_lvb);
1417 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1419 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1423 static inline int obd_adjust_kms(struct obd_export *exp,
1424 struct lov_stripe_md *lsm, obd_off size,
1430 EXP_CHECK_DT_OP(exp, adjust_kms);
1431 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1433 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1437 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1438 int len, void *karg, void *uarg)
1443 EXP_CHECK_DT_OP(exp, iocontrol);
1444 EXP_COUNTER_INCREMENT(exp, iocontrol);
1446 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1450 static inline int obd_enqueue_rqset(struct obd_export *exp,
1451 struct obd_info *oinfo,
1452 struct ldlm_enqueue_info *einfo)
1454 struct ptlrpc_request_set *set = NULL;
1458 EXP_CHECK_DT_OP(exp, enqueue);
1459 EXP_COUNTER_INCREMENT(exp, enqueue);
1461 set = ptlrpc_prep_set();
1465 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1467 rc = ptlrpc_set_wait(set);
1468 ptlrpc_set_destroy(set);
1472 static inline int obd_enqueue(struct obd_export *exp,
1473 struct obd_info *oinfo,
1474 struct ldlm_enqueue_info *einfo,
1475 struct ptlrpc_request_set *set)
1480 EXP_CHECK_DT_OP(exp, enqueue);
1481 EXP_COUNTER_INCREMENT(exp, enqueue);
1483 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1487 static inline int obd_change_cbdata(struct obd_export *exp,
1488 struct lov_stripe_md *lsm,
1489 ldlm_iterator_t it, void *data)
1494 EXP_CHECK_DT_OP(exp, change_cbdata);
1495 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1497 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1501 static inline int obd_find_cbdata(struct obd_export *exp,
1502 struct lov_stripe_md *lsm,
1503 ldlm_iterator_t it, void *data)
1508 EXP_CHECK_DT_OP(exp, find_cbdata);
1509 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1511 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1515 static inline int obd_cancel(struct obd_export *exp,
1516 struct lov_stripe_md *ea, __u32 mode,
1517 struct lustre_handle *lockh)
1522 EXP_CHECK_DT_OP(exp, cancel);
1523 EXP_COUNTER_INCREMENT(exp, cancel);
1525 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1529 static inline int obd_cancel_unused(struct obd_export *exp,
1530 struct lov_stripe_md *ea,
1531 ldlm_cancel_flags_t flags,
1537 EXP_CHECK_DT_OP(exp, cancel_unused);
1538 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1540 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1544 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1545 struct obd_capa *oc, struct obd_client_handle *handle,
1551 EXP_CHECK_DT_OP(exp, pin);
1552 EXP_COUNTER_INCREMENT(exp, pin);
1554 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1558 static inline int obd_unpin(struct obd_export *exp,
1559 struct obd_client_handle *handle, int flag)
1564 EXP_CHECK_DT_OP(exp, unpin);
1565 EXP_COUNTER_INCREMENT(exp, unpin);
1567 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1572 static inline void obd_import_event(struct obd_device *obd,
1573 struct obd_import *imp,
1574 enum obd_import_event event)
1578 CERROR("NULL device\n");
1582 if (obd->obd_set_up && OBP(obd, import_event)) {
1583 OBD_COUNTER_INCREMENT(obd, import_event);
1584 OBP(obd, import_event)(obd, imp, event);
1589 static inline int obd_llog_connect(struct obd_export *exp,
1590 struct llogd_conn_body *body)
1595 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1596 EXP_COUNTER_INCREMENT(exp, llog_connect);
1598 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1603 static inline int obd_notify(struct obd_device *obd,
1604 struct obd_device *watched,
1605 enum obd_notify_event ev,
1612 /* the check for async_recov is a complete hack - I'm hereby
1613 overloading the meaning to also mean "this was called from
1614 mds_postsetup". I know that my mds is able to handle notifies
1615 by this point, and it needs to get them to execute mds_postrecov. */
1616 if (!obd->obd_set_up && !obd->obd_async_recov) {
1617 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1621 if (!OBP(obd, notify)) {
1622 CERROR("obd %s has no notify handler\n", obd->obd_name);
1626 OBD_COUNTER_INCREMENT(obd, notify);
1627 rc = OBP(obd, notify)(obd, watched, ev, data);
1631 static inline int obd_notify_observer(struct obd_device *observer,
1632 struct obd_device *observed,
1633 enum obd_notify_event ev,
1639 struct obd_notify_upcall *onu;
1641 if (observer->obd_observer)
1642 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1646 * Also, call non-obd listener, if any
1648 onu = &observer->obd_upcall;
1649 if (onu->onu_upcall != NULL)
1650 rc2 = onu->onu_upcall(observer, observed, ev,
1651 onu->onu_owner, NULL);
1655 return rc1 ? rc1 : rc2;
1658 static inline int obd_quotacheck(struct obd_export *exp,
1659 struct obd_quotactl *oqctl)
1664 EXP_CHECK_DT_OP(exp, quotacheck);
1665 EXP_COUNTER_INCREMENT(exp, quotacheck);
1667 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1671 static inline int obd_quotactl(struct obd_export *exp,
1672 struct obd_quotactl *oqctl)
1677 EXP_CHECK_DT_OP(exp, quotactl);
1678 EXP_COUNTER_INCREMENT(exp, quotactl);
1680 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1684 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1685 struct quota_adjust_qunit *oqaq,
1686 struct lustre_quota_ctxt *qctxt,
1687 struct ptlrpc_request_set *set)
1689 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1690 struct timeval work_start;
1691 struct timeval work_end;
1697 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1699 cfs_gettimeofday(&work_start);
1701 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1702 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1704 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt, set);
1706 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1708 cfs_gettimeofday(&work_end);
1709 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1710 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1717 static inline int obd_health_check(struct obd_device *obd)
1719 /* returns: 0 on healthy
1720 * >0 on unhealthy + reason code/flag
1721 * however the only suppored reason == 1 right now
1722 * We'll need to define some better reasons
1723 * or flags in the future.
1729 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1730 if (obd == NULL || !OBT(obd)) {
1731 CERROR("cleaned up obd\n");
1732 RETURN(-EOPNOTSUPP);
1734 if (!obd->obd_set_up || obd->obd_stopping)
1736 if (!OBP(obd, health_check))
1739 rc = OBP(obd, health_check)(obd);
1743 static inline int obd_register_observer(struct obd_device *obd,
1744 struct obd_device *observer)
1748 cfs_down_write(&obd->obd_observer_link_sem);
1749 if (obd->obd_observer && observer) {
1750 cfs_up_write(&obd->obd_observer_link_sem);
1753 obd->obd_observer = observer;
1754 cfs_up_write(&obd->obd_observer_link_sem);
1758 static inline int obd_pin_observer(struct obd_device *obd,
1759 struct obd_device **observer)
1762 cfs_down_read(&obd->obd_observer_link_sem);
1763 if (!obd->obd_observer) {
1765 cfs_up_read(&obd->obd_observer_link_sem);
1768 *observer = obd->obd_observer;
1772 static inline int obd_unpin_observer(struct obd_device *obd)
1775 cfs_up_read(&obd->obd_observer_link_sem);
1780 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1781 obd_page_removal_cb_t cb,
1782 obd_pin_extent_cb pin_cb)
1787 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1788 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1790 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1794 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1795 obd_page_removal_cb_t cb)
1800 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1801 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1803 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1807 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1808 obd_lock_cancel_cb cb)
1813 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1814 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1816 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1820 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1821 obd_lock_cancel_cb cb)
1826 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1827 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1829 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1834 /* metadata helpers */
1835 static inline int md_getstatus(struct obd_export *exp,
1836 struct lu_fid *fid, struct obd_capa **pc)
1841 EXP_CHECK_MD_OP(exp, getstatus);
1842 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1843 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1847 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1848 struct ptlrpc_request **request)
1852 EXP_CHECK_MD_OP(exp, getattr);
1853 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1854 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1858 static inline int md_change_cbdata(struct obd_export *exp,
1859 const struct lu_fid *fid,
1860 ldlm_iterator_t it, void *data)
1864 EXP_CHECK_MD_OP(exp, change_cbdata);
1865 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1866 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1870 static inline int md_find_cbdata(struct obd_export *exp,
1871 const struct lu_fid *fid,
1872 ldlm_iterator_t it, void *data)
1876 EXP_CHECK_MD_OP(exp, find_cbdata);
1877 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1878 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1882 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1883 struct md_open_data *mod,
1884 struct ptlrpc_request **request)
1888 EXP_CHECK_MD_OP(exp, close);
1889 EXP_MD_COUNTER_INCREMENT(exp, close);
1890 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1894 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1895 const void *data, int datalen, int mode, __u32 uid,
1896 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1897 struct ptlrpc_request **request)
1901 EXP_CHECK_MD_OP(exp, create);
1902 EXP_MD_COUNTER_INCREMENT(exp, create);
1903 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1904 uid, gid, cap_effective, rdev, request);
1908 static inline int md_done_writing(struct obd_export *exp,
1909 struct md_op_data *op_data,
1910 struct md_open_data *mod)
1914 EXP_CHECK_MD_OP(exp, done_writing);
1915 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1916 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1920 static inline int md_enqueue(struct obd_export *exp,
1921 struct ldlm_enqueue_info *einfo,
1922 struct lookup_intent *it,
1923 struct md_op_data *op_data,
1924 struct lustre_handle *lockh,
1925 void *lmm, int lmmsize,
1926 struct ptlrpc_request **req,
1927 int extra_lock_flags)
1931 EXP_CHECK_MD_OP(exp, enqueue);
1932 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1933 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1934 lmm, lmmsize, req, extra_lock_flags);
1938 static inline int md_getattr_name(struct obd_export *exp,
1939 struct md_op_data *op_data,
1940 struct ptlrpc_request **request)
1944 EXP_CHECK_MD_OP(exp, getattr_name);
1945 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1946 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1950 static inline int md_intent_lock(struct obd_export *exp,
1951 struct md_op_data *op_data, void *lmm,
1952 int lmmsize, struct lookup_intent *it,
1953 int flags, struct ptlrpc_request **reqp,
1954 ldlm_blocking_callback cb_blocking,
1955 int extra_lock_flags)
1959 EXP_CHECK_MD_OP(exp, intent_lock);
1960 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1961 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1962 it, flags, reqp, cb_blocking,
1967 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1968 struct ptlrpc_request **request)
1972 EXP_CHECK_MD_OP(exp, link);
1973 EXP_MD_COUNTER_INCREMENT(exp, link);
1974 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1978 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1979 const char *old, int oldlen, const char *new,
1980 int newlen, struct ptlrpc_request **request)
1984 EXP_CHECK_MD_OP(exp, rename);
1985 EXP_MD_COUNTER_INCREMENT(exp, rename);
1986 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1991 static inline int md_is_subdir(struct obd_export *exp,
1992 const struct lu_fid *pfid,
1993 const struct lu_fid *cfid,
1994 struct ptlrpc_request **request)
1998 EXP_CHECK_MD_OP(exp, is_subdir);
1999 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
2000 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
2004 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
2005 void *ea, int ealen, void *ea2, int ea2len,
2006 struct ptlrpc_request **request,
2007 struct md_open_data **mod)
2011 EXP_CHECK_MD_OP(exp, setattr);
2012 EXP_MD_COUNTER_INCREMENT(exp, setattr);
2013 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
2014 ea2, ea2len, request, mod);
2018 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
2019 struct obd_capa *oc, struct ptlrpc_request **request)
2023 EXP_CHECK_MD_OP(exp, sync);
2024 EXP_MD_COUNTER_INCREMENT(exp, sync);
2025 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
2029 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
2030 struct obd_capa *oc, __u64 offset,
2031 struct page **pages, unsigned npages,
2032 struct ptlrpc_request **request)
2036 EXP_CHECK_MD_OP(exp, readpage);
2037 EXP_MD_COUNTER_INCREMENT(exp, readpage);
2038 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, pages, npages,
2043 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
2044 struct ptlrpc_request **request)
2048 EXP_CHECK_MD_OP(exp, unlink);
2049 EXP_MD_COUNTER_INCREMENT(exp, unlink);
2050 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
2054 static inline int md_get_lustre_md(struct obd_export *exp,
2055 struct ptlrpc_request *req,
2056 struct obd_export *dt_exp,
2057 struct obd_export *md_exp,
2058 struct lustre_md *md)
2061 EXP_CHECK_MD_OP(exp, get_lustre_md);
2062 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
2063 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
2066 static inline int md_free_lustre_md(struct obd_export *exp,
2067 struct lustre_md *md)
2070 EXP_CHECK_MD_OP(exp, free_lustre_md);
2071 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
2072 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
2075 static inline int md_setxattr(struct obd_export *exp,
2076 const struct lu_fid *fid, struct obd_capa *oc,
2077 obd_valid valid, const char *name,
2078 const char *input, int input_size,
2079 int output_size, int flags, __u32 suppgid,
2080 struct ptlrpc_request **request)
2083 EXP_CHECK_MD_OP(exp, setxattr);
2084 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
2085 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
2086 input_size, output_size, flags,
2090 static inline int md_getxattr(struct obd_export *exp,
2091 const struct lu_fid *fid, struct obd_capa *oc,
2092 obd_valid valid, const char *name,
2093 const char *input, int input_size,
2094 int output_size, int flags,
2095 struct ptlrpc_request **request)
2098 EXP_CHECK_MD_OP(exp, getxattr);
2099 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
2100 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
2101 input_size, output_size, flags,
2105 static inline int md_set_open_replay_data(struct obd_export *exp,
2106 struct obd_client_handle *och,
2107 struct ptlrpc_request *open_req)
2110 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2111 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2112 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2115 static inline int md_clear_open_replay_data(struct obd_export *exp,
2116 struct obd_client_handle *och)
2119 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2120 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2121 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2124 static inline int md_set_lock_data(struct obd_export *exp,
2125 __u64 *lockh, void *data, __u32 *bits)
2128 EXP_CHECK_MD_OP(exp, set_lock_data);
2129 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2130 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
2133 static inline int md_cancel_unused(struct obd_export *exp,
2134 const struct lu_fid *fid,
2135 ldlm_policy_data_t *policy,
2137 ldlm_cancel_flags_t flags,
2143 EXP_CHECK_MD_OP(exp, cancel_unused);
2144 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2146 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2151 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2152 const struct lu_fid *fid,
2154 ldlm_policy_data_t *policy,
2156 struct lustre_handle *lockh)
2159 EXP_CHECK_MD_OP(exp, lock_match);
2160 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2161 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2162 policy, mode, lockh));
2165 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2166 int def_asize, int cookiesize)
2169 EXP_CHECK_MD_OP(exp, init_ea_size);
2170 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2171 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2175 static inline int md_get_remote_perm(struct obd_export *exp,
2176 const struct lu_fid *fid,
2177 struct obd_capa *oc, __u32 suppgid,
2178 struct ptlrpc_request **request)
2181 EXP_CHECK_MD_OP(exp, get_remote_perm);
2182 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2183 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2187 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2192 EXP_CHECK_MD_OP(exp, renew_capa);
2193 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2194 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2198 static inline int md_unpack_capa(struct obd_export *exp,
2199 struct ptlrpc_request *req,
2200 const struct req_msg_field *field,
2201 struct obd_capa **oc)
2205 EXP_CHECK_MD_OP(exp, unpack_capa);
2206 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2207 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2211 static inline int md_intent_getattr_async(struct obd_export *exp,
2212 struct md_enqueue_info *minfo,
2213 struct ldlm_enqueue_info *einfo)
2217 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2218 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2219 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2223 static inline int md_revalidate_lock(struct obd_export *exp,
2224 struct lookup_intent *it,
2229 EXP_CHECK_MD_OP(exp, revalidate_lock);
2230 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2231 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2236 /* OBD Metadata Support */
2238 extern int obd_init_caches(void);
2239 extern void obd_cleanup_caches(void);
2241 /* support routines */
2242 extern cfs_mem_cache_t *obdo_cachep;
2244 #define OBDO_ALLOC(ptr) \
2246 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, CFS_ALLOC_IO); \
2249 #define OBDO_FREE(ptr) \
2251 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2255 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2257 /* something here */
2260 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2262 /* something here */
2265 /* I'm as embarrassed about this as you are.
2267 * <shaver> // XXX do not look into _superhack with remaining eye
2268 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2269 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2272 extern void obd_sysctl_init (void);
2273 extern void obd_sysctl_clean (void);
2276 typedef __u8 class_uuid_t[16];
2277 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2280 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2281 int class_add_uuid(const char *uuid, __u64 nid);
2282 int class_del_uuid (const char *uuid);
2283 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
2284 void class_init_uuidlist(void);
2285 void class_exit_uuidlist(void);
2288 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2289 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2292 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
2294 #endif /* __LINUX_OBD_CLASS_H */