Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'vfs-6.19-rc1.fs_header' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs

Pull fs header updates from Christian Brauner:
"This contains initial work to start splitting up fs.h.

Begin the long-overdue work of splitting up the monolithic fs.h
header. The header has grown to over 3000 lines and includes types and
functions for many different subsystems, making it difficult to
navigate and causing excessive compilation dependencies.

This series introduces new focused headers for superblock-related
code:

- Rename fs_types.h to fs_dirent.h to better reflect its actual
content (directory entry types)

- Add fs/super_types.h containing superblock type definitions

- Add fs/super.h containing superblock function declarations

This is the first step in a longer effort to modularize the VFS
headers.

Cleanups:

- Inode Field Layout Optimization (Mateusz Guzik)

Move inode fields used during fast path lookup closer together to
improve cache locality during path resolution.

- current_umask() Optimization (Mateusz Guzik)

Inline current_umask() and move it to fs_struct.h. This improves
performance by avoiding function call overhead for this
frequently-used function, and places it in a more appropriate
header since it operates on fs_struct"

* tag 'vfs-6.19-rc1.fs_header' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs:
fs: move inode fields used during fast path lookup closer together
fs: inline current_umask() and move it to fs_struct.h
fs: add fs/super.h header
fs: add fs/super_types.h header
fs: rename fs_types.h to fs_dirent.h

