[Devel] [PATCH rh7] ve: Kill ve_list_head and ve_struct::ve_list

Kirill Tkhai ktkhai at odin.com
Fri Oct 2 06:35:32 PDT 2015


ping

On 24.09.2015 18:11, Kirill Tkhai wrote:
> Since we use ve_idr layer to reserve a id for a ve,
> and since a ve is linked there, using of ve_list_head
> just for linking VEs becomes redundant.
> 
> This patch replaces ve_list_head in the places, we iterate
> thru VEs list, with ve_idr mechanish, and kills the
> duplicate manner.
> 
> Signed-off-by: Kirill Tkhai <ktkhai at odin.com>
> ---
>  include/linux/ve.h       |    2 --
>  include/linux/ve_proto.h |    3 +--
>  kernel/ve/ve.c           |   10 +++-------
>  kernel/ve/vecalls.c      |   38 +++++++++++++++-----------------------
>  kernel/ve/vzlist.c       |    4 ++--
>  kernel/ve/vzstat.c       |    4 +++-
>  scripts/kconfig/conf     |  Bin
>  6 files changed, 24 insertions(+), 37 deletions(-)
> 
> diff --git a/include/linux/ve.h b/include/linux/ve.h
> index 10c150a..54091a1 100644
> --- a/include/linux/ve.h
> +++ b/include/linux/ve.h
> @@ -37,8 +37,6 @@ struct ve_struct {
>  
>  	const char		*ve_name;
>  
> -	struct list_head	ve_list;
> -
>  	envid_t			veid;
>  	bool			legacy;	/* created using the legacy API
>  					   (vzctl ioctl - see do_env_create) */
> diff --git a/include/linux/ve_proto.h b/include/linux/ve_proto.h
> index 0f5898e..d67341e 100644
> --- a/include/linux/ve_proto.h
> +++ b/include/linux/ve_proto.h
> @@ -49,10 +49,9 @@ void vzmon_unregister_veaddr_print_cb(ve_seq_print_t);
>  int venet_init(void);
>  #endif
>  
> -extern struct list_head ve_list_head;
> -#define for_each_ve(ve)	list_for_each_entry((ve), &ve_list_head, ve_list)
>  extern struct mutex ve_list_lock;
>  extern struct ve_struct *get_ve_by_id(envid_t);
> +extern struct idr ve_idr;
>  extern struct cgroup *ve_cgroup_open(struct cgroup *root, int flags, envid_t veid);
>  extern int ve_cgroup_remove(struct cgroup *root, envid_t veid);
>  
> diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
> index aff3b03..5f6896f 100644
> --- a/kernel/ve/ve.c
> +++ b/kernel/ve/ve.c
> @@ -85,7 +85,6 @@ struct ve_struct ve0 = {
>  };
>  EXPORT_SYMBOL(ve0);
>  
> -LIST_HEAD(ve_list_head);
>  DEFINE_MUTEX(ve_list_lock);
>  
>  int nr_ve = 1;	/* One VE always exists. Compatibility with vestat */
> @@ -94,7 +93,7 @@ EXPORT_SYMBOL(nr_ve);
>  int vz_compat;
>  EXPORT_SYMBOL(vz_compat);
>  
> -static DEFINE_IDR(ve_idr);
> +DEFINE_IDR(ve_idr);
>  
>  static int __init vz_compat_setup(char *arg)
>  {
> @@ -129,7 +128,6 @@ static int ve_list_add(struct ve_struct *ve)
>  			err = -EEXIST;
>  		goto out;
>  	}
> -	list_add(&ve->ve_list, &ve_list_head);
>  	nr_ve++;
>  	err = 0;
>  out:
> @@ -141,7 +139,6 @@ static void ve_list_del(struct ve_struct *ve)
>  {
>  	mutex_lock(&ve_list_lock);
>  	idr_remove(&ve_idr, ve->veid);
> -	list_del_init(&ve->ve_list);
>  	nr_ve--;
>  	mutex_unlock(&ve_list_lock);
>  }
> @@ -194,7 +191,7 @@ struct ve_struct *get_ve_by_id(envid_t veid)
>  EXPORT_SYMBOL(get_ve_by_id);
>  
>  EXPORT_SYMBOL(ve_list_lock);
> -EXPORT_SYMBOL(ve_list_head);
> +EXPORT_SYMBOL(ve_idr);
>  
>  int vz_security_family_check(struct net *net, int family)
>  {
> @@ -627,7 +624,6 @@ static struct cgroup_subsys_state *ve_create(struct cgroup *cg)
>  	init_rwsem(&ve->op_sem);
>  	mutex_init(&ve->sync_mutex);
>  	INIT_LIST_HEAD(&ve->devices);
> -	INIT_LIST_HEAD(&ve->ve_list);
>  	INIT_LIST_HEAD(&ve->devmnt_list);
>  	mutex_init(&ve->devmnt_mutex);
>  	kmapset_init_key(&ve->ve_sysfs_perms);
> @@ -1201,7 +1197,7 @@ EXPORT_SYMBOL(ve_subsys);
>  static int __init ve_subsys_init(void)
>  {
>  	ve_cachep = KMEM_CACHE(ve_struct, SLAB_PANIC);
> -	list_add(&ve0.ve_list, &ve_list_head);
> +	WARN_ON(idr_alloc(&ve_idr, &ve0, 0, 1, GFP_KERNEL) < 0);
>  	return 0;
>  }
>  late_initcall(ve_subsys_init);
> diff --git a/kernel/ve/vecalls.c b/kernel/ve/vecalls.c
> index 9e86615..48c64d2 100644
> --- a/kernel/ve/vecalls.c
> +++ b/kernel/ve/vecalls.c
> @@ -713,8 +713,7 @@ int real_ve_dev_map(envid_t veid, int op, char *dev_name)
>  
>  static int vestat_seq_show(struct seq_file *m, void *v)
>  {
> -	struct list_head *entry;
> -	struct ve_struct *ve;
> +	struct ve_struct *ve = v;
>  	struct ve_struct *curve;
>  	int ret;
>  	unsigned long user_ve, nice_ve, system_ve;
> @@ -722,11 +721,8 @@ static int vestat_seq_show(struct seq_file *m, void *v)
>  	u64 uptime_cycles, idle_time, strv_time, used;
>  	struct kernel_cpustat kstat;
>  
> -	entry = (struct list_head *)v;
> -	ve = list_entry(entry, struct ve_struct, ve_list);
> -
>  	curve = get_exec_env();
> -	if (entry == ve_list_head.next ||
> +	if (ve == get_ve0() ||
>  	    (!ve_is_super(curve) && ve == curve)) {
>  		/* print header */
>  		seq_printf(m, "%-*s\n",
> @@ -772,26 +768,24 @@ static int vestat_seq_show(struct seq_file *m, void *v)
>  
>  void *ve_seq_start(struct seq_file *m, loff_t *pos)
>  {
> -	struct ve_struct *curve;
> -
> -	curve = get_exec_env();
>  	mutex_lock(&ve_list_lock);
> -	if (!ve_is_super(curve)) {
> -		if (*pos != 0)
> -			return NULL;
> -		return &curve->ve_list;
> -	}
>  
> -	return seq_list_start(&ve_list_head, *pos);
> +	return ve_seq_next(m, NULL, pos);
>  }
>  EXPORT_SYMBOL(ve_seq_start);
>  
>  void *ve_seq_next(struct seq_file *m, void *v, loff_t *pos)
>  {
> -	if (!ve_is_super(get_exec_env()))
> -		return NULL;
> -	else
> -		return seq_list_next(v, &ve_list_head, pos);
> +	struct ve_struct *ve = get_exec_env();
> +	int id = *pos;
> +
> +	if (!ve_is_super(ve))
> +		return *pos ? NULL : ve;
> +
> +	ve = idr_get_next(&ve_idr, &id);
> +	*pos = id + 1;
> +
> +	return ve;
>  }
>  EXPORT_SYMBOL(ve_seq_next);
>  
> @@ -822,7 +816,7 @@ static struct file_operations proc_vestat_operations = {
>  
>  static int devperms_seq_show(struct seq_file *m, void *v)
>  {
> -	struct ve_struct *ve = list_entry(v, struct ve_struct, ve_list);
> +	struct ve_struct *ve = v;
>  
>  	if (m->private == (void *)0) {
>  		seq_printf(m, "Version: 2.7\n");
> @@ -894,10 +888,8 @@ EXPORT_SYMBOL(vzmon_unregister_veaddr_print_cb);
>  
>  static int veinfo_seq_show(struct seq_file *m, void *v)
>  {
> -	struct ve_struct *ve;
>  	ve_seq_print_t veaddr_seq_print;
> -
> -	ve = list_entry((struct list_head *)v, struct ve_struct, ve_list);
> +	struct ve_struct *ve = v;
>  
>  	seq_printf(m, "%10s %5u %5u", ve_name(ve), ve->class_id, nr_threads_ve(ve));
>  
> diff --git a/kernel/ve/vzlist.c b/kernel/ve/vzlist.c
> index 31362ea..39966eb 100644
> --- a/kernel/ve/vzlist.c
> +++ b/kernel/ve/vzlist.c
> @@ -25,7 +25,7 @@ static DEFINE_SEMAPHORE(vzlist_sem);
>  static int get_veids(struct vzlist_veidctl *s)
>  {
>  	int ret;
> -	int ves;
> +	int ves, id;
>  	unsigned long size;
>  	envid_t *buf;
>  	struct ve_struct *ve;
> @@ -44,7 +44,7 @@ static int get_veids(struct vzlist_veidctl *s)
>  
>  	ves = 0;
>  	mutex_lock(&ve_list_lock);
> -	for_each_ve(ve) {
> +	idr_for_each_entry(&ve_idr, ve, id) {
>  		if (size >= (ves + 1)*sizeof(envid_t))
>  			buf[ves] = ve->veid;
>  		ves++;
> diff --git a/kernel/ve/vzstat.c b/kernel/ve/vzstat.c
> index 650010d..1382763 100644
> --- a/kernel/ve/vzstat.c
> +++ b/kernel/ve/vzstat.c
> @@ -302,12 +302,14 @@ static void mem_avg_show(struct seq_file *m, void *v)
>  static void update_venum(void)
>  {
>  	struct ve_struct *ve;
> +	int id;
>  
>  	mutex_lock(&ve_list_lock);
>  	spin_lock_irq(&kstat_glb_lock);
> -	for_each_ve(ve)
> +	idr_for_each_entry(&ve_idr, ve, id) {
>  		/* max_snap is already set in update_schedule_latency */
>  		KSTAT_LAT_PCPU_UPDATE(&ve->sched_lat_ve);
> +	}
>  	spin_unlock_irq(&kstat_glb_lock);
>  	mutex_unlock(&ve_list_lock);
>  }
> _______________________________________________
> Devel mailing list
> Devel at openvz.org
> https://lists.openvz.org/mailman/listinfo/devel
> 



More information about the Devel mailing list