The commit is pushed to "branch-rh7-3.10.0-123.1.2-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git after rh7-3.10.0-123.1.2.vz7.4.9 ------> commit e72e1777eb631b77c97358f821d733d93349b8b6 Author: Dmitry Monakhov <dmonak...@openvz.org> Date: Tue May 5 13:44:35 2015 +0400
vziolimit: port diff-iolimit-vzctl-api iolimit: vzctl ioctl interface Implement iolimit control block allocation, add get and set ioctl. Signed-off-by: Konstantin Khlebnikov <khlebni...@openvz.org> ==================================== https://jira.sw.ru/browse/PSBM-20104 Signed-off-by: Dmitry Monakhov <dmonak...@openvz.org> --- include/linux/vziolimit.h | 10 +++++++ kernel/ve/vziolimit.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/include/linux/vziolimit.h b/include/linux/vziolimit.h index a017b0f..5af8c04 100644 --- a/include/linux/vziolimit.h +++ b/include/linux/vziolimit.h @@ -14,4 +14,14 @@ #define VZIOLIMITTYPE 'I' +struct iolimit_state { + unsigned int id; + unsigned int speed; + unsigned int burst; + unsigned int latency; +}; + +#define VZCTL_SET_IOLIMIT _IOW(VZIOLIMITTYPE, 0, struct iolimit_state) +#define VZCTL_GET_IOLIMIT _IOR(VZIOLIMITTYPE, 1, struct iolimit_state) + #endif /* _LINUX_VZIOLIMIT_H */ diff --git a/kernel/ve/vziolimit.c b/kernel/ve/vziolimit.c index 949d1a6..ac5abcd 100644 --- a/kernel/ve/vziolimit.c +++ b/kernel/ve/vziolimit.c @@ -11,6 +11,7 @@ #include <linux/virtinfo.h> #include <linux/vzctl.h> #include <linux/vziolimit.h> +#include <asm/uaccess.h> #include <bc/beancounter.h> struct throttle { @@ -132,6 +133,73 @@ static struct vnotifier_block iolimit_virtinfo_nb = { static int iolimit_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { + struct user_beancounter *ub; + struct iolimit *iolimit, *new_iolimit = NULL; + struct iolimit_state state; + int err; + + if (cmd != VZCTL_SET_IOLIMIT && cmd != VZCTL_GET_IOLIMIT) + return -ENOTTY; + + if (copy_from_user(&state, (void __user *)arg, sizeof(state))) + return -EFAULT; + + ub = get_beancounter_byuid(state.id, 0); + if (!ub) + return -ENOENT; + + iolimit = ub->private_data2; + + switch (cmd) { + case VZCTL_SET_IOLIMIT: + if (!iolimit) { + new_iolimit = kmalloc(sizeof(struct iolimit), GFP_KERNEL); + err = -ENOMEM; + if (!new_iolimit) + break; + } + + spin_lock_irq(&ub->ub_lock); + + if (!iolimit && ub->private_data2) { + kfree(new_iolimit); + iolimit = ub->private_data2; + } else if (!iolimit) + iolimit = new_iolimit; + + throttle_setup(&iolimit->throttle, state.speed, + state.burst, state.latency); + + if (!ub->private_data2) + ub->private_data2 = iolimit; + + spin_unlock_irq(&ub->ub_lock); + + err = 0; + break; + case VZCTL_GET_IOLIMIT: + err = -ENXIO; + if (!iolimit) + break; + + spin_lock_irq(&ub->ub_lock); + state.speed = iolimit->throttle.speed; + state.burst = iolimit->throttle.burst; + state.latency = jiffies_to_msecs(iolimit->throttle.latency); + spin_unlock_irq(&ub->ub_lock); + + err = -EFAULT; + if (copy_to_user((void __user *)arg, &state, sizeof(state))) + break; + + err = 0; + break; + default: + err = -ENOTTY; + } + + put_beancounter(ub); + return err; } static struct vzioctlinfo iolimit_vzioctl = { _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel