Whamcloud - gitweb
LU-3642 seq: make seq_proc_write_common() safer 23/7123/3
authorAndreas Dilger <andreas.dilger@intel.com>
Thu, 25 Jul 2013 22:27:41 +0000 (16:27 -0600)
committerOleg Drokin <oleg.drokin@intel.com>
Thu, 26 Sep 2013 04:42:23 +0000 (04:42 +0000)
Don't allow seq_proc_write_common() to specify arbitrary ranges,
since this can permanently corrupt the sequence controller and/or
sequnece server.  That would allow duplicate FID allocation, or
possibly prevent any new files to be created or servers to be added
to the filesystem.

Instead, limit the sequence range that can be written via /proc to
a subset of the sequence range currently allocated to that node.
Add the "clear" keyword to allow dropping the entire local sequence
and force a new one to be fetched from the sequence server.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Change-Id: I89da0223a52ce8bec787b1d5099402c84274291a
Reviewed-on: http://review.whamcloud.com/7123
Reviewed-by: Jinshan Xiong <jinshan.xiong@intel.com>
Reviewed-by: Alex Zhuravlev <alexey.zhuravlev@intel.com>
Tested-by: Hudson
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/fid/lproc_fid.c
lustre/include/lustre/lustre_idl.h

index 7d70870..de7a5cb 100644 (file)
 #include <md_object.h>
 
 #ifdef LPROCFS
-/*
- * Note: this function is only used for testing, it is no safe for production
- * use.
+/**
+ * Reduce the SEQ range allocated to a node to a strict subset of the range
+ * currently-allocated SEQ range.  If the specified range is "clear", then
+ * drop all allocated sequences and request a new one from the master.
+ *
+ * Note: this function should only be used for testing, it is not necessarily
+ * safe for production use.
  */
-static int
-seq_proc_write_common(struct file *file, const char *buffer,
-                      unsigned long count, void *data,
-                      struct lu_seq_range *range)
+static int seq_proc_write_common(struct file *file, const char *buffer,
+                                unsigned long count, void *data,
+                                struct lu_seq_range *range)
 {
-       struct lu_seq_range tmp;
+       struct lu_seq_range tmp = { 0, };
        int rc;
        ENTRY;
 
@@ -73,24 +76,25 @@ seq_proc_write_common(struct file *file, const char *buffer,
                RETURN(0);
        }
 
-        rc = sscanf(buffer, "[%llx - %llx]\n",
-                    (long long unsigned *)&tmp.lsr_start,
-                    (long long unsigned *)&tmp.lsr_end);
-       if (rc != 2 || !range_is_sane(&tmp) || range_is_zero(&tmp))
+       /* of the form "[0x0000000240000400 - 0x000000028000400]" */
+       rc = sscanf(buffer, "[%llx - %llx]\n",
+                   (long long unsigned *)&tmp.lsr_start,
+                   (long long unsigned *)&tmp.lsr_end);
+       if (!range_is_sane(&tmp) || range_is_zero(&tmp) ||
+           tmp.lsr_start < range->lsr_start || tmp.lsr_end > range->lsr_end)
                RETURN(-EINVAL);
        *range = tmp;
-        RETURN(0);
+       RETURN(0);
 }
 
-static int
-seq_proc_read_common(char *page, char **start, off_t off,
-                     int count, int *eof, void *data,
-                     struct lu_seq_range *range)
+static int seq_proc_read_common(char *page, char **start, off_t off,
+                               int count, int *eof, void *data,
+                               struct lu_seq_range *range)
 {
        int rc;
        ENTRY;
 
-        *eof = 1;
+       *eof = 1;
        rc = snprintf(page, count, "["LPX64" - "LPX64"]:%x:%s\n",
                        PRANGE(range));
        RETURN(rc);
index 45fe409..9271c00 100644 (file)
@@ -264,7 +264,7 @@ static inline __u64 range_space(const struct lu_seq_range *range)
 
 static inline void range_init(struct lu_seq_range *range)
 {
-        range->lsr_start = range->lsr_end = range->lsr_index = 0;
+       memset(range, 0, sizeof(*range));
 }
 
 /**