27 #include <linux/slab.h>
28 #include <linux/types.h>
74 if (cpos >= emi->
ei_cpos && cpos < range) {
83 static int ocfs2_extent_map_lookup(
struct inode *
inode,
unsigned int cpos,
84 unsigned int *
phys,
unsigned int *len,
126 list_move(&emi->
ei_list, &tmp_list);
152 unsigned int range1, range2;
165 if (range2 > emi1->
ei_cpos && range2 <= range1)
209 if (ocfs2_ei_is_contained(emi, ins) ||
210 ocfs2_ei_is_contained(ins, emi)) {
211 ocfs2_copy_emi_fields(emi, ins);
236 ins.
ei_phys = ocfs2_blocks_to_clusters(inode->
i_sb,
245 if (ocfs2_try_to_merge_extent_map(emi, &ins)) {
260 if (new_emi ==
NULL) {
270 ocfs2_copy_emi_fields(new_emi, &ins);
279 ocfs2_copy_emi_fields(emi, &ins);
289 static int ocfs2_last_eb_is_empty(
struct inode *inode,
294 struct buffer_head *eb_bh =
NULL;
309 "Inode %lu has non zero tree depth in "
310 "leaf block %llu\n", inode->
i_ino,
311 (
unsigned long long)eb_bh->b_blocknr);
318 if (next_free == 0 ||
319 (next_free == 1 && ocfs2_is_empty_extent(&el->
l_recs[0])))
360 struct buffer_head *eb_bh,
365 struct buffer_head *next_eb_bh =
NULL;
368 i = ocfs2_search_for_hole_index(el, v_cluster);
378 goto no_more_extents;
390 i = ocfs2_search_for_hole_index(el, v_cluster);
400 *num_clusters =
UINT_MAX - v_cluster;
411 static int ocfs2_get_clusters_nocache(
struct inode *inode,
412 struct buffer_head *di_bh,
413 u32 v_cluster,
unsigned int *hole_len,
415 unsigned int *is_last)
417 int i,
ret, tree_height, len;
422 struct buffer_head *eb_bh =
NULL;
424 memset(ret_rec, 0,
sizeof(*ret_rec));
432 if (tree_height > 0) {
445 "Inode %lu has non zero tree depth in "
446 "leaf block %llu\n", inode->
i_ino,
447 (
unsigned long long)eb_bh->b_blocknr);
480 "record (%u, %u, 0)", inode->
i_ino,
482 ocfs2_rec_clusters(el, rec));
506 if (tree_height == 0)
511 ret = ocfs2_last_eb_is_empty(inode, di);
529 static void ocfs2_relative_extent_offsets(
struct super_block *
sb,
532 u32 *p_cluster,
u32 *num_clusters)
538 *p_cluster = *p_cluster + coff;
545 u32 *p_cluster,
u32 *num_clusters,
547 unsigned int *extent_flags)
550 struct buffer_head *eb_bh =
NULL;
568 "Inode %lu has non zero tree depth in "
569 "xattr leaf block %llu\n", inode->
i_ino,
570 (
unsigned long long)eb_bh->b_blocknr);
587 "record (%u, %u, 0) in xattr", inode->
i_ino,
589 ocfs2_rec_clusters(el, rec));
594 *p_cluster = ocfs2_blocks_to_clusters(inode->
i_sb,
596 *p_cluster = *p_cluster + coff;
598 *num_clusters = ocfs2_rec_clusters(el, rec) - coff;
610 u32 *p_cluster,
u32 *num_clusters,
611 unsigned int *extent_flags)
615 struct buffer_head *di_bh =
NULL;
624 ret = ocfs2_extent_map_lookup(inode, v_cluster, p_cluster,
625 num_clusters, extent_flags);
635 ret = ocfs2_get_clusters_nocache(inode, di_bh, v_cluster, &hole_len,
650 *num_clusters = hole_len;
653 ocfs2_relative_extent_offsets(inode->
i_sb, v_cluster, &rec,
654 p_cluster, num_clusters);
661 *extent_flags =
flags;
673 u64 *ret_count,
unsigned int *extent_flags)
676 int bpc = ocfs2_clusters_to_blocks(inode->
i_sb, 1);
677 u32 cpos, num_clusters, p_cluster;
680 cpos = ocfs2_blocks_to_clusters(inode->
i_sb, v_blkno);
693 boff = ocfs2_clusters_to_blocks(inode->
i_sb, p_cluster);
694 boff += (v_blkno & (
u64)(bpc - 1));
700 *ret_count = ocfs2_clusters_to_blocks(inode->
i_sb, num_clusters);
701 *ret_count -= v_blkno & (
u64)(bpc - 1);
714 static int ocfs2_fiemap_inline(
struct inode *inode,
struct buffer_head *di_bh,
719 unsigned int id_count;
726 if (ocfs2_inode_is_fast_symlink(inode))
727 id_count = ocfs2_fast_symlink_chars(inode->
i_sb);
731 if (map_start < id_count) {
733 if (ocfs2_inode_is_fast_symlink(inode))
748 #define OCFS2_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC)
751 u64 map_start,
u64 map_len)
754 u32 mapping_end, cpos;
755 unsigned int hole_size;
757 u64 len_bytes, phys_bytes, virt_bytes;
758 struct buffer_head *di_bh =
NULL;
771 down_read(&OCFS2_I(inode)->ip_alloc_sem);
777 ocfs2_inode_is_fast_symlink(inode)) {
778 ret = ocfs2_fiemap_inline(inode, di_bh, fieinfo, map_start);
783 mapping_end = ocfs2_clusters_for_bytes(inode->
i_sb,
784 map_start + map_len);
787 while (cpos < mapping_end && !is_last) {
790 ret = ocfs2_get_clusters_nocache(inode, di_bh, cpos,
791 &hole_size, &rec, &is_last);
814 len_bytes, fe_flags);
827 up_read(&OCFS2_I(inode)->ip_alloc_sem);
837 struct inode *inode = file->
f_mapping->host;
839 unsigned int is_last = 0, is_data = 0;
841 u32 cpos, cend,
clen, hole_size;
843 struct buffer_head *di_bh =
NULL;
854 down_read(&OCFS2_I(inode)->ip_alloc_sem);
856 if (*offset >= inode->
i_size) {
868 cpos = *offset >> cs_bits;
869 cend = ocfs2_clusters_for_bytes(inode->
i_sb, inode->
i_size);
871 while (cpos < cend && !is_last) {
872 ret = ocfs2_get_clusters_nocache(inode, di_bh, cpos, &hole_size,
893 if (extoff > *offset)
908 if ((extoff + extlen) > inode->
i_size)
909 extlen = inode->
i_size - extoff;
911 if (extoff > *offset)
922 up_read(&OCFS2_I(inode)->ip_alloc_sem);
930 struct buffer_head *bhs[],
int flags,
932 struct buffer_head *bh))
935 u64 p_block, p_count;
938 trace_ocfs2_read_virt_blocks(
939 inode, (
unsigned long long)v_block, nr, bhs, flags,
942 if (((v_block + nr - 1) << inode->
i_sb->s_blocksize_bits) >=
943 i_size_read(inode)) {
949 down_read(&OCFS2_I(inode)->ip_alloc_sem);
951 &p_block, &p_count,
NULL);
952 up_read(&OCFS2_I(inode)->ip_alloc_sem);
961 "Inode #%llu contains a hole at offset %llu\n",
962 (
unsigned long long)OCFS2_I(inode)->ip_blkno,
963 (
unsigned long long)(v_block + done) <<
964 inode->
i_sb->s_blocksize_bits);
977 for (i = 0; i <
count; i++) {
980 BUG_ON(bhs[done + i]->b_blocknr != (p_block + i));