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.h201
1 files changed, 177 insertions, 24 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 17fd887c798f..38dba16c4176 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,6 +1463,31 @@ 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 */
@@ -1497,8 +1535,7 @@ struct super_block {
1497 struct hlist_node s_instances; 1535 struct hlist_node s_instances;
1498 struct quota_info s_dquot; /* Diskquota specific options */ 1536 struct quota_info s_dquot; /* Diskquota specific options */
1499 1537
1500 int s_frozen; 1538 struct sb_writers s_writers;
1501 wait_queue_head_t s_wait_unfrozen;
1502 1539
1503 char s_id[32]; /* Informational name */ 1540 char s_id[32]; /* Informational name */
1504 u8 s_uuid[16]; /* UUID */ 1541 u8 s_uuid[16]; /* UUID */
@@ -1553,14 +1590,117 @@ extern struct timespec current_fs_time(struct super_block *sb);
1553/* 1590/*
1554 * Snapshotting support. 1591 * Snapshotting support.
1555 */ 1592 */
1556enum {
1557 SB_UNFROZEN = 0,
1558 SB_FREEZE_WRITE = 1,
1559 SB_FREEZE_TRANS = 2,
1560};
1561 1593
1562#define vfs_check_frozen(sb, level) \ 1594void __sb_end_write(struct super_block *sb, int level);
1563 wait_event((sb)->s_wait_unfrozen, ((sb)->s_frozen < (level))) 1595int __sb_start_write(struct super_block *sb, int level, bool wait);
1596
1597/**
1598 * sb_end_write - drop write access to a superblock
1599 * @sb: the super we wrote to
1600 *
1601 * Decrement number of writers to the filesystem. Wake up possible waiters
1602 * wanting to freeze the filesystem.
1603 */
1604static inline void sb_end_write(struct super_block *sb)
1605{
1606 __sb_end_write(sb, SB_FREEZE_WRITE);
1607}
1608
1609/**
1610 * sb_end_pagefault - drop write access to a superblock from a page fault
1611 * @sb: the super we wrote to
1612 *
1613 * Decrement number of processes handling write page fault to the filesystem.
1614 * Wake up possible waiters wanting to freeze the filesystem.
1615 */
1616static inline void sb_end_pagefault(struct super_block *sb)
1617{
1618 __sb_end_write(sb, SB_FREEZE_PAGEFAULT);
1619}
1620
1621/**
1622 * sb_end_intwrite - drop write access to a superblock for internal fs purposes
1623 * @sb: the super we wrote to
1624 *
1625 * Decrement fs-internal number of writers to the filesystem. Wake up possible
1626 * waiters wanting to freeze the filesystem.
1627 */
1628static inline void sb_end_intwrite(struct super_block *sb)
1629{
1630 __sb_end_write(sb, SB_FREEZE_FS);
1631}
1632
1633/**
1634 * sb_start_write - get write access to a superblock
1635 * @sb: the super we write to
1636 *
1637 * When a process wants to write data or metadata to a file system (i.e. dirty
1638 * a page or an inode), it should embed the operation in a sb_start_write() -
1639 * sb_end_write() pair to get exclusion against file system freezing. This
1640 * function increments number of writers preventing freezing. If the file
1641 * system is already frozen, the function waits until the file system is
1642 * thawed.
1643 *
1644 * Since freeze protection behaves as a lock, users have to preserve
1645 * ordering of freeze protection and other filesystem locks. Generally,
1646 * freeze protection should be the outermost lock. In particular, we have:
1647 *
1648 * sb_start_write
1649 * -> i_mutex (write path, truncate, directory ops, ...)
1650 * -> s_umount (freeze_super, thaw_super)
1651 */
1652static inline void sb_start_write(struct super_block *sb)
1653{
1654 __sb_start_write(sb, SB_FREEZE_WRITE, true);
1655}
1656
1657static inline int sb_start_write_trylock(struct super_block *sb)
1658{
1659 return __sb_start_write(sb, SB_FREEZE_WRITE, false);
1660}
1661
1662/**
1663 * sb_start_pagefault - get write access to a superblock from a page fault
1664 * @sb: the super we write to
1665 *
1666 * When a process starts handling write page fault, it should embed the
1667 * operation into sb_start_pagefault() - sb_end_pagefault() pair to get
1668 * exclusion against file system freezing. This is needed since the page fault
1669 * is going to dirty a page. This function increments number of running page
1670 * faults preventing freezing. If the file system is already frozen, the
1671 * function waits until the file system is thawed.
1672 *
1673 * Since page fault freeze protection behaves as a lock, users have to preserve
1674 * ordering of freeze protection and other filesystem locks. It is advised to
1675 * put sb_start_pagefault() close to mmap_sem in lock ordering. Page fault
1676 * handling code implies lock dependency:
1677 *
1678 * mmap_sem
1679 * -> sb_start_pagefault
1680 */
1681static inline void sb_start_pagefault(struct super_block *sb)
1682{
1683 __sb_start_write(sb, SB_FREEZE_PAGEFAULT, true);
1684}
1685
1686/*
1687 * sb_start_intwrite - get write access to a superblock for internal fs purposes
1688 * @sb: the super we write to
1689 *
1690 * This is the third level of protection against filesystem freezing. It is
1691 * free for use by a filesystem. The only requirement is that it must rank
1692 * below sb_start_pagefault.
1693 *
1694 * For example filesystem can call sb_start_intwrite() when starting a
1695 * transaction which somewhat eases handling of freezing for internal sources
1696 * of filesystem changes (internal fs threads, discarding preallocation on file
1697 * close, etc.).
1698 */
1699static inline void sb_start_intwrite(struct super_block *sb)
1700{
1701 __sb_start_write(sb, SB_FREEZE_FS, true);
1702}
1703
1564 1704
1565extern bool inode_owner_or_capable(const struct inode *inode); 1705extern bool inode_owner_or_capable(const struct inode *inode);
1566 1706
@@ -1571,7 +1711,7 @@ extern void unlock_super(struct super_block *);
1571/* 1711/*
1572 * VFS helper functions.. 1712 * VFS helper functions..
1573 */ 1713 */
1574extern int vfs_create(struct inode *, struct dentry *, umode_t, struct nameidata *); 1714extern int vfs_create(struct inode *, struct dentry *, umode_t, bool);
1575extern int vfs_mkdir(struct inode *, struct dentry *, umode_t); 1715extern int vfs_mkdir(struct inode *, struct dentry *, umode_t);
1576extern int vfs_mknod(struct inode *, struct dentry *, umode_t, dev_t); 1716extern int vfs_mknod(struct inode *, struct dentry *, umode_t, dev_t);
1577extern int vfs_symlink(struct inode *, struct dentry *, const char *); 1717extern int vfs_symlink(struct inode *, struct dentry *, const char *);
@@ -1666,7 +1806,7 @@ struct file_operations {
1666}; 1806};
1667 1807
1668struct inode_operations { 1808struct inode_operations {
1669 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *); 1809 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
1670 void * (*follow_link) (struct dentry *, struct nameidata *); 1810 void * (*follow_link) (struct dentry *, struct nameidata *);
1671 int (*permission) (struct inode *, int); 1811 int (*permission) (struct inode *, int);
1672 struct posix_acl * (*get_acl)(struct inode *, int); 1812 struct posix_acl * (*get_acl)(struct inode *, int);
@@ -1674,7 +1814,7 @@ struct inode_operations {
1674 int (*readlink) (struct dentry *, char __user *,int); 1814 int (*readlink) (struct dentry *, char __user *,int);
1675 void (*put_link) (struct dentry *, struct nameidata *, void *); 1815 void (*put_link) (struct dentry *, struct nameidata *, void *);
1676 1816
1677 int (*create) (struct inode *,struct dentry *,umode_t,struct nameidata *); 1817 int (*create) (struct inode *,struct dentry *, umode_t, bool);
1678 int (*link) (struct dentry *,struct inode *,struct dentry *); 1818 int (*link) (struct dentry *,struct inode *,struct dentry *);
1679 int (*unlink) (struct inode *,struct dentry *); 1819 int (*unlink) (struct inode *,struct dentry *);
1680 int (*symlink) (struct inode *,struct dentry *,const char *); 1820 int (*symlink) (struct inode *,struct dentry *,const char *);
@@ -1693,6 +1833,9 @@ struct inode_operations {
1693 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, 1833 int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start,
1694 u64 len); 1834 u64 len);
1695 int (*update_time)(struct inode *, struct timespec *, int); 1835 int (*update_time)(struct inode *, struct timespec *, int);
1836 int (*atomic_open)(struct inode *, struct dentry *,
1837 struct file *, unsigned open_flag,
1838 umode_t create_mode, int *opened);
1696} ____cacheline_aligned; 1839} ____cacheline_aligned;
1697 1840
1698struct seq_file; 1841struct seq_file;
@@ -1881,6 +2024,7 @@ struct file_system_type {
1881 struct lock_class_key s_lock_key; 2024 struct lock_class_key s_lock_key;
1882 struct lock_class_key s_umount_key; 2025 struct lock_class_key s_umount_key;
1883 struct lock_class_key s_vfs_rename_key; 2026 struct lock_class_key s_vfs_rename_key;
2027 struct lock_class_key s_writers_key[SB_FREEZE_LEVELS];
1884 2028
1885 struct lock_class_key i_lock_key; 2029 struct lock_class_key i_lock_key;
1886 struct lock_class_key i_mutex_key; 2030 struct lock_class_key i_mutex_key;
@@ -1911,7 +2055,7 @@ void free_anon_bdev(dev_t);
1911struct super_block *sget(struct file_system_type *type, 2055struct super_block *sget(struct file_system_type *type,
1912 int (*test)(struct super_block *,void *), 2056 int (*test)(struct super_block *,void *),
1913 int (*set)(struct super_block *,void *), 2057 int (*set)(struct super_block *,void *),
1914 void *data); 2058 int flags, void *data);
1915extern struct dentry *mount_pseudo(struct file_system_type *, char *, 2059extern struct dentry *mount_pseudo(struct file_system_type *, char *,
1916 const struct super_operations *ops, 2060 const struct super_operations *ops,
1917 const struct dentry_operations *dops, 2061 const struct dentry_operations *dops,
@@ -2057,10 +2201,17 @@ extern long do_sys_open(int dfd, const char __user *filename, int flags,
2057extern struct file *filp_open(const char *, int, umode_t); 2201extern struct file *filp_open(const char *, int, umode_t);
2058extern struct file *file_open_root(struct dentry *, struct vfsmount *, 2202extern struct file *file_open_root(struct dentry *, struct vfsmount *,
2059 const char *, int); 2203 const char *, int);
2060extern struct file * dentry_open(struct dentry *, struct vfsmount *, int, 2204extern 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); 2205extern int filp_close(struct file *, fl_owner_t id);
2063extern char * getname(const char __user *); 2206extern char * getname(const char __user *);
2207enum {
2208 FILE_CREATED = 1,
2209 FILE_OPENED = 2
2210};
2211extern int finish_open(struct file *file, struct dentry *dentry,
2212 int (*open)(struct inode *, struct file *),
2213 int *opened);
2214extern int finish_no_open(struct file *file, struct dentry *dentry);
2064 2215
2065/* fs/ioctl.c */ 2216/* fs/ioctl.c */
2066 2217
@@ -2091,6 +2242,7 @@ extern sector_t blkdev_max_block(struct block_device *bdev);
2091extern void bd_forget(struct inode *inode); 2242extern void bd_forget(struct inode *inode);
2092extern void bdput(struct block_device *); 2243extern void bdput(struct block_device *);
2093extern void invalidate_bdev(struct block_device *); 2244extern void invalidate_bdev(struct block_device *);
2245extern void iterate_bdevs(void (*)(struct block_device *, void *), void *);
2094extern int sync_blockdev(struct block_device *bdev); 2246extern int sync_blockdev(struct block_device *bdev);
2095extern void kill_bdev(struct block_device *); 2247extern void kill_bdev(struct block_device *);
2096extern struct super_block *freeze_bdev(struct block_device *); 2248extern struct super_block *freeze_bdev(struct block_device *);
@@ -2112,6 +2264,10 @@ static inline int thaw_bdev(struct block_device *bdev, struct super_block *sb)
2112{ 2264{
2113 return 0; 2265 return 0;
2114} 2266}
2267
2268static inline void iterate_bdevs(void (*f)(struct block_device *, void *), void *arg)
2269{
2270}
2115#endif 2271#endif
2116extern int sync_filesystem(struct super_block *); 2272extern int sync_filesystem(struct super_block *);
2117extern const struct file_operations def_blk_fops; 2273extern const struct file_operations def_blk_fops;
@@ -2311,9 +2467,6 @@ static inline void i_readcount_inc(struct inode *inode)
2311} 2467}
2312#endif 2468#endif
2313extern int do_pipe_flags(int *, int); 2469extern 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 2470
2318extern int kernel_read(struct file *, loff_t, char *, unsigned long); 2471extern int kernel_read(struct file *, loff_t, char *, unsigned long);
2319extern struct file * open_exec(const char *); 2472extern struct file * open_exec(const char *);
@@ -2438,7 +2591,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); 2591extern 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); 2592extern 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, 2593extern loff_t generic_file_llseek_size(struct file *file, loff_t offset,
2441 int origin, loff_t maxsize); 2594 int origin, loff_t maxsize, loff_t eof);
2442extern int generic_file_open(struct inode * inode, struct file * filp); 2595extern int generic_file_open(struct inode * inode, struct file * filp);
2443extern int nonseekable_open(struct inode * inode, struct file * filp); 2596extern int nonseekable_open(struct inode * inode, struct file * filp);
2444 2597
@@ -2560,7 +2713,7 @@ extern int simple_write_end(struct file *file, struct address_space *mapping,
2560 loff_t pos, unsigned len, unsigned copied, 2713 loff_t pos, unsigned len, unsigned copied,
2561 struct page *page, void *fsdata); 2714 struct page *page, void *fsdata);
2562 2715
2563extern struct dentry *simple_lookup(struct inode *, struct dentry *, struct nameidata *); 2716extern 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 *); 2717extern ssize_t generic_read_dir(struct file *, char __user *, size_t, loff_t *);
2565extern const struct file_operations simple_dir_operations; 2718extern const struct file_operations simple_dir_operations;
2566extern const struct inode_operations simple_dir_inode_operations; 2719extern const struct inode_operations simple_dir_inode_operations;