Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6
[safe/jmp/linux-2.6] / fs / reiserfs / inode.c
index 8810fda..55fce92 100644 (file)
@@ -7,6 +7,7 @@
 #include <linux/reiserfs_fs.h>
 #include <linux/reiserfs_acl.h>
 #include <linux/reiserfs_xattr.h>
+#include <linux/exportfs.h>
 #include <linux/smp_lock.h>
 #include <linux/pagemap.h>
 #include <linux/highmem.h>
 #include <linux/mpage.h>
 #include <linux/writeback.h>
 #include <linux/quotaops.h>
+#include <linux/swap.h>
 
-static int reiserfs_commit_write(struct file *f, struct page *page,
-                                unsigned from, unsigned to);
-static int reiserfs_prepare_write(struct file *f, struct page *page,
-                                 unsigned from, unsigned to);
+int reiserfs_commit_write(struct file *f, struct page *page,
+                         unsigned from, unsigned to);
+int reiserfs_prepare_write(struct file *f, struct page *page,
+                          unsigned from, unsigned to);
 
 void reiserfs_delete_inode(struct inode *inode)
 {
@@ -43,6 +45,8 @@ void reiserfs_delete_inode(struct inode *inode)
                        goto out;
                reiserfs_update_inode_transaction(inode);
 
+               reiserfs_discard_prealloc(&th, inode);
+
                err = reiserfs_delete_object(&th, inode);
 
                /* Do quota update inside a transaction for journaled quotas. We must do that
@@ -197,7 +201,7 @@ static inline void set_block_dev_mapped(struct buffer_head *bh,
 // files which were created in the earlier version can not be longer,
 // than 2 gb
 //
-static int file_capable(struct inode *inode, long block)
+static int file_capable(struct inode *inode, sector_t block)
 {
        if (get_inode_item_key_version(inode) != KEY_FORMAT_3_5 ||      // it is new file.
            block < (1 << (31 - inode->i_sb->s_blocksize_bits)))        // old file, but 'block' is inside of 2gb
@@ -206,8 +210,8 @@ static int file_capable(struct inode *inode, long block)
        return 0;
 }
 
-/*static*/ int restart_transaction(struct reiserfs_transaction_handle *th,
-                                  struct inode *inode, struct path *path)
+static int restart_transaction(struct reiserfs_transaction_handle *th,
+                              struct inode *inode, struct treepath *path)
 {
        struct super_block *s = th->t_super;
        int len = th->t_blocks_allocated;
@@ -216,11 +220,12 @@ static int file_capable(struct inode *inode, long block)
        BUG_ON(!th->t_trans_id);
        BUG_ON(!th->t_refcount);
 
+       pathrelse(path);
+
        /* we cannot restart while nested */
        if (th->t_refcount > 1) {
                return 0;
        }
-       pathrelse(path);
        reiserfs_update_sd(th, inode);
        err = journal_end(th, s, len);
        if (!err) {
@@ -239,7 +244,7 @@ static int file_capable(struct inode *inode, long block)
 // Please improve the english/clarity in the comment above, as it is
 // hard to understand.
 
-static int _get_block_create_0(struct inode *inode, long block,
+static int _get_block_create_0(struct inode *inode, sector_t block,
                               struct buffer_head *bh_result, int args)
 {
        INITIALIZE_PATH(path);
@@ -247,7 +252,7 @@ static int _get_block_create_0(struct inode *inode, long block,
        struct buffer_head *bh;
        struct item_head *ih, tmp_ih;
        int fs_gen;
-       int blocknr;
+       b_blocknr_t blocknr;
        char *p = NULL;
        int chars;
        int ret;
@@ -566,10 +571,10 @@ static int convert_tail_for_hole(struct inode *inode,
 }
 
 static inline int _allocate_block(struct reiserfs_transaction_handle *th,
-                                 long block,
+                                 sector_t block,
                                  struct inode *inode,
                                  b_blocknr_t * allocated_block_nr,
-                                 struct path *path, int flags)
+                                 struct treepath *path, int flags)
 {
        BUG_ON(!th->t_trans_id);
 
@@ -928,15 +933,12 @@ int reiserfs_get_block(struct inode *inode, sector_t block,
                        if (blocks_needed == 1) {
                                un = &unf_single;
                        } else {
-                               un = kmalloc(min(blocks_needed, max_to_insert) * UNFM_P_SIZE, GFP_ATOMIC);      // We need to avoid scheduling.
+                               un = kzalloc(min(blocks_needed, max_to_insert) * UNFM_P_SIZE, GFP_ATOMIC);      // We need to avoid scheduling.
                                if (!un) {
                                        un = &unf_single;
                                        blocks_needed = 1;
                                        max_to_insert = 0;
-                               } else
-                                       memset(un, 0,
-                                              UNFM_P_SIZE * min(blocks_needed,
-                                                                max_to_insert));
+                               }
                        }
                        if (blocks_needed <= max_to_insert) {
                                /* we are going to add target block to the file. Use allocated
@@ -1109,7 +1111,7 @@ static inline ulong to_fake_used_blocks(struct inode *inode, int sd_size)
 //
 
 // called by read_locked_inode
-static void init_inode(struct inode *inode, struct path *path)
+static void init_inode(struct inode *inode, struct treepath *path)
 {
        struct buffer_head *bh;
        struct item_head *ih;
@@ -1127,9 +1129,10 @@ static void init_inode(struct inode *inode, struct path *path)
        REISERFS_I(inode)->i_prealloc_count = 0;
        REISERFS_I(inode)->i_trans_id = 0;
        REISERFS_I(inode)->i_jl = NULL;
-       REISERFS_I(inode)->i_acl_access = NULL;
-       REISERFS_I(inode)->i_acl_default = NULL;
-       init_rwsem(&REISERFS_I(inode)->xattr_sem);
+       mutex_init(&(REISERFS_I(inode)->i_mmap));
+       reiserfs_init_acl_access(inode);
+       reiserfs_init_acl_default(inode);
+       reiserfs_init_xattr_rwsem(inode);
 
        if (stat_data_v1(ih)) {
                struct stat_data_v1 *sd =
@@ -1286,7 +1289,7 @@ static void inode2sd_v1(void *sd, struct inode *inode, loff_t size)
 /* NOTE, you must prepare the buffer head before sending it here,
 ** and then log it after the call
 */
-static void update_stat_data(struct path *path, struct inode *inode,
+static void update_stat_data(struct treepath *path, struct inode *inode,
                             loff_t size)
 {
        struct buffer_head *bh;
@@ -1514,43 +1517,30 @@ struct inode *reiserfs_iget(struct super_block *s, const struct cpu_key *key)
        return inode;
 }
 
-struct dentry *reiserfs_get_dentry(struct super_block *sb, void *vobjp)
+static struct dentry *reiserfs_get_dentry(struct super_block *sb,
+       u32 objectid, u32 dir_id, u32 generation)
+
 {
-       __u32 *data = vobjp;
        struct cpu_key key;
-       struct dentry *result;
        struct inode *inode;
 
-       key.on_disk_key.k_objectid = data[0];
-       key.on_disk_key.k_dir_id = data[1];
+       key.on_disk_key.k_objectid = objectid;
+       key.on_disk_key.k_dir_id = dir_id;
        reiserfs_write_lock(sb);
        inode = reiserfs_iget(sb, &key);
-       if (inode && !IS_ERR(inode) && data[2] != 0 &&
-           data[2] != inode->i_generation) {
+       if (inode && !IS_ERR(inode) && generation != 0 &&
+           generation != inode->i_generation) {
                iput(inode);
                inode = NULL;
        }
        reiserfs_write_unlock(sb);
-       if (!inode)
-               inode = ERR_PTR(-ESTALE);
-       if (IS_ERR(inode))
-               return ERR_PTR(PTR_ERR(inode));
-       result = d_alloc_anon(inode);
-       if (!result) {
-               iput(inode);
-               return ERR_PTR(-ENOMEM);
-       }
-       return result;
+
+       return d_obtain_alias(inode);
 }
 
-struct dentry *reiserfs_decode_fh(struct super_block *sb, __u32 * data,
-                                 int len, int fhtype,
-                                 int (*acceptable) (void *contect,
-                                                    struct dentry * de),
-                                 void *context)
+struct dentry *reiserfs_fh_to_dentry(struct super_block *sb, struct fid *fid,
+               int fh_len, int fh_type)
 {
-       __u32 obj[3], parent[3];
-
        /* fhtype happens to reflect the number of u32s encoded.
         * due to a bug in earlier code, fhtype might indicate there
         * are more u32s then actually fitted.
@@ -1563,32 +1553,28 @@ struct dentry *reiserfs_decode_fh(struct super_block *sb, __u32 * data,
         *   6 - as above plus generation of directory
         * 6 does not fit in NFSv2 handles
         */
-       if (fhtype > len) {
-               if (fhtype != 6 || len != 5)
+       if (fh_type > fh_len) {
+               if (fh_type != 6 || fh_len != 5)
                        reiserfs_warning(sb,
-                                        "nfsd/reiserfs, fhtype=%d, len=%d - odd",
-                                        fhtype, len);
-               fhtype = 5;
+                               "nfsd/reiserfs, fhtype=%d, len=%d - odd",
+                               fh_type, fh_len);
+               fh_type = 5;
        }
 
-       obj[0] = data[0];
-       obj[1] = data[1];
-       if (fhtype == 3 || fhtype >= 5)
-               obj[2] = data[2];
-       else
-               obj[2] = 0;     /* generation number */
+       return reiserfs_get_dentry(sb, fid->raw[0], fid->raw[1],
+               (fh_type == 3 || fh_type >= 5) ? fid->raw[2] : 0);
+}
 
-       if (fhtype >= 4) {
-               parent[0] = data[fhtype >= 5 ? 3 : 2];
-               parent[1] = data[fhtype >= 5 ? 4 : 3];
-               if (fhtype == 6)
-                       parent[2] = data[5];
-               else
-                       parent[2] = 0;
-       }
-       return sb->s_export_op->find_exported_dentry(sb, obj,
-                                                    fhtype < 4 ? NULL : parent,
-                                                    acceptable, context);
+struct dentry *reiserfs_fh_to_parent(struct super_block *sb, struct fid *fid,
+               int fh_len, int fh_type)
+{
+       if (fh_type < 4)
+               return NULL;
+
+       return reiserfs_get_dentry(sb,
+               (fh_type >= 5) ? fid->raw[3] : fid->raw[2],
+               (fh_type >= 5) ? fid->raw[4] : fid->raw[3],
+               (fh_type == 6) ? fid->raw[5] : 0);
 }
 
 int reiserfs_encode_fh(struct dentry *dentry, __u32 * data, int *lenp,
@@ -1655,7 +1641,7 @@ int reiserfs_write_inode(struct inode *inode, int do_sync)
    containing "." and ".." entries */
 static int reiserfs_new_directory(struct reiserfs_transaction_handle *th,
                                  struct inode *inode,
-                                 struct item_head *ih, struct path *path,
+                                 struct item_head *ih, struct treepath *path,
                                  struct inode *dir)
 {
        struct super_block *sb = th->t_super;
@@ -1714,7 +1700,7 @@ static int reiserfs_new_directory(struct reiserfs_transaction_handle *th,
    containing the body of symlink */
 static int reiserfs_new_symlink(struct reiserfs_transaction_handle *th, struct inode *inode,   /* Inode of symlink */
                                struct item_head *ih,
-                               struct path *path, const char *symname,
+                               struct treepath *path, const char *symname,
                                int item_len)
 {
        struct super_block *sb = th->t_super;
@@ -1767,6 +1753,7 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
                       struct inode *inode)
 {
        struct super_block *sb;
+       struct reiserfs_iget_args args;
        INITIALIZE_PATH(path_to_key);
        struct cpu_key key;
        struct item_head ih;
@@ -1780,7 +1767,7 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
                err = -EDQUOT;
                goto out_end_trans;
        }
-       if (!dir || !dir->i_nlink) {
+       if (!dir->i_nlink) {
                err = -EPERM;
                goto out_bad_inode;
        }
@@ -1794,6 +1781,20 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
                err = -ENOMEM;
                goto out_bad_inode;
        }
+       args.objectid = inode->i_ino = le32_to_cpu(ih.ih_key.k_objectid);
+       if (old_format_only(sb))
+               make_le_item_head(&ih, NULL, KEY_FORMAT_3_5, SD_OFFSET,
+                                 TYPE_STAT_DATA, SD_V1_SIZE, MAX_US_INT);
+       else
+               make_le_item_head(&ih, NULL, KEY_FORMAT_3_6, SD_OFFSET,
+                                 TYPE_STAT_DATA, SD_SIZE, MAX_US_INT);
+       memcpy(INODE_PKEY(inode), &(ih.ih_key), KEY_SIZE);
+       args.dirid = le32_to_cpu(ih.ih_key.k_dir_id);
+       if (insert_inode_locked4(inode, args.objectid,
+                            reiserfs_find_actor, &args) < 0) {
+               err = -EINVAL;
+               goto out_bad_inode;
+       }
        if (old_format_only(sb))
                /* not a perfect generation count, as object ids can be reused, but 
                 ** this is as good as reiserfs can do right now.
@@ -1834,16 +1835,10 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
        REISERFS_I(inode)->i_attrs =
            REISERFS_I(dir)->i_attrs & REISERFS_INHERIT_MASK;
        sd_attrs_to_i_attrs(REISERFS_I(inode)->i_attrs, inode);
-       REISERFS_I(inode)->i_acl_access = NULL;
-       REISERFS_I(inode)->i_acl_default = NULL;
-       init_rwsem(&REISERFS_I(inode)->xattr_sem);
-
-       if (old_format_only(sb))
-               make_le_item_head(&ih, NULL, KEY_FORMAT_3_5, SD_OFFSET,
-                                 TYPE_STAT_DATA, SD_V1_SIZE, MAX_US_INT);
-       else
-               make_le_item_head(&ih, NULL, KEY_FORMAT_3_6, SD_OFFSET,
-                                 TYPE_STAT_DATA, SD_SIZE, MAX_US_INT);
+       mutex_init(&(REISERFS_I(inode)->i_mmap));
+       reiserfs_init_acl_access(inode);
+       reiserfs_init_acl_default(inode);
+       reiserfs_init_xattr_rwsem(inode);
 
        /* key to search for correct place for new stat data */
        _make_cpu_key(&key, KEY_FORMAT_3_6, le32_to_cpu(ih.ih_key.k_dir_id),
@@ -1872,13 +1867,9 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
        } else {
                inode2sd(&sd, inode, inode->i_size);
        }
-       // these do not go to on-disk stat data
-       inode->i_ino = le32_to_cpu(ih.ih_key.k_objectid);
-
        // store in in-core inode the key of stat data and version all
        // object items will have (directory items will have old offset
        // format, other new objects will consist of new items)
-       memcpy(INODE_PKEY(inode), &(ih.ih_key), KEY_SIZE);
        if (old_format_only(sb) || S_ISDIR(mode) || S_ISLNK(mode))
                set_inode_item_key_version(inode, KEY_FORMAT_3_5);
        else
@@ -1942,7 +1933,6 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
                reiserfs_mark_inode_private(inode);
        }
 
-       insert_inode_hash(inode);
        reiserfs_update_sd(th, inode);
        reiserfs_check_path(&path_to_key);
 
@@ -1969,16 +1959,19 @@ int reiserfs_new_inode(struct reiserfs_transaction_handle *th,
       out_inserted_sd:
        inode->i_nlink = 0;
        th->t_trans_id = 0;     /* so the caller can't use this handle later */
+       unlock_new_inode(inode); /* OK to do even if we hadn't locked it */
 
        /* If we were inheriting an ACL, we need to release the lock so that
         * iput doesn't deadlock in reiserfs_delete_xattrs. The locking
         * code really needs to be reworked, but this will take care of it
         * for now. -jeffm */
+#ifdef CONFIG_REISERFS_FS_POSIX_ACL
        if (REISERFS_I(dir)->i_acl_default && !IS_ERR(REISERFS_I(dir)->i_acl_default)) {
                reiserfs_write_unlock_xattrs(dir->i_sb);
                iput(inode);
                reiserfs_write_lock_xattrs(dir->i_sb);
        } else
+#endif
                iput(inode);
        return err;
 }
@@ -2146,13 +2139,8 @@ int reiserfs_truncate_file(struct inode *p_s_inode, int update_timestamps)
                length = offset & (blocksize - 1);
                /* if we are not on a block boundary */
                if (length) {
-                       char *kaddr;
-
                        length = blocksize - length;
-                       kaddr = kmap_atomic(page, KM_USER0);
-                       memset(kaddr + offset, 0, length);
-                       flush_dcache_page(page);
-                       kunmap_atomic(kaddr, KM_USER0);
+                       zero_user(page, offset, length);
                        if (buffer_mapped(bh) && bh->b_blocknr != 0) {
                                mark_buffer_dirty(bh);
                        }
@@ -2368,7 +2356,6 @@ static int reiserfs_write_full_page(struct page *page,
         ** last byte in the file
         */
        if (page->index >= end_index) {
-               char *kaddr;
                unsigned last_offset;
 
                last_offset = inode->i_size & (PAGE_CACHE_SIZE - 1);
@@ -2377,10 +2364,7 @@ static int reiserfs_write_full_page(struct page *page,
                        unlock_page(page);
                        return 0;
                }
-               kaddr = kmap_atomic(page, KM_USER0);
-               memset(kaddr + last_offset, 0, PAGE_CACHE_SIZE - last_offset);
-               flush_dcache_page(page);
-               kunmap_atomic(kaddr, KM_USER0);
+               zero_user_segment(page, last_offset, PAGE_CACHE_SIZE);
        }
        bh = head;
        block = page->index << (PAGE_CACHE_SHIFT - s->s_blocksize_bits);
@@ -2446,7 +2430,7 @@ static int reiserfs_write_full_page(struct page *page,
                if (wbc->sync_mode != WB_SYNC_NONE || !wbc->nonblocking) {
                        lock_buffer(bh);
                } else {
-                       if (test_set_buffer_locked(bh)) {
+                       if (!trylock_buffer(bh)) {
                                redirty_page_for_writepage(wbc, page);
                                continue;
                        }
@@ -2556,8 +2540,78 @@ static int reiserfs_writepage(struct page *page, struct writeback_control *wbc)
        return reiserfs_write_full_page(page, wbc);
 }
 
-static int reiserfs_prepare_write(struct file *f, struct page *page,
-                                 unsigned from, unsigned to)
+static int reiserfs_write_begin(struct file *file,
+                               struct address_space *mapping,
+                               loff_t pos, unsigned len, unsigned flags,
+                               struct page **pagep, void **fsdata)
+{
+       struct inode *inode;
+       struct page *page;
+       pgoff_t index;
+       int ret;
+       int old_ref = 0;
+
+       inode = mapping->host;
+       *fsdata = 0;
+       if (flags & AOP_FLAG_CONT_EXPAND &&
+           (pos & (inode->i_sb->s_blocksize - 1)) == 0) {
+               pos ++;
+               *fsdata = (void *)(unsigned long)flags;
+       }
+
+       index = pos >> PAGE_CACHE_SHIFT;
+       page = grab_cache_page_write_begin(mapping, index, flags);
+       if (!page)
+               return -ENOMEM;
+       *pagep = page;
+
+       reiserfs_wait_on_write_block(inode->i_sb);
+       fix_tail_page_for_writing(page);
+       if (reiserfs_transaction_running(inode->i_sb)) {
+               struct reiserfs_transaction_handle *th;
+               th = (struct reiserfs_transaction_handle *)current->
+                   journal_info;
+               BUG_ON(!th->t_refcount);
+               BUG_ON(!th->t_trans_id);
+               old_ref = th->t_refcount;
+               th->t_refcount++;
+       }
+       ret = block_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
+                               reiserfs_get_block);
+       if (ret && reiserfs_transaction_running(inode->i_sb)) {
+               struct reiserfs_transaction_handle *th = current->journal_info;
+               /* this gets a little ugly.  If reiserfs_get_block returned an
+                * error and left a transacstion running, we've got to close it,
+                * and we've got to free handle if it was a persistent transaction.
+                *
+                * But, if we had nested into an existing transaction, we need
+                * to just drop the ref count on the handle.
+                *
+                * If old_ref == 0, the transaction is from reiserfs_get_block,
+                * and it was a persistent trans.  Otherwise, it was nested above.
+                */
+               if (th->t_refcount > old_ref) {
+                       if (old_ref)
+                               th->t_refcount--;
+                       else {
+                               int err;
+                               reiserfs_write_lock(inode->i_sb);
+                               err = reiserfs_end_persistent_transaction(th);
+                               reiserfs_write_unlock(inode->i_sb);
+                               if (err)
+                                       ret = err;
+                       }
+               }
+       }
+       if (ret) {
+               unlock_page(page);
+               page_cache_release(page);
+       }
+       return ret;
+}
+
+int reiserfs_prepare_write(struct file *f, struct page *page,
+                          unsigned from, unsigned to)
 {
        struct inode *inode = page->mapping->host;
        int ret;
@@ -2610,8 +2664,102 @@ static sector_t reiserfs_aop_bmap(struct address_space *as, sector_t block)
        return generic_block_bmap(as, block, reiserfs_bmap);
 }
 
-static int reiserfs_commit_write(struct file *f, struct page *page,
-                                unsigned from, unsigned to)
+static int reiserfs_write_end(struct file *file, struct address_space *mapping,
+                             loff_t pos, unsigned len, unsigned copied,
+                             struct page *page, void *fsdata)
+{
+       struct inode *inode = page->mapping->host;
+       int ret = 0;
+       int update_sd = 0;
+       struct reiserfs_transaction_handle *th;
+       unsigned start;
+
+       if ((unsigned long)fsdata & AOP_FLAG_CONT_EXPAND)
+               pos ++;
+
+       reiserfs_wait_on_write_block(inode->i_sb);
+       if (reiserfs_transaction_running(inode->i_sb))
+               th = current->journal_info;
+       else
+               th = NULL;
+
+       start = pos & (PAGE_CACHE_SIZE - 1);
+       if (unlikely(copied < len)) {
+               if (!PageUptodate(page))
+                       copied = 0;
+
+               page_zero_new_buffers(page, start + copied, start + len);
+       }
+       flush_dcache_page(page);
+
+       reiserfs_commit_page(inode, page, start, start + copied);
+
+       /* generic_commit_write does this for us, but does not update the
+        ** transaction tracking stuff when the size changes.  So, we have
+        ** to do the i_size updates here.
+        */
+       pos += copied;
+       if (pos > inode->i_size) {
+               struct reiserfs_transaction_handle myth;
+               reiserfs_write_lock(inode->i_sb);
+               /* If the file have grown beyond the border where it
+                  can have a tail, unmark it as needing a tail
+                  packing */
+               if ((have_large_tails(inode->i_sb)
+                    && inode->i_size > i_block_size(inode) * 4)
+                   || (have_small_tails(inode->i_sb)
+                       && inode->i_size > i_block_size(inode)))
+                       REISERFS_I(inode)->i_flags &= ~i_pack_on_close_mask;
+
+               ret = journal_begin(&myth, inode->i_sb, 1);
+               if (ret) {
+                       reiserfs_write_unlock(inode->i_sb);
+                       goto journal_error;
+               }
+               reiserfs_update_inode_transaction(inode);
+               inode->i_size = pos;
+               /*
+                * this will just nest into our transaction.  It's important
+                * to use mark_inode_dirty so the inode gets pushed around on the
+                * dirty lists, and so that O_SYNC works as expected
+                */
+               mark_inode_dirty(inode);
+               reiserfs_update_sd(&myth, inode);
+               update_sd = 1;
+               ret = journal_end(&myth, inode->i_sb, 1);
+               reiserfs_write_unlock(inode->i_sb);
+               if (ret)
+                       goto journal_error;
+       }
+       if (th) {
+               reiserfs_write_lock(inode->i_sb);
+               if (!update_sd)
+                       mark_inode_dirty(inode);
+               ret = reiserfs_end_persistent_transaction(th);
+               reiserfs_write_unlock(inode->i_sb);
+               if (ret)
+                       goto out;
+       }
+
+      out:
+       unlock_page(page);
+       page_cache_release(page);
+       return ret == 0 ? copied : ret;
+
+      journal_error:
+       if (th) {
+               reiserfs_write_lock(inode->i_sb);
+               if (!update_sd)
+                       reiserfs_update_sd(th, inode);
+               ret = reiserfs_end_persistent_transaction(th);
+               reiserfs_write_unlock(inode->i_sb);
+       }
+
+       goto out;
+}
+
+int reiserfs_commit_write(struct file *f, struct page *page,
+                         unsigned from, unsigned to)
 {
        struct inode *inode = page->mapping->host;
        loff_t pos = ((loff_t) page->index << PAGE_CACHE_SHIFT) + to;
@@ -2902,7 +3050,11 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
 {
        struct inode *inode = dentry->d_inode;
        int error;
-       unsigned int ia_valid = attr->ia_valid;
+       unsigned int ia_valid;
+
+       /* must be turned off for recursive notify_change calls */
+       ia_valid = attr->ia_valid &= ~(ATTR_KILL_SUID|ATTR_KILL_SGID);
+
        reiserfs_write_lock(inode->i_sb);
        if (attr->ia_valid & ATTR_SIZE) {
                /* version 2 items will be caught by the s_maxbytes check
@@ -2915,7 +3067,7 @@ int reiserfs_setattr(struct dentry *dentry, struct iattr *attr)
                }
                /* fill in hole pointers in the expanding truncate case. */
                if (attr->ia_size > inode->i_size) {
-                       error = generic_cont_expand(inode, attr->ia_size);
+                       error = generic_cont_expand_simple(inode, attr->ia_size);
                        if (REISERFS_I(inode)->i_prealloc_count > 0) {
                                int err;
                                struct reiserfs_transaction_handle th;
@@ -3005,8 +3157,8 @@ const struct address_space_operations reiserfs_address_space_operations = {
        .releasepage = reiserfs_releasepage,
        .invalidatepage = reiserfs_invalidatepage,
        .sync_page = block_sync_page,
-       .prepare_write = reiserfs_prepare_write,
-       .commit_write = reiserfs_commit_write,
+       .write_begin = reiserfs_write_begin,
+       .write_end = reiserfs_write_end,
        .bmap = reiserfs_aop_bmap,
        .direct_IO = reiserfs_direct_IO,
        .set_page_dirty = reiserfs_set_page_dirty,