Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1485844 > unrolled thread

[PATCH 1/6] f2fs: make f2fs_filetype_table static

Started byChao Yu <chao@kernel.org>
First post2016-09-18 17:40 +0200
Last post2016-09-18 17:40 +0200
Articles 5 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 1/6] f2fs: make f2fs_filetype_table static Chao Yu <chao@kernel.org> - 2016-09-18 17:40 +0200
    [PATCH 3/6] f2fs: fix to avoid race condition when updating sbi flag Chao Yu <chao@kernel.org> - 2016-09-18 17:40 +0200
      Re: [PATCH 3/6] f2fs: fix to avoid race condition when updating sbi  flag Jaegeuk Kim <jaegeuk@kernel.org> - 2016-09-19 23:50 +0200
        Re: [PATCH 3/6] f2fs: fix to avoid race condition when updating sbi  flag Chao Yu <yuchao0@huawei.com> - 2016-09-20 03:50 +0200
    [PATCH 2/6] f2fs: fix to return error number of read_all_xattrs correctly Chao Yu <chao@kernel.org> - 2016-09-18 17:40 +0200

#1485844 — [PATCH 1/6] f2fs: make f2fs_filetype_table static

FromChao Yu <chao@kernel.org>
Date2016-09-18 17:40 +0200
Subject[PATCH 1/6] f2fs: make f2fs_filetype_table static
Message-ID<siMmd-1ol-5@gated-at.bofh.it>
From: Chao Yu <yuchao0@huawei.com>

There is no more user of f2fs_filetype_table outside of dir.c, make it
static.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fs/f2fs/dir.c  | 2 +-
 fs/f2fs/f2fs.h | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 2fb20fc..39a850b 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -37,7 +37,7 @@ static unsigned int bucket_blocks(unsigned int level)
 		return 4;
 }
 
