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

Integrate the virtual 9P driver with the fs library to make it support fs operations #402

Merged
merged 5 commits into from
Apr 25, 2024

Conversation

mob5566
Copy link
Contributor

@mob5566 mob5566 commented Apr 19, 2024

With the following changes, the VirtIO 9p device can be exported as a LK filesystem and use the file APIs, e.g. fs_open_file, fs_read_file, fs_write_file, etc.

An example of using LK command ls to examine the shared filesystem is provided.

# Build the littlekernel with the current directory (the codebase) as
the shared v9p folder
$ scripts/do-qemuarm -f .
...
welcome to lk/MP

boot args 0x0 0x0 0x0 0x0
INIT: cpu 0, calling hook 0x8011fa81 (version) at level 0x3ffff,
flags 0x1
...
# Mount the default VirtIO 9p device `v9p0` as the 9p filesystem onto
# `/v9p` path
] fs mount /v9p 9p v9p0
# List the `/v9p` folder, and we can see the littlekernel codebase
] ls /v9p
D 4096             arch
F 590              lk_inc.mk.example
D 4096             .cache
D 4096             project
D 4096             .github
...

On the other hand, I add an example test v9fs_tests to validate the basic functions of the VirtIO 9p filesystem. The test does a similar check as app/tests/v9p_tests.c. It mount the littlekernel codebase onto /v9p and dump the first 1024 bytes of the LICENSE file.

starting internet servers
starting app shell
entering main console loop
] v9fs_tests
0x802d5060: 2f 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20 |/*. * Copyright
0x802d5070: 28 63 29 20 32 30 30 38 2d 32 30 31 35 20 54 72 |(c) 2008-2015 Tr
0x802d5080: 61 76 69 73 20 47 65 69 73 65 6c 62 72 65 63 68 |avis Geiselbrech
0x802d5090: 74 0a 20 2a 0a 20 2a 20 50 65 72 6d 69 73 73 69 |t. *. * Permissi
0x802d50a0: 6f 6e 20 69 73 20 68 65 72 65 62 79 20 67 72 61 |on is hereby gra

Signed-off-by: Cody Wong <codycswong@google.com>
Add the fundamental filesystem structure to attach a VirtualIO 9p
device. With the implementation of VirtIO 9p devices (lk/dev/virtio/9p),
we can use those APIs to connect to a shared folder as a LK filesystem.

Signed-off-by: Cody Wong <codycswong@google.com>
 - Add the directory operations, e.g., open directory, make directory,
   read directory, and close directory.

Signed-off-by: Cody Wong <codycswong@google.com>
 - Add the file operations APIs for VirtIO 9p devices, such as file
   create/open/close/read/write/stat.
 - After this commit, almost complete file operations for v9p file
   sharing are supported. An intuitive example is that users can use
   filesystem commands, such as `ls`, to examine the shared folder.

   Example:

   ```
   # Build the littlekernel with the current directory (the codebase) as
   the shared v9p folder
   $ scripts/do-qemuarm -f .
   ...
   welcome to lk/MP

   boot args 0x0 0x0 0x0 0x0
   INIT: cpu 0, calling hook 0x8011fa81 (version) at level 0x3ffff,
   flags 0x1
   ...
   # Mount the default VirtIO 9p device `v9p0` as the 9p filesystem onto
   # `/v9p` path
   ] fs mount /v9p 9p v9p0
   # List the `/v9p` folder, and we can see the littlekernel codebase
   ] ls /v9p
   D 4096             arch
   F 590              lk_inc.mk.example
   D 4096             .cache
   D 4096             project
   D 4096             .github
   D 4096             platform
   D 4096             kernel
   D 4096             external
   F 1132             LICENSE
   D 4096             target
   D 4096             dev
   D 4096             .git
   F 120              .gitignore
   F 12579            engine.mk
   F 1388             README.md
   D 4096             make
   D 4096             top
   error -2 opening file '/v9p/..'
   D 4096             build-qemu-virt-arm32-test
   F 763965           compile_commands.json
   D 4096             scripts
   D 4096             lib
   D 4096             app
   D 4096             docs
   D 4096             .
   D 4096             tools
   F 1113             makefile
   ```

Signed-off-by: Cody Wong <codycswong@google.com>
Add a simple test to validate the filesystem APIs that connect the LK
filesystem layer and the virtualIO 9p devices. The test does the same as
`app/tests/v9p_tests.c` to mount the littlekernel codebase folder as the
`/v9p` on the LK filesystem. Then it tries to read the `LICENSE` file
under the codebase and show the first 1024 bytes of the file.

For example:

```
starting internet servers
starting app shell
entering main console loop
] v9fs_tests
0x80017060: 2f 2a 0a 20 2a 20 43 6f 70 79 72 69 67 68 74 20 |/*. * Copyright
0x80017070: 28 63 29 20 32 30 30 38 2d 32 30 31 35 20 54 72 |(c) 2008-2015 Tr
0x80017080: 61 76 69 73 20 47 65 69 73 65 6c 62 72 65 63 68 |avis Geiselbrech
0x80017090: 74 0a 20 2a 0a 20 2a 20 50 65 72 6d 69 73 73 69 |t. *. * Permissi
0x800170a0: 6f 6e 20 69 73 20 68 65 72 65 62 79 20 67 72 61 |on is hereby gra
...
```

Signed-off-by: Cody Wong <codycswong@google.com>
@travisg
Copy link
Member

travisg commented Apr 25, 2024

Very cool! Taking as is. Looks great!

@travisg travisg merged commit 7cda17e into littlekernel:master Apr 25, 2024
189 checks passed
@travisg
Copy link
Member

travisg commented Apr 25, 2024

Suggestion: move the test stuff into lib/fs/v9p to go along with it. I'm starting to move things out of that app into sub modules for various things and trying to generally switch standalone things to the unittest framework. I think FS tests are probably not usable as a unittest per se, since they require the system be set up a particular way, but as an example lib/fs/fat has a test sub module with all the stuff there.

@travisg
Copy link
Member

travisg commented Apr 25, 2024

Oh there's a WITH_TESTS build variable and #define that you can switch including the submodule on.

@mob5566
Copy link
Contributor Author

mob5566 commented Apr 26, 2024

Hi @travisg,

That sounds great! I should have moved the testing code along with the modules, right? The folder app/tests will contain unittests only. Do I understand correctly?

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.

None yet

2 participants