Whamcloud - gitweb
b3da83a73f195a1d9db4aa465275dca8f960a475
[fs/lustre-release.git] / lustre / osd / osd_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
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/osd/osd_internal.h
37  *
38  * Shared definitions and declarations for osd module
39  *
40  * Author: Nikita Danilov <nikita@clusterfs.com>
41  */
42
43 #ifndef _OSD_INTERNAL_H
44 #define _OSD_INTERNAL_H
45
46 #if defined(__KERNEL__)
47
48 /* struct rw_semaphore */
49 #include <linux/rwsem.h>
50 /* struct dentry */
51 #include <linux/dcache.h>
52 /* struct dirent64 */
53 #include <linux/dirent.h>
54
55 #ifdef HAVE_EXT4_LDISKFS
56 #include <ldiskfs/ldiskfs.h>
57 #include <ldiskfs/ldiskfs_jbd2.h>
58 #define osd_journal_callback_set(handle, func, jcb) jbd2_journal_callback_set(handle, func, jcb)
59 #else
60 #include <linux/jbd.h>
61 #include <linux/ldiskfs_fs.h>
62 #include <linux/ldiskfs_jbd.h>
63 #define osd_journal_callback_set(handle, func, jcb) journal_callback_set(handle, func, jcb)
64 #endif
65
66
67 /* LUSTRE_OSD_NAME */
68 #include <obd.h>
69 /* class_register_type(), class_unregister_type(), class_get_type() */
70 #include <obd_class.h>
71 #include <lustre_disk.h>
72
73 #include <dt_object.h>
74 #include "osd_oi.h"
75 #include "osd_iam.h"
76
77 struct inode;
78
79 #define OSD_OII_NOGEN (0)
80 #define OSD_COUNTERS (0)
81
82 #ifdef HAVE_QUOTA_SUPPORT
83 struct osd_ctxt {
84         __u32 oc_uid;
85         __u32 oc_gid;
86         __u32 oc_cap;
87 };
88 #endif
89
90 /*
91  * osd device.
92  */
93 struct osd_device {
94         /* super-class */
95         struct dt_device          od_dt_dev;
96         /* information about underlying file system */
97         struct lustre_mount_info *od_mount;
98         /* object index */
99         struct osd_oi             od_oi;
100         /*
101          * XXX temporary stuff for object index: directory where every object
102          * is named by its fid.
103          */
104         struct dt_object         *od_obj_area;
105
106         /* Environment for transaction commit callback.
107          * Currently, OSD is based on ext3/JBD. Transaction commit in ext3/JBD
108          * is serialized, that is there is no more than one transaction commit
109          * at a time (JBD journal_commit_transaction() is serialized).
110          * This means that it's enough to have _one_ lu_context.
111          */
112         struct lu_env             od_env_for_commit;
113
114         /*
115          * Fid Capability
116          */
117         unsigned int              od_fl_capa:1;
118         unsigned long             od_capa_timeout;
119         __u32                     od_capa_alg;
120         struct lustre_capa_key   *od_capa_keys;
121         cfs_hlist_head_t         *od_capa_hash;
122
123         cfs_proc_dir_entry_t     *od_proc_entry;
124         struct lprocfs_stats     *od_stats;
125         /*
126          * statfs optimization: we cache a bit.
127          */
128         cfs_time_t                od_osfs_age;
129         cfs_kstatfs_t             od_kstatfs;
130         cfs_spinlock_t            od_osfs_lock;
131
132         /**
133          * The following flag indicates, if it is interop mode or not.
134          * It will be initialized, using mount param.
135          */
136         __u32                     od_iop_mode;
137 };
138
139 /**
140  * Storage representation for fids.
141  *
142  * Variable size, first byte contains the length of the whole record.
143  */
144 struct osd_fid_pack {
145         unsigned char fp_len;
146         char fp_area[sizeof(struct lu_fid)];
147 };
148
149 struct osd_it_ea_dirent {
150         __u64           oied_ino;
151         __u64           oied_off;
152         unsigned short  oied_namelen;
153         unsigned int    oied_type;
154         char            oied_name[0];
155 } __attribute__((packed));
156
157 #define OSD_IT_EA_BUFSIZE       CFS_PAGE_SIZE
158
159 /**
160  * This is iterator's in-memory data structure in interoperability
161  * mode (i.e. iterator over ldiskfs style directory)
162  */
163 struct osd_it_ea {
164         struct osd_object   *oie_obj;
165         /** used in ldiskfs iterator, to stored file pointer */
166         struct file          oie_file;
167         /** how many entries have been read-cached from storage */
168         int                  oie_rd_dirent;
169         /** current entry is being iterated by caller */
170         int                  oie_it_dirent;
171         /** current processing entry */
172         struct osd_it_ea_dirent *oie_dirent;
173         /** buffer to hold entries, size == OSD_IT_EA_BUFSIZE */
174         void                *oie_buf;
175 };
176
177 /**
178  * Iterator's in-memory data structure for IAM mode.
179  */
180 struct osd_it_iam {
181         struct osd_object     *oi_obj;
182         struct iam_path_descr *oi_ipd;
183         struct iam_iterator    oi_it;
184 };
185
186 struct osd_thread_info {
187         const struct lu_env   *oti_env;
188         /**
189          * used for index operations.
190          */
191         struct dentry          oti_obj_dentry;
192         struct dentry          oti_child_dentry;
193
194         /** dentry for Iterator context. */
195         struct dentry          oti_it_dentry;
196
197         struct lu_fid          oti_fid;
198         struct osd_inode_id    oti_id;
199         /*
200          * XXX temporary: for ->i_op calls.
201          */
202         struct txn_param       oti_txn;
203         struct timespec        oti_time;
204         struct timespec        oti_time2;
205         /*
206          * XXX temporary: fake struct file for osd_object_sync
207          */
208         struct file            oti_file;
209         /*
210          * XXX temporary: for capa operations.
211          */
212         struct lustre_capa_key oti_capa_key;
213         struct lustre_capa     oti_capa;
214
215         /**
216          * following ipd and it structures are used for osd_index_iam_lookup()
217          * these are defined separately as we might do index operation
218          * in open iterator session.
219          */
220
221         /** osd iterator context used for iterator session */
222
223         union {
224                 struct osd_it_iam      oti_it;
225                 /** ldiskfs iterator data structure, see osd_it_ea_{init, fini} */
226                 struct osd_it_ea       oti_it_ea;
227         };
228
229         /** pre-allocated buffer used by oti_it_ea, size OSD_IT_EA_BUFSIZE */
230         void                  *oti_it_ea_buf;
231
232         /** IAM iterator for index operation. */
233         struct iam_iterator    oti_idx_it;
234
235         /** union to guarantee that ->oti_ipd[] has proper alignment. */
236         union {
237                 char           oti_it_ipd[DX_IPD_MAX_SIZE];
238                 long long      oti_alignment_lieutenant;
239         };
240
241         union {
242                 char           oti_idx_ipd[DX_IPD_MAX_SIZE];
243                 long long      oti_alignment_lieutenant_colonel;
244         };
245
246
247         int                    oti_r_locks;
248         int                    oti_w_locks;
249         int                    oti_txns;
250         /** used in osd_fid_set() to put xattr */
251         struct lu_buf          oti_buf;
252         /** used in osd_ea_fid_set() to set fid into common ea */
253         struct lustre_mdt_attrs oti_mdt_attrs;
254 #ifdef HAVE_QUOTA_SUPPORT
255         struct osd_ctxt        oti_ctxt;
256 #endif
257         struct lu_env          oti_obj_delete_tx_env;
258 #define OSD_FID_REC_SZ 32
259         char                   oti_fid_packed[OSD_FID_REC_SZ];
260 };
261
262 #ifdef LPROCFS
263 /* osd_lproc.c */
264 void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars);
265 int osd_procfs_init(struct osd_device *osd, const char *name);
266 int osd_procfs_fini(struct osd_device *osd);
267 void osd_lprocfs_time_start(const struct lu_env *env);
268 void osd_lprocfs_time_end(const struct lu_env *env,
269                           struct osd_device *osd, int op);
270 #endif
271 int osd_statfs(const struct lu_env *env, struct dt_device *dev,
272                cfs_kstatfs_t *sfs);
273
274 /*
275  * Invariants, assertions.
276  */
277
278 /*
279  * XXX: do not enable this, until invariant checking code is made thread safe
280  * in the face of pdirops locking.
281  */
282 #define OSD_INVARIANT_CHECKS (0)
283
284 #if OSD_INVARIANT_CHECKS
285 static inline int osd_invariant(const struct osd_object *obj)
286 {
287         return
288                 obj != NULL &&
289                 ergo(obj->oo_inode != NULL,
290                      obj->oo_inode->i_sb == osd_sb(osd_obj2dev(obj)) &&
291                      atomic_read(&obj->oo_inode->i_count) > 0) &&
292                 ergo(obj->oo_dir != NULL &&
293                      obj->oo_dir->od_conationer.ic_object != NULL,
294                      obj->oo_dir->od_conationer.ic_object == obj->oo_inode);
295 }
296 #else
297 #define osd_invariant(obj) (1)
298 #endif
299
300 #endif /* __KERNEL__ */
301 #endif /* _OSD_INTERNAL_H */