set guest-specific kernel parameters
authorMartin Willi <martin@strongswan.org>
Fri, 10 Oct 2008 11:20:04 +0000 (11:20 -0000)
committerMartin Willi <martin@strongswan.org>
Fri, 10 Oct 2008 11:20:04 +0000 (11:20 -0000)
removed memory setting, use mem= instead

src/dumm/dumm.c
src/dumm/dumm.h
src/dumm/ext/dumm.c
src/dumm/guest.c
src/dumm/guest.h
src/dumm/main.c

index 190b7cc..eaefddb 100644 (file)
@@ -52,11 +52,11 @@ struct private_dumm_t {
  * Implementation of dumm_t.create_guest.
  */
 static guest_t* create_guest(private_dumm_t *this, char *name, char *kernel, 
-                                                        char *master, int mem)
+                                                        char *master, char *args)
 {
        guest_t *guest;
        
-       guest = guest_create(this->guest_dir, name, kernel, master, mem);
+       guest = guest_create(this->guest_dir, name, kernel, master, args);
        if (guest)
        {
                this->guests->insert_last(this->guests, guest);
@@ -258,7 +258,7 @@ dumm_t *dumm_create(char *dir)
        char cwd[PATH_MAX];
        private_dumm_t *this = malloc_thing(private_dumm_t);
        
-       this->public.create_guest = (guest_t*(*)(dumm_t*,char*,char*,char*,int))create_guest;
+       this->public.create_guest = (guest_t*(*)(dumm_t*,char*,char*,char*,char*))create_guest;
        this->public.create_guest_enumerator = (enumerator_t*(*)(dumm_t*))create_guest_enumerator;
        this->public.delete_guest = (void(*)(dumm_t*,guest_t*))delete_guest;
        this->public.create_bridge = (bridge_t*(*)(dumm_t*, char *name))create_bridge;
index 686b80a..f5db0e4 100644 (file)
@@ -40,11 +40,11 @@ struct dumm_t {
         * @param name          name of the guest
         * @param kernel        UML kernel to use for guest
         * @param master        mounted read only master filesystem
-        * @param mem           amount of memory for guest, in MB
+        * @param args          additional args to pass to kernel
         * @return                      guest if started, NULL if failed
         */
        guest_t* (*create_guest) (dumm_t *this, char *name, char *kernel, 
-                                                         char *master, int mem);
+                                                         char *master, char *args);
        
        /**
         * @brief Create an enumerator over all guests.
index 521311f..3cc256f 100644 (file)
@@ -46,9 +46,6 @@ static pid_t invoke(void *null, guest_t *guest, char *args[], int argc)
 {
        pid_t pid;
        
-       args[argc++] = "con0=xterm";
-       args[argc++] = "xterm=gnome-terminal,-t,-x";
-       
        pid = fork();
        switch (pid)
        {
@@ -145,12 +142,12 @@ static VALUE guest_each(int argc, VALUE *argv, VALUE class)
 }
 
 static VALUE guest_new(VALUE class, VALUE name, VALUE kernel,
-                                          VALUE master, VALUE mem)
+                                          VALUE master, VALUE args)
 {
        guest_t *guest;
        
        guest = dumm->create_guest(dumm, StringValuePtr(name), StringValuePtr(kernel),
-                                                          StringValuePtr(master), FIX2INT(mem));
+                                                          StringValuePtr(master), StringValuePtr(args));
        if (!guest)
        {
                rb_raise(rb_eRuntimeError, "creating guest failed");
index 53e6169..aed2a3e 100644 (file)
@@ -42,7 +42,7 @@
 #define MASTER_DIR "master"
 #define DIFF_DIR "diff"
 #define UNION_DIR "union"
-#define MEMORY_FILE "mem"
+#define ARGS_FILE "args"
 #define PID_FILE "pid"
 #define KERNEL_FILE "linux"
 #define LOG_FILE "boot.log"
@@ -60,8 +60,8 @@ struct private_guest_t {
        int dir;
        /** directory name of guest */
        char *dirname;
-       /** amount of memory for guest, in MB */
-       int mem;
+       /** additional args to pass to guest */
+       char *args;
        /** pid of guest child process */
        int pid;
        /** state of guest */
@@ -265,9 +265,12 @@ static bool start(private_guest_t *this, invoke_function_t invoke, void* data,
        args[i++] = write_arg(&pos, &left, "rootflags=%s/%s", this->dirname, UNION_DIR);
        args[i++] = write_arg(&pos, &left, "uml_dir=%s", this->dirname);
        args[i++] = write_arg(&pos, &left, "umid=%s", this->name);
-       args[i++] = write_arg(&pos, &left, "mem=%dM", this->mem);
        args[i++] = write_arg(&pos, &left, "mconsole=notify:%s", notify);
        args[i++] = write_arg(&pos, &left, "con=null");
+       if (this->args)
+       {
+               args[i++] = this->args;
+       }
          
        this->pid = invoke(data, &this->public, args, i);
        if (!this->pid)
@@ -490,38 +493,38 @@ static bool mount_unionfs(private_guest_t *this)
 }
 
 /**
- * load memory configuration from file
+ * load args configuration from file
  */
-int loadmem(private_guest_t *this)
+char *loadargs(private_guest_t *this)
 {
        FILE *file;
-       int mem = 0;
+       char buf[512], *args = NULL;
        
-       file = fdopen(openat(this->dir, MEMORY_FILE, O_RDONLY, PERM), "r");
+       file = fdopen(openat(this->dir, ARGS_FILE, O_RDONLY, PERM), "r");
        if (file)
        {
-               if (fscanf(file, "%d", &mem) <= 0)
+               if (fgets(buf, sizeof(buf), file))
                {
-                       mem = 0;
+                       args = strdup(buf);
                }
                fclose(file);
        }
-       return mem;
+       return args;
 }
 
 /**
- * save memory configuration to file
+ * save args configuration to file
  */
-bool savemem(private_guest_t *this, int mem)
+bool saveargs(private_guest_t *this, char *args)
 {
        FILE *file;
        bool retval = FALSE;
        
-       file = fdopen(openat(this->dir, MEMORY_FILE, O_RDWR | O_CREAT | O_TRUNC,
+       file = fdopen(openat(this->dir, ARGS_FILE, O_RDWR | O_CREAT | O_TRUNC,
                                                 PERM), "w");
        if (file)
        {
-               if (fprintf(file, "%d", mem) > 0)
+               if (fprintf(file, "%s", args) > 0)
                {
                        retval = TRUE;
                }
@@ -543,6 +546,7 @@ static void destroy(private_guest_t *this)
        }
        this->ifaces->destroy(this->ifaces);
        free(this->dirname);
+       free(this->args);
        free(this->name);
        free(this);
 }
@@ -594,7 +598,7 @@ static private_guest_t *guest_create_generic(char *parent, char *name,
        this->state = GUEST_STOPPED;
        this->mconsole = NULL;
        this->ifaces = linked_list_create();
-       this->mem = 0;
+       this->args = NULL;
        this->name = strdup(name);
        this->cowfs = NULL;
        
@@ -625,7 +629,7 @@ static bool make_symlink(private_guest_t *this, char *old, char *new)
  * create the guest instance, including required dirs and mounts 
  */
 guest_t *guest_create(char *parent, char *name, char *kernel,
-                                         char *master, int mem)
+                                         char *master, char *args)
 {
        private_guest_t *this = guest_create_generic(parent, name, TRUE);
        
@@ -650,8 +654,8 @@ guest_t *guest_create(char *parent, char *name, char *kernel,
                return NULL;
        }
        
-       this->mem = mem;
-       if (!savemem(this, mem))
+       this->args = args;
+       if (args && !saveargs(this, args))
        {
                destroy(this);
                return NULL;
@@ -678,13 +682,7 @@ guest_t *guest_load(char *parent, char *name)
                return NULL;
        }
        
-       this->mem = loadmem(this);
-       if (this->mem == 0)
-       {
-               DBG1("unable to open memory configuration file: %m", name);
-               destroy(this);
-               return NULL;
-       }
+       this->args = loadargs(this);
        
        if (!mount_unionfs(this))
        {
index b430095..0e48b1d 100644 (file)
@@ -187,10 +187,11 @@ struct guest_t {
  * @param name         name of the guest to create
  * @param kernel       kernel this guest uses
  * @param master       read-only master filesystem for guest
+ * @param args         additional args to pass to kernel
  * @param mem          amount of memory to give the guest
  */
 guest_t *guest_create(char *parent, char *name, char *kernel,
-                                         char *master, int mem);
+                                         char *master, char *args);
 
 /**
  * @brief Load a guest created with guest_create().
index d4f2c51..e2f2fc2 100644 (file)
@@ -100,7 +100,6 @@ static page_t* get_page(int num)
 static pid_t invoke(void *vte, guest_t *guest,
                                        char *args[], int argc)
 {
-       args[argc] = "con0=fd:0,fd:1";
        return vte_terminal_fork_command(VTE_TERMINAL(vte), args[0], args, NULL,
                                                                         NULL, FALSE, FALSE, FALSE);
 }
@@ -374,7 +373,7 @@ static page_t* create_page(guest_t *guest)
 static void create_guest()
 {
        guest_t *guest;
-       GtkWidget *dialog, *table, *label, *name, *kernel, *master, *memory;
+       GtkWidget *dialog, *table, *label, *name, *kernel, *master, *args;
        
        dialog = gtk_dialog_new_with_buttons("Create new guest", GTK_WINDOW(window),
                                                        GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -396,7 +395,7 @@ static void create_guest()
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, 0, 0, 0, 0);
        gtk_widget_show(label);
        
-       label = gtk_label_new("Memory (MB)");
+       label = gtk_label_new("Kernel arguments");
        gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, 0, 0, 0, 0);
        gtk_widget_show(label);
        
@@ -417,11 +416,10 @@ static void create_guest()
                                         GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0, 0);
        gtk_widget_show(master);
        
-       memory = gtk_spin_button_new_with_range(1, 4096, 1);
-       gtk_spin_button_set_digits(GTK_SPIN_BUTTON(memory), 0);
-       gtk_table_attach(GTK_TABLE(table), memory, 1, 2, 3, 4,
+       args = gtk_entry_new();
+       gtk_table_attach(GTK_TABLE(table), args, 1, 2, 3, 4,
                                         GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0, 0);
-       gtk_widget_show(memory);
+       gtk_widget_show(args);
        
        gtk_widget_show(table);
        
@@ -431,19 +429,19 @@ static void create_guest()
                {
                        case GTK_RESPONSE_ACCEPT:
                        {
-                               char *sname, *skernel, *smaster;
+                               char *sname, *skernel, *smaster, *sargs;
                                page_t *page;
                                
                                sname = (char*)gtk_entry_get_text(GTK_ENTRY(name));
                                skernel = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(kernel));
                                smaster = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(master));
+                               sargs = (char*)gtk_entry_get_text(GTK_ENTRY(args));
                        
                                if (!sname[0] || !skernel || !smaster)
                                {
                                        continue;
                                }
-                               guest = dumm->create_guest(dumm, sname, skernel, smaster, 
-                                                       gtk_spin_button_get_value(GTK_SPIN_BUTTON(memory)));
+                               guest = dumm->create_guest(dumm, sname, skernel, smaster, sargs);
                                if (!guest)
                                {
                                        error_dialog("creating guest failed!");