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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
36 #include <obd_support.h>
37 #include <lustre_import.h>
38 #include <lustre_net.h>
40 #include <lustre_lib.h>
41 #include <uapi/linux/lustre/lustre_idl.h>
42 #include <lprocfs_status.h>
44 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
45 * and resends for avoid deadlocks */
46 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
48 #define OBD_STATFS_FOR_MDT0 0x0004 /* The statfs is only for retrieving
49 * information from MDT0. */
51 extern rwlock_t obd_dev_lock;
53 /* OBD Operations Declarations */
54 extern struct obd_device *class_conn2obd(struct lustre_handle *);
55 extern struct obd_device *class_exp2obd(struct obd_export *);
56 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
57 int lustre_get_jobid(char *jobid);
58 void lustre_jobid_clear(const char *jobid);
59 void jobid_cache_fini(void);
60 int jobid_cache_init(void);
62 struct lu_device_type;
65 struct obd_export *class_conn2export(struct lustre_handle *);
66 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
67 struct lprocfs_vars *module_vars,
68 const char *nm, struct lu_device_type *ldt);
69 int class_unregister_type(const char *nm);
71 struct obd_device *class_newdev(const char *type_name, const char *name);
72 void class_release_dev(struct obd_device *obd);
74 int class_name2dev(const char *name);
75 struct obd_device *class_name2obd(const char *name);
76 int class_uuid2dev(struct obd_uuid *uuid);
77 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
78 void class_obd_list(void);
79 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
80 const char * typ_name,
81 struct obd_uuid *grp_uuid);
82 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
84 struct obd_device * class_num2obd(int num);
85 int get_devices_count(void);
87 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
89 char *obd_export_nid2str(struct obd_export *exp);
91 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
92 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
93 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
96 int obd_zombie_impexp_init(void);
97 void obd_zombie_impexp_stop(void);
98 void obd_zombie_impexp_cull(void);
99 void obd_zombie_barrier(void);
100 void obd_exports_barrier(struct obd_device *obd);
101 int kuc_len(int payload_len);
102 struct kuc_hdr * kuc_ptr(void *p);
103 void *kuc_alloc(int payload_len, int transport, int type);
104 void kuc_free(void *p, int payload_len);
105 int obd_get_request_slot(struct client_obd *cli);
106 void obd_put_request_slot(struct client_obd *cli);
107 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
108 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
109 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
110 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
111 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
113 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc,
114 struct lookup_intent *it);
115 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc,
116 struct lookup_intent *it, __u16 tag);
120 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
121 struct llog_rec_hdr *, void *);
123 struct obd_export *obd_stale_export_get(void);
124 void obd_stale_export_put(struct obd_export *exp);
125 void obd_stale_export_adjust(struct obd_export *exp);
128 /* For interoperability */
129 struct cfg_interop_param {
134 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
135 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
136 const char *new_name);
137 int class_process_config(struct lustre_cfg *lcfg);
138 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
139 struct lustre_cfg *lcfg, void *data);
140 int class_attach(struct lustre_cfg *lcfg);
141 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
142 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
143 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
145 int class_find_param(char *buf, char *key, char **valp);
146 struct cfg_interop_param *class_find_old_param(const char *param,
147 struct cfg_interop_param *ptr);
148 int class_get_next_param(char **params, char *copy);
149 int class_match_param(char *buf, const char *key, char **valp);
150 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
151 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
152 int class_parse_net(char *buf, u32 *net, char **endh);
153 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
154 int class_match_net(char *buf, char *key, u32 net);
156 struct obd_device *class_incref(struct obd_device *obd,
157 const char *scope, const void *source);
158 void class_decref(struct obd_device *obd,
159 const char *scope, const void *source);
160 void dump_exports(struct obd_device *obd, int locks, int debug_level);
161 int class_config_llog_handler(const struct lu_env *env,
162 struct llog_handle *handle,
163 struct llog_rec_hdr *rec, void *data);
164 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
166 #define CFG_F_START 0x01 /* Set when we start updating from a log */
167 #define CFG_F_MARKER 0x02 /* We are within a maker */
168 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
169 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
170 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
172 /* Passed as data param to class_config_parse_llog */
173 struct config_llog_instance {
176 struct super_block *cfg_sb;
177 struct obd_uuid cfg_uuid;
178 llog_cb_t cfg_callback;
179 int cfg_last_idx; /* for partial llog processing */
184 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
185 char *name, struct config_llog_instance *cfg);
187 #define CONFIG_SUB_SPTLRPC 0x01
188 #define CONFIG_SUB_RECOVER 0x02
189 #define CONFIG_SUB_PARAMS 0x04
190 #define CONFIG_SUB_NODEMAP 0x08
191 #define CONFIG_SUB_BARRIER 0x10
193 /* Sub clds should be attached to the config_llog_data when processing
194 * config log for client or server target. */
195 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
197 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
200 #define PARAMS_FILENAME "params"
201 #define BARRIER_FILENAME "barrier"
202 #define LCTL_UPCALL "lctl"
204 static inline bool logname_is_barrier(const char *logname)
208 /* logname for barrier is "fsname-barrier" */
209 ptr = strstr(logname, BARRIER_FILENAME);
210 if (ptr && (ptr - logname) >= 2 &&
211 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
217 /* list of active configuration logs */
218 struct config_llog_data {
219 struct ldlm_res_id cld_resid;
220 struct config_llog_instance cld_cfg;
221 struct list_head cld_list_chain;
222 atomic_t cld_refcount;
223 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
224 struct config_llog_data *cld_params; /* common parameters log */
225 struct config_llog_data *cld_recover;/* imperative recover log */
226 struct config_llog_data *cld_nodemap;/* nodemap log */
227 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
228 struct obd_export *cld_mgcexp;
229 struct mutex cld_lock;
231 unsigned int cld_stopping:1, /* we were told to stop
233 cld_lostlock:1; /* lock not requeued */
237 struct lustre_profile {
238 struct list_head lp_list;
243 bool lp_list_deleted;
246 struct lustre_profile *class_get_profile(const char * prof);
247 void class_del_profile(const char *prof);
248 void class_put_profile(struct lustre_profile *lprof);
249 void class_del_profiles(void);
252 #if LUSTRE_TRACKS_LOCK_EXP_REFS
254 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
255 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
256 extern void (*class_export_dump_hook)(struct obd_export *);
260 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
261 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
265 #define class_export_rpc_inc(exp) \
267 atomic_inc(&(exp)->exp_rpc_count); \
268 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
269 (exp), atomic_read(&(exp)->exp_rpc_count)); \
272 #define class_export_rpc_dec(exp) \
274 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
275 atomic_dec(&(exp)->exp_rpc_count); \
276 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
277 (exp), atomic_read(&(exp)->exp_rpc_count)); \
280 #define class_export_lock_get(exp, lock) \
282 atomic_inc(&(exp)->exp_locks_count); \
283 __class_export_add_lock_ref(exp, lock); \
284 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
285 (exp), atomic_read(&(exp)->exp_locks_count)); \
286 class_export_get(exp); \
289 #define class_export_lock_put(exp, lock) \
291 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
292 atomic_dec(&(exp)->exp_locks_count); \
293 __class_export_del_lock_ref(exp, lock); \
294 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
295 (exp), atomic_read(&(exp)->exp_locks_count)); \
296 class_export_put(exp); \
299 #define class_export_cb_get(exp) \
301 atomic_inc(&(exp)->exp_cb_count); \
302 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
303 (exp), atomic_read(&(exp)->exp_cb_count)); \
304 class_export_get(exp); \
307 #define class_export_cb_put(exp) \
309 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
310 atomic_dec(&(exp)->exp_cb_count); \
311 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
312 (exp), atomic_read(&(exp)->exp_cb_count)); \
313 class_export_put(exp); \
317 struct obd_export *class_export_get(struct obd_export *exp);
318 void class_export_put(struct obd_export *exp);
319 struct obd_export *class_new_export(struct obd_device *obddev,
320 struct obd_uuid *cluuid);
321 void class_unlink_export(struct obd_export *exp);
323 struct obd_import *class_import_get(struct obd_import *);
324 void class_import_put(struct obd_import *);
325 struct obd_import *class_new_import(struct obd_device *obd);
326 void class_destroy_import(struct obd_import *exp);
328 struct obd_type *class_search_type(const char *name);
329 struct obd_type *class_get_type(const char *name);
330 void class_put_type(struct obd_type *type);
331 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
332 struct obd_uuid *cluuid);
333 int class_disconnect(struct obd_export *exp);
334 void class_fail_export(struct obd_export *exp);
335 int class_connected_export(struct obd_export *exp);
336 void class_disconnect_exports(struct obd_device *obddev);
337 int class_manual_cleanup(struct obd_device *obd);
338 void class_disconnect_stale_exports(struct obd_device *,
339 int (*test_export)(struct obd_export *));
340 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
342 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
343 (obd->obd_force ? OBD_OPT_FORCE : 0) |
344 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
348 #ifdef HAVE_SERVER_SUPPORT
349 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
351 LASSERT(exp->exp_obd);
352 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
354 return exp->exp_obd->u.obt.obt_lut;
357 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
359 LASSERT(obd->u.obt.obt_lut);
360 return &obd->u.obt.obt_lut->lut_lsd;
368 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
369 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
371 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
372 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
374 #define OBT(dev) (dev)->obd_type
375 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
376 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
377 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
379 /* Ensure obd_setup: used for cleanup which must be called
380 while obd is stopping */
381 #define OBD_CHECK_DEV(obd) \
384 CERROR("NULL device\n"); \
389 /* ensure obd_setup and !obd_stopping */
390 #define OBD_CHECK_DEV_ACTIVE(obd) \
392 OBD_CHECK_DEV(obd); \
393 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
394 CERROR("Device %d not setup\n", \
401 #ifdef CONFIG_PROC_FS
402 #define OBD_COUNTER_OFFSET(op) \
403 ((offsetof(struct obd_ops, o_ ## op) - \
404 offsetof(struct obd_ops, o_iocontrol)) \
405 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
407 /* The '- 1' below is for o_owner. */
408 #define NUM_OBD_STATS \
409 (sizeof(struct obd_ops) / \
410 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
412 #define OBD_COUNTER_INCREMENT(obd, op) \
413 lprocfs_counter_incr((obd)->obd_stats, \
414 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
416 #define EXP_COUNTER_INCREMENT(exp, op) \
419 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
420 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
421 if ((exp)->exp_obd->obd_uses_nid_stats && \
422 (exp)->exp_nid_stats != NULL) \
423 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
427 #define _MD_COUNTER_OFFSET(m_op) \
428 ((offsetof(struct md_ops, m_op) - \
429 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
430 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
432 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
434 #define NUM_MD_STATS \
435 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
436 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
438 /* Note that we only increment md counters for ops whose offset is less
439 * than NUM_MD_STATS. This is explained in a comment in the definition
440 * of struct md_ops. */
441 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
443 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
444 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
445 (exp)->exp_obd->obd_md_cntr_base + \
446 MD_COUNTER_OFFSET(op)); \
450 #define OBD_COUNTER_OFFSET(op)
451 #define OBD_COUNTER_INCREMENT(obd, op)
452 #define EXP_COUNTER_INCREMENT(exp, op)
453 #define EXP_MD_COUNTER_INCREMENT(exp, op)
456 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
458 /* Always add in ldlm_stats */
459 tmp->nid_ldlm_stats =
460 lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC,
461 LPROCFS_STATS_FLAG_NOPERCPU);
462 if (tmp->nid_ldlm_stats == NULL)
465 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
467 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
468 tmp->nid_ldlm_stats);
471 #define EXP_CHECK_MD_OP(exp, op) \
473 if ((exp) == NULL) { \
474 CERROR("obd_" #op ": NULL export\n"); \
477 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
478 CERROR("obd_" #op ": cleaned up obd\n"); \
479 RETURN(-EOPNOTSUPP); \
481 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
482 CERROR("%s: obd_" #op ": dev %d no operation\n", \
483 (exp)->exp_obd->obd_name, \
484 (exp)->exp_obd->obd_minor); \
485 RETURN(-EOPNOTSUPP); \
490 #define OBD_CHECK_DT_OP(obd, op, err) \
492 if (!OBT(obd) || !OBP((obd), op)) { \
494 CERROR("%s: no obd_" #op " operation\n", \
500 #define EXP_CHECK_DT_OP(exp, op) \
502 if ((exp) == NULL) { \
503 CERROR("obd_" #op ": NULL export\n"); \
506 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
507 CERROR("obd_" #op ": cleaned up obd\n"); \
508 RETURN(-EOPNOTSUPP); \
510 OBD_CHECK_DT_OP((exp)->exp_obd, op, -EOPNOTSUPP); \
513 #define CTXT_CHECK_OP(ctxt, op, err) \
515 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
517 CERROR("%s: no lop_" #op "operation\n", \
518 ctxt->loc_obd->obd_name); \
523 static inline int class_devno_max(void)
525 return MAX_OBD_DEVICES;
528 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
529 __u32 keylen, void *key,
530 __u32 *vallen, void *val)
535 EXP_CHECK_DT_OP(exp, get_info);
536 EXP_COUNTER_INCREMENT(exp, get_info);
538 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
542 static inline int obd_set_info_async(const struct lu_env *env,
543 struct obd_export *exp,
544 __u32 keylen, void *key,
545 __u32 vallen, void *val,
546 struct ptlrpc_request_set *set)
551 EXP_CHECK_DT_OP(exp, set_info_async);
552 EXP_COUNTER_INCREMENT(exp, set_info_async);
554 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
560 * obd-lu integration.
562 * Functionality is being moved into new lu_device-based layering, but some
563 * pieces of configuration process are still based on obd devices.
565 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
566 * subsume ->o_setup() methods of obd devices they replace. The same for
567 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
568 * result, obd_setup() and obd_process_config() branch and call one XOR
571 * Yet neither lu_device_type_operations::ldto_device_fini() nor
572 * lu_device_type_operations::ldto_device_free() fully implement the
573 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
574 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
577 #define DECLARE_LU_VARS(ldt, d) \
578 struct lu_device_type *ldt; \
581 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
584 DECLARE_LU_VARS(ldt, d);
587 ldt = obd->obd_type->typ_lu;
589 struct lu_context session_ctx;
591 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
592 session_ctx.lc_thread = NULL;
593 lu_context_enter(&session_ctx);
595 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
597 env.le_ses = &session_ctx;
598 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
607 lu_context_exit(&session_ctx);
608 lu_context_fini(&session_ctx);
611 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
612 OBD_COUNTER_INCREMENT(obd, setup);
613 rc = OBP(obd, setup)(obd, cfg);
618 static inline int obd_precleanup(struct obd_device *obd)
621 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_fini(&env, d);
636 OBD_CHECK_DT_OP(obd, precleanup, 0);
637 OBD_COUNTER_INCREMENT(obd, precleanup);
639 rc = OBP(obd, precleanup)(obd);
643 static inline int obd_cleanup(struct obd_device *obd)
646 DECLARE_LU_VARS(ldt, d);
651 ldt = obd->obd_type->typ_lu;
653 if (ldt != NULL && d != NULL) {
656 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
658 ldt->ldt_ops->ldto_device_free(&env, d);
660 obd->obd_lu_dev = NULL;
663 OBD_CHECK_DT_OP(obd, cleanup, 0);
664 OBD_COUNTER_INCREMENT(obd, cleanup);
666 rc = OBP(obd, cleanup)(obd);
670 static inline void obd_cleanup_client_import(struct obd_device *obd)
674 /* If we set up but never connected, the
675 client import will not have been cleaned. */
676 down_write(&obd->u.cli.cl_sem);
677 if (obd->u.cli.cl_import) {
678 struct obd_import *imp;
679 imp = obd->u.cli.cl_import;
680 CDEBUG(D_CONFIG, "%s: client import never connected\n",
682 ptlrpc_invalidate_import(imp);
683 client_destroy_import(imp);
684 obd->u.cli.cl_import = NULL;
686 up_write(&obd->u.cli.cl_sem);
692 obd_process_config(struct obd_device *obd, int datalen, void *data)
695 DECLARE_LU_VARS(ldt, d);
700 obd->obd_process_conf = 1;
701 ldt = obd->obd_type->typ_lu;
703 if (ldt != NULL && d != NULL) {
706 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
708 rc = d->ld_ops->ldo_process_config(&env, d, data);
712 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
713 rc = OBP(obd, process_config)(obd, datalen, data);
715 OBD_COUNTER_INCREMENT(obd, process_config);
716 obd->obd_process_conf = 0;
721 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
727 EXP_CHECK_DT_OP(exp, create);
728 EXP_COUNTER_INCREMENT(exp, create);
730 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
734 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
740 EXP_CHECK_DT_OP(exp, destroy);
741 EXP_COUNTER_INCREMENT(exp, destroy);
743 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
747 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
753 EXP_CHECK_DT_OP(exp, getattr);
754 EXP_COUNTER_INCREMENT(exp, getattr);
755 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
760 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
766 EXP_CHECK_DT_OP(exp, setattr);
767 EXP_COUNTER_INCREMENT(exp, setattr);
768 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
773 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
776 struct obd_device *obd = imp->imp_obd;
780 OBD_CHECK_DEV_ACTIVE(obd);
781 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
782 OBD_COUNTER_INCREMENT(obd, add_conn);
784 rc = OBP(obd, add_conn)(imp, uuid, priority);
788 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
790 struct obd_device *obd = imp->imp_obd;
794 OBD_CHECK_DEV_ACTIVE(obd);
795 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
796 OBD_COUNTER_INCREMENT(obd, del_conn);
798 rc = OBP(obd, del_conn)(imp, uuid);
802 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
804 struct obd_uuid *uuid;
807 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
808 EXP_COUNTER_INCREMENT(exp, get_uuid);
810 uuid = OBP(exp->exp_obd, get_uuid)(exp);
814 /** Create a new /a exp on device /a obd for the uuid /a cluuid
815 * @param exp New export handle
816 * @param d Connect data, supported flags are set, flags also understood
817 * by obd are returned.
819 static inline int obd_connect(const struct lu_env *env,
820 struct obd_export **exp,struct obd_device *obd,
821 struct obd_uuid *cluuid,
822 struct obd_connect_data *data,
826 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
830 OBD_CHECK_DEV_ACTIVE(obd);
831 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
832 OBD_COUNTER_INCREMENT(obd, connect);
834 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
835 /* check that only subset is granted */
836 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
837 data->ocd_connect_flags));
841 static inline int obd_reconnect(const struct lu_env *env,
842 struct obd_export *exp,
843 struct obd_device *obd,
844 struct obd_uuid *cluuid,
845 struct obd_connect_data *d,
849 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
854 OBD_CHECK_DEV_ACTIVE(obd);
855 OBD_CHECK_DT_OP(obd, reconnect, 0);
856 OBD_COUNTER_INCREMENT(obd, reconnect);
858 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
859 /* check that only subset is granted */
860 LASSERT(ergo(d != NULL,
861 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
865 static inline int obd_disconnect(struct obd_export *exp)
870 EXP_CHECK_DT_OP(exp, disconnect);
871 EXP_COUNTER_INCREMENT(exp, disconnect);
873 rc = OBP(exp->exp_obd, disconnect)(exp);
877 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
878 enum lu_cli_type type)
883 OBD_CHECK_DT_OP(obd, fid_init, 0);
884 OBD_COUNTER_INCREMENT(obd, fid_init);
886 rc = OBP(obd, fid_init)(obd, exp, type);
890 static inline int obd_fid_fini(struct obd_device *obd)
895 OBD_CHECK_DT_OP(obd, fid_fini, 0);
896 OBD_COUNTER_INCREMENT(obd, fid_fini);
898 rc = OBP(obd, fid_fini)(obd);
902 static inline int obd_fid_alloc(const struct lu_env *env,
903 struct obd_export *exp,
905 struct md_op_data *op_data)
910 EXP_CHECK_DT_OP(exp, fid_alloc);
911 EXP_COUNTER_INCREMENT(exp, fid_alloc);
913 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
917 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
922 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
923 EXP_COUNTER_INCREMENT(exp, ping);
925 rc = OBP(exp->exp_obd, ping)(env, exp);
929 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
934 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
935 OBD_COUNTER_INCREMENT(obd, pool_new);
937 rc = OBP(obd, pool_new)(obd, poolname);
941 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
946 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
947 OBD_COUNTER_INCREMENT(obd, pool_del);
949 rc = OBP(obd, pool_del)(obd, poolname);
953 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
958 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
959 OBD_COUNTER_INCREMENT(obd, pool_add);
961 rc = OBP(obd, pool_add)(obd, poolname, ostname);
965 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
970 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
971 OBD_COUNTER_INCREMENT(obd, pool_rem);
973 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
977 static inline void obd_getref(struct obd_device *obd)
980 if (OBT(obd) && OBP(obd, getref)) {
981 OBD_COUNTER_INCREMENT(obd, getref);
982 OBP(obd, getref)(obd);
987 static inline void obd_putref(struct obd_device *obd)
990 if (OBT(obd) && OBP(obd, putref)) {
991 OBD_COUNTER_INCREMENT(obd, putref);
992 OBP(obd, putref)(obd);
997 static inline int obd_init_export(struct obd_export *exp)
1002 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1003 OBP((exp)->exp_obd, init_export))
1004 rc = OBP(exp->exp_obd, init_export)(exp);
1008 static inline int obd_destroy_export(struct obd_export *exp)
1011 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1012 OBP((exp)->exp_obd, destroy_export))
1013 OBP(exp->exp_obd, destroy_export)(exp);
1017 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1018 * If the cache is older than @max_age we will get a new value from the
1019 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1020 static inline int obd_statfs_async(struct obd_export *exp,
1021 struct obd_info *oinfo,
1023 struct ptlrpc_request_set *rqset)
1026 struct obd_device *obd;
1029 if (exp == NULL || exp->exp_obd == NULL)
1033 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1034 OBD_COUNTER_INCREMENT(obd, statfs);
1036 CDEBUG(D_SUPER, "%s: osfs %p age %llu, max_age %llu\n",
1037 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1038 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1039 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1041 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1042 obd->obd_name, &obd->obd_osfs,
1043 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1044 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1045 spin_lock(&obd->obd_osfs_lock);
1046 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1047 spin_unlock(&obd->obd_osfs_lock);
1048 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1049 if (oinfo->oi_cb_up)
1050 oinfo->oi_cb_up(oinfo, 0);
1055 static inline int obd_statfs_rqset(struct obd_export *exp,
1056 struct obd_statfs *osfs, __u64 max_age,
1059 struct ptlrpc_request_set *set = NULL;
1060 struct obd_info oinfo = {
1068 set = ptlrpc_prep_set();
1072 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1074 rc = ptlrpc_set_wait(set);
1076 ptlrpc_set_destroy(set);
1081 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1082 * If the cache is older than @max_age we will get a new value from the
1083 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1084 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1085 struct obd_statfs *osfs, __u64 max_age,
1089 struct obd_device *obd = exp->exp_obd;
1095 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1096 OBD_COUNTER_INCREMENT(obd, statfs);
1098 CDEBUG(D_SUPER, "osfs %llu, max_age %llu\n",
1099 obd->obd_osfs_age, max_age);
1100 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1101 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1103 spin_lock(&obd->obd_osfs_lock);
1104 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1105 obd->obd_osfs_age = cfs_time_current_64();
1106 spin_unlock(&obd->obd_osfs_lock);
1109 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu"
1110 " objects %llu/%llu\n",
1111 obd->obd_name, &obd->obd_osfs,
1112 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1113 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1114 spin_lock(&obd->obd_osfs_lock);
1115 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1116 spin_unlock(&obd->obd_osfs_lock);
1121 static inline int obd_preprw(const struct lu_env *env, int cmd,
1122 struct obd_export *exp, struct obdo *oa,
1123 int objcount, struct obd_ioobj *obj,
1124 struct niobuf_remote *remote, int *pages,
1125 struct niobuf_local *local)
1130 EXP_CHECK_DT_OP(exp, preprw);
1131 EXP_COUNTER_INCREMENT(exp, preprw);
1132 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1138 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1139 struct obd_export *exp, struct obdo *oa,
1140 int objcount, struct obd_ioobj *obj,
1141 struct niobuf_remote *rnb, int pages,
1142 struct niobuf_local *local, int rc)
1146 EXP_CHECK_DT_OP(exp, commitrw);
1147 EXP_COUNTER_INCREMENT(exp, commitrw);
1148 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1149 rnb, pages, local, rc);
1154 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1155 int len, void *karg, void __user *uarg)
1160 EXP_CHECK_DT_OP(exp, iocontrol);
1161 EXP_COUNTER_INCREMENT(exp, iocontrol);
1163 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1167 static inline void obd_import_event(struct obd_device *obd,
1168 struct obd_import *imp,
1169 enum obd_import_event event)
1173 CERROR("NULL device\n");
1177 if (obd->obd_set_up && OBP(obd, import_event)) {
1178 OBD_COUNTER_INCREMENT(obd, import_event);
1179 OBP(obd, import_event)(obd, imp, event);
1184 static inline int obd_notify(struct obd_device *obd,
1185 struct obd_device *watched,
1186 enum obd_notify_event ev)
1192 if (!obd->obd_set_up) {
1193 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1197 if (!OBP(obd, notify)) {
1198 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1202 OBD_COUNTER_INCREMENT(obd, notify);
1203 rc = OBP(obd, notify)(obd, watched, ev);
1208 static inline int obd_notify_observer(struct obd_device *observer,
1209 struct obd_device *observed,
1210 enum obd_notify_event ev)
1214 struct obd_notify_upcall *onu;
1216 if (observer->obd_observer)
1217 rc = obd_notify(observer->obd_observer, observed, ev);
1220 * Also, call non-obd listener, if any
1222 onu = &observer->obd_upcall;
1223 if (onu->onu_upcall != NULL)
1224 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1226 return rc ? rc : rc2;
1229 static inline int obd_quotactl(struct obd_export *exp,
1230 struct obd_quotactl *oqctl)
1235 EXP_CHECK_DT_OP(exp, quotactl);
1236 EXP_COUNTER_INCREMENT(exp, quotactl);
1238 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1242 static inline int obd_health_check(const struct lu_env *env,
1243 struct obd_device *obd)
1245 /* returns: 0 on healthy
1246 * >0 on unhealthy + reason code/flag
1247 * however the only suppored reason == 1 right now
1248 * We'll need to define some better reasons
1249 * or flags in the future.
1255 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1256 if (obd == NULL || !OBT(obd)) {
1257 CERROR("cleaned up obd\n");
1258 RETURN(-EOPNOTSUPP);
1260 if (!obd->obd_set_up || obd->obd_stopping)
1262 if (!OBP(obd, health_check))
1265 rc = OBP(obd, health_check)(env, obd);
1269 static inline int obd_register_observer(struct obd_device *obd,
1270 struct obd_device *observer)
1274 down_write(&obd->obd_observer_link_sem);
1275 if (obd->obd_observer && observer) {
1276 up_write(&obd->obd_observer_link_sem);
1279 obd->obd_observer = observer;
1280 up_write(&obd->obd_observer_link_sem);
1284 /* metadata helpers */
1285 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1291 EXP_CHECK_MD_OP(exp, get_root);
1292 EXP_MD_COUNTER_INCREMENT(exp, get_root);
1293 rc = MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1298 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1299 struct ptlrpc_request **request)
1303 EXP_CHECK_MD_OP(exp, getattr);
1304 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1305 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1309 static inline int md_null_inode(struct obd_export *exp,
1310 const struct lu_fid *fid)
1314 EXP_CHECK_MD_OP(exp, null_inode);
1315 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1316 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1320 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1321 struct md_open_data *mod,
1322 struct ptlrpc_request **request)
1326 EXP_CHECK_MD_OP(exp, close);
1327 EXP_MD_COUNTER_INCREMENT(exp, close);
1328 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1332 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1333 const void *data, size_t datalen, umode_t mode,
1334 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1335 __u64 rdev, struct ptlrpc_request **request)
1339 EXP_CHECK_MD_OP(exp, create);
1340 EXP_MD_COUNTER_INCREMENT(exp, create);
1341 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1342 uid, gid, cap_effective, rdev, request);
1346 static inline int md_enqueue(struct obd_export *exp,
1347 struct ldlm_enqueue_info *einfo,
1348 const union ldlm_policy_data *policy,
1349 struct md_op_data *op_data,
1350 struct lustre_handle *lockh,
1351 __u64 extra_lock_flags)
1355 EXP_CHECK_MD_OP(exp, enqueue);
1356 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1357 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1362 static inline int md_getattr_name(struct obd_export *exp,
1363 struct md_op_data *op_data,
1364 struct ptlrpc_request **request)
1368 EXP_CHECK_MD_OP(exp, getattr_name);
1369 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1370 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1374 static inline int md_intent_lock(struct obd_export *exp,
1375 struct md_op_data *op_data,
1376 struct lookup_intent *it,
1377 struct ptlrpc_request **reqp,
1378 ldlm_blocking_callback cb_blocking,
1379 __u64 extra_lock_flags)
1383 EXP_CHECK_MD_OP(exp, intent_lock);
1384 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1385 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1390 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1391 struct ptlrpc_request **request)
1395 EXP_CHECK_MD_OP(exp, link);
1396 EXP_MD_COUNTER_INCREMENT(exp, link);
1397 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1401 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1402 const char *old, size_t oldlen, const char *new,
1403 size_t newlen, struct ptlrpc_request **request)
1407 EXP_CHECK_MD_OP(exp, rename);
1408 EXP_MD_COUNTER_INCREMENT(exp, rename);
1409 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1414 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1415 void *ea, size_t ealen,
1416 struct ptlrpc_request **request)
1420 EXP_CHECK_MD_OP(exp, setattr);
1421 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1422 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1426 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1427 struct ptlrpc_request **request)
1432 EXP_CHECK_MD_OP(exp, fsync);
1433 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1434 rc = MDP(exp->exp_obd, fsync)(exp, fid, request);
1439 static inline int md_read_page(struct obd_export *exp,
1440 struct md_op_data *op_data,
1441 struct md_callback *cb_op,
1443 struct page **ppage)
1447 EXP_CHECK_MD_OP(exp, read_page);
1448 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1449 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1454 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1455 struct ptlrpc_request **request)
1459 EXP_CHECK_MD_OP(exp, unlink);
1460 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1461 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1465 static inline int md_get_lustre_md(struct obd_export *exp,
1466 struct ptlrpc_request *req,
1467 struct obd_export *dt_exp,
1468 struct obd_export *md_exp,
1469 struct lustre_md *md)
1472 EXP_CHECK_MD_OP(exp, get_lustre_md);
1473 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1474 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1477 static inline int md_free_lustre_md(struct obd_export *exp,
1478 struct lustre_md *md)
1481 EXP_CHECK_MD_OP(exp, free_lustre_md);
1482 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1483 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1486 static inline int md_merge_attr(struct obd_export *exp,
1487 const struct lmv_stripe_md *lsm,
1488 struct cl_attr *attr,
1489 ldlm_blocking_callback cb)
1492 EXP_CHECK_MD_OP(exp, merge_attr);
1493 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1494 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1497 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1498 u64 valid, const char *name,
1499 const char *input, int input_size,
1500 int output_size, int flags, __u32 suppgid,
1501 struct ptlrpc_request **request)
1504 EXP_CHECK_MD_OP(exp, setxattr);
1505 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1506 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1507 input_size, output_size, flags,
1511 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1512 u64 valid, const char *name,
1513 const char *input, int input_size,
1514 int output_size, int flags,
1515 struct ptlrpc_request **request)
1518 EXP_CHECK_MD_OP(exp, getxattr);
1519 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1520 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1521 input_size, output_size, flags,
1525 static inline int md_set_open_replay_data(struct obd_export *exp,
1526 struct obd_client_handle *och,
1527 struct lookup_intent *it)
1530 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1531 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1532 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1535 static inline int md_clear_open_replay_data(struct obd_export *exp,
1536 struct obd_client_handle *och)
1539 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1540 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1541 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1544 static inline int md_set_lock_data(struct obd_export *exp,
1545 const struct lustre_handle *lockh,
1546 void *data, __u64 *bits)
1549 EXP_CHECK_MD_OP(exp, set_lock_data);
1550 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1551 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1555 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1556 union ldlm_policy_data *policy, enum ldlm_mode mode,
1557 enum ldlm_cancel_flags cancel_flags, void *opaque)
1562 EXP_CHECK_MD_OP(exp, cancel_unused);
1563 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1565 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1566 cancel_flags, opaque);
1570 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1571 const struct lu_fid *fid,
1572 enum ldlm_type type,
1573 union ldlm_policy_data *policy,
1574 enum ldlm_mode mode,
1575 struct lustre_handle *lockh)
1578 EXP_CHECK_MD_OP(exp, lock_match);
1579 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1580 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1581 policy, mode, lockh));
1584 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1588 EXP_CHECK_MD_OP(exp, init_ea_size);
1589 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1590 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
1593 static inline int md_intent_getattr_async(struct obd_export *exp,
1594 struct md_enqueue_info *minfo)
1598 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1599 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1600 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1604 static inline int md_revalidate_lock(struct obd_export *exp,
1605 struct lookup_intent *it,
1606 struct lu_fid *fid, __u64 *bits)
1610 EXP_CHECK_MD_OP(exp, revalidate_lock);
1611 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1612 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1616 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1617 const struct lmv_stripe_md *lsm,
1618 const char *name, int namelen,
1623 EXP_CHECK_MD_OP(exp, get_fid_from_lsm);
1624 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1625 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1630 /* Unpack an MD struct from disk to in-memory format.
1631 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1633 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1634 * If *plsm == NULL then it will be allocated.
1636 static inline int md_unpackmd(struct obd_export *exp,
1637 struct lmv_stripe_md **plsm,
1638 const union lmv_mds_md *lmm, size_t lmm_size)
1642 EXP_CHECK_MD_OP(exp, unpackmd);
1643 EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
1644 rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1648 /* OBD Metadata Support */
1650 extern int obd_init_caches(void);
1651 extern void obd_cleanup_caches(void);
1653 /* support routines */
1654 extern struct kmem_cache *obdo_cachep;
1656 #define OBDO_ALLOC(ptr) \
1658 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1661 #define OBDO_FREE(ptr) \
1663 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1667 typedef int (*register_lwp_cb)(void *data);
1669 struct lwp_register_item {
1670 struct obd_export **lri_exp;
1671 register_lwp_cb lri_cb_func;
1673 struct list_head lri_list;
1675 char lri_name[MTI_NAME_MAXLEN];
1678 /* I'm as embarrassed about this as you are.
1680 * <shaver> // XXX do not look into _superhack with remaining eye
1681 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1682 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1685 #ifdef HAVE_SERVER_SUPPORT
1686 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1687 register_lwp_cb cb_func, void *cb_data);
1688 void lustre_deregister_lwp_item(struct obd_export **exp);
1689 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1690 void lustre_notify_lwp_list(struct obd_export *exp);
1691 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1692 #endif /* HAVE_SERVER_SUPPORT */
1693 int lustre_register_fs(void);
1694 int lustre_unregister_fs(void);
1695 int lustre_check_exclusion(struct super_block *sb, char *svname);
1698 extern int obd_sysctl_init(void);
1699 extern void obd_sysctl_clean(void);
1702 typedef __u8 class_uuid_t[16];
1703 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1706 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1707 int class_add_uuid(const char *uuid, __u64 nid);
1708 int class_del_uuid (const char *uuid);
1709 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1712 extern char obd_jobid_node[];
1715 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1719 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1720 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1722 /* root squash info */
1723 struct rw_semaphore;
1724 struct root_squash_info {
1727 struct list_head rsi_nosquash_nids;
1728 struct rw_semaphore rsi_sem;
1731 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1733 /* linux-module.c */
1734 extern struct miscdevice obd_psdev;
1735 int obd_ioctl_getdata(char **buf, int *len, void __user *arg);
1736 int class_procfs_init(void);
1737 int class_procfs_clean(void);
1739 #endif /* __LINUX_OBD_CLASS_H */