Fix fs bypassthreshold to accept a size of -1 to disable
authorPhillip Moore <w.phillip.moore@gmail.com>
Tue, 19 Oct 2010 16:17:20 +0000 (12:17 -0400)
committerDerrick Brashear <shadow@dementia.org>
Fri, 29 Oct 2010 19:17:20 +0000 (12:17 -0700)
The fs bypassthreshold command assumes a value of -1 means the feature
is disabled, but the CLI refused to accept this argument, since it is
not strictly a digit (according ti isdigit()).  This patch accepts the
string -1, and makes it possible to both enable AND disable this
feature.

Change-Id: I87720b2dcfc4e9ee9f322c4841836b74440ac442
Reviewed-on: http://gerrit.openafs.org/3009
Reviewed-by: Matt Benjamin <matt@linuxbox.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>

src/venus/fs.c

index 7ce9fc4..a8c1712 100644 (file)
@@ -1358,22 +1358,27 @@ BypassThresholdCmd(struct cmd_syndesc *as, void *arock)
 
        tp = as->parms[0].items->data;
        len = strlen(tp);
-       digit = 1;
-       for(ix = 0; ix < len; ++ix) {
-           if(!isdigit(tp[0])) {
-               digit = 0;
-               break;
-           }
-       }
-       if (digit == 0) {
-           fprintf(stderr, "fs bypassthreshold -size: %s must be an undecorated digit string.\n", tp);
-           return EINVAL;
-       }
-       threshold_i = atoi(tp);
-       if(ix > 9 && threshold_i < 2147483647)
-           threshold_i = 2147483647;
-       blob.in = (char *) &threshold_i;
-       blob.in_size = sizeof(threshold_i);
+
+        if (!strcmp(tp,"-1")) {
+            threshold_i = -1;
+        } else {
+            digit = 1;
+            for(ix = 0; ix < len; ++ix) {
+                if(!isdigit(tp[0])) {
+                    digit = 0;
+                    break;
+                }
+            }
+            if (digit == 0) {
+                fprintf(stderr, "fs bypassthreshold -size: %s must be an integer between -1 and 2^31\n", tp);
+                return EINVAL;
+            }
+            threshold_i = atoi(tp);
+            if(ix > 9 && threshold_i < 2147483647)
+                threshold_i = 2147483647;
+        }
+        blob.in = (char *) &threshold_i;
+        blob.in_size = sizeof(threshold_i);
     } else {
        blob.in = NULL;
        blob.in_size = 0;