[master] refactoring: put totalMemory() into isys.

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

 



so the python implementation in iutil.py can be removed.
---
 anaconda            |    2 +-
 isys/Makefile.am    |    2 +-
 isys/isys.c         |    7 ++++
 isys/isys.h         |   11 ------
 isys/mem.c          |   94 +++++++++++++++++++++++++++++++++++++++++++++++++++
 isys/mem.h          |   37 ++++++++++++++++++++
 iutil.py            |   11 ------
 loader/cdinstall.c  |    1 +
 loader/loader.c     |    1 +
 loader/loadermisc.c |   62 ---------------------------------
 loader/loadermisc.h |    1 -
 11 files changed, 142 insertions(+), 87 deletions(-)
 create mode 100644 isys/mem.c
 create mode 100644 isys/mem.h

diff --git a/anaconda b/anaconda
index 498fa20..d92053b 100755
--- a/anaconda
+++ b/anaconda
@@ -355,7 +355,7 @@ def check_memory(anaconda, opts, display_mode=None):
         extra_ram += isys.URL_INSTALL_EXTRA_RAM
         reason = " using this install method"
 
-    total_ram = iutil.total_memory()
+    total_ram = isys.total_memory()
 
     needed_ram = isys.MIN_RAM + extra_ram
     if needed_ram > total_ram:
diff --git a/isys/Makefile.am b/isys/Makefile.am
index 1a7ca81..978df72 100644
--- a/isys/Makefile.am
+++ b/isys/Makefile.am
@@ -21,7 +21,7 @@ pkgpyexecdir = $(pyexecdir)/py$(PACKAGE_NAME)
 
 ISYS_SRCS = devices.c imount.c cpio.c uncpio.c lang.c \
             isofs.c linkdetect.c vio.c ethtool.c eddsupport.c iface.c \
-            auditd.c log.c
+            auditd.c log.c mem.c
 
 dist_noinst_HEADERS = *.h
 
diff --git a/isys/isys.c b/isys/isys.c
index 6aeb72f..eddc2d4 100644
--- a/isys/isys.c
+++ b/isys/isys.c
@@ -78,6 +78,7 @@
 #include "auditd.h"
 #include "imount.h"
 #include "log.h"
+#include "mem.h"
 
 #ifndef CDROMEJECT
 #define CDROMEJECT 0x5309
@@ -114,6 +115,7 @@ static PyObject * doGetLinkStatus(PyObject * s, PyObject * args);
 static PyObject * doGetAnacondaVersion(PyObject * s, PyObject * args);
 static PyObject * doInitLog(PyObject * s);
 static PyObject * doIsWirelessDevice(PyObject * s, PyObject * args);
