Whamcloud - gitweb
- landing b_fid.
[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 /*Snap Table*/
116 #define SNAP_MAX                32      
117 #define SNAP_MAX_TABLES         32      
118 #define SNAP_MAX_NAMELEN        64
119
120 #define MAX_SNAPTABLE_COUNT  "MAXSnapCount"
121 #define SNAPTABLE_MAGIC      0x19760218
122 #define SNAPTABLE_INFO       "snaptable"
123 #define SNAP_GENERATION      "snap_generation"
124 #define SNAP_COUNT           "snapcount"
125 #define SNAP_ROOT_INO        "snap_root_ino"
126
127 #define SNAP_LOOKUP     (REINT_MAX + 1)
128
129 struct snap {
130         time_t          sn_time;
131         unsigned int    sn_index;
132         unsigned int    sn_gen;
133         unsigned int    sn_flags;
134         char    sn_name[SNAP_MAX_NAMELEN];
135 };
136
137 struct snap_table {
138         unsigned int    sntbl_magic;
139         unsigned int    sntbl_count;
140         unsigned int    sntbl_max_count;
141         unsigned int    sntbl_generation;
142         struct  snap    sntbl_items[0];
143 };
144
145 #define DOT_NAME_MAX_LEN 32 
146 struct snap_dot_info {
147         char    *dot_name;
148         int     dot_name_len;
149         int     dot_snap_enable; 
150 };
151
152 struct snap_info {
153         struct list_head         sni_list;
154         ino_t                    sni_root_ino;
155         struct semaphore         sni_sema;
156         spinlock_t               sni_lock;
157         struct snap_table        *sni_table;
158         struct dentry            *sni_cowed_dentry;
159         struct snap_dot_info     *sni_dot_info;
160 };
161
162 struct snap_super_info {
163         struct fsfilt_operations *snap_fsfilt;  
164         struct fsfilt_operations *snap_cache_fsfilt; 
165         struct list_head          snap_list;
166         int                       snap_table_size;
167         int                       snap_count;
168 };
169
170 extern int smfs_add_snap_item(struct super_block *sb, char *path_name, 
171                               char *name);
172 extern int smfs_start_cow(struct super_block *sb);
173 extern int smfs_stop_cow(struct super_block *sb);
174
175 struct write_extents {
176        size_t w_count;
177        loff_t w_pos; 
178 };
179 int smfs_cow(struct inode *dir, struct dentry *dentry,
180              void *data1, void *data2, int op);
181 int smfs_cow_write_pre(struct inode *inode, void *de, void *data1, void *data2);
182 struct inode* smfs_cow_get_ind(struct inode *inode, int index);
183
184
185 #define DOT_SNAP_NAME          ".snap"
186 #define DOT_SNAP_INDEX         0xffff
187 static inline int smfs_primary_inode(struct inode *inode)
188 {
189         struct snap_inode_info *sn_info = &I2SMI(inode)->sm_sninfo;
190
191         if (sn_info->sn_index == 0)
192                 return 1; 
193         return 0; 
194 }
195 static inline int smfs_dotsnap_inode(struct inode *inode)
196 {
197         struct snap_inode_info *sn_info = &I2SMI(inode)->sm_sninfo;
198
199         if (sn_info->sn_index == DOT_SNAP_INDEX)
200                 return 1; 
201         return 0; 
202 }
203 static inline int smfs_under_dotsnap_inode(struct inode *inode)
204 {
205         struct snap_inode_info *sn_info = &I2SMI(inode)->sm_sninfo;
206         
207         if (sn_info->sn_index > 0 && sn_info->sn_index != DOT_SNAP_INDEX)
208                 return 1;
209         return 0; 
210 }
211 #define SNAP_MINOR 242
212 #define SNAP_MAJOR 10
213
214 #endif /*_LUSTRE_SNAP_H*/