Deleted Added
full compact
linux_mib.c (192895) linux_mib.c (195870)
1/*-
2 * Copyright (c) 1999 Marcel Moolenaar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1999 Marcel Moolenaar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/compat/linux/linux_mib.c 192895 2009-05-27 14:11:23Z jamie $");
30__FBSDID("$FreeBSD: head/sys/compat/linux/linux_mib.c 195870 2009-07-25 14:48:57Z jamie $");
31
32#include <sys/param.h>
33#include <sys/kernel.h>
34#include <sys/systm.h>
35#include <sys/sysctl.h>
36#include <sys/proc.h>
37#include <sys/malloc.h>
38#include <sys/mount.h>

--- 193 unchanged lines hidden (view full) ---

232/*
233 * Jail OSD methods for Linux prison data.
234 */
235static int
236linux_prison_create(void *obj, void *data)
237{
238 struct prison *pr = obj;
239 struct vfsoptlist *opts = data;
31
32#include <sys/param.h>
33#include <sys/kernel.h>
34#include <sys/systm.h>
35#include <sys/sysctl.h>
36#include <sys/proc.h>
37#include <sys/malloc.h>
38#include <sys/mount.h>

--- 193 unchanged lines hidden (view full) ---

232/*
233 * Jail OSD methods for Linux prison data.
234 */
235static int
236linux_prison_create(void *obj, void *data)
237{
238 struct prison *pr = obj;
239 struct vfsoptlist *opts = data;
240 int jsys;
240
241
241 if (vfs_flagopt(opts, "nolinux", NULL, 0))
242 if (vfs_copyopt(opts, "linux", &jsys, sizeof(jsys)) == 0 &&
243 jsys == JAIL_SYS_INHERIT)
242 return (0);
243 /*
244 * Inherit a prison's initial values from its parent
244 return (0);
245 /*
246 * Inherit a prison's initial values from its parent
245 * (different from NULL which also inherits changes).
247 * (different from JAIL_SYS_INHERIT which also inherits changes).
246 */
247 return linux_alloc_prison(pr, NULL);
248}
249
250static int
251linux_prison_check(void *obj __unused, void *data)
252{
253 struct vfsoptlist *opts = data;
254 char *osname, *osrelease;
248 */
249 return linux_alloc_prison(pr, NULL);
250}
251
252static int
253linux_prison_check(void *obj __unused, void *data)
254{
255 struct vfsoptlist *opts = data;
256 char *osname, *osrelease;
255 int error, len, osrel, oss_version;
257 int error, jsys, len, osrel, oss_version;
256
257 /* Check that the parameters are correct. */
258
259 /* Check that the parameters are correct. */
258 (void)vfs_flagopt(opts, "linux", NULL, 0);
259 (void)vfs_flagopt(opts, "nolinux", NULL, 0);
260 error = vfs_copyopt(opts, "linux", &jsys, sizeof(jsys));
261 if (error != ENOENT) {
262 if (error != 0)
263 return (error);
264 if (jsys != JAIL_SYS_NEW && jsys != JAIL_SYS_INHERIT)
265 return (EINVAL);
266 }
260 error = vfs_getopt(opts, "linux.osname", (void **)&osname, &len);
261 if (error != ENOENT) {
262 if (error != 0)
263 return (error);
264 if (len == 0 || osname[len - 1] != '\0')
265 return (EINVAL);
266 if (len > LINUX_MAX_UTSNAME) {
267 vfs_opterror(opts, "linux.osname too long");

--- 23 unchanged lines hidden (view full) ---

291
292static int
293linux_prison_set(void *obj, void *data)
294{
295 struct linux_prison *lpr;
296 struct prison *pr = obj;
297 struct vfsoptlist *opts = data;
298 char *osname, *osrelease;
267 error = vfs_getopt(opts, "linux.osname", (void **)&osname, &len);
268 if (error != ENOENT) {
269 if (error != 0)
270 return (error);
271 if (len == 0 || osname[len - 1] != '\0')
272 return (EINVAL);
273 if (len > LINUX_MAX_UTSNAME) {
274 vfs_opterror(opts, "linux.osname too long");

--- 23 unchanged lines hidden (view full) ---

298
299static int
300linux_prison_set(void *obj, void *data)
301{
302 struct linux_prison *lpr;
303 struct prison *pr = obj;
304 struct vfsoptlist *opts = data;
305 char *osname, *osrelease;
299 int error, gotversion, len, nolinux, oss_version, yeslinux;
306 int error, gotversion, jsys, len, oss_version;
300
301 /* Set the parameters, which should be correct. */
307
308 /* Set the parameters, which should be correct. */
302 yeslinux = vfs_flagopt(opts, "linux", NULL, 0);
303 nolinux = vfs_flagopt(opts, "nolinux", NULL, 0);
309 error = vfs_copyopt(opts, "linux", &jsys, sizeof(jsys));
310 if (error == ENOENT)
311 jsys = -1;
304 error = vfs_getopt(opts, "linux.osname", (void **)&osname, &len);
305 if (error == ENOENT)
306 osname = NULL;
307 else
312 error = vfs_getopt(opts, "linux.osname", (void **)&osname, &len);
313 if (error == ENOENT)
314 osname = NULL;
315 else
308 yeslinux = 1;
316 jsys = JAIL_SYS_NEW;
309 error = vfs_getopt(opts, "linux.osrelease", (void **)&osrelease, &len);
310 if (error == ENOENT)
311 osrelease = NULL;
312 else
317 error = vfs_getopt(opts, "linux.osrelease", (void **)&osrelease, &len);
318 if (error == ENOENT)
319 osrelease = NULL;
320 else
313 yeslinux = 1;
321 jsys = JAIL_SYS_NEW;
314 error = vfs_copyopt(opts, "linux.oss_version", &oss_version,
315 sizeof(oss_version));
322 error = vfs_copyopt(opts, "linux.oss_version", &oss_version,
323 sizeof(oss_version));
316 gotversion = (error == 0);
317 yeslinux |= gotversion;
318 if (nolinux) {
319 /* "nolinux": inherit the parent's Linux info. */
324 if (error == ENOENT)
325 gotversion = 0;
326 else {
327 gotversion = 1;
328 jsys = JAIL_SYS_NEW;
329 }
330 switch (jsys) {
331 case JAIL_SYS_INHERIT:
332 /* "linux=inherit": inherit the parent's Linux info. */
320 mtx_lock(&pr->pr_mtx);
321 osd_jail_del(pr, linux_osd_jail_slot);
322 mtx_unlock(&pr->pr_mtx);
333 mtx_lock(&pr->pr_mtx);
334 osd_jail_del(pr, linux_osd_jail_slot);
335 mtx_unlock(&pr->pr_mtx);
323 } else if (yeslinux) {
336 break;
337 case JAIL_SYS_NEW:
324 /*
338 /*
325 * "linux" or "linux.*":
339 * "linux=new" or "linux.*":
326 * the prison gets its own Linux info.
327 */
328 error = linux_alloc_prison(pr, &lpr);
329 if (error) {
330 mtx_unlock(&pr->pr_mtx);
331 return (error);
332 }
333 if (osrelease) {

--- 9 unchanged lines hidden (view full) ---

343 strlcpy(lpr->pr_osname, osname, LINUX_MAX_UTSNAME);
344 if (gotversion)
345 lpr->pr_oss_version = oss_version;
346 mtx_unlock(&pr->pr_mtx);
347 }
348 return (0);
349}
350
340 * the prison gets its own Linux info.
341 */
342 error = linux_alloc_prison(pr, &lpr);
343 if (error) {
344 mtx_unlock(&pr->pr_mtx);
345 return (error);
346 }
347 if (osrelease) {

--- 9 unchanged lines hidden (view full) ---

357 strlcpy(lpr->pr_osname, osname, LINUX_MAX_UTSNAME);
358 if (gotversion)
359 lpr->pr_oss_version = oss_version;
360 mtx_unlock(&pr->pr_mtx);
361 }
362 return (0);
363}
364
351SYSCTL_JAIL_PARAM_NODE(linux, "Jail Linux parameters");
352SYSCTL_JAIL_PARAM(, nolinux, CTLTYPE_INT | CTLFLAG_RW,
353 "BN", "Jail w/ no Linux parameters");
365SYSCTL_JAIL_PARAM_SYS_NODE(linux, CTLFLAG_RW, "Jail Linux parameters");
354SYSCTL_JAIL_PARAM_STRING(_linux, osname, CTLFLAG_RW, LINUX_MAX_UTSNAME,
355 "Jail Linux kernel OS name");
356SYSCTL_JAIL_PARAM_STRING(_linux, osrelease, CTLFLAG_RW, LINUX_MAX_UTSNAME,
357 "Jail Linux kernel OS release");
358SYSCTL_JAIL_PARAM(_linux, oss_version, CTLTYPE_INT | CTLFLAG_RW,
359 "I", "Jail Linux OSS version");
360
361static int

--- 4 unchanged lines hidden (view full) ---

366 struct prison *pr = obj;
367 struct vfsoptlist *opts = data;
368 int error, i;
369
370 static int version0;
371
372 /* See if this prison is the one with the Linux info. */
373 lpr = linux_find_prison(pr, &ppr);
366SYSCTL_JAIL_PARAM_STRING(_linux, osname, CTLFLAG_RW, LINUX_MAX_UTSNAME,
367 "Jail Linux kernel OS name");
368SYSCTL_JAIL_PARAM_STRING(_linux, osrelease, CTLFLAG_RW, LINUX_MAX_UTSNAME,
369 "Jail Linux kernel OS release");
370SYSCTL_JAIL_PARAM(_linux, oss_version, CTLTYPE_INT | CTLFLAG_RW,
371 "I", "Jail Linux OSS version");
372
373static int

--- 4 unchanged lines hidden (view full) ---

378 struct prison *pr = obj;
379 struct vfsoptlist *opts = data;
380 int error, i;
381
382 static int version0;
383
384 /* See if this prison is the one with the Linux info. */
385 lpr = linux_find_prison(pr, &ppr);
374 i = (ppr == pr);
386 i = (ppr == pr) ? JAIL_SYS_NEW : JAIL_SYS_INHERIT;
375 error = vfs_setopt(opts, "linux", &i, sizeof(i));
376 if (error != 0 && error != ENOENT)
377 goto done;
387 error = vfs_setopt(opts, "linux", &i, sizeof(i));
388 if (error != 0 && error != ENOENT)
389 goto done;
378 i = !i;
379 error = vfs_setopt(opts, "nolinux", &i, sizeof(i));
380 if (error != 0 && error != ENOENT)
381 goto done;
382 if (i) {
390 if (i) {
391 error = vfs_setopts(opts, "linux.osname", lpr->pr_osname);
392 if (error != 0 && error != ENOENT)
393 goto done;
394 error = vfs_setopts(opts, "linux.osrelease", lpr->pr_osrelease);
395 if (error != 0 && error != ENOENT)
396 goto done;
397 error = vfs_setopt(opts, "linux.oss_version",
398 &lpr->pr_oss_version, sizeof(lpr->pr_oss_version));
399 if (error != 0 && error != ENOENT)
400 goto done;
401 } else {
383 /*
384 * If this prison is inheriting its Linux info, report
385 * empty/zero parameters.
386 */
387 error = vfs_setopts(opts, "linux.osname", "");
388 if (error != 0 && error != ENOENT)
389 goto done;
390 error = vfs_setopts(opts, "linux.osrelease", "");
391 if (error != 0 && error != ENOENT)
392 goto done;
393 error = vfs_setopt(opts, "linux.oss_version", &version0,
394 sizeof(lpr->pr_oss_version));
395 if (error != 0 && error != ENOENT)
396 goto done;
402 /*
403 * If this prison is inheriting its Linux info, report
404 * empty/zero parameters.
405 */
406 error = vfs_setopts(opts, "linux.osname", "");
407 if (error != 0 && error != ENOENT)
408 goto done;
409 error = vfs_setopts(opts, "linux.osrelease", "");
410 if (error != 0 && error != ENOENT)
411 goto done;
412 error = vfs_setopt(opts, "linux.oss_version", &version0,
413 sizeof(lpr->pr_oss_version));
414 if (error != 0 && error != ENOENT)
415 goto done;
397 } else {
398 error = vfs_setopts(opts, "linux.osname", lpr->pr_osname);
399 if (error != 0 && error != ENOENT)
400 goto done;
401 error = vfs_setopts(opts, "linux.osrelease", lpr->pr_osrelease);
402 if (error != 0 && error != ENOENT)
403 goto done;
404 error = vfs_setopt(opts, "linux.oss_version",
405 &lpr->pr_oss_version, sizeof(lpr->pr_oss_version));
406 if (error != 0 && error != ENOENT)
407 goto done;
408 }
409 error = 0;
410
411 done:
412 mtx_unlock(&ppr->pr_mtx);
413 return (error);
414}
415

--- 184 unchanged lines hidden ---
416 }
417 error = 0;
418
419 done:
420 mtx_unlock(&ppr->pr_mtx);
421 return (error);
422}
423

--- 184 unchanged lines hidden ---