>From 2f7f407e8eb4b529e964e1226574caecf4ea5820 Mon Sep 17 00:00:00 2001<br />From: Paul Rawson &lt;plrca2@gmail.com&gt;<br />Date: Fri, 17 Apr 2009 00:29:48 -0700<br />Subject: [PATCH] Allow alu&#39;s min-free-disk to be specified as a percent or bytesize<br /><br />---<br /> libglusterfs/src/xlator.c |   52 +++++++++++++++<br /> libglusterfs/src/xlator.h |    8 ++-<br /> scheduler/alu/src/alu.c   |  151 +++++++++------------------------------------<br /> 3 files changed, 86 insertions(+), 125 deletions(-)<br /><br />diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c<br />index 6af2c8e..5b5067a 100644<br />--- a/libglusterfs/src/xlator.c<br />+++ b/libglusterfs/src/xlator.c<br />@@ -431,6 +431,58 @@ _volume_option_value_validate (xlator_t *xl,<br />                 ret = 0;<br />         }<br />         break;<br />+        case GF_OPTION_TYPE_PERCENTORSIZET:<br />+        {<br />+                uint32_t percent = 0;<br />+                uint32_t input_size = 0;<br />+                <br />+                /* Check if the value is valid percentage */<br />+                if (gf_string2percent (pair-&gt;value-&gt;data, <br />+                                       &percent) == 0) {<br />+                        if ((percent &lt; 0) || (percent &gt; 100)) {<br />+                                gf_log (xl-&gt;name, GF_LOG_ERROR,<br />+                                &quot;&#39;%d&#39; in &#39;option %s %s&#39; is out of &quot;<br />+                                &quot;range [0 - 100]&quot;,<br />+                                percent, pair-&gt;key, <br />+                                pair-&gt;value-&gt;data);<br />+                        }<br />+                        ret = 0;<br />+                        goto out;<br />+                } else {<br />+                        /* Check the range */<br />+                        if (gf_string2bytesize (pair-&gt;value-&gt;data,<br />+                                                &input_size) == 0) {<br />+<br />+                                if ((opt-&gt;min == 0) && (opt-&gt;max == 0)) {<br />+                                        gf_log (xl-&gt;name, GF_LOG_DEBUG,<br />+                                                &quot;no range check required for &quot;<br />+                                                &quot;&#39;option %s %s&#39;&quot;,<br />+                                                pair-&gt;key, pair-&gt;value-&gt;data);<br />+                                        ret = 0;<br />+                                        break;<br />+                                }<br />+                                if ((input_size &lt; opt-&gt;min) ||<br />+                                    (input_size &gt; opt-&gt;max)) {<br />+                                        gf_log (xl-&gt;name, GF_LOG_ERROR,<br />+                                                &quot;&#39;%&quot;PRId64&quot;&#39; in &#39;option %s %s&#39; is &quot;<br />+                                                &quot;out of range [%&quot;PRId64&quot; - %&quot;PRId64&quot;]&quot;,<br />+                                                input_size, pair-&gt;key,<br />+                                                pair-&gt;value-&gt;data,<br />+                                                opt-&gt;min, opt-&gt;max);<br />+                                }<br />+                                ret = 0;<br />+                                goto out;<br />+                        } else {<br />+                                // It&#39;s not a percent or size<br />+                                gf_log (xl-&gt;name, GF_LOG_ERROR,<br />+                                &quot;invalid number format \&quot;%s\&quot; &quot;<br />+                                &quot;in \&quot;option %s\&quot;&quot;,<br />+                                pair-&gt;value-&gt;data, pair-&gt;key);<br />+                        <br />+                        }<br />+                }<br />+        }<br />+        break;<br />         case GF_OPTION_TYPE_TIME:<br />         {<br />                 uint32_t input_time = 0;<br />diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h<br />index 654e334..cf8d221 100644<br />--- a/libglusterfs/src/xlator.h<br />+++ b/libglusterfs/src/xlator.h<br />@@ -72,9 +72,10 @@ struct _loc {<br /> <br /> struct xlator_stats {<br />         uint64_t nr_files;         /* Number of files open via this xlator */<br />-        uint64_t free_disk;        /* Mega bytes */<br />-        uint64_t total_disk_size;  /* Mega Bytes */<br />-        uint64_t disk_usage;       /* Mega bytes */<br />+        uint64_t free_disk;        /* Bytes or percent */<br />+        uint64_t total_disk_size;  /* Bytes or percent */<br />+        uint64_t disk_usage;       /* Bytes or percent */<br />+        char     disk_unit;        /* &#39;p&#39; or &#39;b&#39; */<br />         uint64_t disk_speed;       /* MHz or Mbps */<br />         uint64_t nr_clients;       /* Number of client nodes */<br />         uint64_t write_usage;<br />@@ -807,6 +808,7 @@ typedef enum {<br />           GF_OPTION_TYPE_INT,<br />           GF_OPTION_TYPE_SIZET,<br />           GF_OPTION_TYPE_PERCENT,<br />+        GF_OPTION_TYPE_PERCENTORSIZET,<br />           GF_OPTION_TYPE_BOOL,<br />           GF_OPTION_TYPE_XLATOR,<br />           GF_OPTION_TYPE_PATH,<br />diff --git a/scheduler/alu/src/alu.c b/scheduler/alu/src/alu.c<br />index 571d06e..8939531 100644<br />--- a/scheduler/alu/src/alu.c<br />+++ b/scheduler/alu/src/alu.c<br />@@ -54,7 +54,11 @@<br /> static int64_t <br /> get_stats_disk_usage (struct xlator_stats *this)<br /> {<br />-        return this-&gt;disk_usage;<br />+        if (this-&gt;disk_unit == &#39;p&#39;) {<br />+                return (this-&gt;disk_usage * 100) / this-&gt;total_disk_size;<br />+        } else {<br />+                return this-&gt;disk_usage;<br />+        }<br /> }<br /> <br /> static int64_t <br />@@ -87,9 +91,13 @@ get_stats_file_usage (struct xlator_stats *this)<br /> static int64_t <br /> get_stats_free_disk (struct xlator_stats *this)<br /> {<br />-        if (this-&gt;total_disk_size &gt; 0)<br />-                return (this-&gt;free_disk * 100) / this-&gt;total_disk_size;<br />-        return 0;<br />+        if (this-&gt;total_disk_size &gt; 0) {<br />+                if (this-&gt;disk_unit == &#39;p&#39;) {<br />+                        return (this-&gt;free_disk * 100) / this-&gt;total_disk_size;<br />+                } else {<br />+                        return this-&gt;free_disk;<br />+                }<br />+        }<br /> }<br /> <br /> static int64_t <br />@@ -154,15 +162,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)<br />                                 dict_get (xl-&gt;options, <br />                                           &quot;scheduler.alu.disk-usage.entry-threshold&quot;);<br />                         if (entry_fn) {<br />-                                if (gf_string2bytesize (entry_fn-&gt;data, <br />-                                                        &alu_sched-&gt;entry_limit.disk_usage) != 0) {<br />-                                        gf_log (xl-&gt;name, GF_LOG_ERROR, <br />-                                                &quot;invalid number format \&quot;%s\&quot; &quot;<br />-                                                &quot;of \&quot;option scheduler.alu.&quot;<br />-                                                &quot;disk-usage.entry-threshold\&quot;&quot;,<br />-                                                entry_fn-&gt;data);<br />-                                        return -1;<br />-                                }<br />+                                gf_string2bytesize (entry_fn-&gt;data, &alu_sched-&gt;entry_limit.disk_usage);<br />                         } else {<br />                                 alu_sched-&gt;entry_limit.disk_usage = ALU_DISK_USAGE_ENTRY_THRESHOLD_DEFAULT;<br />                         }<br />@@ -170,14 +170,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)<br />                         exit_fn = dict_get (xl-&gt;options, <br />                                             &quot;scheduler.alu.disk-usage.exit-threshold&quot;);<br />                         if (exit_fn) {<br />-                                if (gf_string2bytesize (exit_fn-&gt;data, &alu_sched-&gt;exit_limit.disk_usage) != 0)        {<br />-                                        gf_log (xl-&gt;name, GF_LOG_ERROR, <br />-                                                &quot;invalid number format \&quot;%s\&quot; &quot;<br />-                                                &quot;of \&quot;option scheduler.alu.&quot;<br />-                                                &quot;disk-usage.exit-threshold\&quot;&quot;, <br />-                                                exit_fn-&gt;data);<br />-                                        return -1;<br />-                                }<br />+                                gf_string2bytesize (exit_fn-&gt;data, &alu_sched-&gt;exit_limit.disk_usage);<br />                         } else {<br />                                 alu_sched-&gt;exit_limit.disk_usage = ALU_DISK_USAGE_EXIT_THRESHOLD_DEFAULT;<br />                         }<br />@@ -206,15 +199,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)<br />                         entry_fn = dict_get (xl-&gt;options, <br />                                              &quot;scheduler.alu.write-usage.entry-threshold&quot;);<br />                         if (entry_fn) {<br />-                                if (gf_string2bytesize (entry_fn-&gt;data, <br />-                                                        &alu_sched-&gt;entry_limit.write_usage) != 0) {<br />-                                        gf_log (xl-&gt;name, GF_LOG_ERROR, <br />-                                                &quot;invalid number format \&quot;%s\&quot; &quot;<br />-                                                &quot;of option scheduler.alu.&quot;<br />-                                                &quot;write-usage.entry-threshold&quot;, <br />-                                                entry_fn-&gt;data);<br />-                                        return -1;<br />-                                }<br />+                                gf_string2bytesize (entry_fn-&gt;data, &alu_sched-&gt;entry_limit.write_usage);<br />                         } else {<br />                                 alu_sched-&gt;entry_limit.write_usage = ALU_WRITE_USAGE_ENTRY_THRESHOLD_DEFAULT;<br />                         }<br />@@ -222,15 +207,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)<br />                         exit_fn = dict_get (xl-&gt;options, <br />                                             &quot;scheduler.alu.write-usage.exit-threshold&quot;);<br />                         if (exit_fn) {<br />-                                if (gf_string2bytesize (exit_fn-&gt;data, <br />-                                                        &alu_sched-&gt;exit_limit.write_usage) != 0) {<br />-                                        gf_log (xl-&gt;name, GF_LOG_ERROR, <br />-                                                &quot;invalid number format \&quot;%s\&quot;&quot;<br />-                                                &quot; of \&quot;option scheduler.alu.&quot;<br />-                                                &quot;write-usage.exit-threshold\&quot;&quot;,<br />-                                                exit_fn-&gt;data);<br />-                                        return -1;<br />-                                }<br />+                                gf_string2bytesize (exit_fn-&gt;data, &alu_sched-&gt;exit_limit.write_usage);<br />                         } else {<br />                                 alu_sched-&gt;exit_limit.write_usage = ALU_WRITE_USAGE_EXIT_THRESHOLD_DEFAULT;<br />                         }<br />@@ -259,16 +236,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)<br />                         entry_fn = dict_get (xl-&gt;options, <br />                                              &quot;scheduler.alu.read-usage.entry-threshold&quot;);<br />                         if (entry_fn) {<br />-                                if (gf_string2bytesize (entry_fn-&gt;data, <br />-                                                        &alu_sched-&gt;entry_limit.read_usage) != 0) {<br />-                                        gf_log (xl-&gt;name, <br />-                                                GF_LOG_ERROR, <br />-                                                &quot;invalid number format \&quot;%s\&quot; &quot;<br />-                                                &quot;of \&quot;option scheduler.alu.&quot;<br />-                                                &quot;read-usage.entry-threshold\&quot;&quot;,<br />-                                                entry_fn-&gt;data);<br />-                                        return -1;<br />-                                }<br />+                                gf_string2bytesize (entry_fn-&gt;data, &alu_sched-&gt;entry_limit.read_usage);<br />                         } else {<br />                                 alu_sched-&gt;entry_limit.read_usage = ALU_READ_USAGE_ENTRY_THRESHOLD_DEFAULT;<br />                         }<br />@@ -277,16 +245,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)<br />                                             &quot;scheduler.alu.read-usage.exit-threshold&quot;);<br />                         if (exit_fn)<br />                         {<br />-                                if (gf_string2bytesize (exit_fn-&gt;data, <br />-                                                        &alu_sched-&gt;exit_limit.read_usage) != 0)<br />-                                {<br />-                                        gf_log (&quot;alu&quot;, GF_LOG_ERROR, <br />-                                                &quot;invalid number format \&quot;%s\&quot; &quot;<br />-                                                &quot;of \&quot;option scheduler.alu.&quot;<br />-                                                &quot;read-usage.exit-threshold\&quot;&quot;, <br />-                                                exit_fn-&gt;data);<br />-                                        return -1;<br />-                                }<br />+                                gf_string2bytesize (exit_fn-&gt;data, &alu_sched-&gt;exit_limit.read_usage);<br />                         }<br />                         else<br />                         {<br />@@ -318,16 +277,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)<br />                         entry_fn = dict_get (xl-&gt;options, <br />                                              &quot;scheduler.alu.open-files-usage.entry-threshold&quot;);<br />                         if (entry_fn) {<br />-                                if (gf_string2uint64 (entry_fn-&gt;data, <br />-                                                      &alu_sched-&gt;entry_limit.nr_files) != 0)<br />-                                {<br />-                                        gf_log (&quot;alu&quot;, GF_LOG_ERROR, <br />-                                                &quot;invalid number format \&quot;%s\&quot; &quot;<br />-                                                &quot;of \&quot;option scheduler.alu.&quot;<br />-                                                &quot;open-files-usage.entry-&quot;<br />-                                                &quot;threshold\&quot;&quot;, entry_fn-&gt;data);<br />-                                        return -1;<br />-                                }<br />+                                gf_string2uint64 (entry_fn-&gt;data, &alu_sched-&gt;entry_limit.nr_files);<br />                         }<br />                         else<br />                         {<br />@@ -338,16 +288,7 @@ alu_parse_options (xlator_t *xl, struct alu_sched *alu_sched)<br />                                             &quot;scheduler.alu.open-files-usage.exit-threshold&quot;);<br />                         if (exit_fn)<br />                         {<br />-                                if (gf_string2uint64 (exit_fn-&gt;data, <br />-                                                      &alu_sched-&gt;exit_limit.nr_files) != 0)<br />-                                {<br />-                                        gf_log (&quot;alu&quot;, GF_LOG_ERROR, <br />-                                                &quot;invalid number format \&quot;%s\&quot; &quot;<br />-                                                &quot;of \&quot;option scheduler.alu.&quot;<br />-                                                &quot;open-files-usage.exit-&quot;<br />-                                                &quot;threshold\&quot;&quot;, exit_fn-&gt;data);<br />-                                        return -1;<br />-                                }<br />+                                gf_string2uint64 (exit_fn-&gt;data, &alu_sched-&gt;exit_limit.nr_files);<br />                         }<br />                         else<br />                         {<br />@@ -443,24 +384,14 @@ alu_init (xlator_t *xl)<br />                 _limit_fn-&gt;next = tmp_limits;<br />                 alu_sched-&gt;limits_fn = _limit_fn;<br />                 <br />-                if (gf_string2percent (limits-&gt;data, <br />-                                       &min_free_disk) != 0) {<br />-                        gf_log (&quot;alu&quot;, GF_LOG_ERROR, <br />-                                &quot;invalid number format \&quot;%s\&quot; &quot;<br />-                                &quot;of \&quot;option scheduler.limits.&quot;<br />-                                &quot;min-free-disk\&quot;&quot;, limits-&gt;data);<br />-                        return -1;<br />+                if (gf_string2percent (limits-&gt;data, &min_free_disk) == 0) {<br />+                        alu_sched-&gt;spec_limit.disk_unit = &#39;p&#39;;<br />+                } else {<br />+                        alu_sched-&gt;spec_limit.disk_unit = &#39;b&#39;;<br />                 }<br />+<br />                 alu_sched-&gt;spec_limit.free_disk = min_free_disk;<br />                 <br />-                if (alu_sched-&gt;spec_limit.free_disk &gt;= 100) {<br />-                        gf_log (&quot;alu&quot;, GF_LOG_ERROR,<br />-                                &quot;check the \&quot;option scheduler.&quot;<br />-                                &quot;limits.min-free-disk\&quot;, it should &quot;<br />-                                &quot;be percentage value&quot;);<br />-                        return -1;<br />-                }<br />-                alu_sched-&gt;spec_limit.total_disk_size = ALU_LIMITS_TOTAL_DISK_SIZE_DEFAULT; /* Its in % */<br />                 gf_log (&quot;alu&quot;, GF_LOG_DEBUG,<br />                         &quot;alu.limit.min-disk-free = %&quot;PRId64&quot;&quot;, <br />                         _limit_fn-&gt;cur_value (&(alu_sched-&gt;spec_limit)));<br />@@ -477,16 +408,7 @@ alu_init (xlator_t *xl)<br />                 tmp_limits = alu_sched-&gt;limits_fn ;<br />                 _limit_fn-&gt;next = tmp_limits;<br />                 alu_sched-&gt;limits_fn = _limit_fn;<br />-                if (gf_string2uint64_base10 (limits-&gt;data, <br />-                                             &alu_sched-&gt;spec_limit.nr_files) != 0)<br />-                {<br />-                        gf_log (&quot;alu&quot;, GF_LOG_ERROR, <br />-                                &quot;invalid number format &#39;%s&#39; of option &quot;<br />-                                &quot;scheduler.limits.max-open-files&quot;, <br />-                                limits-&gt;data);<br />-                        return -1;<br />-                }<br />-                <br />+                gf_string2uint64_base10 (limits-&gt;data, &alu_sched-&gt;spec_limit.nr_files);<br />                 gf_log (&quot;alu&quot;, GF_LOG_DEBUG,<br />                         &quot;alu_init: limit.max-open-files = %&quot;PRId64&quot;&quot;,<br />                         _limit_fn-&gt;cur_value (&(alu_sched-&gt;spec_limit)));<br />@@ -497,14 +419,7 @@ alu_init (xlator_t *xl)<br />         limits = dict_get (xl-&gt;options, <br />                            &quot;scheduler.refresh-interval&quot;);<br />         if (limits) {<br />-                if (gf_string2time (limits-&gt;data, <br />-                                    &alu_sched-&gt;refresh_interval) != 0)        {<br />-                        gf_log (&quot;alu&quot;, GF_LOG_ERROR, <br />-                                &quot;invalid number format \&quot;%s\&quot; of &quot;<br />-                                &quot;option scheduler.refresh-interval&quot;, <br />-                                limits-&gt;data);<br />-                        return -1;<br />-                }<br />+                gf_string2time (limits-&gt;data, &alu_sched-&gt;refresh_interval);<br />         } else {<br />                 alu_sched-&gt;refresh_interval = ALU_REFRESH_INTERVAL_DEFAULT;<br />         }<br />@@ -514,15 +429,7 @@ alu_init (xlator_t *xl)<br />         limits = dict_get (xl-&gt;options, <br />                            &quot;scheduler.alu.stat-refresh.num-file-create&quot;);<br />         if (limits) {<br />-                if (gf_string2uint32 (limits-&gt;data, <br />-                                      &alu_sched-&gt;refresh_create_count) != 0)<br />-                {<br />-                        gf_log (&quot;alu&quot;, GF_LOG_ERROR, <br />-                                &quot;invalid number format \&quot;%s\&quot; of \&quot;option &quot;<br />-                                &quot;alu.stat-refresh.num-file-create\&quot;&quot;, <br />-                                limits-&gt;data);<br />-                        return -1;<br />-                }<br />+                gf_string2uint32 (limits-&gt;data, &alu_sched-&gt;refresh_create_count);<br />         } else {<br />                 alu_sched-&gt;refresh_create_count = ALU_REFRESH_CREATE_COUNT_DEFAULT;<br />         }<br />@@ -983,7 +890,7 @@ struct volume_options options[] = {<br />         },<br />         { .key   = { &quot;scheduler.limits.min-free-disk&quot;, <br />                      &quot;alu.limits.min-free-disk&quot; },  <br />-          .type  = GF_OPTION_TYPE_PERCENT<br />+          .type  = GF_OPTION_TYPE_PERCENTORSIZET<br />         },<br />         { .key   = { &quot;scheduler.alu.stat-refresh.num-file-create&quot;<br />                      &quot;alu.stat-refresh.num-file-create&quot;},  <br />-- <br />1.6.0.6