mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
launch: Refactor duplicate code which constructs the appliance command line.
Move this into a common file.
This commit is contained in:
@@ -567,6 +567,7 @@ extern void guestfs___rollback_drives (guestfs_h *g, size_t);
|
||||
extern void guestfs___launch_failed_error (guestfs_h *g);
|
||||
extern void guestfs___add_dummy_appliance_drive (guestfs_h *g);
|
||||
extern void guestfs___free_drives (guestfs_h *g);
|
||||
extern char *guestfs___appliance_command_line (guestfs_h *g, const char *appliance_dev);
|
||||
|
||||
/* launch-appliance.c */
|
||||
extern char *guestfs___drive_name (size_t index, char *ret);
|
||||
|
||||
@@ -281,7 +281,7 @@ launch_appliance (guestfs_h *g, const char *arg)
|
||||
}
|
||||
}
|
||||
|
||||
char appliance_root[64] = "";
|
||||
char appliance_dev[64] = "/dev/Xd";
|
||||
|
||||
/* Add the ext2 appliance drive (after all the drives). */
|
||||
if (appliance) {
|
||||
@@ -305,9 +305,8 @@ launch_appliance (guestfs_h *g, const char *arg)
|
||||
add_cmdline (g, "scsi-hd,drive=appliance");
|
||||
}
|
||||
|
||||
snprintf (appliance_root, sizeof appliance_root, "root=/dev/%cd",
|
||||
virtio_scsi ? 's' : 'v');
|
||||
guestfs___drive_name (g->nr_drives, &appliance_root[12]);
|
||||
appliance_dev[5] = virtio_scsi ? 's' : 'v';
|
||||
guestfs___drive_name (g->nr_drives, &appliance_dev[7]);
|
||||
}
|
||||
|
||||
if (STRNEQ (QEMU_OPTIONS, "")) {
|
||||
@@ -422,41 +421,15 @@ launch_appliance (guestfs_h *g, const char *arg)
|
||||
add_cmdline (g, "virtio-net-pci,netdev=usernet");
|
||||
}
|
||||
|
||||
#if defined(__arm__)
|
||||
#define SERIAL_CONSOLE "ttyAMA0"
|
||||
#else
|
||||
#define SERIAL_CONSOLE "ttyS0"
|
||||
#endif
|
||||
|
||||
#define LINUX_CMDLINE \
|
||||
"panic=1 " /* force kernel to panic if daemon exits */ \
|
||||
"console=" SERIAL_CONSOLE " " /* serial console */ \
|
||||
"udevtimeout=600 " /* good for very slow systems (RHBZ#480319) */ \
|
||||
"no_timer_check " /* fix for RHBZ#502058 */ \
|
||||
"acpi=off " /* we don't need ACPI, turn it off */ \
|
||||
"printk.time=1 " /* display timestamp before kernel messages */ \
|
||||
"cgroup_disable=memory " /* saves us about 5 MB of RAM */
|
||||
|
||||
/* Linux kernel command line. */
|
||||
snprintf (buf, sizeof buf,
|
||||
LINUX_CMDLINE
|
||||
"%s " /* (root) */
|
||||
"%s " /* (selinux) */
|
||||
"%s " /* (verbose) */
|
||||
"TERM=%s " /* (TERM environment variable) */
|
||||
"%s", /* (append) */
|
||||
appliance_root,
|
||||
g->selinux ? "selinux=1 enforcing=0" : "selinux=0",
|
||||
g->verbose ? "guestfs_verbose=1" : "",
|
||||
getenv ("TERM") ? : "linux",
|
||||
g->append ? g->append : "");
|
||||
|
||||
add_cmdline (g, "-kernel");
|
||||
add_cmdline (g, kernel);
|
||||
add_cmdline (g, "-initrd");
|
||||
add_cmdline (g, initrd);
|
||||
|
||||
add_cmdline (g, "-append");
|
||||
add_cmdline (g, buf);
|
||||
char *cmdline = guestfs___appliance_command_line (g, appliance_dev);
|
||||
add_cmdline (g, cmdline);
|
||||
free (cmdline);
|
||||
|
||||
/* Finish off the command line. */
|
||||
incr_cmdline_size (g);
|
||||
|
||||
@@ -623,40 +623,12 @@ construct_libvirt_xml_boot (guestfs_h *g, xmlTextWriterPtr xo,
|
||||
const char *kernel, const char *initrd,
|
||||
size_t appliance_index)
|
||||
{
|
||||
char buf[256];
|
||||
char appliance_root[64] = "";
|
||||
|
||||
/* XXX Lots of common code shared with src/launch-appliance.c */
|
||||
#if defined(__arm__)
|
||||
#define SERIAL_CONSOLE "ttyAMA0"
|
||||
#else
|
||||
#define SERIAL_CONSOLE "ttyS0"
|
||||
#endif
|
||||
|
||||
#define LINUX_CMDLINE \
|
||||
"panic=1 " /* force kernel to panic if daemon exits */ \
|
||||
"console=" SERIAL_CONSOLE " " /* serial console */ \
|
||||
"udevtimeout=600 " /* good for very slow systems (RHBZ#480319) */ \
|
||||
"no_timer_check " /* fix for RHBZ#502058 */ \
|
||||
"acpi=off " /* we don't need ACPI, turn it off */ \
|
||||
"printk.time=1 " /* display timestamp before kernel messages */ \
|
||||
"cgroup_disable=memory " /* saves us about 5 MB of RAM */
|
||||
char appliance_dev[64] = "/dev/sd";
|
||||
char *cmdline;
|
||||
|
||||
/* Linux kernel command line. */
|
||||
guestfs___drive_name (appliance_index, appliance_root);
|
||||
|
||||
snprintf (buf, sizeof buf,
|
||||
LINUX_CMDLINE
|
||||
"root=/dev/sd%s " /* (root) */
|
||||
"%s " /* (selinux) */
|
||||
"%s " /* (verbose) */
|
||||
"TERM=%s " /* (TERM environment variable) */
|
||||
"%s", /* (append) */
|
||||
appliance_root,
|
||||
g->selinux ? "selinux=1 enforcing=0" : "selinux=0",
|
||||
g->verbose ? "guestfs_verbose=1" : "",
|
||||
getenv ("TERM") ? : "linux",
|
||||
g->append ? g->append : "");
|
||||
guestfs___drive_name (appliance_index, &appliance_dev[7]);
|
||||
cmdline = guestfs___appliance_command_line (g, appliance_dev);
|
||||
|
||||
XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "os"));
|
||||
|
||||
@@ -673,14 +645,16 @@ construct_libvirt_xml_boot (guestfs_h *g, xmlTextWriterPtr xo,
|
||||
XMLERROR (-1, xmlTextWriterEndElement (xo));
|
||||
|
||||
XMLERROR (-1, xmlTextWriterStartElement (xo, BAD_CAST "cmdline"));
|
||||
XMLERROR (-1, xmlTextWriterWriteString (xo, BAD_CAST buf));
|
||||
XMLERROR (-1, xmlTextWriterWriteString (xo, BAD_CAST cmdline));
|
||||
XMLERROR (-1, xmlTextWriterEndElement (xo));
|
||||
|
||||
XMLERROR (-1, xmlTextWriterEndElement (xo));
|
||||
|
||||
free (cmdline);
|
||||
return 0;
|
||||
|
||||
err:
|
||||
free (cmdline);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
47
src/launch.c
47
src/launch.c
@@ -784,3 +784,50 @@ guestfs__get_state (guestfs_h *g)
|
||||
{
|
||||
return g->state;
|
||||
}
|
||||
|
||||
/* Construct the Linux command line passed to the appliance. This is
|
||||
* used by the 'appliance' and 'libvirt' attach-methods, and is simply
|
||||
* located in this file because it's a convenient place for this
|
||||
* common code.
|
||||
*
|
||||
* The 'appliance_dev' parameter must be the full device name of the
|
||||
* appliance disk and must have already been adjusted to take into
|
||||
* account virtio-blk or virtio-scsi; eg "/dev/sdb".
|
||||
*
|
||||
* Note that this returns a newly allocated buffer which must be freed
|
||||
* by the caller.
|
||||
*/
|
||||
#if defined(__arm__)
|
||||
#define SERIAL_CONSOLE "ttyAMA0"
|
||||
#else
|
||||
#define SERIAL_CONSOLE "ttyS0"
|
||||
#endif
|
||||
|
||||
char *
|
||||
guestfs___appliance_command_line (guestfs_h *g, const char *appliance_dev)
|
||||
{
|
||||
char *term = getenv ("TERM");
|
||||
char *ret;
|
||||
|
||||
ret = safe_asprintf
|
||||
(g,
|
||||
"panic=1" /* force kernel to panic if daemon exits */
|
||||
" console=" SERIAL_CONSOLE /* serial console */
|
||||
" udevtimeout=600" /* good for very slow systems (RHBZ#480319) */
|
||||
" no_timer_check" /* fix for RHBZ#502058 */
|
||||
" acpi=off" /* we don't need ACPI, turn it off */
|
||||
" printk.time=1" /* display timestamp before kernel messages */
|
||||
" cgroup_disable=memory" /* saves us about 5 MB of RAM */
|
||||
" root=%s" /* root (appliance_dev) */
|
||||
" %s" /* selinux */
|
||||
"%s" /* verbose */
|
||||
" TERM=%s" /* TERM environment variable */
|
||||
"%s%s", /* append */
|
||||
appliance_dev,
|
||||
g->selinux ? "selinux=1 enforcing=0" : "selinux=0",
|
||||
g->verbose ? " guestfs_verbose=1" : "",
|
||||
term ? term : "linux",
|
||||
g->append ? " " : "", g->append ? g->append : "");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user