aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/fs.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/fs.h')
-rw-r--r--include/linux/fs.h204
1 files changed, 177 insertions, 27 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 17fd887c798f..aa110476a95b 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -165,6 +165,8 @@ struct inodes_stat_t {
165#define READ 0 165#define READ 0
166#define WRITE RW_MASK 166#define WRITE RW_MASK
167#define READA RWA_MASK 167#define READA RWA_MASK
168#define KERNEL_READ (READ|REQ_KERNEL)
169#define KERNEL_WRITE (WRITE|REQ_KERNEL)
168 170
169#define READ_SYNC (READ | REQ_SYNC) 171#define READ_SYNC (READ | REQ_SYNC)
170#define WRITE_SYNC (WRITE | REQ_SYNC | REQ_NOIDLE) 172#define WRITE_SYNC (WRITE | REQ_SYNC | REQ_NOIDLE)
@@ -412,6 +414,7 @@ struct inodes_stat_t {
412#include <linux/shrinker.h> 414#include <linux/shrinker.h>
413#include <linux/migrate_mode.h> 415#include <linux/migrate_mode.h>
414#include <linux/uidgid.h> 416#include <linux/uidgid.h>
417#include <linux/lockdep.h>
415 418
416#include <asm/byteorder.h> 419#include <asm/byteorder.h>
417 420
@@ -427,6 +430,7 @@ struct kstatfs;
427struct vm_area_struct; 430struct vm_area_struct;
428struct vfsmount; 431struct vfsmount;
429struct cred; 432struct cred;
433struct swap_info_struct;
430 434
431extern void __init inode_init(void); 435extern void __init inode_init(void);
432extern void __init inode_init_early(void); 436extern void __init inode_init_early(void);
@@ -437,6 +441,8 @@ extern unsigned long get_max_files(void);
437extern int sysctl_nr_open; 441extern int sysctl_nr_open;
438extern struct inodes_stat_t inodes_stat; 442extern struct inodes_stat_t inodes_stat;
439extern int leases_enable, lease_break_time; 443extern int leases_enable, lease_break_time;
444extern int sysctl_protected_symlinks;
445extern int sysctl_protected_hardlinks;
440 446
441struct buffer_head; 447struct buffer_head;
442typedef int (get_block_t)(struct inode *inode, sector_t iblock, 448typedef int (get_block_t)(struct inode *inode, sector_t iblock,
@@ -636,6 +642,11 @@ struct address_space_operations {
636 int (*is_partially_uptodate) (struct page *, read_descriptor_t *, 642 int (*is_partially_uptodate) (struct page *, read_descriptor_t *,
637 unsigned long); 643 unsigned long);
638 int (*error_remove_page)(struct address_space *, struct page *); 644 int (*error_remove_page)(struct address_space *, struct page *);
645
646 /* swapfile support */
647 int (*swap_activate)(struct swap_info_struct *sis, struct file *file,
648 sector_t *span);
649 void (*swap_deactivate)(struct file *file);
639}; 650};
640 651
641extern const struct address_space_operations empty_aops; 652extern const struct address_space_operations empty_aops;
@@ -826,7 +837,7 @@ struct inode {
826 struct list_head i_lru; /* inode LRU list */ 837 struct list_head i_lru; /* inode LRU list */
827 struct list_head i_sb_list; 838 struct list_head i_sb_list;
828 union { 839 union {
829 struct list_head i_dentry; 840 struct hlist_head i_dentry;
830 struct rcu_head i_rcu; 841 struct rcu_head i_rcu;
831 }; 842 };
832 u64 i_version; 843 u64 i_version;
@@ -1154,7 +1165,6 @@ struct lock_manager_operations {
1154 int (*lm_compare_owner)(struct file_lock *, struct file_lock *); 1165 int (*lm_compare_owner)(struct file_lock *, struct file_lock *);
1155 void (*lm_notify)(struct file_lock *); /* unblock callback */ 1166 void (*lm_notify)(struct file_lock *); /* unblock callback */
1156 int (*lm_grant)(struct file_lock *, struct file_lock *, int); 1167 int (*lm_grant)(struct file_lock *, struct file_lock *, int);
1157 void (*lm_release_private)(struct file_lock *);
1158 void (*lm_break)(struct file_lock *); 1168 void (*lm_break)(struct file_lock *);
1159 int (*lm_change)(struct file_lock **, int); 1169 int (*lm_change)(struct file_lock **, int);
1160}; 1170};
@@ -1163,9 +1173,10 @@ struct lock_manager {
1163 struct list_head list; 1173 struct list_head list;
1164}; 1174};
1165 1175
1166void locks_start_grace(struct lock_manager *); 1176struct net;
1177void locks_start_grace(struct net *, struct lock_manager *);
1167void locks_end_grace(struct lock_manager *); 1178void locks_end_grace(struct lock_manager *);
1168int locks_in_grace(void); 1179int locks_in_grace(struct net *);
1169 1180
1170/* that will die - we need it for nfs_lock_info */ 1181/* that will die - we need it for nfs_lock_info */
1171#include <linux/nfs_fs_i.h> 1182#include <linux/nfs_fs_i.h>
@@ -1437,6 +1448,8 @@ extern void f_delown(struct file *filp);
1437extern pid_t f_getown(struct file *filp); 1448extern pid_t f_getown(struct file *filp);
1438extern int send_sigurg(struct fown_struct *fown); 1449extern int send_sigurg(struct fown_struct *fown);
1439 1450
1451struct mm_struct;
1452
1440/* 1453/*
1441 * Umount options 1454 * Umount options
1442 */ 1455 */
@@ -1450,10 +1463,34 @@ extern int send_sigurg(struct fown_struct *fown);
1450extern struct list_head super_blocks; 1463extern struct list_head super_blocks;
1451extern spinlock_t sb_lock; 1464extern spinlock_t sb_lock;
1452 1465
1466/* Possible states of 'frozen' field */
1467enum {
1468 SB_UNFROZEN = 0, /* FS is unfrozen */
1469 SB_FREEZE_WRITE = 1, /* Writes, dir ops, ioctls frozen */
1470 SB_FREEZE_PAGEFAULT = 2, /* Page faults stopped as well */
1471 SB_FREEZE_FS = 3, /* For internal FS use (e.g. to stop
1472 * internal threads if needed) */
1473 SB_FREEZE_COMPLETE = 4, /* ->freeze_fs finished successfully */
1474};
1475
1476#define SB_FREEZE_LEVELS (SB_FREEZE_COMPLETE - 1)
1477
1478struct sb_writers {
1479 /* Counters for counting writers at each level */
1480 struct percpu_counter counter[SB_FREEZE_LEVELS];
1481 wait_queue_head_t wait; /* queue for waiting for
1482 writers / faults to finish */
1483 int frozen; /* Is sb frozen? */
1484 wait_queue_head_t wait_unfrozen; /* queue for waiting for
1485 sb to be thawed */
1486#ifdef CONFIG_DEBUG_LOCK_ALLOC
1487 struct lockdep_map lock_map[SB_FREEZE_LEVELS];
1488#endif
1489};
1490
1453struct super_block { 1491struct super_block {
1454 struct list_head s_list; /* Keep this first */ 1492 struct list_head s_list; /* Keep this first */
1455 dev_t s_dev; /* search index; _not_ kdev_t */ 1493 dev_t s_dev; /* search index; _not_ kdev_t */
1456 unsigned char s_dirt;
1457 unsigned char s_blocksize_bits; 1494 unsigned char s_blocksize_bits;
1458 unsigned long s_blocksize; 1495 unsigned long s_blocksize;
1459 loff_t s_maxbytes; /* Max file size */ 1496 loff_t s_maxbytes; /* Max file size */
@@ -1497,8 +1534,7 @@ struct super_block {
1497 struct hlist_node s_instances; 1534 struct hlist_node s_instances;
1498 struct quota_info s_dquot; /* Diskquota specific options */ 1535 struct quota_info s_dquot; /* Diskquota specific options */
1499 1536
1500 int s_frozen; 1537 struct sb_writers s_writers;
1501 wait_queue_head_t s_wait_unfrozen;
1502 1538
1503 char s_id[32]; /* Informational name */ 1539 char s_id[32]; /* Informational name */
1504 u8 s_uuid[16]; /* UUID */ 1540 u8 s_uuid[16]; /* UUID */
@@ -1553,14 +1589,117 @@ extern struct timespec current_fs_time(struct super_block *sb);
1553/* 1589/*
1554 * Snapshotting support. 1590 * Snapshotting support.
1555 */ 1591 */
1556enum {
1557 SB_UNFROZEN = 0,
1558 SB_FREEZE_WRITE = 1,
1559 SB_FREEZE_TRANS = 2,
1560};
1561 1592
1562#define vfs_check_frozen(sb, level) \ 1593void __sb_end_write(struct super_block *sb, int level);
1563 wait_event((sb)->s_wait_unfrozen, ((sb)->s_frozen < (level))) 1594int __sb_start_write(struct super_block *sb, int level, bool wait);
1595
1596/**
1597 * sb_end_write - drop write access to a superblock
1598 * @sb: the super we wrote to
1599 *
1600 * Decrement number of writers to the filesystem. Wake up possible waiters
1601 * wanting to freeze the filesystem.
1602 */
1603static inline void sb_end_write(struct super_block *sb)
1604{
1605 __sb_end_write(sb, SB_FREEZE_WRITE);
1606}
1607
1608/**
1609 * sb_end_pagefault - drop write access to a superblock from a page fault
1610 * @sb: the super we wrote to
1611 *
1612 * Decrement number of processes handling write page fault to the filesystem.
1613 * Wake up possible waiters wanting to freeze the filesystem.
1614 */
1615static inline void sb_end_pagefault(struct super_block *sb)
1616{
1617 __sb_end_write(sb, SB_FREEZE_PAGEFAULT);
1618}
1619
1620/**
1621 * sb_end_intwrite - drop write access to a superblock for internal fs purposes
1622 * @sb: the super we wrote to
1623 *
1624 * Decrement fs-internal number of writers to the filesystem. Wake up possible
1625 * waiters wanting to freeze the filesystem.
1626 */
1627static inline void sb_end_intwrite(struct super_block *sb)
1628{
1629 __sb_end_write(sb, SB_FREEZE_FS);
1630}
1631
1632/**
1633 * sb_start_write - get write access to a superblock
1634 * @sb: the super we write to
1635 *
1636 * When a process wants to write data or metadata to a file system (i.e. dirty
1637 * a page or an inode), it should embed the operation in a sb_start_write() -
1638 * sb_end_write() pair to get exclusion against file system freezing. This
1639 * function increments number of writers preventing freezing. If the file
1640 * system is already frozen, the function waits until the file system is
1641 * thawed.
1642 *
1643 * Since freeze protection behaves as a lock, users have to preserve
1644 * ordering of freeze protection and other filesystem locks. Generally,
1645 * freeze protection should be the outermost lock. In particular, we have:
1646 *
1647 * sb_start_write
1648 * -> i_mutex (write path, truncate, directory ops, ...)
1649 * -> s_umount (freeze_super, thaw_super)
1650 */
1651static inline void sb_start_write(struct super_block *sb)
1652{
1653 __sb_start_write(sb, SB_FREEZE_WRITE, true);
1654}
1655
1656static inline int sb_start_write_trylock(struct super_block *sb)
1657{
1658 return __sb_start_write(sb, SB_FREEZE_WRITE, false);
1659}
1660
1661/**
1662 * sb_start_pagefault - get write access to a superblock from a page fault
1663 * @sb: the super we write to
1664 *
1665 * When a process starts handling write page fault, it should embed the
1666 * operation into sb_start_pagefault() - sb_end_pagefault() pair to get
1667 * exclusion against file system freezing. This is needed since the page fault
1668 * is going to dirty a page. This function increments number of running page
1669 * faults preventing freezing. If the file system is already frozen, the
1670 * function waits until the file system is thawed.
1671 *
1672 * Since page fault freeze protection behaves as a lock, users have to preserve
1673 * ordering of freeze protection and other filesystem locks. It is advised to
1674 * put sb_start_pagefault() close to mmap_sem in lock ordering. Page fault
1675 * handling code implies lock dependency:
1676 *
1677 * mmap_sem
1678 * -> sb_start_pagefault
1679 */
1680static inline void sb_start_pagefault(struct super_block *sb)
1681{
1682 __sb_start_write(sb, SB_FREEZE_PAGEFAULT, true);
1683}
1684
1685/*
1686 * sb_start_intwrite - get write access to a superblock for internal fs purposes
1687 * @sb: the super we write to
1688 *
1689 * This is the third level of protection against filesystem freezing. It is
1690 * free for use by a filesystem. The only requirement is that it must rank
1691 * below sb_start_pagefault.
1692 *
1693 * For example filesystem can call sb_start_intwrite() when starting a
1694 * transaction which somewhat eases handling of freezing for internal sources
1695 * of filesystem changes (internal fs threads, discarding preallocation on file
1696 * close, etc.).
1697 */
1698static inline void sb_start_intwrite(struct super_block *sb)
1699{
1700 __sb_start_write(sb, SB_FREEZE_FS, true);
1701}
1702
1564 1703
1565extern bool inode_owner_or_capable(const struct inode *inode); 1704extern bool inode_owner_or_capable(const struct inode *inode);
1566 1705
@@ -1571,7 +1710,7 @@ extern void unlock_super(struct super_block *);
1571/* 1710/*
1572 * VFS helper functions.. 1711 * VFS helper functions..
1573 */ 1712 */
1574extern int vfs_create(struct inode *, struct dentry *, umode_t, struct nameidata *); 1713extern int vfs_create(struct inode *, struct dentry *, umode_t, bool);
1575extern int vfs_mkdir(struct inode *, struct dentry *, umode_t); 1714extern int vfs_mkdir(struct inode *, struct dentry *, umode_t);
1576extern int vfs_mknod(struct inode *, struct dentry *, umode_t, dev_t); 1715extern int vfs_mknod(struct inode *, struct dentry *, umode_t, dev_t);
1577extern int vfs_symlink(struct inode *, struct dentry *, const char *); 1716extern int vfs_symlink(struct inode *, struct dentry *, const char *);
@@ -1666,7 +1805,7 @@ struct file_operations {
1666}; 1805};
1667 1806
1668struct inode_operations { 1807struct inode_operations {
1669 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *); 1808 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
1670 void * (*follow_link) (struct dentry *, struct nameidata *); 1809 void * (*follow_link) (struct dentry *, struct nameidata *);
1671 int (*permission) (struct inode *, int); 1810 int (*permission) (struct inode *, int);
1672 struct posix_acl * (*get_acl)(struct inode *, int); 1811 struct posix_acl * (*get_acl)(struct inode *, int);
@@ -1674,7 +1813,7 @@ struct inode_operations {
1674 int (*readlink) (struct dentry *, char __user *,int); 1813 int (*readlink) (struct dentry *, char __user *,int);
1675 void (*put_link) (struct dentry *, struct nameidata *, void *); 1814 void (*put_link) (struct dentry *, struct nameidata *, void *);
1676 1815
1677 int (*create) (struct inode *,struct dentry *,umode_t,struct nameidata *); 1816 int (*create) (struct inode *,struct dentry *, umode_t, bool);
1678 int (*link) (struct dentry *,struct inode *,struct dentry *); 1817 int (*link) (struct dentry *,struct inode *,struct dentry *);
1679 int (*unlink) (struct inode *,struct dentry *); 1818 int (*unlink) (struct inode *,struct dentry *);
1680 int (*symlink) (struct inode *,struct dentry *,const char *); 1819 int (*symlink) (struct inode *,struct dentry *,const char *);
@@ -1693,6 +1832,9 @@ struct inode_operations {
1693 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, 1832 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
1694 u64 len); 1833 u64 len);
1695 int (*update_time)(struct inode *, struct timespec *, int); 1834 int (*update_time)(struct inode *, struct timespec *, int);
1835 int (*atomic_open)(struct inode *, struct dentry *,
1836 struct file *, unsigned open_flag,
1837 umode_t create_mode, int *opened);
1696} ____cacheline_aligned; 1838} ____cacheline_aligned;
1697 1839
1698struct seq_file; 1840struct seq_file;
@@ -1718,7 +1860,6 @@ struct super_operations {
1718 int (*drop_inode) (struct inode *); 1860 int (*drop_inode) (struct inode *);
1719 void (*evict_inode) (struct inode *); 1861 void (*evict_inode) (struct inode *);
1720 void (*put_super) (struct super_block *); 1862 void (*put_super) (struct super_block *);
1721 void (*write_super) (struct super_block *);
1722 int (*sync_fs)(struct super_block *sb, int wait); 1863 int (*sync_fs)(struct super_block *sb, int wait);
1723 int (*freeze_fs) (struct super_block *); 1864 int (*freeze_fs) (struct super_block *);
1724 int (*unfreeze_fs) (struct super_block *); 1865 int (*unfreeze_fs) (struct super_block *);
@@ -1881,6 +2022,7 @@ struct file_system_type {
1881 struct lock_class_key s_lock_key; 2022 struct lock_class_key s_lock_key;
1882 struct lock_class_key s_umount_key; 2023 struct lock_class_key s_umount_key;
1883 struct lock_class_key s_vfs_rename_key; 2024 struct lock_class_key s_vfs_rename_key;
2025 struct lock_class_key s_writers_key[SB_FREEZE_LEVELS];
1884 2026
1885 struct lock_class_key i_lock_key; 2027 struct lock_class_key i_lock_key;
1886 struct lock_class_key i_mutex_key; 2028 struct lock_class_key i_mutex_key;
@@ -1911,7 +2053,7 @@ void free_anon_bdev(dev_t);
1911struct super_block *sget(struct file_system_type *type, 2053struct super_block *sget(struct file_system_type *type,
1912 int (*test)(struct super_block *,void *), 2054 int (*test)(struct super_block *,void *),
1913 int (*set)(struct super_block *,void *), 2055 int (*set)(struct super_block *,void *),
1914 void *data); 2056 int flags, void *data);
1915extern struct dentry *mount_pseudo(struct file_system_type *, char *, 2057extern struct dentry *mount_pseudo(struct file_system_type *, char *,
1916 const struct super_operations *ops, 2058 const struct super_operations *ops,
1917 const struct dentry_operations *dops, 2059 const struct dentry_operations *dops,
@@ -2057,10 +2199,17 @@ extern long do_sys_open(int dfd, const char __user *filename, int flags,
2057extern struct file *filp_open(const char *, int, umode_t); 2199extern struct file *filp_open(const char *, int, umode_t);
2058extern struct file *file_open_root(struct dentry *, struct vfsmount *, 2200extern struct file *file_open_root(struct dentry *, struct vfsmount *,
2059 const char *, int); 2201 const char *, int);
2060extern struct file * dentry_open(struct dentry *, struct vfsmount *, int, 2202extern struct file * dentry_open(const struct path *, int, const struct cred *);
2061 const struct cred *);
2062extern int filp_close(struct file *, fl_owner_t id); 2203extern int filp_close(struct file *, fl_owner_t id);
2063extern char * getname(const char __user *); 2204extern char * getname(const char __user *);
2205enum {
2206 FILE_CREATED = 1,
2207 FILE_OPENED = 2
2208};
2209extern int finish_open(struct file *file, struct dentry *dentry,
2210 int (*open)(struct inode *, struct file *),
2211 int *opened);
2212extern int finish_no_open(struct file *file, struct dentry *dentry);
2064 2213
2065/* fs/ioctl.c */ 2214/* fs/ioctl.c */
2066 2215
@@ -2091,6 +2240,7 @@ extern sector_t blkdev_max_block(struct block_device *bdev);
2091extern void bd_forget(struct inode *inode); 2240extern void bd_forget(struct inode *inode);
2092extern void bdput(struct block_device *); 2241extern void bdput(struct block_device *);
2093extern void invalidate_bdev(struct block_device *); 2242extern void invalidate_bdev(struct block_device *);
2243extern void iterate_bdevs(void (*)(struct block_device *, void *), void *);
2094extern int sync_blockdev(struct block_device *bdev); 2244extern int sync_blockdev(struct block_device *bdev);
2095extern void kill_bdev(struct block_device *); 2245extern void kill_bdev(struct block_device *);
2096extern struct super_block *freeze_bdev(struct block_device *); 2246extern struct super_block *freeze_bdev(struct block_device *);
@@ -2112,6 +2262,10 @@ static inline int thaw_bdev(struct block_device *bdev, struct super_block *sb)
2112{ 2262{
2113 return 0; 2263 return 0;
2114} 2264}
2265
2266static inline void iterate_bdevs(void (*f)(struct block_device *, void *), void *arg)
2267{
2268}
2115#endif 2269#endif
2116extern int sync_filesystem(struct super_block *); 2270extern int sync_filesystem(struct super_block *);
2117extern const struct file_operations def_blk_fops; 2271extern const struct file_operations def_blk_fops;
@@ -2241,7 +2395,6 @@ extern int vfs_fsync_range(struct file *file, loff_t start, loff_t end,
2241 int datasync); 2395 int datasync);
2242extern int vfs_fsync(struct file *file, int datasync); 2396extern int vfs_fsync(struct file *file, int datasync);
2243extern int generic_write_sync(struct file *file, loff_t pos, loff_t count); 2397extern int generic_write_sync(struct file *file, loff_t pos, loff_t count);
2244extern void sync_supers(void);
2245extern void emergency_sync(void); 2398extern void emergency_sync(void);
2246extern void emergency_remount(void); 2399extern void emergency_remount(void);
2247#ifdef CONFIG_BLOCK 2400#ifdef CONFIG_BLOCK
@@ -2311,9 +2464,6 @@ static inline void i_readcount_inc(struct inode *inode)
2311} 2464}
2312#endif 2465#endif
2313extern int do_pipe_flags(int *, int); 2466extern int do_pipe_flags(int *, int);
2314extern struct file *create_read_pipe(struct file *f, int flags);
2315extern struct file *create_write_pipe(int flags);
2316extern void free_write_pipe(struct file *);
2317 2467
2318extern int kernel_read(struct file *, loff_t, char *, unsigned long); 2468extern int kernel_read(struct file *, loff_t, char *, unsigned long);
2319extern struct file * open_exec(const char *); 2469extern struct file * open_exec(const char *);
@@ -2438,7 +2588,7 @@ extern loff_t noop_llseek(struct file *file, loff_t offset, int origin);
2438extern loff_t no_llseek(struct file *file, loff_t offset, int origin); 2588extern loff_t no_llseek(struct file *file, loff_t offset, int origin);
2439extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin); 2589extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin);
2440extern loff_t generic_file_llseek_size(struct file *file, loff_t offset, 2590extern loff_t generic_file_llseek_size(struct file *file, loff_t offset,
2441 int origin, loff_t maxsize); 2591 int origin, loff_t maxsize, loff_t eof);
2442extern int generic_file_open(struct inode * inode, struct file * filp); 2592extern int generic_file_open(struct inode * inode, struct file * filp);
2443extern int nonseekable_open(struct inode * inode, struct file * filp); 2593extern int nonseekable_open(struct inode * inode, struct file * filp);
2444 2594
@@ -2560,7 +2710,7 @@ extern int simple_write_end(struct file *file, struct address_space *mapping,
2560 loff_t pos, unsigned len, unsigned copied, 2710 loff_t pos, unsigned len, unsigned copied,
2561 struct page *page, void *fsdata); 2711 struct page *page, void *fsdata);
2562 2712
2563extern struct dentry *simple_lookup(struct inode *, struct dentry *, struct nameidata *); 2713extern struct dentry *simple_lookup(struct inode *, struct dentry *, unsigned int flags);
2564extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *); 2714extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *);
2565extern const struct file_operations simple_dir_operations; 2715extern const struct file_operations simple_dir_operations;
2566extern const struct inode_operations simple_dir_inode_operations; 2716extern const struct inode_operations simple_dir_inode_operations;