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