Whamcloud - gitweb
Small fix on the description of some lctl commands.
[fs/lustre-release.git] / lustre / smfs / smfs_internal.h
1 #ifndef __LINUX_SMFS_H
2 #define __LINUX_SMFS_H
3
4 #include <linux/lustre_fsfilt.h>
5 #define SMFSDEV_NAME "/dev/smfsconf"
6 #define SMFS_PSDEV_MINOR 250
7 #define SMFS_PSDEV_MAJOR 10
8
9 struct option {
10         char *opt;
11         char *value;
12         struct list_head list;
13 };
14
15 struct smfs_control_device {
16         struct list_head smfs_dev_list;
17 };
18
19 #define SMFS_TYPE                "smfs"
20 #define IOC_SMFS_START           _IOWR('s', 41, long)
21 #define IOC_SMFS_STOP            _IOWR('s', 42, long)
22 #define IOC_SMFS_REINT           _IOWR('s', 43, long)
23 #define IOC_SMFS_UNDO            _IOWR('s', 44, long)
24
25 #ifdef __KERNEL__
26
27 struct smfs_proc_args {
28         struct super_block *sr_sb;
29         int                 sr_count;
30         int                 sr_flags;
31         void               *sr_data;
32 };
33
34
35 #define SB_OPS_CHECK            0x1
36 #define INODE_OPS_CHECK         0x2
37 #define FILE_OPS_CHECK          0x4
38 #define DENTRY_OPS_CHECK        0x8
39 #define DEV_OPS_CHECK           0x10
40 #define SYMLINK_OPS_CHECK       0x20
41 #define DIR_OPS_CHECK           0x40
42
43 #define KML_LOG_NAME "kml_rec"
44
45 #define MYPATHLEN(buffer, path) ((buffer) + PAGE_SIZE - (path))
46
47 #define SMFS_KML_POST(dir, dentry, data1, data2, op, name, rc, label)   \
48 do {                                                                    \
49         if(smfs_do_rec(dir) && !rc) {                                   \
50                 CDEBUG(D_INODE, "Do %s kml post for dir %lu \n",        \
51                               name, dir->i_ino);                        \
52                 rc = smfs_post_kml_rec(dir, dentry, data1, data2, op);  \
53                 if (rc)                                                 \
54                         GOTO(label, rc);                                \
55         }                                                               \
56 } while(0)
57
58 extern int init_smfs_proc_sys(void);
59 /*options.c*/
60 extern int get_opt(struct option **option, char **pos);
61 extern void cleanup_option(void);
62 extern int init_option(char *data);
63 /*cache.c*/
64 extern void sm_set_inode_ops(struct inode *cache_inode, struct inode *inode);
65 extern void sm_set_sb_ops(struct super_block *cache_sb, struct super_block *sb);
66 extern void init_smfs_cache(void);
67 extern void cleanup_smfs_cache(void);
68 extern void sm_set_journal_ops(struct super_block *sb, char *cache_type);
69 extern int smfs_init_sm_ops(struct smfs_super_info *smb);
70 extern void smfs_cleanup_sm_ops(struct smfs_super_info *smb);
71 static inline struct super_operations *cache_sops(struct smfs_super_info *smb)
72 {
73         return &smb->sm_ops->sm_sb_ops;
74 }
75 static inline struct inode_operations *cache_diops(struct smfs_super_info *smb)
76 {
77         return &smb->sm_ops->sm_dir_iops;
78 }
79 static inline struct inode_operations *cache_fiops(struct smfs_super_info *smb)
80 {
81         return &smb->sm_ops->sm_file_iops;
82 }
83 static inline struct inode_operations *cache_siops(struct smfs_super_info *smb)
84 {
85         return &smb->sm_ops->sm_sym_iops;
86 }
87 static inline struct file_operations *cache_dfops(struct smfs_super_info *smb)
88 {
89         return &smb->sm_ops->sm_dir_fops;
90 }
91 static inline struct file_operations *cache_ffops(struct smfs_super_info *smb)
92 {
93         return &smb->sm_ops->sm_file_fops;
94 }
95 static inline struct file_operations *cache_sfops(struct smfs_super_info *smb)
96 {
97         return &smb->sm_ops->sm_sym_fops;
98 }
99 static inline struct dentry_operations *cache_dops(struct smfs_super_info *smb)
100 {
101         return &smb->sm_ops->sm_dentry_ops;
102 }
103 static inline struct journal_operations *journal_ops(struct smfs_super_info *smb)
104 {
105         return &smb->sm_ops->sm_journal_ops;
106 }
107 /*super.c*/
108 extern int init_smfs(void);
109 extern int cleanup_smfs(void);
110 extern void smfs_put_super(struct super_block *sb);
111 extern struct super_block *smfs_get_sb_by_path(char *path, int len);
112 extern struct vfsmount* get_vfsmount(struct super_block *sb);
113 /*sysctl.c*/
114 extern int sm_debug_level;
115 extern int sm_inodes;
116 extern long sm_kmemory;
117 extern int sm_stack;
118 /*dir.c*/
119 extern struct inode_operations smfs_dir_iops;
120 extern struct file_operations smfs_dir_fops;
121 /*file.c*/
122 extern struct inode_operations smfs_file_iops;
123 extern struct file_operations  smfs_file_fops;
124 extern int smfs_ioctl(struct inode * inode, struct file * filp,
125                       unsigned int cmd, unsigned long arg);
126 extern int smfs_fsync(struct file * file, struct dentry *dentry, int datasync);
127 extern int smfs_setattr(struct dentry *dentry, struct iattr *attr);
128 extern int smfs_setxattr(struct dentry *dentry, const char *name,
129                          const void *value, size_t size, int flags);
130 extern int smfs_getxattr(struct dentry *dentry, const char *name, void *buffer,
131                          size_t size);
132 extern ssize_t smfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
133 extern int smfs_removexattr(struct dentry *dentry, const char *name);
134 extern int smfs_open(struct inode * inode, struct file * filp);
135 extern int smfs_release(struct inode * inode, struct file * filp);
136 /*inode.c*/
137 extern struct super_operations smfs_super_ops;
138 /*symlink.c*/
139 extern struct inode_operations smfs_sym_iops;
140 extern struct file_operations smfs_sym_fops;
141 /*journal.c */
142 extern void *smfs_trans_start(struct inode *inode, int op, void *desc_private);
143 extern void smfs_trans_commit(struct inode *inode, void *handle,
144                               int force_sync);
145 extern int  smfs_post_kml_rec(struct inode *dir, struct dentry *dst_dentry,
146                               void *data1, void *data2, int op);
147 /*kml.c*/
148 extern int smfs_kml_init(struct super_block *sb);
149 extern int smfs_do_rec(struct inode *inode);
150 extern int smfs_rec_cleanup(struct super_block *sb);
151 extern int smfs_rec_init(struct super_block *sb);
152 extern int smfs_rec_unpack(struct smfs_proc_args *args,
153                            struct reint_record *u_rec, char *rec_buf);
154 extern int smfs_start_rec(struct super_block *sb);
155 extern int smfs_stop_rec(struct super_block *sb);
156 extern int smfs_process_rec(struct super_block *sb, int count, char *dir,
157                             int flags);
158 void reint_rec_free(struct reint_record *reint_rec);
159
160 extern void smfs_rec_pack(struct update_record *rec, struct inode *dst,
161                           void *data, int op);
162 /*smfs_llog.c*/
163 extern int smfs_llog_setup(struct super_block *sb);
164 extern int smfs_llog_cleanup(struct super_block *sb);
165 extern int smfs_llog_add_rec(struct smfs_super_info * sinfo, void *data,
166                              int data_size);
167 /*ioctl.c*/
168 extern int init_smfs_psdev(void);
169 extern void smfs_cleanup_psdev(void);
170
171 /* cache_space.c */
172 extern int do_cache_manage;
173 struct cache_purge_queue {
174         wait_queue_head_t       cpq_waitq;
175         struct super_block     *cpq_sb;
176         struct llog_handle     *cpq_loghandle;
177         __u32                   cpq_flags;
178         struct completion       cpq_comp;
179 };
180
181 /* opcodes */
182 #define CACHE_SPACE_INSERT 0x1
183 #define CACHE_SPACE_DELETE 0x2
184 #define CACHE_SPACE_COMMIT 0x4
185
186 #define CACHE_LRU_LOG "CACHE_LRU_LIST"
187
188 extern int smfs_cache_hook(struct inode *inode);
189 extern void cache_space_pre(struct inode *inode, int op);
190 extern int cache_space_post(int op, void *handle, struct inode *old_dir,
191                             struct dentry *old_dentry, struct inode *new_dir,
192                             struct dentry *new_dentry);
193
194 extern int cache_space_hook_setup(struct super_block *);
195 extern int cache_space_hook_cleanup(void);
196 extern int cache_space_hook_init(struct super_block *);
197 extern int cache_space_hook_exit(struct super_block *);
198
199 #define XATTR_SMFS_HOARD_MARK           "hoard"
200 #define XATTR_SMFS_CACHE_LOGCOOKIE      "cache"
201 #define XATTR_SMFS_ACTIVE_ENTRY         "entry"
202
203 #define SMFS_TRANS_OP(inode, op)                \
204 {                                               \
205         if (smfs_do_rec(inode))                 \
206                 op = op | 0x10;                 \
207         if (smfs_cache_hook(inode))             \
208                 op = op | 0x20;                 \
209 }
210
211 static inline int set_hoard_priority(struct inode *inode, void *handle,
212                                      __u32 *hoard)
213 {
214         struct fsfilt_operations *fsops = I2CSB(inode)->sm_fsfilt;
215         int rc;
216
217         rc = fsops->fs_set_xattr(inode, handle, XATTR_SMFS_HOARD_MARK,
218                                  hoard, sizeof(__u32));
219         RETURN(rc);
220 }
221
222 static inline int get_hoard_priority(struct inode *inode, __u32 *hoard)
223 {
224         struct fsfilt_operations *fsops = I2CSB(inode)->sm_fsfilt;
225         int rc;
226
227         rc = fsops->fs_get_xattr(inode, XATTR_SMFS_HOARD_MARK,
228                                  hoard, sizeof(__u32));
229         RETURN(rc);
230 }
231
232 static inline int set_active_entry(struct inode *dir, __u64 *active_entry,
233                                    void *handle)
234 {
235         struct fsfilt_operations *fsops = I2CSB(dir)->sm_fsfilt;
236         int rc;
237         *active_entry = cpu_to_le64(*active_entry);
238         rc = fsops->fs_set_xattr(dir, handle, XATTR_SMFS_ACTIVE_ENTRY,
239                                  active_entry, sizeof(__u64));
240         RETURN(rc);
241 }
242 static inline int get_active_entry(struct inode *dir, __u64 *active_entry)
243 {
244         struct fsfilt_operations *fsops = I2CSB(dir)->sm_fsfilt;
245         int rc = fsops->fs_get_xattr(dir, XATTR_SMFS_ACTIVE_ENTRY,
246                                      active_entry, sizeof(__u64));
247         *active_entry = le64_to_cpu(*active_entry);
248         if (rc >= 0)
249                 rc = 0;
250         RETURN(rc);
251 }
252
253 #define CACHE_HOOK_CREATE       1
254 #define CACHE_HOOK_LOOKUP       2
255 #define CACHE_HOOK_LINK         3
256 #define CACHE_HOOK_UNLINK       4
257 #define CACHE_HOOK_SYMLINK      5
258 #define CACHE_HOOK_MKDIR        6
259 #define CACHE_HOOK_RMDIR        7
260 #define CACHE_HOOK_MKNOD        8
261 #define CACHE_HOOK_RENAME       9
262
263 #define CACHE_HOOK_MAX          9
264
265 #define SMFS_CACHE_HOOK_PRE(op, handle, dir)                            \
266 {                                                                       \
267         if (smfs_cache_hook(dir)) {                                     \
268                 LASSERT(handle != NULL);                                \
269                 CDEBUG(D_INODE, "cache hook pre: op %d, dir %lu\n",     \
270                        op, dir->i_ino);                                 \
271                 cache_space_pre(dir, op);                               \
272         }                                                               \
273 }
274
275 #define SMFS_CACHE_HOOK_POST(op, handle, old_dir, old_dentry,           \
276                              new_dir, new_dentry, rc, label)            \
277 {                                                                       \
278         if (!rc && smfs_cache_hook(old_dir)) {                          \
279                 LASSERT(handle != NULL);                                \
280                 CDEBUG(D_INODE, "cache hook post: op %d, dir %lu\n",    \
281                        op, old_dir->i_ino);                             \
282                 rc = cache_space_post(op, handle, old_dir, old_dentry,  \
283                                          new_dir, new_dentry);          \
284                 if (rc)                                                 \
285                         GOTO(label, rc);                                \
286         }                                                               \
287 }
288
289 #endif /*__KERNEL*/
290 #endif /* __LINUX_SMFS_H */