X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Fsrc%2Fdevices%2Fnet_hd.c;h=08947972826ca566040bb83ba221468b1bbabb06;hb=82b8b87c344fcd1eab22e3f3be5ad54cbb3f8f68;hp=26f1d6cf35eb4c42c7ab8a0d51b409b874cc52a6;hpb=153204955413dcb12b2156fc80bdda6e275009b9;p=palacios.git diff --git a/palacios/src/devices/net_hd.c b/palacios/src/devices/net_hd.c index 26f1d6c..0894797 100644 --- a/palacios/src/devices/net_hd.c +++ b/palacios/src/devices/net_hd.c @@ -22,7 +22,7 @@ #include #include -#ifndef DEBUG_IDE +#ifndef CONFIG_DEBUG_IDE #undef PrintDebug #define PrintDebug(fmt, args...) #endif @@ -97,8 +97,8 @@ static int recv_all(int socket, char * buf, int length) { static int hd_read(uint8_t * buf, int sector_count, uint64_t lba, void * private_data) { struct vm_device * hd_dev = (struct vm_device *)private_data; struct hd_state * hd = (struct hd_state *)(hd_dev->private_data); - int offset = lba * IDE_SECTOR_SIZE; - int length = sector_count * IDE_SECTOR_SIZE; + int offset = lba * HD_SECTOR_SIZE; + int length = sector_count * HD_SECTOR_SIZE; uint8_t status; uint32_t ret_len = 0; char nbd_cmd[4] = {0,0,0,0}; @@ -156,8 +156,8 @@ static int hd_read(uint8_t * buf, int sector_count, uint64_t lba, void * privat static int hd_write(uint8_t * buf, int sector_count, uint64_t lba, void * private_data) { struct vm_device * hd_dev = (struct vm_device *)private_data; struct hd_state * hd = (struct hd_state *)(hd_dev->private_data); - int offset = lba * IDE_SECTOR_SIZE; - int length = sector_count * IDE_SECTOR_SIZE; + int offset = lba * HD_SECTOR_SIZE; + int length = sector_count * HD_SECTOR_SIZE; uint8_t status; char nbd_cmd[4] = {0,0,0,0}; @@ -203,18 +203,32 @@ static uint64_t hd_get_capacity(void * private_data) { struct vm_device * hd_dev = (struct vm_device *)private_data; struct hd_state * hd = (struct hd_state *)(hd_dev->private_data); - return hd->capacity / IDE_SECTOR_SIZE; + return hd->capacity / HD_SECTOR_SIZE; } -static struct v3_ide_hd_ops hd_ops = { +static struct v3_hd_ops hd_ops = { .read = hd_read, .write = hd_write, .get_capacity = hd_get_capacity, }; -static int hd_init(struct vm_device * dev) { - struct hd_state * hd = (struct hd_state *)(dev->private_data); + + + +static int hd_free(struct vm_device * dev) { + return 0; +} + +static struct v3_device_ops dev_ops = { + .free = hd_free, + .reset = NULL, + .start = NULL, + .stop = NULL, +}; + + +static int socket_init(struct hd_state * hd) { char header[64]; PrintDebug("Intializing Net HD\n"); @@ -258,47 +272,55 @@ static int hd_init(struct vm_device * dev) { PrintDebug("Capacity: %p\n", (void *)(hd->capacity)); } - PrintDebug("Registering HD\n"); - if (v3_ide_register_harddisk(hd->ide, hd->bus, hd->drive, "V3-NET-HD", &hd_ops, dev) == -1) { - return -1; - } - - PrintDebug("intialization done\n"); return 0; } -static int hd_deinit(struct vm_device * dev) { - return 0; -} +static int hd_init(struct guest_info * vm, void * cfg_data) { + struct hd_state * hd = (struct hd_state *)V3_Malloc(sizeof(struct hd_state)); + struct net_hd_cfg * cfg = (struct net_hd_cfg *)cfg_data; -static struct vm_device_ops dev_ops = { - .init = hd_init, - .deinit = hd_deinit, - .reset = NULL, - .start = NULL, - .stop = NULL, -}; + PrintDebug("Registering Net HD at %s:%d disk=%s\n", cfg->ip_str, cfg->port, cfg->disk_tag); -struct vm_device * v3_create_net_hd(struct vm_device * ide, - uint_t bus, uint_t drive, - const char * ip_str, uint16_t port, - const char * disk_tag) { - struct hd_state * hd = (struct hd_state *)V3_Malloc(sizeof(struct hd_state)); + strncpy(hd->disk_name, cfg->disk_tag, sizeof(hd->disk_name)); + hd->ip_addr = v3_inet_addr(cfg->ip_str); + hd->port = cfg->port; - PrintDebug("Registering Net HD at %s:%d disk=%s\n", ip_str, port, disk_tag); + hd->ide = v3_find_dev(vm, cfg->ide); - strncpy(hd->disk_name, disk_tag, sizeof(hd->disk_name)); - hd->ip_addr = v3_inet_addr(ip_str); - hd->port = port; + if (hd->ide == 0) { + PrintError("Could not find backend %s\n", cfg->ide); + return -1; + } - hd->ide = ide; - hd->bus = bus; - hd->drive = drive; + hd->bus = cfg->bus; + hd->drive = cfg->drive; - struct vm_device * hd_dev = v3_create_device("NET-HD", &dev_ops, hd); + struct vm_device * dev = v3_allocate_device("NET-HD", &dev_ops, hd); + + if (v3_attach_device(vm, dev) == -1) { + PrintError("Could not attach device %s\n", "NET-HD"); + return -1; + } + + if (socket_init(hd) == -1) { + PrintError("could not initialize network connection\n"); + return -1; + } + - return hd_dev; + PrintDebug("Registering HD\n"); + + if (v3_ide_register_harddisk(hd->ide, hd->bus, hd->drive, "V3-NET-HD", &hd_ops, dev) == -1) { + return -1; + } + + PrintDebug("intialization done\n"); + + return 0; } + + +device_register("NET-HD", hd_init)