Whamcloud - gitweb
LU-13985 lustre: seq_file .next functions must update *pos 35/40035/3
authorMr NeilBrown <neilb@suse.de>
Thu, 24 Sep 2020 23:46:24 +0000 (09:46 +1000)
committerOleg Drokin <green@whamcloud.com>
Mon, 12 Oct 2020 05:47:33 +0000 (05:47 +0000)
A seq_file .next function must update *pos on EOF to a value which
will cause a subsequent ->start to also return EOF.
If it doesn't the last record of the file can be returned
twice to a 'read()'.  Also the seq_file code will generate
a warning.

This patch fixes various ->next functions to always update
*pos.

Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: Ia0c432cd50550ecde6b308cbc554b316fa03adae
Reviewed-on: https://review.whamcloud.com/40035
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
ldiskfs/kernel_patches/patches/rhel7.6/ext4-track-extent-status-tree-shrinker-delay-statict.patch
lnet/klnds/gnilnd/gnilnd_proc.c
lustre/fid/lproc_fid.c
lustre/fld/lproc_fld.c
lustre/lov/lov_pool.c
lustre/obdclass/lu_ref.c
lustre/ptlrpc/lproc_ptlrpc.c

index 9cb4d18..c43d374 100644 (file)
@@ -227,7 +227,7 @@ index 3ef7f932..7dfed27b 100644
        trace_ext4_es_shrink_enter(sbi->s_sb, nr_to_scan, ret);
  
        if (!nr_to_scan)
-@@ -1034,23 +1069,149 @@ static int ext4_es_shrink(struct shrinker *shrink, struct shrink_control *sc)
+@@ -1034,23 +1069,150 @@ static int ext4_es_shrink(struct shrinker *shrink, struct shrink_control *sc)
  
        nr_shrunk = __ext4_es_shrink(sbi, nr_to_scan, NULL);
  
@@ -246,6 +246,7 @@ index 3ef7f932..7dfed27b 100644
 +static void *
 +ext4_es_seq_shrinker_info_next(struct seq_file *seq, void *v, loff_t *pos)
 +{
++      ++*pos;
 +      return NULL;
 +}
 +
index a833026..13fb4a5 100644 (file)
@@ -457,10 +457,10 @@ kgnilnd_mdd_seq_next(struct seq_file *s, void *iter, loff_t *pos)
        loff_t                  next = *pos + 1;
 
        rc = kgnilnd_mdd_seq_seek(gseq, next);
+       *pos = next;
        if (rc != 0) {
                return NULL;
        }
-       *pos = next;
        return gseq;
 }
 
@@ -646,11 +646,11 @@ kgnilnd_smsg_seq_next(struct seq_file *s, void *iter, loff_t *pos)
        loff_t                  next = *pos + 1;
 
        rc = kgnilnd_smsg_seq_seek(gseq, next);
+       *pos = next;
        if (rc != 0) {
                LIBCFS_FREE(gseq, sizeof(*gseq));
                return NULL;
        }
-       *pos = next;
        return gseq;
 }
 
@@ -862,11 +862,11 @@ kgnilnd_conn_seq_next(struct seq_file *s, void *iter, loff_t *pos)
        loff_t                  next = *pos + 1;
 
        rc = kgnilnd_conn_seq_seek(gseq, next);
+       *pos = next;
        if (rc != 0) {
                LIBCFS_FREE(gseq, sizeof(*gseq));
                return NULL;
        }
-       *pos = next;
        return gseq;
 }
 
@@ -1215,11 +1215,11 @@ kgnilnd_peer_seq_next(struct seq_file *s, void *iter, loff_t *pos)
        loff_t                  next = *pos + 1;
 
        rc = kgnilnd_peer_seq_seek(gseq, next);
+       *pos = next;
        if (rc != 0) {
                LIBCFS_FREE(gseq, sizeof(*gseq));
                return NULL;
        }
-       *pos = next;
        return gseq;
 }
 
index ffa537f..554e641 100644 (file)
@@ -278,6 +278,7 @@ static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
        const struct dt_it_ops  *iops;
        int                     rc;
 
+       ++*pos;
        if (param == NULL || param->fsp_stop)
                return NULL;
 
index 80f0ae4..8c86abd 100644 (file)
@@ -209,6 +209,7 @@ static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
        const struct dt_it_ops  *iops;
        int                     rc;
 
+       ++*pos;
        if (param == NULL || param->fsp_stop)
                return NULL;
 
index f272cfe..f31a9a7 100644 (file)
@@ -111,25 +111,25 @@ struct pool_iterator {
 
 static void *pool_proc_next(struct seq_file *s, void *v, loff_t *pos)
 {
-        struct pool_iterator *iter = (struct pool_iterator *)s->private;
-        int prev_idx;
+       struct pool_iterator *iter = (struct pool_iterator *)s->private;
+       int prev_idx;
 
        LASSERTF(iter->magic == POOL_IT_MAGIC, "%08X\n", iter->magic);
 
-        /* test if end of file */
-        if (*pos >= pool_tgt_count(iter->pool))
-                return NULL;
+       (*pos)++;
+       /* test if end of file */
+       if (*pos > pool_tgt_count(iter->pool))
+               return NULL;
 
-        /* iterate to find a non empty entry */
-        prev_idx = iter->idx;
-        iter->idx++;
+       /* iterate to find a non empty entry */
+       prev_idx = iter->idx;
+       iter->idx++;
        if (iter->idx >= pool_tgt_count(iter->pool)) {
-                iter->idx = prev_idx; /* we stay on the last entry */
-                return NULL;
-        }
-        (*pos)++;
-        /* return != NULL to continue */
-        return iter;
+               iter->idx = prev_idx; /* we stay on the last entry */
+               return NULL;
+       }
+       /* return != NULL to continue */
+       return iter;
 }
 
 static void *pool_proc_start(struct seq_file *s, loff_t *pos)
index cf674a9..d88e492 100644 (file)
@@ -309,15 +309,15 @@ static void *lu_ref_seq_next(struct seq_file *seq, void *p, loff_t *pos)
        LASSERT(seq->private == p);
        LASSERT(!list_empty(&ref->lf_linkage));
 
+       (*pos)++;
        spin_lock(&lu_ref_refs_guard);
        next = list_entry(ref->lf_linkage.next, struct lu_ref, lf_linkage);
-       if (&next->lf_linkage == &lu_ref_refs) {
+       if (&next->lf_linkage == &lu_ref_refs)
                p = NULL;
-       } else {
-               (*pos)++;
+       else
                list_move(&ref->lf_linkage, &next->lf_linkage);
-       }
        spin_unlock(&lu_ref_refs_guard);
+
        return p;
 }
 
index 03bb88d..9bb515b 100644 (file)
@@ -965,6 +965,7 @@ ptlrpc_lprocfs_svc_req_history_next(struct seq_file *s,
        }
 
        OBD_FREE(srhi, sizeof(*srhi));
+       ++*pos;
        return NULL;
 }