Whamcloud - gitweb
Update snapfs
[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 SNAP_TABLE_MAGIC        0x19760218
146 #define SNAPTABLE_INFO          "snaptable"
147 #define SNAP_GENERATION         "snap_generation"
148 struct snap {
149         time_t          sn_time;
150         unsigned int    sn_index;
151         unsigned int    sn_gen;
152         unsigned int    sn_flags;
153         char    name[SNAP_MAX_NAMELEN];
154 };
155
156 struct snap_table {
157         unsigned int    sntbl_magic;
158         unsigned int    sntbl_count;
159         unsigned int    sntbl_max_count;
160         unsigned int    sntbl_generation;
161         struct  snap    sntbl_items[0];
162 };
163
164 struct snap_info {
165         struct fsfilt_operations *snap_fsfilt;  
166         struct fsfilt_operations *snap_cache_fsfilt;  
167         struct semaphore         sntbl_sema;
168         spinlock_t               sntbl_lock;
169         struct snap_table        *sntbl;
170 };
171
172 #endif /*_LUSTRE_SNAP_H*/