Signed-off-by: Eric B Munson <[EMAIL PROTECTED]>
---
 elflink.c               |   70 +++++++++++++++++++----------------------------
 hugeutils.c             |   21 ++++++++++++++
 libhugetlbfs_internal.h |    6 ++++
 3 files changed, 55 insertions(+), 42 deletions(-)

diff --git a/elflink.c b/elflink.c
index 63229f6..ee21c35 100644
--- a/elflink.c
+++ b/elflink.c
@@ -168,8 +168,6 @@ struct seg_layout {
 
 static struct seg_info htlb_seg_table[MAX_HTLB_SEGS];
 static int htlb_num_segs;
-static int minimal_copy = 1;
-static int sharing; /* =0 */
 static unsigned long force_remap; /* =0 */
 static long hpage_readonly_size, hpage_writable_size;
 
@@ -239,7 +237,6 @@ static void check_memsz()
  */
 static int find_or_create_share_path(long page_size)
 {
-       char *env;
        const char *base_path;
        struct stat sb;
        int ret;
@@ -248,22 +245,24 @@ static int find_or_create_share_path(long page_size)
        if (!page_size)
                return 0;
 
-       env = getenv("HUGETLB_SHARE_PATH");
-       if (env) {
+       if (__hugetlb_opts.share_path) {
                /* Given an explicit path */
-               if (hugetlbfs_test_path(env) != 1) {
+               if (hugetlbfs_test_path(__hugetlb_opts.share_path) != 1) {
                        ERROR("HUGETLB_SHARE_PATH %s is not on a hugetlbfs"
-                             " filesystem\n", env);
+                             " filesystem\n", __hugetlb_opts.share_path);
                        return -1;
                }
 
                /* Make sure the page size matches */
-               if (page_size != hugetlbfs_test_pagesize(env)) {
+               if (page_size !=
+                       hugetlbfs_test_pagesize(__hugetlb_opts.share_path)) {
                        ERROR("HUGETLB_SHARE_PATH %s is not valid for a %li "
-                             "kB page size\n", env, page_size / 1024);
+                             "kB page size\n", __hugetlb_opts.share_path,
+                               page_size / 1024);
                        return -1;
                }
-               assemble_path(share_readonly_path, "%s", env);
+               assemble_path(share_readonly_path, "%s",
+                               __hugetlb_opts.share_path);
                return 0;
        }
 
@@ -480,7 +479,7 @@ static void get_extracopy(struct seg_info *seg, const 
Elf_Phdr *phdr, int phnum)
        start = seg->vaddr + seg->filesz;
        if (seg->filesz == seg->memsz)
                return;
-       if (!minimal_copy)
+       if (!__hugetlb_opts.min_copy)
                goto bail2;
 
        /* Find dynamic program header */
@@ -1057,7 +1056,7 @@ static int obtain_prepared_file(struct seg_info 
*htlb_seg_info)
        long hpage_size = htlb_seg_info->page_size;
 
        /* Share only read-only segments */
-       if (sharing && !(htlb_seg_info->prot & PROT_WRITE)) {
+       if (__hugetlb_opts.sharing && !(htlb_seg_info->prot & PROT_WRITE)) {
                /* first, try to share */
                ret = find_or_prepare_shared_file(htlb_seg_info);
                if (ret == 0)
@@ -1184,32 +1183,29 @@ static int set_hpage_sizes(const char *env)
 
 static int check_env(void)
 {
-       char *env, *env2;
        extern Elf_Ehdr __executable_start __attribute__((weak));
 
-       env = getenv("HUGETLB_ELFMAP");
-       if (env && (strcasecmp(env, "no") == 0)) {
+       if (__hugetlb_opts.elfmap &&
+               (strcasecmp(__hugetlb_opts.elfmap, "no") == 0)) {
                DEBUG("HUGETLB_ELFMAP=%s, not attempting to remap program "
-                     "segments\n", env);
+                     "segments\n", __hugetlb_opts.elfmap);
                return -1;
        }
-       if (env && set_hpage_sizes(env)) {
+       if (__hugetlb_opts.elfmap && set_hpage_sizes(__hugetlb_opts.elfmap)) {
                ERROR("Cannot set elfmap page sizes: %s", strerror(errno));
                return -1;
        }
 
-       env = getenv("LD_PRELOAD");
-       if (env && strstr(env, "libhugetlbfs")) {
-               env2 = getenv("HUGETLB_FORCE_ELFMAP");
-               if (env2 && (strcasecmp(env2, "yes") == 0)) {
+       if (__hugetlb_opts.ld_preload &&
+               strstr(__hugetlb_opts.ld_preload, "libhugetlbfs")) {
+               if (__hugetlb_opts.force_elfmap) {
                        force_remap = 1;
-                       DEBUG("HUGETLB_FORCE_ELFMAP=%s, "
+                       DEBUG("HUGETLB_FORCE_ELFMAP=yes, "
                                        "enabling partial segment "
                                        "remapping for non-relinked "
-                                       "binaries\n",
-                                       env2);
+                                       "binaries\n");
                        DEBUG("Disabling filesz copy optimization\n");
-                       minimal_copy = 0;
+                       __hugetlb_opts.min_copy = 0;
                } else {
                        if (&__executable_start) {
                                ERROR("LD_PRELOAD is incompatible with segment 
remapping\n");
@@ -1219,28 +1215,18 @@ static int check_env(void)
                }
        }
 
-       env = getenv("HUGETLB_MINIMAL_COPY");
-       if (minimal_copy && env && (strcasecmp(env, "no") == 0)) {
-               DEBUG("HUGETLB_MINIMAL_COPY=%s, disabling filesz copy "
-                       "optimization\n", env);
-               minimal_copy = 0;
-       }
-
-       env = getenv("HUGETLB_SHARE");
-       if (env)
-               sharing = atoi(env);
-       if (sharing == 2) {
+       if (__hugetlb_opts.sharing == 2) {
                ERROR("HUGETLB_SHARE=%d, however sharing of writable\n"
                        "segments has been deprecated and is now disabled\n",
-                       sharing);
-               sharing = 0;
+                       __hugetlb_opts.sharing);
+               __hugetlb_opts.sharing = 0;
        } else {
-               DEBUG("HUGETLB_SHARE=%d, sharing ", sharing);
-               if (sharing == 1) {
+               DEBUG("HUGETLB_SHARE=%d, sharing ", __hugetlb_opts.sharing);
+               if (__hugetlb_opts.sharing == 1) {
                        DEBUG_CONT("enabled for only read-only segments\n");
                } else {
                        DEBUG_CONT("disabled\n");
-                       sharing = 0;
+                       __hugetlb_opts.sharing = 0;
                }
        }
 
@@ -1279,7 +1265,7 @@ void hugetlbfs_setup_elflink(void)
        DEBUG("libhugetlbfs version: %s\n", VERSION);
 
        /* Do we need to find a share directory */
-       if (sharing) {
+       if (__hugetlb_opts.sharing) {
                /*
                 * If HUGETLB_ELFMAP is undefined but a shareable segment has
                 * PF_LINUX_HUGETLB set, segment remapping will occur using the
diff --git a/hugeutils.c b/hugeutils.c
index 04c955b..b4e8c2b 100644
--- a/hugeutils.c
+++ b/hugeutils.c
@@ -237,6 +237,8 @@ void hugetlbfs_setup_env()
 {
        char *env;
 
+       __hugetlb_opts.min_copy = 1;
+
        env = getenv("HUGETLB_VERBOSE");
        if (env)
                __hugetlbfs_verbose = atoi(env);
@@ -248,6 +250,25 @@ void hugetlbfs_setup_env()
        env = getenv("HUGETLB_NO_PREFAULT");
        if (env)
                __hugetlbfs_prefault = 0;
+
+       __hugetlb_opts.share_path = getenv("HUGETLB_SHARE_PATH");
+       __hugetlb_opts.elfmap = getenv("HUGETLB_ELFMAP");
+       __hugetlb_opts.ld_preload = getenv("LD_PRELOAD");
+
+       env = getenv("HUGETLB_FORCE_ELFMAP");
+       if (env && (strcasecmp(env, "yes") == 0))
+               __hugetlb_opts.force_elfmap = 1;
+
+       env = getenv("HUGETLB_MINIMAL_COPY");
+       if (__hugetlb_opts.min_copy && env && (strcasecmp(env, "no") == 0)) {
+               DEBUG("HUGETLB_MINIMAL_COPY=%s, disabling filesz copy "
+                       "optimization\n", env);
+               __hugetlb_opts.min_copy = 0;
+       }
+
+       env = getenv("HUGETLB_SHARE");
+       if (env)
+               __hugetlb_opts.sharing = atoi(env);
 }
 
 /*
diff --git a/libhugetlbfs_internal.h b/libhugetlbfs_internal.h
index c6774da..2ad0163 100644
--- a/libhugetlbfs_internal.h
+++ b/libhugetlbfs_internal.h
@@ -56,6 +56,12 @@
 #endif
 
 struct libhugeopts_t {
+       int             min_copy;
+       int             sharing;
+       unsigned long   force_elfmap;
+       char            *ld_preload;
+       char            *elfmap;
+       char            *share_path;
 };
 
 /*
-- 
1.6.0.3


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Libhugetlbfs-devel mailing list
Libhugetlbfs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to