Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
847a9eb1
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
847a9eb1
编写于
3月 30, 2014
作者:
C
Cole Robinson
1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
storage: move block format lookup to shared UpdateVolInfo
上级
16d75d19
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
103 addition
and
159 deletion
+103
-159
src/storage/storage_backend.c
src/storage/storage_backend.c
+93
-82
src/storage/storage_backend.h
src/storage/storage_backend.h
+2
-2
src/storage/storage_backend_disk.c
src/storage/storage_backend_disk.c
+1
-1
src/storage/storage_backend_fs.c
src/storage/storage_backend_fs.c
+2
-2
src/storage/storage_backend_logical.c
src/storage/storage_backend_logical.c
+1
-1
src/storage/storage_backend_mpath.c
src/storage/storage_backend_mpath.c
+2
-34
src/storage/storage_backend_scsi.c
src/storage/storage_backend_scsi.c
+2
-37
未找到文件。
src/storage/storage_backend.c
浏览文件 @
847a9eb1
...
...
@@ -1198,6 +1198,80 @@ virStorageFileBackendForType(int type,
}
struct
diskType
{
int
part_table_type
;
unsigned
short
offset
;
unsigned
short
length
;
unsigned
long
long
magic
;
};
static
struct
diskType
const
disk_types
[]
=
{
{
VIR_STORAGE_POOL_DISK_LVM2
,
0x218
,
8
,
0x31303020324D564CULL
},
{
VIR_STORAGE_POOL_DISK_GPT
,
0x200
,
8
,
0x5452415020494645ULL
},
{
VIR_STORAGE_POOL_DISK_DVH
,
0x0
,
4
,
0x41A9E50BULL
},
{
VIR_STORAGE_POOL_DISK_MAC
,
0x0
,
2
,
0x5245ULL
},
{
VIR_STORAGE_POOL_DISK_BSD
,
0x40
,
4
,
0x82564557ULL
},
{
VIR_STORAGE_POOL_DISK_SUN
,
0x1fc
,
2
,
0xBEDAULL
},
/*
* NOTE: pc98 is funky; the actual signature is 0x55AA (just like dos), so
* we can't use that. At the moment I'm relying on the "dummy" IPL
* bootloader data that comes from parted. Luckily, the chances of running
* into a pc98 machine running libvirt are approximately nil.
*/
/*{ 0x1fe, 2, 0xAA55UL },*/
{
VIR_STORAGE_POOL_DISK_PC98
,
0x0
,
8
,
0x314C5049000000CBULL
},
/*
* NOTE: the order is important here; some other disk types (like GPT and
* and PC98) also have 0x55AA at this offset. For that reason, the DOS
* one must be the last one.
*/
{
VIR_STORAGE_POOL_DISK_DOS
,
0x1fe
,
2
,
0xAA55ULL
},
{
-
1
,
0x0
,
0
,
0x0ULL
},
};
static
int
virStorageBackendDetectBlockVolFormatFD
(
virStorageVolTargetPtr
target
,
int
fd
)
{
size_t
i
;
off_t
start
;
unsigned
char
buffer
[
1024
];
ssize_t
bytes
;
/* make sure to set the target format "unknown" to begin with */
target
->
format
=
VIR_STORAGE_POOL_DISK_UNKNOWN
;
start
=
lseek
(
fd
,
0
,
SEEK_SET
);
if
(
start
<
0
)
{
virReportSystemError
(
errno
,
_
(
"cannot seek to beginning of file '%s'"
),
target
->
path
);
return
-
1
;
}
bytes
=
saferead
(
fd
,
buffer
,
sizeof
(
buffer
));
if
(
bytes
<
0
)
{
virReportSystemError
(
errno
,
_
(
"cannot read beginning of file '%s'"
),
target
->
path
);
return
-
1
;
}
for
(
i
=
0
;
disk_types
[
i
].
part_table_type
!=
-
1
;
i
++
)
{
if
(
disk_types
[
i
].
offset
+
disk_types
[
i
].
length
>
bytes
)
continue
;
if
(
memcmp
(
buffer
+
disk_types
[
i
].
offset
,
&
disk_types
[
i
].
magic
,
disk_types
[
i
].
length
)
==
0
)
{
target
->
format
=
disk_types
[
i
].
part_table_type
;
break
;
}
}
return
0
;
}
/*
* Allows caller to silently ignore files with improper mode
*
...
...
@@ -1316,22 +1390,30 @@ int
virStorageBackendUpdateVolTargetInfo
(
virStorageVolTargetPtr
target
,
unsigned
long
long
*
allocation
,
unsigned
long
long
*
capacity
,
bool
withBlockVolFormat
,
unsigned
int
openflags
)
{
int
ret
,
fd
;
int
ret
,
fd
=
-
1
;
struct
stat
sb
;
if
((
ret
=
virStorageBackendVolOpenCheckMode
(
target
->
path
,
&
sb
,
openflags
))
<
0
)
return
ret
;
goto
cleanup
;
fd
=
ret
;
ret
=
virStorageBackendUpdateVolTargetInfoFD
(
target
,
fd
,
&
sb
,
allocation
,
capacity
);
if
((
ret
=
virStorageBackendUpdateVolTargetInfoFD
(
target
,
fd
,
&
sb
,
allocation
,
capacity
))
<
0
)
goto
cleanup
;
if
(
withBlockVolFormat
)
{
if
((
ret
=
virStorageBackendDetectBlockVolFormatFD
(
target
,
fd
))
<
0
)
goto
cleanup
;
}
cleanup:
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
...
...
@@ -1340,6 +1422,7 @@ virStorageBackendUpdateVolTargetInfo(virStorageVolTargetPtr target,
int
virStorageBackendUpdateVolInfo
(
virStorageVolDefPtr
vol
,
bool
withCapacity
,
bool
withBlockVolFormat
,
unsigned
int
openflags
)
{
int
ret
;
...
...
@@ -1347,12 +1430,14 @@ virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
if
((
ret
=
virStorageBackendUpdateVolTargetInfo
(
&
vol
->
target
,
&
vol
->
allocation
,
withCapacity
?
&
vol
->
capacity
:
NULL
,
withBlockVolFormat
,
openflags
))
<
0
)
return
ret
;
if
(
vol
->
backingStore
.
path
&&
(
ret
=
virStorageBackendUpdateVolTargetInfo
(
&
vol
->
backingStore
,
NULL
,
NULL
,
withBlockVolFormat
,
VIR_STORAGE_VOL_OPEN_DEFAULT
))
<
0
)
return
ret
;
...
...
@@ -1455,80 +1540,6 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageVolTargetPtr target,
}
struct
diskType
{
int
part_table_type
;
unsigned
short
offset
;
unsigned
short
length
;
unsigned
long
long
magic
;
};
static
struct
diskType
const
disk_types
[]
=
{
{
VIR_STORAGE_POOL_DISK_LVM2
,
0x218
,
8
,
0x31303020324D564CULL
},
{
VIR_STORAGE_POOL_DISK_GPT
,
0x200
,
8
,
0x5452415020494645ULL
},
{
VIR_STORAGE_POOL_DISK_DVH
,
0x0
,
4
,
0x41A9E50BULL
},
{
VIR_STORAGE_POOL_DISK_MAC
,
0x0
,
2
,
0x5245ULL
},
{
VIR_STORAGE_POOL_DISK_BSD
,
0x40
,
4
,
0x82564557ULL
},
{
VIR_STORAGE_POOL_DISK_SUN
,
0x1fc
,
2
,
0xBEDAULL
},
/*
* NOTE: pc98 is funky; the actual signature is 0x55AA (just like dos), so
* we can't use that. At the moment I'm relying on the "dummy" IPL
* bootloader data that comes from parted. Luckily, the chances of running
* into a pc98 machine running libvirt are approximately nil.
*/
/*{ 0x1fe, 2, 0xAA55UL },*/
{
VIR_STORAGE_POOL_DISK_PC98
,
0x0
,
8
,
0x314C5049000000CBULL
},
/*
* NOTE: the order is important here; some other disk types (like GPT and
* and PC98) also have 0x55AA at this offset. For that reason, the DOS
* one must be the last one.
*/
{
VIR_STORAGE_POOL_DISK_DOS
,
0x1fe
,
2
,
0xAA55ULL
},
{
-
1
,
0x0
,
0
,
0x0ULL
},
};
int
virStorageBackendDetectBlockVolFormatFD
(
virStorageVolTargetPtr
target
,
int
fd
)
{
size_t
i
;
off_t
start
;
unsigned
char
buffer
[
1024
];
ssize_t
bytes
;
/* make sure to set the target format "unknown" to begin with */
target
->
format
=
VIR_STORAGE_POOL_DISK_UNKNOWN
;
start
=
lseek
(
fd
,
0
,
SEEK_SET
);
if
(
start
<
0
)
{
virReportSystemError
(
errno
,
_
(
"cannot seek to beginning of file '%s'"
),
target
->
path
);
return
-
1
;
}
bytes
=
saferead
(
fd
,
buffer
,
sizeof
(
buffer
));
if
(
bytes
<
0
)
{
virReportSystemError
(
errno
,
_
(
"cannot read beginning of file '%s'"
),
target
->
path
);
return
-
1
;
}
for
(
i
=
0
;
disk_types
[
i
].
part_table_type
!=
-
1
;
i
++
)
{
if
(
disk_types
[
i
].
offset
+
disk_types
[
i
].
length
>
bytes
)
continue
;
if
(
memcmp
(
buffer
+
disk_types
[
i
].
offset
,
&
disk_types
[
i
].
magic
,
disk_types
[
i
].
length
)
==
0
)
{
target
->
format
=
disk_types
[
i
].
part_table_type
;
break
;
}
}
return
0
;
}
/*
* Given a volume path directly in /dev/XXX, iterate over the
* entries in the directory pool->def->target.path and find the
...
...
src/storage/storage_backend.h
浏览文件 @
847a9eb1
...
...
@@ -139,18 +139,18 @@ int virStorageBackendVolOpenCheckMode(const char *path, struct stat *sb,
int
virStorageBackendUpdateVolInfo
(
virStorageVolDefPtr
vol
,
bool
withCapacity
,
bool
withBlockVolFormat
,
unsigned
int
openflags
);
int
virStorageBackendUpdateVolTargetInfo
(
virStorageVolTargetPtr
target
,
unsigned
long
long
*
allocation
,
unsigned
long
long
*
capacity
,
bool
withBlockVolFormat
,
unsigned
int
openflags
);
int
virStorageBackendUpdateVolTargetInfoFD
(
virStorageVolTargetPtr
target
,
int
fd
,
struct
stat
*
sb
,
unsigned
long
long
*
allocation
,
unsigned
long
long
*
capacity
);
int
virStorageBackendDetectBlockVolFormatFD
(
virStorageVolTargetPtr
target
,
int
fd
);
char
*
virStorageBackendStablePath
(
virStoragePoolObjPtr
pool
,
const
char
*
devpath
,
...
...
src/storage/storage_backend_disk.c
浏览文件 @
847a9eb1
...
...
@@ -113,7 +113,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
}
/* Refresh allocation/capacity/perms */
if
(
virStorageBackendUpdateVolInfo
(
vol
,
true
,
if
(
virStorageBackendUpdateVolInfo
(
vol
,
true
,
false
,
VIR_STORAGE_VOL_OPEN_DEFAULT
)
<
0
)
return
-
1
;
...
...
src/storage/storage_backend_fs.c
浏览文件 @
847a9eb1
...
...
@@ -895,7 +895,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
vol
->
backingStore
.
format
=
backingStoreFormat
;
if
(
virStorageBackendUpdateVolTargetInfo
(
&
vol
->
backingStore
,
NULL
,
NULL
,
NULL
,
NULL
,
false
,
VIR_STORAGE_VOL_OPEN_DEFAULT
)
<
0
)
{
/* The backing file is currently unavailable, the capacity,
* allocation, owner, group and mode are unknown. Just log the
...
...
@@ -1180,7 +1180,7 @@ virStorageBackendFileSystemVolRefresh(virConnectPtr conn,
int
ret
;
/* Refresh allocation / permissions info in case its changed */
ret
=
virStorageBackendUpdateVolInfo
(
vol
,
false
,
ret
=
virStorageBackendUpdateVolInfo
(
vol
,
false
,
false
,
VIR_STORAGE_VOL_FS_OPEN_FLAGS
);
if
(
ret
<
0
)
return
ret
;
...
...
src/storage/storage_backend_logical.c
浏览文件 @
847a9eb1
...
...
@@ -149,7 +149,7 @@ virStorageBackendLogicalMakeVol(char **const groups,
if
(
!
vol
->
key
&&
VIR_STRDUP
(
vol
->
key
,
groups
[
2
])
<
0
)
goto
cleanup
;
if
(
virStorageBackendUpdateVolInfo
(
vol
,
true
,
if
(
virStorageBackendUpdateVolInfo
(
vol
,
true
,
false
,
VIR_STORAGE_VOL_OPEN_DEFAULT
)
<
0
)
goto
cleanup
;
...
...
src/storage/storage_backend_mpath.c
浏览文件 @
847a9eb1
...
...
@@ -41,37 +41,6 @@
VIR_LOG_INIT
(
"storage.storage_backend_mpath"
);
static
int
virStorageBackendMpathUpdateVolTargetInfo
(
virStorageVolTargetPtr
target
,
unsigned
long
long
*
allocation
,
unsigned
long
long
*
capacity
)
{
int
ret
=
-
1
;
int
fdret
,
fd
=
-
1
;
struct
stat
sb
;
if
((
fdret
=
virStorageBackendVolOpenCheckMode
(
target
->
path
,
&
sb
,
VIR_STORAGE_VOL_OPEN_DEFAULT
))
<
0
)
goto
out
;
fd
=
fdret
;
if
(
virStorageBackendUpdateVolTargetInfoFD
(
target
,
fd
,
&
sb
,
allocation
,
capacity
)
<
0
)
goto
out
;
if
(
virStorageBackendDetectBlockVolFormatFD
(
target
,
fd
)
<
0
)
goto
out
;
ret
=
0
;
out:
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
static
int
virStorageBackendMpathNewVol
(
virStoragePoolObjPtr
pool
,
const
int
devnum
,
...
...
@@ -91,9 +60,8 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool,
if
(
virAsprintf
(
&
vol
->
target
.
path
,
"/dev/%s"
,
dev
)
<
0
)
goto
cleanup
;
if
(
virStorageBackendMpathUpdateVolTargetInfo
(
&
vol
->
target
,
&
vol
->
allocation
,
&
vol
->
capacity
)
<
0
)
{
if
(
virStorageBackendUpdateVolInfo
(
vol
,
true
,
true
,
VIR_STORAGE_VOL_OPEN_DEFAULT
)
<
0
)
{
goto
cleanup
;
}
...
...
src/storage/storage_backend_scsi.c
浏览文件 @
847a9eb1
...
...
@@ -102,39 +102,6 @@ getDeviceType(uint32_t host,
return
retval
;
}
static
int
virStorageBackendSCSIUpdateVolTargetInfo
(
virStorageVolTargetPtr
target
,
unsigned
long
long
*
allocation
,
unsigned
long
long
*
capacity
)
{
int
fdret
,
fd
=
-
1
;
int
ret
=
-
1
;
struct
stat
sb
;
if
((
fdret
=
virStorageBackendVolOpenCheckMode
(
target
->
path
,
&
sb
,
VIR_STORAGE_VOL_OPEN_DEFAULT
))
<
0
)
goto
cleanup
;
fd
=
fdret
;
if
(
virStorageBackendUpdateVolTargetInfoFD
(
target
,
fd
,
&
sb
,
allocation
,
capacity
)
<
0
)
goto
cleanup
;
if
(
virStorageBackendDetectBlockVolFormatFD
(
target
,
fd
)
<
0
)
goto
cleanup
;
ret
=
0
;
cleanup:
VIR_FORCE_CLOSE
(
fd
);
return
ret
;
}
static
char
*
virStorageBackendSCSISerial
(
const
char
*
dev
)
{
...
...
@@ -232,10 +199,8 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
goto
free_vol
;
}
if
(
virStorageBackendSCSIUpdateVolTargetInfo
(
&
vol
->
target
,
&
vol
->
allocation
,
&
vol
->
capacity
)
<
0
)
{
if
(
virStorageBackendUpdateVolInfo
(
vol
,
true
,
true
,
VIR_STORAGE_VOL_OPEN_DEFAULT
)
<
0
)
{
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
_
(
"Failed to update volume for '%s'"
),
devpath
);
...
...
tester丶
🤺
@ssszwink
mentioned in commit
4dce2ab8
·
9月 10, 2020
mentioned in commit
4dce2ab8
mentioned in commit 4dce2ab89ee084828b11039fb0ace53b4eaaa29b
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录