[vz8,3/4] Revert "ve/bc: added proc beancounter "resources" interface"

Submitted by Andrey Ryabinin on April 28, 2020, 3:32 p.m.

Details

Message ID 20200428153252.28680-3-aryabinin@virtuozzo.com
State New
Series "Series without cover letter"
Headers show

Commit Message

Andrey Ryabinin April 28, 2020, 3:32 p.m.
This reverts commit 66d346ff5c3f700969d759cc9e1d1eadf5eab83d.

We don't really need this stuff as this just mimics different cgroups.

https://jira.sw.ru/browse/PSBM-80807
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 include/linux/ve.h               |   5 -
 include/uapi/linux/beancounter.h |  66 -------
 kernel/ve/bc/Makefile            |   2 +-
 kernel/ve/bc/proc.c              |  17 --
 kernel/ve/bc/proc.h              |   5 -
 kernel/ve/bc/resources.c         | 307 -------------------------------
 6 files changed, 1 insertion(+), 401 deletions(-)
 delete mode 100644 include/uapi/linux/beancounter.h
 delete mode 100644 kernel/ve/bc/resources.c

Patch hide | download patch | download mbox

diff --git a/include/linux/ve.h b/include/linux/ve.h
index 4f8c06b98381..44593c5cc3ed 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -16,8 +16,6 @@ 
 #include <linux/kthread.h>
 #include <linux/binfmts.h>
 
-#include <uapi/linux/beancounter.h>
-
 struct nsproxy;
 struct veip_struct;
 struct user_namespace;
@@ -97,7 +95,6 @@  struct ve_struct {
 #endif
 
 	struct proc_dir_entry	*ub_proc;
-	struct ubparm		ub_parms[UB_RESOURCES];
 };
 
 #define VE_MEMINFO_DEFAULT	1	/* default behaviour */
@@ -110,8 +107,6 @@  extern int nr_ve;
 #define capable_setveid() \
 	(ve_is_super(get_exec_env()) && capable(CAP_SYS_ADMIN))
 
-#define UB_MAXVALUE	((1UL << (sizeof(unsigned long ) * 8 - 1)) - 1)
-
 #ifdef CONFIG_VE
 extern struct ve_struct *get_ve(struct ve_struct *ve);
 extern void put_ve(struct ve_struct *ve);
diff --git a/include/uapi/linux/beancounter.h b/include/uapi/linux/beancounter.h
deleted file mode 100644
index 1bcb67e82927..000000000000
--- a/include/uapi/linux/beancounter.h
+++ /dev/null
@@ -1,66 +0,0 @@ 
-/*
- *  kernel/ve/bc/resources.c
- *
- *  Copyright (c) 2000-2018 Virtuozzo International GmbH.
- *  All rights reserved.
- *
- */
-
-#ifndef _UAPI_LINUX_BEANCOUNTER_H
-#define _UAPI_LINUX_BEANCOUNTER_H
-
-/*
- * Resource list.
- */
-#define UB_KMEMSIZE		0	/* Unswappable kernel memory size including
-					 * struct task, page directories, etc. */
-#define UB_LOCKEDPAGES		1	/* Mlock()ed pages. */
-#define UB_PRIVVMPAGES		2	/* Total number of pages, counting potentially
-					 * private pages as private and used. */
-#define UB_SHMPAGES		3	/* IPC SHM segment size. */
-#define UB_DUMMY		4	/* Dummy resource (compatibility) */
-#define UB_NUMPROC		5	/* Number of processes. */
-#define UB_PHYSPAGES		6	/* All resident pages, for swapout guarantee. */
-#define UB_VMGUARPAGES		7	/* Guarantee for memory allocation,
-					 * checked against PRIVVMPAGES. */
-#define UB_OOMGUARPAGES		8	/* Guarantees against OOM kill.
-					 * Only limit is used, no accounting. */
-#define UB_NUMTCPSOCK		9	/* Number of TCP sockets. */
-#define UB_NUMFLOCK		10	/* Number of file locks. */
-#define UB_NUMPTY		11	/* Number of PTYs. */
-#define UB_NUMSIGINFO		12	/* Number of siginfos. */
-#define UB_TCPSNDBUF		13	/* Total size of tcp send buffers. */
-#define UB_TCPRCVBUF		14	/* Total size of tcp receive buffers. */
-#define UB_OTHERSOCKBUF		15	/* Total size of other socket
-					 * send buffers (all buffers for PF_UNIX). */
-#define UB_DGRAMRCVBUF		16	/* Total size of other socket
-					 * receive buffers. */
-#define UB_NUMOTHERSOCK		17	/* Number of other sockets. */
-#define UB_DCACHESIZE		18	/* Size of busy dentry/inode cache. */
-#define UB_NUMFILE		19	/* Number of open files. */
-
-#define UB_RESOURCES_COMPAT	24
-
-/*
- * Add new resources here.
- */
-#define UB_NUMXTENT		23
-#define UB_SWAPPAGES		24
-#define UB_RESOURCES		25
-
-struct ubparm {
-	/*
-	 * A barrier over which resource allocations are failed gracefully.
-	 * If the amount of consumed memory is over the barrier further sbrk()
-	 * or mmap() calls fail, the existing processes are not killed.
-	 */
-	unsigned long	barrier;
-	unsigned long	limit;		/* hard resource limit */
-	unsigned long	held;		/* consumed resources */
-	unsigned long	maxheld;	/* maximum amount of consumed resources through the last period */
-	unsigned long	minheld;	/* minimum amount of consumed resources through the last period */
-	unsigned long	failcnt;	/* count of failed charges */
-	int		max_precharge;	/* maximum percpu resource precharge */
-};
-
-#endif /* _UAPI_LINUX_BEANCOUNTER_H */
diff --git a/kernel/ve/bc/Makefile b/kernel/ve/bc/Makefile
index 0071c6bc3c20..c6ec2226e61e 100644
--- a/kernel/ve/bc/Makefile
+++ b/kernel/ve/bc/Makefile
@@ -4,4 +4,4 @@ 
 # Copyright (c) 2000-2017 Virtuozzo International GmbH.  All rights reserved.
 #
 
