Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
dc56b3a7
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看板
提交
dc56b3a7
编写于
6月 17, 2016
作者:
J
Ján Tomko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce virBitmapParseUnlimited
For parsing a bitmap of an unknown size.
上级
ff52e9d4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
124 addition
and
0 deletion
+124
-0
src/libvirt_private.syms
src/libvirt_private.syms
+1
-0
src/util/virbitmap.c
src/util/virbitmap.c
+112
-0
src/util/virbitmap.h
src/util/virbitmap.h
+4
-0
tests/virbitmaptest.c
tests/virbitmaptest.c
+7
-0
未找到文件。
src/libvirt_private.syms
浏览文件 @
dc56b3a7
...
...
@@ -1208,6 +1208,7 @@ virBitmapNextSetBit;
virBitmapOverlaps;
virBitmapParse;
virBitmapParseSeparator;
virBitmapParseUnlimited;
virBitmapSetAll;
virBitmapSetBit;
virBitmapSetBitExpand;
...
...
src/util/virbitmap.c
浏览文件 @
dc56b3a7
...
...
@@ -542,6 +542,118 @@ virBitmapParse(const char *str,
return
virBitmapParseSeparator
(
str
,
'\0'
,
bitmap
,
bitmapSize
);
}
/**
* virBitmapParseUnlimited:
* @str: points to a string representing a human-readable bitmap
* @bitmap: a bitmap created from @str
*
* This function is the counterpart of virBitmapFormat. This function creates
* a bitmap, in which bits are set according to the content of @str.
*
* The bitmap is expanded to accomodate all the bits.
*
* @str is a comma separated string of fields N, which means a number of bit
* to set, and ^N, which means to unset the bit, and N-M for ranges of bits
* to set.
*
* Returns 0 on success, or -1 in case of error.
*/
int
virBitmapParseUnlimited
(
const
char
*
str
,
virBitmapPtr
*
bitmap
)
{
bool
neg
=
false
;
const
char
*
cur
=
str
;
char
*
tmp
;
size_t
i
;
int
start
,
last
;
if
(
!
(
*
bitmap
=
virBitmapNewEmpty
()))
return
-
1
;
if
(
!
str
)
goto
error
;
virSkipSpaces
(
&
cur
);
if
(
*
cur
==
'\0'
)
goto
error
;
while
(
*
cur
!=
0
)
{
/*
* 3 constructs are allowed:
* - N : a single CPU number
* - N-M : a range of CPU numbers with N < M
* - ^N : remove a single CPU number from the current set
*/
if
(
*
cur
==
'^'
)
{
cur
++
;
neg
=
true
;
}
if
(
!
c_isdigit
(
*
cur
))
goto
error
;
if
(
virStrToLong_i
(
cur
,
&
tmp
,
10
,
&
start
)
<
0
)
goto
error
;
if
(
start
<
0
)
goto
error
;
cur
=
tmp
;
virSkipSpaces
(
&
cur
);
if
(
*
cur
==
','
||
*
cur
==
0
)
{
if
(
neg
)
{
if
(
virBitmapClearBitExpand
(
*
bitmap
,
start
)
<
0
)
goto
error
;
}
else
{
if
(
virBitmapSetBitExpand
(
*
bitmap
,
start
)
<
0
)
goto
error
;
}
}
else
if
(
*
cur
==
'-'
)
{
if
(
neg
)
goto
error
;
cur
++
;
virSkipSpaces
(
&
cur
);
if
(
virStrToLong_i
(
cur
,
&
tmp
,
10
,
&
last
)
<
0
)
goto
error
;
if
(
last
<
start
)
goto
error
;
cur
=
tmp
;
for
(
i
=
start
;
i
<=
last
;
i
++
)
{
if
(
virBitmapSetBitExpand
(
*
bitmap
,
i
)
<
0
)
goto
error
;
}
virSkipSpaces
(
&
cur
);
}
if
(
*
cur
==
','
)
{
cur
++
;
virSkipSpaces
(
&
cur
);
neg
=
false
;
}
else
if
(
*
cur
==
0
)
{
break
;
}
else
{
goto
error
;
}
}
return
0
;
error:
virReportError
(
VIR_ERR_INVALID_ARG
,
_
(
"Failed to parse bitmap '%s'"
),
str
);
virBitmapFree
(
*
bitmap
);
*
bitmap
=
NULL
;
return
-
1
;
}
/**
* virBitmapNewCopy:
* @src: the source bitmap.
...
...
src/util/virbitmap.h
浏览文件 @
dc56b3a7
...
...
@@ -94,6 +94,10 @@ virBitmapParseSeparator(const char *str,
char
terminator
,
virBitmapPtr
*
bitmap
,
size_t
bitmapSize
);
int
virBitmapParseUnlimited
(
const
char
*
str
,
virBitmapPtr
*
bitmap
)
ATTRIBUTE_NONNULL
(
1
)
ATTRIBUTE_NONNULL
(
2
);
virBitmapPtr
virBitmapNewCopy
(
virBitmapPtr
src
)
ATTRIBUTE_NONNULL
(
1
);
...
...
tests/virbitmaptest.c
浏览文件 @
dc56b3a7
...
...
@@ -632,12 +632,19 @@ test12(const void *opaque ATTRIBUTE_UNUSED)
TEST_MAP
(
151
,
"100"
);
virBitmapFree
(
map
);
if
(
virBitmapParseUnlimited
(
"34,1023"
,
&
map
)
<
0
)
goto
cleanup
;
TEST_MAP
(
1024
,
"34,1023"
);
ret
=
0
;
cleanup:
virBitmapFree
(
map
);
return
ret
;
}
#undef TEST_MAP
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录