linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / fs / direct-io.c
index 5981e17..27f3e78 100644 (file)
@@ -86,12 +86,12 @@ struct dio {
        unsigned first_block_in_page;   /* doesn't change, Used only once */
        int boundary;                   /* prev block is at a boundary */
        int reap_counter;               /* rate limit reaping */
-       get_block_t *get_block;         /* block mapping function */
+       get_blocks_t *get_blocks;       /* block mapping function */
        dio_iodone_t *end_io;           /* IO completion function */
        sector_t final_block_in_bio;    /* current final block in bio + 1 */
        sector_t next_block_for_io;     /* next block to be put under IO,
                                           in dio_blocks units */
-       struct buffer_head map_bh;      /* last get_block() result */
+       struct buffer_head map_bh;      /* last get_blocks() result */
 
        /*
         * Deferred addition of a page to the dio.  These variables are
@@ -129,7 +129,6 @@ struct dio {
        /* AIO related stuff */
        struct kiocb *iocb;             /* kiocb */
        int is_async;                   /* is IO async ? */
-       int io_error;                   /* IO error in completion path */
        ssize_t result;                 /* IO result */
 };
 
@@ -162,7 +161,7 @@ static int dio_refill_pages(struct dio *dio)
                NULL);                          /* vmas */
        up_read(&current->mm->mmap_sem);
 