-obj-$(CONFIG_VE) += proc.o resources.o
+obj-$(CONFIG_VE) += proc.o
diff --git a/kernel/ve/bc/proc.c b/kernel/ve/bc/proc.c
index 4197e51a4c4a..12c57b509496 100644
--- a/kernel/ve/bc/proc.c
+++ b/kernel/ve/bc/proc.c
@@ -22,38 +22,21 @@  static const char *ve_get_name(struct ve_struct *ve)
 
 void ub_remove_proc(struct ve_struct *ve)
 {
-	ub_proc_ve_resources_remove(ve);
 	remove_proc_entry(ve_get_name(ve), bc_proc_root);
 	ve->ub_proc = NULL;
 }
 
 int ub_create_proc(struct ve_struct *ve)
 {
-	int err;
-
 	ve->ub_proc = proc_mkdir(ve_get_name(ve), bc_proc_root);
 	if (!ve->ub_proc)
 		return -ENOMEM;
 
-	err = ub_proc_ve_resources_create(ve);
-	if (err)
-		goto remove_ub_proc;
-
 	return 0;
-
-remove_ub_proc:
-	remove_proc_entry(ve_get_name(ve), bc_proc_root);
-	return err;
 }
 
 static int __init ub_init_proc(void)
 {
-	int err;
-
-	err = ub_proc_all_resources_create();
-	if (err)
-		return err;
-
 	return ub_create_proc(get_ve0());
 }
 core_initcall(ub_init_proc);
diff --git a/kernel/ve/bc/proc.h b/kernel/ve/bc/proc.h
index 9e6c48e0079d..05a0c48da292 100644
--- a/kernel/ve/bc/proc.h
+++ b/kernel/ve/bc/proc.h
@@ -17,9 +17,4 @@  extern struct proc_dir_entry *bc_proc_root;
 void ub_remove_proc(struct ve_struct *ve);
 int ub_create_proc(struct ve_struct *ve);
 
-int ub_proc_ve_resources_create(struct ve_struct *ve);
-void ub_proc_ve_resources_remove(struct ve_struct *ve);
-
-int ub_proc_all_resources_create(void);
-
 #endif
