# HG changeset patch
# User Keir Fraser <keir@xxxxxxx>
# Date 1311600073 -3600
# Node ID 9dbbf1631193bb6df679f5eaaee192ef4ef91fd9
# Parent 3244ff483d615f4ab1d938a240052154c13a62f8
hvmloader: Allow default response to be specified to xenstore_read().
Signed-off-by: Keir Fraser <keir@xxxxxxx>
---
diff -r 3244ff483d61 -r 9dbbf1631193 tools/firmware/hvmloader/hvmloader.c
--- a/tools/firmware/hvmloader/hvmloader.c Mon Jul 25 14:09:41 2011 +0100
+++ b/tools/firmware/hvmloader/hvmloader.c Mon Jul 25 14:21:13 2011 +0100
@@ -368,9 +368,7 @@
const struct bios_info *b;
const char *bios;
- bios = xenstore_read("hvmloader/bios");
- if ( !bios )
- bios = "rombios";
+ bios = xenstore_read("hvmloader/bios", "rombios");
for ( b = &bios_configs[0]; b->key != NULL; b++ )
if ( !strcmp(bios, b->key) )
diff -r 3244ff483d61 -r 9dbbf1631193 tools/firmware/hvmloader/smbios.c
--- a/tools/firmware/hvmloader/smbios.c Mon Jul 25 14:09:41 2011 +0100
+++ b/tools/firmware/hvmloader/smbios.c Mon Jul 25 14:21:13 2011 +0100
@@ -315,15 +315,11 @@
p->embedded_controller_minor = 0xff;
start += sizeof(struct smbios_type_0);
- if ( ((s = xenstore_read("bios-strings/bios-vendor")) == NULL)
- || (*s == '\0') )
- s = "Xen";
+ s = xenstore_read("bios-strings/bios-vendor", "Xen");
strcpy((char *)start, s);
start += strlen(s) + 1;
- if ( ((s = xenstore_read("bios-strings/bios-version")) == NULL)
- || (*s == '\0') )
- s = xen_version;
+ s = xenstore_read("bios-strings/bios-version", xen_version);
strcpy((char *)start, s);
start += strlen(s) + 1;
@@ -362,28 +358,20 @@
start += sizeof(struct smbios_type_1);
- if ( ((s = xenstore_read("bios-strings/system-manufacturer")) == NULL)
- || (*s == '\0') )
- s = "Xen";
+ s = xenstore_read("bios-strings/system-manufacturer", "Xen");
strcpy((char *)start, s);
start += strlen(s) + 1;
- if ( ((s = xenstore_read("bios-strings/system-product-name")) == NULL)
- || (*s == '\0') )
- s = "HVM domU";
+ s = xenstore_read("bios-strings/system-product-name", "HVM domU");
strcpy((char *)start, s);
start += strlen(s) + 1;
- if ( ((s = xenstore_read("bios-strings/system-version")) == NULL)
- || (*s == '\0') )
- s = xen_version;
+ s = xenstore_read("bios-strings/system-version", xen_version);
strcpy((char *)start, s);
start += strlen(s) + 1;
uuid_to_string(uuid_str, uuid);
- if ( ((s = xenstore_read("bios-strings/system-serial-number")) == NULL)
- || (*s == '\0') )
- s = uuid_str;
+ s = xenstore_read("bios-strings/system-serial-number", uuid_str);
strcpy((char *)start, s);
start += strlen(s) + 1;
@@ -494,7 +482,7 @@
{
path[(sizeof path) - 3] = '0' + ((i < 10) ? i : i / 10);
path[(sizeof path) - 2] = (i < 10) ? '\0' : '0' + (i % 10);
- if ( ((s = xenstore_read(path)) == NULL) || (*s == '\0') )
+ if ( ((s = xenstore_read(path, NULL)) == NULL) || (*s == '\0') )
break;
strcpy((char *)start, s);
start += strlen(s) + 1;
diff -r 3244ff483d61 -r 9dbbf1631193 tools/firmware/hvmloader/util.h
--- a/tools/firmware/hvmloader/util.h Mon Jul 25 14:09:41 2011 +0100
+++ b/tools/firmware/hvmloader/util.h Mon Jul 25 14:21:13 2011 +0100
@@ -187,8 +187,11 @@
/* Read a xenstore key. Returns a nul-terminated string (even if the XS
* data wasn't nul-terminated) or NULL. The returned string is in a
- * static buffer, so only valid until the next xenstore/xenbus operation. */
-char *xenstore_read(char *path);
+ * static buffer, so only valid until the next xenstore/xenbus operation.
+ * If @default_resp is specified, it is returned in preference to a NULL or
+ * empty string received from xenstore.
+ */
+const char *xenstore_read(const char *path, const char *default_resp);
/* Setup PCI bus */
void pci_setup(void);
diff -r 3244ff483d61 -r 9dbbf1631193 tools/firmware/hvmloader/xenbus.c
--- a/tools/firmware/hvmloader/xenbus.c Mon Jul 25 14:09:41 2011 +0100
+++ b/tools/firmware/hvmloader/xenbus.c Mon Jul 25 14:21:13 2011 +0100
@@ -83,7 +83,7 @@
}
/* Helper functions: copy data in and out of the ring */
-static void ring_write(char *data, uint32_t len)
+static void ring_write(const char *data, uint32_t len)
{
uint32_t part;
@@ -140,8 +140,8 @@
* Returns 0 for success, or an errno for error.
* The answer is returned in a static buffer which is only
* valid until the next call of xenbus_send(). */
-static int xenbus_send(uint32_t type, uint32_t len, char *data,
- uint32_t *reply_len, char **reply_data)
+static int xenbus_send(uint32_t type, uint32_t len, const char *data,
+ uint32_t *reply_len, const char **reply_data)
{
struct xsd_sockmsg hdr;
evtchn_send_t send;
@@ -190,15 +190,22 @@
/* Read a xenstore key. Returns a nul-terminated string (even if the XS
* data wasn't nul-terminated) or NULL. The returned string is in a
- * static buffer, so only valid until the next xenstore/xenbus operation. */
-char *xenstore_read(char *path)
+ * static buffer, so only valid until the next xenstore/xenbus operation.
+ * If @default_resp is specified, it is returned in preference to a NULL or
+ * empty string received from xenstore.
+ */
+const char *xenstore_read(const char *path, const char *default_resp)
{
uint32_t len = 0;
- char *answer = NULL;
+ const char *answer = NULL;
/* Include the nul in the request */
if ( xenbus_send(XS_READ, strlen(path) + 1, path, &len, &answer) )
- return NULL;
+ answer = NULL;
+
+ if ( (default_resp != NULL) && ((answer == NULL) || (*answer == '\0')) )
+ answer = default_resp;
+
/* We know xenbus_send() nul-terminates its answer, so just pass it on. */
return answer;
}
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|