Whamcloud - gitweb
b=16098
[fs/lustre-release.git] / lustre / obdfilter / filter_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
37 #ifndef _FILTER_INTERNAL_H
38 #define _FILTER_INTERNAL_H
39
40 #ifdef __KERNEL__
41 # include <linux/spinlock.h>
42 #endif
43 #include <lustre_disk.h>
44 #include <lustre_handles.h>
45 #include <lustre_debug.h>
46 #include <obd.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 GRANT_FOR_LLOG(obd) 16
63
64 extern struct file_operations filter_per_export_stats_fops;
65 extern struct file_operations filter_per_nid_stats_fops;
66
67 /* Limit the returned fields marked valid to those that we actually might set */
68 #define FILTER_VALID_FLAGS (OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLGENER  |\
69                             OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ|\
70                             OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME)
71
72 struct filter_fid {
73         struct ll_fid   ff_fid;         /* ff_fid.f_type == file stripe number */
74         __u64           ff_objid;
75         __u64           ff_group;
76 };
77
78 /* per-client-per-object persistent state (LRU) */
79 struct filter_mod_data {
80         struct list_head fmd_list;      /* linked to fed_mod_list */
81         __u64            fmd_id;        /* object being written to */
82         __u64            fmd_gr;        /* group being written to */
83         __u64            fmd_mactime_xid;/* xid highest {m,a,c}time setattr */
84         unsigned long    fmd_expire;    /* jiffies when it should expire */
85         int              fmd_refcount;  /* reference counter - list holds 1 */
86 };
87
88 #ifdef HAVE_BGL_SUPPORT
89 #define FILTER_FMD_MAX_NUM_DEFAULT 128 /* many active files per client on BGL */
90 #else
91 #define FILTER_FMD_MAX_NUM_DEFAULT  32
92 #endif
93 /* Client cache seconds */
94 #define FILTER_FMD_MAX_AGE_DEFAULT ((obd_timeout + 10) * HZ)
95
96 struct filter_mod_data *filter_fmd_find(struct obd_export *exp,
97                                         obd_id objid, obd_gr group);
98 struct filter_mod_data *filter_fmd_get(struct obd_export *exp,
99                                        obd_id objid, obd_gr group);
100 void filter_fmd_put(struct obd_export *exp, struct filter_mod_data *fmd);
101 void filter_fmd_expire(struct obd_export *exp);
102
103 enum {
104         LPROC_FILTER_READ_BYTES = 0,
105         LPROC_FILTER_WRITE_BYTES = 1,
106         LPROC_FILTER_LAST,
107 };
108
109 //#define FILTER_MAX_CACHE_SIZE (32 * 1024 * 1024) /* was OBD_OBJECT_EOF */
110 #define FILTER_MAX_CACHE_SIZE OBD_OBJECT_EOF
111
112 /* We have to pass a 'created' array to fsfilt_map_inode_pages() which we
113  * then ignore.  So we pre-allocate one that everyone can use... */
114 #define OBDFILTER_CREATED_SCRATCHPAD_ENTRIES 1024
115 extern int *obdfilter_created_scratchpad;
116
117 extern void target_recovery_fini(struct obd_device *obd);
118 extern void target_recovery_init(struct obd_device *obd,
119                                  svc_handler_t handler);
120
121 /* filter.c */
122 void f_dput(struct dentry *);
123 struct dentry *filter_fid2dentry(struct obd_device *, struct dentry *dir,
124                                  obd_gr group, obd_id id);
125 struct dentry *__filter_oa2dentry(struct obd_device *obd, struct obdo *oa,
126                                   const char *what, int quiet);
127 #define filter_oa2dentry(obd, oa) __filter_oa2dentry(obd, oa, __FUNCTION__, 0)
128
129 int filter_finish_transno(struct obd_export *, struct obd_trans_info *, int rc,
130                           int force_sync);
131 __u64 filter_next_id(struct filter_obd *, struct obdo *);
132 __u64 filter_last_id(struct filter_obd *, obd_gr group);
133 int filter_update_fidea(struct obd_export *exp, struct inode *inode,
134                         void *handle, struct obdo *oa);
135 int filter_update_server_data(struct obd_device *, struct file *,
136                               struct lr_server_data *, int force_sync);
137 int filter_update_last_objid(struct obd_device *, obd_gr, int force_sync);
138 int filter_common_setup(struct obd_device *, struct lustre_cfg *lcfg,
139                         void *option);
140 int filter_destroy(struct obd_export *exp, struct obdo *oa,
141                    struct lov_stripe_md *md, struct obd_trans_info *,
142                    struct obd_export *);
143 int filter_setattr_internal(struct obd_export *exp, struct dentry *dentry,
144                             struct obdo *oa, struct obd_trans_info *oti);
145 int filter_setattr(struct obd_export *exp, struct obd_info *oinfo,
146                    struct obd_trans_info *oti);
147
148 struct dentry *filter_create_object(struct obd_device *obd, struct obdo *oa);
149
150 struct obd_llog_group *filter_find_olg(struct obd_device *obd, int group);
151
152 /* filter_lvb.c */
153 extern struct ldlm_valblock_ops filter_lvbo;
154
155
156 /* filter_io.c */
157 int filter_preprw(int cmd, struct obd_export *, struct obdo *, int objcount,
158                   struct obd_ioobj *, int niocount, struct niobuf_remote *,
159                   struct niobuf_local *, struct obd_trans_info *,
160                   struct lustre_capa *);
161 int filter_commitrw(int cmd, struct obd_export *, struct obdo *, int objcount,
162                     struct obd_ioobj *, int niocount, struct niobuf_local *,
163                     struct obd_trans_info *, int rc);
164 int filter_brw(int cmd, struct obd_export *, struct obd_info *oinfo,
165                obd_count oa_bufs, struct brw_page *pga, struct obd_trans_info *);
166 void flip_into_page_cache(struct inode *inode, struct page *new_page);
167
168 /* filter_io_*.c */
169 struct filter_iobuf;
170 int filter_commitrw_write(struct obd_export *exp, struct obdo *oa, int objcount,
171                           struct obd_ioobj *obj, int niocount,
172                           struct niobuf_local *res, struct obd_trans_info *oti,
173                           int rc);
174 obd_size filter_grant_space_left(struct obd_export *exp);
175 long filter_grant(struct obd_export *exp, obd_size current_grant,
176                   obd_size want, obd_size fs_space_left);
177 void filter_grant_commit(struct obd_export *exp, int niocount,
178                          struct niobuf_local *res);
179 struct filter_iobuf *filter_alloc_iobuf(struct filter_obd *, int rw,
180                                         int num_pages);
181 void filter_free_iobuf(struct filter_iobuf *iobuf);
182 int filter_iobuf_add_page(struct obd_device *obd, struct filter_iobuf *iobuf,
183                           struct inode *inode, struct page *page);
184 void *filter_iobuf_get(struct filter_obd *filter, struct obd_trans_info *oti);
185 void filter_iobuf_put(struct filter_obd *filter, struct filter_iobuf *iobuf,
186                       struct obd_trans_info *oti);
187 int filter_direct_io(int rw, struct dentry *dchild, struct filter_iobuf *iobuf,
188                      struct obd_export *exp, struct iattr *attr,
189                      struct obd_trans_info *oti, void **wait_handle);
190 int filter_clear_truncated_page(struct inode *inode);
191
192 /* filter_log.c */
193 struct ost_filterdata {
194         __u32  ofd_epoch;
195 };
196 int filter_log_sz_change(struct llog_handle *cathandle,
197                          struct ll_fid *mds_fid,
198                          __u32 ioepoch,
199                          struct llog_cookie *logcookie,
200                          struct inode *inode);
201 //int filter_get_catalog(struct obd_device *);
202 void filter_cancel_cookies_cb(struct obd_device *obd, __u64 transno,
203                               void *cb_data, int error);
204 int filter_recov_log_mds_ost_cb(struct llog_handle *llh,
205                                struct llog_rec_hdr *rec, void *data);
206
207 #ifdef LPROCFS
208 void filter_tally(struct obd_export *exp, struct page **pages, int nr_pages,
209                   unsigned long *blocks, int blocks_per_page, int wr);
210 int lproc_filter_attach_seqstat(struct obd_device *dev);
211 void lprocfs_filter_init_vars(struct lprocfs_static_vars *lvars);
212 #else
213 static inline void filter_tally(struct obd_export *exp, struct page **pages,
214                                 int nr_pages, unsigned long *blocks,
215                                 int blocks_per_page, int wr) {}
216 static inline int lproc_filter_attach_seqstat(struct obd_device *dev) {}
217 static void lprocfs_filter_init_vars(struct lprocfs_static_vars *lvars)
218 {
219         memset(lvars, 0, sizeof(*lvars));
220 }
221 #endif
222
223 /* Quota stuff */
224 extern quota_interface_t *filter_quota_interface_ref;
225
226 /* Capability */
227 static inline __u64 obdo_mdsno(struct obdo *oa)
228 {
229         return oa->o_gr - FILTER_GROUP_MDS0;
230 }
231
232 int filter_update_capa_key(struct obd_device *obd, struct lustre_capa_key *key);
233 int filter_auth_capa(struct obd_export *exp, struct lu_fid *fid, __u64 mdsid,
234                      struct lustre_capa *capa, __u64 opc);
235 void filter_free_capa_keys(struct filter_obd *filter);
236
237 void blacklist_add(uid_t uid);
238 void blacklist_del(uid_t uid);
239 int blacklist_display(char *buf, int bufsize);
240
241 #endif /* _FILTER_INTERNAL_H */