diff --git a/kernel/ve/bc/resources.c b/kernel/ve/bc/resources.c
deleted file mode 100644
index 343e3d82fd98..000000000000
--- a/kernel/ve/bc/resources.c
+++ /dev/null
@@ -1,307 +0,0 @@ 
-/*
- *  kernel/ve/bc/resources.c
- *
- *  Copyright (c) 2000-2018 Virtuozzo International GmbH.
- *  All rights reserved.
- *
- */
-
-#include <linux/proc_fs.h>
-#include <linux/nsproxy.h>
-#include <linux/ve.h>
-
-#include <uapi/linux/beancounter.h>
-#include <net/net_namespace.h>
-
-#include "proc.h"
-
-/* Generic output formats */
-const char *bc_proc_lu_fmt = "\t%-20s %21lu\n";
-const char *bc_proc_lu_lfmt = "\t%-20s %21lu\n";
-const char *bc_proc_llu_fmt = "\t%-20s %21llu\n";
-const char *bc_proc_lu_lu_fmt = "\t%-20s %21lu %21lu\n";
-
-static const char *head_fmt = "%10s  %-12s %20s %20s %20s %20s %20s\n";
-static const char *res_fmt = "%10s%c %-12s %20lu %20lu %20lu %20lu %20lu\n";
-
-static const char *ub_rnames[] = {
-	"kmemsize",     /* 0 */
-	"lockedpages",
-	"privvmpages",
-	"shmpages",
-	"dummy",
-	"numproc",      /* 5 */
-	"physpages",
-	"vmguarpages",
-	"oomguarpages",
-	"numtcpsock",
-	"numflock",     /* 10 */
-	"numpty",
-	"numsiginfo",
-	"tcpsndbuf",
-	"tcprcvbuf",
-	"othersockbuf", /* 15 */
-	"dgramrcvbuf",
-	"numothersock",
-	"dcachesize",
-	"numfile",
-	"dummy",        /* 20 */
-	"dummy",
-	"dummy",
-	"numiptent",
-	"swappages",
-};
-
-static void *ve_to_pde(struct ve_struct *ve)
-{
-	return (void *)(unsigned long)ve->veid;
-}
-
-static struct ve_struct *get_ve_by_inode(struct inode *inode)
-{
-	envid_t veid = (envid_t)(unsigned long)PDE_DATA(inode);
-
-	if (veid)
-		return get_ve_by_id(veid);
-	return get_ve(get_ve0());
-}
-
-static const char *ve_get_name(struct ve_struct *ve)
-{
-	static const char *ve0_name = "0";
-
-	if (ve_is_super(ve))
-		return ve0_name;
-	return ve->ve_name;
-}
-
-static struct nsproxy *get_nsproxy_by_ve(struct ve_struct *ve)
-{
-	struct nsproxy *nsproxy;
-
-	rcu_read_lock();
-	nsproxy = rcu_dereference(ve->ve_ns);
-	if (nsproxy)
-		   get_nsproxy(nsproxy);
-	rcu_read_unlock();
-	return nsproxy;
-}
-
-static void ub_show_res(struct seq_file *f, struct ubparm *p, const char *name,
-			int r, int precharge, int show_uid)
-{
-
-	unsigned long held;
-
-
-	held = p->held;
-	held = (held > precharge) ? (held - precharge) : 0;
-
-	seq_printf(f, res_fmt,
-			show_uid && r == 0 ? name : "",
-			show_uid && r == 0 ? ':' : ' ',
-			ub_rnames[r],
-			held,
-			p->maxheld,
-			p->barrier,
-			p->limit,
-			p->failcnt);
-}
-
-static void cgroups_sync_ub(struct css_set *cset, struct ubparm *ub_parms)
-{
-}
-
-static void __show_resources(struct seq_file *f, struct ve_struct *ve,
-			     struct nsproxy *nsproxy, int show_uid)
-{
-	int r, precharge[UB_RESOURCES] = { };
-
-	cgroups_sync_ub(nsproxy->cgroup_ns->root_cset, ve->ub_parms);
-
-	for (r = 0; r < UB_RESOURCES; r++)
-		if (strcmp(ub_rnames[r], "dummy") != 0)
-			ub_show_res(f, &ve->ub_parms[r], ve_get_name(ve), r,
-				    precharge[r], show_uid);
-}
-
-static int res_show(struct seq_file *f, void *v)
-{
-	struct ve_struct *ve = (struct ve_struct *)v;
-	struct nsproxy *nsproxy;
-
-	nsproxy = get_nsproxy_by_ve(ve);
-	if (nsproxy) {
-		__show_resources(f, ve, nsproxy, 1);
-		put_nsproxy(nsproxy);
-	}
-	return 0;
-}
-
-static int ve_accessible(struct ve_struct *target)
-{
-	return (get_exec_env() == get_ve0() || get_exec_env() == target);
-}
-
-static void ub_show_header(struct seq_file *f)
-{
-	seq_printf(f, "Version: 2.5\n");
-	seq_printf(f, head_fmt, "uid", "resource",
-			"held", "maxheld", "barrier", "limit", "failcnt");
-}
-
-static int bc_res_show(struct seq_file *f, void *v)
-{
-	struct nsproxy *nsproxy = (struct nsproxy *)f->private;
-
-	__show_resources(f, nsproxy->net_ns->owner_ve, nsproxy, 0);
-	return 0;
-}
-
-static int bc_res_open(struct inode *inode, struct file *filp)
-{
-	struct ve_struct *ve;
-	struct nsproxy *nsproxy;
-	int res;
-
-	if (!(capable(CAP_DAC_OVERRIDE) && capable(CAP_DAC_READ_SEARCH)))
-		return -EACCES;
-
-	ve = get_ve_by_inode(inode);
-	if (!ve)
-		return -EINVAL;
-
-	nsproxy = get_nsproxy_by_ve(ve);
-	if (!nsproxy) {
-		put_ve(ve);
-		return -ENODEV;
-	}
-
-	res = single_open(filp, bc_res_show, nsproxy);
-	if (res) {
-		put_nsproxy(nsproxy);
-		put_ve(ve);
-		return res;
-	}
-
-	return 0;
-}
-
-static int bc_res_release(struct inode *inode, struct file *file)
-{
-	struct nsproxy *nsproxy = ((struct seq_file *)file->private_data)->private;
-	struct ve_struct *ve = nsproxy->net_ns->owner_ve;
-
-	put_nsproxy(nsproxy);
-	put_ve(ve);
-
-	return single_release(inode, file);
-}
-
-static struct file_operations resources_operations = {
-	.open		= bc_res_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= bc_res_release,
-};
-
-static void *ub_start(struct seq_file *f, loff_t *ppos)
-{
-	struct ve_struct *ve;
-	unsigned long pos;
-
-	pos = *ppos;
-	if (pos == 0)
-		ub_show_header(f);
-
-	mutex_lock(&ve_list_lock);
-	for_each_ve(ve) {
-		if (!ve_accessible(ve))
-			continue;
-		if (!get_ve(ve))
-			continue;
-		if (pos-- == 0)
-			return ve;
-		put_ve(ve);
-	}
-	mutex_unlock(&ve_list_lock);
-	return NULL;
-}
-
-static void *ub_next(struct seq_file *f, void *v, loff_t *ppos)
-{
-	struct ve_struct *ve = (struct ve_struct *)v;
-
-	for_each_ve_continue(ve) {
-		if (!ve_accessible(ve))
-			continue;
-		if (!get_ve(ve))
-			continue;
-		(*ppos)++;
-		return ve;
-	}
-	return NULL;
-}
-
-static void ub_stop(struct seq_file *f, void *v)
-{
-	struct ve_struct *ve = (struct ve_struct *)v;
-
-	mutex_unlock(&ve_list_lock);
-	put_ve(ve);
-}
-
-static struct seq_operations all_res_seq_ops = {
-	.start = ub_start,
-	.next  = ub_next,
-	.stop  = ub_stop,
-	.show  = res_show,
-};
-
-static int all_res_open(struct inode *inode, struct file *filp)
-{
-	if (!(capable(CAP_DAC_OVERRIDE) && capable(CAP_DAC_READ_SEARCH)))
-		return -EACCES;
-
-	return seq_open(filp, &all_res_seq_ops);
-}
-
-static struct file_operations all_resources_operations = {
-	.open		= all_res_open,
-	.read		= seq_read,
-	.llseek		= seq_lseek,
-	.release	= seq_release,
-};
-
-void ub_proc_ve_resources_remove(struct ve_struct *ve)
-{
-	remove_proc_entry("resources", ve->ub_proc);
-}
-
-static void ub_ve_resources_init(struct ve_struct *ve)
-{
-	int r;
-	struct ubparm *p;
-
-	for (r = 0, p = &ve->ub_parms[0]; r < UB_RESOURCES; r++, p++)
-		p->barrier = p->limit = UB_MAXVALUE;
-}
-
-int ub_proc_ve_resources_create(struct ve_struct *ve)
-{
-	ub_ve_resources_init(ve);
-
-	if (!proc_create_data("resources", S_IRUSR|S_ISVTX,
-				ve->ub_proc, &resources_operations,
-				ve_to_pde(ve)))
-		return -ENOMEM;
-	return 0;
-}
-
-int ub_proc_all_resources_create(void)
-{
-	if (!proc_create("resources", S_IRUSR|S_ISVTX,
-			 bc_proc_root, &all_resources_operations))
-		return -ENOMEM;
-	return 0;
-}