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, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
40 # include <liblustre.h>
43 #include <obd_support.h>
44 #include <lustre_import.h>
45 #include <lustre_net.h>
47 #include <lustre_lib.h>
48 #include <lustre/lustre_idl.h>
49 #include <lprocfs_status.h>
51 #if defined(__linux__)
52 #include <linux/obd_class.h>
53 #elif defined(__APPLE__)
54 #include <darwin/obd_class.h>
55 #elif defined(__WINNT__)
56 #include <winnt/obd_class.h>
58 #error Unsupported operating system.
61 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
62 * and resends for avoid deadlocks */
63 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
65 #define OBD_STATFS_PTLRPCD 0x0004 /* requests will be sent via ptlrpcd
66 * instead of a specific set. This
67 * means that we cannot rely on the set
68 * interpret routine to be called.
69 * lov_statfs_fini() must thus be called
70 * by the request interpret routine */
71 #define OBD_STATFS_FOR_MDT0 0x0008 /* The statfs is only for retrieving
72 * information from MDT0. */
73 #define OBD_FL_PUNCH 0x00000001 /* To indicate it is punch operation */
75 /* OBD Device Declarations */
76 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
77 extern rwlock_t obd_dev_lock;
79 /* OBD Operations Declarations */
80 extern struct obd_device *class_conn2obd(struct lustre_handle *);
81 extern struct obd_device *class_exp2obd(struct obd_export *);
82 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
83 extern int lustre_get_jobid(char *jobid);
85 struct lu_device_type;
88 struct obd_export *class_conn2export(struct lustre_handle *);
89 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
90 struct lprocfs_seq_vars *module_vars,
91 #ifndef HAVE_ONLY_PROCFS_SEQ
92 struct lprocfs_vars *,
94 const char *nm, struct lu_device_type *ldt);
95 int class_unregister_type(const char *nm);
97 struct obd_device *class_newdev(const char *type_name, const char *name);
98 void class_release_dev(struct obd_device *obd);
100 int class_name2dev(const char *name);
101 struct obd_device *class_name2obd(const char *name);
102 int class_uuid2dev(struct obd_uuid *uuid);
103 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
104 void class_obd_list(void);
105 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
106 const char * typ_name,
107 struct obd_uuid *grp_uuid);
108 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
110 struct obd_device * class_num2obd(int num);
111 int get_devices_count(void);
113 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
115 char *obd_export_nid2str(struct obd_export *exp);
117 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
118 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
119 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
121 int obd_zombie_impexp_init(void);
122 void obd_zombie_impexp_stop(void);
123 void obd_zombie_impexp_cull(void);
124 void obd_zombie_barrier(void);
125 void obd_exports_barrier(struct obd_device *obd);
126 int kuc_len(int payload_len);
127 struct kuc_hdr * kuc_ptr(void *p);
128 int kuc_ispayload(void *p);
129 void *kuc_alloc(int payload_len, int transport, int type);
130 void kuc_free(void *p, int payload_len);
134 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
135 struct llog_rec_hdr *, void *);
137 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
138 const char *new_name);
139 int class_process_config(struct lustre_cfg *lcfg);
140 #ifndef HAVE_ONLY_PROCFS_SEQ
141 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
142 struct lustre_cfg *lcfg, void *data);
144 int class_process_proc_seq_param(char *prefix, struct lprocfs_seq_vars *lvars,
145 struct lustre_cfg *lcfg, void *data);
146 int class_attach(struct lustre_cfg *lcfg);
147 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
148 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
149 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
150 struct obd_device *class_incref(struct obd_device *obd,
151 const char *scope, const void *source);
152 void class_decref(struct obd_device *obd,
153 const char *scope, const void *source);
154 void dump_exports(struct obd_device *obd, int locks);
155 int class_config_llog_handler(const struct lu_env *env,
156 struct llog_handle *handle,
157 struct llog_rec_hdr *rec, void *data);
158 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
159 int class_add_uuid(const char *uuid, __u64 nid);
161 #define CFG_F_START 0x01 /* Set when we start updating from a log */
162 #define CFG_F_MARKER 0x02 /* We are within a maker */
163 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
164 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
165 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
167 /* Passed as data param to class_config_parse_llog */
168 struct config_llog_instance {
171 struct super_block *cfg_sb;
172 struct obd_uuid cfg_uuid;
173 llog_cb_t cfg_callback;
174 int cfg_last_idx; /* for partial llog processing */
178 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
179 char *name, struct config_llog_instance *cfg);
180 int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
181 char *name, struct config_llog_instance *cfg);
185 CONFIG_T_SPTLRPC = 1,
186 CONFIG_T_RECOVER = 2,
191 #define PARAMS_FILENAME "params"
192 #define LCTL_UPCALL "lctl"
194 /* list of active configuration logs */
195 struct config_llog_data {
196 struct ldlm_res_id cld_resid;
197 struct config_llog_instance cld_cfg;
198 cfs_list_t cld_list_chain;
199 atomic_t cld_refcount;
200 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
201 struct config_llog_data *cld_params; /* common parameters log */
202 struct config_llog_data *cld_recover;/* imperative recover log */
203 struct obd_export *cld_mgcexp;
204 struct mutex cld_lock;
206 unsigned int cld_stopping:1, /* we were told to stop
208 cld_lostlock:1; /* lock not requeued */
212 struct lustre_profile {
219 struct lustre_profile *class_get_profile(const char * prof);
220 void class_del_profile(const char *prof);
221 void class_del_profiles(void);
223 #if LUSTRE_TRACKS_LOCK_EXP_REFS
225 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
226 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
227 extern void (*class_export_dump_hook)(struct obd_export *);
231 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
232 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
236 #define class_export_rpc_inc(exp) \
238 atomic_inc(&(exp)->exp_rpc_count); \
239 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
240 (exp), atomic_read(&(exp)->exp_rpc_count)); \
243 #define class_export_rpc_dec(exp) \
245 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
246 atomic_dec(&(exp)->exp_rpc_count); \
247 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
248 (exp), atomic_read(&(exp)->exp_rpc_count)); \
251 #define class_export_lock_get(exp, lock) \
253 atomic_inc(&(exp)->exp_locks_count); \
254 __class_export_add_lock_ref(exp, lock); \
255 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
256 (exp), atomic_read(&(exp)->exp_locks_count)); \
257 class_export_get(exp); \
260 #define class_export_lock_put(exp, lock) \
262 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
263 atomic_dec(&(exp)->exp_locks_count); \
264 __class_export_del_lock_ref(exp, lock); \
265 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
266 (exp), atomic_read(&(exp)->exp_locks_count)); \
267 class_export_put(exp); \
270 #define class_export_cb_get(exp) \
272 atomic_inc(&(exp)->exp_cb_count); \
273 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
274 (exp), atomic_read(&(exp)->exp_cb_count)); \
275 class_export_get(exp); \
278 #define class_export_cb_put(exp) \
280 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
281 atomic_dec(&(exp)->exp_cb_count); \
282 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
283 (exp), atomic_read(&(exp)->exp_cb_count)); \
284 class_export_put(exp); \
288 struct obd_export *class_export_get(struct obd_export *exp);
289 void class_export_put(struct obd_export *exp);
290 struct obd_export *class_new_export(struct obd_device *obddev,
291 struct obd_uuid *cluuid);
292 void class_unlink_export(struct obd_export *exp);
294 struct obd_import *class_import_get(struct obd_import *);
295 void class_import_put(struct obd_import *);
296 struct obd_import *class_new_import(struct obd_device *obd);
297 void class_destroy_import(struct obd_import *exp);
299 struct obd_type *class_search_type(const char *name);
300 struct obd_type *class_get_type(const char *name);
301 void class_put_type(struct obd_type *type);
302 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
303 struct obd_uuid *cluuid);
304 int class_disconnect(struct obd_export *exp);
305 void class_fail_export(struct obd_export *exp);
306 int class_connected_export(struct obd_export *exp);
307 void class_disconnect_exports(struct obd_device *obddev);
308 int class_manual_cleanup(struct obd_device *obd);
309 void class_disconnect_stale_exports(struct obd_device *,
310 int (*test_export)(struct obd_export *));
311 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
313 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
314 (obd->obd_force ? OBD_OPT_FORCE : 0) |
315 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
319 #ifdef HAVE_SERVER_SUPPORT
320 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
322 LASSERT(exp->exp_obd);
323 return exp->exp_obd->u.obt.obt_lut;
326 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
328 LASSERT(obd->u.obt.obt_lut);
329 return &obd->u.obt.obt_lut->lut_lsd;
333 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
334 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
335 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
336 unsigned int ia_valid);
337 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
338 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
339 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
342 #define OBT(dev) (dev)->obd_type
343 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
344 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
345 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
347 /* Ensure obd_setup: used for cleanup which must be called
348 while obd is stopping */
349 #define OBD_CHECK_DEV(obd) \
352 CERROR("NULL device\n"); \
357 /* ensure obd_setup and !obd_stopping */
358 #define OBD_CHECK_DEV_ACTIVE(obd) \
360 OBD_CHECK_DEV(obd); \
361 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
362 CERROR("Device %d not setup\n", \
370 #define OBD_COUNTER_OFFSET(op) \
371 ((offsetof(struct obd_ops, o_ ## op) - \
372 offsetof(struct obd_ops, o_iocontrol)) \
373 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
375 /* The '- 1' below is for o_owner. */
376 #define NUM_OBD_STATS \
377 (sizeof(struct obd_ops) / \
378 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
380 #define OBD_COUNTER_INCREMENT(obd, op) \
381 lprocfs_counter_incr((obd)->obd_stats, \
382 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
384 #define EXP_COUNTER_INCREMENT(exp, op) \
387 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
388 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
389 if ((exp)->exp_obd->obd_uses_nid_stats && \
390 (exp)->exp_nid_stats != NULL) \
391 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
395 #define _MD_COUNTER_OFFSET(m_op) \
396 ((offsetof(struct md_ops, m_op) - \
397 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
398 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
400 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
402 #define NUM_MD_STATS \
403 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
404 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
406 /* Note that we only increment md counters for ops whose offset is less
407 * than NUM_MD_STATS. This is explained in a comment in the definition
408 * of struct md_ops. */
409 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
411 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
412 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
413 (exp)->exp_obd->obd_md_cntr_base + \
414 MD_COUNTER_OFFSET(op)); \
418 #define OBD_COUNTER_OFFSET(op)
419 #define OBD_COUNTER_INCREMENT(obd, op)
420 #define EXP_COUNTER_INCREMENT(exp, op)
421 #define EXP_MD_COUNTER_INCREMENT(exp, op)
424 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
426 /* Always add in ldlm_stats */
427 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
428 ,LPROCFS_STATS_FLAG_NOPERCPU);
429 if (tmp->nid_ldlm_stats == NULL)
432 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
434 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
435 tmp->nid_ldlm_stats);
438 #define EXP_CHECK_MD_OP(exp, op) \
440 if ((exp) == NULL) { \
441 CERROR("obd_" #op ": NULL export\n"); \
444 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
445 CERROR("obd_" #op ": cleaned up obd\n"); \
446 RETURN(-EOPNOTSUPP); \
448 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
449 CERROR("obd_" #op ": dev %s/%d no operation\n", \
450 (exp)->exp_obd->obd_name, \
451 (exp)->exp_obd->obd_minor); \
452 RETURN(-EOPNOTSUPP); \
457 #define OBD_CHECK_DT_OP(obd, op, err) \
459 if (!OBT(obd) || !OBP((obd), op)) { \
461 CERROR("obd_" #op ": dev %d no operation\n", \
467 #define EXP_CHECK_DT_OP(exp, op) \
469 if ((exp) == NULL) { \
470 CERROR("obd_" #op ": NULL export\n"); \
473 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
474 CERROR("obd_" #op ": cleaned up obd\n"); \
475 RETURN(-EOPNOTSUPP); \
477 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
478 CERROR("obd_" #op ": dev %d no operation\n", \
479 (exp)->exp_obd->obd_minor); \
480 RETURN(-EOPNOTSUPP); \
484 #define CTXT_CHECK_OP(ctxt, op, err) \
486 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
488 CERROR("lop_" #op ": dev %d no operation\n", \
489 ctxt->loc_obd->obd_minor); \
494 static inline int class_devno_max(void)
496 return MAX_OBD_DEVICES;
499 static inline int obd_get_info(const struct lu_env *env,
500 struct obd_export *exp, __u32 keylen,
501 void *key, __u32 *vallen, void *val,
502 struct lov_stripe_md *lsm)
507 EXP_CHECK_DT_OP(exp, get_info);
508 EXP_COUNTER_INCREMENT(exp, get_info);
510 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val,
515 static inline int obd_set_info_async(const struct lu_env *env,
516 struct obd_export *exp, obd_count keylen,
517 void *key, obd_count vallen, void *val,
518 struct ptlrpc_request_set *set)
523 EXP_CHECK_DT_OP(exp, set_info_async);
524 EXP_COUNTER_INCREMENT(exp, set_info_async);
526 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
532 * obd-lu integration.
534 * Functionality is being moved into new lu_device-based layering, but some
535 * pieces of configuration process are still based on obd devices.
537 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
538 * subsume ->o_setup() methods of obd devices they replace. The same for
539 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
540 * result, obd_setup() and obd_process_config() branch and call one XOR
543 * Yet neither lu_device_type_operations::ldto_device_fini() nor
544 * lu_device_type_operations::ldto_device_free() fully implement the
545 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
546 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
549 #define DECLARE_LU_VARS(ldt, d) \
550 struct lu_device_type *ldt; \
553 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
556 DECLARE_LU_VARS(ldt, d);
559 ldt = obd->obd_type->typ_lu;
561 struct lu_context session_ctx;
563 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
564 session_ctx.lc_thread = NULL;
565 lu_context_enter(&session_ctx);
567 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
569 env.le_ses = &session_ctx;
570 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
579 lu_context_exit(&session_ctx);
580 lu_context_fini(&session_ctx);
583 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
584 OBD_COUNTER_INCREMENT(obd, setup);
585 rc = OBP(obd, setup)(obd, cfg);
590 static inline int obd_precleanup(struct obd_device *obd,
591 enum obd_cleanup_stage cleanup_stage)
594 DECLARE_LU_VARS(ldt, d);
598 ldt = obd->obd_type->typ_lu;
600 if (ldt != NULL && d != NULL) {
601 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
604 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
606 ldt->ldt_ops->ldto_device_fini(&env, d);
611 OBD_CHECK_DT_OP(obd, precleanup, 0);
612 OBD_COUNTER_INCREMENT(obd, precleanup);
614 rc = OBP(obd, precleanup)(obd, cleanup_stage);
618 static inline int obd_cleanup(struct obd_device *obd)
621 DECLARE_LU_VARS(ldt, d);
626 ldt = obd->obd_type->typ_lu;
628 if (ldt != NULL && d != NULL) {
631 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
633 ldt->ldt_ops->ldto_device_free(&env, d);
635 obd->obd_lu_dev = NULL;
638 OBD_CHECK_DT_OP(obd, cleanup, 0);
639 OBD_COUNTER_INCREMENT(obd, cleanup);
641 rc = OBP(obd, cleanup)(obd);
645 static inline void obd_cleanup_client_import(struct obd_device *obd)
649 /* If we set up but never connected, the
650 client import will not have been cleaned. */
651 down_write(&obd->u.cli.cl_sem);
652 if (obd->u.cli.cl_import) {
653 struct obd_import *imp;
654 imp = obd->u.cli.cl_import;
655 CDEBUG(D_CONFIG, "%s: client import never connected\n",
657 ptlrpc_invalidate_import(imp);
658 if (imp->imp_rq_pool) {
659 ptlrpc_free_rq_pool(imp->imp_rq_pool);
660 imp->imp_rq_pool = NULL;
662 client_destroy_import(imp);
663 obd->u.cli.cl_import = NULL;
665 up_write(&obd->u.cli.cl_sem);
671 obd_process_config(struct obd_device *obd, int datalen, void *data)
674 DECLARE_LU_VARS(ldt, d);
679 obd->obd_process_conf = 1;
680 ldt = obd->obd_type->typ_lu;
682 if (ldt != NULL && d != NULL) {
685 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
687 rc = d->ld_ops->ldo_process_config(&env, d, data);
691 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
692 rc = OBP(obd, process_config)(obd, datalen, data);
694 OBD_COUNTER_INCREMENT(obd, process_config);
695 obd->obd_process_conf = 0;
700 /* Pack an in-memory MD struct for storage on disk.
701 * Returns +ve size of packed MD (0 for free), or -ve error.
703 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
704 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
705 * If @*disk_tgt == NULL, it will be allocated
707 static inline int obd_packmd(struct obd_export *exp,
708 struct lov_mds_md **disk_tgt,
709 struct lov_stripe_md *mem_src)
714 EXP_CHECK_DT_OP(exp, packmd);
715 EXP_COUNTER_INCREMENT(exp, packmd);
717 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
721 static inline int obd_size_diskmd(struct obd_export *exp,
722 struct lov_stripe_md *mem_src)
724 return obd_packmd(exp, NULL, mem_src);
727 static inline int obd_free_diskmd(struct obd_export *exp,
728 struct lov_mds_md **disk_tgt)
733 * LU-2590, for caller's convenience, *disk_tgt could be host
734 * endianness, it needs swab to LE if necessary, while just
735 * lov_mds_md header needs it for figuring out how much memory
738 if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
739 (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) ||
740 ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3)))
741 lustre_swab_lov_mds_md(*disk_tgt);
742 return obd_packmd(exp, disk_tgt, NULL);
745 /* Unpack an MD struct from disk to in-memory format.
746 * Returns +ve size of unpacked MD (0 for free), or -ve error.
748 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
749 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
750 * If @*mem_tgt == NULL, it will be allocated
752 static inline int obd_unpackmd(struct obd_export *exp,
753 struct lov_stripe_md **mem_tgt,
754 struct lov_mds_md *disk_src,
760 EXP_CHECK_DT_OP(exp, unpackmd);
761 EXP_COUNTER_INCREMENT(exp, unpackmd);
763 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
767 /* helper functions */
768 static inline int obd_alloc_memmd(struct obd_export *exp,
769 struct lov_stripe_md **mem_tgt)
772 LASSERT(*mem_tgt == NULL);
773 return obd_unpackmd(exp, mem_tgt, NULL, 0);
776 static inline int obd_free_memmd(struct obd_export *exp,
777 struct lov_stripe_md **mem_tgt)
783 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
788 static inline int obd_create_async(struct obd_export *exp,
789 struct obd_info *oinfo,
790 struct lov_stripe_md **ea,
791 struct obd_trans_info *oti)
796 EXP_CHECK_DT_OP(exp, create_async);
797 EXP_COUNTER_INCREMENT(exp, create_async);
799 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
803 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
804 struct obdo *obdo, struct lov_stripe_md **ea,
805 struct obd_trans_info *oti)
810 EXP_CHECK_DT_OP(exp, create);
811 EXP_COUNTER_INCREMENT(exp, create);
813 rc = OBP(exp->exp_obd, create)(env, exp, obdo, ea, oti);
817 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
818 struct obdo *obdo, struct lov_stripe_md *ea,
819 struct obd_trans_info *oti,
820 struct obd_export *md_exp, void *capa)
825 EXP_CHECK_DT_OP(exp, destroy);
826 EXP_COUNTER_INCREMENT(exp, destroy);
828 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp, capa);
832 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
833 struct obd_info *oinfo)
838 EXP_CHECK_DT_OP(exp, getattr);
839 EXP_COUNTER_INCREMENT(exp, getattr);
841 rc = OBP(exp->exp_obd, getattr)(env, exp, oinfo);
845 static inline int obd_getattr_async(struct obd_export *exp,
846 struct obd_info *oinfo,
847 struct ptlrpc_request_set *set)
852 EXP_CHECK_DT_OP(exp, getattr_async);
853 EXP_COUNTER_INCREMENT(exp, getattr_async);
855 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
859 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
860 struct obd_info *oinfo,
861 struct obd_trans_info *oti)
866 EXP_CHECK_DT_OP(exp, setattr);
867 EXP_COUNTER_INCREMENT(exp, setattr);
869 rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti);
873 /* This performs all the requests set init/wait/destroy actions. */
874 static inline int obd_setattr_rqset(struct obd_export *exp,
875 struct obd_info *oinfo,
876 struct obd_trans_info *oti)
878 struct ptlrpc_request_set *set = NULL;
882 EXP_CHECK_DT_OP(exp, setattr_async);
883 EXP_COUNTER_INCREMENT(exp, setattr_async);
885 set = ptlrpc_prep_set();
889 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
891 rc = ptlrpc_set_wait(set);
892 ptlrpc_set_destroy(set);
896 /* This adds all the requests into @set if @set != NULL, otherwise
897 all requests are sent asynchronously without waiting for response. */
898 static inline int obd_setattr_async(struct obd_export *exp,
899 struct obd_info *oinfo,
900 struct obd_trans_info *oti,
901 struct ptlrpc_request_set *set)
906 EXP_CHECK_DT_OP(exp, setattr_async);
907 EXP_COUNTER_INCREMENT(exp, setattr_async);
909 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
913 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
916 struct obd_device *obd = imp->imp_obd;
920 OBD_CHECK_DEV_ACTIVE(obd);
921 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
922 OBD_COUNTER_INCREMENT(obd, add_conn);
924 rc = OBP(obd, add_conn)(imp, uuid, priority);
928 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
930 struct obd_device *obd = imp->imp_obd;
934 OBD_CHECK_DEV_ACTIVE(obd);
935 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
936 OBD_COUNTER_INCREMENT(obd, del_conn);
938 rc = OBP(obd, del_conn)(imp, uuid);
942 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
944 struct obd_uuid *uuid;
947 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
948 EXP_COUNTER_INCREMENT(exp, get_uuid);
950 uuid = OBP(exp->exp_obd, get_uuid)(exp);
954 /** Create a new /a exp on device /a obd for the uuid /a cluuid
955 * @param exp New export handle
956 * @param d Connect data, supported flags are set, flags also understood
957 * by obd are returned.
959 static inline int obd_connect(const struct lu_env *env,
960 struct obd_export **exp,struct obd_device *obd,
961 struct obd_uuid *cluuid,
962 struct obd_connect_data *data,
966 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
970 OBD_CHECK_DEV_ACTIVE(obd);
971 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
972 OBD_COUNTER_INCREMENT(obd, connect);
974 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
975 /* check that only subset is granted */
976 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
977 data->ocd_connect_flags));
981 static inline int obd_reconnect(const struct lu_env *env,
982 struct obd_export *exp,
983 struct obd_device *obd,
984 struct obd_uuid *cluuid,
985 struct obd_connect_data *d,
989 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
994 OBD_CHECK_DEV_ACTIVE(obd);
995 OBD_CHECK_DT_OP(obd, reconnect, 0);
996 OBD_COUNTER_INCREMENT(obd, reconnect);
998 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
999 /* check that only subset is granted */
1000 LASSERT(ergo(d != NULL,
1001 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
1005 static inline int obd_disconnect(struct obd_export *exp)
1010 EXP_CHECK_DT_OP(exp, disconnect);
1011 EXP_COUNTER_INCREMENT(exp, disconnect);
1013 rc = OBP(exp->exp_obd, disconnect)(exp);
1017 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
1018 enum lu_cli_type type)
1023 OBD_CHECK_DT_OP(obd, fid_init, 0);
1024 OBD_COUNTER_INCREMENT(obd, fid_init);
1026 rc = OBP(obd, fid_init)(obd, exp, type);
1030 static inline int obd_fid_fini(struct obd_device *obd)
1035 OBD_CHECK_DT_OP(obd, fid_fini, 0);
1036 OBD_COUNTER_INCREMENT(obd, fid_fini);
1038 rc = OBP(obd, fid_fini)(obd);
1042 static inline int obd_fid_alloc(struct obd_export *exp,
1044 struct md_op_data *op_data)
1049 EXP_CHECK_DT_OP(exp, fid_alloc);
1050 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1052 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
1056 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
1061 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1062 EXP_COUNTER_INCREMENT(exp, ping);
1064 rc = OBP(exp->exp_obd, ping)(env, exp);
1068 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1073 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1074 OBD_COUNTER_INCREMENT(obd, pool_new);
1076 rc = OBP(obd, pool_new)(obd, poolname);
1080 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1085 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1086 OBD_COUNTER_INCREMENT(obd, pool_del);
1088 rc = OBP(obd, pool_del)(obd, poolname);
1092 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1097 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1098 OBD_COUNTER_INCREMENT(obd, pool_add);
1100 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1104 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1109 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1110 OBD_COUNTER_INCREMENT(obd, pool_rem);
1112 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1116 static inline void obd_getref(struct obd_device *obd)
1119 if (OBT(obd) && OBP(obd, getref)) {
1120 OBD_COUNTER_INCREMENT(obd, getref);
1121 OBP(obd, getref)(obd);
1126 static inline void obd_putref(struct obd_device *obd)
1129 if (OBT(obd) && OBP(obd, putref)) {
1130 OBD_COUNTER_INCREMENT(obd, putref);
1131 OBP(obd, putref)(obd);
1136 static inline int obd_init_export(struct obd_export *exp)
1141 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1142 OBP((exp)->exp_obd, init_export))
1143 rc = OBP(exp->exp_obd, init_export)(exp);
1147 static inline int obd_destroy_export(struct obd_export *exp)
1150 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1151 OBP((exp)->exp_obd, destroy_export))
1152 OBP(exp->exp_obd, destroy_export)(exp);
1156 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1157 * If the cache is older than @max_age we will get a new value from the
1158 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1159 static inline int obd_statfs_async(struct obd_export *exp,
1160 struct obd_info *oinfo,
1162 struct ptlrpc_request_set *rqset)
1165 struct obd_device *obd;
1168 if (exp == NULL || exp->exp_obd == NULL)
1172 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1173 OBD_COUNTER_INCREMENT(obd, statfs);
1175 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1176 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1177 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1178 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1180 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1181 " objects "LPU64"/"LPU64"\n",
1182 obd->obd_name, &obd->obd_osfs,
1183 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1184 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1185 spin_lock(&obd->obd_osfs_lock);
1186 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1187 spin_unlock(&obd->obd_osfs_lock);
1188 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1189 if (oinfo->oi_cb_up)
1190 oinfo->oi_cb_up(oinfo, 0);
1195 static inline int obd_statfs_rqset(struct obd_export *exp,
1196 struct obd_statfs *osfs, __u64 max_age,
1199 struct ptlrpc_request_set *set = NULL;
1200 struct obd_info oinfo = { { { 0 } } };
1204 set = ptlrpc_prep_set();
1208 oinfo.oi_osfs = osfs;
1209 oinfo.oi_flags = flags;
1210 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1212 rc = ptlrpc_set_wait(set);
1213 ptlrpc_set_destroy(set);
1217 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1218 * If the cache is older than @max_age we will get a new value from the
1219 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1220 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1221 struct obd_statfs *osfs, __u64 max_age,
1225 struct obd_device *obd = exp->exp_obd;
1231 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1232 OBD_COUNTER_INCREMENT(obd, statfs);
1234 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1235 obd->obd_osfs_age, max_age);
1236 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1237 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1239 spin_lock(&obd->obd_osfs_lock);
1240 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1241 obd->obd_osfs_age = cfs_time_current_64();
1242 spin_unlock(&obd->obd_osfs_lock);
1245 CDEBUG(D_SUPER, "%s: use %p cache blocks "LPU64"/"LPU64
1246 " objects "LPU64"/"LPU64"\n",
1247 obd->obd_name, &obd->obd_osfs,
1248 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1249 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1250 spin_lock(&obd->obd_osfs_lock);
1251 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1252 spin_unlock(&obd->obd_osfs_lock);
1257 static inline int obd_preprw(const struct lu_env *env, int cmd,
1258 struct obd_export *exp, struct obdo *oa,
1259 int objcount, struct obd_ioobj *obj,
1260 struct niobuf_remote *remote, int *pages,
1261 struct niobuf_local *local,
1262 struct obd_trans_info *oti,
1263 struct lustre_capa *capa)
1268 EXP_CHECK_DT_OP(exp, preprw);
1269 EXP_COUNTER_INCREMENT(exp, preprw);
1271 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1272 pages, local, oti, capa);
1276 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1277 struct obd_export *exp, struct obdo *oa,
1278 int objcount, struct obd_ioobj *obj,
1279 struct niobuf_remote *rnb, int pages,
1280 struct niobuf_local *local,
1281 struct obd_trans_info *oti, int rc)
1285 EXP_CHECK_DT_OP(exp, commitrw);
1286 EXP_COUNTER_INCREMENT(exp, commitrw);
1288 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1289 rnb, pages, local, oti, rc);
1293 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1294 int len, void *karg, void *uarg)
1299 EXP_CHECK_DT_OP(exp, iocontrol);
1300 EXP_COUNTER_INCREMENT(exp, iocontrol);
1302 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1306 static inline int obd_change_cbdata(struct obd_export *exp,
1307 struct lov_stripe_md *lsm,
1308 ldlm_iterator_t it, void *data)
1313 EXP_CHECK_DT_OP(exp, change_cbdata);
1314 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1316 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1320 static inline int obd_find_cbdata(struct obd_export *exp,
1321 struct lov_stripe_md *lsm,
1322 ldlm_iterator_t it, void *data)
1327 EXP_CHECK_DT_OP(exp, find_cbdata);
1328 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1330 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1334 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1335 struct obd_capa *oc, struct obd_client_handle *handle,
1341 EXP_CHECK_DT_OP(exp, pin);
1342 EXP_COUNTER_INCREMENT(exp, pin);
1344 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1348 static inline int obd_unpin(struct obd_export *exp,
1349 struct obd_client_handle *handle, int flag)
1354 EXP_CHECK_DT_OP(exp, unpin);
1355 EXP_COUNTER_INCREMENT(exp, unpin);
1357 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1362 static inline void obd_import_event(struct obd_device *obd,
1363 struct obd_import *imp,
1364 enum obd_import_event event)
1368 CERROR("NULL device\n");
1372 if (obd->obd_set_up && OBP(obd, import_event)) {
1373 OBD_COUNTER_INCREMENT(obd, import_event);
1374 OBP(obd, import_event)(obd, imp, event);
1379 static inline int obd_llog_connect(struct obd_export *exp,
1380 struct llogd_conn_body *body)
1385 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1386 EXP_COUNTER_INCREMENT(exp, llog_connect);
1388 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1393 static inline int obd_notify(struct obd_device *obd,
1394 struct obd_device *watched,
1395 enum obd_notify_event ev,
1402 /* the check for async_recov is a complete hack - I'm hereby
1403 overloading the meaning to also mean "this was called from
1404 mds_postsetup". I know that my mds is able to handle notifies
1405 by this point, and it needs to get them to execute mds_postrecov. */
1406 if (!obd->obd_set_up && !obd->obd_async_recov) {
1407 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1411 if (!OBP(obd, notify)) {
1412 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1416 OBD_COUNTER_INCREMENT(obd, notify);
1417 rc = OBP(obd, notify)(obd, watched, ev, data);
1421 static inline int obd_notify_observer(struct obd_device *observer,
1422 struct obd_device *observed,
1423 enum obd_notify_event ev,
1429 struct obd_notify_upcall *onu;
1431 if (observer->obd_observer)
1432 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1436 * Also, call non-obd listener, if any
1438 onu = &observer->obd_upcall;
1439 if (onu->onu_upcall != NULL)
1440 rc2 = onu->onu_upcall(observer, observed, ev,
1441 onu->onu_owner, NULL);
1445 return rc1 ? rc1 : rc2;
1448 static inline int obd_quotacheck(struct obd_export *exp,
1449 struct obd_quotactl *oqctl)
1454 EXP_CHECK_DT_OP(exp, quotacheck);
1455 EXP_COUNTER_INCREMENT(exp, quotacheck);
1457 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1461 static inline int obd_quotactl(struct obd_export *exp,
1462 struct obd_quotactl *oqctl)
1467 EXP_CHECK_DT_OP(exp, quotactl);
1468 EXP_COUNTER_INCREMENT(exp, quotactl);
1470 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1474 static inline int obd_health_check(const struct lu_env *env,
1475 struct obd_device *obd)
1477 /* returns: 0 on healthy
1478 * >0 on unhealthy + reason code/flag
1479 * however the only suppored reason == 1 right now
1480 * We'll need to define some better reasons
1481 * or flags in the future.
1487 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1488 if (obd == NULL || !OBT(obd)) {
1489 CERROR("cleaned up obd\n");
1490 RETURN(-EOPNOTSUPP);
1492 if (!obd->obd_set_up || obd->obd_stopping)
1494 if (!OBP(obd, health_check))
1497 rc = OBP(obd, health_check)(env, obd);
1501 static inline int obd_register_observer(struct obd_device *obd,
1502 struct obd_device *observer)
1506 down_write(&obd->obd_observer_link_sem);
1507 if (obd->obd_observer && observer) {
1508 up_write(&obd->obd_observer_link_sem);
1511 obd->obd_observer = observer;
1512 up_write(&obd->obd_observer_link_sem);
1516 static inline int obd_pin_observer(struct obd_device *obd,
1517 struct obd_device **observer)
1520 down_read(&obd->obd_observer_link_sem);
1521 if (!obd->obd_observer) {
1523 up_read(&obd->obd_observer_link_sem);
1526 *observer = obd->obd_observer;
1530 static inline int obd_unpin_observer(struct obd_device *obd)
1533 up_read(&obd->obd_observer_link_sem);
1538 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1539 obd_page_removal_cb_t cb,
1540 obd_pin_extent_cb pin_cb)
1545 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1546 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1548 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1552 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1553 obd_page_removal_cb_t cb)
1558 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1559 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1561 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1565 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1566 obd_lock_cancel_cb cb)
1571 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1572 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1574 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1578 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1579 obd_lock_cancel_cb cb)
1584 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1585 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1587 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1592 /* metadata helpers */
1593 static inline int md_getstatus(struct obd_export *exp,
1594 struct lu_fid *fid, struct obd_capa **pc)
1599 EXP_CHECK_MD_OP(exp, getstatus);
1600 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1601 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1605 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1606 struct ptlrpc_request **request)
1610 EXP_CHECK_MD_OP(exp, getattr);
1611 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1612 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1616 static inline int md_null_inode(struct obd_export *exp,
1617 const struct lu_fid *fid)
1621 EXP_CHECK_MD_OP(exp, null_inode);
1622 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1623 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1627 static inline int md_find_cbdata(struct obd_export *exp,
1628 const struct lu_fid *fid,
1629 ldlm_iterator_t it, void *data)
1633 EXP_CHECK_MD_OP(exp, find_cbdata);
1634 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1635 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1639 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1640 struct md_open_data *mod,
1641 struct ptlrpc_request **request)
1645 EXP_CHECK_MD_OP(exp, close);
1646 EXP_MD_COUNTER_INCREMENT(exp, close);
1647 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1651 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1652 const void *data, int datalen, int mode, __u32 uid,
1653 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1654 struct ptlrpc_request **request)
1658 EXP_CHECK_MD_OP(exp, create);
1659 EXP_MD_COUNTER_INCREMENT(exp, create);
1660 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1661 uid, gid, cap_effective, rdev, request);
1665 static inline int md_done_writing(struct obd_export *exp,
1666 struct md_op_data *op_data,
1667 struct md_open_data *mod)
1671 EXP_CHECK_MD_OP(exp, done_writing);
1672 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1673 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1677 static inline int md_enqueue(struct obd_export *exp,
1678 struct ldlm_enqueue_info *einfo,
1679 struct lookup_intent *it,
1680 struct md_op_data *op_data,
1681 struct lustre_handle *lockh,
1682 void *lmm, int lmmsize,
1683 struct ptlrpc_request **req,
1684 __u64 extra_lock_flags)
1688 EXP_CHECK_MD_OP(exp, enqueue);
1689 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1690 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1691 lmm, lmmsize, req, extra_lock_flags);
1695 static inline int md_getattr_name(struct obd_export *exp,
1696 struct md_op_data *op_data,
1697 struct ptlrpc_request **request)
1701 EXP_CHECK_MD_OP(exp, getattr_name);
1702 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1703 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1707 static inline int md_intent_lock(struct obd_export *exp,
1708 struct md_op_data *op_data, void *lmm,
1709 int lmmsize, struct lookup_intent *it,
1710 int lookup_flags, struct ptlrpc_request **reqp,
1711 ldlm_blocking_callback cb_blocking,
1712 __u64 extra_lock_flags)
1716 EXP_CHECK_MD_OP(exp, intent_lock);
1717 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1718 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1719 it, lookup_flags, reqp, cb_blocking,
1724 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1725 struct ptlrpc_request **request)
1729 EXP_CHECK_MD_OP(exp, link);
1730 EXP_MD_COUNTER_INCREMENT(exp, link);
1731 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1735 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1736 const char *old, int oldlen, const char *new,
1737 int newlen, struct ptlrpc_request **request)
1741 EXP_CHECK_MD_OP(exp, rename);
1742 EXP_MD_COUNTER_INCREMENT(exp, rename);
1743 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1748 static inline int md_is_subdir(struct obd_export *exp,
1749 const struct lu_fid *pfid,
1750 const struct lu_fid *cfid,
1751 struct ptlrpc_request **request)
1755 EXP_CHECK_MD_OP(exp, is_subdir);
1756 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1757 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1761 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1762 void *ea, int ealen, void *ea2, int ea2len,
1763 struct ptlrpc_request **request,
1764 struct md_open_data **mod)
1768 EXP_CHECK_MD_OP(exp, setattr);
1769 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1770 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1771 ea2, ea2len, request, mod);
1775 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1776 struct obd_capa *oc, struct ptlrpc_request **request)
1780 EXP_CHECK_MD_OP(exp, fsync);
1781 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1782 rc = MDP(exp->exp_obd, fsync)(exp, fid, oc, request);
1786 static inline int md_readpage(struct obd_export *exp, struct md_op_data *opdata,
1787 struct page **pages,
1788 struct ptlrpc_request **request)
1792 EXP_CHECK_MD_OP(exp, readpage);
1793 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1794 rc = MDP(exp->exp_obd, readpage)(exp, opdata, pages, request);
1798 static inline int md_read_entry(struct obd_export *exp,
1799 struct md_op_data *op_data,
1800 struct md_callback *cb_op,
1801 struct lu_dirent **ld,
1802 struct page **ppage)
1806 EXP_CHECK_MD_OP(exp, read_entry);
1807 EXP_MD_COUNTER_INCREMENT(exp, read_entry);
1808 rc = MDP(exp->exp_obd, read_entry)(exp, op_data, cb_op, ld, ppage);
1812 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1813 struct ptlrpc_request **request)
1817 EXP_CHECK_MD_OP(exp, unlink);
1818 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1819 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1823 static inline int md_get_lustre_md(struct obd_export *exp,
1824 struct ptlrpc_request *req,
1825 struct obd_export *dt_exp,
1826 struct obd_export *md_exp,
1827 struct lustre_md *md)
1830 EXP_CHECK_MD_OP(exp, get_lustre_md);
1831 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1832 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1835 static inline int md_free_lustre_md(struct obd_export *exp,
1836 struct lustre_md *md)
1839 EXP_CHECK_MD_OP(exp, free_lustre_md);
1840 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1841 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1844 static inline int md_update_lsm_md(struct obd_export *exp,
1845 struct lmv_stripe_md *lsm,
1846 struct mdt_body *body,
1847 ldlm_blocking_callback cb)
1850 EXP_CHECK_MD_OP(exp, update_lsm_md);
1851 EXP_MD_COUNTER_INCREMENT(exp, update_lsm_md);
1852 RETURN(MDP(exp->exp_obd, update_lsm_md)(exp, lsm, body, cb));
1855 static inline int md_merge_attr(struct obd_export *exp,
1856 const struct lmv_stripe_md *lsm,
1857 struct cl_attr *attr)
1860 EXP_CHECK_MD_OP(exp, merge_attr);
1861 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1862 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr));
1865 static inline int md_setxattr(struct obd_export *exp,
1866 const struct lu_fid *fid, struct obd_capa *oc,
1867 obd_valid valid, const char *name,
1868 const char *input, int input_size,
1869 int output_size, int flags, __u32 suppgid,
1870 struct ptlrpc_request **request)
1873 EXP_CHECK_MD_OP(exp, setxattr);
1874 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1875 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1876 input_size, output_size, flags,
1880 static inline int md_getxattr(struct obd_export *exp,
1881 const struct lu_fid *fid, struct obd_capa *oc,
1882 obd_valid valid, const char *name,
1883 const char *input, int input_size,
1884 int output_size, int flags,
1885 struct ptlrpc_request **request)
1888 EXP_CHECK_MD_OP(exp, getxattr);
1889 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1890 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1891 input_size, output_size, flags,
1895 static inline int md_set_open_replay_data(struct obd_export *exp,
1896 struct obd_client_handle *och,
1897 struct lookup_intent *it)
1900 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1901 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1902 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1905 static inline int md_clear_open_replay_data(struct obd_export *exp,
1906 struct obd_client_handle *och)
1909 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1910 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1911 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1914 static inline int md_set_lock_data(struct obd_export *exp,
1915 __u64 *lockh, void *data, __u64 *bits)
1918 EXP_CHECK_MD_OP(exp, set_lock_data);
1919 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1920 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1923 static inline int md_cancel_unused(struct obd_export *exp,
1924 const struct lu_fid *fid,
1925 ldlm_policy_data_t *policy,
1927 ldlm_cancel_flags_t flags,
1933 EXP_CHECK_MD_OP(exp, cancel_unused);
1934 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1936 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1941 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, __u64 flags,
1942 const struct lu_fid *fid,
1944 ldlm_policy_data_t *policy,
1946 struct lustre_handle *lockh)
1949 EXP_CHECK_MD_OP(exp, lock_match);
1950 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1951 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1952 policy, mode, lockh));
1955 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1956 int def_asize, int cookiesize,
1960 EXP_CHECK_MD_OP(exp, init_ea_size);
1961 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1962 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1963 cookiesize, def_cookiesize));
1966 static inline int md_get_remote_perm(struct obd_export *exp,
1967 const struct lu_fid *fid,
1968 struct obd_capa *oc, __u32 suppgid,
1969 struct ptlrpc_request **request)
1972 EXP_CHECK_MD_OP(exp, get_remote_perm);
1973 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1974 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
1978 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1983 EXP_CHECK_MD_OP(exp, renew_capa);
1984 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1985 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1989 static inline int md_unpack_capa(struct obd_export *exp,
1990 struct ptlrpc_request *req,
1991 const struct req_msg_field *field,
1992 struct obd_capa **oc)
1996 EXP_CHECK_MD_OP(exp, unpack_capa);
1997 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
1998 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2002 static inline int md_intent_getattr_async(struct obd_export *exp,
2003 struct md_enqueue_info *minfo,
2004 struct ldlm_enqueue_info *einfo)
2008 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2009 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2010 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2014 static inline int md_revalidate_lock(struct obd_export *exp,
2015 struct lookup_intent *it,
2016 struct lu_fid *fid, __u64 *bits)
2020 EXP_CHECK_MD_OP(exp, revalidate_lock);
2021 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2022 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
2027 /* OBD Metadata Support */
2029 extern int obd_init_caches(void);
2030 extern void obd_cleanup_caches(void);
2032 /* support routines */
2033 extern struct kmem_cache *obdo_cachep;
2035 #define OBDO_ALLOC(ptr) \
2037 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
2040 #define OBDO_FREE(ptr) \
2042 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2046 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2048 /* something here */
2051 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2053 /* something here */
2056 typedef int (*register_lwp_cb)(void *data);
2058 struct lwp_register_item {
2059 struct obd_export **lri_exp;
2060 register_lwp_cb lri_cb_func;
2062 cfs_list_t lri_list;
2063 char lri_name[MTI_NAME_MAXLEN];
2066 /* I'm as embarrassed about this as you are.
2068 * <shaver> // XXX do not look into _superhack with remaining eye
2069 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2070 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2073 #ifdef HAVE_SERVER_SUPPORT
2074 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
2075 register_lwp_cb cb_func, void *cb_data);
2076 void lustre_deregister_lwp_item(struct obd_export **exp);
2077 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
2078 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
2079 #endif /* HAVE_SERVER_SUPPORT */
2082 extern void obd_sysctl_init (void);
2083 extern void obd_sysctl_clean (void);
2086 typedef __u8 class_uuid_t[16];
2087 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2090 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2091 int class_add_uuid(const char *uuid, __u64 nid);
2092 int class_del_uuid (const char *uuid);
2093 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
2094 void class_init_uuidlist(void);
2095 void class_exit_uuidlist(void);
2098 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
2101 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
2103 # define server_name2index(name, idx, ptr) do {} while (0)
2106 #endif /* __LINUX_OBD_CLASS_H */