[libvirt] [PATCH]lxc: don't do duplicate work when getting pagesize

From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> Don't do duplicate work when getting pagesize. With some debug logs added. Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- src/lxc/lxc_container.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 255c711..e85d01c 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -144,6 +144,7 @@ int lxcContainerHasReboot(void) int cmd, v; int status; char *tmp; + int stacksize = getpagesize() * 4; if (virFileReadAll("/proc/sys/kernel/ctrl-alt-del", 10, &buf) < 0) return -1; @@ -160,10 +161,12 @@ int lxcContainerHasReboot(void) VIR_FREE(buf); cmd = v ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF; - if (VIR_ALLOC_N(stack, getpagesize() * 4) < 0) + if (VIR_ALLOC_N(stack, stacksize) < 0) { + VIR_DEBUG("Unable to allocate stack"); return -1; + } - childStack = stack + (getpagesize() * 4); + childStack = stack + stacksize; cpid = clone(lxcContainerRebootChild, childStack, flags, &cmd); VIR_FREE(stack); @@ -2011,8 +2014,10 @@ int lxcContainerStart(virDomainDefPtr def, }; /* allocate a stack for the container */ - if (VIR_ALLOC_N(stack, stacksize) < 0) + if (VIR_ALLOC_N(stack, stacksize) < 0) { + VIR_DEBUG("Unable to allocate stack"); return -1; + } stacktop = stack + stacksize; cflags = CLONE_NEWPID|CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWIPC|SIGCHLD; @@ -2060,6 +2065,7 @@ int lxcContainerAvailable(int features) int cpid; char *childStack; char *stack; + int stacksize = getpagesize() * 4; if (features & LXC_CONTAINER_FEATURE_USER) flags |= CLONE_NEWUSER; @@ -2067,12 +2073,12 @@ int lxcContainerAvailable(int features) if (features & LXC_CONTAINER_FEATURE_NET) flags |= CLONE_NEWNET; - if (VIR_ALLOC_N(stack, getpagesize() * 4) < 0) { + if (VIR_ALLOC_N(stack, stacksize) < 0) { VIR_DEBUG("Unable to allocate stack"); return -1; } - childStack = stack + (getpagesize() * 4); + childStack = stack + stacksize; cpid = clone(lxcContainerDummyChild, childStack, flags, NULL); VIR_FREE(stack); -- 1.8.2.1

-----Original Message----- From: Chen Hanxiao [mailto:chenhanxiao@cn.fujitsu.com] Sent: Monday, November 18, 2013 4:03 PM To: libvir-list@redhat.com Cc: chenhanxiao@cn.fujitsu.com Subject: [libvirt][PATCH]lxc: don't do duplicate work when getting
ping pagesize
From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Don't do duplicate work when getting pagesize. With some debug logs added.
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- src/lxc/lxc_container.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 255c711..e85d01c 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -144,6 +144,7 @@ int lxcContainerHasReboot(void) int cmd, v; int status; char *tmp; + int stacksize = getpagesize() * 4;
if (virFileReadAll("/proc/sys/kernel/ctrl-alt-del", 10, &buf) < 0) return -1; @@ -160,10 +161,12 @@ int lxcContainerHasReboot(void) VIR_FREE(buf); cmd = v ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF;
- if (VIR_ALLOC_N(stack, getpagesize() * 4) < 0) + if (VIR_ALLOC_N(stack, stacksize) < 0) { + VIR_DEBUG("Unable to allocate stack"); return -1; + }
- childStack = stack + (getpagesize() * 4); + childStack = stack + stacksize;
cpid = clone(lxcContainerRebootChild, childStack, flags, &cmd); VIR_FREE(stack); @@ -2011,8 +2014,10 @@ int lxcContainerStart(virDomainDefPtr def, };
/* allocate a stack for the container */ - if (VIR_ALLOC_N(stack, stacksize) < 0) + if (VIR_ALLOC_N(stack, stacksize) < 0) { + VIR_DEBUG("Unable to allocate stack"); return -1; + } stacktop = stack + stacksize;
cflags = CLONE_NEWPID|CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWIPC|SIGCHLD ; @@ -2060,6 +2065,7 @@ int lxcContainerAvailable(int features) int cpid; char *childStack; char *stack; + int stacksize = getpagesize() * 4;
if (features & LXC_CONTAINER_FEATURE_USER) flags |= CLONE_NEWUSER; @@ -2067,12 +2073,12 @@ int lxcContainerAvailable(int features) if (features & LXC_CONTAINER_FEATURE_NET) flags |= CLONE_NEWNET;
- if (VIR_ALLOC_N(stack, getpagesize() * 4) < 0) { + if (VIR_ALLOC_N(stack, stacksize) < 0) { VIR_DEBUG("Unable to allocate stack"); return -1; }
- childStack = stack + (getpagesize() * 4); + childStack = stack + stacksize;
cpid = clone(lxcContainerDummyChild, childStack, flags, NULL); VIR_FREE(stack); -- 1.8.2.1

On 18/11/13 16:03, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Don't do duplicate work when getting pagesize. With some debug logs added.
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- src/lxc/lxc_container.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 255c711..e85d01c 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -144,6 +144,7 @@ int lxcContainerHasReboot(void) int cmd, v; int status; char *tmp; + int stacksize = getpagesize() * 4;
if (virFileReadAll("/proc/sys/kernel/ctrl-alt-del", 10, &buf) < 0) return -1; @@ -160,10 +161,12 @@ int lxcContainerHasReboot(void) VIR_FREE(buf); cmd = v ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF;
- if (VIR_ALLOC_N(stack, getpagesize() * 4) < 0) + if (VIR_ALLOC_N(stack, stacksize) < 0) { + VIR_DEBUG("Unable to allocate stack");
virAllocN already reports the out-of-memory error, why do we need a debug log? Osier

-----Original Message----- From: Osier Yang [mailto:jyang@redhat.com] Sent: Monday, November 25, 2013 1:13 PM To: Chen Hanxiao Cc: libvir-list@redhat.com Subject: Re: [libvirt] [PATCH]lxc: don't do duplicate work when getting
pagesize
On 18/11/13 16:03, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Don't do duplicate work when getting pagesize. With some debug logs added.
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- src/lxc/lxc_container.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 255c711..e85d01c 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -144,6 +144,7 @@ int lxcContainerHasReboot(void) int cmd, v; int status; char *tmp; + int stacksize = getpagesize() * 4;
if (virFileReadAll("/proc/sys/kernel/ctrl-alt-del", 10, &buf) < 0) return -1; @@ -160,10 +161,12 @@ int lxcContainerHasReboot(void) VIR_FREE(buf); cmd = v ? LINUX_REBOOT_CMD_CAD_ON : LINUX_REBOOT_CMD_CAD_OFF;
- if (VIR_ALLOC_N(stack, getpagesize() * 4) < 0) + if (VIR_ALLOC_N(stack, stacksize) < 0) { + VIR_DEBUG("Unable to allocate stack");
virAllocN already reports the out-of-memory error, why do we need a debug log?
I've already see it. I just want it to look alike the same scenario in lxcContainerAvailable Maybe we should also delete that code in lxcContainerAvailable.
Osier
participants (2)
-
Chen Hanxiao
-
Osier Yang