New API: set-smp, get-smp

These calls allow you to change the number of virtual CPUs assigned to
the appliance.

This also adds a --smp option to virt-rescue.
This commit is contained in:
Richard W.M. Jones
2011-09-28 14:39:31 +01:00
parent 8403f5a9d8
commit 04fbcc63eb
7 changed files with 66 additions and 0 deletions

View File

@@ -1549,6 +1549,22 @@ C<^C> to kill the subprocess.");
"\
This returns the process group flag.");
("set_smp", (RErr, [Int "smp"], []), -1, [FishAlias "smp"],
[],
"set number of virtual CPUs in appliance",
"\
Change the number of virtual CPUs assigned to the appliance. The
default is C<1>. Increasing this may improve performance, though
often it has no effect.
This function must be called before C<guestfs_launch>.");
("get_smp", (RInt "smp", [], []), -1, [],
[],
"get number of virtual CPUs in appliance",
"\
This returns the number of virtual CPUs assigned to the appliance.");
]
(* daemon_functions are any functions which cause some action

View File

@@ -77,6 +77,7 @@ usage (int status)
" --network Enable network\n"
" -r|--ro Access read-only\n"
" --selinux Enable SELinux\n"
" --smp N Enable SMP with N >= 2 virtual CPUs\n"
" -v|--verbose Verbose messages\n"
" -V|--version Display version and exit\n"
" -w|--rw Mount read-write\n"
@@ -115,6 +116,7 @@ main (int argc, char *argv[])
{ "ro", 0, 0, 'r' },
{ "rw", 0, 0, 'w' },
{ "selinux", 0, 0, 0 },
{ "smp", 1, 0, 0 },
{ "verbose", 0, 0, 'v' },
{ "version", 0, 0, 'V' },
{ 0, 0, 0, 0 }
@@ -128,6 +130,7 @@ main (int argc, char *argv[])
const char *append = NULL;
char *append_full;
int memsize = 0;
int smp = 0;
g = guestfs_create ();
if (g == NULL) {
@@ -154,6 +157,17 @@ main (int argc, char *argv[])
format = NULL;
else
format = optarg;
} else if (STREQ (long_options[option_index].name, "smp")) {
if (sscanf (optarg, "%u", &smp) != 1) {
fprintf (stderr, _("%s: could not parse --smp parameter '%s'\n"),
program_name, optarg);
exit (EXIT_FAILURE);
}
if (smp < 1) {
fprintf (stderr, _("%s: --smp parameter '%s' should be >= 1\n"),
program_name, optarg);
exit (EXIT_FAILURE);
}
} else {
fprintf (stderr, _("%s: unknown long option: %s (%d)\n"),
program_name, long_options[option_index].name, option_index);
@@ -270,6 +284,8 @@ main (int argc, char *argv[])
guestfs_set_memsize (g, memsize);
if (network)
guestfs_set_network (g, 1);
if (smp >= 1)
guestfs_set_smp (g, smp);
/* Kernel command line must include guestfs_rescue=1 (see
* appliance/init) as well as other options.

View File

@@ -175,6 +175,10 @@ See also L<guestfish(1)/OPENING DISKS FOR READ AND WRITE>.
Enable SELinux in the rescue appliance. You should read
L<guestfs(3)/SELINUX> before using this option.
=item B<--smp> N
Enable N E<ge> 2 virtual CPUs in the rescue appliance.
=item B<-v>
=item B<--verbose>

View File

@@ -170,6 +170,8 @@ struct guestfs_h
int pgroup; /* Create process group for children? */
int smp; /* If > 1, -smp flag passed to qemu. */
char *last_error;
int last_errnum; /* errno, or 0 if there was no errno */

View File

@@ -144,6 +144,9 @@ guestfs_create (void)
*/
g->msg_next_serial = 0x00123400;
/* Default is uniprocessor appliance. */
g->smp = 1;
/* Link the handles onto a global list. */
gl_lock_lock (handles_lock);
g->next = handles;
@@ -814,6 +817,24 @@ guestfs__get_pgroup (guestfs_h *g)
return g->pgroup;
}
int
guestfs__set_smp (guestfs_h *g, int v)
{
if (v >= 1) {
g->smp = v;
return 0;
} else {
error (g, "invalid smp parameter: %d", v);
return -1;
}
}
int
guestfs__get_smp (guestfs_h *g)
{
return g->smp;
}
/* Note the private data area is allocated lazily, since the vast
* majority of callers will never use it. This means g->pda is
* likely to be NULL.

View File

@@ -555,6 +555,12 @@ launch_appliance (guestfs_h *g)
add_cmdline (g, "-nographic");
if (g->smp > 1) {
snprintf (buf, sizeof buf, "%d", g->smp);
add_cmdline (g, "-smp");
add_cmdline (g, buf);
}
snprintf (buf, sizeof buf, "%d", g->memsize);
add_cmdline (g, "-m");
add_cmdline (g, buf);

View File

@@ -206,6 +206,7 @@ main (int argc, char *argv[])
printf ("guestfs_get_recovery_proc: %d\n",
guestfs_get_recovery_proc (g));
printf ("guestfs_get_selinux: %d\n", guestfs_get_selinux (g));
printf ("guestfs_get_smp: %d\n", guestfs_get_smp (g));
printf ("guestfs_get_trace: %d\n", guestfs_get_trace (g));
printf ("guestfs_get_verbose: %d\n", guestfs_get_verbose (g));