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.
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,
73 int class_register_device(struct obd_device *obd);
74 void class_unregister_device(struct obd_device *obd);
75 void class_free_dev(struct obd_device *obd);
77 struct obd_device *class_dev_by_str(const char *str);
78 int class_name2dev(const char *name);
79 struct obd_device *class_name2obd(const char *name);
80 int class_uuid2dev(struct obd_uuid *uuid);
81 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
82 void class_obd_list(void);
83 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
84 const char * typ_name,
85 struct obd_uuid *grp_uuid);
86 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
88 struct obd_device * class_num2obd(int num);
89 int get_devices_count(void);
91 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
93 char *obd_export_nid2str(struct obd_export *exp);
95 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
96 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
97 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
100 int obd_zombie_impexp_init(void);
101 void obd_zombie_impexp_stop(void);
102 void obd_zombie_impexp_cull(void);
103 void obd_zombie_barrier(void);
104 void obd_exports_barrier(struct obd_device *obd);
105 int kuc_len(int payload_len);
106 struct kuc_hdr * kuc_ptr(void *p);
107 void *kuc_alloc(int payload_len, int transport, int type);
108 void kuc_free(void *p, int payload_len);
109 int obd_get_request_slot(struct client_obd *cli);
110 void obd_put_request_slot(struct client_obd *cli);
111 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
112 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
113 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
114 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
115 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
117 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc,
118 struct lookup_intent *it);
119 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc,
120 struct lookup_intent *it, __u16 tag);
124 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
125 struct llog_rec_hdr *, void *);
127 struct obd_export *obd_stale_export_get(void);
128 void obd_stale_export_put(struct obd_export *exp);
129 void obd_stale_export_adjust(struct obd_export *exp);
132 /* For interoperability */
133 struct cfg_interop_param {
138 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
139 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
140 const char *new_name);
141 void print_lustre_cfg(struct lustre_cfg *lcfg);
142 int class_process_config(struct lustre_cfg *lcfg);
143 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
144 struct lustre_cfg *lcfg, void *data);
145 int class_attach(struct lustre_cfg *lcfg);
146 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
147 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
148 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
150 int class_find_param(char *buf, char *key, char **valp);
151 struct cfg_interop_param *class_find_old_param(const char *param,
152 struct cfg_interop_param *ptr);
153 int class_get_next_param(char **params, char *copy);
154 int class_match_param(char *buf, const char *key, char **valp);
155 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
156 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
157 int class_parse_net(char *buf, u32 *net, char **endh);
158 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
159 int class_match_net(char *buf, char *key, u32 net);
161 struct obd_device *class_incref(struct obd_device *obd,
162 const char *scope, const void *source);
163 void class_decref(struct obd_device *obd,
164 const char *scope, const void *source);
165 void dump_exports(struct obd_device *obd, int locks, int debug_level);
166 int class_config_llog_handler(const struct lu_env *env,
167 struct llog_handle *handle,
168 struct llog_rec_hdr *rec, void *data);
169 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
171 #define CFG_F_START 0x01 /* Set when we start updating from a log */
172 #define CFG_F_MARKER 0x02 /* We are within a maker */
173 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
174 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
175 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
177 /* Passed as data param to class_config_parse_llog */
178 struct config_llog_instance {
181 struct super_block *cfg_sb;
182 struct obd_uuid cfg_uuid;
183 llog_cb_t cfg_callback;
184 int cfg_last_idx; /* for partial llog processing */
189 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
190 char *name, struct config_llog_instance *cfg);
192 #define CONFIG_SUB_SPTLRPC 0x01
193 #define CONFIG_SUB_RECOVER 0x02
194 #define CONFIG_SUB_PARAMS 0x04
195 #define CONFIG_SUB_NODEMAP 0x08
196 #define CONFIG_SUB_BARRIER 0x10
198 /* Sub clds should be attached to the config_llog_data when processing
199 * config log for client or server target. */
200 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
202 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
205 #define PARAMS_FILENAME "params"
206 #define BARRIER_FILENAME "barrier"
207 #define LCTL_UPCALL "lctl"
209 static inline bool logname_is_barrier(const char *logname)
213 /* logname for barrier is "fsname-barrier" */
214 ptr = strstr(logname, BARRIER_FILENAME);
215 if (ptr && (ptr - logname) >= 2 &&
216 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
222 /* list of active configuration logs */
223 struct config_llog_data {
224 struct ldlm_res_id cld_resid;
225 struct config_llog_instance cld_cfg;
226 struct list_head cld_list_chain;/* on config_llog_list */
227 atomic_t cld_refcount;
228 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
229 struct config_llog_data *cld_params; /* common parameters log */
230 struct config_llog_data *cld_recover;/* imperative recover log */
231 struct config_llog_data *cld_nodemap;/* nodemap log */
232 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
233 struct obd_export *cld_mgcexp;
234 struct mutex cld_lock;
236 unsigned int cld_stopping:1, /* we were told to stop
238 cld_lostlock:1; /* lock not requeued */
242 struct lustre_profile {
243 struct list_head lp_list;
248 bool lp_list_deleted;
251 struct lustre_profile *class_get_profile(const char * prof);
252 void class_del_profile(const char *prof);
253 void class_put_profile(struct lustre_profile *lprof);
254 void class_del_profiles(void);
257 #if LUSTRE_TRACKS_LOCK_EXP_REFS
259 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
260 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
261 extern void (*class_export_dump_hook)(struct obd_export *);
265 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
266 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
270 #define class_export_rpc_inc(exp) \
272 atomic_inc(&(exp)->exp_rpc_count); \
273 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
274 (exp), atomic_read(&(exp)->exp_rpc_count)); \
277 #define class_export_rpc_dec(exp) \
279 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
280 atomic_dec(&(exp)->exp_rpc_count); \
281 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
282 (exp), atomic_read(&(exp)->exp_rpc_count)); \
285 #define class_export_lock_get(exp, lock) \
287 atomic_inc(&(exp)->exp_locks_count); \
288 __class_export_add_lock_ref(exp, lock); \
289 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
290 (exp), atomic_read(&(exp)->exp_locks_count)); \
291 class_export_get(exp); \
294 #define class_export_lock_put(exp, lock) \
296 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
297 atomic_dec(&(exp)->exp_locks_count); \
298 __class_export_del_lock_ref(exp, lock); \
299 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
300 (exp), atomic_read(&(exp)->exp_locks_count)); \
301 class_export_put(exp); \
304 #define class_export_cb_get(exp) \
306 atomic_inc(&(exp)->exp_cb_count); \
307 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
308 (exp), atomic_read(&(exp)->exp_cb_count)); \
309 class_export_get(exp); \
312 #define class_export_cb_put(exp) \
314 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
315 atomic_dec(&(exp)->exp_cb_count); \
316 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
317 (exp), atomic_read(&(exp)->exp_cb_count)); \
318 class_export_put(exp); \
322 struct obd_export *class_export_get(struct obd_export *exp);
323 void class_export_put(struct obd_export *exp);
324 struct obd_export *class_new_export(struct obd_device *obddev,
325 struct obd_uuid *cluuid);
326 struct obd_export *class_new_export_self(struct obd_device *obd,
327 struct obd_uuid *uuid);
328 void class_unlink_export(struct obd_export *exp);
330 struct obd_import *class_import_get(struct obd_import *);
331 void class_import_put(struct obd_import *);
332 struct obd_import *class_new_import(struct obd_device *obd);
333 void class_destroy_import(struct obd_import *exp);
335 struct obd_type *class_search_type(const char *name);
336 struct obd_type *class_get_type(const char *name);
337 void class_put_type(struct obd_type *type);
338 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
339 struct obd_uuid *cluuid);
340 int class_disconnect(struct obd_export *exp);
341 void class_fail_export(struct obd_export *exp);
342 int class_connected_export(struct obd_export *exp);
343 void class_disconnect_exports(struct obd_device *obddev);
344 int class_manual_cleanup(struct obd_device *obd);
345 void class_disconnect_stale_exports(struct obd_device *,
346 int (*test_export)(struct obd_export *));
347 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
349 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
350 (obd->obd_force ? OBD_OPT_FORCE : 0) |
351 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
355 #ifdef HAVE_SERVER_SUPPORT
356 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
358 LASSERT(exp->exp_obd);
359 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
361 return exp->exp_obd->u.obt.obt_lut;
364 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
366 LASSERT(obd->u.obt.obt_lut);
367 return &obd->u.obt.obt_lut->lut_lsd;
375 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
376 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
378 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
379 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
381 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
382 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
384 /* Ensure obd_setup: used for cleanup which must be called
385 while obd is stopping */
386 #define OBD_CHECK_DEV(obd) \
389 CERROR("NULL device\n"); \
394 /* ensure obd_setup and !obd_stopping */
395 #define OBD_CHECK_DEV_ACTIVE(obd) \
397 OBD_CHECK_DEV(obd); \
398 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
399 CERROR("Device %d not setup\n", \
406 #ifdef CONFIG_PROC_FS
407 #define OBD_COUNTER_OFFSET(op) \
408 ((offsetof(struct obd_ops, o_ ## op) - \
409 offsetof(struct obd_ops, o_iocontrol)) \
410 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
412 /* The '- 1' below is for o_owner. */
413 #define NUM_OBD_STATS \
414 (sizeof(struct obd_ops) / \
415 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
417 #define OBD_COUNTER_INCREMENT(obd, op) \
418 lprocfs_counter_incr((obd)->obd_stats, \
419 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
421 #define EXP_COUNTER_INCREMENT(exp, op) \
424 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
425 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
426 if ((exp)->exp_obd->obd_uses_nid_stats && \
427 (exp)->exp_nid_stats != NULL) \
428 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
432 #define _MD_COUNTER_OFFSET(m_op) \
433 ((offsetof(struct md_ops, m_op) - \
434 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
435 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
437 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
439 #define NUM_MD_STATS \
440 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
441 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
443 /* Note that we only increment md counters for ops whose offset is less
444 * than NUM_MD_STATS. This is explained in a comment in the definition
445 * of struct md_ops. */
446 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
448 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
449 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
450 (exp)->exp_obd->obd_md_cntr_base + \
451 MD_COUNTER_OFFSET(op)); \
455 #define OBD_COUNTER_OFFSET(op)
456 #define OBD_COUNTER_INCREMENT(obd, op)
457 #define EXP_COUNTER_INCREMENT(exp, op)
458 #define EXP_MD_COUNTER_INCREMENT(exp, op)
461 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
463 /* Always add in ldlm_stats */
464 tmp->nid_ldlm_stats =
465 lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC,
466 LPROCFS_STATS_FLAG_NOPERCPU);
467 if (tmp->nid_ldlm_stats == NULL)
470 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
472 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
473 tmp->nid_ldlm_stats);
476 static inline int exp_check_ops(struct obd_export *exp)
481 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
487 static inline int class_devno_max(void)
489 return MAX_OBD_DEVICES;
492 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
493 __u32 keylen, void *key,
494 __u32 *vallen, void *val)
499 rc = exp_check_ops(exp);
503 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
504 CERROR("%s: no %s operation\n",
505 (exp)->exp_obd->obd_name, __func__);
508 EXP_COUNTER_INCREMENT(exp, get_info);
510 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,
516 __u32 keylen, void *key,
517 __u32 vallen, void *val,
518 struct ptlrpc_request_set *set)
523 rc = exp_check_ops(exp);
527 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
528 CERROR("%s: no %s operation\n",
529 (exp)->exp_obd->obd_name, __func__);
532 EXP_COUNTER_INCREMENT(exp, set_info_async);
534 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
540 * obd-lu integration.
542 * Functionality is being moved into new lu_device-based layering, but some
543 * pieces of configuration process are still based on obd devices.
545 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
546 * subsume ->o_setup() methods of obd devices they replace. The same for
547 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
548 * result, obd_setup() and obd_process_config() branch and call one XOR
551 * Yet neither lu_device_type_operations::ldto_device_fini() nor
552 * lu_device_type_operations::ldto_device_free() fully implement the
553 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
554 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
556 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
559 struct lu_device_type *ldt = obd->obd_type->typ_lu;
565 struct lu_context session_ctx;
567 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
568 session_ctx.lc_thread = NULL;
569 lu_context_enter(&session_ctx);
571 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
573 env.le_ses = &session_ctx;
574 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
583 lu_context_exit(&session_ctx);
584 lu_context_fini(&session_ctx);
587 if (!obd->obd_type->typ_dt_ops->o_setup) {
588 CERROR("%s: no %s operation\n", obd->obd_name,
592 OBD_COUNTER_INCREMENT(obd, setup);
593 rc = OBP(obd, setup)(obd, cfg);
598 static inline int obd_precleanup(struct obd_device *obd)
601 struct lu_device_type *ldt = obd->obd_type->typ_lu;
602 struct lu_device *d = obd->obd_lu_dev;
606 if (ldt != NULL && d != NULL) {
609 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
611 ldt->ldt_ops->ldto_device_fini(&env, d);
616 if (!obd->obd_type->typ_dt_ops->o_precleanup)
619 OBD_COUNTER_INCREMENT(obd, precleanup);
621 rc = OBP(obd, precleanup)(obd);
625 static inline int obd_cleanup(struct obd_device *obd)
628 struct lu_device_type *ldt = obd->obd_type->typ_lu;
629 struct lu_device *d = obd->obd_lu_dev;
632 if (ldt != NULL && d != NULL) {
635 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
637 ldt->ldt_ops->ldto_device_free(&env, d);
639 obd->obd_lu_dev = NULL;
642 if (!obd->obd_type->typ_dt_ops->o_cleanup)
645 OBD_COUNTER_INCREMENT(obd, cleanup);
647 rc = OBP(obd, cleanup)(obd);
651 static inline void obd_cleanup_client_import(struct obd_device *obd)
655 /* If we set up but never connected, the
656 client import will not have been cleaned. */
657 down_write(&obd->u.cli.cl_sem);
658 if (obd->u.cli.cl_import) {
659 struct obd_import *imp;
660 imp = obd->u.cli.cl_import;
661 CDEBUG(D_CONFIG, "%s: client import never connected\n",
663 ptlrpc_invalidate_import(imp);
664 client_destroy_import(imp);
665 obd->u.cli.cl_import = NULL;
667 up_write(&obd->u.cli.cl_sem);
672 static inline int obd_process_config(struct obd_device *obd, int datalen,
676 struct lu_device_type *ldt = obd->obd_type->typ_lu;
677 struct lu_device *d = obd->obd_lu_dev;
681 obd->obd_process_conf = 1;
682 if (ldt != NULL && d != NULL) {
685 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
687 rc = d->ld_ops->ldo_process_config(&env, d, data);
691 if (!obd->obd_type->typ_dt_ops->o_process_config) {
692 CERROR("%s: no %s operation\n",
693 obd->obd_name, __func__);
696 rc = OBP(obd, process_config)(obd, datalen, data);
698 OBD_COUNTER_INCREMENT(obd, process_config);
699 obd->obd_process_conf = 0;
704 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
710 rc = exp_check_ops(exp);
714 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
715 CERROR("%s: no %s operation\n",
716 (exp)->exp_obd->obd_name, __func__);
719 EXP_COUNTER_INCREMENT(exp, create);
721 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
725 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
731 rc = exp_check_ops(exp);
735 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
736 CERROR("%s: no %s operation\n",
737 (exp)->exp_obd->obd_name, __func__);
740 EXP_COUNTER_INCREMENT(exp, destroy);
742 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
746 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
752 rc = exp_check_ops(exp);
756 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
757 CERROR("%s: no %s operation\n",
758 (exp)->exp_obd->obd_name, __func__);
761 EXP_COUNTER_INCREMENT(exp, getattr);
762 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
767 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
773 rc = exp_check_ops(exp);
777 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
778 CERROR("%s: no %s operation\n",
779 (exp)->exp_obd->obd_name, __func__);
782 EXP_COUNTER_INCREMENT(exp, setattr);
783 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
788 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
791 struct obd_device *obd = imp->imp_obd;
795 OBD_CHECK_DEV_ACTIVE(obd);
796 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
797 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
800 OBD_COUNTER_INCREMENT(obd, add_conn);
802 rc = OBP(obd, add_conn)(imp, uuid, priority);
806 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
808 struct obd_device *obd = imp->imp_obd;
812 OBD_CHECK_DEV_ACTIVE(obd);
813 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
814 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
817 OBD_COUNTER_INCREMENT(obd, del_conn);
819 rc = OBP(obd, del_conn)(imp, uuid);
823 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
825 struct obd_uuid *uuid;
828 if (!exp->exp_obd->obd_type ||
829 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
832 EXP_COUNTER_INCREMENT(exp, get_uuid);
834 uuid = OBP(exp->exp_obd, get_uuid)(exp);
838 /** Create a new /a exp on device /a obd for the uuid /a cluuid
839 * @param exp New export handle
840 * @param d Connect data, supported flags are set, flags also understood
841 * by obd are returned.
843 static inline int obd_connect(const struct lu_env *env,
844 struct obd_export **exp,struct obd_device *obd,
845 struct obd_uuid *cluuid,
846 struct obd_connect_data *data,
850 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
854 OBD_CHECK_DEV_ACTIVE(obd);
855 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
856 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
859 OBD_COUNTER_INCREMENT(obd, connect);
861 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
862 /* check that only subset is granted */
863 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
864 data->ocd_connect_flags));
868 static inline int obd_reconnect(const struct lu_env *env,
869 struct obd_export *exp,
870 struct obd_device *obd,
871 struct obd_uuid *cluuid,
872 struct obd_connect_data *d,
876 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
881 OBD_CHECK_DEV_ACTIVE(obd);
882 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
885 OBD_COUNTER_INCREMENT(obd, reconnect);
887 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
888 /* check that only subset is granted */
889 LASSERT(ergo(d != NULL,
890 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
894 static inline int obd_disconnect(struct obd_export *exp)
898 rc = exp_check_ops(exp);
902 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
903 CERROR("%s: no %s operation\n",
904 (exp)->exp_obd->obd_name, __func__);
907 EXP_COUNTER_INCREMENT(exp, disconnect);
909 rc = OBP(exp->exp_obd, disconnect)(exp);
913 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
914 enum lu_cli_type type)
919 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
921 OBD_COUNTER_INCREMENT(obd, fid_init);
923 rc = OBP(obd, fid_init)(obd, exp, type);
927 static inline int obd_fid_fini(struct obd_device *obd)
931 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
933 OBD_COUNTER_INCREMENT(obd, fid_fini);
935 rc = OBP(obd, fid_fini)(obd);
939 static inline int obd_fid_alloc(const struct lu_env *env,
940 struct obd_export *exp,
942 struct md_op_data *op_data)
946 rc = exp_check_ops(exp);
950 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
951 CERROR("%s: no %s operation\n",
952 (exp)->exp_obd->obd_name, __func__);
955 EXP_COUNTER_INCREMENT(exp, fid_alloc);
957 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
961 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
966 if (!exp->exp_obd->obd_type ||
967 !exp->exp_obd->obd_type->typ_dt_ops->o_ping)
970 EXP_COUNTER_INCREMENT(exp, ping);
972 rc = OBP(exp->exp_obd, ping)(env, exp);
976 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
981 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
982 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
985 OBD_COUNTER_INCREMENT(obd, pool_new);
987 rc = OBP(obd, pool_new)(obd, poolname);
991 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
995 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
996 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
999 OBD_COUNTER_INCREMENT(obd, pool_del);
1001 rc = OBP(obd, pool_del)(obd, poolname);
1005 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
1011 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
1012 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1013 RETURN(-EOPNOTSUPP);
1015 OBD_COUNTER_INCREMENT(obd, pool_add);
1017 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1021 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
1027 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
1028 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1029 RETURN(-EOPNOTSUPP);
1031 OBD_COUNTER_INCREMENT(obd, pool_rem);
1033 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1037 static inline void obd_getref(struct obd_device *obd)
1040 if (obd->obd_type && OBP(obd, getref)) {
1041 OBD_COUNTER_INCREMENT(obd, getref);
1042 OBP(obd, getref)(obd);
1047 static inline void obd_putref(struct obd_device *obd)
1050 if (obd->obd_type && OBP(obd, putref)) {
1051 OBD_COUNTER_INCREMENT(obd, putref);
1052 OBP(obd, putref)(obd);
1057 static inline int obd_init_export(struct obd_export *exp)
1062 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1063 OBP((exp)->exp_obd, init_export))
1064 rc = OBP(exp->exp_obd, init_export)(exp);
1068 static inline int obd_destroy_export(struct obd_export *exp)
1071 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1072 OBP(exp->exp_obd, destroy_export))
1073 OBP(exp->exp_obd, destroy_export)(exp);
1077 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1078 * If the cache is older than @max_age we will get a new value from the
1079 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1080 static inline int obd_statfs_async(struct obd_export *exp,
1081 struct obd_info *oinfo,
1083 struct ptlrpc_request_set *rqset)
1086 struct obd_device *obd;
1090 if (exp == NULL || exp->exp_obd == NULL)
1094 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1095 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1096 RETURN(-EOPNOTSUPP);
1098 OBD_COUNTER_INCREMENT(obd, statfs);
1100 CDEBUG(D_SUPER, "%s: osfs %p age %lld, max_age %lld\n",
1101 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1102 if (obd->obd_osfs_age < max_age) {
1103 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1106 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1107 obd->obd_name, &obd->obd_osfs,
1108 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1109 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1110 spin_lock(&obd->obd_osfs_lock);
1111 memcpy(oinfo->oi_osfs, &obd->obd_osfs,
1112 sizeof(*oinfo->oi_osfs));
1113 spin_unlock(&obd->obd_osfs_lock);
1114 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1115 if (oinfo->oi_cb_up)
1116 oinfo->oi_cb_up(oinfo, 0);
1121 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1122 * If the cache is older than @max_age we will get a new value from the
1123 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1124 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1125 struct obd_statfs *osfs, time64_t max_age,
1129 struct obd_device *obd = exp->exp_obd;
1135 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1136 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1137 RETURN(-EOPNOTSUPP);
1139 OBD_COUNTER_INCREMENT(obd, statfs);
1141 CDEBUG(D_SUPER, "osfs %lld, max_age %lld\n",
1142 obd->obd_osfs_age, max_age);
1143 if (obd->obd_osfs_age < max_age) {
1144 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1146 spin_lock(&obd->obd_osfs_lock);
1147 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1148 obd->obd_osfs_age = ktime_get_seconds();
1149 spin_unlock(&obd->obd_osfs_lock);
1152 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu"
1153 " objects %llu/%llu\n",
1154 obd->obd_name, &obd->obd_osfs,
1155 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1156 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1157 spin_lock(&obd->obd_osfs_lock);
1158 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1159 spin_unlock(&obd->obd_osfs_lock);
1164 static inline int obd_preprw(const struct lu_env *env, int cmd,
1165 struct obd_export *exp, struct obdo *oa,
1166 int objcount, struct obd_ioobj *obj,
1167 struct niobuf_remote *remote, int *pages,
1168 struct niobuf_local *local)
1174 rc = exp_check_ops(exp);
1178 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1179 CERROR("%s: no %s operation\n",
1180 (exp)->exp_obd->obd_name, __func__);
1183 EXP_COUNTER_INCREMENT(exp, preprw);
1184 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1190 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1191 struct obd_export *exp, struct obdo *oa,
1192 int objcount, struct obd_ioobj *obj,
1193 struct niobuf_remote *rnb, int pages,
1194 struct niobuf_local *local, int rc)
1198 rc = exp_check_ops(exp);
1202 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1203 CERROR("%s: no %s operation\n",
1204 (exp)->exp_obd->obd_name, __func__);
1207 EXP_COUNTER_INCREMENT(exp, commitrw);
1208 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1209 rnb, pages, local, rc);
1214 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1215 int len, void *karg, void __user *uarg)
1220 rc = exp_check_ops(exp);
1224 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1225 CERROR("%s: no %s operation\n",
1226 (exp)->exp_obd->obd_name, __func__);
1229 EXP_COUNTER_INCREMENT(exp, iocontrol);
1231 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1235 static inline void obd_import_event(struct obd_device *obd,
1236 struct obd_import *imp,
1237 enum obd_import_event event)
1241 CERROR("NULL device\n");
1245 if (obd->obd_set_up && OBP(obd, import_event)) {
1246 OBD_COUNTER_INCREMENT(obd, import_event);
1247 OBP(obd, import_event)(obd, imp, event);
1252 static inline int obd_notify(struct obd_device *obd,
1253 struct obd_device *watched,
1254 enum obd_notify_event ev)
1260 if (!obd->obd_set_up) {
1261 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1265 if (!OBP(obd, notify)) {
1266 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1270 OBD_COUNTER_INCREMENT(obd, notify);
1271 rc = OBP(obd, notify)(obd, watched, ev);
1276 static inline int obd_notify_observer(struct obd_device *observer,
1277 struct obd_device *observed,
1278 enum obd_notify_event ev)
1282 struct obd_notify_upcall *onu;
1284 if (observer->obd_observer)
1285 rc = obd_notify(observer->obd_observer, observed, ev);
1288 * Also, call non-obd listener, if any
1290 onu = &observer->obd_upcall;
1291 if (onu->onu_upcall != NULL)
1292 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1294 return rc ? rc : rc2;
1297 static inline int obd_quotactl(struct obd_export *exp,
1298 struct obd_quotactl *oqctl)
1303 rc = exp_check_ops(exp);
1307 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1308 CERROR("%s: no %s operation\n",
1309 (exp)->exp_obd->obd_name, __func__);
1312 EXP_COUNTER_INCREMENT(exp, quotactl);
1314 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1318 static inline int obd_health_check(const struct lu_env *env,
1319 struct obd_device *obd)
1321 /* returns: 0 on healthy
1322 * >0 on unhealthy + reason code/flag
1323 * however the only suppored reason == 1 right now
1324 * We'll need to define some better reasons
1325 * or flags in the future.
1332 /* NULL method is normal here */
1333 if (obd == NULL || !obd->obd_type) {
1334 CERROR("cleaned up obd\n");
1335 RETURN(-EOPNOTSUPP);
1337 if (!obd->obd_set_up || obd->obd_stopping)
1339 if (!OBP(obd, health_check))
1342 rc = OBP(obd, health_check)(env, obd);
1346 static inline int obd_register_observer(struct obd_device *obd,
1347 struct obd_device *observer)
1351 down_write(&obd->obd_observer_link_sem);
1352 if (obd->obd_observer && observer) {
1353 up_write(&obd->obd_observer_link_sem);
1356 obd->obd_observer = observer;
1357 up_write(&obd->obd_observer_link_sem);
1361 /* metadata helpers */
1362 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1368 rc = exp_check_ops(exp);
1371 EXP_MD_COUNTER_INCREMENT(exp, get_root);
1372 rc = MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1377 static inline int md_getattr(struct obd_export *exp,
1378 struct md_op_data *op_data,
1379 struct ptlrpc_request **request)
1384 rc = exp_check_ops(exp);
1387 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1388 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1392 static inline int md_null_inode(struct obd_export *exp,
1393 const struct lu_fid *fid)
1397 rc = exp_check_ops(exp);
1400 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1401 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1405 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1406 struct md_open_data *mod,
1407 struct ptlrpc_request **request)
1411 rc = exp_check_ops(exp);
1414 EXP_MD_COUNTER_INCREMENT(exp, close);
1415 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1419 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1420 const void *data, size_t datalen, umode_t mode,
1421 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1422 __u64 rdev, struct ptlrpc_request **request)
1426 rc = exp_check_ops(exp);
1429 EXP_MD_COUNTER_INCREMENT(exp, create);
1430 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1431 uid, gid, cap_effective, rdev, request);
1435 static inline int md_enqueue(struct obd_export *exp,
1436 struct ldlm_enqueue_info *einfo,
1437 const union ldlm_policy_data *policy,
1438 struct md_op_data *op_data,
1439 struct lustre_handle *lockh,
1440 __u64 extra_lock_flags)
1444 rc = exp_check_ops(exp);
1447 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1448 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1453 static inline int md_getattr_name(struct obd_export *exp,
1454 struct md_op_data *op_data,
1455 struct ptlrpc_request **request)
1459 rc = exp_check_ops(exp);
1462 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1463 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1467 static inline int md_intent_lock(struct obd_export *exp,
1468 struct md_op_data *op_data,
1469 struct lookup_intent *it,
1470 struct ptlrpc_request **reqp,
1471 ldlm_blocking_callback cb_blocking,
1472 __u64 extra_lock_flags)
1476 rc = exp_check_ops(exp);
1479 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1480 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1485 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1486 struct ptlrpc_request **request)
1490 rc = exp_check_ops(exp);
1493 EXP_MD_COUNTER_INCREMENT(exp, link);
1494 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1498 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1499 const char *old, size_t oldlen, const char *new,
1500 size_t newlen, struct ptlrpc_request **request)
1504 rc = exp_check_ops(exp);
1508 EXP_MD_COUNTER_INCREMENT(exp, rename);
1509 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1514 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1515 void *ea, size_t ealen,
1516 struct ptlrpc_request **request)
1520 rc = exp_check_ops(exp);
1524 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1525 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1529 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1530 struct ptlrpc_request **request)
1535 rc = exp_check_ops(exp);
1539 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1540 rc = MDP(exp->exp_obd, fsync)(exp, fid, request);
1545 /* FLR: resync mirrored files. */
1546 static inline int md_file_resync(struct obd_export *exp,
1547 struct md_op_data *data)
1552 rc = exp_check_ops(exp);
1556 EXP_MD_COUNTER_INCREMENT(exp, file_resync);
1557 rc = MDP(exp->exp_obd, file_resync)(exp, data);
1562 static inline int md_read_page(struct obd_export *exp,
1563 struct md_op_data *op_data,
1564 struct md_callback *cb_op,
1566 struct page **ppage)
1570 rc = exp_check_ops(exp);
1574 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1575 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1580 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1581 struct ptlrpc_request **request)
1585 rc = exp_check_ops(exp);
1589 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1590 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1594 static inline int md_get_lustre_md(struct obd_export *exp,
1595 struct ptlrpc_request *req,
1596 struct obd_export *dt_exp,
1597 struct obd_export *md_exp,
1598 struct lustre_md *md)
1602 rc = exp_check_ops(exp);
1606 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1607 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1610 static inline int md_free_lustre_md(struct obd_export *exp,
1611 struct lustre_md *md)
1615 rc = exp_check_ops(exp);
1618 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1619 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1622 static inline int md_merge_attr(struct obd_export *exp,
1623 const struct lmv_stripe_md *lsm,
1624 struct cl_attr *attr,
1625 ldlm_blocking_callback cb)
1629 rc = exp_check_ops(exp);
1632 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1633 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1636 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1637 u64 valid, const char *name,
1638 const char *input, int input_size,
1639 int output_size, int flags, __u32 suppgid,
1640 struct ptlrpc_request **request)
1645 rc = exp_check_ops(exp);
1648 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1649 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1650 input_size, output_size, flags,
1654 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1655 u64 valid, const char *name,
1656 const char *input, int input_size,
1657 int output_size, int flags,
1658 struct ptlrpc_request **request)
1662 rc = exp_check_ops(exp);
1665 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1666 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1667 input_size, output_size, flags,
1671 static inline int md_set_open_replay_data(struct obd_export *exp,
1672 struct obd_client_handle *och,
1673 struct lookup_intent *it)
1677 rc = exp_check_ops(exp);
1680 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1681 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1684 static inline int md_clear_open_replay_data(struct obd_export *exp,
1685 struct obd_client_handle *och)
1689 rc = exp_check_ops(exp);
1692 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1693 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1696 static inline int md_set_lock_data(struct obd_export *exp,
1697 const struct lustre_handle *lockh,
1698 void *data, __u64 *bits)
1702 rc = exp_check_ops(exp);
1705 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1706 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1710 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1711 union ldlm_policy_data *policy, enum ldlm_mode mode,
1712 enum ldlm_cancel_flags cancel_flags, void *opaque)
1717 rc = exp_check_ops(exp);
1720 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1722 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1723 cancel_flags, opaque);
1727 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1728 const struct lu_fid *fid,
1729 enum ldlm_type type,
1730 union ldlm_policy_data *policy,
1731 enum ldlm_mode mode,
1732 struct lustre_handle *lockh)
1736 rc = exp_check_ops(exp);
1739 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1740 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1741 policy, mode, lockh));
1744 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1749 rc = exp_check_ops(exp);
1752 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1753 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
1756 static inline int md_intent_getattr_async(struct obd_export *exp,
1757 struct md_enqueue_info *minfo)
1761 rc = exp_check_ops(exp);
1764 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1765 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1769 static inline int md_revalidate_lock(struct obd_export *exp,
1770 struct lookup_intent *it,
1771 struct lu_fid *fid, __u64 *bits)
1775 rc = exp_check_ops(exp);
1778 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1779 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1783 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1784 const struct lmv_stripe_md *lsm,
1785 const char *name, int namelen,
1790 rc = exp_check_ops(exp);
1793 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1794 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1799 /* Unpack an MD struct from disk to in-memory format.
1800 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1802 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1803 * If *plsm == NULL then it will be allocated.
1805 static inline int md_unpackmd(struct obd_export *exp,
1806 struct lmv_stripe_md **plsm,
1807 const union lmv_mds_md *lmm, size_t lmm_size)
1811 rc = exp_check_ops(exp);
1814 EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
1815 rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1819 /* OBD Metadata Support */
1821 extern int obd_init_caches(void);
1822 extern void obd_cleanup_caches(void);
1824 /* support routines */
1825 extern struct kmem_cache *obdo_cachep;
1827 #define OBDO_ALLOC(ptr) \
1829 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1832 #define OBDO_FREE(ptr) \
1834 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1838 typedef int (*register_lwp_cb)(void *data);
1840 struct lwp_register_item {
1841 struct obd_export **lri_exp;
1842 register_lwp_cb lri_cb_func;
1844 struct list_head lri_list;
1846 char lri_name[MTI_NAME_MAXLEN];
1849 /* I'm as embarrassed about this as you are.
1851 * <shaver> // XXX do not look into _superhack with remaining eye
1852 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1853 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1856 #ifdef HAVE_SERVER_SUPPORT
1857 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1858 register_lwp_cb cb_func, void *cb_data);
1859 void lustre_deregister_lwp_item(struct obd_export **exp);
1860 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1861 void lustre_notify_lwp_list(struct obd_export *exp);
1862 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1863 #endif /* HAVE_SERVER_SUPPORT */
1864 int lustre_register_fs(void);
1865 int lustre_unregister_fs(void);
1866 int lustre_check_exclusion(struct super_block *sb, char *svname);
1869 extern int obd_sysctl_init(void);
1870 extern void obd_sysctl_clean(void);
1872 typedef __u8 class_uuid_t[16];
1873 static inline void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out)
1875 snprintf(out->uuid, sizeof(out->uuid), "%02x%02x%02x%02x-%02x%02x-"
1876 "%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1877 uu[14], uu[15], uu[12], uu[13], uu[10], uu[11], uu[8], uu[9],
1878 uu[6], uu[7], uu[4], uu[5], uu[2], uu[3], uu[0], uu[1]);
1882 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1883 int class_add_uuid(const char *uuid, __u64 nid);
1884 int class_del_uuid (const char *uuid);
1885 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1888 extern char obd_jobid_node[];
1891 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1895 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1896 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1898 /* root squash info */
1899 struct rw_semaphore;
1900 struct root_squash_info {
1903 struct list_head rsi_nosquash_nids;
1904 struct rw_semaphore rsi_sem;
1907 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1909 /* linux-module.c */
1910 extern struct miscdevice obd_psdev;
1911 int obd_ioctl_getdata(char **buf, int *len, void __user *arg);
1912 int class_procfs_init(void);
1913 int class_procfs_clean(void);
1915 #endif /* __LINUX_OBD_CLASS_H */