X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=kernel%2Fvserver%2Fcvirt.c;h=00a3a6a908f8d02e4ac92af2cc904d79e5e530a2;hb=refs%2Fheads%2Fvserver;hp=21bd0bd0793b660f1d13c765130e60c60cdc67b6;hpb=6a77f38946aaee1cd85eeec6cf4229b204c15071;p=linux-2.6.git diff --git a/kernel/vserver/cvirt.c b/kernel/vserver/cvirt.c index 21bd0bd07..00a3a6a90 100644 --- a/kernel/vserver/cvirt.c +++ b/kernel/vserver/cvirt.c @@ -3,18 +3,21 @@ * * Virtual Server: Context Virtualization * - * Copyright (C) 2004-2005 Herbert Pötzl + * Copyright (C) 2004-2007 Herbert Pötzl * * V0.01 broken out from limit.c + * V0.02 added utsname stuff + * V0.03 changed vcmds to vxi arg * */ -#include #include +#include #include #include #include #include +#include #include #include @@ -66,8 +69,9 @@ void vx_update_load(struct vx_info *vxi) uint32_t now, last, delta; unsigned int nr_running, nr_uninterruptible; unsigned int total; + unsigned long flags; - spin_lock(&vxi->cvirt.load_lock); + spin_lock_irqsave(&vxi->cvirt.load_lock, flags); now = jiffies; last = vxi->cvirt.load_last; @@ -90,7 +94,7 @@ void vx_update_load(struct vx_info *vxi) vxi->cvirt.load_last = now; out: atomic_inc(&vxi->cvirt.load_updates); - spin_unlock(&vxi->cvirt.load_lock); + spin_unlock_irqrestore(&vxi->cvirt.load_lock, flags); } @@ -134,22 +138,11 @@ int vx_do_syslog(int type, char __user *buf, int len) break; case 4: /* Read/clear last kernel messages */ do_clear = 1; - /* FALL THRU */ + /* fall through */ case 3: /* Read last kernel messages */ - // if (count > log_buf_len) - // count = log_buf_len; - spin_lock_irq(&log->logbuf_lock); - // if (count > logged_chars) - // count = logged_chars; - // if (do_clear) - // logged_chars = 0; - spin_unlock_irq(&log->logbuf_lock); - if (error) - break; return 0; case 5: /* Clear ring buffer */ - // logged_chars = 0; return 0; case 6: /* Disable logging to console */ @@ -168,3 +161,144 @@ int vx_do_syslog(int type, char __user *buf, int len) return error; } + +/* virtual host info names */ + +static char * vx_vhi_name(struct vx_info *vxi, int id) +{ + struct nsproxy *nsproxy; + struct uts_namespace *uts; + + + if (id == VHIN_CONTEXT) + return vxi->vx_name; + + nsproxy = vxi->vx_nsproxy; + if (!nsproxy) + return NULL; + + uts = nsproxy->uts_ns; + if (!uts) + return NULL; + + switch (id) { + case VHIN_SYSNAME: + return uts->name.sysname; + case VHIN_NODENAME: + return uts->name.nodename; + case VHIN_RELEASE: + return uts->name.release; + case VHIN_VERSION: + return uts->name.version; + case VHIN_MACHINE: + return uts->name.machine; + case VHIN_DOMAINNAME: + return uts->name.domainname; + default: + return NULL; + } + return NULL; +} + +int vc_set_vhi_name(struct vx_info *vxi, void __user *data) +{ + struct vcmd_vhi_name_v0 vc_data; + char *name; + + if (copy_from_user (&vc_data, data, sizeof(vc_data))) + return -EFAULT; + + name = vx_vhi_name(vxi, vc_data.field); + if (!name) + return -EINVAL; + + memcpy(name, vc_data.name, 65); + return 0; +} + +int vc_get_vhi_name(struct vx_info *vxi, void __user *data) +{ + struct vcmd_vhi_name_v0 vc_data; + char *name; + + if (copy_from_user (&vc_data, data, sizeof(vc_data))) + return -EFAULT; + + name = vx_vhi_name(vxi, vc_data.field); + if (!name) + return -EINVAL; + + memcpy(vc_data.name, name, 65); + if (copy_to_user (data, &vc_data, sizeof(vc_data))) + return -EFAULT; + return 0; +} + + +int vc_virt_stat(struct vx_info *vxi, void __user *data) +{ + struct vcmd_virt_stat_v0 vc_data; + struct _vx_cvirt *cvirt = &vxi->cvirt; + struct timespec uptime; + + do_posix_clock_monotonic_gettime(&uptime); + set_normalized_timespec(&uptime, + uptime.tv_sec - cvirt->bias_uptime.tv_sec, + uptime.tv_nsec - cvirt->bias_uptime.tv_nsec); + + vc_data.offset = timeval_to_ns(&cvirt->bias_tv); + vc_data.uptime = timespec_to_ns(&uptime); + vc_data.nr_threads = atomic_read(&cvirt->nr_threads); + vc_data.nr_running = atomic_read(&cvirt->nr_running); + vc_data.nr_uninterruptible = atomic_read(&cvirt->nr_uninterruptible); + vc_data.nr_onhold = atomic_read(&cvirt->nr_onhold); + vc_data.nr_forks = atomic_read(&cvirt->total_forks); + vc_data.load[0] = cvirt->load[0]; + vc_data.load[1] = cvirt->load[1]; + vc_data.load[2] = cvirt->load[2]; + + if (copy_to_user (data, &vc_data, sizeof(vc_data))) + return -EFAULT; + return 0; +} + + +#ifdef CONFIG_VSERVER_VTIME + +/* virtualized time base */ + +void vx_gettimeofday(struct timeval *tv) +{ + do_gettimeofday(tv); + if (!vx_flags(VXF_VIRT_TIME, 0)) + return; + + tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec; + tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec; + + if (tv->tv_usec >= USEC_PER_SEC) { + tv->tv_sec++; + tv->tv_usec -= USEC_PER_SEC; + } else if (tv->tv_usec < 0) { + tv->tv_sec--; + tv->tv_usec += USEC_PER_SEC; + } +} + +int vx_settimeofday(struct timespec *ts) +{ + struct timeval tv; + + if (!vx_flags(VXF_VIRT_TIME, 0)) + return do_settimeofday(ts); + + do_gettimeofday(&tv); + current->vx_info->cvirt.bias_tv.tv_sec = + ts->tv_sec - tv.tv_sec; + current->vx_info->cvirt.bias_tv.tv_usec = + (ts->tv_nsec/NSEC_PER_USEC) - tv.tv_usec; + return 0; +} + +#endif +