#ifndef _LVE_CGROUP_LIB_H_ #define _LVE_CGROUP_LIB_H_ #include #include "lve_kmod_c.h" struct cgroup; struct vfsmount; enum subsys_id { CPU_SUBSYS = 0, MEM_SUBSYS = 1, BLK_SUBSYS = 2, FREEZER_SUBSYS = 3, PIDS_SUBSYS = 4, NETMARK_SUBSYS = 5, #if OPENVZ_VERSION > 0 /* must last */ UB_SUBSYS, #endif NR_SUBSYS, }; #if OPENVZ_VERSION == 0 #define CGROUPS_SUPPORTED 0xFF #elif RHEL_MAJOR == 7 #define CGROUPS_SUPPORTED (BIT(CPU_SUBSYS) | BIT(FREEZER_SUBSYS) | \ BIT(NETMARK_SUBSYS)) #else #error "please define supported version" #endif #define RESOURCE_SUBSYS_MASK (BIT(PIDS_SUBSYS) | BIT(MEM_SUBSYS) | \ BIT(NETMARK_SUBSYS)) enum lve_cgroup_open_flags { LVE_CGRP_CREAT = 0x0001, /* create if not found */ LVE_CGRP_EXCL = 0x0002, /* fail if already exist */ }; static inline int get_flags(void) { #ifndef LVE_PER_VE return LVE_CGRP_CREAT; #else return 0; #endif } struct cgrp_mount { struct vfsmount *mnt_root; struct dentry *cgrp_root; }; extern struct cgrp_mount cmnt[NR_SUBSYS]; struct params { const char *p_name; unsigned p_subsys; }; struct lvp_private { struct dentry *lve_root[NR_SUBSYS]; }; enum param_id { PARAM_CPU_STAT = 0, PARAM_CPU_LIMIT, PARAM_CPU_CHWT, PARAM_CPU_ENTER, PARAM_CPU_THROTTLE, PARAM_PIDS_ENTER, #ifdef HAVE_PIDS_CGRP PARAM_PIDS_LIMIT, PARAM_PIDS_CURRENT, PARAM_PIDS_EVENTS, #endif PARAM_FREEZER_ENTER, PARAM_MEM_ENTER, PARAM_MEM_LIMIT, PARAM_MEM_STAT, PARAM_MEM_ANON_STAT, PARAM_MEM_FAILCNT, PARAM_BLK_ENTER, PARAM_NETMARK_ENTER, PARAM_NETMARK_MARK, PARAM_FILP_MAX }; /* connected to each creates context / LVE */ struct c_private { #if OPENVZ_VERSION > 0 struct user_beancounter *lve_ub; #endif struct dentry *cgrp[NR_SUBSYS]; struct file *filps[PARAM_FILP_MAX]; unsigned long unlink_id; int flags; }; /* we can't use an container_of macro due type check error */ #define os_lve(cp) ((struct light_ve *)( (char *)(cp) - \ offsetof(struct light_ve ,lve_private) )) extern struct cgrp_mount cmnt[NR_SUBSYS]; #define MAX_GRP_NAMESZ 25 #define UNLINK_FORMAT "rmv-%lu" #ifdef LVE_PER_VE #define LVP_FMT "%u" #else #define LVP_FMT "lvp%u" #endif #define LVE_PREFIX "lve" #define LVE_FMT LVE_PREFIX "%u" #define IS_LVE_NAME(s) (!strncmp(s, LVE_PREFIX, sizeof(LVE_PREFIX) - 1)) unsigned long get_unlink_id(void); int cgrp_obfuscate(struct dentry *cgrp, char *unlink_name); int mount_cgroup_root_fs(struct cgrp_mount *cmnt, u64 supported); void umount_cgroup_root_fs(struct cgrp_mount *cmnt); extern u64 ioprio_weight[]; struct file *cgrp_param_open(struct vfsmount *vfsmnt, struct dentry *grp, const char *param); void cgrp_param_release(struct file *filp); int cgrp_param_set_u64(struct file *filp, __u64 data); int cgrp_param_set_s64(struct file *filp, s64 data); int cgrp_param_set_string(struct file *filp, const char *buf, size_t nbytes); int cgrp_populate_dir(struct dentry **cgrp, struct file **filp, const struct params *p, int nr_params); /* return <0 if error */ __s64 cgrp_param_get(struct file *filp); int cgrp_param_get_string(struct file *filp, char *buf, size_t nbytes); int cgrp_param_open_write_string(struct vfsmount *mnt, struct dentry *cgrp, const char *param, const char *buf, unsigned count); int cgrp_param_open_read_string(struct vfsmount *mnt, struct dentry *cgrp, const char *param, char *buf, unsigned count); struct dentry *lve_cgroup_kernel_open(struct dentry *parent, enum lve_cgroup_open_flags flags, const char *name); int lve_cgroup_kernel_remove(struct dentry *cgrp); void lve_cgroup_kernel_close(struct dentry *cgrp); static inline struct cgroup *__d_cgrp(struct dentry *dentry) { return dentry ? dentry->d_fsdata : NULL; } struct dentry *lve_cgroup_get_root(struct vfsmount *mnt); static inline bool lve_cgroup_is_root(struct dentry *d) { return d == d->d_parent; } #endif