Commit be667377a8b8cd73e1b923f33fb5be4034aa4bfa

Authored by Ryusuke Konishi
1 parent ae191838b0

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>

Showing 7 changed files with 29 additions and 21 deletions Side-by-side Diff

... ... @@ -425,17 +425,6 @@
425 425 /*
426 426 * Internal use only
427 427 */
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   -
439 428 __u64 nilfs_bmap_data_get_key(const struct nilfs_bmap *bmap,
440 429 const struct buffer_head *bh)
441 430 {
... ... @@ -240,9 +240,6 @@
240 240 __u64 nilfs_bmap_find_target_seq(const struct nilfs_bmap *, __u64);
241 241 __u64 nilfs_bmap_find_target_in_group(const struct nilfs_bmap *);
242 242  
243   -void nilfs_bmap_add_blocks(const struct nilfs_bmap *, int);
244   -void nilfs_bmap_sub_blocks(const struct nilfs_bmap *, int);
245   -
246 243  
247 244 /* Assume that bmap semaphore is locked. */
248 245 static inline int nilfs_bmap_dirty(const struct nilfs_bmap *bmap)
... ... @@ -1174,7 +1174,7 @@
1174 1174 if (ret < 0)
1175 1175 goto out;
1176 1176 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);
1178 1178  
1179 1179 out:
1180 1180 nilfs_btree_free_path(path);
... ... @@ -1511,7 +1511,7 @@
1511 1511 if (ret < 0)
1512 1512 goto out;
1513 1513 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);
1515 1515  
1516 1516 out:
1517 1517 nilfs_btree_free_path(path);
... ... @@ -1776,7 +1776,7 @@
1776 1776 return ret;
1777 1777 nilfs_btree_commit_convert_and_insert(btree, key, ptr, keys, ptrs, n,
1778 1778 di, ni, bh);
1779   - nilfs_bmap_add_blocks(btree, stats.bs_nblocks);
  1779 + nilfs_inode_add_blocks(btree->b_inode, stats.bs_nblocks);
1780 1780 return 0;
1781 1781 }
1782 1782  
... ... @@ -146,7 +146,7 @@
146 146 if (NILFS_BMAP_USE_VBN(bmap))
147 147 nilfs_bmap_set_target_v(bmap, key, req.bpr_ptr);
148 148  
149   - nilfs_bmap_add_blocks(bmap, 1);
  149 + nilfs_inode_add_blocks(bmap->b_inode, 1);
150 150 }
151 151 return ret;
152 152 }
... ... @@ -168,7 +168,7 @@
168 168 if (!ret) {
169 169 nilfs_bmap_commit_end_ptr(bmap, &req, dat);
170 170 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);
172 172 }
173 173 return ret;
174 174 }
... ... @@ -41,6 +41,24 @@
41 41 int for_gc;
42 42 };
43 43  
  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 +
44 62 /**
45 63 * nilfs_get_block() - get a file block on the filesystem (callback function)
46 64 * @inode - inode struct of the target file
... ... @@ -251,6 +251,8 @@
251 251 void **);
252 252  
253 253 /* inode.c */
  254 +void nilfs_inode_add_blocks(struct inode *inode, int n);
  255 +void nilfs_inode_sub_blocks(struct inode *inode, int n);
254 256 extern struct inode *nilfs_new_inode(struct inode *, int);
255 257 extern void nilfs_free_inode(struct inode *);
256 258 extern int nilfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
include/linux/nilfs2_fs.h
... ... @@ -216,8 +216,10 @@
216 216 * If there is a bit set in the incompatible feature set that the kernel
217 217 * doesn't know about, it should refuse to mount the filesystem.
218 218 */
  219 +#define NILFS_FEATURE_COMPAT_RO_BLOCK_COUNT 0x00000001ULL
  220 +
219 221 #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
221 223 #define NILFS_FEATURE_INCOMPAT_SUPP 0ULL
222 224  
223 225 /*
... ... @@ -509,7 +511,7 @@
509 511 __le64 cp_create;
510 512 __le64 cp_nblk_inc;
511 513 __le64 cp_inodes_count;
512   - __le64 cp_blocks_count; /* Reserved (might be deleted) */
  514 + __le64 cp_blocks_count;
513 515  
514 516 /* Do not change the byte offset of ifile inode.
515 517 To keep the compatibility of the disk format,