#include <linux/file.h>
#include <linux/uaccess.h>
#include <linux/namei.h>
-#include <linux/vmalloc.h>
#include <linux/poll.h>
#include <linux/anon_inodes.h>
}
- m->data = vmalloc(size);
+ m->data = palacios_valloc(size);
if (!m->data) {
palacios_free(m);
{
if (m) {
if (m->data) {
- vfree(m->data);
+ palacios_vfree(m->data);
}
m->data=0;
palacios_free(m);
static int expand_mem_stream(struct mem_stream *m, uint32_t new_size)
{
- void *data = vmalloc(new_size);
+ void *data = palacios_valloc(new_size);
uint32_t nc;
if (!data) {
memcpy(data,m->data,nc);
- vfree(m->data);
+ palacios_vfree(m->data);
m->data=data;
m->size=new_size;
de = lookup_create(&nd,1);
- if (IS_ERR(de)) {
+ if (!de || IS_ERR(de)) {
ERROR("cannot allocate dentry\n");
goto fail_out;
}
strcat(path,"/");
strcat(path,key);
- fs = (struct file_stream *) palacios_alloc(sizeof(struct file_stream *));
+ fs = (struct file_stream *) palacios_alloc(sizeof(struct file_stream));
if (!fs) {
ERROR("cannot allocate file keyed stream for key %s\n",key);
fs->stype=STREAM_FILE;
- fs->f = filp_open(path,O_RDWR|O_CREAT,0600);
-
- if (IS_ERR(fs->f)) {
+ fs->f = filp_open(path,O_RDWR|O_CREAT|O_LARGEFILE,0600);
+
+ if (!fs->f || IS_ERR(fs->f)) {
ERROR("cannot open relevent file \"%s\" for stream \"file:%s\" and key \"%s\"\n",path,fks->path,key);
palacios_free(fs);
palacios_free(path);
}
- if (token_scan(ms,tempkey,keylen+3," \t\r\n",4)) {
+ if (token_scan(ms,tempkey,keylen+3,"\t\r\n",3)) {
ERROR("Cannot scan for token (key search)\n");
close_key_file(mks,ms);
mks->stype=STREAM_TEXTFILE;
s->waiting = 1;
// release the stream
- spin_unlock_irqrestore(&(s->lock), *flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), *flags);
// wake up anyone waiting on it
wake_up_interruptible(&(s->user_wait_queue));
while (wait_event_interruptible(s->host_wait_queue, (s->waiting == 0)) != 0) {}
// reacquire the lock for our called
- spin_lock_irqsave(&(s->lock), *flags);
+ palacios_spinlock_lock_irqsave(&(s->lock), *flags);
return 0;
}
s->waiting = 0;
// release the stream
- spin_unlock_irqrestore(&(s->lock), *flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), *flags);
// wake up anyone waiting on it
wake_up_interruptible(&(s->host_wait_queue));
return POLLERR;
}
- spin_lock_irqsave(&(s->lock), flags);
+ palacios_spinlock_lock_irqsave(&(s->lock), flags);
+
+ poll_wait(filp, &(s->user_wait_queue), wait);
if (s->waiting) {
- spin_unlock_irqrestore(&(s->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), flags);
return POLLIN | POLLRDNORM;
}
-
- poll_wait(filp, &(s->user_wait_queue), wait);
- spin_unlock_irqrestore(&(s->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), flags);
return 0;
}
// inform request size
- spin_lock_irqsave(&(s->lock), flags);
+ palacios_spinlock_lock_irqsave(&(s->lock), flags);
if (!(s->waiting)) {
- spin_unlock_irqrestore(&(s->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), flags);
return 0;
}
size = sizeof(struct palacios_user_keyed_stream_op) + s->op->buf_len;
if (copy_to_user((void * __user) argp, &size, sizeof(uint64_t))) {
- spin_unlock_irqrestore(&(s->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), flags);
ERROR("palacios user key size request failed to copy data\n");
return -EFAULT;
}
- spin_unlock_irqrestore(&(s->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), flags);
return 1;
// pull the request
- spin_lock_irqsave(&(s->lock), flags);
+ palacios_spinlock_lock_irqsave(&(s->lock), flags);
if (!(s->waiting)) {
- spin_unlock_irqrestore(&(s->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), flags);
ERROR("palacios user key pull request when not waiting\n");
return 0;
}
if (copy_to_user((void __user *) argp, s->op, size)) {
- spin_unlock_irqrestore(&(s->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), flags);
ERROR("palacios user key pull request failed to copy data\n");
return -EFAULT;
}
- spin_unlock_irqrestore(&(s->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), flags);
return 1;
// push the response
- spin_lock_irqsave(&(s->lock), flags);
+ palacios_spinlock_lock_irqsave(&(s->lock), flags);
if (!(s->waiting)) {
- spin_unlock_irqrestore(&(s->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), flags);
ERROR("palacios user key push response when not waiting\n");
return 0;
}
if (copy_from_user(&size, (void __user *) argp, sizeof(uint64_t))) {
ERROR("palacios user key push response failed to copy size\n");
- spin_unlock_irqrestore(&(s->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), flags);
return -EFAULT;
}
if (resize_op(&(s->op),size-sizeof(struct palacios_user_keyed_stream_op))) {
ERROR("unable to resize op in user key push response\n");
- spin_unlock_irqrestore(&(s->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), flags);
return -EFAULT;
}
if (copy_from_user(s->op, (void __user *) argp, size)) {
- spin_unlock_irqrestore(&(s->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), flags);
return -EFAULT;
}
struct user_keyed_stream *s = filp->private_data;
unsigned long f1,f2;
- spin_lock_irqsave(&(user_streams->lock),f1);
- spin_lock_irqsave(&(s->lock), f2);
+ palacios_spinlock_lock_irqsave(&(user_streams->lock),f1);
+ palacios_spinlock_lock_irqsave(&(s->lock), f2);
list_del(&(s->node));
- spin_unlock_irqrestore(&(s->lock), f2);
- spin_unlock_irqrestore(&(user_streams->lock), f1);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), f2);
+ palacios_spinlock_unlock_irqrestore(&(user_streams->lock), f1);
palacios_free(s->url);
palacios_free(s);
// Check for duplicate handler
- spin_lock_irqsave(&(user_streams->lock), flags);
+ palacios_spinlock_lock_irqsave(&(user_streams->lock), flags);
list_for_each_entry(s, &(user_streams->streams), node) {
if (!strncasecmp(url, s->url, len)) {
ERROR("user keyed stream connection with url \"%s\" already exists\n", url);
return -1;
}
}
- spin_unlock_irqrestore(&(user_streams->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(user_streams->lock), flags);
// Create connection
s = palacios_alloc(sizeof(struct user_keyed_stream));
init_waitqueue_head(&(s->host_wait_queue));
// Insert connection into list
- spin_lock_irqsave(&(user_streams->lock), flags);
+ palacios_spinlock_lock_irqsave(&(user_streams->lock), flags);
list_add(&(s->node), &(user_streams->streams));
- spin_unlock_irqrestore(&(user_streams->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(user_streams->lock), flags);
return fd;
}
return NULL;
}
- spin_lock_irqsave(&(user_streams->lock), flags);
+ palacios_spinlock_lock_irqsave(&(user_streams->lock), flags);
list_for_each_entry(s, &(user_streams->streams), node) {
if (!strcasecmp(url, s->url)) {
- spin_unlock_irqrestore(&(user_streams->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(user_streams->lock), flags);
return s;
}
}
- spin_unlock_irqrestore(&(user_streams->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(user_streams->lock), flags);
return NULL;
}
return NULL;
}
- spin_lock_irqsave(&(s->lock), flags);
+ palacios_spinlock_lock_irqsave(&(s->lock), flags);
if (s->waiting) {
- spin_unlock_irqrestore(&(s->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), flags);
ERROR("cannot open user stream %s as it is already in waiting state\n",url);
return NULL;
}
s->otype = ot==V3_KS_WR_ONLY_CREATE ? V3_KS_WR_ONLY : ot;
- spin_unlock_irqrestore(&(s->lock), flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock), flags);
return s;
uint64_t len = strlen(key)+1;
void *user_key;
- spin_lock_irqsave(&(s->lock), flags);
+ palacios_spinlock_lock_irqsave(&(s->lock), flags);
if (resize_op(&(s->op),len)) {
- spin_unlock_irqrestore(&(s->lock),flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock),flags);
ERROR("cannot resize op in opening key %s on user keyed stream %s\n",key,s->url);
return NULL;
}
// enter with it locked
if (do_request_to_response(s,&flags)) {
- spin_unlock_irqrestore(&(s->lock),flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock),flags);
ERROR("request/response handling failed\n");
return NULL;
}
user_key=s->op->user_key;
- spin_unlock_irqrestore(&(s->lock),flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock),flags);
return user_key;
}
uint64_t len = 0;
unsigned long flags;
- spin_lock_irqsave(&(s->lock), flags);
+ palacios_spinlock_lock_irqsave(&(s->lock), flags);
if (resize_op(&(s->op),len)) {
- spin_unlock_irqrestore(&(s->lock),flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock),flags);
ERROR("cannot resize op in closing key 0x%p on user keyed stream %s\n",key,s->url);
return;
}
// enter with it locked
if (do_request_to_response(s,&flags)) {
- spin_unlock_irqrestore(&(s->lock),flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock),flags);
ERROR("request/response handling failed\n");
return;
}
// return with it locked
- spin_unlock_irqrestore(&(s->lock),flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock),flags);
return;
}
sint64_t xfer;
unsigned long flags;
- spin_lock_irqsave(&(s->lock), flags);
+ palacios_spinlock_lock_irqsave(&(s->lock), flags);
if (s->otype != V3_KS_RD_ONLY) {
- spin_unlock_irqrestore(&(s->lock),flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock),flags);
ERROR("attempt to read key from stream that is not in read state on %s\n",s->url);
}
if (resize_op(&(s->op),len)) {
- spin_unlock_irqrestore(&(s->lock),flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock),flags);
ERROR("cannot resize op in reading key 0x%p on user keyed stream %s\n",key,s->url);
return -1;
}
// enter with it locked
if (do_request_to_response(s,&flags)) {
- spin_unlock_irqrestore(&(s->lock),flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock),flags);
ERROR("request/response handling failed\n");
return -1;
}
xfer=s->op->xfer;
- spin_unlock_irqrestore(&(s->lock),flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock),flags);
return xfer;
}
unsigned long flags;
- spin_lock_irqsave(&(s->lock), flags);
+ palacios_spinlock_lock_irqsave(&(s->lock), flags);
if (s->otype != V3_KS_WR_ONLY) {
- spin_unlock_irqrestore(&(s->lock),flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock),flags);
ERROR("attempt to write key on stream that is not in write state on %s\n",s->url);
}
if (resize_op(&(s->op),len)) {
- spin_unlock_irqrestore(&(s->lock),flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock),flags);
ERROR("cannot resize op in reading key 0x%p on user keyed stream %s\n",key,s->url);
return -1;
}
// enter with it locked
if (do_request_to_response(s,&flags)) {
- spin_unlock_irqrestore(&(s->lock),flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock),flags);
ERROR("request/response handling failed\n");
return -1;
}
xfer=s->op->xfer;
- spin_unlock_irqrestore(&(s->lock),flags);
+ palacios_spinlock_unlock_irqrestore(&(s->lock),flags);
return xfer;
}
INIT_LIST_HEAD(&(user_streams->streams));
- spin_lock_init(&(user_streams->lock));
+ palacios_spinlock_init(&(user_streams->lock));
V3_Init_Keyed_Streams(&hooks);
{
palacios_free_htable(mem_streams,1,1);
+ palacios_spinlock_deinit(&(user_streams->lock));
+
palacios_free(user_streams);
WARNING("Deinit of Palacios Keyed Streams likely leaked memory\n");
static int guest_deinit_keyed_streams(struct v3_guest * guest, void * vm_data)
{
+ remove_guest_ctrl(guest, V3_VM_KSTREAM_USER_CONNECT);
return 0;
}