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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs-2.6

* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs-2.6:
quota: Improve checking of quota file header
jbd: jbd-debug and jbd2-debug should be writable
ext4: fix sleep inside spinlock issue with quota and dealloc (#14739)
ext4: Fix potential quota deadlock
quota: Fix 64-bit limits setting on 32-bit archs
ext3: Replace lock/unlock_super() with an explicit lock for resizing
ext3: Replace lock/unlock_super() with an explicit lock for the orphan list
ext3: ext3_mark_recovery_complete() doesn't need to use lock_super
ext3: Remove outdated comment about lock_super()
quota: Move duplicated code to separate functions
ext4: Convert to generic reserved quota's space management.
quota: decouple fs reserved space from quota reservation
Add unlocked version of inode_add_bytes() function
ext3: quota macros cleanup [V2]

+253 -217
+4 -4
fs/ext3/inode.c
··· 970 970 if (max_blocks > DIO_MAX_BLOCKS) 971 971 max_blocks = DIO_MAX_BLOCKS; 972 972 handle = ext3_journal_start(inode, DIO_CREDITS + 973 - 2 * EXT3_QUOTA_TRANS_BLOCKS(inode->i_sb)); 973 + EXT3_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb)); 974 974 if (IS_ERR(handle)) { 975 975 ret = PTR_ERR(handle); 976 976 goto out; ··· 3146 3146 3147 3147 /* (user+group)*(old+new) structure, inode write (sb, 3148 3148 * inode block, ? - but truncate inode update has it) */ 3149 - handle = ext3_journal_start(inode, 2*(EXT3_QUOTA_INIT_BLOCKS(inode->i_sb)+ 3150 - EXT3_QUOTA_DEL_BLOCKS(inode->i_sb))+3); 3149 + handle = ext3_journal_start(inode, EXT3_MAXQUOTAS_INIT_BLOCKS(inode->i_sb)+ 3150 + EXT3_MAXQUOTAS_DEL_BLOCKS(inode->i_sb)+3); 3151 3151 if (IS_ERR(handle)) { 3152 3152 error = PTR_ERR(handle); 3153 3153 goto err_out; ··· 3239 3239 #ifdef CONFIG_QUOTA 3240 3240 /* We know that structure was already allocated during vfs_dq_init so 3241 3241 * we will be updating only the data blocks + inodes */ 3242 - ret += 2*EXT3_QUOTA_TRANS_BLOCKS(inode->i_sb); 3242 + ret += EXT3_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb); 3243 3243 #endif 3244 3244 3245 3245 return ret;
+15 -13
fs/ext3/namei.c
··· 1699 1699 retry: 1700 1700 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + 1701 1701 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + 1702 - 2*EXT3_QUOTA_INIT_BLOCKS(dir->i_sb)); 1702 + EXT3_MAXQUOTAS_INIT_BLOCKS(dir->i_sb)); 1703 1703 if (IS_ERR(handle)) 1704 1704 return PTR_ERR(handle); 1705 1705 ··· 1733 1733 retry: 1734 1734 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + 1735 1735 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + 1736 - 2*EXT3_QUOTA_INIT_BLOCKS(dir->i_sb)); 1736 + EXT3_MAXQUOTAS_INIT_BLOCKS(dir->i_sb)); 1737 1737 if (IS_ERR(handle)) 1738 1738 return PTR_ERR(handle); 1739 1739 ··· 1769 1769 retry: 1770 1770 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + 1771 1771 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 + 1772 - 2*EXT3_QUOTA_INIT_BLOCKS(dir->i_sb)); 1772 + EXT3_MAXQUOTAS_INIT_BLOCKS(dir->i_sb)); 1773 1773 if (IS_ERR(handle)) 1774 1774 return PTR_ERR(handle); 1775 1775 ··· 1920 1920 struct ext3_iloc iloc; 1921 1921 int err = 0, rc; 1922 1922 1923 - lock_super(sb); 1923 + mutex_lock(&EXT3_SB(sb)->s_orphan_lock); 1924 1924 if (!list_empty(&EXT3_I(inode)->i_orphan)) 1925 1925 goto out_unlock; 1926 1926 ··· 1929 1929 1930 1930 /* @@@ FIXME: Observation from aviro: 1931 1931 * I think I can trigger J_ASSERT in ext3_orphan_add(). We block 1932 - * here (on lock_super()), so race with ext3_link() which might bump 1932 + * here (on s_orphan_lock), so race with ext3_link() which might bump 1933 1933 * ->i_nlink. For, say it, character device. Not a regular file, 1934 1934 * not a directory, not a symlink and ->i_nlink > 0. 1935 + * 1936 + * tytso, 4/25/2009: I'm not sure how that could happen; 1937 + * shouldn't the fs core protect us from these sort of 1938 + * unlink()/link() races? 1935 1939 */ 1936 1940 J_ASSERT ((S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || 1937 1941 S_ISLNK(inode->i_mode)) || inode->i_nlink == 0); ··· 1972 1968 jbd_debug(4, "orphan inode %lu will point to %d\n", 1973 1969 inode->i_ino, NEXT_ORPHAN(inode)); 1974 1970 out_unlock: 1975 - unlock_super(sb); 1971 + mutex_unlock(&EXT3_SB(sb)->s_orphan_lock); 1976 1972 ext3_std_error(inode->i_sb, err); 1977 1973 return err; 1978 1974 } ··· 1990 1986 struct ext3_iloc iloc; 1991 1987 int err = 0; 1992 1988 1993 - lock_super(inode->i_sb); 1994 - if (list_empty(&ei->i_orphan)) { 1995 - unlock_super(inode->i_sb); 1996 - return 0; 1997 - } 1989 + mutex_lock(&EXT3_SB(inode->i_sb)->s_orphan_lock); 1990 + if (list_empty(&ei->i_orphan)) 1991 + goto out; 1998 1992 1999 1993 ino_next = NEXT_ORPHAN(inode); 2000 1994 prev = ei->i_orphan.prev; ··· 2042 2040 out_err: 2043 2041 ext3_std_error(inode->i_sb, err); 2044 2042 out: 2045 - unlock_super(inode->i_sb); 2043 + mutex_unlock(&EXT3_SB(inode->i_sb)->s_orphan_lock); 2046 2044 return err; 2047 2045 2048 2046 out_brelse: ··· 2177 2175 retry: 2178 2176 handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) + 2179 2177 EXT3_INDEX_EXTRA_TRANS_BLOCKS + 5 + 2180 - 2*EXT3_QUOTA_INIT_BLOCKS(dir->i_sb)); 2178 + EXT3_MAXQUOTAS_INIT_BLOCKS(dir->i_sb)); 2181 2179 if (IS_ERR(handle)) 2182 2180 return PTR_ERR(handle); 2183 2181
+18 -17
fs/ext3/resize.c
··· 209 209 if (IS_ERR(handle)) 210 210 return PTR_ERR(handle); 211 211 212 - lock_super(sb); 212 + mutex_lock(&sbi->s_resize_lock); 213 213 if (input->group != sbi->s_groups_count) { 214 214 err = -EBUSY; 215 215 goto exit_journal; ··· 324 324 brelse(bh); 325 325 326 326 exit_journal: 327 - unlock_super(sb); 327 + mutex_unlock(&sbi->s_resize_lock); 328 328 if ((err2 = ext3_journal_stop(handle)) && !err) 329 329 err = err2; 330 330 ··· 662 662 * important part is that the new block and inode counts are in the backup 663 663 * superblocks, and the location of the new group metadata in the GDT backups. 664 664 * 665 - * We do not need lock_super() for this, because these blocks are not 666 - * otherwise touched by the filesystem code when it is mounted. We don't 667 - * need to worry about last changing from sbi->s_groups_count, because the 668 - * worst that can happen is that we do not copy the full number of backups 669 - * at this time. The resize which changed s_groups_count will backup again. 665 + * We do not need take the s_resize_lock for this, because these 666 + * blocks are not otherwise touched by the filesystem code when it is 667 + * mounted. We don't need to worry about last changing from 668 + * sbi->s_groups_count, because the worst that can happen is that we 669 + * do not copy the full number of backups at this time. The resize 670 + * which changed s_groups_count will backup again. 670 671 */ 671 672 static void update_backups(struct super_block *sb, 672 673 int blk_off, char *data, int size) ··· 826 825 goto exit_put; 827 826 } 828 827 829 - lock_super(sb); 828 + mutex_lock(&sbi->s_resize_lock); 830 829 if (input->group != sbi->s_groups_count) { 831 830 ext3_warning(sb, __func__, 832 831 "multiple resizers run on filesystem!"); ··· 857 856 /* 858 857 * OK, now we've set up the new group. Time to make it active. 859 858 * 860 - * Current kernels don't lock all allocations via lock_super(), 859 + * We do not lock all allocations via s_resize_lock 861 860 * so we have to be safe wrt. concurrent accesses the group 862 861 * data. So we need to be careful to set all of the relevant 863 862 * group descriptor data etc. *before* we enable the group. ··· 901 900 * 902 901 * The precise rules we use are: 903 902 * 904 - * * Writers of s_groups_count *must* hold lock_super 903 + * * Writers of s_groups_count *must* hold s_resize_lock 905 904 * AND 906 905 * * Writers must perform a smp_wmb() after updating all dependent 907 906 * data and before modifying the groups count 908 907 * 909 - * * Readers must hold lock_super() over the access 908 + * * Readers must hold s_resize_lock over the access 910 909 * OR 911 910 * * Readers must perform an smp_rmb() after reading the groups count 912 911 * and before reading any dependent data. ··· 937 936 ext3_journal_dirty_metadata(handle, sbi->s_sbh); 938 937 939 938 exit_journal: 940 - unlock_super(sb); 939 + mutex_unlock(&sbi->s_resize_lock); 941 940 if ((err2 = ext3_journal_stop(handle)) && !err) 942 941 err = err2; 943 942 if (!err) { ··· 974 973 975 974 /* We don't need to worry about locking wrt other resizers just 976 975 * yet: we're going to revalidate es->s_blocks_count after 977 - * taking lock_super() below. */ 976 + * taking the s_resize_lock below. */ 978 977 o_blocks_count = le32_to_cpu(es->s_blocks_count); 979 978 o_groups_count = EXT3_SB(sb)->s_groups_count; 980 979 ··· 1046 1045 goto exit_put; 1047 1046 } 1048 1047 1049 - lock_super(sb); 1048 + mutex_lock(&EXT3_SB(sb)->s_resize_lock); 1050 1049 if (o_blocks_count != le32_to_cpu(es->s_blocks_count)) { 1051 1050 ext3_warning(sb, __func__, 1052 1051 "multiple resizers run on filesystem!"); 1053 - unlock_super(sb); 1052 + mutex_unlock(&EXT3_SB(sb)->s_resize_lock); 1054 1053 ext3_journal_stop(handle); 1055 1054 err = -EBUSY; 1056 1055 goto exit_put; ··· 1060 1059 EXT3_SB(sb)->s_sbh))) { 1061 1060 ext3_warning(sb, __func__, 1062 1061 "error %d on journal write access", err); 1063 - unlock_super(sb); 1062 + mutex_unlock(&EXT3_SB(sb)->s_resize_lock); 1064 1063 ext3_journal_stop(handle); 1065 1064 goto exit_put; 1066 1065 } 1067 1066 es->s_blocks_count = cpu_to_le32(o_blocks_count + add); 1068 1067 ext3_journal_dirty_metadata(handle, EXT3_SB(sb)->s_sbh); 1069 - unlock_super(sb); 1068 + mutex_unlock(&EXT3_SB(sb)->s_resize_lock); 1070 1069 ext3_debug("freeing blocks %lu through "E3FSBLK"\n", o_blocks_count, 1071 1070 o_blocks_count + add); 1072 1071 ext3_free_blocks_sb(handle, sb, o_blocks_count, add, &freed_blocks);
+3 -16
fs/ext3/super.c
··· 1928 1928 sb->dq_op = &ext3_quota_operations; 1929 1929 #endif 1930 1930 INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */ 1931 + mutex_init(&sbi->s_orphan_lock); 1932 + mutex_init(&sbi->s_resize_lock); 1931 1933 1932 1934 sb->s_root = NULL; 1933 1935 ··· 2016 2014 } 2017 2015 2018 2016 ext3_setup_super (sb, es, sb->s_flags & MS_RDONLY); 2019 - /* 2020 - * akpm: core read_super() calls in here with the superblock locked. 2021 - * That deadlocks, because orphan cleanup needs to lock the superblock 2022 - * in numerous places. Here we just pop the lock - it's relatively 2023 - * harmless, because we are now ready to accept write_super() requests, 2024 - * and aviro says that's the only reason for hanging onto the 2025 - * superblock lock. 2026 - */ 2017 + 2027 2018 EXT3_SB(sb)->s_mount_state |= EXT3_ORPHAN_FS; 2028 2019 ext3_orphan_cleanup(sb, es); 2029 2020 EXT3_SB(sb)->s_mount_state &= ~EXT3_ORPHAN_FS; ··· 2398 2403 if (journal_flush(journal) < 0) 2399 2404 goto out; 2400 2405 2401 - lock_super(sb); 2402 2406 if (EXT3_HAS_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER) && 2403 2407 sb->s_flags & MS_RDONLY) { 2404 2408 EXT3_CLEAR_INCOMPAT_FEATURE(sb, EXT3_FEATURE_INCOMPAT_RECOVER); 2405 2409 ext3_commit_super(sb, es, 1); 2406 2410 } 2407 - unlock_super(sb); 2408 2411 2409 2412 out: 2410 2413 journal_unlock_updates(journal); ··· 2594 2601 (sbi->s_mount_state & EXT3_VALID_FS)) 2595 2602 es->s_state = cpu_to_le16(sbi->s_mount_state); 2596 2603 2597 - /* 2598 - * We have to unlock super so that we can wait for 2599 - * transactions. 2600 - */ 2601 - unlock_super(sb); 2602 2604 ext3_mark_recovery_complete(sb, es); 2603 - lock_super(sb); 2604 2605 } else { 2605 2606 __le32 ret; 2606 2607 if ((ret = EXT3_HAS_RO_COMPAT_FEATURE(sb,
+5 -1
fs/ext4/ext4.h
··· 704 704 __u16 i_extra_isize; 705 705 706 706 spinlock_t i_block_reservation_lock; 707 + #ifdef CONFIG_QUOTA 708 + /* quota space reservation, managed internally by quota code */ 709 + qsize_t i_reserved_quota; 710 + #endif 707 711 708 712 /* completed async DIOs that might need unwritten extents handling */ 709 713 struct list_head i_aio_dio_complete_list; ··· 1439 1435 extern int ext4_block_truncate_page(handle_t *handle, 1440 1436 struct address_space *mapping, loff_t from); 1441 1437 extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf); 1442 - extern qsize_t ext4_get_reserved_space(struct inode *inode); 1438 + extern qsize_t *ext4_get_reserved_space(struct inode *inode); 1443 1439 extern int flush_aio_dio_completed_IO(struct inode *inode); 1444 1440 /* ioctl.c */ 1445 1441 extern long ext4_ioctl(struct file *, unsigned int, unsigned long);
+19 -17
fs/ext4/inode.c
··· 1003 1003 return err; 1004 1004 } 1005 1005 1006 - qsize_t ext4_get_reserved_space(struct inode *inode) 1006 + #ifdef CONFIG_QUOTA 1007 + qsize_t *ext4_get_reserved_space(struct inode *inode) 1007 1008 { 1008 - unsigned long long total; 1009 - 1010 - spin_lock(&EXT4_I(inode)->i_block_reservation_lock); 1011 - total = EXT4_I(inode)->i_reserved_data_blocks + 1012 - EXT4_I(inode)->i_reserved_meta_blocks; 1013 - spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); 1014 - 1015 - return (total << inode->i_blkbits); 1009 + return &EXT4_I(inode)->i_reserved_quota; 1016 1010 } 1011 + #endif 1017 1012 /* 1018 1013 * Calculate the number of metadata blocks need to reserve 1019 1014 * to allocate @blocks for non extent file based file ··· 1046 1051 static void ext4_da_update_reserve_space(struct inode *inode, int used) 1047 1052 { 1048 1053 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 1049 - int total, mdb, mdb_free; 1054 + int total, mdb, mdb_free, mdb_claim = 0; 1050 1055 1051 1056 spin_lock(&EXT4_I(inode)->i_block_reservation_lock); 1052 1057 /* recalculate the number of metablocks still need to be reserved */ ··· 1059 1064 1060 1065 if (mdb_free) { 1061 1066 /* Account for allocated meta_blocks */ 1062 - mdb_free -= EXT4_I(inode)->i_allocated_meta_blocks; 1067 + mdb_claim = EXT4_I(inode)->i_allocated_meta_blocks; 1068 + BUG_ON(mdb_free < mdb_claim); 1069 + mdb_free -= mdb_claim; 1063 1070 1064 1071 /* update fs dirty blocks counter */ 1065 1072 percpu_counter_sub(&sbi->s_dirtyblocks_counter, mdb_free); ··· 1072 1075 /* update per-inode reservations */ 1073 1076 BUG_ON(used > EXT4_I(inode)->i_reserved_data_blocks); 1074 1077 EXT4_I(inode)->i_reserved_data_blocks -= used; 1078 + percpu_counter_sub(&sbi->s_dirtyblocks_counter, used + mdb_claim); 1075 1079 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); 1080 + 1081 + vfs_dq_claim_block(inode, used + mdb_claim); 1076 1082 1077 1083 /* 1078 1084 * free those over-booking quota for metadata blocks ··· 1816 1816 1817 1817 md_needed = mdblocks - EXT4_I(inode)->i_reserved_meta_blocks; 1818 1818 total = md_needed + nrblocks; 1819 + spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); 1819 1820 1820 1821 /* 1821 1822 * Make quota reservation here to prevent quota overflow 1822 1823 * later. Real quota accounting is done at pages writeout 1823 1824 * time. 1824 1825 */ 1825 - if (vfs_dq_reserve_block(inode, total)) { 1826 - spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); 1826 + if (vfs_dq_reserve_block(inode, total)) 1827 1827 return -EDQUOT; 1828 - } 1829 1828 1830 1829 if (ext4_claim_free_blocks(sbi, total)) { 1831 - spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); 1832 1830 vfs_dq_release_reservation_block(inode, total); 1833 1831 if (ext4_should_retry_alloc(inode->i_sb, &retries)) { 1834 1832 yield(); ··· 1834 1836 } 1835 1837 return -ENOSPC; 1836 1838 } 1839 + spin_lock(&EXT4_I(inode)->i_block_reservation_lock); 1837 1840 EXT4_I(inode)->i_reserved_data_blocks += nrblocks; 1838 - EXT4_I(inode)->i_reserved_meta_blocks = mdblocks; 1839 - 1841 + EXT4_I(inode)->i_reserved_meta_blocks += md_needed; 1840 1842 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); 1843 + 1841 1844 return 0; /* success */ 1842 1845 } 1843 1846 ··· 4793 4794 ((__u64)le16_to_cpu(raw_inode->i_file_acl_high)) << 32; 4794 4795 inode->i_size = ext4_isize(raw_inode); 4795 4796 ei->i_disksize = inode->i_size; 4797 + #ifdef CONFIG_QUOTA 4798 + ei->i_reserved_quota = 0; 4799 + #endif 4796 4800 inode->i_generation = le32_to_cpu(raw_inode->i_generation); 4797 4801 ei->i_block_group = iloc.block_group; 4798 4802 ei->i_last_alloc_group = ~0;
-6
fs/ext4/mballoc.c
··· 2755 2755 if (!(ac->ac_flags & EXT4_MB_DELALLOC_RESERVED)) 2756 2756 /* release all the reserved blocks if non delalloc */ 2757 2757 percpu_counter_sub(&sbi->s_dirtyblocks_counter, reserv_blks); 2758 - else { 2759 - percpu_counter_sub(&sbi->s_dirtyblocks_counter, 2760 - ac->ac_b_ex.fe_len); 2761 - /* convert reserved quota blocks to real quota blocks */ 2762 - vfs_dq_claim_block(ac->ac_inode, ac->ac_b_ex.fe_len); 2763 - } 2764 2758 2765 2759 if (sbi->s_log_groups_per_flex) { 2766 2760 ext4_group_t flex_group = ext4_flex_group(sbi,
+5
fs/ext4/super.c
··· 704 704 ei->i_allocated_meta_blocks = 0; 705 705 ei->i_delalloc_reserved_flag = 0; 706 706 spin_lock_init(&(ei->i_block_reservation_lock)); 707 + #ifdef CONFIG_QUOTA 708 + ei->i_reserved_quota = 0; 709 + #endif 707 710 INIT_LIST_HEAD(&ei->i_aio_dio_complete_list); 708 711 ei->cur_aio_dio = NULL; 709 712 ei->i_sync_tid = 0; ··· 1017 1014 .reserve_space = dquot_reserve_space, 1018 1015 .claim_space = dquot_claim_space, 1019 1016 .release_rsv = dquot_release_reserved_space, 1017 + #ifdef CONFIG_QUOTA 1020 1018 .get_reserved_space = ext4_get_reserved_space, 1019 + #endif 1021 1020 .alloc_inode = dquot_alloc_inode, 1022 1021 .free_space = dquot_free_space, 1023 1022 .free_inode = dquot_free_inode,
+1 -1
fs/jbd/journal.c
··· 1913 1913 { 1914 1914 jbd_debugfs_dir = debugfs_create_dir("jbd", NULL); 1915 1915 if (jbd_debugfs_dir) 1916 - jbd_debug = debugfs_create_u8("jbd-debug", S_IRUGO, 1916 + jbd_debug = debugfs_create_u8("jbd-debug", S_IRUGO | S_IWUSR, 1917 1917 jbd_debugfs_dir, 1918 1918 &journal_enable_debug); 1919 1919 }
+2 -1
fs/jbd2/journal.c
··· 2115 2115 { 2116 2116 jbd2_debugfs_dir = debugfs_create_dir("jbd2", NULL); 2117 2117 if (jbd2_debugfs_dir) 2118 - jbd2_debug = debugfs_create_u8(JBD2_DEBUG_NAME, S_IRUGO, 2118 + jbd2_debug = debugfs_create_u8(JBD2_DEBUG_NAME, 2119 + S_IRUGO | S_IWUSR, 2119 2120 jbd2_debugfs_dir, 2120 2121 &jbd2_journal_enable_debug); 2121 2122 }
+156 -132
fs/quota/dquot.c
··· 323 323 } 324 324 EXPORT_SYMBOL(dquot_mark_dquot_dirty); 325 325 326 + /* Dirtify all the dquots - this can block when journalling */ 327 + static inline int mark_all_dquot_dirty(struct dquot * const *dquot) 328 + { 329 + int ret, err, cnt; 330 + 331 + ret = err = 0; 332 + for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 333 + if (dquot[cnt]) 334 + /* Even in case of error we have to continue */ 335 + ret = mark_dquot_dirty(dquot[cnt]); 336 + if (!err) 337 + err = ret; 338 + } 339 + return err; 340 + } 341 + 342 + static inline void dqput_all(struct dquot **dquot) 343 + { 344 + unsigned int cnt; 345 + 346 + for (cnt = 0; cnt < MAXQUOTAS; cnt++) 347 + dqput(dquot[cnt]); 348 + } 349 + 326 350 /* This function needs dq_list_lock */ 327 351 static inline int clear_dquot_dirty(struct dquot *dquot) 328 352 { ··· 1292 1268 out_err: 1293 1269 up_write(&sb_dqopt(sb)->dqptr_sem); 1294 1270 /* Drop unused references */ 1295 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1296 - dqput(got[cnt]); 1271 + dqput_all(got); 1297 1272 return ret; 1298 1273 } 1299 1274 EXPORT_SYMBOL(dquot_initialize); ··· 1311 1288 inode->i_dquot[cnt] = NULL; 1312 1289 } 1313 1290 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1314 - 1315 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1316 - dqput(put[cnt]); 1291 + dqput_all(put); 1317 1292 return 0; 1318 1293 } 1319 1294 EXPORT_SYMBOL(dquot_drop); ··· 1340 1319 EXPORT_SYMBOL(vfs_dq_drop); 1341 1320 1342 1321 /* 1322 + * inode_reserved_space is managed internally by quota, and protected by 1323 + * i_lock similar to i_blocks+i_bytes. 1324 + */ 1325 + static qsize_t *inode_reserved_space(struct inode * inode) 1326 + { 1327 + /* Filesystem must explicitly define it's own method in order to use 1328 + * quota reservation interface */ 1329 + BUG_ON(!inode->i_sb->dq_op->get_reserved_space); 1330 + return inode->i_sb->dq_op->get_reserved_space(inode); 1331 + } 1332 + 1333 + static void inode_add_rsv_space(struct inode *inode, qsize_t number) 1334 + { 1335 + spin_lock(&inode->i_lock); 1336 + *inode_reserved_space(inode) += number; 1337 + spin_unlock(&inode->i_lock); 1338 + } 1339 + 1340 + 1341 + static void inode_claim_rsv_space(struct inode *inode, qsize_t number) 1342 + { 1343 + spin_lock(&inode->i_lock); 1344 + *inode_reserved_space(inode) -= number; 1345 + __inode_add_bytes(inode, number); 1346 + spin_unlock(&inode->i_lock); 1347 + } 1348 + 1349 + static void inode_sub_rsv_space(struct inode *inode, qsize_t number) 1350 + { 1351 + spin_lock(&inode->i_lock); 1352 + *inode_reserved_space(inode) -= number; 1353 + spin_unlock(&inode->i_lock); 1354 + } 1355 + 1356 + static qsize_t inode_get_rsv_space(struct inode *inode) 1357 + { 1358 + qsize_t ret; 1359 + spin_lock(&inode->i_lock); 1360 + ret = *inode_reserved_space(inode); 1361 + spin_unlock(&inode->i_lock); 1362 + return ret; 1363 + } 1364 + 1365 + static void inode_incr_space(struct inode *inode, qsize_t number, 1366 + int reserve) 1367 + { 1368 + if (reserve) 1369 + inode_add_rsv_space(inode, number); 1370 + else 1371 + inode_add_bytes(inode, number); 1372 + } 1373 + 1374 + static void inode_decr_space(struct inode *inode, qsize_t number, int reserve) 1375 + { 1376 + if (reserve) 1377 + inode_sub_rsv_space(inode, number); 1378 + else 1379 + inode_sub_bytes(inode, number); 1380 + } 1381 + 1382 + /* 1343 1383 * Following four functions update i_blocks+i_bytes fields and 1344 1384 * quota information (together with appropriate checks) 1345 1385 * NOTE: We absolutely rely on the fact that caller dirties ··· 1418 1336 int cnt, ret = QUOTA_OK; 1419 1337 char warntype[MAXQUOTAS]; 1420 1338 1339 + /* 1340 + * First test before acquiring mutex - solves deadlocks when we 1341 + * re-enter the quota code and are already holding the mutex 1342 + */ 1343 + if (IS_NOQUOTA(inode)) { 1344 + inode_incr_space(inode, number, reserve); 1345 + goto out; 1346 + } 1347 + 1348 + down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1349 + if (IS_NOQUOTA(inode)) { 1350 + inode_incr_space(inode, number, reserve); 1351 + goto out_unlock; 1352 + } 1353 + 1421 1354 for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1422 1355 warntype[cnt] = QUOTA_NL_NOWARN; 1423 1356 ··· 1443 1346 if (check_bdq(inode->i_dquot[cnt], number, warn, warntype+cnt) 1444 1347 == NO_QUOTA) { 1445 1348 ret = NO_QUOTA; 1446 - goto out_unlock; 1349 + spin_unlock(&dq_data_lock); 1350 + goto out_flush_warn; 1447 1351 } 1448 1352 } 1449 1353 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { ··· 1455 1357 else 1456 1358 dquot_incr_space(inode->i_dquot[cnt], number); 1457 1359 } 1458 - if (!reserve) 1459 - inode_add_bytes(inode, number); 1460 - out_unlock: 1360 + inode_incr_space(inode, number, reserve); 1461 1361 spin_unlock(&dq_data_lock); 1362 + 1363 + if (reserve) 1364 + goto out_flush_warn; 1365 + mark_all_dquot_dirty(inode->i_dquot); 1366 + out_flush_warn: 1462 1367 flush_warnings(inode->i_dquot, warntype); 1368 + out_unlock: 1369 + up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1370 + out: 1463 1371 return ret; 1464 1372 } 1465 1373 1466 1374 int dquot_alloc_space(struct inode *inode, qsize_t number, int warn) 1467 1375 { 1468 - int cnt, ret = QUOTA_OK; 1469 - 1470 - /* 1471 - * First test before acquiring mutex - solves deadlocks when we 1472 - * re-enter the quota code and are already holding the mutex 1473 - */ 1474 - if (IS_NOQUOTA(inode)) { 1475 - inode_add_bytes(inode, number); 1476 - goto out; 1477 - } 1478 - 1479 - down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1480 - if (IS_NOQUOTA(inode)) { 1481 - inode_add_bytes(inode, number); 1482 - goto out_unlock; 1483 - } 1484 - 1485 - ret = __dquot_alloc_space(inode, number, warn, 0); 1486 - if (ret == NO_QUOTA) 1487 - goto out_unlock; 1488 - 1489 - /* Dirtify all the dquots - this can block when journalling */ 1490 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1491 - if (inode->i_dquot[cnt]) 1492 - mark_dquot_dirty(inode->i_dquot[cnt]); 1493 - out_unlock: 1494 - up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1495 - out: 1496 - return ret; 1376 + return __dquot_alloc_space(inode, number, warn, 0); 1497 1377 } 1498 1378 EXPORT_SYMBOL(dquot_alloc_space); 1499 1379 1500 1380 int dquot_reserve_space(struct inode *inode, qsize_t number, int warn) 1501 1381 { 1502 - int ret = QUOTA_OK; 1503 - 1504 - if (IS_NOQUOTA(inode)) 1505 - goto out; 1506 - 1507 - down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1508 - if (IS_NOQUOTA(inode)) 1509 - goto out_unlock; 1510 - 1511 - ret = __dquot_alloc_space(inode, number, warn, 1); 1512 - out_unlock: 1513 - up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1514 - out: 1515 - return ret; 1382 + return __dquot_alloc_space(inode, number, warn, 1); 1516 1383 } 1517 1384 EXPORT_SYMBOL(dquot_reserve_space); 1518 1385 ··· 1518 1455 warn_put_all: 1519 1456 spin_unlock(&dq_data_lock); 1520 1457 if (ret == QUOTA_OK) 1521 - /* Dirtify all the dquots - this can block when journalling */ 1522 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1523 - if (inode->i_dquot[cnt]) 1524 - mark_dquot_dirty(inode->i_dquot[cnt]); 1458 + mark_all_dquot_dirty(inode->i_dquot); 1525 1459 flush_warnings(inode->i_dquot, warntype); 1526 1460 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1527 1461 return ret; ··· 1531 1471 int ret = QUOTA_OK; 1532 1472 1533 1473 if (IS_NOQUOTA(inode)) { 1534 - inode_add_bytes(inode, number); 1474 + inode_claim_rsv_space(inode, number); 1535 1475 goto out; 1536 1476 } 1537 1477 1538 1478 down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1539 1479 if (IS_NOQUOTA(inode)) { 1540 1480 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1541 - inode_add_bytes(inode, number); 1481 + inode_claim_rsv_space(inode, number); 1542 1482 goto out; 1543 1483 } 1544 1484 ··· 1550 1490 number); 1551 1491 } 1552 1492 /* Update inode bytes */ 1553 - inode_add_bytes(inode, number); 1493 + inode_claim_rsv_space(inode, number); 1554 1494 spin_unlock(&dq_data_lock); 1555 - /* Dirtify all the dquots - this can block when journalling */ 1556 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1557 - if (inode->i_dquot[cnt]) 1558 - mark_dquot_dirty(inode->i_dquot[cnt]); 1495 + mark_all_dquot_dirty(inode->i_dquot); 1559 1496 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1560 1497 out: 1561 1498 return ret; ··· 1560 1503 EXPORT_SYMBOL(dquot_claim_space); 1561 1504 1562 1505 /* 1563 - * Release reserved quota space 1564 - */ 1565 - void dquot_release_reserved_space(struct inode *inode, qsize_t number) 1566 - { 1567 - int cnt; 1568 - 1569 - if (IS_NOQUOTA(inode)) 1570 - goto out; 1571 - 1572 - down_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1573 - if (IS_NOQUOTA(inode)) 1574 - goto out_unlock; 1575 - 1576 - spin_lock(&dq_data_lock); 1577 - /* Release reserved dquots */ 1578 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1579 - if (inode->i_dquot[cnt]) 1580 - dquot_free_reserved_space(inode->i_dquot[cnt], number); 1581 - } 1582 - spin_unlock(&dq_data_lock); 1583 - 1584 - out_unlock: 1585 - up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1586 - out: 1587 - return; 1588 - } 1589 - EXPORT_SYMBOL(dquot_release_reserved_space); 1590 - 1591 - /* 1592 1506 * This operation can block, but only after everything is updated 1593 1507 */ 1594 - int dquot_free_space(struct inode *inode, qsize_t number) 1508 + int __dquot_free_space(struct inode *inode, qsize_t number, int reserve) 1595 1509 { 1596 1510 unsigned int cnt; 1597 1511 char warntype[MAXQUOTAS]; ··· 1571 1543 * re-enter the quota code and are already holding the mutex */ 1572 1544 if (IS_NOQUOTA(inode)) { 1573 1545 out_sub: 1574 - inode_sub_bytes(inode, number); 1546 + inode_decr_space(inode, number, reserve); 1575 1547 return QUOTA_OK; 1576 1548 } 1577 1549 ··· 1586 1558 if (!inode->i_dquot[cnt]) 1587 1559 continue; 1588 1560 warntype[cnt] = info_bdq_free(inode->i_dquot[cnt], number); 1589 - dquot_decr_space(inode->i_dquot[cnt], number); 1561 + if (reserve) 1562 + dquot_free_reserved_space(inode->i_dquot[cnt], number); 1563 + else 1564 + dquot_decr_space(inode->i_dquot[cnt], number); 1590 1565 } 1591 - inode_sub_bytes(inode, number); 1566 + inode_decr_space(inode, number, reserve); 1592 1567 spin_unlock(&dq_data_lock); 1593 - /* Dirtify all the dquots - this can block when journalling */ 1594 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1595 - if (inode->i_dquot[cnt]) 1596 - mark_dquot_dirty(inode->i_dquot[cnt]); 1568 + 1569 + if (reserve) 1570 + goto out_unlock; 1571 + mark_all_dquot_dirty(inode->i_dquot); 1572 + out_unlock: 1597 1573 flush_warnings(inode->i_dquot, warntype); 1598 1574 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1599 1575 return QUOTA_OK; 1600 1576 } 1577 + 1578 + int dquot_free_space(struct inode *inode, qsize_t number) 1579 + { 1580 + return __dquot_free_space(inode, number, 0); 1581 + } 1601 1582 EXPORT_SYMBOL(dquot_free_space); 1583 + 1584 + /* 1585 + * Release reserved quota space 1586 + */ 1587 + void dquot_release_reserved_space(struct inode *inode, qsize_t number) 1588 + { 1589 + __dquot_free_space(inode, number, 1); 1590 + 1591 + } 1592 + EXPORT_SYMBOL(dquot_release_reserved_space); 1602 1593 1603 1594 /* 1604 1595 * This operation can block, but only after everything is updated ··· 1646 1599 dquot_decr_inodes(inode->i_dquot[cnt], number); 1647 1600 } 1648 1601 spin_unlock(&dq_data_lock); 1649 - /* Dirtify all the dquots - this can block when journalling */ 1650 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1651 - if (inode->i_dquot[cnt]) 1652 - mark_dquot_dirty(inode->i_dquot[cnt]); 1602 + mark_all_dquot_dirty(inode->i_dquot); 1653 1603 flush_warnings(inode->i_dquot, warntype); 1654 1604 up_read(&sb_dqopt(inode->i_sb)->dqptr_sem); 1655 1605 return QUOTA_OK; 1656 1606 } 1657 1607 EXPORT_SYMBOL(dquot_free_inode); 1658 - 1659 - /* 1660 - * call back function, get reserved quota space from underlying fs 1661 - */ 1662 - qsize_t dquot_get_reserved_space(struct inode *inode) 1663 - { 1664 - qsize_t reserved_space = 0; 1665 - 1666 - if (sb_any_quota_active(inode->i_sb) && 1667 - inode->i_sb->dq_op->get_reserved_space) 1668 - reserved_space = inode->i_sb->dq_op->get_reserved_space(inode); 1669 - return reserved_space; 1670 - } 1671 1608 1672 1609 /* 1673 1610 * Transfer the number of inode and blocks from one diskquota to an other. ··· 1696 1665 } 1697 1666 spin_lock(&dq_data_lock); 1698 1667 cur_space = inode_get_bytes(inode); 1699 - rsv_space = dquot_get_reserved_space(inode); 1668 + rsv_space = inode_get_rsv_space(inode); 1700 1669 space = cur_space + rsv_space; 1701 1670 /* Build the transfer_from list and check the limits */ 1702 1671 for (cnt = 0; cnt < MAXQUOTAS; cnt++) { ··· 1740 1709 spin_unlock(&dq_data_lock); 1741 1710 up_write(&sb_dqopt(inode->i_sb)->dqptr_sem); 1742 1711 1743 - /* Dirtify all the dquots - this can block when journalling */ 1744 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1745 - if (transfer_from[cnt]) 1746 - mark_dquot_dirty(transfer_from[cnt]); 1747 - if (transfer_to[cnt]) { 1748 - mark_dquot_dirty(transfer_to[cnt]); 1749 - /* The reference we got is transferred to the inode */ 1750 - transfer_to[cnt] = NULL; 1751 - } 1752 - } 1712 + mark_all_dquot_dirty(transfer_from); 1713 + mark_all_dquot_dirty(transfer_to); 1714 + /* The reference we got is transferred to the inode */ 1715 + for (cnt = 0; cnt < MAXQUOTAS; cnt++) 1716 + transfer_to[cnt] = NULL; 1753 1717 warn_put_all: 1754 1718 flush_warnings(transfer_to, warntype_to); 1755 1719 flush_warnings(transfer_from, warntype_from_inodes); 1756 1720 flush_warnings(transfer_from, warntype_from_space); 1757 1721 put_all: 1758 - for (cnt = 0; cnt < MAXQUOTAS; cnt++) { 1759 - dqput(transfer_from[cnt]); 1760 - dqput(transfer_to[cnt]); 1761 - } 1722 + dqput_all(transfer_from); 1723 + dqput_all(transfer_to); 1762 1724 return ret; 1763 1725 over_quota: 1764 1726 spin_unlock(&dq_data_lock);
+6 -3
fs/quota/quota_v2.c
··· 97 97 unsigned int version; 98 98 99 99 if (!v2_read_header(sb, type, &dqhead)) 100 - return 0; 100 + return -1; 101 101 version = le32_to_cpu(dqhead.dqh_version); 102 + if ((info->dqi_fmt_id == QFMT_VFS_V0 && version != 0) || 103 + (info->dqi_fmt_id == QFMT_VFS_V1 && version != 1)) 104 + return -1; 102 105 103 106 size = sb->s_op->quota_read(sb, type, (char *)&dinfo, 104 107 sizeof(struct v2_disk_dqinfo), V2_DQINFOOFF); ··· 123 120 info->dqi_maxilimit = 0xffffffff; 124 121 } else { 125 122 /* used space is stored as unsigned 64-bit value */ 126 - info->dqi_maxblimit = 0xffffffffffffffff; /* 2^64-1 */ 127 - info->dqi_maxilimit = 0xffffffffffffffff; 123 + info->dqi_maxblimit = 0xffffffffffffffffULL; /* 2^64-1 */ 124 + info->dqi_maxilimit = 0xffffffffffffffffULL; 128 125 } 129 126 info->dqi_bgrace = le32_to_cpu(dinfo.dqi_bgrace); 130 127 info->dqi_igrace = le32_to_cpu(dinfo.dqi_igrace);
+8 -2
fs/stat.c
··· 401 401 } 402 402 #endif /* __ARCH_WANT_STAT64 */ 403 403 404 - void inode_add_bytes(struct inode *inode, loff_t bytes) 404 + /* Caller is here responsible for sufficient locking (ie. inode->i_lock) */ 405 + void __inode_add_bytes(struct inode *inode, loff_t bytes) 405 406 { 406 - spin_lock(&inode->i_lock); 407 407 inode->i_blocks += bytes >> 9; 408 408 bytes &= 511; 409 409 inode->i_bytes += bytes; ··· 411 411 inode->i_blocks++; 412 412 inode->i_bytes -= 512; 413 413 } 414 + } 415 + 416 + void inode_add_bytes(struct inode *inode, loff_t bytes) 417 + { 418 + spin_lock(&inode->i_lock); 419 + __inode_add_bytes(inode, bytes); 414 420 spin_unlock(&inode->i_lock); 415 421 } 416 422
+2
include/linux/ext3_fs_sb.h
··· 72 72 struct inode * s_journal_inode; 73 73 struct journal_s * s_journal; 74 74 struct list_head s_orphan; 75 + struct mutex s_orphan_lock; 76 + struct mutex s_resize_lock; 75 77 unsigned long s_commit_interval; 76 78 struct block_device *journal_bdev; 77 79 #ifdef CONFIG_JBD_DEBUG
+5 -2
include/linux/ext3_jbd.h
··· 44 44 45 45 #define EXT3_DATA_TRANS_BLOCKS(sb) (EXT3_SINGLEDATA_TRANS_BLOCKS + \ 46 46 EXT3_XATTR_TRANS_BLOCKS - 2 + \ 47 - 2*EXT3_QUOTA_TRANS_BLOCKS(sb)) 47 + EXT3_MAXQUOTAS_TRANS_BLOCKS(sb)) 48 48 49 49 /* Delete operations potentially hit one directory's namespace plus an 50 50 * entire inode, plus arbitrary amounts of bitmap/indirection data. Be 51 51 * generous. We can grow the delete transaction later if necessary. */ 52 52 53 - #define EXT3_DELETE_TRANS_BLOCKS(sb) (2 * EXT3_DATA_TRANS_BLOCKS(sb) + 64) 53 + #define EXT3_DELETE_TRANS_BLOCKS(sb) (EXT3_MAXQUOTAS_TRANS_BLOCKS(sb) + 64) 54 54 55 55 /* Define an arbitrary limit for the amount of data we will anticipate 56 56 * writing to any given transaction. For unbounded transactions such as ··· 86 86 #define EXT3_QUOTA_INIT_BLOCKS(sb) 0 87 87 #define EXT3_QUOTA_DEL_BLOCKS(sb) 0 88 88 #endif 89 + #define EXT3_MAXQUOTAS_TRANS_BLOCKS(sb) (MAXQUOTAS*EXT3_QUOTA_TRANS_BLOCKS(sb)) 90 + #define EXT3_MAXQUOTAS_INIT_BLOCKS(sb) (MAXQUOTAS*EXT3_QUOTA_INIT_BLOCKS(sb)) 91 + #define EXT3_MAXQUOTAS_DEL_BLOCKS(sb) (MAXQUOTAS*EXT3_QUOTA_DEL_BLOCKS(sb)) 89 92 90 93 int 91 94 ext3_mark_iloc_dirty(handle_t *handle,
+1
include/linux/fs.h
··· 2297 2297 extern int generic_readlink(struct dentry *, char __user *, int); 2298 2298 extern void generic_fillattr(struct inode *, struct kstat *); 2299 2299 extern int vfs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 2300 + void __inode_add_bytes(struct inode *inode, loff_t bytes); 2300 2301 void inode_add_bytes(struct inode *inode, loff_t bytes); 2301 2302 void inode_sub_bytes(struct inode *inode, loff_t bytes); 2302 2303 loff_t inode_get_bytes(struct inode *inode);
+3 -2
include/linux/quota.h
··· 315 315 int (*claim_space) (struct inode *, qsize_t); 316 316 /* release rsved quota for delayed alloc */ 317 317 void (*release_rsv) (struct inode *, qsize_t); 318 - /* get reserved quota for delayed alloc */ 319 - qsize_t (*get_reserved_space) (struct inode *); 318 + /* get reserved quota for delayed alloc, value returned is managed by 319 + * quota code only */ 320 + qsize_t *(*get_reserved_space) (struct inode *); 320 321 }; 321 322 322 323 /* Operations handling requests from userspace */