aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/namei.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4/namei.c')
-rw-r--r--fs/ext4/namei.c134
1 files changed, 81 insertions, 53 deletions
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 63adcb792988..ba702bd7910d 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -74,10 +74,6 @@ static struct buffer_head *ext4_append(handle_t *handle,
74#define assert(test) J_ASSERT(test) 74#define assert(test) J_ASSERT(test)
75#endif 75#endif
76 76
77#ifndef swap
78#define swap(x, y) do { typeof(x) z = x; x = y; y = z; } while (0)
79#endif
80
81#ifdef DX_DEBUG 77#ifdef DX_DEBUG
82#define dxtrace(command) command 78#define dxtrace(command) command
83#else 79#else
@@ -372,6 +368,8 @@ dx_probe(const struct qstr *d_name, struct inode *dir,
372 goto fail; 368 goto fail;
373 } 369 }
374 hinfo->hash_version = root->info.hash_version; 370 hinfo->hash_version = root->info.hash_version;
371 if (hinfo->hash_version <= DX_HASH_TEA)
372 hinfo->hash_version += EXT4_SB(dir->i_sb)->s_hash_unsigned;
375 hinfo->seed = EXT4_SB(dir->i_sb)->s_hash_seed; 373 hinfo->seed = EXT4_SB(dir->i_sb)->s_hash_seed;
376 if (d_name) 374 if (d_name)
377 ext4fs_dirhash(d_name->name, d_name->len, hinfo); 375 ext4fs_dirhash(d_name->name, d_name->len, hinfo);
@@ -641,6 +639,9 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
641 dir = dir_file->f_path.dentry->d_inode; 639 dir = dir_file->f_path.dentry->d_inode;
642 if (!(EXT4_I(dir)->i_flags & EXT4_INDEX_FL)) { 640 if (!(EXT4_I(dir)->i_flags & EXT4_INDEX_FL)) {
643 hinfo.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version; 641 hinfo.hash_version = EXT4_SB(dir->i_sb)->s_def_hash_version;
642 if (hinfo.hash_version <= DX_HASH_TEA)
643 hinfo.hash_version +=
644 EXT4_SB(dir->i_sb)->s_hash_unsigned;
644 hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed; 645 hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
645 count = htree_dirblock_to_tree(dir_file, dir, 0, &hinfo, 646 count = htree_dirblock_to_tree(dir_file, dir, 0, &hinfo,
646 start_hash, start_minor_hash); 647 start_hash, start_minor_hash);
@@ -806,7 +807,7 @@ static inline int ext4_match (int len, const char * const name,
806static inline int search_dirblock(struct buffer_head *bh, 807static inline int search_dirblock(struct buffer_head *bh,
807 struct inode *dir, 808 struct inode *dir,
808 const struct qstr *d_name, 809 const struct qstr *d_name,
809 unsigned long offset, 810 unsigned int offset,
810 struct ext4_dir_entry_2 ** res_dir) 811 struct ext4_dir_entry_2 ** res_dir)
811{ 812{
812 struct ext4_dir_entry_2 * de; 813 struct ext4_dir_entry_2 * de;
@@ -1043,11 +1044,11 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, stru
1043 bh = ext4_find_entry(dir, &dentry->d_name, &de); 1044 bh = ext4_find_entry(dir, &dentry->d_name, &de);
1044 inode = NULL; 1045 inode = NULL;
1045 if (bh) { 1046 if (bh) {
1046 unsigned long ino = le32_to_cpu(de->inode); 1047 __u32 ino = le32_to_cpu(de->inode);
1047 brelse(bh); 1048 brelse(bh);
1048 if (!ext4_valid_inum(dir->i_sb, ino)) { 1049 if (!ext4_valid_inum(dir->i_sb, ino)) {
1049 ext4_error(dir->i_sb, "ext4_lookup", 1050 ext4_error(dir->i_sb, "ext4_lookup",
1050 "bad inode number: %lu", ino); 1051 "bad inode number: %u", ino);
1051 return ERR_PTR(-EIO); 1052 return ERR_PTR(-EIO);
1052 } 1053 }
1053 inode = ext4_iget(dir->i_sb, ino); 1054 inode = ext4_iget(dir->i_sb, ino);
@@ -1060,7 +1061,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, stru
1060 1061
1061struct dentry *ext4_get_parent(struct dentry *child) 1062struct dentry *ext4_get_parent(struct dentry *child)
1062{ 1063{
1063 unsigned long ino; 1064 __u32 ino;
1064 struct inode *inode; 1065 struct inode *inode;
1065 static const struct qstr dotdot = { 1066 static const struct qstr dotdot = {
1066 .name = "..", 1067 .name = "..",
@@ -1078,7 +1079,7 @@ struct dentry *ext4_get_parent(struct dentry *child)
1078 1079
1079 if (!ext4_valid_inum(child->d_inode->i_sb, ino)) { 1080 if (!ext4_valid_inum(child->d_inode->i_sb, ino)) {
1080 ext4_error(child->d_inode->i_sb, "ext4_get_parent", 1081 ext4_error(child->d_inode->i_sb, "ext4_get_parent",
1081 "bad inode number: %lu", ino); 1082 "bad inode number: %u", ino);
1082 return ERR_PTR(-EIO); 1083 return ERR_PTR(-EIO);
1083 } 1084 }
1084 1085
@@ -1166,9 +1167,9 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
1166 u32 hash2; 1167 u32 hash2;
1167 struct dx_map_entry *map; 1168 struct dx_map_entry *map;
1168 char *data1 = (*bh)->b_data, *data2; 1169 char *data1 = (*bh)->b_data, *data2;
1169 unsigned split, move, size, i; 1170 unsigned split, move, size;
1170 struct ext4_dir_entry_2 *de = NULL, *de2; 1171 struct ext4_dir_entry_2 *de = NULL, *de2;
1171 int err = 0; 1172 int err = 0, i;
1172 1173
1173 bh2 = ext4_append (handle, dir, &newblock, &err); 1174 bh2 = ext4_append (handle, dir, &newblock, &err);
1174 if (!(bh2)) { 1175 if (!(bh2)) {
@@ -1228,10 +1229,10 @@ static struct ext4_dir_entry_2 *do_split(handle_t *handle, struct inode *dir,
1228 de = de2; 1229 de = de2;
1229 } 1230 }
1230 dx_insert_block(frame, hash2 + continued, newblock); 1231 dx_insert_block(frame, hash2 + continued, newblock);
1231 err = ext4_journal_dirty_metadata(handle, bh2); 1232 err = ext4_handle_dirty_metadata(handle, dir, bh2);
1232 if (err) 1233 if (err)
1233 goto journal_error; 1234 goto journal_error;
1234 err = ext4_journal_dirty_metadata(handle, frame->bh); 1235 err = ext4_handle_dirty_metadata(handle, dir, frame->bh);
1235 if (err) 1236 if (err)
1236 goto journal_error; 1237 goto journal_error;
1237 brelse(bh2); 1238 brelse(bh2);
@@ -1266,7 +1267,7 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
1266 struct inode *dir = dentry->d_parent->d_inode; 1267 struct inode *dir = dentry->d_parent->d_inode;
1267 const char *name = dentry->d_name.name; 1268 const char *name = dentry->d_name.name;
1268 int namelen = dentry->d_name.len; 1269 int namelen = dentry->d_name.len;
1269 unsigned long offset = 0; 1270 unsigned int offset = 0;
1270 unsigned short reclen; 1271 unsigned short reclen;
1271 int nlen, rlen, err; 1272 int nlen, rlen, err;
1272 char *top; 1273 char *top;
@@ -1335,8 +1336,8 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
1335 ext4_update_dx_flag(dir); 1336 ext4_update_dx_flag(dir);
1336 dir->i_version++; 1337 dir->i_version++;
1337 ext4_mark_inode_dirty(handle, dir); 1338 ext4_mark_inode_dirty(handle, dir);
1338 BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata"); 1339 BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata");
1339 err = ext4_journal_dirty_metadata(handle, bh); 1340 err = ext4_handle_dirty_metadata(handle, dir, bh);
1340 if (err) 1341 if (err)
1341 ext4_std_error(dir->i_sb, err); 1342 ext4_std_error(dir->i_sb, err);
1342 brelse(bh); 1343 brelse(bh);
@@ -1367,7 +1368,7 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1367 struct fake_dirent *fde; 1368 struct fake_dirent *fde;
1368 1369
1369 blocksize = dir->i_sb->s_blocksize; 1370 blocksize = dir->i_sb->s_blocksize;
1370 dxtrace(printk(KERN_DEBUG "Creating index\n")); 1371 dxtrace(printk(KERN_DEBUG "Creating index: inode %lu\n", dir->i_ino));
1371 retval = ext4_journal_get_write_access(handle, bh); 1372 retval = ext4_journal_get_write_access(handle, bh);
1372 if (retval) { 1373 if (retval) {
1373 ext4_std_error(dir->i_sb, retval); 1374 ext4_std_error(dir->i_sb, retval);
@@ -1376,6 +1377,20 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1376 } 1377 }
1377 root = (struct dx_root *) bh->b_data; 1378 root = (struct dx_root *) bh->b_data;
1378 1379
1380 /* The 0th block becomes the root, move the dirents out */
1381 fde = &root->dotdot;
1382 de = (struct ext4_dir_entry_2 *)((char *)fde +
1383 ext4_rec_len_from_disk(fde->rec_len));
1384 if ((char *) de >= (((char *) root) + blocksize)) {
1385 ext4_error(dir->i_sb, __func__,
1386 "invalid rec_len for '..' in inode %lu",
1387 dir->i_ino);
1388 brelse(bh);
1389 return -EIO;
1390 }
1391 len = ((char *) root) + blocksize - (char *) de;
1392
1393 /* Allocate new block for the 0th block's dirents */
1379 bh2 = ext4_append(handle, dir, &block, &retval); 1394 bh2 = ext4_append(handle, dir, &block, &retval);
1380 if (!(bh2)) { 1395 if (!(bh2)) {
1381 brelse(bh); 1396 brelse(bh);
@@ -1384,11 +1399,6 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1384 EXT4_I(dir)->i_flags |= EXT4_INDEX_FL; 1399 EXT4_I(dir)->i_flags |= EXT4_INDEX_FL;
1385 data1 = bh2->b_data; 1400 data1 = bh2->b_data;
1386 1401
1387 /* The 0th block becomes the root, move the dirents out */
1388 fde = &root->dotdot;
1389 de = (struct ext4_dir_entry_2 *)((char *)fde +
1390 ext4_rec_len_from_disk(fde->rec_len));
1391 len = ((char *) root) + blocksize - (char *) de;
1392 memcpy (data1, de, len); 1402 memcpy (data1, de, len);
1393 de = (struct ext4_dir_entry_2 *) data1; 1403 de = (struct ext4_dir_entry_2 *) data1;
1394 top = data1 + len; 1404 top = data1 + len;
@@ -1408,6 +1418,8 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
1408 1418
1409 /* Initialize as for dx_probe */ 1419 /* Initialize as for dx_probe */
1410 hinfo.hash_version = root->info.hash_version; 1420 hinfo.hash_version = root->info.hash_version;
1421 if (hinfo.hash_version <= DX_HASH_TEA)
1422 hinfo.hash_version += EXT4_SB(dir->i_sb)->s_hash_unsigned;
1411 hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed; 1423 hinfo.seed = EXT4_SB(dir->i_sb)->s_hash_seed;
1412 ext4fs_dirhash(name, namelen, &hinfo); 1424 ext4fs_dirhash(name, namelen, &hinfo);
1413 frame = frames; 1425 frame = frames;
@@ -1437,7 +1449,6 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
1437 struct inode *inode) 1449 struct inode *inode)
1438{ 1450{
1439 struct inode *dir = dentry->d_parent->d_inode; 1451 struct inode *dir = dentry->d_parent->d_inode;
1440 unsigned long offset;
1441 struct buffer_head *bh; 1452 struct buffer_head *bh;
1442 struct ext4_dir_entry_2 *de; 1453 struct ext4_dir_entry_2 *de;
1443 struct super_block *sb; 1454 struct super_block *sb;
@@ -1459,7 +1470,7 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry,
1459 ext4_mark_inode_dirty(handle, dir); 1470 ext4_mark_inode_dirty(handle, dir);
1460 } 1471 }
1461 blocks = dir->i_size >> sb->s_blocksize_bits; 1472 blocks = dir->i_size >> sb->s_blocksize_bits;
1462 for (block = 0, offset = 0; block < blocks; block++) { 1473 for (block = 0; block < blocks; block++) {
1463 bh = ext4_bread(handle, dir, block, 0, &retval); 1474 bh = ext4_bread(handle, dir, block, 0, &retval);
1464 if(!bh) 1475 if(!bh)
1465 return retval; 1476 return retval;
@@ -1574,7 +1585,7 @@ static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
1574 dxtrace(dx_show_index("node", frames[1].entries)); 1585 dxtrace(dx_show_index("node", frames[1].entries));
1575 dxtrace(dx_show_index("node", 1586 dxtrace(dx_show_index("node",
1576 ((struct dx_node *) bh2->b_data)->entries)); 1587 ((struct dx_node *) bh2->b_data)->entries));
1577 err = ext4_journal_dirty_metadata(handle, bh2); 1588 err = ext4_handle_dirty_metadata(handle, inode, bh2);
1578 if (err) 1589 if (err)
1579 goto journal_error; 1590 goto journal_error;
1580 brelse (bh2); 1591 brelse (bh2);
@@ -1600,7 +1611,7 @@ static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
1600 if (err) 1611 if (err)
1601 goto journal_error; 1612 goto journal_error;
1602 } 1613 }
1603 ext4_journal_dirty_metadata(handle, frames[0].bh); 1614 ext4_handle_dirty_metadata(handle, inode, frames[0].bh);
1604 } 1615 }
1605 de = do_split(handle, dir, &bh, frame, &hinfo, &err); 1616 de = do_split(handle, dir, &bh, frame, &hinfo, &err);
1606 if (!de) 1617 if (!de)
@@ -1646,8 +1657,8 @@ static int ext4_delete_entry(handle_t *handle,
1646 else 1657 else
1647 de->inode = 0; 1658 de->inode = 0;
1648 dir->i_version++; 1659 dir->i_version++;
1649 BUFFER_TRACE(bh, "call ext4_journal_dirty_metadata"); 1660 BUFFER_TRACE(bh, "call ext4_handle_dirty_metadata");
1650 ext4_journal_dirty_metadata(handle, bh); 1661 ext4_handle_dirty_metadata(handle, dir, bh);
1651 return 0; 1662 return 0;
1652 } 1663 }
1653 i += ext4_rec_len_from_disk(de->rec_len); 1664 i += ext4_rec_len_from_disk(de->rec_len);
@@ -1693,9 +1704,11 @@ static int ext4_add_nondir(handle_t *handle,
1693 if (!err) { 1704 if (!err) {
1694 ext4_mark_inode_dirty(handle, inode); 1705 ext4_mark_inode_dirty(handle, inode);
1695 d_instantiate(dentry, inode); 1706 d_instantiate(dentry, inode);
1707 unlock_new_inode(inode);
1696 return 0; 1708 return 0;
1697 } 1709 }
1698 drop_nlink(inode); 1710 drop_nlink(inode);
1711 unlock_new_inode(inode);
1699 iput(inode); 1712 iput(inode);
1700 return err; 1713 return err;
1701} 1714}
@@ -1723,7 +1736,7 @@ retry:
1723 return PTR_ERR(handle); 1736 return PTR_ERR(handle);
1724 1737
1725 if (IS_DIRSYNC(dir)) 1738 if (IS_DIRSYNC(dir))
1726 handle->h_sync = 1; 1739 ext4_handle_sync(handle);
1727 1740
1728 inode = ext4_new_inode (handle, dir, mode); 1741 inode = ext4_new_inode (handle, dir, mode);
1729 err = PTR_ERR(inode); 1742 err = PTR_ERR(inode);
@@ -1757,7 +1770,7 @@ retry:
1757 return PTR_ERR(handle); 1770 return PTR_ERR(handle);
1758 1771
1759 if (IS_DIRSYNC(dir)) 1772 if (IS_DIRSYNC(dir))
1760 handle->h_sync = 1; 1773 ext4_handle_sync(handle);
1761 1774
1762 inode = ext4_new_inode(handle, dir, mode); 1775 inode = ext4_new_inode(handle, dir, mode);
1763 err = PTR_ERR(inode); 1776 err = PTR_ERR(inode);
@@ -1793,7 +1806,7 @@ retry:
1793 return PTR_ERR(handle); 1806 return PTR_ERR(handle);
1794 1807
1795 if (IS_DIRSYNC(dir)) 1808 if (IS_DIRSYNC(dir))
1796 handle->h_sync = 1; 1809 ext4_handle_sync(handle);
1797 1810
1798 inode = ext4_new_inode(handle, dir, S_IFDIR | mode); 1811 inode = ext4_new_inode(handle, dir, S_IFDIR | mode);
1799 err = PTR_ERR(inode); 1812 err = PTR_ERR(inode);
@@ -1822,14 +1835,15 @@ retry:
1822 strcpy(de->name, ".."); 1835 strcpy(de->name, "..");
1823 ext4_set_de_type(dir->i_sb, de, S_IFDIR); 1836 ext4_set_de_type(dir->i_sb, de, S_IFDIR);
1824 inode->i_nlink = 2; 1837 inode->i_nlink = 2;
1825 BUFFER_TRACE(dir_block, "call ext4_journal_dirty_metadata"); 1838 BUFFER_TRACE(dir_block, "call ext4_handle_dirty_metadata");
1826 ext4_journal_dirty_metadata(handle, dir_block); 1839 ext4_handle_dirty_metadata(handle, dir, dir_block);
1827 brelse(dir_block); 1840 brelse(dir_block);
1828 ext4_mark_inode_dirty(handle, inode); 1841 ext4_mark_inode_dirty(handle, inode);
1829 err = ext4_add_entry(handle, dentry, inode); 1842 err = ext4_add_entry(handle, dentry, inode);
1830 if (err) { 1843 if (err) {
1831out_clear_inode: 1844out_clear_inode:
1832 clear_nlink(inode); 1845 clear_nlink(inode);
1846 unlock_new_inode(inode);
1833 ext4_mark_inode_dirty(handle, inode); 1847 ext4_mark_inode_dirty(handle, inode);
1834 iput(inode); 1848 iput(inode);
1835 goto out_stop; 1849 goto out_stop;
@@ -1838,6 +1852,7 @@ out_clear_inode:
1838 ext4_update_dx_flag(dir); 1852 ext4_update_dx_flag(dir);
1839 ext4_mark_inode_dirty(handle, dir); 1853 ext4_mark_inode_dirty(handle, dir);
1840 d_instantiate(dentry, inode); 1854 d_instantiate(dentry, inode);
1855 unlock_new_inode(inode);
1841out_stop: 1856out_stop:
1842 ext4_journal_stop(handle); 1857 ext4_journal_stop(handle);
1843 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries)) 1858 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
@@ -1850,7 +1865,7 @@ out_stop:
1850 */ 1865 */
1851static int empty_dir(struct inode *inode) 1866static int empty_dir(struct inode *inode)
1852{ 1867{
1853 unsigned long offset; 1868 unsigned int offset;
1854 struct buffer_head *bh; 1869 struct buffer_head *bh;
1855 struct ext4_dir_entry_2 *de, *de1; 1870 struct ext4_dir_entry_2 *de, *de1;
1856 struct super_block *sb; 1871 struct super_block *sb;
@@ -1895,7 +1910,7 @@ static int empty_dir(struct inode *inode)
1895 if (err) 1910 if (err)
1896 ext4_error(sb, __func__, 1911 ext4_error(sb, __func__,
1897 "error %d reading directory" 1912 "error %d reading directory"
1898 " #%lu offset %lu", 1913 " #%lu offset %u",
1899 err, inode->i_ino, offset); 1914 err, inode->i_ino, offset);
1900 offset += sb->s_blocksize; 1915 offset += sb->s_blocksize;
1901 continue; 1916 continue;
@@ -1933,6 +1948,9 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)
1933 struct ext4_iloc iloc; 1948 struct ext4_iloc iloc;
1934 int err = 0, rc; 1949 int err = 0, rc;
1935 1950
1951 if (!ext4_handle_valid(handle))
1952 return 0;
1953
1936 lock_super(sb); 1954 lock_super(sb);
1937 if (!list_empty(&EXT4_I(inode)->i_orphan)) 1955 if (!list_empty(&EXT4_I(inode)->i_orphan))
1938 goto out_unlock; 1956 goto out_unlock;
@@ -1961,7 +1979,7 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)
1961 /* Insert this inode at the head of the on-disk orphan list... */ 1979 /* Insert this inode at the head of the on-disk orphan list... */
1962 NEXT_ORPHAN(inode) = le32_to_cpu(EXT4_SB(sb)->s_es->s_last_orphan); 1980 NEXT_ORPHAN(inode) = le32_to_cpu(EXT4_SB(sb)->s_es->s_last_orphan);
1963 EXT4_SB(sb)->s_es->s_last_orphan = cpu_to_le32(inode->i_ino); 1981 EXT4_SB(sb)->s_es->s_last_orphan = cpu_to_le32(inode->i_ino);
1964 err = ext4_journal_dirty_metadata(handle, EXT4_SB(sb)->s_sbh); 1982 err = ext4_handle_dirty_metadata(handle, inode, EXT4_SB(sb)->s_sbh);
1965 rc = ext4_mark_iloc_dirty(handle, inode, &iloc); 1983 rc = ext4_mark_iloc_dirty(handle, inode, &iloc);
1966 if (!err) 1984 if (!err)
1967 err = rc; 1985 err = rc;
@@ -1995,10 +2013,13 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode)
1995 struct list_head *prev; 2013 struct list_head *prev;
1996 struct ext4_inode_info *ei = EXT4_I(inode); 2014 struct ext4_inode_info *ei = EXT4_I(inode);
1997 struct ext4_sb_info *sbi; 2015 struct ext4_sb_info *sbi;
1998 unsigned long ino_next; 2016 __u32 ino_next;
1999 struct ext4_iloc iloc; 2017 struct ext4_iloc iloc;
2000 int err = 0; 2018 int err = 0;
2001 2019
2020 if (!ext4_handle_valid(handle))
2021 return 0;
2022
2002 lock_super(inode->i_sb); 2023 lock_super(inode->i_sb);
2003 if (list_empty(&ei->i_orphan)) { 2024 if (list_empty(&ei->i_orphan)) {
2004 unlock_super(inode->i_sb); 2025 unlock_super(inode->i_sb);
@@ -2017,7 +2038,7 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode)
2017 * transaction handle with which to update the orphan list on 2038 * transaction handle with which to update the orphan list on
2018 * disk, but we still need to remove the inode from the linked 2039 * disk, but we still need to remove the inode from the linked
2019 * list in memory. */ 2040 * list in memory. */
2020 if (!handle) 2041 if (sbi->s_journal && !handle)
2021 goto out; 2042 goto out;
2022 2043
2023 err = ext4_reserve_inode_write(handle, inode, &iloc); 2044 err = ext4_reserve_inode_write(handle, inode, &iloc);
@@ -2025,19 +2046,19 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode)
2025 goto out_err; 2046 goto out_err;
2026 2047
2027 if (prev == &sbi->s_orphan) { 2048 if (prev == &sbi->s_orphan) {
2028 jbd_debug(4, "superblock will point to %lu\n", ino_next); 2049 jbd_debug(4, "superblock will point to %u\n", ino_next);
2029 BUFFER_TRACE(sbi->s_sbh, "get_write_access"); 2050 BUFFER_TRACE(sbi->s_sbh, "get_write_access");
2030 err = ext4_journal_get_write_access(handle, sbi->s_sbh); 2051 err = ext4_journal_get_write_access(handle, sbi->s_sbh);
2031 if (err) 2052 if (err)
2032 goto out_brelse; 2053 goto out_brelse;
2033 sbi->s_es->s_last_orphan = cpu_to_le32(ino_next); 2054 sbi->s_es->s_last_orphan = cpu_to_le32(ino_next);
2034 err = ext4_journal_dirty_metadata(handle, sbi->s_sbh); 2055 err = ext4_handle_dirty_metadata(handle, inode, sbi->s_sbh);
2035 } else { 2056 } else {
2036 struct ext4_iloc iloc2; 2057 struct ext4_iloc iloc2;
2037 struct inode *i_prev = 2058 struct inode *i_prev =
2038 &list_entry(prev, struct ext4_inode_info, i_orphan)->vfs_inode; 2059 &list_entry(prev, struct ext4_inode_info, i_orphan)->vfs_inode;
2039 2060
2040 jbd_debug(4, "orphan inode %lu will point to %lu\n", 2061 jbd_debug(4, "orphan inode %lu will point to %u\n",
2041 i_prev->i_ino, ino_next); 2062 i_prev->i_ino, ino_next);
2042 err = ext4_reserve_inode_write(handle, i_prev, &iloc2); 2063 err = ext4_reserve_inode_write(handle, i_prev, &iloc2);
2043 if (err) 2064 if (err)
@@ -2082,7 +2103,7 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry)
2082 goto end_rmdir; 2103 goto end_rmdir;
2083 2104
2084 if (IS_DIRSYNC(dir)) 2105 if (IS_DIRSYNC(dir))
2085 handle->h_sync = 1; 2106 ext4_handle_sync(handle);
2086 2107
2087 inode = dentry->d_inode; 2108 inode = dentry->d_inode;
2088 2109
@@ -2136,7 +2157,7 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry)
2136 return PTR_ERR(handle); 2157 return PTR_ERR(handle);
2137 2158
2138 if (IS_DIRSYNC(dir)) 2159 if (IS_DIRSYNC(dir))
2139 handle->h_sync = 1; 2160 ext4_handle_sync(handle);
2140 2161
2141 retval = -ENOENT; 2162 retval = -ENOENT;
2142 bh = ext4_find_entry(dir, &dentry->d_name, &de); 2163 bh = ext4_find_entry(dir, &dentry->d_name, &de);
@@ -2193,7 +2214,7 @@ retry:
2193 return PTR_ERR(handle); 2214 return PTR_ERR(handle);
2194 2215
2195 if (IS_DIRSYNC(dir)) 2216 if (IS_DIRSYNC(dir))
2196 handle->h_sync = 1; 2217 ext4_handle_sync(handle);
2197 2218
2198 inode = ext4_new_inode(handle, dir, S_IFLNK|S_IRWXUGO); 2219 inode = ext4_new_inode(handle, dir, S_IFLNK|S_IRWXUGO);
2199 err = PTR_ERR(inode); 2220 err = PTR_ERR(inode);
@@ -2208,10 +2229,10 @@ retry:
2208 * We have a transaction open. All is sweetness. It also sets 2229 * We have a transaction open. All is sweetness. It also sets
2209 * i_size in generic_commit_write(). 2230 * i_size in generic_commit_write().
2210 */ 2231 */
2211 err = __page_symlink(inode, symname, l, 2232 err = __page_symlink(inode, symname, l, 1);
2212 mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS);
2213 if (err) { 2233 if (err) {
2214 clear_nlink(inode); 2234 clear_nlink(inode);
2235 unlock_new_inode(inode);
2215 ext4_mark_inode_dirty(handle, inode); 2236 ext4_mark_inode_dirty(handle, inode);
2216 iput(inode); 2237 iput(inode);
2217 goto out_stop; 2238 goto out_stop;
@@ -2256,13 +2277,20 @@ retry:
2256 return PTR_ERR(handle); 2277 return PTR_ERR(handle);
2257 2278
2258 if (IS_DIRSYNC(dir)) 2279 if (IS_DIRSYNC(dir))
2259 handle->h_sync = 1; 2280 ext4_handle_sync(handle);
2260 2281
2261 inode->i_ctime = ext4_current_time(inode); 2282 inode->i_ctime = ext4_current_time(inode);
2262 ext4_inc_count(handle, inode); 2283 ext4_inc_count(handle, inode);
2263 atomic_inc(&inode->i_count); 2284 atomic_inc(&inode->i_count);
2264 2285
2265 err = ext4_add_nondir(handle, dentry, inode); 2286 err = ext4_add_entry(handle, dentry, inode);
2287 if (!err) {
2288 ext4_mark_inode_dirty(handle, inode);
2289 d_instantiate(dentry, inode);
2290 } else {
2291 drop_nlink(inode);
2292 iput(inode);
2293 }
2266 ext4_journal_stop(handle); 2294 ext4_journal_stop(handle);
2267 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries)) 2295 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries))
2268 goto retry; 2296 goto retry;
@@ -2298,7 +2326,7 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
2298 return PTR_ERR(handle); 2326 return PTR_ERR(handle);
2299 2327
2300 if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir)) 2328 if (IS_DIRSYNC(old_dir) || IS_DIRSYNC(new_dir))
2301 handle->h_sync = 1; 2329 ext4_handle_sync(handle);
2302 2330
2303 old_bh = ext4_find_entry(old_dir, &old_dentry->d_name, &old_de); 2331 old_bh = ext4_find_entry(old_dir, &old_dentry->d_name, &old_de);
2304 /* 2332 /*
@@ -2352,8 +2380,8 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
2352 new_dir->i_ctime = new_dir->i_mtime = 2380 new_dir->i_ctime = new_dir->i_mtime =
2353 ext4_current_time(new_dir); 2381 ext4_current_time(new_dir);
2354 ext4_mark_inode_dirty(handle, new_dir); 2382 ext4_mark_inode_dirty(handle, new_dir);
2355 BUFFER_TRACE(new_bh, "call ext4_journal_dirty_metadata"); 2383 BUFFER_TRACE(new_bh, "call ext4_handle_dirty_metadata");
2356 ext4_journal_dirty_metadata(handle, new_bh); 2384 ext4_handle_dirty_metadata(handle, new_dir, new_bh);
2357 brelse(new_bh); 2385 brelse(new_bh);
2358 new_bh = NULL; 2386 new_bh = NULL;
2359 } 2387 }
@@ -2403,8 +2431,8 @@ static int ext4_rename(struct inode *old_dir, struct dentry *old_dentry,
2403 BUFFER_TRACE(dir_bh, "get_write_access"); 2431 BUFFER_TRACE(dir_bh, "get_write_access");
2404 ext4_journal_get_write_access(handle, dir_bh); 2432 ext4_journal_get_write_access(handle, dir_bh);
2405 PARENT_INO(dir_bh->b_data) = cpu_to_le32(new_dir->i_ino); 2433 PARENT_INO(dir_bh->b_data) = cpu_to_le32(new_dir->i_ino);
2406 BUFFER_TRACE(dir_bh, "call ext4_journal_dirty_metadata"); 2434 BUFFER_TRACE(dir_bh, "call ext4_handle_dirty_metadata");
2407 ext4_journal_dirty_metadata(handle, dir_bh); 2435 ext4_handle_dirty_metadata(handle, old_dir, dir_bh);
2408 ext4_dec_count(handle, old_dir); 2436 ext4_dec_count(handle, old_dir);
2409 if (new_inode) { 2437 if (new_inode) {
2410 /* checked empty_dir above, can't have another parent, 2438 /* checked empty_dir above, can't have another parent,