multi-vkd.patch
| dev/virtual/disk/vdisk.c 27 Jan 2007 23:00:38 -0000 | ||
|---|---|---|
| 63 | 63 |
int fd; |
| 64 | 64 |
}; |
| 65 | 65 | |
| 66 | ||
| 67 | ||
| 68 | 66 |
#define CDEV_MAJOR 97 |
| 69 | 67 | |
| 70 | 68 |
static d_strategy_t vkdstrategy; |
| ... | ... | |
| 82 | 80 |
static void |
| 83 | 81 |
vkdinit(void *dummy __unused) |
| 84 | 82 |
{
|
| 83 |
int vkd_iter = 0; |
|
| 84 |
struct vkd_info *myslot; |
|
| 85 | 85 |
struct vkd_softc *sc; |
| 86 | 86 |
struct stat st; |
| 87 | 87 | |
| 88 |
if (RootImageFd < 0 || fstat(RootImageFd, &st) < 0) |
|
| 89 |
return; |
|
| 88 |
KASSERT(VkdNum <= VKD_MAX, ("too many vkd's: %d\n", NetifNum));
|
|
| 89 |
|
|
| 90 |
for (vkd_iter = 0; vkd_iter < VkdNum; vkd_iter++) {
|
|
| 91 | ||
| 92 |
/* check that the 'bus device' has been initialized */ |
|
| 93 |
myslot = (struct vkd_info*) NULL; |
|
| 94 |
myslot = &VkdInfo[vkd_iter]; |
|
| 95 |
if (myslot == NULL) |
|
| 96 |
continue; |
|
| 97 |
if (myslot->fd < 0 || fstat(myslot->fd, &st) < 0) |
|
| 98 |
continue; |
|
| 99 | ||
| 100 |
/* and create a new device */ |
|
| 101 |
sc = NULL; |
|
| 102 |
sc = kmalloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO); |
|
| 103 |
sc->unit = myslot->unit; |
|
| 104 |
sc->fd = myslot->fd; |
|
| 105 |
bioq_init(&sc->bio_queue); |
|
| 106 |
devstat_add_entry(&sc->stats, "vkd", sc->unit, DEV_BSIZE, |
|
| 107 |
DEVSTAT_NO_ORDERED_TAGS, |
|
| 108 |
DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_OTHER, |
|
| 109 |
DEVSTAT_PRIORITY_DISK); |
|
| 110 |
sc->dev = disk_create(sc->unit, &sc->disk, 0, &vkd_ops); |
|
| 111 |
sc->dev->si_drv1 = sc; |
|
| 112 |
sc->dev->si_iosize_max = 256 * 1024; |
|
| 90 | 113 | |
| 91 |
sc = kmalloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO); |
|
| 92 |
sc->unit = 0; |
|
| 93 |
sc->fd = RootImageFd; |
|
| 94 |
bioq_init(&sc->bio_queue); |
|
| 95 |
devstat_add_entry(&sc->stats, "vkd", sc->unit, DEV_BSIZE, |
|
| 96 |
DEVSTAT_NO_ORDERED_TAGS, |
|
| 97 |
DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_OTHER, |
|
| 98 |
DEVSTAT_PRIORITY_DISK); |
|
| 99 |
sc->dev = disk_create(sc->unit, &sc->disk, 0, &vkd_ops); |
|
| 100 |
sc->dev->si_drv1 = sc; |
|
| 101 |
sc->dev->si_iosize_max = 256 * 1024; |
|
| 114 |
/* not sure why if 0'ed in v1.2... kept here for fun. */ |
|
| 102 | 115 |
#if 0 |
| 103 |
dl = &sc->disk.d_label; |
|
| 104 |
bzero(dl, sizeof(*dl)); |
|
| 105 |
dl->d_secsize = DEV_BSIZE; |
|
| 106 |
dl->d_nsectors = st.st_size / dl->d_secsize; |
|
| 107 |
dl->d_ntracks = 1; |
|
| 108 |
dl->d_secpercyl = dl->d_nsectors; |
|
| 109 |
dl->d_ncylinders = 1; |
|
| 116 |
dl = &sc->disk.d_label;
|
|
| 117 |
bzero(dl, sizeof(*dl));
|
|
| 118 |
dl->d_secsize = DEV_BSIZE;
|
|
| 119 |
dl->d_nsectors = st.st_size / dl->d_secsize;
|
|
| 120 |
dl->d_ntracks = 1;
|
|
| 121 |
dl->d_secpercyl = dl->d_nsectors;
|
|
| 122 |
dl->d_ncylinders = 1;
|
|
| 110 | 123 |
#endif |
| 124 | ||
| 125 |
} |
|
| 111 | 126 |
} |
| 112 | 127 | |
| 113 | 128 |
SYSINIT(vkdisk, SI_SUB_DRIVERS, SI_ORDER_FIRST, vkdinit, NULL); |
| ... | ... | |
| 122 | 137 | |
| 123 | 138 |
dev = ap->a_head.a_dev; |
| 124 | 139 |
sc = dev->si_drv1; |
| 125 |
if (sc->unit != 0) |
|
| 126 |
return(ENXIO); |
|
| 127 | 140 |
if (fstat(sc->fd, &st) < 0 || st.st_size == 0) |
| 128 | 141 |
return(ENXIO); |
| 129 | 142 | |
| platform/vkernel/include/md_var.h 27 Jan 2007 20:04:17 -0000 | ||
|---|---|---|
| 45 | 45 |
#endif |
| 46 | 46 | |
| 47 | 47 |
#define VKNETIF_MAX 16 |
| 48 |
#define VKD_MAX 16 |
|
| 48 | 49 | |
| 49 | 50 |
struct vknetif_info {
|
| 50 | 51 |
int tap_fd; |
| ... | ... | |
| 53 | 54 |
in_addr_t netif_mask; |
| 54 | 55 |
}; |
| 55 | 56 | |
| 57 |
struct vkd_info {
|
|
| 58 |
int fd; |
|
| 59 |
int unit; |
|
| 60 |
char fname[MAXPATHLEN]; |
|
| 61 |
}; |
|
| 62 | ||
| 56 | 63 |
extern char sigcode[]; |
| 57 | 64 |
extern int szsigcode; |
| 58 | 65 |
extern vpte_t *KernelPTA; /* NOTE: Offset for direct VA translation */ |
| ... | ... | |
| 63 | 70 |
extern char cpu_vendor[]; /* XXX belongs in i386 */ |
| 64 | 71 |
extern u_int cpu_id; /* XXX belongs in i386 */ |
| 65 | 72 | |
| 66 |
extern int RootImageFd; |
|
| 73 |
extern struct vkd_info VkdInfo[VKD_MAX]; |
|
| 74 |
extern int VkdNum; |
|
| 67 | 75 |
extern int MemImageFd; |
| 68 | 76 |
extern int KQueueFd; |
| 69 | 77 |
extern struct vknetif_info NetifInfo[VKNETIF_MAX]; |
| platform/vkernel/platform/init.c 27 Jan 2007 22:44:41 -0000 | ||
|---|---|---|
| 76 | 76 |
vm_paddr_t Maxmem; |
| 77 | 77 |
vm_paddr_t Maxmem_bytes; |
| 78 | 78 |
int MemImageFd = -1; |
| 79 |
int RootImageFd = -1; |
|
| 79 |
struct vkd_info VkdInfo[VKD_MAX]; |
|
| 80 |
int VkdNum = 0; |
|
| 80 | 81 |
struct vknetif_info NetifInfo[VKNETIF_MAX]; |
| 81 |
int NetifNum; |
|
| 82 |
int NetifNum = 0;
|
|
| 82 | 83 |
vm_offset_t KvaStart; |
| 83 | 84 |
vm_offset_t KvaEnd; |
| 84 | 85 |
vm_offset_t KvaSize; |
| ... | ... | |
| 104 | 105 |
static void init_kern_memory(void); |
| 105 | 106 |
static void init_globaldata(void); |
| 106 | 107 |
static void init_vkernel(void); |
| 107 |
static void init_rootdevice(char *imageFile);
|
|
| 108 |
static void init_netif(char *netifFile[], int netifFileNum);
|
|
| 108 |
static void init_vkd(char *vkdFile[], int vkdExpNum);
|
|
| 109 |
static void init_netif(char *netifExp[], int netifExpNum);
|
|
| 109 | 110 |
static void usage(const char *ctl); |
| 110 | 111 | |
| 111 | 112 |
/* |
| ... | ... | |
| 115 | 116 |
main(int ac, char **av) |
| 116 | 117 |
{
|
| 117 | 118 |
char *memImageFile = NULL; |
| 118 |
char *rootImageFile = NULL; |
|
| 119 | 119 |
char *netifFile[VKNETIF_MAX]; |
| 120 |
char *vkdFile[VKD_MAX]; |
|
| 120 | 121 |
char *suffix; |
| 121 | 122 |
int netifFileNum = 0; |
| 123 |
int vkdFileNum = 0; |
|
| 122 | 124 |
int c; |
| 123 | 125 |
int i; |
| 124 | 126 |
int n; |
| ... | ... | |
| 159 | 161 |
netifFile[netifFileNum++] = optarg; |
| 160 | 162 |
break; |
| 161 | 163 |
case 'r': |
| 162 |
rootImageFile = optarg; |
|
| 164 |
if ( vkdFileNum < VKD_MAX ) |
|
| 165 |
vkdFile[vkdFileNum++] = optarg; |
|
| 163 | 166 |
break; |
| 164 | 167 |
case 'm': |
| 165 | 168 |
Maxmem_bytes = strtoull(optarg, &suffix, 0); |
| ... | ... | |
| 197 | 200 |
init_globaldata(); |
| 198 | 201 |
init_vkernel(); |
| 199 | 202 |
init_kqueue(); |
| 200 |
init_rootdevice(rootImageFile);
|
|
| 203 |
init_vkd(vkdFile, vkdFileNum);
|
|
| 201 | 204 |
init_netif(netifFile, netifFileNum); |
| 202 | 205 |
init_exceptions(); |
| 203 | 206 |
mi_startup(); |
| ... | ... | |
| 538 | 541 |
} |
| 539 | 542 | |
| 540 | 543 |
/* |
| 541 |
* The root filesystem path for the virtual kernel is optional. If specified |
|
| 542 |
* it points to a filesystem image. |
|
| 544 |
* Filesystem image paths for the virtual kernel are optional. |
|
| 545 |
* If specified they each should point to a disk image, |
|
| 546 |
* the first of which will become the VKERNEL root disk. |
|
| 543 | 547 |
* |
| 544 | 548 |
* The virtual kernel caches data from our 'disk' just like a normal kernel, |
| 545 | 549 |
* so we do not really want the real kernel to cache the data too. Use |
| ... | ... | |
| 547 | 551 |
*/ |
| 548 | 552 |
static |
| 549 | 553 |
void |
| 550 |
init_rootdevice(char *imageFile)
|
|
| 554 |
init_vkd ( char *vkdExp[], int vkdExpNum )
|
|
| 551 | 555 |
{
|
| 552 |
struct stat st; |
|
| 556 |
int i; |
|
| 557 | ||
| 558 |
if (vkdExpNum == 0) |
|
| 559 |
return; |
|
| 560 | ||
| 561 |
for(i=0; i < vkdExpNum; i++){
|
|
| 562 |
char *fname; |
|
| 563 |
fname = vkdExp[i]; |
|
| 564 | ||
| 565 |
if (fname == NULL) {
|
|
| 566 |
warnx("Invalid argument to '-r'");
|
|
| 567 |
continue; |
|
| 568 |
} |
|
| 569 | ||
| 570 |
if (VkdNum < VKD_MAX ) {
|
|
| 571 |
struct stat st; |
|
| 572 |
struct vkd_info* info = NULL; |
|
| 573 |
int fd; |
|
| 574 |
size_t l = 0; |
|
| 575 | ||
| 576 |
fd = open(fname, O_RDWR|O_DIRECT, 0644); |
|
| 577 |
if (fd < 0 || fstat(fd, &st) < 0) {
|
|
| 578 |
err(1, "Unable to open/create %s: %s", |
|
| 579 |
fname, strerror(errno)); |
|
| 580 |
/* NOT REACHED */ |
|
| 581 |
} |
|
| 553 | 582 | |
| 554 |
if (imageFile) {
|
|
| 555 |
RootImageFd = open(imageFile, O_RDWR|O_DIRECT, 0644); |
|
| 556 |
if (RootImageFd < 0 || fstat(RootImageFd, &st) < 0) {
|
|
| 557 |
err(1, "Unable to open/create %s: %s", |
|
| 558 |
imageFile, strerror(errno)); |
|
| 559 |
/* NOT REACHED */ |
|
| 583 |
info = &VkdInfo[VkdNum]; |
|
| 584 |
l = strlen(fname); |
|
| 585 | ||
| 586 |
info->unit = i; |
|
| 587 |
info->fd = fd; |
|
| 588 |
memcpy(info->fname, fname, l); |
|
| 589 | ||
| 590 |
if(i == 0) |
|
| 591 |
rootdevnames[0] = "ufs:vkd0a"; |
|
| 592 | ||
| 593 |
VkdNum++; |
|
| 594 | ||
| 595 |
} |
|
| 596 |
else {
|
|
| 597 |
warnx("vkd%d (%s) > VKD_MAX",
|
|
| 598 |
VkdNum, fname); |
|
| 599 |
continue; |
|
| 560 | 600 |
} |
| 561 |
rootdevnames[0] = "ufs:vkd0a"; |
|
| 562 | 601 |
} |
| 563 | 602 |
} |
| 564 | 603 | |
| ... | ... | |
| 920 | 959 | |
| 921 | 960 |
netif = strtok(netifExp[i], ":"); |
| 922 | 961 |
if (netif == NULL) {
|
| 923 |
warnx("Invalide argument to '-I'");
|
|
| 962 |
warnx("Invalid argument to '-I'");
|
|
| 924 | 963 |
continue; |
| 925 | 964 |
} |
| 926 | 965 | |