* [PATCH 1/2] f2fs: use err for f2fs_preallocate_blocks
@ 2016-11-12 1:30 ` Jaegeuk Kim
0 siblings, 0 replies; 7+ messages in thread
From: Jaegeuk Kim @ 2016-11-12 1:30 UTC (permalink / raw)
To: linux-kernel, linux-fsdevel, linux-f2fs-devel; +Cc: Jaegeuk Kim
This patch has no functional change.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fs/f2fs/data.c | 26 +++++++++++++-------------
fs/f2fs/f2fs.h | 2 +-
fs/f2fs/file.c | 35 +++++++++++++++++++----------------
3 files changed, 33 insertions(+), 30 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 861173f..2938311 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -658,11 +658,11 @@ static int __allocate_data_block(struct dnode_of_data *dn)
return 0;
}
-ssize_t f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
+int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
{
struct inode *inode = file_inode(iocb->ki_filp);
struct f2fs_map_blocks map;
- ssize_t ret = 0;
+ int err = 0;
map.m_lblk = F2FS_BLK_ALIGN(iocb->ki_pos);
map.m_len = F2FS_BYTES_TO_BLK(iocb->ki_pos + iov_iter_count(from));
@@ -674,19 +674,19 @@ ssize_t f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
map.m_next_pgofs = NULL;
if (iocb->ki_flags & IOCB_DIRECT) {
- ret = f2fs_convert_inline_inode(inode);
- if (ret)
- return ret;
+ err = f2fs_convert_inline_inode(inode);
+ if (err)
+ return err;
return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO);
}
if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA) {
- ret = f2fs_convert_inline_inode(inode);
- if (ret)
- return ret;
+ err = f2fs_convert_inline_inode(inode);
+ if (err)
+ return err;
}
if (!f2fs_has_inline_data(inode))
return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO);
- return ret;
+ return err;
}
/*
@@ -863,19 +863,19 @@ static int __get_data_block(struct inode *inode, sector_t iblock,
pgoff_t *next_pgofs)
{
struct f2fs_map_blocks map;
- int ret;
+ int err;
map.m_lblk = iblock;
map.m_len = bh->b_size >> inode->i_blkbits;
map.m_next_pgofs = next_pgofs;
- ret = f2fs_map_blocks(inode, &map, create, flag);
- if (!ret) {
+ err = f2fs_map_blocks(inode, &map, create, flag);
+ if (!err) {
map_bh(bh, inode->i_sb, map.m_pblk);
bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS) | map.m_flags;
bh->b_size = map.m_len << inode->i_blkbits;
}
- return ret;
+ return err;
}
static int get_data_block(struct inode *inode, sector_t iblock,
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 96221b1..a1dcc60 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -2160,7 +2160,7 @@ void f2fs_update_data_blkaddr(struct dnode_of_data *, block_t);
int reserve_new_blocks(struct dnode_of_data *, blkcnt_t);
int reserve_new_block(struct dnode_of_data *);
int f2fs_get_block(struct dnode_of_data *, pgoff_t);
-ssize_t f2fs_preallocate_blocks(struct kiocb *, struct iov_iter *);
+int f2fs_preallocate_blocks(struct kiocb *, struct iov_iter *);
int f2fs_reserve_block(struct dnode_of_data *, pgoff_t);
struct page *get_read_data_page(struct inode *, pgoff_t, int, bool);
struct page *find_data_page(struct inode *, pgoff_t);
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 80eb6a1..6811d4c 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1320,15 +1320,15 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
pgoff_t pg_end;
loff_t new_size = i_size_read(inode);
loff_t off_end;
- int ret;
+ int err;
- ret = inode_newsize_ok(inode, (len + offset));
- if (ret)
- return ret;
+ err = inode_newsize_ok(inode, (len + offset));
+ if (err)
+ return err;
- ret = f2fs_convert_inline_inode(inode);
- if (ret)
- return ret;
+ err = f2fs_convert_inline_inode(inode);
+ if (err)
+ return err;
f2fs_balance_fs(sbi, true);
@@ -1340,12 +1340,12 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
if (off_end)
map.m_len++;
- ret = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO);
- if (ret) {
+ err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO);
+ if (err) {
pgoff_t last_off;
if (!map.m_len)
- return ret;
+ return err;
last_off = map.m_lblk + map.m_len - 1;
@@ -1359,7 +1359,7 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
if (!(mode & FALLOC_FL_KEEP_SIZE) && i_size_read(inode) < new_size)
f2fs_i_size_write(inode, new_size);
- return ret;
+ return err;
}
static long f2fs_fallocate(struct file *file, int mode,
@@ -2263,12 +2263,15 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
inode_lock(inode);
ret = generic_write_checks(iocb, from);
if (ret > 0) {
- ret = f2fs_preallocate_blocks(iocb, from);
- if (!ret) {
- blk_start_plug(&plug);
- ret = __generic_file_write_iter(iocb, from);
- blk_finish_plug(&plug);
+ int err = f2fs_preallocate_blocks(iocb, from);
+
+ if (err) {
+ inode_unlock(inode);
+ return err;
}
+ blk_start_plug(&plug);
+ ret = __generic_file_write_iter(iocb, from);
+ blk_finish_plug(&plug);
}
inode_unlock(inode);
--
2.8.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 1/2] f2fs: use err for f2fs_preallocate_blocks
@ 2016-11-12 1:30 ` Jaegeuk Kim
0 siblings, 0 replies; 7+ messages in thread
From: Jaegeuk Kim @ 2016-11-12 1:30 UTC (permalink / raw)
To: linux-kernel, linux-fsdevel, linux-f2fs-devel; +Cc: Jaegeuk Kim
This patch has no functional change.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fs/f2fs/data.c | 26 +++++++++++++-------------
fs/f2fs/f2fs.h | 2 +-
fs/f2fs/file.c | 35 +++++++++++++++++++----------------
3 files changed, 33 insertions(+), 30 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 861173f..2938311 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -658,11 +658,11 @@ static int __allocate_data_block(struct dnode_of_data *dn)
return 0;
}
-ssize_t f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
+int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
{
struct inode *inode = file_inode(iocb->ki_filp);
struct f2fs_map_blocks map;
- ssize_t ret = 0;
+ int err = 0;
map.m_lblk = F2FS_BLK_ALIGN(iocb->ki_pos);
map.m_len = F2FS_BYTES_TO_BLK(iocb->ki_pos + iov_iter_count(from));
@@ -674,19 +674,19 @@ ssize_t f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
map.m_next_pgofs = NULL;
if (iocb->ki_flags & IOCB_DIRECT) {
- ret = f2fs_convert_inline_inode(inode);
- if (ret)
- return ret;
+ err = f2fs_convert_inline_inode(inode);
+ if (err)
+ return err;
return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO);
}
if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA) {
- ret = f2fs_convert_inline_inode(inode);
- if (ret)
- return ret;
+ err = f2fs_convert_inline_inode(inode);
+ if (err)
+ return err;
}
if (!f2fs_has_inline_data(inode))
return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO);
- return ret;
+ return err;
}
/*
@@ -863,19 +863,19 @@ static int __get_data_block(struct inode *inode, sector_t iblock,
pgoff_t *next_pgofs)
{
struct f2fs_map_blocks map;
- int ret;
+ int err;
map.m_lblk = iblock;
map.m_len = bh->b_size >> inode->i_blkbits;
map.m_next_pgofs = next_pgofs;
- ret = f2fs_map_blocks(inode, &map, create, flag);
- if (!ret) {
+ err = f2fs_map_blocks(inode, &map, create, flag);
+ if (!err) {
map_bh(bh, inode->i_sb, map.m_pblk);
bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS) | map.m_flags;
bh->b_size = map.m_len << inode->i_blkbits;
}
- return ret;
+ return err;
}
static int get_data_block(struct inode *inode, sector_t iblock,
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index 96221b1..a1dcc60 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -2160,7 +2160,7 @@ void f2fs_update_data_blkaddr(struct dnode_of_data *, block_t);
int reserve_new_blocks(struct dnode_of_data *, blkcnt_t);
int reserve_new_block(struct dnode_of_data *);
int f2fs_get_block(struct dnode_of_data *, pgoff_t);
-ssize_t f2fs_preallocate_blocks(struct kiocb *, struct iov_iter *);
+int f2fs_preallocate_blocks(struct kiocb *, struct iov_iter *);
int f2fs_reserve_block(struct dnode_of_data *, pgoff_t);
struct page *get_read_data_page(struct inode *, pgoff_t, int, bool);
struct page *find_data_page(struct inode *, pgoff_t);
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 80eb6a1..6811d4c 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -1320,15 +1320,15 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
pgoff_t pg_end;
loff_t new_size = i_size_read(inode);
loff_t off_end;
- int ret;
+ int err;
- ret = inode_newsize_ok(inode, (len + offset));
- if (ret)
- return ret;
+ err = inode_newsize_ok(inode, (len + offset));
+ if (err)
+ return err;
- ret = f2fs_convert_inline_inode(inode);
- if (ret)
- return ret;
+ err = f2fs_convert_inline_inode(inode);
+ if (err)
+ return err;
f2fs_balance_fs(sbi, true);
@@ -1340,12 +1340,12 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
if (off_end)
map.m_len++;
- ret = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO);
- if (ret) {
+ err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO);
+ if (err) {
pgoff_t last_off;
if (!map.m_len)
- return ret;
+ return err;
last_off = map.m_lblk + map.m_len - 1;
@@ -1359,7 +1359,7 @@ static int expand_inode_data(struct inode *inode, loff_t offset,
if (!(mode & FALLOC_FL_KEEP_SIZE) && i_size_read(inode) < new_size)
f2fs_i_size_write(inode, new_size);
- return ret;
+ return err;
}
static long f2fs_fallocate(struct file *file, int mode,
@@ -2263,12 +2263,15 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
inode_lock(inode);
ret = generic_write_checks(iocb, from);
if (ret > 0) {
- ret = f2fs_preallocate_blocks(iocb, from);
- if (!ret) {
- blk_start_plug(&plug);
- ret = __generic_file_write_iter(iocb, from);
- blk_finish_plug(&plug);
+ int err = f2fs_preallocate_blocks(iocb, from);
+
+ if (err) {
+ inode_unlock(inode);
+ return err;
}
+ blk_start_plug(&plug);
+ ret = __generic_file_write_iter(iocb, from);
+ blk_finish_plug(&plug);
}
inode_unlock(inode);
--
2.8.3
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] f2fs: fix redundant block allocation
2016-11-12 1:30 ` Jaegeuk Kim
@ 2016-11-12 1:30 ` Jaegeuk Kim
-1 siblings, 0 replies; 7+ messages in thread
From: Jaegeuk Kim @ 2016-11-12 1:30 UTC (permalink / raw)
To: linux-kernel, linux-fsdevel, linux-f2fs-devel; +Cc: Jaegeuk Kim
In direct_IO path of f2fs_file_write_iter(),
1. f2fs_preallocate_blocks(F2FS_GET_BLOCK_PRE_DIO)
-> allocate LBA X
2. f2fs_direct_IO()
-> return 0;
Then,
f2fs_write_data_page() will allocate another LBA X+1.
This makes EIO triggered by HM-SMR.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fs/f2fs/data.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 2938311..59203a3 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -658,6 +658,13 @@ static int __allocate_data_block(struct dnode_of_data *dn)
return 0;
}
+static inline bool __force_buffered_io(struct inode *inode, int rw)
+{
+ return ((f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) ||
+ (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) ||
+ F2FS_I_SB(inode)->s_ndevs);
+}
+
int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
{
struct inode *inode = file_inode(iocb->ki_filp);
@@ -677,7 +684,10 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
err = f2fs_convert_inline_inode(inode);
if (err)
return err;
- return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO);
+ return f2fs_map_blocks(inode, &map, 1,
+ __force_buffered_io(inode, WRITE) ?
+ F2FS_GET_BLOCK_PRE_AIO :
+ F2FS_GET_BLOCK_PRE_DIO);
}
if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA) {
err = f2fs_convert_inline_inode(inode);
@@ -1769,11 +1779,7 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
if (err)
return err;
- if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
- return 0;
- if (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS))
- return 0;
- if (F2FS_I_SB(inode)->s_ndevs)
+ if (__force_buffered_io(inode, rw))
return 0;
trace_f2fs_direct_IO_enter(inode, offset, count, rw);
--
2.8.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] f2fs: fix redundant block allocation
@ 2016-11-12 1:30 ` Jaegeuk Kim
0 siblings, 0 replies; 7+ messages in thread
From: Jaegeuk Kim @ 2016-11-12 1:30 UTC (permalink / raw)
To: linux-kernel, linux-fsdevel, linux-f2fs-devel; +Cc: Jaegeuk Kim
In direct_IO path of f2fs_file_write_iter(),
1. f2fs_preallocate_blocks(F2FS_GET_BLOCK_PRE_DIO)
-> allocate LBA X
2. f2fs_direct_IO()
-> return 0;
Then,
f2fs_write_data_page() will allocate another LBA X+1.
This makes EIO triggered by HM-SMR.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fs/f2fs/data.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 2938311..59203a3 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -658,6 +658,13 @@ static int __allocate_data_block(struct dnode_of_data *dn)
return 0;
}
+static inline bool __force_buffered_io(struct inode *inode, int rw)
+{
+ return ((f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) ||
+ (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) ||
+ F2FS_I_SB(inode)->s_ndevs);
+}
+
int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
{
struct inode *inode = file_inode(iocb->ki_filp);
@@ -677,7 +684,10 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
err = f2fs_convert_inline_inode(inode);
if (err)
return err;
- return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO);
+ return f2fs_map_blocks(inode, &map, 1,
+ __force_buffered_io(inode, WRITE) ?
+ F2FS_GET_BLOCK_PRE_AIO :
+ F2FS_GET_BLOCK_PRE_DIO);
}
if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA) {
err = f2fs_convert_inline_inode(inode);
@@ -1769,11 +1779,7 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
if (err)
return err;
- if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
- return 0;
- if (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS))
- return 0;
- if (F2FS_I_SB(inode)->s_ndevs)
+ if (__force_buffered_io(inode, rw))
return 0;
trace_f2fs_direct_IO_enter(inode, offset, count, rw);
--
2.8.3
------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today. http://sdm.link/xeonphi
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [f2fs-dev] [PATCH 2/2] f2fs: fix redundant block allocation
2016-11-12 1:30 ` Jaegeuk Kim
@ 2016-11-25 16:05 ` Chao Yu
-1 siblings, 0 replies; 7+ messages in thread
From: Chao Yu @ 2016-11-25 16:05 UTC (permalink / raw)
To: Jaegeuk Kim, linux-kernel, linux-fsdevel, linux-f2fs-devel
On 2016/11/12 9:30, Jaegeuk Kim wrote:
> In direct_IO path of f2fs_file_write_iter(),
> 1. f2fs_preallocate_blocks(F2FS_GET_BLOCK_PRE_DIO)
> -> allocate LBA X
> 2. f2fs_direct_IO()
> -> return 0;
>
> Then,
> f2fs_write_data_page() will allocate another LBA X+1.
>
> This makes EIO triggered by HM-SMR.
Good catch, :) how do you find this problem?
>
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
> ---
> fs/f2fs/data.c | 18 ++++++++++++------
> 1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 2938311..59203a3 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -658,6 +658,13 @@ static int __allocate_data_block(struct dnode_of_data *dn)
> return 0;
> }
>
> +static inline bool __force_buffered_io(struct inode *inode, int rw)
> +{
> + return ((f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) ||
> + (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) ||
> + F2FS_I_SB(inode)->s_ndevs);
> +}
> +
> int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
> {
> struct inode *inode = file_inode(iocb->ki_filp);
> @@ -677,7 +684,10 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
> err = f2fs_convert_inline_inode(inode);
> if (err)
> return err;
> - return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO);
> + return f2fs_map_blocks(inode, &map, 1,
> + __force_buffered_io(inode, WRITE) ?
> + F2FS_GET_BLOCK_PRE_AIO :
> + F2FS_GET_BLOCK_PRE_DIO);
> }
> if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA) {
> err = f2fs_convert_inline_inode(inode);
> @@ -1769,11 +1779,7 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
> if (err)
> return err;
>
> - if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
> - return 0;
> - if (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS))
> - return 0;
> - if (F2FS_I_SB(inode)->s_ndevs)
> + if (__force_buffered_io(inode, rw))
> return 0;
>
> trace_f2fs_direct_IO_enter(inode, offset, count, rw);
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] f2fs: fix redundant block allocation
@ 2016-11-25 16:05 ` Chao Yu
0 siblings, 0 replies; 7+ messages in thread
From: Chao Yu @ 2016-11-25 16:05 UTC (permalink / raw)
To: Jaegeuk Kim, linux-kernel, linux-fsdevel, linux-f2fs-devel
On 2016/11/12 9:30, Jaegeuk Kim wrote:
> In direct_IO path of f2fs_file_write_iter(),
> 1. f2fs_preallocate_blocks(F2FS_GET_BLOCK_PRE_DIO)
> -> allocate LBA X
> 2. f2fs_direct_IO()
> -> return 0;
>
> Then,
> f2fs_write_data_page() will allocate another LBA X+1.
>
> This makes EIO triggered by HM-SMR.
Good catch, :) how do you find this problem?
>
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
> ---
> fs/f2fs/data.c | 18 ++++++++++++------
> 1 file changed, 12 insertions(+), 6 deletions(-)
>
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 2938311..59203a3 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -658,6 +658,13 @@ static int __allocate_data_block(struct dnode_of_data *dn)
> return 0;
> }
>
> +static inline bool __force_buffered_io(struct inode *inode, int rw)
> +{
> + return ((f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) ||
> + (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) ||
> + F2FS_I_SB(inode)->s_ndevs);
> +}
> +
> int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
> {
> struct inode *inode = file_inode(iocb->ki_filp);
> @@ -677,7 +684,10 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
> err = f2fs_convert_inline_inode(inode);
> if (err)
> return err;
> - return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO);
> + return f2fs_map_blocks(inode, &map, 1,
> + __force_buffered_io(inode, WRITE) ?
> + F2FS_GET_BLOCK_PRE_AIO :
> + F2FS_GET_BLOCK_PRE_DIO);
> }
> if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA) {
> err = f2fs_convert_inline_inode(inode);
> @@ -1769,11 +1779,7 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
> if (err)
> return err;
>
> - if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
> - return 0;
> - if (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS))
> - return 0;
> - if (F2FS_I_SB(inode)->s_ndevs)
> + if (__force_buffered_io(inode, rw))
> return 0;
>
> trace_f2fs_direct_IO_enter(inode, offset, count, rw);
>
------------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [f2fs-dev] [PATCH 2/2] f2fs: fix redundant block allocation
2016-11-25 16:05 ` Chao Yu
(?)
@ 2016-11-25 18:16 ` Jaegeuk Kim
-1 siblings, 0 replies; 7+ messages in thread
From: Jaegeuk Kim @ 2016-11-25 18:16 UTC (permalink / raw)
To: Chao Yu; +Cc: linux-kernel, linux-fsdevel, linux-f2fs-devel
On Sat, Nov 26, 2016 at 12:05:33AM +0800, Chao Yu wrote:
> On 2016/11/12 9:30, Jaegeuk Kim wrote:
> > In direct_IO path of f2fs_file_write_iter(),
> > 1. f2fs_preallocate_blocks(F2FS_GET_BLOCK_PRE_DIO)
> > -> allocate LBA X
> > 2. f2fs_direct_IO()
> > -> return 0;
> >
> > Then,
> > f2fs_write_data_page() will allocate another LBA X+1.
> >
> > This makes EIO triggered by HM-SMR.
>
> Good catch, :) how do you find this problem?
I got an error when running fsstres on HM-SMR.
Thanks,
>
> >
> > Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
>
> Reviewed-by: Chao Yu <yuchao0@huawei.com>
>
> > ---
> > fs/f2fs/data.c | 18 ++++++++++++------
> > 1 file changed, 12 insertions(+), 6 deletions(-)
> >
> > diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> > index 2938311..59203a3 100644
> > --- a/fs/f2fs/data.c
> > +++ b/fs/f2fs/data.c
> > @@ -658,6 +658,13 @@ static int __allocate_data_block(struct dnode_of_data *dn)
> > return 0;
> > }
> >
> > +static inline bool __force_buffered_io(struct inode *inode, int rw)
> > +{
> > + return ((f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) ||
> > + (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS)) ||
> > + F2FS_I_SB(inode)->s_ndevs);
> > +}
> > +
> > int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
> > {
> > struct inode *inode = file_inode(iocb->ki_filp);
> > @@ -677,7 +684,10 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from)
> > err = f2fs_convert_inline_inode(inode);
> > if (err)
> > return err;
> > - return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO);
> > + return f2fs_map_blocks(inode, &map, 1,
> > + __force_buffered_io(inode, WRITE) ?
> > + F2FS_GET_BLOCK_PRE_AIO :
> > + F2FS_GET_BLOCK_PRE_DIO);
> > }
> > if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA) {
> > err = f2fs_convert_inline_inode(inode);
> > @@ -1769,11 +1779,7 @@ static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
> > if (err)
> > return err;
> >
> > - if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
> > - return 0;
> > - if (rw == WRITE && test_opt(F2FS_I_SB(inode), LFS))
> > - return 0;
> > - if (F2FS_I_SB(inode)->s_ndevs)
> > + if (__force_buffered_io(inode, rw))
> > return 0;
> >
> > trace_f2fs_direct_IO_enter(inode, offset, count, rw);
> >
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-11-25 18:16 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-12 1:30 [PATCH 1/2] f2fs: use err for f2fs_preallocate_blocks Jaegeuk Kim
2016-11-12 1:30 ` Jaegeuk Kim
2016-11-12 1:30 ` [PATCH 2/2] f2fs: fix redundant block allocation Jaegeuk Kim
2016-11-12 1:30 ` Jaegeuk Kim
2016-11-25 16:05 ` [f2fs-dev] " Chao Yu
2016-11-25 16:05 ` Chao Yu
2016-11-25 18:16 ` [f2fs-dev] " Jaegeuk Kim
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.