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.


updated file interface
Jack Lange [Tue, 9 Nov 2010 00:19:00 +0000 (18:19 -0600)]
palacios/include/palacios/vmm_file.h
palacios/src/devices/filedisk.c

index cac4c4d..7b0872c 100644 (file)
 
 #ifdef __V3VEE__
 
-#define V3_FileOpen(path, mode)                                                \
+#define V3_FileOpen(path, mode, host_data)                             \
     ({                                                                 \
+       void * fd = NULL;                                               \
        extern struct v3_file_hooks * file_hooks;                       \
-       ((file_hooks) && (file_hooks)->file_open) ?                     \
-           (file_hooks)->file_open((path), (mode)) : -1;               \
+       if ((file_hooks) && (file_hooks)->file_open) {                  \
+           fd = (file_hooks)->file_open((path), (mode), (host_data));  \
+       }                                                               \
+       fd;                                                             \
     })
 
 #define V3_FileClose(fd)                                               \
     ({                                                                 \
+       int ret = 0;                                                    \
        extern struct v3_file_hooks * file_hooks;                       \
-       ((file_hooks) && (file_hooks)->file_close) ?                    \
-           (file_hooks)->file_close((fd))  :  -1;                      \
+       if ((file_hooks) && (file_hooks)->file_close) {                 \
+           ret = (file_hooks)->file_close((fd));                       \
+       }                                                               \
+       ret;                                                            \
     })
 
 #define V3_FileSize(fd)                                                        \
     ({                                                                 \
+       long long size = -1;                                            \
        extern struct v3_file_hooks * file_hooks;                       \
-       ((file_hooks) && (file_hooks)->file_size) ?                     \
-           (file_hooks)->file_size((fd))  : -1;                        \
+       if ((file_hooks) && (file_hooks)->file_size) {                  \
+           size = (file_hooks)->file_size((fd));                       \
+       }                                                               \
+       size;                                                           \
     })
 
 #define V3_FileRead(fd, start, buf, len)                               \
     ({                                                                 \
+       long long ret = -1;                                             \
        extern struct v3_file_hooks * file_hooks;                       \
-       ((file_hooks) && (file_hooks)->file_read) ?                     \
-           (file_hooks)->file_read((fd), (buf), (len), (start)) : -1;  \
+       if ((file_hooks) && (file_hooks)->file_read) {                  \
+           ret = (file_hooks)->file_read((fd), (buf), (len), (start)); \
+       }                                                               \
+       ret;                                                            \
     })
 
 #define V3_FileWrite(fd,start,buf,len)                                 \
     ({                                                                 \
+       long long ret = -1;                                             \
        extern struct v3_file_hooks * file_hooks;                       \
-       ((file_hooks) && (file_hooks)->file_write) ?                    \
-           (file_hooks)->file_write((fd), (buf), (len), (start)) : -1; \
+       if ((file_hooks) && (file_hooks)->file_write) {                 \
+           ret = (file_hooks)->file_write((fd), (buf), (len), (start)); \
+       }                                                               \
+       ret;                                                            \
     })
 
 
@@ -69,7 +84,7 @@
 
 struct v3_file_hooks {
 
-    void (*file_open)(const char * path, int mode, void * host_data);
+    void * (*file_open)(const char * path, int mode, void * host_data);
     int (*file_close)(void * fd);
 
     long long (*file_size)(void * fd);
index ebaaaad..829252a 100644 (file)
@@ -21,6 +21,7 @@
 #include <palacios/vmm_dev_mgr.h>
 
 #include <palacios/vmm_file.h>
+#include <palacios/vm_guest.h>
 
 #ifndef CONFIG_DEBUG_FILEDISK
 #undef PrintDebug
 struct disk_state {
     uint64_t capacity; // in bytes
 
-    int fd;
+    void * fd;
 };
 
 
 
-static int write_all(int fd, char * buf, int offset, int length) {
+static int write_all(void * fd, char * buf, int offset, int length) {
     int bytes_written = 0;
     
     PrintDebug("Writing %d bytes\n", length - bytes_written);
@@ -55,7 +56,7 @@ static int write_all(int fd, char * buf, int offset, int length) {
 }
 
 
-static int read_all(int fd, char * buf, int offset, int length) {
+static int read_all(void * fd, char * buf, int offset, int length) {
     int bytes_read = 0;
     
     PrintDebug("Reading %d bytes\n", length - bytes_read);
@@ -127,11 +128,8 @@ static struct v3_device_ops dev_ops = {
 static int disk_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
     struct disk_state * disk = NULL;
     char * path = v3_cfg_val(cfg, "path");
-
     char * dev_id = v3_cfg_val(cfg, "ID");
 
-
-
     char * writable = v3_cfg_val(cfg, "writable");
     char * readable = v3_cfg_val(cfg, "readable");
     
@@ -144,20 +142,18 @@ static int disk_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) {
     memset(disk, 0, sizeof(struct disk_state));
 
 
-    if (!path) {
-
-
+    if (path == NULL) {
        PrintError("Missing path (%s) for %s\n", path, dev_id);
        return -1;
 
     }
     
-    if ( allowRead && allowWrite ) {
-       disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_READ | FILE_OPEN_MODE_WRITE );
-    } else if ( allowRead && !allowWrite ) {
-       disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_READ );
-    } else if ( !allowRead && allowWrite ) {
-       disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_WRITE );
+    if ( (allowRead == 1) && (allowWrite == 1) ) {
+       disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_READ | FILE_OPEN_MODE_WRITE, vm->host_priv_data );
+    } else if ( (allowRead == 1) && (allowWrite == 0) ) {
+       disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_READ, vm->host_priv_data );
+    } else if ( (allowRead == 0) && (allowWrite == 1) ) {
+       disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_WRITE, vm->host_priv_data );
     } else {
        PrintError("Error on %s: No file mode specified\n", dev_id );
        return -1;