2022-02-25 16:48:20

by Chao Yu

[permalink] [raw]
Subject: Re: [f2fs-dev] [PATCH -next v2] ext4:fix file system corrupted when rmdir non empty directory with IO error

On 2022/2/25 16:22, yebin via Linux-f2fs-devel wrote:
>> diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
>> index a0e51937d92e..3de5a1343070 100644
>> --- a/fs/f2fs/dir.c
>> +++ b/fs/f2fs/dir.c
>> @@ -953,7 +953,7 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
>>           f2fs_drop_nlink(dir, inode);
>>   }
>> -bool f2fs_empty_dir(struct inode *dir)
>> +int f2fs_empty_dir(struct inode *dir)
>>   {
>>       unsigned long bidx;
>>       struct page *dentry_page;
>> @@ -970,7 +970,7 @@ bool f2fs_empty_dir(struct inode *dir)
>>               if (PTR_ERR(dentry_page) == -ENOENT)
>>                   continue;
>>               else
>> -                return false;
>> +                return PTR_ERR(dentry_page);
>>           }
>>           dentry_blk = page_address(dentry_page);
>> @@ -985,9 +985,9 @@ bool f2fs_empty_dir(struct inode *dir)
>>           f2fs_put_page(dentry_page, 1);
>>           if (bit_pos < NR_DENTRY_IN_BLOCK)
>> -            return false;
>> +            return -ENOTEMPTY;
>>       }
>> -    return true;
>> +    return 0;
>>   }
>>   int f2fs_fill_dentries(struct dir_context *ctx, struct f2fs_dentry_ptr *d,
>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
>> index 5c30a65467e2..09617d7b37fd 100644
>> --- a/fs/f2fs/f2fs.h
>> +++ b/fs/f2fs/f2fs.h
>> @@ -3465,7 +3465,7 @@ int f2fs_do_add_link(struct inode *dir, const struct qstr *name,
>>   void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct page *page,
>>               struct inode *dir, struct inode *inode);
>>   int f2fs_do_tmpfile(struct inode *inode, struct inode *dir);
>> -bool f2fs_empty_dir(struct inode *dir);
>> +int f2fs_empty_dir(struct inode *dir);
>>   static inline int f2fs_add_link(struct dentry *dentry, struct inode *inode)
>>   {
>> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
>> index cfdc41f87f5d..a3b60d6a58f7 100644
>> --- a/fs/f2fs/file.c
>> +++ b/fs/f2fs/file.c
>> @@ -1846,10 +1846,13 @@ static int f2fs_setflags_common(struct inode *inode, u32 iflags, u32 mask)
>>           return -EPERM;
>>       if ((iflags ^ masked_flags) & F2FS_CASEFOLD_FL) {
>> +        int ret;
>> +
>>           if (!f2fs_sb_has_casefold(F2FS_I_SB(inode)))
>>               return -EOPNOTSUPP;
>> -        if (!f2fs_empty_dir(inode))
>> -            return -ENOTEMPTY;
>> +        ret = f2fs_empty_dir(inode);
>> +        if (ret)
>> +            return ret;
>>       }
>>       if (iflags & (F2FS_COMPR_FL | F2FS_NOCOMP_FL)) {
>> diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
>> index 13a0ffc39fa4..e4d1821b707b 100644
>> --- a/fs/f2fs/namei.c
>> +++ b/fs/f2fs/namei.c
>> @@ -786,10 +786,10 @@ static int f2fs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
>>   static int f2fs_rmdir(struct inode *dir, struct dentry *dentry)
>>   {
>>       struct inode *inode = d_inode(dentry);
>> +    int ret;
>> -    if (f2fs_empty_dir(inode))
>> -        return f2fs_unlink(dir, dentry);
>> -    return -ENOTEMPTY;
>> +    ret = f2fs_empty_dir(inode);
>> +    return ret ? : f2fs_unlink(dir, dentry);
>>   }
>>   static int f2fs_mknod(struct user_namespace *mnt_userns, struct inode *dir,
>> @@ -1001,9 +1001,7 @@ static int f2fs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
>>       }
>>       if (new_inode) {
>> -
>> -        err = -ENOTEMPTY;
>> -        if (old_dir_entry && !f2fs_empty_dir(new_inode))
>> +        if (old_dir_entry && (err = f2fs_empty_dir(new_inode)))
>>               goto out_dir;
>>           err = -ENOENT;

Could you please move f2fs part to a separated patch?

Thanks,