Skip to content

Commit d36de29

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: sysfs: introduce inject_lock_timeout
This patch adds a new sysfs node in /sys/fs/f2fs/<disk>/inject_lock_timeout, it relies on CONFIG_F2FS_FAULT_INJECTION kernel config. It can be used to simulate different type of timeout in lock duration. ========== =============================== Flag_Value Flag_Description ========== =============================== 0x00000000 No timeout (default) 0x00000001 Simulate running time 0x00000002 Simulate IO type sleep time 0x00000003 Simulate Non-IO type sleep time 0x00000004 Simulate runnable time ========== =============================== Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent c56254e commit d36de29

6 files changed

Lines changed: 93 additions & 5 deletions

File tree

Documentation/ABI/testing/sysfs-fs-f2fs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,3 +948,17 @@ Description: This is a threshold, once a thread enters critical region that lock
948948
elapsed time exceeds this threshold, f2fs will print tracepoint to dump information
949949
of related context. This sysfs entry can be used to control the value of threshold,
950950
by default, the value is 500 ms.
951+
952+
What: /sys/fs/f2fs/<disk>/inject_timeout_type
953+
Date: December 2025
954+
Contact: "Chao Yu" <chao@kernel.org>
955+
Description: This sysfs entry can be used to change type of injected timeout:
956+
========== ===============================
957+
Flag_Value Flag_Description
958+
========== ===============================
959+
0x00000000 No timeout (default)
960+
0x00000001 Simulate running time
961+
0x00000002 Simulate IO type sleep time
962+
0x00000003 Simulate Non-IO type sleep time
963+
0x00000004 Simulate runnable time
964+
========== ===============================

