Whamcloud - gitweb
3e021cd92985a9b177735873fb49082a46a95c9e
[fs/lustre-release.git] / lustre / ofd / ofd_internal.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.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) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Whamcloud, Inc.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef _OFD_INTERNAL_H
38 #define _OFD_INTERNAL_H
39
40 #include <obd.h>
41 #include <dt_object.h>
42
43 struct ofd_device {
44         struct dt_device         ofd_dt_dev;
45         struct dt_device        *ofd_osd;
46         struct dt_device_param   ofd_dt_conf;
47
48         struct lu_site           ofd_site;
49 };
50
51 static inline struct ofd_device *ofd_dev(struct lu_device *d)
52 {
53         return container_of0(d, struct ofd_device, ofd_dt_dev.dd_lu_dev);
54 }
55
56 static inline struct obd_device *ofd_obd(struct ofd_device *ofd)
57 {
58         return ofd->ofd_dt_dev.dd_lu_dev.ld_obd;
59 }
60
61 static inline struct ofd_device *ofd_exp(struct obd_export *exp)
62 {
63         return ofd_dev(exp->exp_obd->obd_lu_dev);
64 }
65
66 static inline char *ofd_name(struct ofd_device *ofd)
67 {
68         return ofd->ofd_dt_dev.dd_lu_dev.ld_obd->obd_name;
69 }
70
71 struct ofd_object {
72         struct lu_object_header ofo_header;
73         struct dt_object        ofo_obj;
74 };
75
76 static inline struct ofd_object *ofd_obj(struct lu_object *o)
77 {
78         return container_of0(o, struct ofd_object, ofo_obj.do_lu);
79 }
80
81 /*
82  * Common data shared by obdofd-level handlers. This is allocated per-thread
83  * to reduce stack consumption.
84  */
85 struct ofd_thread_info {
86         const struct lu_env *fti_env;
87
88         union {
89                 char            name[64]; /* for ofd_init0() */
90         } fti_u;
91 };
92
93 /* ofd_dev.c */
94 extern struct lu_context_key ofd_thread_key;
95
96 /* ofd_obd.c */
97 extern struct obd_ops ofd_obd_ops;
98
99 /* lproc_ofd.c */
100 void lprocfs_ofd_init_vars(struct lprocfs_static_vars *lvars);
101
102 static inline struct ofd_thread_info * ofd_info(const struct lu_env *env)
103 {
104         struct ofd_thread_info *info;
105
106         info = lu_context_key_get(&env->le_ctx, &ofd_thread_key);
107         LASSERT(info);
108         LASSERT(info->fti_env);
109         LASSERT(info->fti_env == env);
110         return info;
111 }
112
113 static inline struct ofd_thread_info * ofd_info_init(const struct lu_env *env,
114                                                      struct obd_export *exp)
115 {
116         struct ofd_thread_info *info;
117
118         info = lu_context_key_get(&env->le_ctx, &ofd_thread_key);
119         LASSERT(info);
120         LASSERT(info->fti_env == NULL);
121
122         info->fti_env = env;
123         return info;
124 }
125
126 #endif /* _OFD_INTERNAL_H */