]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
Merge branch 'work.xattr' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 11 Jan 2016 21:32:10 +0000 (13:32 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 11 Jan 2016 21:32:10 +0000 (13:32 -0800)
Pull vfs xattr updates from Al Viro:
 "Andreas' xattr cleanup series.

  It's a followup to his xattr work that went in last cycle; -0.5KLoC"

* 'work.xattr' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  xattr handlers: Simplify list operation
  ocfs2: Replace list xattr handler operations
  nfs: Move call to security_inode_listsecurity into nfs_listxattr
  xfs: Change how listxattr generates synthetic attributes
  tmpfs: listxattr should include POSIX ACL xattrs
  tmpfs: Use xattr handler infrastructure
  btrfs: Use xattr handler infrastructure
  vfs: Distinguish between full xattr names and proper prefixes
  posix acls: Remove duplicate xattr name definitions
  gfs2: Remove gfs2_xattr_acl_chmod
  vfs: Remove vfs_xattr_cmp

1  2 
fs/btrfs/inode.c
mm/shmem.c

diff --combined fs/btrfs/inode.c
index 1a41a65fd2ff8ebaa94df0182963769373bbb6b6,4fb8d6e28b2152310c399e250e9bec681b691622..3b8856e182ae7b7ee0d6ee4c32454cfc9bffdc3a
@@@ -3550,10 -3550,10 +3550,10 @@@ static noinline int acls_after_inode_it
        int scanned = 0;
  
        if (!xattr_access) {
-               xattr_access = btrfs_name_hash(POSIX_ACL_XATTR_ACCESS,
-                                       strlen(POSIX_ACL_XATTR_ACCESS));
-               xattr_default = btrfs_name_hash(POSIX_ACL_XATTR_DEFAULT,
-                                       strlen(POSIX_ACL_XATTR_DEFAULT));
+               xattr_access = btrfs_name_hash(XATTR_NAME_POSIX_ACL_ACCESS,
+                                       strlen(XATTR_NAME_POSIX_ACL_ACCESS));
+               xattr_default = btrfs_name_hash(XATTR_NAME_POSIX_ACL_DEFAULT,
+                                       strlen(XATTR_NAME_POSIX_ACL_DEFAULT));
        }
  
        slot++;
@@@ -3774,7 -3774,6 +3774,7 @@@ cache_acl
                break;
        case S_IFLNK:
                inode->i_op = &btrfs_symlink_inode_operations;
 +              inode_nohighmem(inode);
                inode->i_mapping->a_ops = &btrfs_symlink_aops;
                break;
        default:
@@@ -9706,7 -9705,6 +9706,7 @@@ static int btrfs_symlink(struct inode *
        btrfs_free_path(path);
  
        inode->i_op = &btrfs_symlink_inode_operations;
 +      inode_nohighmem(inode);
        inode->i_mapping->a_ops = &btrfs_symlink_aops;
        inode_set_bytes(inode, name_len);
        btrfs_i_size_write(inode, name_len);
@@@ -9996,7 -9994,7 +9996,7 @@@ static const struct inode_operations bt
        .setattr        = btrfs_setattr,
        .mknod          = btrfs_mknod,
        .setxattr       = btrfs_setxattr,
-       .getxattr       = btrfs_getxattr,
+       .getxattr       = generic_getxattr,
        .listxattr      = btrfs_listxattr,
        .removexattr    = btrfs_removexattr,
        .permission     = btrfs_permission,
@@@ -10073,7 -10071,7 +10073,7 @@@ static const struct inode_operations bt
        .getattr        = btrfs_getattr,
        .setattr        = btrfs_setattr,
        .setxattr       = btrfs_setxattr,
-       .getxattr       = btrfs_getxattr,
+       .getxattr       = generic_getxattr,
        .listxattr      = btrfs_listxattr,
        .removexattr    = btrfs_removexattr,
        .permission     = btrfs_permission,
@@@ -10087,7 -10085,7 +10087,7 @@@ static const struct inode_operations bt
        .setattr        = btrfs_setattr,
        .permission     = btrfs_permission,
        .setxattr       = btrfs_setxattr,
-       .getxattr       = btrfs_getxattr,
+       .getxattr       = generic_getxattr,
        .listxattr      = btrfs_listxattr,
        .removexattr    = btrfs_removexattr,
        .get_acl        = btrfs_get_acl,
  };
  static const struct inode_operations btrfs_symlink_inode_operations = {
        .readlink       = generic_readlink,
 -      .follow_link    = page_follow_link_light,
 -      .put_link       = page_put_link,
 +      .get_link       = page_get_link,
        .getattr        = btrfs_getattr,
        .setattr        = btrfs_setattr,
        .permission     = btrfs_permission,
        .setxattr       = btrfs_setxattr,
-       .getxattr       = btrfs_getxattr,
+       .getxattr       = generic_getxattr,
        .listxattr      = btrfs_listxattr,
        .removexattr    = btrfs_removexattr,
        .update_time    = btrfs_update_time,
diff --combined mm/shmem.c
index d00c92fad48f4dfdf600f9f0d54bd9dbd814b14b,297390f4e50ffee8068a3adc585925ea4ef08d63..5813b7fa85b64667c7ea7f9c73da84e073b6d325
@@@ -843,14 -843,14 +843,14 @@@ static int shmem_writepage(struct page 
                list_add_tail(&info->swaplist, &shmem_swaplist);
  
        if (add_to_swap_cache(page, swap, GFP_ATOMIC) == 0) {
 -              swap_shmem_alloc(swap);
 -              shmem_delete_from_page_cache(page, swp_to_radix_entry(swap));
 -
                spin_lock(&info->lock);
 -              info->swapped++;
                shmem_recalc_inode(inode);
 +              info->swapped++;
                spin_unlock(&info->lock);
  
 +              swap_shmem_alloc(swap);
 +              shmem_delete_from_page_cache(page, swp_to_radix_entry(swap));
 +
                mutex_unlock(&shmem_swaplist_mutex);
                BUG_ON(page_mapped(page));
                swap_writepage(page, wbc);
@@@ -1078,7 -1078,7 +1078,7 @@@ repeat
        if (sgp != SGP_WRITE && sgp != SGP_FALLOC &&
            ((loff_t)index << PAGE_CACHE_SHIFT) >= i_size_read(inode)) {
                error = -EINVAL;
 -              goto failed;
 +              goto unlock;
        }
  
        if (page && sgp == SGP_WRITE)
@@@ -1246,15 -1246,11 +1246,15 @@@ clear
        /* Perhaps the file has been truncated since we checked */
        if (sgp != SGP_WRITE && sgp != SGP_FALLOC &&
            ((loff_t)index << PAGE_CACHE_SHIFT) >= i_size_read(inode)) {
 +              if (alloced) {
 +                      ClearPageDirty(page);
 +                      delete_from_page_cache(page);
 +                      spin_lock(&info->lock);
 +                      shmem_recalc_inode(inode);
 +                      spin_unlock(&info->lock);
 +              }
                error = -EINVAL;
 -              if (alloced)
 -                      goto trunc;
 -              else
 -                      goto failed;
 +              goto unlock;
        }
        *pagep = page;
        return 0;
        /*
         * Error recovery.
         */
 -trunc:
 -      info = SHMEM_I(inode);
 -      ClearPageDirty(page);
 -      delete_from_page_cache(page);
 -      spin_lock(&info->lock);
 -      info->alloced--;
 -      inode->i_blocks -= BLOCKS_PER_PAGE;
 -      spin_unlock(&info->lock);
  decused:
 -      sbinfo = SHMEM_SB(inode->i_sb);
        if (sbinfo->max_blocks)
                percpu_counter_add(&sbinfo->used_blocks, -1);
  unacct:
        shmem_unacct_blocks(info->flags, 1);
  failed:
 -      if (swap.val && error != -EINVAL &&
 -          !shmem_confirm_swap(mapping, index, swap))
 +      if (swap.val && !shmem_confirm_swap(mapping, index, swap))
                error = -EEXIST;
  unlock:
        if (page) {
@@@ -2438,6 -2444,7 +2438,6 @@@ static int shmem_symlink(struct inode *
        int len;
        struct inode *inode;
        struct page *page;
 -      char *kaddr;
        struct shmem_inode_info *info;
  
        len = strlen(symname) + 1;
                }
                inode->i_mapping->a_ops = &shmem_aops;
                inode->i_op = &shmem_symlink_inode_operations;
 -              kaddr = kmap_atomic(page);
 -              memcpy(kaddr, symname, len);
 -              kunmap_atomic(kaddr);
 +              inode_nohighmem(inode);
 +              memcpy(page_address(page), symname, len);
                SetPageUptodate(page);
                set_page_dirty(page);
                unlock_page(page);
        return 0;
  }
  
 -static const char *shmem_follow_link(struct dentry *dentry, void **cookie)
 +static void shmem_put_link(void *arg)
  {
 -      struct page *page = NULL;
 -      int error = shmem_getpage(d_inode(dentry), 0, &page, SGP_READ, NULL);
 -      if (error)
 -              return ERR_PTR(error);
 -      unlock_page(page);
 -      *cookie = page;
 -      return kmap(page);
 +      mark_page_accessed(arg);
 +      put_page(arg);
  }
  
 -static void shmem_put_link(struct inode *unused, void *cookie)
 +static const char *shmem_get_link(struct dentry *dentry,
 +                                struct inode *inode,
 +                                struct delayed_call *done)
  {
 -      struct page *page = cookie;
 -      kunmap(page);
 -      mark_page_accessed(page);
 -      page_cache_release(page);
 +      struct page *page = NULL;
 +      int error;
 +      if (!dentry) {
 +              page = find_get_page(inode->i_mapping, 0);
 +              if (!page)
 +                      return ERR_PTR(-ECHILD);
 +              if (!PageUptodate(page)) {
 +                      put_page(page);
 +                      return ERR_PTR(-ECHILD);
 +              }
 +      } else {
 +              error = shmem_getpage(inode, 0, &page, SGP_READ, NULL);
 +              if (error)
 +                      return ERR_PTR(error);
 +              unlock_page(page);
 +      }
 +      set_delayed_call(done, shmem_put_link, page);
 +      return page_address(page);
  }
  
  #ifdef CONFIG_TMPFS_XATTR
@@@ -2564,121 -2561,75 +2564,74 @@@ static int shmem_initxattrs(struct inod
        return 0;
  }
  
- static const struct xattr_handler *shmem_xattr_handlers[] = {
- #ifdef CONFIG_TMPFS_POSIX_ACL
-       &posix_acl_access_xattr_handler,
-       &posix_acl_default_xattr_handler,
- #endif
-       NULL
- };
- static int shmem_xattr_validate(const char *name)
- {
-       struct { const char *prefix; size_t len; } arr[] = {
-               { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
-               { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
-       };
-       int i;
-       for (i = 0; i < ARRAY_SIZE(arr); i++) {
-               size_t preflen = arr[i].len;
-               if (strncmp(name, arr[i].prefix, preflen) == 0) {
-                       if (!name[preflen])
-                               return -EINVAL;
-                       return 0;
-               }
-       }
-       return -EOPNOTSUPP;
- }
- static ssize_t shmem_getxattr(struct dentry *dentry, const char *name,
-                             void *buffer, size_t size)
+ static int shmem_xattr_handler_get(const struct xattr_handler *handler,
+                                  struct dentry *dentry, const char *name,
+                                  void *buffer, size_t size)
  {
        struct shmem_inode_info *info = SHMEM_I(d_inode(dentry));
-       int err;
-       /*
-        * If this is a request for a synthetic attribute in the system.*
-        * namespace use the generic infrastructure to resolve a handler
-        * for it via sb->s_xattr.
-        */
-       if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
-               return generic_getxattr(dentry, name, buffer, size);
-       err = shmem_xattr_validate(name);
-       if (err)
-               return err;
  
+       name = xattr_full_name(handler, name);
        return simple_xattr_get(&info->xattrs, name, buffer, size);
  }
  
- static int shmem_setxattr(struct dentry *dentry, const char *name,
-                         const void *value, size_t size, int flags)
+ static int shmem_xattr_handler_set(const struct xattr_handler *handler,
+                                  struct dentry *dentry, const char *name,
+                                  const void *value, size_t size, int flags)
  {
        struct shmem_inode_info *info = SHMEM_I(d_inode(dentry));
-       int err;
-       /*
-        * If this is a request for a synthetic attribute in the system.*
-        * namespace use the generic infrastructure to resolve a handler
-        * for it via sb->s_xattr.
-        */
-       if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
-               return generic_setxattr(dentry, name, value, size, flags);
-       err = shmem_xattr_validate(name);
-       if (err)
-               return err;
  
+       name = xattr_full_name(handler, name);
        return simple_xattr_set(&info->xattrs, name, value, size, flags);
  }
  
- static int shmem_removexattr(struct dentry *dentry, const char *name)
- {
-       struct shmem_inode_info *info = SHMEM_I(d_inode(dentry));
-       int err;
-       /*
-        * If this is a request for a synthetic attribute in the system.*
-        * namespace use the generic infrastructure to resolve a handler
-        * for it via sb->s_xattr.
-        */
-       if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
-               return generic_removexattr(dentry, name);
+ static const struct xattr_handler shmem_security_xattr_handler = {
+       .prefix = XATTR_SECURITY_PREFIX,
+       .get = shmem_xattr_handler_get,
+       .set = shmem_xattr_handler_set,
+ };
  
-       err = shmem_xattr_validate(name);
-       if (err)
-               return err;
+ static const struct xattr_handler shmem_trusted_xattr_handler = {
+       .prefix = XATTR_TRUSTED_PREFIX,
+       .get = shmem_xattr_handler_get,
+       .set = shmem_xattr_handler_set,
+ };
  
-       return simple_xattr_remove(&info->xattrs, name);
- }
+ static const struct xattr_handler *shmem_xattr_handlers[] = {
+ #ifdef CONFIG_TMPFS_POSIX_ACL
+       &posix_acl_access_xattr_handler,
+       &posix_acl_default_xattr_handler,
+ #endif
+       &shmem_security_xattr_handler,
+       &shmem_trusted_xattr_handler,
+       NULL
+ };
  
  static ssize_t shmem_listxattr(struct dentry *dentry, char *buffer, size_t size)
  {
        struct shmem_inode_info *info = SHMEM_I(d_inode(dentry));
-       return simple_xattr_list(&info->xattrs, buffer, size);
+       return simple_xattr_list(d_inode(dentry), &info->xattrs, buffer, size);
  }
  #endif /* CONFIG_TMPFS_XATTR */
  
  static const struct inode_operations shmem_short_symlink_operations = {
        .readlink       = generic_readlink,
 -      .follow_link    = simple_follow_link,
 +      .get_link       = simple_get_link,
  #ifdef CONFIG_TMPFS_XATTR
-       .setxattr       = shmem_setxattr,
-       .getxattr       = shmem_getxattr,
+       .setxattr       = generic_setxattr,
+       .getxattr       = generic_getxattr,
        .listxattr      = shmem_listxattr,
-       .removexattr    = shmem_removexattr,
+       .removexattr    = generic_removexattr,
  #endif
  };
  
  static const struct inode_operations shmem_symlink_inode_operations = {
        .readlink       = generic_readlink,
 -      .follow_link    = shmem_follow_link,
 -      .put_link       = shmem_put_link,
 +      .get_link       = shmem_get_link,
  #ifdef CONFIG_TMPFS_XATTR
-       .setxattr       = shmem_setxattr,
-       .getxattr       = shmem_getxattr,
+       .setxattr       = generic_setxattr,
+       .getxattr       = generic_getxattr,
        .listxattr      = shmem_listxattr,
-       .removexattr    = shmem_removexattr,
+       .removexattr    = generic_removexattr,
  #endif
  };
  
@@@ -3150,10 -3101,10 +3103,10 @@@ static const struct inode_operations sh
        .getattr        = shmem_getattr,
        .setattr        = shmem_setattr,
  #ifdef CONFIG_TMPFS_XATTR
-       .setxattr       = shmem_setxattr,
-       .getxattr       = shmem_getxattr,
+       .setxattr       = generic_setxattr,
+       .getxattr       = generic_getxattr,
        .listxattr      = shmem_listxattr,
-       .removexattr    = shmem_removexattr,
+       .removexattr    = generic_removexattr,
        .set_acl        = simple_set_acl,
  #endif
  };
@@@ -3172,10 -3123,10 +3125,10 @@@ static const struct inode_operations sh
        .tmpfile        = shmem_tmpfile,
  #endif
  #ifdef CONFIG_TMPFS_XATTR
-       .setxattr       = shmem_setxattr,
-       .getxattr       = shmem_getxattr,
+       .setxattr       = generic_setxattr,
+       .getxattr       = generic_getxattr,
        .listxattr      = shmem_listxattr,
-       .removexattr    = shmem_removexattr,
+       .removexattr    = generic_removexattr,
  #endif
  #ifdef CONFIG_TMPFS_POSIX_ACL
        .setattr        = shmem_setattr,
  
  static const struct inode_operations shmem_special_inode_operations = {
  #ifdef CONFIG_TMPFS_XATTR
-       .setxattr       = shmem_setxattr,
-       .getxattr       = shmem_getxattr,
+       .setxattr       = generic_setxattr,
+       .getxattr       = generic_getxattr,
        .listxattr      = shmem_listxattr,
-       .removexattr    = shmem_removexattr,
+       .removexattr    = generic_removexattr,
  #endif
  #ifdef CONFIG_TMPFS_POSIX_ACL
        .setattr        = shmem_setattr,