Skip to content

Commit fcac769

Browse files
authored
Support Linux 6.8 (#47)
To align with the best practices recommended by Linux kernel v6.8, this commit replaces direct accesses to the '__i_atime' and '__i_mtime' fields with the newly introduced accessor functions. Functions such as 'inode_get_atime_sec' and 'simple_inode_init_ts' now encapsulate direct interactions with these inode fields. This change enhances code readability and maintainability, ensures adherence to evolving kernel API manners, and minimizes direct manipulation of internal structures, thereby reducing potential for bugs and improving compatibility with future kernel updates.
1 parent 06707da commit fcac769

File tree

3 files changed

+58
-9
lines changed

3 files changed

+58
-9
lines changed

file.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,19 @@ static int simplefs_readpage(struct file *file, struct page *page)
9696
/* Called by the page cache to write a dirty page to the physical disk (when
9797
* sync is called or when memory is needed).
9898
*/
99+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 8, 0)
100+
static int simplefs_writepage(struct page *page, struct writeback_control *wbc)
101+
{
102+
struct folio *folio = page_folio(page);
103+
return __block_write_full_folio(page->mapping->host, folio,
104+
simplefs_file_get_block, wbc);
105+
}
106+
#else
99107
static int simplefs_writepage(struct page *page, struct writeback_control *wbc)
100108
{
101109
return block_write_full_page(page, simplefs_file_get_block, wbc);
102110
}
111+
#endif
103112

104113
/* Called by the VFS when a write() syscall is made on a file, before writing
105114
* the data into the page cache. This function checks if the write operation
@@ -183,7 +192,11 @@ static int simplefs_write_end(struct file *file,
183192
/* Update inode metadata */
184193
inode->i_blocks = inode->i_size / SIMPLEFS_BLOCK_SIZE + 2;
185194

186-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
195+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
196+
cur_time = current_time(inode);
197+
inode_set_mtime_to_ts(inode, cur_time);
198+
inode_set_ctime_to_ts(inode, cur_time);
199+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
187200
cur_time = current_time(inode);
188201
inode->i_mtime = cur_time;
189202
inode_set_ctime_to_ts(inode, cur_time);

inode.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,16 @@ struct inode *simplefs_iget(struct super_block *sb, unsigned long ino)
6363
inode->i_ctime.tv_nsec = 0;
6464
#endif
6565

66+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
67+
inode_set_atime(inode, (time64_t) le32_to_cpu(cinode->i_atime), 0);
68+
inode_set_mtime(inode, (time64_t) le32_to_cpu(cinode->i_mtime), 0);
69+
#else
6670
inode->i_atime.tv_sec = (time64_t) le32_to_cpu(cinode->i_atime);
6771
inode->i_atime.tv_nsec = 0;
6872
inode->i_mtime.tv_sec = (time64_t) le32_to_cpu(cinode->i_mtime);
6973
inode->i_mtime.tv_nsec = 0;
74+
#endif
75+
7076
inode->i_blocks = le32_to_cpu(cinode->i_blocks);
7177
set_nlink(inode, le32_to_cpu(cinode->i_nlink));
7278

@@ -161,7 +167,12 @@ static struct dentry *simplefs_lookup(struct inode *dir,
161167
brelse(bh);
162168

163169
/* Update directory access time */
170+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
171+
inode_set_atime_to_ts(dir, current_time(dir));
172+
#else
164173
dir->i_atime = current_time(dir);
174+
#endif
175+
165176
mark_inode_dirty(dir);
166177

167178
/* Fill the dentry with the inode */
@@ -219,7 +230,9 @@ static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
219230
#endif
220231
set_nlink(inode, 1);
221232

222-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
233+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
234+
simple_inode_init_ts(inode);
235+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
223236
cur_time = current_time(inode);
224237
inode->i_atime = inode->i_mtime = cur_time;
225238
inode_set_ctime_to_ts(inode, cur_time);
@@ -261,7 +274,9 @@ static struct inode *simplefs_new_inode(struct inode *dir, mode_t mode)
261274
set_nlink(inode, 1);
262275
}
263276

