Whamcloud - gitweb
c3ef77ec10f23107a7fa63c61a16a4978497a8c1
[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 #define SMFS_KML_POST(dir, dentry, data1, data2, op, name, rc, label)   \
63 do {                                                                    \
64         if (smfs_do_rec(dir) && !rc) {                                  \
65                 CDEBUG(D_INODE, "Do %s kml post for dir %lu \n",        \
66                               name, dir->i_ino);                        \
67                 rc = smfs_post_kml_rec(dir, dentry, data1, data2, op);  \
68                 if (rc)                                                 \
69                         GOTO(label, rc);                                \
70         }                                                               \
71 } while(0)
72
73 #define PACK_KML_REC_INIT(buffer, op_code)          \
74 do{                                                 \
75         int opcode = op_code;                       \
76         memcpy(buffer, &opcode, sizeof(opcode));    \
77         buffer += sizeof(opcode);                   \
78 } while (0)
79
80 extern int init_smfs_proc_sys(void);
81 /*options.c*/
82 extern int get_opt(struct option **option, char **pos);
83 extern void cleanup_option(void);
84 extern int init_option(char *data);
85 /*cache.c*/
86 extern void sm_set_inode_ops(struct inode *cache_inode, struct inode *inode);
87 extern void sm_set_sb_ops(struct super_block *cache_sb, struct super_block *sb);
88 extern void init_smfs_cache(void);
89 extern void cleanup_smfs_cache(void);
90 extern void sm_set_journal_ops(struct super_block *sb, char *cache_type);
91 extern int smfs_init_sm_ops(struct smfs_super_info *smb);
92 extern void smfs_cleanup_sm_ops(struct smfs_super_info *smb);
93 static inline struct super_operations *cache_sops(struct smfs_super_info *smb)
94 {
95         return &smb->sm_ops->sm_sb_ops;
96 }
97 static inline struct inode_operations *cache_diops(struct smfs_super_info *smb)
98 {
99         return &smb->sm_ops->sm_dir_iops;
100 }
101 static inline struct inode_operations *cache_fiops(struct smfs_super_info *smb)
102 {
103         return &smb->sm_ops->sm_file_iops;
104 }
105 static inline struct inode_operations *cache_siops(struct smfs_super_info *smb)
106 {
107         return &smb->sm_ops->sm_sym_iops;
108 }
109 static inline struct file_operations *cache_dfops(struct smfs_super_info *smb)
110 {
111         return &smb->sm_ops->sm_dir_fops;
112 }
113 static inline struct file_operations *cache_ffops(struct smfs_super_info *smb)
114 {
115         return &smb->sm_ops->sm_file_fops;
116 }
117 static inline struct file_operations *cache_sfops(struct smfs_super_info *smb)
118 {
119         return &smb->sm_ops->sm_sym_fops;
120 }
121 static inline struct dentry_operations *cache_dops(struct smfs_super_info *smb)
122 {
123         return &smb->sm_ops->sm_dentry_ops;
124 }
125 static inline struct journal_operations *journal_ops(struct smfs_super_info *smb)
126 {
127         return &smb->sm_ops->sm_journal_ops;
128 }
129 /*super.c*/
130 extern int init_smfs(void);
131 extern int cleanup_smfs(void);
132 extern void smfs_put_super(struct super_block *sb);
133 extern struct super_block *smfs_get_sb_by_path(char *path, int len);
134 /*sysctl.c*/
135 extern int sm_debug_level;
136 extern int sm_inodes;
137 extern long sm_kmemory;
138 extern int sm_stack;
139 /*dir.c*/
140 extern struct inode_operations smfs_dir_iops;
141 extern struct file_operations smfs_dir_fops;
142 /*file.c*/
143 extern struct inode_operations smfs_file_iops;
144 extern struct file_operations  smfs_file_fops;
145 extern int smfs_ioctl(struct inode * inode, struct file * filp,
146                       unsigned int cmd, unsigned long arg);
147 extern int smfs_fsync(struct file * file, struct dentry *dentry, int datasync);
148 extern int smfs_setattr(struct dentry *dentry, struct iattr *attr);
149 extern int smfs_setxattr(struct dentry *dentry, const char *name,
150                          const void *value, size_t size, int flags);
151 extern int smfs_getxattr(struct dentry *dentry, const char *name, void *buffer,
152                          size_t size);
153 extern ssize_t smfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
154 extern int smfs_removexattr(struct dentry *dentry, const char *name);
155 extern int smfs_open(struct inode * inode, struct file * filp);
156 extern int smfs_release(struct inode * inode, struct file * filp);
157 /*inode.c*/
158 extern struct super_operations smfs_super_ops;
159 /*symlink.c*/
160 extern struct inode_operations smfs_sym_iops;
161 extern struct file_operations smfs_sym_fops;
162 /*journal.c */
163 extern void *smfs_trans_start(struct inode *inode, int op, void *desc_private);
164 extern void smfs_trans_commit(struct inode *inode, void *handle,
165                               int force_sync);
166 extern int  smfs_post_kml_rec(struct inode *dir, struct dentry *dst_dentry,
167                               void   *data1, void *data2, int op);
168
169 extern int smfs_post_rec_write(struct inode *dir, struct dentry *dentry,
170                                void   *data1, void *data2);
171 extern int smfs_post_rec_setattr(struct inode *dir, struct dentry *dentry,
172                                  void   *data1, void *data2);
173 extern int smfs_post_rec_create(struct inode *dir, struct dentry *dentry,
174                                 void   *data1, void   *data2);
175 /*kml.c*/
176 extern int smfs_kml_init(struct super_block *sb);
177 extern int smfs_do_rec(struct inode *inode);
178 extern int smfs_rec_cleanup(struct super_block *sb);
179 extern int smfs_rec_init(struct super_block *sb);
180 extern int smfs_rec_unpack(struct smfs_proc_args *args, char *record,
181                            char **pbuf, int *opcode);
182 extern int smfs_process_rec(struct super_block *sb, int count,
183                             char *dir, int flags);
184 extern smfs_pack_rec_func smfs_get_rec_pack_type(struct super_block *sb);
185
186 extern int ost_rec_pack_init(struct super_block *sb);
187 /*ost_kml.c*/
188 extern int mds_rec_pack_init(struct super_block *sb);
189
190 /*smfs_llog.c*/
191 extern int smfs_llog_setup(struct super_block *sb, struct vfsmount *mnt);
192 extern int smfs_llog_cleanup(struct super_block *sb);
193 extern int smfs_llog_add_rec(struct smfs_super_info * sinfo, void *data,
194                              int data_size);
195 /*ioctl.c*/
196 extern int init_smfs_psdev(void);
197 extern void smfs_cleanup_psdev(void);
198 /*smfs_cow.c */
199
200 /* cache_space.c */
201 extern int do_cache_manage;
202 struct cache_purge_queue {
203         wait_queue_head_t       cpq_waitq;
204         struct super_block     *cpq_sb;
205         struct llog_handle     *cpq_loghandle;
206         __u32                   cpq_flags;
207         struct completion       cpq_comp;
208 };
209 /* opcodes */
210 #define CACHE_SPACE_INSERT 0x1
211 #define CACHE_SPACE_DELETE 0x2
212 #define CACHE_SPACE_COMMIT 0x4
213
214 #define CACHE_LRU_LOG "CACHE_LRU_LIST"
215
216 extern int smfs_cache_hook(struct inode *inode);
217 extern void cache_space_pre(struct inode *inode, int op);
218 extern int cache_space_post(int op, void *handle, struct inode *old_dir,
219                             struct dentry *old_dentry, struct inode *new_dir,
220                             struct dentry *new_dentry);
221
222 extern int cache_space_hook_setup(struct super_block *);
223 extern int cache_space_hook_cleanup(void);
224 extern int cache_space_hook_init(struct super_block *);
225 extern int cache_space_hook_exit(struct super_block *);
226
227 #define XATTR_SMFS_HOARD_MARK           "hoard"
228 #define XATTR_SMFS_CACHE_LOGCOOKIE      "cache"
229 #define XATTR_SMFS_ACTIVE_ENTRY         "entry"
230
231
232 static inline int set_hoard_priority(struct inode *inode, void *handle,
233                                      __u32 *hoard)
234 {
235         struct fsfilt_operations *fsops = I2CSB(inode)->sm_fsfilt;
236         int rc;
237
238         rc = fsops->fs_set_xattr(inode, handle, XATTR_SMFS_HOARD_MARK,
239                                  hoard, sizeof(__u32));
240         RETURN(rc);
241 }
242
243 static inline int get_hoard_priority(struct inode *inode, __u32 *hoard)
244 {
245         struct fsfilt_operations *fsops = I2CSB(inode)->sm_fsfilt;
246         int rc;
247
248         rc = fsops->fs_get_xattr(inode, XATTR_SMFS_HOARD_MARK,
249                                  hoard, sizeof(__u32));
250         RETURN(rc);
251 }
252
253 static inline int set_active_entry(struct inode *dir, __u64 *active_entry,
254                                    void *handle)
255 {
256         struct fsfilt_operations *fsops = I2CSB(dir)->sm_fsfilt;
257         int rc;
258         *active_entry = cpu_to_le64(*active_entry);
259         rc = fsops->fs_set_xattr(dir, handle, XATTR_SMFS_ACTIVE_ENTRY,
260                                  active_entry, sizeof(__u64));
261         RETURN(rc);
262 }
263 static inline int get_active_entry(struct inode *dir, __u64 *active_entry)
264 {
265         struct fsfilt_operations *fsops = I2CSB(dir)->sm_fsfilt;
266         int rc = fsops->fs_get_xattr(dir, XATTR_SMFS_ACTIVE_ENTRY,
267                                      active_entry, sizeof(__u64));
268         *active_entry = le64_to_cpu(*active_entry);
269         if (rc >= 0)
270                 rc = 0;
271         RETURN(rc);
272 }
273
274 #define CACHE_HOOK_CREATE       1
275 #define CACHE_HOOK_LOOKUP       2
276 #define CACHE_HOOK_LINK         3
277 #define CACHE_HOOK_UNLINK       4
278 #define CACHE_HOOK_SYMLINK      5
279 #define CACHE_HOOK_MKDIR        6
280 #define CACHE_HOOK_RMDIR        7
281 #define CACHE_HOOK_MKNOD        8
282 #define CACHE_HOOK_RENAME       9
283
284 #define CACHE_HOOK_MAX          9
285
286 #define SMFS_CACHE_HOOK_PRE(op, handle, dir, rc)                                \
287 {                                                                               \
288         while (smfs_cache_hook(dir)) {                                          \
289                 if (!handle) {                                                  \
290                         handle = smfs_trans_start(dir, KML_CACHE_NOOP, NULL);   \
291                         if (IS_ERR(handle)) {                                   \
292                                rc = -ENOSPC;                                    \
293                                break;                                           \
294                         }                                                       \
295                 }                                                               \
296                 CDEBUG(D_INODE, "cache hook pre: op %d, dir %lu\n",             \
297                        op, dir->i_ino);                                         \
298                 cache_space_pre(dir, op);                                       \
299                 break;                                                          \
300         }                                                                       \
301 }
302
303 #define SMFS_CACHE_HOOK_POST(op, handle, old_dir, old_dentry,           \
304                              new_dir, new_dentry, rc, label)            \
305 {                                                                       \
306         if (!rc && smfs_cache_hook(old_dir)) {                          \
307                 LASSERT(handle != NULL);                                \
308                 CDEBUG(D_INODE, "cache hook post: op %d, dir %lu\n",    \
309                        op, old_dir->i_ino);                             \
310                 rc = cache_space_post(op, handle, old_dir, old_dentry,  \
311                                          new_dir, new_dentry);          \
312                 if (rc)                                                 \
313                         GOTO(label, rc);                                \
314         }                                                               \
315 }
316 #if CONFIG_SNAPFS
317 /*snap macros*/
318 #define SMFS_PRE_COW(dir, dentry, new_dir, new_dentry, op, name, rc, label)    \
319 do {                                                                           \
320         if (smfs_do_cow(dir) && !rc) {                                         \
321                 CDEBUG(D_INODE, "Do %s snap post for dir %lu \n",              \
322                               name, dir->i_ino);                               \
323                 rc = smfs_cow(dir, dentry, new_dir, new_dentry, op);           \
324                 if (op == SNAP_LOOKUP && rc == 1)                              \
325                         GOTO(label, rc = 0);                                   \
326                 else if (rc)                                                   \
327                         GOTO(label, rc);                                       \
328         }                                                                      \
329 } while(0)
330
331 extern int smfs_cow_init(struct super_block *sb);
332 extern int smfs_cow_cleanup(struct super_block *sb);
333 extern int smfs_init_snap_inode_info(struct inode *inode, int flags);
334 #else
335 #define SMFS_PRE_COW(dir, dentry, new_dir, new_dentry, op, name, rc, label)                 
336 #endif 
337
338 #endif /*__KERNEL*/
339 #endif /* __LINUX_SMFS_H */