From: Jack Lange Date: Tue, 9 Nov 2010 00:19:00 +0000 (-0600) Subject: updated file interface X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=fbfbbc1eec7587e4555e7920c9b15129f90f8d80;p=palacios.git updated file interface --- diff --git a/palacios/include/palacios/vmm_file.h b/palacios/include/palacios/vmm_file.h index cac4c4d..7b0872c 100644 --- a/palacios/include/palacios/vmm_file.h +++ b/palacios/include/palacios/vmm_file.h @@ -26,39 +26,54 @@ #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); diff --git a/palacios/src/devices/filedisk.c b/palacios/src/devices/filedisk.c index ebaaaad..829252a 100644 --- a/palacios/src/devices/filedisk.c +++ b/palacios/src/devices/filedisk.c @@ -21,6 +21,7 @@ #include #include +#include #ifndef CONFIG_DEBUG_FILEDISK #undef PrintDebug @@ -30,12 +31,12 @@ 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;