Whamcloud - gitweb
LU-822 osd: use bitmask to calculate seq hash
[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  * Copyright (c) 2011 Whamcloud, Inc.
34  */
35 /*
36  * This file is part of Lustre, http://www.lustre.org/
37  * Lustre is a trademark of Sun Microsystems, Inc.
38  *
39  * lustre/osd/osd_internal.h
40  *
41  * Shared definitions and declarations for osd module
42  *
43  * Author: Nikita Danilov <nikita@clusterfs.com>
44  */
45
46 #ifndef _OSD_INTERNAL_H
47 #define _OSD_INTERNAL_H
48
49 #if defined(__KERNEL__)
50
51 /* struct rw_semaphore */
52 #include <linux/rwsem.h>
53 /* struct dentry */
54 #include <linux/dcache.h>
55 /* struct dirent64 */
56 #include <linux/dirent.h>
57
58 #ifdef HAVE_EXT4_LDISKFS
59 #include <ldiskfs/ldiskfs.h>
60 #include <ldiskfs/ldiskfs_jbd2.h>
61 # ifdef HAVE_LDISKFS_JOURNAL_CALLBACK_ADD
62 #  define journal_callback ldiskfs_journal_cb_entry
63 #  define osd_journal_callback_set(handle, func, jcb) ldiskfs_journal_callback_add(handle, func, jcb)
64 # else
65 #  define osd_journal_callback_set(handle, func, jcb) jbd2_journal_callback_set(handle, func, jcb)
66 # endif
67 #else
68 #include <linux/jbd.h>
69 #include <linux/ldiskfs_fs.h>
70 #include <linux/ldiskfs_jbd.h>
71 #define osd_journal_callback_set(handle, func, jcb) journal_callback_set(handle, func, jcb)
72 #endif
73
74
75 /* LUSTRE_OSD_NAME */
76 #include <obd.h>
77 /* class_register_type(), class_unregister_type(), class_get_type() */
78 #include <obd_class.h>
79 #include <lustre_disk.h>
80
81 #include <dt_object.h>
82 #include "osd_oi.h"
83 #include "osd_iam.h"
84
85 struct inode;
86
87 #define OSD_OII_NOGEN (0)
88 #define OSD_COUNTERS (0)
89
90 /** Enable thandle usage statistics */
91 #define OSD_THANDLE_STATS (0)
92
93 #ifdef HAVE_QUOTA_SUPPORT
94 struct osd_ctxt {
95         __u32 oc_uid;
96         __u32 oc_gid;
97         cfs_kernel_cap_t oc_cap;
98 };
99 #endif
100
101 #ifdef HAVE_LDISKFS_PDO
102
103 #define osd_ldiskfs_find_entry(dir, dentry, de, lock)   \
104         ll_ldiskfs_find_entry(dir, dentry, de, lock)
105 #define osd_ldiskfs_add_entry(handle, child, cinode, hlock) \
106         ldiskfs_add_entry(handle, child, cinode, hlock)
107
108 #else /* HAVE_LDISKFS_PDO */
109
110 struct htree_lock {
111         int     dummy;
112 };
113
114 struct htree_lock_head {
115         int     dummy;
116 };
117
118 #define ldiskfs_htree_lock(lock, head, inode, op)  do { LBUG(); } while (0)
119 #define ldiskfs_htree_unlock(lock)                 do { LBUG(); } while (0)
120
121 static inline struct htree_lock_head *ldiskfs_htree_lock_head_alloc(int dep)
122 {
123         LBUG();
124         return NULL;
125 }
126
127 #define ldiskfs_htree_lock_head_free(lh)           do { LBUG(); } while (0)
128
129 #define LDISKFS_DUMMY_HTREE_LOCK        0xbabecafe
130
131 static inline struct htree_lock *ldiskfs_htree_lock_alloc(void)
132 {
133         return (struct htree_lock *)LDISKFS_DUMMY_HTREE_LOCK;
134 }
135
136 static inline void ldiskfs_htree_lock_free(struct htree_lock *lk)
137 {
138         LASSERT((unsigned long)lk == LDISKFS_DUMMY_HTREE_LOCK);
139 }
140
141 #define HTREE_HBITS_DEF         0
142
143 #define osd_ldiskfs_find_entry(dir, dentry, de, lock)   \
144         ll_ldiskfs_find_entry(dir, dentry, de)
145 #define osd_ldiskfs_add_entry(handle, child, cinode, lock) \
146         ldiskfs_add_entry(handle, child, cinode)
147
148 #endif /* HAVE_LDISKFS_PDO */
149
150 /*
151  * osd device.
152  */
153 struct osd_device {
154         /* super-class */
155         struct dt_device          od_dt_dev;
156         /* information about underlying file system */
157         struct lustre_mount_info *od_mount;
158         /*
159          * XXX temporary stuff for object index: directory where every object
160          * is named by its fid.
161          */
162         struct dt_object         *od_obj_area;
163         /* object index */
164         struct osd_oi            *od_oi_table;
165         /* total number of OI containers */
166         int                       od_oi_count;
167         /*
168          * Fid Capability
169          */
170         unsigned int              od_fl_capa:1;
171         unsigned long             od_capa_timeout;
172         __u32                     od_capa_alg;
173         struct lustre_capa_key   *od_capa_keys;
174         cfs_hlist_head_t         *od_capa_hash;
175
176         cfs_proc_dir_entry_t     *od_proc_entry;
177         struct lprocfs_stats     *od_stats;
178         /*
179          * statfs optimization: we cache a bit.
180          */
181         cfs_time_t                od_osfs_age;
182         cfs_kstatfs_t             od_kstatfs;
183         cfs_spinlock_t            od_osfs_lock;
184
185         /**
186          * The following flag indicates, if it is interop mode or not.
187          * It will be initialized, using mount param.
188          */
189         __u32                     od_iop_mode;
190 };
191
192 /*
193  * osd dev stats
194  */
195
196 #ifdef LPROCFS
197 enum {
198 #if OSD_THANDLE_STATS
199         LPROC_OSD_THANDLE_STARTING,
200         LPROC_OSD_THANDLE_OPEN,
201         LPROC_OSD_THANDLE_CLOSING,
202 #endif
203         LPROC_OSD_NR
204 };
205 #endif
206
207 /**
208  * Storage representation for fids.
209  *
210  * Variable size, first byte contains the length of the whole record.
211  */
212 struct osd_fid_pack {
213         unsigned char fp_len;
214         char fp_area[sizeof(struct lu_fid)];
215 };
216
217 struct osd_it_ea_dirent {
218         struct lu_fid   oied_fid;
219         __u64           oied_ino;
220         __u64           oied_off;
221         unsigned short  oied_namelen;
222         unsigned int    oied_type;
223         char            oied_name[0];
224 } __attribute__((packed));
225
226 /**
227  * as osd_it_ea_dirent (in memory dirent struct for osd) is greater
228  * than lu_dirent struct. osd readdir reads less number of dirent than
229  * required for mdd dir page. so buffer size need to be increased so that
230  * there  would be one ext3 readdir for every mdd readdir page.
231  */
232
233 #define OSD_IT_EA_BUFSIZE       (CFS_PAGE_SIZE + CFS_PAGE_SIZE/4)
234
235 /**
236  * This is iterator's in-memory data structure in interoperability
237  * mode (i.e. iterator over ldiskfs style directory)
238  */
239 struct osd_it_ea {
240         struct osd_object   *oie_obj;
241         /** used in ldiskfs iterator, to stored file pointer */
242         struct file          oie_file;
243         /** how many entries have been read-cached from storage */
244         int                  oie_rd_dirent;
245         /** current entry is being iterated by caller */
246         int                  oie_it_dirent;
247         /** current processing entry */
248         struct osd_it_ea_dirent *oie_dirent;
249         /** buffer to hold entries, size == OSD_IT_EA_BUFSIZE */
250         void                *oie_buf;
251 };
252
253 /**
254  * Iterator's in-memory data structure for IAM mode.
255  */
256 struct osd_it_iam {
257         struct osd_object     *oi_obj;
258         struct iam_path_descr *oi_ipd;
259         struct iam_iterator    oi_it;
260 };
261
262 struct osd_thread_info {
263         const struct lu_env   *oti_env;
264         /**
265          * used for index operations.
266          */
267         struct dentry          oti_obj_dentry;
268         struct dentry          oti_child_dentry;
269
270         /** dentry for Iterator context. */
271         struct dentry          oti_it_dentry;
272         struct htree_lock     *oti_hlock;
273
274         struct lu_fid          oti_fid;
275         struct osd_inode_id    oti_id;
276         /*
277          * XXX temporary: for ->i_op calls.
278          */
279         struct timespec        oti_time;
280         /*
281          * XXX temporary: fake struct file for osd_object_sync
282          */
283         struct file            oti_file;
284         /*
285          * XXX temporary: for capa operations.
286          */
287         struct lustre_capa_key oti_capa_key;
288         struct lustre_capa     oti_capa;
289
290         /** osd_device reference, initialized in osd_trans_start() and
291             used in osd_trans_stop() */
292         struct osd_device     *oti_dev;
293
294         /**
295          * following ipd and it structures are used for osd_index_iam_lookup()
296          * these are defined separately as we might do index operation
297          * in open iterator session.
298          */
299
300         /** osd iterator context used for iterator session */
301
302         union {
303                 struct osd_it_iam      oti_it;
304                 /** ldiskfs iterator data structure, see osd_it_ea_{init, fini} */
305                 struct osd_it_ea       oti_it_ea;
306         };
307
308         /** pre-allocated buffer used by oti_it_ea, size OSD_IT_EA_BUFSIZE */
309         void                  *oti_it_ea_buf;
310
311         /** IAM iterator for index operation. */
312         struct iam_iterator    oti_idx_it;
313
314         /** union to guarantee that ->oti_ipd[] has proper alignment. */
315         union {
316                 char           oti_it_ipd[DX_IPD_MAX_SIZE];
317                 long long      oti_alignment_lieutenant;
318         };
319
320         union {
321                 char           oti_idx_ipd[DX_IPD_MAX_SIZE];
322                 long long      oti_alignment_lieutenant_colonel;
323         };
324
325
326         int                    oti_r_locks;
327         int                    oti_w_locks;
328         int                    oti_txns;
329         /** used in osd_fid_set() to put xattr */
330         struct lu_buf          oti_buf;
331         /** used in osd_ea_fid_set() to set fid into common ea */
332         struct lustre_mdt_attrs oti_mdt_attrs;
333 #ifdef HAVE_QUOTA_SUPPORT
334         struct osd_ctxt        oti_ctxt;
335 #endif
336         struct lu_env          oti_obj_delete_tx_env;
337 #define OSD_FID_REC_SZ 32
338         char                   oti_ldp[OSD_FID_REC_SZ];
339         char                   oti_ldp2[OSD_FID_REC_SZ];
340 };
341
342 extern int ldiskfs_pdo;
343
344 #ifdef LPROCFS
345 /* osd_lproc.c */
346 void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars);
347 int osd_procfs_init(struct osd_device *osd, const char *name);
348 int osd_procfs_fini(struct osd_device *osd);
349 void osd_lprocfs_time_start(const struct lu_env *env);
350 void osd_lprocfs_time_end(const struct lu_env *env,
351                           struct osd_device *osd, int op);
352 #endif
353 int osd_statfs(const struct lu_env *env, struct dt_device *dev,
354                cfs_kstatfs_t *sfs);
355
356 /*
357  * Invariants, assertions.
358  */
359
360 /*
361  * XXX: do not enable this, until invariant checking code is made thread safe
362  * in the face of pdirops locking.
363  */
364 #define OSD_INVARIANT_CHECKS (0)
365
366 #if OSD_INVARIANT_CHECKS
367 static inline int osd_invariant(const struct osd_object *obj)
368 {
369         return
370                 obj != NULL &&
371                 ergo(obj->oo_inode != NULL,
372                      obj->oo_inode->i_sb == osd_sb(osd_obj2dev(obj)) &&
373                      atomic_read(&obj->oo_inode->i_count) > 0) &&
374                 ergo(obj->oo_dir != NULL &&
375                      obj->oo_dir->od_conationer.ic_object != NULL,
376                      obj->oo_dir->od_conationer.ic_object == obj->oo_inode);
377 }
378 #else
379 #define osd_invariant(obj) (1)
380 #endif
381
382 /* The on-disk extN format reserves inodes 0-11 for internal filesystem
383  * use, and these inodes will be invisible on client side, so the valid
384  * sequence for IGIF fid is 12-0xffffffff. But root inode (2#) will be seen
385  * on server side (osd), and it should be valid too here.
386  */
387 #define OSD_ROOT_SEQ            2
388 static inline int osd_fid_is_root(const struct lu_fid *fid)
389 {
390         return fid_seq(fid) == OSD_ROOT_SEQ;
391 }
392
393 static inline int osd_fid_is_igif(const struct lu_fid *fid)
394 {
395         return fid_is_igif(fid) || osd_fid_is_root(fid);
396 }
397
398 static inline struct osd_oi *
399 osd_fid2oi(struct osd_device *osd, const struct lu_fid *fid)
400 {
401         if (!fid_is_norm(fid))
402                 return NULL;
403
404         LASSERT(osd->od_oi_table != NULL && osd->od_oi_count >= 1);
405         /* It can work even od_oi_count equals to 1 although it's unexpected,
406          * the only reason we set it to 1 is for performance measurement */
407         return &osd->od_oi_table[fid->f_seq & (osd->od_oi_count - 1)];
408 }
409
410 #endif /* __KERNEL__ */
411 #endif /* _OSD_INTERNAL_H */