mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-08 10:15:03 +00:00
refactor: 删除多余的代码
Signed-off-by: longjin <longjin@DragonOS.org>
This commit is contained in:
parent
06b0853a1b
commit
870c34c6f2
3
kernel/Cargo.lock
generated
3
kernel/Cargo.lock
generated
@ -1462,8 +1462,7 @@ checksum = "7fcf8323ef1faaee30a44a340193b1ac6814fd9b7b4e88e9d4519a3e4abe1cfd"
|
||||
[[package]]
|
||||
name = "smoltcp"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a1a996951e50b5971a2c8c0fa05a381480d70a933064245c4a223ddc87ccc97"
|
||||
source = "git+https://git.mirrors.dragonos.org.cn/DragonOS-Community/smoltcp.git?rev=3e61c909fd540d05575068d16dc4574e196499ed#3e61c909fd540d05575068d16dc4574e196499ed"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"byteorder 1.5.0",
|
||||
|
@ -259,102 +259,6 @@ impl KObjectManager {
|
||||
}
|
||||
kobj.set_parent(None);
|
||||
}
|
||||
|
||||
fn get_kobj_path_length(kobj: &Arc<dyn KObject>) -> usize {
|
||||
log::info!("get_kobj_path_length() kobj:{:?}", kobj.name());
|
||||
let mut parent = kobj.parent().unwrap().upgrade().unwrap();
|
||||
/* walk up the ancestors until we hit the one pointing to the
|
||||
* root.
|
||||
* Add 1 to strlen for leading '/' of each level.
|
||||
*/
|
||||
let mut length = 0; // 确保 length 被正确初始化
|
||||
let mut iteration_count = 0; // 用于记录迭代次数
|
||||
const MAX_ITERATIONS: usize = 10; // 最大迭代次数
|
||||
|
||||
loop {
|
||||
log::info!(
|
||||
"Iteration {}: parent.name():{:?}",
|
||||
iteration_count,
|
||||
parent.name()
|
||||
);
|
||||
length += parent.name().len() + 1;
|
||||
if let Some(weak_parent) = parent.parent() {
|
||||
if let Some(upgraded_parent) = weak_parent.upgrade() {
|
||||
parent = upgraded_parent;
|
||||
} else {
|
||||
log::error!("Failed to upgrade weak reference to parent");
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
log::error!("Parent has no parent");
|
||||
break;
|
||||
}
|
||||
|
||||
iteration_count += 1;
|
||||
if iteration_count >= MAX_ITERATIONS {
|
||||
log::error!("Reached maximum iteration count, breaking to avoid infinite loop");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
/*
|
||||
static void fill_kobj_path(struct kobject *kobj, char *path, int length)
|
||||
{
|
||||
struct kobject *parent;
|
||||
|
||||
--length;
|
||||
for (parent = kobj; parent; parent = parent->parent) {
|
||||
int cur = strlen(kobject_name(parent));
|
||||
/* back up enough to print this name with '/' */
|
||||
length -= cur;
|
||||
memcpy(path + length, kobject_name(parent), cur);
|
||||
*(path + --length) = '/';
|
||||
}
|
||||
|
||||
pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj),
|
||||
kobj, __func__, path);
|
||||
}
|
||||
*/
|
||||
fn fill_kobj_path(kobj: &Arc<dyn KObject>, path: &mut [u8], length: usize) {
|
||||
let mut parent = kobj.parent().unwrap().upgrade().unwrap();
|
||||
let mut length = length;
|
||||
length -= 1;
|
||||
loop {
|
||||
log::info!("fill_kobj_path parent.name():{:?}", parent.name());
|
||||
let cur = parent.name().len();
|
||||
if length < cur + 1 {
|
||||
// 如果剩余长度不足以容纳当前名称和分隔符,则退出
|
||||
break;
|
||||
}
|
||||
length -= cur;
|
||||
let parent_name = parent.name();
|
||||
let name = parent_name.as_bytes();
|
||||
path[length..(cur + length)].copy_from_slice(&name[..cur]);
|
||||
length -= 1;
|
||||
path[length] = b'/';
|
||||
if let Some(weak_parent) = parent.parent() {
|
||||
if let Some(upgraded_parent) = weak_parent.upgrade() {
|
||||
parent = upgraded_parent;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: 实现kobject_get_path
|
||||
// https://code.dragonos.org.cn/xref/linux-6.1.9/lib/kobject.c#139
|
||||
pub fn kobject_get_path(kobj: &Arc<dyn KObject>) -> String {
|
||||
log::debug!("kobject_get_path() kobj:{:?}", kobj.name());
|
||||
let length = Self::get_kobj_path_length(kobj);
|
||||
let path: &mut [u8] = &mut vec![0; length];
|
||||
Self::fill_kobj_path(kobj, path, length);
|
||||
let path_string = String::from_utf8(path.to_vec()).unwrap();
|
||||
return path_string;
|
||||
}
|
||||
}
|
||||
|
||||
/// 动态创建的kobject对象的ktype
|
||||
|
@ -284,6 +284,7 @@ pub fn timer_init() {
|
||||
}
|
||||
|
||||
/// 计算接下来n毫秒对应的定时器时间片
|
||||
#[allow(dead_code)]
|
||||
pub fn next_n_ms_timer_jiffies(expire_ms: u64) -> u64 {
|
||||
return TIMER_JIFFIES.load(Ordering::SeqCst) + expire_ms * 1000000 / NSEC_PER_JIFFY as u64;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user