Skip to content

Commit b028fcf

Browse files
konistorvalds
authored andcommitted
nilfs2: fix gc failure on volumes keeping numerous snapshots
This resolves the following failure of nilfs2 cleaner daemon: nilfs_cleanerd[20670]: cannot clean segments: No such file or directory nilfs_cleanerd[20670]: shutdown When creating thousands of snapshots, the cleaner daemon had rarely died as above due to an error returned from the kernel code. After applying the recent patch which fixed memory allocation problems in ioctl (Message-Id: <20081215.155840.105124170.ryusuke@osrg.net>), the problem gets more frequent. It turned out to be a bug of nilfs_ioctl_wrap_copy function and one of its callback routines to read out information of snapshots; if the nilfs_ioctl_wrap_copy function divided a large read request into multiple requests, the second and later requests have failed since a restart position on snapshot meta data was not properly set forward. It's a deficiency of the callback interface that cannot pass the restart position among multiple requests. This patch fixes the issue by allowing nilfs_ioctl_wrap_copy and snapshot read functions to exchange a position argument. 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 85ef9ce commit b028fcf

3 files changed

Lines changed: 38 additions & 26 deletions

File tree

‎fs/nilfs2/cpfile.c‎

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -422,20 +422,20 @@ static ssize_t nilfs_cpfile_do_get_cpinfo(struct inode *cpfile, __u64 cno,
422422
return ret;
423423
}
424424