fs/f2fs/checkpoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static inline void trace_lock_elapsed_time_end(struct f2fs_rwsem *sem,
6464
return;
6565

6666
if (time_to_inject(sem->sbi, FAULT_LOCK_TIMEOUT))
67-
f2fs_io_schedule_timeout_killable(DEFAULT_FAULT_TIMEOUT);
67+
f2fs_schedule_timeout_killable(DEFAULT_FAULT_TIMEOUT, true);
6868

6969
get_lock_elapsed_time(&tts);
7070

fs/f2fs/f2fs.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ enum {
7373
enum fault_option {
7474
FAULT_RATE = 1, /* only update fault rate */
7575
FAULT_TYPE = 2, /* only update fault type */
76-
FAULT_ALL = 4, /* reset all fault injection options/stats */
76+
FAULT_TIMEOUT = 4, /* only update fault timeout type */
77+
FAULT_ALL = 8, /* reset all fault injection options/stats */
7778
};
7879

7980
#ifdef CONFIG_F2FS_FAULT_INJECTION
@@ -83,6 +84,7 @@ struct f2fs_fault_info {
8384
unsigned int inject_type;
8485
/* Used to account total count of injection for each type */
8586
unsigned int inject_count[FAULT_MAX];
87+
unsigned int inject_lock_timeout; /* inject lock timeout */
8688
};
8789

8890
extern const char *f2fs_fault_name[FAULT_MAX];
@@ -184,6 +186,15 @@ enum f2fs_lock_name {
184186
LOCK_NAME_IO_RWSEM,
185187
};
186188

189+
enum f2fs_timeout_type {
190+
TIMEOUT_TYPE_NONE,
191+
TIMEOUT_TYPE_RUNNING,
192+
TIMEOUT_TYPE_IO_SLEEP,
193+
TIMEOUT_TYPE_NONIO_SLEEP,
194+
TIMEOUT_TYPE_RUNNABLE,
195+
TIMEOUT_TYPE_MAX,
196+
};
197+
187198
/*
188199
* An implementation of an rwsem that is explicitly unfair to readers. This
189200
* prevents priority inversion when a low-priority reader acquires the read lock
@@ -4927,13 +4938,18 @@ static inline bool f2fs_need_verity(const struct inode *inode, pgoff_t idx)
49274938
#ifdef CONFIG_F2FS_FAULT_INJECTION
49284939
extern int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned long rate,
49294940
unsigned long type, enum fault_option fo);
4941+
extern void f2fs_simulate_lock_timeout(struct f2fs_sb_info *sbi);
49304942
#else
49314943
static inline int f2fs_build_fault_attr(struct f2fs_sb_info *sbi,
49324944
unsigned long rate, unsigned long type,
49334945
enum fault_option fo)
49344946
{
49354947
return 0;
49364948
}
4949+
static inline void f2fs_simulate_lock_timeout(struct f2fs_sb_info *sbi)
4950+
{
4951+
return;
4952+
}
49374953
#endif
49384954

49394955
static inline bool is_journalled_quota(struct f2fs_sb_info *sbi)
@@ -4984,14 +5000,14 @@ static inline void __f2fs_schedule_timeout(long timeout, bool io)
49845000
#define f2fs_schedule_timeout(timeout) \
49855001
__f2fs_schedule_timeout(timeout, false)
49865002

4987-
static inline void f2fs_io_schedule_timeout_killable(long timeout)
5003+
static inline void f2fs_schedule_timeout_killable(long timeout, bool io)
49885004
{
49895005
unsigned long last_time = jiffies + timeout;
49905006

49915007
while (jiffies < last_time) {
49925008
if (fatal_signal_pending(current))
49935009
return;
4994-
__f2fs_schedule_timeout(DEFAULT_SCHEDULE_TIMEOUT, true);
5010+
__f2fs_schedule_timeout(DEFAULT_SCHEDULE_TIMEOUT, io);
49955011
}
49965012
}
49975013

fs/f2fs/segment.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ static int __f2fs_commit_atomic_write(struct inode *inode)
372372

373373
out:
374374
if (time_to_inject(sbi, FAULT_ATOMIC_TIMEOUT))
375-
f2fs_io_schedule_timeout_killable(DEFAULT_FAULT_TIMEOUT);
375+
f2fs_schedule_timeout_killable(DEFAULT_FAULT_TIMEOUT, true);
376376

377377
if (ret) {
378378
sbi->revoked_atomic_block += fi->atomic_write_cnt;

fs/f2fs/super.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,57 @@ int f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned long rate,
9797
f2fs_info(sbi, "build fault injection type: 0x%lx", type);
9898
}
9999

100+
if (fo & FAULT_TIMEOUT) {
101+
if (type >= TIMEOUT_TYPE_MAX)
102+
return -EINVAL;
103+
ffi->inject_lock_timeout = (unsigned int)type;
104+
f2fs_info(sbi, "build fault timeout injection type: 0x%lx", type);
105+
}
106+
100107
return 0;
101108
}
109+
110+
static void inject_timeout(struct f2fs_sb_info *sbi)
111+
{
112+
struct f2fs_fault_info *ffi = &F2FS_OPTION(sbi).fault_info;
113+
enum f2fs_timeout_type type = ffi->inject_lock_timeout;
114+
unsigned long start_time = jiffies;
115+
unsigned long timeout = HZ;
116+
117+
switch (type) {
118+
case TIMEOUT_TYPE_RUNNING:
119+
while (!time_after(jiffies, start_time + timeout)) {
120+
if (fatal_signal_pending(current))
121+
return;
122+
;
123+
}
124+
break;
125+
case TIMEOUT_TYPE_IO_SLEEP:
126+
f2fs_schedule_timeout_killable(timeout, true);
127+
break;
128+
case TIMEOUT_TYPE_NONIO_SLEEP:
129+
f2fs_schedule_timeout_killable(timeout, false);
130+
break;
131+
case TIMEOUT_TYPE_RUNNABLE:
132+
while (!time_after(jiffies, start_time + timeout)) {
133+
if (fatal_signal_pending(current))
134+
return;
135+
schedule();
136+
}
137+
break;
138+
default:
139+
return;
140+
}
141+
}
142+
143+
void f2fs_simulate_lock_timeout(struct f2fs_sb_info *sbi)
144+
{
145+
struct f2fs_lock_context lc;
146+
147+
f2fs_lock_op(sbi, &lc);
148+
inject_timeout(sbi);
149+
f2fs_unlock_op(sbi, &lc);
150+
}
102151
#endif
103152

104153
/* f2fs-wide shrinker description */

fs/f2fs/sysfs.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ enum {
3535
#ifdef CONFIG_F2FS_FAULT_INJECTION
3636
FAULT_INFO_RATE, /* struct f2fs_fault_info */
3737
FAULT_INFO_TYPE, /* struct f2fs_fault_info */
38+
FAULT_INFO_TIMEOUT, /* struct f2fs_fault_info */
3839
#endif
3940
RESERVED_BLOCKS, /* struct f2fs_sb_info */
4041
CPRC_INFO, /* struct ckpt_req_control */
@@ -529,6 +530,12 @@ static ssize_t __sbi_store(struct f2fs_attr *a,
529530
return -EINVAL;
530531
return count;
531532
}
533+
if (a->struct_type == FAULT_INFO_TIMEOUT) {
534+
if (f2fs_build_fault_attr(sbi, 0, t, FAULT_TIMEOUT))
535+
return -EINVAL;
536+
f2fs_simulate_lock_timeout(sbi);
537+
return count;
538+
}
532539
#endif
533540
if (a->struct_type == RESERVED_BLOCKS) {
534541
spin_lock(&sbi->stat_lock);
@@ -1233,6 +1240,7 @@ STAT_INFO_RO_ATTR(gc_background_calls, gc_call_count[BACKGROUND]);
12331240
#ifdef CONFIG_F2FS_FAULT_INJECTION
12341241
FAULT_INFO_GENERAL_RW_ATTR(FAULT_INFO_RATE, inject_rate);
12351242
FAULT_INFO_GENERAL_RW_ATTR(FAULT_INFO_TYPE, inject_type);
1243+
FAULT_INFO_GENERAL_RW_ATTR(FAULT_INFO_TIMEOUT, inject_lock_timeout);
12361244
#endif
12371245

12381246
/* RESERVED_BLOCKS ATTR */
@@ -1362,6 +1370,7 @@ static struct attribute *f2fs_attrs[] = {
13621370
#ifdef CONFIG_F2FS_FAULT_INJECTION
13631371
ATTR_LIST(inject_rate),
13641372
ATTR_LIST(inject_type),
1373+
ATTR_LIST(inject_lock_timeout),
13651374
#endif
13661375
ATTR_LIST(data_io_flag),
13671376
ATTR_LIST(node_io_flag),

0 commit comments

Comments
 (0)