blob: ccb8e4d4c03243d0a0be05560012f08a07c977b8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/fs/reiserfs/xattr.c
3 *
4 * Copyright (c) 2002 by Jeff Mahoney, <jeffm@suse.com>
5 *
6 */
7
8/*
9 * In order to implement EA/ACLs in a clean, backwards compatible manner,
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
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
14 * generation number are used. Inside each directory are individual files
15 * named with the name of the extended attribute.
16 *
17 * So, for objectid 12648430, we could have:
18 * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_access
19 * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_default
20 * /.reiserfs_priv/xattrs/C0FFEE.0/user.Content-Type
21 * .. or similar.
22 *
23 * The file contents are the text of the EA. The size is known based on the
24 * stat data describing the file.
25 *
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
28 * kernel, in addition, they are negatively and positively cached and attached
29 * to the inode so that unnecessary lookups are avoided.
Jeff Mahoneyd9845612009-03-30 14:02:35 -040030 *
31 * Locking works like so:
Jeff Mahoney8b6dd722009-03-30 14:02:36 -040032 * Directory components (xattr root, xattr dir) are protectd by their i_mutex.
33 * The xattrs themselves are protected by the xattr_sem.
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 */
35
36#include <linux/reiserfs_fs.h>
Randy Dunlap16f7e0f2006-01-11 12:17:46 -080037#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/dcache.h>
39#include <linux/namei.h>
40#include <linux/errno.h>
41#include <linux/fs.h>
42#include <linux/file.h>
43#include <linux/pagemap.h>
44#include <linux/xattr.h>
45#include <linux/reiserfs_xattr.h>
46#include <linux/reiserfs_acl.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include <asm/uaccess.h>
Al Viro3277c392006-11-14 21:13:53 -080048#include <net/checksum.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <linux/smp_lock.h>
50#include <linux/stat.h>
Jeff Mahoney6c176752009-03-30 14:02:34 -040051#include <linux/quotaops.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#define PRIVROOT_NAME ".reiserfs_priv"
54#define XAROOT_NAME "xattrs"
55
Jeff Mahoney8b6dd722009-03-30 14:02:36 -040056static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char *);
57
Jeff Mahoney6c176752009-03-30 14:02:34 -040058/* Helpers for inode ops. We do this so that we don't have all the VFS
59 * overhead and also for proper i_mutex annotation.
60 * dir->i_mutex must be held for all of them. */
61static int xattr_create(struct inode *dir, struct dentry *dentry, int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
Jeff Mahoney6c176752009-03-30 14:02:34 -040063 BUG_ON(!mutex_is_locked(&dir->i_mutex));
64 DQUOT_INIT(dir);
65 return dir->i_op->create(dir, dentry, mode, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
67
Jeff Mahoney6c176752009-03-30 14:02:34 -040068static int xattr_mkdir(struct inode *dir, struct dentry *dentry, int mode)
69{
70 BUG_ON(!mutex_is_locked(&dir->i_mutex));
71 DQUOT_INIT(dir);
72 return dir->i_op->mkdir(dir, dentry, mode);
73}
74
75/* We use I_MUTEX_CHILD here to silence lockdep. It's safe because xattr
76 * mutation ops aren't called during rename or splace, which are the
77 * only other users of I_MUTEX_CHILD. It violates the ordering, but that's
78 * better than allocating another subclass just for this code. */
79static int xattr_unlink(struct inode *dir, struct dentry *dentry)
80{
81 int error;
82 BUG_ON(!mutex_is_locked(&dir->i_mutex));
83 DQUOT_INIT(dir);
84
85 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD);
86 error = dir->i_op->unlink(dir, dentry);
87 mutex_unlock(&dentry->d_inode->i_mutex);
88
89 if (!error)
90 d_delete(dentry);
91 return error;
92}
93
94static int xattr_rmdir(struct inode *dir, struct dentry *dentry)
95{
96 int error;
97 BUG_ON(!mutex_is_locked(&dir->i_mutex));
98 DQUOT_INIT(dir);
99
100 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_CHILD);
101 dentry_unhash(dentry);
102 error = dir->i_op->rmdir(dir, dentry);
103 if (!error)
104 dentry->d_inode->i_flags |= S_DEAD;
105 mutex_unlock(&dentry->d_inode->i_mutex);
106 if (!error)
107 d_delete(dentry);
108 dput(dentry);
109
110 return error;
111}
112
113
114#define xattr_may_create(flags) (!flags || flags & XATTR_CREATE)
115
116/* Returns and possibly creates the xattr dir. */
117static struct dentry *lookup_or_create_dir(struct dentry *parent,
118 const char *name, int flags)
119{
120 struct dentry *dentry;
121 BUG_ON(!parent);
122
123 dentry = lookup_one_len(name, parent, strlen(name));
124 if (IS_ERR(dentry))
125 return dentry;
126 else if (!dentry->d_inode) {
127 int err = -ENODATA;
128
129 if (xattr_may_create(flags)) {
130 mutex_lock_nested(&parent->d_inode->i_mutex,
131 I_MUTEX_XATTR);
132 err = xattr_mkdir(parent->d_inode, dentry, 0700);
133 mutex_unlock(&parent->d_inode->i_mutex);
134 }
135
136 if (err) {
137 dput(dentry);
138 dentry = ERR_PTR(err);
139 }
140 }
141
142 return dentry;
143}
144
145static struct dentry *open_xa_root(struct super_block *sb, int flags)
146{
147 struct dentry *privroot = REISERFS_SB(sb)->priv_root;
148 if (!privroot)
149 return ERR_PTR(-ENODATA);
150 return lookup_or_create_dir(privroot, XAROOT_NAME, flags);
151}
152
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700153static struct dentry *open_xa_dir(const struct inode *inode, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700155 struct dentry *xaroot, *xadir;
156 char namebuf[17];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Jeff Mahoney6c176752009-03-30 14:02:34 -0400158 xaroot = open_xa_root(inode->i_sb, flags);
Jeff Mahoney9b7f3752007-04-23 14:41:17 -0700159 if (IS_ERR(xaroot))
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700160 return xaroot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700162 snprintf(namebuf, sizeof(namebuf), "%X.%X",
163 le32_to_cpu(INODE_PKEY(inode)->k_objectid),
164 inode->i_generation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Jeff Mahoney6c176752009-03-30 14:02:34 -0400166 xadir = lookup_or_create_dir(xaroot, namebuf, flags);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700167 dput(xaroot);
168 return xadir;
Jeff Mahoney6c176752009-03-30 14:02:34 -0400169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170}
171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172/*
173 * this is very similar to fs/reiserfs/dir.c:reiserfs_readdir, but
174 * we need to drop the path before calling the filldir struct. That
175 * would be a big performance hit to the non-xattr case, so I've copied
176 * the whole thing for now. --clm
177 *
178 * the big difference is that I go backwards through the directory,
179 * and don't mess with f->f_pos, but the idea is the same. Do some
180 * action on each and every entry in the directory.
181 *
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800182 * we're called with i_mutex held, so there are no worries about the directory
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 * changing underneath us.
184 */
Jeff Mahoney3227e142008-02-15 14:37:22 -0800185static int __xattr_readdir(struct inode *inode, void *dirent, filldir_t filldir)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700187 struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */
188 INITIALIZE_PATH(path_to_entry);
189 struct buffer_head *bh;
190 int entry_num;
191 struct item_head *ih, tmp_ih;
192 int search_res;
193 char *local_buf;
194 loff_t next_pos;
195 char small_buf[32]; /* avoid kmalloc if we can */
196 struct reiserfs_de_head *deh;
197 int d_reclen;
198 char *d_name;
199 off_t d_off;
200 ino_t d_ino;
201 struct reiserfs_dir_entry de;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700203 /* form key for search the next directory entry using f_pos field of
204 file structure */
205 next_pos = max_reiserfs_offset(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700207 while (1) {
208 research:
209 if (next_pos <= DOT_DOT_OFFSET)
210 break;
211 make_cpu_key(&pos_key, inode, next_pos, TYPE_DIRENTRY, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700213 search_res =
214 search_by_entry_key(inode->i_sb, &pos_key, &path_to_entry,
215 &de);
216 if (search_res == IO_ERROR) {
217 // FIXME: we could just skip part of directory which could
218 // not be read
219 pathrelse(&path_to_entry);
220 return -EIO;
221 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700223 if (search_res == NAME_NOT_FOUND)
224 de.de_entry_num--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700226 set_de_name_and_namelen(&de);
227 entry_num = de.de_entry_num;
228 deh = &(de.de_deh[entry_num]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700230 bh = de.de_bh;
231 ih = de.de_ih;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700233 if (!is_direntry_le_ih(ih)) {
Jeff Mahoney0030b642009-03-30 14:02:28 -0400234 reiserfs_error(inode->i_sb, "jdm-20000",
235 "not direntry %h", ih);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700236 break;
237 }
238 copy_item_head(&tmp_ih, ih);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700240 /* we must have found item, that is item of this directory, */
241 RFALSE(COMP_SHORT_KEYS(&(ih->ih_key), &pos_key),
242 "vs-9000: found item %h does not match to dir we readdir %K",
243 ih, &pos_key);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700245 if (deh_offset(deh) <= DOT_DOT_OFFSET) {
246 break;
247 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700249 /* look for the previous entry in the directory */
250 next_pos = deh_offset(deh) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700252 if (!de_visible(deh))
253 /* it is hidden entry */
254 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700256 d_reclen = entry_length(bh, ih, entry_num);
257 d_name = B_I_DEH_ENTRY_FILE_NAME(bh, ih, deh);
258 d_off = deh_offset(deh);
259 d_ino = deh_objectid(deh);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700261 if (!d_name[d_reclen - 1])
262 d_reclen = strlen(d_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700264 if (d_reclen > REISERFS_MAX_NAME(inode->i_sb->s_blocksize)) {
265 /* too big to send back to VFS */
266 continue;
267 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700269 /* Ignore the .reiserfs_priv entry */
270 if (reiserfs_xattrs(inode->i_sb) &&
271 !old_format_only(inode->i_sb) &&
272 deh_objectid(deh) ==
273 le32_to_cpu(INODE_PKEY
274 (REISERFS_SB(inode->i_sb)->priv_root->d_inode)->
275 k_objectid))
276 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700278 if (d_reclen <= 32) {
279 local_buf = small_buf;
280 } else {
Pekka Enbergd739b422006-02-01 03:06:43 -0800281 local_buf = kmalloc(d_reclen, GFP_NOFS);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700282 if (!local_buf) {
283 pathrelse(&path_to_entry);
284 return -ENOMEM;
285 }
286 if (item_moved(&tmp_ih, &path_to_entry)) {
Pekka Enbergd739b422006-02-01 03:06:43 -0800287 kfree(local_buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700289 /* sigh, must retry. Do this same offset again */
290 next_pos = d_off;
291 goto research;
292 }
293 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700295 // Note, that we copy name to user space via temporary
296 // buffer (local_buf) because filldir will block if
297 // user space buffer is swapped out. At that time
298 // entry can move to somewhere else
299 memcpy(local_buf, d_name, d_reclen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700301 /* the filldir function might need to start transactions,
302 * or do who knows what. Release the path now that we've
303 * copied all the important stuff out of the deh
304 */
305 pathrelse(&path_to_entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700307 if (filldir(dirent, local_buf, d_reclen, d_off, d_ino,
308 DT_UNKNOWN) < 0) {
309 if (local_buf != small_buf) {
Pekka Enbergd739b422006-02-01 03:06:43 -0800310 kfree(local_buf);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700311 }
312 goto end;
313 }
314 if (local_buf != small_buf) {
Pekka Enbergd739b422006-02-01 03:06:43 -0800315 kfree(local_buf);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700316 }
317 } /* while */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700319 end:
320 pathrelse(&path_to_entry);
321 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322}
323
324/*
325 * this could be done with dedicated readdir ops for the xattr files,
326 * but I want to get something working asap
327 * this is stolen from vfs_readdir
328 *
329 */
330static
Jeff Mahoney3227e142008-02-15 14:37:22 -0800331int xattr_readdir(struct inode *inode, filldir_t filler, void *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
Jeff Mahoney3227e142008-02-15 14:37:22 -0800333 int res = -ENOENT;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700334 if (!IS_DEADDIR(inode)) {
335 lock_kernel();
Jeff Mahoney3227e142008-02-15 14:37:22 -0800336 res = __xattr_readdir(inode, buf, filler);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700337 unlock_kernel();
338 }
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700339 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340}
341
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400342/* expects xadir->d_inode->i_mutex to be locked */
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400343static int
344__reiserfs_xattr_del(struct dentry *xadir, const char *name, int namelen)
345{
346 struct dentry *dentry;
347 struct inode *dir = xadir->d_inode;
348 int err = 0;
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400349 struct reiserfs_xattr_handler *xah;
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400350
351 dentry = lookup_one_len(name, xadir, namelen);
352 if (IS_ERR(dentry)) {
353 err = PTR_ERR(dentry);
354 goto out;
355 } else if (!dentry->d_inode) {
356 err = -ENODATA;
357 goto out_file;
358 }
359
360 /* Skip directories.. */
361 if (S_ISDIR(dentry->d_inode->i_mode))
362 goto out_file;
363
364 if (!IS_PRIVATE(dentry->d_inode)) {
365 reiserfs_error(dir->i_sb, "jdm-20003",
366 "OID %08x [%.*s/%.*s] doesn't have "
367 "priv flag set [parent is %sset].",
368 le32_to_cpu(INODE_PKEY(dentry->d_inode)->
369 k_objectid), xadir->d_name.len,
370 xadir->d_name.name, namelen, name,
371 IS_PRIVATE(xadir->d_inode) ? "" :
372 "not ");
373 dput(dentry);
374 return -EIO;
375 }
376
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400377 /* Deletion pre-operation */
378 xah = find_xattr_handler_prefix(name);
379 if (xah && xah->del) {
380 err = xah->del(dentry->d_inode, name);
381 if (err)
382 goto out;
383 }
384
Jeff Mahoney6c176752009-03-30 14:02:34 -0400385 err = xattr_unlink(dir, dentry);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400386
387out_file:
388 dput(dentry);
389
390out:
391 return err;
392}
393
394/* The following are side effects of other operations that aren't explicitly
395 * modifying extended attributes. This includes operations such as permissions
396 * or ownership changes, object deletions, etc. */
397
398static int
399reiserfs_delete_xattrs_filler(void *buf, const char *name, int namelen,
400 loff_t offset, u64 ino, unsigned int d_type)
401{
402 struct dentry *xadir = (struct dentry *)buf;
403
404 return __reiserfs_xattr_del(xadir, name, namelen);
405
406}
407
408/* This is called w/ inode->i_mutex downed */
409int reiserfs_delete_xattrs(struct inode *inode)
410{
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400411 int err = -ENODATA;
Jeff Mahoneyd9845612009-03-30 14:02:35 -0400412 struct dentry *dir, *root;
413 struct reiserfs_transaction_handle th;
414 int blocks = JOURNAL_PER_BALANCE_CNT * 2 + 2 +
415 4 * REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400416
417 /* Skip out, an xattr has no xattrs associated with it */
418 if (IS_PRIVATE(inode) || get_inode_sd_version(inode) == STAT_DATA_V1)
419 return 0;
420
Jeff Mahoney6c176752009-03-30 14:02:34 -0400421 dir = open_xa_dir(inode, XATTR_REPLACE);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400422 if (IS_ERR(dir)) {
423 err = PTR_ERR(dir);
424 goto out;
425 } else if (!dir->d_inode) {
426 dput(dir);
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400427 goto out;
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400428 }
429
Jeff Mahoney6c176752009-03-30 14:02:34 -0400430 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400431 err = xattr_readdir(dir->d_inode, reiserfs_delete_xattrs_filler, dir);
Jeff Mahoney6c176752009-03-30 14:02:34 -0400432 mutex_unlock(&dir->d_inode->i_mutex);
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400433 if (err) {
434 dput(dir);
435 goto out;
436 }
437
438 root = dget(dir->d_parent);
439 dput(dir);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400440
Jeff Mahoneyd9845612009-03-30 14:02:35 -0400441 /* We start a transaction here to avoid a ABBA situation
442 * between the xattr root's i_mutex and the journal lock.
443 * Inode creation will inherit an ACL, which requires a
444 * lookup. The lookup locks the xattr root i_mutex with a
445 * transaction open. Inode deletion takes teh xattr root
446 * i_mutex to delete the directory and then starts a
447 * transaction inside it. Boom. This doesn't incur much
448 * additional overhead since the reiserfs_rmdir transaction
449 * will just nest inside the outer transaction. */
450 err = journal_begin(&th, inode->i_sb, blocks);
451 if (!err) {
452 int jerror;
Jeff Mahoney6c176752009-03-30 14:02:34 -0400453 mutex_lock_nested(&root->d_inode->i_mutex, I_MUTEX_XATTR);
454 err = xattr_rmdir(root->d_inode, dir);
Jeff Mahoneyd9845612009-03-30 14:02:35 -0400455 jerror = journal_end(&th, inode->i_sb, blocks);
Jeff Mahoney6c176752009-03-30 14:02:34 -0400456 mutex_unlock(&root->d_inode->i_mutex);
Jeff Mahoneyd9845612009-03-30 14:02:35 -0400457 err = jerror ?: err;
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400458 }
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400459
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400460 dput(root);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400461out:
462 if (!err)
463 REISERFS_I(inode)->i_flags =
464 REISERFS_I(inode)->i_flags & ~i_has_xattr_dir;
Jeff Mahoneyd9845612009-03-30 14:02:35 -0400465 else
466 reiserfs_warning(inode->i_sb, "jdm-20004",
467 "Couldn't remove all xattrs (%d)\n", err);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400468 return err;
469}
470
471struct reiserfs_chown_buf {
472 struct inode *inode;
473 struct dentry *xadir;
474 struct iattr *attrs;
475};
476
477/* XXX: If there is a better way to do this, I'd love to hear about it */
478static int
479reiserfs_chown_xattrs_filler(void *buf, const char *name, int namelen,
480 loff_t offset, u64 ino, unsigned int d_type)
481{
482 struct reiserfs_chown_buf *chown_buf = (struct reiserfs_chown_buf *)buf;
483 struct dentry *xafile, *xadir = chown_buf->xadir;
484 struct iattr *attrs = chown_buf->attrs;
485 int err = 0;
486
487 xafile = lookup_one_len(name, xadir, namelen);
488 if (IS_ERR(xafile))
489 return PTR_ERR(xafile);
490 else if (!xafile->d_inode) {
491 dput(xafile);
492 return -ENODATA;
493 }
494
Jeff Mahoney6c176752009-03-30 14:02:34 -0400495 if (!S_ISDIR(xafile->d_inode->i_mode)) {
496 mutex_lock_nested(&xafile->d_inode->i_mutex, I_MUTEX_CHILD);
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400497 err = reiserfs_setattr(xafile, attrs);
Jeff Mahoney6c176752009-03-30 14:02:34 -0400498 mutex_unlock(&xafile->d_inode->i_mutex);
499 }
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400500 dput(xafile);
501
502 return err;
503}
504
505int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs)
506{
507 struct dentry *dir;
508 int err = 0;
509 struct reiserfs_chown_buf buf;
510 unsigned int ia_valid = attrs->ia_valid;
511
512 /* Skip out, an xattr has no xattrs associated with it */
513 if (IS_PRIVATE(inode) || get_inode_sd_version(inode) == STAT_DATA_V1)
514 return 0;
515
Jeff Mahoney6c176752009-03-30 14:02:34 -0400516 dir = open_xa_dir(inode, XATTR_REPLACE);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400517 if (IS_ERR(dir)) {
518 if (PTR_ERR(dir) != -ENODATA)
519 err = PTR_ERR(dir);
520 goto out;
Jeff Mahoney6c176752009-03-30 14:02:34 -0400521 } else if (!dir->d_inode)
522 goto out_dir;
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400523
524 attrs->ia_valid &= (ATTR_UID | ATTR_GID | ATTR_CTIME);
525 buf.xadir = dir;
526 buf.attrs = attrs;
527 buf.inode = inode;
528
Jeff Mahoney6c176752009-03-30 14:02:34 -0400529 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400530 err = xattr_readdir(dir->d_inode, reiserfs_chown_xattrs_filler, &buf);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400531
Jeff Mahoney6c176752009-03-30 14:02:34 -0400532 if (!err)
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400533 err = reiserfs_setattr(dir, attrs);
Jeff Mahoney6c176752009-03-30 14:02:34 -0400534 mutex_unlock(&dir->d_inode->i_mutex);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400535
Jeff Mahoney6c176752009-03-30 14:02:34 -0400536 attrs->ia_valid = ia_valid;
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400537out_dir:
538 dput(dir);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400539out:
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400540 if (err)
541 reiserfs_warning(inode->i_sb, "jdm-20007",
542 "Couldn't chown all xattrs (%d)\n", err);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400543 return err;
544}
545
546#ifdef CONFIG_REISERFS_FS_XATTR
547static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
548 *prefix);
549
550/* Returns a dentry corresponding to a specific extended attribute file
551 * for the inode. If flags allow, the file is created. Otherwise, a
552 * valid or negative dentry, or an error is returned. */
553static struct dentry *get_xa_file_dentry(const struct inode *inode,
554 const char *name, int flags)
555{
556 struct dentry *xadir, *xafile;
557 int err = 0;
558
559 xadir = open_xa_dir(inode, flags);
Jeff Mahoney6c176752009-03-30 14:02:34 -0400560 if (IS_ERR(xadir))
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400561 return ERR_CAST(xadir);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400562
563 xafile = lookup_one_len(name, xadir, strlen(name));
564 if (IS_ERR(xafile)) {
Jeff Mahoney6c176752009-03-30 14:02:34 -0400565 err = PTR_ERR(xafile);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400566 goto out;
Jeff Mahoney6c176752009-03-30 14:02:34 -0400567 }
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400568
Jeff Mahoney6c176752009-03-30 14:02:34 -0400569 if (xafile->d_inode && (flags & XATTR_CREATE))
570 err = -EEXIST;
571
572 if (!xafile->d_inode) {
573 err = -ENODATA;
574 if (xattr_may_create(flags)) {
575 mutex_lock_nested(&xadir->d_inode->i_mutex,
576 I_MUTEX_XATTR);
577 err = xattr_create(xadir->d_inode, xafile,
578 0700|S_IFREG);
579 mutex_unlock(&xadir->d_inode->i_mutex);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400580 }
581 }
582
Jeff Mahoney6c176752009-03-30 14:02:34 -0400583 if (err)
584 dput(xafile);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400585out:
586 dput(xadir);
587 if (err)
Jeff Mahoney6c176752009-03-30 14:02:34 -0400588 return ERR_PTR(err);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400589 return xafile;
590}
591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592/* Internal operations on file data */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700593static inline void reiserfs_put_page(struct page *page)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700595 kunmap(page);
596 page_cache_release(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597}
598
Jeff Mahoneyec6ea562009-03-30 14:02:30 -0400599static struct page *reiserfs_get_page(struct inode *dir, size_t n)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700601 struct address_space *mapping = dir->i_mapping;
602 struct page *page;
603 /* We can deadlock if we try to free dentries,
604 and an unlink/rmdir has just occured - GFP_NOFS avoids this */
Al Viroc4cdd032005-10-21 03:22:39 -0400605 mapping_set_gfp_mask(mapping, GFP_NOFS);
Jeff Mahoneyec6ea562009-03-30 14:02:30 -0400606 page = read_mapping_page(mapping, n >> PAGE_CACHE_SHIFT, NULL);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700607 if (!IS_ERR(page)) {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700608 kmap(page);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700609 if (PageError(page))
610 goto fail;
611 }
612 return page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700614 fail:
615 reiserfs_put_page(page);
616 return ERR_PTR(-EIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617}
618
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700619static inline __u32 xattr_hash(const char *msg, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700621 return csum_partial(msg, len, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622}
623
Vladimir Savelievba9d8ce2007-10-16 01:25:14 -0700624int reiserfs_commit_write(struct file *f, struct page *page,
625 unsigned from, unsigned to);
626int reiserfs_prepare_write(struct file *f, struct page *page,
627 unsigned from, unsigned to);
628
629
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630/* Generic extended attribute operations that can be used by xa plugins */
631
632/*
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800633 * inode->i_mutex: down
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 */
635int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700636reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
637 size_t buffer_size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700639 int err = 0;
Jeff Mahoney3227e142008-02-15 14:37:22 -0800640 struct dentry *dentry;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700641 struct page *page;
642 char *data;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700643 size_t file_pos = 0;
644 size_t buffer_pos = 0;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700645 struct iattr newattrs;
646 __u32 xahash = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700648 if (get_inode_sd_version(inode) == STAT_DATA_V1)
649 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400651 if (!buffer)
652 return reiserfs_xattr_del(inode, name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Jeff Mahoney3227e142008-02-15 14:37:22 -0800654 dentry = get_xa_file_dentry(inode, name, flags);
655 if (IS_ERR(dentry)) {
656 err = PTR_ERR(dentry);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700657 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400660 down_write(&REISERFS_I(inode)->i_xattr_sem);
661
662 xahash = xattr_hash(buffer, buffer_size);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700663 REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700665 /* Resize it so we're ok to write there */
666 newattrs.ia_size = buffer_size;
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400667 newattrs.ia_ctime = current_fs_time(inode->i_sb);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700668 newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
Jeff Mahoneyf437c522009-03-30 14:02:29 -0400669 mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_XATTR);
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400670 down_write(&dentry->d_inode->i_alloc_sem);
671 err = reiserfs_setattr(dentry, &newattrs);
672 up_write(&dentry->d_inode->i_alloc_sem);
Jeff Mahoney6c176752009-03-30 14:02:34 -0400673 mutex_unlock(&dentry->d_inode->i_mutex);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700674 if (err)
675 goto out_filp;
676
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700677 while (buffer_pos < buffer_size || buffer_pos == 0) {
678 size_t chunk;
679 size_t skip = 0;
680 size_t page_offset = (file_pos & (PAGE_CACHE_SIZE - 1));
681 if (buffer_size - buffer_pos > PAGE_CACHE_SIZE)
682 chunk = PAGE_CACHE_SIZE;
683 else
684 chunk = buffer_size - buffer_pos;
685
Jeff Mahoneyec6ea562009-03-30 14:02:30 -0400686 page = reiserfs_get_page(dentry->d_inode, file_pos);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700687 if (IS_ERR(page)) {
688 err = PTR_ERR(page);
689 goto out_filp;
690 }
691
692 lock_page(page);
693 data = page_address(page);
694
695 if (file_pos == 0) {
696 struct reiserfs_xattr_header *rxh;
697 skip = file_pos = sizeof(struct reiserfs_xattr_header);
698 if (chunk + skip > PAGE_CACHE_SIZE)
699 chunk = PAGE_CACHE_SIZE - skip;
700 rxh = (struct reiserfs_xattr_header *)data;
701 rxh->h_magic = cpu_to_le32(REISERFS_XATTR_MAGIC);
702 rxh->h_hash = cpu_to_le32(xahash);
703 }
704
Jeff Mahoney3227e142008-02-15 14:37:22 -0800705 err = reiserfs_prepare_write(NULL, page, page_offset,
Vladimir Savelievba9d8ce2007-10-16 01:25:14 -0700706 page_offset + chunk + skip);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700707 if (!err) {
708 if (buffer)
709 memcpy(data + skip, buffer + buffer_pos, chunk);
Jeff Mahoney3227e142008-02-15 14:37:22 -0800710 err = reiserfs_commit_write(NULL, page, page_offset,
711 page_offset + chunk +
712 skip);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700713 }
714 unlock_page(page);
715 reiserfs_put_page(page);
716 buffer_pos += chunk;
717 file_pos += chunk;
718 skip = 0;
719 if (err || buffer_size == 0 || !buffer)
720 break;
721 }
722
723 /* We can't mark the inode dirty if it's not hashed. This is the case
724 * when we're inheriting the default ACL. If we dirty it, the inode
725 * gets marked dirty, but won't (ever) make it onto the dirty list until
726 * it's synced explicitly to clear I_DIRTY. This is bad. */
727 if (!hlist_unhashed(&inode->i_hash)) {
728 inode->i_ctime = CURRENT_TIME_SEC;
729 mark_inode_dirty(inode);
730 }
731
732 out_filp:
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400733 up_write(&REISERFS_I(inode)->i_xattr_sem);
Jeff Mahoney3227e142008-02-15 14:37:22 -0800734 dput(dentry);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700735
736 out:
737 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738}
739
740/*
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800741 * inode->i_mutex: down
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 */
743int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700744reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer,
745 size_t buffer_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700747 ssize_t err = 0;
Jeff Mahoney3227e142008-02-15 14:37:22 -0800748 struct dentry *dentry;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700749 size_t isize;
750 size_t file_pos = 0;
751 size_t buffer_pos = 0;
752 struct page *page;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700753 __u32 hash = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700755 if (name == NULL)
756 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700758 /* We can't have xattrs attached to v1 items since they don't have
759 * generation numbers */
760 if (get_inode_sd_version(inode) == STAT_DATA_V1)
761 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
Jeff Mahoney6c176752009-03-30 14:02:34 -0400763 dentry = get_xa_file_dentry(inode, name, XATTR_REPLACE);
Jeff Mahoney3227e142008-02-15 14:37:22 -0800764 if (IS_ERR(dentry)) {
765 err = PTR_ERR(dentry);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700766 goto out;
767 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400769 down_read(&REISERFS_I(inode)->i_xattr_sem);
Jeff Mahoneyd9845612009-03-30 14:02:35 -0400770
Jeff Mahoneyf437c522009-03-30 14:02:29 -0400771 isize = i_size_read(dentry->d_inode);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700772 REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700774 /* Just return the size needed */
775 if (buffer == NULL) {
776 err = isize - sizeof(struct reiserfs_xattr_header);
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400777 goto out_unlock;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700780 if (buffer_size < isize - sizeof(struct reiserfs_xattr_header)) {
781 err = -ERANGE;
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400782 goto out_unlock;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700783 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700785 while (file_pos < isize) {
786 size_t chunk;
787 char *data;
788 size_t skip = 0;
789 if (isize - file_pos > PAGE_CACHE_SIZE)
790 chunk = PAGE_CACHE_SIZE;
791 else
792 chunk = isize - file_pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Jeff Mahoneyec6ea562009-03-30 14:02:30 -0400794 page = reiserfs_get_page(dentry->d_inode, file_pos);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700795 if (IS_ERR(page)) {
796 err = PTR_ERR(page);
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400797 goto out_unlock;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700798 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700800 lock_page(page);
801 data = page_address(page);
802 if (file_pos == 0) {
803 struct reiserfs_xattr_header *rxh =
804 (struct reiserfs_xattr_header *)data;
805 skip = file_pos = sizeof(struct reiserfs_xattr_header);
806 chunk -= skip;
807 /* Magic doesn't match up.. */
808 if (rxh->h_magic != cpu_to_le32(REISERFS_XATTR_MAGIC)) {
809 unlock_page(page);
810 reiserfs_put_page(page);
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400811 reiserfs_warning(inode->i_sb, "jdm-20001",
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700812 "Invalid magic for xattr (%s) "
813 "associated with %k", name,
814 INODE_PKEY(inode));
815 err = -EIO;
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400816 goto out_unlock;
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700817 }
818 hash = le32_to_cpu(rxh->h_hash);
819 }
820 memcpy(buffer + buffer_pos, data + skip, chunk);
821 unlock_page(page);
822 reiserfs_put_page(page);
823 file_pos += chunk;
824 buffer_pos += chunk;
825 skip = 0;
826 }
827 err = isize - sizeof(struct reiserfs_xattr_header);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700829 if (xattr_hash(buffer, isize - sizeof(struct reiserfs_xattr_header)) !=
830 hash) {
Jeff Mahoney45b03d52009-03-30 14:02:21 -0400831 reiserfs_warning(inode->i_sb, "jdm-20002",
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700832 "Invalid hash for xattr (%s) associated "
833 "with %k", name, INODE_PKEY(inode));
834 err = -EIO;
835 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Jeff Mahoney8b6dd722009-03-30 14:02:36 -0400837out_unlock:
838 up_read(&REISERFS_I(inode)->i_xattr_sem);
Jeff Mahoney3227e142008-02-15 14:37:22 -0800839 dput(dentry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
Jeff Mahoneya72bdb12009-03-30 14:02:33 -0400841out:
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700842 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843}
844
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700845int reiserfs_xattr_del(struct inode *inode, const char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700847 struct dentry *dir;
848 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Jeff Mahoney6c176752009-03-30 14:02:34 -0400850 dir = open_xa_dir(inode, XATTR_REPLACE);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700851 if (IS_ERR(dir)) {
852 err = PTR_ERR(dir);
853 goto out;
854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Jeff Mahoney6c176752009-03-30 14:02:34 -0400856 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700857 err = __reiserfs_xattr_del(dir, name, strlen(name));
Jeff Mahoney6c176752009-03-30 14:02:34 -0400858 mutex_unlock(&dir->d_inode->i_mutex);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700859 dput(dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700861 if (!err) {
862 inode->i_ctime = CURRENT_TIME_SEC;
863 mark_inode_dirty(inode);
864 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700866 out:
867 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868}
869
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870/* Actual operations that are exported to VFS-land */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871/*
872 * Inode operation getxattr()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 */
874ssize_t
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700875reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer,
876 size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700878 struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
879 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700881 if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
882 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
883 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700885 err = xah->get(dentry->d_inode, name, buffer, size);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700886 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887}
888
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889/*
890 * Inode operation setxattr()
891 *
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800892 * dentry->d_inode->i_mutex down
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 */
894int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700895reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value,
896 size_t size, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700898 struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
899 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700901 if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
902 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
903 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700905 err = xah->set(dentry->d_inode, name, value, size, flags);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700906 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907}
908
909/*
910 * Inode operation removexattr()
911 *
Jes Sorensen1b1dcc12006-01-09 15:59:24 -0800912 * dentry->d_inode->i_mutex down
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700914int reiserfs_removexattr(struct dentry *dentry, const char *name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700916 int err;
917 struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700919 if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
920 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
921 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700923 err = reiserfs_xattr_del(dentry->d_inode, name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700925 dentry->d_inode->i_ctime = CURRENT_TIME_SEC;
926 mark_inode_dirty(dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700928 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929}
930
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931/* This is what filldir will use:
932 * r_pos will always contain the amount of space required for the entire
933 * list. If r_pos becomes larger than r_size, we need more space and we
934 * return an error indicating this. If r_pos is less than r_size, then we've
935 * filled the buffer successfully and we return success */
936struct reiserfs_listxattr_buf {
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700937 int r_pos;
938 int r_size;
939 char *r_buf;
940 struct inode *r_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941};
942
943static int
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700944reiserfs_listxattr_filler(void *buf, const char *name, int namelen,
David Howellsafefdbb2006-10-03 01:13:46 -0700945 loff_t offset, u64 ino, unsigned int d_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700947 struct reiserfs_listxattr_buf *b = (struct reiserfs_listxattr_buf *)buf;
948 int len = 0;
949 if (name[0] != '.'
950 || (namelen != 1 && (name[1] != '.' || namelen != 2))) {
951 struct reiserfs_xattr_handler *xah =
952 find_xattr_handler_prefix(name);
953 if (!xah)
954 return 0; /* Unsupported xattr name, skip it */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700956 /* We call ->list() twice because the operation isn't required to just
957 * return the name back - we want to make sure we have enough space */
958 len += xah->list(b->r_inode, name, namelen, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700960 if (len) {
961 if (b->r_pos + len + 1 <= b->r_size) {
962 char *p = b->r_buf + b->r_pos;
963 p += xah->list(b->r_inode, name, namelen, p);
964 *p++ = '\0';
965 }
966 b->r_pos += len + 1;
967 }
968 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700970 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971}
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700972
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973/*
974 * Inode operation listxattr()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 */
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700976ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700978 struct dentry *dir;
979 int err = 0;
980 struct reiserfs_listxattr_buf buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700982 if (!dentry->d_inode)
983 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700985 if (!reiserfs_xattrs(dentry->d_sb) ||
986 get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
987 return -EOPNOTSUPP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
Jeff Mahoney6c176752009-03-30 14:02:34 -0400989 dir = open_xa_dir(dentry->d_inode, XATTR_REPLACE);
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700990 if (IS_ERR(dir)) {
991 err = PTR_ERR(dir);
992 if (err == -ENODATA)
993 err = 0; /* Not an error if there aren't any xattrs */
994 goto out;
995 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
Linus Torvaldsbd4c6252005-07-12 20:21:28 -0700997 buf.r_buf = buffer;
998 buf.r_size = buffer ? size : 0;
999 buf.r_pos = 0;
1000 buf.r_inode = dentry->d_inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001002 REISERFS_I(dentry->d_inode)->i_flags |= i_has_xattr_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
Jeff Mahoney6c176752009-03-30 14:02:34 -04001004 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR);
Jeff Mahoney3227e142008-02-15 14:37:22 -08001005 err = xattr_readdir(dir->d_inode, reiserfs_listxattr_filler, &buf);
Jeff Mahoney6c176752009-03-30 14:02:34 -04001006 mutex_unlock(&dir->d_inode->i_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
Jeff Mahoney8b6dd722009-03-30 14:02:36 -04001008 if (!err) {
1009 if (buf.r_pos > buf.r_size && buffer != NULL)
1010 err = -ERANGE;
1011 else
1012 err = buf.r_pos;
1013 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
Jeff Mahoney3227e142008-02-15 14:37:22 -08001015 dput(dir);
Jeff Mahoney8b6dd722009-03-30 14:02:36 -04001016out:
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001017 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018}
1019
1020/* This is the implementation for the xattr plugin infrastructure */
Denis Chengbcf11cb2008-02-06 01:37:40 -08001021static LIST_HEAD(xattr_handlers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022static DEFINE_RWLOCK(handler_lock);
1023
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001024static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
1025 *prefix)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001027 struct reiserfs_xattr_handler *xah = NULL;
1028 struct list_head *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001030 read_lock(&handler_lock);
1031 list_for_each(p, &xattr_handlers) {
1032 xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
1033 if (strncmp(xah->prefix, prefix, strlen(xah->prefix)) == 0)
1034 break;
1035 xah = NULL;
1036 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001038 read_unlock(&handler_lock);
1039 return xah;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040}
1041
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001042static void __unregister_handlers(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001044 struct reiserfs_xattr_handler *xah;
1045 struct list_head *p, *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001047 list_for_each_safe(p, tmp, &xattr_handlers) {
1048 xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
1049 if (xah->exit)
1050 xah->exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001052 list_del_init(p);
1053 }
1054 INIT_LIST_HEAD(&xattr_handlers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055}
1056
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001057int __init reiserfs_xattr_register_handlers(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001059 int err = 0;
1060 struct reiserfs_xattr_handler *xah;
1061 struct list_head *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001063 write_lock(&handler_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001065 /* If we're already initialized, nothing to do */
1066 if (!list_empty(&xattr_handlers)) {
1067 write_unlock(&handler_lock);
1068 return 0;
1069 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001071 /* Add the handlers */
1072 list_add_tail(&user_handler.handlers, &xattr_handlers);
1073 list_add_tail(&trusted_handler.handlers, &xattr_handlers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074#ifdef CONFIG_REISERFS_FS_SECURITY
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001075 list_add_tail(&security_handler.handlers, &xattr_handlers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076#endif
1077#ifdef CONFIG_REISERFS_FS_POSIX_ACL
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001078 list_add_tail(&posix_acl_access_handler.handlers, &xattr_handlers);
1079 list_add_tail(&posix_acl_default_handler.handlers, &xattr_handlers);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080#endif
1081
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001082 /* Run initializers, if available */
1083 list_for_each(p, &xattr_handlers) {
1084 xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
1085 if (xah->init) {
1086 err = xah->init();
1087 if (err) {
1088 list_del_init(p);
1089 break;
1090 }
1091 }
1092 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001094 /* Clean up other handlers, if any failed */
1095 if (err)
1096 __unregister_handlers();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001098 write_unlock(&handler_lock);
1099 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100}
1101
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001102void reiserfs_xattr_unregister_handlers(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103{
Linus Torvaldsbd4c6252005-07-12 20:21:28 -07001104 write_lock(&handler_lock);
1105 __unregister_handlers();
1106 write_unlock(&handler_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107}
1108
Christoph Hellwigec191572006-02-01 03:06:46 -08001109static int reiserfs_check_acl(struct inode *inode, int mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110{
Christoph Hellwigec191572006-02-01 03:06:46 -08001111 struct posix_acl *acl;
1112 int error = -EAGAIN; /* do regular unix permission checks by default */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
Christoph Hellwigec191572006-02-01 03:06:46 -08001114 acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
1115
Christoph Hellwigec191572006-02-01 03:06:46 -08001116 if (acl) {
1117 if (!IS_ERR(acl)) {
1118 error = posix_acl_permission(inode, acl, mask);
1119 posix_acl_release(acl);
1120 } else if (PTR_ERR(acl) != -ENODATA)
1121 error = PTR_ERR(acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 }
1123
Christoph Hellwigec191572006-02-01 03:06:46 -08001124 return error;
1125}
1126
Al Viroe6305c42008-07-15 21:03:57 -04001127int reiserfs_permission(struct inode *inode, int mask)
Christoph Hellwigec191572006-02-01 03:06:46 -08001128{
1129 /*
1130 * We don't do permission checks on the internal objects.
1131 * Permissions are determined by the "owning" object.
1132 */
Jeff Mahoney6dfede62009-03-30 14:02:32 -04001133 if (IS_PRIVATE(inode))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 /*
Christoph Hellwigec191572006-02-01 03:06:46 -08001136 * Stat data v1 doesn't support ACLs.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 */
Christoph Hellwigec191572006-02-01 03:06:46 -08001138 if (get_inode_sd_version(inode) == STAT_DATA_V1)
1139 return generic_permission(inode, mask, NULL);
1140 else
1141 return generic_permission(inode, mask, reiserfs_check_acl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142}
Jeff Mahoneya72bdb12009-03-30 14:02:33 -04001143
1144static int create_privroot(struct dentry *dentry)
1145{
1146 int err;
1147 struct inode *inode = dentry->d_parent->d_inode;
1148 mutex_lock_nested(&inode->i_mutex, I_MUTEX_XATTR);
Jeff Mahoney6c176752009-03-30 14:02:34 -04001149 err = xattr_mkdir(inode, dentry, 0700);
Jeff Mahoneya72bdb12009-03-30 14:02:33 -04001150 mutex_unlock(&inode->i_mutex);
1151 if (err) {
1152 dput(dentry);
1153 dentry = NULL;
1154 }
1155
1156 if (dentry && dentry->d_inode)
1157 reiserfs_info(dentry->d_sb, "Created %s - reserved for xattr "
1158 "storage.\n", PRIVROOT_NAME);
1159
1160 return err;
1161}
1162
1163static int xattr_mount_check(struct super_block *s)
1164{
1165 /* We need generation numbers to ensure that the oid mapping is correct
1166 * v3.5 filesystems don't have them. */
1167 if (!old_format_only(s)) {
1168 set_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
1169 } else if (reiserfs_xattrs_optional(s)) {
1170 /* Old format filesystem, but optional xattrs have been enabled
1171 * at mount time. Error out. */
1172 reiserfs_warning(s, "jdm-20005",
1173 "xattrs/ACLs not supported on pre v3.6 "
1174 "format filesystem. Failing mount.");
1175 return -EOPNOTSUPP;
1176 } else {
1177 /* Old format filesystem, but no optional xattrs have
1178 * been enabled. This means we silently disable xattrs
1179 * on the filesystem. */
1180 clear_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
1181 }
1182
1183 return 0;
1184}
1185
1186#else
1187int __init reiserfs_xattr_register_handlers(void) { return 0; }
1188void reiserfs_xattr_unregister_handlers(void) {}
1189#endif
1190
1191/* This will catch lookups from the fs root to .reiserfs_priv */
1192static int
1193xattr_lookup_poison(struct dentry *dentry, struct qstr *q1, struct qstr *name)
1194{
1195 struct dentry *priv_root = REISERFS_SB(dentry->d_sb)->priv_root;
1196 if (name->len == priv_root->d_name.len &&
1197 name->hash == priv_root->d_name.hash &&
1198 !memcmp(name->name, priv_root->d_name.name, name->len)) {
1199 return -ENOENT;
1200 } else if (q1->len == name->len &&
1201 !memcmp(q1->name, name->name, name->len))
1202 return 0;
1203 return 1;
1204}
1205
1206static struct dentry_operations xattr_lookup_poison_ops = {
1207 .d_compare = xattr_lookup_poison,
1208};
1209
1210/* We need to take a copy of the mount flags since things like
1211 * MS_RDONLY don't get set until *after* we're called.
1212 * mount_flags != mount_options */
1213int reiserfs_xattr_init(struct super_block *s, int mount_flags)
1214{
1215 int err = 0;
1216
1217#ifdef CONFIG_REISERFS_FS_XATTR
1218 err = xattr_mount_check(s);
1219 if (err)
1220 goto error;
1221#endif
1222
1223 /* If we don't have the privroot located yet - go find it */
1224 if (!REISERFS_SB(s)->priv_root) {
1225 struct dentry *dentry;
1226 dentry = lookup_one_len(PRIVROOT_NAME, s->s_root,
1227 strlen(PRIVROOT_NAME));
1228 if (!IS_ERR(dentry)) {
1229#ifdef CONFIG_REISERFS_FS_XATTR
1230 if (!(mount_flags & MS_RDONLY) && !dentry->d_inode)
1231 err = create_privroot(dentry);
1232#endif
1233 if (!dentry->d_inode) {
1234 dput(dentry);
1235 dentry = NULL;
1236 }
1237 } else
1238 err = PTR_ERR(dentry);
1239
1240 if (!err && dentry) {
1241 s->s_root->d_op = &xattr_lookup_poison_ops;
1242 dentry->d_inode->i_flags |= S_PRIVATE;
1243 REISERFS_SB(s)->priv_root = dentry;
1244#ifdef CONFIG_REISERFS_FS_XATTR
1245 /* xattrs are unavailable */
1246 } else if (!(mount_flags & MS_RDONLY)) {
1247 /* If we're read-only it just means that the dir
1248 * hasn't been created. Not an error -- just no
1249 * xattrs on the fs. We'll check again if we
1250 * go read-write */
1251 reiserfs_warning(s, "jdm-20006",
1252 "xattrs/ACLs enabled and couldn't "
1253 "find/create .reiserfs_priv. "
1254 "Failing mount.");
1255 err = -EOPNOTSUPP;
1256#endif
1257 }
1258 }
1259
1260#ifdef CONFIG_REISERFS_FS_XATTR
1261error:
1262 if (err) {
1263 clear_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
1264 clear_bit(REISERFS_XATTRS_USER, &(REISERFS_SB(s)->s_mount_opt));
1265 clear_bit(REISERFS_POSIXACL, &(REISERFS_SB(s)->s_mount_opt));
1266 }
1267#endif
1268
1269 /* The super_block MS_POSIXACL must mirror the (no)acl mount option. */
1270 s->s_flags = s->s_flags & ~MS_POSIXACL;
1271#ifdef CONFIG_REISERFS_FS_POSIX_ACL
1272 if (reiserfs_posixacl(s))
1273 s->s_flags |= MS_POSIXACL;
1274#endif
1275
1276 return err;
1277}