4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
40 #include "obd_support.h"
41 #include "lustre_import.h"
42 #include "lustre_net.h"
44 #include "lustre_lib.h"
45 #include "lustre/lustre_idl.h"
46 #include "lprocfs_status.h"
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
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 */
62 /* OBD Device Declarations */
63 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
64 extern rwlock_t obd_dev_lock;
66 /* OBD Operations Declarations */
67 extern struct obd_device *class_conn2obd(struct lustre_handle *);
68 extern struct obd_device *class_exp2obd(struct obd_export *);
69 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
70 extern int lustre_get_jobid(char *jobid);
72 struct lu_device_type;
75 extern struct list_head obd_types;
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,
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);
96 int get_devices_count(void);
98 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
100 char *obd_export_nid2str(struct obd_export *exp);
102 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
103 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
104 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
106 int obd_zombie_impexp_init(void);
107 void obd_zombie_impexp_stop(void);
108 void obd_zombie_impexp_cull(void);
109 void obd_zombie_barrier(void);
110 void obd_exports_barrier(struct obd_device *obd);
111 int kuc_len(int payload_len);
112 struct kuc_hdr *kuc_ptr(void *p);
113 int kuc_ispayload(void *p);
114 void *kuc_alloc(int payload_len, int transport, int type);
115 void kuc_free(void *p, int payload_len);
119 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
120 struct llog_rec_hdr *, void *);
122 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
123 const char *new_name);
124 int class_process_config(struct lustre_cfg *lcfg);
125 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
126 struct lustre_cfg *lcfg, void *data);
127 int class_attach(struct lustre_cfg *lcfg);
128 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
129 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
130 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
131 struct obd_device *class_incref(struct obd_device *obd,
132 const char *scope, const void *source);
133 void class_decref(struct obd_device *obd,
134 const char *scope, const void *source);
135 void dump_exports(struct obd_device *obd, int locks);
136 int class_config_llog_handler(const struct lu_env *env,
137 struct llog_handle *handle,
138 struct llog_rec_hdr *rec, void *data);
139 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
140 int class_add_uuid(const char *uuid, __u64 nid);
143 #if defined (CONFIG_PROC_FS)
144 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
146 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
148 memset(lvars, 0, sizeof(*lvars));
152 #define CFG_F_START 0x01 /* Set when we start updating from a log */
153 #define CFG_F_MARKER 0x02 /* We are within a maker */
154 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
155 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
156 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
158 /* Passed as data param to class_config_parse_llog */
159 struct config_llog_instance {
162 struct super_block *cfg_sb;
163 struct obd_uuid cfg_uuid;
164 llog_cb_t cfg_callback;
165 int cfg_last_idx; /* for partial llog processing */
168 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
169 char *name, struct config_llog_instance *cfg);
170 int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
171 char *name, struct config_llog_instance *cfg);
175 CONFIG_T_SPTLRPC = 1,
176 CONFIG_T_RECOVER = 2,
181 #define PARAMS_FILENAME "params"
182 #define LCTL_UPCALL "lctl"
184 /* list of active configuration logs */
185 struct config_llog_data {
186 struct ldlm_res_id cld_resid;
187 struct config_llog_instance cld_cfg;
188 struct list_head cld_list_chain;
189 atomic_t cld_refcount;
190 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
191 struct config_llog_data *cld_params; /* common parameters log */
192 struct config_llog_data *cld_recover;/* imperative recover log */
193 struct obd_export *cld_mgcexp;
194 struct mutex cld_lock;
196 unsigned int cld_stopping:1, /* we were told to stop
198 cld_lostlock:1; /* lock not requeued */
202 struct lustre_profile {
203 struct list_head lp_list;
209 struct lustre_profile *class_get_profile(const char *prof);
210 void class_del_profile(const char *prof);
211 void class_del_profiles(void);
213 #if LUSTRE_TRACKS_LOCK_EXP_REFS
215 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
216 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
217 extern void (*class_export_dump_hook)(struct obd_export *);
221 #define __class_export_add_lock_ref(exp, lock) do {} while (0)
222 #define __class_export_del_lock_ref(exp, lock) do {} while (0)
226 static inline void class_export_rpc_inc(struct obd_export *exp)
228 atomic_inc(&(exp)->exp_rpc_count);
229 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n",
230 (exp), atomic_read(&(exp)->exp_rpc_count));
233 static inline void class_export_rpc_dec(struct obd_export *exp)
235 LASSERT_ATOMIC_POS(&exp->exp_rpc_count);
236 atomic_dec(&(exp)->exp_rpc_count);
237 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n",
238 (exp), atomic_read(&(exp)->exp_rpc_count));
241 #define class_export_lock_get(exp, lock) \
243 atomic_inc(&(exp)->exp_locks_count); \
244 __class_export_add_lock_ref(exp, lock); \
245 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
246 (exp), atomic_read(&(exp)->exp_locks_count)); \
247 class_export_get(exp); \
250 #define class_export_lock_put(exp, lock) \
252 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
253 atomic_dec(&(exp)->exp_locks_count); \
254 __class_export_del_lock_ref(exp, lock); \
255 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
256 (exp), atomic_read(&(exp)->exp_locks_count)); \
257 class_export_put(exp); \
260 #define class_export_cb_get(exp) \
262 atomic_inc(&(exp)->exp_cb_count); \
263 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
264 (exp), atomic_read(&(exp)->exp_cb_count)); \
265 class_export_get(exp); \
268 #define class_export_cb_put(exp) \
270 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
271 atomic_dec(&(exp)->exp_cb_count); \
272 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
273 (exp), atomic_read(&(exp)->exp_cb_count)); \
274 class_export_put(exp); \
278 struct obd_export *class_export_get(struct obd_export *exp);
279 void class_export_put(struct obd_export *exp);
280 struct obd_export *class_new_export(struct obd_device *obddev,
281 struct obd_uuid *cluuid);
282 void class_unlink_export(struct obd_export *exp);
284 struct obd_import *class_import_get(struct obd_import *);
285 void class_import_put(struct obd_import *);
286 struct obd_import *class_new_import(struct obd_device *obd);
287 void class_destroy_import(struct obd_import *exp);
289 struct obd_type *class_search_type(const char *name);
290 struct obd_type *class_get_type(const char *name);
291 void class_put_type(struct obd_type *type);
292 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
293 struct obd_uuid *cluuid);
294 int class_disconnect(struct obd_export *exp);
295 void class_fail_export(struct obd_export *exp);
296 int class_connected_export(struct obd_export *exp);
297 void class_disconnect_exports(struct obd_device *obddev);
298 int class_manual_cleanup(struct obd_device *obd);
299 void class_disconnect_stale_exports(struct obd_device *,
300 int (*test_export)(struct obd_export *));
301 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
303 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
304 (obd->obd_force ? OBD_OPT_FORCE : 0) |
305 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
312 void obdo_from_la(struct obdo *dst, struct lu_attr *la, __u64 valid);
313 void la_from_obdo(struct lu_attr *la, struct obdo *dst, u32 valid);
314 void obdo_refresh_inode(struct inode *dst, struct obdo *src, u32 valid);
315 void obdo_to_inode(struct inode *dst, struct obdo *src, u32 valid);
317 void obdo_cpy_md(struct obdo *dst, struct obdo *src, u32 valid);
318 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
319 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
320 unsigned int ia_valid);
321 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, u32 valid);
322 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, u32 valid);
323 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
326 void obdo_cpu_to_le(struct obdo *dobdo, struct obdo *sobdo);
327 void obdo_le_to_cpu(struct obdo *dobdo, struct obdo *sobdo);
329 #define OBT(dev) (dev)->obd_type
330 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
331 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
332 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
334 /* Ensure obd_setup: used for cleanup which must be called
335 while obd is stopping */
336 static inline int obd_check_dev(struct obd_device *obd)
339 CERROR("NULL device\n");
345 /* ensure obd_setup and !obd_stopping */
346 static inline int obd_check_dev_active(struct obd_device *obd)
350 rc = obd_check_dev(obd);
353 if (!obd->obd_set_up || obd->obd_stopping) {
354 CERROR("Device %d not setup\n", obd->obd_minor);
360 #if defined (CONFIG_PROC_FS)
361 #define OBD_COUNTER_OFFSET(op) \
362 ((offsetof(struct obd_ops, o_ ## op) - \
363 offsetof(struct obd_ops, o_iocontrol)) \
364 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
366 #define OBD_COUNTER_INCREMENT(obdx, op) \
367 if ((obdx)->obd_stats != NULL) { \
368 unsigned int coffset; \
369 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
370 OBD_COUNTER_OFFSET(op); \
371 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
372 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
375 #define EXP_COUNTER_INCREMENT(export, op) \
376 if ((export)->exp_obd->obd_stats != NULL) { \
377 unsigned int coffset; \
378 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
379 OBD_COUNTER_OFFSET(op); \
380 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
381 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
382 if ((export)->exp_nid_stats != NULL && \
383 (export)->exp_nid_stats->nid_stats != NULL) \
384 lprocfs_counter_incr( \
385 (export)->exp_nid_stats->nid_stats, coffset);\
388 #define MD_COUNTER_OFFSET(op) \
389 ((offsetof(struct md_ops, m_ ## op) - \
390 offsetof(struct md_ops, m_getstatus)) \
391 / sizeof(((struct md_ops *)(0))->m_getstatus))
393 #define MD_COUNTER_INCREMENT(obdx, op) \
394 if ((obd)->md_stats != NULL) { \
395 unsigned int coffset; \
396 coffset = (unsigned int)((obdx)->md_cntr_base) + \
397 MD_COUNTER_OFFSET(op); \
398 LASSERT(coffset < (obdx)->md_stats->ls_num); \
399 lprocfs_counter_incr((obdx)->md_stats, coffset); \
402 #define EXP_MD_COUNTER_INCREMENT(export, op) \
403 if ((export)->exp_obd->obd_stats != NULL) { \
404 unsigned int coffset; \
405 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
406 MD_COUNTER_OFFSET(op); \
407 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
408 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
409 if ((export)->exp_md_stats != NULL) \
410 lprocfs_counter_incr( \
411 (export)->exp_md_stats, coffset); \
415 #define OBD_COUNTER_OFFSET(op)
416 #define OBD_COUNTER_INCREMENT(obd, op)
417 #define EXP_COUNTER_INCREMENT(exp, op)
418 #define MD_COUNTER_INCREMENT(obd, op)
419 #define EXP_MD_COUNTER_INCREMENT(exp, op)
422 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat *tmp)
424 /* Always add in ldlm_stats */
425 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
426 ,LPROCFS_STATS_FLAG_NOPERCPU);
427 if (tmp->nid_ldlm_stats == NULL)
430 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
432 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
433 tmp->nid_ldlm_stats);
436 #define OBD_CHECK_MD_OP(obd, op, err) \
438 if (!OBT(obd) || !MDP((obd), op)) { \
440 CERROR("md_" #op ": dev %s/%d no operation\n", \
441 obd->obd_name, obd->obd_minor); \
446 #define EXP_CHECK_MD_OP(exp, op) \
448 if ((exp) == NULL) { \
449 CERROR("obd_" #op ": NULL export\n"); \
452 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
453 CERROR("obd_" #op ": cleaned up obd\n"); \
454 return -EOPNOTSUPP; \
456 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
457 CERROR("obd_" #op ": dev %s/%d no operation\n", \
458 (exp)->exp_obd->obd_name, \
459 (exp)->exp_obd->obd_minor); \
460 return -EOPNOTSUPP; \
465 #define OBD_CHECK_DT_OP(obd, op, err) \
467 if (!OBT(obd) || !OBP((obd), op)) { \
469 CERROR("obd_" #op ": dev %d no operation\n", \
475 #define EXP_CHECK_DT_OP(exp, op) \
477 if ((exp) == NULL) { \
478 CERROR("obd_" #op ": NULL export\n"); \
481 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
482 CERROR("obd_" #op ": cleaned up obd\n"); \
483 return -EOPNOTSUPP; \
485 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
486 CERROR("obd_" #op ": dev %d no operation\n", \
487 (exp)->exp_obd->obd_minor); \
488 return -EOPNOTSUPP; \
492 #define CTXT_CHECK_OP(ctxt, op, err) \
494 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
496 CERROR("lop_" #op ": dev %d no operation\n", \
497 ctxt->loc_obd->obd_minor); \
502 static inline int class_devno_max(void)
504 return MAX_OBD_DEVICES;
507 static inline int obd_get_info(const struct lu_env *env,
508 struct obd_export *exp, __u32 keylen,
509 void *key, __u32 *vallen, void *val,
510 struct lov_stripe_md *lsm)
514 EXP_CHECK_DT_OP(exp, get_info);
515 EXP_COUNTER_INCREMENT(exp, get_info);
517 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val,
522 static inline int obd_set_info_async(const struct lu_env *env,
523 struct obd_export *exp, u32 keylen,
524 void *key, u32 vallen, void *val,
525 struct ptlrpc_request_set *set)
529 EXP_CHECK_DT_OP(exp, set_info_async);
530 EXP_COUNTER_INCREMENT(exp, set_info_async);
532 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
538 * obd-lu integration.
540 * Functionality is being moved into new lu_device-based layering, but some
541 * pieces of configuration process are still based on obd devices.
543 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
544 * subsume ->o_setup() methods of obd devices they replace. The same for
545 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
546 * result, obd_setup() and obd_process_config() branch and call one XOR
549 * Yet neither lu_device_type_operations::ldto_device_fini() nor
550 * lu_device_type_operations::ldto_device_free() fully implement the
551 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
552 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
555 #define DECLARE_LU_VARS(ldt, d) \
556 struct lu_device_type *ldt; \
559 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
562 DECLARE_LU_VARS(ldt, d);
564 ldt = obd->obd_type->typ_lu;
566 struct lu_context session_ctx;
568 lu_context_init(&session_ctx, LCT_SESSION);
569 session_ctx.lc_thread = NULL;
570 lu_context_enter(&session_ctx);
572 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
574 env.le_ses = &session_ctx;
575 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
584 lu_context_exit(&session_ctx);
585 lu_context_fini(&session_ctx);
588 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
589 OBD_COUNTER_INCREMENT(obd, setup);
590 rc = OBP(obd, setup)(obd, cfg);
595 static inline int obd_precleanup(struct obd_device *obd,
596 enum obd_cleanup_stage cleanup_stage)
599 DECLARE_LU_VARS(ldt, d);
601 rc = obd_check_dev(obd);
604 ldt = obd->obd_type->typ_lu;
606 if (ldt != NULL && d != NULL) {
607 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
610 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
612 ldt->ldt_ops->ldto_device_fini(&env, d);
617 OBD_CHECK_DT_OP(obd, precleanup, 0);
618 OBD_COUNTER_INCREMENT(obd, precleanup);
620 rc = OBP(obd, precleanup)(obd, cleanup_stage);
624 static inline int obd_cleanup(struct obd_device *obd)
627 DECLARE_LU_VARS(ldt, d);
629 rc = obd_check_dev(obd);
633 ldt = obd->obd_type->typ_lu;
635 if (ldt != NULL && d != NULL) {
638 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
640 ldt->ldt_ops->ldto_device_free(&env, d);
642 obd->obd_lu_dev = NULL;
645 OBD_CHECK_DT_OP(obd, cleanup, 0);
646 OBD_COUNTER_INCREMENT(obd, cleanup);
648 rc = OBP(obd, cleanup)(obd);
652 static inline void obd_cleanup_client_import(struct obd_device *obd)
654 /* If we set up but never connected, the
655 client import will not have been cleaned. */
656 down_write(&obd->u.cli.cl_sem);
657 if (obd->u.cli.cl_import) {
658 struct obd_import *imp;
659 imp = obd->u.cli.cl_import;
660 CDEBUG(D_CONFIG, "%s: client import never connected\n",
662 ptlrpc_invalidate_import(imp);
663 if (imp->imp_rq_pool) {
664 ptlrpc_free_rq_pool(imp->imp_rq_pool);
665 imp->imp_rq_pool = NULL;
667 client_destroy_import(imp);
668 obd->u.cli.cl_import = NULL;
670 up_write(&obd->u.cli.cl_sem);
674 obd_process_config(struct obd_device *obd, int datalen, void *data)
677 DECLARE_LU_VARS(ldt, d);
679 rc = obd_check_dev(obd);
683 obd->obd_process_conf = 1;
684 ldt = obd->obd_type->typ_lu;
686 if (ldt != NULL && d != NULL) {
689 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
691 rc = d->ld_ops->ldo_process_config(&env, d, data);
695 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
696 rc = OBP(obd, process_config)(obd, datalen, data);
698 OBD_COUNTER_INCREMENT(obd, process_config);
699 obd->obd_process_conf = 0;
704 /* Pack an in-memory MD struct for storage on disk.
705 * Returns +ve size of packed MD (0 for free), or -ve error.
707 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
708 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
709 * If @*disk_tgt == NULL, it will be allocated
711 static inline int obd_packmd(struct obd_export *exp,
712 struct lov_mds_md **disk_tgt,
713 struct lov_stripe_md *mem_src)
717 EXP_CHECK_DT_OP(exp, packmd);
718 EXP_COUNTER_INCREMENT(exp, packmd);
720 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
724 static inline int obd_size_diskmd(struct obd_export *exp,
725 struct lov_stripe_md *mem_src)
727 return obd_packmd(exp, NULL, mem_src);
730 static inline int obd_free_diskmd(struct obd_export *exp,
731 struct lov_mds_md **disk_tgt)
736 * LU-2590, for caller's convenience, *disk_tgt could be host
737 * endianness, it needs swab to LE if necessary, while just
738 * lov_mds_md header needs it for figuring out how much memory
741 if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
742 (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) ||
743 ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3)))
744 lustre_swab_lov_mds_md(*disk_tgt);
745 return obd_packmd(exp, disk_tgt, NULL);
748 /* Unpack an MD struct from disk to in-memory format.
749 * Returns +ve size of unpacked MD (0 for free), or -ve error.
751 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
752 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
753 * If @*mem_tgt == NULL, it will be allocated
755 static inline int obd_unpackmd(struct obd_export *exp,
756 struct lov_stripe_md **mem_tgt,
757 struct lov_mds_md *disk_src,
762 EXP_CHECK_DT_OP(exp, unpackmd);
763 EXP_COUNTER_INCREMENT(exp, unpackmd);
765 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
769 /* helper functions */
770 static inline int obd_alloc_memmd(struct obd_export *exp,
771 struct lov_stripe_md **mem_tgt)
774 LASSERT(*mem_tgt == NULL);
775 return obd_unpackmd(exp, mem_tgt, NULL, 0);
778 static inline int obd_free_memmd(struct obd_export *exp,
779 struct lov_stripe_md **mem_tgt)
785 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
790 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
791 struct obdo *obdo, struct lov_stripe_md **ea,
792 struct obd_trans_info *oti)
796 EXP_CHECK_DT_OP(exp, create);
797 EXP_COUNTER_INCREMENT(exp, create);
799 rc = OBP(exp->exp_obd, create)(env, exp, obdo, ea, oti);
803 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
804 struct obdo *obdo, struct lov_stripe_md *ea,
805 struct obd_trans_info *oti,
806 struct obd_export *md_exp, void *capa)
810 EXP_CHECK_DT_OP(exp, destroy);
811 EXP_COUNTER_INCREMENT(exp, destroy);
813 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp, capa);
817 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
818 struct obd_info *oinfo)
822 EXP_CHECK_DT_OP(exp, getattr);
823 EXP_COUNTER_INCREMENT(exp, getattr);
825 rc = OBP(exp->exp_obd, getattr)(env, exp, oinfo);
829 static inline int obd_getattr_async(struct obd_export *exp,
830 struct obd_info *oinfo,
831 struct ptlrpc_request_set *set)
835 EXP_CHECK_DT_OP(exp, getattr_async);
836 EXP_COUNTER_INCREMENT(exp, getattr_async);
838 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
842 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
843 struct obd_info *oinfo,
844 struct obd_trans_info *oti)
848 EXP_CHECK_DT_OP(exp, setattr);
849 EXP_COUNTER_INCREMENT(exp, setattr);
851 rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti);
855 /* This performs all the requests set init/wait/destroy actions. */
856 static inline int obd_setattr_rqset(struct obd_export *exp,
857 struct obd_info *oinfo,
858 struct obd_trans_info *oti)
860 struct ptlrpc_request_set *set = NULL;
863 EXP_CHECK_DT_OP(exp, setattr_async);
864 EXP_COUNTER_INCREMENT(exp, setattr_async);
866 set = ptlrpc_prep_set();
870 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
872 rc = ptlrpc_set_wait(set);
873 ptlrpc_set_destroy(set);
877 /* This adds all the requests into @set if @set != NULL, otherwise
878 all requests are sent asynchronously without waiting for response. */
879 static inline int obd_setattr_async(struct obd_export *exp,
880 struct obd_info *oinfo,
881 struct obd_trans_info *oti,
882 struct ptlrpc_request_set *set)
886 EXP_CHECK_DT_OP(exp, setattr_async);
887 EXP_COUNTER_INCREMENT(exp, setattr_async);
889 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
893 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
896 struct obd_device *obd = imp->imp_obd;
899 rc = obd_check_dev_active(obd);
902 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
903 OBD_COUNTER_INCREMENT(obd, add_conn);
905 rc = OBP(obd, add_conn)(imp, uuid, priority);
909 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
911 struct obd_device *obd = imp->imp_obd;
914 rc = obd_check_dev_active(obd);
917 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
918 OBD_COUNTER_INCREMENT(obd, del_conn);
920 rc = OBP(obd, del_conn)(imp, uuid);
924 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
926 struct obd_uuid *uuid;
928 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
929 EXP_COUNTER_INCREMENT(exp, get_uuid);
931 uuid = OBP(exp->exp_obd, get_uuid)(exp);
935 /** Create a new /a exp on device /a obd for the uuid /a cluuid
936 * @param exp New export handle
937 * @param d Connect data, supported flags are set, flags also understood
938 * by obd are returned.
940 static inline int obd_connect(const struct lu_env *env,
941 struct obd_export **exp, struct obd_device *obd,
942 struct obd_uuid *cluuid,
943 struct obd_connect_data *data,
947 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
950 rc = obd_check_dev_active(obd);
953 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
954 OBD_COUNTER_INCREMENT(obd, connect);
956 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
957 /* check that only subset is granted */
958 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
959 data->ocd_connect_flags));
963 static inline int obd_reconnect(const struct lu_env *env,
964 struct obd_export *exp,
965 struct obd_device *obd,
966 struct obd_uuid *cluuid,
967 struct obd_connect_data *d,
971 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
974 rc = obd_check_dev_active(obd);
977 OBD_CHECK_DT_OP(obd, reconnect, 0);
978 OBD_COUNTER_INCREMENT(obd, reconnect);
980 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
981 /* check that only subset is granted */
982 LASSERT(ergo(d != NULL,
983 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
987 static inline int obd_disconnect(struct obd_export *exp)
991 EXP_CHECK_DT_OP(exp, disconnect);
992 EXP_COUNTER_INCREMENT(exp, disconnect);
994 rc = OBP(exp->exp_obd, disconnect)(exp);
998 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
999 enum lu_cli_type type)
1003 OBD_CHECK_DT_OP(obd, fid_init, 0);
1004 OBD_COUNTER_INCREMENT(obd, fid_init);
1006 rc = OBP(obd, fid_init)(obd, exp, type);
1010 static inline int obd_fid_fini(struct obd_device *obd)
1014 OBD_CHECK_DT_OP(obd, fid_fini, 0);
1015 OBD_COUNTER_INCREMENT(obd, fid_fini);
1017 rc = OBP(obd, fid_fini)(obd);
1021 static inline int obd_fid_alloc(struct obd_export *exp,
1023 struct md_op_data *op_data)
1027 EXP_CHECK_DT_OP(exp, fid_alloc);
1028 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1030 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
1034 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1038 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1039 OBD_COUNTER_INCREMENT(obd, pool_new);
1041 rc = OBP(obd, pool_new)(obd, poolname);
1045 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1049 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1050 OBD_COUNTER_INCREMENT(obd, pool_del);
1052 rc = OBP(obd, pool_del)(obd, poolname);
1056 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1060 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1061 OBD_COUNTER_INCREMENT(obd, pool_add);
1063 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1067 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1071 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1072 OBD_COUNTER_INCREMENT(obd, pool_rem);
1074 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1078 static inline void obd_getref(struct obd_device *obd)
1080 if (OBT(obd) && OBP(obd, getref)) {
1081 OBD_COUNTER_INCREMENT(obd, getref);
1082 OBP(obd, getref)(obd);
1086 static inline void obd_putref(struct obd_device *obd)
1088 if (OBT(obd) && OBP(obd, putref)) {
1089 OBD_COUNTER_INCREMENT(obd, putref);
1090 OBP(obd, putref)(obd);
1094 static inline int obd_init_export(struct obd_export *exp)
1098 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1099 OBP((exp)->exp_obd, init_export))
1100 rc = OBP(exp->exp_obd, init_export)(exp);
1104 static inline int obd_destroy_export(struct obd_export *exp)
1106 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1107 OBP((exp)->exp_obd, destroy_export))
1108 OBP(exp->exp_obd, destroy_export)(exp);
1112 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1113 * If the cache is older than @max_age we will get a new value from the
1114 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1115 static inline int obd_statfs_async(struct obd_export *exp,
1116 struct obd_info *oinfo,
1118 struct ptlrpc_request_set *rqset)
1121 struct obd_device *obd;
1123 if (exp == NULL || exp->exp_obd == NULL)
1127 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1128 OBD_COUNTER_INCREMENT(obd, statfs);
1130 CDEBUG(D_SUPER, "%s: osfs %p age %llu, max_age %llu\n",
1131 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1132 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1133 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1136 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1137 obd->obd_name, &obd->obd_osfs,
1138 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1139 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1140 spin_lock(&obd->obd_osfs_lock);
1141 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1142 spin_unlock(&obd->obd_osfs_lock);
1143 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1144 if (oinfo->oi_cb_up)
1145 oinfo->oi_cb_up(oinfo, 0);
1150 static inline int obd_statfs_rqset(struct obd_export *exp,
1151 struct obd_statfs *osfs, __u64 max_age,
1154 struct ptlrpc_request_set *set = NULL;
1155 struct obd_info oinfo = { { { 0 } } };
1158 set = ptlrpc_prep_set();
1162 oinfo.oi_osfs = osfs;
1163 oinfo.oi_flags = flags;
1164 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1166 rc = ptlrpc_set_wait(set);
1167 ptlrpc_set_destroy(set);
1171 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1172 * If the cache is older than @max_age we will get a new value from the
1173 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1174 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1175 struct obd_statfs *osfs, __u64 max_age,
1179 struct obd_device *obd = exp->exp_obd;
1184 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1185 OBD_COUNTER_INCREMENT(obd, statfs);
1187 CDEBUG(D_SUPER, "osfs %llu, max_age %llu\n",
1188 obd->obd_osfs_age, max_age);
1189 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1190 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1192 spin_lock(&obd->obd_osfs_lock);
1193 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1194 obd->obd_osfs_age = cfs_time_current_64();
1195 spin_unlock(&obd->obd_osfs_lock);
1198 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1199 obd->obd_name, &obd->obd_osfs,
1200 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1201 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1202 spin_lock(&obd->obd_osfs_lock);
1203 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1204 spin_unlock(&obd->obd_osfs_lock);
1209 static inline int obd_preprw(const struct lu_env *env, int cmd,
1210 struct obd_export *exp, struct obdo *oa,
1211 int objcount, struct obd_ioobj *obj,
1212 struct niobuf_remote *remote, int *pages,
1213 struct niobuf_local *local,
1214 struct obd_trans_info *oti,
1215 struct lustre_capa *capa)
1219 EXP_CHECK_DT_OP(exp, preprw);
1220 EXP_COUNTER_INCREMENT(exp, preprw);
1222 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1223 pages, local, oti, capa);
1227 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1228 struct obd_export *exp, struct obdo *oa,
1229 int objcount, struct obd_ioobj *obj,
1230 struct niobuf_remote *rnb, int pages,
1231 struct niobuf_local *local,
1232 struct obd_trans_info *oti, int rc)
1234 EXP_CHECK_DT_OP(exp, commitrw);
1235 EXP_COUNTER_INCREMENT(exp, commitrw);
1237 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1238 rnb, pages, local, oti, rc);
1242 static inline int obd_adjust_kms(struct obd_export *exp,
1243 struct lov_stripe_md *lsm, u64 size,
1248 EXP_CHECK_DT_OP(exp, adjust_kms);
1249 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1251 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1255 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1256 int len, void *karg, void *uarg)
1260 EXP_CHECK_DT_OP(exp, iocontrol);
1261 EXP_COUNTER_INCREMENT(exp, iocontrol);
1263 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1267 static inline int obd_find_cbdata(struct obd_export *exp,
1268 struct lov_stripe_md *lsm,
1269 ldlm_iterator_t it, void *data)
1273 EXP_CHECK_DT_OP(exp, find_cbdata);
1274 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1276 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1280 static inline void obd_import_event(struct obd_device *obd,
1281 struct obd_import *imp,
1282 enum obd_import_event event)
1285 CERROR("NULL device\n");
1288 if (obd->obd_set_up && OBP(obd, import_event)) {
1289 OBD_COUNTER_INCREMENT(obd, import_event);
1290 OBP(obd, import_event)(obd, imp, event);
1294 static inline int obd_notify(struct obd_device *obd,
1295 struct obd_device *watched,
1296 enum obd_notify_event ev,
1301 rc = obd_check_dev(obd);
1305 /* the check for async_recov is a complete hack - I'm hereby
1306 overloading the meaning to also mean "this was called from
1307 mds_postsetup". I know that my mds is able to handle notifies
1308 by this point, and it needs to get them to execute mds_postrecov. */
1309 if (!obd->obd_set_up && !obd->obd_async_recov) {
1310 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1314 if (!OBP(obd, notify)) {
1315 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1319 OBD_COUNTER_INCREMENT(obd, notify);
1320 rc = OBP(obd, notify)(obd, watched, ev, data);
1324 static inline int obd_notify_observer(struct obd_device *observer,
1325 struct obd_device *observed,
1326 enum obd_notify_event ev,
1332 struct obd_notify_upcall *onu;
1334 if (observer->obd_observer)
1335 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1339 * Also, call non-obd listener, if any
1341 onu = &observer->obd_upcall;
1342 if (onu->onu_upcall != NULL)
1343 rc2 = onu->onu_upcall(observer, observed, ev,
1344 onu->onu_owner, NULL);
1348 return rc1 ? rc1 : rc2;
1351 static inline int obd_quotacheck(struct obd_export *exp,
1352 struct obd_quotactl *oqctl)
1356 EXP_CHECK_DT_OP(exp, quotacheck);
1357 EXP_COUNTER_INCREMENT(exp, quotacheck);
1359 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1363 static inline int obd_quotactl(struct obd_export *exp,
1364 struct obd_quotactl *oqctl)
1368 EXP_CHECK_DT_OP(exp, quotactl);
1369 EXP_COUNTER_INCREMENT(exp, quotactl);
1371 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1375 static inline int obd_health_check(const struct lu_env *env,
1376 struct obd_device *obd)
1378 /* returns: 0 on healthy
1379 * >0 on unhealthy + reason code/flag
1380 * however the only supported reason == 1 right now
1381 * We'll need to define some better reasons
1382 * or flags in the future.
1387 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1388 if (obd == NULL || !OBT(obd)) {
1389 CERROR("cleaned up obd\n");
1392 if (!obd->obd_set_up || obd->obd_stopping)
1394 if (!OBP(obd, health_check))
1397 rc = OBP(obd, health_check)(env, obd);
1401 static inline int obd_register_observer(struct obd_device *obd,
1402 struct obd_device *observer)
1406 rc = obd_check_dev(obd);
1409 down_write(&obd->obd_observer_link_sem);
1410 if (obd->obd_observer && observer) {
1411 up_write(&obd->obd_observer_link_sem);
1414 obd->obd_observer = observer;
1415 up_write(&obd->obd_observer_link_sem);
1420 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1421 obd_page_removal_cb_t cb,
1422 obd_pin_extent_cb pin_cb)
1426 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1427 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1429 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1433 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1434 obd_page_removal_cb_t cb)
1438 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1439 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1441 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1445 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1446 obd_lock_cancel_cb cb)
1450 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1451 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1453 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1457 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1458 obd_lock_cancel_cb cb)
1462 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1463 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1465 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1470 /* metadata helpers */
1471 static inline int md_getstatus(struct obd_export *exp,
1472 struct lu_fid *fid, struct obd_capa **pc)
1476 EXP_CHECK_MD_OP(exp, getstatus);
1477 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1478 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1482 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1483 struct ptlrpc_request **request)
1487 EXP_CHECK_MD_OP(exp, getattr);
1488 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1489 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1493 static inline int md_null_inode(struct obd_export *exp,
1494 const struct lu_fid *fid)
1498 EXP_CHECK_MD_OP(exp, null_inode);
1499 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1500 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1504 static inline int md_find_cbdata(struct obd_export *exp,
1505 const struct lu_fid *fid,
1506 ldlm_iterator_t it, void *data)
1510 EXP_CHECK_MD_OP(exp, find_cbdata);
1511 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1512 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1516 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1517 struct md_open_data *mod,
1518 struct ptlrpc_request **request)
1522 EXP_CHECK_MD_OP(exp, close);
1523 EXP_MD_COUNTER_INCREMENT(exp, close);
1524 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1528 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1529 const void *data, int datalen, int mode, __u32 uid,
1530 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1531 struct ptlrpc_request **request)
1535 EXP_CHECK_MD_OP(exp, create);
1536 EXP_MD_COUNTER_INCREMENT(exp, create);
1537 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1538 uid, gid, cap_effective, rdev, request);
1542 static inline int md_done_writing(struct obd_export *exp,
1543 struct md_op_data *op_data,
1544 struct md_open_data *mod)
1548 EXP_CHECK_MD_OP(exp, done_writing);
1549 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1550 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1554 static inline int md_enqueue(struct obd_export *exp,
1555 struct ldlm_enqueue_info *einfo,
1556 struct lookup_intent *it,
1557 struct md_op_data *op_data,
1558 struct lustre_handle *lockh,
1559 void *lmm, int lmmsize,
1560 struct ptlrpc_request **req,
1561 __u64 extra_lock_flags)
1565 EXP_CHECK_MD_OP(exp, enqueue);
1566 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1567 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1568 lmm, lmmsize, req, extra_lock_flags);
1572 static inline int md_getattr_name(struct obd_export *exp,
1573 struct md_op_data *op_data,
1574 struct ptlrpc_request **request)
1578 EXP_CHECK_MD_OP(exp, getattr_name);
1579 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1580 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1584 static inline int md_intent_lock(struct obd_export *exp,
1585 struct md_op_data *op_data, void *lmm,
1586 int lmmsize, struct lookup_intent *it,
1587 int lookup_flags, struct ptlrpc_request **reqp,
1588 ldlm_blocking_callback cb_blocking,
1589 __u64 extra_lock_flags)
1593 EXP_CHECK_MD_OP(exp, intent_lock);
1594 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1595 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1596 it, lookup_flags, reqp, cb_blocking,
1601 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1602 struct ptlrpc_request **request)
1606 EXP_CHECK_MD_OP(exp, link);
1607 EXP_MD_COUNTER_INCREMENT(exp, link);
1608 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1612 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1613 const char *old, int oldlen, const char *new,
1614 int newlen, struct ptlrpc_request **request)
1618 EXP_CHECK_MD_OP(exp, rename);
1619 EXP_MD_COUNTER_INCREMENT(exp, rename);
1620 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1625 static inline int md_is_subdir(struct obd_export *exp,
1626 const struct lu_fid *pfid,
1627 const struct lu_fid *cfid,
1628 struct ptlrpc_request **request)
1632 EXP_CHECK_MD_OP(exp, is_subdir);
1633 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1634 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1638 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1639 void *ea, int ealen, void *ea2, int ea2len,
1640 struct ptlrpc_request **request,
1641 struct md_open_data **mod)
1645 EXP_CHECK_MD_OP(exp, setattr);
1646 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1647 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1648 ea2, ea2len, request, mod);
1652 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1653 struct obd_capa *oc, struct ptlrpc_request **request)
1657 EXP_CHECK_MD_OP(exp, sync);
1658 EXP_MD_COUNTER_INCREMENT(exp, sync);
1659 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1663 static inline int md_readpage(struct obd_export *exp, struct md_op_data *opdata,
1664 struct page **pages,
1665 struct ptlrpc_request **request)
1669 EXP_CHECK_MD_OP(exp, readpage);
1670 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1671 rc = MDP(exp->exp_obd, readpage)(exp, opdata, pages, request);
1675 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1676 struct ptlrpc_request **request)
1680 EXP_CHECK_MD_OP(exp, unlink);
1681 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1682 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1686 static inline int md_get_lustre_md(struct obd_export *exp,
1687 struct ptlrpc_request *req,
1688 struct obd_export *dt_exp,
1689 struct obd_export *md_exp,
1690 struct lustre_md *md)
1692 EXP_CHECK_MD_OP(exp, get_lustre_md);
1693 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1694 return MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md);
1697 static inline int md_free_lustre_md(struct obd_export *exp,
1698 struct lustre_md *md)
1700 EXP_CHECK_MD_OP(exp, free_lustre_md);
1701 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1702 return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1705 static inline int md_setxattr(struct obd_export *exp,
1706 const struct lu_fid *fid, struct obd_capa *oc,
1707 u64 valid, const char *name,
1708 const char *input, int input_size,
1709 int output_size, int flags, __u32 suppgid,
1710 struct ptlrpc_request **request)
1712 EXP_CHECK_MD_OP(exp, setxattr);
1713 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1714 return MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1715 input_size, output_size, flags,
1719 static inline int md_getxattr(struct obd_export *exp,
1720 const struct lu_fid *fid, struct obd_capa *oc,
1721 u64 valid, const char *name,
1722 const char *input, int input_size,
1723 int output_size, int flags,
1724 struct ptlrpc_request **request)
1726 EXP_CHECK_MD_OP(exp, getxattr);
1727 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1728 return MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1729 input_size, output_size, flags,
1733 static inline int md_set_open_replay_data(struct obd_export *exp,
1734 struct obd_client_handle *och,
1735 struct lookup_intent *it)
1737 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1738 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1739 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
1742 static inline int md_clear_open_replay_data(struct obd_export *exp,
1743 struct obd_client_handle *och)
1745 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1746 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1747 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1750 static inline int md_set_lock_data(struct obd_export *exp,
1751 __u64 *lockh, void *data, __u64 *bits)
1753 EXP_CHECK_MD_OP(exp, set_lock_data);
1754 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1755 return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
1758 static inline int md_cancel_unused(struct obd_export *exp,
1759 const struct lu_fid *fid,
1760 ldlm_policy_data_t *policy,
1762 ldlm_cancel_flags_t flags,
1767 EXP_CHECK_MD_OP(exp, cancel_unused);
1768 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1770 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1775 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, __u64 flags,
1776 const struct lu_fid *fid,
1778 ldlm_policy_data_t *policy,
1780 struct lustre_handle *lockh)
1782 EXP_CHECK_MD_OP(exp, lock_match);
1783 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1784 return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1785 policy, mode, lockh);
1788 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1789 int def_asize, int cookiesize,
1792 EXP_CHECK_MD_OP(exp, init_ea_size);
1793 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1794 return MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1795 cookiesize, def_cookiesize);
1798 static inline int md_get_remote_perm(struct obd_export *exp,
1799 const struct lu_fid *fid,
1800 struct obd_capa *oc, __u32 suppgid,
1801 struct ptlrpc_request **request)
1803 EXP_CHECK_MD_OP(exp, get_remote_perm);
1804 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1805 return MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
1809 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1814 EXP_CHECK_MD_OP(exp, renew_capa);
1815 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1816 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1820 static inline int md_unpack_capa(struct obd_export *exp,
1821 struct ptlrpc_request *req,
1822 const struct req_msg_field *field,
1823 struct obd_capa **oc)
1827 EXP_CHECK_MD_OP(exp, unpack_capa);
1828 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
1829 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
1833 static inline int md_intent_getattr_async(struct obd_export *exp,
1834 struct md_enqueue_info *minfo,
1835 struct ldlm_enqueue_info *einfo)
1839 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1840 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1841 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
1845 static inline int md_revalidate_lock(struct obd_export *exp,
1846 struct lookup_intent *it,
1847 struct lu_fid *fid, __u64 *bits)
1851 EXP_CHECK_MD_OP(exp, revalidate_lock);
1852 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1853 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1858 /* OBD Metadata Support */
1860 extern int obd_init_caches(void);
1861 extern void obd_cleanup_caches(void);
1863 /* support routines */
1864 extern struct kmem_cache *obdo_cachep;
1866 #define OBDO_ALLOC(ptr) \
1868 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1871 #define OBDO_FREE(ptr) \
1873 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1877 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
1879 /* something here */
1882 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
1884 /* something here */
1887 typedef int (*register_lwp_cb)(void *data);
1889 struct lwp_register_item {
1890 struct obd_export **lri_exp;
1891 register_lwp_cb lri_cb_func;
1893 struct list_head lri_list;
1894 char lri_name[MTI_NAME_MAXLEN];
1897 /* I'm as embarrassed about this as you are.
1899 * <shaver> // XXX do not look into _superhack with remaining eye
1900 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1901 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1906 extern void obd_sysctl_init (void);
1907 extern void obd_sysctl_clean (void);
1910 typedef __u8 class_uuid_t[16];
1911 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1914 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1915 int class_add_uuid(const char *uuid, __u64 nid);
1916 int class_del_uuid (const char *uuid);
1917 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1918 void class_init_uuidlist(void);
1919 void class_exit_uuidlist(void);
1922 extern char obd_jobid_node[];
1923 extern struct miscdevice obd_psdev;
1924 extern spinlock_t obd_types_lock;
1927 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1929 #endif /* __LINUX_OBD_CLASS_H */