Whamcloud - gitweb
LU-1303 osp: land precreate code
[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         struct dt_object                *opd_last_used_file;
56
57         /* stored persistently in LE format, updated directly to/from disk
58          * and required le64_to_cpu() conversion before use.
59          * Protected by opd_pre_lock */
60         volatile obd_id                  opd_last_used_id;
61
62         obd_id                           opd_gap_start;
63         int                              opd_gap_count;
64         /* connection to OST */
65         struct obd_device               *opd_obd;
66         struct obd_export               *opd_exp;
67         struct obd_uuid                  opd_cluuid;
68         struct obd_connect_data         *opd_connect_data;
69         int                              opd_connects;
70         cfs_proc_dir_entry_t            *opd_proc_entry;
71         struct lprocfs_stats            *opd_stats;
72         /* connection status. */
73         int                              opd_new_connection;
74         int                              opd_got_disconnected;
75         int                              opd_imp_connected;
76         int                              opd_imp_active;
77         int                              opd_imp_seen_connected:1;
78
79         /* whether local recovery is completed:
80          * reported via ->ldo_recovery_complete() */
81         int                              opd_recovery_completed;
82
83         /*
84          * Precreation pool
85          */
86         cfs_spinlock_t                   opd_pre_lock;
87         /* next id to assign in creation */
88         __u64                            opd_pre_next;
89         /* last created id OST reported, next-created - available id's */
90         __u64                            opd_pre_last_created;
91         /* how many ids are reserved in declare, we shouldn't block in create */
92         __u64                            opd_pre_reserved;
93         /* dedicate precreate thread */
94         struct ptlrpc_thread             opd_pre_thread;
95         /* thread waits for signals about pool going empty */
96         cfs_waitq_t                      opd_pre_waitq;
97         /* consumers (who needs new ids) wait here */
98         cfs_waitq_t                      opd_pre_user_waitq;
99         /* current precreation status: working, failed, stopping? */
100         int                              opd_pre_status;
101         /* how many to precreate next time */
102         int                              opd_pre_grow_count;
103         int                              opd_pre_min_grow_count;
104         int                              opd_pre_max_grow_count;
105         /* whether to grow precreation window next time or not */
106         int                              opd_pre_grow_slow;
107
108         /*
109          * statfs related fields: OSP maintains it on its own
110          */
111         struct obd_statfs                opd_statfs;
112         cfs_time_t                       opd_statfs_fresh_till;
113         cfs_timer_t                      opd_statfs_timer;
114         int                              opd_statfs_update_in_progress;
115         /* how often to update statfs data */
116         int                              opd_statfs_maxage;
117
118         cfs_proc_dir_entry_t            *opd_symlink;
119 };
120
121 extern cfs_mem_cache_t *osp_object_kmem;
122
123 /* this is a top object */
124 struct osp_object {
125         struct lu_object_header  opo_header;
126         struct dt_object         opo_obj;
127         int                      opo_reserved;
128 };
129
130 extern struct lu_object_operations osp_lu_obj_ops;
131
132 struct osp_thread_info {
133         struct lu_buf            osi_lb;
134         struct lu_fid            osi_fid;
135         struct lu_attr           osi_attr;
136         struct ost_id            osi_oi;
137         obd_id                   osi_id;
138         loff_t                   osi_off;
139 };
140
141 static inline void osp_objid_buf_prep(struct osp_thread_info *osi,
142                                       struct osp_device *d, int index)
143 {
144         osi->osi_lb.lb_buf = (void *)&d->opd_last_used_id;
145         osi->osi_lb.lb_len = sizeof(d->opd_last_used_id);
146         osi->osi_off = sizeof(d->opd_last_used_id) * index;
147 }
148
149 extern struct lu_context_key osp_thread_key;
150
151 static inline struct osp_thread_info *osp_env_info(const struct lu_env *env)
152 {
153         struct osp_thread_info *info;
154
155         info = lu_context_key_get(&env->le_ctx, &osp_thread_key);
156         if (info == NULL) {
157                 lu_env_refill((struct lu_env *)env);
158                 info = lu_context_key_get(&env->le_ctx, &osp_thread_key);
159         }
160         LASSERT(info);
161         return info;
162 }
163
164 struct osp_txn_info {
165         __u32   oti_current_id;
166 };
167
168 extern struct lu_context_key osp_txn_key;
169
170 static inline struct osp_txn_info *osp_txn_info(struct lu_context *ctx)
171 {
172         struct osp_txn_info *info;
173
174         info = lu_context_key_get(ctx, &osp_txn_key);
175         return info;
176 }
177
178 extern const struct lu_device_operations osp_lu_ops;
179
180 static inline int lu_device_is_osp(struct lu_device *d)
181 {
182         return ergo(d != NULL && d->ld_ops != NULL, d->ld_ops == &osp_lu_ops);
183 }
184
185 static inline struct osp_device *lu2osp_dev(struct lu_device *d)
186 {
187         LASSERT(lu_device_is_osp(d));
188         return container_of0(d, struct osp_device, opd_dt_dev.dd_lu_dev);
189 }
190
191 static inline struct lu_device *osp2lu_dev(struct osp_device *d)
192 {
193         return &d->opd_dt_dev.dd_lu_dev;
194 }
195
196 static inline struct osp_device *dt2osp_dev(struct dt_device *d)
197 {
198         LASSERT(lu_device_is_osp(&d->dd_lu_dev));
199         return container_of0(d, struct osp_device, opd_dt_dev);
200 }
201
202 static inline struct osp_object *lu2osp_obj(struct lu_object *o)
203 {
204         LASSERT(ergo(o != NULL, lu_device_is_osp(o->lo_dev)));
205         return container_of0(o, struct osp_object, opo_obj.do_lu);
206 }
207
208 static inline struct lu_object *osp2lu_obj(struct osp_object *obj)
209 {
210         return &obj->opo_obj.do_lu;
211 }
212
213 static inline struct osp_object *osp_obj(const struct lu_object *o)
214 {
215         LASSERT(lu_device_is_osp(o->lo_dev));
216         return container_of0(o, struct osp_object, opo_obj.do_lu);
217 }
218
219 static inline struct osp_object *dt2osp_obj(const struct dt_object *d)
220 {
221         return osp_obj(&d->do_lu);
222 }
223
224 static inline struct dt_object *osp_object_child(struct osp_object *o)
225 {
226         return container_of0(lu_object_next(osp2lu_obj(o)),
227                              struct dt_object, do_lu);
228 }
229
230 /* osp_dev.c */
231 void osp_update_last_id(struct osp_device *d, obd_id objid);
232
233 /* osp_precreate.c */
234 int osp_init_precreate(struct osp_device *d);
235 int osp_precreate_reserve(const struct lu_env *env, struct osp_device *d);
236 __u64 osp_precreate_get_id(struct osp_device *d);
237 void osp_precreate_fini(struct osp_device *d);
238 int osp_object_truncate(const struct lu_env *env, struct dt_object *dt, __u64);
239 void osp_pre_update_status(struct osp_device *d, int rc);
240 void osp_statfs_need_now(struct osp_device *d);
241
242 /* lproc_osp.c */
243 void lprocfs_osp_init_vars(struct lprocfs_static_vars *lvars);
244
245 #endif