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 char *obd_export_nid2str(struct obd_export *exp);
96 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
97 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
98 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
101 int obd_zombie_impexp_init(void);
102 void obd_zombie_impexp_stop(void);
103 void obd_zombie_impexp_cull(void);
104 void obd_zombie_barrier(void);
105 void obd_exports_barrier(struct obd_device *obd);
106 int kuc_len(int payload_len);
107 struct kuc_hdr * kuc_ptr(void *p);
108 void *kuc_alloc(int payload_len, int transport, int type);
109 void kuc_free(void *p, int payload_len);
110 int obd_get_request_slot(struct client_obd *cli);
111 void obd_put_request_slot(struct client_obd *cli);
112 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
113 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
114 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
115 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
116 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
118 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc,
119 struct lookup_intent *it);
120 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc,
121 struct lookup_intent *it, __u16 tag);
125 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
126 struct llog_rec_hdr *, void *);
128 struct obd_export *obd_stale_export_get(void);
129 void obd_stale_export_put(struct obd_export *exp);
130 void obd_stale_export_adjust(struct obd_export *exp);
133 /* For interoperability */
134 struct cfg_interop_param {
139 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
140 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
141 const char *new_name);
142 void print_lustre_cfg(struct lustre_cfg *lcfg);
143 int class_process_config(struct lustre_cfg *lcfg);
144 ssize_t class_set_global(const char *param);
145 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
146 struct kobject *kobj);
147 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
148 struct lustre_cfg *lcfg, void *data);
149 int class_attach(struct lustre_cfg *lcfg);
150 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
151 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
152 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
154 int class_find_param(char *buf, char *key, char **valp);
155 struct cfg_interop_param *class_find_old_param(const char *param,
156 struct cfg_interop_param *ptr);
157 int class_get_next_param(char **params, char *copy);
158 int class_match_param(char *buf, const char *key, char **valp);
159 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
160 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
161 int class_parse_net(char *buf, u32 *net, char **endh);
162 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
163 int class_match_net(char *buf, char *key, u32 net);
165 struct obd_device *class_incref(struct obd_device *obd,
166 const char *scope, const void *source);
167 void class_decref(struct obd_device *obd,
168 const char *scope, const void *source);
169 void dump_exports(struct obd_device *obd, int locks, int debug_level);
170 int class_config_llog_handler(const struct lu_env *env,
171 struct llog_handle *handle,
172 struct llog_rec_hdr *rec, void *data);
173 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
175 #define CFG_F_START 0x01 /* Set when we start updating from a log */
176 #define CFG_F_MARKER 0x02 /* We are within a maker */
177 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
178 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
179 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
181 /* Passed as data param to class_config_parse_llog */
182 struct config_llog_instance {
185 struct super_block *cfg_sb;
186 struct obd_uuid cfg_uuid;
187 llog_cb_t cfg_callback;
188 int cfg_last_idx; /* for partial llog processing */
193 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
194 char *name, struct config_llog_instance *cfg);
196 #define CONFIG_SUB_SPTLRPC 0x01
197 #define CONFIG_SUB_RECOVER 0x02
198 #define CONFIG_SUB_PARAMS 0x04
199 #define CONFIG_SUB_NODEMAP 0x08
200 #define CONFIG_SUB_BARRIER 0x10
202 /* Sub clds should be attached to the config_llog_data when processing
203 * config log for client or server target. */
204 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
206 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
209 #define PARAMS_FILENAME "params"
210 #define BARRIER_FILENAME "barrier"
211 #define LCTL_UPCALL "lctl"
213 static inline bool logname_is_barrier(const char *logname)
217 /* logname for barrier is "fsname-barrier" */
218 ptr = strstr(logname, BARRIER_FILENAME);
219 if (ptr && (ptr - logname) >= 2 &&
220 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
226 /* list of active configuration logs */
227 struct config_llog_data {
228 struct ldlm_res_id cld_resid;
229 struct config_llog_instance cld_cfg;
230 struct list_head cld_list_chain;/* on config_llog_list */
231 atomic_t cld_refcount;
232 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
233 struct config_llog_data *cld_params; /* common parameters log */
234 struct config_llog_data *cld_recover;/* imperative recover log */
235 struct config_llog_data *cld_nodemap;/* nodemap log */
236 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
237 struct obd_export *cld_mgcexp;
238 struct mutex cld_lock;
240 unsigned int cld_stopping:1, /* we were told to stop
242 cld_lostlock:1; /* lock not requeued */
246 struct lustre_profile {
247 struct list_head lp_list;
252 bool lp_list_deleted;
255 struct lustre_profile *class_get_profile(const char * prof);
256 void class_del_profile(const char *prof);
257 void class_put_profile(struct lustre_profile *lprof);
258 void class_del_profiles(void);
261 #if LUSTRE_TRACKS_LOCK_EXP_REFS
263 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
264 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
265 extern void (*class_export_dump_hook)(struct obd_export *);
269 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
270 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
274 #define class_export_rpc_inc(exp) \
276 atomic_inc(&(exp)->exp_rpc_count); \
277 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
278 (exp), atomic_read(&(exp)->exp_rpc_count)); \
281 #define class_export_rpc_dec(exp) \
283 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
284 atomic_dec(&(exp)->exp_rpc_count); \
285 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
286 (exp), atomic_read(&(exp)->exp_rpc_count)); \
289 #define class_export_lock_get(exp, lock) \
291 atomic_inc(&(exp)->exp_locks_count); \
292 __class_export_add_lock_ref(exp, lock); \
293 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
294 (exp), atomic_read(&(exp)->exp_locks_count)); \
295 class_export_get(exp); \
298 #define class_export_lock_put(exp, lock) \
300 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
301 atomic_dec(&(exp)->exp_locks_count); \
302 __class_export_del_lock_ref(exp, lock); \
303 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
304 (exp), atomic_read(&(exp)->exp_locks_count)); \
305 class_export_put(exp); \
308 #define class_export_cb_get(exp) \
310 atomic_inc(&(exp)->exp_cb_count); \
311 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
312 (exp), atomic_read(&(exp)->exp_cb_count)); \
313 class_export_get(exp); \
316 #define class_export_cb_put(exp) \
318 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
319 atomic_dec(&(exp)->exp_cb_count); \
320 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
321 (exp), atomic_read(&(exp)->exp_cb_count)); \
322 class_export_put(exp); \
326 struct obd_export *class_export_get(struct obd_export *exp);
327 void class_export_put(struct obd_export *exp);
328 struct obd_export *class_new_export(struct obd_device *obddev,
329 struct obd_uuid *cluuid);
330 struct obd_export *class_new_export_self(struct obd_device *obd,
331 struct obd_uuid *uuid);
332 void class_unlink_export(struct obd_export *exp);
334 struct obd_import *class_import_get(struct obd_import *);
335 void class_import_put(struct obd_import *);
336 struct obd_import *class_new_import(struct obd_device *obd);
337 void class_destroy_import(struct obd_import *exp);
339 struct obd_type *class_search_type(const char *name);
340 struct obd_type *class_get_type(const char *name);
341 void class_put_type(struct obd_type *type);
342 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
343 struct obd_uuid *cluuid);
344 int class_disconnect(struct obd_export *exp);
345 void class_fail_export(struct obd_export *exp);
346 int class_connected_export(struct obd_export *exp);
347 void class_disconnect_exports(struct obd_device *obddev);
348 int class_manual_cleanup(struct obd_device *obd);
349 void class_disconnect_stale_exports(struct obd_device *,
350 int (*test_export)(struct obd_export *));
351 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
353 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
354 (obd->obd_force ? OBD_OPT_FORCE : 0) |
355 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
359 #ifdef HAVE_SERVER_SUPPORT
360 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
362 LASSERT(exp->exp_obd);
363 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
365 return exp->exp_obd->u.obt.obt_lut;
368 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
370 LASSERT(obd->u.obt.obt_lut);
371 return &obd->u.obt.obt_lut->lut_lsd;
379 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
380 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
382 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
383 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
385 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
386 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
388 /* Ensure obd_setup: used for cleanup which must be called
389 while obd is stopping */
390 #define OBD_CHECK_DEV(obd) \
393 CERROR("NULL device\n"); \
398 /* ensure obd_setup and !obd_stopping */
399 #define OBD_CHECK_DEV_ACTIVE(obd) \
401 OBD_CHECK_DEV(obd); \
402 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
403 CERROR("Device %d not setup\n", \
410 #ifdef CONFIG_PROC_FS
411 #define OBD_COUNTER_OFFSET(op) \
412 ((offsetof(struct obd_ops, o_ ## op) - \
413 offsetof(struct obd_ops, o_iocontrol)) \
414 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
416 /* The '- 1' below is for o_owner. */
417 #define NUM_OBD_STATS \
418 (sizeof(struct obd_ops) / \
419 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
421 #define OBD_COUNTER_INCREMENT(obd, op) \
422 lprocfs_counter_incr((obd)->obd_stats, \
423 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
425 #define EXP_COUNTER_INCREMENT(exp, op) \
428 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
429 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
430 if ((exp)->exp_obd->obd_uses_nid_stats && \
431 (exp)->exp_nid_stats != NULL) \
432 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
436 #define _MD_COUNTER_OFFSET(m_op) \
437 ((offsetof(struct md_ops, m_op) - \
438 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
439 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
441 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
443 #define NUM_MD_STATS \
444 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
445 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
447 /* Note that we only increment md counters for ops whose offset is less
448 * than NUM_MD_STATS. This is explained in a comment in the definition
449 * of struct md_ops. */
450 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
452 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
453 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
454 (exp)->exp_obd->obd_md_cntr_base + \
455 MD_COUNTER_OFFSET(op)); \
459 #define OBD_COUNTER_OFFSET(op)
460 #define OBD_COUNTER_INCREMENT(obd, op)
461 #define EXP_COUNTER_INCREMENT(exp, op)
462 #define EXP_MD_COUNTER_INCREMENT(exp, op)
465 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
467 /* Always add in ldlm_stats */
468 tmp->nid_ldlm_stats =
469 lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC,
470 LPROCFS_STATS_FLAG_NOPERCPU);
471 if (tmp->nid_ldlm_stats == NULL)
474 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
476 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
477 tmp->nid_ldlm_stats);
480 static inline int exp_check_ops(struct obd_export *exp)
485 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
491 static inline int class_devno_max(void)
493 return MAX_OBD_DEVICES;
496 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
497 __u32 keylen, void *key,
498 __u32 *vallen, void *val)
503 rc = exp_check_ops(exp);
507 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
508 CERROR("%s: no %s operation\n",
509 (exp)->exp_obd->obd_name, __func__);
512 EXP_COUNTER_INCREMENT(exp, get_info);
514 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
518 static inline int obd_set_info_async(const struct lu_env *env,
519 struct obd_export *exp,
520 __u32 keylen, void *key,
521 __u32 vallen, void *val,
522 struct ptlrpc_request_set *set)
527 rc = exp_check_ops(exp);
531 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
532 CERROR("%s: no %s operation\n",
533 (exp)->exp_obd->obd_name, __func__);
536 EXP_COUNTER_INCREMENT(exp, set_info_async);
538 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
544 * obd-lu integration.
546 * Functionality is being moved into new lu_device-based layering, but some
547 * pieces of configuration process are still based on obd devices.
549 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
550 * subsume ->o_setup() methods of obd devices they replace. The same for
551 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
552 * result, obd_setup() and obd_process_config() branch and call one XOR
555 * Yet neither lu_device_type_operations::ldto_device_fini() nor
556 * lu_device_type_operations::ldto_device_free() fully implement the
557 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
558 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
560 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
563 struct lu_device_type *ldt = obd->obd_type->typ_lu;
569 struct lu_context session_ctx;
571 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
572 session_ctx.lc_thread = NULL;
573 lu_context_enter(&session_ctx);
575 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
577 env.le_ses = &session_ctx;
578 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
587 lu_context_exit(&session_ctx);
588 lu_context_fini(&session_ctx);
591 if (!obd->obd_type->typ_dt_ops->o_setup) {
592 CERROR("%s: no %s operation\n", obd->obd_name,
596 OBD_COUNTER_INCREMENT(obd, setup);
597 rc = OBP(obd, setup)(obd, cfg);
602 static inline int obd_precleanup(struct obd_device *obd)
605 struct lu_device_type *ldt = obd->obd_type->typ_lu;
606 struct lu_device *d = obd->obd_lu_dev;
610 if (ldt != NULL && d != NULL) {
613 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
615 ldt->ldt_ops->ldto_device_fini(&env, d);
620 if (!obd->obd_type->typ_dt_ops->o_precleanup)
623 OBD_COUNTER_INCREMENT(obd, precleanup);
625 rc = OBP(obd, precleanup)(obd);
629 static inline int obd_cleanup(struct obd_device *obd)
632 struct lu_device_type *ldt = obd->obd_type->typ_lu;
633 struct lu_device *d = obd->obd_lu_dev;
636 if (ldt != NULL && d != NULL) {
639 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
641 ldt->ldt_ops->ldto_device_free(&env, d);
643 obd->obd_lu_dev = NULL;
646 if (!obd->obd_type->typ_dt_ops->o_cleanup)
649 OBD_COUNTER_INCREMENT(obd, cleanup);
651 rc = OBP(obd, cleanup)(obd);
655 static inline void obd_cleanup_client_import(struct obd_device *obd)
659 /* If we set up but never connected, the
660 client import will not have been cleaned. */
661 down_write(&obd->u.cli.cl_sem);
662 if (obd->u.cli.cl_import) {
663 struct obd_import *imp;
664 imp = obd->u.cli.cl_import;
665 CDEBUG(D_CONFIG, "%s: client import never connected\n",
667 ptlrpc_invalidate_import(imp);
668 client_destroy_import(imp);
669 obd->u.cli.cl_import = NULL;
671 up_write(&obd->u.cli.cl_sem);
676 static inline int obd_process_config(struct obd_device *obd, int datalen,
680 struct lu_device_type *ldt = obd->obd_type->typ_lu;
681 struct lu_device *d = obd->obd_lu_dev;
685 obd->obd_process_conf = 1;
686 if (ldt != NULL && d != NULL) {
689 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
691 rc = d->ld_ops->ldo_process_config(&env, d, data);
695 if (!obd->obd_type->typ_dt_ops->o_process_config) {
696 CERROR("%s: no %s operation\n",
697 obd->obd_name, __func__);
700 rc = OBP(obd, process_config)(obd, datalen, data);
702 OBD_COUNTER_INCREMENT(obd, process_config);
703 obd->obd_process_conf = 0;
708 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
714 rc = exp_check_ops(exp);
718 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
719 CERROR("%s: no %s operation\n",
720 (exp)->exp_obd->obd_name, __func__);
723 EXP_COUNTER_INCREMENT(exp, create);
725 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
729 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
735 rc = exp_check_ops(exp);
739 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
740 CERROR("%s: no %s operation\n",
741 (exp)->exp_obd->obd_name, __func__);
744 EXP_COUNTER_INCREMENT(exp, destroy);
746 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
750 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
756 rc = exp_check_ops(exp);
760 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
761 CERROR("%s: no %s operation\n",
762 (exp)->exp_obd->obd_name, __func__);
765 EXP_COUNTER_INCREMENT(exp, getattr);
766 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
771 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
777 rc = exp_check_ops(exp);
781 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
782 CERROR("%s: no %s operation\n",
783 (exp)->exp_obd->obd_name, __func__);
786 EXP_COUNTER_INCREMENT(exp, setattr);
787 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
792 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
795 struct obd_device *obd = imp->imp_obd;
799 OBD_CHECK_DEV_ACTIVE(obd);
800 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
801 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
804 OBD_COUNTER_INCREMENT(obd, add_conn);
806 rc = OBP(obd, add_conn)(imp, uuid, priority);
810 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
812 struct obd_device *obd = imp->imp_obd;
816 OBD_CHECK_DEV_ACTIVE(obd);
817 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
818 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
821 OBD_COUNTER_INCREMENT(obd, del_conn);
823 rc = OBP(obd, del_conn)(imp, uuid);
827 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
829 struct obd_uuid *uuid;
832 if (!exp->exp_obd->obd_type ||
833 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
836 EXP_COUNTER_INCREMENT(exp, get_uuid);
838 uuid = OBP(exp->exp_obd, get_uuid)(exp);
842 /** Create a new /a exp on device /a obd for the uuid /a cluuid
843 * @param exp New export handle
844 * @param d Connect data, supported flags are set, flags also understood
845 * by obd are returned.
847 static inline int obd_connect(const struct lu_env *env,
848 struct obd_export **exp,struct obd_device *obd,
849 struct obd_uuid *cluuid,
850 struct obd_connect_data *data,
854 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
858 OBD_CHECK_DEV_ACTIVE(obd);
859 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
860 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
863 OBD_COUNTER_INCREMENT(obd, connect);
865 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
866 /* check that only subset is granted */
867 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
868 data->ocd_connect_flags));
872 static inline int obd_reconnect(const struct lu_env *env,
873 struct obd_export *exp,
874 struct obd_device *obd,
875 struct obd_uuid *cluuid,
876 struct obd_connect_data *d,
880 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
885 OBD_CHECK_DEV_ACTIVE(obd);
886 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
889 OBD_COUNTER_INCREMENT(obd, reconnect);
891 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
892 /* check that only subset is granted */
893 LASSERT(ergo(d != NULL,
894 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
898 static inline int obd_disconnect(struct obd_export *exp)
902 rc = exp_check_ops(exp);
906 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
907 CERROR("%s: no %s operation\n",
908 (exp)->exp_obd->obd_name, __func__);
911 EXP_COUNTER_INCREMENT(exp, disconnect);
913 rc = OBP(exp->exp_obd, disconnect)(exp);
917 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
918 enum lu_cli_type type)
923 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
925 OBD_COUNTER_INCREMENT(obd, fid_init);
927 rc = OBP(obd, fid_init)(obd, exp, type);
931 static inline int obd_fid_fini(struct obd_device *obd)
935 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
937 OBD_COUNTER_INCREMENT(obd, fid_fini);
939 rc = OBP(obd, fid_fini)(obd);
943 static inline int obd_fid_alloc(const struct lu_env *env,
944 struct obd_export *exp,
946 struct md_op_data *op_data)
950 rc = exp_check_ops(exp);
954 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
955 CERROR("%s: no %s operation\n",
956 (exp)->exp_obd->obd_name, __func__);
959 EXP_COUNTER_INCREMENT(exp, fid_alloc);
961 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
965 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
970 if (!exp->exp_obd->obd_type ||
971 !exp->exp_obd->obd_type->typ_dt_ops->o_ping)
974 EXP_COUNTER_INCREMENT(exp, ping);
976 rc = OBP(exp->exp_obd, ping)(env, exp);
980 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
985 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
986 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
989 OBD_COUNTER_INCREMENT(obd, pool_new);
991 rc = OBP(obd, pool_new)(obd, poolname);
995 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
999 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
1000 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1001 RETURN(-EOPNOTSUPP);
1003 OBD_COUNTER_INCREMENT(obd, pool_del);
1005 rc = OBP(obd, pool_del)(obd, poolname);
1009 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
1015 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
1016 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1017 RETURN(-EOPNOTSUPP);
1019 OBD_COUNTER_INCREMENT(obd, pool_add);
1021 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1025 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
1031 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
1032 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1033 RETURN(-EOPNOTSUPP);
1035 OBD_COUNTER_INCREMENT(obd, pool_rem);
1037 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1041 static inline void obd_getref(struct obd_device *obd)
1044 if (obd->obd_type && OBP(obd, getref)) {
1045 OBD_COUNTER_INCREMENT(obd, getref);
1046 OBP(obd, getref)(obd);
1051 static inline void obd_putref(struct obd_device *obd)
1054 if (obd->obd_type && OBP(obd, putref)) {
1055 OBD_COUNTER_INCREMENT(obd, putref);
1056 OBP(obd, putref)(obd);
1061 static inline int obd_init_export(struct obd_export *exp)
1066 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1067 OBP((exp)->exp_obd, init_export))
1068 rc = OBP(exp->exp_obd, init_export)(exp);
1072 static inline int obd_destroy_export(struct obd_export *exp)
1075 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1076 OBP(exp->exp_obd, destroy_export))
1077 OBP(exp->exp_obd, destroy_export)(exp);
1081 /* @max_age is the oldest time in seconds that we accept using a cached data.
1082 * If the cache is older than @max_age we will get a new value from the
1083 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1085 static inline int obd_statfs_async(struct obd_export *exp,
1086 struct obd_info *oinfo,
1088 struct ptlrpc_request_set *rqset)
1091 struct obd_device *obd;
1095 if (exp == NULL || exp->exp_obd == NULL)
1099 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1100 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1101 RETURN(-EOPNOTSUPP);
1103 OBD_COUNTER_INCREMENT(obd, statfs);
1105 CDEBUG(D_SUPER, "%s: osfs %p age %lld, max_age %lld\n",
1106 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1107 if (obd->obd_osfs_age < max_age) {
1108 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1111 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1112 obd->obd_name, &obd->obd_osfs,
1113 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1114 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1115 spin_lock(&obd->obd_osfs_lock);
1116 memcpy(oinfo->oi_osfs, &obd->obd_osfs,
1117 sizeof(*oinfo->oi_osfs));
1118 spin_unlock(&obd->obd_osfs_lock);
1119 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1120 if (oinfo->oi_cb_up)
1121 oinfo->oi_cb_up(oinfo, 0);
1126 /* @max_age is the oldest time in seconds that we accept using a cached data.
1127 * If the cache is older than @max_age we will get a new value from the
1128 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1130 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1131 struct obd_statfs *osfs, time64_t max_age,
1135 struct obd_device *obd = exp->exp_obd;
1141 OBD_CHECK_DEV_ACTIVE(obd);
1143 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1144 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1145 RETURN(-EOPNOTSUPP);
1147 OBD_COUNTER_INCREMENT(obd, statfs);
1149 CDEBUG(D_SUPER, "osfs %lld, max_age %lld\n",
1150 obd->obd_osfs_age, max_age);
1151 if (obd->obd_osfs_age < max_age) {
1152 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1154 spin_lock(&obd->obd_osfs_lock);
1155 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1156 obd->obd_osfs_age = ktime_get_seconds();
1157 spin_unlock(&obd->obd_osfs_lock);
1160 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu"
1161 " objects %llu/%llu\n",
1162 obd->obd_name, &obd->obd_osfs,
1163 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1164 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1165 spin_lock(&obd->obd_osfs_lock);
1166 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1167 spin_unlock(&obd->obd_osfs_lock);
1172 static inline int obd_preprw(const struct lu_env *env, int cmd,
1173 struct obd_export *exp, struct obdo *oa,
1174 int objcount, struct obd_ioobj *obj,
1175 struct niobuf_remote *remote, int *pages,
1176 struct niobuf_local *local)
1182 rc = exp_check_ops(exp);
1186 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1187 CERROR("%s: no %s operation\n",
1188 (exp)->exp_obd->obd_name, __func__);
1191 EXP_COUNTER_INCREMENT(exp, preprw);
1192 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1198 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1199 struct obd_export *exp, struct obdo *oa,
1200 int objcount, struct obd_ioobj *obj,
1201 struct niobuf_remote *rnb, int pages,
1202 struct niobuf_local *local, int rc)
1206 rc = exp_check_ops(exp);
1210 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1211 CERROR("%s: no %s operation\n",
1212 (exp)->exp_obd->obd_name, __func__);
1215 EXP_COUNTER_INCREMENT(exp, commitrw);
1216 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1217 rnb, pages, local, rc);
1222 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1223 int len, void *karg, void __user *uarg)
1228 rc = exp_check_ops(exp);
1232 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1233 CERROR("%s: no %s operation\n",
1234 (exp)->exp_obd->obd_name, __func__);
1237 EXP_COUNTER_INCREMENT(exp, iocontrol);
1239 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1243 static inline void obd_import_event(struct obd_device *obd,
1244 struct obd_import *imp,
1245 enum obd_import_event event)
1249 CERROR("NULL device\n");
1253 if (obd->obd_set_up && OBP(obd, import_event)) {
1254 OBD_COUNTER_INCREMENT(obd, import_event);
1255 OBP(obd, import_event)(obd, imp, event);
1260 static inline int obd_notify(struct obd_device *obd,
1261 struct obd_device *watched,
1262 enum obd_notify_event ev)
1268 if (!obd->obd_set_up) {
1269 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1273 if (!OBP(obd, notify)) {
1274 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1278 OBD_COUNTER_INCREMENT(obd, notify);
1279 rc = OBP(obd, notify)(obd, watched, ev);
1284 static inline int obd_notify_observer(struct obd_device *observer,
1285 struct obd_device *observed,
1286 enum obd_notify_event ev)
1290 struct obd_notify_upcall *onu;
1292 if (observer->obd_observer)
1293 rc = obd_notify(observer->obd_observer, observed, ev);
1296 * Also, call non-obd listener, if any
1298 onu = &observer->obd_upcall;
1299 if (onu->onu_upcall != NULL)
1300 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1302 return rc ? rc : rc2;
1305 static inline int obd_quotactl(struct obd_export *exp,
1306 struct obd_quotactl *oqctl)
1311 rc = exp_check_ops(exp);
1315 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1316 CERROR("%s: no %s operation\n",
1317 (exp)->exp_obd->obd_name, __func__);
1320 EXP_COUNTER_INCREMENT(exp, quotactl);
1322 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1326 static inline int obd_health_check(const struct lu_env *env,
1327 struct obd_device *obd)
1329 /* returns: 0 on healthy
1330 * >0 on unhealthy + reason code/flag
1331 * however the only suppored reason == 1 right now
1332 * We'll need to define some better reasons
1333 * or flags in the future.
1340 /* NULL method is normal here */
1341 if (obd == NULL || !obd->obd_type) {
1342 CERROR("cleaned up obd\n");
1343 RETURN(-EOPNOTSUPP);
1345 if (!obd->obd_set_up || obd->obd_stopping)
1347 if (!OBP(obd, health_check))
1350 rc = OBP(obd, health_check)(env, obd);
1354 static inline int obd_register_observer(struct obd_device *obd,
1355 struct obd_device *observer)
1359 down_write(&obd->obd_observer_link_sem);
1360 if (obd->obd_observer && observer) {
1361 up_write(&obd->obd_observer_link_sem);
1364 obd->obd_observer = observer;
1365 up_write(&obd->obd_observer_link_sem);
1369 /* metadata helpers */
1370 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1376 rc = exp_check_ops(exp);
1379 EXP_MD_COUNTER_INCREMENT(exp, get_root);
1380 rc = MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1385 static inline int md_getattr(struct obd_export *exp,
1386 struct md_op_data *op_data,
1387 struct ptlrpc_request **request)
1392 rc = exp_check_ops(exp);
1395 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1396 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1400 static inline int md_null_inode(struct obd_export *exp,
1401 const struct lu_fid *fid)
1405 rc = exp_check_ops(exp);
1408 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1409 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1413 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1414 struct md_open_data *mod,
1415 struct ptlrpc_request **request)
1419 rc = exp_check_ops(exp);
1422 EXP_MD_COUNTER_INCREMENT(exp, close);
1423 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1427 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1428 const void *data, size_t datalen, umode_t mode,
1429 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1430 __u64 rdev, struct ptlrpc_request **request)
1434 rc = exp_check_ops(exp);
1437 EXP_MD_COUNTER_INCREMENT(exp, create);
1438 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1439 uid, gid, cap_effective, rdev, request);
1443 static inline int md_enqueue(struct obd_export *exp,
1444 struct ldlm_enqueue_info *einfo,
1445 const union ldlm_policy_data *policy,
1446 struct md_op_data *op_data,
1447 struct lustre_handle *lockh,
1448 __u64 extra_lock_flags)
1452 rc = exp_check_ops(exp);
1455 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1456 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1461 static inline int md_getattr_name(struct obd_export *exp,
1462 struct md_op_data *op_data,
1463 struct ptlrpc_request **request)
1467 rc = exp_check_ops(exp);
1470 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1471 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1475 static inline int md_intent_lock(struct obd_export *exp,
1476 struct md_op_data *op_data,
1477 struct lookup_intent *it,
1478 struct ptlrpc_request **reqp,
1479 ldlm_blocking_callback cb_blocking,
1480 __u64 extra_lock_flags)
1484 rc = exp_check_ops(exp);
1487 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1488 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1493 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1494 struct ptlrpc_request **request)
1498 rc = exp_check_ops(exp);
1501 EXP_MD_COUNTER_INCREMENT(exp, link);
1502 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1506 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1507 const char *old, size_t oldlen, const char *new,
1508 size_t newlen, struct ptlrpc_request **request)
1512 rc = exp_check_ops(exp);
1516 EXP_MD_COUNTER_INCREMENT(exp, rename);
1517 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1522 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1523 void *ea, size_t ealen,
1524 struct ptlrpc_request **request)
1528 rc = exp_check_ops(exp);
1532 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1533 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1537 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1538 struct ptlrpc_request **request)
1543 rc = exp_check_ops(exp);
1547 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1548 rc = MDP(exp->exp_obd, fsync)(exp, fid, request);
1553 /* FLR: resync mirrored files. */
1554 static inline int md_file_resync(struct obd_export *exp,
1555 struct md_op_data *data)
1560 rc = exp_check_ops(exp);
1564 EXP_MD_COUNTER_INCREMENT(exp, file_resync);
1565 rc = MDP(exp->exp_obd, file_resync)(exp, data);
1570 static inline int md_read_page(struct obd_export *exp,
1571 struct md_op_data *op_data,
1572 struct md_callback *cb_op,
1574 struct page **ppage)
1578 rc = exp_check_ops(exp);
1582 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1583 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1588 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1589 struct ptlrpc_request **request)
1593 rc = exp_check_ops(exp);
1597 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1598 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1602 static inline int md_get_lustre_md(struct obd_export *exp,
1603 struct ptlrpc_request *req,
1604 struct obd_export *dt_exp,
1605 struct obd_export *md_exp,
1606 struct lustre_md *md)
1610 rc = exp_check_ops(exp);
1614 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1615 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1618 static inline int md_free_lustre_md(struct obd_export *exp,
1619 struct lustre_md *md)
1623 rc = exp_check_ops(exp);
1626 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1627 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1630 static inline int md_merge_attr(struct obd_export *exp,
1631 const struct lmv_stripe_md *lsm,
1632 struct cl_attr *attr,
1633 ldlm_blocking_callback cb)
1637 rc = exp_check_ops(exp);
1640 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1641 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1644 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1645 u64 valid, const char *name,
1646 const char *input, int input_size,
1647 int output_size, int flags, __u32 suppgid,
1648 struct ptlrpc_request **request)
1653 rc = exp_check_ops(exp);
1656 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1657 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1658 input_size, output_size, flags,
1662 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1663 u64 valid, const char *name,
1664 const char *input, int input_size,
1665 int output_size, int flags,
1666 struct ptlrpc_request **request)
1670 rc = exp_check_ops(exp);
1673 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1674 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1675 input_size, output_size, flags,
1679 static inline int md_set_open_replay_data(struct obd_export *exp,
1680 struct obd_client_handle *och,
1681 struct lookup_intent *it)
1685 rc = exp_check_ops(exp);
1688 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1689 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1692 static inline int md_clear_open_replay_data(struct obd_export *exp,
1693 struct obd_client_handle *och)
1697 rc = exp_check_ops(exp);
1700 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1701 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1704 static inline int md_set_lock_data(struct obd_export *exp,
1705 const struct lustre_handle *lockh,
1706 void *data, __u64 *bits)
1710 rc = exp_check_ops(exp);
1713 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1714 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1718 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1719 union ldlm_policy_data *policy, enum ldlm_mode mode,
1720 enum ldlm_cancel_flags cancel_flags, void *opaque)
1725 rc = exp_check_ops(exp);
1728 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1730 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1731 cancel_flags, opaque);
1735 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1736 const struct lu_fid *fid,
1737 enum ldlm_type type,
1738 union ldlm_policy_data *policy,
1739 enum ldlm_mode mode,
1740 struct lustre_handle *lockh)
1744 rc = exp_check_ops(exp);
1747 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1748 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1749 policy, mode, lockh));
1752 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1757 rc = exp_check_ops(exp);
1760 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1761 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
1764 static inline int md_intent_getattr_async(struct obd_export *exp,
1765 struct md_enqueue_info *minfo)
1769 rc = exp_check_ops(exp);
1772 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1773 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1777 static inline int md_revalidate_lock(struct obd_export *exp,
1778 struct lookup_intent *it,
1779 struct lu_fid *fid, __u64 *bits)
1783 rc = exp_check_ops(exp);
1786 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1787 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1791 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1792 const struct lmv_stripe_md *lsm,
1793 const char *name, int namelen,
1798 rc = exp_check_ops(exp);
1801 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1802 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1807 /* Unpack an MD struct from disk to in-memory format.
1808 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1810 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1811 * If *plsm == NULL then it will be allocated.
1813 static inline int md_unpackmd(struct obd_export *exp,
1814 struct lmv_stripe_md **plsm,
1815 const union lmv_mds_md *lmm, size_t lmm_size)
1819 rc = exp_check_ops(exp);
1822 EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
1823 rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1827 /* OBD Metadata Support */
1829 extern int obd_init_caches(void);
1830 extern void obd_cleanup_caches(void);
1832 /* support routines */
1833 extern struct kmem_cache *obdo_cachep;
1835 #define OBDO_ALLOC(ptr) \
1837 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1840 #define OBDO_FREE(ptr) \
1842 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1846 typedef int (*register_lwp_cb)(void *data);
1848 struct lwp_register_item {
1849 struct obd_export **lri_exp;
1850 register_lwp_cb lri_cb_func;
1852 struct list_head lri_list;
1854 char lri_name[MTI_NAME_MAXLEN];
1857 /* I'm as embarrassed about this as you are.
1859 * <shaver> // XXX do not look into _superhack with remaining eye
1860 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1861 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1864 #ifdef HAVE_SERVER_SUPPORT
1865 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1866 register_lwp_cb cb_func, void *cb_data);
1867 void lustre_deregister_lwp_item(struct obd_export **exp);
1868 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1869 void lustre_notify_lwp_list(struct obd_export *exp);
1870 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1871 #endif /* HAVE_SERVER_SUPPORT */
1872 int lustre_register_fs(void);
1873 int lustre_unregister_fs(void);
1874 int lustre_check_exclusion(struct super_block *sb, char *svname);
1876 typedef __u8 class_uuid_t[16];
1877 static inline void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out)
1879 snprintf(out->uuid, sizeof(out->uuid), "%02x%02x%02x%02x-%02x%02x-"
1880 "%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1881 uu[14], uu[15], uu[12], uu[13], uu[10], uu[11], uu[8], uu[9],
1882 uu[6], uu[7], uu[4], uu[5], uu[2], uu[3], uu[0], uu[1]);
1886 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1887 int class_add_uuid(const char *uuid, __u64 nid);
1888 int class_del_uuid (const char *uuid);
1889 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1892 extern char obd_jobid_name[];
1895 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1899 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1900 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1902 /* root squash info */
1903 struct rw_semaphore;
1904 struct root_squash_info {
1907 struct list_head rsi_nosquash_nids;
1908 struct rw_semaphore rsi_sem;
1911 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1913 /* linux-module.c */
1914 extern struct miscdevice obd_psdev;
1915 int obd_ioctl_getdata(char **buf, int *len, void __user *arg);
1916 int class_procfs_init(void);
1917 int class_procfs_clean(void);
1919 #endif /* __LINUX_OBD_CLASS_H */