diff options
author | Phillip Potter <phil@philpotter.co.uk> | 2019-03-26 17:39:34 -0400 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2019-04-29 13:02:29 -0400 |
commit | 7d157c3d4810cfb9ea1bb0977e8e2db02032173a (patch) | |
tree | 144bf4d1aca90cbc1a6a4e8e73a1239c5f4dbc3a | |
parent | 7984ae52bbf75def1d7fcbf4c902e8f787e1ef9d (diff) |
btrfs: use common file type conversion
Deduplicate the btrfs file type conversion implementation - file systems
that use the same file types as defined by POSIX do not need to define
their own versions and can use the common helper functions decared in
fs_types.h and implemented in fs_types.c
Common implementation can be found via commit:
bbe7449e2599 "fs: common implementation of file type"
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Phillip Potter <phil@philpotter.co.uk>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r-- | fs/btrfs/btrfs_inode.h | 2 | ||||
-rw-r--r-- | fs/btrfs/delayed-inode.c | 2 | ||||
-rw-r--r-- | fs/btrfs/inode.c | 32 | ||||
-rw-r--r-- | include/uapi/linux/btrfs_tree.h | 2 |
4 files changed, 18 insertions, 20 deletions
diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index 6f5d07415dab..b16c13d51be0 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h | |||
@@ -203,8 +203,6 @@ struct btrfs_inode { | |||
203 | struct inode vfs_inode; | 203 | struct inode vfs_inode; |
204 | }; | 204 | }; |
205 | 205 | ||
206 | extern unsigned char btrfs_filetype_table[]; | ||
207 | |||
208 | static inline struct btrfs_inode *BTRFS_I(const struct inode *inode) | 206 | static inline struct btrfs_inode *BTRFS_I(const struct inode *inode) |
209 | { | 207 | { |
210 | return container_of(inode, struct btrfs_inode, vfs_inode); | 208 | return container_of(inode, struct btrfs_inode, vfs_inode); |
diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c index c669f250d4a0..e61947f5eb76 100644 --- a/fs/btrfs/delayed-inode.c +++ b/fs/btrfs/delayed-inode.c | |||
@@ -1692,7 +1692,7 @@ int btrfs_readdir_delayed_dir_index(struct dir_context *ctx, | |||
1692 | name = (char *)(di + 1); | 1692 | name = (char *)(di + 1); |
1693 | name_len = btrfs_stack_dir_name_len(di); | 1693 | name_len = btrfs_stack_dir_name_len(di); |
1694 | 1694 | ||
1695 | d_type = btrfs_filetype_table[di->type]; | 1695 | d_type = fs_ftype_to_dtype(di->type); |
1696 | btrfs_disk_key_to_cpu(&location, &di->location); | 1696 | btrfs_disk_key_to_cpu(&location, &di->location); |
1697 | 1697 | ||
1698 | over = !dir_emit(ctx, name, name_len, | 1698 | over = !dir_emit(ctx, name, name_len, |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 4706018d1f9e..1d81a7a78a3f 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -73,17 +73,6 @@ struct kmem_cache *btrfs_trans_handle_cachep; | |||
73 | struct kmem_cache *btrfs_path_cachep; | 73 | struct kmem_cache *btrfs_path_cachep; |
74 | struct kmem_cache *btrfs_free_space_cachep; | 74 | struct kmem_cache *btrfs_free_space_cachep; |
75 | 75 | ||
76 | #define S_SHIFT 12 | ||
77 | static const unsigned char btrfs_type_by_mode[S_IFMT >> S_SHIFT] = { | ||
78 | [S_IFREG >> S_SHIFT] = BTRFS_FT_REG_FILE, | ||
79 | [S_IFDIR >> S_SHIFT] = BTRFS_FT_DIR, | ||
80 | [S_IFCHR >> S_SHIFT] = BTRFS_FT_CHRDEV, | ||
81 | [S_IFBLK >> S_SHIFT] = BTRFS_FT_BLKDEV, | ||
82 | [S_IFIFO >> S_SHIFT] = BTRFS_FT_FIFO, | ||
83 | [S_IFSOCK >> S_SHIFT] = BTRFS_FT_SOCK, | ||
84 | [S_IFLNK >> S_SHIFT] = BTRFS_FT_SYMLINK, | ||
85 | }; | ||
86 | |||
87 | static int btrfs_setsize(struct inode *inode, struct iattr *attr); | 76 | static int btrfs_setsize(struct inode *inode, struct iattr *attr); |
88 | static int btrfs_truncate(struct inode *inode, bool skip_writeback); | 77 | static int btrfs_truncate(struct inode *inode, bool skip_writeback); |
89 | static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent); | 78 | static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent); |
@@ -5797,10 +5786,6 @@ static struct dentry *btrfs_lookup(struct inode *dir, struct dentry *dentry, | |||
5797 | return d_splice_alias(inode, dentry); | 5786 | return d_splice_alias(inode, dentry); |
5798 | } | 5787 | } |
5799 | 5788 | ||
5800 | unsigned char btrfs_filetype_table[] = { | ||
5801 | DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK | ||
5802 | }; | ||
5803 | |||
5804 | /* | 5789 | /* |
5805 | * All this infrastructure exists because dir_emit can fault, and we are holding | 5790 | * All this infrastructure exists because dir_emit can fault, and we are holding |
5806 | * the tree lock when doing readdir. For now just allocate a buffer and copy | 5791 | * the tree lock when doing readdir. For now just allocate a buffer and copy |
@@ -5939,7 +5924,7 @@ again: | |||
5939 | name_ptr = (char *)(entry + 1); | 5924 | name_ptr = (char *)(entry + 1); |
5940 | read_extent_buffer(leaf, name_ptr, (unsigned long)(di + 1), | 5925 | read_extent_buffer(leaf, name_ptr, (unsigned long)(di + 1), |
5941 | name_len); | 5926 | name_len); |
5942 | put_unaligned(btrfs_filetype_table[btrfs_dir_type(leaf, di)], | 5927 | put_unaligned(fs_ftype_to_dtype(btrfs_dir_type(leaf, di)), |
5943 | &entry->type); | 5928 | &entry->type); |
5944 | btrfs_dir_item_key_to_cpu(leaf, di, &location); | 5929 | btrfs_dir_item_key_to_cpu(leaf, di, &location); |
5945 | put_unaligned(location.objectid, &entry->ino); | 5930 | put_unaligned(location.objectid, &entry->ino); |
@@ -6344,7 +6329,20 @@ fail: | |||
6344 | 6329 | ||
6345 | static inline u8 btrfs_inode_type(struct inode *inode) | 6330 | static inline u8 btrfs_inode_type(struct inode *inode) |
6346 | { | 6331 | { |
6347 | return btrfs_type_by_mode[(inode->i_mode & S_IFMT) >> S_SHIFT]; | 6332 | /* |
6333 | * Compile-time asserts that generic FT_* types still match | ||
6334 | * BTRFS_FT_* types | ||
6335 | */ | ||
6336 | BUILD_BUG_ON(BTRFS_FT_UNKNOWN != FT_UNKNOWN); | ||
6337 | BUILD_BUG_ON(BTRFS_FT_REG_FILE != FT_REG_FILE); | ||
6338 | BUILD_BUG_ON(BTRFS_FT_DIR != FT_DIR); | ||
6339 | BUILD_BUG_ON(BTRFS_FT_CHRDEV != FT_CHRDEV); | ||
6340 | BUILD_BUG_ON(BTRFS_FT_BLKDEV != FT_BLKDEV); | ||
6341 | BUILD_BUG_ON(BTRFS_FT_FIFO != FT_FIFO); | ||
6342 | BUILD_BUG_ON(BTRFS_FT_SOCK != FT_SOCK); | ||
6343 | BUILD_BUG_ON(BTRFS_FT_SYMLINK != FT_SYMLINK); | ||
6344 | |||
6345 | return fs_umode_to_ftype(inode->i_mode); | ||
6348 | } | 6346 | } |
6349 | 6347 | ||
6350 | /* | 6348 | /* |
diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h index e974f4bb5378..421239b98db2 100644 --- a/include/uapi/linux/btrfs_tree.h +++ b/include/uapi/linux/btrfs_tree.h | |||
@@ -307,6 +307,8 @@ | |||
307 | * | 307 | * |
308 | * Used by: | 308 | * Used by: |
309 | * struct btrfs_dir_item.type | 309 | * struct btrfs_dir_item.type |
310 | * | ||
311 | * Values 0..7 must match common file type values in fs_types.h. | ||
310 | */ | 312 | */ |
311 | #define BTRFS_FT_UNKNOWN 0 | 313 | #define BTRFS_FT_UNKNOWN 0 |
312 | #define BTRFS_FT_REG_FILE 1 | 314 | #define BTRFS_FT_REG_FILE 1 |