Skip to content

Commit

Permalink
Merge pull request #217 from opurdila/virtio-cleanups
Browse files Browse the repository at this point in the history
virtio cleanups
  • Loading branch information
Octavian Purdila authored Aug 31, 2016
2 parents d141b16 + 9d4b15b commit d58310d
Show file tree
Hide file tree
Showing 11 changed files with 284 additions and 241 deletions.
2 changes: 2 additions & 0 deletions tools/lkl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ ifneq (,$(filter $(OUTPUT_FORMAT),elf64-x86-64 elf32-i386 elf64-x86-64-freebsd e
LDLIBS += -lrt -lpthread
endif
export CONFIG_AUTO_LKL_POSIX_HOST=y
CFLAGS += -DCONFIG_AUTO_LKL_POSIX_HOST

# Intel DPDK configuration
ifeq ($(dpdk),yes)
Expand All @@ -71,6 +72,7 @@ else ifneq (,$(filter $(OUTPUT_FORMAT),pe-i386))
EXESUF := .exe
SOSUF := .dll
export CONFIG_AUTO_LKL_NT_HOST=y
CFLAGS += -DCONFIG_AUTO_LKL_NT_HOST
else
$(error Unrecognized platform: $(OUTPUT_FORMAT))
endif
Expand Down
16 changes: 10 additions & 6 deletions tools/lkl/include/lkl_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ int lkl_printf(const char *fmt, ...);

extern char lkl_virtio_devs[256];

struct lkl_dev_buf {
void *addr;
size_t len;
#ifdef CONFIG_AUTO_LKL_POSIX_HOST
#include <sys/uio.h>
#else
struct iovec {
void *iov_base;
size_t iov_len;
};
#endif

extern struct lkl_dev_blk_ops lkl_dev_blk_ops;

Expand All @@ -35,7 +39,7 @@ struct lkl_blk_req {
unsigned int type;
unsigned int prio;
unsigned long long sector;
struct lkl_dev_buf *buf;
struct iovec *buf;
int count;
};

Expand Down Expand Up @@ -63,7 +67,7 @@ struct lkl_dev_net_ops {
* @cnt - # of vectors in iov.
* @returns number of bytes transmitted
*/
int (*tx)(struct lkl_netdev *nd, struct lkl_dev_buf *iov, int cnt);
int (*tx)(struct lkl_netdev *nd, struct iovec *iov, int cnt);

/*
* Reads a packet from the net device.
Expand All @@ -78,7 +82,7 @@ struct lkl_dev_net_ops {
* @cnt - # of vectors in iov.
* @returns number of bytes read for success or < 0 if error
*/
int (*rx)(struct lkl_netdev *nd, struct lkl_dev_buf *iov, int cnt);
int (*rx)(struct lkl_netdev *nd, struct iovec *iov, int cnt);

#define LKL_DEV_NET_POLL_RX 1
#define LKL_DEV_NET_POLL_TX 2
Expand Down
15 changes: 8 additions & 7 deletions tools/lkl/lib/nt-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,31 +262,32 @@ static int blk_request(struct lkl_disk disk, struct lkl_blk_req *req)

for (i = 0; i < req->count; i++) {
DWORD res;
struct iovec *buf = &req->buf[i];

ov.Offset = offset & 0xffffffff;
ov.OffsetHigh = offset >> 32;

if (req->type == LKL_DEV_BLK_TYPE_READ)
ret = ReadFile(disk.handle, req->buf[i].addr,
req->buf[i].len, &res, &ov);
ret = ReadFile(disk.handle, buf->iov_base,
buf->iov_len, &res, &ov);
else
ret = WriteFile(disk.handle, req->buf[i].addr,
req->buf[i].len, &res, &ov);
ret = WriteFile(disk.handle, buf->iov_base,
buf->iov_len, &res, &ov);
if (!ret) {
lkl_printf("%s: I/O error: %d\n", __func__,
GetLastError());
err = -1;
goto out;
}

if (res != req->buf[i].len) {
if (res != buf->iov_len) {
lkl_printf("%s: I/O error: short: %d %d\n",
res, req->buf[i].len);
res, buf->iov_len);
err = -1;
goto out;
}

offset += req->buf[i].len;
offset += buf->iov_len;
}
break;
}
Expand Down
4 changes: 2 additions & 2 deletions tools/lkl/lib/posix-host.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ static int do_rw(ssize_t (*fn)(), struct lkl_disk disk, struct lkl_blk_req *req)

for (i = 0; i < req->count; i++) {

addr = req->buf[i].addr;
len = req->buf[i].len;
addr = req->buf[i].iov_base;
len = req->buf[i].iov_len;

do {
ret = fn(disk.fd, addr, len, off);
Expand Down
Loading

0 comments on commit d58310d

Please sign in to comment.