From owner-svn-src-projects@FreeBSD.ORG Wed Oct 23 17:04:11 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id A9954477; Wed, 23 Oct 2013 17:04:11 +0000 (UTC) (envelope-from will@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 9649D2E02; Wed, 23 Oct 2013 17:04:11 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9NH4B5X060936; Wed, 23 Oct 2013 17:04:11 GMT (envelope-from will@svn.freebsd.org) Received: (from will@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9NH49hs060921; Wed, 23 Oct 2013 17:04:09 GMT (envelope-from will@svn.freebsd.org) Message-Id: <201310231704.r9NH49hs060921@svn.freebsd.org> From: Will Andrews Date: Wed, 23 Oct 2013 17:04:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r256987 - in projects/vps/sys: kern vps X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Oct 2013 17:04:11 -0000 Author: will Date: Wed Oct 23 17:04:09 2013 New Revision: 256987 URL: http://svnweb.freebsd.org/changeset/base/256987 Log: Sync with svn.7he.at/vps/trunk r189. r189 | klaus | 2013-07-12 01:15:07 -0600 (Fri, 12 Jul 2013) | 3 lines Style and other minor changes. Submitted by: Klaus P. Ohrhallinger Modified: projects/vps/sys/kern/kern_umtx.c projects/vps/sys/vps/if_vps.c projects/vps/sys/vps/vps.h projects/vps/sys/vps/vps2.h projects/vps/sys/vps/vps_account.c projects/vps/sys/vps/vps_account.h projects/vps/sys/vps/vps_console.c projects/vps/sys/vps/vps_core.c projects/vps/sys/vps/vps_ddb.c projects/vps/sys/vps/vps_dev.c projects/vps/sys/vps/vps_libdump.c projects/vps/sys/vps/vps_pager.c projects/vps/sys/vps/vps_priv.c projects/vps/sys/vps/vps_restore.c projects/vps/sys/vps/vps_snapst.c projects/vps/sys/vps/vps_snapst.h projects/vps/sys/vps/vps_suspend.c projects/vps/sys/vps/vps_user.c projects/vps/sys/vps/vps_user.h Modified: projects/vps/sys/kern/kern_umtx.c ============================================================================== --- projects/vps/sys/kern/kern_umtx.c Wed Oct 23 16:59:00 2013 (r256986) +++ projects/vps/sys/kern/kern_umtx.c Wed Oct 23 17:04:09 2013 (r256987) @@ -50,6 +50,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include + #include #include #include @@ -3778,7 +3780,6 @@ umtx_thread_cleanup(struct thread *td) * VPS stuff */ -int vps_umtx_snapshot(struct thread *td); int vps_umtx_snapshot(struct thread *td) { Modified: projects/vps/sys/vps/if_vps.c ============================================================================== --- projects/vps/sys/vps/if_vps.c Wed Oct 23 16:59:00 2013 (r256986) +++ projects/vps/sys/vps/if_vps.c Wed Oct 23 17:04:09 2013 (r256987) @@ -126,12 +126,6 @@ static int vps_if_clone_match(struct if_ static int vps_if_clone_create(struct if_clone *, char *, size_t, caddr_t); static int vps_if_clone_destroy(struct if_clone *, struct ifnet *); -/* -delete -static struct if_clone vps_if_cloner = IFC_CLONE_INITIALIZER( - IFNAME, NULL, IF_MAXUNIT, - NULL, vps_if_clone_match, vps_if_clone_create, vps_if_clone_destroy); -*/ static struct if_clone *vps_if_cloner; #ifdef VIMAGE static VNET_DEFINE(struct if_clone *, vps_if_cloner); @@ -400,11 +394,15 @@ static struct ifnet * vps_if_get_if_by_addr_v4(const struct sockaddr *dst, struct mbuf *m) { struct vps_if_rtentry *vrt; + struct ifnet *ifp; vrt = vps_if_lookup(dst); if (vrt == NULL) { /* Nothing found, so use the default (first) interface. */ - return ((TAILQ_FIRST(&vps_if_head))->ifp); + mtx_lock(&vps_if_mtx); + ifp = TAILQ_FIRST(&vps_if_head)->ifp; + mtx_unlock(&vps_if_mtx); + return (ifp); } return (vrt->rt_ifp); @@ -433,8 +431,6 @@ vps_if_output(struct ifnet *ifp, struct struct vps_if_softc *sc; int isr; - /* LOCK allvpsif read lock */ - switch (dst->sa_family) { case AF_INET: oifp = vps_if_get_if_by_addr_v4(dst, m); @@ -445,14 +441,12 @@ vps_if_output(struct ifnet *ifp, struct default: DBGIF("%s: af=%d unexpected\n", __func__, dst->sa_family); m_freem(m); - /* LOCK allvpsif read unlock */ return (EAFNOSUPPORT); } if (oifp == NULL) { ifp->if_oerrors++; m_freem(m); - /* LOCK allvpsif read unlock */ return (EHOSTUNREACH); } sc = ifp->if_softc; @@ -465,7 +459,6 @@ vps_if_output(struct ifnet *ifp, struct (oifp->if_flags & IFF_UP) == 0) { ifp->if_oerrors++; m_freem(m); - /* LOCK allvpsif read unlock */ return (EHOSTUNREACH); } @@ -474,7 +467,6 @@ vps_if_output(struct ifnet *ifp, struct DBGIF("%s: LOOP ! oifp == ifp == %p\n", __func__, ifp); ifp->if_oerrors++; m_freem(m); - /* LOCK allvpsif read unlock */ return (EHOSTUNREACH); } @@ -502,7 +494,6 @@ vps_if_output(struct ifnet *ifp, struct } refcount_acquire(&sc->refcount); - /* LOCK allvpsif read unlock */ m->m_pkthdr.rcvif = oifp; KASSERT(m->m_pkthdr.rcvif->if_dname[0] == 'v', ("%s: m->m_pkthdr.rcvif->if_dname = [%s]\n", @@ -519,23 +510,6 @@ vps_if_output(struct ifnet *ifp, struct return (error); } -#ifdef DISABLED__VIMAGE -static void -vps_if_reassign(struct ifnet *ifp, struct vnet *vnet, char *dname) -{ - - if_detach(ifp); - ifp->if_bpf = NULL; - if_reassign_common(ifp, vnet, "eth"); - if (dname) - snprintf(ifp->if_xname, IFNAMSIZ, "%s", dname); - - CURVNET_SET_QUIET(vnet); - if_attach(ifp); - CURVNET_RESTORE(); -} -#endif - static void vps_if_ioctl2(u_long cmd, caddr_t data, struct ifnet *ifp, struct thread *td) @@ -774,14 +748,14 @@ vps_if_clone_create(struct if_clone *ifc { int tmpticks = ticks; - memcpy(&ll[0], &curthread->td_vps, 0); + memcpy(&ll[0], &curthread->td_vps, 4); memcpy(&ll[4], &tmpticks, 4); } ifa = ifp->if_addr; KASSERT(ifa != NULL, ("%s: no lladdr!\n", __func__)); sdl = (struct sockaddr_dl *)ifa->ifa_addr; sdl->sdl_type = IFT_PROPVIRTUAL; - sdl->sdl_alen = sizeof (ll); + sdl->sdl_alen = sizeof(ll); bcopy(&ll, LLADDR(sdl), sdl->sdl_alen); mtx_lock(&vps_if_mtx); @@ -851,10 +825,6 @@ vps_modevent(module_t mod, int type, voi /* For now limit us to one global mutex and one inq. */ mtx_init(&vps_if_mtx, "if_vps", NULL, MTX_DEF); vps_if_inithead(); - /* - delete - if_clone_attach(&vps_if_cloner); - */ #ifndef VIMAGE vps_if_cloner = if_clone_advanced(IFNAME, 0, vps_if_clone_match, vps_if_clone_create, @@ -863,19 +833,10 @@ vps_modevent(module_t mod, int type, voi refcount_init(&vps_if_refcnt, 0); if (bootverbose) printf("%s initialized.\n", IFNAME); -#if 0 - printf("%s: SIOCSIFADDR=%08lx\n", __func__, SIOCSIFADDR); - printf("%s: SIOCDIFADDR=%08lx\n", __func__, SIOCDIFADDR); - printf("%s: SIOCAIFADDR=%08lx\n", __func__, SIOCAIFADDR); -#endif break; case MOD_UNLOAD: if (vps_if_refcnt > 0) return (EBUSY); - /* - delete - if_clone_detach(&vps_if_cloner); - */ #ifndef VIMAGE if_clone_detach(vps_if_cloner); #endif Modified: projects/vps/sys/vps/vps.h ============================================================================== --- projects/vps/sys/vps/vps.h Wed Oct 23 16:59:00 2013 (r256986) +++ projects/vps/sys/vps/vps.h Wed Oct 23 17:04:09 2013 (r256987) @@ -46,8 +46,6 @@ #define TD_TO_VPS(x) (x)->td_ucred->cr_vps #define P_TO_VPS(x) (x)->p_ucred->cr_vps -#define VPSYM(x) curthread->td_vps->_##x - /* * At least for now, just use vnet's facility for virtualized * global variables. Modified: projects/vps/sys/vps/vps2.h ============================================================================== --- projects/vps/sys/vps/vps2.h Wed Oct 23 16:59:00 2013 (r256986) +++ projects/vps/sys/vps/vps2.h Wed Oct 23 17:04:09 2013 (r256987) @@ -54,8 +54,6 @@ struct vps_acc; #define TD_TO_VPS(x) (x)->td_ucred->cr_vps #define P_TO_VPS(x) (x)->p_ucred->cr_vps -#define VPSYM(x) curthread->td_vps->_##x - LIST_HEAD(vps_list_head, vps); extern struct vps_list_head vps_head; @@ -70,84 +68,92 @@ struct vps_ref { #endif #ifdef DIAGNOSTIC + +#define VPSFUNC __attribute__((noinline)) #define DBGCORE if (vps_debug_core) printf extern int vps_debug_core; -#else + +#else /* ! DIAGNOSTIC */ + +#define VPSFUNC #define DBGCORE(x, ...) + #endif /* ! DIAGNOSTIC */ #ifdef VPS /* Keep in sync with ''struct vps2'' declared in vps/vps.h ! */ + struct vps { - struct vnet *vnet; - LIST_ENTRY(vps) vps_all; - LIST_ENTRY(vps) vps_sibling; - LIST_HEAD(, vps) vps_child_head; - struct vps *vps_parent; - - struct sx vps_lock; - char *vps_lock_name; - - u_int vps_id; - char vps_name[MAXHOSTNAMELEN]; - u_char vps_status; + struct vnet *vnet; + + LIST_ENTRY(vps) vps_all; + LIST_ENTRY(vps) vps_sibling; + LIST_HEAD(, vps) vps_child_head; + struct vps *vps_parent; + + struct sx vps_lock; + char *vps_lock_name; + + u_int vps_id; + char vps_name[MAXHOSTNAMELEN]; + u_char vps_status; - u_int vps_refcnt; - struct mtx vps_refcnt_lock; + u_int vps_refcnt; + struct mtx vps_refcnt_lock; #ifdef INVARIANTS TAILQ_HEAD(, vps_ref) vps_ref_head; #endif - /* - struct task vps_task; - */ - struct timeout_task vps_task; + struct timeout_task vps_task; - u_char priv_allow_set[PRIV_SET_SIZE]; - u_char priv_impl_set[PRIV_SET_SIZE]; + u_char priv_allow_set[PRIV_SET_SIZE]; + u_char priv_impl_set[PRIV_SET_SIZE]; - struct vps_arg_ip4 *vps_ip4; - struct vps_arg_ip6 *vps_ip6; - u_int16_t vps_ip4_cnt; - u_int16_t vps_ip6_cnt; + struct vps_arg_ip4 *vps_ip4; + struct vps_arg_ip6 *vps_ip6; + u_int16_t vps_ip4_cnt; + u_int16_t vps_ip6_cnt; - u_int vps_flags; + u_int vps_flags; - int restore_count; + int restore_count; - int64_t suspend_time; + int64_t suspend_time; - struct vps_acc *vps_acc; /* XXX do inline */ + struct vps_acc *vps_acc; /* XXX do inline */ - struct vnode *consolelog; - int consolelog_refcnt; - struct tty *console_tty; - struct file *console_fp_ma; - int console_flags; + struct vnode *consolelog; + struct tty *console_tty; + struct file *console_fp_ma; + int consolelog_refcnt; + int console_flags; - struct ucred *vps_ucred; + struct ucred *vps_ucred; - struct devfs_rule *devfs_ruleset; + struct devfs_rule *devfs_ruleset; - struct vnode *_rootvnode; - char _rootpath[MAXPATHLEN]; + struct vnode *_rootvnode; + char _rootpath[MAXPATHLEN]; }; -#define VPS_F_REBOOT 0x00000200 - struct vps_snapst_ctx; struct vps_dev_ctx { - LIST_ENTRY(vps_dev_ctx) list; - struct file *fp; - struct thread *td; - caddr_t data; - size_t length; - u_long cmd; - struct vps_snapst_ctx *snapst; + LIST_ENTRY(vps_dev_ctx) list; + struct file *fp; + struct thread *td; + caddr_t data; + size_t length; + u_long cmd; + struct vps_snapst_ctx *snapst; }; +struct devfs_mount; +struct cdev; +struct cdev_priv; +struct mount; + struct vps *vps_by_name(struct vps *, char *); struct vps *vps_alloc(struct vps *, struct vps_param *, char *, int *errorval); @@ -156,11 +162,7 @@ int vps_free_locked(struct vps *); int vps_destroy(struct vps *); void vps_ref(struct vps *, struct ucred *); void vps_deref(struct vps *, struct ucred *); -struct devfs_mount; -struct cdev; -struct cdev_priv; -struct mount; -int vps_canseemount (struct ucred *, struct mount *); +int vps_canseemount(struct ucred *, struct mount *); int vps_devfs_ruleset_create(struct vps *vps); int vps_devfs_ruleset_destroy(struct vps *vps); @@ -214,15 +216,16 @@ int vps_ioc_fscalcpath(struct vps *, str int vps_ioc_getconsfd(struct vps *, struct vps_dev_ctx *, u_long, caddr_t, int, struct thread *); -void vps_priv_setdefault(struct vps *, struct vps_param *); -int vps_priv_check(struct ucred *, int); +struct in_addr; +struct in6_addr; struct vps_arg_item; + +void vps_priv_setdefault(struct vps *, struct vps_param *); int vps_priv_setitem(struct vps *, struct vps *, struct vps_arg_item *); int vps_priv_getitemall(struct vps *, struct vps *, caddr_t, size_t *); int vps_ip_setitem(struct vps *, struct vps *, struct vps_arg_item *); int vps_ip_getitemall(struct vps *, struct vps *, caddr_t, size_t *); -struct in_addr; -struct in6_addr; +int vps_priv_check(struct ucred *, int); int vps_ip4_check(struct vps *, struct in_addr *, struct in_addr *); int vps_ip6_check(struct vps *, struct in6_addr *, u_int8_t); @@ -235,22 +238,28 @@ int vps_console_getfd(struct vps *, stru int vps_unmount_all(struct vps *vps); +int vps_umtx_snapshot(struct thread *td); + /* machdep stuff */ struct vps_dump_thread; struct execve_args; void vps_md_print_thread(struct thread *td); void vps_md_print_pcb(struct thread *td); int vps_md_snapshot_thread(struct vps_dump_thread *vdtd, struct thread *td); -int vps_md_restore_thread(struct vps_dump_thread *vdtd, struct thread *ntd, struct proc *p); +int vps_md_restore_thread(struct vps_dump_thread *vdtd, struct thread *ntd, + struct proc *p); int vps_md_snapshot_sysentvec(struct sysentvec *sv, long *svtype); int vps_md_restore_sysentvec(long svtype, struct sysentvec **sv); int vps_md_restore_checkarch(u_int8_t ptrsize, u_int8_t byteorder); -int vps_md_snapshot_thread_savefpu(struct vps_snapst_ctx *ctx, struct vps *vps, struct thread *td); -int vps_md_restore_thread_savefpu(struct vps_snapst_ctx *ctx, struct vps *vps, struct thread *td); +int vps_md_snapshot_thread_savefpu(struct vps_snapst_ctx *ctx, + struct vps *vps, struct thread *td); +int vps_md_restore_thread_savefpu(struct vps_snapst_ctx *ctx, + struct vps *vps, struct thread *td); int vps_md_reboot_copyout(struct thread *td, struct execve_args *); int vps_md_syscall_fixup(struct vps *, struct thread *, register_t *ret_code, register_t **ret_args, int *narg); -int vps_md_syscall_fixup_setup_inthread(struct vps *, struct thread *, register_t); +int vps_md_syscall_fixup_setup_inthread(struct vps *, struct thread *, + register_t); extern struct sx vps_all_lock; Modified: projects/vps/sys/vps/vps_account.c ============================================================================== --- projects/vps/sys/vps/vps_account.c Wed Oct 23 16:59:00 2013 (r256986) +++ projects/vps/sys/vps/vps_account.c Wed Oct 23 17:04:09 2013 (r256987) @@ -106,35 +106,27 @@ SYSCTL_INT(_debug, OID_AUTO, vps_account SYSCTL_NODE(, OID_AUTO, vps, CTLFLAG_RD, NULL, "Virtual Private Systems"); SYSCTL_NODE(_vps, OID_AUTO, acc, CTLFLAG_RD, NULL, "Limits and Accounting"); -/* -static VPS_DEFINE(size_t, acc_kmem) = 0; -#define V_acc_kmem VPS(acc_kmem) - -SYSCTL_VPS_UINT(_vps_acc, OID_AUTO, kmem, CTLFLAG_RD, - &VPS_NAME(acc_kmem), 0, ""); -*/ - /* Interval between calls to vps_account_threads() in microseconds. */ /* XXX determine a good default value */ static u_int vps_account_threads_interval = 100*1000; SYSCTL_UINT(_vps_acc, OID_AUTO, account_threads_interval, CTLFLAG_RW, - &vps_account_threads_interval, 0, - "Interval for thread accounting in microseconds"); + &vps_account_threads_interval, 0, + "Interval for thread accounting in microseconds"); -struct mtx vps_pfault_mtx; -struct rqhead vps_paused_threads_head; +struct mtx vps_pfault_mtx; +struct rqhead vps_paused_threads_head; -static u_int vps_account_suspensions; -static u_int vps_account_failedsuspensions; -struct sx vps_account_threads_sx; -struct mtx vps_account_pausedqueue_mtx; -struct task vps_account_threads_task; -static struct proc *vps_account_kproc_p; -static int vps_account_exit; - -static fixpt_t vps_account_cpu_idlepct; -static u_long vps_account_cpu_last; -static long vps_account_cpu_updated; +static u_int vps_account_suspensions; +static u_int vps_account_failedsuspensions; +struct sx vps_account_threads_sx; +struct mtx vps_account_pausedqueue_mtx; +struct task vps_account_threads_task; +static struct proc *vps_account_kproc_p; +static int vps_account_exit; + +static fixpt_t vps_account_cpu_idlepct; +static u_long vps_account_cpu_last; +static long vps_account_cpu_updated; static int _vps_account2(struct vps *, int, int, size_t); static void vps_account_check_threads(void); @@ -142,10 +134,6 @@ static void vps_account_thread_resume(st void vps_account_threads2(void *, int); void vps_account_kproc(void *); -/* -int (*vpsfs_calcusage_path_p)(const char *, struct vpsfs_limits *) = NULL; -*/ - int vps_account_init(void) { @@ -180,11 +168,6 @@ vps_account_init(void) return (0); } -/* -SYSINIT(vps_account, SI_SUB_RUN_SCHEDULER, SI_ORDER_ANY, - vps_account_init, NULL); -*/ - int vps_account_uninit(void) { @@ -280,11 +263,7 @@ _vps_account2(struct vps *vps, int type, case VPS_ACC_PROCS: val = &vps->vps_acc->procs; break; - /* not handled here - case VPS_ACC_PCTCPU: - val = &vps->vps_acc->pctcpu; - break; - */ + /* not handled here: VPS_ACC_PCTCPU: */ default: printf("%s: unkown type %d\n", __func__, type); return (ENOENT); @@ -293,13 +272,6 @@ _vps_account2(struct vps *vps, int type, mtx_lock_spin(&vps->vps_acc->lock); - /* - if (vps != vps0 && type==VPS_ACC_PHYS) - DBGACC("%s: pid=%d type=%d %zu %s %zu\n", - __func__, curthread->td_proc->p_pid, type, - val->cur, action==VPS_ACC_ALLOC ? "+" : "-", size); - */ - error = 0; switch (action) { @@ -339,16 +311,6 @@ _vps_account2(struct vps *vps, int type, break; } - /* - if (type == VPS_ACC_VIRT && vps != vps0) { - DBGACC("%s: VPS_ACC_VIRT: %s %lx --> %lx\n", - __func__, - action == VPS_ACC_ALLOC ? "ALLOC" : "FREE", - size, - val->cur); - } - */ - if (error == 0) val->updated = ticks; @@ -628,8 +590,8 @@ vps_account_threads(void *dummy) } PROC_UNLOCK(p); } - //sx_sunlock(&vps->_proctree_lock); sx_sunlock(&VPS_VPS(vps, allproc_lock)); + //sx_sunlock(&vps->_proctree_lock); mtx_lock_spin(&vps->vps_acc->lock); @@ -696,7 +658,7 @@ _vps_account_thread_pause(struct thread by thread_lock */ TAILQ_INSERT_TAIL(&vps_paused_threads_head, td, td_runq); mtx_unlock_spin(&vps_account_pausedqueue_mtx); - //DBGACC("%s: paused thread=%p/%d\n", __func__, td, td->td_tid); + /*DBGACC("%s: paused thread=%p/%d\n", __func__, td, td->td_tid);*/ } static void @@ -710,7 +672,7 @@ vps_account_thread_resume(struct thread mtx_unlock_spin(&vps_account_pausedqueue_mtx); sched_add(td, SRQ_BORING); - //DBGACC("%s: resumed thread=%p/%d\n", __func__, td, td->td_tid); + /*DBGACC("%s: resumed thread=%p/%d\n", __func__, td, td->td_tid);*/ } @@ -827,14 +789,6 @@ _vps_account_stats(struct vps *vps) printf("%s: vps=%p\n", __func__, vps); printf("%s: virt=%zu\n", __func__, va->virt.cur); printf("%s: phys=%zu\n", __func__, va->phys.cur); - /* - printf("%s: kmem=%zu (0-kmem=%zu)\n", __func__, - va->kmem.cur, 0 - va->kmem.cur); - printf("%s: kernel=%zu (0-kernel=%zu)\n", __func__, - va->kernel.cur, 0 - va->kernel.cur); - printf("%s: buffer=%zu (0-buffer=%zu)\n", __func__, - va->buffer.cur, 0 - va->buffer.cur); - */ printf("%s: pctcpu=%zu\n", __func__, va->pctcpu.cur); printf("%s: blockio=%zu\n", __func__, va->blockio.cur); printf("%s: threads=%zu\n", __func__, va->threads.cur); @@ -920,26 +874,24 @@ _vps_limit_setitem(struct vps *vpsp, str (x)->u.limit.hits_hard = (y)->hits_hard; \ } while (0); +#define ACC_ITEM_CNT 6 + int _vps_limit_getitemall(struct vps *vpsp, struct vps *vps, caddr_t kdata, size_t *kdatalen) { struct vps_arg_item *item; - int cnt; if (vps->vps_acc == NULL) { *kdatalen = 0; return (0); } - /* !!! */ - cnt = 6; - - if ((sizeof (*item) * cnt) > *kdatalen) + if ((sizeof(*item) * ACC_ITEM_CNT) > *kdatalen) return (ENOSPC); item = (struct vps_arg_item *)kdata; - memset(item, 0, sizeof (*item) * cnt); + memset(item, 0, sizeof (*item) * ACC_ITEM_CNT); mtx_lock_spin(&vps->vps_acc->lock); @@ -947,14 +899,6 @@ _vps_limit_getitemall(struct vps *vpsp, item++; FILL(item, &vps->vps_acc->phys, VPS_ACC_PHYS); item++; - /* - FILL(item, &vps->vps_acc->kmem, VPS_ACC_KMEM); - item++; - FILL(item, &vps->vps_acc->kernel, VPS_ACC_KERNEL); - item++; - FILL(item, &vps->vps_acc->buffer, VPS_ACC_BUFFER); - item++; - */ FILL(item, &vps->vps_acc->pctcpu, VPS_ACC_PCTCPU); item++; FILL(item, &vps->vps_acc->blockio, VPS_ACC_BLOCKIO); @@ -966,7 +910,8 @@ _vps_limit_getitemall(struct vps *vpsp, mtx_unlock_spin(&vps->vps_acc->lock); - *kdatalen = sizeof (*item) * cnt; + *kdatalen = sizeof (*item) * ACC_ITEM_CNT; + return (0); } @@ -1000,8 +945,8 @@ vps_account_print_pctcpu(struct vps *vps } PROC_UNLOCK(p); } - //sx_sunlock(&vps->_proctree_lock); sx_sunlock(&VPS_VPS(vps, allproc_lock)); + //sx_sunlock(&vps->_proctree_lock); printf("%s: vps=%p [%s] threads=%d vpstot=%u\n", __func__, vps, vps->vps_name, threads, vpstot); Modified: projects/vps/sys/vps/vps_account.h ============================================================================== --- projects/vps/sys/vps/vps_account.h Wed Oct 23 16:59:00 2013 (r256986) +++ projects/vps/sys/vps/vps_account.h Wed Oct 23 17:04:09 2013 (r256987) @@ -61,20 +61,27 @@ struct vps; struct mount; struct vps_acc_val { + /* Current accounting value (counter or rate). */ size_t cur; + /* For rate calculation. */ size_t cnt_cur; + /* Preconfigured soft limit (a warning is emitted when limit is hit). */ size_t soft; + /* Preconfigured hard limit (allocation is denied and error returned where possible). */ size_t hard; + /* Counter of exceeding the soft limit. */ u_int16_t hits_soft; + /* Counter of attempts exceeding the hard limit. */ u_int16_t hits_hard; + /* Last updated (ticks) */ int updated; }; Modified: projects/vps/sys/vps/vps_console.c ============================================================================== --- projects/vps/sys/vps/vps_console.c Wed Oct 23 16:59:00 2013 (r256986) +++ projects/vps/sys/vps/vps_console.c Wed Oct 23 17:04:09 2013 (r256987) @@ -76,19 +76,20 @@ static const char vpsid[] = MALLOC_DECLARE(M_VPS_CORE); -static struct mtx vps_console_mtx; -static struct proc *vps_console_kproc_p = NULL; -static int vps_console_exit = 0; -static void vps_console_kproc(void *); -static void *vps_console_readbuf; -static size_t vps_console_readbuf_len; +static struct mtx vps_console_mtx; +static struct proc *vps_console_kproc_p = NULL; +static int vps_console_exit = 0; +static void *vps_console_readbuf; +static size_t vps_console_readbuf_len; -static th_getc_capture_t vps_console_getc_capture; +static th_getc_capture_t vps_console_getc_capture; static struct ttyhook vps_console_hook = { .th_getc_capture = vps_console_getc_capture, }; +static void vps_console_kproc(void *); + /* * VPS pseudo system console. * @@ -318,8 +319,8 @@ vps_console_alloc(struct vps *vps, struc struct file *fp_ma; struct tty *tp; int error; -//#ifdef DIAGNOSTIC_2 #if 1 + /* Additional debugging. */ struct ucred *saveucred; struct ucred *dbgucred; @@ -392,7 +393,7 @@ vps_console_alloc(struct vps *vps, struc /* Will be deleted automatically on delete of parent device. */ make_dev_alias_cred(dev, vps_ucred, "ttyv0"); - //DBGCORE("%s: tty=%p dev=%p (slave device)\n", __func__, tp, dev); + DBGCORE("%s: tty=%p dev=%p (slave device)\n", __func__, tp, dev); dev_lock(); dev->si_usecount++; @@ -413,8 +414,8 @@ vps_console_alloc(struct vps *vps, struc } tty_unlock(tp); -//#ifdef DIAGNOSTIC_2 #if 1 + /* Additional debugging. */ td->td_ucred = saveucred; crfree(dbgucred); @@ -488,6 +489,7 @@ vps_console_free(struct vps *vps, struct int vps_console_getfd(struct vps *vps, struct thread *td, int *retfd) { + struct vps *vps2; struct file *fp; int fd; int error; @@ -495,14 +497,16 @@ vps_console_getfd(struct vps *vps, struc DBGCORE("%s: td=%p vps=%p\n", __func__, td, vps); /* - * XXX make sure vps is a child of td->td_vps ! - * - if (td->td_vps != vps) { - DBGCORE("%s: td->td_vps=%p vps=%p\n", - __func__, td->td_vps, vps); + * Make sure vps is a child of td->td_vps. + */ + LIST_FOREACH(vps2, &td->td_vps->vps_child_head, vps_sibling) + if (vps == vps2) + break; + if (vps != vps2) { + DBGCORE("%s: vps=%p is not a child of td->td_vps=%p\n", + __func__, vps, td->td_vps); return (EPERM); } - */ fp = vps->console_fp_ma; Modified: projects/vps/sys/vps/vps_core.c ============================================================================== --- projects/vps/sys/vps/vps_core.c Wed Oct 23 16:59:00 2013 (r256986) +++ projects/vps/sys/vps/vps_core.c Wed Oct 23 17:04:09 2013 (r256987) @@ -1610,14 +1610,6 @@ vps_reboot(struct thread *td, int howto) } sx_sunlock(&V_allproc_lock); -#if 0 - /* No effect. */ - vps->vps_flags |= VPS_F_REBOOT; - - /* Broadcast kill. */ - vps_proc_signal(vps, -1, SIGKILL); -#endif - while ((V_nprocs - V_nprocs_zomb) > 1) { /* Sleep. */ pause("vpsbot", hz / 10); @@ -1636,10 +1628,9 @@ vps_reboot(struct thread *td, int howto) if ( ! reboot ) { /* * When the last proc has exited, - * exit1() calls vps_destroy(). + * exit1() schedules vps_destroy(). * XXX not yet ! */ - //vps->f_destroy = 1; return (error); } Modified: projects/vps/sys/vps/vps_ddb.c ============================================================================== --- projects/vps/sys/vps/vps_ddb.c Wed Oct 23 16:59:00 2013 (r256986) +++ projects/vps/sys/vps/vps_ddb.c Wed Oct 23 17:04:09 2013 (r256987) @@ -73,10 +73,6 @@ static const char * vps_statusstr(int status) { switch (status) { - /* - case VPS_ST_INITISDYING: - return ("init_is_dying"); - */ case VPS_ST_CREATING: return ("creating"); case VPS_ST_RUNNING: Modified: projects/vps/sys/vps/vps_dev.c ============================================================================== --- projects/vps/sys/vps/vps_dev.c Wed Oct 23 16:59:00 2013 (r256986) +++ projects/vps/sys/vps/vps_dev.c Wed Oct 23 17:04:09 2013 (r256987) @@ -79,26 +79,24 @@ SYSCTL_INT(_debug, OID_AUTO, vps_dev_deb #endif /* DIAGNOSTIC */ -static int vps_dev_refcnt = 0; - -static caddr_t vps_dev_emptypage; - -static struct cdev *vps_dev_p; -static d_fdopen_t vps_dev_fdopen; -static d_open_t vps_dev_open; -static d_close_t vps_dev_close; -static d_ioctl_t vps_dev_ioctl; -static d_mmap_t vps_dev_mmap; +static int vps_dev_refcnt = 0; +static caddr_t vps_dev_emptypage; +static struct cdev *vps_dev_p; +static d_fdopen_t vps_dev_fdopen; +static d_open_t vps_dev_open; +static d_close_t vps_dev_close; +static d_ioctl_t vps_dev_ioctl; +static d_mmap_t vps_dev_mmap; static struct cdevsw vps_dev_cdevsw = { - .d_version = D_VERSION, - .d_name = "vps control device", - .d_fdopen = vps_dev_fdopen, - .d_open = vps_dev_open, - .d_close = vps_dev_close, - .d_ioctl = vps_dev_ioctl, - .d_mmap = vps_dev_mmap, - .d_flags = D_TRACKCLOSE, + .d_version = D_VERSION, + .d_name = "vps control device", + .d_fdopen = vps_dev_fdopen, + .d_open = vps_dev_open, + .d_close = vps_dev_close, + .d_ioctl = vps_dev_ioctl, + .d_mmap = vps_dev_mmap, + .d_flags = D_TRACKCLOSE, }; LIST_HEAD(vps_dev_ctx_le, vps_dev_ctx) vps_dev_ctx_head; @@ -173,7 +171,7 @@ vps_dev_get_ctx(struct thread *td) struct vps_dev_ctx *ctx; if (jailed(td->td_ucred)) { - printf("%s: td is jailed --> denying any vps-device " + DBGCORE("%s: td is jailed --> denying any vps-device " "action !\n", __func__); return (NULL); } @@ -185,7 +183,7 @@ vps_dev_get_ctx(struct thread *td) return (ctx); } - printf("%s: ######## dev_ctx not found for td=%p td->td_fpop=%p " + DBGDEV("%s: ######## dev_ctx not found for td=%p td->td_fpop=%p " "pid=%d\n", __func__, td, td->td_fpop, td->td_proc->p_pid); return (NULL); @@ -198,7 +196,7 @@ vps_dev_fdopen(struct cdev *dev, int ffl struct vps_dev_ctx *ctx; if (jailed(td->td_ucred)) { - printf("%s: td is jailed --> denying any vps-device " + DBGDEV("%s: td is jailed --> denying any vps-device " "action !\n", __func__); return (EPERM); } @@ -232,10 +230,8 @@ vps_dev_close(struct cdev *dev, int flag DBGDEV("%s: ctx=%p\n", __func__, ctx); - if (ctx == NULL) { - printf("%s: ctx == NULL !\n", __func__); + if (ctx == NULL) return (0); - } LIST_REMOVE(ctx, list); @@ -264,10 +260,8 @@ vps_dev_ioctl(struct cdev *dev, u_long c int error; ctx = vps_dev_get_ctx(td); - if (ctx == NULL) { - printf("%s: ctx == NULL !\n", __func__); + if (ctx == NULL) return (EBADF); - } /* Needed for conext lookup in mmap pager function. */ ctx->td = td; @@ -344,7 +338,7 @@ vps_dev_ioctl(struct cdev *dev, u_long c return (error); } -__attribute__((noinline)) +VPSFUNC static int vps_dev_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot, vm_memattr_t *memattr) @@ -353,10 +347,6 @@ vps_dev_mmap(struct cdev *dev, vm_ooffse struct vps *vps; int error; - /* td->td_fpop is not set here. - ctx = vps_dev_get_ctx(curthread); - */ - ctx = NULL; LIST_FOREACH(ctx2, &vps_dev_ctx_head, list) if (ctx2->td == curthread) { @@ -370,28 +360,26 @@ vps_dev_mmap(struct cdev *dev, vm_ooffse * Better return an empty page than let the * user cause a kernel panic. */ - printf("%s: ctx == NULL !\n", __func__); + DBGDEV("%s: ctx == NULL !\n", __func__); goto invalid; } if (ctx->data == NULL && ctx->cmd != VPS_IOC_SNAPST) { - printf("%s: ctx->data == NULL !\n", __func__); + DBGDEV("%s: ctx->data == NULL !\n", __func__); goto invalid; } error = 0; vps = TD_TO_VPS(curthread); - /* XXX assert vps != NULL */ - if (offset < 0) { - printf("%s: offset=%zu < 0\n", + DBGDEV("%s: offset=%zu < 0\n", __func__, (size_t)offset); goto invalid; } if (nprot != PROT_READ) { - printf("%s: nprot=%d != PROT_READ\n", + DBGDEV("%s: nprot=%d != PROT_READ\n", __func__, nprot); goto invalid; } @@ -400,7 +388,7 @@ vps_dev_mmap(struct cdev *dev, vm_ooffse /* VPS_IOC_LIST */ if (offset > ctx->length) { - printf("%s: offset=%zu > ctx->length=%zu\n", + DBGDEV("%s: offset=%zu > ctx->length=%zu\n", __func__, (size_t)offset, ctx->length); goto invalid; } Modified: projects/vps/sys/vps/vps_libdump.c ============================================================================== --- projects/vps/sys/vps/vps_libdump.c Wed Oct 23 16:59:00 2013 (r256986) +++ projects/vps/sys/vps/vps_libdump.c Wed Oct 23 17:04:09 2013 (r256987) @@ -199,7 +199,6 @@ struct vps_snapst_ctx; #include -/* XXX remove again from declarations */ static void __vps_dumpobj_printtree(struct vps_snapst_ctx *ctx, struct vps_dumpobj *o); @@ -208,7 +207,8 @@ static void __vps_dumpobj_printtree(stru int test01(void); int checkfile(const char *); -int main(int argc, char **argv, char **envv) +int +main(int argc, char **argv, char **envv) { int error; @@ -231,7 +231,8 @@ int main(int argc, char **argv, char **e (sizeof(struct s) % 8) ? "NOT 64bit aligned" : "ok" \ ); -int structsizes(void) +int +structsizes(void) { PRINT_STRUCT_SIZE(vps_dump_sysinfo); @@ -292,7 +293,8 @@ int structsizes(void) return (0); } -int checkfile(const char *path) +int +checkfile(const char *path) { int fd; int size; @@ -334,7 +336,8 @@ int checkfile(const char *path) return (0); } -int test01(void) +int +test01(void) { void *data; long size; @@ -439,7 +442,7 @@ int test01(void) *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***