[libvirt] [PATCH] Define CPUINFO_FILE_LEN and fix maxlen of cpuinfo file for powerpc

This patch define CPUINFO_FILE_LEN as 2KB which is enough for most architectures. For the 24 cores PowerPC machines, the file of /proc/cpuinfo will be larger than 2KB. It will fail to start libvirtd with the error message as below: virFileReadAll: Failed to read file '/proc/cpuinfo': Value too large for defined data type virSysinfoRead: internal error Failed to open /proc/cpuinfo So this patch increases the maxlen of cpuinfo for PowerPC architecture. Signed-off-by: Olivia Yin <Hong-Hua.Yin@freescale.com> --- src/util/virsysinfo.c | 6 +++--- src/util/virsysinfo.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 7b16157..33c4bc6 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -223,7 +223,7 @@ virSysinfoRead(void) if (VIR_ALLOC(ret) < 0) goto no_memory; - if (virFileReadAll(CPUINFO, 2048, &outbuf) < 0) { + if (virFileReadAll(CPUINFO, 2 * CPUINFO_FILE_LEN, &outbuf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open %s"), CPUINFO); return NULL; @@ -341,7 +341,7 @@ virSysinfoRead(void) if (VIR_ALLOC(ret) < 0) goto no_memory; - if (virFileReadAll(CPUINFO, 2048, &outbuf) < 0) { + if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open %s"), CPUINFO); return NULL; @@ -470,7 +470,7 @@ virSysinfoRead(void) goto no_memory; /* Gather info from /proc/cpuinfo */ - if (virFileReadAll(CPUINFO, 8192, &outbuf) < 0) { + if (virFileReadAll(CPUINFO, 4 * CPUINFO_FILE_LEN, &outbuf) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to open %s"), CPUINFO); return NULL; diff --git a/src/util/virsysinfo.h b/src/util/virsysinfo.h index fbb505b..630b9ce 100644 --- a/src/util/virsysinfo.h +++ b/src/util/virsysinfo.h @@ -102,4 +102,6 @@ bool virSysinfoIsEqual(virSysinfoDefPtr src, VIR_ENUM_DECL(virSysinfo) +#define CPUINFO_FILE_LEN 2048 /*2KB limit for normal cpuinfo file*/ + #endif /* __VIR_SYSINFOS_H__ */ -- 1.8.5

Save/restore the state of domain and migrate need read state XML file. 8192B is not the exactly maximum file length of state file. restore command could work successfully in virsh shell. virsh # list --all Id Name State ---------------------------------------------------- 9 sdk running virsh # save sdk pp Domain sdk saved to pp virsh # list --all Id Name State ---------------------------------------------------- - sdk shut off virsh # restore pp Domain restored from pp virsh # list --all Id Name State ---------------------------------------------------- 10 sdk running But it will fail with 'virsh restore' command because the state file is oversized. ~# virsh restore pp error: Failed to read file 'pp': Value too large for defined data type Signed-off-by: Olivia Yin <Hong-Hua.Yin@freescale.com> --- tools/virsh-domain.c | 6 +++--- tools/virsh.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 73414f8..8ade296 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3547,7 +3547,7 @@ doSave(void *opaque) goto out; if (xmlfile && - virFileReadAll(xmlfile, 8192, &xml) < 0) { + virFileReadAll(xmlfile, STATE_XMLFILE_LEN, &xml) < 0) { vshReportError(ctl); goto out; } @@ -3840,7 +3840,7 @@ cmdSaveImageDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0) return false; - if (virFileReadAll(xmlfile, 8192, &xml) < 0) + if (virFileReadAll(xmlfile, STATE_XMLFILE_LEN, &xml) < 0) goto cleanup; if (virDomainSaveImageDefineXML(ctl->conn, file, xml, flags) < 0) { @@ -4424,7 +4424,7 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd) return false; if (xmlfile && - virFileReadAll(xmlfile, 8192, &xml) < 0) + virFileReadAll(xmlfile, STATE_XMLFILE_LEN, &xml) < 0) goto cleanup; if (((flags || xml) diff --git a/tools/virsh.h b/tools/virsh.h index 3e0251b..3f95216 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -41,6 +41,7 @@ # include "virstring.h" # define VSH_MAX_XML_FILE (10*1024*1024) +# define STATE_XMLFILE_LEN (8*1024) # define VSH_PROMPT_RW "virsh # " # define VSH_PROMPT_RO "virsh > " -- 1.8.5

On 04/03/2014 08:43 AM, Olivia Yin wrote:
Save/restore the state of domain and migrate need read state XML file. 8192B is not the exactly maximum file length of state file.
restore command could work successfully in virsh shell. virsh # list --all Id Name State ---------------------------------------------------- 9 sdk running
virsh # save sdk pp
Domain sdk saved to pp
virsh # list --all Id Name State ---------------------------------------------------- - sdk shut off
virsh # restore pp Domain restored from pp
virsh # list --all Id Name State ---------------------------------------------------- 10 sdk running
But it will fail with 'virsh restore' command because the state file is oversized. ~# virsh restore pp error: Failed to read file 'pp': Value too large for defined data type
There is no xml file supplied here, just the save file...
Signed-off-by: Olivia Yin <Hong-Hua.Yin@freescale.com> --- tools/virsh-domain.c | 6 +++--- tools/virsh.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 73414f8..8ade296 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3547,7 +3547,7 @@ doSave(void *opaque) goto out;
if (xmlfile && - virFileReadAll(xmlfile, 8192, &xml) < 0) { + virFileReadAll(xmlfile, STATE_XMLFILE_LEN, &xml) < 0) { vshReportError(ctl); goto out; } @@ -3840,7 +3840,7 @@ cmdSaveImageDefine(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0) return false;
- if (virFileReadAll(xmlfile, 8192, &xml) < 0) + if (virFileReadAll(xmlfile, STATE_XMLFILE_LEN, &xml) < 0) goto cleanup;
if (virDomainSaveImageDefineXML(ctl->conn, file, xml, flags) < 0) { @@ -4424,7 +4424,7 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd) return false;
if (xmlfile && - virFileReadAll(xmlfile, 8192, &xml) < 0) + virFileReadAll(xmlfile, STATE_XMLFILE_LEN, &xml) < 0)
... but this changes the limit for the XML file of the updated domain, so it shouldn't be executed by the above command. Does this actually fix the issue? Also, VSH_MAX_XML_FILE can be used for all of these. Jan

This patch only defines a macro STATE_FILE_LEN. It doesn't aim to fix the issue. VSH_MAX_XML_FILE is 10MB, but I got a saved XML file about 180MB. Best Regards, Olivia
-----Original Message----- From: Ján Tomko [mailto:jtomko@redhat.com] Sent: Friday, April 04, 2014 2:06 PM To: Yin Olivia-R63875; libvir-list@redhat.com Subject: Re: [libvirt] [PATCH] Define STATE_XMLFILE_LEN as 8192
On 04/03/2014 08:43 AM, Olivia Yin wrote:
Save/restore the state of domain and migrate need read state XML file. 8192B is not the exactly maximum file length of state file.
restore command could work successfully in virsh shell. virsh # list --all Id Name State ---------------------------------------------------- 9 sdk running
virsh # save sdk pp
Domain sdk saved to pp
virsh # list --all Id Name State ---------------------------------------------------- - sdk shut off
virsh # restore pp Domain restored from pp
virsh # list --all Id Name State ---------------------------------------------------- 10 sdk running
But it will fail with 'virsh restore' command because the state file is oversized. ~# virsh restore pp error: Failed to read file 'pp': Value too large for defined data type
There is no xml file supplied here, just the save file...
Signed-off-by: Olivia Yin <Hong-Hua.Yin@freescale.com> --- tools/virsh-domain.c | 6 +++--- tools/virsh.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 73414f8..8ade296 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3547,7 +3547,7 @@ doSave(void *opaque) goto out;
if (xmlfile && - virFileReadAll(xmlfile, 8192, &xml) < 0) { + virFileReadAll(xmlfile, STATE_XMLFILE_LEN, &xml) < 0) { vshReportError(ctl); goto out; } @@ -3840,7 +3840,7 @@ cmdSaveImageDefine(vshControl *ctl, const vshCmd
*cmd)
if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0) return false;
- if (virFileReadAll(xmlfile, 8192, &xml) < 0) + if (virFileReadAll(xmlfile, STATE_XMLFILE_LEN, &xml) < 0) goto cleanup;
if (virDomainSaveImageDefineXML(ctl->conn, file, xml, flags) < 0) { @@ -4424,7 +4424,7 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd) return false;
if (xmlfile && - virFileReadAll(xmlfile, 8192, &xml) < 0) + virFileReadAll(xmlfile, STATE_XMLFILE_LEN, &xml) < 0)
... but this changes the limit for the XML file of the updated domain, so it shouldn't be executed by the above command. Does this actually fix the issue?
Also, VSH_MAX_XML_FILE can be used for all of these.
Jan

