Whamcloud - gitweb
97b87be94837cac19c4ea4cbfd6123e607c77e3e
[fs/lustre-release.git] / lustre / osd-ldiskfs / 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 (c) 2007, 2010, Oracle and/or its affiliates. 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 /** Enable thandle usage statistics */
83 #define OSD_THANDLE_STATS (0)
84
85 #ifdef HAVE_QUOTA_SUPPORT
86 struct osd_ctxt {
87         __u32 oc_uid;
88         __u32 oc_gid;
89         cfs_kernel_cap_t oc_cap;
90 };
91 #endif
92
93 /*
94  * osd device.
95  */
96 struct osd_device {
97         /* super-class */
98         struct dt_device          od_dt_dev;
99         /* information about underlying file system */
100         struct lustre_mount_info *od_mount;
101         /* object index */
102         struct osd_oi             od_oi;
103         /*
104          * XXX temporary stuff for object index: directory where every object
105          * is named by its fid.
106          */
107         struct dt_object         *od_obj_area;
108
109         /* Environment for transaction commit callback.
110          * Currently, OSD is based on ext3/JBD. Transaction commit in ext3/JBD
111          * is serialized, that is there is no more than one transaction commit
112          * at a time (JBD journal_commit_transaction() is serialized).
113          * This means that it's enough to have _one_ lu_context.
114          */
115         struct lu_env             od_env_for_commit;
116
117         /*
118          * Fid Capability
119          */
120         unsigned int              od_fl_capa:1;
121         unsigned long             od_capa_timeout;
122         __u32                     od_capa_alg;
123         struct lustre_capa_key   *od_capa_keys;
124         cfs_hlist_head_t         *od_capa_hash;
125
126         cfs_proc_dir_entry_t     *od_proc_entry;
127         struct lprocfs_stats     *od_stats;
128         /*
129          * statfs optimization: we cache a bit.
130          */
131         cfs_time_t                od_osfs_age;
132         cfs_kstatfs_t             od_kstatfs;
133         cfs_spinlock_t            od_osfs_lock;
134
135         /**
136          * The following flag indicates, if it is interop mode or not.
137          * It will be initialized, using mount param.
138          */
139         __u32                     od_iop_mode;
140 };
141
142 /*
143  * osd dev stats
144  */
145
146 #ifdef LPROCFS
147 enum {
148 #if OSD_THANDLE_STATS
149         LPROC_OSD_THANDLE_STARTING,
150         LPROC_OSD_THANDLE_OPEN,
151         LPROC_OSD_THANDLE_CLOSING,
152 #endif
153         LPROC_OSD_NR
154 };
155 #endif
156
157 /**
158  * Storage representation for fids.
159  *
160  * Variable size, first byte contains the length of the whole record.
161  */
162 struct osd_fid_pack {
163         unsigned char fp_len;
164         char fp_area[sizeof(struct lu_fid)];
165 };
166
167 struct osd_it_ea_dirent {
168         struct lu_fid   oied_fid;
169         __u64           oied_ino;
170         __u64           oied_off;
171         unsigned short  oied_namelen;
172         unsigned int    oied_type;
173         char            oied_name[0];
174 } __attribute__((packed));
175
176 /**
177  * as osd_it_ea_dirent (in memory dirent struct for osd) is greater
178  * than lu_dirent struct. osd readdir reads less number of dirent than
179  * required for mdd dir page. so buffer size need to be increased so that
180  * there  would be one ext3 readdir for every mdd readdir page.
181  */
182
183 #define OSD_IT_EA_BUFSIZE       (CFS_PAGE_SIZE + CFS_PAGE_SIZE/4)
184
185 /**
186  * This is iterator's in-memory data structure in interoperability
187  * mode (i.e. iterator over ldiskfs style directory)
188  */
189 struct osd_it_ea {
190         struct osd_object   *oie_obj;
191         /** used in ldiskfs iterator, to stored file pointer */
192         struct file          oie_file;
193         /** how many entries have been read-cached from storage */
194         int                  oie_rd_dirent;
195         /** current entry is being iterated by caller */
196         int                  oie_it_dirent;
197         /** current processing entry */
198         struct osd_it_ea_dirent *oie_dirent;
199         /** buffer to hold entries, size == OSD_IT_EA_BUFSIZE */
200         void                *oie_buf;
201 };
202
203 /**
204  * Iterator's in-memory data structure for IAM mode.
205  */
206 struct osd_it_iam {
207         struct osd_object     *oi_obj;
208         struct iam_path_descr *oi_ipd;
209         struct iam_iterator    oi_it;
210 };
211
212 struct osd_thread_info {
213         const struct lu_env   *oti_env;
214         /**
215          * used for index operations.
216          */
217         struct dentry          oti_obj_dentry;
218         struct dentry          oti_child_dentry;
219
220         /** dentry for Iterator context. */
221         struct dentry          oti_it_dentry;
222
223         struct lu_fid          oti_fid;
224         struct osd_inode_id    oti_id;
225         /*
226          * XXX temporary: for ->i_op calls.
227          */
228         struct txn_param       oti_txn;
229         struct timespec        oti_time;
230         struct timespec        oti_time2;
231         /*
232          * XXX temporary: fake struct file for osd_object_sync
233          */
234         struct file            oti_file;
235         /*
236          * XXX temporary: for capa operations.
237          */
238         struct lustre_capa_key oti_capa_key;
239         struct lustre_capa     oti_capa;
240
241         /** osd_device reference, initialized in osd_trans_start() and
242             used in osd_trans_stop() */
243         struct osd_device     *oti_dev;
244
245         /**
246          * following ipd and it structures are used for osd_index_iam_lookup()
247          * these are defined separately as we might do index operation
248          * in open iterator session.
249          */
250
251         /** osd iterator context used for iterator session */
252
253         union {
254                 struct osd_it_iam      oti_it;
255                 /** ldiskfs iterator data structure, see osd_it_ea_{init, fini} */
256                 struct osd_it_ea       oti_it_ea;
257         };
258
259         /** pre-allocated buffer used by oti_it_ea, size OSD_IT_EA_BUFSIZE */
260         void                  *oti_it_ea_buf;
261
262         /** IAM iterator for index operation. */
263         struct iam_iterator    oti_idx_it;
264
265         /** union to guarantee that ->oti_ipd[] has proper alignment. */
266         union {
267                 char           oti_it_ipd[DX_IPD_MAX_SIZE];
268                 long long      oti_alignment_lieutenant;
269         };
270
271         union {
272                 char           oti_idx_ipd[DX_IPD_MAX_SIZE];
273                 long long      oti_alignment_lieutenant_colonel;
274         };
275
276
277         int                    oti_r_locks;
278         int                    oti_w_locks;
279         int                    oti_txns;
280         /** used in osd_fid_set() to put xattr */
281         struct lu_buf          oti_buf;
282         /** used in osd_ea_fid_set() to set fid into common ea */
283         struct lustre_mdt_attrs oti_mdt_attrs;
284 #ifdef HAVE_QUOTA_SUPPORT
285         struct osd_ctxt        oti_ctxt;
286 #endif
287         struct lu_env          oti_obj_delete_tx_env;
288 #define OSD_FID_REC_SZ 32
289         char                   oti_ldp[OSD_FID_REC_SZ];
290         char                   oti_ldp2[OSD_FID_REC_SZ];
291 };
292
293 #ifdef LPROCFS
294 /* osd_lproc.c */
295 void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars);
296 int osd_procfs_init(struct osd_device *osd, const char *name);
297 int osd_procfs_fini(struct osd_device *osd);
298 void osd_lprocfs_time_start(const struct lu_env *env);
299 void osd_lprocfs_time_end(const struct lu_env *env,
300                           struct osd_device *osd, int op);
301 #endif
302 int osd_statfs(const struct lu_env *env, struct dt_device *dev,
303                cfs_kstatfs_t *sfs);
304
305 /*
306  * Invariants, assertions.
307  */
308
309 /*
310  * XXX: do not enable this, until invariant checking code is made thread safe
311  * in the face of pdirops locking.
312  */
313 #define OSD_INVARIANT_CHECKS (0)
314
315 #if OSD_INVARIANT_CHECKS
316 static inline int osd_invariant(const struct osd_object *obj)
317 {
318         return
319                 obj != NULL &&
320                 ergo(obj->oo_inode != NULL,
321                      obj->oo_inode->i_sb == osd_sb(osd_obj2dev(obj)) &&
322                      atomic_read(&obj->oo_inode->i_count) > 0) &&
323                 ergo(obj->oo_dir != NULL &&
324                      obj->oo_dir->od_conationer.ic_object != NULL,
325                      obj->oo_dir->od_conationer.ic_object == obj->oo_inode);
326 }
327 #else
328 #define osd_invariant(obj) (1)
329 #endif
330
331 /* The on-disk extN format reserves inodes 0-11 for internal filesystem
332  * use, and these inodes will be invisible on client side, so the valid
333  * sequence for IGIF fid is 12-0xffffffff. But root inode (2#) will be seen
334  * on server side (osd), and it should be valid too here.
335  */
336 #define OSD_ROOT_SEQ            2
337 static inline int osd_fid_is_root(const struct lu_fid *fid)
338 {
339         return fid_seq(fid) == OSD_ROOT_SEQ;
340 }
341
342 static inline int osd_fid_is_igif(const struct lu_fid *fid)
343 {
344         return fid_is_igif(fid) || osd_fid_is_root(fid);
345 }
346
347 #endif /* __KERNEL__ */
348 #endif /* _OSD_INTERNAL_H */