[Devel] [PATCH rh7 07/12] ploop: Add trim_extent_mappings_tail() helper

Kirill Tkhai ktkhai at virtuozzo.com
Fri Mar 1 18:13:59 MSK 2019


Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/block/ploop/io_direct.c     |    5 +++--
 drivers/block/ploop/io_direct_map.c |    6 +++---
 drivers/block/ploop/io_direct_map.h |   13 +++++++++++--
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/block/ploop/io_direct.c b/drivers/block/ploop/io_direct.c
index 3e207a7b9ff5..b0d7095864fc 100644
--- a/drivers/block/ploop/io_direct.c
+++ b/drivers/block/ploop/io_direct.c
@@ -1725,8 +1725,9 @@ static int dio_truncate(struct ploop_io * io, struct file * file,
 
 	mutex_lock(&io->files.inode->i_mutex);
 	if (io->files.em_tree)
-		trim_extent_mappings(io->plo, io->files.em_tree,
-				     newattrs.ia_size>>9);
+		trim_extent_mappings_tail(io->plo, io->files.em_tree,
+					  newattrs.ia_size>>9);
+
 	io->files.inode->i_flags &= ~S_SWAPFILE;
 	err = notify_change(F_DENTRY(file), &newattrs, NULL);
 	io->files.inode->i_flags |= S_SWAPFILE;
diff --git a/drivers/block/ploop/io_direct_map.c b/drivers/block/ploop/io_direct_map.c
index f7784aa32cfa..9afd0610e708 100644
--- a/drivers/block/ploop/io_direct_map.c
+++ b/drivers/block/ploop/io_direct_map.c
@@ -751,13 +751,13 @@ static int drop_extent_map(struct extent_map_tree *tree)
 	return 0;
 }
 
-void trim_extent_mappings(struct ploop_device *plo,
-			  struct extent_map_tree *tree, sector_t start)
+void trim_extent_mappings(struct ploop_device *plo, struct extent_map_tree *tree,
+			  sector_t start, sector_t len)
 {
 	struct extent_map *em;
 
 	spin_lock_irq(&plo->lock);
-	while ((em = lookup_extent_mapping(tree, start, ((sector_t)(-1ULL)) - start))) {
+	while ((em = lookup_extent_mapping(tree, start, len)) != NULL) {
 		remove_extent_mapping(tree, em);
 		WARN_ON(atomic_read(&em->refs) != 2);
 		/* once for us */
diff --git a/drivers/block/ploop/io_direct_map.h b/drivers/block/ploop/io_direct_map.h
index d043d87e22f4..b48a06857567 100644
--- a/drivers/block/ploop/io_direct_map.h
+++ b/drivers/block/ploop/io_direct_map.h
@@ -48,8 +48,8 @@ struct extent_map *extent_lookup(struct extent_map_tree *tree,
 				 sector_t start);
 void ploop_extent_put(struct extent_map *em);
 
-void trim_extent_mappings(struct ploop_device *plo,
-			  struct extent_map_tree *tree, sector_t start);
+void trim_extent_mappings(struct ploop_device *plo, struct extent_map_tree *tree,
+			  sector_t start, sector_t len);
 
 int ploop_dio_close(struct ploop_io * io, int rdonly);
 struct extent_map_tree * ploop_dio_open(struct ploop_io * io, int rdonly);
@@ -59,4 +59,13 @@ int ploop_dio_upgrade(struct ploop_io * io);
 int __init ploop_extent_map_init(void);
 void ploop_extent_map_exit(void);
 
+static inline void trim_extent_mappings_tail(struct ploop_device *plo,
+					     struct extent_map_tree *tree,
+					     sector_t start)
+{
+	sector_t len = ((sector_t)(-1ULL)) - start;
+
+	trim_extent_mappings(plo, tree, start, len);
+}
+
 #endif



More information about the Devel mailing list