Whamcloud - gitweb
b=18504
[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 /* handle_t, journal_start(), journal_stop() */
51 #include <linux/jbd.h>
52 /* struct dx_hash_info */
53 #include <linux/ldiskfs_fs.h>
54 /* struct dentry */
55 #include <linux/dcache.h>
56 /* struct dirent64 */
57 #include <linux/dirent.h>
58
59 /* LUSTRE_OSD_NAME */
60 #include <obd.h>
61 /* class_register_type(), class_unregister_type(), class_get_type() */
62 #include <obd_class.h>
63 #include <lustre_disk.h>
64
65 #include <dt_object.h>
66 #include "osd_oi.h"
67 #include "osd_iam.h"
68
69 struct inode;
70
71 #define OSD_OII_NOGEN (0)
72 #define OSD_COUNTERS (0)
73
74 #ifdef HAVE_QUOTA_SUPPORT
75 struct osd_ctxt {
76         __u32 oc_uid;
77         __u32 oc_gid;
78         __u32 oc_cap;
79 };
80 #endif
81
82 /*
83  * osd device.
84  */
85 struct osd_device {
86         /* super-class */
87         struct dt_device          od_dt_dev;
88         /* information about underlying file system */
89         struct lustre_mount_info *od_mount;
90         /* object index */
91         struct osd_oi             od_oi;
92         /*
93          * XXX temporary stuff for object index: directory where every object
94          * is named by its fid.
95          */
96         struct dt_object         *od_obj_area;
97
98         /* Environment for transaction commit callback.
99          * Currently, OSD is based on ext3/JBD. Transaction commit in ext3/JBD
100          * is serialized, that is there is no more than one transaction commit
101          * at a time (JBD journal_commit_transaction() is serialized).
102          * This means that it's enough to have _one_ lu_context.
103          */
104         struct lu_env             od_env_for_commit;
105
106         /*
107          * Fid Capability
108          */
109         unsigned int              od_fl_capa:1;
110         unsigned long             od_capa_timeout;
111         __u32                     od_capa_alg;
112         struct lustre_capa_key   *od_capa_keys;
113         struct hlist_head        *od_capa_hash;
114
115         cfs_proc_dir_entry_t     *od_proc_entry;
116         struct lprocfs_stats     *od_stats;
117         /*
118          * statfs optimization: we cache a bit.
119          */
120         cfs_time_t                od_osfs_age;
121         struct kstatfs            od_kstatfs;
122         spinlock_t                od_osfs_lock;
123
124         /**
125          * The following flag indicates, if it is interop mode or not.
126          * It will be initialized, using mount param.
127          */
128         __u32                     od_iop_mode;
129 };
130
131 struct osd_it_ea_dirent {
132         __u64           oied_ino;
133         __u64           oied_off;
134         unsigned short  oied_namelen;
135         unsigned int    oied_type;
136         char            oied_name[0];
137 } __attribute__((packed));
138
139 #define OSD_IT_EA_BUFSIZE       CFS_PAGE_SIZE
140
141 /**
142  * This is iterator's in-memory data structure in interoperability
143  * mode (i.e. iterator over ldiskfs style directory)
144  */
145 struct osd_it_ea {
146         struct osd_object   *oie_obj;
147         /** used in ldiskfs iterator, to stored file pointer */
148         struct file          oie_file;
149         /** how many entries have been read-cached from storage */
150         int                  oie_rd_dirent;
151         /** current entry is being iterated by caller */
152         int                  oie_it_dirent;
153         /** current processing entry */
154         struct osd_it_ea_dirent *oie_dirent;
155         /** buffer to hold entries, size == OSD_IT_EA_BUFSIZE */
156         void                *oie_buf;
157 };
158
159 /**
160  * Iterator's in-memory data structure for IAM mode.
161  */
162 struct osd_it_iam {
163         struct osd_object     *oi_obj;
164         struct iam_path_descr *oi_ipd;
165         struct iam_iterator    oi_it;
166 };
167
168 struct osd_thread_info {
169         const struct lu_env   *oti_env;
170         /**
171          * used for index operations.
172          */
173         struct dentry          oti_obj_dentry;
174         struct dentry          oti_child_dentry;
175
176         /** dentry for Iterator context. */
177         struct dentry          oti_it_dentry;
178
179         struct lu_fid          oti_fid;
180         struct osd_inode_id    oti_id;
181         /*
182          * XXX temporary: for ->i_op calls.
183          */
184         struct txn_param       oti_txn;
185         struct timespec        oti_time;
186         struct timespec        oti_time2;
187         /*
188          * XXX temporary: fake struct file for osd_object_sync
189          */
190         struct file            oti_file;
191         /*
192          * XXX temporary: for capa operations.
193          */
194         struct lustre_capa_key oti_capa_key;
195         struct lustre_capa     oti_capa;
196
197         struct lu_fid_pack     oti_pack;
198
199         /**
200          * following ipd and it structures are used for osd_index_iam_lookup()
201          * these are defined separately as we might do index operation
202          * in open iterator session.
203          */
204
205         /** osd iterator context used for iterator session */
206
207         union {
208                 struct osd_it_iam      oti_it;
209                 /** ldiskfs iterator data structure, see osd_it_ea_{init, fini} */
210                 struct osd_it_ea       oti_it_ea;
211         };
212
213         /** pre-allocated buffer used by oti_it_ea, size OSD_IT_EA_BUFSIZE */
214         void                  *oti_it_ea_buf;
215
216         /** IAM iterator for index operation. */
217         struct iam_iterator    oti_idx_it;
218
219         /** union to guarantee that ->oti_ipd[] has proper alignment. */
220         union {
221                 char           oti_it_ipd[DX_IPD_MAX_SIZE];
222                 long long      oti_alignment_lieutenant;
223         };
224
225         union {
226                 char           oti_idx_ipd[DX_IPD_MAX_SIZE];
227                 long long      oti_alignment_lieutenant_colonel;
228         };
229
230
231         int                    oti_r_locks;
232         int                    oti_w_locks;
233         int                    oti_txns;
234         /** used in osd_fid_set() to put xattr */
235         struct lu_buf          oti_buf;
236         /** used in osd_ea_fid_set() to set fid into common ea */
237         struct lustre_mdt_attrs oti_mdt_attrs;
238 #ifdef HAVE_QUOTA_SUPPORT
239         struct osd_ctxt        oti_ctxt;
240 #endif
241         struct lu_env          oti_obj_delete_tx_env;
242 };
243
244 #ifdef LPROCFS
245 /* osd_lproc.c */
246 void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars);
247 int osd_procfs_init(struct osd_device *osd, const char *name);
248 int osd_procfs_fini(struct osd_device *osd);
249 void osd_lprocfs_time_start(const struct lu_env *env);
250 void osd_lprocfs_time_end(const struct lu_env *env,
251                           struct osd_device *osd, int op);
252 #endif
253 int osd_statfs(const struct lu_env *env, struct dt_device *dev,
254                struct kstatfs *sfs);
255
256 /*
257  * Invariants, assertions.
258  */
259
260 /*
261  * XXX: do not enable this, until invariant checking code is made thread safe
262  * in the face of pdirops locking.
263  */
264 #define OSD_INVARIANT_CHECKS (0)
265
266 #if OSD_INVARIANT_CHECKS
267 static inline int osd_invariant(const struct osd_object *obj)
268 {
269         return
270                 obj != NULL &&
271                 ergo(obj->oo_inode != NULL,
272                      obj->oo_inode->i_sb == osd_sb(osd_obj2dev(obj)) &&
273                      atomic_read(&obj->oo_inode->i_count) > 0) &&
274                 ergo(obj->oo_dir != NULL &&
275                      obj->oo_dir->od_conationer.ic_object != NULL,
276                      obj->oo_dir->od_conationer.ic_object == obj->oo_inode);
277 }
278 #else
279 #define osd_invariant(obj) (1)
280 #endif
281
282 #endif /* __KERNEL__ */
283 #endif /* _OSD_INTERNAL_H */