From owner-p4-projects@FreeBSD.ORG Sat Jun 24 14:00:21 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 8986716A4A6; Sat, 24 Jun 2006 14:00:21 +0000 (UTC) X-Original-To: perforce@FreeBSD.org Delivered-To: perforce@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 35A2B16A47E for ; Sat, 24 Jun 2006 14:00:21 +0000 (UTC) (envelope-from als@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id BA6D143D46 for ; Sat, 24 Jun 2006 14:00:20 +0000 (GMT) (envelope-from als@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k5OE0KBb054382 for ; Sat, 24 Jun 2006 14:00:20 GMT (envelope-from als@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k5OE0Kb7054379 for perforce@freebsd.org; Sat, 24 Jun 2006 14:00:20 GMT (envelope-from als@FreeBSD.org) Date: Sat, 24 Jun 2006 14:00:20 GMT Message-Id: <200606241400.k5OE0Kb7054379@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to als@FreeBSD.org using -f From: Alex Lyashkov To: Perforce Change Reviews Cc: Subject: PERFORCE change 99939 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 24 Jun 2006 14:00:21 -0000 http://perforce.freebsd.org/chv.cgi?CH=99939 Change 99939 by als@als_head on 2006/06/24 14:00:09 whitepace cleanup. implement jail2_disk. Affected files ... .. //depot/projects/jail2/sys/kern/kern_jail2_disk.c#2 edit Differences ... ==== //depot/projects/jail2/sys/kern/kern_jail2_disk.c#2 (text+ko) ==== @@ -41,23 +41,26 @@ #include #include +#define jprint(a...) +/* printf(a) */ + int jail_setvroot(struct prison *pr, struct thread *td, char *root) { int error, vfslocked; struct nameidata nd; char path[MAXPATHLEN]; - + error = copyinstr(root, &path, sizeof(path), 0); if (error) goto e_exit; // printf("setvroot %s\n",path); NDINIT(&nd, LOOKUP, MPSAFE | FOLLOW | LOCKLEAF, UIO_SYSSPACE, - path, td); + path, td); error = namei(&nd); - if (error) - goto e_exit; - + if (error) + goto e_exit; + vfslocked = NDHASGIANT(&nd); JAIL_VROOT(pr) = nd.ni_vp; strlcpy(pr->pr_disk.pr_path, path, MAXPATHLEN); @@ -75,90 +78,41 @@ pr->pr_disk.pr_path[0]=0; if (JAIL_VROOT(pr) != NULL) { vfslocked = VFS_LOCK_GIANT(JAIL_VROOT(pr)->v_mount); - vrele(JAIL_VROOT(pr)); + vrele(JAIL_VROOT(pr)); VFS_UNLOCK_GIANT(vfslocked); JAIL_VROOT(pr) = NULL; } } -/* - * Copyright (c) 2004 Alex Lyashkov - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -#include -__FBSDID("$FreeBSD$"); - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -int jail_setvroot(struct prison *pr, struct thread *td, char *root) +int jail2_disk(struct thread *_td, struct jail_2 *_j) { - int error, vfslocked; - struct nameidata nd; - char path[MAXPATHLEN]; - - error = copyinstr(root, &path, sizeof(path), 0); - if (error) - goto e_exit; + struct prison *pr; + int ret = 0; -// printf("setvroot %s\n",path); - NDINIT(&nd, LOOKUP, MPSAFE | FOLLOW | LOCKLEAF, UIO_SYSSPACE, - path, td); - error = namei(&nd); - if (error) - goto e_exit; - - vfslocked = NDHASGIANT(&nd); - JAIL_VROOT(pr) = nd.ni_vp; - strlcpy(pr->pr_disk.pr_path, path, MAXPATHLEN); - VOP_UNLOCK(nd.ni_vp, 0, td); - VFS_UNLOCK_GIANT(vfslocked); - NDFREE(&nd, NDF_ONLY_PNBUF); -e_exit: - return (error); -} + mtx_lock(&allprison_mtx); + pr = prison_find(_j->ctx_id); + mtx_unlock(&allprison_mtx); -void jail_destroyvroot(struct prison *pr) -{ - int vfslocked; + jprint("jail2_disk %d ctx: %d pr: %p\n", JAIL2_CMD(_j->cmd), _j->ctx_id, pr ); + if (pr == NULL) { + printf("Prison not found for command %x\n", _j->cmd); + return (ESRCH); + } - pr->pr_disk.pr_path[0]=0; - if (JAIL_VROOT(pr) != NULL) { - vfslocked = VFS_LOCK_GIANT(JAIL_VROOT(pr)->v_mount); - vrele(JAIL_VROOT(pr)); - VFS_UNLOCK_GIANT(vfslocked); - JAIL_VROOT(pr) = NULL; - } + switch(JAIL2_CMD(_j->cmd)) { + case J_SETVROOT: + if (JAIL_VROOT(pr) != NULL) { + if (JAIL_NPROCS(pr) != 0) { + ret = EPERM; + break; + } + jail_destroyvroot(pr); + } + ret = jail_setvroot(pr, _td, _j->data); + break; + default: + ret = EOPNOTSUPP; + break; + } + return (ret); }