Whamcloud - gitweb
LU-16120 build: Add support for kobj_type default_groups
[fs/lustre-release.git] / lustre / include / obd_class.h
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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  */
31 #ifndef __CLASS_OBD_H
32 #define __CLASS_OBD_H
33
34 #include <linux/kobject.h>
35 #include <obd_support.h>
36 #include <lustre_import.h>
37 #include <lustre_net.h>
38 #include <obd.h>
39 #include <lustre_lib.h>
40 #include <uapi/linux/lustre/lustre_idl.h>
41 #include <lprocfs_status.h>
42 #ifdef HAVE_SERVER_SUPPORT
43 #include <lu_target.h>
44 #include <obd_target.h>
45 #include <dt_object.h>
46 #endif
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_FOR_MDT0     0x0004  /* The statfs is only for retrieving
53                                          * information from MDT0. */
54 #define OBD_STATFS_SUM          0x0008  /* get aggregated statfs from MDT */
55 #define OBD_STATFS_NESTED       0x0010  /* Call while already holding
56                                          * obd_dev_mutex of a difference
57                                          * device.
58                                          */
59
60 extern rwlock_t obd_dev_lock;
61
62 /* OBD Operations Declarations */
63 extern struct obd_device *class_exp2obd(struct obd_export *);
64 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
65 int lustre_get_jobid(char *jobid, size_t len);
66 void lustre_jobid_clear(const char *jobid);
67 void jobid_cache_fini(void);
68 int jobid_cache_init(void);
69 char *jobid_current(void);
70 int jobid_set_current(char *jobid);
71
72 struct lu_device_type;
73
74 /* genops.c */
75 struct obd_export *class_conn2export(struct lustre_handle *);
76 #ifdef HAVE_SERVER_SUPPORT
77 struct obd_type *class_add_symlinks(const char *name, bool enable_proc);
78 #endif
79 int class_register_type(const struct obd_ops *dt_ops,
80                         const struct md_ops *md_ops, bool enable_proc,
81                         const char *nm, struct lu_device_type *ldt);
82 int class_unregister_type(const char *nm);
83
84 struct obd_device *class_newdev(const char *type_name, const char *name,
85                                 const char *uuid);
86 int class_register_device(struct obd_device *obd);
87 void class_unregister_device(struct obd_device *obd);
88 void class_free_dev(struct obd_device *obd);
89
90 struct obd_device *class_dev_by_str(const char *str);
91 int class_name2dev(const char *name);
92 struct obd_device *class_name2obd(const char *name);
93 int class_uuid2dev(struct obd_uuid *uuid);
94 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
95 void class_obd_list(void);
96 struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
97                                          const char *type_name,
98                                          struct obd_uuid *grp_uuid);
99 struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid,
100                                           int *next);
101 struct obd_device *class_num2obd(int num);
102 int get_devices_count(void);
103
104 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
105
106 static inline char *obd_export_nid2str(struct obd_export *exp)
107 {
108         return exp->exp_connection == NULL ?
109                "<unknown>" : libcfs_nidstr(&exp->exp_connection->c_peer.nid);
110 }
111
112 static inline char *obd_import_nid2str(struct obd_import *imp)
113 {
114         return imp->imp_connection == NULL ?
115                "<unknown>" : libcfs_nidstr(&imp->imp_connection->c_peer.nid);
116 }
117
118 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
119 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
120 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
121                           const char *sep);
122
123 int obd_zombie_impexp_init(void);
124 void obd_zombie_impexp_stop(void);
125 void obd_zombie_impexp_cull(void);
126 void obd_zombie_barrier(void);
127 void obd_exports_barrier(struct obd_device *obd);
128 int kuc_len(int payload_len);
129 struct kuc_hdr * kuc_ptr(void *p);
130 void *kuc_alloc(int payload_len, int transport, int type);
131 void kuc_free(void *p, int payload_len);
132 int obd_get_request_slot(struct client_obd *cli);
133 void obd_put_request_slot(struct client_obd *cli);
134 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
135 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
136 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
137 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
138 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
139
140 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc);
141 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc, __u16 tag);
142
143 struct llog_handle;
144 struct llog_rec_hdr;
145 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
146                          struct llog_rec_hdr *, void *);
147
148 struct obd_export *obd_stale_export_get(void);
149 void obd_stale_export_put(struct obd_export *exp);
150 void obd_stale_export_adjust(struct obd_export *exp);
151
152 /* obd_config.c */
153 /* For interoperability */
154 struct cfg_interop_param {
155         char *old_param;
156         char *new_param;
157 };
158
159 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index);
160 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
161                                      const char *new_name);
162 void print_lustre_cfg(struct lustre_cfg *lcfg);
163 int class_process_config(struct lustre_cfg *lcfg);
164 ssize_t class_set_global(const char *param);
165 ssize_t class_modify_config(struct lustre_cfg *lcfg, const char *prefix,
166                             struct kobject *kobj);
167 int class_attach(struct lustre_cfg *lcfg);
168 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
169 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
170 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
171
172 int class_find_param(char *buf, char *key, char **valp);
173 struct cfg_interop_param *class_find_old_param(const char *param,
174                                                struct cfg_interop_param *ptr);
175 int class_get_next_param(char **params, char *copy);
176 int class_match_param(char *buf, const char *key, char **valp);
177 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
178 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
179 int class_parse_net(char *buf, u32 *net, char **endh);
180 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
181 int class_match_net(char *buf, char *key, u32 net);
182
183 struct obd_device *class_incref(struct obd_device *obd,
184                                 const char *scope, const void *source);
185 void class_decref(struct obd_device *obd,
186                   const char *scope, const void *source);
187 void dump_exports(struct obd_device *obd, int locks, int debug_level);
188 int class_config_llog_handler(const struct lu_env *env,
189                               struct llog_handle *handle,
190                               struct llog_rec_hdr *rec, void *data);
191 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
192
193 #define CFG_F_START     0x01   /* Set when we start updating from a log */
194 #define CFG_F_MARKER    0x02   /* We are within a maker */
195 #define CFG_F_SKIP      0x04   /* We should ignore this cfg command */
196 #define CFG_F_EXCLUDE   0x10   /* OST exclusion list */
197
198 /* Passed as data param to class_config_parse_llog */
199 struct config_llog_instance {
200         unsigned long            cfg_instance;
201         struct super_block      *cfg_sb;
202         struct obd_uuid          cfg_uuid;
203         llog_cb_t                cfg_callback;
204         int                      cfg_last_idx; /* for partial llog processing */
205         int                      cfg_flags;
206         __u32                    cfg_lwp_idx;
207         __u32                    cfg_sub_clds;
208 };
209 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
210                             char *name, struct config_llog_instance *cfg);
211
212 /**
213  * Generate a unique configuration instance for this mount
214  *
215  * Temporary hack to bypass ASLR in 4.15+ kernels, a better fix soon.
216  * For now, use the same value as before - the superblock pointer value.
217  *
218  * Using the client UUID would be an option, but it needs more testing.
219  */
220 static inline unsigned long ll_get_cfg_instance(struct super_block *sb)
221 {
222         return (unsigned long)sb;
223 }
224
225 #define CONFIG_SUB_SPTLRPC      0x01
226 #define CONFIG_SUB_RECOVER      0x02
227 #define CONFIG_SUB_PARAMS       0x04
228 #define CONFIG_SUB_NODEMAP      0x08
229 #define CONFIG_SUB_BARRIER      0x10
230
231 /* Sub clds should be attached to the config_llog_data when processing
232  * config log for client or server target. */
233 #define CONFIG_SUB_CLIENT       (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
234                                  CONFIG_SUB_PARAMS)
235 #define CONFIG_SUB_SERVER       (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
236                                  CONFIG_SUB_BARRIER)
237
238 #define PARAMS_FILENAME         "params"
239 #define BARRIER_FILENAME        "barrier"
240 #define LCTL_UPCALL             "lctl"
241
242 static inline bool logname_is_barrier(const char *logname)
243 {
244         char *ptr;
245
246         /* logname for barrier is "fsname-barrier" */
247         ptr = strstr(logname, BARRIER_FILENAME);
248         if (ptr && (ptr - logname) >= 2 &&
249             *(ptr - 1) == '-' && *(ptr + 7) == '\0')
250                 return true;
251
252         return false;
253 }
254
255 /* list of active configuration logs  */
256 struct config_llog_data {
257         struct ldlm_res_id          cld_resid;
258         struct lustre_handle        cld_lockh;
259         struct config_llog_instance cld_cfg;
260         struct list_head            cld_list_chain;/* on config_llog_list */
261         atomic_t                    cld_refcount;
262         struct config_llog_data    *cld_sptlrpc;/* depended sptlrpc log */
263         struct config_llog_data    *cld_params; /* common parameters log */
264         struct config_llog_data    *cld_recover;/* imperative recover log */
265         struct config_llog_data    *cld_nodemap;/* nodemap log */
266         struct config_llog_data    *cld_barrier;/* barrier log (for MDT only) */
267         struct obd_export          *cld_mgcexp;
268         struct mutex                cld_lock;
269         enum mgs_cfg_type           cld_type;
270         unsigned int                cld_stopping:1, /* we were told to stop
271                                                      * watching */
272                                     cld_lostlock:1; /* lock not requeued */
273         char                        cld_logname[0];
274 };
275
276 struct lustre_profile {
277         struct list_head         lp_list;
278         char                    *lp_profile;
279         char                    *lp_dt;
280         char                    *lp_md;
281         int                      lp_refs;
282         bool                     lp_list_deleted;
283 };
284
285 struct lustre_profile *class_get_profile(const char * prof);
286 void class_del_profile(const char *prof);
287 void class_put_profile(struct lustre_profile *lprof);
288 void class_del_profiles(void);
289
290
291 #if LUSTRE_TRACKS_LOCK_EXP_REFS
292
293 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
294 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
295 extern void (*class_export_dump_hook)(struct obd_export *);
296
297 #else
298
299 #define __class_export_add_lock_ref(exp, lock)             do {} while(0)
300 #define __class_export_del_lock_ref(exp, lock)             do {} while(0)
301
302 #endif
303
304 #define class_export_rpc_inc(exp)                                       \
305 ({                                                                      \
306         atomic_inc(&(exp)->exp_rpc_count);                              \
307         CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n",    \
308                (exp), atomic_read(&(exp)->exp_rpc_count));              \
309 })
310
311 #define class_export_rpc_dec(exp)                                       \
312 ({                                                                      \
313         LASSERT_ATOMIC_POS(&exp->exp_rpc_count);                        \
314         atomic_dec(&(exp)->exp_rpc_count);                              \
315         CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n",    \
316                (exp), atomic_read(&(exp)->exp_rpc_count));              \
317 })
318
319 #define class_export_lock_get(exp, lock)                                \
320 ({                                                                      \
321         atomic_inc(&(exp)->exp_locks_count);                            \
322         __class_export_add_lock_ref(exp, lock);                         \
323         CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
324                (exp), atomic_read(&(exp)->exp_locks_count));            \
325         class_export_get(exp);                                          \
326 })
327
328 #define class_export_lock_put(exp, lock)                                \
329 ({                                                                      \
330         LASSERT_ATOMIC_POS(&exp->exp_locks_count);                      \
331         atomic_dec(&(exp)->exp_locks_count);                            \
332         __class_export_del_lock_ref(exp, lock);                         \
333         CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
334                (exp), atomic_read(&(exp)->exp_locks_count));            \
335         class_export_put(exp);                                          \
336 })
337
338 #define class_export_cb_get(exp)                                        \
339 ({                                                                      \
340         atomic_inc(&(exp)->exp_cb_count);                               \
341         CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
342                (exp), atomic_read(&(exp)->exp_cb_count));               \
343         class_export_get(exp);                                          \
344 })
345
346 #define class_export_cb_put(exp)                                        \
347 ({                                                                      \
348         LASSERT_ATOMIC_POS(&exp->exp_cb_count);                         \
349         atomic_dec(&(exp)->exp_cb_count);                               \
350         CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
351                (exp), atomic_read(&(exp)->exp_cb_count));               \
352         class_export_put(exp);                                          \
353 })
354
355 /* genops.c */
356 struct obd_export *class_export_get(struct obd_export *exp);
357 void class_export_put(struct obd_export *exp);
358 struct obd_export *class_new_export(struct obd_device *obd,
359                                     struct obd_uuid *cluuid);
360 struct obd_export *class_new_export_self(struct obd_device *obd,
361                                          struct obd_uuid *uuid);
362 void class_unlink_export(struct obd_export *exp);
363
364 struct obd_import *class_import_get(struct obd_import *);
365 void class_import_put(struct obd_import *);
366 struct obd_import *class_new_import(struct obd_device *obd);
367 void class_destroy_import(struct obd_import *exp);
368
369 #ifdef HAVE_SERVER_SUPPORT
370 struct obd_type *class_search_type(const char *name);
371 struct obd_type *class_get_type(const char *name);
372 #endif
373 void class_put_type(struct obd_type *type);
374 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
375                   struct obd_uuid *cluuid);
376 int class_disconnect(struct obd_export *exp);
377 void class_fail_export(struct obd_export *exp);
378 int class_connected_export(struct obd_export *exp);
379 void class_disconnect_exports(struct obd_device *obd);
380 int class_manual_cleanup(struct obd_device *obd);
381 void class_disconnect_stale_exports(struct obd_device *,
382                                     int (*test_export)(struct obd_export *));
383
384 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
385 {
386         return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
387                 (obd->obd_force ? OBD_OPT_FORCE : 0) |
388                 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
389                 0);
390 }
391
392 #ifdef HAVE_SERVER_SUPPORT
393 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
394 {
395         struct obd_device_target *obt;
396
397         LASSERT(exp->exp_obd);
398         obt = (void *)&exp->exp_obd->u;
399         if (obt->obt_magic != OBT_MAGIC)
400                 return NULL;
401         return obt->obt_lut;
402 }
403
404 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
405 {
406         struct obd_device_target *obt = obd2obt(obd);
407
408         LASSERT(obt);
409         return &obt->obt_lut->lut_lsd;
410 }
411 #endif
412
413 /* obdo.c */
414 struct lu_attr;
415 struct inode;
416
417 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
418 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
419
420 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
421 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
422
423 #define OBP(dev, op)    (dev)->obd_type->typ_dt_ops->o_ ## op
424 #define MDP(dev, op)    (dev)->obd_type->typ_md_ops->m_ ## op
425
426 static inline int obd_check_dev(struct obd_device *obd)
427 {
428         if (!obd) {
429                 CERROR("NULL device\n");
430                 return -ENODEV;
431         }
432         return 0;
433 }
434
435 /* ensure obd_setup and !obd_stopping */
436 #define OBD_CHECK_DEV_ACTIVE(obd)                               \
437 do {                                                            \
438         rc = obd_check_dev(obd);                                \
439         if (rc)                                                 \
440                 return rc;                                      \
441                                                                 \
442         if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
443                 CERROR("Device %d not setup\n",                 \
444                        (obd)->obd_minor);                       \
445                 RETURN(-ENODEV);                                \
446         }                                                       \
447 } while (0)
448
449
450 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
451 {
452         /* Always add in ldlm_stats */
453         tmp->nid_ldlm_stats =
454                 lprocfs_stats_alloc(LDLM_LAST_OPC - LDLM_FIRST_OPC,
455                                     LPROCFS_STATS_FLAG_NOPERCPU);
456         if (tmp->nid_ldlm_stats == NULL)
457                 return -ENOMEM;
458
459         lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
460
461         return lprocfs_stats_register(tmp->nid_proc, "ldlm_stats",
462                                       tmp->nid_ldlm_stats);
463 }
464
465 static inline int exp_check_ops(struct obd_export *exp)
466 {
467         if (exp == NULL) {
468                 RETURN(-ENODEV);
469         }
470         if (exp->exp_obd == NULL || !exp->exp_obd->obd_type) {
471                 RETURN(-EOPNOTSUPP);
472         }
473         RETURN(0);
474 }
475
476 static inline int class_devno_max(void)
477 {
478         return MAX_OBD_DEVICES;
479 }
480
481 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
482                                __u32 keylen, void *key,
483                                __u32 *vallen, void *val)
484 {
485         int rc;
486         ENTRY;
487
488         rc = exp_check_ops(exp);
489         if (rc)
490                 RETURN(rc);
491
492         if (!exp->exp_obd->obd_type->typ_dt_ops->o_get_info) {
493                 CERROR("%s: no %s operation\n",
494                        (exp)->exp_obd->obd_name, __func__);
495                 RETURN(-ENOTSUPP);
496         }
497
498         rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
499         RETURN(rc);
500 }
501
502 static inline int obd_set_info_async(const struct lu_env *env,
503                                      struct obd_export *exp,
504                                      __u32 keylen, void *key,
505                                      __u32 vallen, void *val,
506                                      struct ptlrpc_request_set *set)
507 {
508         int rc;
509         ENTRY;
510
511         rc = exp_check_ops(exp);
512         if (rc)
513                 RETURN(rc);
514
515         if (!exp->exp_obd->obd_type->typ_dt_ops->o_set_info_async) {
516                 CERROR("%s: no %s operation\n",
517                        (exp)->exp_obd->obd_name, __func__);
518                 RETURN(-ENOTSUPP);
519         }
520
521         rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
522                                                val, set);
523         RETURN(rc);
524 }
525
526 /*
527  * obd-lu integration.
528  *
529  * Functionality is being moved into new lu_device-based layering, but some
530  * pieces of configuration process are still based on obd devices.
531  *
532  * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
533  * subsume ->o_setup() methods of obd devices they replace. The same for
534  * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
535  * result, obd_setup() and obd_process_config() branch and call one XOR
536  * another.
537  *
538  * Yet neither lu_device_type_operations::ldto_device_fini() nor
539  * lu_device_type_operations::ldto_device_free() fully implement the
540  * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
541  * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
542  */
543 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
544 {
545         int rc;
546         struct obd_type *type = obd->obd_type;
547         struct lu_device_type *ldt;
548
549         ENTRY;
550
551         wait_var_event(&type->typ_lu,
552                        smp_load_acquire(&type->typ_lu) != OBD_LU_TYPE_SETUP);
553         ldt = type->typ_lu;
554         if (ldt != NULL) {
555                 struct lu_context session_ctx;
556                 struct lu_env env;
557
558                 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_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                         struct lu_device *dev;
565                         env.le_ses = &session_ctx;
566                         dev = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
567                         lu_env_fini(&env);
568                         if (!IS_ERR(dev)) {
569                                 obd->obd_lu_dev = dev;
570                                 dev->ld_obd = obd;
571 #ifdef HAVE_SERVER_SUPPORT
572                                 if (lu_device_is_dt(dev) &&
573                                     lu2dt_dev(dev)->dd_rdonly)
574                                         obd->obd_read_only = 1;
575 #endif
576                                 rc = 0;
577                         } else
578                                 rc = PTR_ERR(dev);
579                 }
580                 lu_context_exit(&session_ctx);
581                 lu_context_fini(&session_ctx);
582         } else {
583                 if (!obd->obd_type->typ_dt_ops->o_setup) {
584                         CERROR("%s: no %s operation\n", obd->obd_name,
585                                __func__);
586                         RETURN(-EOPNOTSUPP);
587                 }
588                 rc = OBP(obd, setup)(obd, cfg);
589         }
590         RETURN(rc);
591 }
592
593 static inline int obd_precleanup(struct obd_device *obd)
594 {
595         int rc;
596         struct lu_device_type *ldt = obd->obd_type->typ_lu;
597         struct lu_device *d = obd->obd_lu_dev;
598
599         ENTRY;
600
601         if (ldt != NULL && d != NULL) {
602                 struct lu_env *env = lu_env_find();
603                 struct lu_env _env;
604
605                 if (!env) {
606                         env = &_env;
607                         rc = lu_env_init(env, ldt->ldt_ctx_tags);
608                         LASSERT(rc == 0);
609                         lu_env_add(env);
610                 }
611                 ldt->ldt_ops->ldto_device_fini(env, d);
612                 if (env == &_env) {
613                         lu_env_remove(env);
614                         lu_env_fini(env);
615                 }
616         }
617
618         if (!obd->obd_type->typ_dt_ops->o_precleanup)
619                 RETURN(0);
620
621         rc = OBP(obd, precleanup)(obd);
622         RETURN(rc);
623 }
624
625 static inline int obd_cleanup(struct obd_device *obd)
626 {
627         int rc;
628         struct lu_device_type *ldt = obd->obd_type->typ_lu;
629         struct lu_device *d = obd->obd_lu_dev;
630
631         ENTRY;
632         if (ldt != NULL && d != NULL) {
633                 struct lu_env env;
634
635                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
636                 if (rc == 0) {
637                         ldt->ldt_ops->ldto_device_free(&env, d);
638                         lu_env_fini(&env);
639                         obd->obd_lu_dev = NULL;
640                 }
641         }
642         if (!obd->obd_type->typ_dt_ops->o_cleanup)
643                 RETURN(0);
644
645         rc = OBP(obd, cleanup)(obd);
646         RETURN(rc);
647 }
648
649 static inline void obd_cleanup_client_import(struct obd_device *obd)
650 {
651         ENTRY;
652
653         /* If we set up but never connected, the client import will not
654          * have been cleaned.
655          */
656         down_write(&obd->u.cli.cl_sem);
657         if (obd->u.cli.cl_import) {
658                 struct obd_import *imp;
659
660                 imp = obd->u.cli.cl_import;
661                 CDEBUG(D_CONFIG, "%s: client import never connected\n",
662                        obd->obd_name);
663                 ptlrpc_invalidate_import(imp);
664                 client_destroy_import(imp);
665                 obd->u.cli.cl_import = NULL;
666         }
667         up_write(&obd->u.cli.cl_sem);
668
669         EXIT;
670 }
671
672 static inline int obd_process_config(struct obd_device *obd, int datalen,
673                                      void *data)
674 {
675         int rc;
676         struct lu_device_type *ldt = obd->obd_type->typ_lu;
677         struct lu_device *d = obd->obd_lu_dev;
678
679         ENTRY;
680
681         obd->obd_process_conf = 1;
682         if (ldt != NULL && d != NULL) {
683                 struct lu_env env;
684
685                 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
686                 if (rc == 0) {
687                         rc = d->ld_ops->ldo_process_config(&env, d, data);
688                         lu_env_fini(&env);
689                 }
690         } else {
691                 if (!obd->obd_type->typ_dt_ops->o_process_config) {
692                         CERROR("%s: no %s operation\n",
693                                obd->obd_name, __func__);
694                         RETURN(-EOPNOTSUPP);
695                 }
696                 rc = OBP(obd, process_config)(obd, datalen, data);
697         }
698
699         obd->obd_process_conf = 0;
700
701         RETURN(rc);
702 }
703
704 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
705                              struct obdo *obdo)
706 {
707         int rc;
708         ENTRY;
709
710         rc = exp_check_ops(exp);
711         if (rc)
712                 RETURN(rc);
713
714         if (!exp->exp_obd->obd_type->typ_dt_ops->o_create) {
715                 CERROR("%s: no %s operation\n",
716                        (exp)->exp_obd->obd_name, __func__);
717                 RETURN(-ENOTSUPP);
718         }
719
720         rc = OBP(exp->exp_obd, create)(env, exp, obdo);
721         RETURN(rc);
722 }
723
724 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
725                               struct obdo *obdo)
726 {
727         int rc;
728         ENTRY;
729
730         rc = exp_check_ops(exp);
731         if (rc)
732                 RETURN(rc);
733
734         if (!exp->exp_obd->obd_type->typ_dt_ops->o_destroy) {
735                 CERROR("%s: no %s operation\n",
736                        (exp)->exp_obd->obd_name, __func__);
737                 RETURN(-ENOTSUPP);
738         }
739
740         rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
741         RETURN(rc);
742 }
743
744 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
745                               struct obdo *oa)
746 {
747         int rc;
748
749         ENTRY;
750         rc = exp_check_ops(exp);
751         if (rc)
752                 RETURN(rc);
753
754         if (!exp->exp_obd->obd_type->typ_dt_ops->o_getattr) {
755                 CERROR("%s: no %s operation\n",
756                        (exp)->exp_obd->obd_name, __func__);
757                 RETURN(-ENOTSUPP);
758         }
759
760         rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
761
762         RETURN(rc);
763 }
764
765 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
766                               struct obdo *oa)
767 {
768         int rc;
769
770         ENTRY;
771         rc = exp_check_ops(exp);
772         if (rc)
773                 RETURN(rc);
774
775         if (!exp->exp_obd->obd_type->typ_dt_ops->o_setattr) {
776                 CERROR("%s: no %s operation\n",
777                        (exp)->exp_obd->obd_name, __func__);
778                 RETURN(-ENOTSUPP);
779         }
780
781         rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
782
783         RETURN(rc);
784 }
785
786 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
787                                int priority)
788 {
789         struct obd_device *obd = imp->imp_obd;
790         int rc;
791         ENTRY;
792
793         OBD_CHECK_DEV_ACTIVE(obd);
794         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_add_conn) {
795                 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
796                 RETURN(-EOPNOTSUPP);
797         }
798
799         rc = OBP(obd, add_conn)(imp, uuid, priority);
800         RETURN(rc);
801 }
802
803 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
804 {
805         struct obd_device *obd = imp->imp_obd;
806         int rc;
807         ENTRY;
808
809         OBD_CHECK_DEV_ACTIVE(obd);
810         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_del_conn) {
811                 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
812                 RETURN(-EOPNOTSUPP);
813         }
814
815         rc = OBP(obd, del_conn)(imp, uuid);
816         RETURN(rc);
817 }
818
819 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
820 {
821         struct obd_uuid *uuid;
822         ENTRY;
823
824         if (!exp->exp_obd->obd_type ||
825             !exp->exp_obd->obd_type->typ_dt_ops->o_get_uuid)
826                 RETURN(NULL);
827
828         uuid = OBP(exp->exp_obd, get_uuid)(exp);
829         RETURN(uuid);
830 }
831
832 /** Create a new /a exp on device /a obd for the uuid /a cluuid
833  * @param exp New export handle
834  * @param d Connect data, supported flags are set, flags also understood
835  *    by obd are returned.
836  */
837 static inline int obd_connect(const struct lu_env *env,
838                               struct obd_export **exp,struct obd_device *obd,
839                               struct obd_uuid *cluuid,
840                               struct obd_connect_data *data,
841                               void *localdata)
842 {
843         int rc;
844         __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
845                                                    * check */
846         ENTRY;
847
848         OBD_CHECK_DEV_ACTIVE(obd);
849         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_connect) {
850                 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
851                 RETURN(-EOPNOTSUPP);
852         }
853
854         rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
855         /* check that only subset is granted */
856         LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
857                                     data->ocd_connect_flags));
858         RETURN(rc);
859 }
860
861 static inline int obd_reconnect(const struct lu_env *env,
862                                 struct obd_export *exp,
863                                 struct obd_device *obd,
864                                 struct obd_uuid *cluuid,
865                                 struct obd_connect_data *d,
866                                 void *localdata)
867 {
868         int rc;
869         __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
870                                                    * check */
871
872         ENTRY;
873
874         OBD_CHECK_DEV_ACTIVE(obd);
875         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_reconnect)
876                 RETURN(0);
877
878         rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
879         /* check that only subset is granted */
880         LASSERT(ergo(d != NULL,
881                      (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
882         RETURN(rc);
883 }
884
885 static inline int obd_disconnect(struct obd_export *exp)
886 {
887         int rc;
888         ENTRY;
889         rc = exp_check_ops(exp);
890         if (rc)
891                 RETURN(rc);
892
893         if (!exp->exp_obd->obd_type->typ_dt_ops->o_disconnect) {
894                 CERROR("%s: no %s operation\n",
895                        (exp)->exp_obd->obd_name, __func__);
896                 RETURN(-ENOTSUPP);
897         }
898
899         rc = OBP(exp->exp_obd, disconnect)(exp);
900         RETURN(rc);
901 }
902
903 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
904                                enum lu_cli_type type)
905 {
906         int rc;
907         ENTRY;
908
909         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_init)
910                 RETURN(0);
911
912         rc = OBP(obd, fid_init)(obd, exp, type);
913         RETURN(rc);
914 }
915
916 static inline int obd_fid_fini(struct obd_device *obd)
917 {
918         int rc;
919         ENTRY;
920         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_fid_fini)
921                 RETURN(0);
922
923         rc = OBP(obd, fid_fini)(obd);
924         RETURN(rc);
925 }
926
927 static inline int obd_fid_alloc(const struct lu_env *env,
928                                 struct obd_export *exp,
929                                 struct lu_fid *fid,
930                                 struct md_op_data *op_data)
931 {
932         int rc;
933         ENTRY;
934         rc = exp_check_ops(exp);
935         if (rc)
936                 RETURN(rc);
937
938         if (!exp->exp_obd->obd_type->typ_dt_ops->o_fid_alloc) {
939                 CERROR("%s: no %s operation\n",
940                        (exp)->exp_obd->obd_name, __func__);
941                 RETURN(-ENOTSUPP);
942         }
943
944         rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
945         RETURN(rc);
946 }
947
948 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
949 {
950         int rc;
951         ENTRY;
952
953         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_new) {
954                 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
955                 RETURN(-EOPNOTSUPP);
956         }
957
958         /* Check poolname validity */
959         if (!poolname || poolname[0] == '\0' || lov_pool_is_reserved(poolname))
960                 RETURN(-EINVAL);
961
962         rc = OBP(obd, pool_new)(obd, poolname);
963         RETURN(rc);
964 }
965
966 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
967 {
968         int rc;
969         ENTRY;
970         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_del) {
971                 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
972                 RETURN(-EOPNOTSUPP);
973         }
974
975         rc = OBP(obd, pool_del)(obd, poolname);
976         RETURN(rc);
977 }
978
979 static inline int obd_pool_add(struct obd_device *obd, char *poolname,
980                                char *ostname)
981 {
982         int rc;
983         ENTRY;
984
985         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_add) {
986                 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
987                 RETURN(-EOPNOTSUPP);
988         }
989
990         rc = OBP(obd, pool_add)(obd, poolname, ostname);
991         RETURN(rc);
992 }
993
994 static inline int obd_pool_rem(struct obd_device *obd, char *poolname,
995                                char *ostname)
996 {
997         int rc;
998
999         ENTRY;
1000         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_pool_rem) {
1001                 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1002                 RETURN(-EOPNOTSUPP);
1003         }
1004
1005         rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1006         RETURN(rc);
1007 }
1008
1009 static inline int obd_init_export(struct obd_export *exp)
1010 {
1011         int rc = 0;
1012
1013         ENTRY;
1014         if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1015             OBP((exp)->exp_obd, init_export))
1016                 rc = OBP(exp->exp_obd, init_export)(exp);
1017         RETURN(rc);
1018 }
1019
1020 static inline int obd_destroy_export(struct obd_export *exp)
1021 {
1022         ENTRY;
1023         if (exp->exp_obd != NULL && exp->exp_obd->obd_type &&
1024             OBP(exp->exp_obd, destroy_export))
1025                 OBP(exp->exp_obd, destroy_export)(exp);
1026         RETURN(0);
1027 }
1028
1029 /* @max_age is the oldest time in seconds that we accept using a cached data.
1030  * If the cache is older than @max_age we will get a new value from the
1031  * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1032  */
1033 static inline int obd_statfs_async(struct obd_export *exp,
1034                                    struct obd_info *oinfo,
1035                                    time64_t max_age,
1036                                    struct ptlrpc_request_set *rqset)
1037 {
1038         struct obd_device *obd;
1039         int rc = 0;
1040
1041         ENTRY;
1042
1043         if (exp == NULL || exp->exp_obd == NULL)
1044                 RETURN(-EINVAL);
1045
1046         obd = exp->exp_obd;
1047         if (!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs) {
1048                 rc = -EOPNOTSUPP;
1049                 CERROR("%s: no statfs operation: rc = %d\n", obd->obd_name, rc);
1050                 RETURN(rc);
1051         }
1052
1053         CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1054                obd->obd_name, obd->obd_osfs_age, max_age);
1055         rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1056
1057         RETURN(rc);
1058 }
1059
1060 /* @max_age is the oldest time in seconds that we accept using a cached data.
1061  * If the cache is older than @max_age we will get a new value from the
1062  * target. Use a value of 'ktime_get_seconds() + X' to guarantee freshness.
1063  */
1064 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1065                              struct obd_statfs *osfs, time64_t max_age,
1066                              __u32 flags)
1067 {
1068         struct obd_device *obd;
1069         int rc = 0;
1070
1071         ENTRY;
1072         if (unlikely(exp == NULL || exp->exp_obd == NULL))
1073                 RETURN(-EINVAL);
1074
1075         obd = exp->exp_obd;
1076         OBD_CHECK_DEV_ACTIVE(obd);
1077
1078         if (unlikely(!obd->obd_type || !obd->obd_type->typ_dt_ops->o_statfs)) {
1079                 CERROR("%s: no %s operation\n", obd->obd_name, __func__);
1080                 RETURN(-EOPNOTSUPP);
1081         }
1082
1083         CDEBUG(D_SUPER, "%s: age %lld, max_age %lld\n",
1084                obd->obd_name, obd->obd_osfs_age, max_age);
1085         /* ignore cache if aggregated isn't expected */
1086         if (obd->obd_osfs_age < max_age ||
1087             ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1088              !(flags & OBD_STATFS_SUM))) {
1089                 /* the RPC will block anyway, so avoid sending many at once */
1090                 rc = mutex_lock_interruptible_nested(&obd->obd_dev_mutex,
1091                                                      (flags & OBD_STATFS_NESTED)
1092                                                      ? SINGLE_DEPTH_NESTING : 0);
1093                 if (rc)
1094                         RETURN(rc);
1095                 if (obd->obd_osfs_age < max_age ||
1096                     ((obd->obd_osfs.os_state & OS_STATFS_SUM) &&
1097                      !(flags & OBD_STATFS_SUM))) {
1098                         rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1099                 } else {
1100                         mutex_unlock(&obd->obd_dev_mutex);
1101                         GOTO(cached, rc = 0);
1102                 }
1103                 if (rc == 0) {
1104                         CDEBUG(D_SUPER,
1105                                "%s: update %p cache blocks %llu/%llu objects %llu/%llu\n",
1106                                obd->obd_name, &obd->obd_osfs,
1107                                osfs->os_bavail, osfs->os_blocks,
1108                                osfs->os_ffree, osfs->os_files);
1109
1110                         spin_lock(&obd->obd_osfs_lock);
1111                         memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1112                         obd->obd_osfs_age = ktime_get_seconds();
1113                         spin_unlock(&obd->obd_osfs_lock);
1114                 }
1115                 mutex_unlock(&obd->obd_dev_mutex);
1116         } else {
1117 cached:
1118                 CDEBUG(D_SUPER,
1119                        "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1120                        obd->obd_name, &obd->obd_osfs,
1121                        obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1122                        obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1123                 spin_lock(&obd->obd_osfs_lock);
1124                 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1125                 spin_unlock(&obd->obd_osfs_lock);
1126         }
1127         RETURN(rc);
1128 }
1129
1130 static inline int obd_preprw(const struct lu_env *env, int cmd,
1131                              struct obd_export *exp, struct obdo *oa,
1132                              int objcount, struct obd_ioobj *obj,
1133                              struct niobuf_remote *remote, int *pages,
1134                              struct niobuf_local *local)
1135 {
1136         int rc;
1137
1138         ENTRY;
1139
1140         rc = exp_check_ops(exp);
1141         if (rc)
1142                 RETURN(rc);
1143
1144         if (!exp->exp_obd->obd_type->typ_dt_ops->o_preprw) {
1145                 CERROR("%s: no %s operation\n",
1146                        (exp)->exp_obd->obd_name, __func__);
1147                 RETURN(-ENOTSUPP);
1148         }
1149
1150         rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1151                                        pages, local);
1152
1153         RETURN(rc);
1154 }
1155
1156 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1157                                struct obd_export *exp, struct obdo *oa,
1158                                int objcount, struct obd_ioobj *obj,
1159                                struct niobuf_remote *rnb, int pages,
1160                                struct niobuf_local *local, const int orig_rc,
1161                                int nob, ktime_t kstart)
1162 {
1163         int rc;
1164         ENTRY;
1165
1166         rc = exp_check_ops(exp);
1167         if (rc)
1168                 RETURN(rc);
1169
1170         if (!exp->exp_obd->obd_type->typ_dt_ops->o_commitrw) {
1171                 CERROR("%s: no %s operation\n",
1172                        (exp)->exp_obd->obd_name, __func__);
1173                 RETURN(-ENOTSUPP);
1174         }
1175
1176         rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1177                                          rnb, pages, local, orig_rc, nob,
1178                                          kstart);
1179
1180         RETURN(rc);
1181 }
1182
1183 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1184                                 int len, void *karg, void __user *uarg)
1185 {
1186         int rc;
1187         ENTRY;
1188
1189         rc = exp_check_ops(exp);
1190         if (rc)
1191                 RETURN(rc);
1192
1193         if (!exp->exp_obd->obd_type->typ_dt_ops->o_iocontrol) {
1194                 CERROR("%s: no %s operation\n",
1195                        (exp)->exp_obd->obd_name, __func__);
1196                 RETURN(-ENOTSUPP);
1197         }
1198
1199         rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1200         RETURN(rc);
1201 }
1202
1203 static inline void obd_import_event(struct obd_device *obd,
1204                                     struct obd_import *imp,
1205                                     enum obd_import_event event)
1206 {
1207         ENTRY;
1208         if (!obd) {
1209                 CERROR("NULL device\n");
1210                 EXIT;
1211                 return;
1212         }
1213
1214         if (obd->obd_set_up && OBP(obd, import_event))
1215                 OBP(obd, import_event)(obd, imp, event);
1216
1217         EXIT;
1218 }
1219
1220 static inline int obd_notify(struct obd_device *obd,
1221                              struct obd_device *watched,
1222                              enum obd_notify_event ev)
1223 {
1224         int rc;
1225         ENTRY;
1226
1227         rc = obd_check_dev(obd);
1228         if (rc)
1229                 return rc;
1230
1231         if (!obd->obd_set_up) {
1232                 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1233                 RETURN(-EINVAL);
1234         }
1235
1236         if (!OBP(obd, notify)) {
1237                 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1238                 RETURN(-ENOSYS);
1239         }
1240
1241         rc = OBP(obd, notify)(obd, watched, ev);
1242
1243         RETURN(rc);
1244 }
1245
1246 static inline int obd_notify_observer(struct obd_device *observer,
1247                                       struct obd_device *observed,
1248                                       enum obd_notify_event ev)
1249 {
1250         int rc = 0;
1251         int rc2 = 0;
1252         struct obd_notify_upcall *onu;
1253
1254         if (observer->obd_observer)
1255                 rc = obd_notify(observer->obd_observer, observed, ev);
1256
1257         /*
1258          * Also, call non-obd listener, if any
1259          */
1260         onu = &observer->obd_upcall;
1261         if (onu->onu_upcall != NULL)
1262                 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1263
1264         return rc ? rc : rc2;
1265 }
1266
1267 static inline int obd_quotactl(struct obd_export *exp,
1268                                struct obd_quotactl *oqctl)
1269 {
1270         int rc;
1271         ENTRY;
1272
1273         rc = exp_check_ops(exp);
1274         if (rc)
1275                 RETURN(rc);
1276
1277         if (!exp->exp_obd->obd_type->typ_dt_ops->o_quotactl) {
1278                 CERROR("%s: no %s operation\n",
1279                        (exp)->exp_obd->obd_name, __func__);
1280                 RETURN(-ENOTSUPP);
1281         }
1282
1283         rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1284         RETURN(rc);
1285 }
1286
1287 static inline int obd_health_check(const struct lu_env *env,
1288                                    struct obd_device *obd)
1289 {
1290         /* returns: 0 on healthy
1291          *         >0 on unhealthy + reason code/flag
1292          *            however the only suppored reason == 1 right now
1293          *            We'll need to define some better reasons
1294          *            or flags in the future.
1295          *         <0 on error
1296          */
1297         int rc;
1298
1299         ENTRY;
1300
1301         /* NULL method is normal here */
1302         if (obd == NULL || !obd->obd_type) {
1303                 CERROR("cleaned up obd\n");
1304                 RETURN(-EOPNOTSUPP);
1305         }
1306         if (!obd->obd_set_up || obd->obd_stopping)
1307                 RETURN(0);
1308         if (!OBP(obd, health_check))
1309                 RETURN(0);
1310
1311         rc = OBP(obd, health_check)(env, obd);
1312         RETURN(rc);
1313 }
1314
1315 static inline int obd_register_observer(struct obd_device *obd,
1316                                         struct obd_device *observer)
1317 {
1318         int rc;
1319         ENTRY;
1320
1321         rc = obd_check_dev(obd);
1322         if (rc)
1323                 return rc;
1324
1325         down_write(&obd->obd_observer_link_sem);
1326         if (obd->obd_observer && observer) {
1327                 up_write(&obd->obd_observer_link_sem);
1328                 RETURN(-EALREADY);
1329         }
1330         obd->obd_observer = observer;
1331         up_write(&obd->obd_observer_link_sem);
1332         RETURN(0);
1333 }
1334
1335 /* metadata helpers */
1336 enum mps_stat_idx {
1337         LPROC_MD_CLOSE,
1338         LPROC_MD_CREATE,
1339         LPROC_MD_ENQUEUE,
1340         LPROC_MD_GETATTR,
1341         LPROC_MD_INTENT_LOCK,
1342         LPROC_MD_LINK,
1343         LPROC_MD_RENAME,
1344         LPROC_MD_SETATTR,
1345         LPROC_MD_FSYNC,
1346         LPROC_MD_READ_PAGE,
1347         LPROC_MD_UNLINK,
1348         LPROC_MD_SETXATTR,
1349         LPROC_MD_GETXATTR,
1350         LPROC_MD_INTENT_GETATTR_ASYNC,
1351         LPROC_MD_REVALIDATE_LOCK,
1352         LPROC_MD_LAST_OPC,
1353 };
1354
1355 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1356                               struct lu_fid *fid)
1357 {
1358         int rc;
1359
1360         rc = exp_check_ops(exp);
1361         if (rc)
1362                 return rc;
1363
1364         return MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1365 }
1366
1367 static inline int md_getattr(struct obd_export *exp,
1368                              struct md_op_data *op_data,
1369                              struct ptlrpc_request **request)
1370 {
1371         int rc;
1372
1373         rc = exp_check_ops(exp);
1374         if (rc)
1375                 return rc;
1376
1377         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1378                              LPROC_MD_GETATTR);
1379
1380         return MDP(exp->exp_obd, getattr)(exp, op_data, request);
1381 }
1382
1383 static inline int md_null_inode(struct obd_export *exp,
1384                                    const struct lu_fid *fid)
1385 {
1386         int rc;
1387
1388         rc = exp_check_ops(exp);
1389         if (rc)
1390                 return rc;
1391
1392         return MDP(exp->exp_obd, null_inode)(exp, fid);
1393 }
1394
1395 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1396                            struct md_open_data *mod,
1397                            struct ptlrpc_request **request)
1398 {
1399         int rc;
1400
1401         rc = exp_check_ops(exp);
1402         if (rc)
1403                 return rc;
1404
1405         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1406                              LPROC_MD_CLOSE);
1407
1408         return MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1409 }
1410
1411 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1412                             const void *data, size_t datalen, umode_t mode,
1413                             uid_t uid, gid_t gid, kernel_cap_t cap_effective,
1414                             __u64 rdev, struct ptlrpc_request **request)
1415 {
1416         int rc;
1417
1418         rc = exp_check_ops(exp);
1419         if (rc)
1420                 return rc;
1421
1422         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1423                              LPROC_MD_CREATE);
1424
1425         return MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1426                                          uid, gid, cap_effective, rdev,
1427                                          request);
1428 }
1429
1430 static inline int md_enqueue(struct obd_export *exp,
1431                              struct ldlm_enqueue_info *einfo,
1432                              const union ldlm_policy_data *policy,
1433                              struct md_op_data *op_data,
1434                              struct lustre_handle *lockh,
1435                              __u64 extra_lock_flags)
1436 {
1437         int rc;
1438
1439         rc = exp_check_ops(exp);
1440         if (rc)
1441                 return rc;
1442
1443         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1444                              LPROC_MD_ENQUEUE);
1445
1446         return MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1447                    extra_lock_flags);
1448 }
1449
1450 static inline int md_getattr_name(struct obd_export *exp,
1451                                   struct md_op_data *op_data,
1452                                   struct ptlrpc_request **request)
1453 {
1454         int rc;
1455
1456         rc = exp_check_ops(exp);
1457         if (rc)
1458                 return rc;
1459
1460         return MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1461 }
1462
1463 static inline int md_intent_lock(struct obd_export *exp,
1464                                  struct md_op_data *op_data,
1465                                  struct lookup_intent *it,
1466                                  struct ptlrpc_request **reqp,
1467                                  ldlm_blocking_callback cb_blocking,
1468                                  __u64 extra_lock_flags)
1469 {
1470         int rc;
1471
1472         rc = exp_check_ops(exp);
1473         if (rc)
1474                 return rc;
1475
1476         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1477                              LPROC_MD_INTENT_LOCK);
1478
1479         return MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp,
1480                                               cb_blocking, extra_lock_flags);
1481 }
1482
1483 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1484                           struct ptlrpc_request **request)
1485 {
1486         int rc;
1487
1488         rc = exp_check_ops(exp);
1489         if (rc)
1490                 return rc;
1491
1492         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1493                              LPROC_MD_LINK);
1494
1495         return MDP(exp->exp_obd, link)(exp, op_data, request);
1496 }
1497
1498 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1499                             const char *old_name, size_t oldlen,
1500                             const char *new_name, size_t newlen,
1501                             struct ptlrpc_request **request)
1502 {
1503         int rc;
1504
1505         rc = exp_check_ops(exp);
1506         if (rc)
1507                 return rc;
1508
1509         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1510                              LPROC_MD_RENAME);
1511
1512         return MDP(exp->exp_obd, rename)(exp, op_data, old_name, oldlen,
1513                                          new_name, newlen, request);
1514 }
1515
1516 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1517                              void *ea, size_t ealen,
1518                              struct ptlrpc_request **request)
1519 {
1520         int rc;
1521
1522         rc = exp_check_ops(exp);
1523         if (rc)
1524                 return rc;
1525
1526         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1527                              LPROC_MD_SETATTR);
1528
1529         return MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1530 }
1531
1532 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1533                            struct ptlrpc_request **request)
1534 {
1535         int rc;
1536
1537         rc = exp_check_ops(exp);
1538         if (rc)
1539                 return rc;
1540
1541         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1542                              LPROC_MD_FSYNC);
1543
1544         return MDP(exp->exp_obd, fsync)(exp, fid, request);
1545 }
1546
1547 /* FLR: resync mirrored files. */
1548 static inline int md_file_resync(struct obd_export *exp,
1549                                  struct md_op_data *data)
1550 {
1551         int rc;
1552
1553         rc = exp_check_ops(exp);
1554         if (rc)
1555                 return rc;
1556
1557         return MDP(exp->exp_obd, file_resync)(exp, data);
1558 }
1559
1560 static inline int md_read_page(struct obd_export *exp,
1561                                struct md_op_data *op_data,
1562                                struct md_readdir_info *mrinfo,
1563                                __u64  hash_offset, struct page **ppage)
1564 {
1565         int rc;
1566
1567         rc = exp_check_ops(exp);
1568         if (rc)
1569                 return rc;
1570
1571         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1572                              LPROC_MD_READ_PAGE);
1573
1574         return MDP(exp->exp_obd, read_page)(exp, op_data, mrinfo, hash_offset,
1575                                             ppage);
1576 }
1577
1578 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1579                             struct ptlrpc_request **request)
1580 {
1581         int rc;
1582
1583         rc = exp_check_ops(exp);
1584         if (rc)
1585                 return rc;
1586
1587         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1588                              LPROC_MD_UNLINK);
1589
1590         return MDP(exp->exp_obd, unlink)(exp, op_data, request);
1591 }
1592
1593 static inline int md_get_lustre_md(struct obd_export *exp,
1594                                    struct req_capsule *pill,
1595                                    struct obd_export *dt_exp,
1596                                    struct obd_export *md_exp,
1597                                    struct lustre_md *md)
1598 {
1599         int rc;
1600
1601         rc = exp_check_ops(exp);
1602         if (rc)
1603                 return rc;
1604
1605         return MDP(exp->exp_obd, get_lustre_md)(exp, pill, dt_exp, md_exp, md);
1606 }
1607
1608 static inline int md_free_lustre_md(struct obd_export *exp,
1609                                     struct lustre_md *md)
1610 {
1611         int rc;
1612
1613         rc = exp_check_ops(exp);
1614         if (rc)
1615                 return rc;
1616
1617         return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1618 }
1619
1620 static inline int md_merge_attr(struct obd_export *exp,
1621                                 const struct lmv_stripe_md *lsm,
1622                                 struct cl_attr *attr,
1623                                 ldlm_blocking_callback cb)
1624 {
1625         int rc;
1626
1627         rc = exp_check_ops(exp);
1628         if (rc)
1629                 return rc;
1630
1631         return MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb);
1632 }
1633
1634 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1635                               u64 obd_md_valid, const char *name,
1636                               const void *value, size_t value_size,
1637                               unsigned int xattr_flags, u32 suppgid,
1638                               struct ptlrpc_request **req)
1639 {
1640         int rc;
1641
1642         rc = exp_check_ops(exp);
1643         if (rc)
1644                 return rc;
1645
1646         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1647                              LPROC_MD_SETXATTR);
1648
1649         return MDP(exp->exp_obd, setxattr)(exp, fid, obd_md_valid, name,
1650                                            value, value_size, xattr_flags,
1651                                            suppgid, req);
1652 }
1653
1654 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1655                               u64 obd_md_valid, const char *name,
1656                               size_t buf_size, struct ptlrpc_request **req)
1657 {
1658         int rc;
1659
1660         rc = exp_check_ops(exp);
1661         if (rc)
1662                 return rc;
1663
1664         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1665                              LPROC_MD_GETXATTR);
1666
1667         return MDP(exp->exp_obd, getxattr)(exp, fid, obd_md_valid, name,
1668                                            buf_size, req);
1669 }
1670
1671 static inline int md_set_open_replay_data(struct obd_export *exp,
1672                                           struct obd_client_handle *och,
1673                                           struct lookup_intent *it)
1674 {
1675         int rc;
1676
1677         rc = exp_check_ops(exp);
1678         if (rc)
1679                 return rc;
1680
1681         return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
1682 }
1683
1684 static inline int md_clear_open_replay_data(struct obd_export *exp,
1685                                             struct obd_client_handle *och)
1686 {
1687         int rc;
1688
1689         rc = exp_check_ops(exp);
1690         if (rc)
1691                 return rc;
1692
1693         return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1694 }
1695
1696 static inline int md_set_lock_data(struct obd_export *exp,
1697                                    const struct lustre_handle *lockh,
1698                                    void *data, __u64 *bits)
1699 {
1700         int rc;
1701
1702         rc = exp_check_ops(exp);
1703         if (rc)
1704                 return rc;
1705
1706         return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
1707 }
1708
1709 static inline
1710 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1711                      union ldlm_policy_data *policy, enum ldlm_mode mode,
1712                      enum ldlm_cancel_flags cancel_flags, void *opaque)
1713 {
1714         int rc;
1715
1716         rc = exp_check_ops(exp);
1717         if (rc)
1718                 return rc;
1719
1720         return MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1721                                                 cancel_flags, opaque);
1722 }
1723
1724 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1725                                            const struct lu_fid *fid,
1726                                            enum ldlm_type type,
1727                                            union ldlm_policy_data *policy,
1728                                            enum ldlm_mode mode,
1729                                            struct lustre_handle *lockh)
1730 {
1731         int rc;
1732
1733         rc = exp_check_ops(exp);
1734         if (rc)
1735                 return rc;
1736
1737         return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1738                                              policy, mode, lockh);
1739 }
1740
1741 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1742                                   __u32 def_ea_size)
1743 {
1744         int rc;
1745
1746         rc = exp_check_ops(exp);
1747         if (rc)
1748                 return rc;
1749
1750         return MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size);
1751 }
1752
1753 static inline int md_intent_getattr_async(struct obd_export *exp,
1754                                           struct md_op_item *item)
1755 {
1756         int rc;
1757
1758         rc = exp_check_ops(exp);
1759         if (rc)
1760                 return rc;
1761
1762         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1763                              LPROC_MD_INTENT_GETATTR_ASYNC);
1764
1765         return MDP(exp->exp_obd, intent_getattr_async)(exp, item);
1766 }
1767
1768 static inline int md_revalidate_lock(struct obd_export *exp,
1769                                      struct lookup_intent *it,
1770                                      struct lu_fid *fid, __u64 *bits)
1771 {
1772         int rc;
1773
1774         rc = exp_check_ops(exp);
1775         if (rc)
1776                 return rc;
1777
1778         lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1779                              LPROC_MD_REVALIDATE_LOCK);
1780
1781         return MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1782 }
1783
1784 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1785                                       const struct lmv_stripe_md *lsm,
1786                                       const char *name, int namelen,
1787                                       struct lu_fid *fid)
1788 {
1789         int rc;
1790
1791         rc = exp_check_ops(exp);
1792         if (rc)
1793                 return rc;
1794
1795         return MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen,
1796                                                    fid);
1797 }
1798
1799 /* Unpack an MD struct from disk to in-memory format.
1800  * Returns +ve size of unpacked MD (0 for free), or -ve error.
1801  *
1802  * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1803  * If *plsm == NULL then it will be allocated.
1804  */
1805 static inline int md_unpackmd(struct obd_export *exp,
1806                               struct lmv_stripe_md **plsm,
1807                               const union lmv_mds_md *lmm, size_t lmm_size)
1808 {
1809         int rc;
1810
1811         rc = exp_check_ops(exp);
1812         if (rc)
1813                 return rc;
1814
1815         return MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1816 }
1817
1818 static inline int md_rmfid(struct obd_export *exp, struct fid_array *fa,
1819                            int *rcs, struct ptlrpc_request_set *set)
1820 {
1821         int rc;
1822
1823         rc = exp_check_ops(exp);
1824         if (rc)
1825                 return rc;
1826
1827         return MDP(exp->exp_obd, rmfid)(exp, fa, rcs, set);
1828 }
1829
1830 /* OBD Metadata Support */
1831
1832 extern int obd_init_caches(void);
1833 extern void obd_cleanup_caches(void);
1834
1835 typedef int (*register_lwp_cb)(void *data);
1836
1837 struct lwp_register_item {
1838         struct obd_export **lri_exp;
1839         register_lwp_cb     lri_cb_func;
1840         void               *lri_cb_data;
1841         struct list_head    lri_list;
1842         atomic_t            lri_ref;
1843         char                lri_name[MTI_NAME_MAXLEN];
1844 };
1845
1846 /* obd_mount.c */
1847 #ifdef HAVE_SERVER_SUPPORT
1848 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1849                              register_lwp_cb cb_func, void *cb_data);
1850 void lustre_deregister_lwp_item(struct obd_export **exp);
1851 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1852 void lustre_notify_lwp_list(struct obd_export *exp);
1853 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1854 #endif /* HAVE_SERVER_SUPPORT */
1855 int lustre_check_exclusion(struct super_block *sb, char *svname);
1856
1857 /* lustre_peer.c    */
1858 int lustre_uuid_to_peer(const char *uuid, struct lnet_nid *peer_nid,
1859                         int index);
1860 int class_add_uuid(const char *uuid, __u64 nid);
1861 int class_del_uuid (const char *uuid);
1862 int class_add_nids_to_uuid(struct obd_uuid *uuid, lnet_nid_t *nids,
1863                            int nid_count);
1864 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1865
1866 /* class_obd.c */
1867 extern char obd_jobid_name[];
1868
1869 extern unsigned int obd_lbug_on_eviction;
1870 extern unsigned int obd_dump_on_eviction;
1871
1872 static inline bool do_dump_on_eviction(struct obd_device *exp_obd)
1873 {
1874         if (obd_lbug_on_eviction &&
1875             strncmp(exp_obd->obd_type->typ_name, LUSTRE_MGC_NAME,
1876                     strlen(LUSTRE_MGC_NAME))) {
1877                 CERROR("LBUG upon eviction\n");
1878                 LBUG();
1879         }
1880
1881         return obd_dump_on_eviction;
1882 }
1883
1884 /* statfs_pack.c */
1885 struct kstatfs;
1886 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1887 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1888
1889 /* root squash info */
1890 struct root_squash_info {
1891         uid_t                   rsi_uid;
1892         gid_t                   rsi_gid;
1893         struct list_head        rsi_nosquash_nids;
1894         spinlock_t              rsi_lock;
1895 };
1896
1897 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1898
1899 /* linux-module.c */
1900 struct obd_ioctl_data;
1901 int obd_ioctl_getdata(struct obd_ioctl_data **data, int *len, void __user *arg);
1902 int class_procfs_init(void);
1903 int class_procfs_clean(void);
1904
1905 extern void obd_heat_add(struct obd_heat_instance *instance,
1906                          unsigned int time_second, __u64 count,
1907                          unsigned int weight, unsigned int period_second);
1908 extern void obd_heat_decay(struct obd_heat_instance *instance,
1909                            __u64 time_second, unsigned int weight,
1910                            unsigned int period_second);
1911 extern __u64 obd_heat_get(struct obd_heat_instance *instance,
1912                           unsigned int time_second, unsigned int weight,
1913                           unsigned int period_second);
1914 extern void obd_heat_clear(struct obd_heat_instance *instance, int count);
1915
1916 /* struct kobj_type */
1917 static inline
1918 struct attribute *_get_attr_matches(const struct kobj_type *typ,
1919                                     const char *key, size_t keylen,
1920                                     int (*is_match)(const char *, const char *,
1921                                                     size_t))
1922 {
1923         int i;
1924
1925 #ifdef HAVE_KOBJ_TYPE_DEFAULT_GROUPS
1926         for (i = 0; typ->default_groups[i]; i++) {
1927                 int k;
1928                 struct attribute **attrs;
1929
1930                 attrs = (struct attribute **)typ->default_groups[i]->attrs;
1931                 for (k = 0; attrs[k]; k++) {
1932                         if (is_match(attrs[k]->name, key, keylen))
1933                                 return (struct attribute *)attrs[k];
1934                 }
1935         }
1936 #else
1937         for (i = 0; typ->default_attrs[i]; i++) {
1938                 if (is_match(typ->default_attrs[i]->name, key, keylen))
1939                         return typ->default_attrs[i];
1940         }
1941 #endif
1942         return NULL;
1943 }
1944
1945 static inline
1946 int _attr_name_exact(const char *attr_name, const char *key, size_t len)
1947 {
1948         return !strcmp(attr_name, key);
1949 }
1950
1951 static inline
1952 struct attribute *get_attr_by_name(const struct kobj_type *typ,
1953                                    const char *name)
1954 {
1955         return _get_attr_matches(typ, name, 0, _attr_name_exact);
1956 }
1957
1958 static inline
1959 int _attr_name_starts_with(const char *attr_name, const char *name, size_t len)
1960 {
1961         return !strncmp(attr_name, name, len);
1962 }
1963
1964 static inline
1965 struct attribute *get_attr_starts_with(const struct kobj_type *typ,
1966                                        const char *name,
1967                                        size_t len)
1968 {
1969         return _get_attr_matches(typ, name, len, _attr_name_starts_with);
1970 }
1971
1972 #endif /* __LINUX_OBD_CLASS_H */