1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <obd_support.h>
27 #include <lustre_import.h>
28 #include <lustre_net.h>
30 #include <lustre_lib.h>
31 #include <lustre/lustre_idl.h>
32 #include <lprocfs_status.h>
34 #if defined(__linux__)
35 #include <linux/obd_class.h>
36 #elif defined(__APPLE__)
37 #include <darwin/obd_class.h>
38 #elif defined(__WINNT__)
39 #include <winnt/obd_class.h>
41 #error Unsupported operating system.
44 /* OBD Device Declarations */
45 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
46 extern spinlock_t obd_dev_lock;
48 /* OBD Operations Declarations */
49 extern struct obd_device *class_conn2obd(struct lustre_handle *);
50 extern struct obd_device *class_exp2obd(struct obd_export *);
53 struct obd_export *class_conn2export(struct lustre_handle *);
54 int class_register_type(struct obd_ops *ops, struct lprocfs_vars *,
56 int class_unregister_type(const char *nm);
58 struct obd_device *class_newdev(const char *type_name, const char *name);
59 void class_release_dev(struct obd_device *obd);
61 int class_name2dev(const char *name);
62 struct obd_device *class_name2obd(const char *name);
63 int class_uuid2dev(struct obd_uuid *uuid);
64 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
65 void class_obd_list(void);
66 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
67 const char * typ_name,
68 struct obd_uuid *grp_uuid);
69 struct obd_device * class_find_client_notype(struct obd_uuid *tgt_uuid,
70 struct obd_uuid *grp_uuid);
71 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
73 struct obd_device * class_num2obd(int num);
75 int oig_init(struct obd_io_group **oig);
76 int oig_add_one(struct obd_io_group *oig, struct oig_callback_context *occ);
77 void oig_complete_one(struct obd_io_group *oig,
78 struct oig_callback_context *occ, int rc);
79 void oig_release(struct obd_io_group *oig);
80 int oig_wait(struct obd_io_group *oig);
82 char *obd_export_nid2str(struct obd_export *exp);
84 int obd_export_evict_by_nid(struct obd_device *obd, char *nid);
85 int obd_export_evict_by_uuid(struct obd_device *obd, char *uuid);
88 int class_process_config(struct lustre_cfg *lcfg);
89 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
90 struct lustre_cfg *lcfg, void *data);
91 int class_attach(struct lustre_cfg *lcfg);
92 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
93 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
94 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
95 struct obd_device *class_incref(struct obd_device *obd);
96 void class_decref(struct obd_device *obd);
98 #define CFG_F_START 0x01 /* Set when we start updating from a log */
99 #define CFG_F_MARKER 0x02 /* We are within a maker */
100 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
101 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
102 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
104 /* Passed as data param to class_config_parse_llog */
105 struct config_llog_instance {
107 struct super_block *cfg_sb;
108 struct obd_uuid cfg_uuid;
109 int cfg_last_idx; /* for partial llog processing */
112 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
113 struct config_llog_instance *cfg);
114 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
115 struct config_llog_instance *cfg);
117 /* list of active configuration logs */
118 struct config_llog_data {
120 struct ldlm_res_id cld_resid;
121 struct config_llog_instance cld_cfg;
122 struct list_head cld_list_chain;
123 atomic_t cld_refcount;
124 struct obd_export *cld_mgcexp;
125 unsigned int cld_stopping:1; /* we were told to stop watching */
126 unsigned int cld_lostlock:1; /* lock not requeued */
129 struct lustre_profile {
130 struct list_head lp_list;
136 struct lustre_profile *class_get_profile(char * prof);
137 void class_del_profile(char *prof);
138 void class_del_profiles(void);
140 #define class_export_rpc_get(exp) \
142 atomic_inc(&(exp)->exp_rpc_count); \
143 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
144 (exp), atomic_read(&(exp)->exp_rpc_count)); \
145 class_export_get(exp); \
148 #define class_export_rpc_put(exp) \
150 atomic_dec(&(exp)->exp_rpc_count); \
151 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
152 (exp), atomic_read(&(exp)->exp_rpc_count)); \
153 class_export_put(exp); \
157 #define class_export_get(exp) \
159 struct obd_export *exp_ = exp; \
160 atomic_inc(&exp_->exp_refcount); \
161 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
162 atomic_read(&exp_->exp_refcount)); \
166 #define class_export_put(exp) \
168 LASSERT((exp) != NULL); \
169 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
170 atomic_read(&(exp)->exp_refcount) - 1); \
171 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
172 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
173 __class_export_put(exp); \
176 void __class_export_put(struct obd_export *);
177 struct obd_export *class_new_export(struct obd_device *obddev,
178 struct obd_uuid *cluuid);
179 void class_unlink_export(struct obd_export *exp);
181 struct obd_import *class_import_get(struct obd_import *);
182 void class_import_put(struct obd_import *);
183 struct obd_import *class_new_import(struct obd_device *obd);
184 void class_destroy_import(struct obd_import *exp);
186 struct obd_type *class_search_type(const char *name);
187 struct obd_type *class_get_type(const char *name);
188 void class_put_type(struct obd_type *type);
189 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
190 struct obd_uuid *cluuid);
191 int class_disconnect(struct obd_export *exp);
192 void class_fail_export(struct obd_export *exp);
193 void class_disconnect_exports(struct obd_device *obddev);
194 void class_disconnect_stale_exports(struct obd_device *obddev);
195 int class_manual_cleanup(struct obd_device *obd);
198 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
199 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
202 #define OBT(dev) (dev)->obd_type
203 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
204 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
206 /* Ensure obd_setup: used for cleanup which must be called
207 while obd is stopping */
208 #define OBD_CHECK_DEV(obd) \
211 CERROR("NULL device\n"); \
216 /* ensure obd_setup and !obd_stopping */
217 #define OBD_CHECK_DEV_ACTIVE(obd) \
219 OBD_CHECK_DEV(obd); \
220 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
221 CERROR("Device %d not setup\n", \
229 #define OBD_COUNTER_OFFSET(op) \
230 ((offsetof(struct obd_ops, o_ ## op) - \
231 offsetof(struct obd_ops, o_iocontrol)) \
232 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
234 #define OBD_COUNTER_INCREMENT(obdx, op) \
235 if ((obdx)->obd_stats != NULL) { \
236 unsigned int coffset; \
237 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
238 OBD_COUNTER_OFFSET(op); \
239 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
240 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
243 #define EXP_COUNTER_INCREMENT(export, op) \
244 if ((export)->exp_obd->obd_stats != NULL) { \
245 unsigned int coffset; \
246 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
247 OBD_COUNTER_OFFSET(op); \
248 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
249 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
250 if ((export)->exp_ops_stats != NULL) \
251 lprocfs_counter_incr( \
252 (export)->exp_ops_stats, coffset); \
256 #define OBD_COUNTER_OFFSET(op)
257 #define OBD_COUNTER_INCREMENT(obd, op)
258 #define EXP_COUNTER_INCREMENT(exp, op);
261 #define OBD_CHECK_OP(obd, op, err) \
263 if (!OBT(obd) || !OBP((obd), op)) {\
265 CERROR("obd_" #op ": dev %d no operation\n", \
271 #define EXP_CHECK_OP(exp, op) \
273 if ((exp) == NULL) { \
274 CERROR("obd_" #op ": NULL export\n"); \
277 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
278 CERROR("obd_" #op ": cleaned up obd\n"); \
279 RETURN(-EOPNOTSUPP); \
281 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
282 CERROR("obd_" #op ": dev %d no operation\n", \
283 (exp)->exp_obd->obd_minor); \
284 RETURN(-EOPNOTSUPP); \
288 #define CTXT_CHECK_OP(ctxt, op, err) \
290 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
292 CERROR("lop_" #op ": dev %d no operation\n", \
293 ctxt->loc_obd->obd_minor); \
298 static inline int class_devno_max(void)
300 return MAX_OBD_DEVICES;
303 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
304 void *key, __u32 *vallen, void *val)
309 EXP_CHECK_OP(exp, get_info);
310 EXP_COUNTER_INCREMENT(exp, get_info);
312 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
316 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
317 void *key, obd_count vallen, void *val,
318 struct ptlrpc_request_set *set)
323 EXP_CHECK_OP(exp, set_info_async);
324 EXP_COUNTER_INCREMENT(exp, set_info_async);
326 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
331 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
336 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
337 OBD_COUNTER_INCREMENT(obd, setup);
339 rc = OBP(obd, setup)(obd, datalen, data);
343 static inline int obd_precleanup(struct obd_device *obd,
344 enum obd_cleanup_stage cleanup_stage)
349 OBD_CHECK_OP(obd, precleanup, 0);
350 OBD_COUNTER_INCREMENT(obd, precleanup);
352 rc = OBP(obd, precleanup)(obd, cleanup_stage);
356 static inline int obd_cleanup(struct obd_device *obd)
362 OBD_CHECK_OP(obd, cleanup, 0);
363 OBD_COUNTER_INCREMENT(obd, cleanup);
365 rc = OBP(obd, cleanup)(obd);
370 obd_process_config(struct obd_device *obd, int datalen, void *data)
375 OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
376 OBD_COUNTER_INCREMENT(obd, process_config);
378 rc = OBP(obd, process_config)(obd, datalen, data);
382 /* Pack an in-memory MD struct for storage on disk.
383 * Returns +ve size of packed MD (0 for free), or -ve error.
385 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
386 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
387 * If @*disk_tgt == NULL, it will be allocated
389 static inline int obd_packmd(struct obd_export *exp,
390 struct lov_mds_md **disk_tgt,
391 struct lov_stripe_md *mem_src)
396 EXP_CHECK_OP(exp, packmd);
397 EXP_COUNTER_INCREMENT(exp, packmd);
399 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
403 static inline int obd_size_diskmd(struct obd_export *exp,
404 struct lov_stripe_md *mem_src)
406 return obd_packmd(exp, NULL, mem_src);
409 /* helper functions */
410 static inline int obd_alloc_diskmd(struct obd_export *exp,
411 struct lov_mds_md **disk_tgt)
414 LASSERT(*disk_tgt == NULL);
415 return obd_packmd(exp, disk_tgt, NULL);
418 static inline int obd_free_diskmd(struct obd_export *exp,
419 struct lov_mds_md **disk_tgt)
423 return obd_packmd(exp, disk_tgt, NULL);
426 /* Unpack an MD struct from disk to in-memory format.
427 * Returns +ve size of unpacked MD (0 for free), or -ve error.
429 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
430 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
431 * If @*mem_tgt == NULL, it will be allocated
433 static inline int obd_unpackmd(struct obd_export *exp,
434 struct lov_stripe_md **mem_tgt,
435 struct lov_mds_md *disk_src,
441 EXP_CHECK_OP(exp, unpackmd);
442 EXP_COUNTER_INCREMENT(exp, unpackmd);
444 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
448 /* helper functions */
449 static inline int obd_alloc_memmd(struct obd_export *exp,
450 struct lov_stripe_md **mem_tgt)
453 LASSERT(*mem_tgt == NULL);
454 return obd_unpackmd(exp, mem_tgt, NULL, 0);
457 static inline int obd_free_memmd(struct obd_export *exp,
458 struct lov_stripe_md **mem_tgt)
462 return obd_unpackmd(exp, mem_tgt, NULL, 0);
465 static inline int obd_checkmd(struct obd_export *exp,
466 struct obd_export *md_exp,
467 struct lov_stripe_md *mem_tgt)
472 EXP_CHECK_OP(exp, checkmd);
473 EXP_COUNTER_INCREMENT(exp, checkmd);
475 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
479 static inline int obd_precreate(struct obd_export *exp, int need_create)
484 EXP_CHECK_OP(exp, precreate);
485 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
487 rc = OBP(exp->exp_obd, precreate)(exp, need_create);
491 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
492 struct lov_stripe_md **ea,
493 struct obd_trans_info *oti)
498 EXP_CHECK_OP(exp, create);
499 EXP_COUNTER_INCREMENT(exp, create);
501 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
505 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
506 struct lov_stripe_md *ea,
507 struct obd_trans_info *oti,
508 struct obd_export *md_exp)
513 EXP_CHECK_OP(exp, destroy);
514 EXP_COUNTER_INCREMENT(exp, destroy);
516 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
520 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
525 EXP_CHECK_OP(exp, getattr);
526 EXP_COUNTER_INCREMENT(exp, getattr);
528 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
532 static inline int obd_getattr_async(struct obd_export *exp,
533 struct obd_info *oinfo,
534 struct ptlrpc_request_set *set)
539 EXP_CHECK_OP(exp, getattr_async);
540 EXP_COUNTER_INCREMENT(exp, getattr_async);
542 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
546 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
547 struct obd_trans_info *oti)
552 EXP_CHECK_OP(exp, setattr);
553 EXP_COUNTER_INCREMENT(exp, setattr);
555 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
559 /* This performs all the requests set init/wait/destroy actions. */
560 static inline int obd_setattr_rqset(struct obd_export *exp,
561 struct obd_info *oinfo,
562 struct obd_trans_info *oti)
564 struct ptlrpc_request_set *set = NULL;
568 EXP_CHECK_OP(exp, setattr_async);
569 EXP_COUNTER_INCREMENT(exp, setattr_async);
571 set = ptlrpc_prep_set();
575 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
577 rc = ptlrpc_set_wait(set);
578 ptlrpc_set_destroy(set);
582 /* This adds all the requests into @set if @set != NULL, otherwise
583 all requests are sent asynchronously without waiting for response. */
584 static inline int obd_setattr_async(struct obd_export *exp,
585 struct obd_info *oinfo,
586 struct obd_trans_info *oti,
587 struct ptlrpc_request_set *set)
592 EXP_CHECK_OP(exp, setattr_async);
593 EXP_COUNTER_INCREMENT(exp, setattr_async);
595 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
599 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
602 struct obd_device *obd = imp->imp_obd;
606 OBD_CHECK_DEV_ACTIVE(obd);
607 OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
608 OBD_COUNTER_INCREMENT(obd, add_conn);
610 rc = OBP(obd, add_conn)(imp, uuid, priority);
614 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
616 struct obd_device *obd = imp->imp_obd;
620 OBD_CHECK_DEV_ACTIVE(obd);
621 OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
622 OBD_COUNTER_INCREMENT(obd, del_conn);
624 rc = OBP(obd, del_conn)(imp, uuid);
628 static inline int obd_connect(struct lustre_handle *conn,struct obd_device *obd,
629 struct obd_uuid *cluuid,
630 struct obd_connect_data *d)
633 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
636 OBD_CHECK_DEV_ACTIVE(obd);
637 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
638 OBD_COUNTER_INCREMENT(obd, connect);
640 rc = OBP(obd, connect)(conn, obd, cluuid, d);
641 /* check that only subset is granted */
642 LASSERT(ergo(d != NULL,
643 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
647 static inline int obd_reconnect(struct obd_export *exp,
648 struct obd_device *obd,
649 struct obd_uuid *cluuid,
650 struct obd_connect_data *d)
653 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
656 OBD_CHECK_DEV_ACTIVE(obd);
657 OBD_CHECK_OP(obd, reconnect, 0);
658 OBD_COUNTER_INCREMENT(obd, reconnect);
660 rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
661 /* check that only subset is granted */
662 LASSERT(ergo(d != NULL,
663 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
667 static inline int obd_disconnect(struct obd_export *exp)
672 EXP_CHECK_OP(exp, disconnect);
673 EXP_COUNTER_INCREMENT(exp, disconnect);
675 rc = OBP(exp->exp_obd, disconnect)(exp);
679 static inline int obd_ping(struct obd_export *exp)
684 OBD_CHECK_OP(exp->exp_obd, ping, 0);
685 EXP_COUNTER_INCREMENT(exp, ping);
687 rc = OBP(exp->exp_obd, ping)(exp);
691 static inline int obd_init_export(struct obd_export *exp)
696 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
697 OBP((exp)->exp_obd, init_export))
698 rc = OBP(exp->exp_obd, init_export)(exp);
702 static inline int obd_destroy_export(struct obd_export *exp)
705 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
706 OBP((exp)->exp_obd, destroy_export))
707 OBP(exp->exp_obd, destroy_export)(exp);
711 static inline int obd_extent_calc(struct obd_export *exp,
712 struct lov_stripe_md *md,
713 int cmd, obd_off *offset)
717 EXP_CHECK_OP(exp, extent_calc);
718 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
722 static inline struct dentry *
723 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
725 LASSERT(exp->exp_obd);
727 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
732 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
735 /* @max_age is the oldest time in jiffies that we accept using a cached data.
736 * If the cache is older than @max_age we will get a new value from the
737 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
738 static inline int obd_statfs_async(struct obd_device *obd,
739 struct obd_info *oinfo,
741 struct ptlrpc_request_set *rqset)
749 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
750 OBD_COUNTER_INCREMENT(obd, statfs);
752 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
753 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
754 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
755 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
757 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
758 " objects "LPU64"/"LPU64"\n",
759 obd->obd_name, &obd->obd_osfs,
760 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
761 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
762 spin_lock(&obd->obd_osfs_lock);
763 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
764 spin_unlock(&obd->obd_osfs_lock);
766 oinfo->oi_cb_up(oinfo, 0);
771 static inline int obd_statfs_rqset(struct obd_device *obd,
772 struct obd_statfs *osfs, __u64 max_age)
774 struct ptlrpc_request_set *set = NULL;
775 struct obd_info oinfo = { { { 0 } } };
779 set = ptlrpc_prep_set();
783 oinfo.oi_osfs = osfs;
784 rc = obd_statfs_async(obd, &oinfo, max_age, set);
786 rc = ptlrpc_set_wait(set);
787 ptlrpc_set_destroy(set);
791 /* @max_age is the oldest time in jiffies that we accept using a cached data.
792 * If the cache is older than @max_age we will get a new value from the
793 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
794 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
803 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
804 OBD_COUNTER_INCREMENT(obd, statfs);
806 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
807 obd->obd_osfs_age, max_age);
808 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
809 rc = OBP(obd, statfs)(obd, osfs, max_age);
811 spin_lock(&obd->obd_osfs_lock);
812 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
813 obd->obd_osfs_age = cfs_time_current_64();
814 spin_unlock(&obd->obd_osfs_lock);
817 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
818 " objects "LPU64"/"LPU64"\n",
819 obd->obd_name, &obd->obd_osfs,
820 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
821 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
822 spin_lock(&obd->obd_osfs_lock);
823 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
824 spin_unlock(&obd->obd_osfs_lock);
829 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
830 struct lov_stripe_md *ea, obd_size start,
836 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
837 EXP_COUNTER_INCREMENT(exp, sync);
839 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
843 static inline int obd_punch_rqset(struct obd_export *exp,
844 struct obd_info *oinfo,
845 struct obd_trans_info *oti)
847 struct ptlrpc_request_set *set = NULL;
851 EXP_CHECK_OP(exp, punch);
852 EXP_COUNTER_INCREMENT(exp, punch);
854 set = ptlrpc_prep_set();
858 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
860 rc = ptlrpc_set_wait(set);
861 ptlrpc_set_destroy(set);
865 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
866 struct obd_trans_info *oti,
867 struct ptlrpc_request_set *rqset)
872 EXP_CHECK_OP(exp, punch);
873 EXP_COUNTER_INCREMENT(exp, punch);
875 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
879 static inline int obd_brw(int cmd, struct obd_export *exp,
880 struct obd_info *oinfo, obd_count oa_bufs,
881 struct brw_page *pg, struct obd_trans_info *oti)
886 EXP_CHECK_OP(exp, brw);
887 EXP_COUNTER_INCREMENT(exp, brw);
889 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
890 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
891 "or OBD_BRW_CHECK\n");
895 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
899 static inline int obd_brw_async(int cmd, struct obd_export *exp,
900 struct obd_info *oinfo, obd_count oa_bufs,
901 struct brw_page *pg, struct obd_trans_info *oti,
902 struct ptlrpc_request_set *set)
907 EXP_CHECK_OP(exp, brw_async);
908 EXP_COUNTER_INCREMENT(exp, brw_async);
910 if (!(cmd & OBD_BRW_RWMASK)) {
911 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
915 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs, pg,oti,set);
919 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
920 struct obdo *oa, struct lov_stripe_md *lsm,
921 obd_count oa_bufs, struct brw_page *pg,
922 struct obd_trans_info *oti)
924 struct ptlrpc_request_set *set = NULL;
925 struct obd_info oinfo = { { { 0 } } };
929 set = ptlrpc_prep_set();
935 rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
937 rc = ptlrpc_set_wait(set);
939 CERROR("error from callback: rc = %d\n", rc);
941 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
942 "error from obd_brw_async: rc = %d\n", rc);
944 ptlrpc_set_destroy(set);
948 static inline int obd_prep_async_page(struct obd_export *exp,
949 struct lov_stripe_md *lsm,
950 struct lov_oinfo *loi,
951 cfs_page_t *page, obd_off offset,
952 struct obd_async_page_ops *ops,
953 void *data, void **res)
958 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
959 EXP_COUNTER_INCREMENT(exp, prep_async_page);
961 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
966 static inline int obd_queue_async_io(struct obd_export *exp,
967 struct lov_stripe_md *lsm,
968 struct lov_oinfo *loi, void *cookie,
969 int cmd, obd_off off, int count,
970 obd_flag brw_flags, obd_flag async_flags)
975 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
976 EXP_COUNTER_INCREMENT(exp, queue_async_io);
977 LASSERT(cmd & OBD_BRW_RWMASK);
979 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
980 count, brw_flags, async_flags);
984 static inline int obd_set_async_flags(struct obd_export *exp,
985 struct lov_stripe_md *lsm,
986 struct lov_oinfo *loi, void *cookie,
987 obd_flag async_flags)
992 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
993 EXP_COUNTER_INCREMENT(exp, set_async_flags);
995 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1000 static inline int obd_queue_group_io(struct obd_export *exp,
1001 struct lov_stripe_md *lsm,
1002 struct lov_oinfo *loi,
1003 struct obd_io_group *oig,
1004 void *cookie, int cmd, obd_off off,
1005 int count, obd_flag brw_flags,
1006 obd_flag async_flags)
1011 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1012 EXP_COUNTER_INCREMENT(exp, queue_group_io);
1013 LASSERT(cmd & OBD_BRW_RWMASK);
1015 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1016 cmd, off, count, brw_flags,
1021 static inline int obd_trigger_group_io(struct obd_export *exp,
1022 struct lov_stripe_md *lsm,
1023 struct lov_oinfo *loi,
1024 struct obd_io_group *oig)
1029 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1030 EXP_COUNTER_INCREMENT(exp, trigger_group_io);
1032 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1036 static inline int obd_teardown_async_page(struct obd_export *exp,
1037 struct lov_stripe_md *lsm,
1038 struct lov_oinfo *loi, void *cookie)
1043 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1044 EXP_COUNTER_INCREMENT(exp, teardown_async_page);
1046 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1050 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1051 int objcount, struct obd_ioobj *obj,
1052 int niocount, struct niobuf_remote *remote,
1053 struct niobuf_local *local,
1054 struct obd_trans_info *oti)
1059 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1060 EXP_COUNTER_INCREMENT(exp, preprw);
1062 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1063 remote, local, oti);
1067 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1068 int objcount, struct obd_ioobj *obj,
1069 int niocount, struct niobuf_local *local,
1070 struct obd_trans_info *oti, int rc)
1074 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1075 EXP_COUNTER_INCREMENT(exp, commitrw);
1077 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1082 static inline int obd_merge_lvb(struct obd_export *exp,
1083 struct lov_stripe_md *lsm,
1084 struct ost_lvb *lvb, int kms_only)
1089 OBD_CHECK_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1090 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1092 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1096 static inline int obd_adjust_kms(struct obd_export *exp,
1097 struct lov_stripe_md *lsm, obd_off size,
1103 OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1104 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1106 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1110 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1111 int len, void *karg, void *uarg)
1116 EXP_CHECK_OP(exp, iocontrol);
1117 EXP_COUNTER_INCREMENT(exp, iocontrol);
1119 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1123 static inline int obd_enqueue_rqset(struct obd_export *exp,
1124 struct obd_info *oinfo,
1125 struct ldlm_enqueue_info *einfo)
1127 struct ptlrpc_request_set *set = NULL;
1131 EXP_CHECK_OP(exp, enqueue);
1132 EXP_COUNTER_INCREMENT(exp, enqueue);
1134 set = ptlrpc_prep_set();
1138 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1140 rc = ptlrpc_set_wait(set);
1141 ptlrpc_set_destroy(set);
1145 static inline int obd_enqueue(struct obd_export *exp,
1146 struct obd_info *oinfo,
1147 struct ldlm_enqueue_info *einfo,
1148 struct ptlrpc_request_set *set)
1153 EXP_CHECK_OP(exp, enqueue);
1154 EXP_COUNTER_INCREMENT(exp, enqueue);
1156 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1160 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1161 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1162 int *flags, void *data, struct lustre_handle *lockh)
1167 EXP_CHECK_OP(exp, match);
1168 EXP_COUNTER_INCREMENT(exp, match);
1170 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1175 static inline int obd_change_cbdata(struct obd_export *exp,
1176 struct lov_stripe_md *lsm,
1177 ldlm_iterator_t it, void *data)
1182 EXP_CHECK_OP(exp, change_cbdata);
1183 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1185 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1189 static inline int obd_cancel(struct obd_export *exp,
1190 struct lov_stripe_md *ea, __u32 mode,
1191 struct lustre_handle *lockh)
1196 EXP_CHECK_OP(exp, cancel);
1197 EXP_COUNTER_INCREMENT(exp, cancel);
1199 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1203 static inline int obd_cancel_unused(struct obd_export *exp,
1204 struct lov_stripe_md *ea, int flags,
1210 EXP_CHECK_OP(exp, cancel_unused);
1211 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1213 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1217 static inline int obd_join_lru(struct obd_export *exp,
1218 struct lov_stripe_md *ea, int join)
1223 EXP_CHECK_OP(exp, join_lru);
1224 EXP_COUNTER_INCREMENT(exp, join_lru);
1226 rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1230 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1231 int type, struct obd_client_handle *handle, int flag)
1236 EXP_CHECK_OP(exp, pin);
1237 EXP_COUNTER_INCREMENT(exp, pin);
1239 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1243 static inline int obd_unpin(struct obd_export *exp,
1244 struct obd_client_handle *handle, int flag)
1249 EXP_CHECK_OP(exp, unpin);
1250 EXP_COUNTER_INCREMENT(exp, unpin);
1252 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1257 static inline void obd_import_event(struct obd_device *obd,
1258 struct obd_import *imp,
1259 enum obd_import_event event)
1263 CERROR("NULL device\n");
1267 if (obd->obd_set_up && OBP(obd, import_event)) {
1268 OBD_COUNTER_INCREMENT(obd, import_event);
1269 OBP(obd, import_event)(obd, imp, event);
1274 static inline int obd_notify(struct obd_device *obd,
1275 struct obd_device *watched,
1276 enum obd_notify_event ev, void *data)
1281 /* the check for async_recov is a complete hack - I'm hereby
1282 overloading the meaning to also mean "this was called from
1283 mds_postsetup". I know that my mds is able to handle notifies
1284 by this point, and it needs to get them to execute mds_postrecov. */
1285 if (!obd->obd_set_up && !obd->obd_async_recov) {
1286 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1290 if (!OBP(obd, notify))
1293 OBD_COUNTER_INCREMENT(obd, notify);
1294 RETURN(OBP(obd, notify)(obd, watched, ev, data));
1297 static inline int obd_notify_observer(struct obd_device *observer,
1298 struct obd_device *observed,
1299 enum obd_notify_event ev, void *data)
1304 struct obd_notify_upcall *onu;
1306 if (observer->obd_observer)
1307 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1311 * Also, call non-obd listener, if any
1313 onu = &observer->obd_upcall;
1314 if (onu->onu_upcall != NULL)
1315 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1322 static inline int obd_quotacheck(struct obd_export *exp,
1323 struct obd_quotactl *oqctl)
1328 EXP_CHECK_OP(exp, quotacheck);
1329 EXP_COUNTER_INCREMENT(exp, quotacheck);
1331 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1335 static inline int obd_quotactl(struct obd_export *exp,
1336 struct obd_quotactl *oqctl)
1341 EXP_CHECK_OP(exp, quotactl);
1342 EXP_COUNTER_INCREMENT(exp, quotactl);
1344 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1348 static inline int obd_health_check(struct obd_device *obd)
1350 /* returns: 0 on healthy
1351 * >0 on unhealthy + reason code/flag
1352 * however the only suppored reason == 1 right now
1353 * We'll need to define some better reasons
1354 * or flags in the future.
1360 /* don't use EXP_CHECK_OP, because NULL method is normal here */
1361 if (obd == NULL || !OBT(obd)) {
1362 CERROR("cleaned up obd\n");
1363 RETURN(-EOPNOTSUPP);
1365 if (!obd->obd_set_up || obd->obd_stopping)
1367 if (!OBP(obd, health_check))
1370 rc = OBP(obd, health_check)(obd);
1374 static inline int obd_register_observer(struct obd_device *obd,
1375 struct obd_device *observer)
1379 if (obd->obd_observer && observer)
1381 obd->obd_observer = observer;
1385 /* OBD Metadata Support */
1387 extern int obd_init_caches(void);
1388 extern void obd_cleanup_caches(void);
1390 /* support routines */
1391 extern cfs_mem_cache_t *obdo_cachep;
1393 #define OBDO_ALLOC(ptr) \
1395 OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep); \
1398 #define OBDO_FREE(ptr) \
1400 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1403 /* I'm as embarrassed about this as you are.
1405 * <shaver> // XXX do not look into _superhack with remaining eye
1406 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1407 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1410 extern void obd_sysctl_init (void);
1411 extern void obd_sysctl_clean (void);
1414 typedef __u8 class_uuid_t[16];
1415 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1418 int lustre_uuid_to_peer(char *uuid, lnet_nid_t *peer_nid, int index);
1419 int class_add_uuid(char *uuid, __u64 nid);
1420 int class_del_uuid (char *uuid);
1421 void class_init_uuidlist(void);
1422 void class_exit_uuidlist(void);
1425 void ll_generate_random_uuid(class_uuid_t uuid_out);
1427 #endif /* __LINUX_OBD_CLASS_H */