代码拉取完成,页面将自动刷新
From f2fe10e3918bcab97a5948c3d88ca91a35b0ede2 Mon Sep 17 00:00:00 2001
From: lixiaokeng <lixiaokeng@huawei.com>
Date: Wed, 1 Jul 2020 11:07:06 +0000
Subject: [PATCH] lvm: code reduce cyclomatic complexity
enhance code and reduce cyclomatic complexity
Fix issue: https://gitee.com/src-openeuler/lvm2/issues/I4RZQQ
Signed-off-by:lixiaokeng <lixiaokeng@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
---
lib/device/dev-cache.c | 41 +++++++++++++++++++++++------------------
1 file changed, 23 insertions(+), 18 deletions(-)
diff --git a/lib/device/dev-cache.c b/lib/device/dev-cache.c
index 94e39fa..868a218 100644
--- a/lib/device/dev-cache.c
+++ b/lib/device/dev-cache.c
@@ -1059,6 +1059,19 @@ static int _device_in_udev_db(const dev_t d)
return 0;
}
+bool time_out(long* time_use, struct timeval start)
+{
+ struct timeval end;
+
+ if (!gettimeofday(&end, NULL)) {
+ *time_use = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec);
+ if (*time_use > udev_getdev_timemax) {
+ return true;
+ }
+ }
+ return false;
+}
+
static int _insert_udev_dir(struct udev *udev, const char *dir)
{
struct udev_enumerate *udev_enum = NULL;
@@ -1067,16 +1080,13 @@ static int _insert_udev_dir(struct udev *udev, const char *dir)
struct udev_device *device;
int r = 1;
int ret = -1;
- struct timeval start, end;
+ struct timeval start;
long time_use = 0;
ret = gettimeofday(&start,NULL);
udev_enum = udev_enumerate_new(udev);
- if (!ret && !gettimeofday(&end,NULL)) {
- time_use = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec);
- if (time_use > udev_getdev_timemax) {
- log_print_unless_silent("Call udev_enumerate_new use %ld usec", time_use);
- }
+ if (!ret && time_out(&time_use, start)) {
+ log_print_unless_silent("Call udev_enumerate_new use %ld usec", time_use);
}
if (!udev_enum) {
log_error("Failed to udev_enumerate_new.");
@@ -1110,14 +1120,12 @@ static int _insert_udev_dir(struct udev *udev, const char *dir)
entry_name);
continue;
}
+
ret = gettimeofday(&start,NULL);
node_name = udev_device_get_devnode(device);
- if (!ret && !gettimeofday(&end,NULL)) {
- time_use = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec);
- if (time_use > udev_getdev_timemax) {
- log_print_unless_silent("Call udev_device_get_devnode use %ld usec, device:%s",
- time_use, entry_name);
- }
+ if (!ret && time_out(&time_use, start)) {
+ log_print_unless_silent("Call udev_device_get_devnode use %ld usec, device:%s",
+ time_use, entry_name);
}
if (!node_name)
@@ -1128,12 +1136,9 @@ static int _insert_udev_dir(struct udev *udev, const char *dir)
ret = gettimeofday(&start,NULL);
first_entry = udev_device_get_devlinks_list_entry(device);
- if (!ret && !gettimeofday(&end,NULL)) {
- time_use = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_usec - start.tv_usec);
- if (time_use > udev_getdev_timemax) {
- log_print_unless_silent("Call udev_device_get_devlinks_list_entry use %ld usec, dev:%s",
- time_use, entry_name);
- }
+ if (!ret && time_out(&time_use, start)) {
+ log_print_unless_silent("Call udev_device_get_devlinks_list_entry use %ld usec, dev:%s",
+ time_use, entry_name);
}
udev_list_entry_foreach(symlink_entry, first_entry) {
if (!(symlink_name = udev_list_entry_get_name(symlink_entry)))
--
1.8.3.1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。