Project

General

Profile

Bug #541 ยป multi-vkd.patch

c.turner, 01/28/2007 02:08 AM

View differences:

dev/virtual/disk/vdisk.c 27 Jan 2007 23:00:38 -0000
int fd;
};
#define CDEV_MAJOR 97
static d_strategy_t vkdstrategy;
......
static void
vkdinit(void *dummy __unused)
{
int vkd_iter = 0;
struct vkd_info *myslot;
struct vkd_softc *sc;
struct stat st;
if (RootImageFd < 0 || fstat(RootImageFd, &st) < 0)
return;
KASSERT(VkdNum <= VKD_MAX, ("too many vkd's: %d\n", NetifNum));
for (vkd_iter = 0; vkd_iter < VkdNum; vkd_iter++) {
/* check that the 'bus device' has been initialized */
myslot = (struct vkd_info*) NULL;
myslot = &VkdInfo[vkd_iter];
if (myslot == NULL)
continue;
if (myslot->fd < 0 || fstat(myslot->fd, &st) < 0)
continue;
/* and create a new device */
sc = NULL;
sc = kmalloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
sc->unit = myslot->unit;
sc->fd = myslot->fd;
bioq_init(&sc->bio_queue);
devstat_add_entry(&sc->stats, "vkd", sc->unit, DEV_BSIZE,
DEVSTAT_NO_ORDERED_TAGS,
DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_OTHER,
DEVSTAT_PRIORITY_DISK);
sc->dev = disk_create(sc->unit, &sc->disk, 0, &vkd_ops);
sc->dev->si_drv1 = sc;
sc->dev->si_iosize_max = 256 * 1024;
sc = kmalloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO);
sc->unit = 0;
sc->fd = RootImageFd;
bioq_init(&sc->bio_queue);
devstat_add_entry(&sc->stats, "vkd", sc->unit, DEV_BSIZE,
DEVSTAT_NO_ORDERED_TAGS,
DEVSTAT_TYPE_DIRECT | DEVSTAT_TYPE_IF_OTHER,
DEVSTAT_PRIORITY_DISK);
sc->dev = disk_create(sc->unit, &sc->disk, 0, &vkd_ops);
sc->dev->si_drv1 = sc;
sc->dev->si_iosize_max = 256 * 1024;
/* not sure why if 0'ed in v1.2... kept here for fun. */
#if 0
dl = &sc->disk.d_label;
bzero(dl, sizeof(*dl));
dl->d_secsize = DEV_BSIZE;
dl->d_nsectors = st.st_size / dl->d_secsize;
dl->d_ntracks = 1;
dl->d_secpercyl = dl->d_nsectors;
dl->d_ncylinders = 1;
dl = &sc->disk.d_label;
bzero(dl, sizeof(*dl));
dl->d_secsize = DEV_BSIZE;
dl->d_nsectors = st.st_size / dl->d_secsize;
dl->d_ntracks = 1;
dl->d_secpercyl = dl->d_nsectors;
dl->d_ncylinders = 1;
#endif
}
}
SYSINIT(vkdisk, SI_SUB_DRIVERS, SI_ORDER_FIRST, vkdinit, NULL);
......
dev = ap->a_head.a_dev;
sc = dev->si_drv1;
if (sc->unit != 0)
return(ENXIO);
if (fstat(sc->fd, &st) < 0 || st.st_size == 0)
return(ENXIO);
platform/vkernel/include/md_var.h 27 Jan 2007 20:04:17 -0000
#endif
#define VKNETIF_MAX 16
#define VKD_MAX 16
struct vknetif_info {
int tap_fd;
......
in_addr_t netif_mask;
};
struct vkd_info {
int fd;
int unit;
char fname[MAXPATHLEN];
};
extern char sigcode[];
extern int szsigcode;
extern vpte_t *KernelPTA; /* NOTE: Offset for direct VA translation */
......
extern char cpu_vendor[]; /* XXX belongs in i386 */
extern u_int cpu_id; /* XXX belongs in i386 */
extern int RootImageFd;
extern struct vkd_info VkdInfo[VKD_MAX];
extern int VkdNum;
extern int MemImageFd;
extern int KQueueFd;
extern struct vknetif_info NetifInfo[VKNETIF_MAX];
platform/vkernel/platform/init.c 27 Jan 2007 22:44:41 -0000
vm_paddr_t Maxmem;
vm_paddr_t Maxmem_bytes;
int MemImageFd = -1;
int RootImageFd = -1;
struct vkd_info VkdInfo[VKD_MAX];
int VkdNum = 0;
struct vknetif_info NetifInfo[VKNETIF_MAX];
int NetifNum;
int NetifNum = 0;
vm_offset_t KvaStart;
vm_offset_t KvaEnd;
vm_offset_t KvaSize;
......
static void init_kern_memory(void);
static void init_globaldata(void);
static void init_vkernel(void);
static void init_rootdevice(char *imageFile);
static void init_netif(char *netifFile[], int netifFileNum);
static void init_vkd(char *vkdFile[], int vkdExpNum);
static void init_netif(char *netifExp[], int netifExpNum);
static void usage(const char *ctl);
/*
......
main(int ac, char **av)
{
char *memImageFile = NULL;
char *rootImageFile = NULL;
char *netifFile[VKNETIF_MAX];
char *vkdFile[VKD_MAX];
char *suffix;
int netifFileNum = 0;
int vkdFileNum = 0;
int c;
int i;
int n;
......
netifFile[netifFileNum++] = optarg;
break;
case 'r':
rootImageFile = optarg;
if ( vkdFileNum < VKD_MAX )
vkdFile[vkdFileNum++] = optarg;
break;
case 'm':
Maxmem_bytes = strtoull(optarg, &suffix, 0);
......
init_globaldata();
init_vkernel();
init_kqueue();
init_rootdevice(rootImageFile);
init_vkd(vkdFile, vkdFileNum);
init_netif(netifFile, netifFileNum);
init_exceptions();
mi_startup();
......
}
/*
* The root filesystem path for the virtual kernel is optional. If specified
* it points to a filesystem image.
* Filesystem image paths for the virtual kernel are optional.
* If specified they each should point to a disk image,
* the first of which will become the VKERNEL root disk.
*
* The virtual kernel caches data from our 'disk' just like a normal kernel,
* so we do not really want the real kernel to cache the data too. Use
......
*/
static
void
init_rootdevice(char *imageFile)
init_vkd ( char *vkdExp[], int vkdExpNum )
{
struct stat st;
int i;
if (vkdExpNum == 0)
return;
for(i=0; i < vkdExpNum; i++){
char *fname;
fname = vkdExp[i];
if (fname == NULL) {
warnx("Invalid argument to '-r'");
continue;
}
if (VkdNum < VKD_MAX ) {
struct stat st;
struct vkd_info* info = NULL;
int fd;
size_t l = 0;
fd = open(fname, O_RDWR|O_DIRECT, 0644);
if (fd < 0 || fstat(fd, &st) < 0) {
err(1, "Unable to open/create %s: %s",
fname, strerror(errno));
/* NOT REACHED */
}
if (imageFile) {
RootImageFd = open(imageFile, O_RDWR|O_DIRECT, 0644);
if (RootImageFd < 0 || fstat(RootImageFd, &st) < 0) {
err(1, "Unable to open/create %s: %s",
imageFile, strerror(errno));
/* NOT REACHED */
info = &VkdInfo[VkdNum];
l = strlen(fname);
info->unit = i;
info->fd = fd;
memcpy(info->fname, fname, l);
if(i == 0)
rootdevnames[0] = "ufs:vkd0a";
VkdNum++;
}
else {
warnx("vkd%d (%s) > VKD_MAX",
VkdNum, fname);
continue;
}
rootdevnames[0] = "ufs:vkd0a";
}
}
......
netif = strtok(netifExp[i], ":");
if (netif == NULL) {
warnx("Invalide argument to '-I'");
warnx("Invalid argument to '-I'");
continue;
}
    (1-1/1)