-unsigned char f2fs_filetype_table[F2FS_FT_MAX] = {
+static unsigned char f2fs_filetype_table[F2FS_FT_MAX] = {
 	[F2FS_FT_UNKNOWN]	= DT_UNKNOWN,
 	[F2FS_FT_REG_FILE]	= DT_REG,
 	[F2FS_FT_DIR]		= DT_DIR,
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index af06303..9b4bbf2 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -1946,7 +1946,6 @@ struct dentry *f2fs_get_parent(struct dentry *child);
 /*
  * dir.c
  */
-extern unsigned char f2fs_filetype_table[F2FS_FT_MAX];
 void set_de_type(struct f2fs_dir_entry *, umode_t);
 unsigned char get_de_type(struct f2fs_dir_entry *);
 struct f2fs_dir_entry *find_target_dentry(struct fscrypt_name *,
-- 
2.7.2

[toc] | [next] | [standalone]


#1485845 — [PATCH 3/6] f2fs: fix to avoid race condition when updating sbi flag

FromChao Yu <chao@kernel.org>
Date2016-09-18 17:40 +0200
Subject[PATCH 3/6] f2fs: fix to avoid race condition when updating sbi flag
Message-ID<siMmd-1ol-17@gated-at.bofh.it>
In reply to#1485844
From: Chao Yu <yuchao0@huawei.com>

Making updating of sbi flag atomic by using {test,set,clear}_bit,
otherwise in concurrency scenario, the flag could be updated incorrectly.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fs/f2fs/f2fs.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 9b4bbf2..c30f744b 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -794,7 +794,7 @@ struct f2fs_sb_info {
 	struct proc_dir_entry *s_proc;		/* proc entry */
 	struct f2fs_super_block *raw_super;	/* raw super block pointer */
 	int valid_super_block;			/* valid super block no */
-	int s_flag;				/* flags for sbi */
+	unsigned long s_flag;				/* flags for sbi */
 
 #ifdef CONFIG_F2FS_FS_ENCRYPTION
 	u8 key_prefix[F2FS_KEY_DESC_PREFIX_SIZE];
@@ -1063,17 +1063,19 @@ static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
 
 static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
 {
-	return sbi->s_flag & (0x01 << type);
+	return test_bit(type, &sbi->s_flag);
 }
 
 static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
 {
-	sbi->s_flag |= (0x01 << type);
+	if (!test_bit(type, &sbi->s_flag))
+		set_bit(type, &sbi->s_flag);
 }
 
 static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
 {
-	sbi->s_flag &= ~(0x01 << type);
+	if (test_bit(type, &sbi->s_flag))
+		clear_bit(type, &sbi->s_flag);
 }
 
 static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
-- 
2.7.2

[toc] | [prev] | [next] | [standalone]


#1486902 — Re: [PATCH 3/6] f2fs: fix to avoid race condition when updating sbi flag

FromJaegeuk Kim <jaegeuk@kernel.org>
Date2016-09-19 23:50 +0200
SubjectRe: [PATCH 3/6] f2fs: fix to avoid race condition when updating sbi flag
Message-ID<sjeBP-2xm-13@gated-at.bofh.it>
In reply to#1485845
Hi Chao,

On Sun, Sep 18, 2016 at 11:30:05PM +0800, Chao Yu wrote:
> From: Chao Yu <yuchao0@huawei.com>
> 
> Making updating of sbi flag atomic by using {test,set,clear}_bit,
> otherwise in concurrency scenario, the flag could be updated incorrectly.
> 
> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> ---
>  fs/f2fs/f2fs.h | 10 ++++++----
>  1 file changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
> index 9b4bbf2..c30f744b 100644
> --- a/fs/f2fs/f2fs.h
> +++ b/fs/f2fs/f2fs.h
> @@ -794,7 +794,7 @@ struct f2fs_sb_info {
>  	struct proc_dir_entry *s_proc;		/* proc entry */
>  	struct f2fs_super_block *raw_super;	/* raw super block pointer */
>  	int valid_super_block;			/* valid super block no */
> -	int s_flag;				/* flags for sbi */
> +	unsigned long s_flag;				/* flags for sbi */
>  
>  #ifdef CONFIG_F2FS_FS_ENCRYPTION
>  	u8 key_prefix[F2FS_KEY_DESC_PREFIX_SIZE];
> @@ -1063,17 +1063,19 @@ static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
>  
>  static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
>  {
> -	return sbi->s_flag & (0x01 << type);
> +	return test_bit(type, &sbi->s_flag);
>  }
>  
>  static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
>  {
> -	sbi->s_flag |= (0x01 << type);
> +	if (!test_bit(type, &sbi->s_flag))
> +		set_bit(type, &sbi->s_flag);

The set_bit() is enough, no?

>  }
>  
>  static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
>  {
> -	sbi->s_flag &= ~(0x01 << type);
> +	if (test_bit(type, &sbi->s_flag))
> +		clear_bit(type, &sbi->s_flag);

ditto.

Thanks,

>  }
>  
>  static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
> -- 
> 2.7.2

[toc] | [prev] | [next] | [standalone]


#1487003 — Re: [PATCH 3/6] f2fs: fix to avoid race condition when updating sbi flag

FromChao Yu <yuchao0@huawei.com>
Date2016-09-20 03:50 +0200
SubjectRe: [PATCH 3/6] f2fs: fix to avoid race condition when updating sbi flag
Message-ID<sjim5-4S8-15@gated-at.bofh.it>
In reply to#1486902
Hi Jaegeuk,

On 2016/9/20 5:40, Jaegeuk Kim wrote:
> Hi Chao,
> 
> On Sun, Sep 18, 2016 at 11:30:05PM +0800, Chao Yu wrote:
>> From: Chao Yu <yuchao0@huawei.com>
>>
>> Making updating of sbi flag atomic by using {test,set,clear}_bit,
>> otherwise in concurrency scenario, the flag could be updated incorrectly.
>>
>> Signed-off-by: Chao Yu <yuchao0@huawei.com>
>> ---
>>  fs/f2fs/f2fs.h | 10 ++++++----
>>  1 file changed, 6 insertions(+), 4 deletions(-)
>>
>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>> index 9b4bbf2..c30f744b 100644
>> --- a/fs/f2fs/f2fs.h
>> +++ b/fs/f2fs/f2fs.h
>> @@ -794,7 +794,7 @@ struct f2fs_sb_info {
>>  	struct proc_dir_entry *s_proc;		/* proc entry */
>>  	struct f2fs_super_block *raw_super;	/* raw super block pointer */
>>  	int valid_super_block;			/* valid super block no */
>> -	int s_flag;				/* flags for sbi */
>> +	unsigned long s_flag;				/* flags for sbi */
>>  
>>  #ifdef CONFIG_F2FS_FS_ENCRYPTION
>>  	u8 key_prefix[F2FS_KEY_DESC_PREFIX_SIZE];
>> @@ -1063,17 +1063,19 @@ static inline struct address_space *NODE_MAPPING(struct f2fs_sb_info *sbi)
>>  
>>  static inline bool is_sbi_flag_set(struct f2fs_sb_info *sbi, unsigned int type)
>>  {
>> -	return sbi->s_flag & (0x01 << type);
>> +	return test_bit(type, &sbi->s_flag);
>>  }
>>  
>>  static inline void set_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
>>  {
>> -	sbi->s_flag |= (0x01 << type);
>> +	if (!test_bit(type, &sbi->s_flag))
>> +		set_bit(type, &sbi->s_flag);
> 
> The set_bit() is enough, no?

It seems OK to me, let me send v2.

Thanks,

> 
>>  }
>>  
>>  static inline void clear_sbi_flag(struct f2fs_sb_info *sbi, unsigned int type)
>>  {
>> -	sbi->s_flag &= ~(0x01 << type);
>> +	if (test_bit(type, &sbi->s_flag))
>> +		clear_bit(type, &sbi->s_flag);
> 
> ditto.
> 
> Thanks,
> 
>>  }
>>  
>>  static inline unsigned long long cur_cp_version(struct f2fs_checkpoint *cp)
>> -- 
>> 2.7.2
> 
> .
> 

[toc] | [prev] | [next] | [standalone]


#1485846 — [PATCH 2/6] f2fs: fix to return error number of read_all_xattrs correctly

FromChao Yu <chao@kernel.org>
Date2016-09-18 17:40 +0200
Subject[PATCH 2/6] f2fs: fix to return error number of read_all_xattrs correctly
Message-ID<siMmd-1ol-19@gated-at.bofh.it>
In reply to#1485844
From: Chao Yu <yuchao0@huawei.com>

We treat all error in read_all_xattrs as a no memory error, which covers
the real reason of failure in it. Fix it by return correct errno in order
to reflect the real cause.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fs/f2fs/xattr.c | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c
index 1660191..83234dd 100644
--- a/fs/f2fs/xattr.c
+++ b/fs/f2fs/xattr.c
@@ -217,18 +217,20 @@ static struct f2fs_xattr_entry *__find_xattr(void *base_addr, int index,
 	return entry;
 }
 
-static void *read_all_xattrs(struct inode *inode, struct page *ipage)
+static int read_all_xattrs(struct inode *inode, struct page *ipage,
+							void **base_addr)
 {
 	struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
 	struct f2fs_xattr_header *header;
 	size_t size = PAGE_SIZE, inline_size = 0;
 	void *txattr_addr;
+	int err;
 
 	inline_size = inline_xattr_size(inode);
 
 	txattr_addr = kzalloc(inline_size + size, GFP_F2FS_ZERO);
 	if (!txattr_addr)
-		return NULL;
+		return -ENOMEM;
 
 	/* read from inline xattr */
 	if (inline_size) {
@@ -239,8 +241,10 @@ static void *read_all_xattrs(struct inode *inode, struct page *ipage)
 			inline_addr = inline_xattr_addr(ipage);
 		} else {
 			page = get_node_page(sbi, inode->i_ino);
-			if (IS_ERR(page))
+			if (IS_ERR(page)) {
+				err = PTR_ERR(page);
 				goto fail;
+			}
 			inline_addr = inline_xattr_addr(page);
 		}
 		memcpy(txattr_addr, inline_addr, inline_size);
@@ -254,8 +258,10 @@ static void *read_all_xattrs(struct inode *inode, struct page *ipage)
 
 		/* The inode already has an extended attribute block. */
 		xpage = get_node_page(sbi, F2FS_I(inode)->i_xattr_nid);
-		if (IS_ERR(xpage))
+		if (IS_ERR(xpage)) {
+			err = PTR_ERR(xpage);
 			goto fail;
+		}
 
 		xattr_addr = page_address(xpage);
 		memcpy(txattr_addr + inline_size, xattr_addr, PAGE_SIZE);
@@ -269,10 +275,11 @@ static void *read_all_xattrs(struct inode *inode, struct page *ipage)
 		header->h_magic = cpu_to_le32(F2FS_XATTR_MAGIC);
 		header->h_refcount = cpu_to_le32(1);
 	}
-	return txattr_addr;
+	*base_addr = txattr_addr;
+	return 0;
 fail:
 	kzfree(txattr_addr);
-	return NULL;
+	return err;
 }
 
 static inline int write_all_xattrs(struct inode *inode, __u32 hsize,
@@ -366,9 +373,9 @@ int f2fs_getxattr(struct inode *inode, int index, const char *name,
 	if (len > F2FS_NAME_LEN)
 		return -ERANGE;
 
-	base_addr = read_all_xattrs(inode, ipage);
-	if (!base_addr)
-		return -ENOMEM;
+	error = read_all_xattrs(inode, ipage, &base_addr);
+	if (error)
+		return error;
 
 	entry = __find_xattr(base_addr, index, len, name);
 	if (IS_XATTR_LAST_ENTRY(entry)) {
@@ -402,9 +409,9 @@ ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
 	int error = 0;
 	size_t rest = buffer_size;
 
-	base_addr = read_all_xattrs(inode, NULL);
-	if (!base_addr)
-		return -ENOMEM;
+	error = read_all_xattrs(inode, NULL, &base_addr);
+	if (error)
+		return error;
 
 	list_for_each_xattr(entry, base_addr) {
 		const struct xattr_handler *handler =
@@ -463,9 +470,9 @@ static int __f2fs_setxattr(struct inode *inode, int index,
 	if (size > MAX_VALUE_LEN(inode))
 		return -E2BIG;
 
-	base_addr = read_all_xattrs(inode, ipage);
-	if (!base_addr)
-		return -ENOMEM;
+	error = read_all_xattrs(inode, ipage, &base_addr);
+	if (error)
+		return error;
 
 	/* find entry with wanted name. */
 	here = __find_xattr(base_addr, index, len, name);
-- 
2.7.2

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web