* [PATCH 1/5] kvm tools: Remove unconditional warning in ivshmem
@ 2011-09-05 23:23 Sasha Levin
2011-09-05 23:23 ` [PATCH 2/5] kvm tools: Fix 32bit warnings Sasha Levin
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Sasha Levin @ 2011-09-05 23:23 UTC (permalink / raw)
To: penberg; +Cc: kvm, mingo, gorcunov, asias.hejun, Sasha Levin
This patch prevents printing a warning if ivshmem device wasn't requested.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/hw/pci-shmem.c | 4 +---
1 files changed, 1 insertions(+), 3 deletions(-)
diff --git a/tools/kvm/hw/pci-shmem.c b/tools/kvm/hw/pci-shmem.c
index 295f5cd..f820164 100644
--- a/tools/kvm/hw/pci-shmem.c
+++ b/tools/kvm/hw/pci-shmem.c
@@ -222,10 +222,8 @@ int pci_shmem__init(struct kvm *kvm)
u8 dev, line, pin;
char *mem;
- if (shmem_region == 0) {
- pr_warning("pci_shmem_init: memory region not registered\n");
+ if (shmem_region == 0)
return 0;
- }
/* Register good old INTx */
if (irq__register_device(PCI_DEVICE_ID_PCI_SHMEM, &dev, &pin, &line) < 0)
--
1.7.6.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/5] kvm tools: Fix 32bit warnings
2011-09-05 23:23 [PATCH 1/5] kvm tools: Remove unconditional warning in ivshmem Sasha Levin
@ 2011-09-05 23:23 ` Sasha Levin
2011-09-05 23:23 ` [PATCH 3/5] kvm tools: Attach default 'root=' only if required Sasha Levin
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Sasha Levin @ 2011-09-05 23:23 UTC (permalink / raw)
To: penberg; +Cc: kvm, mingo, gorcunov, asias.hejun, Sasha Levin
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/hw/pci-shmem.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/kvm/hw/pci-shmem.c b/tools/kvm/hw/pci-shmem.c
index f820164..2907a66 100644
--- a/tools/kvm/hw/pci-shmem.c
+++ b/tools/kvm/hw/pci-shmem.c
@@ -205,7 +205,7 @@ static void *setup_shmem(const char *key, size_t len, int creating)
if (creating) {
rtn = ftruncate(fd, (off_t) len);
if (rtn < 0)
- pr_warning("Can't ftruncate(fd,%ld)\n", len);
+ pr_warning("Can't ftruncate(fd,%zu)\n", len);
}
mem = mmap(NULL, len,
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_NORESERVE, fd, 0);
--
1.7.6.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/5] kvm tools: Attach default 'root=' only if required
2011-09-05 23:23 [PATCH 1/5] kvm tools: Remove unconditional warning in ivshmem Sasha Levin
2011-09-05 23:23 ` [PATCH 2/5] kvm tools: Fix 32bit warnings Sasha Levin
@ 2011-09-05 23:23 ` Sasha Levin
2011-09-05 23:23 ` [PATCH 4/5] kvm tools: Teach 'run' to handle guestfs Sasha Levin
2011-09-05 23:23 ` [PATCH 5/5] kvm tools: Add guestfs network autoconfiguration Sasha Levin
3 siblings, 0 replies; 6+ messages in thread
From: Sasha Levin @ 2011-09-05 23:23 UTC (permalink / raw)
To: penberg; +Cc: kvm, mingo, gorcunov, asias.hejun, Sasha Levin
This patch fixes a case where the 'root=' parameter was passed twice
when using virtio-9p root mode.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/builtin-run.c | 7 +++----
1 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index b9efde2..ef1a358 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -739,11 +739,10 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
strlcat(real_cmdline, " init=/bin/sh ", sizeof(real_cmdline));
}
- if (!strstr(real_cmdline, "root="))
- strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline));
-
if (using_rootfs)
- strcat(real_cmdline, " root=/dev/root rootflags=rw,trans=virtio,version=9p2000.L rootfstype=9p");
+ strcat(real_cmdline, " root=/dev/root rw rootflags=rw,trans=virtio,version=9p2000.L rootfstype=9p");
+ else if (!strstr(real_cmdline, "root="))
+ strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline));
if (image_count) {
kvm->nr_disks = image_count;
--
1.7.6.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 4/5] kvm tools: Teach 'run' to handle guestfs
2011-09-05 23:23 [PATCH 1/5] kvm tools: Remove unconditional warning in ivshmem Sasha Levin
2011-09-05 23:23 ` [PATCH 2/5] kvm tools: Fix 32bit warnings Sasha Levin
2011-09-05 23:23 ` [PATCH 3/5] kvm tools: Attach default 'root=' only if required Sasha Levin
@ 2011-09-05 23:23 ` Sasha Levin
2011-09-06 13:37 ` Cyrill Gorcunov
2011-09-05 23:23 ` [PATCH 5/5] kvm tools: Add guestfs network autoconfiguration Sasha Levin
3 siblings, 1 reply; 6+ messages in thread
From: Sasha Levin @ 2011-09-05 23:23 UTC (permalink / raw)
To: penberg; +Cc: kvm, mingo, gorcunov, asias.hejun, Sasha Levin
This patch allows to run previously created guestfs by simply specifying it
with the '-d' parameter.
This allows running guestfs which were created before using:
kvm setup -n [name]
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/builtin-run.c | 24 ++++++++++++++++++++++--
tools/kvm/include/kvm/kvm.h | 3 +++
tools/kvm/kvm.c | 2 --
3 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index ef1a358..725c23c 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -85,6 +85,7 @@ static bool vnc;
static bool sdl;
static bool balloon;
static bool using_rootfs;
+static bool custom_rootfs;
extern bool ioport_debug;
extern int active_console;
extern int debug_iodelay;
@@ -103,6 +104,7 @@ static int img_name_parser(const struct option *opt, const char *arg, int unset)
{
char *sep;
struct stat st;
+ char path[PATH_MAX];
if (stat(arg, &st) == 0 &&
S_ISDIR(st.st_mode)) {
@@ -115,6 +117,21 @@ static int img_name_parser(const struct option *opt, const char *arg, int unset)
return 0;
}
+ snprintf(path, PATH_MAX, "%s%s%s", HOME_DIR, KVM_PID_FILE_PATH, arg);
+
+ if (stat(path, &st) == 0 &&
+ S_ISDIR(st.st_mode)) {
+ char tmp[PATH_MAX];
+
+ if (realpath(path, tmp) == 0 ||
+ virtio_9p__register(kvm, tmp, "/dev/root") < 0)
+ die("Unable to initialize virtio 9p");
+ if (virtio_9p__register(kvm, "/", "hostfs") < 0)
+ die("Unable to initialize virtio 9p");
+ using_rootfs = custom_rootfs = 1;
+ return 0;
+ }
+
if (image_count >= MAX_DISK_IMAGES)
die("Currently only 4 images are supported");
@@ -739,10 +756,13 @@ int kvm_cmd_run(int argc, const char **argv, const char *prefix)
strlcat(real_cmdline, " init=/bin/sh ", sizeof(real_cmdline));
}
- if (using_rootfs)
+ if (using_rootfs) {
strcat(real_cmdline, " root=/dev/root rw rootflags=rw,trans=virtio,version=9p2000.L rootfstype=9p");
- else if (!strstr(real_cmdline, "root="))
+ if (custom_rootfs)
+ strcat(real_cmdline, " init=/virt/init");
+ } else if (!strstr(real_cmdline, "root=")) {
strlcat(real_cmdline, " root=/dev/vda rw ", sizeof(real_cmdline));
+ }
if (image_count) {
kvm->nr_disks = image_count;
diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index d471cee..bb40c4c 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -24,6 +24,9 @@
#define SIGKVMRESUME (SIGRTMIN + 5)
#define SIGKVMMEMSTAT (SIGRTMIN + 6)
+#define KVM_PID_FILE_PATH "/.kvm-tools/"
+#define HOME_DIR getenv("HOME")
+
struct kvm {
int sys_fd; /* For system ioctls(), i.e. /dev/kvm */
int vm_fd; /* For VM ioctls() */
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index bbfdea2..199c9b9 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -32,8 +32,6 @@
#include <dirent.h>
#define DEFINE_KVM_EXIT_REASON(reason) [reason] = #reason
-#define KVM_PID_FILE_PATH "/.kvm-tools/"
-#define HOME_DIR getenv("HOME")
const char *kvm_exit_reasons[] = {
DEFINE_KVM_EXIT_REASON(KVM_EXIT_UNKNOWN),
--
1.7.6.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 5/5] kvm tools: Add guestfs network autoconfiguration
2011-09-05 23:23 [PATCH 1/5] kvm tools: Remove unconditional warning in ivshmem Sasha Levin
` (2 preceding siblings ...)
2011-09-05 23:23 ` [PATCH 4/5] kvm tools: Teach 'run' to handle guestfs Sasha Levin
@ 2011-09-05 23:23 ` Sasha Levin
3 siblings, 0 replies; 6+ messages in thread
From: Sasha Levin @ 2011-09-05 23:23 UTC (permalink / raw)
To: penberg; +Cc: kvm, mingo, gorcunov, asias.hejun, Sasha Levin
Add a script to automatically configure networking in the guest.
Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/builtin-setup.c | 14 ++++++++++++++
tools/kvm/guest/init.c | 4 ++++
tools/kvm/guest/setnet.sh | 22 ++++++++++++++++++++++
3 files changed, 40 insertions(+), 0 deletions(-)
create mode 100755 tools/kvm/guest/setnet.sh
diff --git a/tools/kvm/builtin-setup.c b/tools/kvm/builtin-setup.c
index 7587476..f7588dd 100644
--- a/tools/kvm/builtin-setup.c
+++ b/tools/kvm/builtin-setup.c
@@ -129,6 +129,15 @@ static int copy_init(const char *guestfs_name)
return copy_file("guest/init", path);
}
+static int copy_net(const char *guestfs_name)
+{
+ char path[PATH_MAX];
+
+ snprintf(path, PATH_MAX, "%s%s%s/virt/setnet.sh", HOME_DIR, KVM_PID_FILE_PATH, guestfs_name);
+
+ return copy_file("guest/setnet.sh", path);
+}
+
static int make_guestfs_symlink(const char *guestfs_name, const char *path)
{
char target[PATH_MAX];
@@ -171,6 +180,7 @@ static void make_guestfs_dir(const char *guestfs_name, const char *dir)
static int do_setup(const char *guestfs_name)
{
unsigned int i;
+ int ret;
make_root_dir();
@@ -183,6 +193,10 @@ static int do_setup(const char *guestfs_name)
make_guestfs_symlink(guestfs_name, guestfs_symlinks[i]);
}
+ ret = copy_net(guestfs_name);
+ if (ret < 0)
+ return ret;
+
return copy_init(guestfs_name);
}
diff --git a/tools/kvm/guest/init.c b/tools/kvm/guest/init.c
index 837acfb..7733026 100644
--- a/tools/kvm/guest/init.c
+++ b/tools/kvm/guest/init.c
@@ -30,6 +30,10 @@ int main(int argc, char *argv[])
do_mounts();
+ puts("Setting up network...");
+
+ system("/bin/sh virt/setnet.sh");
+
puts("Starting '/bin/sh'...");
run_process("/bin/sh");
diff --git a/tools/kvm/guest/setnet.sh b/tools/kvm/guest/setnet.sh
new file mode 100755
index 0000000..3da9c22
--- /dev/null
+++ b/tools/kvm/guest/setnet.sh
@@ -0,0 +1,22 @@
+for f in /sys/class/net/*; do
+ type=`cat $f/type`
+ if [ $type -eq 1 ]; then
+ f=${f#/sys/class/net/}
+
+ eval "dhcpcd -A $f 2> /dev/null"
+ if [ $? -eq 0 ]; then
+ exit
+ fi
+
+ eval "dhclient $f 2> /dev/null"
+ if [ $? -eq 0 ]; then
+ exit
+ fi
+
+ ifconfig $f 192.168.33.15
+ route add default 192.168.33.1
+ echo "nameserver 8.8.8.8" >> /etc/resolv.conf
+
+ exit
+ fi
+done
--
1.7.6.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 4/5] kvm tools: Teach 'run' to handle guestfs
2011-09-05 23:23 ` [PATCH 4/5] kvm tools: Teach 'run' to handle guestfs Sasha Levin
@ 2011-09-06 13:37 ` Cyrill Gorcunov
0 siblings, 0 replies; 6+ messages in thread
From: Cyrill Gorcunov @ 2011-09-06 13:37 UTC (permalink / raw)
To: Sasha Levin; +Cc: penberg, kvm, mingo, asias.hejun
On Tue, Sep 06, 2011 at 02:23:54AM +0300, Sasha Levin wrote:
> This patch allows to run previously created guestfs by simply specifying it
> with the '-d' parameter.
>
> This allows running guestfs which were created before using:
>
> kvm setup -n [name]
>
> Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
> ---
...
> @@ -103,6 +104,7 @@ static int img_name_parser(const struct option *opt, const char *arg, int unset)
> {
> char *sep;
> struct stat st;
> + char path[PATH_MAX];
>
Hi Sasha, the whole series looks good to me, thanks a lot!
The only thing which was always bothering me -- is PATH_MAX on the stack.
As far as I remember it might be up to 4K which is not that good ;) Probably
we might move it somewhere into .bss? (in some patches on top)
Cyrill
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-09-06 13:37 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-05 23:23 [PATCH 1/5] kvm tools: Remove unconditional warning in ivshmem Sasha Levin
2011-09-05 23:23 ` [PATCH 2/5] kvm tools: Fix 32bit warnings Sasha Levin
2011-09-05 23:23 ` [PATCH 3/5] kvm tools: Attach default 'root=' only if required Sasha Levin
2011-09-05 23:23 ` [PATCH 4/5] kvm tools: Teach 'run' to handle guestfs Sasha Levin
2011-09-06 13:37 ` Cyrill Gorcunov
2011-09-05 23:23 ` [PATCH 5/5] kvm tools: Add guestfs network autoconfiguration Sasha Levin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox