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

Konstantin Khorenko khorenko at virtuozzo.com
Fri Jul 14 12:28:03 MSK 2017


The commit is pushed to "branch-rh7-3.10.0-514.26.1.vz7.33.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-514.26.1.vz7.33.7
------>
commit 7eb01b0451fe6a4f6414c795455c89789ca48615
Author: Andrei Vagin <avagin at openvz.org>
Date:   Fri Jul 14 13:28:03 2017 +0400

    ploop: show ino and sdev for ploop images in sysfs
    
    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>
    Acked-by: Maxim Patlasov <mpatlasov at virtuozzo.com>
---
 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,


More information about the Devel mailing list