From: Jack Lange Date: Thu, 18 Nov 2010 19:18:23 +0000 (-0600) Subject: updated file interface X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=dadac9c02898a50c7c128d4bbcef39a0e339aa8c;p=palacios.git updated file interface --- diff --git a/palacios/include/palacios/vmm_file.h b/palacios/include/palacios/vmm_file.h index 7b0872c..9776913 100644 --- a/palacios/include/palacios/vmm_file.h +++ b/palacios/include/palacios/vmm_file.h @@ -25,57 +25,15 @@ #ifdef __V3VEE__ +typedef void * v3_file_t; -#define V3_FileOpen(path, mode, host_data) \ - ({ \ - void * fd = NULL; \ - extern struct v3_file_hooks * file_hooks; \ - 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; \ - 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; \ - 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; \ - 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; \ - if ((file_hooks) && (file_hooks)->file_write) { \ - ret = (file_hooks)->file_write((fd), (buf), (len), (start)); \ - } \ - ret; \ - }) +v3_file_t v3_file_open(struct v3_vm_info * vm, char * path, uint8_t mode); +int v3_file_close(v3_file_t file); +uint64_t v3_file_size(v3_file_t file); + +uint64_t v3_file_read(v3_file_t file, uint8_t * buf, uint64_t len, uint64_t off); +uint64_t v3_file_write(v3_file_t file, uint8_t * buf, uint64_t len, uint64_t off); #endif @@ -84,14 +42,14 @@ struct v3_file_hooks { - void * (*file_open)(const char * path, int mode, void * host_data); - int (*file_close)(void * fd); + void * (*open)(const char * path, int mode, void * host_data); + int (*close)(void * fd); - long long (*file_size)(void * fd); + long long (*size)(void * fd); // blocking reads and writes - long long (*file_read)(void * fd, void * buffer, long long length, long long offset); - long long (*file_write)(void * fd, void * buffer, long long length, long long offset); + long long (*read)(void * fd, void * buffer, long long length, long long offset); + long long (*write)(void * fd, void * buffer, long long length, long long offset); }; diff --git a/palacios/src/devices/filedisk.c b/palacios/src/devices/filedisk.c index 829252a..44ec18c 100644 --- a/palacios/src/devices/filedisk.c +++ b/palacios/src/devices/filedisk.c @@ -31,17 +31,17 @@ struct disk_state { uint64_t capacity; // in bytes - void * fd; + v3_file_t fd; }; -static int write_all(void * fd, char * buf, int offset, int length) { +static int write_all(v3_file_t fd, char * buf, int offset, int length) { int bytes_written = 0; PrintDebug("Writing %d bytes\n", length - bytes_written); while (bytes_written < length) { - int tmp_bytes = V3_FileWrite(fd, offset+bytes_written, buf + bytes_written, length - bytes_written); + int tmp_bytes = v3_file_write(fd, buf + bytes_written, offset + bytes_written, length - bytes_written); PrintDebug("Wrote %d bytes\n", tmp_bytes); if (tmp_bytes <= 0 ) { @@ -56,12 +56,12 @@ static int write_all(void * fd, char * buf, int offset, int length) { } -static int read_all(void * fd, char * buf, int offset, int length) { +static int read_all(v3_file_t fd, char * buf, int offset, int length) { int bytes_read = 0; PrintDebug("Reading %d bytes\n", length - bytes_read); while (bytes_read < length) { - int tmp_bytes = V3_FileRead(fd, offset+bytes_read, buf + bytes_read, length - bytes_read); + int tmp_bytes = v3_file_read(fd, buf + bytes_read, offset + bytes_read, length - bytes_read); PrintDebug("Read %d bytes\n", tmp_bytes); if (tmp_bytes <= 0) { @@ -149,18 +149,18 @@ static int disk_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { } if ( (allowRead == 1) && (allowWrite == 1) ) { - disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_READ | FILE_OPEN_MODE_WRITE, vm->host_priv_data ); + disk->fd = v3_file_open(vm, path, FILE_OPEN_MODE_READ | FILE_OPEN_MODE_WRITE ); } else if ( (allowRead == 1) && (allowWrite == 0) ) { - disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_READ, vm->host_priv_data ); + disk->fd = v3_file_open(vm, path, FILE_OPEN_MODE_READ); } else if ( (allowRead == 0) && (allowWrite == 1) ) { - disk->fd = V3_FileOpen(path, FILE_OPEN_MODE_WRITE, vm->host_priv_data ); + disk->fd = v3_file_open(vm, path, FILE_OPEN_MODE_WRITE); } else { PrintError("Error on %s: No file mode specified\n", dev_id ); return -1; } - disk->capacity = V3_FileSize(disk->fd); + disk->capacity = v3_file_size(disk->fd); PrintDebug("Registering FILEDISK %s (path=%s, fd=%lu, size=%lu)\n", dev_id, path, file->fd, file->capacity); diff --git a/palacios/src/palacios/vmm_file.c b/palacios/src/palacios/vmm_file.c index ada9972..e0e9a54 100644 --- a/palacios/src/palacios/vmm_file.c +++ b/palacios/src/palacios/vmm_file.c @@ -22,9 +22,9 @@ #include #include #include +#include - -struct v3_file_hooks * file_hooks = 0; +static struct v3_file_hooks * file_hooks = NULL; void V3_Init_File(struct v3_file_hooks * hooks) { file_hooks = hooks; @@ -32,3 +32,45 @@ void V3_Init_File(struct v3_file_hooks * hooks) { return; } + + +v3_file_t v3_file_open(struct v3_vm_info * vm, char * path, uint8_t mode) { + V3_ASSERT(file_hooks); + V3_ASSERT(file_hooks->open); + void * priv_data = NULL; + + if (vm) { + priv_data = vm->host_priv_data; + } + + return file_hooks->open(path, mode, priv_data); +} + +int v3_file_close(v3_file_t file) { + V3_ASSERT(file_hooks); + V3_ASSERT(file_hooks->open); + + return file_hooks->close(file); +} + +uint64_t v3_file_size(v3_file_t file) { + V3_ASSERT(file_hooks); + V3_ASSERT(file_hooks->size); + + return file_hooks->size(file); +} + +uint64_t v3_file_read(v3_file_t file, uint8_t * buf, uint64_t len, uint64_t off) { + V3_ASSERT(file_hooks); + V3_ASSERT(file_hooks->read); + + return file_hooks->read(file, buf, len, off); +} + + +uint64_t v3_file_write(v3_file_t file, uint8_t * buf, uint64_t len, uint64_t off) { + V3_ASSERT(file_hooks); + V3_ASSERT(file_hooks->write); + + return file_hooks->write(file, buf, len, off); +} diff --git a/palacios/src/palacios/vmm_socket.c b/palacios/src/palacios/vmm_socket.c index c39fb5e..683f6e4 100644 --- a/palacios/src/palacios/vmm_socket.c +++ b/palacios/src/palacios/vmm_socket.c @@ -207,15 +207,25 @@ uint32_t v3_ntohl(uint32_t n) { v3_sock_t v3_create_udp_socket(struct v3_vm_info * vm) { V3_ASSERT(sock_hooks); V3_ASSERT(sock_hooks->udp_socket); + void * priv_data = NULL; + + if (vm) { + priv_data = vm->host_priv_data; + } - return sock_hooks->udp_socket(0, 0, vm->host_priv_data); + return sock_hooks->udp_socket(0, 0, priv_data); } v3_sock_t v3_create_tcp_socket(struct v3_vm_info * vm) { V3_ASSERT(sock_hooks); V3_ASSERT(sock_hooks->tcp_socket); - - return sock_hooks->tcp_socket(0, 1, 0, vm->host_priv_data); + void * priv_data = NULL; + + if (vm) { + priv_data = vm->host_priv_data; + } + + return sock_hooks->tcp_socket(0, 1, 0, priv_data); } void v3_socket_close(v3_sock_t sock) {