Whamcloud - gitweb
LU-7334 lprocfs: Allow a new line before null terminator 53/20353/4
authorGiuseppe Di Natale <dinatale2@llnl.gov>
Fri, 20 May 2016 15:01:35 +0000 (08:01 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Tue, 14 Jun 2016 03:55:01 +0000 (03:55 +0000)
Kernel string parsing functions support a single new line
before the null terminator of a string. Our numeric string
parsing should do the same. This allows strings to be
echo'ed directly into proc files.

Signed-off-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Change-Id: Ia9d36b4f4f6849547391115d31be34a14215fc2a
Reviewed-on: http://review.whamcloud.com/20353
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Tested-by: Jenkins
Reviewed-by: Frank Zago <fzago@cray.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
lustre/obdclass/lprocfs_status.c

index fce0bb1..c68bb31 100644 (file)
@@ -1708,6 +1708,17 @@ static int preprocess_numeric_str(char *buffer, __u64 *mult, __u64 def_mult,
        start = buffer;
 
        while (*buffer) {
+               /* allow for a single new line before the null terminator */
+               if (*buffer == '\n') {
+                       *buffer = '\0';
+                       buffer++;
+
+                       if (*buffer)
+                               return -EINVAL;
+
+                       break;
+               }
+
                /* any chars after our unit indicates a malformed string */
                if (hit_unit)
                        return -EINVAL;