Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
Kernel
提交
1a200b51
K
Kernel
项目概览
openeuler
/
Kernel
大约 2 年 前同步成功
通知
8
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
Kernel
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
1a200b51
编写于
3月 16, 2023
作者:
D
David S. Miller
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'net-virtio-vsock'
上级
cd356010
7e699d2a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
131 addition
and
16 deletion
+131
-16
net/vmw_vsock/virtio_transport_common.c
net/vmw_vsock/virtio_transport_common.c
+13
-16
tools/testing/vsock/vsock_test.c
tools/testing/vsock/vsock_test.c
+118
-0
未找到文件。
net/vmw_vsock/virtio_transport_common.c
浏览文件 @
1a200b51
...
...
@@ -241,21 +241,18 @@ static int virtio_transport_send_pkt_info(struct vsock_sock *vsk,
}
static
bool
virtio_transport_inc_rx_pkt
(
struct
virtio_vsock_sock
*
vvs
,
struct
sk_buff
*
skb
)
u32
len
)
{
if
(
vvs
->
rx_bytes
+
skb
->
len
>
vvs
->
buf_alloc
)
if
(
vvs
->
rx_bytes
+
len
>
vvs
->
buf_alloc
)
return
false
;
vvs
->
rx_bytes
+=
skb
->
len
;
vvs
->
rx_bytes
+=
len
;
return
true
;
}
static
void
virtio_transport_dec_rx_pkt
(
struct
virtio_vsock_sock
*
vvs
,
struct
sk_buff
*
skb
)
u32
len
)
{
int
len
;
len
=
skb_headroom
(
skb
)
-
sizeof
(
struct
virtio_vsock_hdr
)
-
skb
->
len
;
vvs
->
rx_bytes
-=
len
;
vvs
->
fwd_cnt
+=
len
;
}
...
...
@@ -367,7 +364,7 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk,
spin_lock_bh
(
&
vvs
->
rx_lock
);
while
(
total
<
len
&&
!
skb_queue_empty
(
&
vvs
->
rx_queue
))
{
skb
=
__skb_dequeue
(
&
vvs
->
rx_queue
);
skb
=
skb_peek
(
&
vvs
->
rx_queue
);
bytes
=
len
-
total
;
if
(
bytes
>
skb
->
len
)
...
...
@@ -388,10 +385,11 @@ virtio_transport_stream_do_dequeue(struct vsock_sock *vsk,
skb_pull
(
skb
,
bytes
);
if
(
skb
->
len
==
0
)
{
virtio_transport_dec_rx_pkt
(
vvs
,
skb
);
u32
pkt_len
=
le32_to_cpu
(
virtio_vsock_hdr
(
skb
)
->
len
);
virtio_transport_dec_rx_pkt
(
vvs
,
pkt_len
);
__skb_unlink
(
skb
,
&
vvs
->
rx_queue
);
consume_skb
(
skb
);
}
else
{
__skb_queue_head
(
&
vvs
->
rx_queue
,
skb
);
}
}
...
...
@@ -437,17 +435,17 @@ static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk,
while
(
!
msg_ready
)
{
struct
virtio_vsock_hdr
*
hdr
;
size_t
pkt_len
;
skb
=
__skb_dequeue
(
&
vvs
->
rx_queue
);
if
(
!
skb
)
break
;
hdr
=
virtio_vsock_hdr
(
skb
);
pkt_len
=
(
size_t
)
le32_to_cpu
(
hdr
->
len
);
if
(
dequeued_len
>=
0
)
{
size_t
pkt_len
;
size_t
bytes_to_copy
;
pkt_len
=
(
size_t
)
le32_to_cpu
(
hdr
->
len
);
bytes_to_copy
=
min
(
user_buf_len
,
pkt_len
);
if
(
bytes_to_copy
)
{
...
...
@@ -466,7 +464,6 @@ static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk,
dequeued_len
=
err
;
}
else
{
user_buf_len
-=
bytes_to_copy
;
skb_pull
(
skb
,
bytes_to_copy
);
}
spin_lock_bh
(
&
vvs
->
rx_lock
);
...
...
@@ -484,7 +481,7 @@ static int virtio_transport_seqpacket_do_dequeue(struct vsock_sock *vsk,
msg
->
msg_flags
|=
MSG_EOR
;
}
virtio_transport_dec_rx_pkt
(
vvs
,
skb
);
virtio_transport_dec_rx_pkt
(
vvs
,
pkt_len
);
kfree_skb
(
skb
);
}
...
...
@@ -1040,7 +1037,7 @@ virtio_transport_recv_enqueue(struct vsock_sock *vsk,
spin_lock_bh
(
&
vvs
->
rx_lock
);
can_enqueue
=
virtio_transport_inc_rx_pkt
(
vvs
,
skb
);
can_enqueue
=
virtio_transport_inc_rx_pkt
(
vvs
,
len
);
if
(
!
can_enqueue
)
{
free_pkt
=
true
;
goto
out
;
...
...
tools/testing/vsock/vsock_test.c
浏览文件 @
1a200b51
...
...
@@ -860,6 +860,114 @@ static void test_stream_poll_rcvlowat_client(const struct test_opts *opts)
close
(
fd
);
}
#define INV_BUF_TEST_DATA_LEN 512
static
void
test_inv_buf_client
(
const
struct
test_opts
*
opts
,
bool
stream
)
{
unsigned
char
data
[
INV_BUF_TEST_DATA_LEN
]
=
{
0
};
ssize_t
ret
;
int
fd
;
if
(
stream
)
fd
=
vsock_stream_connect
(
opts
->
peer_cid
,
1234
);
else
fd
=
vsock_seqpacket_connect
(
opts
->
peer_cid
,
1234
);
if
(
fd
<
0
)
{
perror
(
"connect"
);
exit
(
EXIT_FAILURE
);
}
control_expectln
(
"SENDDONE"
);
/* Use invalid buffer here. */
ret
=
recv
(
fd
,
NULL
,
sizeof
(
data
),
0
);
if
(
ret
!=
-
1
)
{
fprintf
(
stderr
,
"expected recv(2) failure, got %zi
\n
"
,
ret
);
exit
(
EXIT_FAILURE
);
}
if
(
errno
!=
ENOMEM
)
{
fprintf
(
stderr
,
"unexpected recv(2) errno %d
\n
"
,
errno
);
exit
(
EXIT_FAILURE
);
}
ret
=
recv
(
fd
,
data
,
sizeof
(
data
),
MSG_DONTWAIT
);
if
(
stream
)
{
/* For SOCK_STREAM we must continue reading. */
if
(
ret
!=
sizeof
(
data
))
{
fprintf
(
stderr
,
"expected recv(2) success, got %zi
\n
"
,
ret
);
exit
(
EXIT_FAILURE
);
}
/* Don't check errno in case of success. */
}
else
{
/* For SOCK_SEQPACKET socket's queue must be empty. */
if
(
ret
!=
-
1
)
{
fprintf
(
stderr
,
"expected recv(2) failure, got %zi
\n
"
,
ret
);
exit
(
EXIT_FAILURE
);
}
if
(
errno
!=
EAGAIN
)
{
fprintf
(
stderr
,
"unexpected recv(2) errno %d
\n
"
,
errno
);
exit
(
EXIT_FAILURE
);
}
}
control_writeln
(
"DONE"
);
close
(
fd
);
}
static
void
test_inv_buf_server
(
const
struct
test_opts
*
opts
,
bool
stream
)
{
unsigned
char
data
[
INV_BUF_TEST_DATA_LEN
]
=
{
0
};
ssize_t
res
;
int
fd
;
if
(
stream
)
fd
=
vsock_stream_accept
(
VMADDR_CID_ANY
,
1234
,
NULL
);
else
fd
=
vsock_seqpacket_accept
(
VMADDR_CID_ANY
,
1234
,
NULL
);
if
(
fd
<
0
)
{
perror
(
"accept"
);
exit
(
EXIT_FAILURE
);
}
res
=
send
(
fd
,
data
,
sizeof
(
data
),
0
);
if
(
res
!=
sizeof
(
data
))
{
fprintf
(
stderr
,
"unexpected send(2) result %zi
\n
"
,
res
);
exit
(
EXIT_FAILURE
);
}
control_writeln
(
"SENDDONE"
);
control_expectln
(
"DONE"
);
close
(
fd
);
}
static
void
test_stream_inv_buf_client
(
const
struct
test_opts
*
opts
)
{
test_inv_buf_client
(
opts
,
true
);
}
static
void
test_stream_inv_buf_server
(
const
struct
test_opts
*
opts
)
{
test_inv_buf_server
(
opts
,
true
);
}
static
void
test_seqpacket_inv_buf_client
(
const
struct
test_opts
*
opts
)
{
test_inv_buf_client
(
opts
,
false
);
}
static
void
test_seqpacket_inv_buf_server
(
const
struct
test_opts
*
opts
)
{
test_inv_buf_server
(
opts
,
false
);
}
static
struct
test_case
test_cases
[]
=
{
{
.
name
=
"SOCK_STREAM connection reset"
,
...
...
@@ -920,6 +1028,16 @@ static struct test_case test_cases[] = {
.
run_client
=
test_seqpacket_bigmsg_client
,
.
run_server
=
test_seqpacket_bigmsg_server
,
},
{
.
name
=
"SOCK_STREAM test invalid buffer"
,
.
run_client
=
test_stream_inv_buf_client
,
.
run_server
=
test_stream_inv_buf_server
,
},
{
.
name
=
"SOCK_SEQPACKET test invalid buffer"
,
.
run_client
=
test_seqpacket_inv_buf_client
,
.
run_server
=
test_seqpacket_inv_buf_server
,
},
{},
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录