Skip to contentSkip to conversation

fat: permit to return phy block number by fibmap in fallocated region

PATCH Superseded Namjae Jeon 2 participants 5 messages Nov 17, 2013 – Dec 6, 2013

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 5/5 fat: permit to return phy block number by fibmap in fallocated region

From: Namjae Jeon <[email protected]>

Make the fibmap call the return the proper physical block number for any offset request in the fallocated range.

---
 fs/fat/cache.c |   16 ++++++++++++++--
 fs/fat/inode.c |    4 ++--
 2 files changed, 16 insertions(+), 4 deletions(-)
fs/fat/cache.c +14 -2
index c56bd7e..7777822 100644
@@ -312,6 +312,7 @@ int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys,
 	const unsigned char blocksize_bits = sb->s_blocksize_bits;
 	sector_t last_block;
 	int cluster, offset;
+	loff_t i_size = i_size_read(inode);
 
 	*phys = 0;
 	*mapped_blocks = 0;
@@ -323,10 +324,20 @@ int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys,
 		return 0;
 	}
 
-	last_block = (i_size_read(inode) + (blocksize - 1)) >> blocksize_bits;
+	last_block = (i_size + (blocksize - 1)) >> blocksize_bits;
 	if (sector >= last_block) {
-		if (!create)
+		if (!create) {
+			/*
+			 * to map cluster in case of read request
+			 * for a block in fallocated region
+			 */
+			if (MSDOS_I(inode)->i_disksize >
+			    round_up(i_size, sb->s_blocksize)) {
+				goto out_map_cluster;
+			}
+
 			return 0;
+		}
 
 		/*
 		 * Both ->mmu_private and ->i_disksize can access
@@ -339,6 +350,7 @@ int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys,
 			return 0;
 	}
 
+out_map_cluster:
 	cluster = sector >> (sbi->cluster_bits - sb->s_blocksize_bits);
 	offset  = sector & (sbi->sec_per_clus - 1);
 	cluster = fat_bmap_cluster(inode, cluster);
fs/fat/inode.c +2 -2
index c9fb9b6..bdd1efd 100644
@@ -243,9 +243,9 @@ static sector_t _fat_bmap(struct address_space *mapping, sector_t block)
 	sector_t blocknr;
 
 	/* fat_get_cluster() assumes the requested blocknr isn't truncated. */
-	down_read(&MSDOS_I(mapping->host)->truncate_lock);
+	mutex_lock(&mapping->host->i_mutex);
 	blocknr = generic_block_bmap(mapping, block, fat_get_block);
-	up_read(&MSDOS_I(mapping->host)->truncate_lock);
+	mutex_unlock(&mapping->host->i_mutex);
 
 	return blocknr;
 }
Signature · 1 line
1.7.9.5
maintainer
#1 lore raw
Quoted 19 lines · Namjae Jeon
fs/fat/cache.c +2 -1
index c56bd7e..7777822 100644
@@ -312,6 +312,7 @@ int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys,
 	const unsigned char blocksize_bits = sb->s_blocksize_bits;
 	sector_t last_block;
 	int cluster, offset;
+	loff_t i_size = i_size_read(inode);
 
 	*phys = 0;
 	*mapped_blocks = 0;
@@ -323,10 +324,20 @@ int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys,
 		return 0;
 	}
 
