1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
39 * lustre/osd/osd_internal.h
41 * Shared definitions and declarations for osd module
43 * Author: Nikita Danilov <nikita@clusterfs.com>
46 #ifndef _OSD_INTERNAL_H
47 #define _OSD_INTERNAL_H
49 #if defined(__KERNEL__)
51 /* struct rw_semaphore */
52 #include <linux/rwsem.h>
54 #include <linux/dcache.h>
56 #include <linux/dirent.h>
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)
65 # define osd_journal_callback_set(handle, func, jcb) jbd2_journal_callback_set(handle, func, jcb)
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)
77 /* class_register_type(), class_unregister_type(), class_get_type() */
78 #include <obd_class.h>
79 #include <lustre_disk.h>
81 #include <dt_object.h>
87 #define OSD_OII_NOGEN (0)
88 #define OSD_COUNTERS (0)
90 /** Enable thandle usage statistics */
91 #define OSD_THANDLE_STATS (0)
93 #ifdef HAVE_QUOTA_SUPPORT
97 cfs_kernel_cap_t oc_cap;
106 struct dt_device od_dt_dev;
107 /* information about underlying file system */
108 struct lustre_mount_info *od_mount;
112 * XXX temporary stuff for object index: directory where every object
113 * is named by its fid.
115 struct dt_object *od_obj_area;
117 /* Environment for transaction commit callback.
118 * Currently, OSD is based on ext3/JBD. Transaction commit in ext3/JBD
119 * is serialized, that is there is no more than one transaction commit
120 * at a time (JBD journal_commit_transaction() is serialized).
121 * This means that it's enough to have _one_ lu_context.
123 struct lu_env od_env_for_commit;
128 unsigned int od_fl_capa:1;
129 unsigned long od_capa_timeout;
131 struct lustre_capa_key *od_capa_keys;
132 cfs_hlist_head_t *od_capa_hash;
134 cfs_proc_dir_entry_t *od_proc_entry;
135 struct lprocfs_stats *od_stats;
137 * statfs optimization: we cache a bit.
139 cfs_time_t od_osfs_age;
140 cfs_kstatfs_t od_kstatfs;
141 cfs_spinlock_t od_osfs_lock;
144 * The following flag indicates, if it is interop mode or not.
145 * It will be initialized, using mount param.
156 #if OSD_THANDLE_STATS
157 LPROC_OSD_THANDLE_STARTING,
158 LPROC_OSD_THANDLE_OPEN,
159 LPROC_OSD_THANDLE_CLOSING,
166 * Storage representation for fids.
168 * Variable size, first byte contains the length of the whole record.
170 struct osd_fid_pack {
171 unsigned char fp_len;
172 char fp_area[sizeof(struct lu_fid)];
175 struct osd_it_ea_dirent {
176 struct lu_fid oied_fid;
179 unsigned short oied_namelen;
180 unsigned int oied_type;
182 } __attribute__((packed));
185 * as osd_it_ea_dirent (in memory dirent struct for osd) is greater
186 * than lu_dirent struct. osd readdir reads less number of dirent than
187 * required for mdd dir page. so buffer size need to be increased so that
188 * there would be one ext3 readdir for every mdd readdir page.
191 #define OSD_IT_EA_BUFSIZE (CFS_PAGE_SIZE + CFS_PAGE_SIZE/4)
194 * This is iterator's in-memory data structure in interoperability
195 * mode (i.e. iterator over ldiskfs style directory)
198 struct osd_object *oie_obj;
199 /** used in ldiskfs iterator, to stored file pointer */
200 struct file oie_file;
201 /** how many entries have been read-cached from storage */
203 /** current entry is being iterated by caller */
205 /** current processing entry */
206 struct osd_it_ea_dirent *oie_dirent;
207 /** buffer to hold entries, size == OSD_IT_EA_BUFSIZE */
212 * Iterator's in-memory data structure for IAM mode.
215 struct osd_object *oi_obj;
216 struct iam_path_descr *oi_ipd;
217 struct iam_iterator oi_it;
220 struct osd_thread_info {
221 const struct lu_env *oti_env;
223 * used for index operations.
225 struct dentry oti_obj_dentry;
226 struct dentry oti_child_dentry;
228 /** dentry for Iterator context. */
229 struct dentry oti_it_dentry;
231 struct lu_fid oti_fid;
232 struct osd_inode_id oti_id;
234 * XXX temporary: for ->i_op calls.
236 struct txn_param oti_txn;
237 struct timespec oti_time;
239 * XXX temporary: fake struct file for osd_object_sync
241 struct file oti_file;
243 * XXX temporary: for capa operations.
245 struct lustre_capa_key oti_capa_key;
246 struct lustre_capa oti_capa;
248 /** osd_device reference, initialized in osd_trans_start() and
249 used in osd_trans_stop() */
250 struct osd_device *oti_dev;
253 * following ipd and it structures are used for osd_index_iam_lookup()
254 * these are defined separately as we might do index operation
255 * in open iterator session.
258 /** osd iterator context used for iterator session */
261 struct osd_it_iam oti_it;
262 /** ldiskfs iterator data structure, see osd_it_ea_{init, fini} */
263 struct osd_it_ea oti_it_ea;
266 /** pre-allocated buffer used by oti_it_ea, size OSD_IT_EA_BUFSIZE */
269 /** IAM iterator for index operation. */
270 struct iam_iterator oti_idx_it;
272 /** union to guarantee that ->oti_ipd[] has proper alignment. */
274 char oti_it_ipd[DX_IPD_MAX_SIZE];
275 long long oti_alignment_lieutenant;
279 char oti_idx_ipd[DX_IPD_MAX_SIZE];
280 long long oti_alignment_lieutenant_colonel;
287 /** used in osd_fid_set() to put xattr */
288 struct lu_buf oti_buf;
289 /** used in osd_ea_fid_set() to set fid into common ea */
290 struct lustre_mdt_attrs oti_mdt_attrs;
291 #ifdef HAVE_QUOTA_SUPPORT
292 struct osd_ctxt oti_ctxt;
294 struct lu_env oti_obj_delete_tx_env;
295 #define OSD_FID_REC_SZ 32
296 char oti_ldp[OSD_FID_REC_SZ];
297 char oti_ldp2[OSD_FID_REC_SZ];
302 void lprocfs_osd_init_vars(struct lprocfs_static_vars *lvars);
303 int osd_procfs_init(struct osd_device *osd, const char *name);
304 int osd_procfs_fini(struct osd_device *osd);
305 void osd_lprocfs_time_start(const struct lu_env *env);
306 void osd_lprocfs_time_end(const struct lu_env *env,
307 struct osd_device *osd, int op);
309 int osd_statfs(const struct lu_env *env, struct dt_device *dev,
313 * Invariants, assertions.
317 * XXX: do not enable this, until invariant checking code is made thread safe
318 * in the face of pdirops locking.
320 #define OSD_INVARIANT_CHECKS (0)
322 #if OSD_INVARIANT_CHECKS
323 static inline int osd_invariant(const struct osd_object *obj)
327 ergo(obj->oo_inode != NULL,
328 obj->oo_inode->i_sb == osd_sb(osd_obj2dev(obj)) &&
329 atomic_read(&obj->oo_inode->i_count) > 0) &&
330 ergo(obj->oo_dir != NULL &&
331 obj->oo_dir->od_conationer.ic_object != NULL,
332 obj->oo_dir->od_conationer.ic_object == obj->oo_inode);
335 #define osd_invariant(obj) (1)
338 /* The on-disk extN format reserves inodes 0-11 for internal filesystem
339 * use, and these inodes will be invisible on client side, so the valid
340 * sequence for IGIF fid is 12-0xffffffff. But root inode (2#) will be seen
341 * on server side (osd), and it should be valid too here.
343 #define OSD_ROOT_SEQ 2
344 static inline int osd_fid_is_root(const struct lu_fid *fid)
346 return fid_seq(fid) == OSD_ROOT_SEQ;
349 static inline int osd_fid_is_igif(const struct lu_fid *fid)
351 return fid_is_igif(fid) || osd_fid_is_root(fid);
354 #endif /* __KERNEL__ */
355 #endif /* _OSD_INTERNAL_H */