btrfs: pass btrfs_inode to btrfs_inode_lock
[linux-block.git] / fs / btrfs / tree-log.c
index 3f3d10a2dd0e603d71bdeab3dcd4d0820c121016..b6e99ef99679488978e41a75bc899266743209e2 100644 (file)
 #include "inode-item.h"
 #include "fs.h"
 #include "accessors.h"
+#include "extent-tree.h"
+#include "root-tree.h"
+#include "dir-item.h"
+#include "file-item.h"
+#include "file.h"
+#include "orphan.h"
 
 #define MAX_CONFLICT_INODES 10
 
@@ -598,7 +604,7 @@ static int overwrite_item(struct btrfs_trans_handle *trans,
 }
 
 static int read_alloc_one_name(struct extent_buffer *eb, void *start, int len,
-                              struct qstr *name)
+                              struct fscrypt_str *name)
 {
        char *buf;
 
@@ -917,7 +923,7 @@ out:
 static int unlink_inode_for_log_replay(struct btrfs_trans_handle *trans,
                                       struct btrfs_inode *dir,
                                       struct btrfs_inode *inode,
-                                      const struct qstr *name)
+                                      const struct fscrypt_str *name)
 {
        int ret;
 
@@ -948,7 +954,7 @@ static noinline int drop_one_dir_item(struct btrfs_trans_handle *trans,
 {
        struct btrfs_root *root = dir->root;
        struct inode *inode;
-       struct qstr name;
+       struct fscrypt_str name;
        struct extent_buffer *leaf;
        struct btrfs_key location;
        int ret;
@@ -989,7 +995,7 @@ out:
 static noinline int inode_in_dir(struct btrfs_root *root,
                                 struct btrfs_path *path,
                                 u64 dirid, u64 objectid, u64 index,
-                                struct qstr *name)
+                                struct fscrypt_str *name)
 {
        struct btrfs_dir_item *di;
        struct btrfs_key location;
@@ -1036,7 +1042,7 @@ out:
 static noinline int backref_in_log(struct btrfs_root *log,
                                   struct btrfs_key *key,
                                   u64 ref_objectid,
-                                  const struct qstr *name)
+                                  const struct fscrypt_str *name)
 {
        struct btrfs_path *path;
        int ret;
@@ -1072,7 +1078,7 @@ static inline int __add_inode_ref(struct btrfs_trans_handle *trans,
                                  struct btrfs_inode *dir,
                                  struct btrfs_inode *inode,
                                  u64 inode_objectid, u64 parent_objectid,
-                                 u64 ref_index, struct qstr *name)
+                                 u64 ref_index, struct fscrypt_str *name)
 {
        int ret;
        struct extent_buffer *leaf;
@@ -1106,7 +1112,7 @@ again:
                ptr = btrfs_item_ptr_offset(leaf, path->slots[0]);
                ptr_end = ptr + btrfs_item_size(leaf, path->slots[0]);
                while (ptr < ptr_end) {
-                       struct qstr victim_name;
+                       struct fscrypt_str victim_name;
 
                        victim_ref = (struct btrfs_inode_ref *)ptr;
                        ret = read_alloc_one_name(leaf, (victim_ref + 1),
@@ -1156,7 +1162,7 @@ again:
                base = btrfs_item_ptr_offset(leaf, path->slots[0]);
 
                while (cur_offset < item_size) {
-                       struct qstr victim_name;
+                       struct fscrypt_str victim_name;
 
                        extref = (struct btrfs_inode_extref *)(base + cur_offset);
 
@@ -1231,7 +1237,7 @@ next:
 }
 
 static int extref_get_fields(struct extent_buffer *eb, unsigned long ref_ptr,
-                            struct qstr *name, u64 *index,
+                            struct fscrypt_str *name, u64 *index,
                             u64 *parent_objectid)
 {
        struct btrfs_inode_extref *extref;
@@ -1253,7 +1259,7 @@ static int extref_get_fields(struct extent_buffer *eb, unsigned long ref_ptr,
 }
 
 static int ref_get_fields(struct extent_buffer *eb, unsigned long ref_ptr,
-                         struct qstr *name, u64 *index)
+                         struct fscrypt_str *name, u64 *index)
 {
        struct btrfs_inode_ref *ref;
        int ret;
@@ -1305,7 +1311,7 @@ again:
        ref_ptr = btrfs_item_ptr_offset(eb, path->slots[0]);
        ref_end = ref_ptr + btrfs_item_size(eb, path->slots[0]);
        while (ref_ptr < ref_end) {
-               struct qstr name;
+               struct fscrypt_str name;
                u64 parent_id;
 
                if (key->type == BTRFS_INODE_EXTREF_KEY) {
@@ -1373,7 +1379,7 @@ static noinline int add_inode_ref(struct btrfs_trans_handle *trans,
        struct inode *inode = NULL;
        unsigned long ref_ptr;
        unsigned long ref_end;
-       struct qstr name;
+       struct fscrypt_str name;
        int ret;
        int log_ref_ver = 0;
        u64 parent_objectid;
@@ -1767,7 +1773,7 @@ static noinline int link_to_fixup_dir(struct btrfs_trans_handle *trans,
 static noinline int insert_one_name(struct btrfs_trans_handle *trans,
                                    struct btrfs_root *root,
                                    u64 dirid, u64 index,
-                                   const struct qstr *name,
+                                   const struct fscrypt_str *name,
                                    struct btrfs_key *location)
 {
        struct inode *inode;
@@ -1799,7 +1805,7 @@ static int delete_conflicting_dir_entry(struct btrfs_trans_handle *trans,
                                        struct btrfs_path *path,
                                        struct btrfs_dir_item *dst_di,
                                        const struct btrfs_key *log_key,
-                                       u8 log_type,
+                                       u8 log_flags,
                                        bool exists)
 {
        struct btrfs_key found_key;
@@ -1809,7 +1815,7 @@ static int delete_conflicting_dir_entry(struct btrfs_trans_handle *trans,
        if (found_key.objectid == log_key->objectid &&
            found_key.type == log_key->type &&
            found_key.offset == log_key->offset &&
-           btrfs_dir_type(path->nodes[0], dst_di) == log_type)
+           btrfs_dir_flags(path->nodes[0], dst_di) == log_flags)
                return 1;
 
        /*
@@ -1845,7 +1851,7 @@ static noinline int replay_one_name(struct btrfs_trans_handle *trans,
                                    struct btrfs_dir_item *di,
                                    struct btrfs_key *key)
 {
-       struct qstr name;
+       struct fscrypt_str name;
        struct btrfs_dir_item *dir_dst_di;
        struct btrfs_dir_item *index_dst_di;
        bool dir_dst_matches = false;
@@ -1853,7 +1859,7 @@ static noinline int replay_one_name(struct btrfs_trans_handle *trans,
        struct btrfs_key log_key;
        struct btrfs_key search_key;
        struct inode *dir;
-       u8 log_type;
+       u8 log_flags;
        bool exists;
        int ret;
        bool update_size = true;
@@ -1867,7 +1873,7 @@ static noinline int replay_one_name(struct btrfs_trans_handle *trans,
        if (ret)
                goto out;
 
-       log_type = btrfs_dir_type(eb, di);
+       log_flags = btrfs_dir_flags(eb, di);
        btrfs_dir_item_key_to_cpu(eb, di, &log_key);
        ret = btrfs_lookup_inode(trans, root, path, &log_key, 0);
        btrfs_release_path(path);
@@ -1883,8 +1889,8 @@ static noinline int replay_one_name(struct btrfs_trans_handle *trans,
                goto out;
        } else if (dir_dst_di) {
                ret = delete_conflicting_dir_entry(trans, BTRFS_I(dir), path,
-                                                  dir_dst_di, &log_key, log_type,
-                                                  exists);
+                                                  dir_dst_di, &log_key,
+                                                  log_flags, exists);
                if (ret < 0)
                        goto out;
                dir_dst_matches = (ret == 1);
@@ -1901,7 +1907,7 @@ static noinline int replay_one_name(struct btrfs_trans_handle *trans,
        } else if (index_dst_di) {
                ret = delete_conflicting_dir_entry(trans, BTRFS_I(dir), path,
                                                   index_dst_di, &log_key,
-                                                  log_type, exists);
+                                                  log_flags, exists);
                if (ret < 0)
                        goto out;
                index_dst_matches = (ret == 1);
@@ -2010,7 +2016,7 @@ static noinline int replay_one_dir_item(struct btrfs_trans_handle *trans,
         * to ever delete the parent directory has it would result in stale
         * dentries that can never be deleted.
         */
-       if (ret == 1 && btrfs_dir_type(eb, di) != BTRFS_FT_DIR) {
+       if (ret == 1 && btrfs_dir_ftype(eb, di) != BTRFS_FT_DIR) {
                struct btrfs_path *fixup_path;
                struct btrfs_key di_key;
 
@@ -2125,7 +2131,7 @@ static noinline int check_item_in_log(struct btrfs_trans_handle *trans,
        struct extent_buffer *eb;
        int slot;
        struct btrfs_dir_item *di;
-       struct qstr name;
+       struct fscrypt_str name;
        struct inode *inode = NULL;
        struct btrfs_key location;
 
@@ -3423,7 +3429,7 @@ static int del_logged_dentry(struct btrfs_trans_handle *trans,
                             struct btrfs_root *log,
                             struct btrfs_path *path,
                             u64 dir_ino,
-                            const struct qstr *name,
+                            const struct fscrypt_str *name,
                             u64 index)
 {
        struct btrfs_dir_item *di;
@@ -3470,7 +3476,7 @@ static int del_logged_dentry(struct btrfs_trans_handle *trans,
  */
 void btrfs_del_dir_entries_in_log(struct btrfs_trans_handle *trans,
                                  struct btrfs_root *root,
-                                 const struct qstr *name,
+                                 const struct fscrypt_str *name,
                                  struct btrfs_inode *dir, u64 index)
 {
        struct btrfs_path *path;
@@ -3509,7 +3515,7 @@ out_unlock:
 /* see comments for btrfs_del_dir_entries_in_log */
 void btrfs_del_inode_ref_in_log(struct btrfs_trans_handle *trans,
                                struct btrfs_root *root,
-                               const struct qstr *name,
+                               const struct fscrypt_str *name,
                                struct btrfs_inode *inode, u64 dirid)
 {
        struct btrfs_root *log;
@@ -5244,7 +5250,7 @@ static int btrfs_check_ref_name_override(struct extent_buffer *eb,
                u32 this_len;
                unsigned long name_ptr;
                struct btrfs_dir_item *di;
-               struct qstr name_str;
+               struct fscrypt_str name_str;
 
                if (key->type == BTRFS_INODE_REF_KEY) {
                        struct btrfs_inode_ref *iref;
@@ -5452,7 +5458,7 @@ again:
                        }
 
                        di = btrfs_item_ptr(leaf, i, struct btrfs_dir_item);
-                       type = btrfs_dir_type(leaf, di);
+                       type = btrfs_dir_ftype(leaf, di);
                        if (btrfs_dir_transid(leaf, di) < trans->transid)
                                continue;
                        btrfs_dir_item_key_to_cpu(leaf, di, &di_key);
@@ -6292,7 +6298,7 @@ static int log_new_delayed_dentries(struct btrfs_trans_handle *trans,
                        continue;
                }
 
-               if (btrfs_stack_dir_type(dir_item) == BTRFS_FT_DIR)
+               if (btrfs_stack_dir_ftype(dir_item) == BTRFS_FT_DIR)
                        log_mode = LOG_INODE_ALL;
 
                ctx->log_new_dentries = false;
@@ -7379,7 +7385,7 @@ void btrfs_record_snapshot_destroy(struct btrfs_trans_handle *trans,
        mutex_unlock(&dir->log_mutex);
 }
 
-/**
+/*
  * Update the log after adding a new name for an inode.
  *
  * @trans:              Transaction handle.
@@ -7447,7 +7453,6 @@ void btrfs_log_new_name(struct btrfs_trans_handle *trans,
                struct btrfs_root *log = old_dir->root->log_root;
                struct btrfs_path *path;
                struct fscrypt_name fname;
-               struct qstr name;
 
                ASSERT(old_dir_index >= BTRFS_DIR_START_INDEX);
 
@@ -7455,7 +7460,6 @@ void btrfs_log_new_name(struct btrfs_trans_handle *trans,
                                             &old_dentry->d_name, 0, &fname);
                if (ret)
                        goto out;
-               name = (struct qstr)FSTR_TO_QSTR(&fname.disk_name);
                /*
                 * We have two inodes to update in the log, the old directory and
                 * the inode that got renamed, so we must pin the log to prevent
@@ -7491,7 +7495,7 @@ void btrfs_log_new_name(struct btrfs_trans_handle *trans,
                 */
                mutex_lock(&old_dir->log_mutex);
                ret = del_logged_dentry(trans, log, path, btrfs_ino(old_dir),
-                                       &name, old_dir_index);
+                                       &fname.disk_name, old_dir_index);
                if (ret > 0) {
                        /*
                         * The dentry does not exist in the log, so record its