Commit c7064ef13b2181a489836349f9baf87df0dab28f

Authored by Jiaying Zhang
Committed by Theodore Ts'o
1 parent b8b8afe236

ext4: mechanical rename some of the direct I/O get_block's identifiers

This commit renames some of the direct I/O's block allocation flags,
variables, and functions introduced in Mingming's "Direct IO for holes
and fallocate" patches so that they can be used by ext4's buffered
write path as well.  Also changed the related function comments
accordingly to cover both direct write and buffered write cases.

Signed-off-by: Jiaying Zhang <jiayingz@google.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>

Showing 5 changed files with 61 additions and 69 deletions Side-by-side Diff

... ... @@ -133,7 +133,7 @@
133 133 int pages_written;
134 134 int retval;
135 135 };
136   -#define DIO_AIO_UNWRITTEN 0x1
  136 +#define EXT4_IO_UNWRITTEN 0x1
137 137 typedef struct ext4_io_end {
138 138 struct list_head list; /* per-file finished AIO list */
139 139 struct inode *inode; /* file being written to */
140 140  
141 141  
... ... @@ -355,13 +355,13 @@
355 355 /* caller is from the direct IO path, request to creation of an
356 356 unitialized extents if not allocated, split the uninitialized
357 357 extent if blocks has been preallocated already*/
358   -#define EXT4_GET_BLOCKS_DIO 0x0008
  358 +#define EXT4_GET_BLOCKS_PRE_IO 0x0008
359 359 #define EXT4_GET_BLOCKS_CONVERT 0x0010
360   -#define EXT4_GET_BLOCKS_DIO_CREATE_EXT (EXT4_GET_BLOCKS_DIO|\
  360 +#define EXT4_GET_BLOCKS_IO_CREATE_EXT (EXT4_GET_BLOCKS_PRE_IO|\
361 361 EXT4_GET_BLOCKS_CREATE_UNINIT_EXT)
362   - /* Convert extent to initialized after direct IO complete */
363   -#define EXT4_GET_BLOCKS_DIO_CONVERT_EXT (EXT4_GET_BLOCKS_CONVERT|\
364   - EXT4_GET_BLOCKS_DIO_CREATE_EXT)
  362 + /* Convert extent to initialized after IO complete */
  363 +#define EXT4_GET_BLOCKS_IO_CONVERT_EXT (EXT4_GET_BLOCKS_CONVERT|\
  364 + EXT4_GET_BLOCKS_IO_CREATE_EXT)
365 365  
366 366 /*
367 367 * Flags used by ext4_free_blocks
... ... @@ -700,8 +700,8 @@
700 700 qsize_t i_reserved_quota;
701 701 #endif
702 702  
703   - /* completed async DIOs that might need unwritten extents handling */
704   - struct list_head i_aio_dio_complete_list;
  703 + /* completed IOs that might need unwritten extents handling */
  704 + struct list_head i_completed_io_list;
705 705 /* current io_end structure for async DIO write*/
706 706 ext4_io_end_t *cur_aio_dio;
707 707  
... ... @@ -1461,7 +1461,7 @@
1461 1461 struct address_space *mapping, loff_t from);
1462 1462 extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf);
1463 1463 extern qsize_t *ext4_get_reserved_space(struct inode *inode);
1464   -extern int flush_aio_dio_completed_IO(struct inode *inode);
  1464 +extern int flush_completed_IO(struct inode *inode);
