History

fs: Add uoff_t

In a recent commit, I inadvertently changed a comparison from being an unsigned comparison (on 64-bit systems) to being a signed comparison (which it had always been on 32-bit systems). This led to a sporadic fstests failure. To make sure this comparison is always unsigned, introduce a new type, uoff_t which is the unsigned version of loff_t. Generally file sizes are restricted to being a signed integer, but in these two places it is convenient to pass -1 to indicate "up to the end of the file".

Matthew Wilcox (Oracle) committed 11 months ago

Commit 37d369f1 parent a77a5956 files · +11 −9Browse files

Unified · Split

6 files
  1. include/linux/mm.h +4 −4
  2. include/linux/shmem_fs.h +1 −1
  3. include/linux/types.h +1 −0
  4. include/uapi/asm-generic/posix_types.h +1 −0
  5. mm/shmem.c +3 −3
  6. mm/truncate.c +1 −1
include/linux/mm.h+4−4
@@ -3495,10 +3495,10 @@ struct vm_unmapped_area_info { · 3494 unmodified lines
3495extern unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info);3495extern unsigned long vm_unmapped_area(struct vm_unmapped_area_info *info);
3496 3496
3497/* truncate.c */3497/* truncate.c */
3498extern void truncate_inode_pages(struct address_space *, loff_t);3498void truncate_inode_pages(struct address_space *mapping, loff_t lstart);
3499extern void truncate_inode_pages_range(struct address_space *,3499void truncate_inode_pages_range(struct address_space *mapping, loff_t lstart,
3500 loff_t lstart, loff_t lend);3500 uoff_t lend);
3501extern void truncate_inode_pages_final(struct address_space *);3501void truncate_inode_pages_final(struct address_space *mapping);
3502 3502
3503/* generic vm_area_ops exported for stackable file systems */3503/* generic vm_area_ops exported for stackable file systems */
3504extern vm_fault_t filemap_fault(struct vm_fault *vmf);3504extern vm_fault_t filemap_fault(struct vm_fault *vmf);
include/linux/shmem_fs.h+1−1
@@ -111,7 +111,7 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, · 110 unmodified lines
111 pgoff_t index, gfp_t gfp_mask);111 pgoff_t index, gfp_t gfp_mask);
112int shmem_writeout(struct folio *folio, struct swap_iocb **plug,112int shmem_writeout(struct folio *folio, struct swap_iocb **plug,
113 struct list_head *folio_list);113 struct list_head *folio_list);
114void shmem_truncate_range(struct inode *inode, loff_t start, loff_t end);114void shmem_truncate_range(struct inode *inode, loff_t start, uoff_t end);
115int shmem_unuse(unsigned int type);115int shmem_unuse(unsigned int type);
116 116
117#ifdef CONFIG_TRANSPARENT_HUGEPAGE117#ifdef CONFIG_TRANSPARENT_HUGEPAGE
include/linux/types.h+1−0
@@ -50,6 +50,7 @@ typedef __kernel_old_gid_t old_gid_t; · 49 unmodified lines
50 50
51#if defined(__GNUC__)51#if defined(__GNUC__)
52typedef __kernel_loff_t loff_t;52typedef __kernel_loff_t loff_t;
53typedef __kernel_uoff_t uoff_t;
53#endif54#endif
54 55
55/*56/*
include/uapi/asm-generic/posix_types.h+1−0
@@ -86,6 +86,7 @@ typedef struct { · 85 unmodified lines
86 */86 */
87typedef __kernel_long_t __kernel_off_t;87typedef __kernel_long_t __kernel_off_t;
88typedef long long __kernel_loff_t;88typedef long long __kernel_loff_t;
89typedef unsigned long long __kernel_uoff_t;
89typedef __kernel_long_t __kernel_old_time_t;90typedef __kernel_long_t __kernel_old_time_t;
90#ifndef __KERNEL__91#ifndef __KERNEL__
91typedef __kernel_long_t __kernel_time_t;92typedef __kernel_long_t __kernel_time_t;
mm/shmem.c+3−3
@@ -1076,7 +1076,7 @@ static struct folio *shmem_get_partial_folio(struct inode *inode, pgoff_t index) · 1075 unmodified lines
1076 * Remove range of pages and swap entries from page cache, and free them.1076 * Remove range of pages and swap entries from page cache, and free them.
1077 * If !unfalloc, truncate or punch hole; if unfalloc, undo failed fallocate.1077 * If !unfalloc, truncate or punch hole; if unfalloc, undo failed fallocate.
1078 */1078 */
1079static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend,1079static void shmem_undo_range(struct inode *inode, loff_t lstart, uoff_t lend,
1080 bool unfalloc)1080 bool unfalloc)
1081{1081{
1082 struct address_space *mapping = inode->i_mapping;1082 struct address_space *mapping = inode->i_mapping;
@@ -1227,7 +1227,7 @@ whole_folios: · 144 unmodified lines
1227 shmem_recalc_inode(inode, 0, -nr_swaps_freed);1227 shmem_recalc_inode(inode, 0, -nr_swaps_freed);
1228}1228}
1229 1229
1230void shmem_truncate_range(struct inode *inode, loff_t lstart, loff_t lend)1230void shmem_truncate_range(struct inode *inode, loff_t lstart, uoff_t lend)
1231{1231{
1232 shmem_undo_range(inode, lstart, lend, false);1232 shmem_undo_range(inode, lstart, lend, false);
1233 inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));1233 inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
@@ -5776,7 +5776,7 @@ unsigned long shmem_get_unmapped_area(struct file *file, · 4542 unmodified lines
5776}5776}
5777#endif5777#endif
5778 5778
5779void shmem_truncate_range(struct inode *inode, loff_t lstart, loff_t lend)5779void shmem_truncate_range(struct inode *inode, loff_t lstart, uoff_t lend)
5780{5780{
5781 truncate_inode_pages_range(inode->i_mapping, lstart, lend);5781 truncate_inode_pages_range(inode->i_mapping, lstart, lend);
5782}5782}
mm/truncate.c+1−1
@@ -339,7 +339,7 @@ long mapping_evict_folio(struct address_space *mapping, struct folio *folio) · 338 unmodified lines
339 * page aligned properly.339 * page aligned properly.
340 */340 */
341void truncate_inode_pages_range(struct address_space *mapping,341void truncate_inode_pages_range(struct address_space *mapping,
342 loff_t lstart, loff_t lend)342 loff_t lstart, uoff_t lend)
343{343{
344 pgoff_t start; /* inclusive */344 pgoff_t start; /* inclusive */
345 pgoff_t end; /* exclusive */345 pgoff_t end; /* exclusive */