]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/reiserfs/file.c
Merge rsync://rsync.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[linux-2.6-omap-h63xx.git] / fs / reiserfs / file.c
index c9f178fb494f511207ca93b982e599f62d7f481d..be12879bb179ac881134a1c7ed9dc0d577d7b061 100644 (file)
@@ -49,7 +49,7 @@ static int reiserfs_file_release(struct inode *inode, struct file *filp)
        }
 
        reiserfs_write_lock(inode->i_sb);
-       down(&inode->i_sem);
+       mutex_lock(&inode->i_mutex);
        /* freeing preallocation only involves relogging blocks that
         * are already in the current transaction.  preallocation gets
         * freed at the end of each transaction, so it is impossible for
@@ -100,7 +100,7 @@ static int reiserfs_file_release(struct inode *inode, struct file *filp)
                err = reiserfs_truncate_file(inode, 0);
        }
       out:
-       up(&inode->i_sem);
+       mutex_unlock(&inode->i_mutex);
        reiserfs_write_unlock(inode->i_sb);
        return err;
 }
@@ -192,6 +192,8 @@ static int reiserfs_allocate_blocks_for_region(struct reiserfs_transaction_handl
 
        allocated_blocks = kmalloc((blocks_to_allocate + will_prealloc) *
                                   sizeof(b_blocknr_t), GFP_NOFS);
+       if (!allocated_blocks)
+               return -ENOMEM;
 
        /* First we compose a key to point at the writing position, we want to do
           that outside of any locking region. */
@@ -251,12 +253,12 @@ static int reiserfs_allocate_blocks_for_region(struct reiserfs_transaction_handl
                                                       blocks_to_allocate,
                                                       blocks_to_allocate);
                        if (res != CARRY_ON) {
-                               res = -ENOSPC;
+                               res = res == QUOTA_EXCEEDED ? -EDQUOT : -ENOSPC;
                                pathrelse(&path);
                                goto error_exit;
                        }
                } else {
-                       res = -ENOSPC;
+                       res = res == QUOTA_EXCEEDED ? -EDQUOT : -ENOSPC;
                        pathrelse(&path);
                        goto error_exit;
                }
