1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc. <info@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
21 * SNAP data structures.
22 * See also lustre_idl.h for wire formats of requests.
25 /* maximum number of snapshots available for users */
27 #ifndef __LUSTRE_SNAP_H
28 #define __LUSTRE_SNAP_H
31 #define SNAP_ATTR "@snap"
36 ino_t ino[MAX_SNAPS+1]; /* including current snapshot */
37 ino_t parent_ino[MAX_SNAPS+1];
39 #define MAX_SNAP_DATA (sizeof(struct snap_ea))
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
46 #define IS_SNAP_EA(name) ( (!strcmp((name), SNAP_ATTR)) || \
47 (!strcmp((name), DISK_SNAP_META_ATTR)))
50 /* file system features */
51 #define SNAP_FEATURE_COMPAT_SNAPFS 0x0010
52 #define SNAP_FEATURE_COMPAT_BLOCKCOW 0x0020
54 /* constants for snap_feature operations */
55 #define SNAP_CLEAR_FEATURE 0x0
56 #define SNAP_SET_FEATURE 0x1
57 #define SNAP_HAS_FEATURE 0x2
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 */
66 /* no snapfs attributes for get_indirect_ino */
67 #define ENOSNAPATTR 320
69 /* constants used by iterator */
70 #define SNAP_ITERATE_ALL_INODE 0x0
71 #define SNAP_ITERATE_COWED_INODE 0x1
73 /* constants used by create_indirect */
74 #define SNAP_CREATE_IND_NORMAL 0x0
75 #define SNAP_CREATE_IND_DEL_PRI 0x1
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)
83 #define SIZEOF_MAGIC 1
85 #define SIZEOF_GENERATION 4
87 #define MAGIC_OFFSET 0
89 #define GENERATION_OFFSET 2
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) \
109 #define SNAP_VERSION_MINOR(v) \
111 #define SNAP_VERSION_REL(v) \
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)
141 #define SNAP_MAX_TABLES 32
142 #define SNAP_MAX_NAMELEN 64
144 #define MAX_SNAPTABLE_COUNT "MAXSnapCount"
145 #define SNAPTABLE_MAGIC 0x19760218
146 #define SNAPTABLE_INFO "snaptable"
147 #define SNAP_GENERATION "snap_generation"
150 #define SNAP_LOOKUP (REINT_MAX + 1)
154 unsigned int sn_index;
156 unsigned int sn_flags;
157 char sn_name[SNAP_MAX_NAMELEN];
161 unsigned int sntbl_magic;
162 unsigned int sntbl_count;
163 unsigned int sntbl_max_count;
164 unsigned int sntbl_generation;
165 struct snap sntbl_items[0];
168 struct snap_dot_info {
175 struct fsfilt_operations *snap_fsfilt;
176 struct fsfilt_operations *snap_cache_fsfilt;
177 struct dentry *snap_root;
178 struct semaphore sntbl_sema;
179 spinlock_t sntbl_lock;
180 struct snap_table *sntbl;
181 struct dentry *sn_cowed_dentry;
182 struct snap_dot_info *sn_dot_info;
186 extern int smfs_add_snap_item(struct super_block *sb, char *name);
187 extern int smfs_start_cow(struct super_block *sb);
188 extern int smfs_stop_cow(struct super_block *sb);
190 struct write_extents {
194 int smfs_cow(struct inode *dir, struct dentry *dentry,
195 void *data1, void *data2, int op);
196 int smfs_cow_write(struct inode *inode, struct dentry *dentry, void *data1,
198 struct inode* smfs_cow_get_ind(struct inode *inode, int index);
199 #endif /*_LUSTRE_SNAP_H*/