Commit ab17c4f02156c4f75d7fa43a5aa2a7f942d47201
Committed by
Al Viro
1 parent
edcc37a047
Exists in
master
and in
20 other branches
reiserfs: fixup xattr_root caching
The xattr_root caching was broken from my previous patch set. It wouldn't cause corruption, but could cause decreased performance due to allocating a larger chunk of the journal (~ 27 blocks) than it would actually use. This patch loads the xattr root dentry at xattr initialization and creates it on-demand. Since we're using the cached dentry, there's no point in keeping lookup_or_create_dir around, so that's removed. Signed-off-by: Jeff Mahoney <jeffm@suse.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Showing 3 changed files with 48 additions and 29 deletions Inline Diff
fs/reiserfs/xattr.c
1 | /* | 1 | /* |
2 | * linux/fs/reiserfs/xattr.c | 2 | * linux/fs/reiserfs/xattr.c |
3 | * | 3 | * |
4 | * Copyright (c) 2002 by Jeff Mahoney, <jeffm@suse.com> | 4 | * Copyright (c) 2002 by Jeff Mahoney, <jeffm@suse.com> |
5 | * | 5 | * |
6 | */ | 6 | */ |
7 | 7 | ||
8 | /* | 8 | /* |
9 | * In order to implement EA/ACLs in a clean, backwards compatible manner, | 9 | * In order to implement EA/ACLs in a clean, backwards compatible manner, |
10 | * they are implemented as files in a "private" directory. | 10 | * they are implemented as files in a "private" directory. |
11 | * Each EA is in it's own file, with the directory layout like so (/ is assumed | 11 | * Each EA is in it's own file, with the directory layout like so (/ is assumed |
12 | * to be relative to fs root). Inside the /.reiserfs_priv/xattrs directory, | 12 | * to be relative to fs root). Inside the /.reiserfs_priv/xattrs directory, |
13 | * directories named using the capital-hex form of the objectid and | 13 | * directories named using the capital-hex form of the objectid and |
14 | * generation number are used. Inside each directory are individual files | 14 | * generation number are used. Inside each directory are individual files |
15 | * named with the name of the extended attribute. | 15 | * named with the name of the extended attribute. |
16 | * | 16 | * |
17 | * So, for objectid 12648430, we could have: | 17 | * So, for objectid 12648430, we could have: |
18 | * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_access | 18 | * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_access |
19 | * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_default | 19 | * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_default |
20 | * /.reiserfs_priv/xattrs/C0FFEE.0/user.Content-Type | 20 | * /.reiserfs_priv/xattrs/C0FFEE.0/user.Content-Type |
21 | * .. or similar. | 21 | * .. or similar. |
22 | * | 22 | * |
23 | * The file contents are the text of the EA. The size is known based on the | 23 | * The file contents are the text of the EA. The size is known based on the |
24 | * stat data describing the file. | 24 | * stat data describing the file. |
25 | * | 25 | * |
26 | * In the case of system.posix_acl_access and system.posix_acl_default, since | 26 | * In the case of system.posix_acl_access and system.posix_acl_default, since |
27 | * these are special cases for filesystem ACLs, they are interpreted by the | 27 | * these are special cases for filesystem ACLs, they are interpreted by the |
28 | * kernel, in addition, they are negatively and positively cached and attached | 28 | * kernel, in addition, they are negatively and positively cached and attached |
29 | * to the inode so that unnecessary lookups are avoided. | 29 | * to the inode so that unnecessary lookups are avoided. |
30 | * | 30 | * |
31 | * Locking works like so: | 31 | * Locking works like so: |
32 | * Directory components (xattr root, xattr dir) are protectd by their i_mutex. | 32 | * Directory components (xattr root, xattr dir) are protectd by their i_mutex. |
33 | * The xattrs themselves are protected by the xattr_sem. | 33 | * The xattrs themselves are protected by the xattr_sem. |
34 | */ | 34 | */ |
35 | 35 | ||
36 | #include <linux/reiserfs_fs.h> | 36 | #include <linux/reiserfs_fs.h> |
37 | #include <linux/capability.h> | 37 | #include <linux/capability.h> |
38 | #include <linux/dcache.h> | 38 | #include <linux/dcache.h> |
39 | #include <linux/namei.h> | 39 | #include <linux/namei.h> |
40 | #include <linux/errno.h> | 40 | #include <linux/errno.h> |
41 | #include <linux/fs.h> | 41 | #include <linux/fs.h> |
42 | #include <linux/file.h> | 42 | #include <linux/file.h> |
43 | #include <linux/pagemap.h> | 43 | #include <linux/pagemap.h> |
44 | #include <linux/xattr.h> | 44 | #include <linux/xattr.h> |
45 | #include <linux/reiserfs_xattr.h> | 45 | #include <linux/reiserfs_xattr.h> |
46 | #include <linux/reiserfs_acl.h> | 46 | #include <linux/reiserfs_acl.h> |
47 | #include <asm/uaccess.h> | 47 | #include <asm/uaccess.h> |
48 | #include <net/checksum.h> | 48 | #include <net/checksum.h> |
49 | #include <linux/smp_lock.h> | 49 | #include <linux/smp_lock.h> |
50 | #include <linux/stat.h> | 50 | #include <linux/stat.h> |
51 | #include <linux/quotaops.h> | 51 | #include <linux/quotaops.h> |
52 | 52 | ||
53 | #define PRIVROOT_NAME ".reiserfs_priv" | 53 | #define PRIVROOT_NAME ".reiserfs_priv" |
54 | #define XAROOT_NAME "xattrs" | 54 | #define XAROOT_NAME "xattrs" |
55 | 55 | ||
56 | 56 | ||
57 | /* Helpers for inode ops. We do this so that we don't have all the VFS | 57 | /* Helpers for inode ops. We do this so that we don't have all the VFS |
58 | * overhead and also for proper i_mutex annotation. | 58 | * overhead and also for proper i_mutex annotation. |
59 | * dir->i_mutex must be held for all of them. */ | 59 | * dir->i_mutex must be held for all of them. */ |
60 | #ifdef CONFIG_REISERFS_FS_XATTR | 60 | #ifdef CONFIG_REISERFS_FS_XATTR |
61 | static int xattr_create(struct inode *dir, struct dentry *dentry, int mode) | 61 | static int xattr_create(struct inode *dir, struct dentry *dentry, int mode) |
62 | { | 62 | { |
63 | BUG_ON(!mutex_is_locked(&dir->i_mutex)); | 63 | BUG_ON(!mutex_is_locked(&dir->i_mutex)); |
64 | vfs_dq_init(dir); | 64 | vfs_dq_init(dir); |
65 | return dir->i_op->create(dir, dentry, mode, NULL); | 65 | return dir->i_op->create(dir, dentry, mode, NULL); |
66 | } | 66 | } |
67 | #endif | 67 | #endif |
68 | 68 | ||
69 | static int xattr_mkdir(struct inode *dir, struct dentry *dentry, int mode) | 69 | static int xattr_mkdir(struct inode *dir, struct dentry *dentry, int mode) |
70 | { | 70 | { |
71 | BUG_ON(!mutex_is_locked(&dir->i_mutex)); | 71 | BUG_ON(!mutex_is_locked(&dir->i_mutex)); |
72 | vfs_dq_init(dir); | 72 | vfs_dq_init(dir); |
73 | return dir->i_op->mkdir(dir, dentry, mode); | 73 | return dir->i_op->mkdir(dir, dentry, mode); |
74 | } | 74 | } |
75 | 75 | ||
76 | /* We use I_MUTEX_CHILD here to silence lockdep. It's safe because xattr | 76 | /* We use I_MUTEX_CHILD here to silence lockdep. It's safe because xattr |
77 | * mutation ops aren't called during rename or splace, which are the | 77 | * mutation ops aren't called during rename or splace, which are the |
78 | * only other users of I_MUTEX_CHILD. It violates the ordering, but that's | 78 | * only other users of I_MUTEX_CHILD. It violates the ordering, but that's |
79 | * better than allocating another subclass just for this code. */ | 79 | * better than allocating another subclass just for this code. */ |
80 | static int xattr_unlink(struct inode *dir, struct dentry *dentry) | 80 | static int xattr_unlink(struct inode *dir, struct dentry *dentry) |
81 | { | 81 | { |
82 | int error; | 82 | int error; |
83 | BUG_ON(!mutex_is_locked(&dir->i_mutex)); | 83 | BUG_ON(!mutex_is_locked(&dir->i_mutex)); |
84 | vfs_dq_init(dir); | 84 | vfs_dq_init(dir); |
85 | 85 | ||
86 | mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD); | 86 | mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD); |
87 | error = dir->i_op->unlink(dir, dentry); | 87 | error = dir->i_op->unlink(dir, dentry); |
88 | mutex_unlock(&dentry->d_inode->i_mutex); | 88 | mutex_unlock(&dentry->d_inode->i_mutex); |
89 | 89 | ||
90 | if (!error) | 90 | if (!error) |
91 | d_delete(dentry); | 91 | d_delete(dentry); |
92 | return error; | 92 | return error; |
93 | } | 93 | } |
94 | 94 | ||
95 | static int xattr_rmdir(struct inode *dir, struct dentry *dentry) | 95 | static int xattr_rmdir(struct inode *dir, struct dentry *dentry) |
96 | { | 96 | { |
97 | int error; | 97 | int error; |
98 | BUG_ON(!mutex_is_locked(&dir->i_mutex)); | 98 | BUG_ON(!mutex_is_locked(&dir->i_mutex)); |
99 | vfs_dq_init(dir); | 99 | vfs_dq_init(dir); |
100 | 100 | ||
101 | mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD); | 101 | mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD); |
102 | dentry_unhash(dentry); | 102 | dentry_unhash(dentry); |
103 | error = dir->i_op->rmdir(dir, dentry); | 103 | error = dir->i_op->rmdir(dir, dentry); |
104 | if (!error) | 104 | if (!error) |
105 | dentry->d_inode->i_flags |= S_DEAD; | 105 | dentry->d_inode->i_flags |= S_DEAD; |
106 | mutex_unlock(&dentry->d_inode->i_mutex); | 106 | mutex_unlock(&dentry->d_inode->i_mutex); |
107 | if (!error) | 107 | if (!error) |
108 | d_delete(dentry); | 108 | d_delete(dentry); |
109 | dput(dentry); | 109 | dput(dentry); |
110 | 110 | ||
111 | return error; | 111 | return error; |
112 | } | 112 | } |
113 | 113 | ||
114 | #define xattr_may_create(flags) (!flags || flags & XATTR_CREATE) | 114 | #define xattr_may_create(flags) (!flags || flags & XATTR_CREATE) |
115 | 115 | ||
116 | /* Returns and possibly creates the xattr dir. */ | 116 | static struct dentry *open_xa_root(struct super_block *sb, int flags) |
117 | static struct dentry *lookup_or_create_dir(struct dentry *parent, | ||
118 | const char *name, int flags) | ||
119 | { | 117 | { |
120 | struct dentry *dentry; | 118 | struct dentry *privroot = REISERFS_SB(sb)->priv_root; |
121 | BUG_ON(!parent); | 119 | struct dentry *xaroot; |
120 | if (!privroot->d_inode) | ||
121 | return ERR_PTR(-ENODATA); | ||
122 | 122 | ||
123 | mutex_lock_nested(&parent->d_inode->i_mutex, I_MUTEX_XATTR); | 123 | mutex_lock_nested(&privroot->d_inode->i_mutex, I_MUTEX_XATTR); |
124 | dentry = lookup_one_len(name, parent, strlen(name)); | ||
125 | if (!IS_ERR(dentry) && !dentry->d_inode) { | ||
126 | int err = -ENODATA; | ||
127 | 124 | ||
125 | xaroot = dget(REISERFS_SB(sb)->xattr_root); | ||
126 | if (!xaroot->d_inode) { | ||
127 | int err = -ENODATA; | ||
128 | if (xattr_may_create(flags)) | 128 | if (xattr_may_create(flags)) |
129 | err = xattr_mkdir(parent->d_inode, dentry, 0700); | 129 | err = xattr_mkdir(privroot->d_inode, xaroot, 0700); |
130 | |||
131 | if (err) { | 130 | if (err) { |
132 | dput(dentry); | 131 | dput(xaroot); |
133 | dentry = ERR_PTR(err); | 132 | xaroot = ERR_PTR(err); |
134 | } | 133 | } |
135 | } | 134 | } |
136 | mutex_unlock(&parent->d_inode->i_mutex); | ||
137 | return dentry; | ||
138 | } | ||
139 | 135 | ||
140 | static struct dentry *open_xa_root(struct super_block *sb, int flags) | 136 | mutex_unlock(&privroot->d_inode->i_mutex); |
141 | { | 137 | return xaroot; |
142 | struct dentry *privroot = REISERFS_SB(sb)->priv_root; | ||
143 | if (!privroot) | ||
144 | return ERR_PTR(-ENODATA); | ||
145 | return lookup_or_create_dir(privroot, XAROOT_NAME, flags); | ||
146 | } | 138 | } |
147 | 139 | ||
148 | static struct dentry *open_xa_dir(const struct inode *inode, int flags) | 140 | static struct dentry *open_xa_dir(const struct inode *inode, int flags) |
149 | { | 141 | { |
150 | struct dentry *xaroot, *xadir; | 142 | struct dentry *xaroot, *xadir; |
151 | char namebuf[17]; | 143 | char namebuf[17]; |
152 | 144 | ||
153 | xaroot = open_xa_root(inode->i_sb, flags); | 145 | xaroot = open_xa_root(inode->i_sb, flags); |
154 | if (IS_ERR(xaroot)) | 146 | if (IS_ERR(xaroot)) |
155 | return xaroot; | 147 | return xaroot; |
156 | 148 | ||
157 | snprintf(namebuf, sizeof(namebuf), "%X.%X", | 149 | snprintf(namebuf, sizeof(namebuf), "%X.%X", |
158 | le32_to_cpu(INODE_PKEY(inode)->k_objectid), | 150 | le32_to_cpu(INODE_PKEY(inode)->k_objectid), |
159 | inode->i_generation); | 151 | inode->i_generation); |
160 | 152 | ||
161 | xadir = lookup_or_create_dir(xaroot, namebuf, flags); | 153 | mutex_lock_nested(&xaroot->d_inode->i_mutex, I_MUTEX_XATTR); |
154 | |||
155 | xadir = lookup_one_len(namebuf, xaroot, strlen(namebuf)); | ||
156 | if (!IS_ERR(xadir) && !xadir->d_inode) { | ||
157 | int err = -ENODATA; | ||
158 | if (xattr_may_create(flags)) | ||
159 | err = xattr_mkdir(xaroot->d_inode, xadir, 0700); | ||
160 | if (err) { | ||
161 | dput(xadir); | ||
162 | xadir = ERR_PTR(err); | ||
163 | } | ||
164 | } | ||
165 | |||
166 | mutex_unlock(&xaroot->d_inode->i_mutex); | ||
162 | dput(xaroot); | 167 | dput(xaroot); |
163 | return xadir; | 168 | return xadir; |
164 | |||
165 | } | 169 | } |
166 | 170 | ||
167 | /* The following are side effects of other operations that aren't explicitly | 171 | /* The following are side effects of other operations that aren't explicitly |
168 | * modifying extended attributes. This includes operations such as permissions | 172 | * modifying extended attributes. This includes operations such as permissions |
169 | * or ownership changes, object deletions, etc. */ | 173 | * or ownership changes, object deletions, etc. */ |
170 | struct reiserfs_dentry_buf { | 174 | struct reiserfs_dentry_buf { |
171 | struct dentry *xadir; | 175 | struct dentry *xadir; |
172 | int count; | 176 | int count; |
173 | struct dentry *dentries[8]; | 177 | struct dentry *dentries[8]; |
174 | }; | 178 | }; |
175 | 179 | ||
176 | static int | 180 | static int |
177 | fill_with_dentries(void *buf, const char *name, int namelen, loff_t offset, | 181 | fill_with_dentries(void *buf, const char *name, int namelen, loff_t offset, |
178 | u64 ino, unsigned int d_type) | 182 | u64 ino, unsigned int d_type) |
179 | { | 183 | { |
180 | struct reiserfs_dentry_buf *dbuf = buf; | 184 | struct reiserfs_dentry_buf *dbuf = buf; |
181 | struct dentry *dentry; | 185 | struct dentry *dentry; |
182 | WARN_ON_ONCE(!mutex_is_locked(&dbuf->xadir->d_inode->i_mutex)); | 186 | WARN_ON_ONCE(!mutex_is_locked(&dbuf->xadir->d_inode->i_mutex)); |
183 | 187 | ||
184 | if (dbuf->count == ARRAY_SIZE(dbuf->dentries)) | 188 | if (dbuf->count == ARRAY_SIZE(dbuf->dentries)) |
185 | return -ENOSPC; | 189 | return -ENOSPC; |
186 | 190 | ||
187 | if (name[0] == '.' && (name[1] == '\0' || | 191 | if (name[0] == '.' && (name[1] == '\0' || |
188 | (name[1] == '.' && name[2] == '\0'))) | 192 | (name[1] == '.' && name[2] == '\0'))) |
189 | return 0; | 193 | return 0; |
190 | 194 | ||
191 | dentry = lookup_one_len(name, dbuf->xadir, namelen); | 195 | dentry = lookup_one_len(name, dbuf->xadir, namelen); |
192 | if (IS_ERR(dentry)) { | 196 | if (IS_ERR(dentry)) { |
193 | return PTR_ERR(dentry); | 197 | return PTR_ERR(dentry); |
194 | } else if (!dentry->d_inode) { | 198 | } else if (!dentry->d_inode) { |
195 | /* A directory entry exists, but no file? */ | 199 | /* A directory entry exists, but no file? */ |
196 | reiserfs_error(dentry->d_sb, "xattr-20003", | 200 | reiserfs_error(dentry->d_sb, "xattr-20003", |
197 | "Corrupted directory: xattr %s listed but " | 201 | "Corrupted directory: xattr %s listed but " |
198 | "not found for file %s.\n", | 202 | "not found for file %s.\n", |
199 | dentry->d_name.name, dbuf->xadir->d_name.name); | 203 | dentry->d_name.name, dbuf->xadir->d_name.name); |
200 | dput(dentry); | 204 | dput(dentry); |
201 | return -EIO; | 205 | return -EIO; |
202 | } | 206 | } |
203 | 207 | ||
204 | dbuf->dentries[dbuf->count++] = dentry; | 208 | dbuf->dentries[dbuf->count++] = dentry; |
205 | return 0; | 209 | return 0; |
206 | } | 210 | } |
207 | 211 | ||
208 | static void | 212 | static void |
209 | cleanup_dentry_buf(struct reiserfs_dentry_buf *buf) | 213 | cleanup_dentry_buf(struct reiserfs_dentry_buf *buf) |
210 | { | 214 | { |
211 | int i; | 215 | int i; |
212 | for (i = 0; i < buf->count; i++) | 216 | for (i = 0; i < buf->count; i++) |
213 | if (buf->dentries[i]) | 217 | if (buf->dentries[i]) |
214 | dput(buf->dentries[i]); | 218 | dput(buf->dentries[i]); |
215 | } | 219 | } |
216 | 220 | ||
217 | static int reiserfs_for_each_xattr(struct inode *inode, | 221 | static int reiserfs_for_each_xattr(struct inode *inode, |
218 | int (*action)(struct dentry *, void *), | 222 | int (*action)(struct dentry *, void *), |
219 | void *data) | 223 | void *data) |
220 | { | 224 | { |
221 | struct dentry *dir; | 225 | struct dentry *dir; |
222 | int i, err = 0; | 226 | int i, err = 0; |
223 | loff_t pos = 0; | 227 | loff_t pos = 0; |
224 | struct reiserfs_dentry_buf buf = { | 228 | struct reiserfs_dentry_buf buf = { |
225 | .count = 0, | 229 | .count = 0, |
226 | }; | 230 | }; |
227 | 231 | ||
228 | /* Skip out, an xattr has no xattrs associated with it */ | 232 | /* Skip out, an xattr has no xattrs associated with it */ |
229 | if (IS_PRIVATE(inode) || get_inode_sd_version(inode) == STAT_DATA_V1) | 233 | if (IS_PRIVATE(inode) || get_inode_sd_version(inode) == STAT_DATA_V1) |
230 | return 0; | 234 | return 0; |
231 | 235 | ||
232 | dir = open_xa_dir(inode, XATTR_REPLACE); | 236 | dir = open_xa_dir(inode, XATTR_REPLACE); |
233 | if (IS_ERR(dir)) { | 237 | if (IS_ERR(dir)) { |
234 | err = PTR_ERR(dir); | 238 | err = PTR_ERR(dir); |
235 | goto out; | 239 | goto out; |
236 | } else if (!dir->d_inode) { | 240 | } else if (!dir->d_inode) { |
237 | err = 0; | 241 | err = 0; |
238 | goto out_dir; | 242 | goto out_dir; |
239 | } | 243 | } |
240 | 244 | ||
241 | mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR); | 245 | mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR); |
242 | buf.xadir = dir; | 246 | buf.xadir = dir; |
243 | err = reiserfs_readdir_dentry(dir, &buf, fill_with_dentries, &pos); | 247 | err = reiserfs_readdir_dentry(dir, &buf, fill_with_dentries, &pos); |
244 | while ((err == 0 || err == -ENOSPC) && buf.count) { | 248 | while ((err == 0 || err == -ENOSPC) && buf.count) { |
245 | err = 0; | 249 | err = 0; |
246 | 250 | ||
247 | for (i = 0; i < buf.count && buf.dentries[i]; i++) { | 251 | for (i = 0; i < buf.count && buf.dentries[i]; i++) { |
248 | int lerr = 0; | 252 | int lerr = 0; |
249 | struct dentry *dentry = buf.dentries[i]; | 253 | struct dentry *dentry = buf.dentries[i]; |
250 | 254 | ||
251 | if (err == 0 && !S_ISDIR(dentry->d_inode->i_mode)) | 255 | if (err == 0 && !S_ISDIR(dentry->d_inode->i_mode)) |
252 | lerr = action(dentry, data); | 256 | lerr = action(dentry, data); |
253 | 257 | ||
254 | dput(dentry); | 258 | dput(dentry); |
255 | buf.dentries[i] = NULL; | 259 | buf.dentries[i] = NULL; |
256 | err = lerr ?: err; | 260 | err = lerr ?: err; |
257 | } | 261 | } |
258 | buf.count = 0; | 262 | buf.count = 0; |
259 | if (!err) | 263 | if (!err) |
260 | err = reiserfs_readdir_dentry(dir, &buf, | 264 | err = reiserfs_readdir_dentry(dir, &buf, |
261 | fill_with_dentries, &pos); | 265 | fill_with_dentries, &pos); |
262 | } | 266 | } |
263 | mutex_unlock(&dir->d_inode->i_mutex); | 267 | mutex_unlock(&dir->d_inode->i_mutex); |
264 | 268 | ||
265 | /* Clean up after a failed readdir */ | 269 | /* Clean up after a failed readdir */ |
266 | cleanup_dentry_buf(&buf); | 270 | cleanup_dentry_buf(&buf); |
267 | 271 | ||
268 | if (!err) { | 272 | if (!err) { |
269 | /* We start a transaction here to avoid a ABBA situation | 273 | /* We start a transaction here to avoid a ABBA situation |
270 | * between the xattr root's i_mutex and the journal lock. | 274 | * between the xattr root's i_mutex and the journal lock. |
271 | * This doesn't incur much additional overhead since the | 275 | * This doesn't incur much additional overhead since the |
272 | * new transaction will just nest inside the | 276 | * new transaction will just nest inside the |
273 | * outer transaction. */ | 277 | * outer transaction. */ |
274 | int blocks = JOURNAL_PER_BALANCE_CNT * 2 + 2 + | 278 | int blocks = JOURNAL_PER_BALANCE_CNT * 2 + 2 + |
275 | 4 * REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb); | 279 | 4 * REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb); |
276 | struct reiserfs_transaction_handle th; | 280 | struct reiserfs_transaction_handle th; |
277 | err = journal_begin(&th, inode->i_sb, blocks); | 281 | err = journal_begin(&th, inode->i_sb, blocks); |
278 | if (!err) { | 282 | if (!err) { |
279 | int jerror; | 283 | int jerror; |
280 | mutex_lock_nested(&dir->d_parent->d_inode->i_mutex, | 284 | mutex_lock_nested(&dir->d_parent->d_inode->i_mutex, |
281 | I_MUTEX_XATTR); | 285 | I_MUTEX_XATTR); |
282 | err = action(dir, data); | 286 | err = action(dir, data); |
283 | jerror = journal_end(&th, inode->i_sb, blocks); | 287 | jerror = journal_end(&th, inode->i_sb, blocks); |
284 | mutex_unlock(&dir->d_parent->d_inode->i_mutex); | 288 | mutex_unlock(&dir->d_parent->d_inode->i_mutex); |
285 | err = jerror ?: err; | 289 | err = jerror ?: err; |
286 | } | 290 | } |
287 | } | 291 | } |
288 | out_dir: | 292 | out_dir: |
289 | dput(dir); | 293 | dput(dir); |
290 | out: | 294 | out: |
291 | /* -ENODATA isn't an error */ | 295 | /* -ENODATA isn't an error */ |
292 | if (err == -ENODATA) | 296 | if (err == -ENODATA) |
293 | err = 0; | 297 | err = 0; |
294 | return err; | 298 | return err; |
295 | } | 299 | } |
296 | 300 | ||
297 | static int delete_one_xattr(struct dentry *dentry, void *data) | 301 | static int delete_one_xattr(struct dentry *dentry, void *data) |
298 | { | 302 | { |
299 | struct inode *dir = dentry->d_parent->d_inode; | 303 | struct inode *dir = dentry->d_parent->d_inode; |
300 | 304 | ||
301 | /* This is the xattr dir, handle specially. */ | 305 | /* This is the xattr dir, handle specially. */ |
302 | if (S_ISDIR(dentry->d_inode->i_mode)) | 306 | if (S_ISDIR(dentry->d_inode->i_mode)) |
303 | return xattr_rmdir(dir, dentry); | 307 | return xattr_rmdir(dir, dentry); |
304 | 308 | ||
305 | return xattr_unlink(dir, dentry); | 309 | return xattr_unlink(dir, dentry); |
306 | } | 310 | } |
307 | 311 | ||
308 | static int chown_one_xattr(struct dentry *dentry, void *data) | 312 | static int chown_one_xattr(struct dentry *dentry, void *data) |
309 | { | 313 | { |
310 | struct iattr *attrs = data; | 314 | struct iattr *attrs = data; |
311 | return reiserfs_setattr(dentry, attrs); | 315 | return reiserfs_setattr(dentry, attrs); |
312 | } | 316 | } |
313 | 317 | ||
314 | /* No i_mutex, but the inode is unconnected. */ | 318 | /* No i_mutex, but the inode is unconnected. */ |
315 | int reiserfs_delete_xattrs(struct inode *inode) | 319 | int reiserfs_delete_xattrs(struct inode *inode) |
316 | { | 320 | { |
317 | int err = reiserfs_for_each_xattr(inode, delete_one_xattr, NULL); | 321 | int err = reiserfs_for_each_xattr(inode, delete_one_xattr, NULL); |
318 | if (err) | 322 | if (err) |
319 | reiserfs_warning(inode->i_sb, "jdm-20004", | 323 | reiserfs_warning(inode->i_sb, "jdm-20004", |
320 | "Couldn't delete all xattrs (%d)\n", err); | 324 | "Couldn't delete all xattrs (%d)\n", err); |
321 | return err; | 325 | return err; |
322 | } | 326 | } |
323 | 327 | ||
324 | /* inode->i_mutex: down */ | 328 | /* inode->i_mutex: down */ |
325 | int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs) | 329 | int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs) |
326 | { | 330 | { |
327 | int err = reiserfs_for_each_xattr(inode, chown_one_xattr, attrs); | 331 | int err = reiserfs_for_each_xattr(inode, chown_one_xattr, attrs); |
328 | if (err) | 332 | if (err) |
329 | reiserfs_warning(inode->i_sb, "jdm-20007", | 333 | reiserfs_warning(inode->i_sb, "jdm-20007", |
330 | "Couldn't chown all xattrs (%d)\n", err); | 334 | "Couldn't chown all xattrs (%d)\n", err); |
331 | return err; | 335 | return err; |
332 | } | 336 | } |
333 | 337 | ||
334 | #ifdef CONFIG_REISERFS_FS_XATTR | 338 | #ifdef CONFIG_REISERFS_FS_XATTR |
335 | /* Returns a dentry corresponding to a specific extended attribute file | 339 | /* Returns a dentry corresponding to a specific extended attribute file |
336 | * for the inode. If flags allow, the file is created. Otherwise, a | 340 | * for the inode. If flags allow, the file is created. Otherwise, a |
337 | * valid or negative dentry, or an error is returned. */ | 341 | * valid or negative dentry, or an error is returned. */ |
338 | static struct dentry *xattr_lookup(struct inode *inode, const char *name, | 342 | static struct dentry *xattr_lookup(struct inode *inode, const char *name, |
339 | int flags) | 343 | int flags) |
340 | { | 344 | { |
341 | struct dentry *xadir, *xafile; | 345 | struct dentry *xadir, *xafile; |
342 | int err = 0; | 346 | int err = 0; |
343 | 347 | ||
344 | xadir = open_xa_dir(inode, flags); | 348 | xadir = open_xa_dir(inode, flags); |
345 | if (IS_ERR(xadir)) | 349 | if (IS_ERR(xadir)) |
346 | return ERR_CAST(xadir); | 350 | return ERR_CAST(xadir); |
347 | 351 | ||
348 | mutex_lock_nested(&xadir->d_inode->i_mutex, I_MUTEX_XATTR); | 352 | mutex_lock_nested(&xadir->d_inode->i_mutex, I_MUTEX_XATTR); |
349 | xafile = lookup_one_len(name, xadir, strlen(name)); | 353 | xafile = lookup_one_len(name, xadir, strlen(name)); |
350 | if (IS_ERR(xafile)) { | 354 | if (IS_ERR(xafile)) { |
351 | err = PTR_ERR(xafile); | 355 | err = PTR_ERR(xafile); |
352 | goto out; | 356 | goto out; |
353 | } | 357 | } |
354 | 358 | ||
355 | if (xafile->d_inode && (flags & XATTR_CREATE)) | 359 | if (xafile->d_inode && (flags & XATTR_CREATE)) |
356 | err = -EEXIST; | 360 | err = -EEXIST; |
357 | 361 | ||
358 | if (!xafile->d_inode) { | 362 | if (!xafile->d_inode) { |
359 | err = -ENODATA; | 363 | err = -ENODATA; |
360 | if (xattr_may_create(flags)) | 364 | if (xattr_may_create(flags)) |
361 | err = xattr_create(xadir->d_inode, xafile, | 365 | err = xattr_create(xadir->d_inode, xafile, |
362 | 0700|S_IFREG); | 366 | 0700|S_IFREG); |
363 | } | 367 | } |
364 | 368 | ||
365 | if (err) | 369 | if (err) |
366 | dput(xafile); | 370 | dput(xafile); |
367 | out: | 371 | out: |
368 | mutex_unlock(&xadir->d_inode->i_mutex); | 372 | mutex_unlock(&xadir->d_inode->i_mutex); |
369 | dput(xadir); | 373 | dput(xadir); |
370 | if (err) | 374 | if (err) |
371 | return ERR_PTR(err); | 375 | return ERR_PTR(err); |
372 | return xafile; | 376 | return xafile; |
373 | } | 377 | } |
374 | 378 | ||
375 | /* Internal operations on file data */ | 379 | /* Internal operations on file data */ |
376 | static inline void reiserfs_put_page(struct page *page) | 380 | static inline void reiserfs_put_page(struct page *page) |
377 | { | 381 | { |
378 | kunmap(page); | 382 | kunmap(page); |
379 | page_cache_release(page); | 383 | page_cache_release(page); |
380 | } | 384 | } |
381 | 385 | ||
382 | static struct page *reiserfs_get_page(struct inode *dir, size_t n) | 386 | static struct page *reiserfs_get_page(struct inode *dir, size_t n) |
383 | { | 387 | { |
384 | struct address_space *mapping = dir->i_mapping; | 388 | struct address_space *mapping = dir->i_mapping; |
385 | struct page *page; | 389 | struct page *page; |
386 | /* We can deadlock if we try to free dentries, | 390 | /* We can deadlock if we try to free dentries, |
387 | and an unlink/rmdir has just occured - GFP_NOFS avoids this */ | 391 | and an unlink/rmdir has just occured - GFP_NOFS avoids this */ |
388 | mapping_set_gfp_mask(mapping, GFP_NOFS); | 392 | mapping_set_gfp_mask(mapping, GFP_NOFS); |
389 | page = read_mapping_page(mapping, n >> PAGE_CACHE_SHIFT, NULL); | 393 | page = read_mapping_page(mapping, n >> PAGE_CACHE_SHIFT, NULL); |
390 | if (!IS_ERR(page)) { | 394 | if (!IS_ERR(page)) { |
391 | kmap(page); | 395 | kmap(page); |
392 | if (PageError(page)) | 396 | if (PageError(page)) |
393 | goto fail; | 397 | goto fail; |
394 | } | 398 | } |
395 | return page; | 399 | return page; |
396 | 400 | ||
397 | fail: | 401 | fail: |
398 | reiserfs_put_page(page); | 402 | reiserfs_put_page(page); |
399 | return ERR_PTR(-EIO); | 403 | return ERR_PTR(-EIO); |
400 | } | 404 | } |
401 | 405 | ||
402 | static inline __u32 xattr_hash(const char *msg, int len) | 406 | static inline __u32 xattr_hash(const char *msg, int len) |
403 | { | 407 | { |
404 | return csum_partial(msg, len, 0); | 408 | return csum_partial(msg, len, 0); |
405 | } | 409 | } |
406 | 410 | ||
407 | int reiserfs_commit_write(struct file *f, struct page *page, | 411 | int reiserfs_commit_write(struct file *f, struct page *page, |
408 | unsigned from, unsigned to); | 412 | unsigned from, unsigned to); |
409 | int reiserfs_prepare_write(struct file *f, struct page *page, | 413 | int reiserfs_prepare_write(struct file *f, struct page *page, |
410 | unsigned from, unsigned to); | 414 | unsigned from, unsigned to); |
411 | 415 | ||
412 | static void update_ctime(struct inode *inode) | 416 | static void update_ctime(struct inode *inode) |
413 | { | 417 | { |
414 | struct timespec now = current_fs_time(inode->i_sb); | 418 | struct timespec now = current_fs_time(inode->i_sb); |
415 | if (hlist_unhashed(&inode->i_hash) || !inode->i_nlink || | 419 | if (hlist_unhashed(&inode->i_hash) || !inode->i_nlink || |
416 | timespec_equal(&inode->i_ctime, &now)) | 420 | timespec_equal(&inode->i_ctime, &now)) |
417 | return; | 421 | return; |
418 | 422 | ||
419 | inode->i_ctime = CURRENT_TIME_SEC; | 423 | inode->i_ctime = CURRENT_TIME_SEC; |
420 | mark_inode_dirty(inode); | 424 | mark_inode_dirty(inode); |
421 | } | 425 | } |
422 | 426 | ||
423 | static int lookup_and_delete_xattr(struct inode *inode, const char *name) | 427 | static int lookup_and_delete_xattr(struct inode *inode, const char *name) |
424 | { | 428 | { |
425 | int err = 0; | 429 | int err = 0; |
426 | struct dentry *dentry, *xadir; | 430 | struct dentry *dentry, *xadir; |
427 | 431 | ||
428 | xadir = open_xa_dir(inode, XATTR_REPLACE); | 432 | xadir = open_xa_dir(inode, XATTR_REPLACE); |
429 | if (IS_ERR(xadir)) | 433 | if (IS_ERR(xadir)) |
430 | return PTR_ERR(xadir); | 434 | return PTR_ERR(xadir); |
431 | 435 | ||
432 | mutex_lock_nested(&xadir->d_inode->i_mutex, I_MUTEX_XATTR); | 436 | mutex_lock_nested(&xadir->d_inode->i_mutex, I_MUTEX_XATTR); |
433 | dentry = lookup_one_len(name, xadir, strlen(name)); | 437 | dentry = lookup_one_len(name, xadir, strlen(name)); |
434 | if (IS_ERR(dentry)) { | 438 | if (IS_ERR(dentry)) { |
435 | err = PTR_ERR(dentry); | 439 | err = PTR_ERR(dentry); |
436 | goto out_dput; | 440 | goto out_dput; |
437 | } | 441 | } |
438 | 442 | ||
439 | if (dentry->d_inode) { | 443 | if (dentry->d_inode) { |
440 | err = xattr_unlink(xadir->d_inode, dentry); | 444 | err = xattr_unlink(xadir->d_inode, dentry); |
441 | update_ctime(inode); | 445 | update_ctime(inode); |
442 | } | 446 | } |
443 | 447 | ||
444 | dput(dentry); | 448 | dput(dentry); |
445 | out_dput: | 449 | out_dput: |
446 | mutex_unlock(&xadir->d_inode->i_mutex); | 450 | mutex_unlock(&xadir->d_inode->i_mutex); |
447 | dput(xadir); | 451 | dput(xadir); |
448 | return err; | 452 | return err; |
449 | } | 453 | } |
450 | 454 | ||
451 | 455 | ||
452 | /* Generic extended attribute operations that can be used by xa plugins */ | 456 | /* Generic extended attribute operations that can be used by xa plugins */ |
453 | 457 | ||
454 | /* | 458 | /* |
455 | * inode->i_mutex: down | 459 | * inode->i_mutex: down |
456 | */ | 460 | */ |
457 | int | 461 | int |
458 | reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *th, | 462 | reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *th, |
459 | struct inode *inode, const char *name, | 463 | struct inode *inode, const char *name, |
460 | const void *buffer, size_t buffer_size, int flags) | 464 | const void *buffer, size_t buffer_size, int flags) |
461 | { | 465 | { |
462 | int err = 0; | 466 | int err = 0; |
463 | struct dentry *dentry; | 467 | struct dentry *dentry; |
464 | struct page *page; | 468 | struct page *page; |
465 | char *data; | 469 | char *data; |
466 | size_t file_pos = 0; | 470 | size_t file_pos = 0; |
467 | size_t buffer_pos = 0; | 471 | size_t buffer_pos = 0; |
468 | size_t new_size; | 472 | size_t new_size; |
469 | __u32 xahash = 0; | 473 | __u32 xahash = 0; |
470 | 474 | ||
471 | if (get_inode_sd_version(inode) == STAT_DATA_V1) | 475 | if (get_inode_sd_version(inode) == STAT_DATA_V1) |
472 | return -EOPNOTSUPP; | 476 | return -EOPNOTSUPP; |
473 | 477 | ||
474 | if (!buffer) | 478 | if (!buffer) |
475 | return lookup_and_delete_xattr(inode, name); | 479 | return lookup_and_delete_xattr(inode, name); |
476 | 480 | ||
477 | dentry = xattr_lookup(inode, name, flags); | 481 | dentry = xattr_lookup(inode, name, flags); |
478 | if (IS_ERR(dentry)) | 482 | if (IS_ERR(dentry)) |
479 | return PTR_ERR(dentry); | 483 | return PTR_ERR(dentry); |
480 | 484 | ||
481 | down_write(&REISERFS_I(inode)->i_xattr_sem); | 485 | down_write(&REISERFS_I(inode)->i_xattr_sem); |
482 | 486 | ||
483 | xahash = xattr_hash(buffer, buffer_size); | 487 | xahash = xattr_hash(buffer, buffer_size); |
484 | while (buffer_pos < buffer_size || buffer_pos == 0) { | 488 | while (buffer_pos < buffer_size || buffer_pos == 0) { |
485 | size_t chunk; | 489 | size_t chunk; |
486 | size_t skip = 0; | 490 | size_t skip = 0; |
487 | size_t page_offset = (file_pos & (PAGE_CACHE_SIZE - 1)); | 491 | size_t page_offset = (file_pos & (PAGE_CACHE_SIZE - 1)); |
488 | if (buffer_size - buffer_pos > PAGE_CACHE_SIZE) | 492 | if (buffer_size - buffer_pos > PAGE_CACHE_SIZE) |
489 | chunk = PAGE_CACHE_SIZE; | 493 | chunk = PAGE_CACHE_SIZE; |
490 | else | 494 | else |
491 | chunk = buffer_size - buffer_pos; | 495 | chunk = buffer_size - buffer_pos; |
492 | 496 | ||
493 | page = reiserfs_get_page(dentry->d_inode, file_pos); | 497 | page = reiserfs_get_page(dentry->d_inode, file_pos); |
494 | if (IS_ERR(page)) { | 498 | if (IS_ERR(page)) { |
495 | err = PTR_ERR(page); | 499 | err = PTR_ERR(page); |
496 | goto out_unlock; | 500 | goto out_unlock; |
497 | } | 501 | } |
498 | 502 | ||
499 | lock_page(page); | 503 | lock_page(page); |
500 | data = page_address(page); | 504 | data = page_address(page); |
501 | 505 | ||
502 | if (file_pos == 0) { | 506 | if (file_pos == 0) { |
503 | struct reiserfs_xattr_header *rxh; | 507 | struct reiserfs_xattr_header *rxh; |
504 | skip = file_pos = sizeof(struct reiserfs_xattr_header); | 508 | skip = file_pos = sizeof(struct reiserfs_xattr_header); |
505 | if (chunk + skip > PAGE_CACHE_SIZE) | 509 | if (chunk + skip > PAGE_CACHE_SIZE) |
506 | chunk = PAGE_CACHE_SIZE - skip; | 510 | chunk = PAGE_CACHE_SIZE - skip; |
507 | rxh = (struct reiserfs_xattr_header *)data; | 511 | rxh = (struct reiserfs_xattr_header *)data; |
508 | rxh->h_magic = cpu_to_le32(REISERFS_XATTR_MAGIC); | 512 | rxh->h_magic = cpu_to_le32(REISERFS_XATTR_MAGIC); |
509 | rxh->h_hash = cpu_to_le32(xahash); | 513 | rxh->h_hash = cpu_to_le32(xahash); |
510 | } | 514 | } |
511 | 515 | ||
512 | err = reiserfs_prepare_write(NULL, page, page_offset, | 516 | err = reiserfs_prepare_write(NULL, page, page_offset, |
513 | page_offset + chunk + skip); | 517 | page_offset + chunk + skip); |
514 | if (!err) { | 518 | if (!err) { |
515 | if (buffer) | 519 | if (buffer) |
516 | memcpy(data + skip, buffer + buffer_pos, chunk); | 520 | memcpy(data + skip, buffer + buffer_pos, chunk); |
517 | err = reiserfs_commit_write(NULL, page, page_offset, | 521 | err = reiserfs_commit_write(NULL, page, page_offset, |
518 | page_offset + chunk + | 522 | page_offset + chunk + |
519 | skip); | 523 | skip); |
520 | } | 524 | } |
521 | unlock_page(page); | 525 | unlock_page(page); |
522 | reiserfs_put_page(page); | 526 | reiserfs_put_page(page); |
523 | buffer_pos += chunk; | 527 | buffer_pos += chunk; |
524 | file_pos += chunk; | 528 | file_pos += chunk; |
525 | skip = 0; | 529 | skip = 0; |
526 | if (err || buffer_size == 0 || !buffer) | 530 | if (err || buffer_size == 0 || !buffer) |
527 | break; | 531 | break; |
528 | } | 532 | } |
529 | 533 | ||
530 | new_size = buffer_size + sizeof(struct reiserfs_xattr_header); | 534 | new_size = buffer_size + sizeof(struct reiserfs_xattr_header); |
531 | if (!err && new_size < i_size_read(dentry->d_inode)) { | 535 | if (!err && new_size < i_size_read(dentry->d_inode)) { |
532 | struct iattr newattrs = { | 536 | struct iattr newattrs = { |
533 | .ia_ctime = current_fs_time(inode->i_sb), | 537 | .ia_ctime = current_fs_time(inode->i_sb), |
534 | .ia_size = buffer_size, | 538 | .ia_size = buffer_size, |
535 | .ia_valid = ATTR_SIZE | ATTR_CTIME, | 539 | .ia_valid = ATTR_SIZE | ATTR_CTIME, |
536 | }; | 540 | }; |
537 | mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_XATTR); | 541 | mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_XATTR); |
538 | down_write(&dentry->d_inode->i_alloc_sem); | 542 | down_write(&dentry->d_inode->i_alloc_sem); |
539 | err = reiserfs_setattr(dentry, &newattrs); | 543 | err = reiserfs_setattr(dentry, &newattrs); |
540 | up_write(&dentry->d_inode->i_alloc_sem); | 544 | up_write(&dentry->d_inode->i_alloc_sem); |
541 | mutex_unlock(&dentry->d_inode->i_mutex); | 545 | mutex_unlock(&dentry->d_inode->i_mutex); |
542 | } else | 546 | } else |
543 | update_ctime(inode); | 547 | update_ctime(inode); |
544 | out_unlock: | 548 | out_unlock: |
545 | up_write(&REISERFS_I(inode)->i_xattr_sem); | 549 | up_write(&REISERFS_I(inode)->i_xattr_sem); |
546 | dput(dentry); | 550 | dput(dentry); |
547 | return err; | 551 | return err; |
548 | } | 552 | } |
549 | 553 | ||
550 | /* We need to start a transaction to maintain lock ordering */ | 554 | /* We need to start a transaction to maintain lock ordering */ |
551 | int reiserfs_xattr_set(struct inode *inode, const char *name, | 555 | int reiserfs_xattr_set(struct inode *inode, const char *name, |
552 | const void *buffer, size_t buffer_size, int flags) | 556 | const void *buffer, size_t buffer_size, int flags) |
553 | { | 557 | { |
554 | 558 | ||
555 | struct reiserfs_transaction_handle th; | 559 | struct reiserfs_transaction_handle th; |
556 | int error, error2; | 560 | int error, error2; |
557 | size_t jbegin_count = reiserfs_xattr_nblocks(inode, buffer_size); | 561 | size_t jbegin_count = reiserfs_xattr_nblocks(inode, buffer_size); |
558 | 562 | ||
559 | if (!(flags & XATTR_REPLACE)) | 563 | if (!(flags & XATTR_REPLACE)) |
560 | jbegin_count += reiserfs_xattr_jcreate_nblocks(inode); | 564 | jbegin_count += reiserfs_xattr_jcreate_nblocks(inode); |
561 | 565 | ||
562 | reiserfs_write_lock(inode->i_sb); | 566 | reiserfs_write_lock(inode->i_sb); |
563 | error = journal_begin(&th, inode->i_sb, jbegin_count); | 567 | error = journal_begin(&th, inode->i_sb, jbegin_count); |
564 | if (error) { | 568 | if (error) { |
565 | reiserfs_write_unlock(inode->i_sb); | 569 | reiserfs_write_unlock(inode->i_sb); |
566 | return error; | 570 | return error; |
567 | } | 571 | } |
568 | 572 | ||
569 | error = reiserfs_xattr_set_handle(&th, inode, name, | 573 | error = reiserfs_xattr_set_handle(&th, inode, name, |
570 | buffer, buffer_size, flags); | 574 | buffer, buffer_size, flags); |
571 | 575 | ||
572 | error2 = journal_end(&th, inode->i_sb, jbegin_count); | 576 | error2 = journal_end(&th, inode->i_sb, jbegin_count); |
573 | if (error == 0) | 577 | if (error == 0) |
574 | error = error2; | 578 | error = error2; |
575 | reiserfs_write_unlock(inode->i_sb); | 579 | reiserfs_write_unlock(inode->i_sb); |
576 | 580 | ||
577 | return error; | 581 | return error; |
578 | } | 582 | } |
579 | 583 | ||
580 | /* | 584 | /* |
581 | * inode->i_mutex: down | 585 | * inode->i_mutex: down |
582 | */ | 586 | */ |
583 | int | 587 | int |
584 | reiserfs_xattr_get(struct inode *inode, const char *name, void *buffer, | 588 | reiserfs_xattr_get(struct inode *inode, const char *name, void *buffer, |
585 | size_t buffer_size) | 589 | size_t buffer_size) |
586 | { | 590 | { |
587 | ssize_t err = 0; | 591 | ssize_t err = 0; |
588 | struct dentry *dentry; | 592 | struct dentry *dentry; |
589 | size_t isize; | 593 | size_t isize; |
590 | size_t file_pos = 0; | 594 | size_t file_pos = 0; |
591 | size_t buffer_pos = 0; | 595 | size_t buffer_pos = 0; |
592 | struct page *page; | 596 | struct page *page; |
593 | __u32 hash = 0; | 597 | __u32 hash = 0; |
594 | 598 | ||
595 | if (name == NULL) | 599 | if (name == NULL) |
596 | return -EINVAL; | 600 | return -EINVAL; |
597 | 601 | ||
598 | /* We can't have xattrs attached to v1 items since they don't have | 602 | /* We can't have xattrs attached to v1 items since they don't have |
599 | * generation numbers */ | 603 | * generation numbers */ |
600 | if (get_inode_sd_version(inode) == STAT_DATA_V1) | 604 | if (get_inode_sd_version(inode) == STAT_DATA_V1) |
601 | return -EOPNOTSUPP; | 605 | return -EOPNOTSUPP; |
602 | 606 | ||
603 | dentry = xattr_lookup(inode, name, XATTR_REPLACE); | 607 | dentry = xattr_lookup(inode, name, XATTR_REPLACE); |
604 | if (IS_ERR(dentry)) { | 608 | if (IS_ERR(dentry)) { |
605 | err = PTR_ERR(dentry); | 609 | err = PTR_ERR(dentry); |
606 | goto out; | 610 | goto out; |
607 | } | 611 | } |
608 | 612 | ||
609 | down_read(&REISERFS_I(inode)->i_xattr_sem); | 613 | down_read(&REISERFS_I(inode)->i_xattr_sem); |
610 | 614 | ||
611 | isize = i_size_read(dentry->d_inode); | 615 | isize = i_size_read(dentry->d_inode); |
612 | 616 | ||
613 | /* Just return the size needed */ | 617 | /* Just return the size needed */ |
614 | if (buffer == NULL) { | 618 | if (buffer == NULL) { |
615 | err = isize - sizeof(struct reiserfs_xattr_header); | 619 | err = isize - sizeof(struct reiserfs_xattr_header); |
616 | goto out_unlock; | 620 | goto out_unlock; |
617 | } | 621 | } |
618 | 622 | ||
619 | if (buffer_size < isize - sizeof(struct reiserfs_xattr_header)) { | 623 | if (buffer_size < isize - sizeof(struct reiserfs_xattr_header)) { |
620 | err = -ERANGE; | 624 | err = -ERANGE; |
621 | goto out_unlock; | 625 | goto out_unlock; |
622 | } | 626 | } |
623 | 627 | ||
624 | while (file_pos < isize) { | 628 | while (file_pos < isize) { |
625 | size_t chunk; | 629 | size_t chunk; |
626 | char *data; | 630 | char *data; |
627 | size_t skip = 0; | 631 | size_t skip = 0; |
628 | if (isize - file_pos > PAGE_CACHE_SIZE) | 632 | if (isize - file_pos > PAGE_CACHE_SIZE) |
629 | chunk = PAGE_CACHE_SIZE; | 633 | chunk = PAGE_CACHE_SIZE; |
630 | else | 634 | else |
631 | chunk = isize - file_pos; | 635 | chunk = isize - file_pos; |
632 | 636 | ||
633 | page = reiserfs_get_page(dentry->d_inode, file_pos); | 637 | page = reiserfs_get_page(dentry->d_inode, file_pos); |
634 | if (IS_ERR(page)) { | 638 | if (IS_ERR(page)) { |
635 | err = PTR_ERR(page); | 639 | err = PTR_ERR(page); |
636 | goto out_unlock; | 640 | goto out_unlock; |
637 | } | 641 | } |
638 | 642 | ||
639 | lock_page(page); | 643 | lock_page(page); |
640 | data = page_address(page); | 644 | data = page_address(page); |
641 | if (file_pos == 0) { | 645 | if (file_pos == 0) { |
642 | struct reiserfs_xattr_header *rxh = | 646 | struct reiserfs_xattr_header *rxh = |
643 | (struct reiserfs_xattr_header *)data; | 647 | (struct reiserfs_xattr_header *)data; |
644 | skip = file_pos = sizeof(struct reiserfs_xattr_header); | 648 | skip = file_pos = sizeof(struct reiserfs_xattr_header); |
645 | chunk -= skip; | 649 | chunk -= skip; |
646 | /* Magic doesn't match up.. */ | 650 | /* Magic doesn't match up.. */ |
647 | if (rxh->h_magic != cpu_to_le32(REISERFS_XATTR_MAGIC)) { | 651 | if (rxh->h_magic != cpu_to_le32(REISERFS_XATTR_MAGIC)) { |
648 | unlock_page(page); | 652 | unlock_page(page); |
649 | reiserfs_put_page(page); | 653 | reiserfs_put_page(page); |
650 | reiserfs_warning(inode->i_sb, "jdm-20001", | 654 | reiserfs_warning(inode->i_sb, "jdm-20001", |
651 | "Invalid magic for xattr (%s) " | 655 | "Invalid magic for xattr (%s) " |
652 | "associated with %k", name, | 656 | "associated with %k", name, |
653 | INODE_PKEY(inode)); | 657 | INODE_PKEY(inode)); |
654 | err = -EIO; | 658 | err = -EIO; |
655 | goto out_unlock; | 659 | goto out_unlock; |
656 | } | 660 | } |
657 | hash = le32_to_cpu(rxh->h_hash); | 661 | hash = le32_to_cpu(rxh->h_hash); |
658 | } | 662 | } |
659 | memcpy(buffer + buffer_pos, data + skip, chunk); | 663 | memcpy(buffer + buffer_pos, data + skip, chunk); |
660 | unlock_page(page); | 664 | unlock_page(page); |
661 | reiserfs_put_page(page); | 665 | reiserfs_put_page(page); |
662 | file_pos += chunk; | 666 | file_pos += chunk; |
663 | buffer_pos += chunk; | 667 | buffer_pos += chunk; |
664 | skip = 0; | 668 | skip = 0; |
665 | } | 669 | } |
666 | err = isize - sizeof(struct reiserfs_xattr_header); | 670 | err = isize - sizeof(struct reiserfs_xattr_header); |
667 | 671 | ||
668 | if (xattr_hash(buffer, isize - sizeof(struct reiserfs_xattr_header)) != | 672 | if (xattr_hash(buffer, isize - sizeof(struct reiserfs_xattr_header)) != |
669 | hash) { | 673 | hash) { |
670 | reiserfs_warning(inode->i_sb, "jdm-20002", | 674 | reiserfs_warning(inode->i_sb, "jdm-20002", |
671 | "Invalid hash for xattr (%s) associated " | 675 | "Invalid hash for xattr (%s) associated " |
672 | "with %k", name, INODE_PKEY(inode)); | 676 | "with %k", name, INODE_PKEY(inode)); |
673 | err = -EIO; | 677 | err = -EIO; |
674 | } | 678 | } |
675 | 679 | ||
676 | out_unlock: | 680 | out_unlock: |
677 | up_read(&REISERFS_I(inode)->i_xattr_sem); | 681 | up_read(&REISERFS_I(inode)->i_xattr_sem); |
678 | dput(dentry); | 682 | dput(dentry); |
679 | 683 | ||
680 | out: | 684 | out: |
681 | return err; | 685 | return err; |
682 | } | 686 | } |
683 | 687 | ||
684 | /* Actual operations that are exported to VFS-land */ | 688 | /* Actual operations that are exported to VFS-land */ |
685 | struct xattr_handler *reiserfs_xattr_handlers[] = { | 689 | struct xattr_handler *reiserfs_xattr_handlers[] = { |
686 | &reiserfs_xattr_user_handler, | 690 | &reiserfs_xattr_user_handler, |
687 | &reiserfs_xattr_trusted_handler, | 691 | &reiserfs_xattr_trusted_handler, |
688 | #ifdef CONFIG_REISERFS_FS_SECURITY | 692 | #ifdef CONFIG_REISERFS_FS_SECURITY |
689 | &reiserfs_xattr_security_handler, | 693 | &reiserfs_xattr_security_handler, |
690 | #endif | 694 | #endif |
691 | #ifdef CONFIG_REISERFS_FS_POSIX_ACL | 695 | #ifdef CONFIG_REISERFS_FS_POSIX_ACL |
692 | &reiserfs_posix_acl_access_handler, | 696 | &reiserfs_posix_acl_access_handler, |
693 | &reiserfs_posix_acl_default_handler, | 697 | &reiserfs_posix_acl_default_handler, |
694 | #endif | 698 | #endif |
695 | NULL | 699 | NULL |
696 | }; | 700 | }; |
697 | 701 | ||
698 | /* | 702 | /* |
699 | * In order to implement different sets of xattr operations for each xattr | 703 | * In order to implement different sets of xattr operations for each xattr |
700 | * prefix with the generic xattr API, a filesystem should create a | 704 | * prefix with the generic xattr API, a filesystem should create a |
701 | * null-terminated array of struct xattr_handler (one for each prefix) and | 705 | * null-terminated array of struct xattr_handler (one for each prefix) and |
702 | * hang a pointer to it off of the s_xattr field of the superblock. | 706 | * hang a pointer to it off of the s_xattr field of the superblock. |
703 | * | 707 | * |
704 | * The generic_fooxattr() functions will use this list to dispatch xattr | 708 | * The generic_fooxattr() functions will use this list to dispatch xattr |
705 | * operations to the correct xattr_handler. | 709 | * operations to the correct xattr_handler. |
706 | */ | 710 | */ |
707 | #define for_each_xattr_handler(handlers, handler) \ | 711 | #define for_each_xattr_handler(handlers, handler) \ |
708 | for ((handler) = *(handlers)++; \ | 712 | for ((handler) = *(handlers)++; \ |
709 | (handler) != NULL; \ | 713 | (handler) != NULL; \ |
710 | (handler) = *(handlers)++) | 714 | (handler) = *(handlers)++) |
711 | 715 | ||
712 | /* This is the implementation for the xattr plugin infrastructure */ | 716 | /* This is the implementation for the xattr plugin infrastructure */ |
713 | static inline struct xattr_handler * | 717 | static inline struct xattr_handler * |
714 | find_xattr_handler_prefix(struct xattr_handler **handlers, | 718 | find_xattr_handler_prefix(struct xattr_handler **handlers, |
715 | const char *name) | 719 | const char *name) |
716 | { | 720 | { |
717 | struct xattr_handler *xah; | 721 | struct xattr_handler *xah; |
718 | 722 | ||
719 | if (!handlers) | 723 | if (!handlers) |
720 | return NULL; | 724 | return NULL; |
721 | 725 | ||
722 | for_each_xattr_handler(handlers, xah) { | 726 | for_each_xattr_handler(handlers, xah) { |
723 | if (strncmp(xah->prefix, name, strlen(xah->prefix)) == 0) | 727 | if (strncmp(xah->prefix, name, strlen(xah->prefix)) == 0) |
724 | break; | 728 | break; |
725 | } | 729 | } |
726 | 730 | ||
727 | return xah; | 731 | return xah; |
728 | } | 732 | } |
729 | 733 | ||
730 | 734 | ||
731 | /* | 735 | /* |
732 | * Inode operation getxattr() | 736 | * Inode operation getxattr() |
733 | */ | 737 | */ |
734 | ssize_t | 738 | ssize_t |
735 | reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer, | 739 | reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer, |
736 | size_t size) | 740 | size_t size) |
737 | { | 741 | { |
738 | struct inode *inode = dentry->d_inode; | 742 | struct inode *inode = dentry->d_inode; |
739 | struct xattr_handler *handler; | 743 | struct xattr_handler *handler; |
740 | 744 | ||
741 | handler = find_xattr_handler_prefix(inode->i_sb->s_xattr, name); | 745 | handler = find_xattr_handler_prefix(inode->i_sb->s_xattr, name); |
742 | 746 | ||
743 | if (!handler || get_inode_sd_version(inode) == STAT_DATA_V1) | 747 | if (!handler || get_inode_sd_version(inode) == STAT_DATA_V1) |
744 | return -EOPNOTSUPP; | 748 | return -EOPNOTSUPP; |
745 | 749 | ||
746 | return handler->get(inode, name, buffer, size); | 750 | return handler->get(inode, name, buffer, size); |
747 | } | 751 | } |
748 | 752 | ||
749 | /* | 753 | /* |
750 | * Inode operation setxattr() | 754 | * Inode operation setxattr() |
751 | * | 755 | * |
752 | * dentry->d_inode->i_mutex down | 756 | * dentry->d_inode->i_mutex down |
753 | */ | 757 | */ |
754 | int | 758 | int |
755 | reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value, | 759 | reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value, |
756 | size_t size, int flags) | 760 | size_t size, int flags) |
757 | { | 761 | { |
758 | struct inode *inode = dentry->d_inode; | 762 | struct inode *inode = dentry->d_inode; |
759 | struct xattr_handler *handler; | 763 | struct xattr_handler *handler; |
760 | 764 | ||
761 | handler = find_xattr_handler_prefix(inode->i_sb->s_xattr, name); | 765 | handler = find_xattr_handler_prefix(inode->i_sb->s_xattr, name); |
762 | 766 | ||
763 | if (!handler || get_inode_sd_version(inode) == STAT_DATA_V1) | 767 | if (!handler || get_inode_sd_version(inode) == STAT_DATA_V1) |
764 | return -EOPNOTSUPP; | 768 | return -EOPNOTSUPP; |
765 | 769 | ||
766 | return handler->set(inode, name, value, size, flags); | 770 | return handler->set(inode, name, value, size, flags); |
767 | } | 771 | } |
768 | 772 | ||
769 | /* | 773 | /* |
770 | * Inode operation removexattr() | 774 | * Inode operation removexattr() |
771 | * | 775 | * |
772 | * dentry->d_inode->i_mutex down | 776 | * dentry->d_inode->i_mutex down |
773 | */ | 777 | */ |
774 | int reiserfs_removexattr(struct dentry *dentry, const char *name) | 778 | int reiserfs_removexattr(struct dentry *dentry, const char *name) |
775 | { | 779 | { |
776 | struct inode *inode = dentry->d_inode; | 780 | struct inode *inode = dentry->d_inode; |
777 | struct xattr_handler *handler; | 781 | struct xattr_handler *handler; |
778 | handler = find_xattr_handler_prefix(inode->i_sb->s_xattr, name); | 782 | handler = find_xattr_handler_prefix(inode->i_sb->s_xattr, name); |
779 | 783 | ||
780 | if (!handler || get_inode_sd_version(inode) == STAT_DATA_V1) | 784 | if (!handler || get_inode_sd_version(inode) == STAT_DATA_V1) |
781 | return -EOPNOTSUPP; | 785 | return -EOPNOTSUPP; |
782 | 786 | ||
783 | return handler->set(inode, name, NULL, 0, XATTR_REPLACE); | 787 | return handler->set(inode, name, NULL, 0, XATTR_REPLACE); |
784 | } | 788 | } |
785 | 789 | ||
786 | struct listxattr_buf { | 790 | struct listxattr_buf { |
787 | size_t size; | 791 | size_t size; |
788 | size_t pos; | 792 | size_t pos; |
789 | char *buf; | 793 | char *buf; |
790 | struct inode *inode; | 794 | struct inode *inode; |
791 | }; | 795 | }; |
792 | 796 | ||
793 | static int listxattr_filler(void *buf, const char *name, int namelen, | 797 | static int listxattr_filler(void *buf, const char *name, int namelen, |
794 | loff_t offset, u64 ino, unsigned int d_type) | 798 | loff_t offset, u64 ino, unsigned int d_type) |
795 | { | 799 | { |
796 | struct listxattr_buf *b = (struct listxattr_buf *)buf; | 800 | struct listxattr_buf *b = (struct listxattr_buf *)buf; |
797 | size_t size; | 801 | size_t size; |
798 | if (name[0] != '.' || | 802 | if (name[0] != '.' || |
799 | (namelen != 1 && (name[1] != '.' || namelen != 2))) { | 803 | (namelen != 1 && (name[1] != '.' || namelen != 2))) { |
800 | struct xattr_handler *handler; | 804 | struct xattr_handler *handler; |
801 | handler = find_xattr_handler_prefix(b->inode->i_sb->s_xattr, | 805 | handler = find_xattr_handler_prefix(b->inode->i_sb->s_xattr, |
802 | name); | 806 | name); |
803 | if (!handler) /* Unsupported xattr name */ | 807 | if (!handler) /* Unsupported xattr name */ |
804 | return 0; | 808 | return 0; |
805 | if (b->buf) { | 809 | if (b->buf) { |
806 | size = handler->list(b->inode, b->buf + b->pos, | 810 | size = handler->list(b->inode, b->buf + b->pos, |
807 | b->size, name, namelen); | 811 | b->size, name, namelen); |
808 | if (size > b->size) | 812 | if (size > b->size) |
809 | return -ERANGE; | 813 | return -ERANGE; |
810 | } else { | 814 | } else { |
811 | size = handler->list(b->inode, NULL, 0, name, namelen); | 815 | size = handler->list(b->inode, NULL, 0, name, namelen); |
812 | } | 816 | } |
813 | 817 | ||
814 | b->pos += size; | 818 | b->pos += size; |
815 | } | 819 | } |
816 | return 0; | 820 | return 0; |
817 | } | 821 | } |
818 | 822 | ||
819 | /* | 823 | /* |
820 | * Inode operation listxattr() | 824 | * Inode operation listxattr() |
821 | * | 825 | * |
822 | * We totally ignore the generic listxattr here because it would be stupid | 826 | * We totally ignore the generic listxattr here because it would be stupid |
823 | * not to. Since the xattrs are organized in a directory, we can just | 827 | * not to. Since the xattrs are organized in a directory, we can just |
824 | * readdir to find them. | 828 | * readdir to find them. |
825 | */ | 829 | */ |
826 | ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size) | 830 | ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size) |
827 | { | 831 | { |
828 | struct dentry *dir; | 832 | struct dentry *dir; |
829 | int err = 0; | 833 | int err = 0; |
830 | loff_t pos = 0; | 834 | loff_t pos = 0; |
831 | struct listxattr_buf buf = { | 835 | struct listxattr_buf buf = { |
832 | .inode = dentry->d_inode, | 836 | .inode = dentry->d_inode, |
833 | .buf = buffer, | 837 | .buf = buffer, |
834 | .size = buffer ? size : 0, | 838 | .size = buffer ? size : 0, |
835 | }; | 839 | }; |
836 | 840 | ||
837 | if (!dentry->d_inode) | 841 | if (!dentry->d_inode) |
838 | return -EINVAL; | 842 | return -EINVAL; |
839 | 843 | ||
840 | if (!reiserfs_xattrs(dentry->d_sb) || | 844 | if (!reiserfs_xattrs(dentry->d_sb) || |
841 | get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) | 845 | get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1) |
842 | return -EOPNOTSUPP; | 846 | return -EOPNOTSUPP; |
843 | 847 | ||
844 | dir = open_xa_dir(dentry->d_inode, XATTR_REPLACE); | 848 | dir = open_xa_dir(dentry->d_inode, XATTR_REPLACE); |
845 | if (IS_ERR(dir)) { | 849 | if (IS_ERR(dir)) { |
846 | err = PTR_ERR(dir); | 850 | err = PTR_ERR(dir); |
847 | if (err == -ENODATA) | 851 | if (err == -ENODATA) |
848 | err = 0; /* Not an error if there aren't any xattrs */ | 852 | err = 0; /* Not an error if there aren't any xattrs */ |
849 | goto out; | 853 | goto out; |
850 | } | 854 | } |
851 | 855 | ||
852 | mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR); | 856 | mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR); |
853 | err = reiserfs_readdir_dentry(dir, &buf, listxattr_filler, &pos); | 857 | err = reiserfs_readdir_dentry(dir, &buf, listxattr_filler, &pos); |
854 | mutex_unlock(&dir->d_inode->i_mutex); | 858 | mutex_unlock(&dir->d_inode->i_mutex); |
855 | 859 | ||
856 | if (!err) | 860 | if (!err) |
857 | err = buf.pos; | 861 | err = buf.pos; |
858 | 862 | ||
859 | dput(dir); | 863 | dput(dir); |
860 | out: | 864 | out: |
861 | return err; | 865 | return err; |
862 | } | 866 | } |
863 | 867 | ||
864 | static int reiserfs_check_acl(struct inode *inode, int mask) | 868 | static int reiserfs_check_acl(struct inode *inode, int mask) |
865 | { | 869 | { |
866 | struct posix_acl *acl; | 870 | struct posix_acl *acl; |
867 | int error = -EAGAIN; /* do regular unix permission checks by default */ | 871 | int error = -EAGAIN; /* do regular unix permission checks by default */ |
868 | 872 | ||
869 | acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS); | 873 | acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS); |
870 | 874 | ||
871 | if (acl) { | 875 | if (acl) { |
872 | if (!IS_ERR(acl)) { | 876 | if (!IS_ERR(acl)) { |
873 | error = posix_acl_permission(inode, acl, mask); | 877 | error = posix_acl_permission(inode, acl, mask); |
874 | posix_acl_release(acl); | 878 | posix_acl_release(acl); |
875 | } else if (PTR_ERR(acl) != -ENODATA) | 879 | } else if (PTR_ERR(acl) != -ENODATA) |
876 | error = PTR_ERR(acl); | 880 | error = PTR_ERR(acl); |
877 | } | 881 | } |
878 | 882 | ||
879 | return error; | 883 | return error; |
880 | } | 884 | } |
881 | 885 | ||
882 | int reiserfs_permission(struct inode *inode, int mask) | 886 | int reiserfs_permission(struct inode *inode, int mask) |
883 | { | 887 | { |
884 | /* | 888 | /* |
885 | * We don't do permission checks on the internal objects. | 889 | * We don't do permission checks on the internal objects. |
886 | * Permissions are determined by the "owning" object. | 890 | * Permissions are determined by the "owning" object. |
887 | */ | 891 | */ |
888 | if (IS_PRIVATE(inode)) | 892 | if (IS_PRIVATE(inode)) |
889 | return 0; | 893 | return 0; |
890 | /* | 894 | /* |
891 | * Stat data v1 doesn't support ACLs. | 895 | * Stat data v1 doesn't support ACLs. |
892 | */ | 896 | */ |
893 | if (get_inode_sd_version(inode) == STAT_DATA_V1) | 897 | if (get_inode_sd_version(inode) == STAT_DATA_V1) |
894 | return generic_permission(inode, mask, NULL); | 898 | return generic_permission(inode, mask, NULL); |
895 | else | 899 | else |
896 | return generic_permission(inode, mask, reiserfs_check_acl); | 900 | return generic_permission(inode, mask, reiserfs_check_acl); |
897 | } | 901 | } |
898 | 902 | ||
899 | static int create_privroot(struct dentry *dentry) | 903 | static int create_privroot(struct dentry *dentry) |
900 | { | 904 | { |
901 | int err; | 905 | int err; |
902 | struct inode *inode = dentry->d_parent->d_inode; | 906 | struct inode *inode = dentry->d_parent->d_inode; |
903 | WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex)); | 907 | WARN_ON_ONCE(!mutex_is_locked(&inode->i_mutex)); |
904 | 908 | ||
905 | err = xattr_mkdir(inode, dentry, 0700); | 909 | err = xattr_mkdir(inode, dentry, 0700); |
906 | if (err || !dentry->d_inode) { | 910 | if (err || !dentry->d_inode) { |
907 | reiserfs_warning(dentry->d_sb, "jdm-20006", | 911 | reiserfs_warning(dentry->d_sb, "jdm-20006", |
908 | "xattrs/ACLs enabled and couldn't " | 912 | "xattrs/ACLs enabled and couldn't " |
909 | "find/create .reiserfs_priv. " | 913 | "find/create .reiserfs_priv. " |
910 | "Failing mount."); | 914 | "Failing mount."); |
911 | return -EOPNOTSUPP; | 915 | return -EOPNOTSUPP; |
912 | } | 916 | } |
913 | 917 | ||
914 | dentry->d_inode->i_flags |= S_PRIVATE; | 918 | dentry->d_inode->i_flags |= S_PRIVATE; |
915 | reiserfs_info(dentry->d_sb, "Created %s - reserved for xattr " | 919 | reiserfs_info(dentry->d_sb, "Created %s - reserved for xattr " |
916 | "storage.\n", PRIVROOT_NAME); | 920 | "storage.\n", PRIVROOT_NAME); |
917 | 921 | ||
918 | return 0; | 922 | return 0; |
919 | } | 923 | } |
920 | 924 | ||
921 | static int xattr_mount_check(struct super_block *s) | 925 | static int xattr_mount_check(struct super_block *s) |
922 | { | 926 | { |
923 | /* We need generation numbers to ensure that the oid mapping is correct | 927 | /* We need generation numbers to ensure that the oid mapping is correct |
924 | * v3.5 filesystems don't have them. */ | 928 | * v3.5 filesystems don't have them. */ |
925 | if (old_format_only(s)) { | 929 | if (old_format_only(s)) { |
926 | if (reiserfs_xattrs_optional(s)) { | 930 | if (reiserfs_xattrs_optional(s)) { |
927 | /* Old format filesystem, but optional xattrs have | 931 | /* Old format filesystem, but optional xattrs have |
928 | * been enabled. Error out. */ | 932 | * been enabled. Error out. */ |
929 | reiserfs_warning(s, "jdm-2005", | 933 | reiserfs_warning(s, "jdm-2005", |
930 | "xattrs/ACLs not supported " | 934 | "xattrs/ACLs not supported " |
931 | "on pre-v3.6 format filesystems. " | 935 | "on pre-v3.6 format filesystems. " |
932 | "Failing mount."); | 936 | "Failing mount."); |
933 | return -EOPNOTSUPP; | 937 | return -EOPNOTSUPP; |
934 | } | 938 | } |
935 | } | 939 | } |
936 | 940 | ||
937 | return 0; | 941 | return 0; |
938 | } | 942 | } |
939 | 943 | ||
940 | #else | 944 | #else |
941 | int __init reiserfs_xattr_register_handlers(void) { return 0; } | 945 | int __init reiserfs_xattr_register_handlers(void) { return 0; } |
942 | void reiserfs_xattr_unregister_handlers(void) {} | 946 | void reiserfs_xattr_unregister_handlers(void) {} |
943 | #endif | 947 | #endif |
944 | 948 | ||
945 | /* This will catch lookups from the fs root to .reiserfs_priv */ | 949 | /* This will catch lookups from the fs root to .reiserfs_priv */ |
946 | static int | 950 | static int |
947 | xattr_lookup_poison(struct dentry *dentry, struct qstr *q1, struct qstr *name) | 951 | xattr_lookup_poison(struct dentry *dentry, struct qstr *q1, struct qstr *name) |
948 | { | 952 | { |
949 | struct dentry *priv_root = REISERFS_SB(dentry->d_sb)->priv_root; | 953 | struct dentry *priv_root = REISERFS_SB(dentry->d_sb)->priv_root; |
950 | if (container_of(q1, struct dentry, d_name) == priv_root) | 954 | if (container_of(q1, struct dentry, d_name) == priv_root) |
951 | return -ENOENT; | 955 | return -ENOENT; |
952 | if (q1->len == name->len && | 956 | if (q1->len == name->len && |
953 | !memcmp(q1->name, name->name, name->len)) | 957 | !memcmp(q1->name, name->name, name->len)) |
954 | return 0; | 958 | return 0; |
955 | return 1; | 959 | return 1; |
956 | } | 960 | } |
957 | 961 | ||
958 | static const struct dentry_operations xattr_lookup_poison_ops = { | 962 | static const struct dentry_operations xattr_lookup_poison_ops = { |
959 | .d_compare = xattr_lookup_poison, | 963 | .d_compare = xattr_lookup_poison, |
960 | }; | 964 | }; |
961 | 965 | ||
962 | int reiserfs_lookup_privroot(struct super_block *s) | 966 | int reiserfs_lookup_privroot(struct super_block *s) |
963 | { | 967 | { |
964 | struct dentry *dentry; | 968 | struct dentry *dentry; |
965 | int err = 0; | 969 | int err = 0; |
966 | 970 | ||
967 | /* If we don't have the privroot located yet - go find it */ | 971 | /* If we don't have the privroot located yet - go find it */ |
968 | mutex_lock(&s->s_root->d_inode->i_mutex); | 972 | mutex_lock(&s->s_root->d_inode->i_mutex); |
969 | dentry = lookup_one_len(PRIVROOT_NAME, s->s_root, | 973 | dentry = lookup_one_len(PRIVROOT_NAME, s->s_root, |
970 | strlen(PRIVROOT_NAME)); | 974 | strlen(PRIVROOT_NAME)); |
971 | if (!IS_ERR(dentry)) { | 975 | if (!IS_ERR(dentry)) { |
972 | REISERFS_SB(s)->priv_root = dentry; | 976 | REISERFS_SB(s)->priv_root = dentry; |
973 | s->s_root->d_op = &xattr_lookup_poison_ops; | 977 | s->s_root->d_op = &xattr_lookup_poison_ops; |
974 | if (dentry->d_inode) | 978 | if (dentry->d_inode) |
975 | dentry->d_inode->i_flags |= S_PRIVATE; | 979 | dentry->d_inode->i_flags |= S_PRIVATE; |
976 | } else | 980 | } else |
977 | err = PTR_ERR(dentry); | 981 | err = PTR_ERR(dentry); |
978 | mutex_unlock(&s->s_root->d_inode->i_mutex); | 982 | mutex_unlock(&s->s_root->d_inode->i_mutex); |
979 | 983 | ||
980 | return err; | 984 | return err; |
981 | } | 985 | } |
982 | 986 | ||
983 | /* We need to take a copy of the mount flags since things like | 987 | /* We need to take a copy of the mount flags since things like |
984 | * MS_RDONLY don't get set until *after* we're called. | 988 | * MS_RDONLY don't get set until *after* we're called. |
985 | * mount_flags != mount_options */ | 989 | * mount_flags != mount_options */ |
986 | int reiserfs_xattr_init(struct super_block *s, int mount_flags) | 990 | int reiserfs_xattr_init(struct super_block *s, int mount_flags) |
987 | { | 991 | { |
988 | int err = 0; | 992 | int err = 0; |
993 | struct dentry *privroot = REISERFS_SB(s)->priv_root; | ||
989 | 994 | ||
990 | #ifdef CONFIG_REISERFS_FS_XATTR | 995 | #ifdef CONFIG_REISERFS_FS_XATTR |
991 | err = xattr_mount_check(s); | 996 | err = xattr_mount_check(s); |
992 | if (err) | 997 | if (err) |
993 | goto error; | 998 | goto error; |
994 | 999 | ||
995 | if (!REISERFS_SB(s)->priv_root->d_inode && !(mount_flags & MS_RDONLY)) { | 1000 | if (!privroot->d_inode && !(mount_flags & MS_RDONLY)) { |
996 | mutex_lock(&s->s_root->d_inode->i_mutex); | 1001 | mutex_lock(&s->s_root->d_inode->i_mutex); |
997 | err = create_privroot(REISERFS_SB(s)->priv_root); | 1002 | err = create_privroot(REISERFS_SB(s)->priv_root); |
998 | mutex_unlock(&s->s_root->d_inode->i_mutex); | 1003 | mutex_unlock(&s->s_root->d_inode->i_mutex); |
999 | } | 1004 | } |
1000 | if (!err) | 1005 | |
1006 | if (privroot->d_inode) { | ||
1001 | s->s_xattr = reiserfs_xattr_handlers; | 1007 | s->s_xattr = reiserfs_xattr_handlers; |
1008 | mutex_lock(&privroot->d_inode->i_mutex); | ||
1009 | if (!REISERFS_SB(s)->xattr_root) { | ||
1010 | struct dentry *dentry; | ||
1011 | dentry = lookup_one_len(XAROOT_NAME, privroot, | ||
1012 | strlen(XAROOT_NAME)); | ||
1013 | if (!IS_ERR(dentry)) | ||
1014 | REISERFS_SB(s)->xattr_root = dentry; | ||
1015 | else | ||
1016 | err = PTR_ERR(dentry); | ||
1017 | } | ||
1018 | mutex_unlock(&privroot->d_inode->i_mutex); | ||
1019 | } | ||
1002 | 1020 | ||
1003 | error: | 1021 | error: |
1004 | if (err) { | 1022 | if (err) { |
1005 | clear_bit(REISERFS_XATTRS_USER, &(REISERFS_SB(s)->s_mount_opt)); | 1023 | clear_bit(REISERFS_XATTRS_USER, &(REISERFS_SB(s)->s_mount_opt)); |
1006 | clear_bit(REISERFS_POSIXACL, &(REISERFS_SB(s)->s_mount_opt)); | 1024 | clear_bit(REISERFS_POSIXACL, &(REISERFS_SB(s)->s_mount_opt)); |
include/linux/reiserfs_fs_sb.h
1 | /* Copyright 1996-2000 Hans Reiser, see reiserfs/README for licensing | 1 | /* Copyright 1996-2000 Hans Reiser, see reiserfs/README for licensing |
2 | * and copyright details */ | 2 | * and copyright details */ |
3 | 3 | ||
4 | #ifndef _LINUX_REISER_FS_SB | 4 | #ifndef _LINUX_REISER_FS_SB |
5 | #define _LINUX_REISER_FS_SB | 5 | #define _LINUX_REISER_FS_SB |
6 | 6 | ||
7 | #ifdef __KERNEL__ | 7 | #ifdef __KERNEL__ |
8 | #include <linux/workqueue.h> | 8 | #include <linux/workqueue.h> |
9 | #include <linux/rwsem.h> | 9 | #include <linux/rwsem.h> |
10 | #endif | 10 | #endif |
11 | 11 | ||
12 | typedef enum { | 12 | typedef enum { |
13 | reiserfs_attrs_cleared = 0x00000001, | 13 | reiserfs_attrs_cleared = 0x00000001, |
14 | } reiserfs_super_block_flags; | 14 | } reiserfs_super_block_flags; |
15 | 15 | ||
16 | /* struct reiserfs_super_block accessors/mutators | 16 | /* struct reiserfs_super_block accessors/mutators |
17 | * since this is a disk structure, it will always be in | 17 | * since this is a disk structure, it will always be in |
18 | * little endian format. */ | 18 | * little endian format. */ |
19 | #define sb_block_count(sbp) (le32_to_cpu((sbp)->s_v1.s_block_count)) | 19 | #define sb_block_count(sbp) (le32_to_cpu((sbp)->s_v1.s_block_count)) |
20 | #define set_sb_block_count(sbp,v) ((sbp)->s_v1.s_block_count = cpu_to_le32(v)) | 20 | #define set_sb_block_count(sbp,v) ((sbp)->s_v1.s_block_count = cpu_to_le32(v)) |
21 | #define sb_free_blocks(sbp) (le32_to_cpu((sbp)->s_v1.s_free_blocks)) | 21 | #define sb_free_blocks(sbp) (le32_to_cpu((sbp)->s_v1.s_free_blocks)) |
22 | #define set_sb_free_blocks(sbp,v) ((sbp)->s_v1.s_free_blocks = cpu_to_le32(v)) | 22 | #define set_sb_free_blocks(sbp,v) ((sbp)->s_v1.s_free_blocks = cpu_to_le32(v)) |
23 | #define sb_root_block(sbp) (le32_to_cpu((sbp)->s_v1.s_root_block)) | 23 | #define sb_root_block(sbp) (le32_to_cpu((sbp)->s_v1.s_root_block)) |
24 | #define set_sb_root_block(sbp,v) ((sbp)->s_v1.s_root_block = cpu_to_le32(v)) | 24 | #define set_sb_root_block(sbp,v) ((sbp)->s_v1.s_root_block = cpu_to_le32(v)) |
25 | 25 | ||
26 | #define sb_jp_journal_1st_block(sbp) \ | 26 | #define sb_jp_journal_1st_block(sbp) \ |
27 | (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_1st_block)) | 27 | (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_1st_block)) |
28 | #define set_sb_jp_journal_1st_block(sbp,v) \ | 28 | #define set_sb_jp_journal_1st_block(sbp,v) \ |
29 | ((sbp)->s_v1.s_journal.jp_journal_1st_block = cpu_to_le32(v)) | 29 | ((sbp)->s_v1.s_journal.jp_journal_1st_block = cpu_to_le32(v)) |
30 | #define sb_jp_journal_dev(sbp) \ | 30 | #define sb_jp_journal_dev(sbp) \ |
31 | (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_dev)) | 31 | (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_dev)) |
32 | #define set_sb_jp_journal_dev(sbp,v) \ | 32 | #define set_sb_jp_journal_dev(sbp,v) \ |
33 | ((sbp)->s_v1.s_journal.jp_journal_dev = cpu_to_le32(v)) | 33 | ((sbp)->s_v1.s_journal.jp_journal_dev = cpu_to_le32(v)) |
34 | #define sb_jp_journal_size(sbp) \ | 34 | #define sb_jp_journal_size(sbp) \ |
35 | (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_size)) | 35 | (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_size)) |
36 | #define set_sb_jp_journal_size(sbp,v) \ | 36 | #define set_sb_jp_journal_size(sbp,v) \ |
37 | ((sbp)->s_v1.s_journal.jp_journal_size = cpu_to_le32(v)) | 37 | ((sbp)->s_v1.s_journal.jp_journal_size = cpu_to_le32(v)) |
38 | #define sb_jp_journal_trans_max(sbp) \ | 38 | #define sb_jp_journal_trans_max(sbp) \ |
39 | (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_trans_max)) | 39 | (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_trans_max)) |
40 | #define set_sb_jp_journal_trans_max(sbp,v) \ | 40 | #define set_sb_jp_journal_trans_max(sbp,v) \ |
41 | ((sbp)->s_v1.s_journal.jp_journal_trans_max = cpu_to_le32(v)) | 41 | ((sbp)->s_v1.s_journal.jp_journal_trans_max = cpu_to_le32(v)) |
42 | #define sb_jp_journal_magic(sbp) \ | 42 | #define sb_jp_journal_magic(sbp) \ |
43 | (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_magic)) | 43 | (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_magic)) |
44 | #define set_sb_jp_journal_magic(sbp,v) \ | 44 | #define set_sb_jp_journal_magic(sbp,v) \ |
45 | ((sbp)->s_v1.s_journal.jp_journal_magic = cpu_to_le32(v)) | 45 | ((sbp)->s_v1.s_journal.jp_journal_magic = cpu_to_le32(v)) |
46 | #define sb_jp_journal_max_batch(sbp) \ | 46 | #define sb_jp_journal_max_batch(sbp) \ |
47 | (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_max_batch)) | 47 | (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_max_batch)) |
48 | #define set_sb_jp_journal_max_batch(sbp,v) \ | 48 | #define set_sb_jp_journal_max_batch(sbp,v) \ |
49 | ((sbp)->s_v1.s_journal.jp_journal_max_batch = cpu_to_le32(v)) | 49 | ((sbp)->s_v1.s_journal.jp_journal_max_batch = cpu_to_le32(v)) |
50 | #define sb_jp_jourmal_max_commit_age(sbp) \ | 50 | #define sb_jp_jourmal_max_commit_age(sbp) \ |
51 | (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_max_commit_age)) | 51 | (le32_to_cpu((sbp)->s_v1.s_journal.jp_journal_max_commit_age)) |
52 | #define set_sb_jp_journal_max_commit_age(sbp,v) \ | 52 | #define set_sb_jp_journal_max_commit_age(sbp,v) \ |
53 | ((sbp)->s_v1.s_journal.jp_journal_max_commit_age = cpu_to_le32(v)) | 53 | ((sbp)->s_v1.s_journal.jp_journal_max_commit_age = cpu_to_le32(v)) |
54 | 54 | ||
55 | #define sb_blocksize(sbp) (le16_to_cpu((sbp)->s_v1.s_blocksize)) | 55 | #define sb_blocksize(sbp) (le16_to_cpu((sbp)->s_v1.s_blocksize)) |
56 | #define set_sb_blocksize(sbp,v) ((sbp)->s_v1.s_blocksize = cpu_to_le16(v)) | 56 | #define set_sb_blocksize(sbp,v) ((sbp)->s_v1.s_blocksize = cpu_to_le16(v)) |
57 | #define sb_oid_maxsize(sbp) (le16_to_cpu((sbp)->s_v1.s_oid_maxsize)) | 57 | #define sb_oid_maxsize(sbp) (le16_to_cpu((sbp)->s_v1.s_oid_maxsize)) |
58 | #define set_sb_oid_maxsize(sbp,v) ((sbp)->s_v1.s_oid_maxsize = cpu_to_le16(v)) | 58 | #define set_sb_oid_maxsize(sbp,v) ((sbp)->s_v1.s_oid_maxsize = cpu_to_le16(v)) |
59 | #define sb_oid_cursize(sbp) (le16_to_cpu((sbp)->s_v1.s_oid_cursize)) | 59 | #define sb_oid_cursize(sbp) (le16_to_cpu((sbp)->s_v1.s_oid_cursize)) |
60 | #define set_sb_oid_cursize(sbp,v) ((sbp)->s_v1.s_oid_cursize = cpu_to_le16(v)) | 60 | #define set_sb_oid_cursize(sbp,v) ((sbp)->s_v1.s_oid_cursize = cpu_to_le16(v)) |
61 | #define sb_umount_state(sbp) (le16_to_cpu((sbp)->s_v1.s_umount_state)) | 61 | #define sb_umount_state(sbp) (le16_to_cpu((sbp)->s_v1.s_umount_state)) |
62 | #define set_sb_umount_state(sbp,v) ((sbp)->s_v1.s_umount_state = cpu_to_le16(v)) | 62 | #define set_sb_umount_state(sbp,v) ((sbp)->s_v1.s_umount_state = cpu_to_le16(v)) |
63 | #define sb_fs_state(sbp) (le16_to_cpu((sbp)->s_v1.s_fs_state)) | 63 | #define sb_fs_state(sbp) (le16_to_cpu((sbp)->s_v1.s_fs_state)) |
64 | #define set_sb_fs_state(sbp,v) ((sbp)->s_v1.s_fs_state = cpu_to_le16(v)) | 64 | #define set_sb_fs_state(sbp,v) ((sbp)->s_v1.s_fs_state = cpu_to_le16(v)) |
65 | #define sb_hash_function_code(sbp) \ | 65 | #define sb_hash_function_code(sbp) \ |
66 | (le32_to_cpu((sbp)->s_v1.s_hash_function_code)) | 66 | (le32_to_cpu((sbp)->s_v1.s_hash_function_code)) |
67 | #define set_sb_hash_function_code(sbp,v) \ | 67 | #define set_sb_hash_function_code(sbp,v) \ |
68 | ((sbp)->s_v1.s_hash_function_code = cpu_to_le32(v)) | 68 | ((sbp)->s_v1.s_hash_function_code = cpu_to_le32(v)) |
69 | #define sb_tree_height(sbp) (le16_to_cpu((sbp)->s_v1.s_tree_height)) | 69 | #define sb_tree_height(sbp) (le16_to_cpu((sbp)->s_v1.s_tree_height)) |
70 | #define set_sb_tree_height(sbp,v) ((sbp)->s_v1.s_tree_height = cpu_to_le16(v)) | 70 | #define set_sb_tree_height(sbp,v) ((sbp)->s_v1.s_tree_height = cpu_to_le16(v)) |
71 | #define sb_bmap_nr(sbp) (le16_to_cpu((sbp)->s_v1.s_bmap_nr)) | 71 | #define sb_bmap_nr(sbp) (le16_to_cpu((sbp)->s_v1.s_bmap_nr)) |
72 | #define set_sb_bmap_nr(sbp,v) ((sbp)->s_v1.s_bmap_nr = cpu_to_le16(v)) | 72 | #define set_sb_bmap_nr(sbp,v) ((sbp)->s_v1.s_bmap_nr = cpu_to_le16(v)) |
73 | #define sb_version(sbp) (le16_to_cpu((sbp)->s_v1.s_version)) | 73 | #define sb_version(sbp) (le16_to_cpu((sbp)->s_v1.s_version)) |
74 | #define set_sb_version(sbp,v) ((sbp)->s_v1.s_version = cpu_to_le16(v)) | 74 | #define set_sb_version(sbp,v) ((sbp)->s_v1.s_version = cpu_to_le16(v)) |
75 | 75 | ||
76 | #define sb_mnt_count(sbp) (le16_to_cpu((sbp)->s_mnt_count)) | 76 | #define sb_mnt_count(sbp) (le16_to_cpu((sbp)->s_mnt_count)) |
77 | #define set_sb_mnt_count(sbp, v) ((sbp)->s_mnt_count = cpu_to_le16(v)) | 77 | #define set_sb_mnt_count(sbp, v) ((sbp)->s_mnt_count = cpu_to_le16(v)) |
78 | 78 | ||
79 | #define sb_reserved_for_journal(sbp) \ | 79 | #define sb_reserved_for_journal(sbp) \ |
80 | (le16_to_cpu((sbp)->s_v1.s_reserved_for_journal)) | 80 | (le16_to_cpu((sbp)->s_v1.s_reserved_for_journal)) |
81 | #define set_sb_reserved_for_journal(sbp,v) \ | 81 | #define set_sb_reserved_for_journal(sbp,v) \ |
82 | ((sbp)->s_v1.s_reserved_for_journal = cpu_to_le16(v)) | 82 | ((sbp)->s_v1.s_reserved_for_journal = cpu_to_le16(v)) |
83 | 83 | ||
84 | /* LOGGING -- */ | 84 | /* LOGGING -- */ |
85 | 85 | ||
86 | /* These all interelate for performance. | 86 | /* These all interelate for performance. |
87 | ** | 87 | ** |
88 | ** If the journal block count is smaller than n transactions, you lose speed. | 88 | ** If the journal block count is smaller than n transactions, you lose speed. |
89 | ** I don't know what n is yet, I'm guessing 8-16. | 89 | ** I don't know what n is yet, I'm guessing 8-16. |
90 | ** | 90 | ** |
91 | ** typical transaction size depends on the application, how often fsync is | 91 | ** typical transaction size depends on the application, how often fsync is |
92 | ** called, and how many metadata blocks you dirty in a 30 second period. | 92 | ** called, and how many metadata blocks you dirty in a 30 second period. |
93 | ** The more small files (<16k) you use, the larger your transactions will | 93 | ** The more small files (<16k) you use, the larger your transactions will |
94 | ** be. | 94 | ** be. |
95 | ** | 95 | ** |
96 | ** If your journal fills faster than dirty buffers get flushed to disk, it must flush them before allowing the journal | 96 | ** If your journal fills faster than dirty buffers get flushed to disk, it must flush them before allowing the journal |
97 | ** to wrap, which slows things down. If you need high speed meta data updates, the journal should be big enough | 97 | ** to wrap, which slows things down. If you need high speed meta data updates, the journal should be big enough |
98 | ** to prevent wrapping before dirty meta blocks get to disk. | 98 | ** to prevent wrapping before dirty meta blocks get to disk. |
99 | ** | 99 | ** |
100 | ** If the batch max is smaller than the transaction max, you'll waste space at the end of the journal | 100 | ** If the batch max is smaller than the transaction max, you'll waste space at the end of the journal |
101 | ** because journal_end sets the next transaction to start at 0 if the next transaction has any chance of wrapping. | 101 | ** because journal_end sets the next transaction to start at 0 if the next transaction has any chance of wrapping. |
102 | ** | 102 | ** |
103 | ** The large the batch max age, the better the speed, and the more meta data changes you'll lose after a crash. | 103 | ** The large the batch max age, the better the speed, and the more meta data changes you'll lose after a crash. |
104 | ** | 104 | ** |
105 | */ | 105 | */ |
106 | 106 | ||
107 | /* don't mess with these for a while */ | 107 | /* don't mess with these for a while */ |
108 | /* we have a node size define somewhere in reiserfs_fs.h. -Hans */ | 108 | /* we have a node size define somewhere in reiserfs_fs.h. -Hans */ |
109 | #define JOURNAL_BLOCK_SIZE 4096 /* BUG gotta get rid of this */ | 109 | #define JOURNAL_BLOCK_SIZE 4096 /* BUG gotta get rid of this */ |
110 | #define JOURNAL_MAX_CNODE 1500 /* max cnodes to allocate. */ | 110 | #define JOURNAL_MAX_CNODE 1500 /* max cnodes to allocate. */ |
111 | #define JOURNAL_HASH_SIZE 8192 | 111 | #define JOURNAL_HASH_SIZE 8192 |
112 | #define JOURNAL_NUM_BITMAPS 5 /* number of copies of the bitmaps to have floating. Must be >= 2 */ | 112 | #define JOURNAL_NUM_BITMAPS 5 /* number of copies of the bitmaps to have floating. Must be >= 2 */ |
113 | 113 | ||
114 | /* One of these for every block in every transaction | 114 | /* One of these for every block in every transaction |
115 | ** Each one is in two hash tables. First, a hash of the current transaction, and after journal_end, a | 115 | ** Each one is in two hash tables. First, a hash of the current transaction, and after journal_end, a |
116 | ** hash of all the in memory transactions. | 116 | ** hash of all the in memory transactions. |
117 | ** next and prev are used by the current transaction (journal_hash). | 117 | ** next and prev are used by the current transaction (journal_hash). |
118 | ** hnext and hprev are used by journal_list_hash. If a block is in more than one transaction, the journal_list_hash | 118 | ** hnext and hprev are used by journal_list_hash. If a block is in more than one transaction, the journal_list_hash |
119 | ** links it in multiple times. This allows flush_journal_list to remove just the cnode belonging | 119 | ** links it in multiple times. This allows flush_journal_list to remove just the cnode belonging |
120 | ** to a given transaction. | 120 | ** to a given transaction. |
121 | */ | 121 | */ |
122 | struct reiserfs_journal_cnode { | 122 | struct reiserfs_journal_cnode { |
123 | struct buffer_head *bh; /* real buffer head */ | 123 | struct buffer_head *bh; /* real buffer head */ |
124 | struct super_block *sb; /* dev of real buffer head */ | 124 | struct super_block *sb; /* dev of real buffer head */ |
125 | __u32 blocknr; /* block number of real buffer head, == 0 when buffer on disk */ | 125 | __u32 blocknr; /* block number of real buffer head, == 0 when buffer on disk */ |
126 | unsigned long state; | 126 | unsigned long state; |
127 | struct reiserfs_journal_list *jlist; /* journal list this cnode lives in */ | 127 | struct reiserfs_journal_list *jlist; /* journal list this cnode lives in */ |
128 | struct reiserfs_journal_cnode *next; /* next in transaction list */ | 128 | struct reiserfs_journal_cnode *next; /* next in transaction list */ |
129 | struct reiserfs_journal_cnode *prev; /* prev in transaction list */ | 129 | struct reiserfs_journal_cnode *prev; /* prev in transaction list */ |
130 | struct reiserfs_journal_cnode *hprev; /* prev in hash list */ | 130 | struct reiserfs_journal_cnode *hprev; /* prev in hash list */ |
131 | struct reiserfs_journal_cnode *hnext; /* next in hash list */ | 131 | struct reiserfs_journal_cnode *hnext; /* next in hash list */ |
132 | }; | 132 | }; |
133 | 133 | ||
134 | struct reiserfs_bitmap_node { | 134 | struct reiserfs_bitmap_node { |
135 | int id; | 135 | int id; |
136 | char *data; | 136 | char *data; |
137 | struct list_head list; | 137 | struct list_head list; |
138 | }; | 138 | }; |
139 | 139 | ||
140 | struct reiserfs_list_bitmap { | 140 | struct reiserfs_list_bitmap { |
141 | struct reiserfs_journal_list *journal_list; | 141 | struct reiserfs_journal_list *journal_list; |
142 | struct reiserfs_bitmap_node **bitmaps; | 142 | struct reiserfs_bitmap_node **bitmaps; |
143 | }; | 143 | }; |
144 | 144 | ||
145 | /* | 145 | /* |
146 | ** one of these for each transaction. The most important part here is the j_realblock. | 146 | ** one of these for each transaction. The most important part here is the j_realblock. |
147 | ** this list of cnodes is used to hash all the blocks in all the commits, to mark all the | 147 | ** this list of cnodes is used to hash all the blocks in all the commits, to mark all the |
148 | ** real buffer heads dirty once all the commits hit the disk, | 148 | ** real buffer heads dirty once all the commits hit the disk, |
149 | ** and to make sure every real block in a transaction is on disk before allowing the log area | 149 | ** and to make sure every real block in a transaction is on disk before allowing the log area |
150 | ** to be overwritten */ | 150 | ** to be overwritten */ |
151 | struct reiserfs_journal_list { | 151 | struct reiserfs_journal_list { |
152 | unsigned long j_start; | 152 | unsigned long j_start; |
153 | unsigned long j_state; | 153 | unsigned long j_state; |
154 | unsigned long j_len; | 154 | unsigned long j_len; |
155 | atomic_t j_nonzerolen; | 155 | atomic_t j_nonzerolen; |
156 | atomic_t j_commit_left; | 156 | atomic_t j_commit_left; |
157 | atomic_t j_older_commits_done; /* all commits older than this on disk */ | 157 | atomic_t j_older_commits_done; /* all commits older than this on disk */ |
158 | struct mutex j_commit_mutex; | 158 | struct mutex j_commit_mutex; |
159 | unsigned int j_trans_id; | 159 | unsigned int j_trans_id; |
160 | time_t j_timestamp; | 160 | time_t j_timestamp; |
161 | struct reiserfs_list_bitmap *j_list_bitmap; | 161 | struct reiserfs_list_bitmap *j_list_bitmap; |
162 | struct buffer_head *j_commit_bh; /* commit buffer head */ | 162 | struct buffer_head *j_commit_bh; /* commit buffer head */ |
163 | struct reiserfs_journal_cnode *j_realblock; | 163 | struct reiserfs_journal_cnode *j_realblock; |
164 | struct reiserfs_journal_cnode *j_freedlist; /* list of buffers that were freed during this trans. free each of these on flush */ | 164 | struct reiserfs_journal_cnode *j_freedlist; /* list of buffers that were freed during this trans. free each of these on flush */ |
165 | /* time ordered list of all active transactions */ | 165 | /* time ordered list of all active transactions */ |
166 | struct list_head j_list; | 166 | struct list_head j_list; |
167 | 167 | ||
168 | /* time ordered list of all transactions we haven't tried to flush yet */ | 168 | /* time ordered list of all transactions we haven't tried to flush yet */ |
169 | struct list_head j_working_list; | 169 | struct list_head j_working_list; |
170 | 170 | ||
171 | /* list of tail conversion targets in need of flush before commit */ | 171 | /* list of tail conversion targets in need of flush before commit */ |
172 | struct list_head j_tail_bh_list; | 172 | struct list_head j_tail_bh_list; |
173 | /* list of data=ordered buffers in need of flush before commit */ | 173 | /* list of data=ordered buffers in need of flush before commit */ |
174 | struct list_head j_bh_list; | 174 | struct list_head j_bh_list; |
175 | int j_refcount; | 175 | int j_refcount; |
176 | }; | 176 | }; |
177 | 177 | ||
178 | struct reiserfs_journal { | 178 | struct reiserfs_journal { |
179 | struct buffer_head **j_ap_blocks; /* journal blocks on disk */ | 179 | struct buffer_head **j_ap_blocks; /* journal blocks on disk */ |
180 | struct reiserfs_journal_cnode *j_last; /* newest journal block */ | 180 | struct reiserfs_journal_cnode *j_last; /* newest journal block */ |
181 | struct reiserfs_journal_cnode *j_first; /* oldest journal block. start here for traverse */ | 181 | struct reiserfs_journal_cnode *j_first; /* oldest journal block. start here for traverse */ |
182 | 182 | ||
183 | struct block_device *j_dev_bd; | 183 | struct block_device *j_dev_bd; |
184 | fmode_t j_dev_mode; | 184 | fmode_t j_dev_mode; |
185 | int j_1st_reserved_block; /* first block on s_dev of reserved area journal */ | 185 | int j_1st_reserved_block; /* first block on s_dev of reserved area journal */ |
186 | 186 | ||
187 | unsigned long j_state; | 187 | unsigned long j_state; |
188 | unsigned int j_trans_id; | 188 | unsigned int j_trans_id; |
189 | unsigned long j_mount_id; | 189 | unsigned long j_mount_id; |
190 | unsigned long j_start; /* start of current waiting commit (index into j_ap_blocks) */ | 190 | unsigned long j_start; /* start of current waiting commit (index into j_ap_blocks) */ |
191 | unsigned long j_len; /* length of current waiting commit */ | 191 | unsigned long j_len; /* length of current waiting commit */ |
192 | unsigned long j_len_alloc; /* number of buffers requested by journal_begin() */ | 192 | unsigned long j_len_alloc; /* number of buffers requested by journal_begin() */ |
193 | atomic_t j_wcount; /* count of writers for current commit */ | 193 | atomic_t j_wcount; /* count of writers for current commit */ |
194 | unsigned long j_bcount; /* batch count. allows turning X transactions into 1 */ | 194 | unsigned long j_bcount; /* batch count. allows turning X transactions into 1 */ |
195 | unsigned long j_first_unflushed_offset; /* first unflushed transactions offset */ | 195 | unsigned long j_first_unflushed_offset; /* first unflushed transactions offset */ |
196 | unsigned j_last_flush_trans_id; /* last fully flushed journal timestamp */ | 196 | unsigned j_last_flush_trans_id; /* last fully flushed journal timestamp */ |
197 | struct buffer_head *j_header_bh; | 197 | struct buffer_head *j_header_bh; |
198 | 198 | ||
199 | time_t j_trans_start_time; /* time this transaction started */ | 199 | time_t j_trans_start_time; /* time this transaction started */ |
200 | struct mutex j_mutex; | 200 | struct mutex j_mutex; |
201 | struct mutex j_flush_mutex; | 201 | struct mutex j_flush_mutex; |
202 | wait_queue_head_t j_join_wait; /* wait for current transaction to finish before starting new one */ | 202 | wait_queue_head_t j_join_wait; /* wait for current transaction to finish before starting new one */ |
203 | atomic_t j_jlock; /* lock for j_join_wait */ | 203 | atomic_t j_jlock; /* lock for j_join_wait */ |
204 | int j_list_bitmap_index; /* number of next list bitmap to use */ | 204 | int j_list_bitmap_index; /* number of next list bitmap to use */ |
205 | int j_must_wait; /* no more journal begins allowed. MUST sleep on j_join_wait */ | 205 | int j_must_wait; /* no more journal begins allowed. MUST sleep on j_join_wait */ |
206 | int j_next_full_flush; /* next journal_end will flush all journal list */ | 206 | int j_next_full_flush; /* next journal_end will flush all journal list */ |
207 | int j_next_async_flush; /* next journal_end will flush all async commits */ | 207 | int j_next_async_flush; /* next journal_end will flush all async commits */ |
208 | 208 | ||
209 | int j_cnode_used; /* number of cnodes on the used list */ | 209 | int j_cnode_used; /* number of cnodes on the used list */ |
210 | int j_cnode_free; /* number of cnodes on the free list */ | 210 | int j_cnode_free; /* number of cnodes on the free list */ |
211 | 211 | ||
212 | unsigned int j_trans_max; /* max number of blocks in a transaction. */ | 212 | unsigned int j_trans_max; /* max number of blocks in a transaction. */ |
213 | unsigned int j_max_batch; /* max number of blocks to batch into a trans */ | 213 | unsigned int j_max_batch; /* max number of blocks to batch into a trans */ |
214 | unsigned int j_max_commit_age; /* in seconds, how old can an async commit be */ | 214 | unsigned int j_max_commit_age; /* in seconds, how old can an async commit be */ |
215 | unsigned int j_max_trans_age; /* in seconds, how old can a transaction be */ | 215 | unsigned int j_max_trans_age; /* in seconds, how old can a transaction be */ |
216 | unsigned int j_default_max_commit_age; /* the default for the max commit age */ | 216 | unsigned int j_default_max_commit_age; /* the default for the max commit age */ |
217 | 217 | ||
218 | struct reiserfs_journal_cnode *j_cnode_free_list; | 218 | struct reiserfs_journal_cnode *j_cnode_free_list; |
219 | struct reiserfs_journal_cnode *j_cnode_free_orig; /* orig pointer returned from vmalloc */ | 219 | struct reiserfs_journal_cnode *j_cnode_free_orig; /* orig pointer returned from vmalloc */ |
220 | 220 | ||
221 | struct reiserfs_journal_list *j_current_jl; | 221 | struct reiserfs_journal_list *j_current_jl; |
222 | int j_free_bitmap_nodes; | 222 | int j_free_bitmap_nodes; |
223 | int j_used_bitmap_nodes; | 223 | int j_used_bitmap_nodes; |
224 | 224 | ||
225 | int j_num_lists; /* total number of active transactions */ | 225 | int j_num_lists; /* total number of active transactions */ |
226 | int j_num_work_lists; /* number that need attention from kreiserfsd */ | 226 | int j_num_work_lists; /* number that need attention from kreiserfsd */ |
227 | 227 | ||
228 | /* debugging to make sure things are flushed in order */ | 228 | /* debugging to make sure things are flushed in order */ |
229 | unsigned int j_last_flush_id; | 229 | unsigned int j_last_flush_id; |
230 | 230 | ||
231 | /* debugging to make sure things are committed in order */ | 231 | /* debugging to make sure things are committed in order */ |
232 | unsigned int j_last_commit_id; | 232 | unsigned int j_last_commit_id; |
233 | 233 | ||
234 | struct list_head j_bitmap_nodes; | 234 | struct list_head j_bitmap_nodes; |
235 | struct list_head j_dirty_buffers; | 235 | struct list_head j_dirty_buffers; |
236 | spinlock_t j_dirty_buffers_lock; /* protects j_dirty_buffers */ | 236 | spinlock_t j_dirty_buffers_lock; /* protects j_dirty_buffers */ |
237 | 237 | ||
238 | /* list of all active transactions */ | 238 | /* list of all active transactions */ |
239 | struct list_head j_journal_list; | 239 | struct list_head j_journal_list; |
240 | /* lists that haven't been touched by writeback attempts */ | 240 | /* lists that haven't been touched by writeback attempts */ |
241 | struct list_head j_working_list; | 241 | struct list_head j_working_list; |
242 | 242 | ||
243 | struct reiserfs_list_bitmap j_list_bitmap[JOURNAL_NUM_BITMAPS]; /* array of bitmaps to record the deleted blocks */ | 243 | struct reiserfs_list_bitmap j_list_bitmap[JOURNAL_NUM_BITMAPS]; /* array of bitmaps to record the deleted blocks */ |
244 | struct reiserfs_journal_cnode *j_hash_table[JOURNAL_HASH_SIZE]; /* hash table for real buffer heads in current trans */ | 244 | struct reiserfs_journal_cnode *j_hash_table[JOURNAL_HASH_SIZE]; /* hash table for real buffer heads in current trans */ |
245 | struct reiserfs_journal_cnode *j_list_hash_table[JOURNAL_HASH_SIZE]; /* hash table for all the real buffer heads in all | 245 | struct reiserfs_journal_cnode *j_list_hash_table[JOURNAL_HASH_SIZE]; /* hash table for all the real buffer heads in all |
246 | the transactions */ | 246 | the transactions */ |
247 | struct list_head j_prealloc_list; /* list of inodes which have preallocated blocks */ | 247 | struct list_head j_prealloc_list; /* list of inodes which have preallocated blocks */ |
248 | int j_persistent_trans; | 248 | int j_persistent_trans; |
249 | unsigned long j_max_trans_size; | 249 | unsigned long j_max_trans_size; |
250 | unsigned long j_max_batch_size; | 250 | unsigned long j_max_batch_size; |
251 | 251 | ||
252 | int j_errno; | 252 | int j_errno; |
253 | 253 | ||
254 | /* when flushing ordered buffers, throttle new ordered writers */ | 254 | /* when flushing ordered buffers, throttle new ordered writers */ |
255 | struct delayed_work j_work; | 255 | struct delayed_work j_work; |
256 | struct super_block *j_work_sb; | 256 | struct super_block *j_work_sb; |
257 | atomic_t j_async_throttle; | 257 | atomic_t j_async_throttle; |
258 | }; | 258 | }; |
259 | 259 | ||
260 | enum journal_state_bits { | 260 | enum journal_state_bits { |
261 | J_WRITERS_BLOCKED = 1, /* set when new writers not allowed */ | 261 | J_WRITERS_BLOCKED = 1, /* set when new writers not allowed */ |
262 | J_WRITERS_QUEUED, /* set when log is full due to too many writers */ | 262 | J_WRITERS_QUEUED, /* set when log is full due to too many writers */ |
263 | J_ABORTED, /* set when log is aborted */ | 263 | J_ABORTED, /* set when log is aborted */ |
264 | }; | 264 | }; |
265 | 265 | ||
266 | #define JOURNAL_DESC_MAGIC "ReIsErLB" /* ick. magic string to find desc blocks in the journal */ | 266 | #define JOURNAL_DESC_MAGIC "ReIsErLB" /* ick. magic string to find desc blocks in the journal */ |
267 | 267 | ||
268 | typedef __u32(*hashf_t) (const signed char *, int); | 268 | typedef __u32(*hashf_t) (const signed char *, int); |
269 | 269 | ||
270 | struct reiserfs_bitmap_info { | 270 | struct reiserfs_bitmap_info { |
271 | __u32 free_count; | 271 | __u32 free_count; |
272 | }; | 272 | }; |
273 | 273 | ||
274 | struct proc_dir_entry; | 274 | struct proc_dir_entry; |
275 | 275 | ||
276 | #if defined( CONFIG_PROC_FS ) && defined( CONFIG_REISERFS_PROC_INFO ) | 276 | #if defined( CONFIG_PROC_FS ) && defined( CONFIG_REISERFS_PROC_INFO ) |
277 | typedef unsigned long int stat_cnt_t; | 277 | typedef unsigned long int stat_cnt_t; |
278 | typedef struct reiserfs_proc_info_data { | 278 | typedef struct reiserfs_proc_info_data { |
279 | spinlock_t lock; | 279 | spinlock_t lock; |
280 | int exiting; | 280 | int exiting; |
281 | int max_hash_collisions; | 281 | int max_hash_collisions; |
282 | 282 | ||
283 | stat_cnt_t breads; | 283 | stat_cnt_t breads; |
284 | stat_cnt_t bread_miss; | 284 | stat_cnt_t bread_miss; |
285 | stat_cnt_t search_by_key; | 285 | stat_cnt_t search_by_key; |
286 | stat_cnt_t search_by_key_fs_changed; | 286 | stat_cnt_t search_by_key_fs_changed; |
287 | stat_cnt_t search_by_key_restarted; | 287 | stat_cnt_t search_by_key_restarted; |
288 | 288 | ||
289 | stat_cnt_t insert_item_restarted; | 289 | stat_cnt_t insert_item_restarted; |
290 | stat_cnt_t paste_into_item_restarted; | 290 | stat_cnt_t paste_into_item_restarted; |
291 | stat_cnt_t cut_from_item_restarted; | 291 | stat_cnt_t cut_from_item_restarted; |
292 | stat_cnt_t delete_solid_item_restarted; | 292 | stat_cnt_t delete_solid_item_restarted; |
293 | stat_cnt_t delete_item_restarted; | 293 | stat_cnt_t delete_item_restarted; |
294 | 294 | ||
295 | stat_cnt_t leaked_oid; | 295 | stat_cnt_t leaked_oid; |
296 | stat_cnt_t leaves_removable; | 296 | stat_cnt_t leaves_removable; |
297 | 297 | ||
298 | /* balances per level. Use explicit 5 as MAX_HEIGHT is not visible yet. */ | 298 | /* balances per level. Use explicit 5 as MAX_HEIGHT is not visible yet. */ |
299 | stat_cnt_t balance_at[5]; /* XXX */ | 299 | stat_cnt_t balance_at[5]; /* XXX */ |
300 | /* sbk == search_by_key */ | 300 | /* sbk == search_by_key */ |
301 | stat_cnt_t sbk_read_at[5]; /* XXX */ | 301 | stat_cnt_t sbk_read_at[5]; /* XXX */ |
302 | stat_cnt_t sbk_fs_changed[5]; | 302 | stat_cnt_t sbk_fs_changed[5]; |
303 | stat_cnt_t sbk_restarted[5]; | 303 | stat_cnt_t sbk_restarted[5]; |
304 | stat_cnt_t items_at[5]; /* XXX */ | 304 | stat_cnt_t items_at[5]; /* XXX */ |
305 | stat_cnt_t free_at[5]; /* XXX */ | 305 | stat_cnt_t free_at[5]; /* XXX */ |
306 | stat_cnt_t can_node_be_removed[5]; /* XXX */ | 306 | stat_cnt_t can_node_be_removed[5]; /* XXX */ |
307 | long int lnum[5]; /* XXX */ | 307 | long int lnum[5]; /* XXX */ |
308 | long int rnum[5]; /* XXX */ | 308 | long int rnum[5]; /* XXX */ |
309 | long int lbytes[5]; /* XXX */ | 309 | long int lbytes[5]; /* XXX */ |
310 | long int rbytes[5]; /* XXX */ | 310 | long int rbytes[5]; /* XXX */ |
311 | stat_cnt_t get_neighbors[5]; | 311 | stat_cnt_t get_neighbors[5]; |
312 | stat_cnt_t get_neighbors_restart[5]; | 312 | stat_cnt_t get_neighbors_restart[5]; |
313 | stat_cnt_t need_l_neighbor[5]; | 313 | stat_cnt_t need_l_neighbor[5]; |
314 | stat_cnt_t need_r_neighbor[5]; | 314 | stat_cnt_t need_r_neighbor[5]; |
315 | 315 | ||
316 | stat_cnt_t free_block; | 316 | stat_cnt_t free_block; |
317 | struct __scan_bitmap_stats { | 317 | struct __scan_bitmap_stats { |
318 | stat_cnt_t call; | 318 | stat_cnt_t call; |
319 | stat_cnt_t wait; | 319 | stat_cnt_t wait; |
320 | stat_cnt_t bmap; | 320 | stat_cnt_t bmap; |
321 | stat_cnt_t retry; | 321 | stat_cnt_t retry; |
322 | stat_cnt_t in_journal_hint; | 322 | stat_cnt_t in_journal_hint; |
323 | stat_cnt_t in_journal_nohint; | 323 | stat_cnt_t in_journal_nohint; |
324 | stat_cnt_t stolen; | 324 | stat_cnt_t stolen; |
325 | } scan_bitmap; | 325 | } scan_bitmap; |
326 | struct __journal_stats { | 326 | struct __journal_stats { |
327 | stat_cnt_t in_journal; | 327 | stat_cnt_t in_journal; |
328 | stat_cnt_t in_journal_bitmap; | 328 | stat_cnt_t in_journal_bitmap; |
329 | stat_cnt_t in_journal_reusable; | 329 | stat_cnt_t in_journal_reusable; |
330 | stat_cnt_t lock_journal; | 330 | stat_cnt_t lock_journal; |
331 | stat_cnt_t lock_journal_wait; | 331 | stat_cnt_t lock_journal_wait; |
332 | stat_cnt_t journal_being; | 332 | stat_cnt_t journal_being; |
333 | stat_cnt_t journal_relock_writers; | 333 | stat_cnt_t journal_relock_writers; |
334 | stat_cnt_t journal_relock_wcount; | 334 | stat_cnt_t journal_relock_wcount; |
335 | stat_cnt_t mark_dirty; | 335 | stat_cnt_t mark_dirty; |
336 | stat_cnt_t mark_dirty_already; | 336 | stat_cnt_t mark_dirty_already; |
337 | stat_cnt_t mark_dirty_notjournal; | 337 | stat_cnt_t mark_dirty_notjournal; |
338 | stat_cnt_t restore_prepared; | 338 | stat_cnt_t restore_prepared; |
339 | stat_cnt_t prepare; | 339 | stat_cnt_t prepare; |
340 | stat_cnt_t prepare_retry; | 340 | stat_cnt_t prepare_retry; |
341 | } journal; | 341 | } journal; |
342 | } reiserfs_proc_info_data_t; | 342 | } reiserfs_proc_info_data_t; |
343 | #else | 343 | #else |
344 | typedef struct reiserfs_proc_info_data { | 344 | typedef struct reiserfs_proc_info_data { |
345 | } reiserfs_proc_info_data_t; | 345 | } reiserfs_proc_info_data_t; |
346 | #endif | 346 | #endif |
347 | 347 | ||
348 | /* reiserfs union of in-core super block data */ | 348 | /* reiserfs union of in-core super block data */ |
349 | struct reiserfs_sb_info { | 349 | struct reiserfs_sb_info { |
350 | struct buffer_head *s_sbh; /* Buffer containing the super block */ | 350 | struct buffer_head *s_sbh; /* Buffer containing the super block */ |
351 | /* both the comment and the choice of | 351 | /* both the comment and the choice of |
352 | name are unclear for s_rs -Hans */ | 352 | name are unclear for s_rs -Hans */ |
353 | struct reiserfs_super_block *s_rs; /* Pointer to the super block in the buffer */ | 353 | struct reiserfs_super_block *s_rs; /* Pointer to the super block in the buffer */ |
354 | struct reiserfs_bitmap_info *s_ap_bitmap; | 354 | struct reiserfs_bitmap_info *s_ap_bitmap; |
355 | struct reiserfs_journal *s_journal; /* pointer to journal information */ | 355 | struct reiserfs_journal *s_journal; /* pointer to journal information */ |
356 | unsigned short s_mount_state; /* reiserfs state (valid, invalid) */ | 356 | unsigned short s_mount_state; /* reiserfs state (valid, invalid) */ |
357 | 357 | ||
358 | /* Comment? -Hans */ | 358 | /* Comment? -Hans */ |
359 | void (*end_io_handler) (struct buffer_head *, int); | 359 | void (*end_io_handler) (struct buffer_head *, int); |
360 | hashf_t s_hash_function; /* pointer to function which is used | 360 | hashf_t s_hash_function; /* pointer to function which is used |
361 | to sort names in directory. Set on | 361 | to sort names in directory. Set on |
362 | mount */ | 362 | mount */ |
363 | unsigned long s_mount_opt; /* reiserfs's mount options are set | 363 | unsigned long s_mount_opt; /* reiserfs's mount options are set |
364 | here (currently - NOTAIL, NOLOG, | 364 | here (currently - NOTAIL, NOLOG, |
365 | REPLAYONLY) */ | 365 | REPLAYONLY) */ |
366 | 366 | ||
367 | struct { /* This is a structure that describes block allocator options */ | 367 | struct { /* This is a structure that describes block allocator options */ |
368 | unsigned long bits; /* Bitfield for enable/disable kind of options */ | 368 | unsigned long bits; /* Bitfield for enable/disable kind of options */ |
369 | unsigned long large_file_size; /* size started from which we consider file to be a large one(in blocks) */ | 369 | unsigned long large_file_size; /* size started from which we consider file to be a large one(in blocks) */ |
370 | int border; /* percentage of disk, border takes */ | 370 | int border; /* percentage of disk, border takes */ |
371 | int preallocmin; /* Minimal file size (in blocks) starting from which we do preallocations */ | 371 | int preallocmin; /* Minimal file size (in blocks) starting from which we do preallocations */ |
372 | int preallocsize; /* Number of blocks we try to prealloc when file | 372 | int preallocsize; /* Number of blocks we try to prealloc when file |
373 | reaches preallocmin size (in blocks) or | 373 | reaches preallocmin size (in blocks) or |
374 | prealloc_list is empty. */ | 374 | prealloc_list is empty. */ |
375 | } s_alloc_options; | 375 | } s_alloc_options; |
376 | 376 | ||
377 | /* Comment? -Hans */ | 377 | /* Comment? -Hans */ |
378 | wait_queue_head_t s_wait; | 378 | wait_queue_head_t s_wait; |
379 | /* To be obsoleted soon by per buffer seals.. -Hans */ | 379 | /* To be obsoleted soon by per buffer seals.. -Hans */ |
380 | atomic_t s_generation_counter; // increased by one every time the | 380 | atomic_t s_generation_counter; // increased by one every time the |
381 | // tree gets re-balanced | 381 | // tree gets re-balanced |
382 | unsigned long s_properties; /* File system properties. Currently holds | 382 | unsigned long s_properties; /* File system properties. Currently holds |
383 | on-disk FS format */ | 383 | on-disk FS format */ |
384 | 384 | ||
385 | /* session statistics */ | 385 | /* session statistics */ |
386 | int s_disk_reads; | 386 | int s_disk_reads; |
387 | int s_disk_writes; | 387 | int s_disk_writes; |
388 | int s_fix_nodes; | 388 | int s_fix_nodes; |
389 | int s_do_balance; | 389 | int s_do_balance; |
390 | int s_unneeded_left_neighbor; | 390 | int s_unneeded_left_neighbor; |
391 | int s_good_search_by_key_reada; | 391 | int s_good_search_by_key_reada; |
392 | int s_bmaps; | 392 | int s_bmaps; |
393 | int s_bmaps_without_search; | 393 | int s_bmaps_without_search; |
394 | int s_direct2indirect; | 394 | int s_direct2indirect; |
395 | int s_indirect2direct; | 395 | int s_indirect2direct; |
396 | /* set up when it's ok for reiserfs_read_inode2() to read from | 396 | /* set up when it's ok for reiserfs_read_inode2() to read from |
397 | disk inode with nlink==0. Currently this is only used during | 397 | disk inode with nlink==0. Currently this is only used during |
398 | finish_unfinished() processing at mount time */ | 398 | finish_unfinished() processing at mount time */ |
399 | int s_is_unlinked_ok; | 399 | int s_is_unlinked_ok; |
400 | reiserfs_proc_info_data_t s_proc_info_data; | 400 | reiserfs_proc_info_data_t s_proc_info_data; |
401 | struct proc_dir_entry *procdir; | 401 | struct proc_dir_entry *procdir; |
402 | int reserved_blocks; /* amount of blocks reserved for further allocations */ | 402 | int reserved_blocks; /* amount of blocks reserved for further allocations */ |
403 | spinlock_t bitmap_lock; /* this lock on now only used to protect reserved_blocks variable */ | 403 | spinlock_t bitmap_lock; /* this lock on now only used to protect reserved_blocks variable */ |
404 | struct dentry *priv_root; /* root of /.reiserfs_priv */ | 404 | struct dentry *priv_root; /* root of /.reiserfs_priv */ |
405 | struct dentry *xattr_root; /* root of /.reiserfs_priv/.xa */ | 405 | struct dentry *xattr_root; /* root of /.reiserfs_priv/xattrs */ |
406 | int j_errno; | 406 | int j_errno; |
407 | #ifdef CONFIG_QUOTA | 407 | #ifdef CONFIG_QUOTA |
408 | char *s_qf_names[MAXQUOTAS]; | 408 | char *s_qf_names[MAXQUOTAS]; |
409 | int s_jquota_fmt; | 409 | int s_jquota_fmt; |
410 | #endif | 410 | #endif |
411 | }; | 411 | }; |
412 | 412 | ||
413 | /* Definitions of reiserfs on-disk properties: */ | 413 | /* Definitions of reiserfs on-disk properties: */ |
414 | #define REISERFS_3_5 0 | 414 | #define REISERFS_3_5 0 |
415 | #define REISERFS_3_6 1 | 415 | #define REISERFS_3_6 1 |
416 | #define REISERFS_OLD_FORMAT 2 | 416 | #define REISERFS_OLD_FORMAT 2 |
417 | 417 | ||
418 | enum reiserfs_mount_options { | 418 | enum reiserfs_mount_options { |
419 | /* Mount options */ | 419 | /* Mount options */ |
420 | REISERFS_LARGETAIL, /* large tails will be created in a session */ | 420 | REISERFS_LARGETAIL, /* large tails will be created in a session */ |
421 | REISERFS_SMALLTAIL, /* small (for files less than block size) tails will be created in a session */ | 421 | REISERFS_SMALLTAIL, /* small (for files less than block size) tails will be created in a session */ |
422 | REPLAYONLY, /* replay journal and return 0. Use by fsck */ | 422 | REPLAYONLY, /* replay journal and return 0. Use by fsck */ |
423 | REISERFS_CONVERT, /* -o conv: causes conversion of old | 423 | REISERFS_CONVERT, /* -o conv: causes conversion of old |
424 | format super block to the new | 424 | format super block to the new |
425 | format. If not specified - old | 425 | format. If not specified - old |
426 | partition will be dealt with in a | 426 | partition will be dealt with in a |
427 | manner of 3.5.x */ | 427 | manner of 3.5.x */ |
428 | 428 | ||
429 | /* -o hash={tea, rupasov, r5, detect} is meant for properly mounting | 429 | /* -o hash={tea, rupasov, r5, detect} is meant for properly mounting |
430 | ** reiserfs disks from 3.5.19 or earlier. 99% of the time, this option | 430 | ** reiserfs disks from 3.5.19 or earlier. 99% of the time, this option |
431 | ** is not required. If the normal autodection code can't determine which | 431 | ** is not required. If the normal autodection code can't determine which |
432 | ** hash to use (because both hashes had the same value for a file) | 432 | ** hash to use (because both hashes had the same value for a file) |
433 | ** use this option to force a specific hash. It won't allow you to override | 433 | ** use this option to force a specific hash. It won't allow you to override |
434 | ** the existing hash on the FS, so if you have a tea hash disk, and mount | 434 | ** the existing hash on the FS, so if you have a tea hash disk, and mount |
435 | ** with -o hash=rupasov, the mount will fail. | 435 | ** with -o hash=rupasov, the mount will fail. |
436 | */ | 436 | */ |
437 | FORCE_TEA_HASH, /* try to force tea hash on mount */ | 437 | FORCE_TEA_HASH, /* try to force tea hash on mount */ |
438 | FORCE_RUPASOV_HASH, /* try to force rupasov hash on mount */ | 438 | FORCE_RUPASOV_HASH, /* try to force rupasov hash on mount */ |
439 | FORCE_R5_HASH, /* try to force rupasov hash on mount */ | 439 | FORCE_R5_HASH, /* try to force rupasov hash on mount */ |
440 | FORCE_HASH_DETECT, /* try to detect hash function on mount */ | 440 | FORCE_HASH_DETECT, /* try to detect hash function on mount */ |
441 | 441 | ||
442 | REISERFS_DATA_LOG, | 442 | REISERFS_DATA_LOG, |
443 | REISERFS_DATA_ORDERED, | 443 | REISERFS_DATA_ORDERED, |
444 | REISERFS_DATA_WRITEBACK, | 444 | REISERFS_DATA_WRITEBACK, |
445 | 445 | ||
446 | /* used for testing experimental features, makes benchmarking new | 446 | /* used for testing experimental features, makes benchmarking new |
447 | features with and without more convenient, should never be used by | 447 | features with and without more convenient, should never be used by |
448 | users in any code shipped to users (ideally) */ | 448 | users in any code shipped to users (ideally) */ |
449 | 449 | ||
450 | REISERFS_NO_BORDER, | 450 | REISERFS_NO_BORDER, |
451 | REISERFS_NO_UNHASHED_RELOCATION, | 451 | REISERFS_NO_UNHASHED_RELOCATION, |
452 | REISERFS_HASHED_RELOCATION, | 452 | REISERFS_HASHED_RELOCATION, |
453 | REISERFS_ATTRS, | 453 | REISERFS_ATTRS, |
454 | REISERFS_XATTRS_USER, | 454 | REISERFS_XATTRS_USER, |
455 | REISERFS_POSIXACL, | 455 | REISERFS_POSIXACL, |
456 | REISERFS_BARRIER_NONE, | 456 | REISERFS_BARRIER_NONE, |
457 | REISERFS_BARRIER_FLUSH, | 457 | REISERFS_BARRIER_FLUSH, |
458 | 458 | ||
459 | /* Actions on error */ | 459 | /* Actions on error */ |
460 | REISERFS_ERROR_PANIC, | 460 | REISERFS_ERROR_PANIC, |
461 | REISERFS_ERROR_RO, | 461 | REISERFS_ERROR_RO, |
462 | REISERFS_ERROR_CONTINUE, | 462 | REISERFS_ERROR_CONTINUE, |
463 | 463 | ||
464 | REISERFS_QUOTA, /* Some quota option specified */ | 464 | REISERFS_QUOTA, /* Some quota option specified */ |
465 | 465 | ||
466 | REISERFS_TEST1, | 466 | REISERFS_TEST1, |
467 | REISERFS_TEST2, | 467 | REISERFS_TEST2, |
468 | REISERFS_TEST3, | 468 | REISERFS_TEST3, |
469 | REISERFS_TEST4, | 469 | REISERFS_TEST4, |
470 | REISERFS_UNSUPPORTED_OPT, | 470 | REISERFS_UNSUPPORTED_OPT, |
471 | }; | 471 | }; |
472 | 472 | ||
473 | #define reiserfs_r5_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_R5_HASH)) | 473 | #define reiserfs_r5_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_R5_HASH)) |
474 | #define reiserfs_rupasov_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_RUPASOV_HASH)) | 474 | #define reiserfs_rupasov_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_RUPASOV_HASH)) |
475 | #define reiserfs_tea_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_TEA_HASH)) | 475 | #define reiserfs_tea_hash(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_TEA_HASH)) |
476 | #define reiserfs_hash_detect(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_HASH_DETECT)) | 476 | #define reiserfs_hash_detect(s) (REISERFS_SB(s)->s_mount_opt & (1 << FORCE_HASH_DETECT)) |
477 | #define reiserfs_no_border(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_NO_BORDER)) | 477 | #define reiserfs_no_border(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_NO_BORDER)) |
478 | #define reiserfs_no_unhashed_relocation(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_NO_UNHASHED_RELOCATION)) | 478 | #define reiserfs_no_unhashed_relocation(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_NO_UNHASHED_RELOCATION)) |
479 | #define reiserfs_hashed_relocation(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_HASHED_RELOCATION)) | 479 | #define reiserfs_hashed_relocation(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_HASHED_RELOCATION)) |
480 | #define reiserfs_test4(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TEST4)) | 480 | #define reiserfs_test4(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_TEST4)) |
481 | 481 | ||
482 | #define have_large_tails(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_LARGETAIL)) | 482 | #define have_large_tails(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_LARGETAIL)) |
483 | #define have_small_tails(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_SMALLTAIL)) | 483 | #define have_small_tails(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_SMALLTAIL)) |
484 | #define replay_only(s) (REISERFS_SB(s)->s_mount_opt & (1 << REPLAYONLY)) | 484 | #define replay_only(s) (REISERFS_SB(s)->s_mount_opt & (1 << REPLAYONLY)) |
485 | #define reiserfs_attrs(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ATTRS)) | 485 | #define reiserfs_attrs(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ATTRS)) |
486 | #define old_format_only(s) (REISERFS_SB(s)->s_properties & (1 << REISERFS_3_5)) | 486 | #define old_format_only(s) (REISERFS_SB(s)->s_properties & (1 << REISERFS_3_5)) |
487 | #define convert_reiserfs(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_CONVERT)) | 487 | #define convert_reiserfs(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_CONVERT)) |
488 | #define reiserfs_data_log(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_LOG)) | 488 | #define reiserfs_data_log(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_LOG)) |
489 | #define reiserfs_data_ordered(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_ORDERED)) | 489 | #define reiserfs_data_ordered(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_ORDERED)) |
490 | #define reiserfs_data_writeback(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_WRITEBACK)) | 490 | #define reiserfs_data_writeback(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_WRITEBACK)) |
491 | #define reiserfs_xattrs(s) ((s)->s_xattr != NULL) | 491 | #define reiserfs_xattrs(s) ((s)->s_xattr != NULL) |
492 | #define reiserfs_xattrs_user(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_XATTRS_USER)) | 492 | #define reiserfs_xattrs_user(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_XATTRS_USER)) |
493 | #define reiserfs_posixacl(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_POSIXACL)) | 493 | #define reiserfs_posixacl(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_POSIXACL)) |
494 | #define reiserfs_xattrs_optional(s) (reiserfs_xattrs_user(s) || reiserfs_posixacl(s)) | 494 | #define reiserfs_xattrs_optional(s) (reiserfs_xattrs_user(s) || reiserfs_posixacl(s)) |
495 | #define reiserfs_barrier_none(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_BARRIER_NONE)) | 495 | #define reiserfs_barrier_none(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_BARRIER_NONE)) |
496 | #define reiserfs_barrier_flush(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_BARRIER_FLUSH)) | 496 | #define reiserfs_barrier_flush(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_BARRIER_FLUSH)) |
497 | 497 | ||
498 | #define reiserfs_error_panic(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ERROR_PANIC)) | 498 | #define reiserfs_error_panic(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ERROR_PANIC)) |
499 | #define reiserfs_error_ro(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ERROR_RO)) | 499 | #define reiserfs_error_ro(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_ERROR_RO)) |
500 | 500 | ||
501 | void reiserfs_file_buffer(struct buffer_head *bh, int list); | 501 | void reiserfs_file_buffer(struct buffer_head *bh, int list); |
502 | extern struct file_system_type reiserfs_fs_type; | 502 | extern struct file_system_type reiserfs_fs_type; |
503 | int reiserfs_resize(struct super_block *, unsigned long); | 503 | int reiserfs_resize(struct super_block *, unsigned long); |
504 | 504 | ||
505 | #define CARRY_ON 0 | 505 | #define CARRY_ON 0 |
506 | #define SCHEDULE_OCCURRED 1 | 506 | #define SCHEDULE_OCCURRED 1 |
507 | 507 | ||
508 | #define SB_BUFFER_WITH_SB(s) (REISERFS_SB(s)->s_sbh) | 508 | #define SB_BUFFER_WITH_SB(s) (REISERFS_SB(s)->s_sbh) |
509 | #define SB_JOURNAL(s) (REISERFS_SB(s)->s_journal) | 509 | #define SB_JOURNAL(s) (REISERFS_SB(s)->s_journal) |
510 | #define SB_JOURNAL_1st_RESERVED_BLOCK(s) (SB_JOURNAL(s)->j_1st_reserved_block) | 510 | #define SB_JOURNAL_1st_RESERVED_BLOCK(s) (SB_JOURNAL(s)->j_1st_reserved_block) |
511 | #define SB_JOURNAL_LEN_FREE(s) (SB_JOURNAL(s)->j_journal_len_free) | 511 | #define SB_JOURNAL_LEN_FREE(s) (SB_JOURNAL(s)->j_journal_len_free) |
512 | #define SB_AP_BITMAP(s) (REISERFS_SB(s)->s_ap_bitmap) | 512 | #define SB_AP_BITMAP(s) (REISERFS_SB(s)->s_ap_bitmap) |
513 | 513 | ||
514 | #define SB_DISK_JOURNAL_HEAD(s) (SB_JOURNAL(s)->j_header_bh->) | 514 | #define SB_DISK_JOURNAL_HEAD(s) (SB_JOURNAL(s)->j_header_bh->) |
515 | 515 | ||
516 | /* A safe version of the "bdevname", which returns the "s_id" field of | 516 | /* A safe version of the "bdevname", which returns the "s_id" field of |
517 | * a superblock or else "Null superblock" if the super block is NULL. | 517 | * a superblock or else "Null superblock" if the super block is NULL. |
518 | */ | 518 | */ |
519 | static inline char *reiserfs_bdevname(struct super_block *s) | 519 | static inline char *reiserfs_bdevname(struct super_block *s) |
520 | { | 520 | { |
521 | return (s == NULL) ? "Null superblock" : s->s_id; | 521 | return (s == NULL) ? "Null superblock" : s->s_id; |
522 | } | 522 | } |
523 | 523 | ||
524 | #define reiserfs_is_journal_aborted(journal) (unlikely (__reiserfs_is_journal_aborted (journal))) | 524 | #define reiserfs_is_journal_aborted(journal) (unlikely (__reiserfs_is_journal_aborted (journal))) |
525 | static inline int __reiserfs_is_journal_aborted(struct reiserfs_journal | 525 | static inline int __reiserfs_is_journal_aborted(struct reiserfs_journal |
526 | *journal) | 526 | *journal) |
527 | { | 527 | { |
528 | return test_bit(J_ABORTED, &journal->j_state); | 528 | return test_bit(J_ABORTED, &journal->j_state); |
529 | } | 529 | } |
530 | 530 | ||
531 | #endif /* _LINUX_REISER_FS_SB */ | 531 | #endif /* _LINUX_REISER_FS_SB */ |
532 | 532 |
include/linux/reiserfs_xattr.h
1 | /* | 1 | /* |
2 | File: linux/reiserfs_xattr.h | 2 | File: linux/reiserfs_xattr.h |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #ifndef _LINUX_REISERFS_XATTR_H | 5 | #ifndef _LINUX_REISERFS_XATTR_H |
6 | #define _LINUX_REISERFS_XATTR_H | 6 | #define _LINUX_REISERFS_XATTR_H |
7 | 7 | ||
8 | #include <linux/types.h> | 8 | #include <linux/types.h> |
9 | 9 | ||
10 | /* Magic value in header */ | 10 | /* Magic value in header */ |
11 | #define REISERFS_XATTR_MAGIC 0x52465841 /* "RFXA" */ | 11 | #define REISERFS_XATTR_MAGIC 0x52465841 /* "RFXA" */ |
12 | 12 | ||
13 | struct reiserfs_xattr_header { | 13 | struct reiserfs_xattr_header { |
14 | __le32 h_magic; /* magic number for identification */ | 14 | __le32 h_magic; /* magic number for identification */ |
15 | __le32 h_hash; /* hash of the value */ | 15 | __le32 h_hash; /* hash of the value */ |
16 | }; | 16 | }; |
17 | 17 | ||
18 | struct reiserfs_security_handle { | 18 | struct reiserfs_security_handle { |
19 | char *name; | 19 | char *name; |
20 | void *value; | 20 | void *value; |
21 | size_t length; | 21 | size_t length; |
22 | }; | 22 | }; |
23 | 23 | ||
24 | #ifdef __KERNEL__ | 24 | #ifdef __KERNEL__ |
25 | 25 | ||
26 | #include <linux/init.h> | 26 | #include <linux/init.h> |
27 | #include <linux/list.h> | 27 | #include <linux/list.h> |
28 | #include <linux/rwsem.h> | 28 | #include <linux/rwsem.h> |
29 | #include <linux/reiserfs_fs_i.h> | 29 | #include <linux/reiserfs_fs_i.h> |
30 | #include <linux/reiserfs_fs.h> | 30 | #include <linux/reiserfs_fs.h> |
31 | 31 | ||
32 | struct inode; | 32 | struct inode; |
33 | struct dentry; | 33 | struct dentry; |
34 | struct iattr; | 34 | struct iattr; |
35 | struct super_block; | 35 | struct super_block; |
36 | struct nameidata; | 36 | struct nameidata; |
37 | 37 | ||
38 | int reiserfs_xattr_register_handlers(void) __init; | 38 | int reiserfs_xattr_register_handlers(void) __init; |
39 | void reiserfs_xattr_unregister_handlers(void); | 39 | void reiserfs_xattr_unregister_handlers(void); |
40 | int reiserfs_xattr_init(struct super_block *sb, int mount_flags); | 40 | int reiserfs_xattr_init(struct super_block *sb, int mount_flags); |
41 | int reiserfs_lookup_privroot(struct super_block *sb); | 41 | int reiserfs_lookup_privroot(struct super_block *sb); |
42 | int reiserfs_delete_xattrs(struct inode *inode); | 42 | int reiserfs_delete_xattrs(struct inode *inode); |
43 | int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs); | 43 | int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs); |
44 | 44 | ||
45 | #ifdef CONFIG_REISERFS_FS_XATTR | 45 | #ifdef CONFIG_REISERFS_FS_XATTR |
46 | #define has_xattr_dir(inode) (REISERFS_I(inode)->i_flags & i_has_xattr_dir) | 46 | #define has_xattr_dir(inode) (REISERFS_I(inode)->i_flags & i_has_xattr_dir) |
47 | ssize_t reiserfs_getxattr(struct dentry *dentry, const char *name, | 47 | ssize_t reiserfs_getxattr(struct dentry *dentry, const char *name, |
48 | void *buffer, size_t size); | 48 | void *buffer, size_t size); |
49 | int reiserfs_setxattr(struct dentry *dentry, const char *name, | 49 | int reiserfs_setxattr(struct dentry *dentry, const char *name, |
50 | const void *value, size_t size, int flags); | 50 | const void *value, size_t size, int flags); |
51 | ssize_t reiserfs_listxattr(struct dentry *dentry, char *buffer, size_t size); | 51 | ssize_t reiserfs_listxattr(struct dentry *dentry, char *buffer, size_t size); |
52 | int reiserfs_removexattr(struct dentry *dentry, const char *name); | 52 | int reiserfs_removexattr(struct dentry *dentry, const char *name); |
53 | int reiserfs_permission(struct inode *inode, int mask); | 53 | int reiserfs_permission(struct inode *inode, int mask); |
54 | 54 | ||
55 | int reiserfs_xattr_get(struct inode *, const char *, void *, size_t); | 55 | int reiserfs_xattr_get(struct inode *, const char *, void *, size_t); |
56 | int reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int); | 56 | int reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int); |
57 | int reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *, | 57 | int reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *, |
58 | struct inode *, const char *, const void *, | 58 | struct inode *, const char *, const void *, |
59 | size_t, int); | 59 | size_t, int); |
60 | 60 | ||
61 | extern struct xattr_handler reiserfs_xattr_user_handler; | 61 | extern struct xattr_handler reiserfs_xattr_user_handler; |
62 | extern struct xattr_handler reiserfs_xattr_trusted_handler; | 62 | extern struct xattr_handler reiserfs_xattr_trusted_handler; |
63 | extern struct xattr_handler reiserfs_xattr_security_handler; | 63 | extern struct xattr_handler reiserfs_xattr_security_handler; |
64 | #ifdef CONFIG_REISERFS_FS_SECURITY | 64 | #ifdef CONFIG_REISERFS_FS_SECURITY |
65 | int reiserfs_security_init(struct inode *dir, struct inode *inode, | 65 | int reiserfs_security_init(struct inode *dir, struct inode *inode, |
66 | struct reiserfs_security_handle *sec); | 66 | struct reiserfs_security_handle *sec); |
67 | int reiserfs_security_write(struct reiserfs_transaction_handle *th, | 67 | int reiserfs_security_write(struct reiserfs_transaction_handle *th, |
68 | struct inode *inode, | 68 | struct inode *inode, |
69 | struct reiserfs_security_handle *sec); | 69 | struct reiserfs_security_handle *sec); |
70 | void reiserfs_security_free(struct reiserfs_security_handle *sec); | 70 | void reiserfs_security_free(struct reiserfs_security_handle *sec); |
71 | #endif | 71 | #endif |
72 | 72 | ||
73 | #define xattr_size(size) ((size) + sizeof(struct reiserfs_xattr_header)) | 73 | #define xattr_size(size) ((size) + sizeof(struct reiserfs_xattr_header)) |
74 | static inline loff_t reiserfs_xattr_nblocks(struct inode *inode, loff_t size) | 74 | static inline loff_t reiserfs_xattr_nblocks(struct inode *inode, loff_t size) |
75 | { | 75 | { |
76 | loff_t ret = 0; | 76 | loff_t ret = 0; |
77 | if (reiserfs_file_data_log(inode)) { | 77 | if (reiserfs_file_data_log(inode)) { |
78 | ret = _ROUND_UP(xattr_size(size), inode->i_sb->s_blocksize); | 78 | ret = _ROUND_UP(xattr_size(size), inode->i_sb->s_blocksize); |
79 | ret >>= inode->i_sb->s_blocksize_bits; | 79 | ret >>= inode->i_sb->s_blocksize_bits; |
80 | } | 80 | } |
81 | return ret; | 81 | return ret; |
82 | } | 82 | } |
83 | 83 | ||
84 | /* We may have to create up to 3 objects: xattr root, xattr dir, xattr file. | 84 | /* We may have to create up to 3 objects: xattr root, xattr dir, xattr file. |
85 | * Let's try to be smart about it. | 85 | * Let's try to be smart about it. |
86 | * xattr root: We cache it. If it's not cached, we may need to create it. | 86 | * xattr root: We cache it. If it's not cached, we may need to create it. |
87 | * xattr dir: If anything has been loaded for this inode, we can set a flag | 87 | * xattr dir: If anything has been loaded for this inode, we can set a flag |
88 | * saying so. | 88 | * saying so. |
89 | * xattr file: Since we don't cache xattrs, we can't tell. We always include | 89 | * xattr file: Since we don't cache xattrs, we can't tell. We always include |
90 | * blocks for it. | 90 | * blocks for it. |
91 | * | 91 | * |
92 | * However, since root and dir can be created between calls - YOU MUST SAVE | 92 | * However, since root and dir can be created between calls - YOU MUST SAVE |
93 | * THIS VALUE. | 93 | * THIS VALUE. |
94 | */ | 94 | */ |
95 | static inline size_t reiserfs_xattr_jcreate_nblocks(struct inode *inode) | 95 | static inline size_t reiserfs_xattr_jcreate_nblocks(struct inode *inode) |
96 | { | 96 | { |
97 | size_t nblocks = JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb); | 97 | size_t nblocks = JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb); |
98 | 98 | ||
99 | if ((REISERFS_I(inode)->i_flags & i_has_xattr_dir) == 0) { | 99 | if ((REISERFS_I(inode)->i_flags & i_has_xattr_dir) == 0) { |
100 | nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb); | 100 | nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb); |
101 | if (REISERFS_SB(inode->i_sb)->xattr_root == NULL) | 101 | if (!REISERFS_SB(inode->i_sb)->xattr_root->d_inode) |
102 | nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb); | 102 | nblocks += JOURNAL_BLOCKS_PER_OBJECT(inode->i_sb); |
103 | } | 103 | } |
104 | 104 | ||
105 | return nblocks; | 105 | return nblocks; |
106 | } | 106 | } |
107 | 107 | ||
108 | static inline void reiserfs_init_xattr_rwsem(struct inode *inode) | 108 | static inline void reiserfs_init_xattr_rwsem(struct inode *inode) |
109 | { | 109 | { |
110 | init_rwsem(&REISERFS_I(inode)->i_xattr_sem); | 110 | init_rwsem(&REISERFS_I(inode)->i_xattr_sem); |
111 | } | 111 | } |
112 | 112 | ||
113 | #else | 113 | #else |
114 | 114 | ||
115 | #define reiserfs_getxattr NULL | 115 | #define reiserfs_getxattr NULL |
116 | #define reiserfs_setxattr NULL | 116 | #define reiserfs_setxattr NULL |
117 | #define reiserfs_listxattr NULL | 117 | #define reiserfs_listxattr NULL |
118 | #define reiserfs_removexattr NULL | 118 | #define reiserfs_removexattr NULL |
119 | 119 | ||
120 | #define reiserfs_permission NULL | 120 | #define reiserfs_permission NULL |
121 | 121 | ||
122 | static inline void reiserfs_init_xattr_rwsem(struct inode *inode) | 122 | static inline void reiserfs_init_xattr_rwsem(struct inode *inode) |
123 | { | 123 | { |
124 | } | 124 | } |
125 | #endif /* CONFIG_REISERFS_FS_XATTR */ | 125 | #endif /* CONFIG_REISERFS_FS_XATTR */ |
126 | 126 | ||
127 | #ifndef CONFIG_REISERFS_FS_SECURITY | 127 | #ifndef CONFIG_REISERFS_FS_SECURITY |
128 | static inline int reiserfs_security_init(struct inode *dir, | 128 | static inline int reiserfs_security_init(struct inode *dir, |
129 | struct inode *inode, | 129 | struct inode *inode, |
130 | struct reiserfs_security_handle *sec) | 130 | struct reiserfs_security_handle *sec) |
131 | { | 131 | { |
132 | return 0; | 132 | return 0; |
133 | } | 133 | } |
134 | static inline int | 134 | static inline int |
135 | reiserfs_security_write(struct reiserfs_transaction_handle *th, | 135 | reiserfs_security_write(struct reiserfs_transaction_handle *th, |
136 | struct inode *inode, | 136 | struct inode *inode, |
137 | struct reiserfs_security_handle *sec) | 137 | struct reiserfs_security_handle *sec) |
138 | { | 138 | { |
139 | return 0; | 139 | return 0; |
140 | } | 140 | } |
141 | static inline void reiserfs_security_free(struct reiserfs_security_handle *sec) | 141 | static inline void reiserfs_security_free(struct reiserfs_security_handle *sec) |
142 | {} | 142 | {} |
143 | #endif | 143 | #endif |
144 | 144 | ||
145 | #endif /* __KERNEL__ */ | 145 | #endif /* __KERNEL__ */ |
146 | 146 | ||
147 | #endif /* _LINUX_REISERFS_XATTR_H */ | 147 | #endif /* _LINUX_REISERFS_XATTR_H */ |
148 | 148 |