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

Closes #290 #555

Merged
merged 2 commits into from
Jun 3, 2021
Merged

Closes #290 #555

merged 2 commits into from
Jun 3, 2021

Conversation

Medowhill
Copy link
Collaborator

Closes #290

@Medowhill
Copy link
Collaborator Author

Medowhill commented Jun 2, 2021

https://github.com/Medowhill/rv6/blob/fbc469fd467727bc254310cbc11d1b13d05cf361/kernel-rs/src/arena/mod.rs#L62-L68

pub trait ArenaObject {
    type Ctx<'a, 'b: 'a>;
    fn finalize<'a, 'b: 'a, A: Arena>(&mut self, ctx: Self::Ctx<'a, 'b>);
}

ArenaObjectCtxfinalize가 추가로 받을 인자의 타입을 나타냅니다. InodeFilefinalize될 때 KernelCtx가 필요합니다.

https://github.com/Medowhill/rv6/blob/fbc469fd467727bc254310cbc11d1b13d05cf361/kernel-rs/src/fs/ufs/inode.rs#L658-L685

impl ArenaObject for Inode<InodeInner> {
    type Ctx<'a, 'id: 'a> = (&'a UfsTx<'a>, &'a KernelCtx<'id, 'a>);
    ...
}

https://github.com/Medowhill/rv6/blob/fbc469fd467727bc254310cbc11d1b13d05cf361/kernel-rs/src/file.rs#L246-L268

impl ArenaObject for File {
    type Ctx<'a, 'id: 'a> = &'a KernelCtx<'id, 'a>;
    ...
}

KernelCtx는 두 개의 lifetime parameter를 가지고 있습니다.

pub struct KernelCtx<'id, 'p> {
kernel: KernelRef<'id, 'p>,
proc: CurrentProc<'id, 'p>,
}

첫 번째 lifetime parameter는 branded type을 사용하기 위해 붙은 brand이며, 두 번째 lifetime parameter는 커널과 현재 프로세스에 대한 reference의 lifetime입니다.

특정 lifetime을 가진 KernelCtxfinalize에 주어져야 하는 것이 아니라, 아무 KernelCtxfinalize에 주어질 수 있으므로, Ctxfinalize는 두 개의 lifetime parameter를 가지고 있습니다.

만약 Rust에 existential lifetime(rust-lang/rust#60670?)이 있다면 아래와 같은 코드를 작성할 수 있겠지만, 현재는 불가능해 보입니다.

pub trait ArenaObject {
    type Ctx;
    fn finalize<A: Arena>(&mut self, ctx: Self::Ctx);
}

impl ArenaObject for Inode<InodeInner> {
    type Ctx = exists<'a, 'b: 'a> (&'a UfsTx<'a>, &'a KernelCtx<'id, 'a>);
    ...
}

impl ArenaObject for File {
    type Ctx = exists<'a, 'b: 'a> &'a KernelCtx<'id, 'a>;
    ...
}

@Medowhill
Copy link
Collaborator Author

다른 이슈들 작업하면서 Arena 쪽 코드를 조금 건드려야 하는 경우가 종종 있어서 일단 그냥 머지하겠습니다. 이 PR의 방향성에 대해서는 크게 이견이 없을 것 같고, 세부적인 부분에서 수정이 필요할 수 있을 것 같은데, 이후에 리뷰 주시면 별도 PR로 해결하겠습니다.

@Medowhill
Copy link
Collaborator Author

bors r+

@kaist-cp-bors
Copy link
Contributor

kaist-cp-bors bot commented Jun 3, 2021

Build succeeded:

@kaist-cp-bors kaist-cp-bors bot merged commit c6798f7 into kaist-cp:riscv Jun 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inode::finalize() 만으로 Fstransaction이 열린 상태인지 파악하기
1 participant