Changeset View
Changeset View
Standalone View
Standalone View
head/usr.sbin/bhyve/block_if.c
Show All 24 Lines | |||||
* | * | ||||
* $FreeBSD$ | * $FreeBSD$ | ||||
*/ | */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#ifndef WITHOUT_CAPSICUM | |||||
#include <sys/capsicum.h> | |||||
#endif | |||||
#include <sys/queue.h> | #include <sys/queue.h> | ||||
#include <sys/errno.h> | #include <sys/errno.h> | ||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <sys/ioctl.h> | #include <sys/ioctl.h> | ||||
#include <sys/disk.h> | #include <sys/disk.h> | ||||
#include <assert.h> | #include <assert.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <pthread.h> | #include <pthread.h> | ||||
#include <pthread_np.h> | #include <pthread_np.h> | ||||
#include <signal.h> | #include <signal.h> | ||||
#include <sysexits.h> | |||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <machine/atomic.h> | #include <machine/atomic.h> | ||||
#include "bhyverun.h" | #include "bhyverun.h" | ||||
#include "mevent.h" | #include "mevent.h" | ||||
#include "block_if.h" | #include "block_if.h" | ||||
▲ Show 20 Lines • Show All 339 Lines • ▼ Show 20 Lines | blockif_open(const char *optstr, const char *ident) | ||||
char name[MAXPATHLEN]; | char name[MAXPATHLEN]; | ||||
char *nopt, *xopts, *cp; | char *nopt, *xopts, *cp; | ||||
struct blockif_ctxt *bc; | struct blockif_ctxt *bc; | ||||
struct stat sbuf; | struct stat sbuf; | ||||
struct diocgattr_arg arg; | struct diocgattr_arg arg; | ||||
off_t size, psectsz, psectoff; | off_t size, psectsz, psectoff; | ||||
int extra, fd, i, sectsz; | int extra, fd, i, sectsz; | ||||
int nocache, sync, ro, candelete, geom, ssopt, pssopt; | int nocache, sync, ro, candelete, geom, ssopt, pssopt; | ||||
#ifndef WITHOUT_CAPSICUM | |||||
cap_rights_t rights; | |||||
cap_ioctl_t cmds[] = { DIOCGFLUSH, DIOCGDELETE }; | |||||
#endif | |||||
pthread_once(&blockif_once, blockif_init); | pthread_once(&blockif_once, blockif_init); | ||||
fd = -1; | fd = -1; | ||||
ssopt = 0; | ssopt = 0; | ||||
nocache = 0; | nocache = 0; | ||||
sync = 0; | sync = 0; | ||||
ro = 0; | ro = 0; | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if (fd < 0) { | ||||
goto err; | goto err; | ||||
} | } | ||||
if (fstat(fd, &sbuf) < 0) { | if (fstat(fd, &sbuf) < 0) { | ||||
warn("Could not stat backing file %s", nopt); | warn("Could not stat backing file %s", nopt); | ||||
goto err; | goto err; | ||||
} | } | ||||
#ifndef WITHOUT_CAPSICUM | |||||
cap_rights_init(&rights, CAP_FSYNC, CAP_IOCTL, CAP_READ, CAP_SEEK, | |||||
CAP_WRITE); | |||||
if (ro) | |||||
cap_rights_clear(&rights, CAP_FSYNC, CAP_WRITE); | |||||
if (cap_rights_limit(fd, &rights) == -1 && errno != ENOSYS) | |||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | |||||
#endif | |||||
/* | /* | ||||
* Deal with raw devices | * Deal with raw devices | ||||
*/ | */ | ||||
size = sbuf.st_size; | size = sbuf.st_size; | ||||
sectsz = DEV_BSIZE; | sectsz = DEV_BSIZE; | ||||
psectsz = psectoff = 0; | psectsz = psectoff = 0; | ||||
candelete = geom = 0; | candelete = geom = 0; | ||||
if (S_ISCHR(sbuf.st_mode)) { | if (S_ISCHR(sbuf.st_mode)) { | ||||
Show All 9 Lines | if (S_ISCHR(sbuf.st_mode)) { | ||||
strlcpy(arg.name, "GEOM::candelete", sizeof(arg.name)); | strlcpy(arg.name, "GEOM::candelete", sizeof(arg.name)); | ||||
arg.len = sizeof(arg.value.i); | arg.len = sizeof(arg.value.i); | ||||
if (ioctl(fd, DIOCGATTR, &arg) == 0) | if (ioctl(fd, DIOCGATTR, &arg) == 0) | ||||
candelete = arg.value.i; | candelete = arg.value.i; | ||||
if (ioctl(fd, DIOCGPROVIDERNAME, name) == 0) | if (ioctl(fd, DIOCGPROVIDERNAME, name) == 0) | ||||
geom = 1; | geom = 1; | ||||
} else | } else | ||||
psectsz = sbuf.st_blksize; | psectsz = sbuf.st_blksize; | ||||
#ifndef WITHOUT_CAPSICUM | |||||
if (cap_ioctls_limit(fd, cmds, nitems(cmds)) == -1 && errno != ENOSYS) | |||||
errx(EX_OSERR, "Unable to apply rights for sandbox"); | |||||
#endif | |||||
if (ssopt != 0) { | if (ssopt != 0) { | ||||
if (!powerof2(ssopt) || !powerof2(pssopt) || ssopt < 512 || | if (!powerof2(ssopt) || !powerof2(pssopt) || ssopt < 512 || | ||||
ssopt > pssopt) { | ssopt > pssopt) { | ||||
fprintf(stderr, "Invalid sector size %d/%d\n", | fprintf(stderr, "Invalid sector size %d/%d\n", | ||||
ssopt, pssopt); | ssopt, pssopt); | ||||
goto err; | goto err; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 329 Lines • Show Last 20 Lines |