1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36#ifndef __CLASS_OBD_H
37#define __CLASS_OBD_H
38
39#include "obd_support.h"
40#include "lustre_import.h"
41#include "lustre_net.h"
42#include "obd.h"
43#include "lustre_lib.h"
44#include "lustre/lustre_idl.h"
45#include "lprocfs_status.h"
46
47#define OBD_STATFS_NODELAY 0x0001
48
49
50#define OBD_STATFS_FROM_CACHE 0x0002
51
52
53#define OBD_STATFS_PTLRPCD 0x0004
54
55
56
57
58
59
60#define OBD_STATFS_FOR_MDT0 0x0008
61
62
63#define OBD_FL_PUNCH 0x00000001
64
65
66extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
67extern rwlock_t obd_dev_lock;
68
69
70struct obd_device *class_exp2obd(struct obd_export *);
71int class_handle_ioctl(unsigned int cmd, unsigned long arg);
72int lustre_get_jobid(char *jobid);
73
74struct lu_device_type;
75
76
77extern struct list_head obd_types;
78struct obd_export *class_conn2export(struct lustre_handle *);
79int class_register_type(struct obd_ops *, struct md_ops *,
80 const char *nm, struct lu_device_type *ldt);
81int class_unregister_type(const char *nm);
82
83struct obd_device *class_newdev(const char *type_name, const char *name);
84void class_release_dev(struct obd_device *obd);
85
86int class_name2dev(const char *name);
87struct obd_device *class_name2obd(const char *name);
88int class_uuid2dev(struct obd_uuid *uuid);
89struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
90 const char *typ_name,
91 struct obd_uuid *grp_uuid);
92struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid,
93 int *next);
94struct obd_device *class_num2obd(int num);
95
96int class_notify_sptlrpc_conf(const char *fsname, int namelen);
97
98int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
99
100int obd_zombie_impexp_init(void);
101void obd_zombie_impexp_stop(void);
102void obd_zombie_barrier(void);
103
104struct llog_handle;
105struct llog_rec_hdr;
106typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
107 struct llog_rec_hdr *, void *);
108
109int class_process_config(struct lustre_cfg *lcfg);
110int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
111 struct lustre_cfg *lcfg, void *data);
112struct obd_device *class_incref(struct obd_device *obd,
113 const char *scope, const void *source);
114void class_decref(struct obd_device *obd,
115 const char *scope, const void *source);
116int class_config_llog_handler(const struct lu_env *env,
117 struct llog_handle *handle,
118 struct llog_rec_hdr *rec, void *data);
119int class_add_uuid(const char *uuid, __u64 nid);
120
121
122void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
123
124#define CFG_F_START 0x01
125#define CFG_F_MARKER 0x02
126#define CFG_F_SKIP 0x04
127#define CFG_F_COMPAT146 0x08
128#define CFG_F_EXCLUDE 0x10
129
130
131struct config_llog_instance {
132 char *cfg_obdname;
133 void *cfg_instance;
134 struct super_block *cfg_sb;
135 struct obd_uuid cfg_uuid;
136 llog_cb_t cfg_callback;
137 int cfg_last_idx;
138 int cfg_flags;
139};
140
141int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
142 char *name, struct config_llog_instance *cfg);
143enum {
144 CONFIG_T_CONFIG = 0,
145 CONFIG_T_SPTLRPC = 1,
146 CONFIG_T_RECOVER = 2,
147 CONFIG_T_PARAMS = 3,
148 CONFIG_T_MAX = 4
149};
150
151#define PARAMS_FILENAME "params"
152#define LCTL_UPCALL "lctl"
153
154
155struct config_llog_data {
156 struct ldlm_res_id cld_resid;
157 struct config_llog_instance cld_cfg;
158 struct list_head cld_list_chain;
159 atomic_t cld_refcount;
160 struct config_llog_data *cld_sptlrpc;
161 struct config_llog_data *cld_params;
162 struct config_llog_data *cld_recover;
163 struct obd_export *cld_mgcexp;
164 struct mutex cld_lock;
165 int cld_type;
166 unsigned int cld_stopping:1,
167
168
169 cld_lostlock:1;
170 char cld_logname[0];
171};
172
173struct lustre_profile {
174 struct list_head lp_list;
175 char *lp_profile;
176 char *lp_dt;
177 char *lp_md;
178};
179
180struct lustre_profile *class_get_profile(const char *prof);
181void class_del_profile(const char *prof);
182void class_del_profiles(void);
183
184#if LUSTRE_TRACKS_LOCK_EXP_REFS
185
186void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
187void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
188extern void (*class_export_dump_hook)(struct obd_export *);
189
190#else
191
192#define __class_export_add_lock_ref(exp, lock) do {} while (0)
193#define __class_export_del_lock_ref(exp, lock) do {} while (0)
194
195#endif
196
197
198struct obd_export *class_export_get(struct obd_export *exp);
199void class_export_put(struct obd_export *exp);
200struct obd_export *class_new_export(struct obd_device *obddev,
201 struct obd_uuid *cluuid);
202void class_unlink_export(struct obd_export *exp);
203
204struct obd_import *class_import_get(struct obd_import *);
205void class_import_put(struct obd_import *);
206struct obd_import *class_new_import(struct obd_device *obd);
207void class_destroy_import(struct obd_import *exp);
208
209void class_put_type(struct obd_type *type);
210int class_connect(struct lustre_handle *conn, struct obd_device *obd,
211 struct obd_uuid *cluuid);
212int class_disconnect(struct obd_export *exp);
213void class_fail_export(struct obd_export *exp);
214int class_manual_cleanup(struct obd_device *obd);
215
216static inline void class_export_rpc_inc(struct obd_export *exp)
217{
218 atomic_inc(&(exp)->exp_rpc_count);
219 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n",
220 (exp), atomic_read(&(exp)->exp_rpc_count));
221}
222
223static inline void class_export_rpc_dec(struct obd_export *exp)
224{
225 LASSERT_ATOMIC_POS(&exp->exp_rpc_count);
226 atomic_dec(&(exp)->exp_rpc_count);
227 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n",
228 (exp), atomic_read(&(exp)->exp_rpc_count));
229}
230
231static inline struct obd_export *class_export_lock_get(struct obd_export *exp,
232 struct ldlm_lock *lock)
233{
234 atomic_inc(&(exp)->exp_locks_count);
235 __class_export_add_lock_ref(exp, lock);
236 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n",
237 (exp), atomic_read(&(exp)->exp_locks_count));
238 return class_export_get(exp);
239}
240
241static inline void class_export_lock_put(struct obd_export *exp,
242 struct ldlm_lock *lock)
243{
244 LASSERT_ATOMIC_POS(&exp->exp_locks_count);
245 atomic_dec(&(exp)->exp_locks_count);
246 __class_export_del_lock_ref(exp, lock);
247 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n",
248 (exp), atomic_read(&(exp)->exp_locks_count));
249 class_export_put(exp);
250}
251
252static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
253{
254 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
255 (obd->obd_force ? OBD_OPT_FORCE : 0) |
256 0);
257}
258
259static inline int lprocfs_climp_check(struct obd_device *obd)
260{
261 down_read(&(obd)->u.cli.cl_sem);
262 if (!(obd)->u.cli.cl_import) {
263 up_read(&(obd)->u.cli.cl_sem);
264 return -ENODEV;
265 }
266 return 0;
267}
268
269struct inode;
270struct lu_attr;
271struct obdo;
272void obdo_refresh_inode(struct inode *dst, struct obdo *src, u32 valid);
273
274void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
275void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, u32 valid);
276
277#define OBT(dev) (dev)->obd_type
278#define OBP(dev, op) (dev)->obd_type->typ_dt_ops->op
279#define MDP(dev, op) (dev)->obd_type->typ_md_ops->op
280#define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
281
282
283
284
285static inline int obd_check_dev(struct obd_device *obd)
286{
287 if (!obd) {
288 CERROR("NULL device\n");
289 return -ENODEV;
290 }
291 return 0;
292}
293
294
295static inline int obd_check_dev_active(struct obd_device *obd)
296{
297 int rc;
298
299 rc = obd_check_dev(obd);
300 if (rc)
301 return rc;
302 if (!obd->obd_set_up || obd->obd_stopping) {
303 CERROR("Device %d not setup\n", obd->obd_minor);
304 return -ENODEV;
305 }
306 return rc;
307}
308
309#define OBD_COUNTER_OFFSET(op) \
310 ((offsetof(struct obd_ops, op) - \
311 offsetof(struct obd_ops, iocontrol)) \
312 / sizeof(((struct obd_ops *)(0))->iocontrol))
313
314#define OBD_COUNTER_INCREMENT(obdx, op) \
315 if ((obdx)->obd_stats) { \
316 unsigned int coffset; \
317 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
318 OBD_COUNTER_OFFSET(op); \
319 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
320 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
321 }
322
323#define EXP_COUNTER_INCREMENT(export, op) \
324 if ((export)->exp_obd->obd_stats) { \
325 unsigned int coffset; \
326 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
327 OBD_COUNTER_OFFSET(op); \
328 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
329 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
330 }
331
332#define MD_COUNTER_OFFSET(op) \
333 ((offsetof(struct md_ops, op) - \
334 offsetof(struct md_ops, getstatus)) \
335 / sizeof(((struct md_ops *)(0))->getstatus))
336
337#define MD_COUNTER_INCREMENT(obdx, op) \
338 if ((obd)->md_stats) { \
339 unsigned int coffset; \
340 coffset = (unsigned int)((obdx)->md_cntr_base) + \
341 MD_COUNTER_OFFSET(op); \
342 LASSERT(coffset < (obdx)->md_stats->ls_num); \
343 lprocfs_counter_incr((obdx)->md_stats, coffset); \
344 }
345
346#define EXP_MD_COUNTER_INCREMENT(export, op) \
347 if ((export)->exp_obd->obd_stats) { \
348 unsigned int coffset; \
349 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
350 MD_COUNTER_OFFSET(op); \
351 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
352 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
353 if ((export)->exp_md_stats) \
354 lprocfs_counter_incr( \
355 (export)->exp_md_stats, coffset); \
356 }
357
358#define EXP_CHECK_MD_OP(exp, op) \
359do { \
360 if (!(exp)) { \
361 CERROR("obd_" #op ": NULL export\n"); \
362 return -ENODEV; \
363 } \
364 if (!(exp)->exp_obd || !OBT((exp)->exp_obd)) { \
365 CERROR("obd_" #op ": cleaned up obd\n"); \
366 return -EOPNOTSUPP; \
367 } \
368 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
369 CERROR("obd_" #op ": dev %s/%d no operation\n", \
370 (exp)->exp_obd->obd_name, \
371 (exp)->exp_obd->obd_minor); \
372 return -EOPNOTSUPP; \
373 } \
374} while (0)
375
376#define OBD_CHECK_DT_OP(obd, op, err) \
377do { \
378 if (!OBT(obd) || !OBP((obd), op)) { \
379 if (err) \
380 CERROR("obd_" #op ": dev %d no operation\n", \
381 obd->obd_minor); \
382 return err; \
383 } \
384} while (0)
385
386#define EXP_CHECK_DT_OP(exp, op) \
387do { \
388 if (!(exp)) { \
389 CERROR("obd_" #op ": NULL export\n"); \
390 return -ENODEV; \
391 } \
392 if (!(exp)->exp_obd || !OBT((exp)->exp_obd)) { \
393 CERROR("obd_" #op ": cleaned up obd\n"); \
394 return -EOPNOTSUPP; \
395 } \
396 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
397 CERROR("obd_" #op ": dev %d no operation\n", \
398 (exp)->exp_obd->obd_minor); \
399 return -EOPNOTSUPP; \
400 } \
401} while (0)
402
403#define CTXT_CHECK_OP(ctxt, op, err) \
404do { \
405 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
406 if (err) \
407 CERROR("lop_" #op ": dev %d no operation\n", \
408 ctxt->loc_obd->obd_minor); \
409 return err; \
410 } \
411} while (0)
412
413static inline int class_devno_max(void)
414{
415 return MAX_OBD_DEVICES;
416}
417
418static inline int obd_get_info(const struct lu_env *env,
419 struct obd_export *exp, __u32 keylen,
420 void *key, __u32 *vallen, void *val,
421 struct lov_stripe_md *lsm)
422{
423 int rc;
424
425 EXP_CHECK_DT_OP(exp, get_info);
426 EXP_COUNTER_INCREMENT(exp, get_info);
427
428 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val,
429 lsm);
430 return rc;
431}
432
433static inline int obd_set_info_async(const struct lu_env *env,
434 struct obd_export *exp, u32 keylen,
435 void *key, u32 vallen, void *val,
436 struct ptlrpc_request_set *set)
437{
438 int rc;
439
440 EXP_CHECK_DT_OP(exp, set_info_async);
441 EXP_COUNTER_INCREMENT(exp, set_info_async);
442
443 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
444 val, set);
445 return rc;
446}
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466#define DECLARE_LU_VARS(ldt, d) \
467 struct lu_device_type *ldt; \
468 struct lu_device *d
469
470static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
471{
472 int rc;
473 DECLARE_LU_VARS(ldt, d);
474
475 ldt = obd->obd_type->typ_lu;
476 if (ldt) {
477 struct lu_context session_ctx;
478 struct lu_env env;
479
480 lu_context_init(&session_ctx, LCT_SESSION);
481 session_ctx.lc_thread = NULL;
482 lu_context_enter(&session_ctx);
483
484 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
485 if (rc == 0) {
486 env.le_ses = &session_ctx;
487 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
488 lu_env_fini(&env);
489 if (!IS_ERR(d)) {
490 obd->obd_lu_dev = d;
491 d->ld_obd = obd;
492 rc = 0;
493 } else
494 rc = PTR_ERR(d);
495 }
496 lu_context_exit(&session_ctx);
497 lu_context_fini(&session_ctx);
498
499 } else {
500 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
501 OBD_COUNTER_INCREMENT(obd, setup);
502 rc = OBP(obd, setup)(obd, cfg);
503 }
504 return rc;
505}
506
507static inline int obd_precleanup(struct obd_device *obd,
508 enum obd_cleanup_stage cleanup_stage)
509{
510 int rc;
511 DECLARE_LU_VARS(ldt, d);
512
513 rc = obd_check_dev(obd);
514 if (rc)
515 return rc;
516 ldt = obd->obd_type->typ_lu;
517 d = obd->obd_lu_dev;
518 if (ldt && d) {
519 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
520 struct lu_env env;
521
522 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
523 if (rc == 0) {
524 ldt->ldt_ops->ldto_device_fini(&env, d);
525 lu_env_fini(&env);
526 }
527 }
528 }
529 OBD_CHECK_DT_OP(obd, precleanup, 0);
530 OBD_COUNTER_INCREMENT(obd, precleanup);
531
532 rc = OBP(obd, precleanup)(obd, cleanup_stage);
533 return rc;
534}
535
536static inline int obd_cleanup(struct obd_device *obd)
537{
538 int rc;
539 DECLARE_LU_VARS(ldt, d);
540
541 rc = obd_check_dev(obd);
542 if (rc)
543 return rc;
544
545 ldt = obd->obd_type->typ_lu;
546 d = obd->obd_lu_dev;
547 if (ldt && d) {
548 struct lu_env env;
549
550 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
551 if (rc == 0) {
552 ldt->ldt_ops->ldto_device_free(&env, d);
553 lu_env_fini(&env);
554 obd->obd_lu_dev = NULL;
555 }
556 }
557 OBD_CHECK_DT_OP(obd, cleanup, 0);
558 OBD_COUNTER_INCREMENT(obd, cleanup);
559
560 rc = OBP(obd, cleanup)(obd);
561 return rc;
562}
563
564static inline void obd_cleanup_client_import(struct obd_device *obd)
565{
566
567
568
569 down_write(&obd->u.cli.cl_sem);
570 if (obd->u.cli.cl_import) {
571 struct obd_import *imp;
572
573 imp = obd->u.cli.cl_import;
574 CDEBUG(D_CONFIG, "%s: client import never connected\n",
575 obd->obd_name);
576 ptlrpc_invalidate_import(imp);
577 client_destroy_import(imp);
578 obd->u.cli.cl_import = NULL;
579 }
580 up_write(&obd->u.cli.cl_sem);
581}
582
583static inline int
584obd_process_config(struct obd_device *obd, int datalen, void *data)
585{
586 int rc;
587 DECLARE_LU_VARS(ldt, d);
588
589 rc = obd_check_dev(obd);
590 if (rc)
591 return rc;
592
593 obd->obd_process_conf = 1;
594 ldt = obd->obd_type->typ_lu;
595 d = obd->obd_lu_dev;
596 if (ldt && d) {
597 struct lu_env env;
598
599 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
600 if (rc == 0) {
601 rc = d->ld_ops->ldo_process_config(&env, d, data);
602 lu_env_fini(&env);
603 }
604 } else {
605 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
606 rc = OBP(obd, process_config)(obd, datalen, data);
607 }
608 OBD_COUNTER_INCREMENT(obd, process_config);
609 obd->obd_process_conf = 0;
610
611 return rc;
612}
613
614
615
616
617
618
619
620
621static inline int obd_packmd(struct obd_export *exp,
622 struct lov_mds_md **disk_tgt,
623 struct lov_stripe_md *mem_src)
624{
625 int rc;
626
627 EXP_CHECK_DT_OP(exp, packmd);
628 EXP_COUNTER_INCREMENT(exp, packmd);
629
630 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
631 return rc;
632}
633
634static inline int obd_size_diskmd(struct obd_export *exp,
635 struct lov_stripe_md *mem_src)
636{
637 return obd_packmd(exp, NULL, mem_src);
638}
639
640static inline int obd_free_diskmd(struct obd_export *exp,
641 struct lov_mds_md **disk_tgt)
642{
643 LASSERT(disk_tgt);
644 LASSERT(*disk_tgt);
645
646
647
648
649
650
651 if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
652 (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) ||
653 ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3)))
654 lustre_swab_lov_mds_md(*disk_tgt);
655 return obd_packmd(exp, disk_tgt, NULL);
656}
657
658
659
660
661
662
663
664
665static inline int obd_unpackmd(struct obd_export *exp,
666 struct lov_stripe_md **mem_tgt,
667 struct lov_mds_md *disk_src,
668 int disk_len)
669{
670 int rc;
671
672 EXP_CHECK_DT_OP(exp, unpackmd);
673 EXP_COUNTER_INCREMENT(exp, unpackmd);
674
675 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
676 return rc;
677}
678
679
680static inline int obd_alloc_memmd(struct obd_export *exp,
681 struct lov_stripe_md **mem_tgt)
682{
683 LASSERT(mem_tgt);
684 LASSERT(!*mem_tgt);
685 return obd_unpackmd(exp, mem_tgt, NULL, 0);
686}
687
688static inline int obd_free_memmd(struct obd_export *exp,
689 struct lov_stripe_md **mem_tgt)
690{
691 int rc;
692
693 LASSERT(mem_tgt);
694 LASSERT(*mem_tgt);
695 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
696 *mem_tgt = NULL;
697 return rc;
698}
699
700static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
701 struct obdo *obdo, struct lov_stripe_md **ea,
702 struct obd_trans_info *oti)
703{
704 int rc;
705
706 EXP_CHECK_DT_OP(exp, create);
707 EXP_COUNTER_INCREMENT(exp, create);
708
709 rc = OBP(exp->exp_obd, create)(env, exp, obdo, ea, oti);
710 return rc;
711}
712
713static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
714 struct obdo *obdo, struct lov_stripe_md *ea,
715 struct obd_trans_info *oti,
716 struct obd_export *md_exp)
717{
718 int rc;
719
720 EXP_CHECK_DT_OP(exp, destroy);
721 EXP_COUNTER_INCREMENT(exp, destroy);
722
723 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp);
724 return rc;
725}
726
727static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
728 struct obd_info *oinfo)
729{
730 int rc;
731
732 EXP_CHECK_DT_OP(exp, getattr);
733 EXP_COUNTER_INCREMENT(exp, getattr);
734
735 rc = OBP(exp->exp_obd, getattr)(env, exp, oinfo);
736 return rc;
737}
738
739static inline int obd_getattr_async(struct obd_export *exp,
740 struct obd_info *oinfo,
741 struct ptlrpc_request_set *set)
742{
743 int rc;
744
745 EXP_CHECK_DT_OP(exp, getattr_async);
746 EXP_COUNTER_INCREMENT(exp, getattr_async);
747
748 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
749 return rc;
750}
751
752static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
753 struct obd_info *oinfo,
754 struct obd_trans_info *oti)
755{
756 int rc;
757
758 EXP_CHECK_DT_OP(exp, setattr);
759 EXP_COUNTER_INCREMENT(exp, setattr);
760
761 rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti);
762 return rc;
763}
764
765
766static inline int obd_setattr_rqset(struct obd_export *exp,
767 struct obd_info *oinfo,
768 struct obd_trans_info *oti)
769{
770 struct ptlrpc_request_set *set = NULL;
771 int rc;
772
773 EXP_CHECK_DT_OP(exp, setattr_async);
774 EXP_COUNTER_INCREMENT(exp, setattr_async);
775
776 set = ptlrpc_prep_set();
777 if (!set)
778 return -ENOMEM;
779
780 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
781 if (rc == 0)
782 rc = ptlrpc_set_wait(set);
783 ptlrpc_set_destroy(set);
784 return rc;
785}
786
787
788
789
790static inline int obd_setattr_async(struct obd_export *exp,
791 struct obd_info *oinfo,
792 struct obd_trans_info *oti,
793 struct ptlrpc_request_set *set)
794{
795 int rc;
796
797 EXP_CHECK_DT_OP(exp, setattr_async);
798 EXP_COUNTER_INCREMENT(exp, setattr_async);
799
800 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
801 return rc;
802}
803
804static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
805 int priority)
806{
807 struct obd_device *obd = imp->imp_obd;
808 int rc;
809
810 rc = obd_check_dev_active(obd);
811 if (rc)
812 return rc;
813 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
814 OBD_COUNTER_INCREMENT(obd, add_conn);
815
816 rc = OBP(obd, add_conn)(imp, uuid, priority);
817 return rc;
818}
819
820static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
821{
822 struct obd_device *obd = imp->imp_obd;
823 int rc;
824
825 rc = obd_check_dev_active(obd);
826 if (rc)
827 return rc;
828 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
829 OBD_COUNTER_INCREMENT(obd, del_conn);
830
831 rc = OBP(obd, del_conn)(imp, uuid);
832 return rc;
833}
834
835static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
836{
837 struct obd_uuid *uuid;
838
839 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
840 EXP_COUNTER_INCREMENT(exp, get_uuid);
841
842 uuid = OBP(exp->exp_obd, get_uuid)(exp);
843 return uuid;
844}
845
846
847
848
849
850
851static inline int obd_connect(const struct lu_env *env,
852 struct obd_export **exp, struct obd_device *obd,
853 struct obd_uuid *cluuid,
854 struct obd_connect_data *data,
855 void *localdata)
856{
857 int rc;
858 __u64 ocf = data ? data->ocd_connect_flags : 0;
859
860
861
862 rc = obd_check_dev_active(obd);
863 if (rc)
864 return rc;
865 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
866 OBD_COUNTER_INCREMENT(obd, connect);
867
868 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
869
870 LASSERT(ergo(data, (data->ocd_connect_flags & ocf) ==
871 data->ocd_connect_flags));
872 return rc;
873}
874
875static inline int obd_reconnect(const struct lu_env *env,
876 struct obd_export *exp,
877 struct obd_device *obd,
878 struct obd_uuid *cluuid,
879 struct obd_connect_data *d,
880 void *localdata)
881{
882 int rc;
883 __u64 ocf = d ? d->ocd_connect_flags : 0;
884
885 rc = obd_check_dev_active(obd);
886 if (rc)
887 return rc;
888 OBD_CHECK_DT_OP(obd, reconnect, 0);
889 OBD_COUNTER_INCREMENT(obd, reconnect);
890
891 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
892
893 LASSERT(ergo(d, (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
894 return rc;
895}
896
897static inline int obd_disconnect(struct obd_export *exp)
898{
899 int rc;
900
901 EXP_CHECK_DT_OP(exp, disconnect);
902 EXP_COUNTER_INCREMENT(exp, disconnect);
903
904 rc = OBP(exp->exp_obd, disconnect)(exp);
905 return rc;
906}
907
908static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
909 enum lu_cli_type type)
910{
911 int rc;
912
913 OBD_CHECK_DT_OP(obd, fid_init, 0);
914 OBD_COUNTER_INCREMENT(obd, fid_init);
915
916 rc = OBP(obd, fid_init)(obd, exp, type);
917 return rc;
918}
919
920static inline int obd_fid_fini(struct obd_device *obd)
921{
922 int rc;
923
924 OBD_CHECK_DT_OP(obd, fid_fini, 0);
925 OBD_COUNTER_INCREMENT(obd, fid_fini);
926
927 rc = OBP(obd, fid_fini)(obd);
928 return rc;
929}
930
931static inline int obd_fid_alloc(struct obd_export *exp,
932 struct lu_fid *fid,
933 struct md_op_data *op_data)
934{
935 int rc;
936
937 EXP_CHECK_DT_OP(exp, fid_alloc);
938 EXP_COUNTER_INCREMENT(exp, fid_alloc);
939
940 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
941 return rc;
942}
943
944static inline int obd_pool_new(struct obd_device *obd, char *poolname)
945{
946 int rc;
947
948 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
949 OBD_COUNTER_INCREMENT(obd, pool_new);
950
951 rc = OBP(obd, pool_new)(obd, poolname);
952 return rc;
953}
954
955static inline int obd_pool_del(struct obd_device *obd, char *poolname)
956{
957 int rc;
958
959 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
960 OBD_COUNTER_INCREMENT(obd, pool_del);
961
962 rc = OBP(obd, pool_del)(obd, poolname);
963 return rc;
964}
965
966static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
967{
968 int rc;
969
970 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
971 OBD_COUNTER_INCREMENT(obd, pool_add);
972
973 rc = OBP(obd, pool_add)(obd, poolname, ostname);
974 return rc;
975}
976
977static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
978{
979 int rc;
980
981 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
982 OBD_COUNTER_INCREMENT(obd, pool_rem);
983
984 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
985 return rc;
986}
987
988static inline void obd_getref(struct obd_device *obd)
989{
990 if (OBT(obd) && OBP(obd, getref)) {
991 OBD_COUNTER_INCREMENT(obd, getref);
992 OBP(obd, getref)(obd);
993 }
994}
995
996static inline void obd_putref(struct obd_device *obd)
997{
998 if (OBT(obd) && OBP(obd, putref)) {
999 OBD_COUNTER_INCREMENT(obd, putref);
1000 OBP(obd, putref)(obd);
1001 }
1002}
1003
1004static inline int obd_init_export(struct obd_export *exp)
1005{
1006 int rc = 0;
1007
1008 if ((exp)->exp_obd && OBT((exp)->exp_obd) &&
1009 OBP((exp)->exp_obd, init_export))
1010 rc = OBP(exp->exp_obd, init_export)(exp);
1011 return rc;
1012}
1013
1014static inline int obd_destroy_export(struct obd_export *exp)
1015{
1016 if ((exp)->exp_obd && OBT((exp)->exp_obd) &&
1017 OBP((exp)->exp_obd, destroy_export))
1018 OBP(exp->exp_obd, destroy_export)(exp);
1019 return 0;
1020}
1021
1022
1023
1024
1025
1026static inline int obd_statfs_async(struct obd_export *exp,
1027 struct obd_info *oinfo,
1028 __u64 max_age,
1029 struct ptlrpc_request_set *rqset)
1030{
1031 int rc = 0;
1032 struct obd_device *obd;
1033
1034 if (!exp || !exp->exp_obd)
1035 return -EINVAL;
1036
1037 obd = exp->exp_obd;
1038 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1039 OBD_COUNTER_INCREMENT(obd, statfs);
1040
1041 CDEBUG(D_SUPER, "%s: osfs %p age %llu, max_age %llu\n",
1042 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1043 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1044 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1045 } else {
1046 CDEBUG(D_SUPER,
1047 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1048 obd->obd_name, &obd->obd_osfs,
1049 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1050 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1051 spin_lock(&obd->obd_osfs_lock);
1052 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1053 spin_unlock(&obd->obd_osfs_lock);
1054 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1055 if (oinfo->oi_cb_up)
1056 oinfo->oi_cb_up(oinfo, 0);
1057 }
1058 return rc;
1059}
1060
1061static inline int obd_statfs_rqset(struct obd_export *exp,
1062 struct obd_statfs *osfs, __u64 max_age,
1063 __u32 flags)
1064{
1065 struct ptlrpc_request_set *set = NULL;
1066 struct obd_info oinfo = { };
1067 int rc = 0;
1068
1069 set = ptlrpc_prep_set();
1070 if (!set)
1071 return -ENOMEM;
1072
1073 oinfo.oi_osfs = osfs;
1074 oinfo.oi_flags = flags;
1075 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1076 if (rc == 0)
1077 rc = ptlrpc_set_wait(set);
1078 ptlrpc_set_destroy(set);
1079 return rc;
1080}
1081
1082
1083
1084
1085
1086static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1087 struct obd_statfs *osfs, __u64 max_age,
1088 __u32 flags)
1089{
1090 int rc = 0;
1091 struct obd_device *obd = exp->exp_obd;
1092
1093 if (!obd)
1094 return -EINVAL;
1095
1096 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1097 OBD_COUNTER_INCREMENT(obd, statfs);
1098
1099 CDEBUG(D_SUPER, "osfs %llu, max_age %llu\n",
1100 obd->obd_osfs_age, max_age);
1101 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1102 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1103 if (rc == 0) {
1104 spin_lock(&obd->obd_osfs_lock);
1105 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1106 obd->obd_osfs_age = cfs_time_current_64();
1107 spin_unlock(&obd->obd_osfs_lock);
1108 }
1109 } else {
1110 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1111 obd->obd_name, &obd->obd_osfs,
1112 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1113 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1114 spin_lock(&obd->obd_osfs_lock);
1115 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1116 spin_unlock(&obd->obd_osfs_lock);
1117 }
1118 return rc;
1119}
1120
1121static inline int obd_preprw(const struct lu_env *env, int cmd,
1122 struct obd_export *exp, struct obdo *oa,
1123 int objcount, struct obd_ioobj *obj,
1124 struct niobuf_remote *remote, int *pages,
1125 struct niobuf_local *local,
1126 struct obd_trans_info *oti)
1127{
1128 int rc;
1129
1130 EXP_CHECK_DT_OP(exp, preprw);
1131 EXP_COUNTER_INCREMENT(exp, preprw);
1132
1133 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1134 pages, local, oti);
1135 return rc;
1136}
1137
1138static inline int obd_commitrw(const struct lu_env *env, int cmd,
1139 struct obd_export *exp, struct obdo *oa,
1140 int objcount, struct obd_ioobj *obj,
1141 struct niobuf_remote *rnb, int pages,
1142 struct niobuf_local *local,
1143 struct obd_trans_info *oti, int rc)
1144{
1145 EXP_CHECK_DT_OP(exp, commitrw);
1146 EXP_COUNTER_INCREMENT(exp, commitrw);
1147
1148 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1149 rnb, pages, local, oti, rc);
1150 return rc;
1151}
1152
1153static inline int obd_adjust_kms(struct obd_export *exp,
1154 struct lov_stripe_md *lsm, u64 size,
1155 int shrink)
1156{
1157 int rc;
1158
1159 EXP_CHECK_DT_OP(exp, adjust_kms);
1160 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1161
1162 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1163 return rc;
1164}
1165
1166static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1167 int len, void *karg, void __user *uarg)
1168{
1169 int rc;
1170
1171 EXP_CHECK_DT_OP(exp, iocontrol);
1172 EXP_COUNTER_INCREMENT(exp, iocontrol);
1173
1174 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1175 return rc;
1176}
1177
1178static inline int obd_find_cbdata(struct obd_export *exp,
1179 struct lov_stripe_md *lsm,
1180 ldlm_iterator_t it, void *data)
1181{
1182 int rc;
1183
1184 EXP_CHECK_DT_OP(exp, find_cbdata);
1185 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1186
1187 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1188 return rc;
1189}
1190
1191static inline void obd_import_event(struct obd_device *obd,
1192 struct obd_import *imp,
1193 enum obd_import_event event)
1194{
1195 if (!obd) {
1196 CERROR("NULL device\n");
1197 return;
1198 }
1199 if (obd->obd_set_up && OBP(obd, import_event)) {
1200 OBD_COUNTER_INCREMENT(obd, import_event);
1201 OBP(obd, import_event)(obd, imp, event);
1202 }
1203}
1204
1205static inline int obd_notify(struct obd_device *obd,
1206 struct obd_device *watched,
1207 enum obd_notify_event ev,
1208 void *data)
1209{
1210 int rc;
1211
1212 rc = obd_check_dev(obd);
1213 if (rc)
1214 return rc;
1215
1216
1217
1218
1219
1220
1221 if (!obd->obd_set_up && !obd->obd_async_recov) {
1222 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1223 return -EINVAL;
1224 }
1225
1226 if (!OBP(obd, notify)) {
1227 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1228 return -ENOSYS;
1229 }
1230
1231 OBD_COUNTER_INCREMENT(obd, notify);
1232 rc = OBP(obd, notify)(obd, watched, ev, data);
1233 return rc;
1234}
1235
1236static inline int obd_notify_observer(struct obd_device *observer,
1237 struct obd_device *observed,
1238 enum obd_notify_event ev,
1239 void *data)
1240{
1241 int rc1;
1242 int rc2;
1243
1244 struct obd_notify_upcall *onu;
1245
1246 if (observer->obd_observer)
1247 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1248 else
1249 rc1 = 0;
1250
1251
1252
1253 onu = &observer->obd_upcall;
1254 if (onu->onu_upcall)
1255 rc2 = onu->onu_upcall(observer, observed, ev,
1256 onu->onu_owner, NULL);
1257 else
1258 rc2 = 0;
1259
1260 return rc1 ? rc1 : rc2;
1261}
1262
1263static inline int obd_quotacheck(struct obd_export *exp,
1264 struct obd_quotactl *oqctl)
1265{
1266 int rc;
1267
1268 EXP_CHECK_DT_OP(exp, quotacheck);
1269 EXP_COUNTER_INCREMENT(exp, quotacheck);
1270
1271 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1272 return rc;
1273}
1274
1275static inline int obd_quotactl(struct obd_export *exp,
1276 struct obd_quotactl *oqctl)
1277{
1278 int rc;
1279
1280 EXP_CHECK_DT_OP(exp, quotactl);
1281 EXP_COUNTER_INCREMENT(exp, quotactl);
1282
1283 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1284 return rc;
1285}
1286
1287static inline int obd_health_check(const struct lu_env *env,
1288 struct obd_device *obd)
1289{
1290
1291
1292
1293
1294
1295
1296
1297 int rc;
1298
1299
1300 if (!obd || !OBT(obd)) {
1301 CERROR("cleaned up obd\n");
1302 return -EOPNOTSUPP;
1303 }
1304 if (!obd->obd_set_up || obd->obd_stopping)
1305 return 0;
1306 if (!OBP(obd, health_check))
1307 return 0;
1308
1309 rc = OBP(obd, health_check)(env, obd);
1310 return rc;
1311}
1312
1313static inline int obd_register_observer(struct obd_device *obd,
1314 struct obd_device *observer)
1315{
1316 int rc;
1317
1318 rc = obd_check_dev(obd);
1319 if (rc)
1320 return rc;
1321 down_write(&obd->obd_observer_link_sem);
1322 if (obd->obd_observer && observer) {
1323 up_write(&obd->obd_observer_link_sem);
1324 return -EALREADY;
1325 }
1326 obd->obd_observer = observer;
1327 up_write(&obd->obd_observer_link_sem);
1328 return 0;
1329}
1330
1331
1332static inline int md_getstatus(struct obd_export *exp, struct lu_fid *fid)
1333{
1334 int rc;
1335
1336 EXP_CHECK_MD_OP(exp, getstatus);
1337 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1338 rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1339 return rc;
1340}
1341
1342static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1343 struct ptlrpc_request **request)
1344{
1345 int rc;
1346
1347 EXP_CHECK_MD_OP(exp, getattr);
1348 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1349 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1350 return rc;
1351}
1352
1353static inline int md_null_inode(struct obd_export *exp,
1354 const struct lu_fid *fid)
1355{
1356 int rc;
1357
1358 EXP_CHECK_MD_OP(exp, null_inode);
1359 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1360 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1361 return rc;
1362}
1363
1364static inline int md_find_cbdata(struct obd_export *exp,
1365 const struct lu_fid *fid,
1366 ldlm_iterator_t it, void *data)
1367{
1368 int rc;
1369
1370 EXP_CHECK_MD_OP(exp, find_cbdata);
1371 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1372 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1373 return rc;
1374}
1375
1376static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1377 struct md_open_data *mod,
1378 struct ptlrpc_request **request)
1379{
1380 int rc;
1381
1382 EXP_CHECK_MD_OP(exp, close);
1383 EXP_MD_COUNTER_INCREMENT(exp, close);
1384 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1385 return rc;
1386}
1387
1388static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1389 const void *data, int datalen, int mode, __u32 uid,
1390 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1391 struct ptlrpc_request **request)
1392{
1393 int rc;
1394
1395 EXP_CHECK_MD_OP(exp, create);
1396 EXP_MD_COUNTER_INCREMENT(exp, create);
1397 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1398 uid, gid, cap_effective, rdev, request);
1399 return rc;
1400}
1401
1402static inline int md_done_writing(struct obd_export *exp,
1403 struct md_op_data *op_data,
1404 struct md_open_data *mod)
1405{
1406 int rc;
1407
1408 EXP_CHECK_MD_OP(exp, done_writing);
1409 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1410 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1411 return rc;
1412}
1413
1414static inline int md_enqueue(struct obd_export *exp,
1415 struct ldlm_enqueue_info *einfo,
1416 struct lookup_intent *it,
1417 struct md_op_data *op_data,
1418 struct lustre_handle *lockh,
1419 void *lmm, int lmmsize,
1420 struct ptlrpc_request **req,
1421 __u64 extra_lock_flags)
1422{
1423 int rc;
1424
1425 EXP_CHECK_MD_OP(exp, enqueue);
1426 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1427 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1428 lmm, lmmsize, req, extra_lock_flags);
1429 return rc;
1430}
1431
1432static inline int md_getattr_name(struct obd_export *exp,
1433 struct md_op_data *op_data,
1434 struct ptlrpc_request **request)
1435{
1436 int rc;
1437
1438 EXP_CHECK_MD_OP(exp, getattr_name);
1439 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1440 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1441 return rc;
1442}
1443
1444static inline int md_intent_lock(struct obd_export *exp,
1445 struct md_op_data *op_data, void *lmm,
1446 int lmmsize, struct lookup_intent *it,
1447 int lookup_flags, struct ptlrpc_request **reqp,
1448 ldlm_blocking_callback cb_blocking,
1449 __u64 extra_lock_flags)
1450{
1451 int rc;
1452
1453 EXP_CHECK_MD_OP(exp, intent_lock);
1454 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1455 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1456 it, lookup_flags, reqp, cb_blocking,
1457 extra_lock_flags);
1458 return rc;
1459}
1460
1461static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1462 struct ptlrpc_request **request)
1463{
1464 int rc;
1465
1466 EXP_CHECK_MD_OP(exp, link);
1467 EXP_MD_COUNTER_INCREMENT(exp, link);
1468 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1469 return rc;
1470}
1471
1472static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1473 const char *old, int oldlen, const char *new,
1474 int newlen, struct ptlrpc_request **request)
1475{
1476 int rc;
1477
1478 EXP_CHECK_MD_OP(exp, rename);
1479 EXP_MD_COUNTER_INCREMENT(exp, rename);
1480 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1481 newlen, request);
1482 return rc;
1483}
1484
1485static inline int md_is_subdir(struct obd_export *exp,
1486 const struct lu_fid *pfid,
1487 const struct lu_fid *cfid,
1488 struct ptlrpc_request **request)
1489{
1490 int rc;
1491
1492 EXP_CHECK_MD_OP(exp, is_subdir);
1493 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1494 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1495 return rc;
1496}
1497
1498static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1499 void *ea, int ealen, void *ea2, int ea2len,
1500 struct ptlrpc_request **request,
1501 struct md_open_data **mod)
1502{
1503 int rc;
1504
1505 EXP_CHECK_MD_OP(exp, setattr);
1506 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1507 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1508 ea2, ea2len, request, mod);
1509 return rc;
1510}
1511
1512static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1513 struct ptlrpc_request **request)
1514{
1515 int rc;
1516
1517 EXP_CHECK_MD_OP(exp, sync);
1518 EXP_MD_COUNTER_INCREMENT(exp, sync);
1519 rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1520 return rc;
1521}
1522
1523static inline int md_readpage(struct obd_export *exp, struct md_op_data *opdata,
1524 struct page **pages,
1525 struct ptlrpc_request **request)
1526{
1527 int rc;
1528
1529 EXP_CHECK_MD_OP(exp, readpage);
1530 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1531 rc = MDP(exp->exp_obd, readpage)(exp, opdata, pages, request);
1532 return rc;
1533}
1534
1535static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1536 struct ptlrpc_request **request)
1537{
1538 int rc;
1539
1540 EXP_CHECK_MD_OP(exp, unlink);
1541 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1542 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1543 return rc;
1544}
1545
1546static inline int md_get_lustre_md(struct obd_export *exp,
1547 struct ptlrpc_request *req,
1548 struct obd_export *dt_exp,
1549 struct obd_export *md_exp,
1550 struct lustre_md *md)
1551{
1552 EXP_CHECK_MD_OP(exp, get_lustre_md);
1553 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1554 return MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md);
1555}
1556
1557static inline int md_free_lustre_md(struct obd_export *exp,
1558 struct lustre_md *md)
1559{
1560 EXP_CHECK_MD_OP(exp, free_lustre_md);
1561 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1562 return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1563}
1564
1565static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1566 u64 valid, const char *name,
1567 const char *input, int input_size,
1568 int output_size, int flags, __u32 suppgid,
1569 struct ptlrpc_request **request)
1570{
1571 EXP_CHECK_MD_OP(exp, setxattr);
1572 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1573 return MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1574 input_size, output_size, flags,
1575 suppgid, request);
1576}
1577
1578static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1579 u64 valid, const char *name,
1580 const char *input, int input_size,
1581 int output_size, int flags,
1582 struct ptlrpc_request **request)
1583{
1584 EXP_CHECK_MD_OP(exp, getxattr);
1585 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1586 return MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1587 input_size, output_size, flags,
1588 request);
1589}
1590
1591static inline int md_set_open_replay_data(struct obd_export *exp,
1592 struct obd_client_handle *och,
1593 struct lookup_intent *it)
1594{
1595 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1596 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1597 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
1598}
1599
1600static inline int md_clear_open_replay_data(struct obd_export *exp,
1601 struct obd_client_handle *och)
1602{
1603 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1604 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1605 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1606}
1607
1608static inline int md_set_lock_data(struct obd_export *exp,
1609 __u64 *lockh, void *data, __u64 *bits)
1610{
1611 EXP_CHECK_MD_OP(exp, set_lock_data);
1612 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1613 return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
1614}
1615
1616static inline int md_cancel_unused(struct obd_export *exp,
1617 const struct lu_fid *fid,
1618 ldlm_policy_data_t *policy,
1619 enum ldlm_mode mode,
1620 enum ldlm_cancel_flags flags,
1621 void *opaque)
1622{
1623 int rc;
1624
1625 EXP_CHECK_MD_OP(exp, cancel_unused);
1626 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1627
1628 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1629 flags, opaque);
1630 return rc;
1631}
1632
1633static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1634 const struct lu_fid *fid,
1635 enum ldlm_type type,
1636 ldlm_policy_data_t *policy,
1637 enum ldlm_mode mode,
1638 struct lustre_handle *lockh)
1639{
1640 EXP_CHECK_MD_OP(exp, lock_match);
1641 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1642 return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1643 policy, mode, lockh);
1644}
1645
1646static inline int md_init_ea_size(struct obd_export *exp, int easize,
1647 int def_asize, int cookiesize,
1648 int def_cookiesize)
1649{
1650 EXP_CHECK_MD_OP(exp, init_ea_size);
1651 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1652 return MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1653 cookiesize, def_cookiesize);
1654}
1655
1656static inline int md_get_remote_perm(struct obd_export *exp,
1657 const struct lu_fid *fid, __u32 suppgid,
1658 struct ptlrpc_request **request)
1659{
1660 EXP_CHECK_MD_OP(exp, get_remote_perm);
1661 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1662 return MDP(exp->exp_obd, get_remote_perm)(exp, fid, suppgid,
1663 request);
1664}
1665
1666static inline int md_intent_getattr_async(struct obd_export *exp,
1667 struct md_enqueue_info *minfo,
1668 struct ldlm_enqueue_info *einfo)
1669{
1670 int rc;
1671
1672 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1673 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1674 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
1675 return rc;
1676}
1677
1678static inline int md_revalidate_lock(struct obd_export *exp,
1679 struct lookup_intent *it,
1680 struct lu_fid *fid, __u64 *bits)
1681{
1682 int rc;
1683
1684 EXP_CHECK_MD_OP(exp, revalidate_lock);
1685 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1686 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1687 return rc;
1688}
1689
1690
1691
1692int obd_init_caches(void);
1693void obd_cleanup_caches(void);
1694
1695
1696extern struct kmem_cache *obdo_cachep;
1697
1698static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
1699{
1700
1701}
1702
1703static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
1704{
1705
1706}
1707
1708typedef int (*register_lwp_cb)(void *data);
1709
1710struct lwp_register_item {
1711 struct obd_export **lri_exp;
1712 register_lwp_cb lri_cb_func;
1713 void *lri_cb_data;
1714 struct list_head lri_list;
1715 char lri_name[MTI_NAME_MAXLEN];
1716};
1717
1718
1719
1720
1721
1722
1723extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1724
1725
1726
1727
1728int obd_sysctl_init(void);
1729
1730
1731typedef __u8 class_uuid_t[16];
1732void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1733
1734
1735int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1736int class_add_uuid(const char *uuid, __u64 nid);
1737int class_del_uuid(const char *uuid);
1738int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1739void class_init_uuidlist(void);
1740void class_exit_uuidlist(void);
1741
1742
1743extern char obd_jobid_node[];
1744extern struct miscdevice obd_psdev;
1745extern spinlock_t obd_types_lock;
1746
1747
1748#define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1749
1750#endif
1751