* ext4_ext_split: * inserts new subtree into the path, using free index entry * at depth @at: * - allocates all needed blocks (new leaf and all intermediate index blocks) * - makes decision where to split * - moves remaining extents and index entries (right to the split point) * into the newly allocated blocks * - initializes subtree */
| 776 | * - initializes subtree |
| 777 | */ |
| 778 | static int ext4_ext_split(void *icb, handle_t *handle, struct inode *inode, |
| 779 | unsigned int flags, |
| 780 | struct ext4_ext_path *path, |
| 781 | struct ext4_extent *newext, int at) |
| 782 | { |
| 783 | struct buffer_head *bh = NULL; |
| 784 | int depth = ext_depth(inode); |
| 785 | struct ext4_extent_header *neh; |
| 786 | struct ext4_extent_idx *fidx; |
| 787 | int i = at, k, m, a; |
| 788 | ext4_fsblk_t newblock, oldblock; |
| 789 | __le32 border; |
| 790 | ext4_fsblk_t *ablocks = NULL; /* array of allocated blocks */ |
| 791 | int err = 0; |
| 792 | |
| 793 | /* make decision: where to split? */ |
| 794 | /* FIXME: now decision is simplest: at current extent */ |
| 795 | |
| 796 | /* if current leaf will be split, then we should use |
| 797 | * border from split point */ |
| 798 | if (unlikely(path[depth].p_ext > EXT_MAX_EXTENT(path[depth].p_hdr))) { |
| 799 | EXT4_ERROR_INODE(inode, "p_ext > EXT_MAX_EXTENT!"); |
| 800 | return -EIO; |
| 801 | } |
| 802 | if (path[depth].p_ext != EXT_MAX_EXTENT(path[depth].p_hdr)) { |
| 803 | border = path[depth].p_ext[1].ee_block; |
| 804 | ext_debug("leaf will be split." |
| 805 | " next leaf starts at %d\n", |
| 806 | le32_to_cpu(border)); |
| 807 | } else { |
| 808 | border = newext->ee_block; |
| 809 | ext_debug("leaf will be added." |
| 810 | " next leaf starts at %d\n", |
| 811 | le32_to_cpu(border)); |
| 812 | } |
| 813 | |
| 814 | /* |
| 815 | * If error occurs, then we break processing |
| 816 | * and mark filesystem read-only. index won't |
| 817 | * be inserted and tree will be in consistent |
| 818 | * state. Next mount will repair buffers too. |
| 819 | */ |
| 820 | |
| 821 | /* |
| 822 | * Get array to track all allocated blocks. |
| 823 | * We need this to handle errors and free blocks |
| 824 | * upon them. |
| 825 | */ |
| 826 | ablocks = kzalloc(sizeof(ext4_fsblk_t) * depth, GFP_NOFS); |
| 827 | if (!ablocks) |
| 828 | return -ENOMEM; |
| 829 | |
| 830 | /* allocate all needed blocks */ |
| 831 | ext_debug("allocate %d blocks for indexes/leaf\n", depth - at); |
| 832 | for (a = 0; a < depth - at; a++) { |
| 833 | newblock = ext4_ext_new_meta_block(icb, handle, inode, path, |
| 834 | newext, &err, flags); |
| 835 | if (newblock == 0) |
no test coverage detected