Whamcloud - gitweb
Branch: HEAD
[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 "smfs_api.h"
28 #define SMFSDEV_NAME "/dev/smfsconf"
29 #define SMFS_PSDEV_MINOR 250
30 #define SMFS_PSDEV_MAJOR 10
31
32 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,10))
33 #define FC3_KERNEL
34 #endif
35
36 struct option {
37         char *opt;
38         char *value;
39         struct list_head list;
40 };
41
42 struct smfs_control_device {
43         struct list_head smfs_dev_list;
44 };
45
46 #define SMFS_TYPE                "smfs"
47 #define IOC_SMFS_START           _IOWR('s', 41, long)
48 #define IOC_SMFS_STOP            _IOWR('s', 42, long)
49 #define IOC_SMFS_REINT           _IOWR('s', 43, long)
50 #define IOC_SMFS_UNDO            _IOWR('s', 44, long)
51
52 #ifdef __KERNEL__
53
54 #define SB_OPS_CHECK             0x1
55 #define INODE_OPS_CHECK          0x2
56 #define FILE_OPS_CHECK           0x4
57 #define DENTRY_OPS_CHECK         0x8
58 #define DEV_OPS_CHECK            0x10
59 #define SYMLINK_OPS_CHECK        0x20
60 #define DIR_OPS_CHECK            0x40
61
62 #define KML_LOG_NAME "kml_rec"
63
64 #define MYPATHLEN(buffer, path) ((buffer) + PAGE_SIZE - (path))
65
66
67 #define PACK_KML_REC_INIT(buffer, op_code)          \
68 do{                                                 \
69         int opcode = op_code;                       \
70         memcpy(buffer, &opcode, sizeof(opcode));    \
71         buffer += sizeof(opcode);                   \
72 } while (0)
73
74
75 extern int init_smfs_proc_sys(void);
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
85 static inline struct inode_operations *cache_diops(struct smfs_super_info *smb)
86 {
87         return &smb->sm_ops->sm_dir_iops;
88 }
89 static inline struct inode_operations *cache_fiops(struct smfs_super_info *smb)
90 {
91         return &smb->sm_ops->sm_file_iops;
92 }
93 static inline struct inode_operations *cache_siops(struct smfs_super_info *smb)
94 {
95         return &smb->sm_ops->sm_sym_iops;
96 }
97 static inline struct file_operations *cache_dfops(struct smfs_super_info *smb)
98 {
99         return &smb->sm_ops->sm_dir_fops;
100 }
101 static inline struct file_operations *cache_ffops(struct smfs_super_info *smb)
102 {
103         return &smb->sm_ops->sm_file_fops;
104 }
105 static inline struct file_operations *cache_sfops(struct smfs_super_info *smb)
106 {
107         return &smb->sm_ops->sm_sym_fops;
108 }
109 static inline struct dentry_operations *cache_dops(struct smfs_super_info *smb)
110 {
111         return &smb->sm_ops->sm_dentry_ops;
112 }
113 static inline struct journal_operations *journal_ops(struct smfs_super_info *smb)
114 {
115         return &smb->sm_ops->sm_journal_ops;
116 }
117
118 struct smfs_hook_ops *smfs_alloc_hook_ops(char *name, 
119                                           smfs_hook_func pre_hook, 
120                                           smfs_hook_func post_hook);
121
122 void smfs_free_hook_ops(struct smfs_hook_ops *hops);
123 int smfs_register_hook_ops(struct smfs_super_info *smb, 
124                            struct smfs_hook_ops *smh_ops);
125
126 struct smfs_hook_ops *smfs_unregister_hook_ops(struct smfs_super_info *smb, 
127                                                char *name);
128 /*smfs_lib.c*/
129 void smfs_put_super(struct super_block *sb);
130 int smfs_fill_super(struct super_block *sb, void *data, int silent);
131 int smfs_post_setup(struct super_block *, struct vfsmount *);
132 void smfs_post_cleanup(struct super_block *);
133 /*sysctl.c*/
134 extern int sm_debug_level;
135 extern int sm_inodes;
136 extern long sm_kmemory;
137 extern int sm_stack;
138 /*dir.c*/
139 extern struct inode_operations smfs_dir_iops;
140 extern struct file_operations smfs_dir_fops;
141 extern struct inode_operations smfs_iopen_iops;
142 extern struct file_operations smfs_iopen_fops;
143
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 struct inode *smfs_get_inode(struct super_block *sb, ino_t hash, 
161                              struct inode *dir, int index);
162
163 extern struct super_operations smfs_super_ops;
164
165 struct smfs_iget_args {
166         struct inode *s_inode;
167         int           s_index;
168         int           s_ino;
169 };
170 /*symlink.c*/
171 extern struct inode_operations smfs_sym_iops;
172 extern struct file_operations smfs_sym_fops;
173 /*journal.c */
174 void *smfs_trans_start(struct inode *inode, int op, void *desc_private);
175 void smfs_trans_commit(struct inode *inode, void *handle, int force_sync);
176
177 extern int smfs_post_rec_write(struct inode *dir, struct dentry *dentry,
178                                void   *data1, void *data2);
179 extern int smfs_post_rec_setattr(struct inode *dir, struct dentry *dentry,
180                                  void   *data1, void *data2);
181 extern int smfs_post_rec_create(struct inode *dir, struct dentry *dentry,
182                                 void   *data1, void   *data2);
183 /*kml.c*/
184 int smfs_do_rec(struct inode *inode);
185 int smfs_rec_cleanup(struct smfs_super_info *sb);
186 int smfs_rec_init(struct super_block *sb);
187
188 extern int smfs_rec_unpack(struct smfs_proc_args *args, char *record,
189                            char **pbuf, int *opcode);
190 extern int smfs_process_rec(struct super_block *sb, int count,
191                             char *dir, int flags);
192
193 /*mds_kml.c*/
194 int mds_rec_pack_init(struct smfs_super_info *smb);
195 /*ost_kml.c*/
196 int ost_rec_pack_init(struct smfs_super_info *smb);
197
198 /*smfs_llog.c*/
199 extern int smfs_llog_setup(struct super_block *sb, struct vfsmount *mnt);
200 extern int smfs_llog_cleanup(struct super_block *sb);
201 extern int smfs_llog_add_rec(struct smfs_super_info * sinfo, void *data,
202                              int data_size);
203 /*ioctl.c*/
204 extern int init_smfs_psdev(void);
205 extern void smfs_cleanup_psdev(void);
206 /*smfs_cow.c */
207
208 /* cache_space.c */
209 extern int do_cache_manage;
210 struct cache_purge_queue {
211         wait_queue_head_t       cpq_waitq;
212         struct super_block     *cpq_sb;
213         struct llog_handle     *cpq_loghandle;
214         __u32                   cpq_flags;
215         struct completion       cpq_comp;
216 };
217 /* opcodes */
218 #define CACHE_SPACE_INSERT 0x1
219 #define CACHE_SPACE_DELETE 0x2
220 #define CACHE_SPACE_COMMIT 0x4
221
222 #define CACHE_LRU_LOG "CACHE_LRU_LIST"
223
224 extern int smfs_cache_hook(struct inode *inode);
225 extern void cache_space_pre(struct inode *inode, int op);
226 extern int cache_space_post(int op, void *handle, struct inode *old_dir,
227                             struct dentry *old_dentry, struct inode *new_dir,
228                             struct dentry *new_dentry);
229
230 int cache_space_hook_setup(struct super_block *);
231 int cache_space_hook_cleanup(void);
232 int cache_space_hook_init(struct super_block *sb);
233 int cache_space_hook_exit(struct smfs_super_info *smfs_info);
234
235 #define XATTR_SMFS_HOARD_MARK           "hoard"
236 #define XATTR_SMFS_CACHE_LOGCOOKIE      "cache"
237 #define XATTR_SMFS_ACTIVE_ENTRY         "entry"
238
239
240 static inline int set_hoard_priority(struct inode *inode, void *handle,
241                                      __u32 *hoard)
242 {
243         struct fsfilt_operations *fsops = I2CSB(inode)->sm_fsfilt;
244         int rc;
245
246         rc = fsops->fs_set_xattr(inode, handle, XATTR_SMFS_HOARD_MARK,
247                                  hoard, sizeof(__u32));
248         RETURN(rc);
249 }
250
251 static inline int get_hoard_priority(struct inode *inode, __u32 *hoard)
252 {
253         struct fsfilt_operations *fsops = I2CSB(inode)->sm_fsfilt;
254         int rc;
255
256         rc = fsops->fs_get_xattr(inode, XATTR_SMFS_HOARD_MARK,
257                                  hoard, sizeof(__u32));
258         RETURN(rc);
259 }
260
261 static inline int set_active_entry(struct inode *dir, __u64 *active_entry,
262                                    void *handle)
263 {
264         struct fsfilt_operations *fsops = I2CSB(dir)->sm_fsfilt;
265         int rc;
266         *active_entry = cpu_to_le64(*active_entry);
267         rc = fsops->fs_set_xattr(dir, handle, XATTR_SMFS_ACTIVE_ENTRY,
268                                  active_entry, sizeof(__u64));
269         RETURN(rc);
270 }
271 static inline int get_active_entry(struct inode *dir, __u64 *active_entry)
272 {
273         struct fsfilt_operations *fsops = I2CSB(dir)->sm_fsfilt;
274         int rc = fsops->fs_get_xattr(dir, XATTR_SMFS_ACTIVE_ENTRY,
275                                      active_entry, sizeof(__u64));
276         *active_entry = le64_to_cpu(*active_entry);
277         if (rc >= 0)
278                 rc = 0;
279         RETURN(rc);
280 }
281
282 #if CONFIG_SNAPFS
283 int smfs_cow_init(struct super_block *sb);
284 int smfs_cow_cleanup(struct smfs_super_info *smb);
285 int smfs_snap_test_inode(struct inode *inode, void *args);
286 #else
287 #define SMFS_PRE_COW(dir, dentry, new_dir, new_dentry, op, name, rc, label)                 
288 #endif 
289 #endif /*__KERNEL*/
290 #endif /* __LINUX_SMFS_H */