1465 1465 extern void ext4_da_update_reserve_space(struct inode *inode,
1466 1466 int used, int quota_claim);
1467 1467 /* ioctl.c */
... ... @@ -1619,7 +1619,7 @@
1619 1619 BUG_ON(path[depth].p_hdr == NULL);
1620 1620  
1621 1621 /* try to insert block into found extent and return */
1622   - if (ex && (flag != EXT4_GET_BLOCKS_DIO_CREATE_EXT)
  1622 + if (ex && (flag != EXT4_GET_BLOCKS_PRE_IO)
1623 1623 && ext4_can_extents_be_merged(inode, ex, newext)) {
1624 1624 ext_debug("append [%d]%d block to %d:[%d]%d (from %llu)\n",
1625 1625 ext4_ext_is_uninitialized(newext),
... ... @@ -1740,7 +1740,7 @@
1740 1740  
1741 1741 merge:
1742 1742 /* try to merge extents to the right */
1743   - if (flag != EXT4_GET_BLOCKS_DIO_CREATE_EXT)
  1743 + if (flag != EXT4_GET_BLOCKS_PRE_IO)
1744 1744 ext4_ext_try_to_merge(inode, path, nearex);
1745 1745  
1746 1746 /* try to merge extents to the left */
... ... @@ -2984,7 +2984,7 @@
2984 2984 ext4_ext_dirty(handle, inode, path + depth);
2985 2985 return err;
2986 2986 }
2987   -static int ext4_convert_unwritten_extents_dio(handle_t *handle,
  2987 +static int ext4_convert_unwritten_extents_endio(handle_t *handle,
2988 2988 struct inode *inode,
2989 2989 struct ext4_ext_path *path)
2990 2990 {
... ... @@ -3064,8 +3064,8 @@
3064 3064 flags, allocated);
3065 3065 ext4_ext_show_leaf(inode, path);
3066 3066  
3067   - /* DIO get_block() before submit the IO, split the extent */
3068   - if (flags == EXT4_GET_BLOCKS_DIO_CREATE_EXT) {
  3067 + /* get_block() before submit the IO, split the extent */
  3068 + if (flags == EXT4_GET_BLOCKS_PRE_IO) {
3069 3069 ret = ext4_split_unwritten_extents(handle,
3070 3070 inode, path, iblock,
3071 3071 max_blocks, flags);
3072 3072  
... ... @@ -3075,14 +3075,14 @@
3075 3075 * completed
3076 3076 */
3077 3077 if (io)
3078   - io->flag = DIO_AIO_UNWRITTEN;
  3078 + io->flag = EXT4_IO_UNWRITTEN;
3079 3079 else
3080 3080 ext4_set_inode_state(inode, EXT4_STATE_DIO_UNWRITTEN);
3081 3081 goto out;
3082 3082 }
3083   - /* async DIO end_io complete, convert the filled extent to written */
3084   - if (flags == EXT4_GET_BLOCKS_DIO_CONVERT_EXT) {
3085   - ret = ext4_convert_unwritten_extents_dio(handle, inode,
  3083 + /* IO end_io complete, convert the filled extent to written */
  3084 + if (flags == EXT4_GET_BLOCKS_CONVERT) {
  3085 + ret = ext4_convert_unwritten_extents_endio(handle, inode,
3086 3086 path);
3087 3087 if (ret >= 0)
3088 3088 ext4_update_inode_fsync_trans(handle, inode, 1);
3089 3089  
... ... @@ -3359,9 +3359,9 @@
3359 3359 * For non asycn direct IO case, flag the inode state
3360 3360 * that we need to perform convertion when IO is done.
3361 3361 */
3362   - if (flags == EXT4_GET_BLOCKS_DIO_CREATE_EXT) {
  3362 + if (flags == EXT4_GET_BLOCKS_PRE_IO) {
3363 3363 if (io)
3364   - io->flag = DIO_AIO_UNWRITTEN;
  3364 + io->flag = EXT4_IO_UNWRITTEN;
3365 3365 else
3366 3366 ext4_set_inode_state(inode,
3367 3367 EXT4_STATE_DIO_UNWRITTEN);
... ... @@ -3656,7 +3656,7 @@
3656 3656 map_bh.b_state = 0;
3657 3657 ret = ext4_get_blocks(handle, inode, block,
3658 3658 max_blocks, &map_bh,
3659   - EXT4_GET_BLOCKS_DIO_CONVERT_EXT);
  3659 + EXT4_GET_BLOCKS_IO_CONVERT_EXT);
3660 3660 if (ret <= 0) {
3661 3661 WARN_ON(ret <= 0);
3662 3662 printk(KERN_ERR "%s: ext4_ext_get_blocks "
... ... @@ -63,7 +63,7 @@
63 63 if (inode->i_sb->s_flags & MS_RDONLY)
64 64 return 0;
65 65  
66   - ret = flush_aio_dio_completed_IO(inode);
  66 + ret = flush_completed_IO(inode);
67 67 if (ret < 0)
68 68 return ret;
69 69  
... ... @@ -3468,7 +3468,7 @@
3468 3468 return ret;
3469 3469 }
3470 3470  
3471   -static int ext4_get_block_dio_write(struct inode *inode, sector_t iblock,
  3471 +static int ext4_get_block_write(struct inode *inode, sector_t iblock,
3472 3472 struct buffer_head *bh_result, int create)
3473 3473 {
3474 3474 handle_t *handle = NULL;
3475 3475  
3476 3476  
... ... @@ -3476,28 +3476,14 @@
3476 3476 unsigned max_blocks = bh_result->b_size >> inode->i_blkbits;
3477 3477 int dio_credits;
3478 3478  
3479   - ext4_debug("ext4_get_block_dio_write: inode %lu, create flag %d\n",
  3479 + ext4_debug("ext4_get_block_write: inode %lu, create flag %d\n",
3480 3480 inode->i_ino, create);
3481 3481 /*
3482   - * DIO VFS code passes create = 0 flag for write to
3483   - * the middle of file. It does this to avoid block
3484   - * allocation for holes, to prevent expose stale data
3485   - * out when there is parallel buffered read (which does
3486   - * not hold the i_mutex lock) while direct IO write has
3487   - * not completed. DIO request on holes finally falls back
3488   - * to buffered IO for this reason.
3489   - *
3490   - * For ext4 extent based file, since we support fallocate,
3491   - * new allocated extent as uninitialized, for holes, we
3492   - * could fallocate blocks for holes, thus parallel
3493   - * buffered IO read will zero out the page when read on
3494   - * a hole while parallel DIO write to the hole has not completed.
3495   - *
3496   - * when we come here, we know it's a direct IO write to
3497   - * to the middle of file (<i_size)
3498   - * so it's safe to override the create flag from VFS.
  3482 + * ext4_get_block in prepare for a DIO write or buffer write.
  3483 + * We allocate an uinitialized extent if blocks haven't been allocated.
  3484 + * The extent will be converted to initialized after IO complete.
3499 3485 */
3500   - create = EXT4_GET_BLOCKS_DIO_CREATE_EXT;
  3486 + create = EXT4_GET_BLOCKS_IO_CREATE_EXT;
3501 3487  
3502 3488 if (max_blocks > DIO_MAX_BLOCKS)
3503 3489 max_blocks = DIO_MAX_BLOCKS;
3504 3490  
3505 3491  
... ... @@ -3524,19 +3510,20 @@
3524 3510 iput(io->inode);
3525 3511 kfree(io);
3526 3512 }
3527   -static void dump_aio_dio_list(struct inode * inode)
  3513 +
  3514 +static void dump_completed_IO(struct inode * inode)
3528 3515 {
3529 3516 #ifdef EXT4_DEBUG
3530 3517 struct list_head *cur, *before, *after;
3531 3518 ext4_io_end_t *io, *io0, *io1;
3532 3519  
3533   - if (list_empty(&EXT4_I(inode)->i_aio_dio_complete_list)){
3534   - ext4_debug("inode %lu aio dio list is empty\n", inode->i_ino);
  3520 + if (list_empty(&EXT4_I(inode)->i_completed_io_list)){
  3521 + ext4_debug("inode %lu completed_io list is empty\n", inode->i_ino);
3535 3522 return;
3536 3523 }
3537 3524  
3538   - ext4_debug("Dump inode %lu aio_dio_completed_IO list \n", inode->i_ino);
3539   - list_for_each_entry(io, &EXT4_I(inode)->i_aio_dio_complete_list, list){
  3525 + ext4_debug("Dump inode %lu completed_io list \n", inode->i_ino);
  3526 + list_for_each_entry(io, &EXT4_I(inode)->i_completed_io_list, list){
3540 3527 cur = &io->list;
3541 3528 before = cur->prev;
3542 3529 io0 = container_of(before, ext4_io_end_t, list);
3543 3530  
3544 3531  
... ... @@ -3552,21 +3539,21 @@
3552 3539 /*
3553 3540 * check a range of space and convert unwritten extents to written.
3554 3541 */
3555   -static int ext4_end_aio_dio_nolock(ext4_io_end_t *io)
  3542 +static int ext4_end_io_nolock(ext4_io_end_t *io)
3556 3543 {
3557 3544 struct inode *inode = io->inode;
3558 3545 loff_t offset = io->offset;
3559 3546 ssize_t size = io->size;
3560 3547 int ret = 0;
3561 3548  
3562   - ext4_debug("end_aio_dio_onlock: io 0x%p from inode %lu,list->next 0x%p,"
  3549 + ext4_debug("ext4_end_io_nolock: io 0x%p from inode %lu,list->next 0x%p,"
3563 3550 "list->prev 0x%p\n",
3564 3551 io, inode->i_ino, io->list.next, io->list.prev);
3565 3552  
3566 3553 if (list_empty(&io->list))
3567 3554 return ret;
3568 3555  
3569   - if (io->flag != DIO_AIO_UNWRITTEN)
  3556 + if (io->flag != EXT4_IO_UNWRITTEN)
3570 3557 return ret;
3571 3558  
3572 3559 if (offset + size <= i_size_read(inode))
3573 3560  
3574 3561  
... ... @@ -3584,17 +3571,18 @@
3584 3571 io->flag = 0;
3585 3572 return ret;
3586 3573 }
  3574 +
3587 3575 /*
3588 3576 * work on completed aio dio IO, to convert unwritten extents to extents
3589 3577 */
3590   -static void ext4_end_aio_dio_work(struct work_struct *work)
  3578 +static void ext4_end_io_work(struct work_struct *work)
3591 3579 {
3592 3580 ext4_io_end_t *io = container_of(work, ext4_io_end_t, work);
3593 3581 struct inode *inode = io->inode;
3594 3582 int ret = 0;
3595 3583  
3596 3584 mutex_lock(&inode->i_mutex);
3597   - ret = ext4_end_aio_dio_nolock(io);
  3585 + ret = ext4_end_io_nolock(io);
3598 3586 if (ret >= 0) {
3599 3587 if (!list_empty(&io->list))
3600 3588 list_del_init(&io->list);
3601 3589  
3602 3590  
3603 3591  
3604 3592  
3605 3593  
3606 3594  
... ... @@ -3602,32 +3590,35 @@
3602 3590 }
3603 3591 mutex_unlock(&inode->i_mutex);
3604 3592 }
  3593 +
3605 3594 /*
3606 3595 * This function is called from ext4_sync_file().
3607 3596 *
3608   - * When AIO DIO IO is completed, the work to convert unwritten
3609   - * extents to written is queued on workqueue but may not get immediately
  3597 + * When IO is completed, the work to convert unwritten extents to
  3598 + * written is queued on workqueue but may not get immediately
3610 3599 * scheduled. When fsync is called, we need to ensure the
3611 3600 * conversion is complete before fsync returns.
3612   - * The inode keeps track of a list of completed AIO from DIO path
3613   - * that might needs to do the conversion. This function walks through
3614   - * the list and convert the related unwritten extents to written.
  3601 + * The inode keeps track of a list of pending/completed IO that
  3602 + * might needs to do the conversion. This function walks through
  3603 + * the list and convert the related unwritten extents for completed IO
  3604 + * to written.
  3605 + * The function return the number of pending IOs on success.
3615 3606 */
3616   -int flush_aio_dio_completed_IO(struct inode *inode)
  3607 +int flush_completed_IO(struct inode *inode)
3617 3608 {
3618 3609 ext4_io_end_t *io;
3619 3610 int ret = 0;
3620 3611 int ret2 = 0;
3621 3612  
3622   - if (list_empty(&EXT4_I(inode)->i_aio_dio_complete_list))
  3613 + if (list_empty(&EXT4_I(inode)->i_completed_io_list))
3623 3614 return ret;
3624 3615  
3625   - dump_aio_dio_list(inode);
3626   - while (!list_empty(&EXT4_I(inode)->i_aio_dio_complete_list)){
3627   - io = list_entry(EXT4_I(inode)->i_aio_dio_complete_list.next,
  3616 + dump_completed_IO(inode);
  3617 + while (!list_empty(&EXT4_I(inode)->i_completed_io_list)){
  3618 + io = list_entry(EXT4_I(inode)->i_completed_io_list.next,
3628 3619 ext4_io_end_t, list);
3629 3620 /*
3630   - * Calling ext4_end_aio_dio_nolock() to convert completed
  3621 + * Calling ext4_end_io_nolock() to convert completed
3631 3622 * IO to written.
3632 3623 *
3633 3624 * When ext4_sync_file() is called, run_queue() may already
... ... @@ -3640,7 +3631,7 @@
3640 3631 * avoid double converting from both fsync and background work
3641 3632 * queue work.
3642 3633 */
3643   - ret = ext4_end_aio_dio_nolock(io);
  3634 + ret = ext4_end_io_nolock(io);
3644 3635 if (ret < 0)
3645 3636 ret2 = ret;
3646 3637 else
... ... @@ -3662,7 +3653,7 @@
3662 3653 io->offset = 0;
3663 3654 io->size = 0;
3664 3655 io->error = 0;
3665   - INIT_WORK(&io->work, ext4_end_aio_dio_work);
  3656 + INIT_WORK(&io->work, ext4_end_io_work);
3666 3657 INIT_LIST_HEAD(&io->list);
3667 3658 }
3668 3659  
... ... @@ -3685,7 +3676,7 @@
3685 3676 size);
3686 3677  
3687 3678 /* if not aio dio with unwritten extents, just free io and return */
3688   - if (io_end->flag != DIO_AIO_UNWRITTEN){
  3679 + if (io_end->flag != EXT4_IO_UNWRITTEN){
3689 3680 ext4_free_io_end(io_end);
3690 3681 iocb->private = NULL;
3691 3682 return;
3692 3683  
... ... @@ -3700,9 +3691,10 @@
3700 3691  
3701 3692 /* Add the io_end to per-inode completed aio dio list*/
3702 3693 list_add_tail(&io_end->list,
3703   - &EXT4_I(io_end->inode)->i_aio_dio_complete_list);
  3694 + &EXT4_I(io_end->inode)->i_completed_io_list);
3704 3695 iocb->private = NULL;
3705 3696 }
  3697 +
3706 3698 /*
3707 3699 * For ext4 extent files, ext4 will do direct-io write to holes,
3708 3700 * preallocated extents, and those write extend the file, no need to
... ... @@ -3772,7 +3764,7 @@
3772 3764 ret = blockdev_direct_IO(rw, iocb, inode,
3773 3765 inode->i_sb->s_bdev, iov,
3774 3766 offset, nr_segs,
3775   - ext4_get_block_dio_write,
  3767 + ext4_get_block_write,
3776 3768 ext4_end_io_dio);
3777 3769 if (iocb->private)
3778 3770 EXT4_I(inode)->cur_aio_dio = NULL;
... ... @@ -708,7 +708,7 @@
708 708 #ifdef CONFIG_QUOTA
709 709 ei->i_reserved_quota = 0;
710 710 #endif
711   - INIT_LIST_HEAD(&ei->i_aio_dio_complete_list);
  711 + INIT_LIST_HEAD(&ei->i_completed_io_list);
712 712 ei->cur_aio_dio = NULL;
713 713 ei->i_sync_tid = 0;
714 714 ei->i_datasync_tid = 0;