Whamcloud - gitweb
LU-1303 osp: Basic OSP device implementation
[fs/lustre-release.git] / lustre / osp / osp_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) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Intel, 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  * lustre/osp/osp_internal.h
37  *
38  * Author: Alex Zhuravlev <alexey.zhuravlev@intel.com>
39  */
40
41 #ifndef _OSP_INTERNAL_H
42 #define _OSP_INTERNAL_H
43
44 #include <obd.h>
45 #include <dt_object.h>
46 #include <lustre_fid.h>
47
48 struct osp_device {
49         struct dt_device                 opd_dt_dev;
50         /* corresponded OST index */
51         int                              opd_index;
52         /* device used to store persistent state (llogs, last ids) */
53         struct obd_export               *opd_storage_exp;
54         struct dt_device                *opd_storage;
55         /* connection to OST */
56         struct obd_device               *opd_obd;
57         struct obd_export               *opd_exp;
58         struct obd_uuid                  opd_cluuid;
59         struct obd_connect_data         *opd_connect_data;
60         int                              opd_connects;
61         cfs_proc_dir_entry_t            *opd_proc_entry;
62         struct lprocfs_stats            *opd_stats;
63         /* connection status. */
64         int                              opd_new_connection;
65         int                              opd_got_disconnected;
66         int                              opd_imp_connected;
67         int                              opd_imp_active;
68         int                              opd_imp_seen_connected:1;
69
70         /* whether local recovery is completed:
71          * reported via ->ldo_recovery_complete() */
72         int                              opd_recovery_completed;
73
74         cfs_proc_dir_entry_t            *opd_symlink;
75 };
76
77 extern cfs_mem_cache_t *osp_object_kmem;
78
79 /* this is a top object */
80 struct osp_object {
81         struct lu_object_header  opo_header;
82         struct dt_object         opo_obj;
83         int                      opo_reserved;
84 };
85
86 extern struct lu_object_operations osp_lu_obj_ops;
87
88 struct osp_thread_info {
89         struct lu_attr           osi_attr;
90 };
91
92 extern struct lu_context_key osp_thread_key;
93
94 static inline struct osp_thread_info *osp_env_info(const struct lu_env *env)
95 {
96         struct osp_thread_info *info;
97
98         info = lu_context_key_get(&env->le_ctx, &osp_thread_key);
99         if (info == NULL) {
100                 lu_env_refill((struct lu_env *)env);
101                 info = lu_context_key_get(&env->le_ctx, &osp_thread_key);
102         }
103         LASSERT(info);
104         return info;
105 }
106
107 struct osp_txn_info {
108         __u32   oti_current_id;
109 };
110
111 extern struct lu_context_key osp_txn_key;
112
113 static inline struct osp_txn_info *osp_txn_info(struct lu_context *ctx)
114 {
115         struct osp_txn_info *info;
116
117         info = lu_context_key_get(ctx, &osp_txn_key);
118         return info;
119 }
120
121 extern const struct lu_device_operations osp_lu_ops;
122
123 static inline int lu_device_is_osp(struct lu_device *d)
124 {
125         return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &osp_lu_ops);
126 }
127
128 static inline struct osp_device *lu2osp_dev(struct lu_device *d)
129 {
130         LASSERT(lu_device_is_osp(d));
131         return container_of0(d, struct osp_device, opd_dt_dev.dd_lu_dev);
132 }
133
134 static inline struct lu_device *osp2lu_dev(struct osp_device *d)
135 {
136         return &d->opd_dt_dev.dd_lu_dev;
137 }
138
139 static inline struct osp_device *dt2osp_dev(struct dt_device *d)
140 {
141         LASSERT(lu_device_is_osp(&d->dd_lu_dev));
142         return container_of0(d, struct osp_device, opd_dt_dev);
143 }
144
145 static inline struct osp_object *lu2osp_obj(struct lu_object *o)
146 {
147         LASSERT(ergo(o != NULL, lu_device_is_osp(o->lo_dev)));
148         return container_of0(o, struct osp_object, opo_obj.do_lu);
149 }
150
151 static inline struct lu_object *osp2lu_obj(struct osp_object *obj)
152 {
153         return &obj->opo_obj.do_lu;
154 }
155
156 static inline struct osp_object *osp_obj(const struct lu_object *o)
157 {
158         LASSERT(lu_device_is_osp(o->lo_dev));
159         return container_of0(o, struct osp_object, opo_obj.do_lu);
160 }
161
162 static inline struct osp_object *dt2osp_obj(const struct dt_object *d)
163 {
164         return osp_obj(&d->do_lu);
165 }
166
167 static inline struct dt_object *osp_object_child(struct osp_object *o)
168 {
169         return container_of0(lu_object_next(osp2lu_obj(o)),
170                              struct dt_object, do_lu);
171 }
172
173 /* lproc_osp.c */
174 void lprocfs_osp_init_vars(struct lprocfs_static_vars *lvars);
175
176 #endif