Skip to content

Commit d58310d

Browse files
author
Octavian Purdila
authored
Merge pull request torvalds#217 from opurdila/virtio-cleanups
virtio cleanups
2 parents d141b16 + 9d4b15b commit d58310d

11 files changed

+284
-241
lines changed

tools/lkl/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ ifneq (,$(filter $(OUTPUT_FORMAT),elf64-x86-64 elf32-i386 elf64-x86-64-freebsd e
4848
LDLIBS += -lrt -lpthread
4949
endif
5050
export CONFIG_AUTO_LKL_POSIX_HOST=y
51+
CFLAGS += -DCONFIG_AUTO_LKL_POSIX_HOST
5152

5253
# Intel DPDK configuration
5354
ifeq ($(dpdk),yes)
@@ -71,6 +72,7 @@ else ifneq (,$(filter $(OUTPUT_FORMAT),pe-i386))
7172
EXESUF := .exe
7273
SOSUF := .dll
7374
export CONFIG_AUTO_LKL_NT_HOST=y
75+
CFLAGS += -DCONFIG_AUTO_LKL_NT_HOST
7476
else
7577
$(error Unrecognized platform: $(OUTPUT_FORMAT))
7678
endif

tools/lkl/include/lkl_host.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ int lkl_printf(const char *fmt, ...);
1919

2020
extern char lkl_virtio_devs[256];
2121

22-
struct lkl_dev_buf {
23-
void *addr;
24-
size_t len;
22+
#ifdef CONFIG_AUTO_LKL_POSIX_HOST
23+
#include <sys/uio.h>
24+
#else
25+
struct iovec {
26+
void *iov_base;
27+
size_t iov_len;
2528
};
29+
#endif
2630

2731
extern struct lkl_dev_blk_ops lkl_dev_blk_ops;
2832

@@ -35,7 +39,7 @@ struct lkl_blk_req {
3539
unsigned int type;
3640
unsigned int prio;
3741
unsigned long long sector;
38-
struct lkl_dev_buf *buf;
42+
struct iovec *buf;
3943
int count;
4044
};
4145

@@ -63,7 +67,7 @@ struct lkl_dev_net_ops {
6367
* @cnt - # of vectors in iov.
6468
* @returns number of bytes transmitted
6569
*/
66-
int (*tx)(struct lkl_netdev *nd, struct lkl_dev_buf *iov, int cnt);
70+
int (*tx)(struct lkl_netdev *nd, struct iovec *iov, int cnt);
6771

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

8387
#define LKL_DEV_NET_POLL_RX 1
8488
#define LKL_DEV_NET_POLL_TX 2

tools/lkl/lib/nt-host.c

+8-7
Original file line numberDiff line numberDiff line change
@@ -262,31 +262,32 @@ static int blk_request(struct lkl_disk disk, struct lkl_blk_req *req)
262262

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

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

269270
if (req->type == LKL_DEV_BLK_TYPE_READ)
270-
ret = ReadFile(disk.handle, req->buf[i].addr,
271-
req->buf[i].len, &res, &ov);
271+
ret = ReadFile(disk.handle, buf->iov_base,
272+
buf->iov_len, &res, &ov);
272273
else
273-
ret = WriteFile(disk.handle, req->buf[i].addr,
274-
req->buf[i].len, &res, &ov);
274+
ret = WriteFile(disk.handle, buf->iov_base,
275+
buf->iov_len, &res, &ov);
275276
if (!ret) {
276277
lkl_printf("%s: I/O error: %d\n", __func__,
277278
GetLastError());
278279
err = -1;
279280
goto out;
280281
}
281282

282-
if (res != req->buf[i].len) {
283+
if (res != buf->iov_len) {
283284
lkl_printf("%s: I/O error: short: %d %d\n",
284-
res, req->buf[i].len);
285+
res, buf->iov_len);
285286
err = -1;
286287
goto out;
287288
}
288289

289-
offset += req->buf[i].len;
290+
offset += buf->iov_len;
290291
}
291292
break;
292293
}

tools/lkl/lib/posix-host.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ static int do_rw(ssize_t (*fn)(), struct lkl_disk disk, struct lkl_blk_req *req)
336336

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

339-
addr = req->buf[i].addr;
340-
len = req->buf[i].len;
339+
addr = req->buf[i].iov_base;
340+
len = req->buf[i].iov_len;
341341

342342
do {
343343
ret = fn(disk.fd, addr, len, off);

0 commit comments

Comments
 (0)