All of lore.kernel.org
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH v4] f2fs: compress: allow write compress released file after truncate to zero
@ 2021-08-06  9:59 Fengnan Chang
  2021-08-09  0:30 ` Chao Yu
  0 siblings, 1 reply; 2+ messages in thread
From: Fengnan Chang @ 2021-08-06  9:59 UTC (permalink / raw)
  To: jaegeuk, chao, linux-f2fs-devel; +Cc: Fengnan Chang

For compressed file, after release compress blocks, don't allow write
direct, but we should allow write direct after truncate to zero.

Signed-off-by: Fengnan Chang <changfengnan@vivo.com>
---
 Documentation/filesystems/f2fs.rst | 7 +++++--
 fs/f2fs/file.c                     | 8 ++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/Documentation/filesystems/f2fs.rst b/Documentation/filesystems/f2fs.rst
index 8f251a662542..d4de7ea4a83d 100644
--- a/Documentation/filesystems/f2fs.rst
+++ b/Documentation/filesystems/f2fs.rst
@@ -865,8 +865,11 @@ Compression implementation
   directly in order to guarantee potential data updates later to the space.
   Instead, the main goal is to reduce data writes to flash disk as much as
   possible, resulting in extending disk life time as well as relaxing IO
-  congestion. Alternatively, we've added ioctl interface to reclaim compressed
-  space and show it to user after putting the immutable bit.
+  congestion. Alternatively, we've added ioctl(F2FS_IOC_RELEASE_COMPRESS_BLOCKS)
+  interface to reclaim compressed space and show it to user after putting the
+  immutable bit. After call ioctl release compreesed space, don't allow write
+  file directly, unless call ioctl(F2FS_IOC_RESERVE_COMPRESS_BLOCKS) to reserve
+  compreesed space or file truncated be zero.
 
 Compress metadata layout::
 
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 7d8ee60f6c1f..d4fc5e0d2ffe 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -753,6 +753,14 @@ int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock)
 		return err;
 
 #ifdef CONFIG_F2FS_FS_COMPRESSION
+	/*
+	 * For compressed file, after release compress blocks, don't allow write
+	 * direct, but we should allow write direct after truncate to zero.
+	 */
+	if (f2fs_compressed_file(inode) && !free_from
+			&& is_inode_flag_set(inode, FI_COMPRESS_RELEASED))
+		clear_inode_flag(inode, FI_COMPRESS_RELEASED);
+
 	if (from != free_from) {
 		err = f2fs_truncate_partial_cluster(inode, from, lock);
 		if (err)
-- 
2.29.0



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [f2fs-dev] [PATCH v4] f2fs: compress: allow write compress released file after truncate to zero
  2021-08-06  9:59 [f2fs-dev] [PATCH v4] f2fs: compress: allow write compress released file after truncate to zero Fengnan Chang
@ 2021-08-09  0:30 ` Chao Yu
  0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2021-08-09  0:30 UTC (permalink / raw)
  To: Fengnan Chang, jaegeuk, linux-f2fs-devel

On 2021/8/6 17:59, Fengnan Chang wrote:
> For compressed file, after release compress blocks, don't allow write
> direct, but we should allow write direct after truncate to zero.
> 
> Signed-off-by: Fengnan Chang <changfengnan@vivo.com>
> ---
>   Documentation/filesystems/f2fs.rst | 7 +++++--
>   fs/f2fs/file.c                     | 8 ++++++++
>   2 files changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/Documentation/filesystems/f2fs.rst b/Documentation/filesystems/f2fs.rst
> index 8f251a662542..d4de7ea4a83d 100644
> --- a/Documentation/filesystems/f2fs.rst
> +++ b/Documentation/filesystems/f2fs.rst
> @@ -865,8 +865,11 @@ Compression implementation
>     directly in order to guarantee potential data updates later to the space.
>     Instead, the main goal is to reduce data writes to flash disk as much as
>     possible, resulting in extending disk life time as well as relaxing IO
> -  congestion. Alternatively, we've added ioctl interface to reclaim compressed
> -  space and show it to user after putting the immutable bit.
> +  congestion. Alternatively, we've added ioctl(F2FS_IOC_RELEASE_COMPRESS_BLOCKS)
> +  interface to reclaim compressed space and show it to user after putting the
> +  immutable bit. After call ioctl release compreesed space, don't allow write

immutable bit, after release, it doesn't allow writing/mmaping on the file,
until reserving compressed space via ioctl(F2FS_IOC_RESERVE_COMPRESS_BLOCKS)
or truncating filesize to zero.

Otherwise, it looks good to me.

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

> +  file directly, unless call ioctl(F2FS_IOC_RESERVE_COMPRESS_BLOCKS) to reserve
> +  compreesed space or file truncated be zero.
>   
>   Compress metadata layout::
>   
> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
> index 7d8ee60f6c1f..d4fc5e0d2ffe 100644
> --- a/fs/f2fs/file.c
> +++ b/fs/f2fs/file.c
> @@ -753,6 +753,14 @@ int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock)
>   		return err;
>   
>   #ifdef CONFIG_F2FS_FS_COMPRESSION
> +	/*
> +	 * For compressed file, after release compress blocks, don't allow write
> +	 * direct, but we should allow write direct after truncate to zero.
> +	 */
> +	if (f2fs_compressed_file(inode) && !free_from
> +			&& is_inode_flag_set(inode, FI_COMPRESS_RELEASED))
> +		clear_inode_flag(inode, FI_COMPRESS_RELEASED);
> +
>   	if (from != free_from) {
>   		err = f2fs_truncate_partial_cluster(inode, from, lock);
>   		if (err)
> 


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-09  0:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-06  9:59 [f2fs-dev] [PATCH v4] f2fs: compress: allow write compress released file after truncate to zero Fengnan Chang
2021-08-09  0:30 ` Chao Yu

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.