Changeset 4410
- Timestamp:
- 10/10/08 13:20:04 (3 months ago)
- Files:
-
- trunk/src/dumm/dumm.c (modified) (2 diffs)
- trunk/src/dumm/dumm.h (modified) (1 diff)
- trunk/src/dumm/ext/dumm.c (modified) (2 diffs)
- trunk/src/dumm/guest.c (modified) (9 diffs)
- trunk/src/dumm/guest.h (modified) (1 diff)
- trunk/src/dumm/main.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/dumm/dumm.c
r4306 r4410 53 53 */ 54 54 static guest_t* create_guest(private_dumm_t *this, char *name, char *kernel, 55 char *master, int mem)56 { 57 guest_t *guest; 58 59 guest = guest_create(this->guest_dir, name, kernel, master, mem);55 char *master, char *args) 56 { 57 guest_t *guest; 58 59 guest = guest_create(this->guest_dir, name, kernel, master, args); 60 60 if (guest) 61 61 { … … 259 259 private_dumm_t *this = malloc_thing(private_dumm_t); 260 260 261 this->public.create_guest = (guest_t*(*)(dumm_t*,char*,char*,char*, int))create_guest;261 this->public.create_guest = (guest_t*(*)(dumm_t*,char*,char*,char*,char*))create_guest; 262 262 this->public.create_guest_enumerator = (enumerator_t*(*)(dumm_t*))create_guest_enumerator; 263 263 this->public.delete_guest = (void(*)(dumm_t*,guest_t*))delete_guest; trunk/src/dumm/dumm.h
r4306 r4410 41 41 * @param kernel UML kernel to use for guest 42 42 * @param master mounted read only master filesystem 43 * @param mem amount of memory for guest, in MB43 * @param args additional args to pass to kernel 44 44 * @return guest if started, NULL if failed 45 45 */ 46 46 guest_t* (*create_guest) (dumm_t *this, char *name, char *kernel, 47 char *master, int mem);47 char *master, char *args); 48 48 49 49 /** trunk/src/dumm/ext/dumm.c
r4306 r4410 47 47 pid_t pid; 48 48 49 args[argc++] = "con0=xterm";50 args[argc++] = "xterm=gnome-terminal,-t,-x";51 52 49 pid = fork(); 53 50 switch (pid) … … 146 143 147 144 static VALUE guest_new(VALUE class, VALUE name, VALUE kernel, 148 VALUE master, VALUE mem)145 VALUE master, VALUE args) 149 146 { 150 147 guest_t *guest; 151 148 152 149 guest = dumm->create_guest(dumm, StringValuePtr(name), StringValuePtr(kernel), 153 StringValuePtr(master), FIX2INT(mem));150 StringValuePtr(master), StringValuePtr(args)); 154 151 if (!guest) 155 152 { trunk/src/dumm/guest.c
r4306 r4410 43 43 #define DIFF_DIR "diff" 44 44 #define UNION_DIR "union" 45 #define MEMORY_FILE "mem"45 #define ARGS_FILE "args" 46 46 #define PID_FILE "pid" 47 47 #define KERNEL_FILE "linux" … … 61 61 /** directory name of guest */ 62 62 char *dirname; 63 /** a mount of memory for guest, in MB*/64 int mem;63 /** additional args to pass to guest */ 64 char *args; 65 65 /** pid of guest child process */ 66 66 int pid; … … 266 266 args[i++] = write_arg(&pos, &left, "uml_dir=%s", this->dirname); 267 267 args[i++] = write_arg(&pos, &left, "umid=%s", this->name); 268 args[i++] = write_arg(&pos, &left, "mem=%dM", this->mem);269 268 args[i++] = write_arg(&pos, &left, "mconsole=notify:%s", notify); 270 269 args[i++] = write_arg(&pos, &left, "con=null"); 270 if (this->args) 271 { 272 args[i++] = this->args; 273 } 271 274 272 275 this->pid = invoke(data, &this->public, args, i); … … 491 494 492 495 /** 493 * load memoryconfiguration from file494 */ 495 int loadmem(private_guest_t *this)496 * load args configuration from file 497 */ 498 char *loadargs(private_guest_t *this) 496 499 { 497 500 FILE *file; 498 int mem = 0;499 500 file = fdopen(openat(this->dir, MEMORY_FILE, O_RDONLY, PERM), "r");501 char buf[512], *args = NULL; 502 503 file = fdopen(openat(this->dir, ARGS_FILE, O_RDONLY, PERM), "r"); 501 504 if (file) 502 505 { 503 if (f scanf(file, "%d", &mem) <= 0)504 { 505 mem = 0;506 if (fgets(buf, sizeof(buf), file)) 507 { 508 args = strdup(buf); 506 509 } 507 510 fclose(file); 508 511 } 509 return mem;510 } 511 512 /** 513 * save memoryconfiguration to file514 */ 515 bool save mem(private_guest_t *this, int mem)512 return args; 513 } 514 515 /** 516 * save args configuration to file 517 */ 518 bool saveargs(private_guest_t *this, char *args) 516 519 { 517 520 FILE *file; 518 521 bool retval = FALSE; 519 522 520 file = fdopen(openat(this->dir, MEMORY_FILE, O_RDWR | O_CREAT | O_TRUNC,523 file = fdopen(openat(this->dir, ARGS_FILE, O_RDWR | O_CREAT | O_TRUNC, 521 524 PERM), "w"); 522 525 if (file) 523 526 { 524 if (fprintf(file, "% d", mem) > 0)527 if (fprintf(file, "%s", args) > 0) 525 528 { 526 529 retval = TRUE; … … 544 547 this->ifaces->destroy(this->ifaces); 545 548 free(this->dirname); 549 free(this->args); 546 550 free(this->name); 547 551 free(this); … … 595 599 this->mconsole = NULL; 596 600 this->ifaces = linked_list_create(); 597 this-> mem = 0;601 this->args = NULL; 598 602 this->name = strdup(name); 599 603 this->cowfs = NULL; … … 626 630 */ 627 631 guest_t *guest_create(char *parent, char *name, char *kernel, 628 char *master, int mem)632 char *master, char *args) 629 633 { 630 634 private_guest_t *this = guest_create_generic(parent, name, TRUE); … … 651 655 } 652 656 653 this-> mem = mem;654 if ( !savemem(this, mem))657 this->args = args; 658 if (args && !saveargs(this, args)) 655 659 { 656 660 destroy(this); … … 679 683 } 680 684 681 this-> mem = loadmem(this);682 if (this->mem == 0)683 {684 DBG1("unable to open memory configuration file: %m", name);685 this->args = loadargs(this); 686 687 if (!mount_unionfs(this)) 688 { 685 689 destroy(this); 686 690 return NULL; 687 691 } 688 692 689 if (!mount_unionfs(this))690 {691 destroy(this);692 return NULL;693 }694 695 693 return &this->public; 696 694 } trunk/src/dumm/guest.h
r4251 r4410 188 188 * @param kernel kernel this guest uses 189 189 * @param master read-only master filesystem for guest 190 * @param args additional args to pass to kernel 190 191 * @param mem amount of memory to give the guest 191 192 */ 192 193 guest_t *guest_create(char *parent, char *name, char *kernel, 193 char *master, int mem);194 char *master, char *args); 194 195 195 196 /** trunk/src/dumm/main.c
r3957 r4410 101 101 char *args[], int argc) 102 102 { 103 args[argc] = "con0=fd:0,fd:1";104 103 return vte_terminal_fork_command(VTE_TERMINAL(vte), args[0], args, NULL, 105 104 NULL, FALSE, FALSE, FALSE); … … 375 374 { 376 375 guest_t *guest; 377 GtkWidget *dialog, *table, *label, *name, *kernel, *master, * memory;376 GtkWidget *dialog, *table, *label, *name, *kernel, *master, *args; 378 377 379 378 dialog = gtk_dialog_new_with_buttons("Create new guest", GTK_WINDOW(window), … … 397 396 gtk_widget_show(label); 398 397 399 label = gtk_label_new(" Memory (MB)");398 label = gtk_label_new("Kernel arguments"); 400 399 gtk_table_attach(GTK_TABLE(table), label, 0, 1, 3, 4, 0, 0, 0, 0); 401 400 gtk_widget_show(label); … … 418 417 gtk_widget_show(master); 419 418 420 memory = gtk_spin_button_new_with_range(1, 4096, 1); 421 gtk_spin_button_set_digits(GTK_SPIN_BUTTON(memory), 0); 422 gtk_table_attach(GTK_TABLE(table), memory, 1, 2, 3, 4, 419 args = gtk_entry_new(); 420 gtk_table_attach(GTK_TABLE(table), args, 1, 2, 3, 4, 423 421 GTK_FILL | GTK_EXPAND | GTK_SHRINK, 0, 0, 0); 424 gtk_widget_show( memory);422 gtk_widget_show(args); 425 423 426 424 gtk_widget_show(table); … … 432 430 case GTK_RESPONSE_ACCEPT: 433 431 { 434 char *sname, *skernel, *smaster ;432 char *sname, *skernel, *smaster, *sargs; 435 433 page_t *page; 436 434 … … 438 436 skernel = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(kernel)); 439 437 smaster = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(master)); 438 sargs = (char*)gtk_entry_get_text(GTK_ENTRY(args)); 440 439 441 440 if (!sname[0] || !skernel || !smaster) … … 443 442 continue; 444 443 } 445 guest = dumm->create_guest(dumm, sname, skernel, smaster, 446 gtk_spin_button_get_value(GTK_SPIN_BUTTON(memory))); 444 guest = dumm->create_guest(dumm, sname, skernel, smaster, sargs); 447 445 if (!guest) 448 446 {
