4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
36 #include <obd_support.h>
37 #include <lustre_import.h>
38 #include <lustre_net.h>
40 #include <lustre_lib.h>
41 #include <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 extern int lustre_get_jobid(char *jobid);
59 struct lu_device_type;
62 struct obd_export *class_conn2export(struct lustre_handle *);
63 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
64 struct lprocfs_vars *module_vars,
65 const char *nm, struct lu_device_type *ldt);
66 int class_unregister_type(const char *nm);
68 struct obd_device *class_newdev(const char *type_name, const char *name,
70 int class_register_device(struct obd_device *obd);
71 void class_unregister_device(struct obd_device *obd);
72 void class_free_dev(struct obd_device *obd);
74 struct obd_device *class_dev_by_str(const char *str);
75 int class_name2dev(const char *name);
76 struct obd_device *class_name2obd(const char *name);
77 int class_uuid2dev(struct obd_uuid *uuid);
78 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
79 void class_obd_list(void);
80 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
81 const char * typ_name,
82 struct obd_uuid *grp_uuid);
83 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
85 struct obd_device * class_num2obd(int num);
86 int get_devices_count(void);
88 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
90 char *obd_export_nid2str(struct obd_export *exp);
92 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
93 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
94 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
97 int obd_zombie_impexp_init(void);
98 void obd_zombie_impexp_stop(void);
99 void obd_zombie_impexp_cull(void);
100 void obd_zombie_barrier(void);
101 void obd_exports_barrier(struct obd_device *obd);
102 int kuc_len(int payload_len);
103 struct kuc_hdr * kuc_ptr(void *p);
104 void *kuc_alloc(int payload_len, int transport, int type);
105 void kuc_free(void *p, int payload_len);
106 int obd_get_request_slot(struct client_obd *cli);
107 void obd_put_request_slot(struct client_obd *cli);
108 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
109 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
110 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
111 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
112 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
114 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc,
115 struct lookup_intent *it);
116 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc,
117 struct lookup_intent *it, __u16 tag);
121 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
122 struct llog_rec_hdr *, void *);
124 struct obd_export *obd_stale_export_get(void);
125 void obd_stale_export_put(struct obd_export *exp);
126 void obd_stale_export_adjust(struct obd_export *exp);
129 /* For interoperability */
130 struct cfg_interop_param {
135 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
136 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
137 const char *new_name);
138 void print_lustre_cfg(struct lustre_cfg *lcfg);
139 int class_process_config(struct lustre_cfg *lcfg);
140 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
141 struct lustre_cfg *lcfg, void *data);
142 int class_attach(struct lustre_cfg *lcfg);
143 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
144 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
145 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
147 int class_find_param(char *buf, char *key, char **valp);
148 struct cfg_interop_param *class_find_old_param(const char *param,
149 struct cfg_interop_param *ptr);
150 int class_get_next_param(char **params, char *copy);
151 int class_match_param(char *buf, const char *key, char **valp);
152 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
153 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
154 int class_parse_net(char *buf, u32 *net, char **endh);
155 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
156 int class_match_net(char *buf, char *key, u32 net);
158 struct obd_device *class_incref(struct obd_device *obd,
159 const char *scope, const void *source);
160 void class_decref(struct obd_device *obd,
161 const char *scope, const void *source);
162 void dump_exports(struct obd_device *obd, int locks, int debug_level);
163 int class_config_llog_handler(const struct lu_env *env,
164 struct llog_handle *handle,
165 struct llog_rec_hdr *rec, void *data);
166 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
168 #define CFG_F_START 0x01 /* Set when we start updating from a log */
169 #define CFG_F_MARKER 0x02 /* We are within a maker */
170 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
171 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
172 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
174 /* Passed as data param to class_config_parse_llog */
175 struct config_llog_instance {
178 struct super_block *cfg_sb;
179 struct obd_uuid cfg_uuid;
180 llog_cb_t cfg_callback;
181 int cfg_last_idx; /* for partial llog processing */
186 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
187 char *name, struct config_llog_instance *cfg);
189 #define CONFIG_SUB_SPTLRPC 0x01
190 #define CONFIG_SUB_RECOVER 0x02
191 #define CONFIG_SUB_PARAMS 0x04
192 #define CONFIG_SUB_NODEMAP 0x08
193 #define CONFIG_SUB_BARRIER 0x10
195 /* Sub clds should be attached to the config_llog_data when processing
196 * config log for client or server target. */
197 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
199 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
202 #define PARAMS_FILENAME "params"
203 #define BARRIER_FILENAME "barrier"
204 #define LCTL_UPCALL "lctl"
206 static inline bool logname_is_barrier(const char *logname)
210 /* logname for barrier is "fsname-barrier" */
211 ptr = strstr(logname, BARRIER_FILENAME);
212 if (ptr && (ptr - logname) >= 2 &&
213 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
219 /* list of active configuration logs */
220 struct config_llog_data {
221 struct ldlm_res_id cld_resid;
222 struct config_llog_instance cld_cfg;
223 struct list_head cld_list_chain;
224 atomic_t cld_refcount;
225 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
226 struct config_llog_data *cld_params; /* common parameters log */
227 struct config_llog_data *cld_recover;/* imperative recover log */
228 struct config_llog_data *cld_nodemap;/* nodemap log */
229 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
230 struct obd_export *cld_mgcexp;
231 struct mutex cld_lock;
233 unsigned int cld_stopping:1, /* we were told to stop
235 cld_lostlock:1; /* lock not requeued */
239 struct lustre_profile {
240 struct list_head lp_list;
245 bool lp_list_deleted;
248 struct lustre_profile *class_get_profile(const char * prof);
249 void class_del_profile(const char *prof);
250 void class_put_profile(struct lustre_profile *lprof);
251 void class_del_profiles(void);
254 #if LUSTRE_TRACKS_LOCK_EXP_REFS
256 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
257 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
258 extern void (*class_export_dump_hook)(struct obd_export *);
262 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
263 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
267 #define class_export_rpc_inc(exp) \
269 atomic_inc(&(exp)->exp_rpc_count); \
270 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
271 (exp), atomic_read(&(exp)->exp_rpc_count)); \
274 #define class_export_rpc_dec(exp) \
276 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
277 atomic_dec(&(exp)->exp_rpc_count); \
278 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
279 (exp), atomic_read(&(exp)->exp_rpc_count)); \
282 #define class_export_lock_get(exp, lock) \
284 atomic_inc(&(exp)->exp_locks_count); \
285 __class_export_add_lock_ref(exp, lock); \
286 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
287 (exp), atomic_read(&(exp)->exp_locks_count)); \
288 class_export_get(exp); \
291 #define class_export_lock_put(exp, lock) \
293 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
294 atomic_dec(&(exp)->exp_locks_count); \
295 __class_export_del_lock_ref(exp, lock); \
296 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
297 (exp), atomic_read(&(exp)->exp_locks_count)); \
298 class_export_put(exp); \
301 #define class_export_cb_get(exp) \
303 atomic_inc(&(exp)->exp_cb_count); \
304 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
305 (exp), atomic_read(&(exp)->exp_cb_count)); \
306 class_export_get(exp); \
309 #define class_export_cb_put(exp) \
311 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
312 atomic_dec(&(exp)->exp_cb_count); \
313 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
314 (exp), atomic_read(&(exp)->exp_cb_count)); \
315 class_export_put(exp); \
319 struct obd_export *class_export_get(struct obd_export *exp);
320 void class_export_put(struct obd_export *exp);
321 struct obd_export *class_new_export(struct obd_device *obddev,
322 struct obd_uuid *cluuid);
323 struct obd_export *class_new_export_self(struct obd_device *obd,
324 struct obd_uuid *uuid);
325 void class_unlink_export(struct obd_export *exp);
327 struct obd_import *class_import_get(struct obd_import *);
328 void class_import_put(struct obd_import *);
329 struct obd_import *class_new_import(struct obd_device *obd);
330 void class_destroy_import(struct obd_import *exp);
332 struct obd_type *class_search_type(const char *name);
333 struct obd_type *class_get_type(const char *name);
334 void class_put_type(struct obd_type *type);
335 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
336 struct obd_uuid *cluuid);
337 int class_disconnect(struct obd_export *exp);
338 void class_fail_export(struct obd_export *exp);
339 int class_connected_export(struct obd_export *exp);
340 void class_disconnect_exports(struct obd_device *obddev);
341 int class_manual_cleanup(struct obd_device *obd);
342 void class_disconnect_stale_exports(struct obd_device *,
343 int (*test_export)(struct obd_export *));
344 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
346 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
347 (obd->obd_force ? OBD_OPT_FORCE : 0) |
348 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
352 #ifdef HAVE_SERVER_SUPPORT
353 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
355 LASSERT(exp->exp_obd);
356 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
358 return exp->exp_obd->u.obt.obt_lut;
361 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
363 LASSERT(obd->u.obt.obt_lut);
364 return &obd->u.obt.obt_lut->lut_lsd;
372 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
373 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
375 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
376 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
378 #define OBT(dev) (dev)->obd_type
379 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
380 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
381 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
383 /* Ensure obd_setup: used for cleanup which must be called
384 while obd is stopping */
385 #define OBD_CHECK_DEV(obd) \
388 CERROR("NULL device\n"); \
393 /* ensure obd_setup and !obd_stopping */
394 #define OBD_CHECK_DEV_ACTIVE(obd) \
396 OBD_CHECK_DEV(obd); \
397 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
398 CERROR("Device %d not setup\n", \
405 #ifdef CONFIG_PROC_FS
406 #define OBD_COUNTER_OFFSET(op) \
407 ((offsetof(struct obd_ops, o_ ## op) - \
408 offsetof(struct obd_ops, o_iocontrol)) \
409 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
411 /* The '- 1' below is for o_owner. */
412 #define NUM_OBD_STATS \
413 (sizeof(struct obd_ops) / \
414 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
416 #define OBD_COUNTER_INCREMENT(obd, op) \
417 lprocfs_counter_incr((obd)->obd_stats, \
418 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
420 #define EXP_COUNTER_INCREMENT(exp, op) \
423 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
424 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
425 if ((exp)->exp_obd->obd_uses_nid_stats && \
426 (exp)->exp_nid_stats != NULL) \
427 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
431 #define _MD_COUNTER_OFFSET(m_op) \
432 ((offsetof(struct md_ops, m_op) - \
433 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
434 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
436 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
438 #define NUM_MD_STATS \
439 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
440 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
442 /* Note that we only increment md counters for ops whose offset is less
443 * than NUM_MD_STATS. This is explained in a comment in the definition
444 * of struct md_ops. */
445 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
447 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
448 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
449 (exp)->exp_obd->obd_md_cntr_base + \
450 MD_COUNTER_OFFSET(op)); \
454 #define OBD_COUNTER_OFFSET(op)
455 #define OBD_COUNTER_INCREMENT(obd, op)
456 #define EXP_COUNTER_INCREMENT(exp, op)
457 #define EXP_MD_COUNTER_INCREMENT(exp, op)
460 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
462 /* Always add in ldlm_stats */
463 tmp->nid_ldlm_stats =
464 lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC,
465 LPROCFS_STATS_FLAG_NOPERCPU);
466 if (tmp->nid_ldlm_stats == NULL)
469 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
471 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
472 tmp->nid_ldlm_stats);
475 #define EXP_CHECK_MD_OP(exp, op) \
477 if ((exp) == NULL) { \
478 CERROR("obd_" #op ": NULL export\n"); \
481 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
482 CERROR("obd_" #op ": cleaned up obd\n"); \
483 RETURN(-EOPNOTSUPP); \
485 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
486 CERROR("%s: obd_" #op ": dev %d no operation\n", \
487 (exp)->exp_obd->obd_name, \
488 (exp)->exp_obd->obd_minor); \
489 RETURN(-EOPNOTSUPP); \
494 #define OBD_CHECK_DT_OP(obd, op, err) \
496 if (!OBT(obd) || !OBP((obd), op)) { \
498 CERROR("%s: no obd_" #op " operation\n", \
504 #define EXP_CHECK_DT_OP(exp, op) \
506 if ((exp) == NULL) { \
507 CERROR("obd_" #op ": NULL export\n"); \
510 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
511 CERROR("obd_" #op ": cleaned up obd\n"); \
512 RETURN(-EOPNOTSUPP); \
514 OBD_CHECK_DT_OP((exp)->exp_obd, op, -EOPNOTSUPP); \
517 #define CTXT_CHECK_OP(ctxt, op, err) \
519 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
521 CERROR("%s: no lop_" #op "operation\n", \
522 ctxt->loc_obd->obd_name); \
527 static inline int class_devno_max(void)
529 return MAX_OBD_DEVICES;
532 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
533 __u32 keylen, void *key,
534 __u32 *vallen, void *val)
539 EXP_CHECK_DT_OP(exp, get_info);
540 EXP_COUNTER_INCREMENT(exp, get_info);
542 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
546 static inline int obd_set_info_async(const struct lu_env *env,
547 struct obd_export *exp,
548 __u32 keylen, void *key,
549 __u32 vallen, void *val,
550 struct ptlrpc_request_set *set)
555 EXP_CHECK_DT_OP(exp, set_info_async);
556 EXP_COUNTER_INCREMENT(exp, set_info_async);
558 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
564 * obd-lu integration.
566 * Functionality is being moved into new lu_device-based layering, but some
567 * pieces of configuration process are still based on obd devices.
569 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
570 * subsume ->o_setup() methods of obd devices they replace. The same for
571 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
572 * result, obd_setup() and obd_process_config() branch and call one XOR
575 * Yet neither lu_device_type_operations::ldto_device_fini() nor
576 * lu_device_type_operations::ldto_device_free() fully implement the
577 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
578 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
581 #define DECLARE_LU_VARS(ldt, d) \
582 struct lu_device_type *ldt; \
585 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
588 DECLARE_LU_VARS(ldt, d);
591 ldt = obd->obd_type->typ_lu;
593 struct lu_context session_ctx;
595 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
596 session_ctx.lc_thread = NULL;
597 lu_context_enter(&session_ctx);
599 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
601 env.le_ses = &session_ctx;
602 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
611 lu_context_exit(&session_ctx);
612 lu_context_fini(&session_ctx);
615 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
616 OBD_COUNTER_INCREMENT(obd, setup);
617 rc = OBP(obd, setup)(obd, cfg);
622 static inline int obd_precleanup(struct obd_device *obd)
625 DECLARE_LU_VARS(ldt, d);
629 ldt = obd->obd_type->typ_lu;
631 if (ldt != NULL && d != NULL) {
634 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
636 ldt->ldt_ops->ldto_device_fini(&env, d);
640 OBD_CHECK_DT_OP(obd, precleanup, 0);
641 OBD_COUNTER_INCREMENT(obd, precleanup);
643 rc = OBP(obd, precleanup)(obd);
647 static inline int obd_cleanup(struct obd_device *obd)
650 DECLARE_LU_VARS(ldt, d);
655 ldt = obd->obd_type->typ_lu;
657 if (ldt != NULL && d != NULL) {
660 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
662 ldt->ldt_ops->ldto_device_free(&env, d);
664 obd->obd_lu_dev = NULL;
667 OBD_CHECK_DT_OP(obd, cleanup, 0);
668 OBD_COUNTER_INCREMENT(obd, cleanup);
670 rc = OBP(obd, cleanup)(obd);
674 static inline void obd_cleanup_client_import(struct obd_device *obd)
678 /* If we set up but never connected, the
679 client import will not have been cleaned. */
680 down_write(&obd->u.cli.cl_sem);
681 if (obd->u.cli.cl_import) {
682 struct obd_import *imp;
683 imp = obd->u.cli.cl_import;
684 CDEBUG(D_CONFIG, "%s: client import never connected\n",
686 ptlrpc_invalidate_import(imp);
687 client_destroy_import(imp);
688 obd->u.cli.cl_import = NULL;
690 up_write(&obd->u.cli.cl_sem);
696 obd_process_config(struct obd_device *obd, int datalen, void *data)
699 DECLARE_LU_VARS(ldt, d);
704 obd->obd_process_conf = 1;
705 ldt = obd->obd_type->typ_lu;
707 if (ldt != NULL && d != NULL) {
710 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
712 rc = d->ld_ops->ldo_process_config(&env, d, data);
716 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
717 rc = OBP(obd, process_config)(obd, datalen, data);
719 OBD_COUNTER_INCREMENT(obd, process_config);
720 obd->obd_process_conf = 0;
725 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
731 EXP_CHECK_DT_OP(exp, create);
732 EXP_COUNTER_INCREMENT(exp, create);
734 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
738 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
744 EXP_CHECK_DT_OP(exp, destroy);
745 EXP_COUNTER_INCREMENT(exp, destroy);
747 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
751 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
757 EXP_CHECK_DT_OP(exp, getattr);
758 EXP_COUNTER_INCREMENT(exp, getattr);
759 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
764 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
770 EXP_CHECK_DT_OP(exp, setattr);
771 EXP_COUNTER_INCREMENT(exp, setattr);
772 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
777 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
780 struct obd_device *obd = imp->imp_obd;
784 OBD_CHECK_DEV_ACTIVE(obd);
785 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
786 OBD_COUNTER_INCREMENT(obd, add_conn);
788 rc = OBP(obd, add_conn)(imp, uuid, priority);
792 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
794 struct obd_device *obd = imp->imp_obd;
798 OBD_CHECK_DEV_ACTIVE(obd);
799 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
800 OBD_COUNTER_INCREMENT(obd, del_conn);
802 rc = OBP(obd, del_conn)(imp, uuid);
806 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
808 struct obd_uuid *uuid;
811 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
812 EXP_COUNTER_INCREMENT(exp, get_uuid);
814 uuid = OBP(exp->exp_obd, get_uuid)(exp);
818 /** Create a new /a exp on device /a obd for the uuid /a cluuid
819 * @param exp New export handle
820 * @param d Connect data, supported flags are set, flags also understood
821 * by obd are returned.
823 static inline int obd_connect(const struct lu_env *env,
824 struct obd_export **exp,struct obd_device *obd,
825 struct obd_uuid *cluuid,
826 struct obd_connect_data *data,
830 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
834 OBD_CHECK_DEV_ACTIVE(obd);
835 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
836 OBD_COUNTER_INCREMENT(obd, connect);
838 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
839 /* check that only subset is granted */
840 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
841 data->ocd_connect_flags));
845 static inline int obd_reconnect(const struct lu_env *env,
846 struct obd_export *exp,
847 struct obd_device *obd,
848 struct obd_uuid *cluuid,
849 struct obd_connect_data *d,
853 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
858 OBD_CHECK_DEV_ACTIVE(obd);
859 OBD_CHECK_DT_OP(obd, reconnect, 0);
860 OBD_COUNTER_INCREMENT(obd, reconnect);
862 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
863 /* check that only subset is granted */
864 LASSERT(ergo(d != NULL,
865 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
869 static inline int obd_disconnect(struct obd_export *exp)
874 EXP_CHECK_DT_OP(exp, disconnect);
875 EXP_COUNTER_INCREMENT(exp, disconnect);
877 rc = OBP(exp->exp_obd, disconnect)(exp);
881 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
882 enum lu_cli_type type)
887 OBD_CHECK_DT_OP(obd, fid_init, 0);
888 OBD_COUNTER_INCREMENT(obd, fid_init);
890 rc = OBP(obd, fid_init)(obd, exp, type);
894 static inline int obd_fid_fini(struct obd_device *obd)
899 OBD_CHECK_DT_OP(obd, fid_fini, 0);
900 OBD_COUNTER_INCREMENT(obd, fid_fini);
902 rc = OBP(obd, fid_fini)(obd);
906 static inline int obd_fid_alloc(const struct lu_env *env,
907 struct obd_export *exp,
909 struct md_op_data *op_data)
914 EXP_CHECK_DT_OP(exp, fid_alloc);
915 EXP_COUNTER_INCREMENT(exp, fid_alloc);
917 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
921 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
926 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
927 EXP_COUNTER_INCREMENT(exp, ping);
929 rc = OBP(exp->exp_obd, ping)(env, exp);
933 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
938 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
939 OBD_COUNTER_INCREMENT(obd, pool_new);
941 rc = OBP(obd, pool_new)(obd, poolname);
945 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
950 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
951 OBD_COUNTER_INCREMENT(obd, pool_del);
953 rc = OBP(obd, pool_del)(obd, poolname);
957 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
962 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
963 OBD_COUNTER_INCREMENT(obd, pool_add);
965 rc = OBP(obd, pool_add)(obd, poolname, ostname);
969 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
974 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
975 OBD_COUNTER_INCREMENT(obd, pool_rem);
977 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
981 static inline void obd_getref(struct obd_device *obd)
984 if (OBT(obd) && OBP(obd, getref)) {
985 OBD_COUNTER_INCREMENT(obd, getref);
986 OBP(obd, getref)(obd);
991 static inline void obd_putref(struct obd_device *obd)
994 if (OBT(obd) && OBP(obd, putref)) {
995 OBD_COUNTER_INCREMENT(obd, putref);
996 OBP(obd, putref)(obd);
1001 static inline int obd_init_export(struct obd_export *exp)
1006 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1007 OBP((exp)->exp_obd, init_export))
1008 rc = OBP(exp->exp_obd, init_export)(exp);
1012 static inline int obd_destroy_export(struct obd_export *exp)
1015 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1016 OBP((exp)->exp_obd, destroy_export))
1017 OBP(exp->exp_obd, destroy_export)(exp);
1021 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1022 * If the cache is older than @max_age we will get a new value from the
1023 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1024 static inline int obd_statfs_async(struct obd_export *exp,
1025 struct obd_info *oinfo,
1027 struct ptlrpc_request_set *rqset)
1030 struct obd_device *obd;
1033 if (exp == NULL || exp->exp_obd == NULL)
1037 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1038 OBD_COUNTER_INCREMENT(obd, statfs);
1040 CDEBUG(D_SUPER, "%s: osfs %p age %llu, max_age %llu\n",
1041 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1042 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1043 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1045 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1046 obd->obd_name, &obd->obd_osfs,
1047 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1048 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1049 spin_lock(&obd->obd_osfs_lock);
1050 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1051 spin_unlock(&obd->obd_osfs_lock);
1052 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1053 if (oinfo->oi_cb_up)
1054 oinfo->oi_cb_up(oinfo, 0);
1059 static inline int obd_statfs_rqset(struct obd_export *exp,
1060 struct obd_statfs *osfs, __u64 max_age,
1063 struct ptlrpc_request_set *set = NULL;
1064 struct obd_info oinfo = {
1072 set = ptlrpc_prep_set();
1076 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1078 rc = ptlrpc_set_wait(set);
1080 ptlrpc_set_destroy(set);
1085 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1086 * If the cache is older than @max_age we will get a new value from the
1087 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1088 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1089 struct obd_statfs *osfs, __u64 max_age,
1093 struct obd_device *obd = exp->exp_obd;
1099 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1100 OBD_CHECK_DEV_ACTIVE(obd);
1101 OBD_COUNTER_INCREMENT(obd, statfs);
1103 CDEBUG(D_SUPER, "osfs %llu, max_age %llu\n",
1104 obd->obd_osfs_age, max_age);
1105 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1106 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1108 spin_lock(&obd->obd_osfs_lock);
1109 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1110 obd->obd_osfs_age = cfs_time_current_64();
1111 spin_unlock(&obd->obd_osfs_lock);
1114 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu"
1115 " objects %llu/%llu\n",
1116 obd->obd_name, &obd->obd_osfs,
1117 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1118 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1119 spin_lock(&obd->obd_osfs_lock);
1120 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1121 spin_unlock(&obd->obd_osfs_lock);
1126 static inline int obd_preprw(const struct lu_env *env, int cmd,
1127 struct obd_export *exp, struct obdo *oa,
1128 int objcount, struct obd_ioobj *obj,
1129 struct niobuf_remote *remote, int *pages,
1130 struct niobuf_local *local)
1135 EXP_CHECK_DT_OP(exp, preprw);
1136 EXP_COUNTER_INCREMENT(exp, preprw);
1137 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1143 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1144 struct obd_export *exp, struct obdo *oa,
1145 int objcount, struct obd_ioobj *obj,
1146 struct niobuf_remote *rnb, int pages,
1147 struct niobuf_local *local, int rc)
1151 EXP_CHECK_DT_OP(exp, commitrw);
1152 EXP_COUNTER_INCREMENT(exp, commitrw);
1153 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1154 rnb, pages, local, rc);
1159 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1160 int len, void *karg, void __user *uarg)
1165 EXP_CHECK_DT_OP(exp, iocontrol);
1166 EXP_COUNTER_INCREMENT(exp, iocontrol);
1168 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1172 static inline void obd_import_event(struct obd_device *obd,
1173 struct obd_import *imp,
1174 enum obd_import_event event)
1178 CERROR("NULL device\n");
1182 if (obd->obd_set_up && OBP(obd, import_event)) {
1183 OBD_COUNTER_INCREMENT(obd, import_event);
1184 OBP(obd, import_event)(obd, imp, event);
1189 static inline int obd_notify(struct obd_device *obd,
1190 struct obd_device *watched,
1191 enum obd_notify_event ev)
1197 if (!obd->obd_set_up) {
1198 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1202 if (!OBP(obd, notify)) {
1203 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1207 OBD_COUNTER_INCREMENT(obd, notify);
1208 rc = OBP(obd, notify)(obd, watched, ev);
1213 static inline int obd_notify_observer(struct obd_device *observer,
1214 struct obd_device *observed,
1215 enum obd_notify_event ev)
1219 struct obd_notify_upcall *onu;
1221 if (observer->obd_observer)
1222 rc = obd_notify(observer->obd_observer, observed, ev);
1225 * Also, call non-obd listener, if any
1227 onu = &observer->obd_upcall;
1228 if (onu->onu_upcall != NULL)
1229 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1231 return rc ? rc : rc2;
1234 static inline int obd_quotactl(struct obd_export *exp,
1235 struct obd_quotactl *oqctl)
1240 EXP_CHECK_DT_OP(exp, quotactl);
1241 EXP_COUNTER_INCREMENT(exp, quotactl);
1243 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1247 static inline int obd_health_check(const struct lu_env *env,
1248 struct obd_device *obd)
1250 /* returns: 0 on healthy
1251 * >0 on unhealthy + reason code/flag
1252 * however the only suppored reason == 1 right now
1253 * We'll need to define some better reasons
1254 * or flags in the future.
1260 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1261 if (obd == NULL || !OBT(obd)) {
1262 CERROR("cleaned up obd\n");
1263 RETURN(-EOPNOTSUPP);
1265 if (!obd->obd_set_up || obd->obd_stopping)
1267 if (!OBP(obd, health_check))
1270 rc = OBP(obd, health_check)(env, obd);
1274 static inline int obd_register_observer(struct obd_device *obd,
1275 struct obd_device *observer)
1279 down_write(&obd->obd_observer_link_sem);
1280 if (obd->obd_observer && observer) {
1281 up_write(&obd->obd_observer_link_sem);
1284 obd->obd_observer = observer;
1285 up_write(&obd->obd_observer_link_sem);
1289 /* metadata helpers */
1290 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1296 EXP_CHECK_MD_OP(exp, get_root);
1297 EXP_MD_COUNTER_INCREMENT(exp, get_root);
1298 rc = MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1303 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1304 struct ptlrpc_request **request)
1308 EXP_CHECK_MD_OP(exp, getattr);
1309 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1310 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1314 static inline int md_null_inode(struct obd_export *exp,
1315 const struct lu_fid *fid)
1319 EXP_CHECK_MD_OP(exp, null_inode);
1320 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1321 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1325 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1326 struct md_open_data *mod,
1327 struct ptlrpc_request **request)
1331 EXP_CHECK_MD_OP(exp, close);
1332 EXP_MD_COUNTER_INCREMENT(exp, close);
1333 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1337 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1338 const void *data, size_t datalen, umode_t mode,
1339 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1340 __u64 rdev, struct ptlrpc_request **request)
1344 EXP_CHECK_MD_OP(exp, create);
1345 EXP_MD_COUNTER_INCREMENT(exp, create);
1346 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1347 uid, gid, cap_effective, rdev, request);
1351 static inline int md_enqueue(struct obd_export *exp,
1352 struct ldlm_enqueue_info *einfo,
1353 const union ldlm_policy_data *policy,
1354 struct md_op_data *op_data,
1355 struct lustre_handle *lockh,
1356 __u64 extra_lock_flags)
1360 EXP_CHECK_MD_OP(exp, enqueue);
1361 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1362 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1367 static inline int md_getattr_name(struct obd_export *exp,
1368 struct md_op_data *op_data,
1369 struct ptlrpc_request **request)
1373 EXP_CHECK_MD_OP(exp, getattr_name);
1374 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1375 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1379 static inline int md_intent_lock(struct obd_export *exp,
1380 struct md_op_data *op_data,
1381 struct lookup_intent *it,
1382 struct ptlrpc_request **reqp,
1383 ldlm_blocking_callback cb_blocking,
1384 __u64 extra_lock_flags)
1388 EXP_CHECK_MD_OP(exp, intent_lock);
1389 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1390 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1395 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1396 struct ptlrpc_request **request)
1400 EXP_CHECK_MD_OP(exp, link);
1401 EXP_MD_COUNTER_INCREMENT(exp, link);
1402 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1406 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1407 const char *old, size_t oldlen, const char *new,
1408 size_t newlen, struct ptlrpc_request **request)
1412 EXP_CHECK_MD_OP(exp, rename);
1413 EXP_MD_COUNTER_INCREMENT(exp, rename);
1414 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1419 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1420 void *ea, size_t ealen,
1421 struct ptlrpc_request **request)
1425 EXP_CHECK_MD_OP(exp, setattr);
1426 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1427 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1431 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1432 struct ptlrpc_request **request)
1437 EXP_CHECK_MD_OP(exp, fsync);
1438 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1439 rc = MDP(exp->exp_obd, fsync)(exp, fid, request);
1444 static inline int md_read_page(struct obd_export *exp,
1445 struct md_op_data *op_data,
1446 struct md_callback *cb_op,
1448 struct page **ppage)
1452 EXP_CHECK_MD_OP(exp, read_page);
1453 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1454 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1459 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1460 struct ptlrpc_request **request)
1464 EXP_CHECK_MD_OP(exp, unlink);
1465 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1466 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1470 static inline int md_get_lustre_md(struct obd_export *exp,
1471 struct ptlrpc_request *req,
1472 struct obd_export *dt_exp,
1473 struct obd_export *md_exp,
1474 struct lustre_md *md)
1477 EXP_CHECK_MD_OP(exp, get_lustre_md);
1478 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1479 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1482 static inline int md_free_lustre_md(struct obd_export *exp,
1483 struct lustre_md *md)
1486 EXP_CHECK_MD_OP(exp, free_lustre_md);
1487 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1488 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1491 static inline int md_merge_attr(struct obd_export *exp,
1492 const struct lmv_stripe_md *lsm,
1493 struct cl_attr *attr,
1494 ldlm_blocking_callback cb)
1497 EXP_CHECK_MD_OP(exp, merge_attr);
1498 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1499 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1502 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1503 u64 valid, const char *name,
1504 const char *input, int input_size,
1505 int output_size, int flags, __u32 suppgid,
1506 struct ptlrpc_request **request)
1509 EXP_CHECK_MD_OP(exp, setxattr);
1510 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1511 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1512 input_size, output_size, flags,
1516 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1517 u64 valid, const char *name,
1518 const char *input, int input_size,
1519 int output_size, int flags,
1520 struct ptlrpc_request **request)
1523 EXP_CHECK_MD_OP(exp, getxattr);
1524 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1525 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1526 input_size, output_size, flags,
1530 static inline int md_set_open_replay_data(struct obd_export *exp,
1531 struct obd_client_handle *och,
1532 struct lookup_intent *it)
1535 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1536 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1537 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1540 static inline int md_clear_open_replay_data(struct obd_export *exp,
1541 struct obd_client_handle *och)
1544 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1545 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1546 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1549 static inline int md_set_lock_data(struct obd_export *exp,
1550 const struct lustre_handle *lockh,
1551 void *data, __u64 *bits)
1554 EXP_CHECK_MD_OP(exp, set_lock_data);
1555 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1556 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1560 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1561 union ldlm_policy_data *policy, enum ldlm_mode mode,
1562 enum ldlm_cancel_flags cancel_flags, void *opaque)
1567 EXP_CHECK_MD_OP(exp, cancel_unused);
1568 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1570 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1571 cancel_flags, opaque);
1575 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1576 const struct lu_fid *fid,
1577 enum ldlm_type type,
1578 union ldlm_policy_data *policy,
1579 enum ldlm_mode mode,
1580 struct lustre_handle *lockh)
1583 EXP_CHECK_MD_OP(exp, lock_match);
1584 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1585 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1586 policy, mode, lockh));
1589 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1593 EXP_CHECK_MD_OP(exp, init_ea_size);
1594 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1595 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
1598 static inline int md_intent_getattr_async(struct obd_export *exp,
1599 struct md_enqueue_info *minfo)
1603 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1604 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1605 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1609 static inline int md_revalidate_lock(struct obd_export *exp,
1610 struct lookup_intent *it,
1611 struct lu_fid *fid, __u64 *bits)
1615 EXP_CHECK_MD_OP(exp, revalidate_lock);
1616 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1617 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1621 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1622 const struct lmv_stripe_md *lsm,
1623 const char *name, int namelen,
1628 EXP_CHECK_MD_OP(exp, get_fid_from_lsm);
1629 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1630 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1635 /* Unpack an MD struct from disk to in-memory format.
1636 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1638 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1639 * If *plsm == NULL then it will be allocated.
1641 static inline int md_unpackmd(struct obd_export *exp,
1642 struct lmv_stripe_md **plsm,
1643 const union lmv_mds_md *lmm, size_t lmm_size)
1647 EXP_CHECK_MD_OP(exp, unpackmd);
1648 EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
1649 rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1653 /* OBD Metadata Support */
1655 extern int obd_init_caches(void);
1656 extern void obd_cleanup_caches(void);
1658 /* support routines */
1659 extern struct kmem_cache *obdo_cachep;
1661 #define OBDO_ALLOC(ptr) \
1663 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1666 #define OBDO_FREE(ptr) \
1668 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1672 typedef int (*register_lwp_cb)(void *data);
1674 struct lwp_register_item {
1675 struct obd_export **lri_exp;
1676 register_lwp_cb lri_cb_func;
1678 struct list_head lri_list;
1680 char lri_name[MTI_NAME_MAXLEN];
1683 /* I'm as embarrassed about this as you are.
1685 * <shaver> // XXX do not look into _superhack with remaining eye
1686 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1687 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1690 #ifdef HAVE_SERVER_SUPPORT
1691 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1692 register_lwp_cb cb_func, void *cb_data);
1693 void lustre_deregister_lwp_item(struct obd_export **exp);
1694 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1695 void lustre_notify_lwp_list(struct obd_export *exp);
1696 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1697 #endif /* HAVE_SERVER_SUPPORT */
1698 int lustre_register_fs(void);
1699 int lustre_unregister_fs(void);
1700 int lustre_check_exclusion(struct super_block *sb, char *svname);
1703 extern int obd_sysctl_init(void);
1704 extern void obd_sysctl_clean(void);
1707 typedef __u8 class_uuid_t[16];
1708 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1711 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1712 int class_add_uuid(const char *uuid, __u64 nid);
1713 int class_del_uuid (const char *uuid);
1714 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1717 extern char obd_jobid_node[];
1720 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1724 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1725 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1727 /* root squash info */
1728 struct rw_semaphore;
1729 struct root_squash_info {
1732 struct list_head rsi_nosquash_nids;
1733 struct rw_semaphore rsi_sem;
1736 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1738 /* linux-module.c */
1739 extern struct miscdevice obd_psdev;
1740 int obd_ioctl_getdata(char **buf, int *len, void __user *arg);
1741 int class_procfs_init(void);
1742 int class_procfs_clean(void);
1744 #endif /* __LINUX_OBD_CLASS_H */