264-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
277+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
278+
simple_inode_init_ts(inode);
279+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
265280
cur_time = current_time(inode);
266281
inode->i_atime = inode->i_mtime = cur_time;
267282
inode_set_ctime_to_ts(inode, cur_time);
@@ -395,7 +410,9 @@ static int simplefs_create(struct inode *dir,
395410
/* Update stats and mark dir and new inode dirty */
396411
mark_inode_dirty(inode);
397412

398-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
413+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
414+
simple_inode_init_ts(dir);
415+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
399416
cur_time = current_time(dir);
400417
dir->i_mtime = dir->i_atime = cur_time;
401418
inode_set_ctime_to_ts(dir, cur_time);
@@ -537,7 +554,9 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
537554
goto clean_inode;
538555

539556
/* Update inode stats */
540-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
557+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
558+
simple_inode_init_ts(dir);
559+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
541560
cur_time = current_time(dir);
542561
dir->i_mtime = dir->i_atime = cur_time;
543562
inode_set_ctime_to_ts(dir, cur_time);
@@ -606,7 +625,11 @@ static int simplefs_unlink(struct inode *dir, struct dentry *dentry)
606625
i_gid_write(inode, 0);
607626
inode->i_mode = 0;
608627

609-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
628+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
629+
inode_set_mtime(inode, 0, 0);
630+
inode_set_atime(inode, 0, 0);
631+
inode_set_ctime(inode, 0, 0);
632+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
610633
inode->i_mtime.tv_sec = inode->i_atime.tv_sec = 0;
611634
inode_set_ctime(inode, 0, 0);
612635
#else
@@ -750,7 +773,9 @@ static int simplefs_rename(struct inode *old_dir,
750773
brelse(bh2);
751774

752775
/* Update new parent inode metadata */
753-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
776+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
777+
simple_inode_init_ts(new_dir);
778+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
754779
cur_time = current_time(new_dir);
755780
new_dir->i_atime = new_dir->i_mtime = cur_time;
756781
inode_set_ctime_to_ts(new_dir, cur_time);
@@ -769,7 +794,9 @@ static int simplefs_rename(struct inode *old_dir,
769794
goto release_new;
770795

771796
/* Update old parent inode metadata */
772-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
797+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
798+
simple_inode_init_ts(old_dir);
799+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(6, 6, 0)
773800
cur_time = current_time(old_dir);
774801
old_dir->i_atime = old_dir->i_mtime = cur_time;
775802
inode_set_ctime_to_ts(old_dir, cur_time);

super.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
#include <linux/statfs.h>
99

1010
#include "simplefs.h"
11-
11+
struct dentry *simplefs_mount(struct file_system_type *fs_type,
12+
int flags,
13+
const char *dev_name,
14+
void *data);
15+
void simplefs_kill_sb(struct super_block *sb);
1216
static struct kmem_cache *simplefs_inode_cache;
1317

1418
int simplefs_init_inode_cache(void)
@@ -78,8 +82,13 @@ static int simplefs_write_inode(struct inode *inode,
7882
disk_inode->i_ctime = inode->i_ctime.tv_sec;
7983
#endif
8084

85+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0)
86+
disk_inode->i_atime = inode_get_atime_sec(inode);
87+
disk_inode->i_atime = inode_get_mtime_sec(inode);
88+
#else
8189
disk_inode->i_atime = inode->i_atime.tv_sec;
8290
disk_inode->i_mtime = inode->i_mtime.tv_sec;
91+
#endif
8392
disk_inode->i_blocks = inode->i_blocks;
8493
disk_inode->i_nlink = inode->i_nlink;
8594
disk_inode->ei_block = ci->ei_block;

0 commit comments

Comments
 (0)