Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xiphi1978
linux
提交
788f20eb
L
linux
项目概览
xiphi1978
/
linux
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
linux
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
788f20eb
编写于
4月 28, 2008
作者:
C
Chris Mason
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Btrfs: Add new ioctl to add devices
Signed-off-by:
N
Chris Mason
<
chris.mason@oracle.com
>
上级
8e7bf94f
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
108 addition
and
0 deletion
+108
-0
fs/btrfs/ctree.h
fs/btrfs/ctree.h
+2
-0
fs/btrfs/inode.c
fs/btrfs/inode.c
+23
-0
fs/btrfs/ioctl.h
fs/btrfs/ioctl.h
+6
-0
fs/btrfs/super.c
fs/btrfs/super.c
+1
-0
fs/btrfs/volumes.c
fs/btrfs/volumes.c
+75
-0
fs/btrfs/volumes.h
fs/btrfs/volumes.h
+1
-0
未找到文件。
fs/btrfs/ctree.h
浏览文件 @
788f20eb
...
...
@@ -551,6 +551,8 @@ struct btrfs_fs_info {
u64
data_alloc_profile
;
u64
metadata_alloc_profile
;
u64
system_alloc_profile
;
void
*
bdev_holder
;
};
/*
...
...
fs/btrfs/inode.c
浏览文件 @
788f20eb
...
...
@@ -3070,6 +3070,27 @@ static int btrfs_ioctl_defrag(struct file *file)
return
0
;
}
long
btrfs_ioctl_add_dev
(
struct
btrfs_root
*
root
,
void
__user
*
arg
)
{
struct
btrfs_ioctl_vol_args
*
vol_args
;
int
ret
;
vol_args
=
kmalloc
(
sizeof
(
*
vol_args
),
GFP_NOFS
);
if
(
!
vol_args
)
return
-
ENOMEM
;
if
(
copy_from_user
(
vol_args
,
arg
,
sizeof
(
*
vol_args
)))
{
ret
=
-
EFAULT
;
goto
out
;
}
ret
=
btrfs_init_new_device
(
root
,
vol_args
->
name
);
out:
kfree
(
vol_args
);
return
ret
;
}
long
btrfs_ioctl
(
struct
file
*
file
,
unsigned
int
cmd
,
unsigned
long
arg
)
{
...
...
@@ -3082,6 +3103,8 @@ long btrfs_ioctl(struct file *file, unsigned int
return
btrfs_ioctl_defrag
(
file
);
case
BTRFS_IOC_RESIZE
:
return
btrfs_ioctl_resize
(
root
,
(
void
__user
*
)
arg
);
case
BTRFS_IOC_ADD_DEV
:
return
btrfs_ioctl_add_dev
(
root
,
(
void
__user
*
)
arg
);
}
return
-
ENOTTY
;
...
...
fs/btrfs/ioctl.h
浏览文件 @
788f20eb
...
...
@@ -36,4 +36,10 @@ struct btrfs_ioctl_vol_args {
struct btrfs_ioctl_vol_args)
#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \
struct btrfs_ioctl_vol_args)
#define BTRFS_IOC_ADD_DEV _IOW(BTRFS_IOCTL_MAGIC, 10, \
struct btrfs_ioctl_vol_args)
#define BTRFS_IOC_RM_DEV _IOW(BTRFS_IOCTL_MAGIC, 11, \
struct btrfs_ioctl_vol_args)
#define BTRFS_IOC_BALANCE _IOW(BTRFS_IOCTL_MAGIC, 12, \
struct btrfs_ioctl_vol_args)
#endif
fs/btrfs/super.c
浏览文件 @
788f20eb
...
...
@@ -388,6 +388,7 @@ int btrfs_get_sb_bdev(struct file_system_type *fs_type,
goto
error
;
}
btrfs_sb
(
s
)
->
fs_info
->
bdev_holder
=
fs_type
;
s
->
s_flags
|=
MS_ACTIVE
;
}
...
...
fs/btrfs/volumes.c
浏览文件 @
788f20eb
...
...
@@ -19,6 +19,7 @@
#include <linux/bio.h>
#include <linux/buffer_head.h>
#include <linux/blkdev.h>
#include <linux/random.h>
#include <asm/div64.h>
#include "ctree.h"
#include "extent_map.h"
...
...
@@ -592,6 +593,80 @@ int btrfs_add_device(struct btrfs_trans_handle *trans,
return
ret
;
}
int
btrfs_init_new_device
(
struct
btrfs_root
*
root
,
char
*
device_path
)
{
struct
btrfs_trans_handle
*
trans
;
struct
btrfs_device
*
device
;
struct
block_device
*
bdev
;
struct
list_head
*
cur
;
struct
list_head
*
devices
;
u64
total_bytes
;
int
ret
=
0
;
bdev
=
open_bdev_excl
(
device_path
,
0
,
root
->
fs_info
->
bdev_holder
);
if
(
!
bdev
)
{
return
-
EIO
;
}
mutex_lock
(
&
root
->
fs_info
->
fs_mutex
);
trans
=
btrfs_start_transaction
(
root
,
1
);
devices
=
&
root
->
fs_info
->
fs_devices
->
devices
;
list_for_each
(
cur
,
devices
)
{
device
=
list_entry
(
cur
,
struct
btrfs_device
,
dev_list
);
if
(
device
->
bdev
==
bdev
)
{
ret
=
-
EEXIST
;
goto
out
;
}
}
device
=
kzalloc
(
sizeof
(
*
device
),
GFP_NOFS
);
if
(
!
device
)
{
/* we can safely leave the fs_devices entry around */
ret
=
-
ENOMEM
;
goto
out_close_bdev
;
}
device
->
barriers
=
1
;
generate_random_uuid
(
device
->
uuid
);
spin_lock_init
(
&
device
->
io_lock
);
device
->
name
=
kstrdup
(
device_path
,
GFP_NOFS
);
if
(
!
device
->
name
)
{
kfree
(
device
);
goto
out_close_bdev
;
}
device
->
io_width
=
root
->
sectorsize
;
device
->
io_align
=
root
->
sectorsize
;
device
->
sector_size
=
root
->
sectorsize
;
device
->
total_bytes
=
i_size_read
(
bdev
->
bd_inode
);
device
->
dev_root
=
root
->
fs_info
->
dev_root
;
device
->
bdev
=
bdev
;
ret
=
btrfs_add_device
(
trans
,
root
,
device
);
if
(
ret
)
goto
out_close_bdev
;
total_bytes
=
btrfs_super_total_bytes
(
&
root
->
fs_info
->
super_copy
);
btrfs_set_super_total_bytes
(
&
root
->
fs_info
->
super_copy
,
total_bytes
+
device
->
total_bytes
);
total_bytes
=
btrfs_super_num_devices
(
&
root
->
fs_info
->
super_copy
);
btrfs_set_super_num_devices
(
&
root
->
fs_info
->
super_copy
,
total_bytes
+
1
);
list_add
(
&
device
->
dev_list
,
&
root
->
fs_info
->
fs_devices
->
devices
);
list_add
(
&
device
->
dev_alloc_list
,
&
root
->
fs_info
->
fs_devices
->
alloc_list
);
root
->
fs_info
->
fs_devices
->
num_devices
++
;
out:
btrfs_end_transaction
(
trans
,
root
);
mutex_unlock
(
&
root
->
fs_info
->
fs_mutex
);
return
ret
;
out_close_bdev:
close_bdev_excl
(
bdev
);
goto
out
;
}
int
btrfs_update_device
(
struct
btrfs_trans_handle
*
trans
,
struct
btrfs_device
*
device
)
{
...
...
fs/btrfs/volumes.h
浏览文件 @
788f20eb
...
...
@@ -133,4 +133,5 @@ int btrfs_grow_device(struct btrfs_trans_handle *trans,
struct
btrfs_device
*
btrfs_find_device
(
struct
btrfs_root
*
root
,
u64
devid
,
u8
*
uuid
);
int
btrfs_shrink_device
(
struct
btrfs_device
*
device
,
u64
new_size
);
int
btrfs_init_new_device
(
struct
btrfs_root
*
root
,
char
*
path
);
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录