1 Subject: reiserfs: use generic xattr handlers
2 From: Jeff Mahoney <jeffm@suse.com>
4 Christoph Hellwig had asked me quite some time ago to port the reiserfs
5 xattrs to the generic xattr interface.
7 This patch replaces the reiserfs-specific xattr handling code with the
8 generic struct xattr_handler.
10 However, since reiserfs doesn't split the prefix and name when accessing
11 xattrs, it can't leverage generic_{set,get,list,remove}xattr without
12 needlessly reconstructing the name on the back end.
14 Update 7/26/07: Added missing dput() to deletion path.
15 Update 8/30/07: Added missing mark_inode_dirty when i_mode is used to
16 represent an ACL and no previous ACL existed.
18 Signed-off-by: Jeff Mahoney <jeffm@suse.com>
22 fs/reiserfs/super.c | 7
23 fs/reiserfs/xattr.c | 467 ++++++++++++++++-------------------------
24 fs/reiserfs/xattr_acl.c | 79 ++----
25 fs/reiserfs/xattr_security.c | 26 --
26 fs/reiserfs/xattr_trusted.c | 45 ---
27 fs/reiserfs/xattr_user.c | 31 --
28 include/linux/reiserfs_acl.h | 16 -
29 include/linux/reiserfs_fs_sb.h | 3
30 include/linux/reiserfs_xattr.h | 25 --
31 9 files changed, 258 insertions(+), 441 deletions(-)
33 --- a/fs/reiserfs/super.c
34 +++ b/fs/reiserfs/super.c
35 @@ -2261,9 +2261,6 @@ static int __init init_reiserfs_fs(void)
39 - if ((ret = reiserfs_xattr_register_handlers()))
40 - goto failed_reiserfs_xattr_register_handlers;
42 reiserfs_proc_info_global_init();
43 reiserfs_proc_register_global("version",
44 reiserfs_global_version_in_proc);
45 @@ -2274,9 +2271,6 @@ static int __init init_reiserfs_fs(void)
49 - reiserfs_xattr_unregister_handlers();
51 - failed_reiserfs_xattr_register_handlers:
52 reiserfs_proc_unregister_global("version");
53 reiserfs_proc_info_global_done();
55 @@ -2286,7 +2280,6 @@ static int __init init_reiserfs_fs(void)
57 static void __exit exit_reiserfs_fs(void)
59 - reiserfs_xattr_unregister_handlers();
60 reiserfs_proc_unregister_global("version");
61 reiserfs_proc_info_global_done();
62 unregister_filesystem(&reiserfs_fs_type);
63 --- a/fs/reiserfs/xattr_acl.c
64 +++ b/fs/reiserfs/xattr_acl.c
65 @@ -271,7 +271,7 @@ reiserfs_set_acl(struct inode *inode, in
68 struct posix_acl **p_acl;
72 struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
74 @@ -308,16 +308,21 @@ reiserfs_set_acl(struct inode *inode, in
75 value = posix_acl_to_disk(acl, &size);
77 return (int)PTR_ERR(value);
78 - error = reiserfs_xattr_set(inode, name, value, size, 0);
80 - error = reiserfs_xattr_del(inode, name);
81 - if (error == -ENODATA) {
82 - /* This may seem odd here, but it means that the ACL was set
83 - * with a value representable with mode bits. If there was
84 - * an ACL before, reiserfs_xattr_del already dirtied the inode.
88 + error = __reiserfs_xattr_set(inode, name, value, size, 0);
91 + * Ensure that the inode gets dirtied if we're only using
92 + * the mode bits and an old ACL didn't exist. We don't need
93 + * to check if the inode is hashed here since we won't get
94 + * called by reiserfs_inherit_default_acl().
96 + if (error == -ENODATA) {
98 + if (type == ACL_TYPE_ACCESS) {
99 + inode->i_ctime = CURRENT_TIME_SEC;
100 mark_inode_dirty(inode);
105 @@ -474,33 +479,22 @@ posix_acl_access_set(struct inode *inode
106 return xattr_set_acl(inode, ACL_TYPE_ACCESS, value, size);
109 -static int posix_acl_access_del(struct inode *inode, const char *name)
111 - struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
112 - if (strlen(name) != sizeof(POSIX_ACL_XATTR_ACCESS) - 1)
114 - iset_acl(inode, &reiserfs_i->i_acl_access, ERR_PTR(-ENODATA));
119 -posix_acl_access_list(struct inode *inode, const char *name, int namelen,
121 +static size_t posix_acl_access_list(struct inode *inode, char *list,
122 + size_t list_size, const char *name,
126 + const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS);
127 if (!reiserfs_posixacl(inode->i_sb))
130 - memcpy(out, name, len);
133 + if (list && size <= list_size)
134 + memcpy(list, POSIX_ACL_XATTR_ACCESS, size);
138 -struct reiserfs_xattr_handler posix_acl_access_handler = {
139 +struct xattr_handler reiserfs_posix_acl_access_handler = {
140 .prefix = POSIX_ACL_XATTR_ACCESS,
141 .get = posix_acl_access_get,
142 .set = posix_acl_access_set,
143 - .del = posix_acl_access_del,
144 .list = posix_acl_access_list,
147 @@ -522,32 +516,21 @@ posix_acl_default_set(struct inode *inod
148 return xattr_set_acl(inode, ACL_TYPE_DEFAULT, value, size);
151 -static int posix_acl_default_del(struct inode *inode, const char *name)
153 - struct reiserfs_inode_info *reiserfs_i = REISERFS_I(inode);
154 - if (strlen(name) != sizeof(POSIX_ACL_XATTR_DEFAULT) - 1)
156 - iset_acl(inode, &reiserfs_i->i_acl_default, ERR_PTR(-ENODATA));
161 -posix_acl_default_list(struct inode *inode, const char *name, int namelen,
163 +static size_t posix_acl_default_list(struct inode *inode, char *list,
164 + size_t list_size, const char *name,
168 + const size_t size = sizeof(POSIX_ACL_XATTR_DEFAULT);
169 if (!reiserfs_posixacl(inode->i_sb))
172 - memcpy(out, name, len);
175 + if (list && size <= list_size)
176 + memcpy(list, POSIX_ACL_XATTR_DEFAULT, size);
180 -struct reiserfs_xattr_handler posix_acl_default_handler = {
181 +struct xattr_handler reiserfs_posix_acl_default_handler = {
182 .prefix = POSIX_ACL_XATTR_DEFAULT,
183 .get = posix_acl_default_get,
184 .set = posix_acl_default_set,
185 - .del = posix_acl_default_del,
186 .list = posix_acl_default_list,
188 --- a/fs/reiserfs/xattr.c
189 +++ b/fs/reiserfs/xattr.c
191 #define PRIVROOT_NAME ".reiserfs_priv"
192 #define XAROOT_NAME "xattrs"
194 -static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char *);
196 /* Helpers for inode ops. We do this so that we don't have all the VFS
197 * overhead and also for proper i_mutex annotation.
198 @@ -110,7 +109,6 @@ static int xattr_rmdir(struct inode *dir
203 #define xattr_may_create(flags) (!flags || flags & XATTR_CREATE)
205 /* Returns and possibly creates the xattr dir. */
206 @@ -339,14 +337,17 @@ int xattr_readdir(struct inode *inode, f
210 -/* expects xadir->d_inode->i_mutex to be locked */
211 +/* The following are side effects of other operations that aren't explicitly
212 + * modifying extended attributes. This includes operations such as permissions
213 + * or ownership changes, object deletions, etc. */
216 -__reiserfs_xattr_del(struct dentry *xadir, const char *name, int namelen)
217 +reiserfs_delete_xattrs_filler(void *buf, const char *name, int namelen,
218 + loff_t offset, u64 ino, unsigned int d_type)
220 + struct dentry *xadir = (struct dentry *)buf;
221 struct dentry *dentry;
222 - struct inode *dir = xadir->d_inode;
224 - struct reiserfs_xattr_handler *xah;
226 dentry = lookup_one_len(name, xadir, namelen);
227 if (IS_ERR(dentry)) {
228 @@ -361,28 +362,7 @@ __reiserfs_xattr_del(struct dentry *xadi
229 if (S_ISDIR(dentry->d_inode->i_mode))
232 - if (!IS_PRIVATE(dentry->d_inode)) {
233 - reiserfs_error(dir->i_sb, "jdm-20003",
234 - "OID %08x [%.*s/%.*s] doesn't have "
235 - "priv flag set [parent is %sset].",
236 - le32_to_cpu(INODE_PKEY(dentry->d_inode)->
237 - k_objectid), xadir->d_name.len,
238 - xadir->d_name.name, namelen, name,
239 - IS_PRIVATE(xadir->d_inode) ? "" :
245 - /* Deletion pre-operation */
246 - xah = find_xattr_handler_prefix(name);
247 - if (xah && xah->del) {
248 - err = xah->del(dentry->d_inode, name);
253 - err = xattr_unlink(dir, dentry);
254 + err = xattr_unlink(xadir->d_inode, dentry);
258 @@ -391,20 +371,6 @@ out:
262 -/* The following are side effects of other operations that aren't explicitly
263 - * modifying extended attributes. This includes operations such as permissions
264 - * or ownership changes, object deletions, etc. */
267 -reiserfs_delete_xattrs_filler(void *buf, const char *name, int namelen,
268 - loff_t offset, u64 ino, unsigned int d_type)
270 - struct dentry *xadir = (struct dentry *)buf;
272 - return __reiserfs_xattr_del(xadir, name, namelen);
276 /* This is called w/ inode->i_mutex downed */
277 int reiserfs_delete_xattrs(struct inode *inode)
279 @@ -541,14 +507,11 @@ out:
282 #ifdef CONFIG_REISERFS_FS_XATTR
283 -static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
286 /* Returns a dentry corresponding to a specific extended attribute file
287 * for the inode. If flags allow, the file is created. Otherwise, a
288 * valid or negative dentry, or an error is returned. */
289 -static struct dentry *get_xa_file_dentry(const struct inode *inode,
290 - const char *name, int flags)
291 +static struct dentry *xattr_lookup(struct inode *inode, const char *name,
294 struct dentry *xadir, *xafile;
296 @@ -623,6 +586,45 @@ int reiserfs_commit_write(struct file *f
297 int reiserfs_prepare_write(struct file *f, struct page *page,
298 unsigned from, unsigned to);
300 +static void update_ctime(struct inode *inode)
302 + struct timespec now = current_fs_time(inode->i_sb);
303 + if (hlist_unhashed(&inode->i_hash) || !inode->i_nlink ||
304 + timespec_equal(&inode->i_ctime, &now))
307 + inode->i_ctime = CURRENT_TIME_SEC;
308 + mark_inode_dirty(inode);
311 +static int lookup_and_delete_xattr(struct inode *inode, const char *name)
314 + struct dentry *dentry, *xadir;
316 + xadir = open_xa_dir(inode, XATTR_REPLACE);
318 + return PTR_ERR(xadir);
320 + dentry = lookup_one_len(name, xadir, strlen(name));
321 + if (IS_ERR(dentry)) {
322 + err = PTR_ERR(dentry);
326 + if (dentry->d_inode) {
327 + mutex_lock_nested(&xadir->d_inode->i_mutex, I_MUTEX_XATTR);
328 + err = xattr_unlink(xadir->d_inode, dentry);
329 + mutex_unlock(&xadir->d_inode->i_mutex);
330 + update_ctime(inode);
340 /* Generic extended attribute operations that can be used by xa plugins */
342 @@ -630,8 +632,8 @@ int reiserfs_prepare_write(struct file *
343 * inode->i_mutex: down
346 -reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
347 - size_t buffer_size, int flags)
348 +__reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
349 + size_t buffer_size, int flags)
352 struct dentry *dentry;
353 @@ -639,37 +641,22 @@ reiserfs_xattr_set(struct inode *inode,
356 size_t buffer_pos = 0;
357 - struct iattr newattrs;
361 if (get_inode_sd_version(inode) == STAT_DATA_V1)
365 - return reiserfs_xattr_del(inode, name);
366 + return lookup_and_delete_xattr(inode, name);
368 - dentry = get_xa_file_dentry(inode, name, flags);
369 - if (IS_ERR(dentry)) {
370 - err = PTR_ERR(dentry);
373 + dentry = xattr_lookup(inode, name, flags);
374 + if (IS_ERR(dentry))
375 + return PTR_ERR(dentry);
377 down_write(&REISERFS_I(inode)->i_xattr_sem);
379 xahash = xattr_hash(buffer, buffer_size);
381 - /* Resize it so we're ok to write there */
382 - newattrs.ia_size = buffer_size;
383 - newattrs.ia_ctime = current_fs_time(inode->i_sb);
384 - newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
385 - mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_XATTR);
386 - down_write(&dentry->d_inode->i_alloc_sem);
387 - err = reiserfs_setattr(dentry, &newattrs);
388 - up_write(&dentry->d_inode->i_alloc_sem);
389 - mutex_unlock(&dentry->d_inode->i_mutex);
393 while (buffer_pos < buffer_size || buffer_pos == 0) {
396 @@ -682,7 +669,7 @@ reiserfs_xattr_set(struct inode *inode,
397 page = reiserfs_get_page(dentry->d_inode, file_pos);
405 @@ -716,20 +703,33 @@ reiserfs_xattr_set(struct inode *inode,
409 - /* We can't mark the inode dirty if it's not hashed. This is the case
410 - * when we're inheriting the default ACL. If we dirty it, the inode
411 - * gets marked dirty, but won't (ever) make it onto the dirty list until
412 - * it's synced explicitly to clear I_DIRTY. This is bad. */
413 - if (!hlist_unhashed(&inode->i_hash)) {
414 - inode->i_ctime = CURRENT_TIME_SEC;
415 - mark_inode_dirty(inode);
419 + new_size = buffer_size + sizeof(struct reiserfs_xattr_header);
420 + if (!err && new_size < i_size_read(dentry->d_inode)) {
421 + struct iattr newattrs = {
422 + .ia_ctime = current_fs_time(inode->i_sb),
423 + .ia_size = buffer_size,
424 + .ia_valid = ATTR_SIZE | ATTR_CTIME,
426 + mutex_lock_nested(&dentry->d_inode->i_mutex, I_MUTEX_XATTR);
427 + down_write(&dentry->d_inode->i_alloc_sem);
428 + err = reiserfs_setattr(dentry, &newattrs);
429 + up_write(&dentry->d_inode->i_alloc_sem);
430 + mutex_unlock(&dentry->d_inode->i_mutex);
432 + update_ctime(inode);
434 up_write(&REISERFS_I(inode)->i_xattr_sem);
441 +reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
442 + size_t buffer_size, int flags)
444 + int err = __reiserfs_xattr_set(inode, name, buffer, buffer_size, flags);
445 + if (err == -ENODATA)
450 @@ -737,7 +737,7 @@ reiserfs_xattr_set(struct inode *inode,
451 * inode->i_mutex: down
454 -reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer,
455 +reiserfs_xattr_get(struct inode *inode, const char *name, void *buffer,
459 @@ -756,7 +756,7 @@ reiserfs_xattr_get(const struct inode *i
460 if (get_inode_sd_version(inode) == STAT_DATA_V1)
463 - dentry = get_xa_file_dentry(inode, name, XATTR_REPLACE);
464 + dentry = xattr_lookup(inode, name, XATTR_REPLACE);
465 if (IS_ERR(dentry)) {
466 err = PTR_ERR(dentry);
468 @@ -837,32 +837,53 @@ out:
472 -int reiserfs_xattr_del(struct inode *inode, const char *name)
474 - struct dentry *dir;
476 +/* Actual operations that are exported to VFS-land */
477 +struct xattr_handler *reiserfs_xattr_handlers[] = {
478 + &reiserfs_xattr_user_handler,
479 + &reiserfs_xattr_trusted_handler,
480 +#ifdef CONFIG_REISERFS_FS_SECURITY
481 + &reiserfs_xattr_security_handler,
483 +#ifdef CONFIG_REISERFS_FS_POSIX_ACL
484 + &reiserfs_posix_acl_access_handler,
485 + &reiserfs_posix_acl_default_handler,
490 - dir = open_xa_dir(inode, XATTR_REPLACE);
492 - err = PTR_ERR(dir);
496 + * In order to implement different sets of xattr operations for each xattr
497 + * prefix with the generic xattr API, a filesystem should create a
498 + * null-terminated array of struct xattr_handler (one for each prefix) and
499 + * hang a pointer to it off of the s_xattr field of the superblock.
501 + * The generic_fooxattr() functions will use this list to dispatch xattr
502 + * operations to the correct xattr_handler.
504 +#define for_each_xattr_handler(handlers, handler) \
505 + for ((handler) = *(handlers)++; \
506 + (handler) != NULL; \
507 + (handler) = *(handlers)++)
509 - mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR);
510 - err = __reiserfs_xattr_del(dir, name, strlen(name));
511 - mutex_unlock(&dir->d_inode->i_mutex);
513 +/* This is the implementation for the xattr plugin infrastructure */
514 +static inline struct xattr_handler *
515 +find_xattr_handler_prefix(struct xattr_handler **handlers,
518 + struct xattr_handler *xah;
521 - inode->i_ctime = CURRENT_TIME_SEC;
522 - mark_inode_dirty(inode);
526 + for_each_xattr_handler(handlers, xah) {
527 + if (strncmp(xah->prefix, name, strlen(xah->prefix)) == 0)
536 -/* Actual operations that are exported to VFS-land */
539 * Inode operation getxattr()
541 @@ -870,15 +891,15 @@ ssize_t
542 reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer,
545 - struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
547 + struct inode *inode = dentry->d_inode;
548 + struct xattr_handler *handler;
550 - if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
551 - get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
552 + handler = find_xattr_handler_prefix(inode->i_sb->s_xattr, name);
554 + if (!handler || get_inode_sd_version(inode) == STAT_DATA_V1)
557 - err = xah->get(dentry->d_inode, name, buffer, size);
559 + return handler->get(inode, name, buffer, size);
563 @@ -890,15 +911,15 @@ int
564 reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value,
565 size_t size, int flags)
567 - struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
569 + struct inode *inode = dentry->d_inode;
570 + struct xattr_handler *handler;
572 - if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
573 - get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
574 + handler = find_xattr_handler_prefix(inode->i_sb->s_xattr, name);
576 + if (!handler || get_inode_sd_version(inode) == STAT_DATA_V1)
579 - err = xah->set(dentry->d_inode, name, value, size, flags);
581 + return handler->set(inode, name, value, size, flags);
585 @@ -908,71 +929,65 @@ reiserfs_setxattr(struct dentry *dentry,
587 int reiserfs_removexattr(struct dentry *dentry, const char *name)
590 - struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
591 + struct inode *inode = dentry->d_inode;
592 + struct xattr_handler *handler;
593 + handler = find_xattr_handler_prefix(inode->i_sb->s_xattr, name);
595 - if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
596 - get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
597 + if (!handler || get_inode_sd_version(inode) == STAT_DATA_V1)
600 - err = reiserfs_xattr_del(dentry->d_inode, name);
602 - dentry->d_inode->i_ctime = CURRENT_TIME_SEC;
603 - mark_inode_dirty(dentry->d_inode);
606 + return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
609 -/* This is what filldir will use:
610 - * r_pos will always contain the amount of space required for the entire
611 - * list. If r_pos becomes larger than r_size, we need more space and we
612 - * return an error indicating this. If r_pos is less than r_size, then we've
613 - * filled the buffer successfully and we return success */
614 -struct reiserfs_listxattr_buf {
618 - struct inode *r_inode;
619 +struct listxattr_buf {
623 + struct inode *inode;
627 -reiserfs_listxattr_filler(void *buf, const char *name, int namelen,
628 - loff_t offset, u64 ino, unsigned int d_type)
629 +static int listxattr_filler(void *buf, const char *name, int namelen,
630 + loff_t offset, u64 ino, unsigned int d_type)
632 - struct reiserfs_listxattr_buf *b = (struct reiserfs_listxattr_buf *)buf;
635 - || (namelen != 1 && (name[1] != '.' || namelen != 2))) {
636 - struct reiserfs_xattr_handler *xah =
637 - find_xattr_handler_prefix(name);
639 - return 0; /* Unsupported xattr name, skip it */
641 - /* We call ->list() twice because the operation isn't required to just
642 - * return the name back - we want to make sure we have enough space */
643 - len += xah->list(b->r_inode, name, namelen, NULL);
646 - if (b->r_pos + len + 1 <= b->r_size) {
647 - char *p = b->r_buf + b->r_pos;
648 - p += xah->list(b->r_inode, name, namelen, p);
651 - b->r_pos += len + 1;
652 + struct listxattr_buf *b = (struct listxattr_buf *)buf;
654 + if (name[0] != '.' ||
655 + (namelen != 1 && (name[1] != '.' || namelen != 2))) {
656 + struct xattr_handler *handler;
657 + handler = find_xattr_handler_prefix(b->inode->i_sb->s_xattr,
659 + if (!handler) /* Unsupported xattr name */
662 + size = handler->list(b->inode, b->buf + b->pos,
663 + b->size, name, namelen);
664 + if (size > b->size)
667 + size = handler->list(b->inode, NULL, 0, name, namelen);
677 * Inode operation listxattr()
679 + * We totally ignore the generic listxattr here because it would be stupid
680 + * not to. Since the xattrs are organized in a directory, we can just
681 + * readdir to find them.
683 ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
687 - struct reiserfs_listxattr_buf buf;
688 + struct listxattr_buf buf = {
689 + .inode = dentry->d_inode,
691 + .size = buffer ? size : 0,
694 if (!dentry->d_inode)
696 @@ -985,120 +1000,22 @@ ssize_t reiserfs_listxattr(struct dentry
700 - err = 0; /* Not an error if there aren't any xattrs */
701 + err = 0; /* Not an error if there aren't any xattrs */
705 - buf.r_buf = buffer;
706 - buf.r_size = buffer ? size : 0;
708 - buf.r_inode = dentry->d_inode;
710 mutex_lock_nested(&dir->d_inode->i_mutex, I_MUTEX_XATTR);
711 - err = xattr_readdir(dir->d_inode, reiserfs_listxattr_filler, &buf);
712 + err = xattr_readdir(dir->d_inode, listxattr_filler, &buf);
713 mutex_unlock(&dir->d_inode->i_mutex);
716 - if (buf.r_pos > buf.r_size && buffer != NULL)
729 -/* This is the implementation for the xattr plugin infrastructure */
730 -static LIST_HEAD(xattr_handlers);
731 -static DEFINE_RWLOCK(handler_lock);
733 -static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
736 - struct reiserfs_xattr_handler *xah = NULL;
737 - struct list_head *p;
739 - read_lock(&handler_lock);
740 - list_for_each(p, &xattr_handlers) {
741 - xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
742 - if (strncmp(xah->prefix, prefix, strlen(xah->prefix)) == 0)
747 - read_unlock(&handler_lock);
751 -static void __unregister_handlers(void)
753 - struct reiserfs_xattr_handler *xah;
754 - struct list_head *p, *tmp;
756 - list_for_each_safe(p, tmp, &xattr_handlers) {
757 - xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
763 - INIT_LIST_HEAD(&xattr_handlers);
766 -int __init reiserfs_xattr_register_handlers(void)
769 - struct reiserfs_xattr_handler *xah;
770 - struct list_head *p;
772 - write_lock(&handler_lock);
774 - /* If we're already initialized, nothing to do */
775 - if (!list_empty(&xattr_handlers)) {
776 - write_unlock(&handler_lock);
780 - /* Add the handlers */
781 - list_add_tail(&user_handler.handlers, &xattr_handlers);
782 - list_add_tail(&trusted_handler.handlers, &xattr_handlers);
783 -#ifdef CONFIG_REISERFS_FS_SECURITY
784 - list_add_tail(&security_handler.handlers, &xattr_handlers);
786 -#ifdef CONFIG_REISERFS_FS_POSIX_ACL
787 - list_add_tail(&posix_acl_access_handler.handlers, &xattr_handlers);
788 - list_add_tail(&posix_acl_default_handler.handlers, &xattr_handlers);
791 - /* Run initializers, if available */
792 - list_for_each(p, &xattr_handlers) {
793 - xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
803 - /* Clean up other handlers, if any failed */
805 - __unregister_handlers();
807 - write_unlock(&handler_lock);
811 -void reiserfs_xattr_unregister_handlers(void)
813 - write_lock(&handler_lock);
814 - __unregister_handlers();
815 - write_unlock(&handler_lock);
818 static int reiserfs_check_acl(struct inode *inode, int mask)
820 struct posix_acl *acl;
821 @@ -1157,20 +1074,16 @@ static int xattr_mount_check(struct supe
823 /* We need generation numbers to ensure that the oid mapping is correct
824 * v3.5 filesystems don't have them. */
825 - if (!old_format_only(s)) {
826 - set_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
827 - } else if (reiserfs_xattrs_optional(s)) {
828 - /* Old format filesystem, but optional xattrs have been enabled
829 - * at mount time. Error out. */
830 - reiserfs_warning(s, "jdm-20005",
831 - "xattrs/ACLs not supported on pre v3.6 "
832 - "format filesystem. Failing mount.");
833 - return -EOPNOTSUPP;
835 - /* Old format filesystem, but no optional xattrs have
836 - * been enabled. This means we silently disable xattrs
837 - * on the filesystem. */
838 - clear_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
839 + if (old_format_only(s)) {
840 + if (reiserfs_xattrs_optional(s)) {
841 + /* Old format filesystem, but optional xattrs have
842 + * been enabled. Error out. */
843 + reiserfs_warning(s, "jdm-2005",
844 + "xattrs/ACLs not supported "
845 + "on pre-v3.6 format filesystems. "
847 + return -EOPNOTSUPP;
852 @@ -1251,9 +1164,11 @@ int reiserfs_xattr_init(struct super_blo
855 #ifdef CONFIG_REISERFS_FS_XATTR
857 + s->s_xattr = reiserfs_xattr_handlers;
861 - clear_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
862 clear_bit(REISERFS_XATTRS_USER, &(REISERFS_SB(s)->s_mount_opt));
863 clear_bit(REISERFS_POSIXACL, &(REISERFS_SB(s)->s_mount_opt));
865 --- a/fs/reiserfs/xattr_security.c
866 +++ b/fs/reiserfs/xattr_security.c
867 @@ -31,35 +31,25 @@ security_set(struct inode *inode, const
868 return reiserfs_xattr_set(inode, name, buffer, size, flags);
871 -static int security_del(struct inode *inode, const char *name)
872 +static size_t security_list(struct inode *inode, char *list, size_t list_len,
873 + const char *name, size_t namelen)
875 - if (strlen(name) < sizeof(XATTR_SECURITY_PREFIX))
878 - if (IS_PRIVATE(inode))
885 -security_list(struct inode *inode, const char *name, int namelen, char *out)
888 + const size_t len = namelen + 1;
890 if (IS_PRIVATE(inode))
894 - memcpy(out, name, len);
895 + if (list && len <= list_len) {
896 + memcpy(list, name, namelen);
897 + list[namelen] = '\0';
903 -struct reiserfs_xattr_handler security_handler = {
904 +struct xattr_handler reiserfs_xattr_security_handler = {
905 .prefix = XATTR_SECURITY_PREFIX,
908 - .del = security_del,
909 .list = security_list,
911 --- a/fs/reiserfs/xattr_trusted.c
912 +++ b/fs/reiserfs/xattr_trusted.c
913 @@ -13,10 +13,7 @@ trusted_get(struct inode *inode, const c
914 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
917 - if (!reiserfs_xattrs(inode->i_sb))
918 - return -EOPNOTSUPP;
920 - if (!(capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode)))
921 + if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
924 return reiserfs_xattr_get(inode, name, buffer, size);
925 @@ -29,50 +26,30 @@ trusted_set(struct inode *inode, const c
926 if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
929 - if (!reiserfs_xattrs(inode->i_sb))
930 - return -EOPNOTSUPP;
932 - if (!(capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode)))
933 + if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
936 return reiserfs_xattr_set(inode, name, buffer, size, flags);
939 -static int trusted_del(struct inode *inode, const char *name)
940 +static size_t trusted_list(struct inode *inode, char *list, size_t list_size,
941 + const char *name, size_t name_len)
943 - if (strlen(name) < sizeof(XATTR_TRUSTED_PREFIX))
945 + const size_t len = name_len + 1;
947 - if (!reiserfs_xattrs(inode->i_sb))
948 - return -EOPNOTSUPP;
950 - if (!(capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode)))
957 -trusted_list(struct inode *inode, const char *name, int namelen, char *out)
961 - if (!reiserfs_xattrs(inode->i_sb))
962 + if (!capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode))
965 - if (!(capable(CAP_SYS_ADMIN) || IS_PRIVATE(inode)))
969 - memcpy(out, name, len);
971 + if (list && len <= list_size) {
972 + memcpy(list, name, name_len);
973 + list[name_len] = '\0';
978 -struct reiserfs_xattr_handler trusted_handler = {
979 +struct xattr_handler reiserfs_xattr_trusted_handler = {
980 .prefix = XATTR_TRUSTED_PREFIX,
983 - .del = trusted_del,
984 .list = trusted_list,
986 --- a/fs/reiserfs/xattr_user.c
987 +++ b/fs/reiserfs/xattr_user.c
989 #include <linux/reiserfs_xattr.h>
990 #include <asm/uaccess.h>
992 -#ifdef CONFIG_REISERFS_FS_POSIX_ACL
993 -# include <linux/reiserfs_acl.h>
997 user_get(struct inode *inode, const char *name, void *buffer, size_t size)
999 @@ -25,7 +21,6 @@ static int
1000 user_set(struct inode *inode, const char *name, const void *buffer,
1001 size_t size, int flags)
1004 if (strlen(name) < sizeof(XATTR_USER_PREFIX))
1007 @@ -34,33 +29,23 @@ user_set(struct inode *inode, const char
1008 return reiserfs_xattr_set(inode, name, buffer, size, flags);
1011 -static int user_del(struct inode *inode, const char *name)
1012 +static size_t user_list(struct inode *inode, char *list, size_t list_size,
1013 + const char *name, size_t name_len)
1015 - if (strlen(name) < sizeof(XATTR_USER_PREFIX))
1018 - if (!reiserfs_xattrs_user(inode->i_sb))
1019 - return -EOPNOTSUPP;
1022 + const size_t len = name_len + 1;
1025 -user_list(struct inode *inode, const char *name, int namelen, char *out)
1027 - int len = namelen;
1028 if (!reiserfs_xattrs_user(inode->i_sb))
1032 - memcpy(out, name, len);
1034 + if (list && len <= list_size) {
1035 + memcpy(list, name, name_len);
1036 + list[name_len] = '\0';
1041 -struct reiserfs_xattr_handler user_handler = {
1042 +struct xattr_handler reiserfs_xattr_user_handler = {
1043 .prefix = XATTR_USER_PREFIX,
1049 --- a/include/linux/reiserfs_acl.h
1050 +++ b/include/linux/reiserfs_acl.h
1051 @@ -52,10 +52,8 @@ int reiserfs_acl_chmod(struct inode *ino
1052 int reiserfs_inherit_default_acl(struct inode *dir, struct dentry *dentry,
1053 struct inode *inode);
1054 int reiserfs_cache_default_acl(struct inode *dir);
1055 -extern int reiserfs_xattr_posix_acl_init(void) __init;
1056 -extern int reiserfs_xattr_posix_acl_exit(void);
1057 -extern struct reiserfs_xattr_handler posix_acl_default_handler;
1058 -extern struct reiserfs_xattr_handler posix_acl_access_handler;
1059 +extern struct xattr_handler reiserfs_posix_acl_default_handler;
1060 +extern struct xattr_handler reiserfs_posix_acl_access_handler;
1062 static inline void reiserfs_init_acl_access(struct inode *inode)
1064 @@ -75,16 +73,6 @@ static inline struct posix_acl *reiserfs
1068 -static inline int reiserfs_xattr_posix_acl_init(void)
1073 -static inline int reiserfs_xattr_posix_acl_exit(void)
1078 static inline int reiserfs_acl_chmod(struct inode *inode)
1081 --- a/include/linux/reiserfs_fs_sb.h
1082 +++ b/include/linux/reiserfs_fs_sb.h
1083 @@ -450,7 +450,6 @@ enum reiserfs_mount_options {
1084 REISERFS_NO_UNHASHED_RELOCATION,
1085 REISERFS_HASHED_RELOCATION,
1088 REISERFS_XATTRS_USER,
1090 REISERFS_BARRIER_NONE,
1091 @@ -488,7 +487,7 @@ enum reiserfs_mount_options {
1092 #define reiserfs_data_log(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_LOG))
1093 #define reiserfs_data_ordered(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_ORDERED))
1094 #define reiserfs_data_writeback(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_DATA_WRITEBACK))
1095 -#define reiserfs_xattrs(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_XATTRS))
1096 +#define reiserfs_xattrs(s) ((s)->s_xattr != NULL)
1097 #define reiserfs_xattrs_user(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_XATTRS_USER))
1098 #define reiserfs_posixacl(s) (REISERFS_SB(s)->s_mount_opt & (1 << REISERFS_POSIXACL))
1099 #define reiserfs_xattrs_optional(s) (reiserfs_xattrs_user(s) || reiserfs_posixacl(s))
1100 --- a/include/linux/reiserfs_xattr.h
1101 +++ b/include/linux/reiserfs_xattr.h
1102 @@ -29,20 +29,6 @@ struct iattr;
1106 -struct reiserfs_xattr_handler {
1108 - int (*init) (void);
1109 - void (*exit) (void);
1110 - int (*get) (struct inode * inode, const char *name, void *buffer,
1112 - int (*set) (struct inode * inode, const char *name, const void *buffer,
1113 - size_t size, int flags);
1114 - int (*del) (struct inode * inode, const char *name);
1115 - int (*list) (struct inode * inode, const char *name, int namelen,
1117 - struct list_head handlers;
1120 int reiserfs_xattr_register_handlers(void) __init;
1121 void reiserfs_xattr_unregister_handlers(void);
1122 int reiserfs_xattr_init(struct super_block *sb, int mount_flags);
1123 @@ -59,13 +45,14 @@ ssize_t reiserfs_listxattr(struct dentry
1124 int reiserfs_removexattr(struct dentry *dentry, const char *name);
1125 int reiserfs_permission(struct inode *inode, int mask);
1127 -int reiserfs_xattr_del(struct inode *, const char *);
1128 -int reiserfs_xattr_get(const struct inode *, const char *, void *, size_t);
1129 +int reiserfs_xattr_get(struct inode *, const char *, void *, size_t);
1130 +int __reiserfs_xattr_set(struct inode *, const char *, const void *,
1132 int reiserfs_xattr_set(struct inode *, const char *, const void *, size_t, int);
1134 -extern struct reiserfs_xattr_handler user_handler;
1135 -extern struct reiserfs_xattr_handler trusted_handler;
1136 -extern struct reiserfs_xattr_handler security_handler;
1137 +extern struct xattr_handler reiserfs_xattr_user_handler;
1138 +extern struct xattr_handler reiserfs_xattr_trusted_handler;
1139 +extern struct xattr_handler reiserfs_xattr_security_handler;
1141 static inline void reiserfs_init_xattr_rwsem(struct inode *inode)