-	last_block = (i_size_read(inode) + (blocksize - 1)) >> blocksize_bits;
+	last_block = (i_size + (blocksize - 1)) >> blocksize_bits;
 	if (sector >= last_block) {

fs/fat/cache.c int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys, · line 337

Quoted 10 lines
fs/fat/cache.c +9 -1
-		if (!create)
+		if (!create) {
+			/*
+			 * to map cluster in case of read request
+			 * for a block in fallocated region
+			 */
+			if (MSDOS_I(inode)->i_disksize >
+			    round_up(i_size, sb->s_blocksize)) {
+				goto out_map_cluster;
+			}

Said on another reply though, we will have to add new flag for this. Because normal read get_block() operation should not return mapping beyond ->i_size.

fs/fat/cache.c int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys,

Quoted 9 lines
fs/fat/cache.c +2 -2
 	/* fat_get_cluster() assumes the requested blocknr isn't truncated. */
-	down_read(&MSDOS_I(mapping->host)->truncate_lock);
+	mutex_lock(&mapping->host->i_mutex);
 	blocknr = generic_block_bmap(mapping, block, fat_get_block);
-	up_read(&MSDOS_I(mapping->host)->truncate_lock);
+	mutex_unlock(&mapping->host->i_mutex);
 
 	return blocknr;
 }

->i_mutex doesn't work for swapfile.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#2 lore raw

2013/12/1, OGAWA Hirofumi <[email protected]>:

Quoted 29 lines
Quoted 27 lines · Namjae Jeon
fs/fat/cache.c +1 -0
index c56bd7e..7777822 100644
@@ -312,6 +312,7 @@ int fat_bmap(struct inode *inode, sector_t sector,
 sector_t *phys,
 	const unsigned char blocksize_bits = sb->s_blocksize_bits;
 	sector_t last_block;
 	int cluster, offset;
+	loff_t i_size = i_size_read(inode);
 
 	*phys = 0;
fs/fat/cache.c +6 -2
 	*mapped_blocks = 0;
@@ -323,10 +324,20 @@ int fat_bmap(struct inode *inode, sector_t sector,
 sector_t *phys,
 		return 0;
 	}
 
-	last_block = (i_size_read(inode) + (blocksize - 1)) >> blocksize_bits;
+	last_block = (i_size + (blocksize - 1)) >> blocksize_bits;
 	if (sector >= last_block) {
-		if (!create)
+		if (!create) {
+			/*
+			 * to map cluster in case of read request
+			 * for a block in fallocated region
+			 */
Quoted 8 lines

fs/fat/cache.c int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys, · line 337

Quoted 4 lines
fs/fat/cache.c +4 -0
+			if (MSDOS_I(inode)->i_disksize >
+			    round_up(i_size, sb->s_blocksize)) {
+				goto out_map_cluster;
+			}

Said on another reply though, we will have to add new flag for this. Because normal read get_block() operation should not return mapping beyond ->i_size.

Okay.

Quoted 8 lines
Quoted 8 lines
fs/fat/cache.c +2 -2
 	/* fat_get_cluster() assumes the requested blocknr isn't truncated. */
-	down_read(&MSDOS_I(mapping->host)->truncate_lock);
+	mutex_lock(&mapping->host->i_mutex);
 	blocknr = generic_block_bmap(mapping, block, fat_get_block);
-	up_read(&MSDOS_I(mapping->host)->truncate_lock);
+	mutex_unlock(&mapping->host->i_mutex);
Quoted 4 lines
Quoted 2 lines

return blocknr;
}

->i_mutex doesn't work for swapfile.

Sorry, Actually, I don't understand why it is related with swapfile. Could you elaborate more ?

Thanks.

Quoted 3 lines

--
OGAWA Hirofumi <[email protected]>

maintainer
#3 lore raw
Quoted 3 lines · Namjae Jeon
Quoted 1 line

->i_mutex doesn't work for swapfile.

Sorry, Actually, I don't understand why it is related with swapfile. Could you elaborate more ?

swapfile.c calls ->bmap to know physical address in swapfile. However, swapfile.c calls ->bmap under inode->i_mutex.

Thanks.

Signature · 1 line
OGAWA Hirofumi <[email protected]>
#4 lore raw

2013/12/6, OGAWA Hirofumi <[email protected]>:

Quoted 8 lines
Quoted 3 lines · Namjae Jeon
Quoted 1 line

->i_mutex doesn't work for swapfile.

Sorry, Actually, I don't understand why it is related with swapfile. Could you elaborate more ?

swapfile.c calls ->bmap to know physical address in swapfile. However, swapfile.c calls ->bmap under inode->i_mutex.

Okay, Thanks for explanation.

Quoted 5 lines

Thanks.
--
OGAWA Hirofumi <[email protected]>