Whamcloud - gitweb
- landing of b_fid after merge with b_hd_cleanup_merge.
[fs/lustre-release.git] / lustre / include / linux / lustre_snap.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001-2003 Cluster File Systems, Inc. <info@clusterfs.com>
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * SNAP data structures.
22  * See also lustre_idl.h for wire formats of requests.
23  *
24  */
25 /* maximum number of snapshots available for users */
26
27 #ifndef __LUSTRE_SNAP_H
28 #define __LUSTRE_SNAP_H
29
30 #define MAX_SNAPS       20
31 #define SNAP_ATTR       "@snap"
32 struct snap_ea{
33         int   generation;
34         ino_t prev_ino;
35         ino_t next_ino;
36         ino_t ino[MAX_SNAPS+1]; /* including current snapshot */
37         ino_t parent_ino[MAX_SNAPS+1];
38 };
39 #define MAX_SNAP_DATA (sizeof(struct snap_ea))
40
41 /*
42  * Check if the EA @name is Snap EA or not.
43  * Snap EA includes the SNAP_ATTR, SNAP_NEW_INO_ATTR and DISK_SNAP_META_ATTR
44  */
45
46 #define IS_SNAP_EA(name) ( (!strcmp((name), SNAP_ATTR)) ||              \
47                            (!strcmp((name), DISK_SNAP_META_ATTR)))
48
49
50 /* file system features */
51 #define SNAP_FEATURE_COMPAT_SNAPFS              0x0010
52 #define SNAP_FEATURE_COMPAT_BLOCKCOW            0x0020
53
54 /* constants for snap_feature operations */
55 #define SNAP_CLEAR_FEATURE      0x0
56 #define SNAP_SET_FEATURE        0x1
57 #define SNAP_HAS_FEATURE        0x2
58
59 /* snap flags for inode, within 1 byte range, each occupy 1 bit */
60 #define SNAP_INO_MAGIC  0x88            /* magic for snap inode */
61 #define SNAP_COW_FLAG   0x01            /* snap redirected inode */
62 #define SNAP_DEL_FLAG   0x02            /* snap deleted inode */
63 #define SNAP_TABLE_FLAG 0x04            /* snap table inode */
64 #define SNAP_PRI_FLAG   0x08            /* primary inode */
65
66 /* no snapfs attributes for get_indirect_ino */
67 #define ENOSNAPATTR     320
68
69 /* constants used by iterator */
70 #define SNAP_ITERATE_ALL_INODE          0x0
71 #define SNAP_ITERATE_COWED_INODE        0x1
72
73 /* constants used by create_indirect */
74 #define SNAP_CREATE_IND_NORMAL          0x0
75 #define SNAP_CREATE_IND_DEL_PRI         0x1
76
77 /* the data structure represent in the xfs_dinode.pad
78         offset  0:      magic   (1 byte)
79         offset  1:      flag    (1 byte)
80         offset  2:      gen     (4 bytes)
81         offset  6:      unused
82  */
83 #define SIZEOF_MAGIC            1
84 #define SIZEOF_FLAG             1
85 #define SIZEOF_GENERATION       4
86
87 #define MAGIC_OFFSET            0
88 #define FLAG_OFFSET             1
89 #define GENERATION_OFFSET       2
90
91 #define SNAP_GET_DINODE_MAGIC(dinode)   \
92                 (((__u8*)(dinode)->di_pad)[MAGIC_OFFSET])
93 #define SNAP_SET_DINODE_MAGIC(dinode)   \
94                 ((__u8*)(dinode)->di_pad)[MAGIC_OFFSET] = (SNAP_INO_MAGIC)
95 #define SNAP_GET_DINODE_FLAG(dinode)    \
96                 (((__u8*)(dinode)->di_pad)[FLAG_OFFSET])
97 #define SNAP_SET_DINODE_FLAG(dinode, flag)      \
98                 (((__u8*)(dinode)->di_pad)[FLAG_OFFSET] |= (flag))
99 #define SNAP_CLEAR_DINODE_FLAG(dinode, flag)    \
100                 (((__u8*)(dinode)->di_pad)[FLAG_OFFSET] &= ~(flag))
101 #define SNAP_GET_DINODE_GEN(dinode)     \
102                 (le32_to_cpu(*(__u32*)(&((__u8*)(dinode)->di_pad)[GENERATION_OFFSET])))
103 #define SNAP_SET_DINODE_GEN(dinode, gen)        \
104                 *(__u32*)(&((__u8*)(dinode)->di_pad)[GENERATION_OFFSET]) = cpu_to_le32(gen)
105 #define SNAP_VERSION(a,b,c)             \
106                 (((a & 0xFF) << 16) | ((b & 0xFF) << 8) | (c & 0xFF))
107 #define SNAP_VERSION_MAJOR(v)           \
108                 ((v >> 16) & 0xFF)
109 #define SNAP_VERSION_MINOR(v)           \
110                 ((v >> 8) & 0xFF)
111 #define SNAP_VERSION_REL(v)             \
112                 (v & 0xFF)
113                                                                                                                                                                                                      
114                                                                                                                                                                                                      
115 #define EXT3_EA_TRANS_BLOCKS            EXT3_DATA_TRANS_BLOCKS
116 #define EXT3_SETMETA_TRANS_BLOCKS       EXT3_DATA_TRANS_BLOCKS
117 #define EXT3_NEWINODE_TRANS_BLOCKS      10
118 #define SNAP_INSERTLIST_TRANS_BLOCKS    (2 * EXT3_EA_TRANS_BLOCKS + 1)
119 #define SNAP_DELETELIST_TRANS_BLOCKS    (2 * EXT3_EA_TRANS_BLOCKS + 2)
120 #define SNAP_COPYBLOCK_TRANS_BLOCKS     (EXT3_DATA_TRANS_BLOCKS)
121 #define SNAP_MIGRATEDATA_TRANS_BLOCKS   2
122 #define SNAP_SETIND_TRANS_BLOCKS        (SNAP_INSERTLIST_TRANS_BLOCKS + 1)
123 #define SNAP_ADDORPHAN_TRANS_BLOCKS     2
124 #define SNAP_REMOVEORPHAN_TRANS_BLOCKS  1
125 #define SNAP_RESTOREORPHAN_TRANS_BLOCKS (EXT3_EA_TRANS_BLOCKS + \
126                                          SNAP_DELETELIST_TRANS_BLOCKS + \
127                                          EXT3_NEWINODE_TRANS_BLOCKS + \
128                                          2 * SNAP_MIGRATEDATA_TRANS_BLOCKS)
129 #define SNAP_BIGCOPY_TRANS_BLOCKS       (2 * EXT3_DATA_TRANS_BLOCKS)
130 #define SNAP_CREATEIND_TRANS_BLOCKS     (EXT3_NEWINODE_TRANS_BLOCKS + \
131                                          SNAP_MIGRATEDATA_TRANS_BLOCKS + \
132                                          SNAP_SETIND_TRANS_BLOCKS + \
133                                          SNAP_BIGCOPY_TRANS_BLOCKS + 3)
134 #define SNAP_MIGRATEBLK_TRANS_BLOCKS    2
135 #define SNAP_DESTROY_TRANS_BLOCKS       (SNAP_DELETELIST_TRANS_BLOCKS + \
136                                          EXT3_EA_TRANS_BLOCKS + 2)
137 #define SNAP_RESTORE_TRANS_BLOCKS       (EXT3_NEWINODE_TRANS_BLOCKS + \
138                                          2 * SNAP_MIGRATEDATA_TRANS_BLOCKS + 1)
139 /*Snap Table*/
140 #define SNAP_MAX                32      
141 #define SNAP_MAX_TABLES         32      
142 #define SNAP_MAX_NAMELEN        64
143
144 #define MAX_SNAPTABLE_COUNT  "MAXSnapCount"
145 #define SNAPTABLE_MAGIC      0x19760218
146 #define SNAPTABLE_INFO       "snaptable"
147 #define SNAP_GENERATION      "snap_generation"
148 #define SNAP_COUNT           "snapcount"
149 #define SNAP_ROOT_INO        "snap_root_ino"
150
151 #define SNAP_LOOKUP     (REINT_MAX + 1)
152
153 struct snap {
154         time_t          sn_time;
155         unsigned int    sn_index;
156         unsigned int    sn_gen;
157         unsigned int    sn_flags;
158         char    sn_name[SNAP_MAX_NAMELEN];
159 };
160
161 struct snap_table {
162         unsigned int    sntbl_magic;
163         unsigned int    sntbl_count;
164         unsigned int    sntbl_max_count;
165         unsigned int    sntbl_generation;
166         struct  snap    sntbl_items[0];
167 };
168
169 #define DOT_NAME_MAX_LEN 32 
170 struct snap_dot_info {
171         char    *dot_name;
172         int     dot_name_len;
173         int     dot_snap_enable; 
174 };
175
176 struct snap_info {
177         struct list_head         sni_list;
178         ino_t                    sni_root_ino;
179         struct semaphore         sni_sema;
180         spinlock_t               sni_lock;
181         struct snap_table        *sni_table;
182         struct dentry            *sni_cowed_dentry;
183         struct snap_dot_info     *sni_dot_info;
184 };
185
186 struct snap_super_info {
187         struct fsfilt_operations *snap_fsfilt;  
188         struct fsfilt_operations *snap_cache_fsfilt; 
189         struct list_head          snap_list;
190         int                       snap_table_size;
191 };
192
193 extern int smfs_add_snap_item(struct super_block *sb, char *path_name, 
194                               char *name);
195 extern int smfs_start_cow(struct super_block *sb);
196 extern int smfs_stop_cow(struct super_block *sb);
197
198 struct write_extents {
199        size_t w_count;
200        loff_t w_pos; 
201 };
202 int smfs_cow(struct inode *dir, struct dentry *dentry,
203              void *data1, void *data2, int op);
204 int smfs_cow_write_pre(struct inode *inode, void *de, void *data1, void *data2);
205 struct inode* smfs_cow_get_ind(struct inode *inode, int index);
206
207
208 #define DOT_SNAP_NAME          ".snap"
209 #define DOT_SNAP_INDEX         0xffff
210 static inline int smfs_primary_inode(struct inode *inode)
211 {
212         struct snap_inode_info *sn_info = &I2SMI(inode)->sm_sninfo;
213
214         if (sn_info->sn_index == 0)
215                 return 1; 
216         return 0; 
217 }
218 static inline int smfs_dotsnap_inode(struct inode *inode)
219 {
220         struct snap_inode_info *sn_info = &I2SMI(inode)->sm_sninfo;
221
222         if (sn_info->sn_index == DOT_SNAP_INDEX)
223                 return 1; 
224         return 0; 
225 }
226 static inline int smfs_under_dotsnap_inode(struct inode *inode)
227 {
228         struct snap_inode_info *sn_info = &I2SMI(inode)->sm_sninfo;
229         
230         if (sn_info->sn_index > 0 && sn_info->sn_index != DOT_SNAP_INDEX)
231                 return 1;
232         return 0; 
233 }
234 #define SNAP_MINOR 242
235 #define SNAP_MAJOR 10
236
237 #endif /*_LUSTRE_SNAP_H*/