[Devel] [PATCH RHEL7 COMMIT] ve: Add a ability to show ve.mount_opts

Konstantin Khorenko khorenko at virtuozzo.com
Thu Aug 27 07:38:33 PDT 2015


The commit is pushed to "branch-rh7-3.10.0-229.7.2-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-229.7.2.vz7.6.2
------>
commit a6c8cc76947a3748a0151032a28d2dfeb49af2fd
Author: Kirill Tkhai <ktkhai at odin.com>
Date:   Thu Aug 27 18:38:33 2015 +0400

    ve: Add a ability to show ve.mount_opts
    
    A user may want to see allowed mount options.
    This patch allows that.
    
    khorenko@:
    * by default ve cgroup is not visible from inside a CT
    
    * currently it's possible to mount ve cgroup inside a CT, but this is
      temporarily, we'll disable this in the scope of
      https://jira.sw.ru/browse/PSBM-34291
    
    * this patch allows to see mount options via ve cgroup =>
      after PSBM-34291 is fixed, mount options will be visible only from ve0 (host)
    
    * for host it's OK to see all hidden options
    
    Signed-off-by: Kirill Tkhai <ktkhai at odin.com>
---
 kernel/ve/ve.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 82 insertions(+)

diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index 6496727..4cd1f8b 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -929,6 +929,85 @@ out:
 	return err;
 }
 
+static void *ve_mount_opts_start(struct seq_file *m, loff_t *ppos)
+{
+	struct ve_struct *ve = m->private;
+	struct ve_devmnt *devmnt;
+	loff_t pos = *ppos;
+
+	mutex_lock(&ve->devmnt_mutex);
+	list_for_each_entry(devmnt, &ve->devmnt_list, link) {
+		if (!pos--)
+			return devmnt;
+	}
+	return NULL;
+}
+
+static void *ve_mount_opts_next(struct seq_file *m, void *v, loff_t *ppos)
+{
+	struct ve_struct *ve = m->private;
+	struct ve_devmnt *devmnt = v;
+
+	(*ppos)++;
+	if (list_is_last(&devmnt->link, &ve->devmnt_list))
+		return NULL;
+	return list_entry(devmnt->link.next, struct ve_devmnt, link);
+}
+
+static void ve_mount_opts_stop(struct seq_file *m, void *v)
+{
+	struct ve_struct *ve = m->private;
+
+	mutex_unlock(&ve->devmnt_mutex);
+}
+
+static int ve_mount_opts_show(struct seq_file *m, void *v)
+{
+	struct ve_devmnt *devmnt = v;
+	dev_t dev = devmnt->dev;
+
+	seq_printf(m, "0 %u:%u;1 %s;2 %s;\n", MAJOR(dev), MINOR(dev),
+					      devmnt->hidden_options,
+					      devmnt->allowed_options);
+	return 0;
+}
+
+struct seq_operations ve_mount_opts_sops = {
+	.start = ve_mount_opts_start,
+	.stop = ve_mount_opts_stop,
+	.next = ve_mount_opts_next,
+	.show = ve_mount_opts_show,
+};
+
+static int ve_mount_opts_open(struct inode *inode, struct file *file)
+{
+	struct ve_struct *ve = cgroup_ve(file->f_dentry->d_parent->d_fsdata);
+	struct seq_file *m;
+	int ret;
+
+	if (ve_is_super(ve))
+		return -ENODEV;
+
+	ret = seq_open(file, &ve_mount_opts_sops);
+	if (!ret) {
+		m = file->private_data;
+		m->private = ve;
+	}
+	return ret;
+}
+
+static ssize_t ve_mount_opts_read(struct cgroup *cgrp, struct cftype *cft,
+				  struct file *file, char __user *buf,
+				  size_t nbytes, loff_t *ppos)
+{
+	return seq_read(file, buf, nbytes, ppos);
+}
+
+static int ve_mount_opts_release(struct inode *inode, struct file *file)
+{
+	return seq_release(inode, file);
+}
+
 /*
  * 'data' for VE_CONFIGURE_MOUNT_OPTIONS is a zero-terminated string
  * consisting of substrings separated by MNTOPT_DELIM.
@@ -1162,6 +1241,9 @@ static struct cftype ve_cftypes[] = {
 	{
 		.name			= "mount_opts",
 		.flags			= CFTYPE_NOT_ON_ROOT,
+		.open			= ve_mount_opts_open,
+		.read			= ve_mount_opts_read,
+		.release		= ve_mount_opts_release,
 		.write_string		= ve_mount_opts_write,
 	},
 	{



More information about the Devel mailing list