+static PyObject * doTotalMemory(PyObject * s);
 
 static PyMethodDef isysModuleMethods[] = {
     { "ejectcdrom", (PyCFunction) doEjectCdrom, METH_VARARGS, NULL },
@@ -147,6 +149,7 @@ static PyMethodDef isysModuleMethods[] = {
     { "getAnacondaVersion", (PyCFunction) doGetAnacondaVersion, METH_VARARGS, NULL },
     { "initLog", (PyCFunction) doInitLog, METH_VARARGS, NULL },
     { "isWirelessDevice", (PyCFunction) doIsWirelessDevice, METH_VARARGS, NULL },
+    { "total_memory", (PyCFunction) doTotalMemory, METH_NOARGS, NULL },
     { NULL, NULL, 0, NULL }
 } ;
 
@@ -713,6 +716,10 @@ static PyObject * doIsWirelessDevice(PyObject * s, PyObject * args) {
     }
 
     return PyBool_FromLong(0);
+
+static PyObject * doTotalMemory(PyObject * s) {
+    int tm = totalMemory();
+    return PyInt_FromLong(tm);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4: */
diff --git a/isys/isys.h b/isys/isys.h
index 659e3d6..980a872 100644
--- a/isys/isys.h
+++ b/isys/isys.h
@@ -20,17 +20,6 @@
 #ifndef H_ISYS
 #define H_ISYS
 
-#if defined(__powerpc64__) || defined(__sparc__)
-  #define MIN_RAM                 1024*1024 // 1 GB
-  #define GUI_INSTALL_EXTRA_RAM   512*1024  // 512 MB
-#else
-  #define MIN_RAM                 256 * 1024 // 256 MB
-  #define GUI_INSTALL_EXTRA_RAM   128 * 1024 // 128 MB
-#endif
-#define URL_INSTALL_EXTRA_RAM   128 * 1024 // 128 MB
-#define MIN_GUI_RAM             MIN_RAM + GUI_INSTALL_EXTRA_RAM
-#define EARLY_SWAP_RAM          512 * 1024 // 512 MB
-
 #define OUTPUT_TERMINAL "/dev/tty5"
 
 int insmod(char * modName, char * path, char ** args);
diff --git a/isys/mem.c b/isys/mem.c
new file mode 100644
index 0000000..3003ba0
--- /dev/null
+++ b/isys/mem.c
@@ -0,0 +1,94 @@
+/*
+ * mem.c - memory checking
+ *
+ * Copyright (C) 2010
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <ctype.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "mem.h"
+#include "log.h"
+
+/* 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;
+    }
+
+    close(fd);
+    buf[bytesRead] = '\0';
+
+    chptr = buf;
+    while (*chptr && !total) {
+        if (strncmp(chptr, "MemTotal:", 9)) {
+            chptr++;
+            continue;
+        }
+
+        start = ++chptr ;
+        while (*chptr && *chptr != '\n') chptr++;
+
+        *chptr = '\0';
+
+        while (!isdigit(*start) && *start) start++;
+        if (!*start) {
+            logMessage(WARNING, "no number appears after MemTotal tag");
+            return 0;
+        }
+
+        chptr = start;
+        while (*chptr && isdigit(*chptr)) {
+            total = (total * 10) + (*chptr - '0');
+            chptr++;
+        }
+    }
+
+    /*Because /proc/meminfo only gives us the MemTotal (total physical RAM minus
+    the kernel binary code), we need to round this up. Assuming every machine
+    has the total RAM MB number divisible by 128. */
+    total /= 1024;
+    total = (total / 128 + 1) * 128;
+    total *= 1024;
+
+    logMessage(INFO, "%d kB are available", total);
+
+    return total;
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4: */
diff --git a/isys/mem.h b/isys/mem.h
new file mode 100644
index 0000000..1a715d4
--- /dev/null
+++ b/isys/mem.h
@@ -0,0 +1,37 @@
+/*
+ * mem.h
+ *
+ * Copyright (C) 2010
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _MEM_H_
+#define _MEM_H_
+
+#if defined(__powerpc64__) || defined(__sparc__)
+  #define MIN_RAM                 1024*1024 // 1 GB
+  #define GUI_INSTALL_EXTRA_RAM   512*1024  // 512 MB
+#else
+  #define MIN_RAM                 256 * 1024 // 256 MB
+  #define GUI_INSTALL_EXTRA_RAM   128 * 1024 // 128 MB
+#endif
+#define URL_INSTALL_EXTRA_RAM   128 * 1024 // 128 MB
+#define MIN_GUI_RAM             MIN_RAM + GUI_INSTALL_EXTRA_RAM
+#define EARLY_SWAP_RAM          512 * 1024 // 512 MB
+
+int totalMemory(void);
+
+#endif /* _MEM_H_ */
diff --git a/iutil.py b/iutil.py
index 3daa737..b0f125a 100644
--- a/iutil.py
+++ b/iutil.py
@@ -455,17 +455,6 @@ def swapSuggestion(quiet=0):
 
     return (minswap, maxswap)
 
-def total_memory():
-    """
-    Calculate how much memory this machine has in kB. Because /proc/meminfo only
-    gives us the MemTotal (total physical RAM minus the kernel binary code), we
-    need to round this up. Assuming every machine has the total RAM MB number
-    divisible by 128
-    """
-    reported_mb = memInstalled() / 1024
-    mem = ((reported_mb / 128) + 1) * 128
-    return mem * 1024
-
 ## Create a directory path.  Don't fail if the directory already exists.
 # @param dir The directory path to create.
 def mkdirChain(dir):
diff --git a/loader/cdinstall.c b/loader/cdinstall.c
index 9d5cee1..a896406 100644
--- a/loader/cdinstall.c
+++ b/loader/cdinstall.c
@@ -59,6 +59,7 @@
 #include "../isys/imount.h"
 #include "../isys/isys.h"
 #include "../isys/log.h"
+#include "../isys/mem.h"
 
 /* boot flags */
 extern uint64_t flags;
diff --git a/loader/loader.c b/loader/loader.c
index 84fd116..fbbd13b 100644
--- a/loader/loader.c
+++ b/loader/loader.c
@@ -99,6 +99,7 @@
 #include "../isys/lang.h"
 #include "../isys/eddsupport.h"
 #include "../isys/log.h"
+#include "../isys/mem.h"
 
 /* maximum number of extra arguments that can be passed to the second stage */
 #define MAX_EXTRA_ARGS 128
diff --git a/loader/loadermisc.c b/loader/loadermisc.c
index 2e667f5..6a50438 100644
--- a/loader/loadermisc.c
+++ b/loader/loadermisc.c
@@ -93,65 +93,3 @@ 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;
-    }
-
-    close(fd);
-    buf[bytesRead] = '\0';
-
-    chptr = buf;
-    while (*chptr && !total) {
-        if (strncmp(chptr, "MemTotal:", 9)) {
-            chptr++;
-            continue;
-        }
-
-        start = ++chptr ;
-        while (*chptr && *chptr != '\n') chptr++;
-
-        *chptr = '\0';
-
-        while (!isdigit(*start) && *start) start++;
-        if (!*start) {
-            logMessage(WARNING, "no number appears after MemTotal tag");
-            return 0;
-        }
-
-        chptr = start;
-        while (*chptr && isdigit(*chptr)) {
-            total = (total * 10) + (*chptr - '0');
-            chptr++;
-        }
-    }
-
-    /*Because /proc/meminfo only gives us the MemTotal (total physical RAM minus
-    the kernel binary code), we need to round this up. Assuming every machine
-    has the total RAM MB number divisible by 128. */
-    total /= 1024;
-    total = (total / 128 + 1) * 128;
-    total *= 1024;
-
-    logMessage(INFO, "%d kB are available", total);
-
-    return total;
-}
diff --git a/loader/loadermisc.h b/loader/loadermisc.h
index 23ebf4a..a9032ec 100644
--- a/loader/loadermisc.h
+++ b/loader/loadermisc.h
@@ -28,6 +28,5 @@ 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);
 
 #endif
-- 
1.6.6

_______________________________________________
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