From: Jadhav Vikram Date: Thu, 12 Jan 2017 12:11:14 +0000 (+0530) Subject: LU-9620 lod: protected ost pool count updation X-Git-Tag: 2.10.51~73 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=61c803319b914992f8a8fd3e21a0c3a576c9dfd0 LU-9620 lod: protected ost pool count updation ASSERTION(iter->lpi_idx <= ((iter->lpi_pool)->pool_obds.op_count) caused due to reading of ost pool count is not protected in pool_proc_next and pool_proc_show, pool_proc_show get called when op_count was zero. Fix to protect ost pool count by taking lock at start sequence function pool_proc_start and released lock in pool_proc_stop. Rather than using down_read / up_read pairs around pool_proc_next and pool_proc_show, this changes make sure ost pool data gets protected throughout sequence operation. Change-Id: I2954496d52dd703b600e69a494898c6266f026bd Seagate-bug-id: MRP-3629 Signed-off-by: Jadhav Vikram Reviewed-by: Ashish Purkar Tested-by: Elena V. Gryaznova Reviewed-by: Vladimir Saveliev Reviewed-on: https://review.whamcloud.com/27506 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Fan Yong Reviewed-by: Niu Yawei Reviewed-by: Oleg Drokin --- diff --git a/lustre/lod/lod_pool.c b/lustre/lod/lod_pool.c index 27b945e..df66bb3 100644 --- a/lustre/lod/lod_pool.c +++ b/lustre/lod/lod_pool.c @@ -262,14 +262,11 @@ static void *pool_proc_next(struct seq_file *seq, void *v, loff_t *pos) /* iterate to find a non empty entry */ prev_idx = iter->lpi_idx; - down_read(&pool_tgt_rw_sem(iter->lpi_pool)); iter->lpi_idx++; - if (iter->lpi_idx == pool_tgt_count(iter->lpi_pool)) { + if (iter->lpi_idx >= pool_tgt_count(iter->lpi_pool)) { iter->lpi_idx = prev_idx; /* we stay on the last entry */ - up_read(&pool_tgt_rw_sem(iter->lpi_pool)); return NULL; } - up_read(&pool_tgt_rw_sem(iter->lpi_pool)); (*pos)++; /* return != NULL to continue */ return iter; @@ -312,6 +309,7 @@ static void *pool_proc_start(struct seq_file *seq, loff_t *pos) iter->lpi_idx = 0; seq->private = iter; + down_read(&pool_tgt_rw_sem(pool)); if (*pos > 0) { loff_t i; void *ptr; @@ -346,6 +344,7 @@ static void pool_proc_stop(struct seq_file *seq, void *v) struct lod_pool_iterator *iter = seq->private; if (iter != NULL && iter->lpi_magic == POOL_IT_MAGIC) { + up_read(&pool_tgt_rw_sem(iter->lpi_pool)); seq->private = iter->lpi_pool; lod_pool_putref(iter->lpi_pool); OBD_FREE_PTR(iter); @@ -369,9 +368,7 @@ static int pool_proc_show(struct seq_file *seq, void *v) LASSERT(iter->lpi_pool != NULL); LASSERT(iter->lpi_idx <= pool_tgt_count(iter->lpi_pool)); - down_read(&pool_tgt_rw_sem(iter->lpi_pool)); tgt = pool_tgt(iter->lpi_pool, iter->lpi_idx); - up_read(&pool_tgt_rw_sem(iter->lpi_pool)); if (tgt != NULL) seq_printf(seq, "%s\n", obd_uuid2str(&(tgt->ltd_uuid))); diff --git a/lustre/lov/lov_pool.c b/lustre/lov/lov_pool.c index 7a2b9ac..08ecfde 100644 --- a/lustre/lov/lov_pool.c +++ b/lustre/lov/lov_pool.c @@ -181,14 +181,11 @@ static void *pool_proc_next(struct seq_file *s, void *v, loff_t *pos) /* iterate to find a non empty entry */ prev_idx = iter->idx; - down_read(&pool_tgt_rw_sem(iter->pool)); iter->idx++; - if (iter->idx == pool_tgt_count(iter->pool)) { + if (iter->idx >= pool_tgt_count(iter->pool)) { iter->idx = prev_idx; /* we stay on the last entry */ - up_read(&pool_tgt_rw_sem(iter->pool)); return NULL; } - up_read(&pool_tgt_rw_sem(iter->pool)); (*pos)++; /* return != NULL to continue */ return iter; @@ -219,6 +216,7 @@ static void *pool_proc_start(struct seq_file *s, loff_t *pos) * we can free it at stop() */ /* /!\ do not forget to restore it to pool before freeing it */ s->private = iter; + down_read(&pool_tgt_rw_sem(pool)); if (*pos > 0) { loff_t i; void *ptr; @@ -240,6 +238,7 @@ static void pool_proc_stop(struct seq_file *s, void *v) * calling start() method (see seq_read() from fs/seq_file.c) * we have to free only if s->private is an iterator */ if ((iter) && (iter->magic == POOL_IT_MAGIC)) { + up_read(&pool_tgt_rw_sem(iter->pool)); /* we restore s->private so next call to pool_proc_start() * will work */ s->private = iter->pool; @@ -258,9 +257,7 @@ static int pool_proc_show(struct seq_file *s, void *v) LASSERT(iter->pool != NULL); LASSERT(iter->idx <= pool_tgt_count(iter->pool)); - down_read(&pool_tgt_rw_sem(iter->pool)); tgt = pool_tgt(iter->pool, iter->idx); - up_read(&pool_tgt_rw_sem(iter->pool)); if (tgt) seq_printf(s, "%s\n", obd_uuid2str(&(tgt->ltd_uuid)));