tools/kvm/9p: Always include system header before our headers
PATCH 1/2 tools/kvm/9p: Always include system header before our headers
Otherwise many things can break, such as mapping of stat to stat64
--- tools/kvm/virtio/9p.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
tools/kvm/virtio/9p.c +6 -6
@@ -1,3 +1,9 @@ +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <pthread.h> +#include <dirent.h> +#include "kvm/virtio-9p.h" #include "kvm/virtio-pci-dev.h" #include "kvm/virtio.h"
@@ -13,12 +19,6 @@#include <linux/virtio_9p.h> #include <net/9p/9p.h> -#include <fcntl.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <pthread.h> -#include <dirent.h> -#define NUM_VIRT_QUEUES 1#define VIRTIO_P9_QUEUE_SIZE 128#define VIRTIO_P9_TAG "kvm_9p"
Signature · 1 line
1.7.4.1
PATCH 2/2 tools/kvm/9p: Add support for multiple 9p export dirs
--- tools/kvm/include/kvm/virtio-9p.h | 2 +- tools/kvm/kvm-run.c | 37 +++-- tools/kvm/virtio/9p.c | 357 +++++++++++++++++++++--------------- 3 files changed, 234 insertions(+), 162 deletions(-)
tools/kvm/include/kvm/virtio-9p.h +1 -1
@@ -3,6 +3,6 @@struct kvm ; -void virtio_9p__init (struct kvm *kvm,const char *root); +void virtio_9p__init (struct kvm *kvm,const char *root,const char *tag_name);#endif
tools/kvm/kvm-run.c +25 -12
@@ -69,7 +69,6 @@ static const char *network;static const char *host_ip_addr;static const char *guest_mac;static const char *script; -static const char *virtio_9p_dir;static bool single_step;static bool readonly_image[MAX_DISK_IMAGES ];static bool vnc;
@@ -108,6 +107,29 @@ static int img_name_parser(const struct option *opt, const char *arg, int unset)return 0 ; } +static int virtio_9p_rootdir_parser (const struct option *opt,const char *arg,int unset) +{ +char *tag_name; +char tmp[PATH_MAX ]; + +/* +* 9p dir can be of the form dirname,tag_name or +* just dirname. In the later case we use the +* default tag name +*/ + tag_name =strstr (arg,"," ); +if (tag_name) { + *tag_name ='\0' ; + tag_name++; + } +if (realpath (arg, tmp)) +virtio_9p__init (kvm, tmp, tag_name); +else +die ("Failed resolving 9p path" ); +return 0 ; +} + +static const struct option options[] = {OPT_GROUP ("Basic options:" ),OPT_INTEGER ('c' ,"cpus" , &nrcpus,"Number of CPUs" ),
@@ -118,8 +140,8 @@ static const struct option options[] = {OPT_INCR ('\0' ,"rng" , &virtio_rng,"Enable virtio Random Number Generator" ),OPT_STRING ('\0' ,"kvm-dev" , &kvm_dev,"kvm-dev" ,"KVM device file" ), -OPT_STRING ('\0' ,"virtio-9p" , &virtio_9p_dir,"root dir" , -"Enable 9p over virtio" ), +OPT_CALLBACK ('\0' ,"virtio-9p" ,NULL ,"dirname,tag_name" , +"Enable 9p over virtio" , virtio_9p_rootdir_parser),OPT_BOOLEAN ('\0' ,"vnc" , &vnc,"Enable VNC framebuffer" ), OPT_BOOLEAN('\0', "sdl", &sdl, "Enable SDL framebuffer"),
@@ -520,15 +542,6 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)if (!script) script =DEFAULT_SCRIPT ; -if (virtio_9p_dir) { -char tmp[PATH_MAX ]; - -if (realpath (virtio_9p_dir, tmp)) -virtio_9p__init (kvm, tmp); -else -die ("Failed resolving 9p path" ); - } -symbol__init (vmlinux_filename);term_init ();
tools/kvm/virtio/9p.c +208 -149
681 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Re: [PATCH 2/2] tools/kvm/9p: Add support for multiple 9p export dirs
Quoted 6 lines · Aneesh Kumar K.V
Signed-off-by Aneesh Kumar K.V <[email protected]>--- tools/kvm/include/kvm/virtio-9p.h | 2 +- tools/kvm/kvm-run.c | 37 +++-- tools/kvm/virtio/9p.c | 357 +++++++++++++++++++++--------------- 3 files changed, 234 insertions(+), 162 deletions(-)
Looks great!
Signature · 1 line
Sasha.
Quoted 1 line · Aneesh Kumar K.V
Otherwise many things can break, such as mapping of stat to stat64
We always include our headers before system headers to make sure we don't have any hidden prerequisites or dependencies within the headers.
Why did you need to move system headers before our headers in this case?
Quoted 5 lines
Signed-off-by Aneesh Kumar K.V <[email protected]>--- tools/kvm/virtio/9p.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
Signature · 1 line
Sasha.
Quoted 7 lines · Sasha Levin
Quoted 1 line · Aneesh Kumar K.V
Otherwise many things can break, such as mapping of stat to stat64
We always include our headers before system headers to make sure we don't have any hidden prerequisites or dependencies within the headers.
Why did you need to move system headers before our headers in this case?
The stat64() breakage seems rather odd since we do this in the Makefile:
DEFINES += -D_FILE_OFFSET_BITS=64
DEFINES += -D_GNU_SOURCE
Aneesh, what kind of build problems are you seeing?
Quoted 7 lines · Pekka Enberg
Quoted 6 lines · Sasha Levin
Quoted 1 line · Aneesh Kumar K.V
Otherwise many things can break, such as mapping of stat to stat64
We always include our headers before system headers to make sure we don't have any hidden prerequisites or dependencies within the headers.
Quoted 8 lines
Quoted 1 line
Why did you need to move system headers before our headers in this case?
The
stat64()breakage seems rather odd since we do this in theMakefile:DEFINES += -D_FILE_OFFSET_BITS=64
DEFINES += -D_GNU_SOURCEAneesh, what kind of build problems are you seeing?
ubuntu natty x86_32 system. When you try to mount 9p you get "not a directory" error, because virtio_p9_stat gets the stat value wrong and virtio_p9_fill_stat don't find the export dir as a directory.
-aneesh
Quoted 7 lines · Pekka Enberg
Quoted 6 lines · Sasha Levin
Quoted 1 line · Aneesh Kumar K.V
Otherwise many things can break, such as mapping of stat to stat64
We always include our headers before system headers to make sure we don't have any hidden prerequisites or dependencies within the headers.
Quoted 8 lines
Quoted 1 line
Why did you need to move system headers before our headers in this case?
The
stat64()breakage seems rather odd since we do this in theMakefile:DEFINES += -D_FILE_OFFSET_BITS=64
DEFINES += -D_GNU_SOURCEAneesh, what kind of build problems are you seeing?
Ok the below change also fix the issue for me. So it could be some mapping in the kernel headers
tools/kvm/virtio/9p.c +4 -4
@@ -9,16 +9,16 @@#include "kvm/threadpool.h" #include "kvm/irq.h" -#include <linux/virtio_ring.h> -#include <linux/virtio_9p.h> -#include <net/9p/9p.h> -#include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> #include <pthread.h> #include <dirent.h> +#include <linux/virtio_ring.h> +#include <linux/virtio_9p.h> +#include <net/9p/9p.h> +#define NUM_VIRT_QUEUES 1#define VIRTIO_P9_QUEUE_SIZE 128#define VIRTIO_P9_TAG "kvm_9p"
Quoted 35 lines · Aneesh Kumar K.V
Quoted 7 lines · Pekka Enberg
Quoted 6 lines · Sasha Levin
Quoted 1 line · Aneesh Kumar K.V
Otherwise many things can break, such as mapping of stat to stat64
We always include our headers before system headers to make sure we don't have any hidden prerequisites or dependencies within the headers.
Quoted 8 lines
Quoted 1 line
Why did you need to move system headers before our headers in this case?
The
stat64()breakage seems rather odd since we do this in theMakefile:DEFINES += -D_FILE_OFFSET_BITS=64
DEFINES += -D_GNU_SOURCEAneesh, what kind of build problems are you seeing?
Ok the below change also fix the issue for me. So it could be some mapping in the kernel headers
tools/kvm/virtio/9p.c +0
-4@@ -9,16 +9,16 @@#include "kvm/threadpool.h" #include "kvm/irq.h" -#include <linux/virtio_ring.h> -#include <linux/virtio_9p.h> -#include <net/9p/9p.h> -#include <fcntl.h> #include <sys/types.h> #include <sys/stat.h>
tools/kvm/virtio/9p.c line 24
Quoted 10 lines
tools/kvm/virtio/9p.c +4
-0#include <pthread.h> #include <dirent.h> +#include <linux/virtio_ring.h> +#include <linux/virtio_9p.h> +#include <net/9p/9p.h> +#define NUM_VIRT_QUEUES 1#define VIRTIO_P9_QUEUE_SIZE 128#define VIRTIO_P9_TAG "kvm_9p"
Yes, makes sense. Can you send that as a proper patch and I'll apply it?
The ordering of #includes is as follows:
1. Our own headers. This helps in ensuring there's no missing
#includes in the headers themselves.
2. Library headers and glibc headers
3. Linux kernel headers.
Code that doesn't follow that is a bug waiting to happen.
Pekka