Skip to content

Commit 2724daf

Browse files
author
Jaegeuk Kim
committed
f2fs: compress tmp files given extension
Let's compress tmp files for the given extension list. This patch does not change the previous behavior, but allow the cases as below. Extention example: "ext" - abc.ext : allow - abc.ext.abc : allow - abc.extm : not allow Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 6201c47 commit 2724daf

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

fs/f2fs/namei.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <trace/events/f2fs.h>
2424

2525
static inline bool is_extension_exist(const unsigned char *s, const char *sub,
26-
bool tmp_ext)
26+
bool tmp_ext, bool tmp_dot)
2727
{
2828
size_t slen = strlen(s);
2929
size_t sublen = strlen(sub);
@@ -49,13 +49,27 @@ static inline bool is_extension_exist(const unsigned char *s, const char *sub,
4949
for (i = 1; i < slen - sublen; i++) {
5050
if (s[i] != '.')
5151
continue;
52-
if (!strncasecmp(s + i + 1, sub, sublen))
53-
return true;
52+
if (!strncasecmp(s + i + 1, sub, sublen)) {
53+
if (!tmp_dot)
54+
return true;
55+
if (i == slen - sublen - 1 || s[i + 1 + sublen] == '.')
56+
return true;
57+
}
5458
}
5559

5660
return false;
5761
}
5862

63+
static inline bool is_temperature_extension(const unsigned char *s, const char *sub)
64+
{
65+
return is_extension_exist(s, sub, true, false);
66+
}
67+
68+
static inline bool is_compress_extension(const unsigned char *s, const char *sub)
69+
{
70+
return is_extension_exist(s, sub, true, true);
71+
}
72+
5973
int f2fs_update_extension_list(struct f2fs_sb_info *sbi, const char *name,
6074
bool hot, bool set)
6175
{
@@ -148,20 +162,20 @@ static void set_compress_new_inode(struct f2fs_sb_info *sbi, struct inode *dir,
148162
cold_count = le32_to_cpu(sbi->raw_super->extension_count);
149163
hot_count = sbi->raw_super->hot_ext_count;
150164
for (i = cold_count; i < cold_count + hot_count; i++)
151-
if (is_extension_exist(name, extlist[i], false))
165+
if (is_temperature_extension(name, extlist[i]))
152166
break;
153167
f2fs_up_read(&sbi->sb_lock);
154168
if (i < (cold_count + hot_count))
155169
return;
156170

157171
/* Don't compress unallowed extension. */
158172
for (i = 0; i < noext_cnt; i++)
159-
if (is_extension_exist(name, noext[i], false))
173+
if (is_compress_extension(name, noext[i]))
160174
return;
161175

162176
/* Compress wanting extension. */
163177
for (i = 0; i < ext_cnt; i++) {
164-
if (is_extension_exist(name, ext[i], false)) {
178+
if (is_compress_extension(name, ext[i])) {
165179
set_compress_context(inode);
166180
return;
167181
}
@@ -189,7 +203,7 @@ static void set_file_temperature(struct f2fs_sb_info *sbi, struct inode *inode,
189203
cold_count = le32_to_cpu(sbi->raw_super->extension_count);
190204
hot_count = sbi->raw_super->hot_ext_count;
191205
for (i = 0; i < cold_count + hot_count; i++)
192-
if (is_extension_exist(name, extlist[i], true))
206+
if (is_temperature_extension(name, extlist[i]))
193207
break;
194208
f2fs_up_read(&sbi->sb_lock);
195209

0 commit comments

Comments
 (0)