425-
static ssize_t nilfs_cpfile_do_get_ssinfo(struct inode *cpfile, __u64 cno,
425+
static ssize_t nilfs_cpfile_do_get_ssinfo(struct inode *cpfile, __u64 *cnop,
426426
struct nilfs_cpinfo *ci, size_t nci)
427427
{
428428
struct buffer_head *bh;
429429
struct nilfs_cpfile_header *header;
430430
struct nilfs_checkpoint *cp;
431-
__u64 curr, next;
431+
__u64 curr = *cnop, next;
432432
unsigned long curr_blkoff, next_blkoff;
433433
void *kaddr;
434434
int n, ret;
435435

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

438-
if (cno == 0) {
438+
if (curr == 0) {
439439
ret = nilfs_cpfile_get_header_block(cpfile, &bh);
440440
if (ret < 0)
441441
goto out;
@@ -448,8 +448,11 @@ static ssize_t nilfs_cpfile_do_get_ssinfo(struct inode *cpfile, __u64 cno,
448448
ret = 0;
449449
goto out;
450450
}
451-
} else
452-
curr = cno;
451+
} else if (unlikely(curr == ~(__u64)0)) {
452+
ret = 0;
453+
goto out;
454+
}
455+
453456
curr_blkoff = nilfs_cpfile_get_blkoff(cpfile, curr);
454457
ret = nilfs_cpfile_get_checkpoint_block(cpfile, curr, 0, &bh);
455458
if (ret < 0)
@@ -461,7 +464,7 @@ static ssize_t nilfs_cpfile_do_get_ssinfo(struct inode *cpfile, __u64 cno,
461464
nilfs_cpfile_checkpoint_to_cpinfo(cpfile, cp, &ci[n]);
462465
next = le64_to_cpu(cp->cp_snapshot_list.ssl_next);
463466
if (next == 0) {
464-
curr = next;
467+
curr = ~(__u64)0; /* Terminator */
465468
n++;
466469
break;
467470
}
@@ -480,6 +483,7 @@ static ssize_t nilfs_cpfile_do_get_ssinfo(struct inode *cpfile, __u64 cno,
480483
}
481484
kunmap_atomic(kaddr, KM_USER0);
482485
brelse(bh);
486+
*cnop = curr;
483487
ret = n;
484488

485489
out:
@@ -494,15 +498,15 @@ static ssize_t nilfs_cpfile_do_get_ssinfo(struct inode *cpfile, __u64 cno,
494498
* @ci:
495499
* @nci:
496500
*/
497-
ssize_t nilfs_cpfile_get_cpinfo(struct inode *cpfile,
498-
__u64 cno, int mode,
501+
502+
ssize_t nilfs_cpfile_get_cpinfo(struct inode *cpfile, __u64 *cnop, int mode,
499503
struct nilfs_cpinfo *ci, size_t nci)
500504
{
501505
switch (mode) {
502506
case NILFS_CHECKPOINT:
503-
return nilfs_cpfile_do_get_cpinfo(cpfile, cno, ci, nci);
507+
return nilfs_cpfile_do_get_cpinfo(cpfile, *cnop, ci, nci);
504508
case NILFS_SNAPSHOT:
505-
return nilfs_cpfile_do_get_ssinfo(cpfile, cno, ci, nci);
509+
return nilfs_cpfile_do_get_ssinfo(cpfile, cnop, ci, nci);
506510
default:
507511
return -EINVAL;
508512
}

‎fs/nilfs2/cpfile.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int nilfs_cpfile_delete_checkpoint(struct inode *, __u64);
3939
int nilfs_cpfile_change_cpmode(struct inode *, __u64, int);
4040
int nilfs_cpfile_is_snapshot(struct inode *, __u64);
4141
int nilfs_cpfile_get_stat(struct inode *, struct nilfs_cpstat *);
42-
ssize_t nilfs_cpfile_get_cpinfo(struct inode *, __u64, int,
42+
ssize_t nilfs_cpfile_get_cpinfo(struct inode *, __u64 *, int,
4343
struct nilfs_cpinfo *, size_t);
4444

4545
#endif /* _NILFS_CPFILE_H */

‎fs/nilfs2/ioctl.c‎

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@
3737
static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs,
3838
struct nilfs_argv *argv, int dir,
3939
ssize_t (*dofunc)(struct the_nilfs *,
40-
int, int,
40+
__u64 *, int,
4141
void *, size_t, size_t))
4242
{
4343
void *buf;
4444
size_t maxmembs, total, n;
4545
ssize_t nr;
4646
int ret, i;
47+
__u64 pos, ppos;
4748

4849
if (argv->v_nmembs == 0)
4950
return 0;
@@ -58,6 +59,7 @@ static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs,
5859

5960
ret = 0;
6061
total = 0;
62+
pos = argv->v_index;
6163
for (i = 0; i < argv->v_nmembs; i += n) {
6264
n = (argv->v_nmembs - i < maxmembs) ?
6365
argv->v_nmembs - i : maxmembs;
@@ -68,8 +70,9 @@ static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs,
6870
ret = -EFAULT;
6971
break;
7072
}
71-
nr = (*dofunc)(nilfs, argv->v_index + i, argv->v_flags, buf,
72-
argv->v_size, n);
73+
ppos = pos;
74+
nr = (*dofunc)(nilfs, &pos, argv->v_flags, buf, argv->v_size,
75+
n);
7376
if (nr < 0) {
7477
ret = nr;
7578
break;
@@ -82,6 +85,10 @@ static int nilfs_ioctl_wrap_copy(struct the_nilfs *nilfs,
8285
break;
8386
}
8487
total += nr;
88+
if ((size_t)nr < n)
89+
break;
90+
if (pos == ppos)
91+
pos += n;
8592
}
8693
argv->v_nmembs = total;
8794

@@ -138,10 +145,10 @@ nilfs_ioctl_delete_checkpoint(struct inode *inode, struct file *filp,
138145
}
139146

140147
static ssize_t
141-
nilfs_ioctl_do_get_cpinfo(struct the_nilfs *nilfs, int index, int flags,
148+
nilfs_ioctl_do_get_cpinfo(struct the_nilfs *nilfs, __u64 *posp, int flags,
142149
void *buf, size_t size, size_t nmembs)
143150
{
144-
return nilfs_cpfile_get_cpinfo(nilfs->ns_cpfile, index, flags, buf,
151+
return nilfs_cpfile_get_cpinfo(nilfs->ns_cpfile, posp, flags, buf,
145152
nmembs);
146153
}
147154

@@ -186,10 +193,10 @@ static int nilfs_ioctl_get_cpstat(struct inode *inode, struct file *filp,
186193
}
187194

188195
static ssize_t
189-
nilfs_ioctl_do_get_suinfo(struct the_nilfs *nilfs, int index, int flags,
196+
nilfs_ioctl_do_get_suinfo(struct the_nilfs *nilfs, __u64 *posp, int flags,
190197
void *buf, size_t size, size_t nmembs)
191198
{
192-
return nilfs_sufile_get_suinfo(nilfs->ns_sufile, index, buf, nmembs);
199+
return nilfs_sufile_get_suinfo(nilfs->ns_sufile, *posp, buf, nmembs);
193200
}
194201

195202
static int nilfs_ioctl_get_suinfo(struct inode *inode, struct file *filp,
@@ -233,7 +240,7 @@ static int nilfs_ioctl_get_sustat(struct inode *inode, struct file *filp,
233240
}
234241

235242
static ssize_t
236-
nilfs_ioctl_do_get_vinfo(struct the_nilfs *nilfs, int index, int flags,
243+
nilfs_ioctl_do_get_vinfo(struct the_nilfs *nilfs, __u64 *posp, int flags,
237244
void *buf, size_t size, size_t nmembs)
238245
{
239246
return nilfs_dat_get_vinfo(nilfs_dat_inode(nilfs), buf, nmembs);
@@ -262,7 +269,7 @@ static int nilfs_ioctl_get_vinfo(struct inode *inode, struct file *filp,
262269
}
263270

264271
static ssize_t
265-
nilfs_ioctl_do_get_bdescs(struct the_nilfs *nilfs, int index, int flags,
272+
nilfs_ioctl_do_get_bdescs(struct the_nilfs *nilfs, __u64 *posp, int flags,
266273
void *buf, size_t size, size_t nmembs)
267274
{
268275
struct inode *dat = nilfs_dat_inode(nilfs);
@@ -341,7 +348,7 @@ static int nilfs_ioctl_move_inode_block(struct inode *inode,
341348
}
342349

343350
static ssize_t
344-
nilfs_ioctl_do_move_blocks(struct the_nilfs *nilfs, int index, int flags,
351+
nilfs_ioctl_do_move_blocks(struct the_nilfs *nilfs, __u64 *posp, int flags,
345352
void *buf, size_t size, size_t nmembs)
346353
{
347354
struct inode *inode;
@@ -413,7 +420,7 @@ static inline int nilfs_ioctl_move_blocks(struct the_nilfs *nilfs,
413420
}
414421

415422
static ssize_t
416-
nilfs_ioctl_do_delete_checkpoints(struct the_nilfs *nilfs, int index,
423+
nilfs_ioctl_do_delete_checkpoints(struct the_nilfs *nilfs, __u64 *posp,
417424
int flags, void *buf, size_t size,
418425
size_t nmembs)
419426
{
@@ -439,7 +446,7 @@ static inline int nilfs_ioctl_delete_checkpoints(struct the_nilfs *nilfs,
439446
}
440447

441448
static ssize_t
442-
nilfs_ioctl_do_free_vblocknrs(struct the_nilfs *nilfs, int index, int flags,
449+
nilfs_ioctl_do_free_vblocknrs(struct the_nilfs *nilfs, __u64 *posp, int flags,
443450
void *buf, size_t size, size_t nmembs)
444451
{
445452
int ret = nilfs_dat_freev(nilfs_dat_inode(nilfs), buf, nmembs);
@@ -456,8 +463,9 @@ static inline int nilfs_ioctl_free_vblocknrs(struct the_nilfs *nilfs,
456463
}
457464

458465
static ssize_t
459-
nilfs_ioctl_do_mark_blocks_dirty(struct the_nilfs *nilfs, int index, int flags,
460-
void *buf, size_t size, size_t nmembs)
466+
nilfs_ioctl_do_mark_blocks_dirty(struct the_nilfs *nilfs, __u64 *posp,
467+
int flags, void *buf, size_t size,
468+
size_t nmembs)
461469
{
462470
struct inode *dat = nilfs_dat_inode(nilfs);
463471
struct nilfs_bmap *bmap = NILFS_I(dat)->i_bmap;
@@ -506,7 +514,7 @@ static inline int nilfs_ioctl_mark_blocks_dirty(struct the_nilfs *nilfs,
506514
}
507515

508516
static ssize_t
509-
nilfs_ioctl_do_free_segments(struct the_nilfs *nilfs, int index, int flags,
517+
nilfs_ioctl_do_free_segments(struct the_nilfs *nilfs, __u64 *posp, int flags,
510518
void *buf, size_t size, size_t nmembs)
511519
{
512520
struct nilfs_sb_info *sbi = nilfs_get_writer(nilfs);

0 commit comments

Comments
 (0)