On 04/03/2014 12:43 AM, Olivia Yin wrote:
This patch define CPUINFO_FILE_LEN as 2KB which is enough for most architectures.
For the 24 cores PowerPC machines, the file of /proc/cpuinfo will be larger than 2KB. It will fail to start libvirtd with the error message as below: virFileReadAll: Failed to read file '/proc/cpuinfo': Value too large for defined data type virSysinfoRead: internal error Failed to open /proc/cpuinfo
So this patch increases the maxlen of cpuinfo for PowerPC architecture.
Signed-off-by: Olivia Yin <Hong-Hua.Yin@freescale.com> --- src/util/virsysinfo.c | 6 +++--- src/util/virsysinfo.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 7b16157..33c4bc6 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -223,7 +223,7 @@ virSysinfoRead(void) if (VIR_ALLOC(ret) < 0) goto no_memory;
- if (virFileReadAll(CPUINFO, 2048, &outbuf) < 0) { + if (virFileReadAll(CPUINFO, 2 * CPUINFO_FILE_LEN, &outbuf) < 0) {
Uggh. Having to multiply the constant means you defined the constant wrong. Just make CPUINFO_FILE_LEN big enough. Even as large as 1M, for ALL uses, is not a burden.
+++ b/src/util/virsysinfo.h @@ -102,4 +102,6 @@ bool virSysinfoIsEqual(virSysinfoDefPtr src,
VIR_ENUM_DECL(virSysinfo)
+#define CPUINFO_FILE_LEN 2048 /*2KB limit for normal cpuinfo file*/ + #endif /* __VIR_SYSINFOS_H__ */
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Hi Eric, Thanks for comments. I'll submit a new revision of this patch. Best Regards, Olivia
-----Original Message----- From: Eric Blake [mailto:eblake@redhat.com] Sent: Thursday, April 03, 2014 8:25 PM To: Yin Olivia-R63875; libvir-list@redhat.com Subject: Re: [libvirt] [PATCH] Define CPUINFO_FILE_LEN and fix maxlen of cpuinfo file for powerpc
On 04/03/2014 12:43 AM, Olivia Yin wrote:
This patch define CPUINFO_FILE_LEN as 2KB which is enough for most architectures.
For the 24 cores PowerPC machines, the file of /proc/cpuinfo will be larger than 2KB. It will fail to start libvirtd with the error message as below: virFileReadAll: Failed to read file '/proc/cpuinfo': Value too large for defined data type virSysinfoRead: internal error Failed to open /proc/cpuinfo
So this patch increases the maxlen of cpuinfo for PowerPC architecture.
Signed-off-by: Olivia Yin <Hong-Hua.Yin@freescale.com> --- src/util/virsysinfo.c | 6 +++--- src/util/virsysinfo.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 7b16157..33c4bc6 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -223,7 +223,7 @@ virSysinfoRead(void) if (VIR_ALLOC(ret) < 0) goto no_memory;
- if (virFileReadAll(CPUINFO, 2048, &outbuf) < 0) { + if (virFileReadAll(CPUINFO, 2 * CPUINFO_FILE_LEN, &outbuf) < 0) {
Uggh. Having to multiply the constant means you defined the constant wrong. Just make CPUINFO_FILE_LEN big enough. Even as large as 1M, for ALL uses, is not a burden.
+++ b/src/util/virsysinfo.h @@ -102,4 +102,6 @@ bool virSysinfoIsEqual(virSysinfoDefPtr src,
VIR_ENUM_DECL(virSysinfo)
+#define CPUINFO_FILE_LEN 2048 /*2KB limit for normal cpuinfo file*/ + #endif /* __VIR_SYSINFOS_H__ */
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (4)
-
Eric Blake
-
Hong-Hua.Yin@freescale.com
-
Ján Tomko
-
Olivia Yin