Whamcloud - gitweb
land b_hd_sec onto HEAD: various security related fixes.
[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 SPECIAL_OPS_CHECK        0x10
59 #define SYMLINK_OPS_CHECK        0x20
60 #define DIR_OPS_CHECK            0x40
61
62 #define MYPATHLEN(buffer, path) ((buffer) + PAGE_SIZE - (path))
63
64 #define PACK_KML_REC_INIT(buffer, op_code)          \
65 do{                                                 \
66         int opcode = op_code;                       \
67         memcpy(buffer, &opcode, sizeof(opcode));    \
68         buffer += sizeof(opcode);                   \
69 } while (0)
70
71
72 extern int init_smfs_proc_sys(void);
73 /*cache.c*/
74 extern void sm_set_inode_ops(struct inode *);
75 extern void sm_set_sb_ops(struct super_block *cache_sb, struct super_block *sb);
76 //extern void init_smfs_cache(void);
77 //extern void cleanup_smfs_cache(void);
78 //extern void sm_set_journal_ops(struct super_block *sb, char *cache_type);
79 extern int smfs_init_sm_ops(struct smfs_super_info *smb);
80 extern void smfs_cleanup_sm_ops(struct smfs_super_info *smb);
81
82 /*smfs_lib.c*/
83 void smfs_put_super(struct super_block *sb);
84 int smfs_fill_super(struct super_block *sb, void *data, int silent);
85 int smfs_post_setup(struct obd_device *, struct vfsmount *, struct dentry *);
86 void smfs_post_cleanup(struct super_block *);
87 /*sysctl.c*/
88 extern int sm_debug_level;
89 extern int sm_inodes;
90 extern long sm_kmemory;
91 extern int sm_stack;
92 /*dir.c*/
93 extern struct inode_operations smfs_dir_iops;
94 extern struct file_operations smfs_dir_fops;
95 extern struct inode_operations smfs_iopen_iops;
96 extern struct file_operations smfs_iopen_fops;
97
98 /*file.c*/
99 extern struct inode_operations smfs_file_iops;
100 extern struct file_operations  smfs_file_fops;
101 extern struct inode_operations smfs_special_iops;
102 extern int smfs_ioctl(struct inode * inode, struct file * filp,
103                       unsigned int cmd, unsigned long arg);
104 extern int smfs_fsync(struct file * file, struct dentry *dentry, int datasync);
105 extern int smfs_setattr(struct dentry *dentry, struct iattr *attr);
106 extern int smfs_setxattr(struct dentry *dentry, const char *name,
107                          const void *value, size_t size, int flags);
108 extern int smfs_getxattr(struct dentry *dentry, const char *name, void *buffer,
109                          size_t size);
110 extern ssize_t smfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
111 extern int smfs_removexattr(struct dentry *dentry, const char *name);
112 extern int smfs_permission(struct inode *inode, int mask, struct nameidata *nd);
113 extern int smfs_open(struct inode * inode, struct file * filp);
114 extern int smfs_release(struct inode * inode, struct file * filp);
115 /*inode.c*/
116 struct inode *smfs_get_inode(struct super_block *, struct inode*,  
117                              struct smfs_inode_info *, int);
118
119 extern struct super_operations smfs_super_ops;
120
121 struct smfs_iget_args {
122         struct inode            *s_inode;
123         struct smfs_inode_info  *s_info;
124         int                      s_index;
125 };
126
127 /*symlink.c*/
128 extern struct inode_operations smfs_sym_iops;
129 extern struct file_operations smfs_sym_fops;
130
131 void *smfs_trans_start(struct inode *inode, int op, void *desc_private);
132 void smfs_trans_commit(struct inode *inode, void *handle, int force_sync);
133
134 extern int smfs_post_rec_write(struct inode *dir, struct dentry *dentry,
135                                void   *data1, void *data2);
136 extern int smfs_post_rec_setattr(struct inode *dir, struct dentry *dentry,
137                                  void   *data1, void *data2);
138 extern int smfs_post_rec_create(struct inode *dir, struct dentry *dentry,
139                                 void   *data1, void   *data2);
140 /*kml.c*/
141 int smfs_do_rec(struct inode *inode);
142 int smfs_rec_cleanup(struct smfs_super_info *sb);
143 int smfs_rec_init(struct super_block *sb);
144
145 extern int smfs_rec_unpack(struct smfs_proc_args *args, char *record,
146                            char **pbuf, int *opcode);
147 extern int smfs_process_rec(struct super_block *sb, int count,
148                             char *dir, int flags);
149
150 /*mds_kml.c*/
151 int mds_rec_pack_init(struct smfs_super_info *smb);
152 /*ost_kml.c*/
153 int ost_rec_pack_init(struct smfs_super_info *smb);
154
155 /*smfs_llog.c*/
156 extern int smfs_llog_setup(struct smfs_super_info *);
157 extern int smfs_llog_cleanup(struct smfs_super_info *);
158 extern int smfs_llog_add_rec(struct smfs_super_info *, void *, int);
159 /*ioctl.c*/
160 extern int init_smfs_psdev(void);
161 extern void smfs_cleanup_psdev(void);
162 /*smfs_cow.c */
163
164 /* cache_space.c */
165 extern int do_cache_manage;
166 struct cache_purge_queue {
167         wait_queue_head_t       cpq_waitq;
168         struct super_block     *cpq_sb;
169         struct llog_handle     *cpq_loghandle;
170         __u32                   cpq_flags;
171         struct completion       cpq_comp;
172 };
173 /* opcodes */
174 #define CACHE_SPACE_INSERT 0x1
175 #define CACHE_SPACE_DELETE 0x2
176 #define CACHE_SPACE_COMMIT 0x4
177
178 #define CACHE_LRU_LOG "CACHE_LRU_LIST"
179
180 extern int smfs_cache_hook(struct inode *inode);
181 extern void cache_space_pre(struct inode *inode, int op);
182 extern int cache_space_post(int op, void *handle, struct inode *old_dir,
183                             struct dentry *old_dentry, struct inode *new_dir,
184                             struct dentry *new_dentry);
185
186 int cache_space_hook_setup(struct super_block *);
187 int cache_space_hook_cleanup(void);
188 int cache_space_hook_init(struct super_block *sb);
189 int cache_space_hook_exit(struct smfs_super_info *smfs_info);
190
191 #define XATTR_SMFS_HOARD_MARK           "hoard"
192 #define XATTR_SMFS_CACHE_LOGCOOKIE      "cache"
193 #define XATTR_SMFS_ACTIVE_ENTRY         "entry"
194
195
196 static inline int set_hoard_priority(struct inode *inode, void *handle,
197                                      __u32 *hoard)
198 {
199         struct fsfilt_operations *fsops = I2CSB(inode)->sm_fsfilt;
200         int rc;
201
202         rc = fsops->fs_set_xattr(inode, handle, XATTR_SMFS_HOARD_MARK,
203                                  hoard, sizeof(__u32));
204         RETURN(rc);
205 }
206
207 static inline int get_hoard_priority(struct inode *inode, __u32 *hoard)
208 {
209         struct fsfilt_operations *fsops = I2CSB(inode)->sm_fsfilt;
210         int rc;
211
212         rc = fsops->fs_get_xattr(inode, XATTR_SMFS_HOARD_MARK,
213                                  hoard, sizeof(__u32));
214         RETURN(rc);
215 }
216
217 static inline int set_active_entry(struct inode *dir, __u64 *active_entry,
218                                    void *handle)
219 {
220         struct fsfilt_operations *fsops = I2CSB(dir)->sm_fsfilt;
221         int rc;
222         *active_entry = cpu_to_le64(*active_entry);
223         rc = fsops->fs_set_xattr(dir, handle, XATTR_SMFS_ACTIVE_ENTRY,
224                                  active_entry, sizeof(__u64));
225         RETURN(rc);
226 }
227 static inline int get_active_entry(struct inode *dir, __u64 *active_entry)
228 {
229         struct fsfilt_operations *fsops = I2CSB(dir)->sm_fsfilt;
230         int rc = fsops->fs_get_xattr(dir, XATTR_SMFS_ACTIVE_ENTRY,
231                                      active_entry, sizeof(__u64));
232         *active_entry = le64_to_cpu(*active_entry);
233         if (rc >= 0)
234                 rc = 0;
235         RETURN(rc);
236 }
237
238 #if CONFIG_SNAPFS
239 int smfs_cow_init(struct super_block *sb);
240 int smfs_cow_cleanup(struct smfs_super_info *smb);
241 int smfs_snap_test_inode(struct inode *inode, void *args);
242 #else
243 #define SMFS_PRE_COW(dir, dentry, new_dir, new_dentry, op, name, rc, label)                 
244 #endif 
245 #endif /*__KERNEL*/
246 #endif /* __LINUX_SMFS_H */