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);
100 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
102 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
104 memset(lvars, 0, sizeof(*lvars));
108 #define CFG_F_START 0x01 /* Set when we start updating from a log */
109 #define CFG_F_MARKER 0x02 /* We are within a maker */
110 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
111 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
112 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
114 /* Passed as data param to class_config_parse_llog */
115 struct config_llog_instance {
117 struct super_block *cfg_sb;
118 struct obd_uuid cfg_uuid;
119 int cfg_last_idx; /* for partial llog processing */
122 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
123 struct config_llog_instance *cfg);
124 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
125 struct config_llog_instance *cfg);
127 /* list of active configuration logs */
128 struct config_llog_data {
130 struct ldlm_res_id cld_resid;
131 struct config_llog_instance cld_cfg;
132 struct list_head cld_list_chain;
133 atomic_t cld_refcount;
134 struct obd_export *cld_mgcexp;
135 unsigned int cld_stopping:1; /* we were told to stop watching */
136 unsigned int cld_lostlock:1; /* lock not requeued */
139 struct lustre_profile {
140 struct list_head lp_list;
146 struct lustre_profile *class_get_profile(char * prof);
147 void class_del_profile(char *prof);
148 void class_del_profiles(void);
150 #define class_export_rpc_get(exp) \
152 atomic_inc(&(exp)->exp_rpc_count); \
153 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
154 (exp), atomic_read(&(exp)->exp_rpc_count)); \
155 class_export_get(exp); \
158 #define class_export_rpc_put(exp) \
160 atomic_dec(&(exp)->exp_rpc_count); \
161 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
162 (exp), atomic_read(&(exp)->exp_rpc_count)); \
163 class_export_put(exp); \
167 #define class_export_get(exp) \
169 struct obd_export *exp_ = exp; \
170 atomic_inc(&exp_->exp_refcount); \
171 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
172 atomic_read(&exp_->exp_refcount)); \
176 #define class_export_put(exp) \
178 LASSERT((exp) != NULL); \
179 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
180 atomic_read(&(exp)->exp_refcount) - 1); \
181 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
182 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
183 __class_export_put(exp); \
186 void __class_export_put(struct obd_export *);
187 struct obd_export *class_new_export(struct obd_device *obddev,
188 struct obd_uuid *cluuid);
189 void class_unlink_export(struct obd_export *exp);
191 struct obd_import *class_import_get(struct obd_import *);
192 void class_import_put(struct obd_import *);
193 struct obd_import *class_new_import(struct obd_device *obd);
194 void class_destroy_import(struct obd_import *exp);
196 struct obd_type *class_search_type(const char *name);
197 struct obd_type *class_get_type(const char *name);
198 void class_put_type(struct obd_type *type);
199 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
200 struct obd_uuid *cluuid);
201 int class_disconnect(struct obd_export *exp);
202 void class_fail_export(struct obd_export *exp);
203 void class_disconnect_exports(struct obd_device *obddev);
204 void class_disconnect_stale_exports(struct obd_device *obddev);
205 int class_manual_cleanup(struct obd_device *obd);
208 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
209 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
212 #define OBT(dev) (dev)->obd_type
213 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
214 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
216 /* Ensure obd_setup: used for cleanup which must be called
217 while obd is stopping */
218 #define OBD_CHECK_DEV(obd) \
221 CERROR("NULL device\n"); \
226 /* ensure obd_setup and !obd_stopping */
227 #define OBD_CHECK_DEV_ACTIVE(obd) \
229 OBD_CHECK_DEV(obd); \
230 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
231 CERROR("Device %d not setup\n", \
239 #define OBD_COUNTER_OFFSET(op) \
240 ((offsetof(struct obd_ops, o_ ## op) - \
241 offsetof(struct obd_ops, o_iocontrol)) \
242 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
244 #define OBD_COUNTER_INCREMENT(obdx, op) \
245 if ((obdx)->obd_stats != NULL) { \
246 unsigned int coffset; \
247 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
248 OBD_COUNTER_OFFSET(op); \
249 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
250 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
253 #define EXP_COUNTER_INCREMENT(export, op) \
254 if ((export)->exp_obd->obd_stats != NULL) { \
255 unsigned int coffset; \
256 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
257 OBD_COUNTER_OFFSET(op); \
258 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
259 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
260 if ((export)->exp_nid_stats != NULL && \
261 (export)->exp_nid_stats->nid_stats != NULL) \
262 lprocfs_counter_incr( \
263 (export)->exp_nid_stats->nid_stats, coffset);\
267 #define OBD_COUNTER_OFFSET(op)
268 #define OBD_COUNTER_INCREMENT(obd, op)
269 #define EXP_COUNTER_INCREMENT(exp, op);
272 #define OBD_CHECK_OP(obd, op, err) \
274 if (!OBT(obd) || !OBP((obd), op)) {\
276 CERROR("obd_" #op ": dev %d no operation\n", \
282 #define EXP_CHECK_OP(exp, op) \
284 if ((exp) == NULL) { \
285 CERROR("obd_" #op ": NULL export\n"); \
288 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
289 CERROR("obd_" #op ": cleaned up obd\n"); \
290 RETURN(-EOPNOTSUPP); \
292 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
293 CERROR("obd_" #op ": dev %d no operation\n", \
294 (exp)->exp_obd->obd_minor); \
295 RETURN(-EOPNOTSUPP); \
299 #define CTXT_CHECK_OP(ctxt, op, err) \
301 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
303 CERROR("lop_" #op ": dev %d no operation\n", \
304 ctxt->loc_obd->obd_minor); \
309 static inline int class_devno_max(void)
311 return MAX_OBD_DEVICES;
314 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
315 void *key, __u32 *vallen, void *val)
320 EXP_CHECK_OP(exp, get_info);
321 EXP_COUNTER_INCREMENT(exp, get_info);
323 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
327 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
328 void *key, obd_count vallen, void *val,
329 struct ptlrpc_request_set *set)
334 EXP_CHECK_OP(exp, set_info_async);
335 EXP_COUNTER_INCREMENT(exp, set_info_async);
337 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
342 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
347 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
348 OBD_COUNTER_INCREMENT(obd, setup);
350 rc = OBP(obd, setup)(obd, datalen, data);
354 static inline int obd_precleanup(struct obd_device *obd,
355 enum obd_cleanup_stage cleanup_stage)
360 OBD_CHECK_OP(obd, precleanup, 0);
361 OBD_COUNTER_INCREMENT(obd, precleanup);
363 rc = OBP(obd, precleanup)(obd, cleanup_stage);
367 static inline int obd_cleanup(struct obd_device *obd)
373 OBD_CHECK_OP(obd, cleanup, 0);
374 OBD_COUNTER_INCREMENT(obd, cleanup);
376 rc = OBP(obd, cleanup)(obd);
381 obd_process_config(struct obd_device *obd, int datalen, void *data)
386 OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
387 OBD_COUNTER_INCREMENT(obd, process_config);
389 rc = OBP(obd, process_config)(obd, datalen, data);
393 /* Pack an in-memory MD struct for storage on disk.
394 * Returns +ve size of packed MD (0 for free), or -ve error.
396 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
397 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
398 * If @*disk_tgt == NULL, it will be allocated
400 static inline int obd_packmd(struct obd_export *exp,
401 struct lov_mds_md **disk_tgt,
402 struct lov_stripe_md *mem_src)
407 EXP_CHECK_OP(exp, packmd);
408 EXP_COUNTER_INCREMENT(exp, packmd);
410 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
414 static inline int obd_size_diskmd(struct obd_export *exp,
415 struct lov_stripe_md *mem_src)
417 return obd_packmd(exp, NULL, mem_src);
420 /* helper functions */
421 static inline int obd_alloc_diskmd(struct obd_export *exp,
422 struct lov_mds_md **disk_tgt)
425 LASSERT(*disk_tgt == NULL);
426 return obd_packmd(exp, disk_tgt, NULL);
429 static inline int obd_free_diskmd(struct obd_export *exp,
430 struct lov_mds_md **disk_tgt)
434 return obd_packmd(exp, disk_tgt, NULL);
437 /* Unpack an MD struct from disk to in-memory format.
438 * Returns +ve size of unpacked MD (0 for free), or -ve error.
440 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
441 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
442 * If @*mem_tgt == NULL, it will be allocated
444 static inline int obd_unpackmd(struct obd_export *exp,
445 struct lov_stripe_md **mem_tgt,
446 struct lov_mds_md *disk_src,
452 EXP_CHECK_OP(exp, unpackmd);
453 EXP_COUNTER_INCREMENT(exp, unpackmd);
455 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
459 /* helper functions */
460 static inline int obd_alloc_memmd(struct obd_export *exp,
461 struct lov_stripe_md **mem_tgt)
464 LASSERT(*mem_tgt == NULL);
465 return obd_unpackmd(exp, mem_tgt, NULL, 0);
468 static inline int obd_free_memmd(struct obd_export *exp,
469 struct lov_stripe_md **mem_tgt)
473 return obd_unpackmd(exp, mem_tgt, NULL, 0);
476 static inline int obd_checkmd(struct obd_export *exp,
477 struct obd_export *md_exp,
478 struct lov_stripe_md *mem_tgt)
483 EXP_CHECK_OP(exp, checkmd);
484 EXP_COUNTER_INCREMENT(exp, checkmd);
486 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
490 static inline int obd_precreate(struct obd_export *exp)
495 EXP_CHECK_OP(exp, precreate);
496 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
498 rc = OBP(exp->exp_obd, precreate)(exp);
502 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
503 struct lov_stripe_md **ea,
504 struct obd_trans_info *oti)
509 EXP_CHECK_OP(exp, create);
510 EXP_COUNTER_INCREMENT(exp, create);
512 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
516 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
517 struct lov_stripe_md *ea,
518 struct obd_trans_info *oti,
519 struct obd_export *md_exp)
524 EXP_CHECK_OP(exp, destroy);
525 EXP_COUNTER_INCREMENT(exp, destroy);
527 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
531 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
536 EXP_CHECK_OP(exp, getattr);
537 EXP_COUNTER_INCREMENT(exp, getattr);
539 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
543 static inline int obd_getattr_async(struct obd_export *exp,
544 struct obd_info *oinfo,
545 struct ptlrpc_request_set *set)
550 EXP_CHECK_OP(exp, getattr_async);
551 EXP_COUNTER_INCREMENT(exp, getattr_async);
553 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
557 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
558 struct obd_trans_info *oti)
563 EXP_CHECK_OP(exp, setattr);
564 EXP_COUNTER_INCREMENT(exp, setattr);
566 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
570 /* This performs all the requests set init/wait/destroy actions. */
571 static inline int obd_setattr_rqset(struct obd_export *exp,
572 struct obd_info *oinfo,
573 struct obd_trans_info *oti)
575 struct ptlrpc_request_set *set = NULL;
579 EXP_CHECK_OP(exp, setattr_async);
580 EXP_COUNTER_INCREMENT(exp, setattr_async);
582 set = ptlrpc_prep_set();
586 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
588 rc = ptlrpc_set_wait(set);
589 ptlrpc_set_destroy(set);
593 /* This adds all the requests into @set if @set != NULL, otherwise
594 all requests are sent asynchronously without waiting for response. */
595 static inline int obd_setattr_async(struct obd_export *exp,
596 struct obd_info *oinfo,
597 struct obd_trans_info *oti,
598 struct ptlrpc_request_set *set)
603 EXP_CHECK_OP(exp, setattr_async);
604 EXP_COUNTER_INCREMENT(exp, setattr_async);
606 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
610 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
613 struct obd_device *obd = imp->imp_obd;
617 OBD_CHECK_DEV_ACTIVE(obd);
618 OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
619 OBD_COUNTER_INCREMENT(obd, add_conn);
621 rc = OBP(obd, add_conn)(imp, uuid, priority);
625 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
627 struct obd_device *obd = imp->imp_obd;
631 OBD_CHECK_DEV_ACTIVE(obd);
632 OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
633 OBD_COUNTER_INCREMENT(obd, del_conn);
635 rc = OBP(obd, del_conn)(imp, uuid);
639 static inline int obd_connect(struct lustre_handle *conn,struct obd_device *obd,
640 struct obd_uuid *cluuid,
641 struct obd_connect_data *d,
645 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
648 OBD_CHECK_DEV_ACTIVE(obd);
649 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
650 OBD_COUNTER_INCREMENT(obd, connect);
652 rc = OBP(obd, connect)(conn, obd, cluuid, d, localdata);
653 /* check that only subset is granted */
654 LASSERT(ergo(d != NULL,
655 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
659 static inline int obd_reconnect(struct obd_export *exp,
660 struct obd_device *obd,
661 struct obd_uuid *cluuid,
662 struct obd_connect_data *d)
665 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
668 OBD_CHECK_DEV_ACTIVE(obd);
669 OBD_CHECK_OP(obd, reconnect, 0);
670 OBD_COUNTER_INCREMENT(obd, reconnect);
672 rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
673 /* check that only subset is granted */
674 LASSERT(ergo(d != NULL,
675 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
679 static inline int obd_disconnect(struct obd_export *exp)
684 EXP_CHECK_OP(exp, disconnect);
685 EXP_COUNTER_INCREMENT(exp, disconnect);
687 rc = OBP(exp->exp_obd, disconnect)(exp);
691 static inline int obd_ping(struct obd_export *exp)
696 OBD_CHECK_OP(exp->exp_obd, ping, 0);
697 EXP_COUNTER_INCREMENT(exp, ping);
699 rc = OBP(exp->exp_obd, ping)(exp);
703 static inline int obd_init_export(struct obd_export *exp)
708 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
709 OBP((exp)->exp_obd, init_export))
710 rc = OBP(exp->exp_obd, init_export)(exp);
714 static inline int obd_destroy_export(struct obd_export *exp)
717 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
718 OBP((exp)->exp_obd, destroy_export))
719 OBP(exp->exp_obd, destroy_export)(exp);
723 static inline int obd_extent_calc(struct obd_export *exp,
724 struct lov_stripe_md *md,
725 int cmd, obd_off *offset)
729 EXP_CHECK_OP(exp, extent_calc);
730 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
734 static inline struct dentry *
735 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
737 LASSERT(exp->exp_obd);
739 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
744 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
747 /* @max_age is the oldest time in jiffies that we accept using a cached data.
748 * If the cache is older than @max_age we will get a new value from the
749 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
750 static inline int obd_statfs_async(struct obd_device *obd,
751 struct obd_info *oinfo,
753 struct ptlrpc_request_set *rqset)
761 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
762 OBD_COUNTER_INCREMENT(obd, statfs);
764 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
765 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
766 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
767 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
769 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
770 " objects "LPU64"/"LPU64"\n",
771 obd->obd_name, &obd->obd_osfs,
772 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
773 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
774 spin_lock(&obd->obd_osfs_lock);
775 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
776 spin_unlock(&obd->obd_osfs_lock);
778 oinfo->oi_cb_up(oinfo, 0);
783 static inline int obd_statfs_rqset(struct obd_device *obd,
784 struct obd_statfs *osfs, __u64 max_age)
786 struct ptlrpc_request_set *set = NULL;
787 struct obd_info oinfo = { { { 0 } } };
791 set = ptlrpc_prep_set();
795 oinfo.oi_osfs = osfs;
796 rc = obd_statfs_async(obd, &oinfo, max_age, set);
798 rc = ptlrpc_set_wait(set);
799 ptlrpc_set_destroy(set);
803 /* @max_age is the oldest time in jiffies that we accept using a cached data.
804 * If the cache is older than @max_age we will get a new value from the
805 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
806 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
815 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
816 OBD_COUNTER_INCREMENT(obd, statfs);
818 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
819 obd->obd_osfs_age, max_age);
820 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
821 rc = OBP(obd, statfs)(obd, osfs, max_age);
823 spin_lock(&obd->obd_osfs_lock);
824 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
825 obd->obd_osfs_age = cfs_time_current_64();
826 spin_unlock(&obd->obd_osfs_lock);
829 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
830 " objects "LPU64"/"LPU64"\n",
831 obd->obd_name, &obd->obd_osfs,
832 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
833 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
834 spin_lock(&obd->obd_osfs_lock);
835 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
836 spin_unlock(&obd->obd_osfs_lock);
841 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
842 struct lov_stripe_md *ea, obd_size start,
848 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
849 EXP_COUNTER_INCREMENT(exp, sync);
851 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
855 static inline int obd_punch_rqset(struct obd_export *exp,
856 struct obd_info *oinfo,
857 struct obd_trans_info *oti)
859 struct ptlrpc_request_set *set = NULL;
863 EXP_CHECK_OP(exp, punch);
864 EXP_COUNTER_INCREMENT(exp, punch);
866 set = ptlrpc_prep_set();
870 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
872 rc = ptlrpc_set_wait(set);
873 ptlrpc_set_destroy(set);
877 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
878 struct obd_trans_info *oti,
879 struct ptlrpc_request_set *rqset)
884 EXP_CHECK_OP(exp, punch);
885 EXP_COUNTER_INCREMENT(exp, punch);
887 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
891 static inline int obd_brw(int cmd, struct obd_export *exp,
892 struct obd_info *oinfo, obd_count oa_bufs,
893 struct brw_page *pg, struct obd_trans_info *oti)
898 EXP_CHECK_OP(exp, brw);
899 EXP_COUNTER_INCREMENT(exp, brw);
901 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
902 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
903 "or OBD_BRW_CHECK\n");
907 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
911 static inline int obd_brw_async(int cmd, struct obd_export *exp,
912 struct obd_info *oinfo, obd_count oa_bufs,
913 struct brw_page *pg, struct obd_trans_info *oti,
914 struct ptlrpc_request_set *set)
919 EXP_CHECK_OP(exp, brw_async);
920 EXP_COUNTER_INCREMENT(exp, brw_async);
922 if (!(cmd & OBD_BRW_RWMASK)) {
923 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
927 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs, pg,oti,set);
931 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
932 struct obdo *oa, struct lov_stripe_md *lsm,
933 obd_count oa_bufs, struct brw_page *pg,
934 struct obd_trans_info *oti)
936 struct ptlrpc_request_set *set = NULL;
937 struct obd_info oinfo = { { { 0 } } };
941 set = ptlrpc_prep_set();
947 rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
949 rc = ptlrpc_set_wait(set);
951 CERROR("error from callback: rc = %d\n", rc);
953 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
954 "error from obd_brw_async: rc = %d\n", rc);
956 ptlrpc_set_destroy(set);
960 static inline int obd_prep_async_page(struct obd_export *exp,
961 struct lov_stripe_md *lsm,
962 struct lov_oinfo *loi,
963 cfs_page_t *page, obd_off offset,
964 struct obd_async_page_ops *ops,
965 void *data, void **res, int nocache,
966 struct lustre_handle *lockh)
971 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
972 EXP_COUNTER_INCREMENT(exp, prep_async_page);
974 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
975 ops, data, res, nocache,
980 static inline int obd_queue_async_io(struct obd_export *exp,
981 struct lov_stripe_md *lsm,
982 struct lov_oinfo *loi, void *cookie,
983 int cmd, obd_off off, int count,
984 obd_flag brw_flags, obd_flag async_flags)
989 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
990 EXP_COUNTER_INCREMENT(exp, queue_async_io);
991 LASSERT(cmd & OBD_BRW_RWMASK);
993 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
994 count, brw_flags, async_flags);
998 static inline int obd_set_async_flags(struct obd_export *exp,
999 struct lov_stripe_md *lsm,
1000 struct lov_oinfo *loi, void *cookie,
1001 obd_flag async_flags)
1006 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
1007 EXP_COUNTER_INCREMENT(exp, set_async_flags);
1009 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1014 static inline int obd_queue_group_io(struct obd_export *exp,
1015 struct lov_stripe_md *lsm,
1016 struct lov_oinfo *loi,
1017 struct obd_io_group *oig,
1018 void *cookie, int cmd, obd_off off,
1019 int count, obd_flag brw_flags,
1020 obd_flag async_flags)
1025 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
1026 EXP_COUNTER_INCREMENT(exp, queue_group_io);
1027 LASSERT(cmd & OBD_BRW_RWMASK);
1029 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1030 cmd, off, count, brw_flags,
1035 static inline int obd_trigger_group_io(struct obd_export *exp,
1036 struct lov_stripe_md *lsm,
1037 struct lov_oinfo *loi,
1038 struct obd_io_group *oig)
1043 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
1044 EXP_COUNTER_INCREMENT(exp, trigger_group_io);
1046 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1050 static inline int obd_teardown_async_page(struct obd_export *exp,
1051 struct lov_stripe_md *lsm,
1052 struct lov_oinfo *loi, void *cookie)
1057 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
1058 EXP_COUNTER_INCREMENT(exp, teardown_async_page);
1060 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1064 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1065 int objcount, struct obd_ioobj *obj,
1066 int niocount, struct niobuf_remote *remote,
1067 struct niobuf_local *local,
1068 struct obd_trans_info *oti)
1073 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
1074 EXP_COUNTER_INCREMENT(exp, preprw);
1076 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1077 remote, local, oti);
1081 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1082 int objcount, struct obd_ioobj *obj,
1083 int niocount, struct niobuf_local *local,
1084 struct obd_trans_info *oti, int rc)
1088 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1089 EXP_COUNTER_INCREMENT(exp, commitrw);
1091 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1096 static inline int obd_merge_lvb(struct obd_export *exp,
1097 struct lov_stripe_md *lsm,
1098 struct ost_lvb *lvb, int kms_only)
1103 OBD_CHECK_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1104 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1106 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1110 static inline int obd_adjust_kms(struct obd_export *exp,
1111 struct lov_stripe_md *lsm, obd_off size,
1117 OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1118 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1120 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1124 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1125 int len, void *karg, void *uarg)
1130 EXP_CHECK_OP(exp, iocontrol);
1131 EXP_COUNTER_INCREMENT(exp, iocontrol);
1133 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1137 static inline int obd_enqueue_rqset(struct obd_export *exp,
1138 struct obd_info *oinfo,
1139 struct ldlm_enqueue_info *einfo)
1141 struct ptlrpc_request_set *set = NULL;
1145 EXP_CHECK_OP(exp, enqueue);
1146 EXP_COUNTER_INCREMENT(exp, enqueue);
1148 set = ptlrpc_prep_set();
1152 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1154 rc = ptlrpc_set_wait(set);
1155 ptlrpc_set_destroy(set);
1159 static inline int obd_enqueue(struct obd_export *exp,
1160 struct obd_info *oinfo,
1161 struct ldlm_enqueue_info *einfo,
1162 struct ptlrpc_request_set *set)
1167 EXP_CHECK_OP(exp, enqueue);
1168 EXP_COUNTER_INCREMENT(exp, enqueue);
1170 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1174 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1175 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1176 int *flags, void *data, struct lustre_handle *lockh)
1181 EXP_CHECK_OP(exp, match);
1182 EXP_COUNTER_INCREMENT(exp, match);
1184 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1189 static inline int obd_change_cbdata(struct obd_export *exp,
1190 struct lov_stripe_md *lsm,
1191 ldlm_iterator_t it, void *data)
1196 EXP_CHECK_OP(exp, change_cbdata);
1197 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1199 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1203 static inline int obd_cancel(struct obd_export *exp,
1204 struct lov_stripe_md *ea, __u32 mode,
1205 struct lustre_handle *lockh)
1210 EXP_CHECK_OP(exp, cancel);
1211 EXP_COUNTER_INCREMENT(exp, cancel);
1213 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1217 static inline int obd_cancel_unused(struct obd_export *exp,
1218 struct lov_stripe_md *ea, int flags,
1224 EXP_CHECK_OP(exp, cancel_unused);
1225 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1227 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1231 static inline int obd_join_lru(struct obd_export *exp,
1232 struct lov_stripe_md *ea, int join)
1237 EXP_CHECK_OP(exp, join_lru);
1238 EXP_COUNTER_INCREMENT(exp, join_lru);
1240 rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1244 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1245 int type, struct obd_client_handle *handle, int flag)
1250 EXP_CHECK_OP(exp, pin);
1251 EXP_COUNTER_INCREMENT(exp, pin);
1253 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1257 static inline int obd_unpin(struct obd_export *exp,
1258 struct obd_client_handle *handle, int flag)
1263 EXP_CHECK_OP(exp, unpin);
1264 EXP_COUNTER_INCREMENT(exp, unpin);
1266 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1271 static inline void obd_import_event(struct obd_device *obd,
1272 struct obd_import *imp,
1273 enum obd_import_event event)
1277 CERROR("NULL device\n");
1281 if (obd->obd_set_up && OBP(obd, import_event)) {
1282 OBD_COUNTER_INCREMENT(obd, import_event);
1283 OBP(obd, import_event)(obd, imp, event);
1288 static inline int obd_notify(struct obd_device *obd,
1289 struct obd_device *watched,
1290 enum obd_notify_event ev, void *data)
1295 /* the check for async_recov is a complete hack - I'm hereby
1296 overloading the meaning to also mean "this was called from
1297 mds_postsetup". I know that my mds is able to handle notifies
1298 by this point, and it needs to get them to execute mds_postrecov. */
1299 if (!obd->obd_set_up && !obd->obd_async_recov) {
1300 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1304 if (!OBP(obd, notify))
1307 OBD_COUNTER_INCREMENT(obd, notify);
1308 RETURN(OBP(obd, notify)(obd, watched, ev, data));
1311 static inline int obd_notify_observer(struct obd_device *observer,
1312 struct obd_device *observed,
1313 enum obd_notify_event ev, void *data)
1318 struct obd_notify_upcall *onu;
1320 if (observer->obd_observer)
1321 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1325 * Also, call non-obd listener, if any
1327 onu = &observer->obd_upcall;
1328 if (onu->onu_upcall != NULL)
1329 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1336 static inline int obd_quotacheck(struct obd_export *exp,
1337 struct obd_quotactl *oqctl)
1342 EXP_CHECK_OP(exp, quotacheck);
1343 EXP_COUNTER_INCREMENT(exp, quotacheck);
1345 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1349 static inline int obd_quotactl(struct obd_export *exp,
1350 struct obd_quotactl *oqctl)
1355 EXP_CHECK_OP(exp, quotactl);
1356 EXP_COUNTER_INCREMENT(exp, quotactl);
1358 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1362 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1363 struct quota_adjust_qunit *oqaq)
1368 EXP_CHECK_OP(exp, quota_adjust_qunit);
1369 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1371 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq);
1375 static inline int obd_health_check(struct obd_device *obd)
1377 /* returns: 0 on healthy
1378 * >0 on unhealthy + reason code/flag
1379 * however the only suppored reason == 1 right now
1380 * We'll need to define some better reasons
1381 * or flags in the future.
1387 /* don't use EXP_CHECK_OP, because NULL method is normal here */
1388 if (obd == NULL || !OBT(obd)) {
1389 CERROR("cleaned up obd\n");
1390 RETURN(-EOPNOTSUPP);
1392 if (!obd->obd_set_up || obd->obd_stopping)
1394 if (!OBP(obd, health_check))
1397 rc = OBP(obd, health_check)(obd);
1401 static inline int obd_register_observer(struct obd_device *obd,
1402 struct obd_device *observer)
1406 if (obd->obd_observer && observer)
1408 obd->obd_observer = observer;
1412 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1413 obd_page_removal_cb_t cb,
1414 obd_pin_extent_cb pin_cb)
1419 OBD_CHECK_OP(exp->exp_obd, register_page_removal_cb, 0);
1420 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1422 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1426 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1427 obd_page_removal_cb_t cb)
1432 OBD_CHECK_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1433 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1435 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1439 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1440 obd_lock_cancel_cb cb)
1445 OBD_CHECK_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1446 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1448 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1452 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1453 obd_lock_cancel_cb cb)
1458 OBD_CHECK_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1459 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1461 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1465 /* OBD Metadata Support */
1467 extern int obd_init_caches(void);
1468 extern void obd_cleanup_caches(void);
1470 /* support routines */
1471 extern cfs_mem_cache_t *obdo_cachep;
1473 #define OBDO_ALLOC(ptr) \
1475 OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep); \
1478 #define OBDO_FREE(ptr) \
1480 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1483 /* I'm as embarrassed about this as you are.
1485 * <shaver> // XXX do not look into _superhack with remaining eye
1486 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1487 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1490 extern void obd_sysctl_init (void);
1491 extern void obd_sysctl_clean (void);
1494 typedef __u8 class_uuid_t[16];
1495 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1498 int lustre_uuid_to_peer(char *uuid, lnet_nid_t *peer_nid, int index);
1499 int class_add_uuid(char *uuid, __u64 nid);
1500 int class_del_uuid (char *uuid);
1501 void class_init_uuidlist(void);
1502 void class_exit_uuidlist(void);
1505 void ll_generate_random_uuid(class_uuid_t uuid_out);
1507 #endif /* __LINUX_OBD_CLASS_H */