]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/xfs/linux-2.6/xfs_aops.c
pata_hpt37x: actually clock HPT374 with 50 MHz DPLL (take 2)
[linux-2.6-omap-h63xx.git] / fs / xfs / linux-2.6 / xfs_aops.c
index 4475588e973a4aa922144c80b39df5948b5199ef..fd4105d662e036b11821f15fb7780a91f0929b00 100644 (file)
@@ -108,14 +108,19 @@ xfs_page_trace(
 
 /*
  * Schedule IO completion handling on a xfsdatad if this was
- * the final hold on this ioend.
+ * the final hold on this ioend. If we are asked to wait,
+ * flush the workqueue.
  */
 STATIC void
 xfs_finish_ioend(
-       xfs_ioend_t             *ioend)
+       xfs_ioend_t     *ioend,
+       int             wait)
 {
-       if (atomic_dec_and_test(&ioend->io_remaining))
+       if (atomic_dec_and_test(&ioend->io_remaining)) {
                queue_work(xfsdatad_workqueue, &ioend->io_work);
+               if (wait)
+                       flush_workqueue(xfsdatad_workqueue);
+       }
 }
 
 /*
@@ -156,6 +161,8 @@ xfs_setfilesize(
        xfs_fsize_t             bsize;
 
        ip = xfs_vtoi(ioend->io_vnode);
+       if (!ip)
+               return;
 
        ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFREG);
        ASSERT(ioend->io_type != IOMAP_READ);
@@ -334,7 +341,7 @@ xfs_end_bio(
        bio->bi_end_io = NULL;
        bio_put(bio);
 
-       xfs_finish_ioend(ioend);
+       xfs_finish_ioend(ioend, 0);
        return 0;
 }
 
@@ -470,7 +477,7 @@ xfs_submit_ioend(
                }
                if (bio)
                        xfs_submit_ioend_bio(ioend, bio);
-               xfs_finish_ioend(ioend);
+               xfs_finish_ioend(ioend, 0);
        } while ((ioend = next) != NULL);
 }
 
@@ -701,7 +708,7 @@ xfs_is_delayed_page(
                        else if (buffer_delay(bh))
                                acceptable = (type == IOMAP_DELAY);
                        else if (buffer_dirty(bh) && buffer_mapped(bh))
-                               acceptable = (type == 0);
+                               acceptable = (type == IOMAP_NEW);
                        else
                                break;
                } while ((bh = bh->b_this_page) != head);
@@ -810,7 +817,7 @@ xfs_convert_page(
                        page_dirty--;
                        count++;
                } else {
-                       type = 0;
+                       type = IOMAP_NEW;
                        if (buffer_mapped(bh) && all_bh && startio) {
                                lock_buffer(bh);
                                xfs_add_to_ioend(inode, bh, offset,
@@ -968,8 +975,8 @@ xfs_page_state_convert(
 
        bh = head = page_buffers(page);
        offset = page_offset(page);
-       flags = -1;
-       type = IOMAP_READ;
+       flags = BMAPI_READ;
+       type = IOMAP_NEW;
 
        /* TODO: cleanup count and page_dirty */
 
@@ -999,14 +1006,16 @@ xfs_page_state_convert(
                 *
                 * Third case, an unmapped buffer was found, and we are
                 * in a path where we need to write the whole page out.
-                */
+                */
                if (buffer_unwritten(bh) || buffer_delay(bh) ||
                    ((buffer_uptodate(bh) || PageUptodate(page)) &&
                     !buffer_mapped(bh) && (unmapped || startio))) {
-                       /*
+                       int new_ioend = 0;
+
+                       /*
                         * Make sure we don't use a read-only iomap
                         */
-                       if (flags == BMAPI_READ)
+                       if (flags == BMAPI_READ)
                                iomap_valid = 0;
 
                        if (buffer_unwritten(bh)) {
@@ -1021,6 +1030,15 @@ xfs_page_state_convert(
                        }
 
                        if (!iomap_valid) {
+                               /*
+                                * if we didn't have a valid mapping then we
+                                * need to ensure that we put the new mapping
+                                * in a new ioend structure. This needs to be
+                                * done to ensure that the ioends correctly
+                                * reflect the block mappings at io completion
+                                * for unwritten extent conversion.
+                                */
+                               new_ioend = 1;
                                if (type == IOMAP_NEW) {
                                        size = xfs_probe_cluster(inode,
                                                        page, bh, head, 0);
@@ -1040,7 +1058,7 @@ xfs_page_state_convert(
                                if (startio) {
                                        xfs_add_to_ioend(inode, bh, offset,
                                                        type, &ioend,
-                                                       !iomap_valid);
+                                                       new_ioend);
                                } else {
                                        set_buffer_dirty(bh);
                                        unlock_buffer(bh);
@@ -1055,7 +1073,7 @@ xfs_page_state_convert(
                         * That means it must already have extents allocated
                         * underneath it. Map the extent by reading it.
                         */
-                       if (!iomap_valid || type != IOMAP_READ) {
+                       if (!iomap_valid || flags != BMAPI_READ) {
                                flags = BMAPI_READ;
                                size = xfs_probe_cluster(inode, page, bh,
                                                                head, 1);
@@ -1066,7 +1084,15 @@ xfs_page_state_convert(
                                iomap_valid = xfs_iomap_valid(&iomap, offset);
                        }
 
-                       type = IOMAP_READ;
+                       /*
+                        * We set the type to IOMAP_NEW in case we are doing a
+                        * small write at EOF that is extending the file but
+                        * without needing an allocation. We need to update the
+                        * file size on I/O completion in this case so it is
+                        * the same case as having just allocated a new extent
+                        * that we are writing into for the first time.
+                        */
+                       type = IOMAP_NEW;
                        if (!test_and_set_bit(BH_Lock, &bh->b_state)) {
                                ASSERT(buffer_mapped(bh));
                                if (iomap_valid)
@@ -1408,6 +1434,13 @@ xfs_end_io_direct(
         * This is not necessary for synchronous direct I/O, but we do
         * it anyway to keep the code uniform and simpler.
         *
+        * Well, if only it were that simple. Because synchronous direct I/O
+        * requires extent conversion to occur *before* we return to userspace,
+        * we have to wait for extent conversion to complete. Look at the
+        * iocb that has been passed to us to determine if this is AIO or
+        * not. If it is synchronous, tell xfs_finish_ioend() to kick the
+        * workqueue and wait for it to complete.
+        *
         * The core direct I/O code might be changed to always call the
         * completion handler in the future, in which case all this can
         * go away.
@@ -1415,9 +1448,9 @@ xfs_end_io_direct(
        ioend->io_offset = offset;
        ioend->io_size = size;
        if (ioend->io_type == IOMAP_READ) {
-               xfs_finish_ioend(ioend);
+               xfs_finish_ioend(ioend, 0);
        } else if (private && size > 0) {
-               xfs_finish_ioend(ioend);
+               xfs_finish_ioend(ioend, is_sync_kiocb(iocb));
        } else {
                /*
                 * A direct I/O write ioend starts it's life in unwritten
@@ -1426,7 +1459,7 @@ xfs_end_io_direct(
                 * handler.
                 */
                INIT_WORK(&ioend->io_work, xfs_end_bio_written);
-               xfs_finish_ioend(ioend);
+               xfs_finish_ioend(ioend, 0);
        }
 
        /*