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, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
35 #include <linux/kobject.h>
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, size_t len);
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 struct kobject *class_setup_tunables(const char *name);
67 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
68 struct lprocfs_vars *module_vars,
69 const char *nm, struct lu_device_type *ldt);
70 int class_unregister_type(const char *nm);
72 struct obd_device *class_newdev(const char *type_name, const char *name,
74 int class_register_device(struct obd_device *obd);
75 void class_unregister_device(struct obd_device *obd);
76 void class_free_dev(struct obd_device *obd);
78 struct obd_device *class_dev_by_str(const char *str);
79 int class_name2dev(const char *name);
80 struct obd_device *class_name2obd(const char *name);
81 int class_uuid2dev(struct obd_uuid *uuid);
82 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
83 void class_obd_list(void);
84 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
85 const char * typ_name,
86 struct obd_uuid *grp_uuid);
87 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
89 struct obd_device * class_num2obd(int num);
90 int get_devices_count(void);
92 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
94 static inline char *obd_export_nid2str(struct obd_export *exp)
96 return exp->exp_connection == NULL ?
97 "<unknown>" : libcfs_nid2str(exp->exp_connection->c_peer.nid);
100 static inline char *obd_import_nid2str(struct obd_import *imp)
102 return imp->imp_connection == NULL ?
103 "<unknown>" : libcfs_nid2str(imp->imp_connection->c_peer.nid);
106 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
107 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
108 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
111 int obd_zombie_impexp_init(void);
112 void obd_zombie_impexp_stop(void);
113 void obd_zombie_impexp_cull(void);
114 void obd_zombie_barrier(void);
115 void obd_exports_barrier(struct obd_device *obd);
116 int kuc_len(int payload_len);
117 struct kuc_hdr * kuc_ptr(void *p);
118 void *kuc_alloc(int payload_len, int transport, int type);
119 void kuc_free(void *p, int payload_len);
120 int obd_get_request_slot(struct client_obd *cli);
121 void obd_put_request_slot(struct client_obd *cli);
122 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
123 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
124 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
125 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
126 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
128 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc,
129 struct lookup_intent *it);
130 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc,
131 struct lookup_intent *it, __u16 tag);
135 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
136 struct llog_rec_hdr *, void *);
138 struct obd_export *obd_stale_export_get(void);
139 void obd_stale_export_put(struct obd_export *exp);
140 void obd_stale_export_adjust(struct obd_export *exp);
143 /* For interoperability */
144 struct cfg_interop_param {
149 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
150 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
151 const char *new_name);
152 void print_lustre_cfg(struct lustre_cfg *lcfg);
153 int class_process_config(struct lustre_cfg *lcfg);
154 ssize_t class_set_global(const char *param);
155 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
156 struct kobject *kobj);
157 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
158 struct lustre_cfg *lcfg, void *data);
159 int class_attach(struct lustre_cfg *lcfg);
160 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
161 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
162 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
164 int class_find_param(char *buf, char *key, char **valp);
165 struct cfg_interop_param *class_find_old_param(const char *param,
166 struct cfg_interop_param *ptr);
167 int class_get_next_param(char **params, char *copy);
168 int class_match_param(char *buf, const char *key, char **valp);
169 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
170 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
171 int class_parse_net(char *buf, u32 *net, char **endh);
172 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
173 int class_match_net(char *buf, char *key, u32 net);
175 struct obd_device *class_incref(struct obd_device *obd,
176 const char *scope, const void *source);
177 void class_decref(struct obd_device *obd,
178 const char *scope, const void *source);
179 void dump_exports(struct obd_device *obd, int locks, int debug_level);
180 int class_config_llog_handler(const struct lu_env *env,
181 struct llog_handle *handle,
182 struct llog_rec_hdr *rec, void *data);
183 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
185 #define CFG_F_START 0x01 /* Set when we start updating from a log */
186 #define CFG_F_MARKER 0x02 /* We are within a maker */
187 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
188 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
189 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
191 /* Passed as data param to class_config_parse_llog */
192 struct config_llog_instance {
195 struct super_block *cfg_sb;
196 struct obd_uuid cfg_uuid;
197 llog_cb_t cfg_callback;
198 int cfg_last_idx; /* for partial llog processing */
203 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
204 char *name, struct config_llog_instance *cfg);
206 #define CONFIG_SUB_SPTLRPC 0x01
207 #define CONFIG_SUB_RECOVER 0x02
208 #define CONFIG_SUB_PARAMS 0x04
209 #define CONFIG_SUB_NODEMAP 0x08
210 #define CONFIG_SUB_BARRIER 0x10
212 /* Sub clds should be attached to the config_llog_data when processing
213 * config log for client or server target. */
214 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
216 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
219 #define PARAMS_FILENAME "params"
220 #define BARRIER_FILENAME "barrier"
221 #define LCTL_UPCALL "lctl"
223 static inline bool logname_is_barrier(const char *logname)
227 /* logname for barrier is "fsname-barrier" */
228 ptr = strstr(logname, BARRIER_FILENAME);
229 if (ptr && (ptr - logname) >= 2 &&
230 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
236 /* list of active configuration logs */
237 struct config_llog_data {
238 struct ldlm_res_id cld_resid;
239 struct config_llog_instance cld_cfg;
240 struct list_head cld_list_chain;/* on config_llog_list */
241 atomic_t cld_refcount;
242 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
243 struct config_llog_data *cld_params; /* common parameters log */
244 struct config_llog_data *cld_recover;/* imperative recover log */
245 struct config_llog_data *cld_nodemap;/* nodemap log */
246 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
247 struct obd_export *cld_mgcexp;
248 struct mutex cld_lock;
250 unsigned int cld_stopping:1, /* we were told to stop
252 cld_lostlock:1; /* lock not requeued */
256 struct lustre_profile {
257 struct list_head lp_list;
262 bool lp_list_deleted;
265 struct lustre_profile *class_get_profile(const char * prof);
266 void class_del_profile(const char *prof);
267 void class_put_profile(struct lustre_profile *lprof);
268 void class_del_profiles(void);
271 #if LUSTRE_TRACKS_LOCK_EXP_REFS
273 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
274 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
275 extern void (*class_export_dump_hook)(struct obd_export *);
279 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
280 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
284 #define class_export_rpc_inc(exp) \
286 atomic_inc(&(exp)->exp_rpc_count); \
287 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
288 (exp), atomic_read(&(exp)->exp_rpc_count)); \
291 #define class_export_rpc_dec(exp) \
293 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
294 atomic_dec(&(exp)->exp_rpc_count); \
295 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
296 (exp), atomic_read(&(exp)->exp_rpc_count)); \
299 #define class_export_lock_get(exp, lock) \
301 atomic_inc(&(exp)->exp_locks_count); \
302 __class_export_add_lock_ref(exp, lock); \
303 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
304 (exp), atomic_read(&(exp)->exp_locks_count)); \
305 class_export_get(exp); \
308 #define class_export_lock_put(exp, lock) \
310 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
311 atomic_dec(&(exp)->exp_locks_count); \
312 __class_export_del_lock_ref(exp, lock); \
313 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
314 (exp), atomic_read(&(exp)->exp_locks_count)); \
315 class_export_put(exp); \
318 #define class_export_cb_get(exp) \
320 atomic_inc(&(exp)->exp_cb_count); \
321 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
322 (exp), atomic_read(&(exp)->exp_cb_count)); \
323 class_export_get(exp); \
326 #define class_export_cb_put(exp) \
328 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
329 atomic_dec(&(exp)->exp_cb_count); \
330 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
331 (exp), atomic_read(&(exp)->exp_cb_count)); \
332 class_export_put(exp); \
336 struct obd_export *class_export_get(struct obd_export *exp);
337 void class_export_put(struct obd_export *exp);
338 struct obd_export *class_new_export(struct obd_device *obddev,
339 struct obd_uuid *cluuid);
340 struct obd_export *class_new_export_self(struct obd_device *obd,
341 struct obd_uuid *uuid);
342 void class_unlink_export(struct obd_export *exp);
344 struct obd_import *class_import_get(struct obd_import *);
345 void class_import_put(struct obd_import *);
346 struct obd_import *class_new_import(struct obd_device *obd);
347 void class_destroy_import(struct obd_import *exp);
349 struct obd_type *class_search_type(const char *name);
350 struct obd_type *class_get_type(const char *name);
351 void class_put_type(struct obd_type *type);
352 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
353 struct obd_uuid *cluuid);
354 int class_disconnect(struct obd_export *exp);
355 void class_fail_export(struct obd_export *exp);
356 int class_connected_export(struct obd_export *exp);
357 void class_disconnect_exports(struct obd_device *obddev);
358 int class_manual_cleanup(struct obd_device *obd);
359 void class_disconnect_stale_exports(struct obd_device *,
360 int (*test_export)(struct obd_export *));
361 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
363 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
364 (obd->obd_force ? OBD_OPT_FORCE : 0) |
365 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
369 #ifdef HAVE_SERVER_SUPPORT
370 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
372 LASSERT(exp->exp_obd);
373 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
375 return exp->exp_obd->u.obt.obt_lut;
378 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
380 LASSERT(obd->u.obt.obt_lut);
381 return &obd->u.obt.obt_lut->lut_lsd;
389 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
390 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
392 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
393 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
395 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
396 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
398 /* Ensure obd_setup: used for cleanup which must be called
399 while obd is stopping */
400 #define OBD_CHECK_DEV(obd) \
403 CERROR("NULL device\n"); \
408 /* ensure obd_setup and !obd_stopping */
409 #define OBD_CHECK_DEV_ACTIVE(obd) \
411 OBD_CHECK_DEV(obd); \
412 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
413 CERROR("Device %d not setup\n", \
420 #ifdef CONFIG_PROC_FS
421 #define OBD_COUNTER_OFFSET(op) \
422 ((offsetof(struct obd_ops, o_ ## op) - \
423 offsetof(struct obd_ops, o_iocontrol)) \
424 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
426 /* The '- 1' below is for o_owner. */
427 #define NUM_OBD_STATS \
428 (sizeof(struct obd_ops) / \
429 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
431 #define OBD_COUNTER_INCREMENT(obd, op) \
432 lprocfs_counter_incr((obd)->obd_stats, \
433 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
435 #define EXP_COUNTER_INCREMENT(exp, op) \
438 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
439 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
440 if ((exp)->exp_obd->obd_uses_nid_stats && \
441 (exp)->exp_nid_stats != NULL) \
442 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
446 #define _MD_COUNTER_OFFSET(m_op) \
447 ((offsetof(struct md_ops, m_op) - \
448 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
449 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
451 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
453 #define NUM_MD_STATS \
454 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
455 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
457 /* Note that we only increment md counters for ops whose offset is less
458 * than NUM_MD_STATS. This is explained in a comment in the definition
459 * of struct md_ops. */
460 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
462 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
463 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
464 (exp)->exp_obd->obd_md_cntr_base + \
465 MD_COUNTER_OFFSET(op)); \
469 #define OBD_COUNTER_OFFSET(op)
470 #define OBD_COUNTER_INCREMENT(obd, op)
471 #define EXP_COUNTER_INCREMENT(exp, op)
472 #define EXP_MD_COUNTER_INCREMENT(exp, op)
475 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
477 /* Always add in ldlm_stats */
478 tmp->nid_ldlm_stats =
479 lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC,
480 LPROCFS_STATS_FLAG_NOPERCPU);
481 if (tmp->nid_ldlm_stats == NULL)
484 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
486 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
487 tmp->nid_ldlm_stats);
490 static inline int exp_check_ops(struct obd_export *exp)
495 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
501 static inline int class_devno_max(void)
503 return MAX_OBD_DEVICES;
506 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
507 __u32 keylen, void *key,
508 __u32 *vallen, void *val)
513 rc = exp_check_ops(exp);
517 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
518 CERROR("%s: no %s operation\n",
519 (exp)->exp_obd->obd_name, __func__);
522 EXP_COUNTER_INCREMENT(exp, get_info);
524 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
528 static inline int obd_set_info_async(const struct lu_env *env,
529 struct obd_export *exp,
530 __u32 keylen, void *key,
531 __u32 vallen, void *val,
532 struct ptlrpc_request_set *set)
537 rc = exp_check_ops(exp);
541 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
542 CERROR("%s: no %s operation\n",
543 (exp)->exp_obd->obd_name, __func__);
546 EXP_COUNTER_INCREMENT(exp, set_info_async);
548 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
554 * obd-lu integration.
556 * Functionality is being moved into new lu_device-based layering, but some
557 * pieces of configuration process are still based on obd devices.
559 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
560 * subsume ->o_setup() methods of obd devices they replace. The same for
561 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
562 * result, obd_setup() and obd_process_config() branch and call one XOR
565 * Yet neither lu_device_type_operations::ldto_device_fini() nor
566 * lu_device_type_operations::ldto_device_free() fully implement the
567 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
568 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
570 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
573 struct lu_device_type *ldt = obd->obd_type->typ_lu;
579 struct lu_context session_ctx;
581 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
582 session_ctx.lc_thread = NULL;
583 lu_context_enter(&session_ctx);
585 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
587 env.le_ses = &session_ctx;
588 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
597 lu_context_exit(&session_ctx);
598 lu_context_fini(&session_ctx);
601 if (!obd->obd_type->typ_dt_ops->o_setup) {
602 CERROR("%s: no %s operation\n", obd->obd_name,
606 OBD_COUNTER_INCREMENT(obd, setup);
607 rc = OBP(obd, setup)(obd, cfg);
612 static inline int obd_precleanup(struct obd_device *obd)
615 struct lu_device_type *ldt = obd->obd_type->typ_lu;
616 struct lu_device *d = obd->obd_lu_dev;
620 if (ldt != NULL && d != NULL) {
623 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
625 ldt->ldt_ops->ldto_device_fini(&env, d);
630 if (!obd->obd_type->typ_dt_ops->o_precleanup)
633 OBD_COUNTER_INCREMENT(obd, precleanup);
635 rc = OBP(obd, precleanup)(obd);
639 static inline int obd_cleanup(struct obd_device *obd)
642 struct lu_device_type *ldt = obd->obd_type->typ_lu;
643 struct lu_device *d = obd->obd_lu_dev;
646 if (ldt != NULL && d != NULL) {
649 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
651 ldt->ldt_ops->ldto_device_free(&env, d);
653 obd->obd_lu_dev = NULL;
656 if (!obd->obd_type->typ_dt_ops->o_cleanup)
659 OBD_COUNTER_INCREMENT(obd, cleanup);
661 rc = OBP(obd, cleanup)(obd);
665 static inline void obd_cleanup_client_import(struct obd_device *obd)
669 /* If we set up but never connected, the
670 client import will not have been cleaned. */
671 down_write(&obd->u.cli.cl_sem);
672 if (obd->u.cli.cl_import) {
673 struct obd_import *imp;
674 imp = obd->u.cli.cl_import;
675 CDEBUG(D_CONFIG, "%s: client import never connected\n",
677 ptlrpc_invalidate_import(imp);
678 client_destroy_import(imp);
679 obd->u.cli.cl_import = NULL;
681 up_write(&obd->u.cli.cl_sem);
686 static inline int obd_process_config(struct obd_device *obd, int datalen,
690 struct lu_device_type *ldt = obd->obd_type->typ_lu;
691 struct lu_device *d = obd->obd_lu_dev;
695 obd->obd_process_conf = 1;
696 if (ldt != NULL && d != NULL) {
699 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
701 rc = d->ld_ops->ldo_process_config(&env, d, data);
705 if (!obd->obd_type->typ_dt_ops->o_process_config) {
706 CERROR("%s: no %s operation\n",
707 obd->obd_name, __func__);
710 rc = OBP(obd, process_config)(obd, datalen, data);
712 OBD_COUNTER_INCREMENT(obd, process_config);
713 obd->obd_process_conf = 0;
718 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
724 rc = exp_check_ops(exp);
728 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
729 CERROR("%s: no %s operation\n",
730 (exp)->exp_obd->obd_name, __func__);
733 EXP_COUNTER_INCREMENT(exp, create);
735 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
739 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
745 rc = exp_check_ops(exp);
749 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
750 CERROR("%s: no %s operation\n",
751 (exp)->exp_obd->obd_name, __func__);
754 EXP_COUNTER_INCREMENT(exp, destroy);
756 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
760 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
766 rc = exp_check_ops(exp);
770 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
771 CERROR("%s: no %s operation\n",
772 (exp)->exp_obd->obd_name, __func__);
775 EXP_COUNTER_INCREMENT(exp, getattr);
776 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
781 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
787 rc = exp_check_ops(exp);
791 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
792 CERROR("%s: no %s operation\n",
793 (exp)->exp_obd->obd_name, __func__);
796 EXP_COUNTER_INCREMENT(exp, setattr);
797 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
802 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
805 struct obd_device *obd = imp->imp_obd;
809 OBD_CHECK_DEV_ACTIVE(obd);
810 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
811 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
814 OBD_COUNTER_INCREMENT(obd, add_conn);
816 rc = OBP(obd, add_conn)(imp, uuid, priority);
820 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
822 struct obd_device *obd = imp->imp_obd;
826 OBD_CHECK_DEV_ACTIVE(obd);
827 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
828 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
831 OBD_COUNTER_INCREMENT(obd, del_conn);
833 rc = OBP(obd, del_conn)(imp, uuid);
837 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
839 struct obd_uuid *uuid;
842 if (!exp->exp_obd->obd_type ||
843 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
846 EXP_COUNTER_INCREMENT(exp, get_uuid);
848 uuid = OBP(exp->exp_obd, get_uuid)(exp);
852 /** Create a new /a exp on device /a obd for the uuid /a cluuid
853 * @param exp New export handle
854 * @param d Connect data, supported flags are set, flags also understood
855 * by obd are returned.
857 static inline int obd_connect(const struct lu_env *env,
858 struct obd_export **exp,struct obd_device *obd,
859 struct obd_uuid *cluuid,
860 struct obd_connect_data *data,
864 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
868 OBD_CHECK_DEV_ACTIVE(obd);
869 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
870 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
873 OBD_COUNTER_INCREMENT(obd, connect);
875 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
876 /* check that only subset is granted */
877 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
878 data->ocd_connect_flags));
882 static inline int obd_reconnect(const struct lu_env *env,
883 struct obd_export *exp,
884 struct obd_device *obd,
885 struct obd_uuid *cluuid,
886 struct obd_connect_data *d,
890 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
895 OBD_CHECK_DEV_ACTIVE(obd);
896 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
899 OBD_COUNTER_INCREMENT(obd, reconnect);
901 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
902 /* check that only subset is granted */
903 LASSERT(ergo(d != NULL,
904 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
908 static inline int obd_disconnect(struct obd_export *exp)
912 rc = exp_check_ops(exp);
916 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
917 CERROR("%s: no %s operation\n",
918 (exp)->exp_obd->obd_name, __func__);
921 EXP_COUNTER_INCREMENT(exp, disconnect);
923 rc = OBP(exp->exp_obd, disconnect)(exp);
927 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
928 enum lu_cli_type type)
933 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
935 OBD_COUNTER_INCREMENT(obd, fid_init);
937 rc = OBP(obd, fid_init)(obd, exp, type);
941 static inline int obd_fid_fini(struct obd_device *obd)
945 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
947 OBD_COUNTER_INCREMENT(obd, fid_fini);
949 rc = OBP(obd, fid_fini)(obd);
953 static inline int obd_fid_alloc(const struct lu_env *env,
954 struct obd_export *exp,
956 struct md_op_data *op_data)
960 rc = exp_check_ops(exp);
964 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
965 CERROR("%s: no %s operation\n",
966 (exp)->exp_obd->obd_name, __func__);
969 EXP_COUNTER_INCREMENT(exp, fid_alloc);
971 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
975 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
980 if (!exp->exp_obd->obd_type ||
981 !exp->exp_obd->obd_type->typ_dt_ops->o_ping)
984 EXP_COUNTER_INCREMENT(exp, ping);
986 rc = OBP(exp->exp_obd, ping)(env, exp);
990 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
995 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
996 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
999 OBD_COUNTER_INCREMENT(obd, pool_new);
1001 rc = OBP(obd, pool_new)(obd, poolname);
1005 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1009 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
1010 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1011 RETURN(-EOPNOTSUPP);
1013 OBD_COUNTER_INCREMENT(obd, pool_del);
1015 rc = OBP(obd, pool_del)(obd, poolname);
1019 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
1025 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
1026 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1027 RETURN(-EOPNOTSUPP);
1029 OBD_COUNTER_INCREMENT(obd, pool_add);
1031 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1035 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
1041 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
1042 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1043 RETURN(-EOPNOTSUPP);
1045 OBD_COUNTER_INCREMENT(obd, pool_rem);
1047 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1051 static inline void obd_getref(struct obd_device *obd)
1054 if (obd->obd_type && OBP(obd, getref)) {
1055 OBD_COUNTER_INCREMENT(obd, getref);
1056 OBP(obd, getref)(obd);
1061 static inline void obd_putref(struct obd_device *obd)
1064 if (obd->obd_type && OBP(obd, putref)) {
1065 OBD_COUNTER_INCREMENT(obd, putref);
1066 OBP(obd, putref)(obd);
1071 static inline int obd_init_export(struct obd_export *exp)
1076 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1077 OBP((exp)->exp_obd, init_export))
1078 rc = OBP(exp->exp_obd, init_export)(exp);
1082 static inline int obd_destroy_export(struct obd_export *exp)
1085 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1086 OBP(exp->exp_obd, destroy_export))
1087 OBP(exp->exp_obd, destroy_export)(exp);
1091 /* @max_age is the oldest time in seconds that we accept using a cached data.
1092 * If the cache is older than @max_age we will get a new value from the
1093 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1095 static inline int obd_statfs_async(struct obd_export *exp,
1096 struct obd_info *oinfo,
1098 struct ptlrpc_request_set *rqset)
1101 struct obd_device *obd;
1105 if (exp == NULL || exp->exp_obd == NULL)
1109 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1110 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1111 RETURN(-EOPNOTSUPP);
1113 OBD_COUNTER_INCREMENT(obd, statfs);
1115 CDEBUG(D_SUPER, "%s: osfs %p age %lld, max_age %lld\n",
1116 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1117 if (obd->obd_osfs_age < max_age) {
1118 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1121 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1122 obd->obd_name, &obd->obd_osfs,
1123 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1124 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1125 spin_lock(&obd->obd_osfs_lock);
1126 memcpy(oinfo->oi_osfs, &obd->obd_osfs,
1127 sizeof(*oinfo->oi_osfs));
1128 spin_unlock(&obd->obd_osfs_lock);
1129 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1130 if (oinfo->oi_cb_up)
1131 oinfo->oi_cb_up(oinfo, 0);
1136 /* @max_age is the oldest time in seconds that we accept using a cached data.
1137 * If the cache is older than @max_age we will get a new value from the
1138 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1140 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1141 struct obd_statfs *osfs, time64_t max_age,
1145 struct obd_device *obd = exp->exp_obd;
1151 OBD_CHECK_DEV_ACTIVE(obd);
1153 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1154 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1155 RETURN(-EOPNOTSUPP);
1157 OBD_COUNTER_INCREMENT(obd, statfs);
1159 CDEBUG(D_SUPER, "osfs %lld, max_age %lld\n",
1160 obd->obd_osfs_age, max_age);
1161 if (obd->obd_osfs_age < max_age) {
1162 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1164 spin_lock(&obd->obd_osfs_lock);
1165 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1166 obd->obd_osfs_age = ktime_get_seconds();
1167 spin_unlock(&obd->obd_osfs_lock);
1170 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu"
1171 " objects %llu/%llu\n",
1172 obd->obd_name, &obd->obd_osfs,
1173 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1174 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1175 spin_lock(&obd->obd_osfs_lock);
1176 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1177 spin_unlock(&obd->obd_osfs_lock);
1182 static inline int obd_preprw(const struct lu_env *env, int cmd,
1183 struct obd_export *exp, struct obdo *oa,
1184 int objcount, struct obd_ioobj *obj,
1185 struct niobuf_remote *remote, int *pages,
1186 struct niobuf_local *local)
1192 rc = exp_check_ops(exp);
1196 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1197 CERROR("%s: no %s operation\n",
1198 (exp)->exp_obd->obd_name, __func__);
1201 EXP_COUNTER_INCREMENT(exp, preprw);
1202 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1208 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1209 struct obd_export *exp, struct obdo *oa,
1210 int objcount, struct obd_ioobj *obj,
1211 struct niobuf_remote *rnb, int pages,
1212 struct niobuf_local *local, int rc)
1216 rc = exp_check_ops(exp);
1220 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1221 CERROR("%s: no %s operation\n",
1222 (exp)->exp_obd->obd_name, __func__);
1225 EXP_COUNTER_INCREMENT(exp, commitrw);
1226 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1227 rnb, pages, local, rc);
1232 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1233 int len, void *karg, void __user *uarg)
1238 rc = exp_check_ops(exp);
1242 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1243 CERROR("%s: no %s operation\n",
1244 (exp)->exp_obd->obd_name, __func__);
1247 EXP_COUNTER_INCREMENT(exp, iocontrol);
1249 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1253 static inline void obd_import_event(struct obd_device *obd,
1254 struct obd_import *imp,
1255 enum obd_import_event event)
1259 CERROR("NULL device\n");
1263 if (obd->obd_set_up && OBP(obd, import_event)) {
1264 OBD_COUNTER_INCREMENT(obd, import_event);
1265 OBP(obd, import_event)(obd, imp, event);
1270 static inline int obd_notify(struct obd_device *obd,
1271 struct obd_device *watched,
1272 enum obd_notify_event ev)
1278 if (!obd->obd_set_up) {
1279 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1283 if (!OBP(obd, notify)) {
1284 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1288 OBD_COUNTER_INCREMENT(obd, notify);
1289 rc = OBP(obd, notify)(obd, watched, ev);
1294 static inline int obd_notify_observer(struct obd_device *observer,
1295 struct obd_device *observed,
1296 enum obd_notify_event ev)
1300 struct obd_notify_upcall *onu;
1302 if (observer->obd_observer)
1303 rc = obd_notify(observer->obd_observer, observed, ev);
1306 * Also, call non-obd listener, if any
1308 onu = &observer->obd_upcall;
1309 if (onu->onu_upcall != NULL)
1310 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1312 return rc ? rc : rc2;
1315 static inline int obd_quotactl(struct obd_export *exp,
1316 struct obd_quotactl *oqctl)
1321 rc = exp_check_ops(exp);
1325 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1326 CERROR("%s: no %s operation\n",
1327 (exp)->exp_obd->obd_name, __func__);
1330 EXP_COUNTER_INCREMENT(exp, quotactl);
1332 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1336 static inline int obd_health_check(const struct lu_env *env,
1337 struct obd_device *obd)
1339 /* returns: 0 on healthy
1340 * >0 on unhealthy + reason code/flag
1341 * however the only suppored reason == 1 right now
1342 * We'll need to define some better reasons
1343 * or flags in the future.
1350 /* NULL method is normal here */
1351 if (obd == NULL || !obd->obd_type) {
1352 CERROR("cleaned up obd\n");
1353 RETURN(-EOPNOTSUPP);
1355 if (!obd->obd_set_up || obd->obd_stopping)
1357 if (!OBP(obd, health_check))
1360 rc = OBP(obd, health_check)(env, obd);
1364 static inline int obd_register_observer(struct obd_device *obd,
1365 struct obd_device *observer)
1369 down_write(&obd->obd_observer_link_sem);
1370 if (obd->obd_observer && observer) {
1371 up_write(&obd->obd_observer_link_sem);
1374 obd->obd_observer = observer;
1375 up_write(&obd->obd_observer_link_sem);
1379 /* metadata helpers */
1380 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1386 rc = exp_check_ops(exp);
1389 EXP_MD_COUNTER_INCREMENT(exp, get_root);
1390 rc = MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1395 static inline int md_getattr(struct obd_export *exp,
1396 struct md_op_data *op_data,
1397 struct ptlrpc_request **request)
1402 rc = exp_check_ops(exp);
1405 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1406 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1410 static inline int md_null_inode(struct obd_export *exp,
1411 const struct lu_fid *fid)
1415 rc = exp_check_ops(exp);
1418 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1419 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1423 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1424 struct md_open_data *mod,
1425 struct ptlrpc_request **request)
1429 rc = exp_check_ops(exp);
1432 EXP_MD_COUNTER_INCREMENT(exp, close);
1433 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1437 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1438 const void *data, size_t datalen, umode_t mode,
1439 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1440 __u64 rdev, struct ptlrpc_request **request)
1444 rc = exp_check_ops(exp);
1447 EXP_MD_COUNTER_INCREMENT(exp, create);
1448 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1449 uid, gid, cap_effective, rdev, request);
1453 static inline int md_enqueue(struct obd_export *exp,
1454 struct ldlm_enqueue_info *einfo,
1455 const union ldlm_policy_data *policy,
1456 struct md_op_data *op_data,
1457 struct lustre_handle *lockh,
1458 __u64 extra_lock_flags)
1462 rc = exp_check_ops(exp);
1465 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1466 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1471 static inline int md_getattr_name(struct obd_export *exp,
1472 struct md_op_data *op_data,
1473 struct ptlrpc_request **request)
1477 rc = exp_check_ops(exp);
1480 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1481 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1485 static inline int md_intent_lock(struct obd_export *exp,
1486 struct md_op_data *op_data,
1487 struct lookup_intent *it,
1488 struct ptlrpc_request **reqp,
1489 ldlm_blocking_callback cb_blocking,
1490 __u64 extra_lock_flags)
1494 rc = exp_check_ops(exp);
1497 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1498 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1503 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1504 struct ptlrpc_request **request)
1508 rc = exp_check_ops(exp);
1511 EXP_MD_COUNTER_INCREMENT(exp, link);
1512 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1516 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1517 const char *old, size_t oldlen, const char *new,
1518 size_t newlen, struct ptlrpc_request **request)
1522 rc = exp_check_ops(exp);
1526 EXP_MD_COUNTER_INCREMENT(exp, rename);
1527 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1532 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1533 void *ea, size_t ealen,
1534 struct ptlrpc_request **request)
1538 rc = exp_check_ops(exp);
1542 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1543 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1547 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1548 struct ptlrpc_request **request)
1553 rc = exp_check_ops(exp);
1557 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1558 rc = MDP(exp->exp_obd, fsync)(exp, fid, request);
1563 /* FLR: resync mirrored files. */
1564 static inline int md_file_resync(struct obd_export *exp,
1565 struct md_op_data *data)
1570 rc = exp_check_ops(exp);
1574 EXP_MD_COUNTER_INCREMENT(exp, file_resync);
1575 rc = MDP(exp->exp_obd, file_resync)(exp, data);
1580 static inline int md_read_page(struct obd_export *exp,
1581 struct md_op_data *op_data,
1582 struct md_callback *cb_op,
1584 struct page **ppage)
1588 rc = exp_check_ops(exp);
1592 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1593 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1598 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1599 struct ptlrpc_request **request)
1603 rc = exp_check_ops(exp);
1607 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1608 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1612 static inline int md_get_lustre_md(struct obd_export *exp,
1613 struct ptlrpc_request *req,
1614 struct obd_export *dt_exp,
1615 struct obd_export *md_exp,
1616 struct lustre_md *md)
1620 rc = exp_check_ops(exp);
1624 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1625 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1628 static inline int md_free_lustre_md(struct obd_export *exp,
1629 struct lustre_md *md)
1633 rc = exp_check_ops(exp);
1636 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1637 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1640 static inline int md_merge_attr(struct obd_export *exp,
1641 const struct lmv_stripe_md *lsm,
1642 struct cl_attr *attr,
1643 ldlm_blocking_callback cb)
1647 rc = exp_check_ops(exp);
1650 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1651 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1654 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1655 u64 obd_md_valid, const char *name,
1656 const void *value, size_t value_size,
1657 unsigned int xattr_flags, u32 suppgid,
1658 struct ptlrpc_request **req)
1663 rc = exp_check_ops(exp);
1666 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1667 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, obd_md_valid, name,
1668 value, value_size, xattr_flags,
1672 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1673 u64 obd_md_valid, const char *name,
1674 size_t buf_size, struct ptlrpc_request **req)
1678 rc = exp_check_ops(exp);
1681 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1682 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, obd_md_valid, name,
1686 static inline int md_set_open_replay_data(struct obd_export *exp,
1687 struct obd_client_handle *och,
1688 struct lookup_intent *it)
1692 rc = exp_check_ops(exp);
1695 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1696 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1699 static inline int md_clear_open_replay_data(struct obd_export *exp,
1700 struct obd_client_handle *och)
1704 rc = exp_check_ops(exp);
1707 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1708 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1711 static inline int md_set_lock_data(struct obd_export *exp,
1712 const struct lustre_handle *lockh,
1713 void *data, __u64 *bits)
1717 rc = exp_check_ops(exp);
1720 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1721 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1725 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1726 union ldlm_policy_data *policy, enum ldlm_mode mode,
1727 enum ldlm_cancel_flags cancel_flags, void *opaque)
1732 rc = exp_check_ops(exp);
1735 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1737 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1738 cancel_flags, opaque);
1742 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1743 const struct lu_fid *fid,
1744 enum ldlm_type type,
1745 union ldlm_policy_data *policy,
1746 enum ldlm_mode mode,
1747 struct lustre_handle *lockh)
1751 rc = exp_check_ops(exp);
1754 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1755 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1756 policy, mode, lockh));
1759 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1764 rc = exp_check_ops(exp);
1767 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1768 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
1771 static inline int md_intent_getattr_async(struct obd_export *exp,
1772 struct md_enqueue_info *minfo)
1776 rc = exp_check_ops(exp);
1779 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1780 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1784 static inline int md_revalidate_lock(struct obd_export *exp,
1785 struct lookup_intent *it,
1786 struct lu_fid *fid, __u64 *bits)
1790 rc = exp_check_ops(exp);
1793 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1794 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1798 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1799 const struct lmv_stripe_md *lsm,
1800 const char *name, int namelen,
1805 rc = exp_check_ops(exp);
1808 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1809 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1814 /* Unpack an MD struct from disk to in-memory format.
1815 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1817 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1818 * If *plsm == NULL then it will be allocated.
1820 static inline int md_unpackmd(struct obd_export *exp,
1821 struct lmv_stripe_md **plsm,
1822 const union lmv_mds_md *lmm, size_t lmm_size)
1826 rc = exp_check_ops(exp);
1829 EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
1830 rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1834 /* OBD Metadata Support */
1836 extern int obd_init_caches(void);
1837 extern void obd_cleanup_caches(void);
1839 /* support routines */
1840 extern struct kmem_cache *obdo_cachep;
1842 #define OBDO_ALLOC(ptr) \
1844 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1847 #define OBDO_FREE(ptr) \
1849 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1853 typedef int (*register_lwp_cb)(void *data);
1855 struct lwp_register_item {
1856 struct obd_export **lri_exp;
1857 register_lwp_cb lri_cb_func;
1859 struct list_head lri_list;
1861 char lri_name[MTI_NAME_MAXLEN];
1864 /* I'm as embarrassed about this as you are.
1866 * <shaver> // XXX do not look into _superhack with remaining eye
1867 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1868 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1871 #ifdef HAVE_SERVER_SUPPORT
1872 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1873 register_lwp_cb cb_func, void *cb_data);
1874 void lustre_deregister_lwp_item(struct obd_export **exp);
1875 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1876 void lustre_notify_lwp_list(struct obd_export *exp);
1877 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1878 #endif /* HAVE_SERVER_SUPPORT */
1879 int lustre_register_fs(void);
1880 int lustre_unregister_fs(void);
1881 int lustre_check_exclusion(struct super_block *sb, char *svname);
1883 typedef __u8 class_uuid_t[16];
1884 static inline void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out)
1886 snprintf(out->uuid, sizeof(out->uuid), "%02x%02x%02x%02x-%02x%02x-"
1887 "%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1888 uu[14], uu[15], uu[12], uu[13], uu[10], uu[11], uu[8], uu[9],
1889 uu[6], uu[7], uu[4], uu[5], uu[2], uu[3], uu[0], uu[1]);
1893 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1894 int class_add_uuid(const char *uuid, __u64 nid);
1895 int class_del_uuid (const char *uuid);
1896 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1899 extern char obd_jobid_name[];
1902 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1906 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1907 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1909 /* root squash info */
1910 struct rw_semaphore;
1911 struct root_squash_info {
1914 struct list_head rsi_nosquash_nids;
1915 struct rw_semaphore rsi_sem;
1918 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1920 /* linux-module.c */
1921 extern struct miscdevice obd_psdev;
1922 int obd_ioctl_getdata(char **buf, int *len, void __user *arg);
1923 int class_procfs_init(void);
1924 int class_procfs_clean(void);
1926 #endif /* __LINUX_OBD_CLASS_H */