Whamcloud - gitweb
LU-15059 nrs: do not overwrite "cmd" in nrs_tbf_rule 42/45142/4
authorEtienne AUJAMES <etienne.aujames@cea.fr>
Wed, 6 Oct 2021 20:11:17 +0000 (22:11 +0200)
committerOleg Drokin <green@whamcloud.com>
Tue, 30 Nov 2021 03:47:51 +0000 (03:47 +0000)
"cmd" pointer inside ptlrpc_lprocfs_nrs_tbf_rule_seq_write() and
nrs_tbf_parse_cmd are static. This could cause a double kfree call
because "cmd" could be overwriten by another "nrs_tbf_rule" write
instance.

Let's try to remove the "static" definition.

Signed-off-by: Etienne AUJAMES <eaujames@ddn.com>
Change-Id: I8cd7d9dd0483778c82bbf8711c07e49255983f4b
Reviewed-on: https://review.whamcloud.com/45142
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Li Xi <lixi@ddn.com>
lustre/ptlrpc/nrs_tbf.c
lustre/tests/sanityn.sh

index 653b55e..47724dc 100644 (file)
@@ -3479,10 +3479,10 @@ nrs_tbf_parse_value_pairs(struct nrs_tbf_cmd *cmd, char *buffer)
 static struct nrs_tbf_cmd *
 nrs_tbf_parse_cmd(char *buffer, unsigned long count, __u32 type_flag)
 {
-       static struct nrs_tbf_cmd       *cmd;
-       char                            *token;
-       char                            *val;
-       int                              rc = 0;
+       struct nrs_tbf_cmd *cmd;
+       char *token;
+       char *val;
+       int rc = 0;
 
        OBD_ALLOC_PTR(cmd);
        if (cmd == NULL)
@@ -3580,15 +3580,15 @@ ptlrpc_lprocfs_nrs_tbf_rule_seq_write(struct file *file,
                                      const char __user *buffer,
                                      size_t count, loff_t *off)
 {
-       struct seq_file           *m = file->private_data;
-       struct ptlrpc_service     *svc = m->private;
-       char                      *kernbuf;
-       char                      *val;
-       int                        rc;
-       static struct nrs_tbf_cmd *cmd;
+       struct seq_file *m = file->private_data;
+       struct ptlrpc_service *svc = m->private;
+       char *kernbuf;
+       char *val;
+       int rc;
+       struct nrs_tbf_cmd *cmd;
        enum ptlrpc_nrs_queue_type queue = PTLRPC_NRS_QUEUE_BOTH;
-       unsigned long              length;
-       char                      *token;
+       unsigned long length;
+       char *token;
 
        OBD_ALLOC(kernbuf, LPROCFS_WR_NRS_TBF_MAX_CMD);
        if (kernbuf == NULL)
index 7f20a86..7a4cc88 100755 (executable)
@@ -4429,6 +4429,35 @@ test_77o() {
 }
 run_test 77o "Changing rank should not panic"
 
+test_77q() {
+       local i
+
+       (( $MDS1_VERSION > $(version_code 2.14.54) )) ||
+               skip "need MDS >= 2.14.54"
+
+       do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_policies="tbf"
+       stack_trap "do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_policies=fifo"
+
+       for i in {1..50}; do
+               local pid1 pid2
+
+               do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'start rule77q_1 uid={500}&gid={500} rate=100'" &
+               pid1=$!
+               do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'start rule77q_2 uid={1000}&gid={1000} rate=100'" &
+               pid2=$!
+               wait $pid1 || error "$i: Fail to start TBF rule 'rule77q_1'"
+               wait $pid2 || error "$i: Fail to start TBF rule 'rule77q_2'"
+
+               do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'stop rule77q_1'" &
+               pid1=$!
+               do_facet mds1 $LCTL set_param mds.MDS.mdt.nrs_tbf_rule="'stop rule77q_2'" &
+               pid2=$!
+               wait $pid1 || error "$i: Fail to stop TBF rule 'rule77q_1'"
+               wait $pid2 || error "$i: Fail to stop TBF rule 'rule77q_2'"
+       done
+}
+run_test 77q "Parallel TBF rule definitions should not panic"
+
 test_78() { #LU-6673
        local rc