When hugeadm creates mount points currently the pagesize is
used in bytes.  This is not very human readable as page sizes
grow.  This patch changes the mount point creation to use
points labeled in a more readable fashion.  For instance
2MB instead of 2097152.

Signed-off-by: Eric B Munson <[email protected]>
---
 hugeadm.c |   41 +++++++++++++++++++++++++++++++++--------
 1 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/hugeadm.c b/hugeadm.c
index fe5f89f..c0f1fa1 100644
--- a/hugeadm.c
+++ b/hugeadm.c
@@ -61,6 +61,10 @@ extern char *optarg;
 #define OPTION(opts, text)     fprintf(stderr, " %-25s  %s\n", opts, text)
 #define CONT(text)             fprintf(stderr, " %-25s  %s\n", "", text)
 
+#define KB 1024
+#define MB (KB*1024)
+#define GB (MB*1024)
+
 #define MOUNT_DIR "/var/lib/hugetlbfs"
 #define OPT_MAX 4096
 
@@ -553,6 +557,26 @@ int mount_dir(char *path, char *options, mode_t mode, 
uid_t uid, gid_t gid)
        return 0;
 }
 
+int scale_pagesize(char *units, int size, unsigned long pagesize)
+{
+       int ret;
+
+       ret = pagesize / GB;
+       if (ret != 0) {
+               snprintf(units, size, "GB");
+               return ret;
+       }
+
+       ret = pagesize / MB;
+       if (ret != 0) {
+               snprintf(units, size, "MB");
+               return ret;
+       }
+
+       ret = pagesize / KB;
+       snprintf(units, size, "KB");
+       return ret;
+}
 
 void create_mounts(char *user, char *group, char *base, mode_t mode)
 {
@@ -560,7 +584,8 @@ void create_mounts(char *user, char *group, char *base, 
mode_t mode)
        char path[PATH_MAX];
        char options[OPT_MAX];
        char limits[OPT_MAX];
-       int cnt, pos;
+       char units[4];
+       int cnt, pos, scaled;
        struct passwd *pwd;
        struct group *grp;
        uid_t uid = 0;
@@ -599,14 +624,14 @@ void create_mounts(char *user, char *group, char *base, 
mode_t mode)
 
        for (pos=0; cnt--; pos++) {
                if (user)
-                       snprintf(path, PATH_MAX, "%s/%s/pagesize-%ld",
-                               base, user, pools[pos].pagesize);
+                       snprintf(path, PATH_MAX, "%s/%s", base, user);
                else if (group)
-                       snprintf(path, PATH_MAX, "%s/%s/pagesize-%ld",
-                               base, group, pools[pos].pagesize);
-               else
-                       snprintf(path, PATH_MAX, "%s/pagesize-%ld",
-                               base, pools[pos].pagesize);
+                       snprintf(path, PATH_MAX, "%s/%s", base, group);
+
+               scaled = scale_pagesize(units, 4, pools[pos].pagesize);
+
+               snprintf(path, PATH_MAX, "%s/pagesize-%d%s",
+                               path, scaled, units);
 
                snprintf(options, OPT_MAX, "pagesize=%ld",
                                pools[pos].pagesize);
-- 
1.7.1


------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Libhugetlbfs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to