Merge branch 'foreign/liubo/replace-lockup' into for-chris-4.6
[cascardo/linux.git] / fs / btrfs / inode.c
index 8a7c68f..d4381f5 100644 (file)
@@ -3547,10 +3547,10 @@ static noinline int acls_after_inode_item(struct extent_buffer *leaf,
        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++;
@@ -3771,6 +3771,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:
@@ -4211,11 +4212,20 @@ static int truncate_space_check(struct btrfs_trans_handle *trans,
 {
        int ret;
 
+       /*
+        * This is only used to apply pressure to the enospc system, we don't
+        * intend to use this reservation at all.
+        */
        bytes_deleted = btrfs_csum_bytes_to_leaves(root, bytes_deleted);
+       bytes_deleted *= root->nodesize;
        ret = btrfs_block_rsv_add(root, &root->fs_info->trans_block_rsv,
                                  bytes_deleted, BTRFS_RESERVE_NO_FLUSH);
-       if (!ret)
+       if (!ret) {
+               trace_btrfs_space_reservation(root->fs_info, "transaction",
+                                             trans->transid,
+                                             bytes_deleted, 1);
                trans->bytes_reserved += bytes_deleted;
+       }
        return ret;
 
 }
@@ -4899,7 +4909,6 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
        }
 
        if (newsize > oldsize) {
-               truncate_pagecache(inode, newsize);
                /*
                 * Don't do an expanding truncate while snapshoting is ongoing.
                 * This is to ensure the snapshot captures a fully consistent
@@ -4922,6 +4931,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
 
                i_size_write(inode, newsize);
                btrfs_ordered_update_i_size(inode, i_size_read(inode), NULL);
+               pagecache_isize_extended(inode, oldsize, newsize);
                ret = btrfs_update_inode(trans, root, inode);
                btrfs_end_write_no_snapshoting(root);
                btrfs_end_transaction(trans, root);
@@ -5721,6 +5731,7 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx)
        char *name_ptr;
        int name_len;
        int is_curr = 0;        /* ctx->pos points to the current index? */
+       bool emitted;
 
        /* FIXME, use a real flag for deciding about the key type */
        if (root->fs_info->tree_root == root)
@@ -5749,6 +5760,7 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx)
        if (ret < 0)
                goto err;
 
+       emitted = false;
        while (1) {
                leaf = path->nodes[0];
                slot = path->slots[0];
@@ -5792,7 +5804,7 @@ static int btrfs_real_readdir(struct file *file, struct dir_context *ctx)
                        if (name_len <= sizeof(tmp_name)) {
                                name_ptr = tmp_name;
                        } else {
-                               name_ptr = kmalloc(name_len, GFP_NOFS);
+                               name_ptr = kmalloc(name_len, GFP_KERNEL);
                                if (!name_ptr) {
                                        ret = -ENOMEM;
                                        goto err;
@@ -5828,6 +5840,7 @@ skip:
 
                        if (over)
                                goto nopos;
+                       emitted = true;
                        di_len = btrfs_dir_name_len(leaf, di) +
                                 btrfs_dir_data_len(leaf, di) + sizeof(*di);
                        di_cur += di_len;
@@ -5840,11 +5853,20 @@ next:
        if (key_type == BTRFS_DIR_INDEX_KEY) {
                if (is_curr)
                        ctx->pos++;
-               ret = btrfs_readdir_delayed_dir_index(ctx, &ins_list);
+               ret = btrfs_readdir_delayed_dir_index(ctx, &ins_list, &emitted);
                if (ret)
                        goto nopos;
        }
 
+       /*
+        * If we haven't emitted any dir entry, we must not touch ctx->pos as
+        * it was was set to the termination value in previous call. We assume
+        * that "." and ".." were emitted if we reach this point and set the
+        * termination value as well for an empty directory.
+        */
+       if (ctx->pos > 2 && !emitted)
+               goto nopos;
+
        /* Reached end of directory/root. Bump pos past the last item. */
        ctx->pos++;
 
@@ -8532,7 +8554,7 @@ static ssize_t btrfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
                 * not unlock the i_mutex at this case.
                 */
                if (offset + count <= inode->i_size) {
-                       mutex_unlock(&inode->i_mutex);
+                       inode_unlock(inode);
                        relock = true;
                }
                ret = btrfs_delalloc_reserve_space(inode, offset, count);
@@ -8589,7 +8611,7 @@ out:
        if (wakeup)
                inode_dio_end(inode);
        if (relock)
-               mutex_lock(&inode->i_mutex);
+               inode_lock(inode);
 
        return ret;
 }
@@ -9292,7 +9314,8 @@ int btrfs_init_cachep(void)
 {
        btrfs_inode_cachep = kmem_cache_create("btrfs_inode",
                        sizeof(struct btrfs_inode), 0,
-                       SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, init_once);
+                       SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD | SLAB_ACCOUNT,
+                       init_once);
        if (!btrfs_inode_cachep)
                goto fail;
 
@@ -9822,6 +9845,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
        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);
@@ -10118,7 +10142,7 @@ static const struct inode_operations btrfs_dir_inode_operations = {
        .setattr        = btrfs_setattr,
        .mknod          = btrfs_mknod,
        .setxattr       = btrfs_setxattr,
-       .getxattr       = btrfs_getxattr,
+       .getxattr       = generic_getxattr,
        .listxattr      = btrfs_listxattr,
        .removexattr    = btrfs_removexattr,
        .permission     = btrfs_permission,
@@ -10195,7 +10219,7 @@ static const struct inode_operations btrfs_file_inode_operations = {
        .getattr        = btrfs_getattr,
        .setattr        = btrfs_setattr,
        .setxattr       = btrfs_setxattr,
-       .getxattr       = btrfs_getxattr,
+       .getxattr       = generic_getxattr,
        .listxattr      = btrfs_listxattr,
        .removexattr    = btrfs_removexattr,
        .permission     = btrfs_permission,
@@ -10209,7 +10233,7 @@ static const struct inode_operations btrfs_special_inode_operations = {
        .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,
@@ -10218,13 +10242,12 @@ static const struct inode_operations btrfs_special_inode_operations = {
 };
 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,