drivers: staging: lustre: lustre: Fix "foo * bar" should be "foo *bar" errors
[deliverable/linux.git] / drivers / staging / lustre / lustre / include / obd_class.h
CommitLineData
d7e09d03
PT
1/*
2 * GPL HEADER START
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 *
24 * GPL HEADER END
25 */
26/*
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
29 *
30 * Copyright (c) 2011, 2012, Intel Corporation.
31 */
32/*
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
35 */
36#ifndef __CLASS_OBD_H
37#define __CLASS_OBD_H
38
39
1accaadf
GKH
40#include "obd_support.h"
41#include "lustre_import.h"
42#include "lustre_net.h"
43#include "obd.h"
44#include "lustre_lib.h"
45#include "lustre/lustre_idl.h"
46#include "lprocfs_status.h"
d7e09d03 47
1accaadf 48#include "linux/obd_class.h"
d7e09d03
PT
49
50#define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
51 * and resends for avoid deadlocks */
52#define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
53 * obd_osfs_age */
54#define OBD_STATFS_PTLRPCD 0x0004 /* requests will be sent via ptlrpcd
55 * instead of a specific set. This
56 * means that we cannot rely on the set
57 * interpret routine to be called.
58 * lov_statfs_fini() must thus be called
59 * by the request interpret routine */
60#define OBD_STATFS_FOR_MDT0 0x0008 /* The statfs is only for retrieving
61 * information from MDT0. */
62#define OBD_FL_PUNCH 0x00000001 /* To indicate it is punch operation */
63
64/* OBD Device Declarations */
65extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
66extern rwlock_t obd_dev_lock;
67
68/* OBD Operations Declarations */
69extern struct obd_device *class_conn2obd(struct lustre_handle *);
70extern struct obd_device *class_exp2obd(struct obd_export *);
71extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
72extern int lustre_get_jobid(char *jobid);
73
74struct lu_device_type;
75
76/* genops.c */
77struct obd_export *class_conn2export(struct lustre_handle *);
78int class_register_type(struct obd_ops *, struct md_ops *,
79 struct lprocfs_vars *, const char *nm,
80 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_uuid2obd(struct obd_uuid *uuid);
90void class_obd_list(void);
aff9d8e8
GD
91struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
92 const char *typ_name,
d7e09d03 93 struct obd_uuid *grp_uuid);
aff9d8e8 94struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid,
d7e09d03 95 int *next);
aff9d8e8 96struct obd_device *class_num2obd(int num);
d7e09d03
PT
97int get_devices_count(void);
98
99int class_notify_sptlrpc_conf(const char *fsname, int namelen);
100
101char *obd_export_nid2str(struct obd_export *exp);
102
103int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
104int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
105int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
106
107int obd_zombie_impexp_init(void);
108void obd_zombie_impexp_stop(void);
109void obd_zombie_impexp_cull(void);
110void obd_zombie_barrier(void);
111void obd_exports_barrier(struct obd_device *obd);
112int kuc_len(int payload_len);
aff9d8e8 113struct kuc_hdr *kuc_ptr(void *p);
d7e09d03
PT
114int kuc_ispayload(void *p);
115void *kuc_alloc(int payload_len, int transport, int type);
116void kuc_free(void *p, int payload_len);
117
118struct llog_handle;
119struct llog_rec_hdr;
120typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
121 struct llog_rec_hdr *, void *);
122/* obd_config.c */
123struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
124 const char *new_name);
125int class_process_config(struct lustre_cfg *lcfg);
126int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
127 struct lustre_cfg *lcfg, void *data);
128int class_attach(struct lustre_cfg *lcfg);
129int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
130int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
131int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
132struct obd_device *class_incref(struct obd_device *obd,
133 const char *scope, const void *source);
134void class_decref(struct obd_device *obd,
135 const char *scope, const void *source);
136void dump_exports(struct obd_device *obd, int locks);
137int class_config_llog_handler(const struct lu_env *env,
138 struct llog_handle *handle,
139 struct llog_rec_hdr *rec, void *data);
140int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
141int class_add_uuid(const char *uuid, __u64 nid);
142
143/*obdecho*/
f267cdb4 144#if defined (CONFIG_PROC_FS)
d7e09d03
PT
145extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
146#else
147static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
148{
149 memset(lvars, 0, sizeof(*lvars));
150}
151#endif
152
153#define CFG_F_START 0x01 /* Set when we start updating from a log */
154#define CFG_F_MARKER 0x02 /* We are within a maker */
155#define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
156#define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
157#define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
158
159/* Passed as data param to class_config_parse_llog */
160struct config_llog_instance {
161 char *cfg_obdname;
162 void *cfg_instance;
163 struct super_block *cfg_sb;
164 struct obd_uuid cfg_uuid;
165 llog_cb_t cfg_callback;
166 int cfg_last_idx; /* for partial llog processing */
167 int cfg_flags;
168};
169int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
170 char *name, struct config_llog_instance *cfg);
171int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
172 char *name, struct config_llog_instance *cfg);
173
174enum {
175 CONFIG_T_CONFIG = 0,
176 CONFIG_T_SPTLRPC = 1,
177 CONFIG_T_RECOVER = 2,
7d4bae45
AB
178 CONFIG_T_PARAMS = 3,
179 CONFIG_T_MAX = 4
d7e09d03
PT
180};
181
7d4bae45
AB
182#define PARAMS_FILENAME "params"
183#define LCTL_UPCALL "lctl"
184
d7e09d03
PT
185/* list of active configuration logs */
186struct config_llog_data {
187 struct ldlm_res_id cld_resid;
188 struct config_llog_instance cld_cfg;
189 struct list_head cld_list_chain;
190 atomic_t cld_refcount;
191 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
7d4bae45
AB
192 struct config_llog_data *cld_params; /* common parameters log */
193 struct config_llog_data *cld_recover;/* imperative recover log */
d7e09d03
PT
194 struct obd_export *cld_mgcexp;
195 struct mutex cld_lock;
196 int cld_type;
197 unsigned int cld_stopping:1, /* we were told to stop
198 * watching */
199 cld_lostlock:1; /* lock not requeued */
200 char cld_logname[0];
201};
202
203struct lustre_profile {
204 struct list_head lp_list;
205 char *lp_profile;
206 char *lp_dt;
207 char *lp_md;
208};
209
aff9d8e8 210struct lustre_profile *class_get_profile(const char *prof);
d7e09d03
PT
211void class_del_profile(const char *prof);
212void class_del_profiles(void);
213
214#if LUSTRE_TRACKS_LOCK_EXP_REFS
215
216void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
217void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
218extern void (*class_export_dump_hook)(struct obd_export *);
219
220#else
221
222#define __class_export_add_lock_ref(exp, lock) do {} while(0)
223#define __class_export_del_lock_ref(exp, lock) do {} while(0)
224
225#endif
226
227#define class_export_rpc_inc(exp) \
228({ \
229 atomic_inc(&(exp)->exp_rpc_count); \
230 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
231 (exp), atomic_read(&(exp)->exp_rpc_count)); \
232})
233
234#define class_export_rpc_dec(exp) \
235({ \
236 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
237 atomic_dec(&(exp)->exp_rpc_count); \
238 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
239 (exp), atomic_read(&(exp)->exp_rpc_count)); \
240})
241
242#define class_export_lock_get(exp, lock) \
243({ \
244 atomic_inc(&(exp)->exp_locks_count); \
245 __class_export_add_lock_ref(exp, lock); \
246 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
247 (exp), atomic_read(&(exp)->exp_locks_count)); \
248 class_export_get(exp); \
249})
250
251#define class_export_lock_put(exp, lock) \
252({ \
253 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
254 atomic_dec(&(exp)->exp_locks_count); \
255 __class_export_del_lock_ref(exp, lock); \
256 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
257 (exp), atomic_read(&(exp)->exp_locks_count)); \
258 class_export_put(exp); \
259})
260
261#define class_export_cb_get(exp) \
262({ \
263 atomic_inc(&(exp)->exp_cb_count); \
264 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
265 (exp), atomic_read(&(exp)->exp_cb_count)); \
266 class_export_get(exp); \
267})
268
269#define class_export_cb_put(exp) \
270({ \
271 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
272 atomic_dec(&(exp)->exp_cb_count); \
273 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
274 (exp), atomic_read(&(exp)->exp_cb_count)); \
275 class_export_put(exp); \
276})
277
278/* genops.c */
279struct obd_export *class_export_get(struct obd_export *exp);
280void class_export_put(struct obd_export *exp);
281struct obd_export *class_new_export(struct obd_device *obddev,
282 struct obd_uuid *cluuid);
283void class_unlink_export(struct obd_export *exp);
284
285struct obd_import *class_import_get(struct obd_import *);
286void class_import_put(struct obd_import *);
287struct obd_import *class_new_import(struct obd_device *obd);
288void class_destroy_import(struct obd_import *exp);
289
290struct obd_type *class_search_type(const char *name);
291struct obd_type *class_get_type(const char *name);
292void class_put_type(struct obd_type *type);
293int class_connect(struct lustre_handle *conn, struct obd_device *obd,
294 struct obd_uuid *cluuid);
295int class_disconnect(struct obd_export *exp);
296void class_fail_export(struct obd_export *exp);
297int class_connected_export(struct obd_export *exp);
298void class_disconnect_exports(struct obd_device *obddev);
299int class_manual_cleanup(struct obd_device *obd);
300void class_disconnect_stale_exports(struct obd_device *,
301 int (*test_export)(struct obd_export *));
302static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
303{
304 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
305 (obd->obd_force ? OBD_OPT_FORCE : 0) |
306 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
307 0);
308}
309
310
21aef7d9 311void obdo_cpy_md(struct obdo *dst, struct obdo *src, u32 valid);
d7e09d03
PT
312void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
313void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
314 unsigned int ia_valid);
21aef7d9
OD
315void iattr_from_obdo(struct iattr *attr, struct obdo *oa, u32 valid);
316void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, u32 valid);
d7e09d03
PT
317void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
318 unsigned int valid);
319
320void obdo_cpu_to_le(struct obdo *dobdo, struct obdo *sobdo);
321void obdo_le_to_cpu(struct obdo *dobdo, struct obdo *sobdo);
322
323#define OBT(dev) (dev)->obd_type
324#define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
325#define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
326#define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
327
328/* Ensure obd_setup: used for cleanup which must be called
329 while obd is stopping */
330#define OBD_CHECK_DEV(obd) \
331do { \
332 if (!(obd)) { \
333 CERROR("NULL device\n"); \
0a3bdb00 334 return -ENODEV; \
d7e09d03
PT
335 } \
336} while (0)
337
338/* ensure obd_setup and !obd_stopping */
339#define OBD_CHECK_DEV_ACTIVE(obd) \
340do { \
341 OBD_CHECK_DEV(obd); \
342 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
343 CERROR("Device %d not setup\n", \
344 (obd)->obd_minor); \
0a3bdb00 345 return -ENODEV; \
d7e09d03
PT
346 } \
347} while (0)
348
349
f267cdb4 350#if defined (CONFIG_PROC_FS)
d7e09d03
PT
351#define OBD_COUNTER_OFFSET(op) \
352 ((offsetof(struct obd_ops, o_ ## op) - \
353 offsetof(struct obd_ops, o_iocontrol)) \
354 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
355
356#define OBD_COUNTER_INCREMENT(obdx, op) \
357 if ((obdx)->obd_stats != NULL) { \
358 unsigned int coffset; \
359 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
360 OBD_COUNTER_OFFSET(op); \
361 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
362 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
363 }
364
365#define EXP_COUNTER_INCREMENT(export, op) \
366 if ((export)->exp_obd->obd_stats != NULL) { \
367 unsigned int coffset; \
368 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
369 OBD_COUNTER_OFFSET(op); \
370 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
371 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
372 if ((export)->exp_nid_stats != NULL && \
373 (export)->exp_nid_stats->nid_stats != NULL) \
374 lprocfs_counter_incr( \
375 (export)->exp_nid_stats->nid_stats, coffset);\
376 }
377
378#define MD_COUNTER_OFFSET(op) \
379 ((offsetof(struct md_ops, m_ ## op) - \
380 offsetof(struct md_ops, m_getstatus)) \
381 / sizeof(((struct md_ops *)(0))->m_getstatus))
382
383#define MD_COUNTER_INCREMENT(obdx, op) \
384 if ((obd)->md_stats != NULL) { \
385 unsigned int coffset; \
386 coffset = (unsigned int)((obdx)->md_cntr_base) + \
387 MD_COUNTER_OFFSET(op); \
388 LASSERT(coffset < (obdx)->md_stats->ls_num); \
389 lprocfs_counter_incr((obdx)->md_stats, coffset); \
390 }
391
392#define EXP_MD_COUNTER_INCREMENT(export, op) \
393 if ((export)->exp_obd->obd_stats != NULL) { \
394 unsigned int coffset; \
395 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
396 MD_COUNTER_OFFSET(op); \
397 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
398 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
399 if ((export)->exp_md_stats != NULL) \
400 lprocfs_counter_incr( \
401 (export)->exp_md_stats, coffset); \
402 }
403
404#else
405#define OBD_COUNTER_OFFSET(op)
406#define OBD_COUNTER_INCREMENT(obd, op)
407#define EXP_COUNTER_INCREMENT(exp, op)
408#define MD_COUNTER_INCREMENT(obd, op)
409#define EXP_MD_COUNTER_INCREMENT(exp, op)
410#endif
411
412static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
413{
414 /* Always add in ldlm_stats */
415 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
416 ,LPROCFS_STATS_FLAG_NOPERCPU);
417 if (tmp->nid_ldlm_stats == NULL)
418 return -ENOMEM;
419
420 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
421
422 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
423 tmp->nid_ldlm_stats);
424}
425
426#define OBD_CHECK_MD_OP(obd, op, err) \
427do { \
428 if (!OBT(obd) || !MDP((obd), op)) { \
429 if (err) \
430 CERROR("md_" #op ": dev %s/%d no operation\n", \
431 obd->obd_name, obd->obd_minor); \
0a3bdb00 432 return err; \
d7e09d03
PT
433 } \
434} while (0)
435
436#define EXP_CHECK_MD_OP(exp, op) \
437do { \
438 if ((exp) == NULL) { \
439 CERROR("obd_" #op ": NULL export\n"); \
0a3bdb00 440 return -ENODEV; \
d7e09d03
PT
441 } \
442 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
443 CERROR("obd_" #op ": cleaned up obd\n"); \
0a3bdb00 444 return -EOPNOTSUPP; \
d7e09d03
PT
445 } \
446 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
447 CERROR("obd_" #op ": dev %s/%d no operation\n", \
448 (exp)->exp_obd->obd_name, \
449 (exp)->exp_obd->obd_minor); \
0a3bdb00 450 return -EOPNOTSUPP; \
d7e09d03
PT
451 } \
452} while (0)
453
454
455#define OBD_CHECK_DT_OP(obd, op, err) \
456do { \
457 if (!OBT(obd) || !OBP((obd), op)) { \
458 if (err) \
459 CERROR("obd_" #op ": dev %d no operation\n", \
460 obd->obd_minor); \
0a3bdb00 461 return err; \
d7e09d03
PT
462 } \
463} while (0)
464
465#define EXP_CHECK_DT_OP(exp, op) \
466do { \
467 if ((exp) == NULL) { \
468 CERROR("obd_" #op ": NULL export\n"); \
0a3bdb00 469 return -ENODEV; \
d7e09d03
PT
470 } \
471 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
472 CERROR("obd_" #op ": cleaned up obd\n"); \
0a3bdb00 473 return -EOPNOTSUPP; \
d7e09d03
PT
474 } \
475 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
476 CERROR("obd_" #op ": dev %d no operation\n", \
477 (exp)->exp_obd->obd_minor); \
0a3bdb00 478 return -EOPNOTSUPP; \
d7e09d03
PT
479 } \
480} while (0)
481
482#define CTXT_CHECK_OP(ctxt, op, err) \
483do { \
484 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
485 if (err) \
486 CERROR("lop_" #op ": dev %d no operation\n", \
487 ctxt->loc_obd->obd_minor); \
0a3bdb00 488 return err; \
d7e09d03
PT
489 } \
490} while (0)
491
492static inline int class_devno_max(void)
493{
494 return MAX_OBD_DEVICES;
495}
496
497static inline int obd_get_info(const struct lu_env *env,
498 struct obd_export *exp, __u32 keylen,
499 void *key, __u32 *vallen, void *val,
500 struct lov_stripe_md *lsm)
501{
502 int rc;
d7e09d03
PT
503
504 EXP_CHECK_DT_OP(exp, get_info);
505 EXP_COUNTER_INCREMENT(exp, get_info);
506
507 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val,
508 lsm);
0a3bdb00 509 return rc;
d7e09d03
PT
510}
511
512static inline int obd_set_info_async(const struct lu_env *env,
21aef7d9
OD
513 struct obd_export *exp, u32 keylen,
514 void *key, u32 vallen, void *val,
d7e09d03
PT
515 struct ptlrpc_request_set *set)
516{
517 int rc;
d7e09d03
PT
518
519 EXP_CHECK_DT_OP(exp, set_info_async);
520 EXP_COUNTER_INCREMENT(exp, set_info_async);
521
522 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
523 val, set);
0a3bdb00 524 return rc;
d7e09d03
PT
525}
526
527/*
528 * obd-lu integration.
529 *
530 * Functionality is being moved into new lu_device-based layering, but some
531 * pieces of configuration process are still based on obd devices.
532 *
533 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
534 * subsume ->o_setup() methods of obd devices they replace. The same for
535 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
536 * result, obd_setup() and obd_process_config() branch and call one XOR
537 * another.
538 *
539 * Yet neither lu_device_type_operations::ldto_device_fini() nor
540 * lu_device_type_operations::ldto_device_free() fully implement the
541 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
542 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
543 */
544
545#define DECLARE_LU_VARS(ldt, d) \
546 struct lu_device_type *ldt; \
547 struct lu_device *d
548
549static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
550{
551 int rc;
552 DECLARE_LU_VARS(ldt, d);
d7e09d03
PT
553
554 ldt = obd->obd_type->typ_lu;
555 if (ldt != NULL) {
556 struct lu_context session_ctx;
557 struct lu_env env;
558 lu_context_init(&session_ctx, LCT_SESSION);
559 session_ctx.lc_thread = NULL;
560 lu_context_enter(&session_ctx);
561
562 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
563 if (rc == 0) {
564 env.le_ses = &session_ctx;
565 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
566 lu_env_fini(&env);
567 if (!IS_ERR(d)) {
568 obd->obd_lu_dev = d;
569 d->ld_obd = obd;
570 rc = 0;
571 } else
572 rc = PTR_ERR(d);
573 }
574 lu_context_exit(&session_ctx);
575 lu_context_fini(&session_ctx);
576
577 } else {
578 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
579 OBD_COUNTER_INCREMENT(obd, setup);
580 rc = OBP(obd, setup)(obd, cfg);
581 }
0a3bdb00 582 return rc;
d7e09d03
PT
583}
584
585static inline int obd_precleanup(struct obd_device *obd,
586 enum obd_cleanup_stage cleanup_stage)
587{
588 int rc;
589 DECLARE_LU_VARS(ldt, d);
d7e09d03
PT
590
591 OBD_CHECK_DEV(obd);
592 ldt = obd->obd_type->typ_lu;
593 d = obd->obd_lu_dev;
594 if (ldt != NULL && d != NULL) {
595 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
596 struct lu_env env;
597
598 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
599 if (rc == 0) {
600 ldt->ldt_ops->ldto_device_fini(&env, d);
601 lu_env_fini(&env);
602 }
603 }
604 }
605 OBD_CHECK_DT_OP(obd, precleanup, 0);
606 OBD_COUNTER_INCREMENT(obd, precleanup);
607
608 rc = OBP(obd, precleanup)(obd, cleanup_stage);
0a3bdb00 609 return rc;
d7e09d03
PT
610}
611
612static inline int obd_cleanup(struct obd_device *obd)
613{
614 int rc;
615 DECLARE_LU_VARS(ldt, d);
d7e09d03
PT
616
617 OBD_CHECK_DEV(obd);
618
619 ldt = obd->obd_type->typ_lu;
620 d = obd->obd_lu_dev;
621 if (ldt != NULL && d != NULL) {
622 struct lu_env env;
623
624 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
625 if (rc == 0) {
626 ldt->ldt_ops->ldto_device_free(&env, d);
627 lu_env_fini(&env);
628 obd->obd_lu_dev = NULL;
629 }
630 }
631 OBD_CHECK_DT_OP(obd, cleanup, 0);
632 OBD_COUNTER_INCREMENT(obd, cleanup);
633
634 rc = OBP(obd, cleanup)(obd);
0a3bdb00 635 return rc;
d7e09d03
PT
636}
637
638static inline void obd_cleanup_client_import(struct obd_device *obd)
639{
d7e09d03
PT
640 /* If we set up but never connected, the
641 client import will not have been cleaned. */
642 down_write(&obd->u.cli.cl_sem);
643 if (obd->u.cli.cl_import) {
644 struct obd_import *imp;
645 imp = obd->u.cli.cl_import;
646 CDEBUG(D_CONFIG, "%s: client import never connected\n",
647 obd->obd_name);
648 ptlrpc_invalidate_import(imp);
649 if (imp->imp_rq_pool) {
650 ptlrpc_free_rq_pool(imp->imp_rq_pool);
651 imp->imp_rq_pool = NULL;
652 }
653 client_destroy_import(imp);
654 obd->u.cli.cl_import = NULL;
655 }
656 up_write(&obd->u.cli.cl_sem);
d7e09d03
PT
657}
658
659static inline int
660obd_process_config(struct obd_device *obd, int datalen, void *data)
661{
662 int rc;
663 DECLARE_LU_VARS(ldt, d);
d7e09d03
PT
664
665 OBD_CHECK_DEV(obd);
666
667 obd->obd_process_conf = 1;
668 ldt = obd->obd_type->typ_lu;
669 d = obd->obd_lu_dev;
670 if (ldt != NULL && d != NULL) {
671 struct lu_env env;
672
673 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
674 if (rc == 0) {
675 rc = d->ld_ops->ldo_process_config(&env, d, data);
676 lu_env_fini(&env);
677 }
678 } else {
679 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
680 rc = OBP(obd, process_config)(obd, datalen, data);
681 }
682 OBD_COUNTER_INCREMENT(obd, process_config);
683 obd->obd_process_conf = 0;
684
0a3bdb00 685 return rc;
d7e09d03
PT
686}
687
688/* Pack an in-memory MD struct for storage on disk.
689 * Returns +ve size of packed MD (0 for free), or -ve error.
690 *
691 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
692 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
693 * If @*disk_tgt == NULL, it will be allocated
694 */
695static inline int obd_packmd(struct obd_export *exp,
696 struct lov_mds_md **disk_tgt,
697 struct lov_stripe_md *mem_src)
698{
699 int rc;
d7e09d03
PT
700
701 EXP_CHECK_DT_OP(exp, packmd);
702 EXP_COUNTER_INCREMENT(exp, packmd);
703
704 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
0a3bdb00 705 return rc;
d7e09d03
PT
706}
707
708static inline int obd_size_diskmd(struct obd_export *exp,
709 struct lov_stripe_md *mem_src)
710{
711 return obd_packmd(exp, NULL, mem_src);
712}
713
d7e09d03
PT
714static inline int obd_free_diskmd(struct obd_export *exp,
715 struct lov_mds_md **disk_tgt)
716{
717 LASSERT(disk_tgt);
718 LASSERT(*disk_tgt);
719 /*
720 * LU-2590, for caller's convenience, *disk_tgt could be host
721 * endianness, it needs swab to LE if necessary, while just
722 * lov_mds_md header needs it for figuring out how much memory
723 * needs to be freed.
724 */
725 if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
726 (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) ||
727 ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3)))
728 lustre_swab_lov_mds_md(*disk_tgt);
729 return obd_packmd(exp, disk_tgt, NULL);
730}
731
732/* Unpack an MD struct from disk to in-memory format.
733 * Returns +ve size of unpacked MD (0 for free), or -ve error.
734 *
735 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
736 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
737 * If @*mem_tgt == NULL, it will be allocated
738 */
739static inline int obd_unpackmd(struct obd_export *exp,
740 struct lov_stripe_md **mem_tgt,
741 struct lov_mds_md *disk_src,
742 int disk_len)
743{
744 int rc;
d7e09d03
PT
745
746 EXP_CHECK_DT_OP(exp, unpackmd);
747 EXP_COUNTER_INCREMENT(exp, unpackmd);
748
749 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
0a3bdb00 750 return rc;
d7e09d03
PT
751}
752
753/* helper functions */
754static inline int obd_alloc_memmd(struct obd_export *exp,
755 struct lov_stripe_md **mem_tgt)
756{
757 LASSERT(mem_tgt);
758 LASSERT(*mem_tgt == NULL);
759 return obd_unpackmd(exp, mem_tgt, NULL, 0);
760}
761
762static inline int obd_free_memmd(struct obd_export *exp,
763 struct lov_stripe_md **mem_tgt)
764{
765 int rc;
766
767 LASSERT(mem_tgt);
768 LASSERT(*mem_tgt);
769 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
770 *mem_tgt = NULL;
771 return rc;
772}
773
774static inline int obd_precreate(struct obd_export *exp)
775{
776 int rc;
d7e09d03
PT
777
778 EXP_CHECK_DT_OP(exp, precreate);
779 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
780
781 rc = OBP(exp->exp_obd, precreate)(exp);
0a3bdb00 782 return rc;
d7e09d03
PT
783}
784
785static inline int obd_create_async(struct obd_export *exp,
786 struct obd_info *oinfo,
787 struct lov_stripe_md **ea,
788 struct obd_trans_info *oti)
789{
790 int rc;
d7e09d03
PT
791
792 EXP_CHECK_DT_OP(exp, create_async);
793 EXP_COUNTER_INCREMENT(exp, create_async);
794
795 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
0a3bdb00 796 return rc;
d7e09d03
PT
797}
798
799static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
800 struct obdo *obdo, struct lov_stripe_md **ea,
801 struct obd_trans_info *oti)
802{
803 int rc;
d7e09d03
PT
804
805 EXP_CHECK_DT_OP(exp, create);
806 EXP_COUNTER_INCREMENT(exp, create);
807
808 rc = OBP(exp->exp_obd, create)(env, exp, obdo, ea, oti);
0a3bdb00 809 return rc;
d7e09d03
PT
810}
811
812static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
813 struct obdo *obdo, struct lov_stripe_md *ea,
814 struct obd_trans_info *oti,
815 struct obd_export *md_exp, void *capa)
816{
817 int rc;
d7e09d03
PT
818
819 EXP_CHECK_DT_OP(exp, destroy);
820 EXP_COUNTER_INCREMENT(exp, destroy);
821
822 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp, capa);
0a3bdb00 823 return rc;
d7e09d03
PT
824}
825
826static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
827 struct obd_info *oinfo)
828{
829 int rc;
d7e09d03
PT
830
831 EXP_CHECK_DT_OP(exp, getattr);
832 EXP_COUNTER_INCREMENT(exp, getattr);
833
834 rc = OBP(exp->exp_obd, getattr)(env, exp, oinfo);
0a3bdb00 835 return rc;
d7e09d03
PT
836}
837
838static inline int obd_getattr_async(struct obd_export *exp,
839 struct obd_info *oinfo,
840 struct ptlrpc_request_set *set)
841{
842 int rc;
d7e09d03
PT
843
844 EXP_CHECK_DT_OP(exp, getattr_async);
845 EXP_COUNTER_INCREMENT(exp, getattr_async);
846
847 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
0a3bdb00 848 return rc;
d7e09d03
PT
849}
850
851static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
852 struct obd_info *oinfo,
853 struct obd_trans_info *oti)
854{
855 int rc;
d7e09d03
PT
856
857 EXP_CHECK_DT_OP(exp, setattr);
858 EXP_COUNTER_INCREMENT(exp, setattr);
859
860 rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti);
0a3bdb00 861 return rc;
d7e09d03
PT
862}
863
864/* This performs all the requests set init/wait/destroy actions. */
865static inline int obd_setattr_rqset(struct obd_export *exp,
866 struct obd_info *oinfo,
867 struct obd_trans_info *oti)
868{
869 struct ptlrpc_request_set *set = NULL;
870 int rc;
d7e09d03
PT
871
872 EXP_CHECK_DT_OP(exp, setattr_async);
873 EXP_COUNTER_INCREMENT(exp, setattr_async);
874
875 set = ptlrpc_prep_set();
876 if (set == NULL)
0a3bdb00 877 return -ENOMEM;
d7e09d03
PT
878
879 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
880 if (rc == 0)
881 rc = ptlrpc_set_wait(set);
882 ptlrpc_set_destroy(set);
0a3bdb00 883 return rc;
d7e09d03
PT
884}
885
886/* This adds all the requests into @set if @set != NULL, otherwise
887 all requests are sent asynchronously without waiting for response. */
888static inline int obd_setattr_async(struct obd_export *exp,
889 struct obd_info *oinfo,
890 struct obd_trans_info *oti,
891 struct ptlrpc_request_set *set)
892{
893 int rc;
d7e09d03
PT
894
895 EXP_CHECK_DT_OP(exp, setattr_async);
896 EXP_COUNTER_INCREMENT(exp, setattr_async);
897
898 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
0a3bdb00 899 return rc;
d7e09d03
PT
900}
901
902static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
903 int priority)
904{
905 struct obd_device *obd = imp->imp_obd;
906 int rc;
d7e09d03
PT
907
908 OBD_CHECK_DEV_ACTIVE(obd);
909 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
910 OBD_COUNTER_INCREMENT(obd, add_conn);
911
912 rc = OBP(obd, add_conn)(imp, uuid, priority);
0a3bdb00 913 return rc;
d7e09d03
PT
914}
915
916static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
917{
918 struct obd_device *obd = imp->imp_obd;
919 int rc;
d7e09d03
PT
920
921 OBD_CHECK_DEV_ACTIVE(obd);
922 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
923 OBD_COUNTER_INCREMENT(obd, del_conn);
924
925 rc = OBP(obd, del_conn)(imp, uuid);
0a3bdb00 926 return rc;
d7e09d03
PT
927}
928
929static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
930{
931 struct obd_uuid *uuid;
d7e09d03
PT
932
933 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
934 EXP_COUNTER_INCREMENT(exp, get_uuid);
935
936 uuid = OBP(exp->exp_obd, get_uuid)(exp);
0a3bdb00 937 return uuid;
d7e09d03
PT
938}
939
940/** Create a new /a exp on device /a obd for the uuid /a cluuid
941 * @param exp New export handle
942 * @param d Connect data, supported flags are set, flags also understood
943 * by obd are returned.
944 */
945static inline int obd_connect(const struct lu_env *env,
946 struct obd_export **exp,struct obd_device *obd,
947 struct obd_uuid *cluuid,
948 struct obd_connect_data *data,
949 void *localdata)
950{
951 int rc;
952 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
953 * check */
d7e09d03
PT
954
955 OBD_CHECK_DEV_ACTIVE(obd);
956 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
957 OBD_COUNTER_INCREMENT(obd, connect);
958
959 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
960 /* check that only subset is granted */
961 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
962 data->ocd_connect_flags));
0a3bdb00 963 return rc;
d7e09d03
PT
964}
965
966static inline int obd_reconnect(const struct lu_env *env,
967 struct obd_export *exp,
968 struct obd_device *obd,
969 struct obd_uuid *cluuid,
970 struct obd_connect_data *d,
971 void *localdata)
972{
973 int rc;
974 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
975 * check */
976
d7e09d03
PT
977 OBD_CHECK_DEV_ACTIVE(obd);
978 OBD_CHECK_DT_OP(obd, reconnect, 0);
979 OBD_COUNTER_INCREMENT(obd, reconnect);
980
981 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
982 /* check that only subset is granted */
983 LASSERT(ergo(d != NULL,
984 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
0a3bdb00 985 return rc;
d7e09d03
PT
986}
987
988static inline int obd_disconnect(struct obd_export *exp)
989{
990 int rc;
d7e09d03
PT
991
992 EXP_CHECK_DT_OP(exp, disconnect);
993 EXP_COUNTER_INCREMENT(exp, disconnect);
994
995 rc = OBP(exp->exp_obd, disconnect)(exp);
0a3bdb00 996 return rc;
d7e09d03
PT
997}
998
999static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
1000 enum lu_cli_type type)
1001{
1002 int rc;
d7e09d03
PT
1003
1004 OBD_CHECK_DT_OP(obd, fid_init, 0);
1005 OBD_COUNTER_INCREMENT(obd, fid_init);
1006
1007 rc = OBP(obd, fid_init)(obd, exp, type);
0a3bdb00 1008 return rc;
d7e09d03
PT
1009}
1010
1011static inline int obd_fid_fini(struct obd_device *obd)
1012{
1013 int rc;
d7e09d03
PT
1014
1015 OBD_CHECK_DT_OP(obd, fid_fini, 0);
1016 OBD_COUNTER_INCREMENT(obd, fid_fini);
1017
1018 rc = OBP(obd, fid_fini)(obd);
0a3bdb00 1019 return rc;
d7e09d03
PT
1020}
1021
1022static inline int obd_fid_alloc(struct obd_export *exp,
1023 struct lu_fid *fid,
1024 struct md_op_data *op_data)
1025{
1026 int rc;
d7e09d03
PT
1027
1028 EXP_CHECK_DT_OP(exp, fid_alloc);
1029 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1030
1031 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
0a3bdb00 1032 return rc;
d7e09d03
PT
1033}
1034
1035static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
1036{
1037 int rc;
d7e09d03
PT
1038
1039 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1040 EXP_COUNTER_INCREMENT(exp, ping);
1041
1042 rc = OBP(exp->exp_obd, ping)(env, exp);
0a3bdb00 1043 return rc;
d7e09d03
PT
1044}
1045
1046static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1047{
1048 int rc;
d7e09d03
PT
1049
1050 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1051 OBD_COUNTER_INCREMENT(obd, pool_new);
1052
1053 rc = OBP(obd, pool_new)(obd, poolname);
0a3bdb00 1054 return rc;
d7e09d03
PT
1055}
1056
1057static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1058{
1059 int rc;
d7e09d03
PT
1060
1061 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1062 OBD_COUNTER_INCREMENT(obd, pool_del);
1063
1064 rc = OBP(obd, pool_del)(obd, poolname);
0a3bdb00 1065 return rc;
d7e09d03
PT
1066}
1067
1068static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1069{
1070 int rc;
d7e09d03
PT
1071
1072 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1073 OBD_COUNTER_INCREMENT(obd, pool_add);
1074
1075 rc = OBP(obd, pool_add)(obd, poolname, ostname);
0a3bdb00 1076 return rc;
d7e09d03
PT
1077}
1078
1079static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1080{
1081 int rc;
d7e09d03
PT
1082
1083 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1084 OBD_COUNTER_INCREMENT(obd, pool_rem);
1085
1086 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
0a3bdb00 1087 return rc;
d7e09d03
PT
1088}
1089
1090static inline void obd_getref(struct obd_device *obd)
1091{
d7e09d03
PT
1092 if (OBT(obd) && OBP(obd, getref)) {
1093 OBD_COUNTER_INCREMENT(obd, getref);
1094 OBP(obd, getref)(obd);
1095 }
d7e09d03
PT
1096}
1097
1098static inline void obd_putref(struct obd_device *obd)
1099{
d7e09d03
PT
1100 if (OBT(obd) && OBP(obd, putref)) {
1101 OBD_COUNTER_INCREMENT(obd, putref);
1102 OBP(obd, putref)(obd);
1103 }
d7e09d03
PT
1104}
1105
1106static inline int obd_init_export(struct obd_export *exp)
1107{
1108 int rc = 0;
1109
d7e09d03
PT
1110 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1111 OBP((exp)->exp_obd, init_export))
1112 rc = OBP(exp->exp_obd, init_export)(exp);
0a3bdb00 1113 return rc;
d7e09d03
PT
1114}
1115
1116static inline int obd_destroy_export(struct obd_export *exp)
1117{
d7e09d03
PT
1118 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1119 OBP((exp)->exp_obd, destroy_export))
1120 OBP(exp->exp_obd, destroy_export)(exp);
0a3bdb00 1121 return 0;
d7e09d03
PT
1122}
1123
1124static inline int obd_extent_calc(struct obd_export *exp,
1125 struct lov_stripe_md *md,
21aef7d9 1126 int cmd, u64 *offset)
d7e09d03
PT
1127{
1128 int rc;
29aaf496 1129
d7e09d03
PT
1130 EXP_CHECK_DT_OP(exp, extent_calc);
1131 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
0a3bdb00 1132 return rc;
d7e09d03
PT
1133}
1134
1135static inline struct dentry *
1136obd_lvfs_fid2dentry(struct obd_export *exp, struct ost_id *oi, __u32 gen)
1137{
1138 struct lvfs_run_ctxt *ctxt = &exp->exp_obd->obd_lvfs_ctxt;
1139 LASSERT(exp->exp_obd);
1140
1141 return ctxt->cb_ops.l_fid2dentry(ostid_id(oi), gen, ostid_seq(oi),
1142 exp->exp_obd);
1143}
1144
1145/* @max_age is the oldest time in jiffies that we accept using a cached data.
1146 * If the cache is older than @max_age we will get a new value from the
1147 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1148static inline int obd_statfs_async(struct obd_export *exp,
1149 struct obd_info *oinfo,
1150 __u64 max_age,
1151 struct ptlrpc_request_set *rqset)
1152{
1153 int rc = 0;
1154 struct obd_device *obd;
d7e09d03
PT
1155
1156 if (exp == NULL || exp->exp_obd == NULL)
0a3bdb00 1157 return -EINVAL;
d7e09d03
PT
1158
1159 obd = exp->exp_obd;
1160 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1161 OBD_COUNTER_INCREMENT(obd, statfs);
1162
b0f5aad5 1163 CDEBUG(D_SUPER, "%s: osfs %p age %llu, max_age %llu\n",
d7e09d03
PT
1164 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1165 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1166 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1167 } else {
b0f5aad5 1168 CDEBUG(D_SUPER,"%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
d7e09d03
PT
1169 obd->obd_name, &obd->obd_osfs,
1170 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1171 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1172 spin_lock(&obd->obd_osfs_lock);
1173 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1174 spin_unlock(&obd->obd_osfs_lock);
1175 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1176 if (oinfo->oi_cb_up)
1177 oinfo->oi_cb_up(oinfo, 0);
1178 }
0a3bdb00 1179 return rc;
d7e09d03
PT
1180}
1181
1182static inline int obd_statfs_rqset(struct obd_export *exp,
1183 struct obd_statfs *osfs, __u64 max_age,
1184 __u32 flags)
1185{
1186 struct ptlrpc_request_set *set = NULL;
1187 struct obd_info oinfo = { { { 0 } } };
1188 int rc = 0;
d7e09d03
PT
1189
1190 set = ptlrpc_prep_set();
1191 if (set == NULL)
0a3bdb00 1192 return -ENOMEM;
d7e09d03
PT
1193
1194 oinfo.oi_osfs = osfs;
1195 oinfo.oi_flags = flags;
1196 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1197 if (rc == 0)
1198 rc = ptlrpc_set_wait(set);
1199 ptlrpc_set_destroy(set);
0a3bdb00 1200 return rc;
d7e09d03
PT
1201}
1202
1203/* @max_age is the oldest time in jiffies that we accept using a cached data.
1204 * If the cache is older than @max_age we will get a new value from the
1205 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1206static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1207 struct obd_statfs *osfs, __u64 max_age,
1208 __u32 flags)
1209{
1210 int rc = 0;
1211 struct obd_device *obd = exp->exp_obd;
d7e09d03
PT
1212
1213 if (obd == NULL)
0a3bdb00 1214 return -EINVAL;
d7e09d03
PT
1215
1216 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1217 OBD_COUNTER_INCREMENT(obd, statfs);
1218
b0f5aad5 1219 CDEBUG(D_SUPER, "osfs %llu, max_age %llu\n",
d7e09d03
PT
1220 obd->obd_osfs_age, max_age);
1221 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1222 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1223 if (rc == 0) {
1224 spin_lock(&obd->obd_osfs_lock);
1225 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1226 obd->obd_osfs_age = cfs_time_current_64();
1227 spin_unlock(&obd->obd_osfs_lock);
1228 }
1229 } else {
b0f5aad5 1230 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
d7e09d03
PT
1231 obd->obd_name, &obd->obd_osfs,
1232 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1233 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1234 spin_lock(&obd->obd_osfs_lock);
1235 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1236 spin_unlock(&obd->obd_osfs_lock);
1237 }
0a3bdb00 1238 return rc;
d7e09d03
PT
1239}
1240
1241static inline int obd_sync_rqset(struct obd_export *exp, struct obd_info *oinfo,
21aef7d9 1242 u64 start, u64 end)
d7e09d03
PT
1243{
1244 struct ptlrpc_request_set *set = NULL;
1245 int rc;
d7e09d03
PT
1246
1247 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1248 EXP_COUNTER_INCREMENT(exp, sync);
1249
1250 set = ptlrpc_prep_set();
1251 if (set == NULL)
0a3bdb00 1252 return -ENOMEM;
d7e09d03
PT
1253
1254 rc = OBP(exp->exp_obd, sync)(NULL, exp, oinfo, start, end, set);
1255 if (rc == 0)
1256 rc = ptlrpc_set_wait(set);
1257 ptlrpc_set_destroy(set);
0a3bdb00 1258 return rc;
d7e09d03
PT
1259}
1260
1261static inline int obd_sync(const struct lu_env *env, struct obd_export *exp,
21aef7d9 1262 struct obd_info *oinfo, u64 start, u64 end,
d7e09d03
PT
1263 struct ptlrpc_request_set *set)
1264{
1265 int rc;
d7e09d03
PT
1266
1267 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1268 EXP_COUNTER_INCREMENT(exp, sync);
1269
1270 rc = OBP(exp->exp_obd, sync)(env, exp, oinfo, start, end, set);
0a3bdb00 1271 return rc;
d7e09d03
PT
1272}
1273
1274static inline int obd_punch_rqset(struct obd_export *exp,
1275 struct obd_info *oinfo,
1276 struct obd_trans_info *oti)
1277{
1278 struct ptlrpc_request_set *set = NULL;
1279 int rc;
d7e09d03
PT
1280
1281 EXP_CHECK_DT_OP(exp, punch);
1282 EXP_COUNTER_INCREMENT(exp, punch);
1283
1284 set = ptlrpc_prep_set();
1285 if (set == NULL)
0a3bdb00 1286 return -ENOMEM;
d7e09d03
PT
1287
1288 rc = OBP(exp->exp_obd, punch)(NULL, exp, oinfo, oti, set);
1289 if (rc == 0)
1290 rc = ptlrpc_set_wait(set);
1291 ptlrpc_set_destroy(set);
0a3bdb00 1292 return rc;
d7e09d03
PT
1293}
1294
1295static inline int obd_punch(const struct lu_env *env, struct obd_export *exp,
1296 struct obd_info *oinfo, struct obd_trans_info *oti,
1297 struct ptlrpc_request_set *rqset)
1298{
1299 int rc;
d7e09d03
PT
1300
1301 EXP_CHECK_DT_OP(exp, punch);
1302 EXP_COUNTER_INCREMENT(exp, punch);
1303
1304 rc = OBP(exp->exp_obd, punch)(env, exp, oinfo, oti, rqset);
0a3bdb00 1305 return rc;
d7e09d03
PT
1306}
1307
1308static inline int obd_brw(int cmd, struct obd_export *exp,
21aef7d9 1309 struct obd_info *oinfo, u32 oa_bufs,
d7e09d03
PT
1310 struct brw_page *pg, struct obd_trans_info *oti)
1311{
1312 int rc;
d7e09d03
PT
1313
1314 EXP_CHECK_DT_OP(exp, brw);
1315 EXP_COUNTER_INCREMENT(exp, brw);
1316
1317 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1318 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1319 "or OBD_BRW_CHECK\n");
1320 LBUG();
1321 }
1322
1323 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
0a3bdb00 1324 return rc;
d7e09d03
PT
1325}
1326
1327static inline int obd_preprw(const struct lu_env *env, int cmd,
1328 struct obd_export *exp, struct obdo *oa,
1329 int objcount, struct obd_ioobj *obj,
1330 struct niobuf_remote *remote, int *pages,
1331 struct niobuf_local *local,
1332 struct obd_trans_info *oti,
1333 struct lustre_capa *capa)
1334{
1335 int rc;
d7e09d03
PT
1336
1337 EXP_CHECK_DT_OP(exp, preprw);
1338 EXP_COUNTER_INCREMENT(exp, preprw);
1339
1340 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1341 pages, local, oti, capa);
0a3bdb00 1342 return rc;
d7e09d03
PT
1343}
1344
1345static inline int obd_commitrw(const struct lu_env *env, int cmd,
1346 struct obd_export *exp, struct obdo *oa,
1347 int objcount, struct obd_ioobj *obj,
1348 struct niobuf_remote *rnb, int pages,
1349 struct niobuf_local *local,
1350 struct obd_trans_info *oti, int rc)
1351{
d7e09d03
PT
1352 EXP_CHECK_DT_OP(exp, commitrw);
1353 EXP_COUNTER_INCREMENT(exp, commitrw);
1354
1355 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1356 rnb, pages, local, oti, rc);
0a3bdb00 1357 return rc;
d7e09d03
PT
1358}
1359
1360static inline int obd_merge_lvb(struct obd_export *exp,
1361 struct lov_stripe_md *lsm,
1362 struct ost_lvb *lvb, int kms_only)
1363{
1364 int rc;
d7e09d03
PT
1365
1366 EXP_CHECK_DT_OP(exp, merge_lvb);
1367 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1368
1369 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
0a3bdb00 1370 return rc;
d7e09d03
PT
1371}
1372
1373static inline int obd_adjust_kms(struct obd_export *exp,
21aef7d9 1374 struct lov_stripe_md *lsm, u64 size,
d7e09d03
PT
1375 int shrink)
1376{
1377 int rc;
d7e09d03
PT
1378
1379 EXP_CHECK_DT_OP(exp, adjust_kms);
1380 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1381
1382 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
0a3bdb00 1383 return rc;
d7e09d03
PT
1384}
1385
1386static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1387 int len, void *karg, void *uarg)
1388{
1389 int rc;
d7e09d03
PT
1390
1391 EXP_CHECK_DT_OP(exp, iocontrol);
1392 EXP_COUNTER_INCREMENT(exp, iocontrol);
1393
1394 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
0a3bdb00 1395 return rc;
d7e09d03
PT
1396}
1397
1398static inline int obd_enqueue_rqset(struct obd_export *exp,
1399 struct obd_info *oinfo,
1400 struct ldlm_enqueue_info *einfo)
1401{
1402 struct ptlrpc_request_set *set = NULL;
1403 int rc;
d7e09d03
PT
1404
1405 EXP_CHECK_DT_OP(exp, enqueue);
1406 EXP_COUNTER_INCREMENT(exp, enqueue);
1407
1408 set = ptlrpc_prep_set();
1409 if (set == NULL)
0a3bdb00 1410 return -ENOMEM;
d7e09d03
PT
1411
1412 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1413 if (rc == 0)
1414 rc = ptlrpc_set_wait(set);
1415 ptlrpc_set_destroy(set);
0a3bdb00 1416 return rc;
d7e09d03
PT
1417}
1418
1419static inline int obd_enqueue(struct obd_export *exp,
1420 struct obd_info *oinfo,
1421 struct ldlm_enqueue_info *einfo,
1422 struct ptlrpc_request_set *set)
1423{
1424 int rc;
d7e09d03
PT
1425
1426 EXP_CHECK_DT_OP(exp, enqueue);
1427 EXP_COUNTER_INCREMENT(exp, enqueue);
1428
1429 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
0a3bdb00 1430 return rc;
d7e09d03
PT
1431}
1432
1433static inline int obd_change_cbdata(struct obd_export *exp,
1434 struct lov_stripe_md *lsm,
1435 ldlm_iterator_t it, void *data)
1436{
1437 int rc;
d7e09d03
PT
1438
1439 EXP_CHECK_DT_OP(exp, change_cbdata);
1440 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1441
1442 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
0a3bdb00 1443 return rc;
d7e09d03
PT
1444}
1445
1446static inline int obd_find_cbdata(struct obd_export *exp,
1447 struct lov_stripe_md *lsm,
1448 ldlm_iterator_t it, void *data)
1449{
1450 int rc;
d7e09d03
PT
1451
1452 EXP_CHECK_DT_OP(exp, find_cbdata);
1453 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1454
1455 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
0a3bdb00 1456 return rc;
d7e09d03
PT
1457}
1458
1459static inline int obd_cancel(struct obd_export *exp,
1460 struct lov_stripe_md *ea, __u32 mode,
1461 struct lustre_handle *lockh)
1462{
1463 int rc;
d7e09d03
PT
1464
1465 EXP_CHECK_DT_OP(exp, cancel);
1466 EXP_COUNTER_INCREMENT(exp, cancel);
1467
1468 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
0a3bdb00 1469 return rc;
d7e09d03
PT
1470}
1471
1472static inline int obd_cancel_unused(struct obd_export *exp,
1473 struct lov_stripe_md *ea,
1474 ldlm_cancel_flags_t flags,
1475 void *opaque)
1476{
1477 int rc;
d7e09d03
PT
1478
1479 EXP_CHECK_DT_OP(exp, cancel_unused);
1480 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1481
1482 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
0a3bdb00 1483 return rc;
d7e09d03
PT
1484}
1485
1486static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1487 struct obd_capa *oc, struct obd_client_handle *handle,
1488 int flag)
1489{
1490 int rc;
d7e09d03
PT
1491
1492 EXP_CHECK_DT_OP(exp, pin);
1493 EXP_COUNTER_INCREMENT(exp, pin);
1494
1495 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
0a3bdb00 1496 return rc;
d7e09d03
PT
1497}
1498
1499static inline int obd_unpin(struct obd_export *exp,
1500 struct obd_client_handle *handle, int flag)
1501{
1502 int rc;
d7e09d03
PT
1503
1504 EXP_CHECK_DT_OP(exp, unpin);
1505 EXP_COUNTER_INCREMENT(exp, unpin);
1506
1507 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
0a3bdb00 1508 return rc;
d7e09d03
PT
1509}
1510
1511
1512static inline void obd_import_event(struct obd_device *obd,
1513 struct obd_import *imp,
1514 enum obd_import_event event)
1515{
d7e09d03
PT
1516 if (!obd) {
1517 CERROR("NULL device\n");
d7e09d03
PT
1518 return;
1519 }
1520 if (obd->obd_set_up && OBP(obd, import_event)) {
1521 OBD_COUNTER_INCREMENT(obd, import_event);
1522 OBP(obd, import_event)(obd, imp, event);
1523 }
d7e09d03
PT
1524}
1525
1526static inline int obd_llog_connect(struct obd_export *exp,
1527 struct llogd_conn_body *body)
1528{
1529 int rc;
d7e09d03
PT
1530
1531 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1532 EXP_COUNTER_INCREMENT(exp, llog_connect);
1533
1534 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
0a3bdb00 1535 return rc;
d7e09d03
PT
1536}
1537
1538
1539static inline int obd_notify(struct obd_device *obd,
1540 struct obd_device *watched,
1541 enum obd_notify_event ev,
1542 void *data)
1543{
1544 int rc;
29aaf496 1545
d7e09d03
PT
1546 OBD_CHECK_DEV(obd);
1547
1548 /* the check for async_recov is a complete hack - I'm hereby
1549 overloading the meaning to also mean "this was called from
1550 mds_postsetup". I know that my mds is able to handle notifies
1551 by this point, and it needs to get them to execute mds_postrecov. */
1552 if (!obd->obd_set_up && !obd->obd_async_recov) {
1553 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
0a3bdb00 1554 return -EINVAL;
d7e09d03
PT
1555 }
1556
1557 if (!OBP(obd, notify)) {
1558 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
0a3bdb00 1559 return -ENOSYS;
d7e09d03
PT
1560 }
1561
1562 OBD_COUNTER_INCREMENT(obd, notify);
1563 rc = OBP(obd, notify)(obd, watched, ev, data);
0a3bdb00 1564 return rc;
d7e09d03
PT
1565}
1566
1567static inline int obd_notify_observer(struct obd_device *observer,
1568 struct obd_device *observed,
1569 enum obd_notify_event ev,
1570 void *data)
1571{
1572 int rc1;
1573 int rc2;
1574
1575 struct obd_notify_upcall *onu;
1576
1577 if (observer->obd_observer)
1578 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1579 else
1580 rc1 = 0;
1581 /*
1582 * Also, call non-obd listener, if any
1583 */
1584 onu = &observer->obd_upcall;
1585 if (onu->onu_upcall != NULL)
1586 rc2 = onu->onu_upcall(observer, observed, ev,
1587 onu->onu_owner, NULL);
1588 else
1589 rc2 = 0;
1590
1591 return rc1 ? rc1 : rc2;
1592}
1593
1594static inline int obd_quotacheck(struct obd_export *exp,
1595 struct obd_quotactl *oqctl)
1596{
1597 int rc;
d7e09d03
PT
1598
1599 EXP_CHECK_DT_OP(exp, quotacheck);
1600 EXP_COUNTER_INCREMENT(exp, quotacheck);
1601
1602 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
0a3bdb00 1603 return rc;
d7e09d03
PT
1604}
1605
1606static inline int obd_quotactl(struct obd_export *exp,
1607 struct obd_quotactl *oqctl)
1608{
1609 int rc;
d7e09d03
PT
1610
1611 EXP_CHECK_DT_OP(exp, quotactl);
1612 EXP_COUNTER_INCREMENT(exp, quotactl);
1613
1614 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
0a3bdb00 1615 return rc;
d7e09d03
PT
1616}
1617
1618static inline int obd_health_check(const struct lu_env *env,
1619 struct obd_device *obd)
1620{
1621 /* returns: 0 on healthy
1622 * >0 on unhealthy + reason code/flag
bd9070cb 1623 * however the only supported reason == 1 right now
d7e09d03
PT
1624 * We'll need to define some better reasons
1625 * or flags in the future.
1626 * <0 on error
1627 */
1628 int rc;
d7e09d03
PT
1629
1630 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1631 if (obd == NULL || !OBT(obd)) {
1632 CERROR("cleaned up obd\n");
0a3bdb00 1633 return -EOPNOTSUPP;
d7e09d03
PT
1634 }
1635 if (!obd->obd_set_up || obd->obd_stopping)
0a3bdb00 1636 return 0;
d7e09d03 1637 if (!OBP(obd, health_check))
0a3bdb00 1638 return 0;
d7e09d03
PT
1639
1640 rc = OBP(obd, health_check)(env, obd);
0a3bdb00 1641 return rc;
d7e09d03
PT
1642}
1643
1644static inline int obd_register_observer(struct obd_device *obd,
1645 struct obd_device *observer)
1646{
d7e09d03
PT
1647 OBD_CHECK_DEV(obd);
1648 down_write(&obd->obd_observer_link_sem);
1649 if (obd->obd_observer && observer) {
1650 up_write(&obd->obd_observer_link_sem);
0a3bdb00 1651 return -EALREADY;
d7e09d03
PT
1652 }
1653 obd->obd_observer = observer;
1654 up_write(&obd->obd_observer_link_sem);
0a3bdb00 1655 return 0;
d7e09d03
PT
1656}
1657
1658static inline int obd_pin_observer(struct obd_device *obd,
1659 struct obd_device **observer)
1660{
d7e09d03
PT
1661 down_read(&obd->obd_observer_link_sem);
1662 if (!obd->obd_observer) {
1663 *observer = NULL;
1664 up_read(&obd->obd_observer_link_sem);
0a3bdb00 1665 return -ENOENT;
d7e09d03
PT
1666 }
1667 *observer = obd->obd_observer;
0a3bdb00 1668 return 0;
d7e09d03
PT
1669}
1670
1671static inline int obd_unpin_observer(struct obd_device *obd)
1672{
d7e09d03 1673 up_read(&obd->obd_observer_link_sem);
0a3bdb00 1674 return 0;
d7e09d03
PT
1675}
1676
1677#if 0
1678static inline int obd_register_page_removal_cb(struct obd_export *exp,
1679 obd_page_removal_cb_t cb,
1680 obd_pin_extent_cb pin_cb)
1681{
1682 int rc;
d7e09d03
PT
1683
1684 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1685 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1686
1687 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
0a3bdb00 1688 return rc;
d7e09d03
PT
1689}
1690
1691static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1692 obd_page_removal_cb_t cb)
1693{
1694 int rc;
d7e09d03
PT
1695
1696 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1697 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1698
1699 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
0a3bdb00 1700 return rc;
d7e09d03
PT
1701}
1702
1703static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1704 obd_lock_cancel_cb cb)
1705{
1706 int rc;
d7e09d03
PT
1707
1708 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1709 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1710
1711 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
0a3bdb00 1712 return rc;
d7e09d03
PT
1713}
1714
1715static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1716 obd_lock_cancel_cb cb)
1717{
1718 int rc;
d7e09d03
PT
1719
1720 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1721 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1722
1723 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
0a3bdb00 1724 return rc;
d7e09d03
PT
1725}
1726#endif
1727
1728/* metadata helpers */
1729static inline int md_getstatus(struct obd_export *exp,
1730 struct lu_fid *fid, struct obd_capa **pc)
1731{
1732 int rc;
d7e09d03
PT
1733
1734 EXP_CHECK_MD_OP(exp, getstatus);
1735 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1736 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
0a3bdb00 1737 return rc;
d7e09d03
PT
1738}
1739
1740static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1741 struct ptlrpc_request **request)
1742{
1743 int rc;
29aaf496 1744
d7e09d03
PT
1745 EXP_CHECK_MD_OP(exp, getattr);
1746 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1747 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
0a3bdb00 1748 return rc;
d7e09d03
PT
1749}
1750
1751static inline int md_null_inode(struct obd_export *exp,
1752 const struct lu_fid *fid)
1753{
1754 int rc;
29aaf496 1755
d7e09d03
PT
1756 EXP_CHECK_MD_OP(exp, null_inode);
1757 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1758 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
0a3bdb00 1759 return rc;
d7e09d03
PT
1760}
1761
1762static inline int md_find_cbdata(struct obd_export *exp,
1763 const struct lu_fid *fid,
1764 ldlm_iterator_t it, void *data)
1765{
1766 int rc;
29aaf496 1767
d7e09d03
PT
1768 EXP_CHECK_MD_OP(exp, find_cbdata);
1769 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1770 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
0a3bdb00 1771 return rc;
d7e09d03
PT
1772}
1773
1774static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1775 struct md_open_data *mod,
1776 struct ptlrpc_request **request)
1777{
1778 int rc;
29aaf496 1779
d7e09d03
PT
1780 EXP_CHECK_MD_OP(exp, close);
1781 EXP_MD_COUNTER_INCREMENT(exp, close);
1782 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
0a3bdb00 1783 return rc;
d7e09d03
PT
1784}
1785
1786static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1787 const void *data, int datalen, int mode, __u32 uid,
1788 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1789 struct ptlrpc_request **request)
1790{
1791 int rc;
29aaf496 1792
d7e09d03
PT
1793 EXP_CHECK_MD_OP(exp, create);
1794 EXP_MD_COUNTER_INCREMENT(exp, create);
1795 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1796 uid, gid, cap_effective, rdev, request);
0a3bdb00 1797 return rc;
d7e09d03
PT
1798}
1799
1800static inline int md_done_writing(struct obd_export *exp,
1801 struct md_op_data *op_data,
1802 struct md_open_data *mod)
1803{
1804 int rc;
29aaf496 1805
d7e09d03
PT
1806 EXP_CHECK_MD_OP(exp, done_writing);
1807 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1808 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
0a3bdb00 1809 return rc;
d7e09d03
PT
1810}
1811
1812static inline int md_enqueue(struct obd_export *exp,
1813 struct ldlm_enqueue_info *einfo,
1814 struct lookup_intent *it,
1815 struct md_op_data *op_data,
1816 struct lustre_handle *lockh,
1817 void *lmm, int lmmsize,
1818 struct ptlrpc_request **req,
875332d4 1819 __u64 extra_lock_flags)
d7e09d03
PT
1820{
1821 int rc;
29aaf496 1822
d7e09d03
PT
1823 EXP_CHECK_MD_OP(exp, enqueue);
1824 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1825 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1826 lmm, lmmsize, req, extra_lock_flags);
0a3bdb00 1827 return rc;
d7e09d03
PT
1828}
1829
1830static inline int md_getattr_name(struct obd_export *exp,
1831 struct md_op_data *op_data,
1832 struct ptlrpc_request **request)
1833{
1834 int rc;
29aaf496 1835
d7e09d03
PT
1836 EXP_CHECK_MD_OP(exp, getattr_name);
1837 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1838 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
0a3bdb00 1839 return rc;
d7e09d03
PT
1840}
1841
1842static inline int md_intent_lock(struct obd_export *exp,
1843 struct md_op_data *op_data, void *lmm,
1844 int lmmsize, struct lookup_intent *it,
1845 int lookup_flags, struct ptlrpc_request **reqp,
1846 ldlm_blocking_callback cb_blocking,
1847 __u64 extra_lock_flags)
1848{
1849 int rc;
29aaf496 1850
d7e09d03
PT
1851 EXP_CHECK_MD_OP(exp, intent_lock);
1852 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1853 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1854 it, lookup_flags, reqp, cb_blocking,
1855 extra_lock_flags);
0a3bdb00 1856 return rc;
d7e09d03
PT
1857}
1858
1859static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1860 struct ptlrpc_request **request)
1861{
1862 int rc;
29aaf496 1863
d7e09d03
PT
1864 EXP_CHECK_MD_OP(exp, link);
1865 EXP_MD_COUNTER_INCREMENT(exp, link);
1866 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
0a3bdb00 1867 return rc;
d7e09d03
PT
1868}
1869
1870static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1871 const char *old, int oldlen, const char *new,
1872 int newlen, struct ptlrpc_request **request)
1873{
1874 int rc;
29aaf496 1875
d7e09d03
PT
1876 EXP_CHECK_MD_OP(exp, rename);
1877 EXP_MD_COUNTER_INCREMENT(exp, rename);
1878 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1879 newlen, request);
0a3bdb00 1880 return rc;
d7e09d03
PT
1881}
1882
1883static inline int md_is_subdir(struct obd_export *exp,
1884 const struct lu_fid *pfid,
1885 const struct lu_fid *cfid,
1886 struct ptlrpc_request **request)
1887{
1888 int rc;
29aaf496 1889
d7e09d03
PT
1890 EXP_CHECK_MD_OP(exp, is_subdir);
1891 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1892 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
0a3bdb00 1893 return rc;
d7e09d03
PT
1894}
1895
1896static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1897 void *ea, int ealen, void *ea2, int ea2len,
1898 struct ptlrpc_request **request,
1899 struct md_open_data **mod)
1900{
1901 int rc;
29aaf496 1902
d7e09d03
PT
1903 EXP_CHECK_MD_OP(exp, setattr);
1904 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1905 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1906 ea2, ea2len, request, mod);
0a3bdb00 1907 return rc;
d7e09d03
PT
1908}
1909
1910static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1911 struct obd_capa *oc, struct ptlrpc_request **request)
1912{
1913 int rc;
29aaf496 1914
d7e09d03
PT
1915 EXP_CHECK_MD_OP(exp, sync);
1916 EXP_MD_COUNTER_INCREMENT(exp, sync);
1917 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
0a3bdb00 1918 return rc;
d7e09d03
PT
1919}
1920
1921static inline int md_readpage(struct obd_export *exp, struct md_op_data *opdata,
1922 struct page **pages,
1923 struct ptlrpc_request **request)
1924{
1925 int rc;
29aaf496 1926
d7e09d03
PT
1927 EXP_CHECK_MD_OP(exp, readpage);
1928 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1929 rc = MDP(exp->exp_obd, readpage)(exp, opdata, pages, request);
0a3bdb00 1930 return rc;
d7e09d03
PT
1931}
1932
1933static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1934 struct ptlrpc_request **request)
1935{
1936 int rc;
29aaf496 1937
d7e09d03
PT
1938 EXP_CHECK_MD_OP(exp, unlink);
1939 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1940 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
0a3bdb00 1941 return rc;
d7e09d03
PT
1942}
1943
1944static inline int md_get_lustre_md(struct obd_export *exp,
1945 struct ptlrpc_request *req,
1946 struct obd_export *dt_exp,
1947 struct obd_export *md_exp,
1948 struct lustre_md *md)
1949{
d7e09d03
PT
1950 EXP_CHECK_MD_OP(exp, get_lustre_md);
1951 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
0a3bdb00 1952 return MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md);
d7e09d03
PT
1953}
1954
1955static inline int md_free_lustre_md(struct obd_export *exp,
1956 struct lustre_md *md)
1957{
d7e09d03
PT
1958 EXP_CHECK_MD_OP(exp, free_lustre_md);
1959 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
0a3bdb00 1960 return MDP(exp->exp_obd, free_lustre_md)(exp, md);
d7e09d03
PT
1961}
1962
1963static inline int md_setxattr(struct obd_export *exp,
1964 const struct lu_fid *fid, struct obd_capa *oc,
21aef7d9 1965 u64 valid, const char *name,
d7e09d03
PT
1966 const char *input, int input_size,
1967 int output_size, int flags, __u32 suppgid,
1968 struct ptlrpc_request **request)
1969{
d7e09d03
PT
1970 EXP_CHECK_MD_OP(exp, setxattr);
1971 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
0a3bdb00 1972 return MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
d7e09d03 1973 input_size, output_size, flags,
0a3bdb00 1974 suppgid, request);
d7e09d03
PT
1975}
1976
1977static inline int md_getxattr(struct obd_export *exp,
1978 const struct lu_fid *fid, struct obd_capa *oc,
21aef7d9 1979 u64 valid, const char *name,
d7e09d03
PT
1980 const char *input, int input_size,
1981 int output_size, int flags,
1982 struct ptlrpc_request **request)
1983{
d7e09d03
PT
1984 EXP_CHECK_MD_OP(exp, getxattr);
1985 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
0a3bdb00 1986 return MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
d7e09d03 1987 input_size, output_size, flags,
0a3bdb00 1988 request);
d7e09d03
PT
1989}
1990
1991static inline int md_set_open_replay_data(struct obd_export *exp,
1992 struct obd_client_handle *och,
63d42578 1993 struct lookup_intent *it)
d7e09d03 1994{
d7e09d03
PT
1995 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1996 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
63d42578 1997 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
d7e09d03
PT
1998}
1999
2000static inline int md_clear_open_replay_data(struct obd_export *exp,
2001 struct obd_client_handle *och)
2002{
d7e09d03
PT
2003 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2004 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
0a3bdb00 2005 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
d7e09d03
PT
2006}
2007
2008static inline int md_set_lock_data(struct obd_export *exp,
2009 __u64 *lockh, void *data, __u64 *bits)
2010{
d7e09d03
PT
2011 EXP_CHECK_MD_OP(exp, set_lock_data);
2012 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
0a3bdb00 2013 return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
d7e09d03
PT
2014}
2015
2016static inline int md_cancel_unused(struct obd_export *exp,
2017 const struct lu_fid *fid,
2018 ldlm_policy_data_t *policy,
2019 ldlm_mode_t mode,
2020 ldlm_cancel_flags_t flags,
2021 void *opaque)
2022{
2023 int rc;
d7e09d03
PT
2024
2025 EXP_CHECK_MD_OP(exp, cancel_unused);
2026 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2027
2028 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2029 flags, opaque);
0a3bdb00 2030 return rc;
d7e09d03
PT
2031}
2032
2033static inline ldlm_mode_t md_lock_match(struct obd_export *exp, __u64 flags,
2034 const struct lu_fid *fid,
2035 ldlm_type_t type,
2036 ldlm_policy_data_t *policy,
2037 ldlm_mode_t mode,
2038 struct lustre_handle *lockh)
2039{
d7e09d03
PT
2040 EXP_CHECK_MD_OP(exp, lock_match);
2041 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
0a3bdb00
GKH
2042 return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2043 policy, mode, lockh);
d7e09d03
PT
2044}
2045
2046static inline int md_init_ea_size(struct obd_export *exp, int easize,
44779340
BB
2047 int def_asize, int cookiesize,
2048 int def_cookiesize)
d7e09d03 2049{
d7e09d03
PT
2050 EXP_CHECK_MD_OP(exp, init_ea_size);
2051 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
0a3bdb00 2052 return MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
44779340 2053 cookiesize, def_cookiesize);
d7e09d03
PT
2054}
2055
2056static inline int md_get_remote_perm(struct obd_export *exp,
2057 const struct lu_fid *fid,
2058 struct obd_capa *oc, __u32 suppgid,
2059 struct ptlrpc_request **request)
2060{
d7e09d03
PT
2061 EXP_CHECK_MD_OP(exp, get_remote_perm);
2062 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
0a3bdb00
GKH
2063 return MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2064 request);
d7e09d03
PT
2065}
2066
2067static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2068 renew_capa_cb_t cb)
2069{
2070 int rc;
29aaf496 2071
d7e09d03
PT
2072 EXP_CHECK_MD_OP(exp, renew_capa);
2073 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2074 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
0a3bdb00 2075 return rc;
d7e09d03
PT
2076}
2077
2078static inline int md_unpack_capa(struct obd_export *exp,
2079 struct ptlrpc_request *req,
2080 const struct req_msg_field *field,
2081 struct obd_capa **oc)
2082{
2083 int rc;
29aaf496 2084
d7e09d03
PT
2085 EXP_CHECK_MD_OP(exp, unpack_capa);
2086 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2087 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
0a3bdb00 2088 return rc;
d7e09d03
PT
2089}
2090
2091static inline int md_intent_getattr_async(struct obd_export *exp,
2092 struct md_enqueue_info *minfo,
2093 struct ldlm_enqueue_info *einfo)
2094{
2095 int rc;
29aaf496 2096
d7e09d03
PT
2097 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2098 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2099 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
0a3bdb00 2100 return rc;
d7e09d03
PT
2101}
2102
2103static inline int md_revalidate_lock(struct obd_export *exp,
2104 struct lookup_intent *it,
2105 struct lu_fid *fid, __u64 *bits)
2106{
2107 int rc;
29aaf496 2108
d7e09d03
PT
2109 EXP_CHECK_MD_OP(exp, revalidate_lock);
2110 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2111 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
0a3bdb00 2112 return rc;
d7e09d03
PT
2113}
2114
2115
2116/* OBD Metadata Support */
2117
2118extern int obd_init_caches(void);
2119extern void obd_cleanup_caches(void);
2120
2121/* support routines */
2122extern struct kmem_cache *obdo_cachep;
2123
2124#define OBDO_ALLOC(ptr) \
2125do { \
0be19afa 2126 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
d7e09d03
PT
2127} while(0)
2128
2129#define OBDO_FREE(ptr) \
2130do { \
2131 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2132} while(0)
2133
2134
2135static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2136{
2137 /* something here */
2138}
2139
2140static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2141{
2142 /* something here */
2143}
2144
2145typedef int (*register_lwp_cb)(void *data);
2146
2147struct lwp_register_item {
2148 struct obd_export **lri_exp;
2149 register_lwp_cb lri_cb_func;
2150 void *lri_cb_data;
2151 struct list_head lri_list;
2152 char lri_name[MTI_NAME_MAXLEN];
2153};
2154
2155/* I'm as embarrassed about this as you are.
2156 *
2157 * <shaver> // XXX do not look into _superhack with remaining eye
2158 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2159extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2160
2161/* obd_mount.c */
2162
2163/* sysctl.c */
2164extern void obd_sysctl_init (void);
2165extern void obd_sysctl_clean (void);
2166
2167/* uuid.c */
2168typedef __u8 class_uuid_t[16];
2169void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2170
2171/* lustre_peer.c */
2172int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2173int class_add_uuid(const char *uuid, __u64 nid);
2174int class_del_uuid (const char *uuid);
2175int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
2176void class_init_uuidlist(void);
2177void class_exit_uuidlist(void);
2178
2179/* mea.c */
2180int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2181int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2182
76133e66
OD
2183/* class_obd.c */
2184extern char obd_jobid_node[];
2185
d7e09d03
PT
2186/* prng.c */
2187#define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
2188
2189#endif /* __LINUX_OBD_CLASS_H */
This page took 0.325331 seconds and 5 git commands to generate.