Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
5053dd6a
提交
5053dd6a
8月 15, 2011
创建
作者:
Robert Morris
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
avoid deadlock by calling begin_trans() before locking any inodes
上级
c95ce31c
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
66 行增加
和
15 行删除
+66
-15
file.c
file.c
+4
-2
fs.c
fs.c
+3
-4
log.c
log.c
+2
-2
sysfile.c
sysfile.c
+10
-4
usertests.c
usertests.c
+47
-3
没有找到文件。
file.c
浏览文件 @
5053dd6a
...
...
@@ -118,7 +118,6 @@ filewrite(struct file *f, char *addr, int n)
if
(
f
->
type
==
FD_PIPE
)
return
pipewrite
(
f
->
pipe
,
addr
,
n
);
if
(
f
->
type
==
FD_INODE
){
ilock
(
f
->
ip
);
// write a few blocks at a time to avoid exceeding
// the maximum log transaction size, including
// i-node, indirect block, allocation blocks,
...
...
@@ -131,9 +130,13 @@ filewrite(struct file *f, char *addr, int n)
int
n1
=
n
-
i
;
if
(
n1
>
max
)
n1
=
max
;
begin_trans
();
ilock
(
f
->
ip
);
r
=
writei
(
f
->
ip
,
addr
+
i
,
f
->
off
,
n1
);
iunlock
(
f
->
ip
);
commit_trans
();
if
(
r
<
0
)
break
;
if
(
r
!=
n1
)
...
...
@@ -141,7 +144,6 @@ filewrite(struct file *f, char *addr, int n)
f
->
off
+=
r
;
i
+=
r
;
}
iunlock
(
f
->
ip
);
return
i
==
n
?
n
:
-
1
;
}
panic
(
"filewrite"
);
...
...
fs.c
浏览文件 @
5053dd6a
...
...
@@ -43,13 +43,13 @@ bzero(int dev, int bno)
bp
=
bread
(
dev
,
bno
);
memset
(
bp
->
data
,
0
,
BSIZE
);
b
write
(
bp
);
log_
write
(
bp
);
brelse
(
bp
);
}
// Blocks.
// Allocate a disk block.
// Allocate a
zeroed
disk block.
static
uint
balloc
(
uint
dev
)
{
...
...
@@ -67,6 +67,7 @@ balloc(uint dev)
bp
->
data
[
bi
/
8
]
|=
m
;
// Mark block in use on disk.
log_write
(
bp
);
brelse
(
bp
);
bzero
(
dev
,
b
+
bi
);
return
b
+
bi
;
}
}
...
...
@@ -83,8 +84,6 @@ bfree(int dev, uint b)
struct
superblock
sb
;
int
bi
,
m
;
bzero
(
dev
,
b
);
readsb
(
dev
,
&
sb
);
bp
=
bread
(
dev
,
BBLOCK
(
b
,
sb
.
ninodes
));
bi
=
b
%
BPB
;
...
...
log.c
浏览文件 @
5053dd6a
...
...
@@ -124,9 +124,9 @@ static void
recover_from_log
(
void
)
{
read_head
();
install_trans
();
// Install all transactions till head
install_trans
();
// if committed, copy from log to disk
log
.
lh
.
n
=
0
;
write_head
();
// Reclaim
log
write_head
();
// clear the
log
}
void
...
...
sysfile.c
浏览文件 @
5053dd6a
...
...
@@ -116,14 +116,16 @@ sys_link(void)
return
-
1
;
if
((
ip
=
namei
(
old
))
==
0
)
return
-
1
;
begin_trans
();
ilock
(
ip
);
if
(
ip
->
type
==
T_DIR
){
iunlockput
(
ip
);
commit_trans
();
return
-
1
;
}
begin_trans
();
ip
->
nlink
++
;
iupdate
(
ip
);
iunlock
(
ip
);
...
...
@@ -180,16 +182,21 @@ sys_unlink(void)
return
-
1
;
if
((
dp
=
nameiparent
(
path
,
name
))
==
0
)
return
-
1
;
begin_trans
();
ilock
(
dp
);
// Cannot unlink "." or "..".
if
(
namecmp
(
name
,
"."
)
==
0
||
namecmp
(
name
,
".."
)
==
0
){
iunlockput
(
dp
);
commit_trans
();
return
-
1
;
}
if
((
ip
=
dirlookup
(
dp
,
name
,
&
off
))
==
0
){
iunlockput
(
dp
);
commit_trans
();
return
-
1
;
}
ilock
(
ip
);
...
...
@@ -199,11 +206,10 @@ sys_unlink(void)
if
(
ip
->
type
==
T_DIR
&&
!
isdirempty
(
ip
)){
iunlockput
(
ip
);
iunlockput
(
dp
);
commit_trans
();
return
-
1
;
}
begin_trans
();
memset
(
&
de
,
0
,
sizeof
(
de
));
if
(
writei
(
dp
,
(
char
*
)
&
de
,
off
,
sizeof
(
de
))
!=
sizeof
(
de
))
panic
(
"unlink: writei"
);
...
...
usertests.c
浏览文件 @
5053dd6a
...
...
@@ -364,6 +364,8 @@ sharedfd(void)
int
fd
,
pid
,
i
,
n
,
nc
,
np
;
char
buf
[
10
];
printf
(
1
,
"sharedfd test
\n
"
);
unlink
(
"sharedfd"
);
fd
=
open
(
"sharedfd"
,
O_CREATE
|
O_RDWR
);
if
(
fd
<
0
){
...
...
@@ -655,7 +657,7 @@ linktest(void)
printf
(
1
,
"linktest ok
\n
"
);
}
// test concurrent create
and
unlink of the same file
// test concurrent create
/link/
unlink of the same file
void
concreate
(
void
)
{
...
...
@@ -728,10 +730,15 @@ concreate(void)
}
if
(((
i
%
3
)
==
0
&&
pid
==
0
)
||
((
i
%
3
)
==
1
&&
pid
!=
0
)){
fd
=
open
(
file
,
0
);
close
(
fd
);
close
(
open
(
file
,
0
));
close
(
open
(
file
,
0
));
close
(
open
(
file
,
0
));
close
(
open
(
file
,
0
));
}
else
{
unlink
(
file
);
unlink
(
file
);
unlink
(
file
);
unlink
(
file
);
}
if
(
pid
==
0
)
exit
();
...
...
@@ -742,6 +749,42 @@ concreate(void)
printf
(
1
,
"concreate ok
\n
"
);
}
// another concurrent link/unlink/create test,
// to look for deadlocks.
void
linkunlink
()
{
int
pid
,
i
;
printf
(
1
,
"linkunlink test
\n
"
);
unlink
(
"x"
);
pid
=
fork
();
if
(
pid
<
0
){
printf
(
1
,
"fork failed
\n
"
);
exit
();
}
unsigned
int
x
=
(
pid
?
1
:
97
);
for
(
i
=
0
;
i
<
100
;
i
++
){
x
=
x
*
1103515245
+
12345
;
if
((
x
%
3
)
==
0
){
close
(
open
(
"x"
,
O_RDWR
|
O_CREATE
));
}
else
if
((
x
%
3
)
==
1
){
link
(
"cat"
,
"x"
);
}
else
{
unlink
(
"x"
);
}
}
if
(
pid
)
wait
();
else
exit
();
printf
(
1
,
"linkunlink ok
\n
"
);
}
// directory that uses indirect blocks
void
bigdir
(
void
)
...
...
@@ -1518,6 +1561,7 @@ main(int argc, char *argv[])
bigfile
();
subdir
();
concreate
();
linkunlink
();
linktest
();
unlinkread
();
createdelete
();
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论