| 2171 | } |
| 2172 | |
| 2173 | int ext4_ext_remove_space(void *icb, struct inode *inode, unsigned long start) |
| 2174 | { |
| 2175 | struct super_block *sb = inode->i_sb; |
| 2176 | int depth = ext_depth(inode); |
| 2177 | struct ext4_ext_path *path; |
| 2178 | handle_t *handle = NULL; |
| 2179 | int i = 0, err = 0; |
| 2180 | |
| 2181 | /* probably first extent we're gonna free will be last in block */ |
| 2182 | /*handle = ext4_journal_start(inode, depth + 1);*/ |
| 2183 | /*if (IS_ERR(icb, handle))*/ |
| 2184 | /*return PTR_ERR(icb, handle);*/ |
| 2185 | |
| 2186 | /* |
| 2187 | * we start scanning from right side freeing all the blocks |
| 2188 | * after i_size and walking into the deep |
| 2189 | */ |
| 2190 | path = kmalloc(sizeof(struct ext4_ext_path) * (depth + 1), GFP_KERNEL); |
| 2191 | if (path == NULL) { |
| 2192 | ext4_journal_stop(icb, handle); |
| 2193 | return -ENOMEM; |
| 2194 | } |
| 2195 | memset(path, 0, sizeof(struct ext4_ext_path) * (depth + 1)); |
| 2196 | path[0].p_hdr = ext_inode_hdr(inode); |
| 2197 | if (ext4_ext_check_inode(inode)) { |
| 2198 | err = -EIO; |
| 2199 | goto out; |
| 2200 | } |
| 2201 | path[0].p_depth = depth; |
| 2202 | |
| 2203 | while (i >= 0 && err == 0) { |
| 2204 | if (i == depth) { |
| 2205 | /* this is leaf block */ |
| 2206 | err = ext4_ext_rm_leaf(icb, handle, inode, path, start); |
| 2207 | /* root level have p_bh == NULL, extents_brelse() eats this */ |
| 2208 | extents_brelse(path[i].p_bh); |
| 2209 | path[i].p_bh = NULL; |
| 2210 | i--; |
| 2211 | continue; |
| 2212 | } |
| 2213 | |
| 2214 | /* this is index block */ |
| 2215 | if (!path[i].p_hdr) { |
| 2216 | path[i].p_hdr = ext_block_hdr(path[i].p_bh); |
| 2217 | } |
| 2218 | |
| 2219 | if (!path[i].p_idx) { |
| 2220 | /* this level hasn't touched yet */ |
| 2221 | path[i].p_idx = EXT_LAST_INDEX(path[i].p_hdr); |
| 2222 | path[i].p_block = le16_to_cpu(path[i].p_hdr->eh_entries)+1; |
| 2223 | } else { |
| 2224 | /* we've already was here, see at next index */ |
| 2225 | path[i].p_idx--; |
| 2226 | } |
| 2227 | |
| 2228 | if (ext4_ext_more_to_rm(path + i)) { |
| 2229 | struct buffer_head *bh; |
| 2230 | /* go to the next level */ |
no test coverage detected