52 lines
1.6 KiB
Diff
52 lines
1.6 KiB
Diff
|
From 366e8b54bc18621fe904742a93bc02b695688edf Mon Sep 17 00:00:00 2001
|
||
|
From: Paul Lawrence <paullawrence@google.com>
|
||
|
Date: Wed, 17 Mar 2021 13:35:44 -0700
|
||
|
Subject: [PATCH 18/31] ANDROID: Incremental fs: Truncate file when complete
|
||
|
|
||
|
Bug: 182185202
|
||
|
Test: incfs_test passes
|
||
|
Signed-off-by: Paul Lawrence <paullawrence@google.com>
|
||
|
Change-Id: I01bdd7f942b1831c1937af8458a09be52cafe227
|
||
|
---
|
||
|
fs/incfs/vfs.c | 17 +++++++++++++++++
|
||
|
1 file changed, 17 insertions(+)
|
||
|
|
||
|
diff --git a/fs/incfs/vfs.c b/fs/incfs/vfs.c
|
||
|
index 4e2ef07ec617..8b728a3ec101 100644
|
||
|
--- a/fs/incfs/vfs.c
|
||
|
+++ b/fs/incfs/vfs.c
|
||
|
@@ -639,6 +639,7 @@ static void notify_unlink(struct dentry *dentry, const char *file_id_str,
|
||
|
static void maybe_delete_incomplete_file(struct file *f,
|
||
|
struct data_file *df)
|
||
|
{
|
||
|
+ struct backing_file_context *bfc;
|
||
|
struct mount_info *mi = df->df_mount_info;
|
||
|
char *file_id_str = NULL;
|
||
|
struct dentry *incomplete_file_dentry = NULL;
|
||
|
@@ -648,6 +649,22 @@ static void maybe_delete_incomplete_file(struct file *f,
|
||
|
if (atomic_read(&df->df_data_blocks_written) < df->df_data_block_count)
|
||
|
goto out;
|
||
|
|
||
|
+ /* Truncate file to remove any preallocated space */
|
||
|
+ bfc = df->df_backing_file_context;
|
||
|
+ if (bfc) {
|
||
|
+ struct file *f = bfc->bc_file;
|
||
|
+
|
||
|
+ if (f) {
|
||
|
+ loff_t size = i_size_read(file_inode(f));
|
||
|
+
|
||
|
+ error = vfs_truncate(&f->f_path, size);
|
||
|
+ if (error)
|
||
|
+ /* No useful action on failure */
|
||
|
+ pr_warn("incfs: Failed to truncate complete file: %d\n",
|
||
|
+ error);
|
||
|
+ }
|
||
|
+ }
|
||
|
+
|
||
|
/* This is best effort - there is no useful action to take on failure */
|
||
|
file_id_str = file_id_to_str(df->df_id);
|
||
|
if (!file_id_str)
|
||
|
--
|
||
|
2.17.1
|
||
|
|