1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/smfs/smfs_internal.h
5 * Lustre filesystem abstraction routines
7 * Copyright (C) 2004 Cluster File Systems, Inc.
9 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
24 #ifndef __LINUX_SMFS_H
25 #define __LINUX_SMFS_H
27 //#include <linux/lustre_fsfilt.h>
28 #define SMFSDEV_NAME "/dev/smfsconf"
29 #define SMFS_PSDEV_MINOR 250
30 #define SMFS_PSDEV_MAJOR 10
35 struct list_head list;
38 struct smfs_control_device {
39 struct list_head smfs_dev_list;
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)
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
58 #define KML_LOG_NAME "kml_rec"
60 #define MYPATHLEN(buffer, path) ((buffer) + PAGE_SIZE - (path))
63 #define PACK_KML_REC_INIT(buffer, op_code) \
65 int opcode = op_code; \
66 memcpy(buffer, &opcode, sizeof(opcode)); \
67 buffer += sizeof(opcode); \
71 extern int init_smfs_proc_sys(void);
73 extern int get_opt(struct option **option, char **pos);
74 extern void cleanup_option(void);
75 extern int init_option(char *data);
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)
86 return &smb->sm_ops->sm_sb_ops;
88 static inline struct inode_operations *cache_diops(struct smfs_super_info *smb)
90 return &smb->sm_ops->sm_dir_iops;
92 static inline struct inode_operations *cache_fiops(struct smfs_super_info *smb)
94 return &smb->sm_ops->sm_file_iops;
96 static inline struct inode_operations *cache_siops(struct smfs_super_info *smb)
98 return &smb->sm_ops->sm_sym_iops;
100 static inline struct file_operations *cache_dfops(struct smfs_super_info *smb)
102 return &smb->sm_ops->sm_dir_fops;
104 static inline struct file_operations *cache_ffops(struct smfs_super_info *smb)
106 return &smb->sm_ops->sm_file_fops;
108 static inline struct file_operations *cache_sfops(struct smfs_super_info *smb)
110 return &smb->sm_ops->sm_sym_fops;
112 static inline struct dentry_operations *cache_dops(struct smfs_super_info *smb)
114 return &smb->sm_ops->sm_dentry_ops;
116 static inline struct journal_operations *journal_ops(struct smfs_super_info *smb)
118 return &smb->sm_ops->sm_journal_ops;
121 struct smfs_hook_ops *smfs_alloc_hook_ops(char *name,
122 smfs_hook_func pre_hook,
123 smfs_hook_func post_hook);
125 void smfs_free_hook_ops(struct smfs_hook_ops *hops);
126 int smfs_register_hook_ops(struct smfs_super_info *smb,
127 struct smfs_hook_ops *smh_ops);
129 struct smfs_hook_ops *smfs_unregister_hook_ops(struct smfs_super_info *smb,
132 void smfs_put_super(struct super_block *sb);
133 int smfs_fill_super(struct super_block *sb, void *data, int silent);
135 extern int sm_debug_level;
136 extern int sm_inodes;
137 extern long sm_kmemory;
140 extern struct inode_operations smfs_dir_iops;
141 extern struct file_operations smfs_dir_fops;
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,
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);
158 struct inode *smfs_get_inode(struct super_block *sb, ino_t hash,
159 struct inode *dir, int index);
161 extern struct super_operations smfs_super_ops;
163 struct smfs_iget_args {
164 struct inode *s_inode;
169 extern struct inode_operations smfs_sym_iops;
170 extern struct file_operations smfs_sym_fops;
172 extern void *smfs_trans_start(struct inode *inode, int op, void *desc_private);
173 extern void smfs_trans_commit(struct inode *inode, void *handle,
175 extern int smfs_post_kml_rec(struct inode *dir, struct dentry *dst_dentry,
176 void *data1, void *data2, int op);
178 extern int smfs_post_rec_write(struct inode *dir, struct dentry *dentry,
179 void *data1, void *data2);
180 extern int smfs_post_rec_setattr(struct inode *dir, struct dentry *dentry,
181 void *data1, void *data2);
182 extern int smfs_post_rec_create(struct inode *dir, struct dentry *dentry,
183 void *data1, void *data2);
185 int smfs_do_rec(struct inode *inode);
186 int smfs_rec_cleanup(struct super_block *sb);
187 int smfs_rec_init(struct super_block *sb);
189 extern int smfs_rec_unpack(struct smfs_proc_args *args, char *record,
190 char **pbuf, int *opcode);
191 extern int smfs_process_rec(struct super_block *sb, int count,
192 char *dir, int flags);
193 extern smfs_pack_rec_func smfs_get_rec_pack_type(struct super_block *sb);
197 int mds_rec_pack_init(struct super_block *sb);
199 int ost_rec_pack_init(struct super_block *sb);
202 extern int smfs_llog_setup(struct super_block *sb, struct vfsmount *mnt);
203 extern int smfs_llog_cleanup(struct super_block *sb);
204 extern int smfs_llog_add_rec(struct smfs_super_info * sinfo, void *data,
207 extern int init_smfs_psdev(void);
208 extern void smfs_cleanup_psdev(void);
212 extern int do_cache_manage;
213 struct cache_purge_queue {
214 wait_queue_head_t cpq_waitq;
215 struct super_block *cpq_sb;
216 struct llog_handle *cpq_loghandle;
218 struct completion cpq_comp;
221 #define CACHE_SPACE_INSERT 0x1
222 #define CACHE_SPACE_DELETE 0x2
223 #define CACHE_SPACE_COMMIT 0x4
225 #define CACHE_LRU_LOG "CACHE_LRU_LIST"
227 extern int smfs_cache_hook(struct inode *inode);
228 extern void cache_space_pre(struct inode *inode, int op);
229 extern int cache_space_post(int op, void *handle, struct inode *old_dir,
230 struct dentry *old_dentry, struct inode *new_dir,
231 struct dentry *new_dentry);
233 int cache_space_hook_setup(struct super_block *);
234 int cache_space_hook_cleanup(void);
235 int cache_space_hook_init(struct super_block *sb);
236 int cache_space_hook_exit(struct smfs_super_info *smfs_info);
238 #define XATTR_SMFS_HOARD_MARK "hoard"
239 #define XATTR_SMFS_CACHE_LOGCOOKIE "cache"
240 #define XATTR_SMFS_ACTIVE_ENTRY "entry"
243 static inline int set_hoard_priority(struct inode *inode, void *handle,
246 struct fsfilt_operations *fsops = I2CSB(inode)->sm_fsfilt;
249 rc = fsops->fs_set_xattr(inode, handle, XATTR_SMFS_HOARD_MARK,
250 hoard, sizeof(__u32));
254 static inline int get_hoard_priority(struct inode *inode, __u32 *hoard)
256 struct fsfilt_operations *fsops = I2CSB(inode)->sm_fsfilt;
259 rc = fsops->fs_get_xattr(inode, XATTR_SMFS_HOARD_MARK,
260 hoard, sizeof(__u32));
264 static inline int set_active_entry(struct inode *dir, __u64 *active_entry,
267 struct fsfilt_operations *fsops = I2CSB(dir)->sm_fsfilt;
269 *active_entry = cpu_to_le64(*active_entry);
270 rc = fsops->fs_set_xattr(dir, handle, XATTR_SMFS_ACTIVE_ENTRY,
271 active_entry, sizeof(__u64));
274 static inline int get_active_entry(struct inode *dir, __u64 *active_entry)
276 struct fsfilt_operations *fsops = I2CSB(dir)->sm_fsfilt;
277 int rc = fsops->fs_get_xattr(dir, XATTR_SMFS_ACTIVE_ENTRY,
278 active_entry, sizeof(__u64));
279 *active_entry = le64_to_cpu(*active_entry);
284 #define HOOK_CREATE 1
285 #define HOOK_LOOKUP 2
287 #define HOOK_UNLINK 4
288 #define HOOK_SYMLINK 5
292 #define HOOK_RENAME 9
293 #define HOOK_SETATTR 10
294 #define HOOK_WRITE 11
299 #define SMFS_HOOK(inode, dentry, data1, data2, op, handle, flag, rc, label) \
301 LASSERT(inode->i_sb); \
303 struct smfs_super_info *smb = S2SMI(inode->i_sb); \
304 struct list_head *hlist = &smb->smsi_hook_list; \
305 struct list_head *p; \
307 list_for_each(p, hlist) { \
308 struct smfs_hook_ops *hops; \
310 hops = list_entry(p, typeof(*hops), smh_list); \
311 if (flag == PRE_HOOK && hops->smh_pre_op) \
312 rc = hops->smh_pre_op(inode, dentry, data1, \
313 data2, op, handle); \
314 else if (flag == POST_HOOK && hops->smh_post_op) \
315 rc = hops->smh_post_op(inode, dentry, data1, \
316 data2, op, handle); \
325 #define SMFS_GET_INODE(sb, cache_inode, dir, index, inode, rc, label) \
327 LASSERT(cache_inode); \
328 inode = smfs_get_inode(sb, cache_inode->i_ino, dir, index); \
331 GOTO(label, rc = -ENOENT); \
336 int smfs_cow_init(struct super_block *sb);
337 int smfs_cow_cleanup(struct smfs_super_info *smb);
338 int smfs_init_snap_inode_info(struct inode *inode, struct smfs_iget_args *args);
339 int smfs_snap_test_inode(struct inode *inode, void *args);
341 #define SMFS_PRE_COW(dir, dentry, new_dir, new_dentry, op, name, rc, label)
344 #endif /* __LINUX_SMFS_H */