Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


add backend device for direct host network bridge
[palacios.git] / palacios / src / devices / netdisk.c
index 521f543..479baeb 100644 (file)
 struct disk_state {
     uint64_t capacity; // in bytes
 
-    int socket;
+    v3_sock_t socket;
 
     uint32_t ip_addr;
     uint16_t port;
 
+    struct v3_vm_info * vm;
+
     char disk_name[32];
 
 };
 
 
-static int send_all(int socket, char * buf, int length) {
+static int send_all(v3_sock_t socket, char * buf, int length) {
     int bytes_sent = 0;
     
     PrintDebug("Sending %d bytes\n", length - bytes_sent);
     while (bytes_sent < length) {
-       int tmp_bytes = V3_Send(socket, buf + bytes_sent, length - bytes_sent);
+       int tmp_bytes = v3_socket_send(socket, buf + bytes_sent, length - bytes_sent);
        PrintDebug("Sent %d bytes\n", tmp_bytes);
        
        if (tmp_bytes == 0) {
@@ -68,12 +70,12 @@ static int send_all(int socket, char * buf, int length) {
 }
 
 
-static int recv_all(int socket, char * buf, int length) {
+static int recv_all(v3_sock_t socket, char * buf, int length) {
     int bytes_read = 0;
     
     PrintDebug("Reading %d bytes\n", length - bytes_read);
     while (bytes_read < length) {
-       int tmp_bytes = V3_Recv(socket, buf + bytes_read, length - bytes_read);
+       int tmp_bytes = v3_socket_recv(socket, buf + bytes_read, length - bytes_read);
        PrintDebug("Received %d bytes\n", tmp_bytes);
        
        if (tmp_bytes == 0) {
@@ -225,12 +227,12 @@ static int socket_init(struct disk_state * disk) {
     
     PrintDebug("Intializing Net Disk\n");
 
-    disk->socket = V3_Create_TCP_Socket();
+    disk->socket = v3_create_tcp_socket(disk->vm);
 
     PrintDebug("DISK socket: %d\n", disk->socket);
     PrintDebug("Connecting to: %s:%d\n", v3_inet_ntoa(disk->ip_addr), disk->port);
 
-    V3_Connect_To_IP(disk->socket, v3_ntohl(disk->ip_addr), disk->port);
+    v3_connect_to_ip(disk->socket, v3_ntohl(disk->ip_addr), disk->port);
 
     PrintDebug("Connected to NBD server\n");
 
@@ -276,7 +278,7 @@ static int disk_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
     char * ip_str = v3_cfg_val(cfg, "IP");
     char * port_str = v3_cfg_val(cfg, "port");
     char * disk_tag = v3_cfg_val(cfg, "tag");
-    char * name = v3_cfg_val(cfg, "name");
+    char * dev_id = v3_cfg_val(cfg, "ID");
 
     v3_cfg_tree_t * frontend_cfg = v3_cfg_subtree(cfg, "frontend");
 
@@ -285,11 +287,12 @@ static int disk_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
     strncpy(disk->disk_name, disk_tag, sizeof(disk->disk_name));
     disk->ip_addr = v3_inet_addr(ip_str);
     disk->port = atoi(port_str);
-       
-    struct vm_device * dev = v3_allocate_device(name, &dev_ops, disk);
+    disk->vm = vm;
+
+    struct vm_device * dev = v3_allocate_device(dev_id, &dev_ops, disk);
 
     if (v3_attach_device(vm, dev) == -1) {
-       PrintError("Could not attach device %s\n", name);
+       PrintError("Could not attach device %s\n", dev_id);
        return -1;
     }
 
@@ -302,7 +305,7 @@ static int disk_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
 
     if (v3_dev_connect_blk(vm, v3_cfg_val(frontend_cfg, "tag"), 
                           &blk_ops, frontend_cfg, disk) == -1) {
-       PrintError("Could not connect %s to frontend\n", name);
+       PrintError("Could not connect %s to frontend\n", dev_id);
        return -1;
     }