Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Jun 2006 14:00:20 GMT
From:      Alex Lyashkov <als@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 99939 for review
Message-ID:  <200606241400.k5OE0Kb7054379@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <sys/jail.h>
 #include <sys/jail2.h>
 
+#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 <shadow@psoft.net>
- * 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 <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include <sys/errno.h>
-#include <sys/param.h>
-#include <sys/proc.h>
-#include <sys/systm.h>
-#include <sys/namei.h>
-#include <sys/vnode.h>
-#include <sys/mount.h>
-#include <sys/lock.h>
-#include <sys/mutex.h>
-#include <sys/sx.h>
-
-#include <sys/jail.h>
-#include <sys/jail2.h>
-
-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);
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200606241400.k5OE0Kb7054379>