@@ -578,8 +578,8 @@ enum {
* allows jbd2 to avoid submitting data before commit. */
#define EXT4_GET_BLOCKS_IO_SUBMIT 0x0400
- /* Search in extent tree only */
-#define EXT4_GET_BLOCKS_EXTENT_TREE_ONLY 0x8000
+ /* Search in extent tree only and do not block */
+#define EXT4_GET_BLOCKS_EXTENT_TREE_ONLY_NONBLOCK 0x8000
/*
* The bit position of these flags must not overlap with any of the
@@ -798,7 +798,12 @@ int __ext4_es_lookup_extent(struct inode *inode, ext4_lblk_t lblk,
es_debug("lookup extent in block %u\n", lblk);
tree = &EXT4_I(inode)->i_es_tree;
- read_lock(&EXT4_I(inode)->i_es_lock);
+
+ if (flags & EXT4_GET_BLOCKS_EXTENT_TREE_ONLY_NONBLOCK) {
+ if (!read_trylock(&EXT4_I(inode)->i_es_lock))
+ return 0;
+ } else
+ read_lock(&EXT4_I(inode)->i_es_lock);
/* find extent in cache firstly */
es->es_lblk = es->es_len = es->es_pblk = 0;
@@ -137,7 +137,7 @@ static int ext4_fastmap(struct inode *inode, sector_t lblk_sec,
return -ENOENT;
found = __ext4_overwrite_io(inode, lblk_sec << 9, len, &map,
- EXT4_GET_BLOCKS_EXTENT_TREE_ONLY);
+ EXT4_GET_BLOCKS_EXTENT_TREE_ONLY_NONBLOCK);
if (!found)
return -ENOENT;
@@ -497,7 +497,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
return -EIO;
/* Lookup extent status tree firstly */
- if (ext4_es_lookup_extent(inode, map->m_lblk, &es)) {
+ if (__ext4_es_lookup_extent(inode, map->m_lblk, &es, flags)) {
if (ext4_es_is_written(&es) || ext4_es_is_unwritten(&es)) {
map->m_pblk = ext4_es_pblock(&es) +
map->m_lblk - es.es_lblk;
@@ -524,7 +524,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
goto found;
}
- if (flags & EXT4_GET_BLOCKS_EXTENT_TREE_ONLY)
+ if (flags & EXT4_GET_BLOCKS_EXTENT_TREE_ONLY_NONBLOCK)
return -ENOENT;
/*