@@ -667,7 +669,7 @@ static int reiserfs_allocate_blocks_for_region(struct reiserfs_transaction_handl
        if (th->t_trans_id) {
                int err;
                // update any changes we made to blk count
-               reiserfs_update_sd(th, inode);
+               mark_inode_dirty(inode);
                err =
                    journal_end(th, inode->i_sb,
                                JOURNAL_PER_BALANCE_CNT * 3 + 1 +
@@ -855,17 +857,18 @@ static int reiserfs_submit_file_region_for_write(struct reiserfs_transaction_han
 
                if (th->t_trans_id) {
                        reiserfs_write_lock(inode->i_sb);
-                       reiserfs_update_sd(th, inode);  // And update on-disk metadata
+                       // this sets the proper flags for O_SYNC to trigger a commit
+                       mark_inode_dirty(inode);
                        reiserfs_write_unlock(inode->i_sb);
                } else
-                       inode->i_sb->s_op->dirty_inode(inode);
+                       mark_inode_dirty(inode);
 
                sd_update = 1;
        }
        if (th->t_trans_id) {
                reiserfs_write_lock(inode->i_sb);
                if (!sd_update)
-                       reiserfs_update_sd(th, inode);
+                       mark_inode_dirty(inode);
                status = journal_end(th, th->t_super, th->t_blocks_allocated);
                if (status)
                        retval = status;
@@ -1284,6 +1287,23 @@ static ssize_t reiserfs_file_write(struct file *file,    /* the file we are going t
        struct reiserfs_transaction_handle th;
        th.t_trans_id = 0;
 
+       /* If a filesystem is converted from 3.5 to 3.6, we'll have v3.5 items
+       * lying around (most of the disk, in fact). Despite the filesystem
+       * now being a v3.6 format, the old items still can't support large
+       * file sizes. Catch this case here, as the rest of the VFS layer is
+       * oblivious to the different limitations between old and new items.
+       * reiserfs_setattr catches this for truncates. This chunk is lifted
+       * from generic_write_checks. */
+       if (get_inode_item_key_version (inode) == KEY_FORMAT_3_5 &&
+           *ppos + count > MAX_NON_LFS) {
+               if (*ppos >= MAX_NON_LFS) {
+                       send_sig(SIGXFSZ, current, 0);
+                       return -EFBIG;
+               }
+               if (count > MAX_NON_LFS - (unsigned long)*ppos)
+                       count = MAX_NON_LFS - (unsigned long)*ppos;
+       }
+
        if (file->f_flags & O_DIRECT) { // Direct IO needs treatment
                ssize_t result, after_file_end = 0;
                if ((*ppos + count >= inode->i_size)
@@ -1320,7 +1340,7 @@ static ssize_t reiserfs_file_write(struct file *file,     /* the file we are going t
                                return err;
                        }
                        reiserfs_update_inode_transaction(inode);
-                       reiserfs_update_sd(&th, inode);
+                       mark_inode_dirty(inode);
                        err = journal_end(&th, inode->i_sb, 1);
                        if (err) {
                                reiserfs_write_unlock(inode->i_sb);
@@ -1341,7 +1361,7 @@ static ssize_t reiserfs_file_write(struct file *file,     /* the file we are going t
        if (unlikely(!access_ok(VERIFY_READ, buf, count)))
                return -EFAULT;
 
-       down(&inode->i_sem);    // locks the entire file for just us
+       mutex_lock(&inode->i_mutex);    // locks the entire file for just us
 
        pos = *ppos;
 
@@ -1359,7 +1379,7 @@ static ssize_t reiserfs_file_write(struct file *file,     /* the file we are going t
        if (res)
                goto out;
 
-       inode_update_time(inode, 1);    /* Both mtime and ctime */
+       file_update_time(file);
 
        // Ok, we are done with all the checks.
 
@@ -1444,13 +1464,11 @@ static ssize_t reiserfs_file_write(struct file *file,   /* the file we are going t
                   partially overwritten pages, if needed. And lock the pages,
                   so that nobody else can access these until we are done.
                   We get number of actual blocks needed as a result. */
-               blocks_to_allocate =
-                   reiserfs_prepare_file_region_for_write(inode, pos,
-                                                          num_pages,
-                                                          write_bytes,
-                                                          prepared_pages);
-               if (blocks_to_allocate < 0) {
-                       res = blocks_to_allocate;
+               res = reiserfs_prepare_file_region_for_write(inode, pos,
+                                                            num_pages,
+                                                            write_bytes,
+                                                            prepared_pages);
+               if (res < 0) {
                        reiserfs_release_claimed_blocks(inode->i_sb,
                                                        num_pages <<
                                                        (PAGE_CACHE_SHIFT -
@@ -1458,6 +1476,8 @@ static ssize_t reiserfs_file_write(struct file *file,     /* the file we are going t
                        break;
                }
 
+               blocks_to_allocate = res;
+
                /* First we correct our estimate of how many blocks we need */
                reiserfs_release_claimed_blocks(inode->i_sb,
                                                (num_pages <<
@@ -1531,12 +1551,12 @@ static ssize_t reiserfs_file_write(struct file *file,   /* the file we are going t
                    generic_osync_inode(inode, file->f_mapping,
                                        OSYNC_METADATA | OSYNC_DATA);
 
-       up(&inode->i_sem);
+       mutex_unlock(&inode->i_mutex);
        reiserfs_async_progress_wait(inode->i_sb);
        return (already_written != 0) ? already_written : res;
 
       out:
-       up(&inode->i_sem);      // unlock the file on exit.
+       mutex_unlock(&inode->i_mutex);  // unlock the file on exit.
        return res;
 }