ext4: fix warning in ext4_iomap_begin as race between bmap and write
[linux-2.6-microblaze.git] / fs / ext4 / inode.c
index 641c9af..7db52de 100644 (file)
@@ -3147,13 +3147,15 @@ static sector_t ext4_bmap(struct address_space *mapping, sector_t block)
 {
        struct inode *inode = mapping->host;
        journal_t *journal;
+       sector_t ret = 0;
        int err;
 
+       inode_lock_shared(inode);
        /*
         * We can get here for an inline file via the FIBMAP ioctl
         */
        if (ext4_has_inline_data(inode))
-               return 0;
+               goto out;
 
        if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY) &&
                        test_opt(inode->i_sb, DELALLOC)) {
@@ -3192,10 +3194,14 @@ static sector_t ext4_bmap(struct address_space *mapping, sector_t block)
                jbd2_journal_unlock_updates(journal);
 
                if (err)
-                       return 0;
+                       goto out;
        }
 
-       return iomap_bmap(mapping, block, &ext4_iomap_ops);
+       ret = iomap_bmap(mapping, block, &ext4_iomap_ops);
+
+out:
+       inode_unlock_shared(inode);
+       return ret;
 }
 
 static int ext4_read_folio(struct file *file, struct folio *folio)