X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=linux_usr%2Fv3_user_keyed_stream_file.c;h=3e33eb782571c3fb3de8517a03f495460c9c88c3;hb=68f8c4cd303c5da40c1083cbabdaf6395e4dbaa1;hp=275983ca8baa24bf66ea798ac73e94381904954d;hpb=7b67d47d87463b237db5ad43941742c5a5d4b0bf;p=palacios.git diff --git a/linux_usr/v3_user_keyed_stream_file.c b/linux_usr/v3_user_keyed_stream_file.c index 275983c..3e33eb7 100644 --- a/linux_usr/v3_user_keyed_stream_file.c +++ b/linux_usr/v3_user_keyed_stream_file.c @@ -92,8 +92,9 @@ int handle_open_key(struct palacios_user_keyed_stream_op *req, (*resp)->len=sizeof(struct palacios_user_keyed_stream_op); (*resp)->type=req->type; (*resp)->xfer=0; - (*resp)->user_key=(void*)fd; + (*resp)->user_key=(void*)(uint64_t)fd; (*resp)->buf_len=0; + (*resp)->data_off=0; return 0; @@ -106,7 +107,7 @@ int handle_close_key(struct palacios_user_keyed_stream_op *req, int fd; int rc; - fd = (int) (req->user_key); + fd = (int) (uint64_t) (req->user_key); rc = close(fd); @@ -119,8 +120,9 @@ int handle_close_key(struct palacios_user_keyed_stream_op *req, (*resp)->len=sizeof(struct palacios_user_keyed_stream_op); (*resp)->type=req->type; (*resp)->xfer=rc; - (*resp)->user_key=(void*)fd; + (*resp)->user_key=(void*)(uint64_t)fd; (*resp)->buf_len=0; + (*resp)->data_off=0; return 0; @@ -171,10 +173,32 @@ int handle_write_key(struct palacios_user_keyed_stream_op *req, { int fd; int rc; + sint64_t taglen = req->data_off; + sint64_t datalen = req->buf_len - req->data_off; + + if (datalen != req->xfer) { + fprintf(stderr,"Odd, xfer=%ld but datalen computed is %ld\n",req->xfer,datalen); + if (datalen > req->xfer) { + datalen = req->xfer; + } + } - fd = (int) (req->user_key); + fd = (int) (uint64_t) (req->user_key); - rc = write_all(fd,req->buf,req->xfer); + // Write tag + rc = write_all(fd,req->buf,taglen); + + if (rc!=taglen) { + // failed to write tag, lets report as negative error + fprintf(stderr,"Failed to write tag (taglen=%ld, rc=%d)\n",taglen,rc); + rc = -1; + } else { + // Write data + rc = write_all(fd,req->buf+taglen,datalen); + if (rc!=datalen) { + fprintf(stderr,"Failed to write data (datalen=%ld, rc=%d)\n",datalen,rc); + } + } (*resp) = malloc(sizeof(struct palacios_user_keyed_stream_op)+0); @@ -185,8 +209,9 @@ int handle_write_key(struct palacios_user_keyed_stream_op *req, (*resp)->len=sizeof(struct palacios_user_keyed_stream_op); (*resp)->type=req->type; (*resp)->xfer=rc; - (*resp)->user_key=(void*)fd; + (*resp)->user_key=(void*)(uint64_t)fd; (*resp)->buf_len=0; + (*resp)->data_off=0; return 0; @@ -199,8 +224,10 @@ int handle_read_key(struct palacios_user_keyed_stream_op *req, { int fd; int rc; + sint64_t taglen = req->data_off; + char temptag[taglen]; - fd = (int) (req->user_key); + fd = (int) (uint64_t) (req->user_key); (*resp) = malloc(sizeof(struct palacios_user_keyed_stream_op)+req->xfer); @@ -208,14 +235,31 @@ int handle_read_key(struct palacios_user_keyed_stream_op *req, return -1; } - rc = read_all(fd,(*resp)->buf,req->xfer); + // read key and compare + rc = read_all(fd,temptag,taglen); + + if (rc!=taglen) { + // Error + fprintf(stderr,"Failed to read tag (taglen=%ld, rc=%d)\n",taglen,rc); + rc = -1; + } else { + // tag check + if (memcmp(temptag,req->buf,taglen)) { + // tag mismatch + fprintf(stderr,"Tag mismatch in read tag\n"); + rc =-1; + } else { + // OK, do data read + rc = read_all(fd,(*resp)->buf,req->xfer); + } + } (*resp)->len=sizeof(struct palacios_user_keyed_stream_op) + (rc>0 ? rc : 0); (*resp)->type=req->type; (*resp)->xfer=rc; - (*resp)->user_key=(void*)fd; + (*resp)->user_key=(void*)(uint64_t)fd; (*resp)->buf_len=rc>0 ? rc : 0; - + (*resp)->data_off = 0; return 0;