-       if (ret < 0 && dio->blocks_available && (dio->rw & WRITE)) {
+       if (ret < 0 && dio->blocks_available && (dio->rw == WRITE)) {
                struct page *page = ZERO_PAGE(dio->curr_user_address);
                /*
                 * A memory fault, but the filesystem has some outstanding
@@ -211,17 +210,16 @@ static struct page *dio_get_page(struct dio *dio)
 
 /*
  * Called when all DIO BIO I/O has been completed - let the filesystem
- * know, if it registered an interest earlier via get_block.  Pass the
+ * know, if it registered an interest earlier via get_blocks.  Pass the
  * private field of the map buffer_head so that filesystems can use it
- * to hold additional state between get_block calls and dio_complete.
+ * to hold additional state between get_blocks calls and dio_complete.
  */
 static void dio_complete(struct dio *dio, loff_t offset, ssize_t bytes)
 {
        if (dio->end_io && dio->result)
                dio->end_io(dio->iocb, offset, bytes, dio->map_bh.b_private);
        if (dio->lock_type == DIO_LOCKING)
-               /* lockdep: non-owner release */
-               up_read_non_owner(&dio->inode->i_alloc_sem);
+               up_read(&dio->inode->i_alloc_sem);
 }
 
 /*
@@ -252,10 +250,6 @@ static void finished_one_bio(struct dio *dio)
                            ((offset + transferred) > dio->i_size))
                                transferred = dio->i_size - offset;
 
-                       /* check for error in completion path */
-                       if (dio->io_error)
-                               transferred = dio->io_error;
-
                        dio_complete(dio, offset, transferred);
 
                        /* Complete AIO later if falling back to buffered i/o */
@@ -412,7 +406,7 @@ static int dio_bio_complete(struct dio *dio, struct bio *bio)
        int page_no;
 
        if (!uptodate)
-               dio->io_error = -EIO;
+               dio->result = -EIO;
 
        if (dio->is_async && dio->rw == READ) {
                bio_check_pages_dirty(bio);     /* transfers ownership */
@@ -494,7 +488,7 @@ static int dio_bio_reap(struct dio *dio)
  * The fs is allowed to map lots of blocks at once.  If it wants to do that,
  * it uses the passed inode-relative block number as the file offset, as usual.
  *
- * get_block() is passed the number of i_blkbits-sized blocks which direct_io
+ * get_blocks() is passed the number of i_blkbits-sized blocks which direct_io
  * has remaining to do.  The fs should not map more than this number of blocks.
  *
  * If the fs has mapped a lot of blocks, it should populate bh->b_size to
@@ -507,7 +501,7 @@ static int dio_bio_reap(struct dio *dio)
  * In the case of filesystem holes: the fs may return an arbitrarily-large
  * hole by returning an appropriate value in b_size and by clearing
  * buffer_mapped().  However the direct-io code will only process holes one
- * block at a time - it will repeatedly call get_block() as it walks the hole.
+ * block at a time - it will repeatedly call get_blocks() as it walks the hole.
  */
 static int get_more_blocks(struct dio *dio)
 {
@@ -525,6 +519,8 @@ static int get_more_blocks(struct dio *dio)
         */
        ret = dio->page_errors;
        if (ret == 0) {
+               map_bh->b_state = 0;
+               map_bh->b_size = 0;
                BUG_ON(dio->block_in_file >= dio->final_block_in_request);
                fs_startblk = dio->block_in_file >> dio->blkfactor;
                dio_count = dio->final_block_in_request - dio->block_in_file;
@@ -533,10 +529,7 @@ static int get_more_blocks(struct dio *dio)
                if (dio_count & blkmask)        
                        fs_count++;
 
-               map_bh->b_state = 0;
-               map_bh->b_size = fs_count << dio->inode->i_blkbits;
-
-               create = dio->rw & WRITE;
+               create = dio->rw == WRITE;
                if (dio->lock_type == DIO_LOCKING) {
                        if (dio->block_in_file < (i_size_read(dio->inode) >>
                                                        dio->blkbits))
@@ -544,14 +537,13 @@ static int get_more_blocks(struct dio *dio)
                } else if (dio->lock_type == DIO_NO_LOCKING) {
                        create = 0;
                }
-
                /*
                 * For writes inside i_size we forbid block creations: only
                 * overwrites are permitted.  We fall back to buffered writes
                 * at a higher level for inside-i_size block-instantiating
                 * writes.
                 */
-               ret = (*dio->get_block)(dio->inode, fs_startblk,
+               ret = (*dio->get_blocks)(dio->inode, fs_startblk, fs_count,
                                                map_bh, create);
        }
        return ret;
@@ -786,11 +778,11 @@ static void dio_zero_block(struct dio *dio, int end)
  * happily perform page-sized but 512-byte aligned IOs.  It is important that
  * blockdev IO be able to have fine alignment and large sizes.
  *
- * So what we do is to permit the ->get_block function to populate bh.b_size
+ * So what we do is to permit the ->get_blocks function to populate bh.b_size
  * with the size of IO which is permitted at this offset and this i_blkbits.
  *
  * For best results, the blockdev should be set up with 512-byte i_blkbits and
- * it should set b_size to PAGE_SIZE or more inside get_block().  This gives
+ * it should set b_size to PAGE_SIZE or more inside get_blocks().  This gives
  * fine alignment but still allows this function to work in PAGE_SIZE units.
  */
 static int do_direct_IO(struct dio *dio)
@@ -868,7 +860,7 @@ do_holes:
                                loff_t i_size_aligned;
 
                                /* AKPM: eargh, -ENOTBLK is a hack */
-                               if (dio->rw & WRITE) {
+                               if (dio->rw == WRITE) {
                                        page_cache_release(page);
                                        return -ENOTBLK;
                                }
@@ -930,7 +922,8 @@ do_holes:
                        block_in_page += this_chunk_blocks;
                        dio->blocks_available -= this_chunk_blocks;
 next_block:
-                       BUG_ON(dio->block_in_file > dio->final_block_in_request);
+                       if (dio->block_in_file > dio->final_block_in_request)
+                               BUG();
                        if (dio->block_in_file == dio->final_block_in_request)
                                break;
                }
@@ -949,7 +942,7 @@ out:
 static ssize_t
 direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode, 
        const struct iovec *iov, loff_t offset, unsigned long nr_segs, 
-       unsigned blkbits, get_block_t get_block, dio_iodone_t end_io,
+       unsigned blkbits, get_blocks_t get_blocks, dio_iodone_t end_io,
        struct dio *dio)
 {
        unsigned long user_addr; 
@@ -971,14 +964,13 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
 
        dio->boundary = 0;
        dio->reap_counter = 0;
-       dio->get_block = get_block;
+       dio->get_blocks = get_blocks;
        dio->end_io = end_io;
        dio->map_bh.b_private = NULL;
        dio->final_block_in_bio = -1;
        dio->next_block_for_io = -1;
 
        dio->page_errors = 0;
-       dio->io_error = 0;
        dio->result = 0;
        dio->iocb = iocb;
        dio->i_size = i_size_read(inode);
@@ -1046,7 +1038,7 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
                }
        } /* end iovec loop */
 
-       if (ret == -ENOTBLK && (rw & WRITE)) {
+       if (ret == -ENOTBLK && rw == WRITE) {
                /*
                 * The remaining part of the request will be
                 * be handled by buffered I/O when we return
@@ -1090,7 +1082,7 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
        if (dio->is_async) {
                int should_wait = 0;
 
-               if (dio->result < dio->size && (rw & WRITE)) {
+               if (dio->result < dio->size && rw == WRITE) {
                        dio->waiter = current;
                        should_wait = 1;
                }
@@ -1143,7 +1135,7 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
                        ret = transferred;
 
                /* We could have also come here on an AIO file extend */
-               if (!is_sync_kiocb(iocb) && (rw & WRITE) &&
+               if (!is_sync_kiocb(iocb) && rw == WRITE &&
                    ret >= 0 && dio->result == dio->size)
                        /*
                         * For AIO writes where we have completed the
@@ -1179,7 +1171,7 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
 ssize_t
 __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
        struct block_device *bdev, const struct iovec *iov, loff_t offset, 
-       unsigned long nr_segs, get_block_t get_block, dio_iodone_t end_io,
+       unsigned long nr_segs, get_blocks_t get_blocks, dio_iodone_t end_io,
        int dio_lock_type)
 {
        int seg;
@@ -1195,7 +1187,7 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
        int acquire_i_mutex = 0;
 
        if (rw & WRITE)
-               rw = WRITE_SYNC;
+               current->flags |= PF_SYNCWRITE;
 
        if (bdev)
                bdev_blkbits = blksize_bits(bdev_hardsect_size(bdev));
@@ -1262,8 +1254,7 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
                }
 
                if (dio_lock_type == DIO_LOCKING)
-                       /* lockdep: not the owner will release it */
-                       down_read_non_owner(&inode->i_alloc_sem);
+                       down_read(&inode->i_alloc_sem);
        }
 
        /*
@@ -1272,11 +1263,11 @@ __blockdev_direct_IO(int rw, struct kiocb *iocb, struct inode *inode,
         * even for AIO, we need to wait for i/o to complete before
         * returning in this case.
         */
-       dio->is_async = !is_sync_kiocb(iocb) && !((rw & WRITE) &&
+       dio->is_async = !is_sync_kiocb(iocb) && !((rw == WRITE) &&
                (end > i_size_read(inode)));
 
        retval = direct_io_worker(rw, iocb, inode, iov, offset,
-                               nr_segs, blkbits, get_block, end_io, dio);
+                               nr_segs, blkbits, get_blocks, end_io, dio);
 
        if (rw == READ && dio_lock_type == DIO_LOCKING)
                release_i_mutex = 0;
@@ -1286,6 +1277,8 @@ out:
                mutex_unlock(&inode->i_mutex);
        else if (acquire_i_mutex)
                mutex_lock(&inode->i_mutex);
+       if (rw & WRITE)
+               current->flags &= ~PF_SYNCWRITE;
        return retval;
 }
 EXPORT_SYMBOL(__blockdev_direct_IO);