Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(time): Add syscall support for utime* #838

Merged
merged 3 commits into from
Jun 27, 2024

Conversation

Godones
Copy link
Contributor

@Godones Godones commented Jun 13, 2024

impl sys_utimensat
impl sys_utimes
add utimensat test
fix some warning

impl sys_utimensat
impl sys_utimes
add utimensat test
fix some warning
@github-actions github-actions bot added the enhancement New feature or request label Jun 13, 2024
@fslongjin fslongjin changed the title feat(vfs): Add syscall support for utime* feat(time): Add syscall support for utime* Jun 13, 2024
@fslongjin
Copy link
Member

r? @houmkh

hey,麻烦看看这个

pub fn sys_utimensat(
dirfd: i32,
pathname: *const u8,
times: *const PosixTimeSpec,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里传入的裸指针需要像其他的系统调用那样,用userbuffer结构体去校验合法性&读写

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@dragonosbot dragonosbot added A-fs Area: 文件系统 O-x86_64 Target: x86_64 labels Jun 13, 2024
@@ -1644,9 +1645,9 @@ impl Syscall {
let times = if times.is_null() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉好像不用判断空的,因为如果空指针的话userbuffer会报错

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是允许times为空的

Comment on lines +1112 to +1123
#[cfg(target_arch = "x86_64")]
SYS_FUTIMESAT => {
let flags = UtimensFlags::empty();
Self::sys_utimensat(
args[0] as i32,
args[1] as *const u8,
args[2] as *const PosixTimeSpec,
flags.bits(),
)
}
#[cfg(target_arch = "x86_64")]
SYS_UTIMES => Self::sys_utimes(args[0] as *const u8, args[1] as *const PosixTimeval),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里条件编译的作用是什么,如果是架构特有的系统调用应该放在arch/<x86/riscv>/syscall下,不用条件编译

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其它的系统调用不也是使用这种条件编译的方式吗?arch/<x86/riscv>/syscall目录不是系统调用实现的存放位置吧

Copy link
Member

@Chiichen Chiichen Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有两种情况,一种情况是这个系统调用是架构相关的,比如 SYS_RT_SIGRETURN,第二种情况是定义的系统调用是通用的系统调用,条件编译是因为目前只有X86下有实现,但是系统调用本身是架构无关的。你这两个系统调用SYS_UTIMENSAT 和 SYS_FUTIMESAT,在都是一个逻辑Self::sys_utimensat,但是一个条件编译一个不条件编译,所以才想知道你写条件编译的目的

@@ -87,7 +87,7 @@ extern crate uefi;
extern crate uefi_raw;

use crate::mm::allocator::kernel_allocator::KernelAllocator;

#[cfg(target_os = "none")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这两个#[cfg(target_os = "none")]的作用是什么,kernel会有非none的target_os吗

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

panic函数的实现带有#[cfg(target_os = "none")], 而这里的ProcessManager是在panic函数中使用,为什么不使用这个条件编译呢

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

但是target_os = "none"这个条件在kernel里是恒为真的,你加不加都不会产生实质影响

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是为了消除cargo clippy的一个warning,确实是加不加都可以

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是为了消除cargo clippy的一个warning,确实是加不加都可以

那我觉得就没必要硬加了,确实有warning的话把这个lint禁掉吧

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Comment on lines +1112 to +1123
#[cfg(target_arch = "x86_64")]
SYS_FUTIMESAT => {
let flags = UtimensFlags::empty();
Self::sys_utimensat(
args[0] as i32,
args[1] as *const u8,
args[2] as *const PosixTimeSpec,
flags.bits(),
)
}
#[cfg(target_arch = "x86_64")]
SYS_UTIMES => Self::sys_utimes(args[0] as *const u8, args[1] as *const PosixTimeval),
Copy link
Member

@Chiichen Chiichen Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有两种情况,一种情况是这个系统调用是架构相关的,比如 SYS_RT_SIGRETURN,第二种情况是定义的系统调用是通用的系统调用,条件编译是因为目前只有X86下有实现,但是系统调用本身是架构无关的。你这两个系统调用SYS_UTIMENSAT 和 SYS_FUTIMESAT,在都是一个逻辑Self::sys_utimensat,但是一个条件编译一个不条件编译,所以才想知道你写条件编译的目的

@Godones
Copy link
Contributor Author

Godones commented Jun 18, 2024

因为这几个系统调用可以复用同一个底下的实现,但是SYS_FUTIMESAT以及SYS_UTIMES 在riscv架构下没有定义。

@Chiichen
Copy link
Member

因为这几个系统调用可以复用同一个底下的实现,但是SYS_FUTIMESAT以及SYS_UTIMES 在riscv架构下没有定义。

那这种就应该写到arch/x86/syscall/mod.rs里面,参考SYS_ARCH_PRCTL

@Chiichen
Copy link
Member

Associated issue: #834

@Godones
Copy link
Contributor Author

Godones commented Jun 18, 2024

可能是我的表述有问题,这两个系统调用不是架构相关的,应该属于你说的第二种情况。第二种情况是定义的系统调用是通用的系统调用,条件编译是因为目前只有X86下有实现,但是系统调用本身是架构无关的。我的理解是这里的条件编译是指这个系统调用只在x86平台下使用,其它平台没有这个系统调用。

@Chiichen
Copy link
Member

可能是我的表述有问题,这两个系统调用不是架构相关的,应该属于你说的第二种情况。第二种情况是定义的系统调用是通用的系统调用,条件编译是因为目前只有X86下有实现,但是系统调用本身是架构无关的。我的理解是这里的条件编译是指这个系统调用只在x86平台下使用,其它平台没有这个系统调用。

那ok

kernel/src/lib.rs Outdated Show resolved Hide resolved
@Chiichen Chiichen requested a review from fslongjin June 20, 2024 06:01
@Chiichen
Copy link
Member

@fslongjin LGTM,你看看新的改动

@Chiichen Chiichen merged commit 6f189d2 into DragonOS-Community:master Jun 27, 2024
7 checks passed
Chiichen added a commit that referenced this pull request Sep 2, 2024
* docs(sched):调度子系统文档即cfs文档 (#807)

* 调度子系统文档以及cfs文档

* fix(net): Fix TCP Unresponsiveness and Inability to Close Connections (#791)

* fix(net): Improve stability. 为RawSocket与UdpSocket实现close时调用close方法,符合smoltcp的行为。为SocketInode实现drop,保证程序任何情况下退出时都能正确close对应socket, 释放被占用的端口。

* fix(net): Correct socket close behavior.

* fix: disable mm debug log to prevent system lockup due to thingbuf issue (#808)

* 添加支持gentoo系统的一键安装脚本 (#809)

* feat(driver/pci): add pci bus into sysfs (#792)

把pci设备加入sysfs

* doc: Add Gentoo Linux In build_system.md (#810)

* 增加安装文档中的Gentoo Linux提示

* doc: add v0.1.10 changelog (#813)

* 完成v0.1.10 changelog

* fix(driver/apic_timer): 修复local apic timer初始化顺序导致的在某些云服务器上无法收到中断的bug (#815)

* chore: move setup_arch_post timepoint to before clocksource_boot_finish (#820)

This commit adjusts the timing of the setup_arch_post event to occur before the clocksource_boot_finish event, allowing the time subsystem to properly register architecture-specific clock sources.

* feat(log): 将内核日志统一为新的logger (#814)

* fix(log): 修复pr #814 的问题 (#821)

* feat(driver/pci): 完善pci root结构体,增加portio的pci配置空间访问 (#818)

* feat(driver/pci): 完善pci root结构体,增加portio的pci配置空间访问

* 增加rust sparse稀疏索引选项 (#826)

* fix(time):修复了issue #816 (#830)

* chore(tools): add the gentoo grub_auto_install support (#827)

* 20240524 3:40

* 20240527 0010

* 修复mmap未延迟分配内存的问题

* feat(procfs): update procfs (#831)

为procfs增加是否是kthread的显示
增加返回进程已经占用的文件描述符数量

* Revert "Merge branch 'patch-add-file-mapping' into patch-fix-mmap"

This reverts commit 8eb687c, reversing
changes made to 33e9f0b.

* 20240528 1800

* Revert "Revert "Merge branch 'patch-add-file-mapping' into patch-fix-mmap""

This reverts commit 9261cb7.

* feat(mm): 修复mmap未延迟分配内存的问题 (#837)

* 20240524 3:40

* 20240527 0010

* 修复mmap未延迟分配内存的问题

* Revert "Merge branch 'patch-add-file-mapping' into patch-fix-mmap"

This reverts commit 8eb687c, reversing
changes made to 33e9f0b.

* update-20240529-0347

* fix(driver): fix memory security problem in tty device ioctl (#833)

* add soft link to musl-gcc

* fix the tty_ioctl

* modified

* modified

* update 20240604 0233

* feat(user): user management tool (#825)

* 用户管理工具

* 重构

* 改为多个bin文件入口

* bin文件的usage显示自身程序名而非固定程序名

* update 20240606 1800

* update 20240607 0200

* update 20240617 1747

* 重写页面保护标志的构造逻辑

* update20240620 1726

* 添加Riscv64的protection_map

* 简单实现fat文件系统的文件映射,添加msync系统调用

* trait FileSystem增加统一接口

* MountFS实现文件映射相关接口

* 格式化代码

* feat(time): Add syscall support for utime* (#838)

* feat(vfs): Add syscall support for utime*

impl sys_utimensat
impl sys_utimes
add utimensat test
fix some warning

* fix(vfs): Verify pointer validity

* fix: remove bad cfg

* pagecache存储方式由HashMap改为XArray

* 修复mprotect系统调用未正确设置vm_flags的错误 (#847)

* fix(time): modify update wall time (#836)

更改了时间子系统的update_wall_time函数,通过读取当前周期数,计算delta值进行更新,而不是通过传入delta值进行更新

* chore: 调整triagebot.toml以适应新的组织架构 (#848)

* doc: 完善README.md (#849)

* doc: 完善README.md

* chore: 更新sphinx相关配置,适应read the docs的更新 (#850)

根据read the docs在7月15日blog,进行此修改

https://about.readthedocs.com/blog/2024/07/addons-by-default/

* feat(driver/net): 实现Loopback网卡接口 (#845)

* 初步实现loopback设备

* fix: build-scripts和tools目录下的make check指定工具链版本 (#861)

* fix: tcp poll没有正确处理posix socket的listen状态的问题 (#859)

* 使用读写锁包装Page结构体

* chore: 将工具链更新到2024-07-23 (#864)

* chore: 将工具链更新到2024-07-23

* PageCache由存放物理地址改为直接存放页面

* 优化protection_map的初始化方式

* feat(fs): add eventfd syscall support (#858)

* feat(fs): add eventfd syscall support

* refactor: 删除过时的va-pa转换函数,改为统一使用MMArch (#862)

* 添加shrink_list方法释放页面

* 默认nightly-2024-07-23 & config改为config.toml (#872)

* fix: 修复由于升级到2024-07-23工具链之后,某些机器上面内核运行一直fault的问题。 (#870)

* fix: 修复由于升级到2024-07-23工具链之后,某些机器上面内核运行一直fault的问题。

* 添加页面回收机制

* 添加页面回收内核线程

* feat(cred): 初步实现Cred (#846)

* 初步实现Cred

* 添加seteuid和setegid

* 添加cred测试程序

* 修改Cred::fscmp返回结果为CredFsCmp枚举

* 完善root用户相关信息

* fix: 修复键盘码解析器没能正确处理类似ctrl C的控制字符的问题 (#877)

* fix: 修复键盘码解析器没能正确处理类似ctrl C的控制字符的问题

* fix: 解决ntty潜在的panic问题

* 缺页中断使用的锁修改为irq_save; 添加脏页回写机制

* 优化代码结构,添加部分注释

* ci: enable ci workflow on branches other than master (#891)

* 修复unlink、unlinkat系统调用的路径错误 (#892)

* fix: socket shutdown wrong implement (#893)

* feat: 增加tokio异步运行时支持 (#894)

* fix the EventFdFlags error

* feat: support tokio (Single thread version)

Fix deadlock issue on closing file.
Add function for PipeInode and EventFdInode.

* 优化PageCache的创建

* fix: pipe 读取/写入阻塞时,无法kill进程的问题 (#889)

* 将入口点改为链接器;修正链接器加载地址

* 修复合并错误

* 修复do_cow_page死锁问题

* 将PageFaultMessage中的地址对齐

* auxv添加随机数指针;修复AtType序号错误

* 简单实现用户栈的16字节对齐

* 通过check fmt

* 完善用户栈的字节对齐机制

* 通过riscv64编译

* 修改测试程序路径

* 添加动态库libgcc_s.so.1

---------

Co-authored-by: GnoCiYeH <[email protected]>
Co-authored-by: Samuel Dai <[email protected]>
Co-authored-by: LoGin <[email protected]>
Co-authored-by: donjuanplatinum <[email protected]>
Co-authored-by: 曾俊 <[email protected]>
Co-authored-by: Mingtao Huang <[email protected]>
Co-authored-by: BrahmaMantra <[email protected]>
Co-authored-by: laokengwt <[email protected]>
Co-authored-by: Jomo <[email protected]>
Co-authored-by: linfeng <[email protected]>
Co-authored-by: SMALLC <[email protected]>
Co-authored-by: linfeng <[email protected]>
Co-authored-by: Chiichen <[email protected]>
Co-authored-by: Samuel Dai <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-fs Area: 文件系统 enhancement New feature or request O-x86_64 Target: x86_64
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants