mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
hw/9pfs: Add synthetic file system support using 9p
This patch create a synthetic file system with mount tag
v_synth when -virtfs_synth command line option is specified
in qemu. The synthetic file system can be mounted in guest
using 9p using the below command line
mount -t 9p -oversion=9p2000.L,trans=virtio v_synth <mountpint>
Synthetic file system enabled different qemu subsystem to register
callbacks for read and write events from guest. The subsystem
can create directories and files in the synthetic file system as show
in ex below
qemu_v9fs_synth_mkdir(NULL, 0777, "test2", &node);
qemu_v9fs_synth_add_file(node, 0777, "testfile",
my_test_read, NULL, NULL);
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
This commit is contained in:
@@ -310,6 +310,7 @@ hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
|
||||
9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-xattr-user.o virtio-9p-posix-acl.o
|
||||
9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-coth.o cofs.o codir.o cofile.o
|
||||
9pfs-nested-$(CONFIG_VIRTFS) += coxattr.o virtio-9p-handle.o
|
||||
9pfs-nested-$(CONFIG_VIRTFS) += virtio-9p-synth.o
|
||||
|
||||
hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y))
|
||||
$(addprefix 9pfs/, $(9pfs-nested-y)): QEMU_CFLAGS+=$(GLIB_CFLAGS)
|
||||
|
||||
@@ -24,6 +24,7 @@ static QTAILQ_HEAD(FsDriverEntry_head, FsDriverListEntry) fsdriver_entries =
|
||||
static FsDriverTable FsDrivers[] = {
|
||||
{ .name = "local", .ops = &local_ops},
|
||||
{ .name = "handle", .ops = &handle_ops},
|
||||
{ .name = "synth", .ops = &synth_ops},
|
||||
};
|
||||
|
||||
int qemu_fsdev_add(QemuOpts *opts)
|
||||
|
||||
@@ -53,4 +53,5 @@ int qemu_fsdev_add(QemuOpts *opts);
|
||||
FsDriverEntry *get_fsdev_fsentry(char *id);
|
||||
extern FileOperations local_ops;
|
||||
extern FileOperations handle_ops;
|
||||
extern FileOperations synth_ops;
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Virtio 9p
|
||||
*
|
||||
* Copyright IBM, Corp. 2011
|
||||
*
|
||||
* Authors:
|
||||
* Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2. See
|
||||
* the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <limits.h>
|
||||
|
||||
typedef struct V9fsSynthNode V9fsSynthNode;
|
||||
typedef ssize_t (*v9fs_synth_read)(void *buf, int len, off_t offset,
|
||||
void *arg);
|
||||
typedef ssize_t (*v9fs_synth_write)(void *buf, int len, off_t offset,
|
||||
void *arg);
|
||||
typedef struct V9fsSynthNodeAttr {
|
||||
int mode;
|
||||
int inode;
|
||||
int nlink;
|
||||
v9fs_synth_read read;
|
||||
v9fs_synth_write write;
|
||||
} V9fsSynthNodeAttr;
|
||||
|
||||
struct V9fsSynthNode {
|
||||
QLIST_HEAD(, V9fsSynthNode) child;
|
||||
QLIST_ENTRY(V9fsSynthNode) sibling;
|
||||
char name[NAME_MAX];
|
||||
V9fsSynthNodeAttr *attr;
|
||||
V9fsSynthNodeAttr actual_attr;
|
||||
void *private;
|
||||
int open_count;
|
||||
};
|
||||
|
||||
typedef struct V9fsSynthOpenState {
|
||||
off_t offset;
|
||||
V9fsSynthNode *node;
|
||||
} V9fsSynthOpenState;
|
||||
|
||||
extern int qemu_v9fs_synth_mkdir(V9fsSynthNode *parent, int mode,
|
||||
const char *name, V9fsSynthNode **result);
|
||||
extern int qemu_v9fs_synth_add_file(V9fsSynthNode *parent, int mode,
|
||||
const char *name, v9fs_synth_read read,
|
||||
v9fs_synth_write write, void *arg);
|
||||
@@ -212,6 +212,12 @@ union V9fsFidOpenState {
|
||||
int fd;
|
||||
DIR *dir;
|
||||
V9fsXattr xattr;
|
||||
/*
|
||||
* private pointer for fs drivers, that
|
||||
* have its own internal representation of
|
||||
* open files.
|
||||
*/
|
||||
void *private;
|
||||
};
|
||||
|
||||
struct V9fsFidState
|
||||
|
||||
@@ -628,6 +628,15 @@ read-write access is given.
|
||||
@end table
|
||||
ETEXI
|
||||
|
||||
DEF("virtfs_synth", 0, QEMU_OPTION_virtfs_synth,
|
||||
"-virtfs_synth Create synthetic file system image\n",
|
||||
QEMU_ARCH_ALL)
|
||||
STEXI
|
||||
@item -virtfs_synth
|
||||
@findex -virtfs_synth
|
||||
Create synthetic file system image
|
||||
ETEXI
|
||||
|
||||
DEFHEADING()
|
||||
|
||||
DEF("name", HAS_ARG, QEMU_OPTION_name,
|
||||
|
||||
@@ -2717,6 +2717,24 @@ int main(int argc, char **argv, char **envp)
|
||||
qemu_opt_get(opts, "mount_tag"));
|
||||
break;
|
||||
}
|
||||
case QEMU_OPTION_virtfs_synth: {
|
||||
QemuOpts *fsdev;
|
||||
QemuOpts *device;
|
||||
|
||||
fsdev = qemu_opts_create(qemu_find_opts("fsdev"), "v_synth", 1);
|
||||
if (!fsdev) {
|
||||
fprintf(stderr, "duplicate option: %s\n", "virtfs_synth");
|
||||
exit(1);
|
||||
}
|
||||
qemu_opt_set(fsdev, "fsdriver", "synth");
|
||||
qemu_opt_set(fsdev, "path", "/"); /* ignored */
|
||||
|
||||
device = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
|
||||
qemu_opt_set(device, "driver", "virtio-9p-pci");
|
||||
qemu_opt_set(device, "fsdev", "v_synth");
|
||||
qemu_opt_set(device, "mount_tag", "v_synth");
|
||||
break;
|
||||
}
|
||||
case QEMU_OPTION_serial:
|
||||
add_device_config(DEV_SERIAL, optarg);
|
||||
default_serial = 0;
|
||||
|
||||
Reference in New Issue
Block a user