Whamcloud - gitweb
- CROW (CReate On Write) (precreation is removed)
[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  * Copyright (C) 2003 Cluster File Systems, Inc.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  */
9
10 #ifndef _FILTER_INTERNAL_H
11 #define _FILTER_INTERNAL_H
12
13 #ifdef __KERNEL__
14 # include <linux/spinlock.h>
15 #endif
16 #include <linux/lustre_handles.h>
17 #include <linux/obd.h>
18
19 #ifndef OBD_FILTER_DEVICENAME
20 # define OBD_FILTER_DEVICENAME "obdfilter"
21 #endif
22
23 #ifndef OBD_FILTER_SAN_DEVICENAME
24 # define OBD_FILTER_SAN_DEVICENAME "sanobdfilter"
25 #endif
26
27 #define LAST_RCVD "last_rcvd"
28 #define FILTER_INIT_OBJID 0
29
30 #define FILTER_LR_SERVER_SIZE    512
31
32 #define FILTER_LR_CLIENT_START   8192
33 #define FILTER_LR_CLIENT_SIZE    128
34
35 /* This limit is arbitrary, but for now we fit it in 1 page (32k clients) */
36 #define FILTER_LR_MAX_CLIENTS (PAGE_SIZE * 8)
37
38 #define FILTER_RECOVERY_TIMEOUT (obd_timeout * 5 * HZ / 2) /* *waves hands* */
39
40 #define FILTER_ROCOMPAT_SUPP   (0)
41
42 #define FILTER_INCOMPAT_GROUPS 0x00000001
43 #define FILTER_INCOMPAT_SUPP   (FILTER_INCOMPAT_GROUPS)
44
45 #define FILTER_GRANT_CHUNK (2ULL*1024*1024)
46
47 /* Data stored per server at the head of the last_rcvd file.  In le32 order.
48  * Try to keep this the same as mds_server_data so we might one day merge. */
49 struct filter_server_data {
50         __u8  fsd_uuid[40];        /* server UUID */
51         __u64 fsd_unused;          /* was fsd_last_objid - don't use for now */
52         __u64 fsd_last_transno;    /* last completed transaction ID */
53         __u64 fsd_mount_count;     /* FILTER incarnation number */
54         __u32 fsd_feature_compat;  /* compatible feature flags */
55         __u32 fsd_feature_rocompat;/* read-only compatible feature flags */
56         __u32 fsd_feature_incompat;/* incompatible feature flags */
57         __u32 fsd_server_size;     /* size of server data area */
58         __u32 fsd_client_start;    /* start of per-client data area */
59         __u16 fsd_client_size;     /* size of per-client data area */
60         __u16 fsd_subdir_count;    /* number of subdirectories for objects */
61         __u64 fsd_catalog_oid;     /* recovery catalog object id */
62         __u32 fsd_catalog_ogen;    /* recovery catalog inode generation */
63         __u8  fsd_peeruuid[40];    /* UUID of MDS associated with this OST */
64         __u8  fsd_padding[FILTER_LR_SERVER_SIZE - 140];
65 };
66
67 /* Data stored per client in the last_rcvd file.  In le32 order. */
68 struct filter_client_data {
69         __u8  fcd_uuid[40];        /* client UUID */
70         __u64 fcd_last_rcvd;       /* last completed transaction ID */
71         __u64 fcd_last_xid;        /* client RPC xid for the last transaction */
72         __u32 fcd_group;           /* client group num*/
73         __u8  fcd_padding[FILTER_LR_CLIENT_SIZE - 60];
74 };
75
76 #define FILTER_DENTRY_MAGIC 0x9efba101
77 #define FILTER_FLAG_DESTROY 0x0001      /* destroy dentry on last file close */
78
79 /* Limit the returned fields marked valid to those that we actually might set */
80 #define FILTER_VALID_FLAGS (OBD_MD_FLTYPE | OBD_MD_FLMODE | OBD_MD_FLGENER  |\
81                             OBD_MD_FLSIZE | OBD_MD_FLBLOCKS | OBD_MD_FLBLKSZ|\
82                             OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME)
83
84 enum {
85         LPROC_FILTER_READ_BYTES = 0,
86         LPROC_FILTER_WRITE_BYTES = 1,
87         LPROC_FILTER_LAST,
88 };
89
90 #define FILTER_MAX_CACHE_SIZE (32 * 1024 * 1024) /* was OBD_OBJECT_EOF */
91
92 /* We have to pass a 'created' array to fsfilt_map_inode_pages() which we
93  * then ignore.  So we pre-allocate one that everyone can use... */
94 #define OBDFILTER_CREATED_SCRATCHPAD_ENTRIES 1024
95 extern int *obdfilter_created_scratchpad;
96
97 /* filter.c */
98 void f_dput(struct dentry *);
99 struct dentry *filter_id2dentry(struct obd_device *, struct dentry *dir,
100                                 obd_gr group, obd_id id);
101 struct dentry *__filter_oa2dentry(struct obd_device *obd, struct obdo *oa,
102                                   const char *what);
103 #define filter_oa2dentry(obd, oa) __filter_oa2dentry(obd, oa, __FUNCTION__)
104
105 int filter_finish_transno(struct obd_export *, struct obd_trans_info *, int rc);
106 __u64 filter_next_id(struct filter_obd *, int group);
107 __u64 filter_last_id(struct filter_obd *, int group);
108 int filter_update_server_data(struct obd_device *, struct file *,
109                               struct filter_server_data *, int force_sync);
110 int filter_update_last_objid(struct obd_device *, obd_gr, int force_sync);
111 int filter_common_setup(struct obd_device *, obd_count len, void *buf,
112                         char *option);
113
114 struct dentry *filter_crow_object(struct obd_device *obd, __u64 ogr,
115                                   __u64 oid);
116
117 int filter_setattr_internal(struct obd_export *exp, struct dentry *dentry,
118                             struct obdo *oa, struct obd_trans_info *oti);
119
120 int filter_setattr(struct obd_export *exp, struct obdo *oa,
121                    struct lov_stripe_md *md, struct obd_trans_info *oti);
122
123 int filter_create_object(struct obd_device *obd, struct obdo *oa,
124                          obd_gr group);
125
126 /* filter_lvb.c */
127 extern struct ldlm_valblock_ops filter_lvbo;
128
129
130 /* filter_io.c */
131 int filter_preprw(int cmd, struct obd_export *, struct obdo *, int objcount,
132                   struct obd_ioobj *, int niocount, struct niobuf_remote *,
133                   struct niobuf_local *, struct obd_trans_info *);
134 int filter_commitrw(int cmd, struct obd_export *, struct obdo *, int objcount,
135                     struct obd_ioobj *, int niocount, struct niobuf_local *,
136                     struct obd_trans_info *, int rc);
137 int filter_write_extents(struct obd_export *exp, struct obd_ioobj *obj,
138                          int objcount, int niocount,struct niobuf_local *local, 
139                          int rc);
140 int filter_do_cow(struct obd_export *exp, struct obd_ioobj *obj,
141                   int nioo, struct niobuf_remote *rnb);
142 int filter_brw(int cmd, struct obd_export *, struct obdo *,
143                struct lov_stripe_md *, obd_count oa_bufs, struct brw_page *,
144                struct obd_trans_info *);
145 void flip_into_page_cache(struct inode *inode, struct page *new_page);
146
147 void filter_free_dio_pages(int objcount, struct obd_ioobj *obj,
148                            int niocount, struct niobuf_local *res);
149
150 /* filter_io_*.c */
151 int filter_commitrw_write(struct obd_export *exp, struct obdo *oa, int objcount,
152                           struct obd_ioobj *obj, int niocount,
153                           struct niobuf_local *res, struct obd_trans_info *oti,
154                           int rc);
155 obd_size filter_grant_space_left(struct obd_export *exp);
156 long filter_grant(struct obd_export *exp, obd_size current_grant,
157                   obd_size want, obd_size fs_space_left);
158 void filter_grant_commit(struct obd_export *exp, int niocount,
159                          struct niobuf_local *res);
160
161 int filter_alloc_iobuf(int rw, int num_pages, void **ret);
162 void filter_free_iobuf(void *iobuf);
163 int filter_iobuf_add_page(struct obd_device *obd, void *iobuf,
164                           struct inode *inode, struct page *page);
165 int filter_direct_io(int rw, struct dentry *dchild, void *iobuf,
166                      struct obd_export *exp, struct iattr *attr,
167                      struct obd_trans_info *oti, void **wait_handle);
168
169 /* filter_log.c */
170 struct ost_filterdata {
171         __u32  ofd_epoch;
172 };
173
174 int filter_log_sz_change(struct llog_handle *cathandle,
175                          struct lustre_id *id, __u32 io_epoch,
176                          struct llog_cookie *logcookie,
177                          struct inode *inode);
178 //int filter_get_catalog(struct obd_device *);
179 void filter_cancel_cookies_cb(struct obd_device *obd, __u64 transno,
180                               void *cb_data, int error);
181 int filter_recov_log_unlink_cb(struct llog_handle *llh,
182                                struct llog_rec_hdr *rec, void *data);
183
184 /* filter_san.c */
185 int filter_san_setup(struct obd_device *obd, obd_count len, void *buf);
186 int filter_san_preprw(int cmd, struct obd_export *, struct obdo *, int objcount,
187                       struct obd_ioobj *, int niocount, struct niobuf_remote *);
188
189 #ifdef __KERNEL__
190 void filter_tally_write(struct filter_obd *filter, struct page **pages,
191                         int nr_pages, unsigned long *blocks, 
192                         int blocks_per_page);
193 void filter_tally_read(struct filter_obd *filter, struct niobuf_local *lnb, 
194                        int niocount);
195 int lproc_filter_attach_seqstat(struct obd_device *dev);
196 #else
197 static inline filter_tally_write(struct filter_obd *filter, 
198                                  struct page **pages, int nr_pages, 
199                                  unsigned long *blocks, int blocks_per_page) {}
200 static inline void  filter_tally_read(struct filter_obd *filter, 
201                                       struct niobuf_local *lnb, int niocount)
202                                       {}
203 static inline lproc_filter_attach_seqstat(struct obd_device *dev) {}
204 #endif
205
206
207 #endif