File 0062-LU-13985-lustre-seq_file-.next-functions-must-update.patch of Package lustre_2_12
From 817d6c116599639599919bcde7999a7f06b74d2c Mon Sep 17 00:00:00 2001
From: Mr NeilBrown <neilb@suse.de>
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 <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>
---
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 +
6 files changed, 25 insertions(+), 22 deletions(-)
--- a/lnet/klnds/gnilnd/gnilnd_proc.c
+++ b/lnet/klnds/gnilnd/gnilnd_proc.c
@@ -459,10 +459,10 @@ kgnilnd_mdd_seq_next(struct seq_file *s,
loff_t next = *pos + 1;
rc = kgnilnd_mdd_seq_seek(gseq, next);
+ *pos = next;
if (rc != 0) {
return NULL;
}
- *pos = next;
return gseq;
}
@@ -648,11 +648,11 @@ kgnilnd_smsg_seq_next(struct seq_file *s
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;
}
@@ -864,11 +864,11 @@ kgnilnd_conn_seq_next(struct seq_file *s
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;
}
@@ -1217,11 +1217,11 @@ kgnilnd_peer_seq_next(struct seq_file *s
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;
}
--- a/lustre/fid/lproc_fid.c
+++ b/lustre/fid/lproc_fid.c
@@ -278,6 +278,7 @@ static void *fldb_seq_next(struct seq_fi
const struct dt_it_ops *iops;
int rc;
+ ++*pos;
if (param == NULL || param->fsp_stop)
return NULL;
--- a/lustre/fld/lproc_fld.c
+++ b/lustre/fld/lproc_fld.c
@@ -210,6 +210,7 @@ static void *fldb_seq_next(struct seq_fi
const struct dt_it_ops *iops;
int rc;
+ ++*pos;
if (param == NULL || param->fsp_stop)
return NULL;
--- a/lustre/lov/lov_pool.c
+++ b/lustre/lov/lov_pool.c
@@ -170,25 +170,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)
--- a/lustre/obdclass/lu_ref.c
+++ b/lustre/obdclass/lu_ref.c
@@ -309,15 +309,15 @@ static void *lu_ref_seq_next(struct seq_
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;
}
--- a/lustre/ptlrpc/lproc_ptlrpc.c
+++ b/lustre/ptlrpc/lproc_ptlrpc.c
@@ -946,6 +946,7 @@ ptlrpc_lprocfs_svc_req_history_start(str
}
OBD_FREE(srhi, sizeof(*srhi));
+ ++*pos;
return NULL;
}