From 817d6c116599639599919bcde7999a7f06b74d2c Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Fri, 25 Sep 2020 09:46:24 +1000 Subject: [PATCH] LU-13985 lustre: seq_file .next functions must update *pos 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 Change-Id: Ia0c432cd50550ecde6b308cbc554b316fa03adae Reviewed-on: https://review.whamcloud.com/40035 Tested-by: jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Chris Horn Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- ...extent-status-tree-shrinker-delay-statict.patch | 3 ++- lnet/klnds/gnilnd/gnilnd_proc.c | 8 +++---- lustre/fid/lproc_fid.c | 1 + lustre/fld/lproc_fld.c | 1 + lustre/lov/lov_pool.c | 28 +++++++++++----------- lustre/obdclass/lu_ref.c | 8 +++---- lustre/ptlrpc/lproc_ptlrpc.c | 1 + 7 files changed, 27 insertions(+), 23 deletions(-) diff --git a/ldiskfs/kernel_patches/patches/rhel7.6/ext4-track-extent-status-tree-shrinker-delay-statict.patch b/ldiskfs/kernel_patches/patches/rhel7.6/ext4-track-extent-status-tree-shrinker-delay-statict.patch index 9cb4d18..c43d374 100644 --- a/ldiskfs/kernel_patches/patches/rhel7.6/ext4-track-extent-status-tree-shrinker-delay-statict.patch +++ b/ldiskfs/kernel_patches/patches/rhel7.6/ext4-track-extent-status-tree-shrinker-delay-statict.patch @@ -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; +} + diff --git a/lnet/klnds/gnilnd/gnilnd_proc.c b/lnet/klnds/gnilnd/gnilnd_proc.c index a833026..13fb4a5 100644 --- a/lnet/klnds/gnilnd/gnilnd_proc.c +++ b/lnet/klnds/gnilnd/gnilnd_proc.c @@ -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; } diff --git a/lustre/fid/lproc_fid.c b/lustre/fid/lproc_fid.c index ffa537f..554e641 100644 --- a/lustre/fid/lproc_fid.c +++ b/lustre/fid/lproc_fid.c @@ -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; diff --git a/lustre/fld/lproc_fld.c b/lustre/fld/lproc_fld.c index 80f0ae4..8c86abd 100644 --- a/lustre/fld/lproc_fld.c +++ b/lustre/fld/lproc_fld.c @@ -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; diff --git a/lustre/lov/lov_pool.c b/lustre/lov/lov_pool.c index f272cfe..f31a9a7 100644 --- a/lustre/lov/lov_pool.c +++ b/lustre/lov/lov_pool.c @@ -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) diff --git a/lustre/obdclass/lu_ref.c b/lustre/obdclass/lu_ref.c index cf674a9..d88e492 100644 --- a/lustre/obdclass/lu_ref.c +++ b/lustre/obdclass/lu_ref.c @@ -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; } diff --git a/lustre/ptlrpc/lproc_ptlrpc.c b/lustre/ptlrpc/lproc_ptlrpc.c index 03bb88d..9bb515b 100644 --- a/lustre/ptlrpc/lproc_ptlrpc.c +++ b/lustre/ptlrpc/lproc_ptlrpc.c @@ -965,6 +965,7 @@ ptlrpc_lprocfs_svc_req_history_next(struct seq_file *s, } OBD_FREE(srhi, sizeof(*srhi)); + ++*pos; return NULL; } -- 1.8.3.1