4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
35 #include <linux/kobject.h>
36 #include <obd_support.h>
37 #include <lustre_import.h>
38 #include <lustre_net.h>
40 #include <lustre_lib.h>
41 #include <uapi/linux/lustre/lustre_idl.h>
42 #include <lprocfs_status.h>
44 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
45 * and resends for avoid deadlocks */
46 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
48 #define OBD_STATFS_FOR_MDT0 0x0004 /* The statfs is only for retrieving
49 * information from MDT0. */
51 extern rwlock_t obd_dev_lock;
53 /* OBD Operations Declarations */
54 extern struct obd_device *class_conn2obd(struct lustre_handle *);
55 extern struct obd_device *class_exp2obd(struct obd_export *);
56 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
57 int lustre_get_jobid(char *jobid, size_t len);
58 void lustre_jobid_clear(const char *jobid);
59 void jobid_cache_fini(void);
60 int jobid_cache_init(void);
62 struct lu_device_type;
65 struct obd_export *class_conn2export(struct lustre_handle *);
66 struct kobject *class_setup_tunables(const char *name);
67 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
68 struct lprocfs_vars *module_vars,
69 const char *nm, struct lu_device_type *ldt);
70 int class_unregister_type(const char *nm);
72 struct obd_device *class_newdev(const char *type_name, const char *name,
74 int class_register_device(struct obd_device *obd);
75 void class_unregister_device(struct obd_device *obd);
76 void class_free_dev(struct obd_device *obd);
78 struct obd_device *class_dev_by_str(const char *str);
79 int class_name2dev(const char *name);
80 struct obd_device *class_name2obd(const char *name);
81 int class_uuid2dev(struct obd_uuid *uuid);
82 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
83 void class_obd_list(void);
84 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
85 const char * typ_name,
86 struct obd_uuid *grp_uuid);
87 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
89 struct obd_device * class_num2obd(int num);
90 int get_devices_count(void);
92 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
94 static inline char *obd_export_nid2str(struct obd_export *exp)
96 return exp->exp_connection == NULL ?
97 "<unknown>" : libcfs_nid2str(exp->exp_connection->c_peer.nid);
100 static inline char *obd_import_nid2str(struct obd_import *imp)
102 return imp->imp_connection == NULL ?
103 "<unknown>" : libcfs_nid2str(imp->imp_connection->c_peer.nid);
106 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
107 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
108 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
111 int obd_zombie_impexp_init(void);
112 void obd_zombie_impexp_stop(void);
113 void obd_zombie_impexp_cull(void);
114 void obd_zombie_barrier(void);
115 void obd_exports_barrier(struct obd_device *obd);
116 int kuc_len(int payload_len);
117 struct kuc_hdr * kuc_ptr(void *p);
118 void *kuc_alloc(int payload_len, int transport, int type);
119 void kuc_free(void *p, int payload_len);
120 int obd_get_request_slot(struct client_obd *cli);
121 void obd_put_request_slot(struct client_obd *cli);
122 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
123 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
124 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
125 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
126 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
128 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc,
129 struct lookup_intent *it);
130 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc,
131 struct lookup_intent *it, __u16 tag);
135 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
136 struct llog_rec_hdr *, void *);
138 struct obd_export *obd_stale_export_get(void);
139 void obd_stale_export_put(struct obd_export *exp);
140 void obd_stale_export_adjust(struct obd_export *exp);
143 /* For interoperability */
144 struct cfg_interop_param {
149 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
150 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
151 const char *new_name);
152 void print_lustre_cfg(struct lustre_cfg *lcfg);
153 int class_process_config(struct lustre_cfg *lcfg);
154 ssize_t class_set_global(const char *param);
155 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
156 struct kobject *kobj);
157 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
158 struct lustre_cfg *lcfg, void *data);
159 int class_attach(struct lustre_cfg *lcfg);
160 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
161 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
162 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
164 int class_find_param(char *buf, char *key, char **valp);
165 struct cfg_interop_param *class_find_old_param(const char *param,
166 struct cfg_interop_param *ptr);
167 int class_get_next_param(char **params, char *copy);
168 int class_match_param(char *buf, const char *key, char **valp);
169 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
170 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
171 int class_parse_net(char *buf, u32 *net, char **endh);
172 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
173 int class_match_net(char *buf, char *key, u32 net);
175 struct obd_device *class_incref(struct obd_device *obd,
176 const char *scope, const void *source);
177 void class_decref(struct obd_device *obd,
178 const char *scope, const void *source);
179 void dump_exports(struct obd_device *obd, int locks, int debug_level);
180 int class_config_llog_handler(const struct lu_env *env,
181 struct llog_handle *handle,
182 struct llog_rec_hdr *rec, void *data);
183 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
185 #define CFG_F_START 0x01 /* Set when we start updating from a log */
186 #define CFG_F_MARKER 0x02 /* We are within a maker */
187 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
188 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
190 /* Passed as data param to class_config_parse_llog */
191 struct config_llog_instance {
194 struct super_block *cfg_sb;
195 struct obd_uuid cfg_uuid;
196 llog_cb_t cfg_callback;
197 int cfg_last_idx; /* for partial llog processing */
202 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
203 char *name, struct config_llog_instance *cfg);
205 #define CONFIG_SUB_SPTLRPC 0x01
206 #define CONFIG_SUB_RECOVER 0x02
207 #define CONFIG_SUB_PARAMS 0x04
208 #define CONFIG_SUB_NODEMAP 0x08
209 #define CONFIG_SUB_BARRIER 0x10
211 /* Sub clds should be attached to the config_llog_data when processing
212 * config log for client or server target. */
213 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
215 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
218 #define PARAMS_FILENAME "params"
219 #define BARRIER_FILENAME "barrier"
220 #define LCTL_UPCALL "lctl"
222 static inline bool logname_is_barrier(const char *logname)
226 /* logname for barrier is "fsname-barrier" */
227 ptr = strstr(logname, BARRIER_FILENAME);
228 if (ptr && (ptr - logname) >= 2 &&
229 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
235 /* list of active configuration logs */
236 struct config_llog_data {
237 struct ldlm_res_id cld_resid;
238 struct config_llog_instance cld_cfg;
239 struct list_head cld_list_chain;/* on config_llog_list */
240 atomic_t cld_refcount;
241 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
242 struct config_llog_data *cld_params; /* common parameters log */
243 struct config_llog_data *cld_recover;/* imperative recover log */
244 struct config_llog_data *cld_nodemap;/* nodemap log */
245 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
246 struct obd_export *cld_mgcexp;
247 struct mutex cld_lock;
249 unsigned int cld_stopping:1, /* we were told to stop
251 cld_lostlock:1; /* lock not requeued */
255 struct lustre_profile {
256 struct list_head lp_list;
261 bool lp_list_deleted;
264 struct lustre_profile *class_get_profile(const char * prof);
265 void class_del_profile(const char *prof);
266 void class_put_profile(struct lustre_profile *lprof);
267 void class_del_profiles(void);
270 #if LUSTRE_TRACKS_LOCK_EXP_REFS
272 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
273 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
274 extern void (*class_export_dump_hook)(struct obd_export *);
278 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
279 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
283 #define class_export_rpc_inc(exp) \
285 atomic_inc(&(exp)->exp_rpc_count); \
286 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
287 (exp), atomic_read(&(exp)->exp_rpc_count)); \
290 #define class_export_rpc_dec(exp) \
292 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
293 atomic_dec(&(exp)->exp_rpc_count); \
294 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
295 (exp), atomic_read(&(exp)->exp_rpc_count)); \
298 #define class_export_lock_get(exp, lock) \
300 atomic_inc(&(exp)->exp_locks_count); \
301 __class_export_add_lock_ref(exp, lock); \
302 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
303 (exp), atomic_read(&(exp)->exp_locks_count)); \
304 class_export_get(exp); \
307 #define class_export_lock_put(exp, lock) \
309 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
310 atomic_dec(&(exp)->exp_locks_count); \
311 __class_export_del_lock_ref(exp, lock); \
312 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
313 (exp), atomic_read(&(exp)->exp_locks_count)); \
314 class_export_put(exp); \
317 #define class_export_cb_get(exp) \
319 atomic_inc(&(exp)->exp_cb_count); \
320 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
321 (exp), atomic_read(&(exp)->exp_cb_count)); \
322 class_export_get(exp); \
325 #define class_export_cb_put(exp) \
327 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
328 atomic_dec(&(exp)->exp_cb_count); \
329 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
330 (exp), atomic_read(&(exp)->exp_cb_count)); \
331 class_export_put(exp); \
335 struct obd_export *class_export_get(struct obd_export *exp);
336 void class_export_put(struct obd_export *exp);
337 struct obd_export *class_new_export(struct obd_device *obddev,
338 struct obd_uuid *cluuid);
339 struct obd_export *class_new_export_self(struct obd_device *obd,
340 struct obd_uuid *uuid);
341 void class_unlink_export(struct obd_export *exp);
343 struct obd_import *class_import_get(struct obd_import *);
344 void class_import_put(struct obd_import *);
345 struct obd_import *class_new_import(struct obd_device *obd);
346 void class_destroy_import(struct obd_import *exp);
348 struct obd_type *class_search_type(const char *name);
349 struct obd_type *class_get_type(const char *name);
350 void class_put_type(struct obd_type *type);
351 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
352 struct obd_uuid *cluuid);
353 int class_disconnect(struct obd_export *exp);
354 void class_fail_export(struct obd_export *exp);
355 int class_connected_export(struct obd_export *exp);
356 void class_disconnect_exports(struct obd_device *obddev);
357 int class_manual_cleanup(struct obd_device *obd);
358 void class_disconnect_stale_exports(struct obd_device *,
359 int (*test_export)(struct obd_export *));
360 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
362 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
363 (obd->obd_force ? OBD_OPT_FORCE : 0) |
364 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
368 #ifdef HAVE_SERVER_SUPPORT
369 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
371 LASSERT(exp->exp_obd);
372 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
374 return exp->exp_obd->u.obt.obt_lut;
377 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
379 LASSERT(obd->u.obt.obt_lut);
380 return &obd->u.obt.obt_lut->lut_lsd;
388 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
389 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
391 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
392 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
394 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
395 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
397 /* Ensure obd_setup: used for cleanup which must be called
398 while obd is stopping */
399 #define OBD_CHECK_DEV(obd) \
402 CERROR("NULL device\n"); \
407 /* ensure obd_setup and !obd_stopping */
408 #define OBD_CHECK_DEV_ACTIVE(obd) \
410 OBD_CHECK_DEV(obd); \
411 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
412 CERROR("Device %d not setup\n", \
419 #ifdef CONFIG_PROC_FS
420 #define OBD_COUNTER_OFFSET(op) \
421 ((offsetof(struct obd_ops, o_ ## op) - \
422 offsetof(struct obd_ops, o_iocontrol)) \
423 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
425 /* The '- 1' below is for o_owner. */
426 #define NUM_OBD_STATS \
427 (sizeof(struct obd_ops) / \
428 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
430 #define OBD_COUNTER_INCREMENT(obd, op) \
431 lprocfs_counter_incr((obd)->obd_stats, \
432 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
434 #define EXP_COUNTER_INCREMENT(exp, op) \
437 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
438 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
439 if ((exp)->exp_obd->obd_uses_nid_stats && \
440 (exp)->exp_nid_stats != NULL) \
441 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
445 #define _MD_COUNTER_OFFSET(m_op) \
446 ((offsetof(struct md_ops, m_op) - \
447 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
448 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
450 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
452 #define NUM_MD_STATS \
453 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
454 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
456 /* Note that we only increment md counters for ops whose offset is less
457 * than NUM_MD_STATS. This is explained in a comment in the definition
458 * of struct md_ops. */
459 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
461 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
462 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
463 (exp)->exp_obd->obd_md_cntr_base + \
464 MD_COUNTER_OFFSET(op)); \
468 #define OBD_COUNTER_OFFSET(op)
469 #define OBD_COUNTER_INCREMENT(obd, op)
470 #define EXP_COUNTER_INCREMENT(exp, op)
471 #define EXP_MD_COUNTER_INCREMENT(exp, op)
474 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
476 /* Always add in ldlm_stats */
477 tmp->nid_ldlm_stats =
478 lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC,
479 LPROCFS_STATS_FLAG_NOPERCPU);
480 if (tmp->nid_ldlm_stats == NULL)
483 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
485 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
486 tmp->nid_ldlm_stats);
489 static inline int exp_check_ops(struct obd_export *exp)
494 if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
500 static inline int class_devno_max(void)
502 return MAX_OBD_DEVICES;
505 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
506 __u32 keylen, void *key,
507 __u32 *vallen, void *val)
512 rc = exp_check_ops(exp);
516 if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
517 CERROR("%s: no %s operation\n",
518 (exp)->exp_obd->obd_name, __func__);
521 EXP_COUNTER_INCREMENT(exp, get_info);
523 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
527 static inline int obd_set_info_async(const struct lu_env *env,
528 struct obd_export *exp,
529 __u32 keylen, void *key,
530 __u32 vallen, void *val,
531 struct ptlrpc_request_set *set)
536 rc = exp_check_ops(exp);
540 if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
541 CERROR("%s: no %s operation\n",
542 (exp)->exp_obd->obd_name, __func__);
545 EXP_COUNTER_INCREMENT(exp, set_info_async);
547 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
553 * obd-lu integration.
555 * Functionality is being moved into new lu_device-based layering, but some
556 * pieces of configuration process are still based on obd devices.
558 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
559 * subsume ->o_setup() methods of obd devices they replace. The same for
560 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
561 * result, obd_setup() and obd_process_config() branch and call one XOR
564 * Yet neither lu_device_type_operations::ldto_device_fini() nor
565 * lu_device_type_operations::ldto_device_free() fully implement the
566 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
567 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
569 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
572 struct lu_device_type *ldt = obd->obd_type->typ_lu;
578 struct lu_context session_ctx;
580 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
581 session_ctx.lc_thread = NULL;
582 lu_context_enter(&session_ctx);
584 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
586 env.le_ses = &session_ctx;
587 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
596 lu_context_exit(&session_ctx);
597 lu_context_fini(&session_ctx);
600 if (!obd->obd_type->typ_dt_ops->o_setup) {
601 CERROR("%s: no %s operation\n", obd->obd_name,
605 OBD_COUNTER_INCREMENT(obd, setup);
606 rc = OBP(obd, setup)(obd, cfg);
611 static inline int obd_precleanup(struct obd_device *obd)
614 struct lu_device_type *ldt = obd->obd_type->typ_lu;
615 struct lu_device *d = obd->obd_lu_dev;
619 if (ldt != NULL && d != NULL) {
622 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
624 ldt->ldt_ops->ldto_device_fini(&env, d);
629 if (!obd->obd_type->typ_dt_ops->o_precleanup)
632 OBD_COUNTER_INCREMENT(obd, precleanup);
634 rc = OBP(obd, precleanup)(obd);
638 static inline int obd_cleanup(struct obd_device *obd)
641 struct lu_device_type *ldt = obd->obd_type->typ_lu;
642 struct lu_device *d = obd->obd_lu_dev;
645 if (ldt != NULL && d != NULL) {
648 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
650 ldt->ldt_ops->ldto_device_free(&env, d);
652 obd->obd_lu_dev = NULL;
655 if (!obd->obd_type->typ_dt_ops->o_cleanup)
658 OBD_COUNTER_INCREMENT(obd, cleanup);
660 rc = OBP(obd, cleanup)(obd);
664 static inline void obd_cleanup_client_import(struct obd_device *obd)
668 /* If we set up but never connected, the
669 client import will not have been cleaned. */
670 down_write(&obd->u.cli.cl_sem);
671 if (obd->u.cli.cl_import) {
672 struct obd_import *imp;
673 imp = obd->u.cli.cl_import;
674 CDEBUG(D_CONFIG, "%s: client import never connected\n",
676 ptlrpc_invalidate_import(imp);
677 client_destroy_import(imp);
678 obd->u.cli.cl_import = NULL;
680 up_write(&obd->u.cli.cl_sem);
685 static inline int obd_process_config(struct obd_device *obd, int datalen,
689 struct lu_device_type *ldt = obd->obd_type->typ_lu;
690 struct lu_device *d = obd->obd_lu_dev;
694 obd->obd_process_conf = 1;
695 if (ldt != NULL && d != NULL) {
698 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
700 rc = d->ld_ops->ldo_process_config(&env, d, data);
704 if (!obd->obd_type->typ_dt_ops->o_process_config) {
705 CERROR("%s: no %s operation\n",
706 obd->obd_name, __func__);
709 rc = OBP(obd, process_config)(obd, datalen, data);
711 OBD_COUNTER_INCREMENT(obd, process_config);
712 obd->obd_process_conf = 0;
717 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
723 rc = exp_check_ops(exp);
727 if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
728 CERROR("%s: no %s operation\n",
729 (exp)->exp_obd->obd_name, __func__);
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 rc = exp_check_ops(exp);
748 if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
749 CERROR("%s: no %s operation\n",
750 (exp)->exp_obd->obd_name, __func__);
753 EXP_COUNTER_INCREMENT(exp, destroy);
755 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
759 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
765 rc = exp_check_ops(exp);
769 if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
770 CERROR("%s: no %s operation\n",
771 (exp)->exp_obd->obd_name, __func__);
774 EXP_COUNTER_INCREMENT(exp, getattr);
775 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
780 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
786 rc = exp_check_ops(exp);
790 if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
791 CERROR("%s: no %s operation\n",
792 (exp)->exp_obd->obd_name, __func__);
795 EXP_COUNTER_INCREMENT(exp, setattr);
796 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
801 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
804 struct obd_device *obd = imp->imp_obd;
808 OBD_CHECK_DEV_ACTIVE(obd);
809 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
810 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
813 OBD_COUNTER_INCREMENT(obd, add_conn);
815 rc = OBP(obd, add_conn)(imp, uuid, priority);
819 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
821 struct obd_device *obd = imp->imp_obd;
825 OBD_CHECK_DEV_ACTIVE(obd);
826 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
827 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
830 OBD_COUNTER_INCREMENT(obd, del_conn);
832 rc = OBP(obd, del_conn)(imp, uuid);
836 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
838 struct obd_uuid *uuid;
841 if (!exp->exp_obd->obd_type ||
842 !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
845 EXP_COUNTER_INCREMENT(exp, get_uuid);
847 uuid = OBP(exp->exp_obd, get_uuid)(exp);
851 /** Create a new /a exp on device /a obd for the uuid /a cluuid
852 * @param exp New export handle
853 * @param d Connect data, supported flags are set, flags also understood
854 * by obd are returned.
856 static inline int obd_connect(const struct lu_env *env,
857 struct obd_export **exp,struct obd_device *obd,
858 struct obd_uuid *cluuid,
859 struct obd_connect_data *data,
863 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
867 OBD_CHECK_DEV_ACTIVE(obd);
868 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
869 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
872 OBD_COUNTER_INCREMENT(obd, connect);
874 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
875 /* check that only subset is granted */
876 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
877 data->ocd_connect_flags));
881 static inline int obd_reconnect(const struct lu_env *env,
882 struct obd_export *exp,
883 struct obd_device *obd,
884 struct obd_uuid *cluuid,
885 struct obd_connect_data *d,
889 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
894 OBD_CHECK_DEV_ACTIVE(obd);
895 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
898 OBD_COUNTER_INCREMENT(obd, reconnect);
900 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
901 /* check that only subset is granted */
902 LASSERT(ergo(d != NULL,
903 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
907 static inline int obd_disconnect(struct obd_export *exp)
911 rc = exp_check_ops(exp);
915 if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
916 CERROR("%s: no %s operation\n",
917 (exp)->exp_obd->obd_name, __func__);
920 EXP_COUNTER_INCREMENT(exp, disconnect);
922 rc = OBP(exp->exp_obd, disconnect)(exp);
926 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
927 enum lu_cli_type type)
932 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
934 OBD_COUNTER_INCREMENT(obd, fid_init);
936 rc = OBP(obd, fid_init)(obd, exp, type);
940 static inline int obd_fid_fini(struct obd_device *obd)
944 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
946 OBD_COUNTER_INCREMENT(obd, fid_fini);
948 rc = OBP(obd, fid_fini)(obd);
952 static inline int obd_fid_alloc(const struct lu_env *env,
953 struct obd_export *exp,
955 struct md_op_data *op_data)
959 rc = exp_check_ops(exp);
963 if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
964 CERROR("%s: no %s operation\n",
965 (exp)->exp_obd->obd_name, __func__);
968 EXP_COUNTER_INCREMENT(exp, fid_alloc);
970 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
974 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
979 if (!exp->exp_obd->obd_type ||
980 !exp->exp_obd->obd_type->typ_dt_ops->o_ping)
983 EXP_COUNTER_INCREMENT(exp, ping);
985 rc = OBP(exp->exp_obd, ping)(env, exp);
989 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
994 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
995 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
998 OBD_COUNTER_INCREMENT(obd, pool_new);
1000 rc = OBP(obd, pool_new)(obd, poolname);
1004 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1008 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
1009 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1010 RETURN(-EOPNOTSUPP);
1012 OBD_COUNTER_INCREMENT(obd, pool_del);
1014 rc = OBP(obd, pool_del)(obd, poolname);
1018 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
1024 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
1025 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1026 RETURN(-EOPNOTSUPP);
1028 OBD_COUNTER_INCREMENT(obd, pool_add);
1030 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1034 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
1040 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
1041 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1042 RETURN(-EOPNOTSUPP);
1044 OBD_COUNTER_INCREMENT(obd, pool_rem);
1046 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1050 static inline void obd_getref(struct obd_device *obd)
1053 if (obd->obd_type && OBP(obd, getref)) {
1054 OBD_COUNTER_INCREMENT(obd, getref);
1055 OBP(obd, getref)(obd);
1060 static inline void obd_putref(struct obd_device *obd)
1063 if (obd->obd_type && OBP(obd, putref)) {
1064 OBD_COUNTER_INCREMENT(obd, putref);
1065 OBP(obd, putref)(obd);
1070 static inline int obd_init_export(struct obd_export *exp)
1075 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1076 OBP((exp)->exp_obd, init_export))
1077 rc = OBP(exp->exp_obd, init_export)(exp);
1081 static inline int obd_destroy_export(struct obd_export *exp)
1084 if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1085 OBP(exp->exp_obd, destroy_export))
1086 OBP(exp->exp_obd, destroy_export)(exp);
1090 /* @max_age is the oldest time in seconds that we accept using a cached data.
1091 * If the cache is older than @max_age we will get a new value from the
1092 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1094 static inline int obd_statfs_async(struct obd_export *exp,
1095 struct obd_info *oinfo,
1097 struct ptlrpc_request_set *rqset)
1100 struct obd_device *obd;
1104 if (exp == NULL || exp->exp_obd == NULL)
1108 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1109 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1110 RETURN(-EOPNOTSUPP);
1112 OBD_COUNTER_INCREMENT(obd, statfs);
1114 CDEBUG(D_SUPER, "%s: osfs %p age %lld, max_age %lld\n",
1115 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1116 if (obd->obd_osfs_age < max_age) {
1117 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1120 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1121 obd->obd_name, &obd->obd_osfs,
1122 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1123 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1124 spin_lock(&obd->obd_osfs_lock);
1125 memcpy(oinfo->oi_osfs, &obd->obd_osfs,
1126 sizeof(*oinfo->oi_osfs));
1127 spin_unlock(&obd->obd_osfs_lock);
1128 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1129 if (oinfo->oi_cb_up)
1130 oinfo->oi_cb_up(oinfo, 0);
1135 /* @max_age is the oldest time in seconds that we accept using a cached data.
1136 * If the cache is older than @max_age we will get a new value from the
1137 * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1139 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1140 struct obd_statfs *osfs, time64_t max_age,
1144 struct obd_device *obd = exp->exp_obd;
1150 OBD_CHECK_DEV_ACTIVE(obd);
1152 if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1153 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1154 RETURN(-EOPNOTSUPP);
1156 OBD_COUNTER_INCREMENT(obd, statfs);
1158 CDEBUG(D_SUPER, "osfs %lld, max_age %lld\n",
1159 obd->obd_osfs_age, max_age);
1160 if (obd->obd_osfs_age < max_age) {
1161 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1163 spin_lock(&obd->obd_osfs_lock);
1164 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1165 obd->obd_osfs_age = ktime_get_seconds();
1166 spin_unlock(&obd->obd_osfs_lock);
1169 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu"
1170 " objects %llu/%llu\n",
1171 obd->obd_name, &obd->obd_osfs,
1172 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1173 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1174 spin_lock(&obd->obd_osfs_lock);
1175 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1176 spin_unlock(&obd->obd_osfs_lock);
1181 static inline int obd_preprw(const struct lu_env *env, int cmd,
1182 struct obd_export *exp, struct obdo *oa,
1183 int objcount, struct obd_ioobj *obj,
1184 struct niobuf_remote *remote, int *pages,
1185 struct niobuf_local *local)
1191 rc = exp_check_ops(exp);
1195 if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1196 CERROR("%s: no %s operation\n",
1197 (exp)->exp_obd->obd_name, __func__);
1200 EXP_COUNTER_INCREMENT(exp, preprw);
1201 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1207 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1208 struct obd_export *exp, struct obdo *oa,
1209 int objcount, struct obd_ioobj *obj,
1210 struct niobuf_remote *rnb, int pages,
1211 struct niobuf_local *local, int rc)
1215 rc = exp_check_ops(exp);
1219 if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1220 CERROR("%s: no %s operation\n",
1221 (exp)->exp_obd->obd_name, __func__);
1224 EXP_COUNTER_INCREMENT(exp, commitrw);
1225 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1226 rnb, pages, local, rc);
1231 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1232 int len, void *karg, void __user *uarg)
1237 rc = exp_check_ops(exp);
1241 if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1242 CERROR("%s: no %s operation\n",
1243 (exp)->exp_obd->obd_name, __func__);
1246 EXP_COUNTER_INCREMENT(exp, iocontrol);
1248 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1252 static inline void obd_import_event(struct obd_device *obd,
1253 struct obd_import *imp,
1254 enum obd_import_event event)
1258 CERROR("NULL device\n");
1262 if (obd->obd_set_up && OBP(obd, import_event)) {
1263 OBD_COUNTER_INCREMENT(obd, import_event);
1264 OBP(obd, import_event)(obd, imp, event);
1269 static inline int obd_notify(struct obd_device *obd,
1270 struct obd_device *watched,
1271 enum obd_notify_event ev)
1277 if (!obd->obd_set_up) {
1278 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1282 if (!OBP(obd, notify)) {
1283 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1287 OBD_COUNTER_INCREMENT(obd, notify);
1288 rc = OBP(obd, notify)(obd, watched, ev);
1293 static inline int obd_notify_observer(struct obd_device *observer,
1294 struct obd_device *observed,
1295 enum obd_notify_event ev)
1299 struct obd_notify_upcall *onu;
1301 if (observer->obd_observer)
1302 rc = obd_notify(observer->obd_observer, observed, ev);
1305 * Also, call non-obd listener, if any
1307 onu = &observer->obd_upcall;
1308 if (onu->onu_upcall != NULL)
1309 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1311 return rc ? rc : rc2;
1314 static inline int obd_quotactl(struct obd_export *exp,
1315 struct obd_quotactl *oqctl)
1320 rc = exp_check_ops(exp);
1324 if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1325 CERROR("%s: no %s operation\n",
1326 (exp)->exp_obd->obd_name, __func__);
1329 EXP_COUNTER_INCREMENT(exp, quotactl);
1331 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1335 static inline int obd_health_check(const struct lu_env *env,
1336 struct obd_device *obd)
1338 /* returns: 0 on healthy
1339 * >0 on unhealthy + reason code/flag
1340 * however the only suppored reason == 1 right now
1341 * We'll need to define some better reasons
1342 * or flags in the future.
1349 /* NULL method is normal here */
1350 if (obd == NULL || !obd->obd_type) {
1351 CERROR("cleaned up obd\n");
1352 RETURN(-EOPNOTSUPP);
1354 if (!obd->obd_set_up || obd->obd_stopping)
1356 if (!OBP(obd, health_check))
1359 rc = OBP(obd, health_check)(env, obd);
1363 static inline int obd_register_observer(struct obd_device *obd,
1364 struct obd_device *observer)
1368 down_write(&obd->obd_observer_link_sem);
1369 if (obd->obd_observer && observer) {
1370 up_write(&obd->obd_observer_link_sem);
1373 obd->obd_observer = observer;
1374 up_write(&obd->obd_observer_link_sem);
1378 /* metadata helpers */
1379 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1385 rc = exp_check_ops(exp);
1388 EXP_MD_COUNTER_INCREMENT(exp, get_root);
1389 rc = MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1394 static inline int md_getattr(struct obd_export *exp,
1395 struct md_op_data *op_data,
1396 struct ptlrpc_request **request)
1401 rc = exp_check_ops(exp);
1404 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1405 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1409 static inline int md_null_inode(struct obd_export *exp,
1410 const struct lu_fid *fid)
1414 rc = exp_check_ops(exp);
1417 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1418 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1422 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1423 struct md_open_data *mod,
1424 struct ptlrpc_request **request)
1428 rc = exp_check_ops(exp);
1431 EXP_MD_COUNTER_INCREMENT(exp, close);
1432 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1436 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1437 const void *data, size_t datalen, umode_t mode,
1438 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1439 __u64 rdev, struct ptlrpc_request **request)
1443 rc = exp_check_ops(exp);
1446 EXP_MD_COUNTER_INCREMENT(exp, create);
1447 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1448 uid, gid, cap_effective, rdev, request);
1452 static inline int md_enqueue(struct obd_export *exp,
1453 struct ldlm_enqueue_info *einfo,
1454 const union ldlm_policy_data *policy,
1455 struct md_op_data *op_data,
1456 struct lustre_handle *lockh,
1457 __u64 extra_lock_flags)
1461 rc = exp_check_ops(exp);
1464 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1465 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1470 static inline int md_getattr_name(struct obd_export *exp,
1471 struct md_op_data *op_data,
1472 struct ptlrpc_request **request)
1476 rc = exp_check_ops(exp);
1479 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1480 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1484 static inline int md_intent_lock(struct obd_export *exp,
1485 struct md_op_data *op_data,
1486 struct lookup_intent *it,
1487 struct ptlrpc_request **reqp,
1488 ldlm_blocking_callback cb_blocking,
1489 __u64 extra_lock_flags)
1493 rc = exp_check_ops(exp);
1496 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1497 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1502 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1503 struct ptlrpc_request **request)
1507 rc = exp_check_ops(exp);
1510 EXP_MD_COUNTER_INCREMENT(exp, link);
1511 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1515 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1516 const char *old, size_t oldlen, const char *new,
1517 size_t newlen, struct ptlrpc_request **request)
1521 rc = exp_check_ops(exp);
1525 EXP_MD_COUNTER_INCREMENT(exp, rename);
1526 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1531 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1532 void *ea, size_t ealen,
1533 struct ptlrpc_request **request)
1537 rc = exp_check_ops(exp);
1541 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1542 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1546 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1547 struct ptlrpc_request **request)
1552 rc = exp_check_ops(exp);
1556 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1557 rc = MDP(exp->exp_obd, fsync)(exp, fid, request);
1562 /* FLR: resync mirrored files. */
1563 static inline int md_file_resync(struct obd_export *exp,
1564 struct md_op_data *data)
1569 rc = exp_check_ops(exp);
1573 EXP_MD_COUNTER_INCREMENT(exp, file_resync);
1574 rc = MDP(exp->exp_obd, file_resync)(exp, data);
1579 static inline int md_read_page(struct obd_export *exp,
1580 struct md_op_data *op_data,
1581 struct md_callback *cb_op,
1583 struct page **ppage)
1587 rc = exp_check_ops(exp);
1591 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1592 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1597 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1598 struct ptlrpc_request **request)
1602 rc = exp_check_ops(exp);
1606 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1607 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1611 static inline int md_get_lustre_md(struct obd_export *exp,
1612 struct ptlrpc_request *req,
1613 struct obd_export *dt_exp,
1614 struct obd_export *md_exp,
1615 struct lustre_md *md)
1619 rc = exp_check_ops(exp);
1623 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1624 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1627 static inline int md_free_lustre_md(struct obd_export *exp,
1628 struct lustre_md *md)
1632 rc = exp_check_ops(exp);
1635 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1636 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1639 static inline int md_merge_attr(struct obd_export *exp,
1640 const struct lmv_stripe_md *lsm,
1641 struct cl_attr *attr,
1642 ldlm_blocking_callback cb)
1646 rc = exp_check_ops(exp);
1649 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1650 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1653 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1654 u64 obd_md_valid, const char *name,
1655 const void *value, size_t value_size,
1656 unsigned int xattr_flags, u32 suppgid,
1657 struct ptlrpc_request **req)
1662 rc = exp_check_ops(exp);
1665 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1666 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, obd_md_valid, name,
1667 value, value_size, xattr_flags,
1671 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1672 u64 obd_md_valid, const char *name,
1673 size_t buf_size, struct ptlrpc_request **req)
1677 rc = exp_check_ops(exp);
1680 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1681 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, obd_md_valid, name,
1685 static inline int md_set_open_replay_data(struct obd_export *exp,
1686 struct obd_client_handle *och,
1687 struct lookup_intent *it)
1691 rc = exp_check_ops(exp);
1694 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1695 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1698 static inline int md_clear_open_replay_data(struct obd_export *exp,
1699 struct obd_client_handle *och)
1703 rc = exp_check_ops(exp);
1706 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1707 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1710 static inline int md_set_lock_data(struct obd_export *exp,
1711 const struct lustre_handle *lockh,
1712 void *data, __u64 *bits)
1716 rc = exp_check_ops(exp);
1719 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1720 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1724 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1725 union ldlm_policy_data *policy, enum ldlm_mode mode,
1726 enum ldlm_cancel_flags cancel_flags, void *opaque)
1731 rc = exp_check_ops(exp);
1734 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1736 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1737 cancel_flags, opaque);
1741 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1742 const struct lu_fid *fid,
1743 enum ldlm_type type,
1744 union ldlm_policy_data *policy,
1745 enum ldlm_mode mode,
1746 struct lustre_handle *lockh)
1750 rc = exp_check_ops(exp);
1753 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1754 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1755 policy, mode, lockh));
1758 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1763 rc = exp_check_ops(exp);
1766 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1767 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
1770 static inline int md_intent_getattr_async(struct obd_export *exp,
1771 struct md_enqueue_info *minfo)
1775 rc = exp_check_ops(exp);
1778 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1779 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1783 static inline int md_revalidate_lock(struct obd_export *exp,
1784 struct lookup_intent *it,
1785 struct lu_fid *fid, __u64 *bits)
1789 rc = exp_check_ops(exp);
1792 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1793 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1797 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1798 const struct lmv_stripe_md *lsm,
1799 const char *name, int namelen,
1804 rc = exp_check_ops(exp);
1807 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1808 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1813 /* Unpack an MD struct from disk to in-memory format.
1814 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1816 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1817 * If *plsm == NULL then it will be allocated.
1819 static inline int md_unpackmd(struct obd_export *exp,
1820 struct lmv_stripe_md **plsm,
1821 const union lmv_mds_md *lmm, size_t lmm_size)
1825 rc = exp_check_ops(exp);
1828 EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
1829 rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1833 /* OBD Metadata Support */
1835 extern int obd_init_caches(void);
1836 extern void obd_cleanup_caches(void);
1838 /* support routines */
1839 extern struct kmem_cache *obdo_cachep;
1841 #define OBDO_ALLOC(ptr) \
1843 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1846 #define OBDO_FREE(ptr) \
1848 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1852 typedef int (*register_lwp_cb)(void *data);
1854 struct lwp_register_item {
1855 struct obd_export **lri_exp;
1856 register_lwp_cb lri_cb_func;
1858 struct list_head lri_list;
1860 char lri_name[MTI_NAME_MAXLEN];
1863 /* I'm as embarrassed about this as you are.
1865 * <shaver> // XXX do not look into _superhack with remaining eye
1866 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1867 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1870 #ifdef HAVE_SERVER_SUPPORT
1871 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1872 register_lwp_cb cb_func, void *cb_data);
1873 void lustre_deregister_lwp_item(struct obd_export **exp);
1874 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1875 void lustre_notify_lwp_list(struct obd_export *exp);
1876 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1877 #endif /* HAVE_SERVER_SUPPORT */
1878 int lustre_register_fs(void);
1879 int lustre_unregister_fs(void);
1880 int lustre_check_exclusion(struct super_block *sb, char *svname);
1882 typedef __u8 class_uuid_t[16];
1883 static inline void class_uuid_unparse(class_uuid_t uu, struct obd_uuid *out)
1885 snprintf(out->uuid, sizeof(out->uuid), "%02x%02x%02x%02x-%02x%02x-"
1886 "%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1887 uu[14], uu[15], uu[12], uu[13], uu[10], uu[11], uu[8], uu[9],
1888 uu[6], uu[7], uu[4], uu[5], uu[2], uu[3], uu[0], uu[1]);
1892 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1893 int class_add_uuid(const char *uuid, __u64 nid);
1894 int class_del_uuid (const char *uuid);
1895 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1898 extern char obd_jobid_name[];
1901 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1905 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1906 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1908 /* root squash info */
1909 struct rw_semaphore;
1910 struct root_squash_info {
1913 struct list_head rsi_nosquash_nids;
1914 struct rw_semaphore rsi_sem;
1917 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1919 /* linux-module.c */
1920 extern struct miscdevice obd_psdev;
1921 int obd_ioctl_getdata(char **buf, int *len, void __user *arg);
1922 int class_procfs_init(void);
1923 int class_procfs_clean(void);
1924 #endif /* __LINUX_OBD_CLASS_H */