[Devel] [PATCH] ploop: show ino and sdev for ploop images in sysfs

Andrei Vagin avagin at openvz.org
Fri Jul 14 03:10:05 MSK 2017


Currently we can get an image file for a ploop delta from sysfs, but
there is a problem, if a ploop was mounted or snapshoted from another
mount namespace. In this case, we can't report a full path to a delta in
a current mount namespace, because the origin namespace may be already
destroyed or a mount with ploop deltas can be mounted into another place
in the current mntns.

Here is an example of one of such cases:

$ unshare -m ploop mount /mnt/vstorage/test/DiskDescriptor.xml
Opening delta /mnt/vstorage/test/test
Opening delta /mnt/vstorage/test/test
Adding delta dev=/dev/ploop64360 img=/mnt/vstorage/test/test (rw)

$ cat /sys/block/ploop64360/pdelta/0/image
/test/test

$ cat /sys/block/ploop64360/pdelta/0/image_info
ino:254
sdev:0:38

$ stat /mnt/vstorage/test/test
Device: 26h/38d	Inode: 254         Links: 1

The ploop tool uses delta names to find a proper device by
Diskdescriptor.xml. Actually, a path to a delta file isn't required in
this case, it is enough to know a pair of ino and s_dev.

This patch introduces one more file in sysfs, which is called image_info
and contains an inode number and a source devices for a delta file.

https://jira.sw.ru/browse/PSBM-68404
Signed-off-by: Andrei Vagin <avagin at openvz.org>
---
 drivers/block/ploop/sysfs.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/block/ploop/sysfs.c b/drivers/block/ploop/sysfs.c
index 0395ccf..acd18ff 100644
--- a/drivers/block/ploop/sysfs.c
+++ b/drivers/block/ploop/sysfs.c
@@ -102,6 +102,22 @@ static ssize_t delta_image_show(struct ploop_delta *delta, char *page)
 	return len;
 }
 
+static ssize_t delta_image_info_show(struct ploop_delta *delta, char *page)
+{
+	int len = -ENOENT;
+
+	mutex_lock(&delta->plo->sysfs_mutex);
+	if (delta->io.files.file) {
+		struct inode *inode = file_inode(delta->io.files.file);
+		len = snprintf(page, PAGE_SIZE, "ino:%lu\nsdev:%u:%u\n",
+				inode->i_ino,
+				MAJOR(inode->i_sb->s_dev),
+				MINOR(inode->i_sb->s_dev));
+	}
+	mutex_unlock(&delta->plo->sysfs_mutex);
+	return len;
+}
+
 static ssize_t delta_format_show(struct ploop_delta *delta, char *page)
 {
 	return delta_string_show(delta->ops->name, page);
@@ -147,6 +163,12 @@ static struct delta_sysfs_entry delta_image_entry = {
 	.store = NULL,
 };
 
+static struct delta_sysfs_entry delta_image_info_entry = {
+	.attr = {.name = "image_info", .mode = S_IRUGO },
+	.show = delta_image_info_show,
+	.store = NULL,
+};
+
 static struct delta_sysfs_entry delta_format_entry = {
 	.attr = {.name = "format", .mode = S_IRUGO },
 	.show = delta_format_show,
@@ -179,6 +201,7 @@ static struct delta_sysfs_entry delta_dump_entry = {
 static struct attribute *default_attrs[] = {
 	&delta_level_entry.attr,
 	&delta_image_entry.attr,
+	&delta_image_info_entry.attr,
 	&delta_format_entry.attr,
 	&delta_io_entry.attr,
 	&delta_ro_entry.attr,
-- 
1.8.3.1



More information about the Devel mailing list