-
Notifications
You must be signed in to change notification settings - Fork 60
Support virtio-fs #88
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
base: master
Are you sure you want to change the base?
Conversation
README.md
Outdated
@@ -77,13 +77,33 @@ You can exit the emulator using: \<Ctrl-a x\>. (press Ctrl+A, leave it, afterwar | |||
## Usage | |||
|
|||
```shell | |||
./semu -k linux-image [-b dtb-file] [-i initrd-image] [-d disk-image] | |||
./semu -k linux-image [-b dtb-file] [-i initrd-image] [-d disk-image] [-s mount-folder] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never use "folder." Instead, use "directory."
configs/linux.config
Outdated
@@ -102,7 +102,8 @@ CONFIG_SRCU=y | |||
CONFIG_TINY_SRCU=y | |||
# end of RCU Subsystem | |||
|
|||
# CONFIG_IKCONFIG is not set | |||
CONFIG_IKCONFIG=y | |||
CONFIG_IKCONFIG_PROC=y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minimize the necessary changes.
configs/linux.config
Outdated
@@ -1257,7 +1262,7 @@ CONFIG_INOTIFY_USER=y | |||
# CONFIG_QUOTA is not set | |||
CONFIG_AUTOFS4_FS=y | |||
CONFIG_AUTOFS_FS=y | |||
# CONFIG_FUSE_FS is not set | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix build breakage.
int32_t error; | ||
uint64_t unique; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant line.
fuse.h
Outdated
|
||
struct fuse_lookup_in { | ||
uint64_t parent; // inode of parent dir | ||
// char name[]; // followed by name (not null-terminated!) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't leave dead code. Add TODO if this requires further development.
main.c
Outdated
|
||
#if SEMU_HAS(VIRTIOFS) | ||
case 0x48: /* virtio-fs */ | ||
// printf("width:%d\n",width); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove debugging code.
minimal.dts
Outdated
compatible = "virtio,mmio"; | ||
reg = <0x4800000 0x1000>; | ||
interrupts = <6>; | ||
tag = "myfs"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is tag necessary?
#define FUSE_RELEASE 18 | ||
#define FUSE_FLUSH 25 | ||
#define FUSE_DESTROY 38 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant line.
fuse.h
Outdated
}; | ||
|
||
struct fuse_init_in { | ||
uint32_t major; // FUSE major version supported by the guest (typically 7) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow the coding style guide from CONTRIBUTING.md, i.e., using /* ... */
instead of // ...
for single-line comment.
fuse.h
Outdated
uint32_t major; // FUSE major version supported by the device | ||
uint32_t minor; // FUSE minor version supported by the device | ||
uint32_t max_readahead; // Maximum readahead size accepted by the device | ||
uint32_t |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrite like
/* Flags supported by the device (negotiated with the guest) */
uint32_t flags;
to avoid line breaking.
uint64_t lock_owner; | ||
}; | ||
|
||
struct fuse_flush_in { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <sys/uio.h> | ||
#include <time.h> | ||
#include <unistd.h> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove all redundant lines in the file.
case FUSE_DESTROY: | ||
virtio_fs_destroy_handler(vfs, vq_desc, plen); | ||
break; | ||
default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add TODO for the OP codes to implement in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always write comments in C-style and American English.
Clean up the commit history by squashing related commits using
|
Why |
Please improve the pull request description to make the content clearer and easier to understand. See: |
Please move |
Many thanks to @shengwen-tw . I rebased the branch, and split the changes into two commits: one for configs/linux.config, and the other for the rest. |
device.h
Outdated
|
||
typedef struct { | ||
uint64_t ino; | ||
char path[4096]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of hard-coding the value, consider using PATH_MAX
from the standard library (limits.h
) for better portability and readability.
#include <stdio.h>
#include <limits.h>
int main(void) {
printf("PATH_MAX is defined: %d\n", PATH_MAX);
return 0;
}
main.c
Outdated
|
||
#if SEMU_HAS(VIRTIOFS) | ||
case 0x48: /* virtio-fs */ | ||
// printf("width:%d\n",width); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove debugging code.
main.c
Outdated
execpath); | ||
fprintf(stderr, | ||
"Usage: %s -k linux-image [-b dtb] [-i initrd-image] [-d " | ||
"disk-image] [-s mount-folder]\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use directory (UNIX terminology)
instead of folder (Windows terminology)
.
@@ -24,6 +24,45 @@ | |||
#define VIRTIO_BLK_S_IOERR 1 | |||
#define VIRTIO_BLK_S_UNSUPP 2 | |||
|
|||
#define FUSE_INIT 26 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you point out the source for the FUSE OP codes and what are missing in the current implementation?
device.h
Outdated
/* guest memory base */ | ||
uint32_t *ram; | ||
|
||
char *mount_tag; // guest sees this tag |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use /* ... */
instead.
virtio-fs.c
Outdated
PACKED(struct virtio_fs_config { | ||
char tag[36]; | ||
uint32_t num_request_queues; | ||
uint32_t notify_buf_size; // ignored |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrite all // ...
with /* ... */
in this file.
virtio-fs.c
Outdated
|
||
typedef struct { | ||
DIR *dir; | ||
char path[4096]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to use malloc()
instead of a fixing path size?
virtio-fs.c
Outdated
uint32_t *ram = vfs->ram; | ||
void *priv = vfs->priv; | ||
char *mount_tag = vfs->mount_tag; | ||
char shared_dir[4096]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to use malloc()
instead of a fixing path size?
virtio-fs.c
Outdated
*plen = header_resp->out.len; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove redundant lines.
virtio-fs.c
Outdated
fprintf(stderr, "unsupported virtio-fs operation!\n"); | ||
return -1; | ||
} | ||
/* TO DO: FUSE_WRITE, FUSE_MKDIR, FUSE_RMDIR , FUSE_CREATE */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use TODO
instead of TO DO
.
Check Effectively Managing Technical Debt with TODO, FIXME, and Other Code Reminders.
README.md
Outdated
@@ -77,13 +77,33 @@ You can exit the emulator using: \<Ctrl-a x\>. (press Ctrl+A, leave it, afterwar | |||
## Usage | |||
|
|||
```shell | |||
./semu -k linux-image [-b dtb-file] [-i initrd-image] [-d disk-image] | |||
./semu -k linux-image [-b dtb-file] [-i initrd-image] [-d disk-image] [-s mount-directory] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mount-directory
might be ambiguous, especially in contexts involving virtio-blk
devices. Consider renaming it to something more descriptive, such as shared-directory
.
Drop |
9168250
to
9210af1
Compare
@MikazukiHikari Hi, could you provide a Linux image with virtio-fs enabled for quick testing? Thank you! |
Please rebase to the latest remote master branch. Otherwise, the build on macOS will fail. |
No problem! How should I send it to you? via Gmail? Or just commit the Linux image? |
You can simply upload to this code review thread. |
THX for the reminder. |
@MikazukiHikari After a quick test, it seems that the create operation is not yet implemented. However, you mentioned file creation in your earlier comment. I encountered the following error when trying to create a file using the touch command in the guest:
My testing environment: |
You're right! I wrote the previous comment incorrectly — it's been corrected. Sorry for the confusion. |
Map MMIO region at 0xF48____ for virtio-fs device in semu. Introduce special-case logic for char tag in virtio_fs config handling in semu. Add inode_map hash table for mapping inodes to file paths. Implement FUSE core operations: - INIT - GETATTR - OPENDIR - READDIRPLUS - LOOKUP - FORGET - RELEASEDIR - OPEN - READ - RELEASE - FLUSH - DESTROY to make semu supports commands:`cd`, `cat`, `ls`. Introduced uthash.h to implement a hash table for mapping inode numbers to file paths. This improves lookup performance and simplifies path management in the virtio-fs implementation. Set default mount tag to "myfs" and mount directory to "./shared". When `make check`, if MOUNT_DIRECTORY is not exist, then create a new one. If -s parameter is empty, virtio-fs is unused. Add the explanation about virtio-fs in `Usage` of README.md. Add the introduction of how to mount and unmount in semu.
Overview
This commit introduces the VirtIO file system device (virtio-fs) to enable efficient and secure sharing of host directories with semu.
Implementation Details
Test Procedures
ls
,cat
, andcd
to ensure correct operation.This project is implemented on 6.11.0-26-generic 24.04.1-Ubuntu GNU/Linux.