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) \
117 #define SNAP_MAX_TABLES 32
118 #define SNAP_MAX_NAMELEN 64
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"
127 #define SNAP_LOOKUP (REINT_MAX + 1)
131 unsigned int sn_index;
133 unsigned int sn_flags;
134 char sn_name[SNAP_MAX_NAMELEN];
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];
145 #define DOT_NAME_MAX_LEN 32
146 struct snap_dot_info {
153 struct list_head sni_list;
155 struct semaphore sni_sema;
157 struct snap_table *sni_table;
158 struct dentry *sni_cowed_dentry;
159 struct snap_dot_info *sni_dot_info;
162 struct snap_super_info {
163 struct fsfilt_operations *snap_fsfilt;
164 struct fsfilt_operations *snap_cache_fsfilt;
165 struct list_head snap_list;
170 extern int smfs_add_snap_item(struct super_block *sb, char *path_name,
172 extern int smfs_start_cow(struct super_block *sb);
173 extern int smfs_stop_cow(struct super_block *sb);
175 struct write_extents {
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);
185 #define DOT_SNAP_NAME ".snap"
186 #define DOT_SNAP_INDEX 0xffff
187 static inline int smfs_primary_inode(struct inode *inode)
189 struct snap_inode_info *sn_info = &I2SMI(inode)->sm_sninfo;
191 if (sn_info->sn_index == 0)
195 static inline int smfs_dotsnap_inode(struct inode *inode)
197 struct snap_inode_info *sn_info = &I2SMI(inode)->sm_sninfo;
199 if (sn_info->sn_index == DOT_SNAP_INDEX)
203 static inline int smfs_under_dotsnap_inode(struct inode *inode)
205 struct snap_inode_info *sn_info = &I2SMI(inode)->sm_sninfo;
207 if (sn_info->sn_index > 0 && sn_info->sn_index != DOT_SNAP_INDEX)
211 #define SNAP_MINOR 242
212 #define SNAP_MAJOR 10
214 #endif /*_LUSTRE_SNAP_H*/