MCPcopy Create free account
hub / github.com/bobranten/Ext4Fsd / ext4_ext_split

Function ext4_ext_split

Ext4Fsd/ext4/ext4_extents.c:778–1002  ·  view source on GitHub ↗

* 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 */

Source from the content-addressed store, hash-verified

776 * - initializes subtree
777 */
778static 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)

Callers 1

ext4_ext_create_new_leafFunction · 0.85

Calls 15

ext_depthFunction · 0.85
ext_debugFunction · 0.85
kzallocFunction · 0.85
ext4_ext_new_meta_blockFunction · 0.85
extents_bwriteFunction · 0.85
ext_block_hdrFunction · 0.85
ext4_ext_space_blockFunction · 0.85
ext4_ext_show_moveFunction · 0.85
le16_add_cpuFunction · 0.85
extents_brelseFunction · 0.85
ext4_ext_get_accessFunction · 0.85

Tested by

no test coverage detected