exfat: Fixes for ENAMETOOLONG error handling
Subsystems (2)
v2 cover exfat: Fixes for ENAMETOOLONG error handling
Hi,
this is a revised series for fixing the error code of rename syscall as well as cleanup / suppress the superfluous error messages.
As an LTP test case reported, exfat returns the inconsistent error code for the case of renaming oversized file names:
https://bugzilla.suse.com/show_bug.cgi?id=1201725
The first patch fixes this inconsistency.
The second patch is just for correcting the definitions as bit flags, and the remaining two patches are for suppressing the error message that can be triggered too easily to debug messages.
thanks,
Takashi
===
v1: https://lore.kernel.org/r/[email protected]
v1->v2:
* Expand to pr_*() directly in exfat_*() macros
* Add a patch to drop superfluous newlines in error messages
===
Takashi Iwai (5):
exfat: Return ENAMETOOLONG consistently for oversized paths
exfat: Define NLS_NAME_* as bit flags explicitly
exfat: Expand exfat_err() and co directly to pr_*() macro
exfat: Downgrade ENAMETOOLONG error message to debug messages
exfat: Drop superfluous new line for error messages
fs/exfat/exfat_fs.h | 18 ++++++++++-------- fs/exfat/fatent.c | 2 +- fs/exfat/misc.c | 17 ----------------- fs/exfat/namei.c | 2 +- fs/exfat/nls.c | 4 ++-- fs/exfat/super.c | 4 ++-- 6 files changed, 16 insertions(+), 31 deletions(-)
Signature · 1 line
2.35.3
PATCH v2 1/5 exfat: Return ENAMETOOLONG consistently for oversized paths
LTP has a test for oversized file path renames and it expects the return value to be ENAMETOOLONG. However, exfat returns EINVAL unexpectedly in some cases, hence LTP test fails. The further investigation indicated that the problem happens only when iocharset isn't set to utf8.
The difference comes from that, in the case of utf8, exfat_utf8_to_utf16() returns the error -ENAMETOOLONG directly and it's treated as the final error code. Meanwhile, on other iocharsets, exfat_nls_to_ucs2() returns the max path size but it sets NLS_NAME_OVERLEN to lossy flag instead; the caller side checks only whether lossy flag is set or not, resulting in always -EINVAL unconditionally.
This patch aligns the return code for both cases by checking the lossy flag bit and returning ENAMETOOLONG when NLS_NAME_OVERLEN bit is set.
--- fs/exfat/namei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/exfat/namei.c +1 -1
@@ -462,7 +462,7 @@ static int __exfat_resolve_path(struct inode *inode, const unsigned char *path,return namelen;/* return error value */ if ((lossy && !lookup) || !namelen) -return -EINVAL ; +return (lossy &NLS_NAME_OVERLEN ) ? -ENAMETOOLONG : -EINVAL ;exfat_chain_set (p_dir, ei->start_clu,EXFAT_B_TO_CLU (i_size_read (inode), sbi), ei->flags);
Signature · 1 line
2.35.3
PATCH v2 2/5 exfat: Define NLS_NAME_* as bit flags explicitly
In reply to Takashi IwaiNLS_NAME_* are bit flags although they are currently defined as enum; it's casually working so far (from 0 to 2), but it's error-prone and may bring a problem when we want to add more flag.
This patch changes the definitions of NLS_NAME_* explicitly being bit flags.
--- fs/exfat/exfat_fs.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/exfat/exfat_fs.h +3 -3
@@ -27,9 +27,9 @@ enum exfat_error_mode {* exfat nls lossy flag */ enum { -NLS_NAME_NO_LOSSY ,/* no lossy */ -NLS_NAME_LOSSY ,/* just detected incorrect filename(s) */ -NLS_NAME_OVERLEN ,/* the length is over than its limit */ +NLS_NAME_NO_LOSSY =0 ,/* no lossy */ +NLS_NAME_LOSSY =1 <<0 ,/* just detected incorrect filename(s) */ +NLS_NAME_OVERLEN =1 <<1 ,/* the length is over than its limit */ };#define EXFAT_HASH_BITS 8
Signature · 1 line
2.35.3
PATCH v2 3/5 exfat: Expand exfat_err() and co directly to pr_*() macro
In reply to Takashi IwaiCurrently the error and info messages handled by exfat_err() and co are tossed to exfat_msg() function that does nothing but passes the strings with printk() invocation. Not only that this is more overhead by the indirect calls, but also this makes harder to extend for the debug print usage; because of the direct printk() call, you cannot make it for dynamic debug or without debug like the standard helpers such as pr_debug() or dev_dbg().
For addressing the problem, this patch replaces exfat_*() macro to expand to pr_*() directly. Along with it, add the new exfat_debug() macro that is expanded to pr_debug() (which output can be gracefully suppressed via dyndbg).
--- fs/exfat/exfat_fs.h | 12 +++++++----- fs/exfat/misc.c | 17 ----------------- 2 files changed, 7 insertions(+), 22 deletions(-)
fs/exfat/exfat_fs.h +7 -5
@@ -508,14 +508,16 @@ void __exfat_fs_error(struct super_block *sb, int report, const char *fmt, ...) #define exfat_fs_error_ratelimit(sb, fmt, args...) \ __exfat_fs_error(sb, __ratelimit(&EXFAT_SB(sb)->ratelimit), \ fmt, ## args) -void exfat_msg(struct super_block *sb, const char *lv, const char *fmt, ...) - __printf(3, 4) __cold; + +/* expand to pr_*() with prefix */ #define exfat_err (sb, fmt, ...) \ - exfat_msg(sb, KERN_ERR, fmt, ##__VA_ARGS__) + pr_err("exFAT-fs (%s): " fmt "\n", (sb)->s_id, ##__VA_ARGS__)#define exfat_warn (sb, fmt, ...) \ - exfat_msg(sb, KERN_WARNING, fmt, ##__VA_ARGS__) + pr_warn("exFAT-fs (%s): " fmt "\n", (sb)->s_id, ##__VA_ARGS__)#define exfat_info (sb, fmt, ...) \ - exfat_msg(sb, KERN_INFO, fmt, ##__VA_ARGS__) + pr_info("exFAT-fs (%s): " fmt "\n", (sb)->s_id, ##__VA_ARGS__) +#define exfat_debug (sb, fmt, ...) \ + pr_debug("exFAT-fs (%s): " fmt "\n", (sb)->s_id, ##__VA_ARGS__)void exfat_get_entry_time (struct exfat_sb_info *sbi,struct timespec64 *ts,u8 tz,__le16 time,__le16 date,u8 time_cs);
fs/exfat/misc.c +0 -17
@@ -46,23 +46,6 @@ void __exfat_fs_error(struct super_block *sb, int report, const char *fmt, ...) } } -/* -* exfat_msg() - print preformated EXFAT specific messages. -* All logs except what uses exfat_fs_error() should be written by exfat_msg() -*/ -void exfat_msg (struct super_block *sb,const char *level,const char *fmt, ...) -{ -struct va_format vaf; -va_list args; - -va_start (args, fmt); - vaf.fmt = fmt; - vaf.va = &args; -/* level means KERN_ pacility level */ -printk ("%sexFAT-fs (%s): %pV\n" , level, sb->s_id, &vaf); -va_end (args); -} -#define SECS_PER_MIN (60)#define TIMEZONE_SEC (x) ((x) * 15 * SECS_PER_MIN)
Signature · 1 line
2.35.3
PATCH v2 4/5 exfat: Downgrade ENAMETOOLONG error message to debug messages
In reply to Takashi IwaiThe ENAMETOOLONG error message is printed at each time when user tries to operate with a too long name, and this can flood the kernel logs easily, as every user can trigger this. Let's downgrade this error message level to a debug message for suppressing the superfluous logs.
--- fs/exfat/nls.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/exfat/nls.c +1 -1
@@ -509,7 +509,7 @@ static int exfat_utf8_to_utf16(struct super_block *sb, }if (unilen >MAX_NAME_LENGTH ) { -exfat_err (sb,"failed to %s (estr:ENAMETOOLONG) nls len : %d, unilen : %d > %d" , +exfat_debug (sb,"failed to %s (estr:ENAMETOOLONG) nls len : %d, unilen : %d > %d" , __func__, len, unilen,MAX_NAME_LENGTH );return -ENAMETOOLONG ; }
Signature · 1 line
2.35.3
PATCH v2 5/5 exfat: Drop superfluous new line for error messages
In reply to Takashi Iwaiexfat_err() adds the new line at the end of the message by itself, hence the passed string shouldn't contain a new line. Drop the superfluous newline letters in the error messages in a few places that have been put mistakenly.
--- fs/exfat/fatent.c | 2 +- fs/exfat/nls.c | 2 +- fs/exfat/super.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-)
fs/exfat/fatent.c +1 -1
@@ -331,7 +331,7 @@ int exfat_alloc_cluster(struct inode *inode, unsigned int num_alloc,/* find new cluster */ if (hint_clu ==EXFAT_EOF_CLUSTER ) {if (sbi->clu_srch_ptr <EXFAT_FIRST_CLUSTER ) { -exfat_err (sb,"sbi->clu_srch_ptr is invalid (%u)\n" , +exfat_err (sb,"sbi->clu_srch_ptr is invalid (%u)" , sbi->clu_srch_ptr); sbi->clu_srch_ptr =EXFAT_FIRST_CLUSTER ; }
fs/exfat/nls.c +1 -1
@@ -671,7 +671,7 @@ static int exfat_load_upcase_table(struct super_block *sb, bh =sb_bread (sb, sector);if (!bh) { -exfat_err (sb,"failed to read sector(0x%llx)\n" , +exfat_err (sb,"failed to read sector(0x%llx)" , (unsigned long long )sector); ret = -EIO ; goto free_table;
fs/exfat/super.c +2 -2
@@ -464,7 +464,7 @@ static int exfat_read_boot_sector(struct super_block *sb)*/ if (p_boot->sect_size_bits <EXFAT_MIN_SECT_SIZE_BITS || p_boot->sect_size_bits >EXFAT_MAX_SECT_SIZE_BITS ) { -exfat_err (sb,"bogus sector size bits : %u\n" , +exfat_err (sb,"bogus sector size bits : %u" , p_boot->sect_size_bits);return -EINVAL ; }
@@ -473,7 +473,7 @@ static int exfat_read_boot_sector(struct super_block *sb)* sect_per_clus_bits could be at least 0 and at most 25 - sect_size_bits. */ if (p_boot->sect_per_clus_bits >EXFAT_MAX_SECT_PER_CLUS_BITS (p_boot)) { -exfat_err (sb,"bogus sectors bits per cluster : %u\n" , +exfat_err (sb,"bogus sectors bits per cluster : %u" , p_boot->sect_per_clus_bits);return -EINVAL ; }
Signature · 1 line
2.35.3
2022-07-26 17:39 GMT+09:00, Takashi Iwai <[email protected]>:
Quoted 5 lines
Hi,
this is a revised series for fixing the error code of rename syscall as well as cleanup / suppress the superfluous error messages.
Quoted 8 lines
As an LTP test case reported, exfat returns the inconsistent error code for the case of renaming oversized file names:
https://bugzilla.suse.com/show_bug.cgi?id=1201725
The first patch fixes this inconsistency.The second patch is just for correcting the definitions as bit flags, and the remaining two patches are for suppressing the error message that can be triggered too easily to debug messages.
Applied, Thanks for your work!
Quoted 35 lines
thanks,
Takashi
===
v1: https://lore.kernel.org/r/[email protected]
v1->v2:
* Expand to pr_*() directly in exfat_*() macros
* Add a patch to drop superfluous newlines in error messages===
Takashi Iwai (5):
exfat: Return ENAMETOOLONG consistently for oversized paths
exfat: Define NLS_NAME_* as bit flags explicitly
exfat: Expandexfat_err()and co directly to pr_*() macro
exfat: Downgrade ENAMETOOLONG error message to debug messages
exfat: Drop superfluous new line for error messagesfs/exfat/exfat_fs.h | 18 ++++++++++-------- fs/exfat/fatent.c | 2 +- fs/exfat/misc.c | 17 ----------------- fs/exfat/namei.c | 2 +- fs/exfat/nls.c | 4 ++-- fs/exfat/super.c | 4 ++-- 6 files changed, 16 insertions(+), 31 deletions(-)--
2.35.3