Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
Kernel
提交
83bfccb5
K
Kernel
项目概览
openeuler
/
Kernel
1 年多 前同步成功
通知
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看板
提交
83bfccb5
编写于
1月 21, 2013
作者:
C
Chris Mason
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'mutex-ops@next-for-chris' of
git://github.com/idryomov/btrfs-unstable
into linus
上级
daf2c089
25122d15
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
86 addition
and
31 deletion
+86
-31
fs/btrfs/ioctl.c
fs/btrfs/ioctl.c
+79
-28
fs/btrfs/volumes.c
fs/btrfs/volumes.c
+7
-3
未找到文件。
fs/btrfs/ioctl.c
浏览文件 @
83bfccb5
...
...
@@ -1340,7 +1340,7 @@ static noinline int btrfs_ioctl_resize(struct file *file,
1
))
{
pr_info
(
"btrfs: dev add/delete/balance/replace/resize operation in progress
\n
"
);
mnt_drop_write_file
(
file
);
return
-
EIN
PROGRESS
;
return
-
EIN
VAL
;
}
mutex_lock
(
&
root
->
fs_info
->
volume_mutex
);
...
...
@@ -1446,8 +1446,8 @@ static noinline int btrfs_ioctl_resize(struct file *file,
kfree
(
vol_args
);
out:
mutex_unlock
(
&
root
->
fs_info
->
volume_mutex
);
mnt_drop_write_file
(
file
);
atomic_set
(
&
root
->
fs_info
->
mutually_exclusive_operation_running
,
0
);
mnt_drop_write_file
(
file
);
return
ret
;
}
...
...
@@ -2186,19 +2186,20 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp)
struct
btrfs_ioctl_defrag_range_args
*
range
;
int
ret
;
if
(
btrfs_root_readonly
(
root
))
return
-
EROFS
;
ret
=
mnt_want_write_file
(
file
);
if
(
ret
)
return
ret
;
if
(
atomic_xchg
(
&
root
->
fs_info
->
mutually_exclusive_operation_running
,
1
))
{
pr_info
(
"btrfs: dev add/delete/balance/replace/resize operation in progress
\n
"
);
return
-
EINPROGRESS
;
mnt_drop_write_file
(
file
);
return
-
EINVAL
;
}
ret
=
mnt_want_write_file
(
file
);
if
(
ret
)
{
atomic_set
(
&
root
->
fs_info
->
mutually_exclusive_operation_running
,
0
);
return
ret
;
if
(
btrfs_root_readonly
(
root
))
{
ret
=
-
EROFS
;
goto
out
;
}
switch
(
inode
->
i_mode
&
S_IFMT
)
{
...
...
@@ -2250,8 +2251,8 @@ static int btrfs_ioctl_defrag(struct file *file, void __user *argp)
ret
=
-
EINVAL
;
}
out:
mnt_drop_write_file
(
file
);
atomic_set
(
&
root
->
fs_info
->
mutually_exclusive_operation_running
,
0
);
mnt_drop_write_file
(
file
);
return
ret
;
}
...
...
@@ -2266,7 +2267,7 @@ static long btrfs_ioctl_add_dev(struct btrfs_root *root, void __user *arg)
if
(
atomic_xchg
(
&
root
->
fs_info
->
mutually_exclusive_operation_running
,
1
))
{
pr_info
(
"btrfs: dev add/delete/balance/replace/resize operation in progress
\n
"
);
return
-
EIN
PROGRESS
;
return
-
EIN
VAL
;
}
mutex_lock
(
&
root
->
fs_info
->
volume_mutex
);
...
...
@@ -2303,7 +2304,7 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
1
))
{
pr_info
(
"btrfs: dev add/delete/balance/replace/resize operation in progress
\n
"
);
mnt_drop_write_file
(
file
);
return
-
EIN
PROGRESS
;
return
-
EIN
VAL
;
}
mutex_lock
(
&
root
->
fs_info
->
volume_mutex
);
...
...
@@ -2319,8 +2320,8 @@ static long btrfs_ioctl_rm_dev(struct file *file, void __user *arg)
kfree
(
vol_args
);
out:
mutex_unlock
(
&
root
->
fs_info
->
volume_mutex
);
mnt_drop_write_file
(
file
);
atomic_set
(
&
root
->
fs_info
->
mutually_exclusive_operation_running
,
0
);
mnt_drop_write_file
(
file
);
return
ret
;
}
...
...
@@ -3440,8 +3441,8 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)
struct
btrfs_fs_info
*
fs_info
=
root
->
fs_info
;
struct
btrfs_ioctl_balance_args
*
bargs
;
struct
btrfs_balance_control
*
bctl
;
bool
need_unlock
;
/* for mut. excl. ops lock */
int
ret
;
int
need_to_clear_lock
=
0
;
if
(
!
capable
(
CAP_SYS_ADMIN
))
return
-
EPERM
;
...
...
@@ -3450,14 +3451,61 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)
if
(
ret
)
return
ret
;
mutex_lock
(
&
fs_info
->
volume_mutex
);
again:
if
(
!
atomic_xchg
(
&
fs_info
->
mutually_exclusive_operation_running
,
1
))
{
mutex_lock
(
&
fs_info
->
volume_mutex
);
mutex_lock
(
&
fs_info
->
balance_mutex
);
need_unlock
=
true
;
goto
locked
;
}
/*
* mut. excl. ops lock is locked. Three possibilites:
* (1) some other op is running
* (2) balance is running
* (3) balance is paused -- special case (think resume)
*/
mutex_lock
(
&
fs_info
->
balance_mutex
);
if
(
fs_info
->
balance_ctl
)
{
/* this is either (2) or (3) */
if
(
!
atomic_read
(
&
fs_info
->
balance_running
))
{
mutex_unlock
(
&
fs_info
->
balance_mutex
);
if
(
!
mutex_trylock
(
&
fs_info
->
volume_mutex
))
goto
again
;
mutex_lock
(
&
fs_info
->
balance_mutex
);
if
(
fs_info
->
balance_ctl
&&
!
atomic_read
(
&
fs_info
->
balance_running
))
{
/* this is (3) */
need_unlock
=
false
;
goto
locked
;
}
mutex_unlock
(
&
fs_info
->
balance_mutex
);
mutex_unlock
(
&
fs_info
->
volume_mutex
);
goto
again
;
}
else
{
/* this is (2) */
mutex_unlock
(
&
fs_info
->
balance_mutex
);
ret
=
-
EINPROGRESS
;
goto
out
;
}
}
else
{
/* this is (1) */
mutex_unlock
(
&
fs_info
->
balance_mutex
);
pr_info
(
"btrfs: dev add/delete/balance/replace/resize operation in progress
\n
"
);
ret
=
-
EINVAL
;
goto
out
;
}
locked:
BUG_ON
(
!
atomic_read
(
&
fs_info
->
mutually_exclusive_operation_running
));
if
(
arg
)
{
bargs
=
memdup_user
(
arg
,
sizeof
(
*
bargs
));
if
(
IS_ERR
(
bargs
))
{
ret
=
PTR_ERR
(
bargs
);
goto
out
;
goto
out
_unlock
;
}
if
(
bargs
->
flags
&
BTRFS_BALANCE_RESUME
)
{
...
...
@@ -3477,13 +3525,10 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)
bargs
=
NULL
;
}
if
(
atomic_xchg
(
&
root
->
fs_info
->
mutually_exclusive_operation_running
,
1
))
{
pr_info
(
"btrfs: dev add/delete/balance/replace/resize operation in progress
\n
"
);
if
(
fs_info
->
balance_ctl
)
{
ret
=
-
EINPROGRESS
;
goto
out_bargs
;
}
need_to_clear_lock
=
1
;
bctl
=
kzalloc
(
sizeof
(
*
bctl
),
GFP_NOFS
);
if
(
!
bctl
)
{
...
...
@@ -3504,11 +3549,17 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)
}
do_balance:
ret
=
btrfs_balance
(
bctl
,
bargs
);
/*
* bctl is freed in __cancel_balance or in free_fs_info if
* restriper was paused all the way until unmount
* Ownership of bctl and mutually_exclusive_operation_running
* goes to to btrfs_balance. bctl is freed in __cancel_balance,
* or, if restriper was paused all the way until unmount, in
* free_fs_info. mutually_exclusive_operation_running is
* cleared in __cancel_balance.
*/
need_unlock
=
false
;
ret
=
btrfs_balance
(
bctl
,
bargs
);
if
(
arg
)
{
if
(
copy_to_user
(
arg
,
bargs
,
sizeof
(
*
bargs
)))
ret
=
-
EFAULT
;
...
...
@@ -3516,12 +3567,12 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)
out_bargs:
kfree
(
bargs
);
out:
if
(
need_to_clear_lock
)
atomic_set
(
&
root
->
fs_info
->
mutually_exclusive_operation_running
,
0
);
out_unlock:
mutex_unlock
(
&
fs_info
->
balance_mutex
);
mutex_unlock
(
&
fs_info
->
volume_mutex
);
if
(
need_unlock
)
atomic_set
(
&
fs_info
->
mutually_exclusive_operation_running
,
0
);
out:
mnt_drop_write_file
(
file
);
return
ret
;
}
...
...
fs/btrfs/volumes.c
浏览文件 @
83bfccb5
...
...
@@ -2959,6 +2959,8 @@ static void __cancel_balance(struct btrfs_fs_info *fs_info)
unset_balance_control
(
fs_info
);
ret
=
del_balance_item
(
fs_info
->
tree_root
);
BUG_ON
(
ret
);
atomic_set
(
&
fs_info
->
mutually_exclusive_operation_running
,
0
);
}
void
update_ioctl_balance_args
(
struct
btrfs_fs_info
*
fs_info
,
int
lock
,
...
...
@@ -3138,8 +3140,10 @@ int btrfs_balance(struct btrfs_balance_control *bctl,
out:
if
(
bctl
->
flags
&
BTRFS_BALANCE_RESUME
)
__cancel_balance
(
fs_info
);
else
else
{
kfree
(
bctl
);
atomic_set
(
&
fs_info
->
mutually_exclusive_operation_running
,
0
);
}
return
ret
;
}
...
...
@@ -3156,7 +3160,6 @@ static int balance_kthread(void *data)
ret
=
btrfs_balance
(
fs_info
->
balance_ctl
,
NULL
);
}
atomic_set
(
&
fs_info
->
mutually_exclusive_operation_running
,
0
);
mutex_unlock
(
&
fs_info
->
balance_mutex
);
mutex_unlock
(
&
fs_info
->
volume_mutex
);
...
...
@@ -3179,7 +3182,6 @@ int btrfs_resume_balance_async(struct btrfs_fs_info *fs_info)
return
0
;
}
WARN_ON
(
atomic_xchg
(
&
fs_info
->
mutually_exclusive_operation_running
,
1
));
tsk
=
kthread_run
(
balance_kthread
,
fs_info
,
"btrfs-balance"
);
if
(
IS_ERR
(
tsk
))
return
PTR_ERR
(
tsk
);
...
...
@@ -3233,6 +3235,8 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
btrfs_balance_sys
(
leaf
,
item
,
&
disk_bargs
);
btrfs_disk_balance_args_to_cpu
(
&
bctl
->
sys
,
&
disk_bargs
);
WARN_ON
(
atomic_xchg
(
&
fs_info
->
mutually_exclusive_operation_running
,
1
));
mutex_lock
(
&
fs_info
->
volume_mutex
);
mutex_lock
(
&
fs_info
->
balance_mutex
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录