knfsd: avoid use of unitialised variables on error path when nfs exports
[powerpc.git] / fs / mpage.c
index 9bf2eb3..fa2441f 100644 (file)
@@ -663,12 +663,7 @@ confused:
        /*
         * The caller has a ref on the inode, so *mapping is stable
         */
-       if (*ret) {
-               if (*ret == -ENOSPC)
-                       set_bit(AS_ENOSPC, &mapping->flags);
-               else
-                       set_bit(AS_EIO, &mapping->flags);
-       }
+       mapping_set_error(mapping, *ret);
 out:
        return bio;
 }
@@ -693,6 +688,8 @@ out:
  * the call was made get new I/O started against them.  If wbc->sync_mode is
  * WB_SYNC_ALL then we were called for data integrity and we must wait for
  * existing IO to complete.
+ *
+ * If you fix this you should check generic_writepages() also!
  */
 int
 mpage_writepages(struct address_space *mapping,
@@ -707,9 +704,9 @@ mpage_writepages(struct address_space *mapping,
        struct pagevec pvec;
        int nr_pages;
        pgoff_t index;
-       pgoff_t end = -1;               /* Inclusive */
+       pgoff_t end;            /* Inclusive */
        int scanned = 0;
-       int is_range = 0;
+       int range_whole = 0;
 
        if (wbc->nonblocking && bdi_write_congested(bdi)) {
                wbc->encountered_congestion = 1;
@@ -721,16 +718,14 @@ mpage_writepages(struct address_space *mapping,
                writepage = mapping->a_ops->writepage;
 
        pagevec_init(&pvec, 0);
-       if (wbc->sync_mode == WB_SYNC_NONE) {
+       if (wbc->range_cyclic) {
                index = mapping->writeback_index; /* Start from prev offset */
+               end = -1;
        } else {
-               index = 0;                        /* whole-file sweep */
-               scanned = 1;
-       }
-       if (wbc->start || wbc->end) {
-               index = wbc->start >> PAGE_CACHE_SHIFT;
-               end = wbc->end >> PAGE_CACHE_SHIFT;
-               is_range = 1;
+               index = wbc->range_start >> PAGE_CACHE_SHIFT;
+               end = wbc->range_end >> PAGE_CACHE_SHIFT;
+               if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
+                       range_whole = 1;
                scanned = 1;
        }
 retry:
@@ -759,7 +754,7 @@ retry:
                                continue;
                        }
 
-                       if (unlikely(is_range) && page->index > end) {
+                       if (!wbc->range_cyclic && page->index > end) {
                                done = 1;
                                unlock_page(page);
                                continue;
@@ -776,14 +771,7 @@ retry:
 
                        if (writepage) {
                                ret = (*writepage)(page, wbc);
-                               if (ret) {
-                                       if (ret == -ENOSPC)
-                                               set_bit(AS_ENOSPC,
-                                                       &mapping->flags);
-                                       else
-                                               set_bit(AS_EIO,
-                                                       &mapping->flags);
-                               }
+                               mapping_set_error(mapping, ret);
                        } else {
                                bio = __mpage_writepage(bio, page, get_block,
                                                &last_block_in_bio, &ret, wbc,
@@ -810,7 +798,7 @@ retry:
                index = 0;
                goto retry;
        }
-       if (!is_range)
+       if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
                mapping->writeback_index = index;
        if (bio)
                mpage_bio_submit(WRITE, bio);