From patchwork Thu Jan 21 18:42:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 60103 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp178587lbb; Thu, 21 Jan 2016 10:45:59 -0800 (PST) X-Received: by 10.140.236.68 with SMTP id h65mr57686704qhc.13.1453401959895; Thu, 21 Jan 2016 10:45:59 -0800 (PST) Return-Path: Received: from mx5-phx2.redhat.com (mx5-phx2.redhat.com. [209.132.183.37]) by mx.google.com with ESMTPS id d21si2561204qkb.86.2016.01.21.10.45.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jan 2016 10:45:59 -0800 (PST) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.37 as permitted sender) client-ip=209.132.183.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.37 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx5-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0LIhPVt062908; Thu, 21 Jan 2016 13:43:25 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u0LIh5KG013924 for ; Thu, 21 Jan 2016 13:43:05 -0500 Received: from colepc.redhat.com (ovpn-113-198.phx2.redhat.com [10.3.113.198]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u0LIh4Yg032379; Thu, 21 Jan 2016 13:43:05 -0500 From: Cole Robinson To: libvirt-list@redhat.com Date: Thu, 21 Jan 2016 13:42:57 -0500 Message-Id: <84ba247557eb846843316bb8f9ddf4ddccfa32c0.1453401727.git.crobinso@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/4] lxc: fuse: Unindent meminfo logic X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com Reverse the conditional at the start so we aren't stuffing all the logic in an 'if' block --- src/lxc/lxc_fuse.c | 122 ++++++++++++++++++++++++++--------------------------- 1 file changed, 61 insertions(+), 61 deletions(-) -- 2.5.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c index 862dca3..86c0d10 100644 --- a/src/lxc/lxc_fuse.c +++ b/src/lxc/lxc_fuse.c @@ -161,68 +161,68 @@ static int lxcProcReadMeminfo(char *hostpath, virDomainDefPtr def, res = -1; while (copied < size && getline(&line, &n, fd) > 0) { char *ptr = strchr(line, ':'); - if (ptr) { - *ptr = '\0'; - - if (STREQ(line, "MemTotal") && - (virMemoryLimitIsSet(def->mem.hard_limit) || - virDomainDefGetMemoryActual(def))) { - virBufferAsprintf(new_meminfo, "MemTotal: %8llu kB\n", - meminfo.memtotal); - } else if (STREQ(line, "MemFree") && - (virMemoryLimitIsSet(def->mem.hard_limit) || - virDomainDefGetMemoryActual(def))) { - virBufferAsprintf(new_meminfo, "MemFree: %8llu kB\n", - (meminfo.memtotal - meminfo.memusage)); - } else if (STREQ(line, "Buffers")) { - virBufferAsprintf(new_meminfo, "Buffers: %8d kB\n", 0); - } else if (STREQ(line, "Cached")) { - virBufferAsprintf(new_meminfo, "Cached: %8llu kB\n", - meminfo.cached); - } else if (STREQ(line, "Active")) { - virBufferAsprintf(new_meminfo, "Active: %8llu kB\n", - (meminfo.active_anon + meminfo.active_file)); - } else if (STREQ(line, "Inactive")) { - virBufferAsprintf(new_meminfo, "Inactive: %8llu kB\n", - (meminfo.inactive_anon + meminfo.inactive_file)); - } else if (STREQ(line, "Active(anon)")) { - virBufferAsprintf(new_meminfo, "Active(anon): %8llu kB\n", - meminfo.active_anon); - } else if (STREQ(line, "Inactive(anon)")) { - virBufferAsprintf(new_meminfo, "Inactive(anon): %8llu kB\n", - meminfo.inactive_anon); - } else if (STREQ(line, "Active(file)")) { - virBufferAsprintf(new_meminfo, "Active(file): %8llu kB\n", - meminfo.active_file); - } else if (STREQ(line, "Inactive(file)")) { - virBufferAsprintf(new_meminfo, "Inactive(file): %8llu kB\n", - meminfo.inactive_file); - } else if (STREQ(line, "Unevictable")) { - virBufferAsprintf(new_meminfo, "Unevictable: %8llu kB\n", - meminfo.unevictable); - } else if (STREQ(line, "SwapTotal") && - virMemoryLimitIsSet(def->mem.swap_hard_limit)) { - virBufferAsprintf(new_meminfo, "SwapTotal: %8llu kB\n", - (meminfo.swaptotal - meminfo.memtotal)); - } else if (STREQ(line, "SwapFree") && - virMemoryLimitIsSet(def->mem.swap_hard_limit)) { - virBufferAsprintf(new_meminfo, "SwapFree: %8llu kB\n", - (meminfo.swaptotal - meminfo.memtotal - - meminfo.swapusage + meminfo.memusage)); - } else { - *ptr = ':'; - virBufferAdd(new_meminfo, line, -1); - } - - if (virBufferCheckError(new_meminfo) < 0) { - res = -errno; - goto cleanup; - } - - copied += strlen(line); - if (copied > size) - copied = size; + if (!ptr) + continue; + *ptr = '\0'; + + if (STREQ(line, "MemTotal") && + (virMemoryLimitIsSet(def->mem.hard_limit) || + virDomainDefGetMemoryActual(def))) { + virBufferAsprintf(new_meminfo, "MemTotal: %8llu kB\n", + meminfo.memtotal); + } else if (STREQ(line, "MemFree") && + (virMemoryLimitIsSet(def->mem.hard_limit) || + virDomainDefGetMemoryActual(def))) { + virBufferAsprintf(new_meminfo, "MemFree: %8llu kB\n", + (meminfo.memtotal - meminfo.memusage)); + } else if (STREQ(line, "Buffers")) { + virBufferAsprintf(new_meminfo, "Buffers: %8d kB\n", 0); + } else if (STREQ(line, "Cached")) { + virBufferAsprintf(new_meminfo, "Cached: %8llu kB\n", + meminfo.cached); + } else if (STREQ(line, "Active")) { + virBufferAsprintf(new_meminfo, "Active: %8llu kB\n", + (meminfo.active_anon + meminfo.active_file)); + } else if (STREQ(line, "Inactive")) { + virBufferAsprintf(new_meminfo, "Inactive: %8llu kB\n", + (meminfo.inactive_anon + meminfo.inactive_file)); + } else if (STREQ(line, "Active(anon)")) { + virBufferAsprintf(new_meminfo, "Active(anon): %8llu kB\n", + meminfo.active_anon); + } else if (STREQ(line, "Inactive(anon)")) { + virBufferAsprintf(new_meminfo, "Inactive(anon): %8llu kB\n", + meminfo.inactive_anon); + } else if (STREQ(line, "Active(file)")) { + virBufferAsprintf(new_meminfo, "Active(file): %8llu kB\n", + meminfo.active_file); + } else if (STREQ(line, "Inactive(file)")) { + virBufferAsprintf(new_meminfo, "Inactive(file): %8llu kB\n", + meminfo.inactive_file); + } else if (STREQ(line, "Unevictable")) { + virBufferAsprintf(new_meminfo, "Unevictable: %8llu kB\n", + meminfo.unevictable); + } else if (STREQ(line, "SwapTotal") && + virMemoryLimitIsSet(def->mem.swap_hard_limit)) { + virBufferAsprintf(new_meminfo, "SwapTotal: %8llu kB\n", + (meminfo.swaptotal - meminfo.memtotal)); + } else if (STREQ(line, "SwapFree") && + virMemoryLimitIsSet(def->mem.swap_hard_limit)) { + virBufferAsprintf(new_meminfo, "SwapFree: %8llu kB\n", + (meminfo.swaptotal - meminfo.memtotal - + meminfo.swapusage + meminfo.memusage)); + } else { + *ptr = ':'; + virBufferAdd(new_meminfo, line, -1); } + + if (virBufferCheckError(new_meminfo) < 0) { + res = -errno; + goto cleanup; + } + + copied += strlen(line); + if (copied > size) + copied = size; } res = copied; memcpy(buf, virBufferCurrentContent(new_meminfo), copied);