@@ -117,14 +117,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;
@@ -157,6 +154,7 @@ static void *pool_proc_start(struct seq_file *s, loff_t *pos)
*/
/* /!\ 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;
@@ -179,6 +177,7 @@ static void pool_proc_stop(struct seq_file *s, void *v)
* 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
*/
@@ -197,9 +196,7 @@ static int pool_proc_show(struct seq_file *s, void *v)
LASSERT(iter->pool);
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));