Skip to content

Commit 7826756

Browse files
author
Octavian Purdila
authored
Merge pull request torvalds#197 from liuyuan10/ipv6
lkl: Fix ipv6 netperf failure
2 parents e99de6d + 255bfc8 commit 7826756

File tree

7 files changed

+305
-168
lines changed

7 files changed

+305
-168
lines changed

tools/lkl/include/lkl.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ int lkl_set_ipv4_gateway(unsigned int addr);
224224

225225
/**
226226
* lkl_if_set_ipv6 - set IPv6 address on interface
227+
* must be called after interface is up.
227228
*
228229
* @ifindex - the ifindex of the interface
229230
* @addr - 16-byte IPv6 address (i.e., struct in6_addr)
@@ -369,6 +370,13 @@ void lkl_register_dbg_handler();
369370
*/
370371
int lkl_add_neighbor(int ifindex, int af, void* addr, void* mac);
371372

373+
/**
374+
* lkl_mount_fs - mount a file system type like proc, sys
375+
* @fstype - file system type. e.g. proc, sys
376+
* @returns - 0 on success. 1 if it's already mounted. negative on failure.
377+
*/
378+
int lkl_mount_fs(char *fstype);
379+
372380
#ifdef __cplusplus
373381
}
374382
#endif

tools/lkl/lib/dbg.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -143,36 +143,17 @@ static void cd() {
143143

144144
static void mount() {
145145
char* fstype;
146-
char dir[MAX_BUF] = "/";
147-
int flags = 0, ret = 0;
146+
int ret = 0;
148147

149148
if (argc != 1) {
150149
fprintf(stderr, "%s\n", "One argument is needed.");
151150
return;
152151
}
153152

154153
fstype = argv[0];
155-
strncat(dir, fstype, MAX_BUF - 1);
156-
157-
/* Create with regular umask */
158-
ret = lkl_sys_mkdir(dir, 0xff);
159-
if (ret) {
160-
fprintf(stderr, "mount mkdir %s: %s\n", dir,
161-
lkl_strerror(ret));
162-
return;
163-
}
164-
165-
ret = lkl_sys_mount(dir, dir, fstype, flags, NULL);
166-
if (ret) {
167-
fprintf(stderr, "mount mount %s as %s: %s\n",
168-
dir, fstype, strerror(ret));
169-
ret = lkl_sys_rmdir(dir);
170-
if (ret) {
171-
fprintf(stderr, "mount rmdir %s: %s\n",
172-
dir, strerror(ret));
173-
}
174-
return;
175-
}
154+
ret = lkl_mount_fs(fstype);
155+
if (ret == 1)
156+
fprintf(stderr, "%s is already mounted.\n", fstype);
176157
}
177158

178159
static void cat() {

tools/lkl/lib/fs.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,46 @@
22
#include <string.h>
33
#include <lkl_host.h>
44

5-
long lkl_mount_sysfs(void)
5+
#define MAX_FSTYPE_LEN 50
6+
int lkl_mount_fs(char *fstype)
67
{
7-
long ret;
8-
static int sysfs_mounted;
8+
char dir[MAX_FSTYPE_LEN+2] = "/";
9+
int flags = 0, ret = 0;
910

10-
if (sysfs_mounted)
11-
return 0;
11+
strncat(dir, fstype, MAX_FSTYPE_LEN);
1212

13-
ret = lkl_sys_mkdir("/sys", 0700);
14-
if (ret)
13+
/* Create with regular umask */
14+
ret = lkl_sys_mkdir(dir, 0xff);
15+
if (ret && ret != -LKL_EEXIST) {
16+
lkl_perror("mount_fs mkdir", ret);
1517
return ret;
18+
}
1619

17-
ret = lkl_sys_mount("none", "sys", "sysfs", 0, NULL);
18-
19-
if (ret == 0)
20-
sysfs_mounted = 1;
20+
/* We have no use for nonzero flags right now */
21+
ret = lkl_sys_mount("none", dir, fstype, flags, NULL);
22+
if (ret && ret != -LKL_EBUSY) {
23+
lkl_sys_rmdir(dir);
24+
return ret;
25+
}
2126

22-
return ret;
27+
if (ret == -LKL_EBUSY)
28+
return 1;
29+
return 0;
2330
}
2431

2532
static long get_virtio_blkdev(int disk_id)
2633
{
27-
char sysfs_path[] = "/sys/block/vda/dev";
34+
char sysfs_path[] = "/sysfs/block/vda/dev";
2835
char buf[16] = { 0, };
2936
long fd, ret;
3037
int major, minor;
3138

32-
ret = lkl_mount_sysfs();
33-
if (ret)
39+
40+
ret = lkl_mount_fs("sysfs");
41+
if (ret < 0)
3442
return ret;
3543

36-
sysfs_path[strlen("/sys/block/vd")] += disk_id;
44+
sysfs_path[strlen("/sysfs/block/vd")] += disk_id;
3745

3846
fd = lkl_sys_open(sysfs_path, LKL_O_RDONLY, 0);
3947
if (fd < 0)

tools/lkl/lib/hijack/init.c

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -137,48 +137,19 @@ static int dump_file(char *path)
137137
return 0;
138138
}
139139

140-
/* For simplicity, if we want to mount a filesystem of a particular
141-
* type, we'll create a directory under / with the name of the type;
142-
* e.g. we'll have our sysfs as /sysfs */
143-
static int mount_fs(char *fstype)
144-
{
145-
char dir[MAX_FSTYPE_LEN] = "/";
146-
int flags = 0, ret = 0;
147-
148-
strncat(dir, fstype, MAX_FSTYPE_LEN - 1);
149-
150-
/* Create with regular umask */
151-
ret = lkl_sys_mkdir(dir, 0xff);
152-
if (ret) {
153-
fprintf(stderr, "mount_fs mkdir %s: %s\n", dir,
154-
lkl_strerror(ret));
155-
return -1;
156-
}
157-
158-
/* We have no use for nonzero flags right now */
159-
ret = lkl_sys_mount(dir, dir, fstype, flags, NULL);
160-
if (ret) {
161-
fprintf(stderr, "mount_fs mount %s as %s: %s\n",
162-
dir, fstype, strerror(ret));
163-
return -1;
164-
}
165-
166-
return 0;
167-
}
168-
169140
static void mount_cmds_exec(char *_cmds, int (*callback)(char*))
170141
{
171142
char *saveptr = NULL, *token;
172143
int ret = 0;
173144
char *cmds = strdup(_cmds);
174145
token = strtok_r(cmds, ",", &saveptr);
175146

176-
while (token && !ret) {
147+
while (token && ret >= 0) {
177148
ret = callback(token);
178149
token = strtok_r(NULL, ",", &saveptr);
179150
}
180151

181-
if (ret)
152+
if (ret < 0)
182153
fprintf(stderr, "mount_cmds_exec: failed parsing %s\n", _cmds);
183154

184155
free(cmds);
@@ -417,13 +388,13 @@ hijack_init(void)
417388
}
418389

419390
if (nd_ifindex >= 0 && ipv6 && netmask6_len) {
420-
char addr[16];
391+
struct in6_addr addr;
421392
unsigned int pflen = atoi(netmask6_len);
422393

423-
if (inet_pton(AF_INET6, ipv6, addr) != 1) {
394+
if (inet_pton(AF_INET6, ipv6, &addr) != 1) {
424395
fprintf(stderr, "Invalid ipv6 addr: %s\n", ipv6);
425396
} else {
426-
ret = lkl_if_set_ipv6(nd_ifindex, addr, pflen);
397+
ret = lkl_if_set_ipv6(nd_ifindex, &addr, pflen);
427398
if (ret < 0)
428399
fprintf(stderr, "failed to set IPv6address: %s\n",
429400
lkl_strerror(ret));
@@ -444,7 +415,7 @@ hijack_init(void)
444415
}
445416

446417
if (mount)
447-
mount_cmds_exec(mount, mount_fs);
418+
mount_cmds_exec(mount, lkl_mount_fs);
448419

449420
if (nd_ifindex >=0 && neigh_entries)
450421
add_neighbor(nd_ifindex, neigh_entries);

0 commit comments

Comments
 (0)