[PATCH] remove file.f_maxcount
[safe/jmp/linux-2.6] / fs / ntfs / aops.c
index 2b4b8b9..78adad7 100644 (file)
@@ -264,7 +264,8 @@ lock_retry_remap:
                                        goto lock_retry_remap;
                                rl = NULL;
                                lcn = err;
-                       }
+                       } else if (!rl)
+                               up_read(&ni->runlist.lock);
                        /* Hard error, zero out region. */
                        bh->b_blocknr = -1;
                        SetPageError(page);
@@ -355,6 +356,7 @@ static int ntfs_readpage(struct file *file, struct page *page)
        u32 attr_len;
        int err = 0;
 
+retry_readpage:
        BUG_ON(!PageLocked(page));
        /*
         * This can potentially happen because we clear PageUptodate() during
@@ -408,6 +410,14 @@ static int ntfs_readpage(struct file *file, struct page *page)
                err = PTR_ERR(mrec);
                goto err_out;
        }
+       /*
+        * If a parallel write made the attribute non-resident, drop the mft
+        * record and retry the readpage.
+        */
+       if (unlikely(NInoNonResident(ni))) {
+               unmap_mft_record(base_ni);
+               goto retry_readpage;
+       }
        ctx = ntfs_attr_get_search_ctx(base_ni, mrec);
        if (unlikely(!ctx)) {
                err = -ENOMEM;
@@ -681,7 +691,8 @@ lock_retry_remap:
                                goto lock_retry_remap;
                        rl = NULL;
                        lcn = err;
-               }
+               } else if (!rl)
+                       up_read(&ni->runlist.lock);
                /* Failed to map the buffer, even after retrying. */
                bh->b_blocknr = -1;
                ntfs_error(vol->sb, "Failed to write to inode 0x%lx, "
@@ -816,17 +827,15 @@ static int ntfs_write_mst_block(struct page *page,
        ntfs_inode *ni = NTFS_I(vi);
        ntfs_volume *vol = ni->vol;
        u8 *kaddr;
-       unsigned char bh_size_bits = vi->i_blkbits;
-       unsigned int bh_size = 1 << bh_size_bits;
        unsigned int rec_size = ni->itype.index.block_size;
        ntfs_inode *locked_nis[PAGE_CACHE_SIZE / rec_size];
        struct buffer_head *bh, *head, *tbh, *rec_start_bh;
-       int max_bhs = PAGE_CACHE_SIZE / bh_size;
-       struct buffer_head *bhs[max_bhs];
+       struct buffer_head *bhs[MAX_BUF_PER_PAGE];
        runlist_element *rl;
-       int i, nr_locked_nis, nr_recs, nr_bhs, bhs_per_rec, err, err2;
-       unsigned rec_size_bits;
+       int i, nr_locked_nis, nr_recs, nr_bhs, max_bhs, bhs_per_rec, err, err2;
+       unsigned bh_size, rec_size_bits;
        BOOL sync, is_mft, page_is_dirty, rec_is_dirty;
+       unsigned char bh_size_bits;
 
        ntfs_debug("Entering for inode 0x%lx, attribute type 0x%x, page index "
                        "0x%lx.", vi->i_ino, ni->type, page->index);
@@ -841,7 +850,11 @@ static int ntfs_write_mst_block(struct page *page,
         */
        BUG_ON(!(is_mft || S_ISDIR(vi->i_mode) ||
                        (NInoAttr(ni) && ni->type == AT_INDEX_ALLOCATION)));
+       bh_size_bits = vi->i_blkbits;
+       bh_size = 1 << bh_size_bits;
+       max_bhs = PAGE_CACHE_SIZE / bh_size;
        BUG_ON(!max_bhs);
+       BUG_ON(max_bhs > MAX_BUF_PER_PAGE);
 
        /* Were we called for sync purposes? */
        sync = (wbc->sync_mode == WB_SYNC_ALL);
@@ -911,6 +924,7 @@ static int ntfs_write_mst_block(struct page *page,
                        LCN lcn;
                        unsigned int vcn_ofs;
 
+                       bh->b_bdev = vol->sb->s_bdev;
                        /* Obtain the vcn and offset of the current block. */
                        vcn = (VCN)block << bh_size_bits;
                        vcn_ofs = vcn & vol->cluster_size_mask;
@@ -954,8 +968,11 @@ lock_retry_remap:
                                        if (err2 == -ENOMEM)
                                                page_is_dirty = TRUE;
                                        lcn = err2;
-                               } else
+                               } else {
                                        err2 = -EIO;
+                                       if (!rl)
+                                               up_read(&ni->runlist.lock);
+                               }
                                /* Hard error.  Abort writing this record. */
                                if (!err || err == -ENOMEM)
                                        err = err2;
@@ -965,7 +982,8 @@ lock_retry_remap:
                                                "attribute type 0x%x) because "
                                                "its location on disk could "
                                                "not be determined (error "
-                                               "code %lli).", (s64)block <<
+                                               "code %lli).",
+                                               (long long)block <<
                                                bh_size_bits >>
                                                vol->mft_record_size_bits,
                                                ni->mft_no, ni->type,
@@ -1247,6 +1265,7 @@ static int ntfs_writepage(struct page *page, struct writeback_control *wbc)
        u32 attr_len;
        int err;
 
+retry_writepage:
        BUG_ON(!PageLocked(page));
        i_size = i_size_read(vi);
        /* Is the page fully outside i_size? (truncate in progress) */
@@ -1337,6 +1356,14 @@ static int ntfs_writepage(struct page *page, struct writeback_control *wbc)
                ctx = NULL;
                goto err_out;
        }
+       /*
+        * If a parallel write made the attribute non-resident, drop the mft
+        * record and retry the writepage.
+        */
+       if (unlikely(NInoNonResident(ni))) {
+               unmap_mft_record(base_ni);
+               goto retry_writepage;
+       }
        ctx = ntfs_attr_get_search_ctx(base_ni, m);
        if (unlikely(!ctx)) {
                err = -ENOMEM;
@@ -1639,6 +1666,8 @@ lock_retry_remap:
                                                        "not supported yet. "
                                                        "Sorry.");
                                        err = -EOPNOTSUPP;
+                                       if (!rl)
+                                               up_read(&ni->runlist.lock);
                                        goto err_out;
                                } else if (!is_retry &&
                                                lcn == LCN_RL_NOT_MAPPED) {
@@ -1653,7 +1682,8 @@ lock_retry_remap:
                                                goto lock_retry_remap;
                                        rl = NULL;
                                        lcn = err;
-                               }
+                               } else if (!rl)
+                                       up_read(&ni->runlist.lock);
                                /*
                                 * Failed to map the buffer, even after
                                 * retrying.