Skip to content

Commit be66737

Browse files
committed
nilfs2: record used amount of each checkpoint in checkpoint list
This records the number of used blocks per checkpoint in each checkpoint entry of cpfile. Even though userland tools can get the block count via nilfs_get_cpinfo ioctl, it was not updated by the nilfs2 kernel code. This fixes the issue and makes it available for userland tools to calculate used amount per checkpoint. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp> Cc: Jiro SEKIBA <jir@unicus.jp>
1 parent ae19183 commit be66737

7 files changed

Lines changed: 29 additions & 21 deletions

File tree

‎fs/nilfs2/bmap.c‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -425,17 +425,6 @@ int nilfs_bmap_test_and_clear_dirty(struct nilfs_bmap *bmap)
425425
/*
426426
* Internal use only
427427
*/
428-
429-
void nilfs_bmap_add_blocks(const struct nilfs_bmap *bmap, int n)
430-
{
431-
inode_add_bytes(bmap->b_inode, (1 << bmap->b_inode->i_blkbits) * n);
432-
}
433-
434-
void nilfs_bmap_sub_blocks(const struct nilfs_bmap *bmap, int n)
435-
{
436-
inode_sub_bytes(bmap->b_inode, (1 << bmap->b_inode->i_blkbits) * n);
437-
}
438-
439428
__u64 nilfs_bmap_data_get_key(const struct nilfs_bmap *bmap,
440429
const struct buffer_head *bh)
441430
{

‎fs/nilfs2/bmap.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,6 @@ __u64 nilfs_bmap_data_get_key(const struct nilfs_bmap *,
240240
__u64 nilfs_bmap_find_target_seq(const struct nilfs_bmap *, __u64);
241241
__u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *);
242242

243-
void nilfs_bmap_add_blocks(const struct nilfs_bmap *, int);
244-
void nilfs_bmap_sub_blocks(const struct nilfs_bmap *, int);
245-
246243

247244
/* Assume that bmap semaphore is locked. */
248245
static inline int nilfs_bmap_dirty(const struct nilfs_bmap *bmap)

‎fs/nilfs2/btree.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ static int nilfs_btree_insert(struct nilfs_bmap *btree, __u64 key, __u64 ptr)
11741174
if (ret < 0)
11751175
goto out;
11761176
nilfs_btree_commit_insert(btree, path, level, key, ptr);
1177-
nilfs_bmap_add_blocks(btree, stats.bs_nblocks);
1177+
nilfs_inode_add_blocks(btree->b_inode, stats.bs_nblocks);
11781178

11791179
out:
11801180
nilfs_btree_free_path(path);
@@ -1511,7 +1511,7 @@ static int nilfs_btree_delete(struct nilfs_bmap *btree, __u64 key)
15111511
if (ret < 0)
15121512
goto out;
15131513
nilfs_btree_commit_delete(btree, path, level, dat);
1514-
nilfs_bmap_sub_blocks(btree, stats.bs_nblocks);
1514+
nilfs_inode_sub_blocks(btree->b_inode, stats.bs_nblocks);
15151515

15161516
out:
15171517
nilfs_btree_free_path(path);
@@ -1776,7 +1776,7 @@ int nilfs_btree_convert_and_insert(struct nilfs_bmap *btree,
17761776
return ret;
17771777
nilfs_btree_commit_convert_and_insert(btree, key, ptr, keys, ptrs, n,
17781778
di, ni, bh);
1779-
nilfs_bmap_add_blocks(btree, stats.bs_nblocks);
1779+
nilfs_inode_add_blocks(btree->b_inode, stats.bs_nblocks);
17801780
return 0;
17811781
}
17821782

‎fs/nilfs2/direct.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static int nilfs_direct_insert(struct nilfs_bmap *bmap, __u64 key, __u64 ptr)
146146
if (NILFS_BMAP_USE_VBN(bmap))
147147
nilfs_bmap_set_target_v(bmap, key, req.bpr_ptr);
148148

149-
nilfs_bmap_add_blocks(bmap, 1);
149+
nilfs_inode_add_blocks(bmap->b_inode, 1);
150150
}
151151
return ret;
152152
}
@@ -168,7 +168,7 @@ static int nilfs_direct_delete(struct nilfs_bmap *bmap, __u64 key)
168168
if (!ret) {
169169
nilfs_bmap_commit_end_ptr(bmap, &req, dat);
170170
nilfs_direct_set_ptr(bmap, key, NILFS_BMAP_INVALID_PTR);
171-
nilfs_bmap_sub_blocks(bmap, 1);
171+
nilfs_inode_sub_blocks(bmap->b_inode, 1);
172172
}
173173
return ret;
174174
}

‎fs/nilfs2/inode.c‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ struct nilfs_iget_args {
4141
int for_gc;
4242
};
4343

44+
void nilfs_inode_add_blocks(struct inode *inode, int n)
45+
{
46+
struct nilfs_root *root = NILFS_I(inode)->i_root;
47+
48+
inode_add_bytes(inode, (1 << inode->i_blkbits) * n);
49+
if (root)
50+
atomic_add(n, &root->blocks_count);
51+
}
52+
53+
void nilfs_inode_sub_blocks(struct inode *inode, int n)
54+
{
55+
struct nilfs_root *root = NILFS_I(inode)->i_root;
56+
57+
inode_sub_bytes(inode, (1 << inode->i_blkbits) * n);
58+
if (root)
59+
atomic_sub(n, &root->blocks_count);
60+
}
61+
4462
/**
4563
* nilfs_get_block() - get a file block on the filesystem (callback function)
4664
* @inode - inode struct of the target file

‎fs/nilfs2/nilfs.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ int nilfs_ioctl_prepare_clean_segments(struct the_nilfs *, struct nilfs_argv *,
251251
void **);
252252

253253
/* inode.c */
254+
void nilfs_inode_add_blocks(struct inode *inode, int n);
255+
void nilfs_inode_sub_blocks(struct inode *inode, int n);
254256
extern struct inode *nilfs_new_inode(struct inode *, int);
255257
extern void nilfs_free_inode(struct inode *);
256258
extern int nilfs_get_block(struct inode *, sector_t, struct buffer_head *, int);

‎include/linux/nilfs2_fs.h‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,10 @@ struct nilfs_super_block {
216216
* If there is a bit set in the incompatible feature set that the kernel
217217
* doesn't know about, it should refuse to mount the filesystem.
218218
*/
219+
#define NILFS_FEATURE_COMPAT_RO_BLOCK_COUNT 0x00000001ULL
220+
219221
#define NILFS_FEATURE_COMPAT_SUPP 0ULL
220-
#define NILFS_FEATURE_COMPAT_RO_SUPP 0ULL
222+
#define NILFS_FEATURE_COMPAT_RO_SUPP NILFS_FEATURE_COMPAT_RO_BLOCK_COUNT
221223
#define NILFS_FEATURE_INCOMPAT_SUPP 0ULL
222224

223225
/*
@@ -509,7 +511,7 @@ struct nilfs_checkpoint {
509511
__le64 cp_create;
510512
__le64 cp_nblk_inc;
511513
__le64 cp_inodes_count;
512-
__le64 cp_blocks_count; /* Reserved (might be deleted) */
514+
__le64 cp_blocks_count;
513515

514516
/* Do not change the byte offset of ifile inode.
515517
To keep the compatibility of the disk format,

0 commit comments

Comments
 (0)