+601 -543
+1
fs/9p/acl.c
··· 6 6 7 7 #include <linux/module.h> 8 8 #include <linux/fs.h> 9 + #include <linux/fs_struct.h> 9 10 #include <net/9p/9p.h> 10 11 #include <net/9p/client.h> 11 12 #include <linux/slab.h>
+1 -1
fs/Makefile
··· 14 14 seq_file.o xattr.o libfs.o fs-writeback.o \ 15 15 pnode.o splice.o sync.o utimes.o d_path.o \ 16 16 stack.o fs_struct.o statfs.o fs_pin.o nsfs.o \ 17 - fs_types.o fs_context.o fs_parser.o fsopen.o init.o \ 17 + fs_dirent.o fs_context.o fs_parser.o fsopen.o init.o \ 18 18 kernel_read_file.o mnt_idmapping.o remap_range.o pidfs.o \ 19 19 file_attr.o 20 20
+1
fs/btrfs/inode.c
··· 9 9 #include <linux/blk-cgroup.h> 10 10 #include <linux/file.h> 11 11 #include <linux/fs.h> 12 + #include <linux/fs_struct.h> 12 13 #include <linux/pagemap.h> 13 14 #include <linux/highmem.h> 14 15 #include <linux/time.h>
+1
fs/f2fs/acl.c
··· 9 9 * 10 10 * Copyright (C) 2001-2003 Andreas Gruenbacher, <agruen@suse.de> 11 11 */ 12 + #include <linux/fs_struct.h> 12 13 #include <linux/f2fs_fs.h> 13 14 #include "f2fs.h" 14 15 #include "xattr.h"
+1
fs/fat/inode.c
··· 22 22 #include <linux/unaligned.h> 23 23 #include <linux/random.h> 24 24 #include <linux/iversion.h> 25 + #include <linux/fs_struct.h> 25 26 #include "fat.h" 26 27 27 28 #ifndef CONFIG_FAT_DEFAULT_IOCHARSET
-6
fs/fs_struct.c
··· 146 146 } 147 147 EXPORT_SYMBOL_GPL(unshare_fs_struct); 148 148 149 - int current_umask(void) 150 - { 151 - return current->fs->umask; 152 - } 153 - EXPORT_SYMBOL(current_umask); 154 - 155 149 /* to be mentioned only in INIT_TASK */ 156 150 struct fs_struct init_fs = { 157 151 .users = 1,
+1 -1
fs/fs_types.c fs/fs_dirent.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 - #include <linux/fs.h> 2 + #include <linux/fs_dirent.h> 3 3 #include <linux/export.h> 4 4 5 5 /*
+1
fs/hfsplus/options.c
··· 12 12 #include <linux/string.h> 13 13 #include <linux/kernel.h> 14 14 #include <linux/sched.h> 15 + #include <linux/fs_struct.h> 15 16 #include <linux/fs_context.h> 16 17 #include <linux/fs_parser.h> 17 18 #include <linux/nls.h>
+1
fs/hpfs/super.c
··· 9 9 10 10 #include "hpfs_fn.h" 11 11 #include <linux/module.h> 12 + #include <linux/fs_struct.h> 12 13 #include <linux/fs_context.h> 13 14 #include <linux/fs_parser.h> 14 15 #include <linux/init.h>
+1
fs/nilfs2/nilfs.h
··· 14 14 #include <linux/buffer_head.h> 15 15 #include <linux/spinlock.h> 16 16 #include <linux/blkdev.h> 17 + #include <linux/fs_struct.h> 17 18 #include <linux/nilfs2_api.h> 18 19 #include <linux/nilfs2_ondisk.h> 19 20 #include "the_nilfs.h"
+1
fs/ntfs3/super.c
··· 51 51 #include <linux/buffer_head.h> 52 52 #include <linux/exportfs.h> 53 53 #include <linux/fs.h> 54 + #include <linux/fs_struct.h> 54 55 #include <linux/fs_context.h> 55 56 #include <linux/fs_parser.h> 56 57 #include <linux/log2.h>
+1
fs/ocfs2/acl.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/slab.h> 15 15 #include <linux/string.h> 16 + #include <linux/fs_struct.h> 16 17 17 18 #include <cluster/masklog.h> 18 19
+1
fs/omfs/inode.c
··· 14 14 #include <linux/writeback.h> 15 15 #include <linux/seq_file.h> 16 16 #include <linux/crc-itu-t.h> 17 + #include <linux/fs_struct.h> 17 18 #include <linux/fs_context.h> 18 19 #include <linux/fs_parser.h> 19 20 #include "omfs.h"
+1
fs/smb/client/file.c
··· 9 9 * 10 10 */ 11 11 #include <linux/fs.h> 12 + #include <linux/fs_struct.h> 12 13 #include <linux/filelock.h> 13 14 #include <linux/backing-dev.h> 14 15 #include <linux/stat.h>
+1
fs/smb/client/inode.c
··· 6 6 * 7 7 */ 8 8 #include <linux/fs.h> 9 + #include <linux/fs_struct.h> 9 10 #include <linux/stat.h> 10 11 #include <linux/slab.h> 11 12 #include <linux/pagemap.h>
+1
fs/smb/client/smb1ops.c
··· 7 7 8 8 #include <linux/pagemap.h> 9 9 #include <linux/vfs.h> 10 + #include <linux/fs_struct.h> 10 11 #include <uapi/linux/magic.h> 11 12 #include "cifsglob.h" 12 13 #include "cifsproto.h"
+3 -531
include/linux/fs.h
··· 2 2 #ifndef _LINUX_FS_H 3 3 #define _LINUX_FS_H 4 4 5 + #include <linux/fs/super.h> 5 6 #include <linux/vfsdebug.h> 6 7 #include <linux/linkage.h> 7 8 #include <linux/wait_bit.h> ··· 12 11 #include <linux/stat.h> 13 12 #include <linux/cache.h> 14 13 #include <linux/list.h> 15 - #include <linux/list_lru.h> 16 14 #include <linux/llist.h> 17 15 #include <linux/radix-tree.h> 18 16 #include <linux/xarray.h> ··· 37 37 #include <linux/uuid.h> 38 38 #include <linux/errseq.h> 39 39 #include <linux/ioprio.h> 40 - #include <linux/fs_types.h> 41 40 #include <linux/build_bug.h> 42 41 #include <linux/stddef.h> 43 42 #include <linux/mount.h> ··· 51 52 #include <asm/byteorder.h> 52 53 #include <uapi/linux/fs.h> 53 54 54 - struct backing_dev_info; 55 55 struct bdi_writeback; 56 56 struct bio; 57 57 struct io_comp_batch; 58 - struct export_operations; 59 58 struct fiemap_extent_info; 60 59 struct hd_geometry; 61 60 struct iovec; ··· 67 70 struct cred; 68 71 struct swap_info_struct; 69 72 struct seq_file; 70 - struct workqueue_struct; 71 73 struct iov_iter; 72 - struct fscrypt_operations; 73 - struct fsverity_operations; 74 74 struct fsnotify_mark_connector; 75 - struct fsnotify_sb_info; 76 75 struct fs_context; 77 76 struct fs_parameter_spec; 78 77 struct file_kattr; ··· 290 297 */ 291 298 struct file *ia_file; 292 299 }; 293 - 294 - /* 295 - * Includes for diskquotas. 296 - */ 297 - #include <linux/quota.h> 298 300 299 301 /* 300 302 * Maximum number of layers of fs stack. Needs to be limited to ··· 764 776 struct inode { 765 777 umode_t i_mode; 766 778 unsigned short i_opflags; 767 - kuid_t i_uid; 768 - kgid_t i_gid; 769 779 unsigned int i_flags; 770 - 771 780 #ifdef CONFIG_FS_POSIX_ACL 772 781 struct posix_acl *i_acl; 773 782 struct posix_acl *i_default_acl; 774 783 #endif 784 + kuid_t i_uid; 785 + kgid_t i_gid; 775 786 776 787 const struct inode_operations *i_op; 777 788 struct super_block *i_sb; ··· 1394 1407 extern int send_sigurg(struct file *file); 1395 1408 1396 1409 /* 1397 - * sb->s_flags. Note that these mirror the equivalent MS_* flags where 1398 - * represented in both. 1399 - */ 1400 - #define SB_RDONLY BIT(0) /* Mount read-only */ 1401 - #define SB_NOSUID BIT(1) /* Ignore suid and sgid bits */ 1402 - #define SB_NODEV BIT(2) /* Disallow access to device special files */ 1403 - #define SB_NOEXEC BIT(3) /* Disallow program execution */ 1404 - #define SB_SYNCHRONOUS BIT(4) /* Writes are synced at once */ 1405 - #define SB_MANDLOCK BIT(6) /* Allow mandatory locks on an FS */ 1406 - #define SB_DIRSYNC BIT(7) /* Directory modifications are synchronous */ 1407 - #define SB_NOATIME BIT(10) /* Do not update access times. */ 1408 - #define SB_NODIRATIME BIT(11) /* Do not update directory access times */ 1409 - #define SB_SILENT BIT(15) 1410 - #define SB_POSIXACL BIT(16) /* Supports POSIX ACLs */ 1411 - #define SB_INLINECRYPT BIT(17) /* Use blk-crypto for encrypted files */ 1412 - #define SB_KERNMOUNT BIT(22) /* this is a kern_mount call */ 1413 - #define SB_I_VERSION BIT(23) /* Update inode I_version field */ 1414 - #define SB_LAZYTIME BIT(25) /* Update the on-disk [acm]times lazily */ 1415 - 1416 - /* These sb flags are internal to the kernel */ 1417 - #define SB_DEAD BIT(21) 1418 - #define SB_DYING BIT(24) 1419 - #define SB_FORCE BIT(27) 1420 - #define SB_NOSEC BIT(28) 1421 - #define SB_BORN BIT(29) 1422 - #define SB_ACTIVE BIT(30) 1423 - #define SB_NOUSER BIT(31) 1424 - 1425 - /* These flags relate to encoding and casefolding */ 1426 - #define SB_ENC_STRICT_MODE_FL (1 << 0) 1427 - #define SB_ENC_NO_COMPAT_FALLBACK_FL (1 << 1) 1428 - 1429 - #define sb_has_strict_encoding(sb) \ 1430 - (sb->s_encoding_flags & SB_ENC_STRICT_MODE_FL) 1431 - 1432 - #if IS_ENABLED(CONFIG_UNICODE) 1433 - #define sb_no_casefold_compat_fallback(sb) \ 1434 - (sb->s_encoding_flags & SB_ENC_NO_COMPAT_FALLBACK_FL) 1435 - #else 1436 - #define sb_no_casefold_compat_fallback(sb) (1) 1437 - #endif 1438 - 1439 - /* 1440 1410 * Umount options 1441 1411 */ 1442 1412 ··· 1402 1458 #define MNT_EXPIRE 0x00000004 /* Mark for expiry */ 1403 1459 #define UMOUNT_NOFOLLOW 0x00000008 /* Don't follow symlink on umount */ 1404 1460 #define UMOUNT_UNUSED 0x80000000 /* Flag guaranteed to be unused */ 1405 - 1406 - /* sb->s_iflags */ 1407 - #define SB_I_CGROUPWB 0x00000001 /* cgroup-aware writeback enabled */ 1408 - #define SB_I_NOEXEC 0x00000002 /* Ignore executables on this fs */ 1409 - #define SB_I_NODEV 0x00000004 /* Ignore devices on this fs */ 1410 - #define SB_I_STABLE_WRITES 0x00000008 /* don't modify blks until WB is done */ 1411 - 1412 - /* sb->s_iflags to limit user namespace mounts */ 1413 - #define SB_I_USERNS_VISIBLE 0x00000010 /* fstype already mounted */ 1414 - #define SB_I_IMA_UNVERIFIABLE_SIGNATURE 0x00000020 1415 - #define SB_I_UNTRUSTED_MOUNTER 0x00000040 1416 - #define SB_I_EVM_HMAC_UNSUPPORTED 0x00000080 1417 - 1418 - #define SB_I_SKIP_SYNC 0x00000100 /* Skip superblock at global sync */ 1419 - #define SB_I_PERSB_BDI 0x00000200 /* has a per-sb bdi */ 1420 - #define SB_I_TS_EXPIRY_WARNED 0x00000400 /* warned about timestamp range expiry */ 1421 - #define SB_I_RETIRED 0x00000800 /* superblock shouldn't be reused */ 1422 - #define SB_I_NOUMASK 0x00001000 /* VFS does not apply umask */ 1423 - #define SB_I_NOIDMAP 0x00002000 /* No idmapped mounts on this superblock */ 1424 - #define SB_I_ALLOW_HSM 0x00004000 /* Allow HSM events on this superblock */ 1425 - 1426 - /* Possible states of 'frozen' field */ 1427 - enum { 1428 - SB_UNFROZEN = 0, /* FS is unfrozen */ 1429 - SB_FREEZE_WRITE = 1, /* Writes, dir ops, ioctls frozen */ 1430 - SB_FREEZE_PAGEFAULT = 2, /* Page faults stopped as well */ 1431 - SB_FREEZE_FS = 3, /* For internal FS use (e.g. to stop 1432 - * internal threads if needed) */ 1433 - SB_FREEZE_COMPLETE = 4, /* ->freeze_fs finished successfully */ 1434 - }; 1435 - 1436 - #define SB_FREEZE_LEVELS (SB_FREEZE_COMPLETE - 1) 1437 - 1438 - struct sb_writers { 1439 - unsigned short frozen; /* Is sb frozen? */ 1440 - int freeze_kcount; /* How many kernel freeze requests? */ 1441 - int freeze_ucount; /* How many userspace freeze requests? */ 1442 - const void *freeze_owner; /* Owner of the freeze */ 1443 - struct percpu_rw_semaphore rw_sem[SB_FREEZE_LEVELS]; 1444 - }; 1445 - 1446 - struct mount; 1447 - 1448 - struct super_block { 1449 - struct list_head s_list; /* Keep this first */ 1450 - dev_t s_dev; /* search index; _not_ kdev_t */ 1451 - unsigned char s_blocksize_bits; 1452 - unsigned long s_blocksize; 1453 - loff_t s_maxbytes; /* Max file size */ 1454 - struct file_system_type *s_type; 1455 - const struct super_operations *s_op; 1456 - const struct dquot_operations *dq_op; 1457 - const struct quotactl_ops *s_qcop; 1458 - const struct export_operations *s_export_op; 1459 - unsigned long s_flags; 1460 - unsigned long s_iflags; /* internal SB_I_* flags */ 1461 - unsigned long s_magic; 1462 - struct dentry *s_root; 1463 - struct rw_semaphore s_umount; 1464 - int s_count; 1465 - atomic_t s_active; 1466 - #ifdef CONFIG_SECURITY 1467 - void *s_security; 1468 - #endif 1469 - const struct xattr_handler * const *s_xattr; 1470 - #ifdef CONFIG_FS_ENCRYPTION 1471 - const struct fscrypt_operations *s_cop; 1472 - struct fscrypt_keyring *s_master_keys; /* master crypto keys in use */ 1473 - #endif 1474 - #ifdef CONFIG_FS_VERITY 1475 - const struct fsverity_operations *s_vop; 1476 - #endif 1477 - #if IS_ENABLED(CONFIG_UNICODE) 1478 - struct unicode_map *s_encoding; 1479 - __u16 s_encoding_flags; 1480 - #endif 1481 - struct hlist_bl_head s_roots; /* alternate root dentries for NFS */ 1482 - struct mount *s_mounts; /* list of mounts; _not_ for fs use */ 1483 - struct block_device *s_bdev; /* can go away once we use an accessor for @s_bdev_file */ 1484 - struct file *s_bdev_file; 1485 - struct backing_dev_info *s_bdi; 1486 - struct mtd_info *s_mtd; 1487 - struct hlist_node s_instances; 1488 - unsigned int s_quota_types; /* Bitmask of supported quota types */ 1489 - struct quota_info s_dquot; /* Diskquota specific options */ 1490 - 1491 - struct sb_writers s_writers; 1492 - 1493 - /* 1494 - * Keep s_fs_info, s_time_gran, s_fsnotify_mask, and 1495 - * s_fsnotify_info together for cache efficiency. They are frequently 1496 - * accessed and rarely modified. 1497 - */ 1498 - void *s_fs_info; /* Filesystem private info */ 1499 - 1500 - /* Granularity of c/m/atime in ns (cannot be worse than a second) */ 1501 - u32 s_time_gran; 1502 - /* Time limits for c/m/atime in seconds */ 1503 - time64_t s_time_min; 1504 - time64_t s_time_max; 1505 - #ifdef CONFIG_FSNOTIFY 1506 - u32 s_fsnotify_mask; 1507 - struct fsnotify_sb_info *s_fsnotify_info; 1508 - #endif 1509 - 1510 - /* 1511 - * q: why are s_id and s_sysfs_name not the same? both are human 1512 - * readable strings that identify the filesystem 1513 - * a: s_id is allowed to change at runtime; it's used in log messages, 1514 - * and we want to when a device starts out as single device (s_id is dev 1515 - * name) but then a device is hot added and we have to switch to 1516 - * identifying it by UUID 1517 - * but s_sysfs_name is a handle for programmatic access, and can't 1518 - * change at runtime 1519 - */ 1520 - char s_id[32]; /* Informational name */ 1521 - uuid_t s_uuid; /* UUID */ 1522 - u8 s_uuid_len; /* Default 16, possibly smaller for weird filesystems */ 1523 - 1524 - /* if set, fs shows up under sysfs at /sys/fs/$FSTYP/s_sysfs_name */ 1525 - char s_sysfs_name[UUID_STRING_LEN + 1]; 1526 - 1527 - unsigned int s_max_links; 1528 - unsigned int s_d_flags; /* default d_flags for dentries */ 1529 - 1530 - /* 1531 - * The next field is for VFS *only*. No filesystems have any business 1532 - * even looking at it. You had been warned. 1533 - */ 1534 - struct mutex s_vfs_rename_mutex; /* Kludge */ 1535 - 1536 - /* 1537 - * Filesystem subtype. If non-empty the filesystem type field 1538 - * in /proc/mounts will be "type.subtype" 1539 - */ 1540 - const char *s_subtype; 1541 - 1542 - const struct dentry_operations *__s_d_op; /* default d_op for dentries */ 1543 - 1544 - struct shrinker *s_shrink; /* per-sb shrinker handle */ 1545 - 1546 - /* Number of inodes with nlink == 0 but still referenced */ 1547 - atomic_long_t s_remove_count; 1548 - 1549 - /* Read-only state of the superblock is being changed */ 1550 - int s_readonly_remount; 1551 - 1552 - /* per-sb errseq_t for reporting writeback errors via syncfs */ 1553 - errseq_t s_wb_err; 1554 - 1555 - /* AIO completions deferred from interrupt context */ 1556 - struct workqueue_struct *s_dio_done_wq; 1557 - struct hlist_head s_pins; 1558 - 1559 - /* 1560 - * Owning user namespace and default context in which to 1561 - * interpret filesystem uids, gids, quotas, device nodes, 1562 - * xattrs and security labels. 1563 - */ 1564 - struct user_namespace *s_user_ns; 1565 - 1566 - /* 1567 - * The list_lru structure is essentially just a pointer to a table 1568 - * of per-node lru lists, each of which has its own spinlock. 1569 - * There is no need to put them into separate cachelines. 1570 - */ 1571 - struct list_lru s_dentry_lru; 1572 - struct list_lru s_inode_lru; 1573 - struct rcu_head rcu; 1574 - struct work_struct destroy_work; 1575 - 1576 - struct mutex s_sync_lock; /* sync serialisation lock */ 1577 - 1578 - /* 1579 - * Indicates how deep in a filesystem stack this SB is 1580 - */ 1581 - int s_stack_depth; 1582 - 1583 - /* s_inode_list_lock protects s_inodes */ 1584 - spinlock_t s_inode_list_lock ____cacheline_aligned_in_smp; 1585 - struct list_head s_inodes; /* all inodes */ 1586 - 1587 - spinlock_t s_inode_wblist_lock; 1588 - struct list_head s_inodes_wb; /* writeback inodes */ 1589 - long s_min_writeback_pages; 1590 - } __randomize_layout; 1591 1461 1592 1462 static inline struct user_namespace *i_user_ns(const struct inode *inode) 1593 1463 { ··· 1720 1962 * Snapshotting support. 1721 1963 */ 1722 1964 1723 - /* 1724 - * These are internal functions, please use sb_start_{write,pagefault,intwrite} 1725 - * instead. 1726 - */ 1727 - static inline void __sb_end_write(struct super_block *sb, int level) 1728 - { 1729 - percpu_up_read(sb->s_writers.rw_sem + level-1); 1730 - } 1731 - 1732 - static inline void __sb_start_write(struct super_block *sb, int level) 1733 - { 1734 - percpu_down_read_freezable(sb->s_writers.rw_sem + level - 1, true); 1735 - } 1736 - 1737 - static inline bool __sb_start_write_trylock(struct super_block *sb, int level) 1738 - { 1739 - return percpu_down_read_trylock(sb->s_writers.rw_sem + level - 1); 1740 - } 1741 - 1742 - #define __sb_writers_acquired(sb, lev) \ 1743 - percpu_rwsem_acquire(&(sb)->s_writers.rw_sem[(lev)-1], 1, _THIS_IP_) 1744 - #define __sb_writers_release(sb, lev) \ 1745 - percpu_rwsem_release(&(sb)->s_writers.rw_sem[(lev)-1], _THIS_IP_) 1746 - 1747 - /** 1748 - * __sb_write_started - check if sb freeze level is held 1749 - * @sb: the super we write to 1750 - * @level: the freeze level 1751 - * 1752 - * * > 0 - sb freeze level is held 1753 - * * 0 - sb freeze level is not held 1754 - * * < 0 - !CONFIG_LOCKDEP/LOCK_STATE_UNKNOWN 1755 - */ 1756 - static inline int __sb_write_started(const struct super_block *sb, int level) 1757 - { 1758 - return lockdep_is_held_type(sb->s_writers.rw_sem + level - 1, 1); 1759 - } 1760 - 1761 - /** 1762 - * sb_write_started - check if SB_FREEZE_WRITE is held 1763 - * @sb: the super we write to 1764 - * 1765 - * May be false positive with !CONFIG_LOCKDEP/LOCK_STATE_UNKNOWN. 1766 - */ 1767 - static inline bool sb_write_started(const struct super_block *sb) 1768 - { 1769 - return __sb_write_started(sb, SB_FREEZE_WRITE); 1770 - } 1771 - 1772 - /** 1773 - * sb_write_not_started - check if SB_FREEZE_WRITE is not held 1774 - * @sb: the super we write to 1775 - * 1776 - * May be false positive with !CONFIG_LOCKDEP/LOCK_STATE_UNKNOWN. 1777 - */ 1778 - static inline bool sb_write_not_started(const struct super_block *sb) 1779 - { 1780 - return __sb_write_started(sb, SB_FREEZE_WRITE) <= 0; 1781 - } 1782 - 1783 1965 /** 1784 1966 * file_write_started - check if SB_FREEZE_WRITE is held 1785 1967 * @file: the file we write to ··· 1748 2050 if (!S_ISREG(file_inode(file)->i_mode)) 1749 2051 return true; 1750 2052 return sb_write_not_started(file_inode(file)->i_sb); 1751 - } 1752 - 1753 - /** 1754 - * sb_end_write - drop write access to a superblock 1755 - * @sb: the super we wrote to 1756 - * 1757 - * Decrement number of writers to the filesystem. Wake up possible waiters 1758 - * wanting to freeze the filesystem. 1759 - */ 1760 - static inline void sb_end_write(struct super_block *sb) 1761 - { 1762 - __sb_end_write(sb, SB_FREEZE_WRITE); 1763 - } 1764 - 1765 - /** 1766 - * sb_end_pagefault - drop write access to a superblock from a page fault 1767 - * @sb: the super we wrote to 1768 - * 1769 - * Decrement number of processes handling write page fault to the filesystem. 1770 - * Wake up possible waiters wanting to freeze the filesystem. 1771 - */ 1772 - static inline void sb_end_pagefault(struct super_block *sb) 1773 - { 1774 - __sb_end_write(sb, SB_FREEZE_PAGEFAULT); 1775 - } 1776 - 1777 - /** 1778 - * sb_end_intwrite - drop write access to a superblock for internal fs purposes 1779 - * @sb: the super we wrote to 1780 - * 1781 - * Decrement fs-internal number of writers to the filesystem. Wake up possible 1782 - * waiters wanting to freeze the filesystem. 1783 - */ 1784 - static inline void sb_end_intwrite(struct super_block *sb) 1785 - { 1786 - __sb_end_write(sb, SB_FREEZE_FS); 1787 - } 1788 - 1789 - /** 1790 - * sb_start_write - get write access to a superblock 1791 - * @sb: the super we write to 1792 - * 1793 - * When a process wants to write data or metadata to a file system (i.e. dirty 1794 - * a page or an inode), it should embed the operation in a sb_start_write() - 1795 - * sb_end_write() pair to get exclusion against file system freezing. This 1796 - * function increments number of writers preventing freezing. If the file 1797 - * system is already frozen, the function waits until the file system is 1798 - * thawed. 1799 - * 1800 - * Since freeze protection behaves as a lock, users have to preserve 1801 - * ordering of freeze protection and other filesystem locks. Generally, 1802 - * freeze protection should be the outermost lock. In particular, we have: 1803 - * 1804 - * sb_start_write 1805 - * -> i_rwsem (write path, truncate, directory ops, ...) 1806 - * -> s_umount (freeze_super, thaw_super) 1807 - */ 1808 - static inline void sb_start_write(struct super_block *sb) 1809 - { 1810 - __sb_start_write(sb, SB_FREEZE_WRITE); 1811 - } 1812 - 1813 - static inline bool sb_start_write_trylock(struct super_block *sb) 1814 - { 1815 - return __sb_start_write_trylock(sb, SB_FREEZE_WRITE); 1816 - } 1817 - 1818 - /** 1819 - * sb_start_pagefault - get write access to a superblock from a page fault 1820 - * @sb: the super we write to 1821 - * 1822 - * When a process starts handling write page fault, it should embed the 1823 - * operation into sb_start_pagefault() - sb_end_pagefault() pair to get 1824 - * exclusion against file system freezing. This is needed since the page fault 1825 - * is going to dirty a page. This function increments number of running page 1826 - * faults preventing freezing. If the file system is already frozen, the 1827 - * function waits until the file system is thawed. 1828 - * 1829 - * Since page fault freeze protection behaves as a lock, users have to preserve 1830 - * ordering of freeze protection and other filesystem locks. It is advised to 1831 - * put sb_start_pagefault() close to mmap_lock in lock ordering. Page fault 1832 - * handling code implies lock dependency: 1833 - * 1834 - * mmap_lock 1835 - * -> sb_start_pagefault 1836 - */ 1837 - static inline void sb_start_pagefault(struct super_block *sb) 1838 - { 1839 - __sb_start_write(sb, SB_FREEZE_PAGEFAULT); 1840 - } 1841 - 1842 - /** 1843 - * sb_start_intwrite - get write access to a superblock for internal fs purposes 1844 - * @sb: the super we write to 1845 - * 1846 - * This is the third level of protection against filesystem freezing. It is 1847 - * free for use by a filesystem. The only requirement is that it must rank 1848 - * below sb_start_pagefault. 1849 - * 1850 - * For example filesystem can call sb_start_intwrite() when starting a 1851 - * transaction which somewhat eases handling of freezing for internal sources 1852 - * of filesystem changes (internal fs threads, discarding preallocation on file 1853 - * close, etc.). 1854 - */ 1855 - static inline void sb_start_intwrite(struct super_block *sb) 1856 - { 1857 - __sb_start_write(sb, SB_FREEZE_FS); 1858 - } 1859 - 1860 - static inline bool sb_start_intwrite_trylock(struct super_block *sb) 1861 - { 1862 - return __sb_start_write_trylock(sb, SB_FREEZE_FS); 1863 2053 } 1864 2054 1865 2055 bool inode_owner_or_capable(struct mnt_idmap *idmap, ··· 2077 2491 struct file *dst_file, loff_t dst_pos, 2078 2492 loff_t len, unsigned int remap_flags); 2079 2493 2080 - /** 2081 - * enum freeze_holder - holder of the freeze 2082 - * @FREEZE_HOLDER_KERNEL: kernel wants to freeze or thaw filesystem 2083 - * @FREEZE_HOLDER_USERSPACE: userspace wants to freeze or thaw filesystem 2084 - * @FREEZE_MAY_NEST: whether nesting freeze and thaw requests is allowed 2085 - * @FREEZE_EXCL: a freeze that can only be undone by the owner 2086 - * 2087 - * Indicate who the owner of the freeze or thaw request is and whether 2088 - * the freeze needs to be exclusive or can nest. 2089 - * Without @FREEZE_MAY_NEST, multiple freeze and thaw requests from the 2090 - * same holder aren't allowed. It is however allowed to hold a single 2091 - * @FREEZE_HOLDER_USERSPACE and a single @FREEZE_HOLDER_KERNEL freeze at 2092 - * the same time. This is relied upon by some filesystems during online 2093 - * repair or similar. 2094 - */ 2095 - enum freeze_holder { 2096 - FREEZE_HOLDER_KERNEL = (1U << 0), 2097 - FREEZE_HOLDER_USERSPACE = (1U << 1), 2098 - FREEZE_MAY_NEST = (1U << 2), 2099 - FREEZE_EXCL = (1U << 3), 2100 - }; 2101 - 2102 - struct super_operations { 2103 - struct inode *(*alloc_inode)(struct super_block *sb); 2104 - void (*destroy_inode)(struct inode *); 2105 - void (*free_inode)(struct inode *); 2106 - 2107 - void (*dirty_inode) (struct inode *, int flags); 2108 - int (*write_inode) (struct inode *, struct writeback_control *wbc); 2109 - int (*drop_inode) (struct inode *); 2110 - void (*evict_inode) (struct inode *); 2111 - void (*put_super) (struct super_block *); 2112 - int (*sync_fs)(struct super_block *sb, int wait); 2113 - int (*freeze_super) (struct super_block *, enum freeze_holder who, const void *owner); 2114 - int (*freeze_fs) (struct super_block *); 2115 - int (*thaw_super) (struct super_block *, enum freeze_holder who, const void *owner); 2116 - int (*unfreeze_fs) (struct super_block *); 2117 - int (*statfs) (struct dentry *, struct kstatfs *); 2118 - int (*remount_fs) (struct super_block *, int *, char *); 2119 - void (*umount_begin) (struct super_block *); 2120 - 2121 - int (*show_options)(struct seq_file *, struct dentry *); 2122 - int (*show_devname)(struct seq_file *, struct dentry *); 2123 - int (*show_path)(struct seq_file *, struct dentry *); 2124 - int (*show_stats)(struct seq_file *, struct dentry *); 2125 - #ifdef CONFIG_QUOTA 2126 - ssize_t (*quota_read)(struct super_block *, int, char *, size_t, loff_t); 2127 - ssize_t (*quota_write)(struct super_block *, int, const char *, size_t, loff_t); 2128 - struct dquot __rcu **(*get_dquots)(struct inode *); 2129 - #endif 2130 - long (*nr_cached_objects)(struct super_block *, 2131 - struct shrink_control *); 2132 - long (*free_cached_objects)(struct super_block *, 2133 - struct shrink_control *); 2134 - /* 2135 - * If a filesystem can support graceful removal of a device and 2136 - * continue read-write operations, implement this callback. 2137 - * 2138 - * Return 0 if the filesystem can continue read-write. 2139 - * Non-zero return value or no such callback means the fs will be shutdown 2140 - * as usual. 2141 - */ 2142 - int (*remove_bdev)(struct super_block *sb, struct block_device *bdev); 2143 - void (*shutdown)(struct super_block *sb); 2144 - }; 2145 - 2146 2494 /* 2147 2495 * Inode flags - they have no relation to superblock flags now 2148 2496 */ ··· 2119 2599 */ 2120 2600 #define __IS_FLG(inode, flg) ((inode)->i_sb->s_flags & (flg)) 2121 2601 2122 - static inline bool sb_rdonly(const struct super_block *sb) { return sb->s_flags & SB_RDONLY; } 2123 2602 #define IS_RDONLY(inode) sb_rdonly((inode)->i_sb) 2124 2603 #define IS_SYNC(inode) (__IS_FLG(inode, SB_SYNCHRONOUS) || \ 2125 2604 ((inode)->i_flags & S_SYNC)) ··· 2353 2834 extern int vfs_statfs(const struct path *, struct kstatfs *); 2354 2835 extern int user_statfs(const char __user *, struct kstatfs *); 2355 2836 extern int fd_statfs(int, struct kstatfs *); 2356 - int freeze_super(struct super_block *super, enum freeze_holder who, 2357 - const void *freeze_owner); 2358 - int thaw_super(struct super_block *super, enum freeze_holder who, 2359 - const void *freeze_owner); 2360 2837 extern __printf(2, 3) 2361 2838 int super_setup_bdi_name(struct super_block *sb, char *fmt, ...); 2362 2839 extern int super_setup_bdi(struct super_block *sb); ··· 2394 2879 vsnprintf(sb->s_sysfs_name, sizeof(sb->s_sysfs_name), fmt, args); 2395 2880 va_end(args); 2396 2881 } 2397 - 2398 - extern int current_umask(void); 2399 2882 2400 2883 extern void ihold(struct inode * inode); 2401 2884 extern void iput(struct inode *); ··· 2537 3024 2538 3025 #define __getname() kmem_cache_alloc(names_cachep, GFP_KERNEL) 2539 3026 #define __putname(name) kmem_cache_free(names_cachep, (void *)(name)) 2540 - 2541 - extern struct super_block *blockdev_superblock; 2542 - static inline bool sb_is_blkdev_sb(struct super_block *sb) 2543 - { 2544 - return IS_ENABLED(CONFIG_BLOCK) && sb == blockdev_superblock; 2545 - } 2546 3027 2547 3028 void emergency_thaw_all(void); 2548 3029 extern int sync_filesystem(struct super_block *); ··· 2990 3483 extern void inode_sb_list_add(struct inode *inode); 2991 3484 extern void inode_lru_list_add(struct inode *inode); 2992 3485 2993 - int sb_set_blocksize(struct super_block *sb, int size); 2994 - int __must_check sb_min_blocksize(struct super_block *sb, int size); 2995 - 2996 3486 int generic_file_mmap(struct file *, struct vm_area_struct *); 2997 3487 int generic_file_mmap_prepare(struct vm_area_desc *desc); 2998 3488 int generic_file_readonly_mmap(struct file *, struct vm_area_struct *); ··· 3308 3804 return true; 3309 3805 } 3310 3806 #endif 3311 - 3312 - static inline struct unicode_map *sb_encoding(const struct super_block *sb) 3313 - { 3314 - #if IS_ENABLED(CONFIG_UNICODE) 3315 - return sb->s_encoding; 3316 - #else 3317 - return NULL; 3318 - #endif 3319 - } 3320 - 3321 - static inline bool sb_has_encoding(const struct super_block *sb) 3322 - { 3323 - return !!sb_encoding(sb); 3324 - } 3325 - 3326 - /* 3327 - * Compare if two super blocks have the same encoding and flags 3328 - */ 3329 - static inline bool sb_same_encoding(const struct super_block *sb1, 3330 - const struct super_block *sb2) 3331 - { 3332 - #if IS_ENABLED(CONFIG_UNICODE) 3333 - if (sb1->s_encoding == sb2->s_encoding) 3334 - return true; 3335 - 3336 - return (sb1->s_encoding && sb2->s_encoding && 3337 - (sb1->s_encoding->version == sb2->s_encoding->version) && 3338 - (sb1->s_encoding_flags == sb2->s_encoding_flags)); 3339 - #else 3340 - return true; 3341 - #endif 3342 - } 3343 3807 3344 3808 int may_setattr(struct mnt_idmap *idmap, struct inode *inode, 3345 3809 unsigned int ia_valid);
+233
include/linux/fs/super.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _LINUX_FS_SUPER_H 3 + #define _LINUX_FS_SUPER_H 4 + 5 + #include <linux/fs/super_types.h> 6 + #include <linux/unicode.h> 7 + 8 + /* 9 + * These are internal functions, please use sb_start_{write,pagefault,intwrite} 10 + * instead. 11 + */ 12 + static inline void __sb_end_write(struct super_block *sb, int level) 13 + { 14 + percpu_up_read(sb->s_writers.rw_sem + level - 1); 15 + } 16 + 17 + static inline void __sb_start_write(struct super_block *sb, int level) 18 + { 19 + percpu_down_read_freezable(sb->s_writers.rw_sem + level - 1, true); 20 + } 21 + 22 + static inline bool __sb_start_write_trylock(struct super_block *sb, int level) 23 + { 24 + return percpu_down_read_trylock(sb->s_writers.rw_sem + level - 1); 25 + } 26 + 27 + #define __sb_writers_acquired(sb, lev) \ 28 + percpu_rwsem_acquire(&(sb)->s_writers.rw_sem[(lev) - 1], 1, _THIS_IP_) 29 + #define __sb_writers_release(sb, lev) \ 30 + percpu_rwsem_release(&(sb)->s_writers.rw_sem[(lev) - 1], _THIS_IP_) 31 + 32 + /** 33 + * __sb_write_started - check if sb freeze level is held 34 + * @sb: the super we write to 35 + * @level: the freeze level 36 + * 37 + * * > 0 - sb freeze level is held 38 + * * 0 - sb freeze level is not held 39 + * * < 0 - !CONFIG_LOCKDEP/LOCK_STATE_UNKNOWN 40 + */ 41 + static inline int __sb_write_started(const struct super_block *sb, int level) 42 + { 43 + return lockdep_is_held_type(sb->s_writers.rw_sem + level - 1, 1); 44 + } 45 + 46 + /** 47 + * sb_write_started - check if SB_FREEZE_WRITE is held 48 + * @sb: the super we write to 49 + * 50 + * May be false positive with !CONFIG_LOCKDEP/LOCK_STATE_UNKNOWN. 51 + */ 52 + static inline bool sb_write_started(const struct super_block *sb) 53 + { 54 + return __sb_write_started(sb, SB_FREEZE_WRITE); 55 + } 56 + 57 + /** 58 + * sb_write_not_started - check if SB_FREEZE_WRITE is not held 59 + * @sb: the super we write to 60 + * 61 + * May be false positive with !CONFIG_LOCKDEP/LOCK_STATE_UNKNOWN. 62 + */ 63 + static inline bool sb_write_not_started(const struct super_block *sb) 64 + { 65 + return __sb_write_started(sb, SB_FREEZE_WRITE) <= 0; 66 + } 67 + 68 + /** 69 + * sb_end_write - drop write access to a superblock 70 + * @sb: the super we wrote to 71 + * 72 + * Decrement number of writers to the filesystem. Wake up possible waiters 73 + * wanting to freeze the filesystem. 74 + */ 75 + static inline void sb_end_write(struct super_block *sb) 76 + { 77 + __sb_end_write(sb, SB_FREEZE_WRITE); 78 + } 79 + 80 + /** 81 + * sb_end_pagefault - drop write access to a superblock from a page fault 82 + * @sb: the super we wrote to 83 + * 84 + * Decrement number of processes handling write page fault to the filesystem. 85 + * Wake up possible waiters wanting to freeze the filesystem. 86 + */ 87 + static inline void sb_end_pagefault(struct super_block *sb) 88 + { 89 + __sb_end_write(sb, SB_FREEZE_PAGEFAULT); 90 + } 91 + 92 + /** 93 + * sb_end_intwrite - drop write access to a superblock for internal fs purposes 94 + * @sb: the super we wrote to 95 + * 96 + * Decrement fs-internal number of writers to the filesystem. Wake up possible 97 + * waiters wanting to freeze the filesystem. 98 + */ 99 + static inline void sb_end_intwrite(struct super_block *sb) 100 + { 101 + __sb_end_write(sb, SB_FREEZE_FS); 102 + } 103 + 104 + /** 105 + * sb_start_write - get write access to a superblock 106 + * @sb: the super we write to 107 + * 108 + * When a process wants to write data or metadata to a file system (i.e. dirty 109 + * a page or an inode), it should embed the operation in a sb_start_write() - 110 + * sb_end_write() pair to get exclusion against file system freezing. This 111 + * function increments number of writers preventing freezing. If the file 112 + * system is already frozen, the function waits until the file system is 113 + * thawed. 114 + * 115 + * Since freeze protection behaves as a lock, users have to preserve 116 + * ordering of freeze protection and other filesystem locks. Generally, 117 + * freeze protection should be the outermost lock. In particular, we have: 118 + * 119 + * sb_start_write 120 + * -> i_rwsem (write path, truncate, directory ops, ...) 121 + * -> s_umount (freeze_super, thaw_super) 122 + */ 123 + static inline void sb_start_write(struct super_block *sb) 124 + { 125 + __sb_start_write(sb, SB_FREEZE_WRITE); 126 + } 127 + 128 + static inline bool sb_start_write_trylock(struct super_block *sb) 129 + { 130 + return __sb_start_write_trylock(sb, SB_FREEZE_WRITE); 131 + } 132 + 133 + /** 134 + * sb_start_pagefault - get write access to a superblock from a page fault 135 + * @sb: the super we write to 136 + * 137 + * When a process starts handling write page fault, it should embed the 138 + * operation into sb_start_pagefault() - sb_end_pagefault() pair to get 139 + * exclusion against file system freezing. This is needed since the page fault 140 + * is going to dirty a page. This function increments number of running page 141 + * faults preventing freezing. If the file system is already frozen, the 142 + * function waits until the file system is thawed. 143 + * 144 + * Since page fault freeze protection behaves as a lock, users have to preserve 145 + * ordering of freeze protection and other filesystem locks. It is advised to 146 + * put sb_start_pagefault() close to mmap_lock in lock ordering. Page fault 147 + * handling code implies lock dependency: 148 + * 149 + * mmap_lock 150 + * -> sb_start_pagefault 151 + */ 152 + static inline void sb_start_pagefault(struct super_block *sb) 153 + { 154 + __sb_start_write(sb, SB_FREEZE_PAGEFAULT); 155 + } 156 + 157 + /** 158 + * sb_start_intwrite - get write access to a superblock for internal fs purposes 159 + * @sb: the super we write to 160 + * 161 + * This is the third level of protection against filesystem freezing. It is 162 + * free for use by a filesystem. The only requirement is that it must rank 163 + * below sb_start_pagefault. 164 + * 165 + * For example filesystem can call sb_start_intwrite() when starting a 166 + * transaction which somewhat eases handling of freezing for internal sources 167 + * of filesystem changes (internal fs threads, discarding preallocation on file 168 + * close, etc.). 169 + */ 170 + static inline void sb_start_intwrite(struct super_block *sb) 171 + { 172 + __sb_start_write(sb, SB_FREEZE_FS); 173 + } 174 + 175 + static inline bool sb_start_intwrite_trylock(struct super_block *sb) 176 + { 177 + return __sb_start_write_trylock(sb, SB_FREEZE_FS); 178 + } 179 + 180 + static inline bool sb_rdonly(const struct super_block *sb) 181 + { 182 + return sb->s_flags & SB_RDONLY; 183 + } 184 + 185 + static inline bool sb_is_blkdev_sb(struct super_block *sb) 186 + { 187 + return IS_ENABLED(CONFIG_BLOCK) && sb == blockdev_superblock; 188 + } 189 + 190 + #if IS_ENABLED(CONFIG_UNICODE) 191 + static inline struct unicode_map *sb_encoding(const struct super_block *sb) 192 + { 193 + return sb->s_encoding; 194 + } 195 + 196 + /* Compare if two super blocks have the same encoding and flags */ 197 + static inline bool sb_same_encoding(const struct super_block *sb1, 198 + const struct super_block *sb2) 199 + { 200 + if (sb1->s_encoding == sb2->s_encoding) 201 + return true; 202 + 203 + return (sb1->s_encoding && sb2->s_encoding && 204 + (sb1->s_encoding->version == sb2->s_encoding->version) && 205 + (sb1->s_encoding_flags == sb2->s_encoding_flags)); 206 + } 207 + #else 208 + static inline struct unicode_map *sb_encoding(const struct super_block *sb) 209 + { 210 + return NULL; 211 + } 212 + 213 + static inline bool sb_same_encoding(const struct super_block *sb1, 214 + const struct super_block *sb2) 215 + { 216 + return true; 217 + } 218 + #endif 219 + 220 + static inline bool sb_has_encoding(const struct super_block *sb) 221 + { 222 + return !!sb_encoding(sb); 223 + } 224 + 225 + int sb_set_blocksize(struct super_block *sb, int size); 226 + int __must_check sb_min_blocksize(struct super_block *sb, int size); 227 + 228 + int freeze_super(struct super_block *super, enum freeze_holder who, 229 + const void *freeze_owner); 230 + int thaw_super(struct super_block *super, enum freeze_holder who, 231 + const void *freeze_owner); 232 + 233 + #endif /* _LINUX_FS_SUPER_H */
+336
include/linux/fs/super_types.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _LINUX_FS_SUPER_TYPES_H 3 + #define _LINUX_FS_SUPER_TYPES_H 4 + 5 + #include <linux/fs_dirent.h> 6 + #include <linux/errseq.h> 7 + #include <linux/list_lru.h> 8 + #include <linux/list.h> 9 + #include <linux/list_bl.h> 10 + #include <linux/llist.h> 11 + #include <linux/uidgid.h> 12 + #include <linux/uuid.h> 13 + #include <linux/percpu-rwsem.h> 14 + #include <linux/workqueue_types.h> 15 + #include <linux/quota.h> 16 + 17 + struct backing_dev_info; 18 + struct block_device; 19 + struct dentry; 20 + struct dentry_operations; 21 + struct dquot_operations; 22 + struct export_operations; 23 + struct file; 24 + struct file_system_type; 25 + struct fscrypt_operations; 26 + struct fsnotify_sb_info; 27 + struct fsverity_operations; 28 + struct kstatfs; 29 + struct mount; 30 + struct mtd_info; 31 + struct quotactl_ops; 32 + struct shrinker; 33 + struct unicode_map; 34 + struct user_namespace; 35 + struct workqueue_struct; 36 + struct writeback_control; 37 + struct xattr_handler; 38 + 39 + extern struct super_block *blockdev_superblock; 40 + 41 + /* Possible states of 'frozen' field */ 42 + enum { 43 + SB_UNFROZEN = 0, /* FS is unfrozen */ 44 + SB_FREEZE_WRITE = 1, /* Writes, dir ops, ioctls frozen */ 45 + SB_FREEZE_PAGEFAULT = 2, /* Page faults stopped as well */ 46 + SB_FREEZE_FS = 3, /* For internal FS use (e.g. to stop internal threads if needed) */ 47 + SB_FREEZE_COMPLETE = 4, /* ->freeze_fs finished successfully */ 48 + }; 49 + 50 + #define SB_FREEZE_LEVELS (SB_FREEZE_COMPLETE - 1) 51 + 52 + struct sb_writers { 53 + unsigned short frozen; /* Is sb frozen? */ 54 + int freeze_kcount; /* How many kernel freeze requests? */ 55 + int freeze_ucount; /* How many userspace freeze requests? */ 56 + const void *freeze_owner; /* Owner of the freeze */ 57 + struct percpu_rw_semaphore rw_sem[SB_FREEZE_LEVELS]; 58 + }; 59 + 60 + /** 61 + * enum freeze_holder - holder of the freeze 62 + * @FREEZE_HOLDER_KERNEL: kernel wants to freeze or thaw filesystem 63 + * @FREEZE_HOLDER_USERSPACE: userspace wants to freeze or thaw filesystem 64 + * @FREEZE_MAY_NEST: whether nesting freeze and thaw requests is allowed 65 + * @FREEZE_EXCL: a freeze that can only be undone by the owner 66 + * 67 + * Indicate who the owner of the freeze or thaw request is and whether 68 + * the freeze needs to be exclusive or can nest. 69 + * Without @FREEZE_MAY_NEST, multiple freeze and thaw requests from the 70 + * same holder aren't allowed. It is however allowed to hold a single 71 + * @FREEZE_HOLDER_USERSPACE and a single @FREEZE_HOLDER_KERNEL freeze at 72 + * the same time. This is relied upon by some filesystems during online 73 + * repair or similar. 74 + */ 75 + enum freeze_holder { 76 + FREEZE_HOLDER_KERNEL = (1U << 0), 77 + FREEZE_HOLDER_USERSPACE = (1U << 1), 78 + FREEZE_MAY_NEST = (1U << 2), 79 + FREEZE_EXCL = (1U << 3), 80 + }; 81 + 82 + struct super_operations { 83 + struct inode *(*alloc_inode)(struct super_block *sb); 84 + void (*destroy_inode)(struct inode *inode); 85 + void (*free_inode)(struct inode *inode); 86 + void (*dirty_inode)(struct inode *inode, int flags); 87 + int (*write_inode)(struct inode *inode, struct writeback_control *wbc); 88 + int (*drop_inode)(struct inode *inode); 89 + void (*evict_inode)(struct inode *inode); 90 + void (*put_super)(struct super_block *sb); 91 + int (*sync_fs)(struct super_block *sb, int wait); 92 + int (*freeze_super)(struct super_block *sb, enum freeze_holder who, 93 + const void *owner); 94 + int (*freeze_fs)(struct super_block *sb); 95 + int (*thaw_super)(struct super_block *sb, enum freeze_holder who, 96 + const void *owner); 97 + int (*unfreeze_fs)(struct super_block *sb); 98 + int (*statfs)(struct dentry *dentry, struct kstatfs *kstatfs); 99 + int (*remount_fs) (struct super_block *, int *, char *); 100 + void (*umount_begin)(struct super_block *sb); 101 + 102 + int (*show_options)(struct seq_file *seq, struct dentry *dentry); 103 + int (*show_devname)(struct seq_file *seq, struct dentry *dentry); 104 + int (*show_path)(struct seq_file *seq, struct dentry *dentry); 105 + int (*show_stats)(struct seq_file *seq, struct dentry *dentry); 106 + #ifdef CONFIG_QUOTA 107 + ssize_t (*quota_read)(struct super_block *sb, int type, char *data, 108 + size_t len, loff_t off); 109 + ssize_t (*quota_write)(struct super_block *sb, int type, 110 + const char *data, size_t len, loff_t off); 111 + struct dquot __rcu **(*get_dquots)(struct inode *inode); 112 + #endif 113 + long (*nr_cached_objects)(struct super_block *sb, 114 + struct shrink_control *sc); 115 + long (*free_cached_objects)(struct super_block *sb, 116 + struct shrink_control *sc); 117 + /* 118 + * If a filesystem can support graceful removal of a device and 119 + * continue read-write operations, implement this callback. 120 + * 121 + * Return 0 if the filesystem can continue read-write. 122 + * Non-zero return value or no such callback means the fs will be shutdown 123 + * as usual. 124 + */ 125 + int (*remove_bdev)(struct super_block *sb, struct block_device *bdev); 126 + void (*shutdown)(struct super_block *sb); 127 + }; 128 + 129 + struct super_block { 130 + struct list_head s_list; /* Keep this first */ 131 + dev_t s_dev; /* search index; _not_ kdev_t */ 132 + unsigned char s_blocksize_bits; 133 + unsigned long s_blocksize; 134 + loff_t s_maxbytes; /* Max file size */ 135 + struct file_system_type *s_type; 136 + const struct super_operations *s_op; 137 + const struct dquot_operations *dq_op; 138 + const struct quotactl_ops *s_qcop; 139 + const struct export_operations *s_export_op; 140 + unsigned long s_flags; 141 + unsigned long s_iflags; /* internal SB_I_* flags */ 142 + unsigned long s_magic; 143 + struct dentry *s_root; 144 + struct rw_semaphore s_umount; 145 + int s_count; 146 + atomic_t s_active; 147 + #ifdef CONFIG_SECURITY 148 + void *s_security; 149 + #endif 150 + const struct xattr_handler *const *s_xattr; 151 + #ifdef CONFIG_FS_ENCRYPTION 152 + const struct fscrypt_operations *s_cop; 153 + struct fscrypt_keyring *s_master_keys; /* master crypto keys in use */ 154 + #endif 155 + #ifdef CONFIG_FS_VERITY 156 + const struct fsverity_operations *s_vop; 157 + #endif 158 + #if IS_ENABLED(CONFIG_UNICODE) 159 + struct unicode_map *s_encoding; 160 + __u16 s_encoding_flags; 161 + #endif 162 + struct hlist_bl_head s_roots; /* alternate root dentries for NFS */ 163 + struct mount *s_mounts; /* list of mounts; _not_ for fs use */ 164 + struct block_device *s_bdev; /* can go away once we use an accessor for @s_bdev_file */ 165 + struct file *s_bdev_file; 166 + struct backing_dev_info *s_bdi; 167 + struct mtd_info *s_mtd; 168 + struct hlist_node s_instances; 169 + unsigned int s_quota_types; /* Bitmask of supported quota types */ 170 + struct quota_info s_dquot; /* Diskquota specific options */ 171 + 172 + struct sb_writers s_writers; 173 + 174 + /* 175 + * Keep s_fs_info, s_time_gran, s_fsnotify_mask, and 176 + * s_fsnotify_info together for cache efficiency. They are frequently 177 + * accessed and rarely modified. 178 + */ 179 + void *s_fs_info; /* Filesystem private info */ 180 + 181 + /* Granularity of c/m/atime in ns (cannot be worse than a second) */ 182 + u32 s_time_gran; 183 + /* Time limits for c/m/atime in seconds */ 184 + time64_t s_time_min; 185 + time64_t s_time_max; 186 + #ifdef CONFIG_FSNOTIFY 187 + u32 s_fsnotify_mask; 188 + struct fsnotify_sb_info *s_fsnotify_info; 189 + #endif 190 + 191 + /* 192 + * q: why are s_id and s_sysfs_name not the same? both are human 193 + * readable strings that identify the filesystem 194 + * a: s_id is allowed to change at runtime; it's used in log messages, 195 + * and we want to when a device starts out as single device (s_id is dev 196 + * name) but then a device is hot added and we have to switch to 197 + * identifying it by UUID 198 + * but s_sysfs_name is a handle for programmatic access, and can't 199 + * change at runtime 200 + */ 201 + char s_id[32]; /* Informational name */ 202 + uuid_t s_uuid; /* UUID */ 203 + u8 s_uuid_len; /* Default 16, possibly smaller for weird filesystems */ 204 + 205 + /* if set, fs shows up under sysfs at /sys/fs/$FSTYP/s_sysfs_name */ 206 + char s_sysfs_name[UUID_STRING_LEN + 1]; 207 + 208 + unsigned int s_max_links; 209 + unsigned int s_d_flags; /* default d_flags for dentries */ 210 + 211 + /* 212 + * The next field is for VFS *only*. No filesystems have any business 213 + * even looking at it. You had been warned. 214 + */ 215 + struct mutex s_vfs_rename_mutex; /* Kludge */ 216 + 217 + /* 218 + * Filesystem subtype. If non-empty the filesystem type field 219 + * in /proc/mounts will be "type.subtype" 220 + */ 221 + const char *s_subtype; 222 + 223 + const struct dentry_operations *__s_d_op; /* default d_op for dentries */ 224 + 225 + struct shrinker *s_shrink; /* per-sb shrinker handle */ 226 + 227 + /* Number of inodes with nlink == 0 but still referenced */ 228 + atomic_long_t s_remove_count; 229 + 230 + /* Read-only state of the superblock is being changed */ 231 + int s_readonly_remount; 232 + 233 + /* per-sb errseq_t for reporting writeback errors via syncfs */ 234 + errseq_t s_wb_err; 235 + 236 + /* AIO completions deferred from interrupt context */ 237 + struct workqueue_struct *s_dio_done_wq; 238 + struct hlist_head s_pins; 239 + 240 + /* 241 + * Owning user namespace and default context in which to 242 + * interpret filesystem uids, gids, quotas, device nodes, 243 + * xattrs and security labels. 244 + */ 245 + struct user_namespace *s_user_ns; 246 + 247 + /* 248 + * The list_lru structure is essentially just a pointer to a table 249 + * of per-node lru lists, each of which has its own spinlock. 250 + * There is no need to put them into separate cachelines. 251 + */ 252 + struct list_lru s_dentry_lru; 253 + struct list_lru s_inode_lru; 254 + struct rcu_head rcu; 255 + struct work_struct destroy_work; 256 + 257 + struct mutex s_sync_lock; /* sync serialisation lock */ 258 + 259 + /* 260 + * Indicates how deep in a filesystem stack this SB is 261 + */ 262 + int s_stack_depth; 263 + 264 + /* s_inode_list_lock protects s_inodes */ 265 + spinlock_t s_inode_list_lock ____cacheline_aligned_in_smp; 266 + struct list_head s_inodes; /* all inodes */ 267 + 268 + spinlock_t s_inode_wblist_lock; 269 + struct list_head s_inodes_wb; /* writeback inodes */ 270 + long s_min_writeback_pages; 271 + } __randomize_layout; 272 + 273 + /* 274 + * sb->s_flags. Note that these mirror the equivalent MS_* flags where 275 + * represented in both. 276 + */ 277 + #define SB_RDONLY BIT(0) /* Mount read-only */ 278 + #define SB_NOSUID BIT(1) /* Ignore suid and sgid bits */ 279 + #define SB_NODEV BIT(2) /* Disallow access to device special files */ 280 + #define SB_NOEXEC BIT(3) /* Disallow program execution */ 281 + #define SB_SYNCHRONOUS BIT(4) /* Writes are synced at once */ 282 + #define SB_MANDLOCK BIT(6) /* Allow mandatory locks on an FS */ 283 + #define SB_DIRSYNC BIT(7) /* Directory modifications are synchronous */ 284 + #define SB_NOATIME BIT(10) /* Do not update access times. */ 285 + #define SB_NODIRATIME BIT(11) /* Do not update directory access times */ 286 + #define SB_SILENT BIT(15) 287 + #define SB_POSIXACL BIT(16) /* Supports POSIX ACLs */ 288 + #define SB_INLINECRYPT BIT(17) /* Use blk-crypto for encrypted files */ 289 + #define SB_KERNMOUNT BIT(22) /* this is a kern_mount call */ 290 + #define SB_I_VERSION BIT(23) /* Update inode I_version field */ 291 + #define SB_LAZYTIME BIT(25) /* Update the on-disk [acm]times lazily */ 292 + 293 + /* These sb flags are internal to the kernel */ 294 + #define SB_DEAD BIT(21) 295 + #define SB_DYING BIT(24) 296 + #define SB_FORCE BIT(27) 297 + #define SB_NOSEC BIT(28) 298 + #define SB_BORN BIT(29) 299 + #define SB_ACTIVE BIT(30) 300 + #define SB_NOUSER BIT(31) 301 + 302 + /* These flags relate to encoding and casefolding */ 303 + #define SB_ENC_STRICT_MODE_FL (1 << 0) 304 + #define SB_ENC_NO_COMPAT_FALLBACK_FL (1 << 1) 305 + 306 + #define sb_has_strict_encoding(sb) \ 307 + (sb->s_encoding_flags & SB_ENC_STRICT_MODE_FL) 308 + 309 + #if IS_ENABLED(CONFIG_UNICODE) 310 + #define sb_no_casefold_compat_fallback(sb) \ 311 + (sb->s_encoding_flags & SB_ENC_NO_COMPAT_FALLBACK_FL) 312 + #else 313 + #define sb_no_casefold_compat_fallback(sb) (1) 314 + #endif 315 + 316 + /* sb->s_iflags */ 317 + #define SB_I_CGROUPWB 0x00000001 /* cgroup-aware writeback enabled */ 318 + #define SB_I_NOEXEC 0x00000002 /* Ignore executables on this fs */ 319 + #define SB_I_NODEV 0x00000004 /* Ignore devices on this fs */ 320 + #define SB_I_STABLE_WRITES 0x00000008 /* don't modify blks until WB is done */ 321 + 322 + /* sb->s_iflags to limit user namespace mounts */ 323 + #define SB_I_USERNS_VISIBLE 0x00000010 /* fstype already mounted */ 324 + #define SB_I_IMA_UNVERIFIABLE_SIGNATURE 0x00000020 325 + #define SB_I_UNTRUSTED_MOUNTER 0x00000040 326 + #define SB_I_EVM_HMAC_UNSUPPORTED 0x00000080 327 + 328 + #define SB_I_SKIP_SYNC 0x00000100 /* Skip superblock at global sync */ 329 + #define SB_I_PERSB_BDI 0x00000200 /* has a per-sb bdi */ 330 + #define SB_I_TS_EXPIRY_WARNED 0x00000400 /* warned about timestamp range expiry */ 331 + #define SB_I_RETIRED 0x00000800 /* superblock shouldn't be reused */ 332 + #define SB_I_NOUMASK 0x00001000 /* VFS does not apply umask */ 333 + #define SB_I_NOIDMAP 0x00002000 /* No idmapped mounts on this superblock */ 334 + #define SB_I_ALLOW_HSM 0x00004000 /* Allow HSM events on this superblock */ 335 + 336 + #endif /* _LINUX_FS_SUPER_TYPES_H */
+6
include/linux/fs_struct.h
··· 2 2 #ifndef _LINUX_FS_STRUCT_H 3 3 #define _LINUX_FS_STRUCT_H 4 4 5 + #include <linux/sched.h> 5 6 #include <linux/path.h> 6 7 #include <linux/spinlock.h> 7 8 #include <linux/seqlock.h> ··· 41 40 } 42 41 43 42 extern bool current_chrooted(void); 43 + 44 + static inline int current_umask(void) 45 + { 46 + return current->fs->umask; 47 + } 44 48 45 49 #endif /* _LINUX_FS_STRUCT_H */
+7 -4
include/linux/fs_types.h include/linux/fs_dirent.h
··· 1 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 - #ifndef _LINUX_FS_TYPES_H 3 - #define _LINUX_FS_TYPES_H 2 + #ifndef _LINUX_FS_DIRENT_H 3 + #define _LINUX_FS_DIRENT_H 4 + 5 + #include <linux/stat.h> 6 + #include <linux/types.h> 4 7 5 8 /* 6 9 * This is a header for the common implementation of dirent ··· 69 66 70 67 /* 71 68 * declarations for helper functions, accompanying implementation 72 - * is in fs/fs_types.c 69 + * is in fs/fs_dirent.c 73 70 */ 74 71 extern unsigned char fs_ftype_to_dtype(unsigned int filetype); 75 72 extern unsigned char fs_umode_to_ftype(umode_t mode); 76 73 extern unsigned char fs_umode_to_dtype(umode_t mode); 77 74 78 - #endif 75 + #endif /* _LINUX_FS_DIRENT_H */
+1
include/linux/namei.h
··· 7 7 #include <linux/path.h> 8 8 #include <linux/fcntl.h> 9 9 #include <linux/errno.h> 10 + #include <linux/fs_struct.h> 10 11 11 12 enum { MAX_NESTED_LINKS = 8 }; 12 13