linux/drivers/staging/lustre/lustre/include/obd_class.h
<<
>>
Prefs
   1/*
   2 * GPL HEADER START
   3 *
   4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5 *
   6 * This program is free software; you can redistribute it and/or modify
   7 * it under the terms of the GNU General Public License version 2 only,
   8 * as published by the Free Software Foundation.
   9 *
  10 * This program is distributed in the hope that it will be useful, but
  11 * WITHOUT ANY WARRANTY; without even the implied warranty of
  12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13 * General Public License version 2 for more details (a copy is included
  14 * in the LICENSE file that accompanied this code).
  15 *
  16 * You should have received a copy of the GNU General Public License
  17 * version 2 along with this program; If not, see
  18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
  19 *
  20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  21 * CA 95054 USA or visit www.sun.com if you need additional information or
  22 * have any questions.
  23 *
  24 * GPL HEADER END
  25 */
  26/*
  27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  28 * Use is subject to license terms.
  29 *
  30 * Copyright (c) 2011, 2012, Intel Corporation.
  31 */
  32/*
  33 * This file is part of Lustre, http://www.lustre.org/
  34 * Lustre is a trademark of Sun Microsystems, Inc.
  35 */
  36#ifndef __CLASS_OBD_H
  37#define __CLASS_OBD_H
  38
  39
  40#include "obd_support.h"
  41#include "lustre_import.h"
  42#include "lustre_net.h"
  43#include "obd.h"
  44#include "lustre_lib.h"
  45#include "lustre/lustre_idl.h"
  46#include "lprocfs_status.h"
  47
  48#define OBD_STATFS_NODELAY      0x0001  /* requests should be send without delay
  49                                         * and resends for avoid deadlocks */
  50#define OBD_STATFS_FROM_CACHE   0x0002  /* the statfs callback should not update
  51                                         * obd_osfs_age */
  52#define OBD_STATFS_PTLRPCD      0x0004  /* requests will be sent via ptlrpcd
  53                                         * instead of a specific set. This
  54                                         * means that we cannot rely on the set
  55                                         * interpret routine to be called.
  56                                         * lov_statfs_fini() must thus be called
  57                                         * by the request interpret routine */
  58#define OBD_STATFS_FOR_MDT0     0x0008  /* The statfs is only for retrieving
  59                                         * information from MDT0. */
  60#define OBD_FL_PUNCH    0x00000001      /* To indicate it is punch operation */
  61
  62/* OBD Device Declarations */
  63extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
  64extern rwlock_t obd_dev_lock;
  65
  66/* OBD Operations Declarations */
  67extern struct obd_device *class_conn2obd(struct lustre_handle *);
  68extern struct obd_device *class_exp2obd(struct obd_export *);
  69extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
  70extern int lustre_get_jobid(char *jobid);
  71
  72struct lu_device_type;
  73
  74/* genops.c */
  75extern struct list_head obd_types;
  76struct obd_export *class_conn2export(struct lustre_handle *);
  77int class_register_type(struct obd_ops *, struct md_ops *,
  78                        const char *nm, struct lu_device_type *ldt);
  79int class_unregister_type(const char *nm);
  80
  81struct obd_device *class_newdev(const char *type_name, const char *name);
  82void class_release_dev(struct obd_device *obd);
  83
  84int class_name2dev(const char *name);
  85struct obd_device *class_name2obd(const char *name);
  86int class_uuid2dev(struct obd_uuid *uuid);
  87struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
  88void class_obd_list(void);
  89struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
  90                                          const char *typ_name,
  91                                          struct obd_uuid *grp_uuid);
  92struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid,
  93                                           int *next);
  94struct obd_device *class_num2obd(int num);
  95int get_devices_count(void);
  96
  97int class_notify_sptlrpc_conf(const char *fsname, int namelen);
  98
  99char *obd_export_nid2str(struct obd_export *exp);
 100
 101int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
 102int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
 103int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
 104
 105int obd_zombie_impexp_init(void);
 106void obd_zombie_impexp_stop(void);
 107void obd_zombie_impexp_cull(void);
 108void obd_zombie_barrier(void);
 109void obd_exports_barrier(struct obd_device *obd);
 110int kuc_len(int payload_len);
 111struct kuc_hdr *kuc_ptr(void *p);
 112int kuc_ispayload(void *p);
 113void *kuc_alloc(int payload_len, int transport, int type);
 114void kuc_free(void *p, int payload_len);
 115
 116struct llog_handle;
 117struct llog_rec_hdr;
 118typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
 119                         struct llog_rec_hdr *, void *);
 120/* obd_config.c */
 121struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
 122                                     const char *new_name);
 123int class_process_config(struct lustre_cfg *lcfg);
 124int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
 125                             struct lustre_cfg *lcfg, void *data);
 126int class_attach(struct lustre_cfg *lcfg);
 127int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
 128int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
 129int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
 130struct obd_device *class_incref(struct obd_device *obd,
 131                                const char *scope, const void *source);
 132void class_decref(struct obd_device *obd,
 133                  const char *scope, const void *source);
 134void dump_exports(struct obd_device *obd, int locks);
 135int class_config_llog_handler(const struct lu_env *env,
 136                              struct llog_handle *handle,
 137                              struct llog_rec_hdr *rec, void *data);
 138int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
 139int class_add_uuid(const char *uuid, __u64 nid);
 140
 141/*obdecho*/
 142extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
 143
 144#define CFG_F_START     0x01   /* Set when we start updating from a log */
 145#define CFG_F_MARKER    0x02   /* We are within a maker */
 146#define CFG_F_SKIP      0x04   /* We should ignore this cfg command */
 147#define CFG_F_COMPAT146 0x08   /* Allow old-style logs */
 148#define CFG_F_EXCLUDE   0x10   /* OST exclusion list */
 149
 150/* Passed as data param to class_config_parse_llog */
 151struct config_llog_instance {
 152        char           *cfg_obdname;
 153        void           *cfg_instance;
 154        struct super_block *cfg_sb;
 155        struct obd_uuid     cfg_uuid;
 156        llog_cb_t           cfg_callback;
 157        int              cfg_last_idx; /* for partial llog processing */
 158        int              cfg_flags;
 159};
 160int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
 161                            char *name, struct config_llog_instance *cfg);
 162int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
 163                           char *name, struct config_llog_instance *cfg);
 164
 165enum {
 166        CONFIG_T_CONFIG  = 0,
 167        CONFIG_T_SPTLRPC = 1,
 168        CONFIG_T_RECOVER = 2,
 169        CONFIG_T_PARAMS  = 3,
 170        CONFIG_T_MAX     = 4
 171};
 172
 173#define PARAMS_FILENAME "params"
 174#define LCTL_UPCALL     "lctl"
 175
 176/* list of active configuration logs  */
 177struct config_llog_data {
 178        struct ldlm_res_id        cld_resid;
 179        struct config_llog_instance cld_cfg;
 180        struct list_head                  cld_list_chain;
 181        atomic_t                cld_refcount;
 182        struct config_llog_data    *cld_sptlrpc;/* depended sptlrpc log */
 183        struct config_llog_data    *cld_params; /* common parameters log */
 184        struct config_llog_data    *cld_recover;/* imperative recover log */
 185        struct obd_export         *cld_mgcexp;
 186        struct mutex                cld_lock;
 187        int                      cld_type;
 188        unsigned int            cld_stopping:1, /* we were told to stop
 189                                                     * watching */
 190                                    cld_lostlock:1; /* lock not requeued */
 191        char                    cld_logname[0];
 192};
 193
 194struct lustre_profile {
 195        struct list_head       lp_list;
 196        char        *lp_profile;
 197        char        *lp_dt;
 198        char        *lp_md;
 199};
 200
 201struct lustre_profile *class_get_profile(const char *prof);
 202void class_del_profile(const char *prof);
 203void class_del_profiles(void);
 204
 205#if LUSTRE_TRACKS_LOCK_EXP_REFS
 206
 207void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
 208void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
 209extern void (*class_export_dump_hook)(struct obd_export *);
 210
 211#else
 212
 213#define __class_export_add_lock_ref(exp, lock)       do {} while (0)
 214#define __class_export_del_lock_ref(exp, lock)       do {} while (0)
 215
 216#endif
 217
 218static inline void class_export_rpc_inc(struct obd_export *exp)
 219{
 220        atomic_inc(&(exp)->exp_rpc_count);
 221        CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n",
 222               (exp), atomic_read(&(exp)->exp_rpc_count));
 223}
 224
 225static inline void class_export_rpc_dec(struct obd_export *exp)
 226{
 227        LASSERT_ATOMIC_POS(&exp->exp_rpc_count);
 228        atomic_dec(&(exp)->exp_rpc_count);
 229        CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n",
 230               (exp), atomic_read(&(exp)->exp_rpc_count));
 231}
 232
 233#define class_export_lock_get(exp, lock)                                \
 234({                                                                    \
 235        atomic_inc(&(exp)->exp_locks_count);                    \
 236        __class_export_add_lock_ref(exp, lock);                  \
 237        CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
 238               (exp), atomic_read(&(exp)->exp_locks_count));    \
 239        class_export_get(exp);                                    \
 240})
 241
 242#define class_export_lock_put(exp, lock)                                \
 243({                                                                    \
 244        LASSERT_ATOMIC_POS(&exp->exp_locks_count);                    \
 245        atomic_dec(&(exp)->exp_locks_count);                    \
 246        __class_export_del_lock_ref(exp, lock);                  \
 247        CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
 248               (exp), atomic_read(&(exp)->exp_locks_count));    \
 249        class_export_put(exp);                                    \
 250})
 251
 252#define class_export_cb_get(exp)                                        \
 253({                                                                    \
 254        atomic_inc(&(exp)->exp_cb_count);                          \
 255        CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
 256               (exp), atomic_read(&(exp)->exp_cb_count));          \
 257        class_export_get(exp);                                    \
 258})
 259
 260#define class_export_cb_put(exp)                                        \
 261({                                                                    \
 262        LASSERT_ATOMIC_POS(&exp->exp_cb_count);                  \
 263        atomic_dec(&(exp)->exp_cb_count);                          \
 264        CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
 265               (exp), atomic_read(&(exp)->exp_cb_count));          \
 266        class_export_put(exp);                                    \
 267})
 268
 269/* genops.c */
 270struct obd_export *class_export_get(struct obd_export *exp);
 271void class_export_put(struct obd_export *exp);
 272struct obd_export *class_new_export(struct obd_device *obddev,
 273                                    struct obd_uuid *cluuid);
 274void class_unlink_export(struct obd_export *exp);
 275
 276struct obd_import *class_import_get(struct obd_import *);
 277void class_import_put(struct obd_import *);
 278struct obd_import *class_new_import(struct obd_device *obd);
 279void class_destroy_import(struct obd_import *exp);
 280
 281struct obd_type *class_search_type(const char *name);
 282struct obd_type *class_get_type(const char *name);
 283void class_put_type(struct obd_type *type);
 284int class_connect(struct lustre_handle *conn, struct obd_device *obd,
 285                  struct obd_uuid *cluuid);
 286int class_disconnect(struct obd_export *exp);
 287void class_fail_export(struct obd_export *exp);
 288int class_connected_export(struct obd_export *exp);
 289void class_disconnect_exports(struct obd_device *obddev);
 290int class_manual_cleanup(struct obd_device *obd);
 291void class_disconnect_stale_exports(struct obd_device *,
 292                                    int (*test_export)(struct obd_export *));
 293static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
 294{
 295        return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
 296                (obd->obd_force ? OBD_OPT_FORCE : 0) |
 297                (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
 298                0);
 299}
 300
 301struct inode;
 302struct lu_attr;
 303struct obdo;
 304void obdo_from_la(struct obdo *dst, struct lu_attr *la, __u64 valid);
 305void la_from_obdo(struct lu_attr *la, struct obdo *dst, u32 valid);
 306void obdo_refresh_inode(struct inode *dst, struct obdo *src, u32 valid);
 307void obdo_to_inode(struct inode *dst, struct obdo *src, u32 valid);
 308
 309void obdo_cpy_md(struct obdo *dst, struct obdo *src, u32 valid);
 310void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
 311void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
 312                     unsigned int ia_valid);
 313void iattr_from_obdo(struct iattr *attr, struct obdo *oa, u32 valid);
 314void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, u32 valid);
 315void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
 316                  unsigned int valid);
 317
 318void obdo_cpu_to_le(struct obdo *dobdo, struct obdo *sobdo);
 319void obdo_le_to_cpu(struct obdo *dobdo, struct obdo *sobdo);
 320
 321#define OBT(dev)        (dev)->obd_type
 322#define OBP(dev, op)    (dev)->obd_type->typ_dt_ops->o_ ## op
 323#define MDP(dev, op)    (dev)->obd_type->typ_md_ops->m_ ## op
 324#define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
 325
 326/* Ensure obd_setup: used for cleanup which must be called
 327   while obd is stopping */
 328static inline int obd_check_dev(struct obd_device *obd)
 329{
 330        if (!obd) {
 331                CERROR("NULL device\n");
 332                return -ENODEV;
 333        }
 334        return 0;
 335}
 336
 337/* ensure obd_setup and !obd_stopping */
 338static inline int obd_check_dev_active(struct obd_device *obd)
 339{
 340        int rc;
 341
 342        rc = obd_check_dev(obd);
 343        if (rc)
 344                return rc;
 345        if (!obd->obd_set_up || obd->obd_stopping) {
 346                CERROR("Device %d not setup\n", obd->obd_minor);
 347                return -ENODEV;
 348        }
 349        return rc;
 350}
 351
 352#define OBD_COUNTER_OFFSET(op)                            \
 353        ((offsetof(struct obd_ops, o_ ## op) -            \
 354          offsetof(struct obd_ops, o_iocontrol))                \
 355         / sizeof(((struct obd_ops *)(0))->o_iocontrol))
 356
 357#define OBD_COUNTER_INCREMENT(obdx, op)                    \
 358        if ((obdx)->obd_stats != NULL) {                          \
 359                unsigned int coffset;                        \
 360                coffset = (unsigned int)((obdx)->obd_cntr_base) + \
 361                        OBD_COUNTER_OFFSET(op);            \
 362                LASSERT(coffset < (obdx)->obd_stats->ls_num);     \
 363                lprocfs_counter_incr((obdx)->obd_stats, coffset); \
 364        }
 365
 366#define EXP_COUNTER_INCREMENT(export, op)                                   \
 367        if ((export)->exp_obd->obd_stats != NULL) {                       \
 368                unsigned int coffset;                                   \
 369                coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
 370                        OBD_COUNTER_OFFSET(op);                       \
 371                LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num);     \
 372                lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
 373        }
 374
 375#define MD_COUNTER_OFFSET(op)                              \
 376        ((offsetof(struct md_ops, m_ ## op) -              \
 377          offsetof(struct md_ops, m_getstatus))          \
 378         / sizeof(((struct md_ops *)(0))->m_getstatus))
 379
 380#define MD_COUNTER_INCREMENT(obdx, op)                     \
 381        if ((obd)->md_stats != NULL) {                     \
 382                unsigned int coffset;                       \
 383                coffset = (unsigned int)((obdx)->md_cntr_base) + \
 384                        MD_COUNTER_OFFSET(op);             \
 385                LASSERT(coffset < (obdx)->md_stats->ls_num);     \
 386                lprocfs_counter_incr((obdx)->md_stats, coffset); \
 387        }
 388
 389#define EXP_MD_COUNTER_INCREMENT(export, op)                             \
 390        if ((export)->exp_obd->obd_stats != NULL) {                       \
 391                unsigned int coffset;                                   \
 392                coffset = (unsigned int)((export)->exp_obd->md_cntr_base) +  \
 393                        MD_COUNTER_OFFSET(op);                         \
 394                LASSERT(coffset < (export)->exp_obd->md_stats->ls_num);      \
 395                lprocfs_counter_incr((export)->exp_obd->md_stats, coffset);  \
 396                if ((export)->exp_md_stats != NULL)                       \
 397                        lprocfs_counter_incr(                           \
 398                                (export)->exp_md_stats, coffset);           \
 399        }
 400
 401
 402#define OBD_CHECK_MD_OP(obd, op, err)                      \
 403do {                                                        \
 404        if (!OBT(obd) || !MDP((obd), op)) {                  \
 405                if (err)                                        \
 406                        CERROR("md_" #op ": dev %s/%d no operation\n", \
 407                               obd->obd_name, obd->obd_minor);  \
 408                return err;                                 \
 409        }                                                      \
 410} while (0)
 411
 412#define EXP_CHECK_MD_OP(exp, op)                                \
 413do {                                                        \
 414        if ((exp) == NULL) {                                \
 415                CERROR("obd_" #op ": NULL export\n");      \
 416                return -ENODEV;                         \
 417        }                                                      \
 418        if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
 419                CERROR("obd_" #op ": cleaned up obd\n");        \
 420                return -EOPNOTSUPP;                         \
 421        }                                                      \
 422        if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
 423                CERROR("obd_" #op ": dev %s/%d no operation\n", \
 424                       (exp)->exp_obd->obd_name,                \
 425                       (exp)->exp_obd->obd_minor);            \
 426                return -EOPNOTSUPP;                         \
 427        }                                                      \
 428} while (0)
 429
 430
 431#define OBD_CHECK_DT_OP(obd, op, err)                      \
 432do {                                                        \
 433        if (!OBT(obd) || !OBP((obd), op)) {                  \
 434                if (err)                                        \
 435                        CERROR("obd_" #op ": dev %d no operation\n",    \
 436                               obd->obd_minor);          \
 437                return err;                                 \
 438        }                                                      \
 439} while (0)
 440
 441#define EXP_CHECK_DT_OP(exp, op)                                \
 442do {                                                        \
 443        if ((exp) == NULL) {                                \
 444                CERROR("obd_" #op ": NULL export\n");      \
 445                return -ENODEV;                         \
 446        }                                                      \
 447        if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
 448                CERROR("obd_" #op ": cleaned up obd\n");        \
 449                return -EOPNOTSUPP;                         \
 450        }                                                      \
 451        if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
 452                CERROR("obd_" #op ": dev %d no operation\n",    \
 453                       (exp)->exp_obd->obd_minor);            \
 454                return -EOPNOTSUPP;                         \
 455        }                                                      \
 456} while (0)
 457
 458#define CTXT_CHECK_OP(ctxt, op, err)                             \
 459do {                                                             \
 460        if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {             \
 461                if (err)                                             \
 462                        CERROR("lop_" #op ": dev %d no operation\n", \
 463                               ctxt->loc_obd->obd_minor);           \
 464                return err;                                      \
 465        }                                                           \
 466} while (0)
 467
 468static inline int class_devno_max(void)
 469{
 470        return MAX_OBD_DEVICES;
 471}
 472
 473static inline int obd_get_info(const struct lu_env *env,
 474                               struct obd_export *exp, __u32 keylen,
 475                               void *key, __u32 *vallen, void *val,
 476                               struct lov_stripe_md *lsm)
 477{
 478        int rc;
 479
 480        EXP_CHECK_DT_OP(exp, get_info);
 481        EXP_COUNTER_INCREMENT(exp, get_info);
 482
 483        rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val,
 484                                         lsm);
 485        return rc;
 486}
 487
 488static inline int obd_set_info_async(const struct lu_env *env,
 489                                     struct obd_export *exp, u32 keylen,
 490                                     void *key, u32 vallen, void *val,
 491                                     struct ptlrpc_request_set *set)
 492{
 493        int rc;
 494
 495        EXP_CHECK_DT_OP(exp, set_info_async);
 496        EXP_COUNTER_INCREMENT(exp, set_info_async);
 497
 498        rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
 499                                               val, set);
 500        return rc;
 501}
 502
 503/*
 504 * obd-lu integration.
 505 *
 506 * Functionality is being moved into new lu_device-based layering, but some
 507 * pieces of configuration process are still based on obd devices.
 508 *
 509 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
 510 * subsume ->o_setup() methods of obd devices they replace. The same for
 511 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
 512 * result, obd_setup() and obd_process_config() branch and call one XOR
 513 * another.
 514 *
 515 * Yet neither lu_device_type_operations::ldto_device_fini() nor
 516 * lu_device_type_operations::ldto_device_free() fully implement the
 517 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
 518 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
 519 */
 520
 521#define DECLARE_LU_VARS(ldt, d)          \
 522        struct lu_device_type *ldt;       \
 523        struct lu_device *d
 524
 525static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
 526{
 527        int rc;
 528        DECLARE_LU_VARS(ldt, d);
 529
 530        ldt = obd->obd_type->typ_lu;
 531        if (ldt != NULL) {
 532                struct lu_context  session_ctx;
 533                struct lu_env env;
 534                lu_context_init(&session_ctx, LCT_SESSION);
 535                session_ctx.lc_thread = NULL;
 536                lu_context_enter(&session_ctx);
 537
 538                rc = lu_env_init(&env, ldt->ldt_ctx_tags);
 539                if (rc == 0) {
 540                        env.le_ses = &session_ctx;
 541                        d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
 542                        lu_env_fini(&env);
 543                        if (!IS_ERR(d)) {
 544                                obd->obd_lu_dev = d;
 545                                d->ld_obd = obd;
 546                                rc = 0;
 547                        } else
 548                                rc = PTR_ERR(d);
 549                }
 550                lu_context_exit(&session_ctx);
 551                lu_context_fini(&session_ctx);
 552
 553        } else {
 554                OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
 555                OBD_COUNTER_INCREMENT(obd, setup);
 556                rc = OBP(obd, setup)(obd, cfg);
 557        }
 558        return rc;
 559}
 560
 561static inline int obd_precleanup(struct obd_device *obd,
 562                                 enum obd_cleanup_stage cleanup_stage)
 563{
 564        int rc;
 565        DECLARE_LU_VARS(ldt, d);
 566
 567        rc = obd_check_dev(obd);
 568        if (rc)
 569                return rc;
 570        ldt = obd->obd_type->typ_lu;
 571        d = obd->obd_lu_dev;
 572        if (ldt != NULL && d != NULL) {
 573                if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
 574                        struct lu_env env;
 575
 576                        rc = lu_env_init(&env, ldt->ldt_ctx_tags);
 577                        if (rc == 0) {
 578                                ldt->ldt_ops->ldto_device_fini(&env, d);
 579                                lu_env_fini(&env);
 580                        }
 581                }
 582        }
 583        OBD_CHECK_DT_OP(obd, precleanup, 0);
 584        OBD_COUNTER_INCREMENT(obd, precleanup);
 585
 586        rc = OBP(obd, precleanup)(obd, cleanup_stage);
 587        return rc;
 588}
 589
 590static inline int obd_cleanup(struct obd_device *obd)
 591{
 592        int rc;
 593        DECLARE_LU_VARS(ldt, d);
 594
 595        rc = obd_check_dev(obd);
 596        if (rc)
 597                return rc;
 598
 599        ldt = obd->obd_type->typ_lu;
 600        d = obd->obd_lu_dev;
 601        if (ldt != NULL && d != NULL) {
 602                struct lu_env env;
 603
 604                rc = lu_env_init(&env, ldt->ldt_ctx_tags);
 605                if (rc == 0) {
 606                        ldt->ldt_ops->ldto_device_free(&env, d);
 607                        lu_env_fini(&env);
 608                        obd->obd_lu_dev = NULL;
 609                }
 610        }
 611        OBD_CHECK_DT_OP(obd, cleanup, 0);
 612        OBD_COUNTER_INCREMENT(obd, cleanup);
 613
 614        rc = OBP(obd, cleanup)(obd);
 615        return rc;
 616}
 617
 618static inline void obd_cleanup_client_import(struct obd_device *obd)
 619{
 620        /* If we set up but never connected, the
 621           client import will not have been cleaned. */
 622        down_write(&obd->u.cli.cl_sem);
 623        if (obd->u.cli.cl_import) {
 624                struct obd_import *imp;
 625                imp = obd->u.cli.cl_import;
 626                CDEBUG(D_CONFIG, "%s: client import never connected\n",
 627                       obd->obd_name);
 628                ptlrpc_invalidate_import(imp);
 629                if (imp->imp_rq_pool) {
 630                        ptlrpc_free_rq_pool(imp->imp_rq_pool);
 631                        imp->imp_rq_pool = NULL;
 632                }
 633                client_destroy_import(imp);
 634                obd->u.cli.cl_import = NULL;
 635        }
 636        up_write(&obd->u.cli.cl_sem);
 637}
 638
 639static inline int
 640obd_process_config(struct obd_device *obd, int datalen, void *data)
 641{
 642        int rc;
 643        DECLARE_LU_VARS(ldt, d);
 644
 645        rc = obd_check_dev(obd);
 646        if (rc)
 647                return rc;
 648
 649        obd->obd_process_conf = 1;
 650        ldt = obd->obd_type->typ_lu;
 651        d = obd->obd_lu_dev;
 652        if (ldt != NULL && d != NULL) {
 653                struct lu_env env;
 654
 655                rc = lu_env_init(&env, ldt->ldt_ctx_tags);
 656                if (rc == 0) {
 657                        rc = d->ld_ops->ldo_process_config(&env, d, data);
 658                        lu_env_fini(&env);
 659                }
 660        } else {
 661                OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
 662                rc = OBP(obd, process_config)(obd, datalen, data);
 663        }
 664        OBD_COUNTER_INCREMENT(obd, process_config);
 665        obd->obd_process_conf = 0;
 666
 667        return rc;
 668}
 669
 670/* Pack an in-memory MD struct for storage on disk.
 671 * Returns +ve size of packed MD (0 for free), or -ve error.
 672 *
 673 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
 674 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
 675 * If @*disk_tgt == NULL, it will be allocated
 676 */
 677static inline int obd_packmd(struct obd_export *exp,
 678                             struct lov_mds_md **disk_tgt,
 679                             struct lov_stripe_md *mem_src)
 680{
 681        int rc;
 682
 683        EXP_CHECK_DT_OP(exp, packmd);
 684        EXP_COUNTER_INCREMENT(exp, packmd);
 685
 686        rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
 687        return rc;
 688}
 689
 690static inline int obd_size_diskmd(struct obd_export *exp,
 691                                  struct lov_stripe_md *mem_src)
 692{
 693        return obd_packmd(exp, NULL, mem_src);
 694}
 695
 696static inline int obd_free_diskmd(struct obd_export *exp,
 697                                  struct lov_mds_md **disk_tgt)
 698{
 699        LASSERT(disk_tgt);
 700        LASSERT(*disk_tgt);
 701        /*
 702         * LU-2590, for caller's convenience, *disk_tgt could be host
 703         * endianness, it needs swab to LE if necessary, while just
 704         * lov_mds_md header needs it for figuring out how much memory
 705         * needs to be freed.
 706         */
 707        if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
 708            (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) ||
 709             ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3)))
 710                lustre_swab_lov_mds_md(*disk_tgt);
 711        return obd_packmd(exp, disk_tgt, NULL);
 712}
 713
 714/* Unpack an MD struct from disk to in-memory format.
 715 * Returns +ve size of unpacked MD (0 for free), or -ve error.
 716 *
 717 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
 718 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
 719 * If @*mem_tgt == NULL, it will be allocated
 720 */
 721static inline int obd_unpackmd(struct obd_export *exp,
 722                               struct lov_stripe_md **mem_tgt,
 723                               struct lov_mds_md *disk_src,
 724                               int disk_len)
 725{
 726        int rc;
 727
 728        EXP_CHECK_DT_OP(exp, unpackmd);
 729        EXP_COUNTER_INCREMENT(exp, unpackmd);
 730
 731        rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
 732        return rc;
 733}
 734
 735/* helper functions */
 736static inline int obd_alloc_memmd(struct obd_export *exp,
 737                                  struct lov_stripe_md **mem_tgt)
 738{
 739        LASSERT(mem_tgt);
 740        LASSERT(*mem_tgt == NULL);
 741        return obd_unpackmd(exp, mem_tgt, NULL, 0);
 742}
 743
 744static inline int obd_free_memmd(struct obd_export *exp,
 745                                 struct lov_stripe_md **mem_tgt)
 746{
 747        int rc;
 748
 749        LASSERT(mem_tgt);
 750        LASSERT(*mem_tgt);
 751        rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
 752        *mem_tgt = NULL;
 753        return rc;
 754}
 755
 756static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
 757                             struct obdo *obdo, struct lov_stripe_md **ea,
 758                             struct obd_trans_info *oti)
 759{
 760        int rc;
 761
 762        EXP_CHECK_DT_OP(exp, create);
 763        EXP_COUNTER_INCREMENT(exp, create);
 764
 765        rc = OBP(exp->exp_obd, create)(env, exp, obdo, ea, oti);
 766        return rc;
 767}
 768
 769static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
 770                              struct obdo *obdo, struct lov_stripe_md *ea,
 771                              struct obd_trans_info *oti,
 772                              struct obd_export *md_exp, void *capa)
 773{
 774        int rc;
 775
 776        EXP_CHECK_DT_OP(exp, destroy);
 777        EXP_COUNTER_INCREMENT(exp, destroy);
 778
 779        rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp, capa);
 780        return rc;
 781}
 782
 783static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
 784                              struct obd_info *oinfo)
 785{
 786        int rc;
 787
 788        EXP_CHECK_DT_OP(exp, getattr);
 789        EXP_COUNTER_INCREMENT(exp, getattr);
 790
 791        rc = OBP(exp->exp_obd, getattr)(env, exp, oinfo);
 792        return rc;
 793}
 794
 795static inline int obd_getattr_async(struct obd_export *exp,
 796                                    struct obd_info *oinfo,
 797                                    struct ptlrpc_request_set *set)
 798{
 799        int rc;
 800
 801        EXP_CHECK_DT_OP(exp, getattr_async);
 802        EXP_COUNTER_INCREMENT(exp, getattr_async);
 803
 804        rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
 805        return rc;
 806}
 807
 808static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
 809                              struct obd_info *oinfo,
 810                              struct obd_trans_info *oti)
 811{
 812        int rc;
 813
 814        EXP_CHECK_DT_OP(exp, setattr);
 815        EXP_COUNTER_INCREMENT(exp, setattr);
 816
 817        rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti);
 818        return rc;
 819}
 820
 821/* This performs all the requests set init/wait/destroy actions. */
 822static inline int obd_setattr_rqset(struct obd_export *exp,
 823                                    struct obd_info *oinfo,
 824                                    struct obd_trans_info *oti)
 825{
 826        struct ptlrpc_request_set *set = NULL;
 827        int rc;
 828
 829        EXP_CHECK_DT_OP(exp, setattr_async);
 830        EXP_COUNTER_INCREMENT(exp, setattr_async);
 831
 832        set =  ptlrpc_prep_set();
 833        if (set == NULL)
 834                return -ENOMEM;
 835
 836        rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
 837        if (rc == 0)
 838                rc = ptlrpc_set_wait(set);
 839        ptlrpc_set_destroy(set);
 840        return rc;
 841}
 842
 843/* This adds all the requests into @set if @set != NULL, otherwise
 844   all requests are sent asynchronously without waiting for response. */
 845static inline int obd_setattr_async(struct obd_export *exp,
 846                                    struct obd_info *oinfo,
 847                                    struct obd_trans_info *oti,
 848                                    struct ptlrpc_request_set *set)
 849{
 850        int rc;
 851
 852        EXP_CHECK_DT_OP(exp, setattr_async);
 853        EXP_COUNTER_INCREMENT(exp, setattr_async);
 854
 855        rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
 856        return rc;
 857}
 858
 859static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
 860                               int priority)
 861{
 862        struct obd_device *obd = imp->imp_obd;
 863        int rc;
 864
 865        rc = obd_check_dev_active(obd);
 866        if (rc)
 867                return rc;
 868        OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
 869        OBD_COUNTER_INCREMENT(obd, add_conn);
 870
 871        rc = OBP(obd, add_conn)(imp, uuid, priority);
 872        return rc;
 873}
 874
 875static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
 876{
 877        struct obd_device *obd = imp->imp_obd;
 878        int rc;
 879
 880        rc = obd_check_dev_active(obd);
 881        if (rc)
 882                return rc;
 883        OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
 884        OBD_COUNTER_INCREMENT(obd, del_conn);
 885
 886        rc = OBP(obd, del_conn)(imp, uuid);
 887        return rc;
 888}
 889
 890static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
 891{
 892        struct obd_uuid *uuid;
 893
 894        OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
 895        EXP_COUNTER_INCREMENT(exp, get_uuid);
 896
 897        uuid = OBP(exp->exp_obd, get_uuid)(exp);
 898        return uuid;
 899}
 900
 901/** Create a new /a exp on device /a obd for the uuid /a cluuid
 902 * @param exp New export handle
 903 * @param d Connect data, supported flags are set, flags also understood
 904 *    by obd are returned.
 905 */
 906static inline int obd_connect(const struct lu_env *env,
 907                              struct obd_export **exp, struct obd_device *obd,
 908                              struct obd_uuid *cluuid,
 909                              struct obd_connect_data *data,
 910                              void *localdata)
 911{
 912        int rc;
 913        __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
 914                                                   * check */
 915
 916        rc = obd_check_dev_active(obd);
 917        if (rc)
 918                return rc;
 919        OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
 920        OBD_COUNTER_INCREMENT(obd, connect);
 921
 922        rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
 923        /* check that only subset is granted */
 924        LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
 925                                    data->ocd_connect_flags));
 926        return rc;
 927}
 928
 929static inline int obd_reconnect(const struct lu_env *env,
 930                                struct obd_export *exp,
 931                                struct obd_device *obd,
 932                                struct obd_uuid *cluuid,
 933                                struct obd_connect_data *d,
 934                                void *localdata)
 935{
 936        int rc;
 937        __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
 938                                                   * check */
 939
 940        rc = obd_check_dev_active(obd);
 941        if (rc)
 942                return rc;
 943        OBD_CHECK_DT_OP(obd, reconnect, 0);
 944        OBD_COUNTER_INCREMENT(obd, reconnect);
 945
 946        rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
 947        /* check that only subset is granted */
 948        LASSERT(ergo(d != NULL,
 949                     (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
 950        return rc;
 951}
 952
 953static inline int obd_disconnect(struct obd_export *exp)
 954{
 955        int rc;
 956
 957        EXP_CHECK_DT_OP(exp, disconnect);
 958        EXP_COUNTER_INCREMENT(exp, disconnect);
 959
 960        rc = OBP(exp->exp_obd, disconnect)(exp);
 961        return rc;
 962}
 963
 964static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
 965                               enum lu_cli_type type)
 966{
 967        int rc;
 968
 969        OBD_CHECK_DT_OP(obd, fid_init, 0);
 970        OBD_COUNTER_INCREMENT(obd, fid_init);
 971
 972        rc = OBP(obd, fid_init)(obd, exp, type);
 973        return rc;
 974}
 975
 976static inline int obd_fid_fini(struct obd_device *obd)
 977{
 978        int rc;
 979
 980        OBD_CHECK_DT_OP(obd, fid_fini, 0);
 981        OBD_COUNTER_INCREMENT(obd, fid_fini);
 982
 983        rc = OBP(obd, fid_fini)(obd);
 984        return rc;
 985}
 986
 987static inline int obd_fid_alloc(struct obd_export *exp,
 988                                struct lu_fid *fid,
 989                                struct md_op_data *op_data)
 990{
 991        int rc;
 992
 993        EXP_CHECK_DT_OP(exp, fid_alloc);
 994        EXP_COUNTER_INCREMENT(exp, fid_alloc);
 995
 996        rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
 997        return rc;
 998}
 999
1000static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1001{
1002        int rc;
1003
1004        OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1005        OBD_COUNTER_INCREMENT(obd, pool_new);
1006
1007        rc = OBP(obd, pool_new)(obd, poolname);
1008        return rc;
1009}
1010
1011static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1012{
1013        int rc;
1014
1015        OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1016        OBD_COUNTER_INCREMENT(obd, pool_del);
1017
1018        rc = OBP(obd, pool_del)(obd, poolname);
1019        return rc;
1020}
1021
1022static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1023{
1024        int rc;
1025
1026        OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1027        OBD_COUNTER_INCREMENT(obd, pool_add);
1028
1029        rc = OBP(obd, pool_add)(obd, poolname, ostname);
1030        return rc;
1031}
1032
1033static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1034{
1035        int rc;
1036
1037        OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1038        OBD_COUNTER_INCREMENT(obd, pool_rem);
1039
1040        rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1041        return rc;
1042}
1043
1044static inline void obd_getref(struct obd_device *obd)
1045{
1046        if (OBT(obd) && OBP(obd, getref)) {
1047                OBD_COUNTER_INCREMENT(obd, getref);
1048                OBP(obd, getref)(obd);
1049        }
1050}
1051
1052static inline void obd_putref(struct obd_device *obd)
1053{
1054        if (OBT(obd) && OBP(obd, putref)) {
1055                OBD_COUNTER_INCREMENT(obd, putref);
1056                OBP(obd, putref)(obd);
1057        }
1058}
1059
1060static inline int obd_init_export(struct obd_export *exp)
1061{
1062        int rc = 0;
1063
1064        if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1065            OBP((exp)->exp_obd, init_export))
1066                rc = OBP(exp->exp_obd, init_export)(exp);
1067        return rc;
1068}
1069
1070static inline int obd_destroy_export(struct obd_export *exp)
1071{
1072        if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1073            OBP((exp)->exp_obd, destroy_export))
1074                OBP(exp->exp_obd, destroy_export)(exp);
1075        return 0;
1076}
1077
1078/* @max_age is the oldest time in jiffies that we accept using a cached data.
1079 * If the cache is older than @max_age we will get a new value from the
1080 * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1081static inline int obd_statfs_async(struct obd_export *exp,
1082                                   struct obd_info *oinfo,
1083                                   __u64 max_age,
1084                                   struct ptlrpc_request_set *rqset)
1085{
1086        int rc = 0;
1087        struct obd_device *obd;
1088
1089        if (exp == NULL || exp->exp_obd == NULL)
1090                return -EINVAL;
1091
1092        obd = exp->exp_obd;
1093        OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1094        OBD_COUNTER_INCREMENT(obd, statfs);
1095
1096        CDEBUG(D_SUPER, "%s: osfs %p age %llu, max_age %llu\n",
1097               obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1098        if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1099                rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1100        } else {
1101                CDEBUG(D_SUPER,
1102                       "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1103                       obd->obd_name, &obd->obd_osfs,
1104                       obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1105                       obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1106                spin_lock(&obd->obd_osfs_lock);
1107                memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1108                spin_unlock(&obd->obd_osfs_lock);
1109                oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1110                if (oinfo->oi_cb_up)
1111                        oinfo->oi_cb_up(oinfo, 0);
1112        }
1113        return rc;
1114}
1115
1116static inline int obd_statfs_rqset(struct obd_export *exp,
1117                                   struct obd_statfs *osfs, __u64 max_age,
1118                                   __u32 flags)
1119{
1120        struct ptlrpc_request_set *set = NULL;
1121        struct obd_info oinfo = { { { 0 } } };
1122        int rc = 0;
1123
1124        set =  ptlrpc_prep_set();
1125        if (set == NULL)
1126                return -ENOMEM;
1127
1128        oinfo.oi_osfs = osfs;
1129        oinfo.oi_flags = flags;
1130        rc = obd_statfs_async(exp, &oinfo, max_age, set);
1131        if (rc == 0)
1132                rc = ptlrpc_set_wait(set);
1133        ptlrpc_set_destroy(set);
1134        return rc;
1135}
1136
1137/* @max_age is the oldest time in jiffies that we accept using a cached data.
1138 * If the cache is older than @max_age we will get a new value from the
1139 * target.  Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1140static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1141                             struct obd_statfs *osfs, __u64 max_age,
1142                             __u32 flags)
1143{
1144        int rc = 0;
1145        struct obd_device *obd = exp->exp_obd;
1146
1147        if (obd == NULL)
1148                return -EINVAL;
1149
1150        OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1151        OBD_COUNTER_INCREMENT(obd, statfs);
1152
1153        CDEBUG(D_SUPER, "osfs %llu, max_age %llu\n",
1154               obd->obd_osfs_age, max_age);
1155        if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1156                rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1157                if (rc == 0) {
1158                        spin_lock(&obd->obd_osfs_lock);
1159                        memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1160                        obd->obd_osfs_age = cfs_time_current_64();
1161                        spin_unlock(&obd->obd_osfs_lock);
1162                }
1163        } else {
1164                CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1165                       obd->obd_name, &obd->obd_osfs,
1166                       obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1167                       obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1168                spin_lock(&obd->obd_osfs_lock);
1169                memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1170                spin_unlock(&obd->obd_osfs_lock);
1171        }
1172        return rc;
1173}
1174
1175static inline int obd_preprw(const struct lu_env *env, int cmd,
1176                             struct obd_export *exp, struct obdo *oa,
1177                             int objcount, struct obd_ioobj *obj,
1178                             struct niobuf_remote *remote, int *pages,
1179                             struct niobuf_local *local,
1180                             struct obd_trans_info *oti,
1181                             struct lustre_capa *capa)
1182{
1183        int rc;
1184
1185        EXP_CHECK_DT_OP(exp, preprw);
1186        EXP_COUNTER_INCREMENT(exp, preprw);
1187
1188        rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1189                                       pages, local, oti, capa);
1190        return rc;
1191}
1192
1193static inline int obd_commitrw(const struct lu_env *env, int cmd,
1194                               struct obd_export *exp, struct obdo *oa,
1195                               int objcount, struct obd_ioobj *obj,
1196                               struct niobuf_remote *rnb, int pages,
1197                               struct niobuf_local *local,
1198                               struct obd_trans_info *oti, int rc)
1199{
1200        EXP_CHECK_DT_OP(exp, commitrw);
1201        EXP_COUNTER_INCREMENT(exp, commitrw);
1202
1203        rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1204                                         rnb, pages, local, oti, rc);
1205        return rc;
1206}
1207
1208static inline int obd_adjust_kms(struct obd_export *exp,
1209                                 struct lov_stripe_md *lsm, u64 size,
1210                                 int shrink)
1211{
1212        int rc;
1213
1214        EXP_CHECK_DT_OP(exp, adjust_kms);
1215        EXP_COUNTER_INCREMENT(exp, adjust_kms);
1216
1217        rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1218        return rc;
1219}
1220
1221static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1222                                int len, void *karg, void *uarg)
1223{
1224        int rc;
1225
1226        EXP_CHECK_DT_OP(exp, iocontrol);
1227        EXP_COUNTER_INCREMENT(exp, iocontrol);
1228
1229        rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1230        return rc;
1231}
1232
1233static inline int obd_find_cbdata(struct obd_export *exp,
1234                                  struct lov_stripe_md *lsm,
1235                                  ldlm_iterator_t it, void *data)
1236{
1237        int rc;
1238
1239        EXP_CHECK_DT_OP(exp, find_cbdata);
1240        EXP_COUNTER_INCREMENT(exp, find_cbdata);
1241
1242        rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1243        return rc;
1244}
1245
1246static inline void obd_import_event(struct obd_device *obd,
1247                                    struct obd_import *imp,
1248                                    enum obd_import_event event)
1249{
1250        if (!obd) {
1251                CERROR("NULL device\n");
1252                return;
1253        }
1254        if (obd->obd_set_up && OBP(obd, import_event)) {
1255                OBD_COUNTER_INCREMENT(obd, import_event);
1256                OBP(obd, import_event)(obd, imp, event);
1257        }
1258}
1259
1260static inline int obd_notify(struct obd_device *obd,
1261                             struct obd_device *watched,
1262                             enum obd_notify_event ev,
1263                             void *data)
1264{
1265        int rc;
1266
1267        rc = obd_check_dev(obd);
1268        if (rc)
1269                return rc;
1270
1271        /* the check for async_recov is a complete hack - I'm hereby
1272           overloading the meaning to also mean "this was called from
1273           mds_postsetup".  I know that my mds is able to handle notifies
1274           by this point, and it needs to get them to execute mds_postrecov. */
1275        if (!obd->obd_set_up && !obd->obd_async_recov) {
1276                CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1277                return -EINVAL;
1278        }
1279
1280        if (!OBP(obd, notify)) {
1281                CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1282                return -ENOSYS;
1283        }
1284
1285        OBD_COUNTER_INCREMENT(obd, notify);
1286        rc = OBP(obd, notify)(obd, watched, ev, data);
1287        return rc;
1288}
1289
1290static inline int obd_notify_observer(struct obd_device *observer,
1291                                      struct obd_device *observed,
1292                                      enum obd_notify_event ev,
1293                                      void *data)
1294{
1295        int rc1;
1296        int rc2;
1297
1298        struct obd_notify_upcall *onu;
1299
1300        if (observer->obd_observer)
1301                rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1302        else
1303                rc1 = 0;
1304        /*
1305         * Also, call non-obd listener, if any
1306         */
1307        onu = &observer->obd_upcall;
1308        if (onu->onu_upcall != NULL)
1309                rc2 = onu->onu_upcall(observer, observed, ev,
1310                                      onu->onu_owner, NULL);
1311        else
1312                rc2 = 0;
1313
1314        return rc1 ? rc1 : rc2;
1315}
1316
1317static inline int obd_quotacheck(struct obd_export *exp,
1318                                 struct obd_quotactl *oqctl)
1319{
1320        int rc;
1321
1322        EXP_CHECK_DT_OP(exp, quotacheck);
1323        EXP_COUNTER_INCREMENT(exp, quotacheck);
1324
1325        rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1326        return rc;
1327}
1328
1329static inline int obd_quotactl(struct obd_export *exp,
1330                               struct obd_quotactl *oqctl)
1331{
1332        int rc;
1333
1334        EXP_CHECK_DT_OP(exp, quotactl);
1335        EXP_COUNTER_INCREMENT(exp, quotactl);
1336
1337        rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1338        return rc;
1339}
1340
1341static inline int obd_health_check(const struct lu_env *env,
1342                                   struct obd_device *obd)
1343{
1344        /* returns: 0 on healthy
1345         *       >0 on unhealthy + reason code/flag
1346         *          however the only supported reason == 1 right now
1347         *          We'll need to define some better reasons
1348         *          or flags in the future.
1349         *       <0 on error
1350         */
1351        int rc;
1352
1353        /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1354        if (obd == NULL || !OBT(obd)) {
1355                CERROR("cleaned up obd\n");
1356                return -EOPNOTSUPP;
1357        }
1358        if (!obd->obd_set_up || obd->obd_stopping)
1359                return 0;
1360        if (!OBP(obd, health_check))
1361                return 0;
1362
1363        rc = OBP(obd, health_check)(env, obd);
1364        return rc;
1365}
1366
1367static inline int obd_register_observer(struct obd_device *obd,
1368                                        struct obd_device *observer)
1369{
1370        int rc;
1371
1372        rc = obd_check_dev(obd);
1373        if (rc)
1374                return rc;
1375        down_write(&obd->obd_observer_link_sem);
1376        if (obd->obd_observer && observer) {
1377                up_write(&obd->obd_observer_link_sem);
1378                return -EALREADY;
1379        }
1380        obd->obd_observer = observer;
1381        up_write(&obd->obd_observer_link_sem);
1382        return 0;
1383}
1384
1385#if 0
1386static inline int obd_register_page_removal_cb(struct obd_export *exp,
1387                                               obd_page_removal_cb_t cb,
1388                                               obd_pin_extent_cb pin_cb)
1389{
1390        int rc;
1391
1392        OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1393        OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1394
1395        rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1396        return rc;
1397}
1398
1399static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1400                                                 obd_page_removal_cb_t cb)
1401{
1402        int rc;
1403
1404        OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1405        OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1406
1407        rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1408        return rc;
1409}
1410
1411static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1412                                              obd_lock_cancel_cb cb)
1413{
1414        int rc;
1415
1416        OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1417        OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1418
1419        rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1420        return rc;
1421}
1422
1423static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1424                                                 obd_lock_cancel_cb cb)
1425{
1426        int rc;
1427
1428        OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1429        OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1430
1431        rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1432        return rc;
1433}
1434#endif
1435
1436/* metadata helpers */
1437static inline int md_getstatus(struct obd_export *exp,
1438                               struct lu_fid *fid, struct obd_capa **pc)
1439{
1440        int rc;
1441
1442        EXP_CHECK_MD_OP(exp, getstatus);
1443        EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1444        rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1445        return rc;
1446}
1447
1448static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1449                             struct ptlrpc_request **request)
1450{
1451        int rc;
1452
1453        EXP_CHECK_MD_OP(exp, getattr);
1454        EXP_MD_COUNTER_INCREMENT(exp, getattr);
1455        rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1456        return rc;
1457}
1458
1459static inline int md_null_inode(struct obd_export *exp,
1460                                   const struct lu_fid *fid)
1461{
1462        int rc;
1463
1464        EXP_CHECK_MD_OP(exp, null_inode);
1465        EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1466        rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1467        return rc;
1468}
1469
1470static inline int md_find_cbdata(struct obd_export *exp,
1471                                 const struct lu_fid *fid,
1472                                 ldlm_iterator_t it, void *data)
1473{
1474        int rc;
1475
1476        EXP_CHECK_MD_OP(exp, find_cbdata);
1477        EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1478        rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1479        return rc;
1480}
1481
1482static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1483                           struct md_open_data *mod,
1484                           struct ptlrpc_request **request)
1485{
1486        int rc;
1487
1488        EXP_CHECK_MD_OP(exp, close);
1489        EXP_MD_COUNTER_INCREMENT(exp, close);
1490        rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1491        return rc;
1492}
1493
1494static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1495                            const void *data, int datalen, int mode, __u32 uid,
1496                            __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1497                            struct ptlrpc_request **request)
1498{
1499        int rc;
1500
1501        EXP_CHECK_MD_OP(exp, create);
1502        EXP_MD_COUNTER_INCREMENT(exp, create);
1503        rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1504                                       uid, gid, cap_effective, rdev, request);
1505        return rc;
1506}
1507
1508static inline int md_done_writing(struct obd_export *exp,
1509                                  struct md_op_data *op_data,
1510                                  struct md_open_data *mod)
1511{
1512        int rc;
1513
1514        EXP_CHECK_MD_OP(exp, done_writing);
1515        EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1516        rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1517        return rc;
1518}
1519
1520static inline int md_enqueue(struct obd_export *exp,
1521                             struct ldlm_enqueue_info *einfo,
1522                             struct lookup_intent *it,
1523                             struct md_op_data *op_data,
1524                             struct lustre_handle *lockh,
1525                             void *lmm, int lmmsize,
1526                             struct ptlrpc_request **req,
1527                             __u64 extra_lock_flags)
1528{
1529        int rc;
1530
1531        EXP_CHECK_MD_OP(exp, enqueue);
1532        EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1533        rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1534                                        lmm, lmmsize, req, extra_lock_flags);
1535        return rc;
1536}
1537
1538static inline int md_getattr_name(struct obd_export *exp,
1539                                  struct md_op_data *op_data,
1540                                  struct ptlrpc_request **request)
1541{
1542        int rc;
1543
1544        EXP_CHECK_MD_OP(exp, getattr_name);
1545        EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1546        rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1547        return rc;
1548}
1549
1550static inline int md_intent_lock(struct obd_export *exp,
1551                                 struct md_op_data *op_data, void *lmm,
1552                                 int lmmsize, struct lookup_intent *it,
1553                                 int lookup_flags, struct ptlrpc_request **reqp,
1554                                 ldlm_blocking_callback cb_blocking,
1555                                 __u64 extra_lock_flags)
1556{
1557        int rc;
1558
1559        EXP_CHECK_MD_OP(exp, intent_lock);
1560        EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1561        rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1562                                            it, lookup_flags, reqp, cb_blocking,
1563                                            extra_lock_flags);
1564        return rc;
1565}
1566
1567static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1568                          struct ptlrpc_request **request)
1569{
1570        int rc;
1571
1572        EXP_CHECK_MD_OP(exp, link);
1573        EXP_MD_COUNTER_INCREMENT(exp, link);
1574        rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1575        return rc;
1576}
1577
1578static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1579                            const char *old, int oldlen, const char *new,
1580                            int newlen, struct ptlrpc_request **request)
1581{
1582        int rc;
1583
1584        EXP_CHECK_MD_OP(exp, rename);
1585        EXP_MD_COUNTER_INCREMENT(exp, rename);
1586        rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1587                                       newlen, request);
1588        return rc;
1589}
1590
1591static inline int md_is_subdir(struct obd_export *exp,
1592                               const struct lu_fid *pfid,
1593                               const struct lu_fid *cfid,
1594                               struct ptlrpc_request **request)
1595{
1596        int rc;
1597
1598        EXP_CHECK_MD_OP(exp, is_subdir);
1599        EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1600        rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1601        return rc;
1602}
1603
1604static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1605                             void *ea, int ealen, void *ea2, int ea2len,
1606                             struct ptlrpc_request **request,
1607                             struct md_open_data **mod)
1608{
1609        int rc;
1610
1611        EXP_CHECK_MD_OP(exp, setattr);
1612        EXP_MD_COUNTER_INCREMENT(exp, setattr);
1613        rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1614                                        ea2, ea2len, request, mod);
1615        return rc;
1616}
1617
1618static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1619                          struct obd_capa *oc, struct ptlrpc_request **request)
1620{
1621        int rc;
1622
1623        EXP_CHECK_MD_OP(exp, sync);
1624        EXP_MD_COUNTER_INCREMENT(exp, sync);
1625        rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1626        return rc;
1627}
1628
1629static inline int md_readpage(struct obd_export *exp, struct md_op_data *opdata,
1630                              struct page **pages,
1631                              struct ptlrpc_request **request)
1632{
1633        int rc;
1634
1635        EXP_CHECK_MD_OP(exp, readpage);
1636        EXP_MD_COUNTER_INCREMENT(exp, readpage);
1637        rc = MDP(exp->exp_obd, readpage)(exp, opdata, pages, request);
1638        return rc;
1639}
1640
1641static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1642                            struct ptlrpc_request **request)
1643{
1644        int rc;
1645
1646        EXP_CHECK_MD_OP(exp, unlink);
1647        EXP_MD_COUNTER_INCREMENT(exp, unlink);
1648        rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1649        return rc;
1650}
1651
1652static inline int md_get_lustre_md(struct obd_export *exp,
1653                                   struct ptlrpc_request *req,
1654                                   struct obd_export *dt_exp,
1655                                   struct obd_export *md_exp,
1656                                   struct lustre_md *md)
1657{
1658        EXP_CHECK_MD_OP(exp, get_lustre_md);
1659        EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1660        return MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md);
1661}
1662
1663static inline int md_free_lustre_md(struct obd_export *exp,
1664                                    struct lustre_md *md)
1665{
1666        EXP_CHECK_MD_OP(exp, free_lustre_md);
1667        EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1668        return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1669}
1670
1671static inline int md_setxattr(struct obd_export *exp,
1672                              const struct lu_fid *fid, struct obd_capa *oc,
1673                              u64 valid, const char *name,
1674                              const char *input, int input_size,
1675                              int output_size, int flags, __u32 suppgid,
1676                              struct ptlrpc_request **request)
1677{
1678        EXP_CHECK_MD_OP(exp, setxattr);
1679        EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1680        return MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1681                                           input_size, output_size, flags,
1682                                           suppgid, request);
1683}
1684
1685static inline int md_getxattr(struct obd_export *exp,
1686                              const struct lu_fid *fid, struct obd_capa *oc,
1687                              u64 valid, const char *name,
1688                              const char *input, int input_size,
1689                              int output_size, int flags,
1690                              struct ptlrpc_request **request)
1691{
1692        EXP_CHECK_MD_OP(exp, getxattr);
1693        EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1694        return MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1695                                           input_size, output_size, flags,
1696                                           request);
1697}
1698
1699static inline int md_set_open_replay_data(struct obd_export *exp,
1700                                          struct obd_client_handle *och,
1701                                          struct lookup_intent *it)
1702{
1703        EXP_CHECK_MD_OP(exp, set_open_replay_data);
1704        EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1705        return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
1706}
1707
1708static inline int md_clear_open_replay_data(struct obd_export *exp,
1709                                            struct obd_client_handle *och)
1710{
1711        EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1712        EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1713        return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1714}
1715
1716static inline int md_set_lock_data(struct obd_export *exp,
1717                                   __u64 *lockh, void *data, __u64 *bits)
1718{
1719        EXP_CHECK_MD_OP(exp, set_lock_data);
1720        EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1721        return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
1722}
1723
1724static inline int md_cancel_unused(struct obd_export *exp,
1725                                   const struct lu_fid *fid,
1726                                   ldlm_policy_data_t *policy,
1727                                   ldlm_mode_t mode,
1728                                   ldlm_cancel_flags_t flags,
1729                                   void *opaque)
1730{
1731        int rc;
1732
1733        EXP_CHECK_MD_OP(exp, cancel_unused);
1734        EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1735
1736        rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1737                                              flags, opaque);
1738        return rc;
1739}
1740
1741static inline ldlm_mode_t md_lock_match(struct obd_export *exp, __u64 flags,
1742                                        const struct lu_fid *fid,
1743                                        ldlm_type_t type,
1744                                        ldlm_policy_data_t *policy,
1745                                        ldlm_mode_t mode,
1746                                        struct lustre_handle *lockh)
1747{
1748        EXP_CHECK_MD_OP(exp, lock_match);
1749        EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1750        return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1751                                             policy, mode, lockh);
1752}
1753
1754static inline int md_init_ea_size(struct obd_export *exp, int easize,
1755                                  int def_asize, int cookiesize,
1756                                  int def_cookiesize)
1757{
1758        EXP_CHECK_MD_OP(exp, init_ea_size);
1759        EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1760        return MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1761                                               cookiesize, def_cookiesize);
1762}
1763
1764static inline int md_get_remote_perm(struct obd_export *exp,
1765                                     const struct lu_fid *fid,
1766                                     struct obd_capa *oc, __u32 suppgid,
1767                                     struct ptlrpc_request **request)
1768{
1769        EXP_CHECK_MD_OP(exp, get_remote_perm);
1770        EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1771        return MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
1772                                                  request);
1773}
1774
1775static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1776                                renew_capa_cb_t cb)
1777{
1778        int rc;
1779
1780        EXP_CHECK_MD_OP(exp, renew_capa);
1781        EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1782        rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1783        return rc;
1784}
1785
1786static inline int md_unpack_capa(struct obd_export *exp,
1787                                 struct ptlrpc_request *req,
1788                                 const struct req_msg_field *field,
1789                                 struct obd_capa **oc)
1790{
1791        int rc;
1792
1793        EXP_CHECK_MD_OP(exp, unpack_capa);
1794        EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
1795        rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
1796        return rc;
1797}
1798
1799static inline int md_intent_getattr_async(struct obd_export *exp,
1800                                          struct md_enqueue_info *minfo,
1801                                          struct ldlm_enqueue_info *einfo)
1802{
1803        int rc;
1804
1805        EXP_CHECK_MD_OP(exp, intent_getattr_async);
1806        EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1807        rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
1808        return rc;
1809}
1810
1811static inline int md_revalidate_lock(struct obd_export *exp,
1812                                     struct lookup_intent *it,
1813                                     struct lu_fid *fid, __u64 *bits)
1814{
1815        int rc;
1816
1817        EXP_CHECK_MD_OP(exp, revalidate_lock);
1818        EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1819        rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1820        return rc;
1821}
1822
1823
1824/* OBD Metadata Support */
1825
1826extern int obd_init_caches(void);
1827extern void obd_cleanup_caches(void);
1828
1829/* support routines */
1830extern struct kmem_cache *obdo_cachep;
1831
1832#define OBDO_ALLOC(ptr)                                                \
1833do {                                                                      \
1834        OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS);             \
1835} while (0)
1836
1837#define OBDO_FREE(ptr)                                                  \
1838do {                                                                      \
1839        OBD_SLAB_FREE_PTR((ptr), obdo_cachep);                          \
1840} while (0)
1841
1842
1843static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
1844{
1845        /* something here */
1846}
1847
1848static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
1849{
1850        /* something here */
1851}
1852
1853typedef int (*register_lwp_cb)(void *data);
1854
1855struct lwp_register_item {
1856        struct obd_export **lri_exp;
1857        register_lwp_cb     lri_cb_func;
1858        void               *lri_cb_data;
1859        struct list_head            lri_list;
1860        char                lri_name[MTI_NAME_MAXLEN];
1861};
1862
1863/* I'm as embarrassed about this as you are.
1864 *
1865 * <shaver> // XXX do not look into _superhack with remaining eye
1866 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1867extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1868
1869/* obd_mount.c */
1870
1871/* sysctl.c */
1872extern void obd_sysctl_init (void);
1873extern void obd_sysctl_clean (void);
1874
1875/* uuid.c  */
1876typedef __u8 class_uuid_t[16];
1877void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1878
1879/* lustre_peer.c    */
1880int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1881int class_add_uuid(const char *uuid, __u64 nid);
1882int class_del_uuid (const char *uuid);
1883int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1884void class_init_uuidlist(void);
1885void class_exit_uuidlist(void);
1886
1887/* class_obd.c */
1888extern char obd_jobid_node[];
1889extern struct miscdevice obd_psdev;
1890extern spinlock_t obd_types_lock;
1891
1892/* prng.c */
1893#define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1894
1895#endif /* __LINUX_OBD_CLASS_H */
1896