Re: [PATCH 2/3] Handle systems with more than 2147483647 kB of memory (#704593).

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/01/2011 04:03 AM, Radek Vykydal wrote:
On 06/30/2011 09:29 PM, David Cantrell wrote:
Our code had a limit of 2TB for the memory check. At least one
reporter is
trying to install on a system with 3TB of memory and anaconda reports
that
he does not have enough memory. The log file reports he has
-1119974932 kB
of memory.
---
iutil.py | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/iutil.py b/iutil.py
index ca20002..596b5d2 100644
--- a/iutil.py
+++ b/iutil.py
@@ -438,7 +438,7 @@ def memInstalled():
mem = fields[1]
break

- return int(mem)
+ return long(mem)


Dosn't int() return long if argument is too big for int?

Maybe? I can't seem to trigger that here, but since the types are supposedly unified in Python, the upper bound may be extremely high. Regardless, leaving long() is harmless.

The real problem was, of course, in loadermisc.c. Which is in the revised patch. Read the MemTotal: from /proc/meminfo in to a guint64 and return that.

New patch attached.

--
David Cantrell <dcantrell@xxxxxxxxxx>
Supervisor, Installer Engineering Team
Red Hat, Inc. | Westford, MA | EST5EDT
>From 754e28e962716e98a8feac4173f7baa77740f6f2 Mon Sep 17 00:00:00 2001
From: David Cantrell <dcantrell@xxxxxxxxxx>
Date: Fri, 24 Jun 2011 12:45:24 -0400
Subject: [PATCH 2/3] Handle systems with more than 2147483647 kB of memory (#704593).

Our code had a limit of 2TB for the memory check.  At least one reporter is
trying to install on a system with 3TB of memory and anaconda reports that
he does not have enough memory.  The log file reports he has -1119974932 kB
of memory.

Make two changes here.  The first is in iutil.py to explicitly use the
long() Python type for memory reporting.  The second is in the
totalMemory() function in loadermisc.c, which is the source of error
reported in #704593.
---
 iutil.py            |    2 +-
 loader/loadermisc.c |   81 ++++++++++++++++++++++++---------------------------
 loader/loadermisc.h |    5 ++-
 3 files changed, 43 insertions(+), 45 deletions(-)

diff --git a/iutil.py b/iutil.py
index ca20002..596b5d2 100644
--- a/iutil.py
+++ b/iutil.py
@@ -438,7 +438,7 @@ def memInstalled():
             mem = fields[1]
             break
 
-    return int(mem)
+    return long(mem)
 
 ## Suggest the size of the swap partition that will be created.
 # @param quiet Should size information be logged?
diff --git a/loader/loadermisc.c b/loader/loadermisc.c
index 03d26bb..55b4520 100644
--- a/loader/loadermisc.c
+++ b/loader/loadermisc.c
@@ -3,7 +3,7 @@
  * anywhere else (yet)  (was misc.c)
  * JKFIXME: need to break out into reasonable files based on function
  *
- * Copyright (C) 1999, 2000, 2001, 2002  Red Hat, Inc.  All rights reserved.
+ * Copyright (C) 1999-2011  Red Hat, Inc.  All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -22,6 +22,7 @@
  *            Matt Wilson <msw@xxxxxxxxxx>
  *            Michael Fulbright <msf@xxxxxxxxxx>
  *            Jeremy Katz <katzj@xxxxxxxxxx>
+ *            David Cantrell <dcantrell@xxxxxxxxxx>
  */
 
 #include <ctype.h>
@@ -31,9 +32,11 @@
 #include <unistd.h>
 #include <stdarg.h>
 #include <stdlib.h>
+#include <glib.h>
 
 #include "log.h"
 #include "windows.h"
+#include "loadermisc.h"
 
 int copyFileFd(int infd, char * dest, progressCB pbcb,
                struct progressCBdata *data, long long total) {
@@ -93,57 +96,49 @@ int simpleStringCmp(const void * a, const void * b) {
     return strverscmp(first, second);
 }
 
-/* look for available memory.  note: won't ever report more than the 
- * 900 megs or so supported by the -BOOT kernel due to not using e820 */
-int totalMemory(void) {
-    int fd;
-    int bytesRead;
-    char buf[4096];
-    char * chptr, * start;
-    int total = 0;
-
-    fd = open("/proc/meminfo", O_RDONLY);
-    if (fd < 0) {
-        logMessage(ERROR, "failed to open /proc/meminfo: %m");
-        return 0;
-    }
-
-    bytesRead = read(fd, buf, sizeof(buf) - 1);
-    if (bytesRead < 0) {
-        logMessage(ERROR, "failed to read from /proc/meminfo: %m");
-        close(fd);
-        return 0;
+/* report total system memory in kB (given to us by /proc/meminfo) */
+guint64 totalMemory(void) {
+    int i = 0, len = 0;
+    uint64_t total = 0;
+    gchar *contents = NULL;
+    gchar **lines = NULL, **fields = NULL;
+    GError *fileErr = NULL;
+
+    if (!g_file_get_contents(MEMINFO, &contents, NULL, &fileErr)) {
+        logMessage(ERROR, "error reading %s: %s", MEMINFO, fileErr->message);
+        g_error_free(fileErr);
+        return total;
     }
 
-    close(fd);
-    buf[bytesRead] = '\0';
+    lines = g_strsplit(contents, "\n", 0);
+    g_free(contents);
 
-    chptr = buf;
-    while (*chptr && !total) {
-        if (strncmp(chptr, "MemTotal:", 9)) {
-            chptr++;
-            continue;
-        }
+    for (i = 0; i < g_strv_length(lines); i++) {
+        if (g_str_has_prefix(lines[i], "MemTotal:")) {
+            fields = g_strsplit(lines[i], " ", 0);
+            len = g_strv_length(fields);
 
-        start = ++chptr ;
-        while (*chptr && *chptr != '\n') chptr++;
+            if (len < 3) {
+                logMessage(ERROR, "unknown format for MemTotal line in %s", MEMINFO);
+                g_strfreev(fields);
+                g_strfreev(lines);
+                return total;
+            }
 
-        *chptr = '\0';
+            errno = 0;
+            total = g_ascii_strtoull(fields[len - 2], NULL, 10);
 
-        while (!isdigit(*start) && *start) start++;
-        if (!*start) {
-            logMessage(WARNING, "no number appears after MemTotal tag");
-            return 0;
-        }
+            if ((errno == ERANGE && total == G_MAXUINT64) ||
+                (errno == EINVAL && total == 0)) {
+                logMessage(ERROR, "%s: %d: %m", __func__, __LINE__);
+                abort();
+            }
 
-        chptr = start;
-        while (*chptr && isdigit(*chptr)) {
-            total = (total * 10) + (*chptr - '0');
-            chptr++;
+            g_strfreev(fields);
+            break;
         }
     }
 
-    logMessage(INFO, "%d kB are available", total);
-
+    g_strfreev(lines);
     return total;
 }
diff --git a/loader/loadermisc.h b/loader/loadermisc.h
index 23ebf4a..5f8b068 100644
--- a/loader/loadermisc.h
+++ b/loader/loadermisc.h
@@ -21,13 +21,16 @@
 #define H_LOADER_MISC_H
 #include <stdio.h>
 #include <stdarg.h>
+#include <glib.h>
 
 #include "windows.h"
 
+#define MEMINFO "/proc/meminfo"
+
 int copyFile(char * source, char * dest);
 int copyFileFd(int infd, char * dest, progressCB pbcb,
                struct progressCBdata *data, long long total);
 int simpleStringCmp(const void * a, const void * b);
-int totalMemory(void);
+guint64 totalMemory(void);
 
 #endif
-- 
1.7.1

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux