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. */
74 /* OBD Device Declarations */
75 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
76 extern rwlock_t obd_dev_lock;
78 /* OBD Operations Declarations */
79 extern struct obd_device *class_conn2obd(struct lustre_handle *);
80 extern struct obd_device *class_exp2obd(struct obd_export *);
81 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
82 extern int lustre_get_jobid(char *jobid);
84 struct lu_device_type;
87 struct obd_export *class_conn2export(struct lustre_handle *);
88 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
89 struct lprocfs_seq_vars *module_vars,
90 #ifndef HAVE_ONLY_PROCFS_SEQ
91 struct lprocfs_vars *,
93 const char *nm, struct lu_device_type *ldt);
94 int class_unregister_type(const char *nm);
96 struct obd_device *class_newdev(const char *type_name, const char *name);
97 void class_release_dev(struct obd_device *obd);
99 int class_name2dev(const char *name);
100 struct obd_device *class_name2obd(const char *name);
101 int class_uuid2dev(struct obd_uuid *uuid);
102 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
103 void class_obd_list(void);
104 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
105 const char * typ_name,
106 struct obd_uuid *grp_uuid);
107 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
109 struct obd_device * class_num2obd(int num);
110 int get_devices_count(void);
112 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
114 char *obd_export_nid2str(struct obd_export *exp);
116 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
117 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
118 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
120 int obd_zombie_impexp_init(void);
121 void obd_zombie_impexp_stop(void);
122 void obd_zombie_impexp_cull(void);
123 void obd_zombie_barrier(void);
124 void obd_exports_barrier(struct obd_device *obd);
125 int kuc_len(int payload_len);
126 struct kuc_hdr * kuc_ptr(void *p);
127 int kuc_ispayload(void *p);
128 void *kuc_alloc(int payload_len, int transport, int type);
129 void kuc_free(void *p, int payload_len);
130 int obd_get_request_slot(struct client_obd *cli);
131 void obd_put_request_slot(struct client_obd *cli);
132 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
133 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
137 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
138 struct llog_rec_hdr *, void *);
140 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
141 const char *new_name);
142 int class_process_config(struct lustre_cfg *lcfg);
143 #ifndef HAVE_ONLY_PROCFS_SEQ
144 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
145 struct lustre_cfg *lcfg, void *data);
147 int class_process_proc_seq_param(char *prefix, struct lprocfs_seq_vars *lvars,
148 struct lustre_cfg *lcfg, void *data);
149 int class_attach(struct lustre_cfg *lcfg);
150 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
151 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
152 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
153 struct obd_device *class_incref(struct obd_device *obd,
154 const char *scope, const void *source);
155 void class_decref(struct obd_device *obd,
156 const char *scope, const void *source);
157 void dump_exports(struct obd_device *obd, int locks);
158 int class_config_llog_handler(const struct lu_env *env,
159 struct llog_handle *handle,
160 struct llog_rec_hdr *rec, void *data);
161 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
162 int class_add_uuid(const char *uuid, __u64 nid);
164 #define CFG_F_START 0x01 /* Set when we start updating from a log */
165 #define CFG_F_MARKER 0x02 /* We are within a maker */
166 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
167 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
168 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
170 /* Passed as data param to class_config_parse_llog */
171 struct config_llog_instance {
174 struct super_block *cfg_sb;
175 struct obd_uuid cfg_uuid;
176 llog_cb_t cfg_callback;
177 int cfg_last_idx; /* for partial llog processing */
181 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
182 char *name, struct config_llog_instance *cfg);
183 int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
184 char *name, struct config_llog_instance *cfg);
188 CONFIG_T_SPTLRPC = 1,
189 CONFIG_T_RECOVER = 2,
194 #define PARAMS_FILENAME "params"
195 #define LCTL_UPCALL "lctl"
197 /* list of active configuration logs */
198 struct config_llog_data {
199 struct ldlm_res_id cld_resid;
200 struct config_llog_instance cld_cfg;
201 cfs_list_t cld_list_chain;
202 atomic_t cld_refcount;
203 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
204 struct config_llog_data *cld_params; /* common parameters log */
205 struct config_llog_data *cld_recover;/* imperative recover log */
206 struct obd_export *cld_mgcexp;
207 struct mutex cld_lock;
209 unsigned int cld_stopping:1, /* we were told to stop
211 cld_lostlock:1; /* lock not requeued */
215 struct lustre_profile {
222 struct lustre_profile *class_get_profile(const char * prof);
223 void class_del_profile(const char *prof);
224 void class_del_profiles(void);
226 #if LUSTRE_TRACKS_LOCK_EXP_REFS
228 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
229 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
230 extern void (*class_export_dump_hook)(struct obd_export *);
234 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
235 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
239 #define class_export_rpc_inc(exp) \
241 atomic_inc(&(exp)->exp_rpc_count); \
242 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
243 (exp), atomic_read(&(exp)->exp_rpc_count)); \
246 #define class_export_rpc_dec(exp) \
248 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
249 atomic_dec(&(exp)->exp_rpc_count); \
250 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
251 (exp), atomic_read(&(exp)->exp_rpc_count)); \
254 #define class_export_lock_get(exp, lock) \
256 atomic_inc(&(exp)->exp_locks_count); \
257 __class_export_add_lock_ref(exp, lock); \
258 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
259 (exp), atomic_read(&(exp)->exp_locks_count)); \
260 class_export_get(exp); \
263 #define class_export_lock_put(exp, lock) \
265 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
266 atomic_dec(&(exp)->exp_locks_count); \
267 __class_export_del_lock_ref(exp, lock); \
268 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
269 (exp), atomic_read(&(exp)->exp_locks_count)); \
270 class_export_put(exp); \
273 #define class_export_cb_get(exp) \
275 atomic_inc(&(exp)->exp_cb_count); \
276 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
277 (exp), atomic_read(&(exp)->exp_cb_count)); \
278 class_export_get(exp); \
281 #define class_export_cb_put(exp) \
283 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
284 atomic_dec(&(exp)->exp_cb_count); \
285 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
286 (exp), atomic_read(&(exp)->exp_cb_count)); \
287 class_export_put(exp); \
291 struct obd_export *class_export_get(struct obd_export *exp);
292 void class_export_put(struct obd_export *exp);
293 struct obd_export *class_new_export(struct obd_device *obddev,
294 struct obd_uuid *cluuid);
295 void class_unlink_export(struct obd_export *exp);
297 struct obd_import *class_import_get(struct obd_import *);
298 void class_import_put(struct obd_import *);
299 struct obd_import *class_new_import(struct obd_device *obd);
300 void class_destroy_import(struct obd_import *exp);
302 struct obd_type *class_search_type(const char *name);
303 struct obd_type *class_get_type(const char *name);
304 void class_put_type(struct obd_type *type);
305 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
306 struct obd_uuid *cluuid);
307 int class_disconnect(struct obd_export *exp);
308 void class_fail_export(struct obd_export *exp);
309 int class_connected_export(struct obd_export *exp);
310 void class_disconnect_exports(struct obd_device *obddev);
311 int class_manual_cleanup(struct obd_device *obd);
312 void class_disconnect_stale_exports(struct obd_device *,
313 int (*test_export)(struct obd_export *));
314 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
316 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
317 (obd->obd_force ? OBD_OPT_FORCE : 0) |
318 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
322 #ifdef HAVE_SERVER_SUPPORT
323 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
325 LASSERT(exp->exp_obd);
326 return exp->exp_obd->u.obt.obt_lut;
329 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
331 LASSERT(obd->u.obt.obt_lut);
332 return &obd->u.obt.obt_lut->lut_lsd;
336 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, obd_flag valid);
337 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
338 void md_from_obdo(struct md_op_data *op_data, const struct obdo *oa,
341 #define OBT(dev) (dev)->obd_type
342 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
343 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
344 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
346 /* Ensure obd_setup: used for cleanup which must be called
347 while obd is stopping */
348 #define OBD_CHECK_DEV(obd) \
351 CERROR("NULL device\n"); \
356 /* ensure obd_setup and !obd_stopping */
357 #define OBD_CHECK_DEV_ACTIVE(obd) \
359 OBD_CHECK_DEV(obd); \
360 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
361 CERROR("Device %d not setup\n", \
369 #define OBD_COUNTER_OFFSET(op) \
370 ((offsetof(struct obd_ops, o_ ## op) - \
371 offsetof(struct obd_ops, o_iocontrol)) \
372 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
374 /* The '- 1' below is for o_owner. */
375 #define NUM_OBD_STATS \
376 (sizeof(struct obd_ops) / \
377 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
379 #define OBD_COUNTER_INCREMENT(obd, op) \
380 lprocfs_counter_incr((obd)->obd_stats, \
381 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
383 #define EXP_COUNTER_INCREMENT(exp, op) \
386 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
387 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
388 if ((exp)->exp_obd->obd_uses_nid_stats && \
389 (exp)->exp_nid_stats != NULL) \
390 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
394 #define _MD_COUNTER_OFFSET(m_op) \
395 ((offsetof(struct md_ops, m_op) - \
396 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
397 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
399 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
401 #define NUM_MD_STATS \
402 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
403 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
405 /* Note that we only increment md counters for ops whose offset is less
406 * than NUM_MD_STATS. This is explained in a comment in the definition
407 * of struct md_ops. */
408 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
410 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
411 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
412 (exp)->exp_obd->obd_md_cntr_base + \
413 MD_COUNTER_OFFSET(op)); \
417 #define OBD_COUNTER_OFFSET(op)
418 #define OBD_COUNTER_INCREMENT(obd, op)
419 #define EXP_COUNTER_INCREMENT(exp, op)
420 #define EXP_MD_COUNTER_INCREMENT(exp, op)
423 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
425 /* Always add in ldlm_stats */
426 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
427 ,LPROCFS_STATS_FLAG_NOPERCPU);
428 if (tmp->nid_ldlm_stats == NULL)
431 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
433 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
434 tmp->nid_ldlm_stats);
437 #define EXP_CHECK_MD_OP(exp, op) \
439 if ((exp) == NULL) { \
440 CERROR("obd_" #op ": NULL export\n"); \
443 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
444 CERROR("obd_" #op ": cleaned up obd\n"); \
445 RETURN(-EOPNOTSUPP); \
447 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
448 CERROR("obd_" #op ": dev %s/%d no operation\n", \
449 (exp)->exp_obd->obd_name, \
450 (exp)->exp_obd->obd_minor); \
451 RETURN(-EOPNOTSUPP); \
456 #define OBD_CHECK_DT_OP(obd, op, err) \
458 if (!OBT(obd) || !OBP((obd), op)) { \
460 CERROR("obd_" #op ": dev %d no operation\n", \
466 #define EXP_CHECK_DT_OP(exp, op) \
468 if ((exp) == NULL) { \
469 CERROR("obd_" #op ": NULL export\n"); \
472 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
473 CERROR("obd_" #op ": cleaned up obd\n"); \
474 RETURN(-EOPNOTSUPP); \
476 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
477 CERROR("obd_" #op ": dev %d no operation\n", \
478 (exp)->exp_obd->obd_minor); \
479 RETURN(-EOPNOTSUPP); \
483 #define CTXT_CHECK_OP(ctxt, op, err) \
485 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
487 CERROR("lop_" #op ": dev %d no operation\n", \
488 ctxt->loc_obd->obd_minor); \
493 static inline int class_devno_max(void)
495 return MAX_OBD_DEVICES;
498 static inline int obd_get_info(const struct lu_env *env,
499 struct obd_export *exp, __u32 keylen,
500 void *key, __u32 *vallen, void *val,
501 struct lov_stripe_md *lsm)
506 EXP_CHECK_DT_OP(exp, get_info);
507 EXP_COUNTER_INCREMENT(exp, get_info);
509 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val,
514 static inline int obd_set_info_async(const struct lu_env *env,
515 struct obd_export *exp, obd_count keylen,
516 void *key, obd_count vallen, void *val,
517 struct ptlrpc_request_set *set)
522 EXP_CHECK_DT_OP(exp, set_info_async);
523 EXP_COUNTER_INCREMENT(exp, set_info_async);
525 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
531 * obd-lu integration.
533 * Functionality is being moved into new lu_device-based layering, but some
534 * pieces of configuration process are still based on obd devices.
536 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
537 * subsume ->o_setup() methods of obd devices they replace. The same for
538 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
539 * result, obd_setup() and obd_process_config() branch and call one XOR
542 * Yet neither lu_device_type_operations::ldto_device_fini() nor
543 * lu_device_type_operations::ldto_device_free() fully implement the
544 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
545 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
548 #define DECLARE_LU_VARS(ldt, d) \
549 struct lu_device_type *ldt; \
552 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
555 DECLARE_LU_VARS(ldt, d);
558 ldt = obd->obd_type->typ_lu;
560 struct lu_context session_ctx;
562 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
563 session_ctx.lc_thread = NULL;
564 lu_context_enter(&session_ctx);
566 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
568 env.le_ses = &session_ctx;
569 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
578 lu_context_exit(&session_ctx);
579 lu_context_fini(&session_ctx);
582 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
583 OBD_COUNTER_INCREMENT(obd, setup);
584 rc = OBP(obd, setup)(obd, cfg);
589 static inline int obd_precleanup(struct obd_device *obd,
590 enum obd_cleanup_stage cleanup_stage)
593 DECLARE_LU_VARS(ldt, d);
597 ldt = obd->obd_type->typ_lu;
599 if (ldt != NULL && d != NULL) {
600 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
603 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
605 ldt->ldt_ops->ldto_device_fini(&env, d);
610 OBD_CHECK_DT_OP(obd, precleanup, 0);
611 OBD_COUNTER_INCREMENT(obd, precleanup);
613 rc = OBP(obd, precleanup)(obd, cleanup_stage);
617 static inline int obd_cleanup(struct obd_device *obd)
620 DECLARE_LU_VARS(ldt, d);
625 ldt = obd->obd_type->typ_lu;
627 if (ldt != NULL && d != NULL) {
630 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
632 ldt->ldt_ops->ldto_device_free(&env, d);
634 obd->obd_lu_dev = NULL;
637 OBD_CHECK_DT_OP(obd, cleanup, 0);
638 OBD_COUNTER_INCREMENT(obd, cleanup);
640 rc = OBP(obd, cleanup)(obd);
644 static inline void obd_cleanup_client_import(struct obd_device *obd)
648 /* If we set up but never connected, the
649 client import will not have been cleaned. */
650 down_write(&obd->u.cli.cl_sem);
651 if (obd->u.cli.cl_import) {
652 struct obd_import *imp;
653 imp = obd->u.cli.cl_import;
654 CDEBUG(D_CONFIG, "%s: client import never connected\n",
656 ptlrpc_invalidate_import(imp);
657 if (imp->imp_rq_pool) {
658 ptlrpc_free_rq_pool(imp->imp_rq_pool);
659 imp->imp_rq_pool = NULL;
661 client_destroy_import(imp);
662 obd->u.cli.cl_import = NULL;
664 up_write(&obd->u.cli.cl_sem);
670 obd_process_config(struct obd_device *obd, int datalen, void *data)
673 DECLARE_LU_VARS(ldt, d);
678 obd->obd_process_conf = 1;
679 ldt = obd->obd_type->typ_lu;
681 if (ldt != NULL && d != NULL) {
684 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
686 rc = d->ld_ops->ldo_process_config(&env, d, data);
690 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
691 rc = OBP(obd, process_config)(obd, datalen, data);
693 OBD_COUNTER_INCREMENT(obd, process_config);
694 obd->obd_process_conf = 0;
699 /* Pack an in-memory MD struct for storage on disk.
700 * Returns +ve size of packed MD (0 for free), or -ve error.
702 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
703 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
704 * If @*disk_tgt == NULL, it will be allocated
706 static inline int obd_packmd(struct obd_export *exp,
707 struct lov_mds_md **disk_tgt,
708 struct lov_stripe_md *mem_src)
713 EXP_CHECK_DT_OP(exp, packmd);
714 EXP_COUNTER_INCREMENT(exp, packmd);
716 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
720 static inline int obd_size_diskmd(struct obd_export *exp,
721 struct lov_stripe_md *mem_src)
723 return obd_packmd(exp, NULL, mem_src);
726 static inline int obd_free_diskmd(struct obd_export *exp,
727 struct lov_mds_md **disk_tgt)
732 * LU-2590, for caller's convenience, *disk_tgt could be host
733 * endianness, it needs swab to LE if necessary, while just
734 * lov_mds_md header needs it for figuring out how much memory
737 if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
738 (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) ||
739 ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3)))
740 lustre_swab_lov_mds_md(*disk_tgt);
741 return obd_packmd(exp, disk_tgt, NULL);
744 /* Unpack an MD struct from disk to in-memory format.
745 * Returns +ve size of unpacked MD (0 for free), or -ve error.
747 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
748 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
749 * If @*mem_tgt == NULL, it will be allocated
751 static inline int obd_unpackmd(struct obd_export *exp,
752 struct lov_stripe_md **mem_tgt,
753 struct lov_mds_md *disk_src,
759 EXP_CHECK_DT_OP(exp, unpackmd);
760 EXP_COUNTER_INCREMENT(exp, unpackmd);
762 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
766 /* helper functions */
767 static inline int obd_alloc_memmd(struct obd_export *exp,
768 struct lov_stripe_md **mem_tgt)
771 LASSERT(*mem_tgt == NULL);
772 return obd_unpackmd(exp, mem_tgt, NULL, 0);
775 static inline int obd_free_memmd(struct obd_export *exp,
776 struct lov_stripe_md **mem_tgt)
782 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
787 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
788 struct obdo *obdo, struct lov_stripe_md **ea,
789 struct obd_trans_info *oti)
794 EXP_CHECK_DT_OP(exp, create);
795 EXP_COUNTER_INCREMENT(exp, create);
797 rc = OBP(exp->exp_obd, create)(env, exp, obdo, ea, oti);
801 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
802 struct obdo *obdo, struct lov_stripe_md *ea,
803 struct obd_trans_info *oti,
804 struct obd_export *md_exp, void *capa)
809 EXP_CHECK_DT_OP(exp, destroy);
810 EXP_COUNTER_INCREMENT(exp, destroy);
812 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp, capa);
816 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
817 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)
836 EXP_CHECK_DT_OP(exp, getattr_async);
837 EXP_COUNTER_INCREMENT(exp, getattr_async);
839 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
843 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
844 struct obd_info *oinfo,
845 struct obd_trans_info *oti)
850 EXP_CHECK_DT_OP(exp, setattr);
851 EXP_COUNTER_INCREMENT(exp, setattr);
853 rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti);
857 /* This performs all the requests set init/wait/destroy actions. */
858 static inline int obd_setattr_rqset(struct obd_export *exp,
859 struct obd_info *oinfo,
860 struct obd_trans_info *oti)
862 struct ptlrpc_request_set *set = NULL;
866 EXP_CHECK_DT_OP(exp, setattr_async);
867 EXP_COUNTER_INCREMENT(exp, setattr_async);
869 set = ptlrpc_prep_set();
873 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
875 rc = ptlrpc_set_wait(set);
876 ptlrpc_set_destroy(set);
880 /* This adds all the requests into @set if @set != NULL, otherwise
881 all requests are sent asynchronously without waiting for response. */
882 static inline int obd_setattr_async(struct obd_export *exp,
883 struct obd_info *oinfo,
884 struct obd_trans_info *oti,
885 struct ptlrpc_request_set *set)
890 EXP_CHECK_DT_OP(exp, setattr_async);
891 EXP_COUNTER_INCREMENT(exp, setattr_async);
893 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
897 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
900 struct obd_device *obd = imp->imp_obd;
904 OBD_CHECK_DEV_ACTIVE(obd);
905 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
906 OBD_COUNTER_INCREMENT(obd, add_conn);
908 rc = OBP(obd, add_conn)(imp, uuid, priority);
912 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
914 struct obd_device *obd = imp->imp_obd;
918 OBD_CHECK_DEV_ACTIVE(obd);
919 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
920 OBD_COUNTER_INCREMENT(obd, del_conn);
922 rc = OBP(obd, del_conn)(imp, uuid);
926 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
928 struct obd_uuid *uuid;
931 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
932 EXP_COUNTER_INCREMENT(exp, get_uuid);
934 uuid = OBP(exp->exp_obd, get_uuid)(exp);
938 /** Create a new /a exp on device /a obd for the uuid /a cluuid
939 * @param exp New export handle
940 * @param d Connect data, supported flags are set, flags also understood
941 * by obd are returned.
943 static inline int obd_connect(const struct lu_env *env,
944 struct obd_export **exp,struct obd_device *obd,
945 struct obd_uuid *cluuid,
946 struct obd_connect_data *data,
950 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
954 OBD_CHECK_DEV_ACTIVE(obd);
955 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
956 OBD_COUNTER_INCREMENT(obd, connect);
958 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
959 /* check that only subset is granted */
960 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
961 data->ocd_connect_flags));
965 static inline int obd_reconnect(const struct lu_env *env,
966 struct obd_export *exp,
967 struct obd_device *obd,
968 struct obd_uuid *cluuid,
969 struct obd_connect_data *d,
973 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
978 OBD_CHECK_DEV_ACTIVE(obd);
979 OBD_CHECK_DT_OP(obd, reconnect, 0);
980 OBD_COUNTER_INCREMENT(obd, reconnect);
982 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
983 /* check that only subset is granted */
984 LASSERT(ergo(d != NULL,
985 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
989 static inline int obd_disconnect(struct obd_export *exp)
994 EXP_CHECK_DT_OP(exp, disconnect);
995 EXP_COUNTER_INCREMENT(exp, disconnect);
997 rc = OBP(exp->exp_obd, disconnect)(exp);
1001 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
1002 enum lu_cli_type type)
1007 OBD_CHECK_DT_OP(obd, fid_init, 0);
1008 OBD_COUNTER_INCREMENT(obd, fid_init);
1010 rc = OBP(obd, fid_init)(obd, exp, type);
1014 static inline int obd_fid_fini(struct obd_device *obd)
1019 OBD_CHECK_DT_OP(obd, fid_fini, 0);
1020 OBD_COUNTER_INCREMENT(obd, fid_fini);
1022 rc = OBP(obd, fid_fini)(obd);
1026 static inline int obd_fid_alloc(const struct lu_env *env,
1027 struct obd_export *exp,
1029 struct md_op_data *op_data)
1034 EXP_CHECK_DT_OP(exp, fid_alloc);
1035 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1037 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
1041 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
1046 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1047 EXP_COUNTER_INCREMENT(exp, ping);
1049 rc = OBP(exp->exp_obd, ping)(env, exp);
1053 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1058 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1059 OBD_COUNTER_INCREMENT(obd, pool_new);
1061 rc = OBP(obd, pool_new)(obd, poolname);
1065 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1070 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1071 OBD_COUNTER_INCREMENT(obd, pool_del);
1073 rc = OBP(obd, pool_del)(obd, poolname);
1077 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1082 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1083 OBD_COUNTER_INCREMENT(obd, pool_add);
1085 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1089 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1094 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1095 OBD_COUNTER_INCREMENT(obd, pool_rem);
1097 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1101 static inline void obd_getref(struct obd_device *obd)
1104 if (OBT(obd) && OBP(obd, getref)) {
1105 OBD_COUNTER_INCREMENT(obd, getref);
1106 OBP(obd, getref)(obd);
1111 static inline void obd_putref(struct obd_device *obd)
1114 if (OBT(obd) && OBP(obd, putref)) {
1115 OBD_COUNTER_INCREMENT(obd, putref);
1116 OBP(obd, putref)(obd);
1121 static inline int obd_init_export(struct obd_export *exp)
1126 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1127 OBP((exp)->exp_obd, init_export))
1128 rc = OBP(exp->exp_obd, init_export)(exp);
1132 static inline int obd_destroy_export(struct obd_export *exp)
1135 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1136 OBP((exp)->exp_obd, destroy_export))
1137 OBP(exp->exp_obd, destroy_export)(exp);
1141 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1142 * If the cache is older than @max_age we will get a new value from the
1143 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1144 static inline int obd_statfs_async(struct obd_export *exp,
1145 struct obd_info *oinfo,
1147 struct ptlrpc_request_set *rqset)
1150 struct obd_device *obd;
1153 if (exp == NULL || exp->exp_obd == NULL)
1157 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1158 OBD_COUNTER_INCREMENT(obd, statfs);
1160 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1161 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1162 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1163 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1165 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1166 " objects "LPU64"/"LPU64"\n",
1167 obd->obd_name, &obd->obd_osfs,
1168 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1169 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1170 spin_lock(&obd->obd_osfs_lock);
1171 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1172 spin_unlock(&obd->obd_osfs_lock);
1173 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1174 if (oinfo->oi_cb_up)
1175 oinfo->oi_cb_up(oinfo, 0);
1180 static inline int obd_statfs_rqset(struct obd_export *exp,
1181 struct obd_statfs *osfs, __u64 max_age,
1184 struct ptlrpc_request_set *set = NULL;
1185 struct obd_info oinfo = { { { 0 } } };
1189 set = ptlrpc_prep_set();
1193 oinfo.oi_osfs = osfs;
1194 oinfo.oi_flags = flags;
1195 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1197 rc = ptlrpc_set_wait(set);
1198 ptlrpc_set_destroy(set);
1202 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1203 * If the cache is older than @max_age we will get a new value from the
1204 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1205 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1206 struct obd_statfs *osfs, __u64 max_age,
1210 struct obd_device *obd = exp->exp_obd;
1216 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1217 OBD_COUNTER_INCREMENT(obd, statfs);
1219 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1220 obd->obd_osfs_age, max_age);
1221 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1222 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1224 spin_lock(&obd->obd_osfs_lock);
1225 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1226 obd->obd_osfs_age = cfs_time_current_64();
1227 spin_unlock(&obd->obd_osfs_lock);
1230 CDEBUG(D_SUPER, "%s: use %p cache blocks "LPU64"/"LPU64
1231 " objects "LPU64"/"LPU64"\n",
1232 obd->obd_name, &obd->obd_osfs,
1233 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1234 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1235 spin_lock(&obd->obd_osfs_lock);
1236 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1237 spin_unlock(&obd->obd_osfs_lock);
1242 static inline int obd_preprw(const struct lu_env *env, int cmd,
1243 struct obd_export *exp, struct obdo *oa,
1244 int objcount, struct obd_ioobj *obj,
1245 struct niobuf_remote *remote, int *pages,
1246 struct niobuf_local *local,
1247 struct obd_trans_info *oti,
1248 struct lustre_capa *capa)
1253 EXP_CHECK_DT_OP(exp, preprw);
1254 EXP_COUNTER_INCREMENT(exp, preprw);
1256 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1257 pages, local, oti, capa);
1261 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1262 struct obd_export *exp, struct obdo *oa,
1263 int objcount, struct obd_ioobj *obj,
1264 struct niobuf_remote *rnb, int pages,
1265 struct niobuf_local *local,
1266 struct obd_trans_info *oti, int rc)
1270 EXP_CHECK_DT_OP(exp, commitrw);
1271 EXP_COUNTER_INCREMENT(exp, commitrw);
1273 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1274 rnb, pages, local, oti, rc);
1278 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1279 int len, void *karg, void *uarg)
1284 EXP_CHECK_DT_OP(exp, iocontrol);
1285 EXP_COUNTER_INCREMENT(exp, iocontrol);
1287 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1291 static inline int obd_change_cbdata(struct obd_export *exp,
1292 struct lov_stripe_md *lsm,
1293 ldlm_iterator_t it, void *data)
1298 EXP_CHECK_DT_OP(exp, change_cbdata);
1299 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1301 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1305 static inline int obd_find_cbdata(struct obd_export *exp,
1306 struct lov_stripe_md *lsm,
1307 ldlm_iterator_t it, void *data)
1312 EXP_CHECK_DT_OP(exp, find_cbdata);
1313 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1315 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1319 static inline void obd_import_event(struct obd_device *obd,
1320 struct obd_import *imp,
1321 enum obd_import_event event)
1325 CERROR("NULL device\n");
1329 if (obd->obd_set_up && OBP(obd, import_event)) {
1330 OBD_COUNTER_INCREMENT(obd, import_event);
1331 OBP(obd, import_event)(obd, imp, event);
1336 static inline int obd_notify(struct obd_device *obd,
1337 struct obd_device *watched,
1338 enum obd_notify_event ev,
1345 if (!obd->obd_set_up) {
1346 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1350 if (!OBP(obd, notify)) {
1351 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1355 OBD_COUNTER_INCREMENT(obd, notify);
1356 rc = OBP(obd, notify)(obd, watched, ev, data);
1360 static inline int obd_notify_observer(struct obd_device *observer,
1361 struct obd_device *observed,
1362 enum obd_notify_event ev,
1368 struct obd_notify_upcall *onu;
1370 if (observer->obd_observer)
1371 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1375 * Also, call non-obd listener, if any
1377 onu = &observer->obd_upcall;
1378 if (onu->onu_upcall != NULL)
1379 rc2 = onu->onu_upcall(observer, observed, ev,
1380 onu->onu_owner, NULL);
1384 return rc1 ? rc1 : rc2;
1387 static inline int obd_quotacheck(struct obd_export *exp,
1388 struct obd_quotactl *oqctl)
1393 EXP_CHECK_DT_OP(exp, quotacheck);
1394 EXP_COUNTER_INCREMENT(exp, quotacheck);
1396 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1400 static inline int obd_quotactl(struct obd_export *exp,
1401 struct obd_quotactl *oqctl)
1406 EXP_CHECK_DT_OP(exp, quotactl);
1407 EXP_COUNTER_INCREMENT(exp, quotactl);
1409 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1413 static inline int obd_health_check(const struct lu_env *env,
1414 struct obd_device *obd)
1416 /* returns: 0 on healthy
1417 * >0 on unhealthy + reason code/flag
1418 * however the only suppored reason == 1 right now
1419 * We'll need to define some better reasons
1420 * or flags in the future.
1426 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1427 if (obd == NULL || !OBT(obd)) {
1428 CERROR("cleaned up obd\n");
1429 RETURN(-EOPNOTSUPP);
1431 if (!obd->obd_set_up || obd->obd_stopping)
1433 if (!OBP(obd, health_check))
1436 rc = OBP(obd, health_check)(env, obd);
1440 static inline int obd_register_observer(struct obd_device *obd,
1441 struct obd_device *observer)
1445 down_write(&obd->obd_observer_link_sem);
1446 if (obd->obd_observer && observer) {
1447 up_write(&obd->obd_observer_link_sem);
1450 obd->obd_observer = observer;
1451 up_write(&obd->obd_observer_link_sem);
1455 /* metadata helpers */
1456 static inline int md_getstatus(struct obd_export *exp,
1457 struct lu_fid *fid, struct obd_capa **pc)
1462 EXP_CHECK_MD_OP(exp, getstatus);
1463 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1464 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1468 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1469 struct ptlrpc_request **request)
1473 EXP_CHECK_MD_OP(exp, getattr);
1474 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1475 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1479 static inline int md_null_inode(struct obd_export *exp,
1480 const struct lu_fid *fid)
1484 EXP_CHECK_MD_OP(exp, null_inode);
1485 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1486 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1490 static inline int md_find_cbdata(struct obd_export *exp,
1491 const struct lu_fid *fid,
1492 ldlm_iterator_t it, void *data)
1496 EXP_CHECK_MD_OP(exp, find_cbdata);
1497 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1498 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1502 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1503 struct md_open_data *mod,
1504 struct ptlrpc_request **request)
1508 EXP_CHECK_MD_OP(exp, close);
1509 EXP_MD_COUNTER_INCREMENT(exp, close);
1510 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1514 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1515 const void *data, int datalen, int mode, __u32 uid,
1516 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1517 struct ptlrpc_request **request)
1521 EXP_CHECK_MD_OP(exp, create);
1522 EXP_MD_COUNTER_INCREMENT(exp, create);
1523 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1524 uid, gid, cap_effective, rdev, request);
1528 static inline int md_done_writing(struct obd_export *exp,
1529 struct md_op_data *op_data,
1530 struct md_open_data *mod)
1534 EXP_CHECK_MD_OP(exp, done_writing);
1535 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1536 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1540 static inline int md_enqueue(struct obd_export *exp,
1541 struct ldlm_enqueue_info *einfo,
1542 const union ldlm_policy_data *policy,
1543 struct lookup_intent *it,
1544 struct md_op_data *op_data,
1545 struct lustre_handle *lockh,
1546 __u64 extra_lock_flags)
1550 EXP_CHECK_MD_OP(exp, enqueue);
1551 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1552 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, it, op_data, lockh,
1557 static inline int md_getattr_name(struct obd_export *exp,
1558 struct md_op_data *op_data,
1559 struct ptlrpc_request **request)
1563 EXP_CHECK_MD_OP(exp, getattr_name);
1564 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1565 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1569 static inline int md_intent_lock(struct obd_export *exp,
1570 struct md_op_data *op_data,
1571 struct lookup_intent *it,
1572 struct ptlrpc_request **reqp,
1573 ldlm_blocking_callback cb_blocking,
1574 __u64 extra_lock_flags)
1578 EXP_CHECK_MD_OP(exp, intent_lock);
1579 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1580 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1585 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1586 struct ptlrpc_request **request)
1590 EXP_CHECK_MD_OP(exp, link);
1591 EXP_MD_COUNTER_INCREMENT(exp, link);
1592 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1596 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1597 const char *old, int oldlen, const char *new,
1598 int newlen, struct ptlrpc_request **request)
1602 EXP_CHECK_MD_OP(exp, rename);
1603 EXP_MD_COUNTER_INCREMENT(exp, rename);
1604 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1609 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1610 void *ea, int ealen, void *ea2, int ea2len,
1611 struct ptlrpc_request **request,
1612 struct md_open_data **mod)
1616 EXP_CHECK_MD_OP(exp, setattr);
1617 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1618 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1619 ea2, ea2len, request, mod);
1623 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1624 struct obd_capa *oc, struct ptlrpc_request **request)
1628 EXP_CHECK_MD_OP(exp, fsync);
1629 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1630 rc = MDP(exp->exp_obd, fsync)(exp, fid, oc, request);
1634 static inline int md_read_page(struct obd_export *exp,
1635 struct md_op_data *op_data,
1636 struct md_callback *cb_op,
1638 struct page **ppage)
1642 EXP_CHECK_MD_OP(exp, read_page);
1643 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1644 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1649 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1650 struct ptlrpc_request **request)
1654 EXP_CHECK_MD_OP(exp, unlink);
1655 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1656 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1660 static inline int md_get_lustre_md(struct obd_export *exp,
1661 struct ptlrpc_request *req,
1662 struct obd_export *dt_exp,
1663 struct obd_export *md_exp,
1664 struct lustre_md *md)
1667 EXP_CHECK_MD_OP(exp, get_lustre_md);
1668 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1669 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1672 static inline int md_free_lustre_md(struct obd_export *exp,
1673 struct lustre_md *md)
1676 EXP_CHECK_MD_OP(exp, free_lustre_md);
1677 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1678 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1681 static inline int md_update_lsm_md(struct obd_export *exp,
1682 struct lmv_stripe_md *lsm,
1683 struct mdt_body *body,
1684 ldlm_blocking_callback cb)
1687 EXP_CHECK_MD_OP(exp, update_lsm_md);
1688 EXP_MD_COUNTER_INCREMENT(exp, update_lsm_md);
1689 RETURN(MDP(exp->exp_obd, update_lsm_md)(exp, lsm, body, cb));
1692 static inline int md_merge_attr(struct obd_export *exp,
1693 const struct lmv_stripe_md *lsm,
1694 struct cl_attr *attr)
1697 EXP_CHECK_MD_OP(exp, merge_attr);
1698 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1699 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr));
1702 static inline int md_setxattr(struct obd_export *exp,
1703 const struct lu_fid *fid, struct obd_capa *oc,
1704 obd_valid valid, const char *name,
1705 const char *input, int input_size,
1706 int output_size, int flags, __u32 suppgid,
1707 struct ptlrpc_request **request)
1710 EXP_CHECK_MD_OP(exp, setxattr);
1711 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1712 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1713 input_size, output_size, flags,
1717 static inline int md_getxattr(struct obd_export *exp,
1718 const struct lu_fid *fid, struct obd_capa *oc,
1719 obd_valid valid, const char *name,
1720 const char *input, int input_size,
1721 int output_size, int flags,
1722 struct ptlrpc_request **request)
1725 EXP_CHECK_MD_OP(exp, getxattr);
1726 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1727 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1728 input_size, output_size, flags,
1732 static inline int md_set_open_replay_data(struct obd_export *exp,
1733 struct obd_client_handle *och,
1734 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)
1746 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1747 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1748 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1751 static inline int md_set_lock_data(struct obd_export *exp,
1752 __u64 *lockh, void *data, __u64 *bits)
1755 EXP_CHECK_MD_OP(exp, set_lock_data);
1756 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1757 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1760 static inline int md_cancel_unused(struct obd_export *exp,
1761 const struct lu_fid *fid,
1762 ldlm_policy_data_t *policy,
1764 ldlm_cancel_flags_t flags,
1770 EXP_CHECK_MD_OP(exp, cancel_unused);
1771 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1773 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1778 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, __u64 flags,
1779 const struct lu_fid *fid,
1781 ldlm_policy_data_t *policy,
1783 struct lustre_handle *lockh)
1786 EXP_CHECK_MD_OP(exp, lock_match);
1787 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1788 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1789 policy, mode, lockh));
1792 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1793 int def_asize, int cookiesize,
1797 EXP_CHECK_MD_OP(exp, init_ea_size);
1798 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1799 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1800 cookiesize, def_cookiesize));
1803 static inline int md_get_remote_perm(struct obd_export *exp,
1804 const struct lu_fid *fid,
1805 struct obd_capa *oc, __u32 suppgid,
1806 struct ptlrpc_request **request)
1809 EXP_CHECK_MD_OP(exp, get_remote_perm);
1810 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1811 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
1815 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1820 EXP_CHECK_MD_OP(exp, renew_capa);
1821 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1822 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1826 static inline int md_unpack_capa(struct obd_export *exp,
1827 struct ptlrpc_request *req,
1828 const struct req_msg_field *field,
1829 struct obd_capa **oc)
1833 EXP_CHECK_MD_OP(exp, unpack_capa);
1834 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
1835 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
1839 static inline int md_intent_getattr_async(struct obd_export *exp,
1840 struct md_enqueue_info *minfo,
1841 struct ldlm_enqueue_info *einfo)
1845 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1846 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1847 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
1851 static inline int md_revalidate_lock(struct obd_export *exp,
1852 struct lookup_intent *it,
1853 struct lu_fid *fid, __u64 *bits)
1857 EXP_CHECK_MD_OP(exp, revalidate_lock);
1858 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1859 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1863 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1864 const struct lmv_stripe_md *lsm,
1865 const char *name, int namelen,
1870 EXP_CHECK_MD_OP(exp, get_fid_from_lsm);
1871 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1872 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1876 /* OBD Metadata Support */
1878 extern int obd_init_caches(void);
1879 extern void obd_cleanup_caches(void);
1881 /* support routines */
1882 extern struct kmem_cache *obdo_cachep;
1884 #define OBDO_ALLOC(ptr) \
1886 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1889 #define OBDO_FREE(ptr) \
1891 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1895 typedef int (*register_lwp_cb)(void *data);
1897 struct lwp_register_item {
1898 struct obd_export **lri_exp;
1899 register_lwp_cb lri_cb_func;
1901 cfs_list_t lri_list;
1902 char lri_name[MTI_NAME_MAXLEN];
1905 /* I'm as embarrassed about this as you are.
1907 * <shaver> // XXX do not look into _superhack with remaining eye
1908 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1909 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1912 #ifdef HAVE_SERVER_SUPPORT
1913 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1914 register_lwp_cb cb_func, void *cb_data);
1915 void lustre_deregister_lwp_item(struct obd_export **exp);
1916 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1917 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1918 #endif /* HAVE_SERVER_SUPPORT */
1921 extern void obd_sysctl_init (void);
1922 extern void obd_sysctl_clean (void);
1925 typedef __u8 class_uuid_t[16];
1926 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1929 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1930 int class_add_uuid(const char *uuid, __u64 nid);
1931 int class_del_uuid (const char *uuid);
1932 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1933 void class_init_uuidlist(void);
1934 void class_exit_uuidlist(void);
1937 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1939 /* root squash info */
1940 struct rw_semaphore;
1941 struct root_squash_info {
1944 struct list_head rsi_nosquash_nids;
1945 struct rw_semaphore rsi_sem;
1949 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1951 # define server_name2index(name, idx, ptr) do {} while (0)
1954 #endif /* __LINUX_OBD_CLASS_H */