Whamcloud - gitweb
1)reorganize the smfs hook ops to make smfs walk a list of hooks ops in hook macro
[fs/lustre-release.git] / lustre / smfs / smfs_internal.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/smfs/smfs_internal.h
5  *  Lustre filesystem abstraction routines
6  *
7  *  Copyright (C) 2004 Cluster File Systems, Inc.
8  *
9  *   This file is part of Lustre, http://www.lustre.org.
10  *
11  *   Lustre is free software; you can redistribute it and/or
12  *   modify it under the terms of version 2 of the GNU General Public
13  *   License as published by the Free Software Foundation.
14  *
15  *   Lustre is distributed in the hope that it will be useful,
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *   GNU General Public License for more details.
19  *
20  *   You should have received a copy of the GNU General Public License
21  *   along with Lustre; if not, write to the Free Software
22  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24 #ifndef __LINUX_SMFS_H
25 #define __LINUX_SMFS_H
26
27 //#include <linux/lustre_fsfilt.h>
28 #define SMFSDEV_NAME "/dev/smfsconf"
29 #define SMFS_PSDEV_MINOR 250
30 #define SMFS_PSDEV_MAJOR 10
31
32 struct option {
33         char *opt;
34         char *value;
35         struct list_head list;
36 };
37
38 struct smfs_control_device {
39         struct list_head smfs_dev_list;
40 };
41
42 #define SMFS_TYPE                "smfs"
43 #define IOC_SMFS_START           _IOWR('s', 41, long)
44 #define IOC_SMFS_STOP            _IOWR('s', 42, long)
45 #define IOC_SMFS_REINT           _IOWR('s', 43, long)
46 #define IOC_SMFS_UNDO            _IOWR('s', 44, long)
47
48 #ifdef __KERNEL__
49
50 #define SB_OPS_CHECK             0x1
51 #define INODE_OPS_CHECK          0x2
52 #define FILE_OPS_CHECK           0x4
53 #define DENTRY_OPS_CHECK         0x8
54 #define DEV_OPS_CHECK            0x10
55 #define SYMLINK_OPS_CHECK        0x20
56 #define DIR_OPS_CHECK            0x40
57
58 #define KML_LOG_NAME "kml_rec"
59
60 #define MYPATHLEN(buffer, path) ((buffer) + PAGE_SIZE - (path))
61
62
63 #define PACK_KML_REC_INIT(buffer, op_code)          \
64 do{                                                 \
65         int opcode = op_code;                       \
66         memcpy(buffer, &opcode, sizeof(opcode));    \
67         buffer += sizeof(opcode);                   \
68 } while (0)
69
70
71 extern int init_smfs_proc_sys(void);
72 /*options.c*/
73 extern int get_opt(struct option **option, char **pos);
74 extern void cleanup_option(void);
75 extern int init_option(char *data);
76 /*cache.c*/
77 extern void sm_set_inode_ops(struct inode *cache_inode, struct inode *inode);
78 extern void sm_set_sb_ops(struct super_block *cache_sb, struct super_block *sb);
79 extern void init_smfs_cache(void);
80 extern void cleanup_smfs_cache(void);
81 extern void sm_set_journal_ops(struct super_block *sb, char *cache_type);
82 extern int smfs_init_sm_ops(struct smfs_super_info *smb);
83 extern void smfs_cleanup_sm_ops(struct smfs_super_info *smb);
84 static inline struct super_operations *cache_sops(struct smfs_super_info *smb)
85 {
86         return &smb->sm_ops->sm_sb_ops;
87 }
88 static inline struct inode_operations *cache_diops(struct smfs_super_info *smb)
89 {
90         return &smb->sm_ops->sm_dir_iops;
91 }
92 static inline struct inode_operations *cache_fiops(struct smfs_super_info *smb)
93 {
94         return &smb->sm_ops->sm_file_iops;
95 }
96 static inline struct inode_operations *cache_siops(struct smfs_super_info *smb)
97 {
98         return &smb->sm_ops->sm_sym_iops;
99 }
100 static inline struct file_operations *cache_dfops(struct smfs_super_info *smb)
101 {
102         return &smb->sm_ops->sm_dir_fops;
103 }
104 static inline struct file_operations *cache_ffops(struct smfs_super_info *smb)
105 {
106         return &smb->sm_ops->sm_file_fops;
107 }
108 static inline struct file_operations *cache_sfops(struct smfs_super_info *smb)
109 {
110         return &smb->sm_ops->sm_sym_fops;
111 }
112 static inline struct dentry_operations *cache_dops(struct smfs_super_info *smb)
113 {
114         return &smb->sm_ops->sm_dentry_ops;
115 }
116 static inline struct journal_operations *journal_ops(struct smfs_super_info *smb)
117 {
118         return &smb->sm_ops->sm_journal_ops;
119 }
120
121 struct smfs_hook_ops *smfs_alloc_hook_ops(char *name, 
122                                           smfs_hook_func pre_hook, 
123                                           smfs_hook_func post_hook);
124
125 void smfs_free_hook_ops(struct smfs_hook_ops *hops);
126 int smfs_register_hook_ops(struct super_block *sb, 
127                            struct smfs_hook_ops *smh_ops);
128
129 struct smfs_hook_ops *smfs_unregister_hook_ops(struct super_block *sb, 
130                                                char *name);
131 /*super.c*/
132 extern int init_smfs(void);
133 extern int cleanup_smfs(void);
134 extern void smfs_put_super(struct super_block *sb);
135 extern struct super_block *smfs_get_sb_by_path(char *path, int len);
136 /*sysctl.c*/
137 extern int sm_debug_level;
138 extern int sm_inodes;
139 extern long sm_kmemory;
140 extern int sm_stack;
141 /*dir.c*/
142 extern struct inode_operations smfs_dir_iops;
143 extern struct file_operations smfs_dir_fops;
144 /*file.c*/
145 extern struct inode_operations smfs_file_iops;
146 extern struct file_operations  smfs_file_fops;
147 extern int smfs_ioctl(struct inode * inode, struct file * filp,
148                       unsigned int cmd, unsigned long arg);
149 extern int smfs_fsync(struct file * file, struct dentry *dentry, int datasync);
150 extern int smfs_setattr(struct dentry *dentry, struct iattr *attr);
151 extern int smfs_setxattr(struct dentry *dentry, const char *name,
152                          const void *value, size_t size, int flags);
153 extern int smfs_getxattr(struct dentry *dentry, const char *name, void *buffer,
154                          size_t size);
155 extern ssize_t smfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
156 extern int smfs_removexattr(struct dentry *dentry, const char *name);
157 extern int smfs_open(struct inode * inode, struct file * filp);
158 extern int smfs_release(struct inode * inode, struct file * filp);
159 /*inode.c*/
160 extern struct super_operations smfs_super_ops;
161 /*symlink.c*/
162 extern struct inode_operations smfs_sym_iops;
163 extern struct file_operations smfs_sym_fops;
164 /*journal.c */
165 extern void *smfs_trans_start(struct inode *inode, int op, void *desc_private);
166 extern void smfs_trans_commit(struct inode *inode, void *handle,
167                               int force_sync);
168 extern int  smfs_post_kml_rec(struct inode *dir, struct dentry *dst_dentry,
169                               void   *data1, void *data2, int op);
170
171 extern int smfs_post_rec_write(struct inode *dir, struct dentry *dentry,
172                                void   *data1, void *data2);
173 extern int smfs_post_rec_setattr(struct inode *dir, struct dentry *dentry,
174                                  void   *data1, void *data2);
175 extern int smfs_post_rec_create(struct inode *dir, struct dentry *dentry,
176                                 void   *data1, void   *data2);
177 /*kml.c*/
178 extern int smfs_kml_init(struct super_block *sb);
179 extern int smfs_do_rec(struct inode *inode);
180 extern int smfs_rec_cleanup(struct super_block *sb);
181 extern int smfs_rec_init(struct super_block *sb);
182 extern int smfs_rec_unpack(struct smfs_proc_args *args, char *record,
183                            char **pbuf, int *opcode);
184 extern int smfs_process_rec(struct super_block *sb, int count,
185                             char *dir, int flags);
186 extern smfs_pack_rec_func smfs_get_rec_pack_type(struct super_block *sb);
187
188 extern int ost_rec_pack_init(struct super_block *sb);
189 /*ost_kml.c*/
190 extern int mds_rec_pack_init(struct super_block *sb);
191
192 /*smfs_llog.c*/
193 extern int smfs_llog_setup(struct super_block *sb, struct vfsmount *mnt);
194 extern int smfs_llog_cleanup(struct super_block *sb);
195 extern int smfs_llog_add_rec(struct smfs_super_info * sinfo, void *data,
196                              int data_size);
197 /*ioctl.c*/
198 extern int init_smfs_psdev(void);
199 extern void smfs_cleanup_psdev(void);
200 /*smfs_cow.c */
201
202 /* cache_space.c */
203 extern int do_cache_manage;
204 struct cache_purge_queue {
205         wait_queue_head_t       cpq_waitq;
206         struct super_block     *cpq_sb;
207         struct llog_handle     *cpq_loghandle;
208         __u32                   cpq_flags;
209         struct completion       cpq_comp;
210 };
211 /* opcodes */
212 #define CACHE_SPACE_INSERT 0x1
213 #define CACHE_SPACE_DELETE 0x2
214 #define CACHE_SPACE_COMMIT 0x4
215
216 #define CACHE_LRU_LOG "CACHE_LRU_LIST"
217
218 extern int smfs_cache_hook(struct inode *inode);
219 extern void cache_space_pre(struct inode *inode, int op);
220 extern int cache_space_post(int op, void *handle, struct inode *old_dir,
221                             struct dentry *old_dentry, struct inode *new_dir,
222                             struct dentry *new_dentry);
223
224 extern int cache_space_hook_setup(struct super_block *);
225 extern int cache_space_hook_cleanup(void);
226 extern int cache_space_hook_init(struct super_block *);
227 extern int cache_space_hook_exit(struct super_block *);
228
229 #define XATTR_SMFS_HOARD_MARK           "hoard"
230 #define XATTR_SMFS_CACHE_LOGCOOKIE      "cache"
231 #define XATTR_SMFS_ACTIVE_ENTRY         "entry"
232
233
234 static inline int set_hoard_priority(struct inode *inode, void *handle,
235                                      __u32 *hoard)
236 {
237         struct fsfilt_operations *fsops = I2CSB(inode)->sm_fsfilt;
238         int rc;
239
240         rc = fsops->fs_set_xattr(inode, handle, XATTR_SMFS_HOARD_MARK,
241                                  hoard, sizeof(__u32));
242         RETURN(rc);
243 }
244
245 static inline int get_hoard_priority(struct inode *inode, __u32 *hoard)
246 {
247         struct fsfilt_operations *fsops = I2CSB(inode)->sm_fsfilt;
248         int rc;
249
250         rc = fsops->fs_get_xattr(inode, XATTR_SMFS_HOARD_MARK,
251                                  hoard, sizeof(__u32));
252         RETURN(rc);
253 }
254
255 static inline int set_active_entry(struct inode *dir, __u64 *active_entry,
256                                    void *handle)
257 {
258         struct fsfilt_operations *fsops = I2CSB(dir)->sm_fsfilt;
259         int rc;
260         *active_entry = cpu_to_le64(*active_entry);
261         rc = fsops->fs_set_xattr(dir, handle, XATTR_SMFS_ACTIVE_ENTRY,
262                                  active_entry, sizeof(__u64));
263         RETURN(rc);
264 }
265 static inline int get_active_entry(struct inode *dir, __u64 *active_entry)
266 {
267         struct fsfilt_operations *fsops = I2CSB(dir)->sm_fsfilt;
268         int rc = fsops->fs_get_xattr(dir, XATTR_SMFS_ACTIVE_ENTRY,
269                                      active_entry, sizeof(__u64));
270         *active_entry = le64_to_cpu(*active_entry);
271         if (rc >= 0)
272                 rc = 0;
273         RETURN(rc);
274 }
275 #define HOOK_CREATE       1
276 #define HOOK_LOOKUP       2
277 #define HOOK_LINK         3
278 #define HOOK_UNLINK       4
279 #define HOOK_SYMLINK      5
280 #define HOOK_MKDIR        6
281 #define HOOK_RMDIR        7
282 #define HOOK_MKNOD        8
283 #define HOOK_RENAME       9
284 #define HOOK_SETATTR      10
285 #define HOOK_WRITE        11 
286 #define HOOK_MAX          11 
287
288 #define PRE_HOOK 0
289 #define POST_HOOK 1
290 #define SMFS_HOOK(inode, dentry, data1, data2, op, handle, flag, rc, label)    \
291 do {                                                                           \
292         LASSERT(inode->i_sb);                                                  \
293         if (!rc) {                                                             \
294                 struct smfs_super_info *smb = S2SMI(inode->i_sb);              \
295                 struct list_head *hlist = &smb->smsi_hook_list;                \
296                 struct list_head *p;                                           \
297                                                                                \
298                 list_for_each(p, hlist) {                                      \
299                         struct smfs_hook_ops *hops;                            \
300                                                                                \
301                         hops = list_entry(p, typeof(*hops), smh_list);         \
302                         if (flag == PRE_HOOK && hops->smh_pre_op)              \
303                                 rc = hops->smh_pre_op(inode, dentry, data1,    \
304                                                       data2, op, handle);      \
305                         else if (flag == POST_HOOK && hops->smh_post_op)       \
306                                 rc = hops->smh_post_op(inode, dentry, data1,   \
307                                                        data2, op, handle);     \
308                         if (rc)                                                \
309                                 break;                                         \
310                 }                                                              \
311         }                                                                      \
312         if (rc)                                                                \
313                 GOTO(label, rc);                                               \
314 } while(0)                                                                     \
315
316 #if CONFIG_SNAPFS
317 extern int smfs_cow_init(struct super_block *sb);
318 extern int smfs_cow_cleanup(struct super_block *sb);
319 extern int smfs_init_snap_inode_info(struct inode *inode, int flags);
320 #else
321 #define SMFS_PRE_COW(dir, dentry, new_dir, new_dentry, op, name, rc, label)                 
322 #endif 
323 #endif /*__KERNEL*/
324 #endif /* __LINUX_SMFS_H */