Change the internal domain conf representation of localtime/utc

The XML will soon be extended to allow more than just a simple
localtime/utc boolean flag. This change replaces the plain
'int localtime' with a separate struct to prepare for future
extension

* src/conf/domain_conf.c, src/conf/domain_conf.h: Add a new
  virDomainClockDef structure
* src/libvirt_private.syms: Export virDomainClockOffsetTypeToString
  and virDomainClockOffsetTypeFromString
* src/qemu/qemu_conf.c, src/vbox/vbox_tmpl.c, src/xen/xend_internal.c,
  src/xen/xm_internal.c: Updated to use new structure for localtime
This commit is contained in:
Daniel P. Berrange 2010-02-02 17:22:03 +00:00
parent a3301b71f6
commit eed2f8c3a9
7 changed files with 71 additions and 16 deletions

View File

@ -232,6 +232,10 @@ VIR_ENUM_IMPL(virDomainNetdevMacvtap, VIR_DOMAIN_NETDEV_MACVTAP_MODE_LAST,
"private", "private",
"bridge") "bridge")
VIR_ENUM_IMPL(virDomainClockOffset, VIR_DOMAIN_CLOCK_OFFSET_LAST,
"utc",
"localtime");
#define virDomainReportError(code, fmt...) \ #define virDomainReportError(code, fmt...) \
virReportErrorHelper(NULL, VIR_FROM_DOMAIN, code, __FILE__, \ virReportErrorHelper(NULL, VIR_FROM_DOMAIN, code, __FILE__, \
__FUNCTION__, __LINE__, fmt) __FUNCTION__, __LINE__, fmt)
@ -3566,9 +3570,16 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
tmp = virXPathString("string(./clock/@offset)", ctxt); tmp = virXPathString("string(./clock/@offset)", ctxt);
if (tmp && STREQ(tmp, "localtime")) if (tmp) {
def->localtime = 1; if ((def->clock.offset = virDomainClockOffsetTypeFromString(tmp)) < 0) {
virDomainReportError(VIR_ERR_INTERNAL_ERROR,
_("unknown clock offset '%s'"), tmp);
goto error;
}
VIR_FREE(tmp); VIR_FREE(tmp);
} else {
def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
}
def->os.bootloader = virXPathString("string(./bootloader)", ctxt); def->os.bootloader = virXPathString("string(./bootloader)", ctxt);
def->os.bootloaderArgs = virXPathString("string(./bootloader_args)", ctxt); def->os.bootloaderArgs = virXPathString("string(./bootloader_args)", ctxt);
@ -5525,7 +5536,7 @@ char *virDomainDefFormat(virDomainDefPtr def,
goto cleanup; goto cleanup;
virBufferVSprintf(&buf, " <clock offset='%s'/>\n", virBufferVSprintf(&buf, " <clock offset='%s'/>\n",
def->localtime ? "localtime" : "utc"); virDomainClockOffsetTypeToString(def->clock.offset));
if (virDomainLifecycleDefFormat(&buf, def->onPoweroff, if (virDomainLifecycleDefFormat(&buf, def->onPoweroff,
"on_poweroff") < 0) "on_poweroff") < 0)

View File

@ -631,6 +631,19 @@ struct _virSecurityLabelDef {
int type; int type;
}; };
enum virDomainClockOffsetType {
VIR_DOMAIN_CLOCK_OFFSET_UTC = 0,
VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME = 1,
VIR_DOMAIN_CLOCK_OFFSET_LAST,
};
typedef struct _virDomainClockDef virDomainClockDef;
typedef virDomainClockDef *virDomainClockDefPtr;
struct _virDomainClockDef {
int offset;
};
#define VIR_DOMAIN_CPUMASK_LEN 1024 #define VIR_DOMAIN_CPUMASK_LEN 1024
/* Guest VM main configuration */ /* Guest VM main configuration */
@ -659,7 +672,7 @@ struct _virDomainDef {
char *emulator; char *emulator;
int features; int features;
int localtime; virDomainClockDef clock;
int ngraphics; int ngraphics;
virDomainGraphicsDefPtr *graphics; virDomainGraphicsDefPtr *graphics;
@ -927,6 +940,7 @@ VIR_ENUM_DECL(virDomainGraphics)
/* from libvirt.h */ /* from libvirt.h */
VIR_ENUM_DECL(virDomainState) VIR_ENUM_DECL(virDomainState)
VIR_ENUM_DECL(virDomainSeclabel) VIR_ENUM_DECL(virDomainSeclabel)
VIR_ENUM_DECL(virDomainClockOffset)
VIR_ENUM_DECL(virDomainNetdevMacvtap) VIR_ENUM_DECL(virDomainNetdevMacvtap)

View File

@ -189,6 +189,8 @@ virDomainDefAddImplicitControllers;
virDomainDefClearPCIAddresses; virDomainDefClearPCIAddresses;
virDomainDefClearDeviceAliases; virDomainDefClearDeviceAliases;
virDomainDeviceInfoIterate; virDomainDeviceInfoIterate;
virDomainClockOffsetTypeToString;
virDomainClockOffsetTypeFromString;
# domain_event.h # domain_event.h

View File

@ -3488,8 +3488,14 @@ int qemudBuildCommandLine(virConnectPtr conn,
} }
} }
if (def->localtime) if (def->clock.offset == VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME)
ADD_ARG_LIT("-localtime"); ADD_ARG_LIT("-localtime");
else if (def->clock.offset != VIR_DOMAIN_CLOCK_OFFSET_UTC) {
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unsupported clock offset '%s'"),
virDomainClockOffsetTypeToString(def->clock.offset));
goto error;
}
if ((qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT) && if ((qemuCmdFlags & QEMUD_CMD_FLAG_NO_REBOOT) &&
def->onReboot != VIR_DOMAIN_LIFECYCLE_RESTART) def->onReboot != VIR_DOMAIN_LIFECYCLE_RESTART)
@ -5326,6 +5332,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr caps,
def->id = -1; def->id = -1;
def->memory = def->maxmem = 64 * 1024; def->memory = def->maxmem = 64 * 1024;
def->vcpus = 1; def->vcpus = 1;
def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
def->features = (1 << VIR_DOMAIN_FEATURE_ACPI) def->features = (1 << VIR_DOMAIN_FEATURE_ACPI)
/*| (1 << VIR_DOMAIN_FEATURE_APIC)*/; /*| (1 << VIR_DOMAIN_FEATURE_APIC)*/;
def->onReboot = VIR_DOMAIN_LIFECYCLE_RESTART; def->onReboot = VIR_DOMAIN_LIFECYCLE_RESTART;
@ -5505,7 +5512,7 @@ virDomainDefPtr qemuParseCommandLine(virCapsPtr caps,
} else if (STREQ(arg, "-full-screen")) { } else if (STREQ(arg, "-full-screen")) {
fullscreen = 1; fullscreen = 1;
} else if (STREQ(arg, "-localtime")) { } else if (STREQ(arg, "-localtime")) {
def->localtime = 1; def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME;
} else if (STREQ(arg, "-kernel")) { } else if (STREQ(arg, "-kernel")) {
WANT_VALUE(); WANT_VALUE();
if (!(def->os.kernel = strdup(val))) if (!(def->os.kernel = strdup(val)))

View File

@ -2051,7 +2051,7 @@ static char *vboxDomainDumpXML(virDomainPtr dom, int flags) {
/* Currently VirtualBox always uses locatime /* Currently VirtualBox always uses locatime
* so locatime is always true here */ * so locatime is always true here */
def->localtime = 1; def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME;
/* dump video options vram/2d/3d/directx/etc. */ /* dump video options vram/2d/3d/directx/etc. */
{ {

View File

@ -2451,7 +2451,7 @@ xenDaemonParseSxpr(virConnectPtr conn,
} else } else
def->onCrash = VIR_DOMAIN_LIFECYCLE_DESTROY; def->onCrash = VIR_DOMAIN_LIFECYCLE_DESTROY;
def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC;
if (hvm) { if (hvm) {
if (sexpr_int(root, "domain/image/hvm/acpi")) if (sexpr_int(root, "domain/image/hvm/acpi"))
def->features |= (1 << VIR_DOMAIN_FEATURE_ACPI); def->features |= (1 << VIR_DOMAIN_FEATURE_ACPI);
@ -2462,12 +2462,12 @@ xenDaemonParseSxpr(virConnectPtr conn,
/* Old XenD only allows localtime here for HVM */ /* Old XenD only allows localtime here for HVM */
if (sexpr_int(root, "domain/image/hvm/localtime")) if (sexpr_int(root, "domain/image/hvm/localtime"))
def->localtime = 1; def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME;
} }
/* Current XenD allows localtime here, for PV and HVM */ /* Current XenD allows localtime here, for PV and HVM */
if (sexpr_int(root, "domain/localtime")) if (sexpr_int(root, "domain/localtime"))
def->localtime = 1; def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME;
if (sexpr_node_copy(root, hvm ? if (sexpr_node_copy(root, hvm ?
"domain/image/hvm/device_model" : "domain/image/hvm/device_model" :
@ -5846,8 +5846,14 @@ xenDaemonFormatSxpr(virConnectPtr conn,
virBufferVSprintf(&buf, "(on_crash '%s')", tmp); virBufferVSprintf(&buf, "(on_crash '%s')", tmp);
/* Set localtime here for current XenD (both PV & HVM) */ /* Set localtime here for current XenD (both PV & HVM) */
if (def->localtime) if (def->clock.offset == VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME)
virBufferAddLit(&buf, "(localtime 1)"); virBufferAddLit(&buf, "(localtime 1)");
else if (def->clock.offset != VIR_DOMAIN_CLOCK_OFFSET_UTC) {
virXendError(conn, VIR_ERR_CONFIG_UNSUPPORTED,
_("unsupported clock offset '%s'"),
virDomainClockOffsetTypeToString(def->clock.offset));
goto error;
}
if (!def->os.bootloader) { if (!def->os.bootloader) {
if (STREQ(def->os.type, "hvm")) if (STREQ(def->os.type, "hvm"))
@ -5965,7 +5971,7 @@ xenDaemonFormatSxpr(virConnectPtr conn,
} }
/* Set localtime here to keep old XenD happy for HVM */ /* Set localtime here to keep old XenD happy for HVM */
if (def->localtime) if (def->clock.offset == VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME)
virBufferAddLit(&buf, "(localtime 1)"); virBufferAddLit(&buf, "(localtime 1)");
if (def->sounds) { if (def->sounds) {

View File

@ -683,6 +683,7 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) {
virDomainHostdevDefPtr hostdev = NULL; virDomainHostdevDefPtr hostdev = NULL;
int i; int i;
const char *defaultArch, *defaultMachine; const char *defaultArch, *defaultMachine;
int vmlocaltime = 0;
if (VIR_ALLOC(def) < 0) { if (VIR_ALLOC(def) < 0) {
virReportOOMError(); virReportOOMError();
@ -830,9 +831,13 @@ xenXMDomainConfigParse(virConnectPtr conn, virConfPtr conf) {
else if (val) else if (val)
def->features |= (1 << VIR_DOMAIN_FEATURE_APIC); def->features |= (1 << VIR_DOMAIN_FEATURE_APIC);
} }
if (xenXMConfigGetBool(conn, conf, "localtime", &def->localtime, 0) < 0) if (xenXMConfigGetBool(conn, conf, "localtime", &vmlocaltime, 0) < 0)
goto cleanup; goto cleanup;
def->clock.offset = vmlocaltime ?
VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME :
VIR_DOMAIN_CLOCK_OFFSET_UTC;
if (xenXMConfigCopyStringOpt(conn, conf, "device_model", &def->emulator) < 0) if (xenXMConfigCopyStringOpt(conn, conf, "device_model", &def->emulator) < 0)
goto cleanup; goto cleanup;
@ -2323,8 +2328,18 @@ virConfPtr xenXMDomainConfigFormat(virConnectPtr conn,
goto no_memory; goto no_memory;
if (xenXMConfigSetInt(conf, "localtime", def->localtime ? 1 : 0) < 0) if (def->clock.offset == VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME ||
def->clock.offset == VIR_DOMAIN_CLOCK_OFFSET_UTC) {
if (xenXMConfigSetInt(conf, "localtime",
def->clock.offset == VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME ?
1 : 0) < 0)
goto no_memory; goto no_memory;
} else {
xenXMError(conn, VIR_ERR_CONFIG_UNSUPPORTED,
_("unsupported clock offset '%s'"),
virDomainClockOffsetTypeToString(def->clock.offset));
goto cleanup;
}
if (priv->xendConfigVersion == 1) { if (priv->xendConfigVersion == 1) {
for (i = 0 ; i < def->ndisks ; i++) { for (i = 0 ; i < def->ndisks ; i++) {