Skip to content

Commit 7fa10d2

Browse files
konistorvalds
authored andcommitted
nilfs2: fix improper return values of nilfs_get_cpinfo ioctl
A few tool developers gave me requests for fixing inconvenient return value of nilfs_get_cpinfo() ioctl; if the requested mode is NILFS_SNAPSHOT and the specified start entry is not a snapshot, the ioctl unnaturally returns one as the number of acquired snapshot item. In addition, the ioctl function returns an ENOENT error for checkpoints within blocks deleted by garbage collection. These behaviors require corrections for programs which enumerate snapshots. This resolves the inconvenience by changing the return values to zero for the above cases. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b028fcf commit 7fa10d2

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

‎fs/nilfs2/cpfile.c‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ static ssize_t nilfs_cpfile_do_get_ssinfo(struct inode *cpfile, __u64 *cnop,
431431
__u64 curr = *cnop, next;
432432
unsigned long curr_blkoff, next_blkoff;
433433
void *kaddr;
434-
int n, ret;
434+
int n = 0, ret;
435435

436436
down_read(&NILFS_MDT(cpfile)->mi_sem);
437437

@@ -455,27 +455,33 @@ static ssize_t nilfs_cpfile_do_get_ssinfo(struct inode *cpfile, __u64 *cnop,
455455

456456
curr_blkoff = nilfs_cpfile_get_blkoff(cpfile, curr);
457457
ret = nilfs_cpfile_get_checkpoint_block(cpfile, curr, 0, &bh);
458-
if (ret < 0)
458+
if (unlikely(ret < 0)) {
459+
if (ret == -ENOENT)
460+
ret = 0; /* No snapshots (started from a hole block) */
459461
goto out;
462+
}
460463
kaddr = kmap_atomic(bh->b_page, KM_USER0);
461-
for (n = 0; n < nci; n++) {
462-
cp = nilfs_cpfile_block_get_checkpoint(
463-
cpfile, curr, bh, kaddr);
464-
nilfs_cpfile_checkpoint_to_cpinfo(cpfile, cp, &ci[n]);
465-
next = le64_to_cpu(cp->cp_snapshot_list.ssl_next);
466-
if (next == 0) {
467-
curr = ~(__u64)0; /* Terminator */
468-
n++;
464+
while (n < nci) {
465+
cp = nilfs_cpfile_block_get_checkpoint(cpfile, curr, bh, kaddr);
466+
curr = ~(__u64)0; /* Terminator */
467+
if (unlikely(nilfs_checkpoint_invalid(cp) ||
468+
!nilfs_checkpoint_snapshot(cp)))
469469
break;
470-
}
470+
nilfs_cpfile_checkpoint_to_cpinfo(cpfile, cp, &ci[n++]);
471+
next = le64_to_cpu(cp->cp_snapshot_list.ssl_next);
472+
if (next == 0)
473+
break; /* reach end of the snapshot list */
474+
471475
next_blkoff = nilfs_cpfile_get_blkoff(cpfile, next);
472476
if (curr_blkoff != next_blkoff) {
473477
kunmap_atomic(kaddr, KM_USER0);
474478
brelse(bh);
475479
ret = nilfs_cpfile_get_checkpoint_block(cpfile, next,
476480
0, &bh);
477-
if (ret < 0)
481+
if (unlikely(ret < 0)) {
482+
WARN_ON(ret == -ENOENT);
478483
goto out;
484+
}
479485
kaddr = kmap_atomic(bh->b_page, KM_USER0);
480486
}
481487
curr = next;

0 commit comments

Comments
 (0)