[Devel] [PATCH RH7] ploop: Change type of freezing argument on snapshot

Kirill Tkhai ktkhai at virtuozzo.com
Thu Oct 1 13:26:23 MSK 2020


This interface is currently unused, so we can change it.
Before become to use it, Igor requested a possibility
to pass partition/block device/crypto target instead
of mount point.

This patch changes the type of argument: now open
block device fd is required. Also added sanity check
of sync_fd: in case of passed sync_fd == -1, we don't
differ it with the case when it is not passed at all.

https://jira.sw.ru/browse/PSBM-107925
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/block/ploop/dev.c |   21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/block/ploop/dev.c b/drivers/block/ploop/dev.c
index 81340f97b7c1..d6edbfbe4422 100644
--- a/drivers/block/ploop/dev.c
+++ b/drivers/block/ploop/dev.c
@@ -3680,20 +3680,23 @@ static int get_bdev_from_fd(int fd, struct block_device **bdev)
 {
 	struct file *file = fget(fd);
 	struct inode *inode;
-	int ret = -ENODEV;
+	int ret;
 
 	if (!file)
-		return -ENODEV;
+		return -EBADF;
 
-	inode = file_inode(file);
+	ret = -ENODEV;
+	inode = file->f_mapping->host;
 	if (!inode)
 		goto fput;
 
-	*bdev = inode->i_sb->s_bdev;
-	if (*bdev) {
-		bdgrab(*bdev);
-		ret = 0;
-	}
+	ret = -ENOTBLK;
+	if (!S_ISBLK(inode->i_mode))
+		goto fput;
+
+	ret = 0;
+	*bdev = I_BDEV(inode);
+	bdgrab(*bdev);
 fput:
 	fput(file);
 	return ret;
@@ -3780,6 +3783,8 @@ static int ploop_snapshot(struct ploop_device * plo, unsigned long arg,
 			return -EINVAL;
 		/* The rest of fields are ignored */
 		sync_fd = chunk.pctl_fd;
+		if (sync_fd < 0)
+			return -EBADF;
 		ctl.pctl_chunks = 1;
 	}
 	if (ctl.pctl_chunks != 1)




More information about the Devel mailing list