(*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;
int fd;
int rc;
- fd = (int) (req->user_key);
+ fd = (int) (uint64_t) (req->user_key);
rc = close(fd);
(*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;
{
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=%lld but datalen computed is %lld\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=%lld, 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=%lld, rc=%d)\n",datalen,rc);
+ }
+ }
(*resp) = malloc(sizeof(struct palacios_user_keyed_stream_op)+0);
(*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;
{
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);
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=%lld, 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;