Whamcloud - gitweb
27c41a021bc33bdd0bc08f8cd9cc8d57be1a1970
[fs/lustre-release.git] / lustre / obdfilter / filter_internal.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, Whamcloud, Inc.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #ifndef _FILTER_INTERNAL_H
38 #define _FILTER_INTERNAL_H
39
40 #ifdef __KERNEL__
41 # include <linux/spinlock.h>
42 #endif
43 #include <lustre_handles.h>
44 #include <lustre_debug.h>
45 #include <obd.h>
46 #include <obd_class.h>
47 #include <lprocfs_status.h>
48
49 #define FILTER_LAYOUT_VERSION "2"
50
51 #define FILTER_INIT_OBJID 0
52
53 #define FILTER_SUBDIR_COUNT 32 /* set to zero for no subdirs */
54 #define FILTER_GROUPS        3 /* must be at least 3; not dynamic yet */
55
56 #define FILTER_ROCOMPAT_SUPP (0)
57
58 #define FILTER_INCOMPAT_SUPP (OBD_INCOMPAT_GROUPS | OBD_INCOMPAT_OST | \
59                               OBD_INCOMPAT_COMMON_LR)
60
61 #define FILTER_GRANT_CHUNK (2ULL * PTLRPC_MAX_BRW_SIZE)
62 #define FILTER_GRANT_SHRINK_LIMIT (16ULL * FILTER_GRANT_CHUNK)
63 #define GRANT_FOR_LLOG(obd) 16
64
65 extern struct file_operations filter_per_export_stats_fops;
66 extern struct file_operations filter_per_nid_stats_fops;
67
68 /* Limit the returned fields marked valid to those that we actually might set */
69 #define FILTER_VALID_FLAGS (OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLGENER  |\
70                             OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ|\
71                             OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME)
72
73 /* per-client-per-object persistent state (LRU) */
74 struct filter_mod_data {
75         cfs_list_t       fmd_list;       /* linked to fed_mod_list */
76         __u64            fmd_id;         /* object being written to */
77         __u64            fmd_gr;         /* group being written to */
78         __u64            fmd_mactime_xid;/* xid highest {m,a,c}time
79                                               * setattr */
80         unsigned long    fmd_expire;   /* jiffies when it should expire */
81         int              fmd_refcount; /* reference counter, list holds 1 */
82 };
83
84 #ifdef HAVE_BGL_SUPPORT
85 #define FILTER_FMD_MAX_NUM_DEFAULT 128 /* many active files per client on BGL */
86 #else
87 #define FILTER_FMD_MAX_NUM_DEFAULT  32
88 #endif
89 /* Client cache seconds */
90 #define FILTER_FMD_MAX_AGE_DEFAULT ((obd_timeout + 10) * CFS_HZ)
91
92 #ifndef HAVE_PAGE_CONSTANT
93 #define mapping_cap_page_constant_write(mapping) 0
94 #define SetPageConstant(page) do {} while (0)
95 #define ClearPageConstant(page) do {} while (0)
96 #endif
97
98 struct filter_mod_data *filter_fmd_find(struct obd_export *exp,
99                                         obd_id objid, obd_seq seq);
100 struct filter_mod_data *filter_fmd_get(struct obd_export *exp,
101                                        obd_id objid, obd_seq seq);
102 void filter_fmd_put(struct obd_export *exp, struct filter_mod_data *fmd);
103 void filter_fmd_expire(struct obd_export *exp);
104
105 enum {
106         LPROC_FILTER_READ_BYTES = 0,
107         LPROC_FILTER_WRITE_BYTES = 1,
108         LPROC_FILTER_GET_PAGE = 2,
109         LPROC_FILTER_NO_PAGE = 3,
110         LPROC_FILTER_CACHE_ACCESS = 4,
111         LPROC_FILTER_CACHE_HIT = 5,
112         LPROC_FILTER_CACHE_MISS = 6,
113         LPROC_FILTER_LAST,
114 };
115
116 //#define FILTER_MAX_CACHE_SIZE (32 * 1024 * 1024) /* was OBD_OBJECT_EOF */
117 #define FILTER_MAX_CACHE_SIZE OBD_OBJECT_EOF
118
119 /* We have to pass a 'created' array to fsfilt_map_inode_pages() which we
120  * then ignore.  So we pre-allocate one that everyone can use... */
121 #define OBDFILTER_CREATED_SCRATCHPAD_ENTRIES 1024
122 extern int *obdfilter_created_scratchpad;
123
124 extern void target_recovery_fini(struct obd_device *obd);
125 extern void target_recovery_init(struct lu_target *lut,
126                                  svc_handler_t handler);
127
128 /* filter.c */
129 void f_dput(struct dentry *);
130 struct dentry *filter_fid2dentry(struct obd_device *, struct dentry *dir,
131                                  obd_seq seq, obd_id id);
132 struct dentry *__filter_oa2dentry(struct obd_device *obd, struct ost_id *ostid,
133                                   const char *what, int quiet);
134 #define filter_oa2dentry(obd, ostid) __filter_oa2dentry(obd, ostid,     \
135                                                         __func__, 0)
136
137 int filter_finish_transno(struct obd_export *, struct inode *,
138                           struct obd_trans_info *, int rc, int force_sync);
139 __u64 filter_next_id(struct filter_obd *, struct obdo *);
140 __u64 filter_last_id(struct filter_obd *, obd_seq seq);
141 int filter_update_fidea(struct obd_export *exp, struct inode *inode,
142                         void *handle, struct obdo *oa);
143 int filter_update_server_data(struct obd_device *);
144 int filter_update_last_objid(struct obd_device *, obd_seq, int force_sync);
145 int filter_common_setup(struct obd_device *, struct lustre_cfg *lcfg,
146                         void *option);
147 int filter_destroy(const struct lu_env *env, struct obd_export *exp,
148                    struct obdo *oa, struct lov_stripe_md *md,
149                    struct obd_trans_info *, struct obd_export *, void *);
150 int filter_setattr_internal(struct obd_export *exp, struct dentry *dentry,
151                             struct obdo *oa, struct obd_trans_info *oti);
152 int filter_setattr(const struct lu_env *env, struct obd_export *exp,
153                    struct obd_info *oinfo, struct obd_trans_info *oti);
154
155 int filter_create(const struct lu_env *env, struct obd_export *exp,
156                   struct obdo *oa, struct lov_stripe_md **ea,
157                   struct obd_trans_info *oti);
158
159 struct obd_llog_group *filter_find_olg(struct obd_device *obd, int seq);
160
161 /* filter_lvb.c */
162 extern struct ldlm_valblock_ops filter_lvbo;
163
164
165 /* filter_io.c */
166 int filter_preprw(const struct lu_env *env, int cmd, struct obd_export *,
167                   struct obdo *, int objcount,
168                   struct obd_ioobj *, struct niobuf_remote *,
169                   int *, struct niobuf_local *, struct obd_trans_info *,
170                   struct lustre_capa *);
171 int filter_commitrw(const struct lu_env *, int cmd, struct obd_export *,
172                     struct obdo *, int objcount,
173                     struct obd_ioobj *, struct niobuf_remote *,  int,
174                     struct niobuf_local *, struct obd_trans_info *, int rc);
175 void filter_release_cache(struct obd_device *, struct obd_ioobj *,
176                           struct niobuf_remote *, struct inode *);
177
178 /* filter_io_*.c */
179 struct filter_iobuf;
180 int filter_commitrw_write(struct obd_export *exp, struct obdo *oa, int objcount,
181                           struct obd_ioobj *obj, struct niobuf_remote *, int,
182                           struct niobuf_local *res, struct obd_trans_info *oti,
183                           int rc);
184 obd_size filter_grant_space_left(struct obd_export *exp);
185 long filter_grant(struct obd_export *exp, obd_size current_grant,
186                   obd_size want, obd_size fs_space_left, int conservative);
187 void filter_grant_commit(struct obd_export *exp, int niocount,
188                          struct niobuf_local *res);
189 void filter_grant_incoming(struct obd_export *exp, struct obdo *oa);
190 struct filter_iobuf *filter_alloc_iobuf(struct filter_obd *, int rw,
191                                         int num_pages);
192 void filter_free_iobuf(struct filter_iobuf *iobuf);
193 int filter_iobuf_add_page(struct obd_device *obd, struct filter_iobuf *iobuf,
194                           struct inode *inode, struct page *page);
195 void *filter_iobuf_get(struct filter_obd *filter, struct obd_trans_info *oti);
196 void filter_iobuf_put(struct filter_obd *filter, struct filter_iobuf *iobuf,
197                       struct obd_trans_info *oti);
198 int filter_direct_io(int rw, struct dentry *dchild, struct filter_iobuf *iobuf,
199                      struct obd_export *exp, struct iattr *attr,
200                      struct obd_trans_info *oti, void **wait_handle);
201 int filter_clear_truncated_page(struct inode *inode);
202
203 /* filter_log.c */
204 struct ost_filterdata {
205         __u32  ofd_epoch;
206 };
207 int filter_log_sz_change(struct llog_handle *cathandle,
208                          struct ll_fid *mds_fid,
209                          __u32 ioepoch,
210                          struct llog_cookie *logcookie,
211                          struct inode *inode);
212 //int filter_get_catalog(struct obd_device *);
213 void filter_cancel_cookies_cb(struct obd_device *obd, __u64 transno,
214                               void *cb_data, int error);
215 int filter_recov_log_mds_ost_cb(struct llog_handle *llh,
216                                struct llog_rec_hdr *rec, void *data);
217
218 #ifdef LPROCFS
219 void filter_tally(struct obd_export *exp, struct page **pages, int nr_pages,
220                   unsigned long *blocks, int blocks_per_page, int wr);
221 int lproc_filter_attach_seqstat(struct obd_device *dev);
222 void lprocfs_filter_init_vars(struct lprocfs_static_vars *lvars);
223 #else
224 static inline void filter_tally(struct obd_export *exp, struct page **pages,
225                                 int nr_pages, unsigned long *blocks,
226                                 int blocks_per_page, int wr) {}
227 static inline int lproc_filter_attach_seqstat(struct obd_device *dev) {}
228 static void lprocfs_filter_init_vars(struct lprocfs_static_vars *lvars)
229 {
230         memset(lvars, 0, sizeof(*lvars));
231 }
232 #endif
233
234 /* Quota stuff */
235 extern quota_interface_t *filter_quota_interface_ref;
236
237 int filter_update_capa_key(struct obd_device *obd, struct lustre_capa_key *key);
238 int filter_auth_capa(struct obd_export *exp, struct lu_fid *fid, obd_seq seq,
239                      struct lustre_capa *capa, __u64 opc);
240 int filter_capa_fixoa(struct obd_export *exp, struct obdo *oa, obd_seq seq,
241                       struct lustre_capa *capa);
242 void filter_free_capa_keys(struct filter_obd *filter);
243
244 void blacklist_add(uid_t uid);
245 void blacklist_del(uid_t uid);
246 int blacklist_display(char *buf, int bufsize);
247
248 /* sync on lock cancel is useless when we force a journal flush,
249  * and if we enable async journal commit, we should also turn on
250  * sync on lock cancel if it is not enabled already. */
251 static inline void filter_slc_set(struct filter_obd *filter)
252 {
253         if (filter->fo_syncjournal == 1)
254                 filter->fo_sync_lock_cancel = NEVER_SYNC_ON_CANCEL;
255         else if (filter->fo_sync_lock_cancel == NEVER_SYNC_ON_CANCEL)
256                 filter->fo_sync_lock_cancel = ALWAYS_SYNC_ON_CANCEL;
257 }
258
259 #endif /* _FILTER_INTERNAL_H */