Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ryusuke/nilfs2

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/ryusuke/nilfs2: (23 commits)
nilfs2: disallow remount of snapshot from/to a regular mount
nilfs2: use huge_encode_dev/huge_decode_dev
nilfs2: update comment on deactivate_super at nilfs_get_sb
nilfs2: replace MS_VERBOSE with MS_SILENT
nilfs2: add missing initialization of s_mode
nilfs2: fix misuse of open_bdev_exclusive/close_bdev_exclusive
nilfs2: enlarge s_volume_name member in nilfs_super_block
nilfs2: use checkpoint number instead of timestamp to select super block
nilfs2: add missing endian conversion on super block magic number
nilfs2: make nilfs_sc_*_ops static
nilfs2: add kernel doc comments to persistent object allocator functions
nilfs2: change sc_timer from a pointer to an embedded one in struct nilfs_sc_info
nilfs2: remove nilfs_segctor_init() in segment.c
nilfs2: insert checkpoint number in segment summary header
nilfs2: add a print message after loading nilfs2
nilfs2: cleanup multi kmem_cache_{create,destroy} code
nilfs2: move out checksum routines to segment buffer code
nilfs2: move pointer to super root block into logs
nilfs2: change default of 'errors' mount option to 'remount-ro' mode
nilfs2: Combine nilfs_btree_release_path() and nilfs_btree_free_path()
...

+424 -351
+2 -2
Documentation/filesystems/nilfs2.txt
··· 50 50 (*) == default 51 51 52 52 nobarrier Disables barriers. 53 - errors=continue(*) Keep going on a filesystem error. 54 - errors=remount-ro Remount the filesystem read-only on an error. 53 + errors=continue Keep going on a filesystem error. 54 + errors=remount-ro(*) Remount the filesystem read-only on an error. 55 55 errors=panic Panic and halt the machine if an error occurs. 56 56 cp=n Specify the checkpoint-number of the snapshot to be 57 57 mounted. Checkpoints and snapshots are listed by lscp
+153 -1
fs/nilfs2/alloc.c
··· 31 31 #include "alloc.h" 32 32 33 33 34 + /** 35 + * nilfs_palloc_groups_per_desc_block - get the number of groups that a group 36 + * descriptor block can maintain 37 + * @inode: inode of metadata file using this allocator 38 + */ 34 39 static inline unsigned long 35 40 nilfs_palloc_groups_per_desc_block(const struct inode *inode) 36 41 { ··· 43 38 sizeof(struct nilfs_palloc_group_desc); 44 39 } 45 40 41 + /** 42 + * nilfs_palloc_groups_count - get maximum number of groups 43 + * @inode: inode of metadata file using this allocator 44 + */ 46 45 static inline unsigned long 47 46 nilfs_palloc_groups_count(const struct inode *inode) 48 47 { 49 48 return 1UL << (BITS_PER_LONG - (inode->i_blkbits + 3 /* log2(8) */)); 50 49 } 51 50 51 + /** 52 + * nilfs_palloc_init_blockgroup - initialize private variables for allocator 53 + * @inode: inode of metadata file using this allocator 54 + * @entry_size: size of the persistent object 55 + */ 52 56 int nilfs_palloc_init_blockgroup(struct inode *inode, unsigned entry_size) 53 57 { 54 58 struct nilfs_mdt_info *mi = NILFS_MDT(inode); ··· 83 69 return 0; 84 70 } 85 71 72 + /** 73 + * nilfs_palloc_group - get group number and offset from an entry number 74 + * @inode: inode of metadata file using this allocator 75 + * @nr: serial number of the entry (e.g. inode number) 76 + * @offset: pointer to store offset number in the group 77 + */ 86 78 static unsigned long nilfs_palloc_group(const struct inode *inode, __u64 nr, 87 79 unsigned long *offset) 88 80 { ··· 98 78 return group; 99 79 } 100 80 81 + /** 82 + * nilfs_palloc_desc_blkoff - get block offset of a group descriptor block 83 + * @inode: inode of metadata file using this allocator 84 + * @group: group number 85 + * 86 + * nilfs_palloc_desc_blkoff() returns block offset of the descriptor 87 + * block which contains a descriptor of the specified group. 88 + */ 101 89 static unsigned long 102 90 nilfs_palloc_desc_blkoff(const struct inode *inode, unsigned long group) 103 91 { ··· 114 86 return desc_block * NILFS_MDT(inode)->mi_blocks_per_desc_block; 115 87 } 116 88 89 + /** 90 + * nilfs_palloc_bitmap_blkoff - get block offset of a bitmap block 91 + * @inode: inode of metadata file using this allocator 92 + * @group: group number 93 + * 94 + * nilfs_palloc_bitmap_blkoff() returns block offset of the bitmap 95 + * block used to allocate/deallocate entries in the specified group. 96 + */ 117 97 static unsigned long 118 98 nilfs_palloc_bitmap_blkoff(const struct inode *inode, unsigned long group) 119 99 { ··· 131 95 desc_offset * NILFS_MDT(inode)->mi_blocks_per_group; 132 96 } 133 97 98 + /** 99 + * nilfs_palloc_group_desc_nfrees - get the number of free entries in a group 100 + * @inode: inode of metadata file using this allocator 101 + * @group: group number 102 + * @desc: pointer to descriptor structure for the group 103 + */ 134 104 static unsigned long 135 105 nilfs_palloc_group_desc_nfrees(struct inode *inode, unsigned long group, 136 106 const struct nilfs_palloc_group_desc *desc) ··· 149 107 return nfree; 150 108 } 151 109 110 + /** 111 + * nilfs_palloc_group_desc_add_entries - adjust count of free entries 112 + * @inode: inode of metadata file using this allocator 113 + * @group: group number 114 + * @desc: pointer to descriptor structure for the group 115 + * @n: delta to be added 116 + */ 152 117 static void 153 118 nilfs_palloc_group_desc_add_entries(struct inode *inode, 154 119 unsigned long group, ··· 167 118 spin_unlock(nilfs_mdt_bgl_lock(inode, group)); 168 119 } 169 120 121 + /** 122 + * nilfs_palloc_entry_blkoff - get block offset of an entry block 123 + * @inode: inode of metadata file using this allocator 124 + * @nr: serial number of the entry (e.g. inode number) 125 + */ 170 126 static unsigned long 171 127 nilfs_palloc_entry_blkoff(const struct inode *inode, __u64 nr) 172 128 { ··· 183 129 group_offset / NILFS_MDT(inode)->mi_entries_per_block; 184 130 } 185 131 132 + /** 133 + * nilfs_palloc_desc_block_init - initialize buffer of a group descriptor block 134 + * @inode: inode of metadata file 135 + * @bh: buffer head of the buffer to be initialized 136 + * @kaddr: kernel address mapped for the page including the buffer 137 + */ 186 138 static void nilfs_palloc_desc_block_init(struct inode *inode, 187 139 struct buffer_head *bh, void *kaddr) 188 140 { ··· 239 179 return ret; 240 180 } 241 181 182 + /** 183 + * nilfs_palloc_get_desc_block - get buffer head of a group descriptor block 184 + * @inode: inode of metadata file using this allocator 185 + * @group: group number 186 + * @create: create flag 187 + * @bhp: pointer to store the resultant buffer head 188 + */ 242 189 static int nilfs_palloc_get_desc_block(struct inode *inode, 243 190 unsigned long group, 244 191 int create, struct buffer_head **bhp) ··· 258 191 bhp, &cache->prev_desc, &cache->lock); 259 192 } 260 193 194 + /** 195 + * nilfs_palloc_get_bitmap_block - get buffer head of a bitmap block 196 + * @inode: inode of metadata file using this allocator 197 + * @group: group number 198 + * @create: create flag 199 + * @bhp: pointer to store the resultant buffer head 200 + */ 261 201 static int nilfs_palloc_get_bitmap_block(struct inode *inode, 262 202 unsigned long group, 263 203 int create, struct buffer_head **bhp) ··· 277 203 &cache->prev_bitmap, &cache->lock); 278 204 } 279 205 206 + /** 207 + * nilfs_palloc_get_entry_block - get buffer head of an entry block 208 + * @inode: inode of metadata file using this allocator 209 + * @nr: serial number of the entry (e.g. inode number) 210 + * @create: create flag 211 + * @bhp: pointer to store the resultant buffer head 212 + */ 280 213 int nilfs_palloc_get_entry_block(struct inode *inode, __u64 nr, 281 214 int create, struct buffer_head **bhp) 282 215 { ··· 295 214 &cache->prev_entry, &cache->lock); 296 215 } 297 216 217 + /** 218 + * nilfs_palloc_block_get_group_desc - get kernel address of a group descriptor 219 + * @inode: inode of metadata file using this allocator 220 + * @group: group number 221 + * @bh: buffer head of the buffer storing the group descriptor block 222 + * @kaddr: kernel address mapped for the page including the buffer 223 + */ 298 224 static struct nilfs_palloc_group_desc * 299 225 nilfs_palloc_block_get_group_desc(const struct inode *inode, 300 226 unsigned long group, ··· 311 223 group % nilfs_palloc_groups_per_desc_block(inode); 312 224 } 313 225 226 + /** 227 + * nilfs_palloc_block_get_entry - get kernel address of an entry 228 + * @inode: inode of metadata file using this allocator 229 + * @nr: serial number of the entry (e.g. inode number) 230 + * @bh: buffer head of the buffer storing the entry block 231 + * @kaddr: kernel address mapped for the page including the buffer 232 + */ 314 233 void *nilfs_palloc_block_get_entry(const struct inode *inode, __u64 nr, 315 234 const struct buffer_head *bh, void *kaddr) 316 235 { ··· 330 235 entry_offset * NILFS_MDT(inode)->mi_entry_size; 331 236 } 332 237 238 + /** 239 + * nilfs_palloc_find_available_slot - find available slot in a group 240 + * @inode: inode of metadata file using this allocator 241 + * @group: group number 242 + * @target: offset number of an entry in the group (start point) 243 + * @bitmap: bitmap of the group 244 + * @bsize: size in bits 245 + */ 333 246 static int nilfs_palloc_find_available_slot(struct inode *inode, 334 247 unsigned long group, 335 248 unsigned long target, 336 249 unsigned char *bitmap, 337 - int bsize) /* size in bits */ 250 + int bsize) 338 251 { 339 252 int curr, pos, end, i; 340 253 ··· 380 277 return -ENOSPC; 381 278 } 382 279 280 + /** 281 + * nilfs_palloc_rest_groups_in_desc_block - get the remaining number of groups 282 + * in a group descriptor block 283 + * @inode: inode of metadata file using this allocator 284 + * @curr: current group number 285 + * @max: maximum number of groups 286 + */ 383 287 static unsigned long 384 288 nilfs_palloc_rest_groups_in_desc_block(const struct inode *inode, 385 289 unsigned long curr, unsigned long max) ··· 397 287 max - curr + 1); 398 288 } 399 289 290 + /** 291 + * nilfs_palloc_prepare_alloc_entry - prepare to allocate a persistent object 292 + * @inode: inode of metadata file using this allocator 293 + * @req: nilfs_palloc_req structure exchanged for the allocation 294 + */ 400 295 int nilfs_palloc_prepare_alloc_entry(struct inode *inode, 401 296 struct nilfs_palloc_req *req) 402 297 { ··· 481 366 return ret; 482 367 } 483 368 369 + /** 370 + * nilfs_palloc_commit_alloc_entry - finish allocation of a persistent object 371 + * @inode: inode of metadata file using this allocator 372 + * @req: nilfs_palloc_req structure exchanged for the allocation 373 + */ 484 374 void nilfs_palloc_commit_alloc_entry(struct inode *inode, 485 375 struct nilfs_palloc_req *req) 486 376 { ··· 497 377 brelse(req->pr_desc_bh); 498 378 } 499 379 380 + /** 381 + * nilfs_palloc_commit_free_entry - finish deallocating a persistent object 382 + * @inode: inode of metadata file using this allocator 383 + * @req: nilfs_palloc_req structure exchanged for the removal 384 + */ 500 385 void nilfs_palloc_commit_free_entry(struct inode *inode, 501 386 struct nilfs_palloc_req *req) 502 387 { ··· 535 410 brelse(req->pr_desc_bh); 536 411 } 537 412 413 + /** 414 + * nilfs_palloc_abort_alloc_entry - cancel allocation of a persistent object 415 + * @inode: inode of metadata file using this allocator 416 + * @req: nilfs_palloc_req structure exchanged for the allocation 417 + */ 538 418 void nilfs_palloc_abort_alloc_entry(struct inode *inode, 539 419 struct nilfs_palloc_req *req) 540 420 { ··· 572 442 req->pr_desc_bh = NULL; 573 443 } 574 444 445 + /** 446 + * nilfs_palloc_prepare_free_entry - prepare to deallocate a persistent object 447 + * @inode: inode of metadata file using this allocator 448 + * @req: nilfs_palloc_req structure exchanged for the removal 449 + */ 575 450 int nilfs_palloc_prepare_free_entry(struct inode *inode, 576 451 struct nilfs_palloc_req *req) 577 452 { ··· 599 464 return 0; 600 465 } 601 466 467 + /** 468 + * nilfs_palloc_abort_free_entry - cancel deallocating a persistent object 469 + * @inode: inode of metadata file using this allocator 470 + * @req: nilfs_palloc_req structure exchanged for the removal 471 + */ 602 472 void nilfs_palloc_abort_free_entry(struct inode *inode, 603 473 struct nilfs_palloc_req *req) 604 474 { ··· 615 475 req->pr_desc_bh = NULL; 616 476 } 617 477 478 + /** 479 + * nilfs_palloc_group_is_in - judge if an entry is in a group 480 + * @inode: inode of metadata file using this allocator 481 + * @group: group number 482 + * @nr: serial number of the entry (e.g. inode number) 483 + */ 618 484 static int 619 485 nilfs_palloc_group_is_in(struct inode *inode, unsigned long group, __u64 nr) 620 486 { ··· 631 485 return (nr >= first) && (nr <= last); 632 486 } 633 487 488 + /** 489 + * nilfs_palloc_freev - deallocate a set of persistent objects 490 + * @inode: inode of metadata file using this allocator 491 + * @entry_nrs: array of entry numbers to be deallocated 492 + * @nitems: number of entries stored in @entry_nrs 493 + */ 634 494 int nilfs_palloc_freev(struct inode *inode, __u64 *entry_nrs, size_t nitems) 635 495 { 636 496 struct buffer_head *desc_bh, *bitmap_bh;
+7
fs/nilfs2/alloc.h
··· 29 29 #include <linux/buffer_head.h> 30 30 #include <linux/fs.h> 31 31 32 + /** 33 + * nilfs_palloc_entries_per_group - get the number of entries per group 34 + * @inode: inode of metadata file using this allocator 35 + * 36 + * The number of entries per group is defined by the number of bits 37 + * that a bitmap block can maintain. 38 + */ 32 39 static inline unsigned long 33 40 nilfs_palloc_entries_per_group(const struct inode *inode) 34 41 {
+17 -74
fs/nilfs2/btree.c
··· 31 31 #include "alloc.h" 32 32 #include "dat.h" 33 33 34 - /** 35 - * struct nilfs_btree_path - A path on which B-tree operations are executed 36 - * @bp_bh: buffer head of node block 37 - * @bp_sib_bh: buffer head of sibling node block 38 - * @bp_index: index of child node 39 - * @bp_oldreq: ptr end request for old ptr 40 - * @bp_newreq: ptr alloc request for new ptr 41 - * @bp_op: rebalance operation 42 - */ 43 - struct nilfs_btree_path { 44 - struct buffer_head *bp_bh; 45 - struct buffer_head *bp_sib_bh; 46 - int bp_index; 47 - union nilfs_bmap_ptr_req bp_oldreq; 48 - union nilfs_bmap_ptr_req bp_newreq; 49 - struct nilfs_btnode_chkey_ctxt bp_ctxt; 50 - void (*bp_op)(struct nilfs_btree *, struct nilfs_btree_path *, 51 - int, __u64 *, __u64 *); 52 - }; 53 - 54 - /* 55 - * B-tree path operations 56 - */ 57 - 58 - static struct kmem_cache *nilfs_btree_path_cache; 59 - 60 - int __init nilfs_btree_path_cache_init(void) 34 + static struct nilfs_btree_path *nilfs_btree_alloc_path(void) 61 35 { 62 - nilfs_btree_path_cache = 63 - kmem_cache_create("nilfs2_btree_path_cache", 64 - sizeof(struct nilfs_btree_path) * 65 - NILFS_BTREE_LEVEL_MAX, 0, 0, NULL); 66 - return (nilfs_btree_path_cache != NULL) ? 0 : -ENOMEM; 67 - } 36 + struct nilfs_btree_path *path; 37 + int level = NILFS_BTREE_LEVEL_DATA; 68 38 69 - void nilfs_btree_path_cache_destroy(void) 70 - { 71 - kmem_cache_destroy(nilfs_btree_path_cache); 72 - } 39 + path = kmem_cache_alloc(nilfs_btree_path_cache, GFP_NOFS); 40 + if (path == NULL) 41 + goto out; 73 42 74 - static inline struct nilfs_btree_path *nilfs_btree_alloc_path(void) 75 - { 76 - return kmem_cache_alloc(nilfs_btree_path_cache, GFP_NOFS); 77 - } 78 - 79 - static inline void nilfs_btree_free_path(struct nilfs_btree_path *path) 80 - { 81 - kmem_cache_free(nilfs_btree_path_cache, path); 82 - } 83 - 84 - static void nilfs_btree_init_path(struct nilfs_btree_path *path) 85 - { 86 - int level; 87 - 88 - for (level = NILFS_BTREE_LEVEL_DATA; 89 - level < NILFS_BTREE_LEVEL_MAX; 90 - level++) { 43 + for (; level < NILFS_BTREE_LEVEL_MAX; level++) { 91 44 path[level].bp_bh = NULL; 92 45 path[level].bp_sib_bh = NULL; 93 46 path[level].bp_index = 0; ··· 48 95 path[level].bp_newreq.bpr_ptr = NILFS_BMAP_INVALID_PTR; 49 96 path[level].bp_op = NULL; 50 97 } 98 + 99 + out: 100 + return path; 51 101 } 52 102 53 - static void nilfs_btree_release_path(struct nilfs_btree_path *path) 103 + static void nilfs_btree_free_path(struct nilfs_btree_path *path) 54 104 { 55 - int level; 105 + int level = NILFS_BTREE_LEVEL_DATA; 56 106 57 - for (level = NILFS_BTREE_LEVEL_DATA; level < NILFS_BTREE_LEVEL_MAX; 58 - level++) 107 + for (; level < NILFS_BTREE_LEVEL_MAX; level++) 59 108 brelse(path[level].bp_bh); 109 + 110 + kmem_cache_free(nilfs_btree_path_cache, path); 60 111 } 61 112 62 113 /* ··· 523 566 path = nilfs_btree_alloc_path(); 524 567 if (path == NULL) 525 568 return -ENOMEM; 526 - nilfs_btree_init_path(path); 527 569 528 570 ret = nilfs_btree_do_lookup(btree, path, key, &ptr, level); 529 571 530 572 if (ptrp != NULL) 531 573 *ptrp = ptr; 532 574 533 - nilfs_btree_release_path(path); 534 575 nilfs_btree_free_path(path); 535 576 536 577 return ret; ··· 549 594 path = nilfs_btree_alloc_path(); 550 595 if (path == NULL) 551 596 return -ENOMEM; 552 - nilfs_btree_init_path(path); 597 + 553 598 ret = nilfs_btree_do_lookup(btree, path, key, &ptr, level); 554 599 if (ret < 0) 555 600 goto out; ··· 610 655 *ptrp = ptr; 611 656 ret = cnt; 612 657 out: 613 - nilfs_btree_release_path(path); 614 658 nilfs_btree_free_path(path); 615 659 return ret; 616 660 } ··· 1077 1123 path = nilfs_btree_alloc_path(); 1078 1124 if (path == NULL) 1079 1125 return -ENOMEM; 1080 - nilfs_btree_init_path(path); 1081 1126 1082 1127 ret = nilfs_btree_do_lookup(btree, path, key, NULL, 1083 1128 NILFS_BTREE_LEVEL_NODE_MIN); ··· 1093 1140 nilfs_bmap_add_blocks(bmap, stats.bs_nblocks); 1094 1141 1095 1142 out: 1096 - nilfs_btree_release_path(path); 1097 1143 nilfs_btree_free_path(path); 1098 1144 return ret; 1099 1145 } ··· 1408 1456 path = nilfs_btree_alloc_path(); 1409 1457 if (path == NULL) 1410 1458 return -ENOMEM; 1411 - nilfs_btree_init_path(path); 1459 + 1412 1460 ret = nilfs_btree_do_lookup(btree, path, key, NULL, 1413 1461 NILFS_BTREE_LEVEL_NODE_MIN); 1414 1462 if (ret < 0) ··· 1425 1473 nilfs_bmap_sub_blocks(bmap, stats.bs_nblocks); 1426 1474 1427 1475 out: 1428 - nilfs_btree_release_path(path); 1429 1476 nilfs_btree_free_path(path); 1430 1477 return ret; 1431 1478 } ··· 1439 1488 path = nilfs_btree_alloc_path(); 1440 1489 if (path == NULL) 1441 1490 return -ENOMEM; 1442 - nilfs_btree_init_path(path); 1443 1491 1444 1492 ret = nilfs_btree_do_lookup_last(btree, path, keyp, NULL); 1445 1493 1446 - nilfs_btree_release_path(path); 1447 1494 nilfs_btree_free_path(path); 1448 1495 1449 1496 return ret; ··· 1872 1923 path = nilfs_btree_alloc_path(); 1873 1924 if (path == NULL) 1874 1925 return -ENOMEM; 1875 - nilfs_btree_init_path(path); 1876 1926 1877 1927 if (buffer_nilfs_node(bh)) { 1878 1928 node = (struct nilfs_btree_node *)bh->b_data; ··· 1895 1947 nilfs_btree_propagate_p(btree, path, level, bh); 1896 1948 1897 1949 out: 1898 - nilfs_btree_release_path(path); 1899 1950 nilfs_btree_free_path(path); 1900 1951 1901 1952 return ret; ··· 2055 2108 path = nilfs_btree_alloc_path(); 2056 2109 if (path == NULL) 2057 2110 return -ENOMEM; 2058 - nilfs_btree_init_path(path); 2059 2111 2060 2112 if (buffer_nilfs_node(*bh)) { 2061 2113 node = (struct nilfs_btree_node *)(*bh)->b_data; ··· 2076 2130 nilfs_btree_assign_p(btree, path, level, bh, blocknr, binfo); 2077 2131 2078 2132 out: 2079 - nilfs_btree_release_path(path); 2080 2133 nilfs_btree_free_path(path); 2081 2134 2082 2135 return ret; ··· 2120 2175 path = nilfs_btree_alloc_path(); 2121 2176 if (path == NULL) 2122 2177 return -ENOMEM; 2123 - nilfs_btree_init_path(path); 2124 2178 2125 2179 ret = nilfs_btree_do_lookup(btree, path, key, &ptr, level + 1); 2126 2180 if (ret < 0) { ··· 2139 2195 nilfs_bmap_set_dirty(&btree->bt_bmap); 2140 2196 2141 2197 out: 2142 - nilfs_btree_release_path(path); 2143 2198 nilfs_btree_free_path(path); 2144 2199 return ret; 2145 2200 }
+20 -3
fs/nilfs2/btree.h
··· 30 30 #include "btnode.h" 31 31 #include "bmap.h" 32 32 33 - struct nilfs_btree; 34 - struct nilfs_btree_path; 35 - 36 33 /** 37 34 * struct nilfs_btree - B-tree structure 38 35 * @bt_bmap: bmap base structure ··· 38 41 struct nilfs_bmap bt_bmap; 39 42 }; 40 43 44 + /** 45 + * struct nilfs_btree_path - A path on which B-tree operations are executed 46 + * @bp_bh: buffer head of node block 47 + * @bp_sib_bh: buffer head of sibling node block 48 + * @bp_index: index of child node 49 + * @bp_oldreq: ptr end request for old ptr 50 + * @bp_newreq: ptr alloc request for new ptr 51 + * @bp_op: rebalance operation 52 + */ 53 + struct nilfs_btree_path { 54 + struct buffer_head *bp_bh; 55 + struct buffer_head *bp_sib_bh; 56 + int bp_index; 57 + union nilfs_bmap_ptr_req bp_oldreq; 58 + union nilfs_bmap_ptr_req bp_newreq; 59 + struct nilfs_btnode_chkey_ctxt bp_ctxt; 60 + void (*bp_op)(struct nilfs_btree *, struct nilfs_btree_path *, 61 + int, __u64 *, __u64 *); 62 + }; 41 63 42 64 #define NILFS_BTREE_ROOT_SIZE NILFS_BMAP_SIZE 43 65 #define NILFS_BTREE_ROOT_NCHILDREN_MAX \ ··· 73 57 #define NILFS_BTREE_KEY_MIN ((__u64)0) 74 58 #define NILFS_BTREE_KEY_MAX (~(__u64)0) 75 59 60 + extern struct kmem_cache *nilfs_btree_path_cache; 76 61 77 62 int nilfs_btree_path_cache_init(void); 78 63 void nilfs_btree_path_cache_destroy(void);
+2 -2
fs/nilfs2/inode.c
··· 451 451 inode->i_op = &nilfs_special_inode_operations; 452 452 init_special_inode( 453 453 inode, inode->i_mode, 454 - new_decode_dev(le64_to_cpu(raw_inode->i_device_code))); 454 + huge_decode_dev(le64_to_cpu(raw_inode->i_device_code))); 455 455 } 456 456 nilfs_ifile_unmap_inode(sbi->s_ifile, ino, bh); 457 457 brelse(bh); ··· 511 511 nilfs_bmap_write(ii->i_bmap, raw_inode); 512 512 else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) 513 513 raw_inode->i_device_code = 514 - cpu_to_le64(new_encode_dev(inode->i_rdev)); 514 + cpu_to_le64(huge_encode_dev(inode->i_rdev)); 515 515 /* When extending inode, nilfs->ns_inode_size should be checked 516 516 for substitutions of appended fields */ 517 517 }
+2
fs/nilfs2/recovery.c
··· 105 105 106 106 ssi->nsumblk = DIV_ROUND_UP(ssi->sumbytes, blocksize); 107 107 ssi->nfileblk = ssi->nblocks - ssi->nsumblk - !!NILFS_SEG_HAS_SR(ssi); 108 + 109 + /* need to verify ->ss_bytes field if read ->ss_cno */ 108 110 } 109 111 110 112 /**
+40 -30
fs/nilfs2/segbuf.c
··· 40 40 sector_t blocknr; 41 41 }; 42 42 43 - 44 43 static int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf, 45 44 struct the_nilfs *nilfs); 46 45 static int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf); 47 - 48 - 49 - static struct kmem_cache *nilfs_segbuf_cachep; 50 - 51 - static void nilfs_segbuf_init_once(void *obj) 52 - { 53 - memset(obj, 0, sizeof(struct nilfs_segment_buffer)); 54 - } 55 - 56 - int __init nilfs_init_segbuf_cache(void) 57 - { 58 - nilfs_segbuf_cachep = 59 - kmem_cache_create("nilfs2_segbuf_cache", 60 - sizeof(struct nilfs_segment_buffer), 61 - 0, SLAB_RECLAIM_ACCOUNT, 62 - nilfs_segbuf_init_once); 63 - 64 - return (nilfs_segbuf_cachep == NULL) ? -ENOMEM : 0; 65 - } 66 - 67 - void nilfs_destroy_segbuf_cache(void) 68 - { 69 - kmem_cache_destroy(nilfs_segbuf_cachep); 70 - } 71 46 72 47 struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *sb) 73 48 { ··· 56 81 INIT_LIST_HEAD(&segbuf->sb_list); 57 82 INIT_LIST_HEAD(&segbuf->sb_segsum_buffers); 58 83 INIT_LIST_HEAD(&segbuf->sb_payload_buffers); 84 + segbuf->sb_super_root = NULL; 59 85 60 86 init_completion(&segbuf->sb_bio_event); 61 87 atomic_set(&segbuf->sb_err, 0); ··· 134 158 } 135 159 136 160 int nilfs_segbuf_reset(struct nilfs_segment_buffer *segbuf, unsigned flags, 137 - time_t ctime) 161 + time_t ctime, __u64 cno) 138 162 { 139 163 int err; 140 164 ··· 147 171 segbuf->sb_sum.sumbytes = sizeof(struct nilfs_segment_summary); 148 172 segbuf->sb_sum.nfinfo = segbuf->sb_sum.nfileblk = 0; 149 173 segbuf->sb_sum.ctime = ctime; 174 + segbuf->sb_sum.cno = cno; 150 175 return 0; 151 176 } 152 177 ··· 173 196 raw_sum->ss_nfinfo = cpu_to_le32(segbuf->sb_sum.nfinfo); 174 197 raw_sum->ss_sumbytes = cpu_to_le32(segbuf->sb_sum.sumbytes); 175 198 raw_sum->ss_pad = 0; 199 + raw_sum->ss_cno = cpu_to_le64(segbuf->sb_sum.cno); 176 200 } 177 201 178 202 /* 179 203 * CRC calculation routines 180 204 */ 181 - void nilfs_segbuf_fill_in_segsum_crc(struct nilfs_segment_buffer *segbuf, 182 - u32 seed) 205 + static void 206 + nilfs_segbuf_fill_in_segsum_crc(struct nilfs_segment_buffer *segbuf, u32 seed) 183 207 { 184 208 struct buffer_head *bh; 185 209 struct nilfs_segment_summary *raw_sum; ··· 207 229 raw_sum->ss_sumsum = cpu_to_le32(crc); 208 230 } 209 231 210 - void nilfs_segbuf_fill_in_data_crc(struct nilfs_segment_buffer *segbuf, 211 - u32 seed) 232 + static void nilfs_segbuf_fill_in_data_crc(struct nilfs_segment_buffer *segbuf, 233 + u32 seed) 212 234 { 213 235 struct buffer_head *bh; 214 236 struct nilfs_segment_summary *raw_sum; ··· 232 254 kunmap_atomic(kaddr, KM_USER0); 233 255 } 234 256 raw_sum->ss_datasum = cpu_to_le32(crc); 257 + } 258 + 259 + static void 260 + nilfs_segbuf_fill_in_super_root_crc(struct nilfs_segment_buffer *segbuf, 261 + u32 seed) 262 + { 263 + struct nilfs_super_root *raw_sr; 264 + u32 crc; 265 + 266 + raw_sr = (struct nilfs_super_root *)segbuf->sb_super_root->b_data; 267 + crc = crc32_le(seed, 268 + (unsigned char *)raw_sr + sizeof(raw_sr->sr_sum), 269 + NILFS_SR_BYTES - sizeof(raw_sr->sr_sum)); 270 + raw_sr->sr_sum = cpu_to_le32(crc); 235 271 } 236 272 237 273 static void nilfs_release_buffers(struct list_head *list) ··· 274 282 { 275 283 nilfs_release_buffers(&segbuf->sb_segsum_buffers); 276 284 nilfs_release_buffers(&segbuf->sb_payload_buffers); 285 + segbuf->sb_super_root = NULL; 277 286 } 278 287 279 288 /* ··· 325 332 ret = err; 326 333 } 327 334 return ret; 335 + } 336 + 337 + /** 338 + * nilfs_add_checksums_on_logs - add checksums on the logs 339 + * @logs: list of segment buffers storing target logs 340 + * @seed: checksum seed value 341 + */ 342 + void nilfs_add_checksums_on_logs(struct list_head *logs, u32 seed) 343 + { 344 + struct nilfs_segment_buffer *segbuf; 345 + 346 + list_for_each_entry(segbuf, logs, sb_list) { 347 + if (segbuf->sb_super_root) 348 + nilfs_segbuf_fill_in_super_root_crc(segbuf, seed); 349 + nilfs_segbuf_fill_in_segsum_crc(segbuf, seed); 350 + nilfs_segbuf_fill_in_data_crc(segbuf, seed); 351 + } 328 352 } 329 353 330 354 /*
+7 -3
fs/nilfs2/segbuf.h
··· 37 37 * @sumbytes: Byte count of segment summary 38 38 * @nfileblk: Total number of file blocks 39 39 * @seg_seq: Segment sequence number 40 + * @cno: Checkpoint number 40 41 * @ctime: Creation time 41 42 * @next: Block number of the next full segment 42 43 */ ··· 49 48 unsigned long sumbytes; 50 49 unsigned long nfileblk; 51 50 u64 seg_seq; 51 + __u64 cno; 52 52 time_t ctime; 53 53 sector_t next; 54 54 }; ··· 78 76 * @sb_rest_blocks: Number of residual blocks in the current segment 79 77 * @sb_segsum_buffers: List of buffers for segment summaries 80 78 * @sb_payload_buffers: List of buffers for segment payload 79 + * @sb_super_root: Pointer to buffer storing a super root block (if exists) 81 80 * @sb_nbio: Number of flying bio requests 82 81 * @sb_err: I/O error status 83 82 * @sb_bio_event: Completion event of log writing ··· 98 95 /* Buffers */ 99 96 struct list_head sb_segsum_buffers; 100 97 struct list_head sb_payload_buffers; /* including super root */ 98 + struct buffer_head *sb_super_root; 101 99 102 100 /* io status */ 103 101 int sb_nbio; ··· 125 121 b_assoc_buffers)) 126 122 #define NILFS_SEGBUF_BH_IS_LAST(bh, head) ((bh)->b_assoc_buffers.next == head) 127 123 124 + extern struct kmem_cache *nilfs_segbuf_cachep; 128 125 129 126 int __init nilfs_init_segbuf_cache(void); 130 127 void nilfs_destroy_segbuf_cache(void); ··· 137 132 struct nilfs_segment_buffer *prev); 138 133 void nilfs_segbuf_set_next_segnum(struct nilfs_segment_buffer *, __u64, 139 134 struct the_nilfs *); 140 - int nilfs_segbuf_reset(struct nilfs_segment_buffer *, unsigned, time_t); 135 + int nilfs_segbuf_reset(struct nilfs_segment_buffer *, unsigned, time_t, __u64); 141 136 int nilfs_segbuf_extend_segsum(struct nilfs_segment_buffer *); 142 137 int nilfs_segbuf_extend_payload(struct nilfs_segment_buffer *, 143 138 struct buffer_head **); 144 139 void nilfs_segbuf_fill_in_segsum(struct nilfs_segment_buffer *); 145 - void nilfs_segbuf_fill_in_segsum_crc(struct nilfs_segment_buffer *, u32); 146 - void nilfs_segbuf_fill_in_data_crc(struct nilfs_segment_buffer *, u32); 147 140 148 141 static inline void 149 142 nilfs_segbuf_add_segsum_buffer(struct nilfs_segment_buffer *segbuf, ··· 174 171 struct nilfs_segment_buffer *last); 175 172 int nilfs_write_logs(struct list_head *logs, struct the_nilfs *nilfs); 176 173 int nilfs_wait_on_logs(struct list_head *logs); 174 + void nilfs_add_checksums_on_logs(struct list_head *logs, u32 seed); 177 175 178 176 static inline void nilfs_destroy_logs(struct list_head *logs) 179 177 {
+40 -117
fs/nilfs2/segment.c
··· 116 116 #define nilfs_cnt32_lt(a, b) nilfs_cnt32_gt(b, a) 117 117 #define nilfs_cnt32_le(a, b) nilfs_cnt32_ge(b, a) 118 118 119 - /* 120 - * Transaction 121 - */ 122 - static struct kmem_cache *nilfs_transaction_cachep; 123 - 124 - /** 125 - * nilfs_init_transaction_cache - create a cache for nilfs_transaction_info 126 - * 127 - * nilfs_init_transaction_cache() creates a slab cache for the struct 128 - * nilfs_transaction_info. 129 - * 130 - * Return Value: On success, it returns 0. On error, one of the following 131 - * negative error code is returned. 132 - * 133 - * %-ENOMEM - Insufficient memory available. 134 - */ 135 - int nilfs_init_transaction_cache(void) 136 - { 137 - nilfs_transaction_cachep = 138 - kmem_cache_create("nilfs2_transaction_cache", 139 - sizeof(struct nilfs_transaction_info), 140 - 0, SLAB_RECLAIM_ACCOUNT, NULL); 141 - return (nilfs_transaction_cachep == NULL) ? -ENOMEM : 0; 142 - } 143 - 144 - /** 145 - * nilfs_destroy_transaction_cache - destroy the cache for transaction info 146 - * 147 - * nilfs_destroy_transaction_cache() frees the slab cache for the struct 148 - * nilfs_transaction_info. 149 - */ 150 - void nilfs_destroy_transaction_cache(void) 151 - { 152 - kmem_cache_destroy(nilfs_transaction_cachep); 153 - } 154 - 155 119 static int nilfs_prepare_segment_lock(struct nilfs_transaction_info *ti) 156 120 { 157 121 struct nilfs_transaction_info *cur_ti = current->journal_info; ··· 366 402 367 403 if (nilfs_doing_gc()) 368 404 flags = NILFS_SS_GC; 369 - err = nilfs_segbuf_reset(segbuf, flags, sci->sc_seg_ctime); 405 + err = nilfs_segbuf_reset(segbuf, flags, sci->sc_seg_ctime, 406 + sci->sc_sbi->s_nilfs->ns_cno); 370 407 if (unlikely(err)) 371 408 return err; 372 409 ··· 400 435 return err; 401 436 segbuf = sci->sc_curseg; 402 437 } 403 - err = nilfs_segbuf_extend_payload(segbuf, &sci->sc_super_root); 438 + err = nilfs_segbuf_extend_payload(segbuf, &segbuf->sb_super_root); 404 439 if (likely(!err)) 405 440 segbuf->sb_sum.flags |= NILFS_SS_SR; 406 441 return err; ··· 564 599 *vblocknr = binfo->bi_v.bi_vblocknr; 565 600 } 566 601 567 - struct nilfs_sc_operations nilfs_sc_file_ops = { 602 + static struct nilfs_sc_operations nilfs_sc_file_ops = { 568 603 .collect_data = nilfs_collect_file_data, 569 604 .collect_node = nilfs_collect_file_node, 570 605 .collect_bmap = nilfs_collect_file_bmap, ··· 614 649 *binfo_dat = binfo->bi_dat; 615 650 } 616 651 617 - struct nilfs_sc_operations nilfs_sc_dat_ops = { 652 + static struct nilfs_sc_operations nilfs_sc_dat_ops = { 618 653 .collect_data = nilfs_collect_dat_data, 619 654 .collect_node = nilfs_collect_file_node, 620 655 .collect_bmap = nilfs_collect_dat_bmap, ··· 622 657 .write_node_binfo = nilfs_write_dat_node_binfo, 623 658 }; 624 659 625 - struct nilfs_sc_operations nilfs_sc_dsync_ops = { 660 + static struct nilfs_sc_operations nilfs_sc_dsync_ops = { 626 661 .collect_data = nilfs_collect_file_data, 627 662 .collect_node = NULL, 628 663 .collect_bmap = NULL, ··· 897 932 } 898 933 } 899 934 900 - /* 901 - * CRC calculation routines 902 - */ 903 - static void nilfs_fill_in_super_root_crc(struct buffer_head *bh_sr, u32 seed) 904 - { 905 - struct nilfs_super_root *raw_sr = 906 - (struct nilfs_super_root *)bh_sr->b_data; 907 - u32 crc; 908 - 909 - crc = crc32_le(seed, 910 - (unsigned char *)raw_sr + sizeof(raw_sr->sr_sum), 911 - NILFS_SR_BYTES - sizeof(raw_sr->sr_sum)); 912 - raw_sr->sr_sum = cpu_to_le32(crc); 913 - } 914 - 915 - static void nilfs_segctor_fill_in_checksums(struct nilfs_sc_info *sci, 916 - u32 seed) 917 - { 918 - struct nilfs_segment_buffer *segbuf; 919 - 920 - if (sci->sc_super_root) 921 - nilfs_fill_in_super_root_crc(sci->sc_super_root, seed); 922 - 923 - list_for_each_entry(segbuf, &sci->sc_segbufs, sb_list) { 924 - nilfs_segbuf_fill_in_segsum_crc(segbuf, seed); 925 - nilfs_segbuf_fill_in_data_crc(segbuf, seed); 926 - } 927 - } 928 - 929 935 static void nilfs_segctor_fill_in_super_root(struct nilfs_sc_info *sci, 930 936 struct the_nilfs *nilfs) 931 937 { 932 - struct buffer_head *bh_sr = sci->sc_super_root; 933 - struct nilfs_super_root *raw_sr = 934 - (struct nilfs_super_root *)bh_sr->b_data; 938 + struct buffer_head *bh_sr; 939 + struct nilfs_super_root *raw_sr; 935 940 unsigned isz = nilfs->ns_inode_size; 941 + 942 + bh_sr = NILFS_LAST_SEGBUF(&sci->sc_segbufs)->sb_super_root; 943 + raw_sr = (struct nilfs_super_root *)bh_sr->b_data; 936 944 937 945 raw_sr->sr_bytes = cpu_to_le16(NILFS_SR_BYTES); 938 946 raw_sr->sr_nongc_ctime ··· 1429 1491 1430 1492 /* Collection retry loop */ 1431 1493 for (;;) { 1432 - sci->sc_super_root = NULL; 1433 1494 sci->sc_nblk_this_inc = 0; 1434 1495 sci->sc_curseg = NILFS_FIRST_SEGBUF(&sci->sc_segbufs); 1435 1496 ··· 1505 1568 ssp.offset = sizeof(struct nilfs_segment_summary); 1506 1569 1507 1570 list_for_each_entry(bh, &segbuf->sb_payload_buffers, b_assoc_buffers) { 1508 - if (bh == sci->sc_super_root) 1571 + if (bh == segbuf->sb_super_root) 1509 1572 break; 1510 1573 if (!finfo) { 1511 1574 finfo = nilfs_segctor_map_segsum_entry( ··· 1666 1729 1667 1730 list_for_each_entry(bh, &segbuf->sb_payload_buffers, 1668 1731 b_assoc_buffers) { 1669 - if (bh == sci->sc_super_root) { 1732 + if (bh == segbuf->sb_super_root) { 1670 1733 if (bh->b_page != bd_page) { 1671 1734 lock_page(bd_page); 1672 1735 clear_page_dirty_for_io(bd_page); ··· 1785 1848 } 1786 1849 1787 1850 static void nilfs_abort_logs(struct list_head *logs, struct page *failed_page, 1788 - struct buffer_head *bh_sr, int err) 1851 + int err) 1789 1852 { 1790 1853 struct nilfs_segment_buffer *segbuf; 1791 1854 struct page *bd_page = NULL, *fs_page = NULL; ··· 1806 1869 1807 1870 list_for_each_entry(bh, &segbuf->sb_payload_buffers, 1808 1871 b_assoc_buffers) { 1809 - if (bh == bh_sr) { 1872 + if (bh == segbuf->sb_super_root) { 1810 1873 if (bh->b_page != bd_page) { 1811 1874 end_page_writeback(bd_page); 1812 1875 bd_page = bh->b_page; ··· 1835 1898 1836 1899 list_splice_tail_init(&sci->sc_write_logs, &logs); 1837 1900 ret = nilfs_wait_on_logs(&logs); 1838 - nilfs_abort_logs(&logs, NULL, sci->sc_super_root, ret ? : err); 1901 + nilfs_abort_logs(&logs, NULL, ret ? : err); 1839 1902 1840 1903 list_splice_tail_init(&sci->sc_segbufs, &logs); 1841 1904 nilfs_cancel_segusage(&logs, nilfs->ns_sufile); ··· 1851 1914 } 1852 1915 1853 1916 nilfs_destroy_logs(&logs); 1854 - sci->sc_super_root = NULL; 1855 1917 } 1856 1918 1857 1919 static void nilfs_set_next_segment(struct the_nilfs *nilfs, ··· 1869 1933 struct nilfs_segment_buffer *segbuf; 1870 1934 struct page *bd_page = NULL, *fs_page = NULL; 1871 1935 struct the_nilfs *nilfs = sci->sc_sbi->s_nilfs; 1872 - int update_sr = (sci->sc_super_root != NULL); 1936 + int update_sr = false; 1873 1937 1874 1938 list_for_each_entry(segbuf, &sci->sc_write_logs, sb_list) { 1875 1939 struct buffer_head *bh; ··· 1900 1964 set_buffer_uptodate(bh); 1901 1965 clear_buffer_dirty(bh); 1902 1966 clear_buffer_nilfs_volatile(bh); 1903 - if (bh == sci->sc_super_root) { 1967 + if (bh == segbuf->sb_super_root) { 1904 1968 if (bh->b_page != bd_page) { 1905 1969 end_page_writeback(bd_page); 1906 1970 bd_page = bh->b_page; 1907 1971 } 1972 + update_sr = true; 1908 1973 break; 1909 1974 } 1910 1975 if (bh->b_page != fs_page) { ··· 2052 2115 struct nilfs_sb_info *sbi = sci->sc_sbi; 2053 2116 struct the_nilfs *nilfs = sbi->s_nilfs; 2054 2117 struct page *failed_page; 2055 - int err, has_sr = 0; 2118 + int err; 2056 2119 2057 2120 sci->sc_stage.scnt = NILFS_ST_INIT; 2058 2121 ··· 2080 2143 if (unlikely(err)) 2081 2144 goto failed; 2082 2145 2083 - has_sr = (sci->sc_super_root != NULL); 2084 - 2085 2146 /* Avoid empty segment */ 2086 2147 if (sci->sc_stage.scnt == NILFS_ST_DONE && 2087 2148 NILFS_SEG_EMPTY(&sci->sc_curseg->sb_sum)) { ··· 2094 2159 if (sci->sc_stage.flags & NILFS_CF_IFILE_STARTED) 2095 2160 nilfs_segctor_fill_in_file_bmap(sci, sbi->s_ifile); 2096 2161 2097 - if (has_sr) { 2162 + if (mode == SC_LSEG_SR && 2163 + sci->sc_stage.scnt >= NILFS_ST_CPFILE) { 2098 2164 err = nilfs_segctor_fill_in_checkpoint(sci); 2099 2165 if (unlikely(err)) 2100 2166 goto failed_to_write; ··· 2107 2171 /* Write partial segments */ 2108 2172 err = nilfs_segctor_prepare_write(sci, &failed_page); 2109 2173 if (err) { 2110 - nilfs_abort_logs(&sci->sc_segbufs, failed_page, 2111 - sci->sc_super_root, err); 2174 + nilfs_abort_logs(&sci->sc_segbufs, failed_page, err); 2112 2175 goto failed_to_write; 2113 2176 } 2114 - nilfs_segctor_fill_in_checksums(sci, nilfs->ns_crc_seed); 2177 + 2178 + nilfs_add_checksums_on_logs(&sci->sc_segbufs, 2179 + nilfs->ns_crc_seed); 2115 2180 2116 2181 err = nilfs_segctor_write(sci, nilfs); 2117 2182 if (unlikely(err)) ··· 2132 2195 goto failed_to_write; 2133 2196 } 2134 2197 } while (sci->sc_stage.scnt != NILFS_ST_DONE); 2135 - 2136 - sci->sc_super_root = NULL; 2137 2198 2138 2199 out: 2139 2200 nilfs_segctor_check_out_files(sci, sbi); ··· 2159 2224 static void nilfs_segctor_start_timer(struct nilfs_sc_info *sci) 2160 2225 { 2161 2226 spin_lock(&sci->sc_state_lock); 2162 - if (sci->sc_timer && !(sci->sc_state & NILFS_SEGCTOR_COMMIT)) { 2163 - sci->sc_timer->expires = jiffies + sci->sc_interval; 2164 - add_timer(sci->sc_timer); 2227 + if (!(sci->sc_state & NILFS_SEGCTOR_COMMIT)) { 2228 + sci->sc_timer.expires = jiffies + sci->sc_interval; 2229 + add_timer(&sci->sc_timer); 2165 2230 sci->sc_state |= NILFS_SEGCTOR_COMMIT; 2166 2231 } 2167 2232 spin_unlock(&sci->sc_state_lock); ··· 2366 2431 spin_lock(&sci->sc_state_lock); 2367 2432 sci->sc_seq_accepted = sci->sc_seq_request; 2368 2433 spin_unlock(&sci->sc_state_lock); 2369 - 2370 - if (sci->sc_timer) 2371 - del_timer_sync(sci->sc_timer); 2434 + del_timer_sync(&sci->sc_timer); 2372 2435 } 2373 2436 2374 2437 /** ··· 2392 2459 sci->sc_flush_request &= ~FLUSH_DAT_BIT; 2393 2460 2394 2461 /* re-enable timer if checkpoint creation was not done */ 2395 - if (sci->sc_timer && (sci->sc_state & NILFS_SEGCTOR_COMMIT) && 2396 - time_before(jiffies, sci->sc_timer->expires)) 2397 - add_timer(sci->sc_timer); 2462 + if ((sci->sc_state & NILFS_SEGCTOR_COMMIT) && 2463 + time_before(jiffies, sci->sc_timer.expires)) 2464 + add_timer(&sci->sc_timer); 2398 2465 } 2399 2466 spin_unlock(&sci->sc_state_lock); 2400 2467 } ··· 2573 2640 { 2574 2641 struct nilfs_sc_info *sci = (struct nilfs_sc_info *)arg; 2575 2642 struct the_nilfs *nilfs = sci->sc_sbi->s_nilfs; 2576 - struct timer_list timer; 2577 2643 int timeout = 0; 2578 2644 2579 - init_timer(&timer); 2580 - timer.data = (unsigned long)current; 2581 - timer.function = nilfs_construction_timeout; 2582 - sci->sc_timer = &timer; 2645 + sci->sc_timer.data = (unsigned long)current; 2646 + sci->sc_timer.function = nilfs_construction_timeout; 2583 2647 2584 2648 /* start sync. */ 2585 2649 sci->sc_task = current; ··· 2625 2695 should_sleep = 0; 2626 2696 else if (sci->sc_state & NILFS_SEGCTOR_COMMIT) 2627 2697 should_sleep = time_before(jiffies, 2628 - sci->sc_timer->expires); 2698 + sci->sc_timer.expires); 2629 2699 2630 2700 if (should_sleep) { 2631 2701 spin_unlock(&sci->sc_state_lock); ··· 2634 2704 } 2635 2705 finish_wait(&sci->sc_wait_daemon, &wait); 2636 2706 timeout = ((sci->sc_state & NILFS_SEGCTOR_COMMIT) && 2637 - time_after_eq(jiffies, sci->sc_timer->expires)); 2707 + time_after_eq(jiffies, sci->sc_timer.expires)); 2638 2708 2639 2709 if (nilfs_sb_dirty(nilfs) && nilfs_sb_need_update(nilfs)) 2640 2710 set_nilfs_discontinued(nilfs); ··· 2643 2713 2644 2714 end_thread: 2645 2715 spin_unlock(&sci->sc_state_lock); 2646 - del_timer_sync(sci->sc_timer); 2647 - sci->sc_timer = NULL; 2648 2716 2649 2717 /* end sync. */ 2650 2718 sci->sc_task = NULL; ··· 2678 2750 } 2679 2751 } 2680 2752 2681 - static int nilfs_segctor_init(struct nilfs_sc_info *sci) 2682 - { 2683 - sci->sc_seq_done = sci->sc_seq_request; 2684 - 2685 - return nilfs_segctor_start_thread(sci); 2686 - } 2687 - 2688 2753 /* 2689 2754 * Setup & clean-up functions 2690 2755 */ ··· 2701 2780 INIT_LIST_HEAD(&sci->sc_write_logs); 2702 2781 INIT_LIST_HEAD(&sci->sc_gc_inodes); 2703 2782 INIT_LIST_HEAD(&sci->sc_copied_buffers); 2783 + init_timer(&sci->sc_timer); 2704 2784 2705 2785 sci->sc_interval = HZ * NILFS_SC_DEFAULT_TIMEOUT; 2706 2786 sci->sc_mjcp_freq = HZ * NILFS_SC_DEFAULT_SR_FREQ; ··· 2768 2846 2769 2847 down_write(&sbi->s_nilfs->ns_segctor_sem); 2770 2848 2849 + del_timer_sync(&sci->sc_timer); 2771 2850 kfree(sci); 2772 2851 } 2773 2852 ··· 2803 2880 return -ENOMEM; 2804 2881 2805 2882 nilfs_attach_writer(nilfs, sbi); 2806 - err = nilfs_segctor_init(NILFS_SC(sbi)); 2883 + err = nilfs_segctor_start_thread(NILFS_SC(sbi)); 2807 2884 if (err) { 2808 2885 nilfs_detach_writer(nilfs, sbi); 2809 2886 kfree(sbi->s_sc_info);
+3 -3
fs/nilfs2/segment.h
··· 100 100 * @sc_write_logs: List of segment buffers to hold logs under writing 101 101 * @sc_segbuf_nblocks: Number of available blocks in segment buffers. 102 102 * @sc_curseg: Current segment buffer 103 - * @sc_super_root: Pointer to the super root buffer 104 103 * @sc_stage: Collection stage 105 104 * @sc_finfo_ptr: pointer to the current finfo struct in the segment summary 106 105 * @sc_binfo_ptr: pointer to the current binfo struct in the segment summary ··· 147 148 struct list_head sc_write_logs; 148 149 unsigned long sc_segbuf_nblocks; 149 150 struct nilfs_segment_buffer *sc_curseg; 150 - struct buffer_head *sc_super_root; 151 151 152 152 struct nilfs_cstage sc_stage; 153 153 ··· 177 179 unsigned long sc_lseg_stime; /* in 1/HZ seconds */ 178 180 unsigned long sc_watermark; 179 181 180 - struct timer_list *sc_timer; 182 + struct timer_list sc_timer; 181 183 struct task_struct *sc_task; 182 184 }; 183 185 ··· 217 219 */ 218 220 #define NILFS_SC_DEFAULT_WATERMARK 3600 219 221 222 + /* super.c */ 223 + extern struct kmem_cache *nilfs_transaction_cachep; 220 224 221 225 /* segment.c */ 222 226 extern int nilfs_init_transaction_cache(void);
+115 -105
fs/nilfs2/super.c
··· 67 67 "(NILFS)"); 68 68 MODULE_LICENSE("GPL"); 69 69 70 + struct kmem_cache *nilfs_inode_cachep; 71 + struct kmem_cache *nilfs_transaction_cachep; 72 + struct kmem_cache *nilfs_segbuf_cachep; 73 + struct kmem_cache *nilfs_btree_path_cache; 74 + 70 75 static int nilfs_remount(struct super_block *sb, int *flags, char *data); 71 76 72 77 /** ··· 134 129 va_end(args); 135 130 } 136 131 137 - static struct kmem_cache *nilfs_inode_cachep; 138 132 139 133 struct inode *nilfs_alloc_inode_common(struct the_nilfs *nilfs) 140 134 { ··· 157 153 void nilfs_destroy_inode(struct inode *inode) 158 154 { 159 155 kmem_cache_free(nilfs_inode_cachep, NILFS_I(inode)); 160 - } 161 - 162 - static void init_once(void *obj) 163 - { 164 - struct nilfs_inode_info *ii = obj; 165 - 166 - INIT_LIST_HEAD(&ii->i_dirty); 167 - #ifdef CONFIG_NILFS_XATTR 168 - init_rwsem(&ii->xattr_sem); 169 - #endif 170 - nilfs_btnode_cache_init_once(&ii->i_btnode_cache); 171 - ii->i_bmap = (struct nilfs_bmap *)&ii->i_bmap_union; 172 - inode_init_once(&ii->vfs_inode); 173 - } 174 - 175 - static int nilfs_init_inode_cache(void) 176 - { 177 - nilfs_inode_cachep = kmem_cache_create("nilfs2_inode_cache", 178 - sizeof(struct nilfs_inode_info), 179 - 0, SLAB_RECLAIM_ACCOUNT, 180 - init_once); 181 - 182 - return (nilfs_inode_cachep == NULL) ? -ENOMEM : 0; 183 - } 184 - 185 - static inline void nilfs_destroy_inode_cache(void) 186 - { 187 - kmem_cache_destroy(nilfs_inode_cachep); 188 156 } 189 157 190 158 static void nilfs_clear_inode(struct inode *inode) ··· 242 266 int err; 243 267 244 268 /* nilfs->sem must be locked by the caller. */ 245 - if (sbp[0]->s_magic != NILFS_SUPER_MAGIC) { 246 - if (sbp[1] && sbp[1]->s_magic == NILFS_SUPER_MAGIC) 269 + if (sbp[0]->s_magic != cpu_to_le16(NILFS_SUPER_MAGIC)) { 270 + if (sbp[1] && sbp[1]->s_magic == cpu_to_le16(NILFS_SUPER_MAGIC)) 247 271 nilfs_swap_super_block(nilfs); 248 272 else { 249 273 printk(KERN_CRIT "NILFS: superblock broke on dev %s\n", ··· 446 470 if (nilfs_test_opt(sbi, SNAPSHOT)) 447 471 seq_printf(seq, ",cp=%llu", 448 472 (unsigned long long int)sbi->s_snapshot_cno); 449 - if (nilfs_test_opt(sbi, ERRORS_RO)) 450 - seq_printf(seq, ",errors=remount-ro"); 451 473 if (nilfs_test_opt(sbi, ERRORS_PANIC)) 452 474 seq_printf(seq, ",errors=panic"); 475 + if (nilfs_test_opt(sbi, ERRORS_CONT)) 476 + seq_printf(seq, ",errors=continue"); 453 477 if (nilfs_test_opt(sbi, STRICT_ORDER)) 454 478 seq_printf(seq, ",order=strict"); 455 479 if (nilfs_test_opt(sbi, NORECOVERY)) ··· 607 631 struct nilfs_super_block *sbp) 608 632 { 609 633 sbi->s_mount_opt = 610 - NILFS_MOUNT_ERRORS_CONT | NILFS_MOUNT_BARRIER; 634 + NILFS_MOUNT_ERRORS_RO | NILFS_MOUNT_BARRIER; 611 635 } 612 636 613 637 static int nilfs_setup_super(struct nilfs_sb_info *sbi) ··· 754 778 goto failed_sbi; 755 779 } 756 780 cno = sbi->s_snapshot_cno; 757 - } else 758 - /* Read-only mount */ 759 - sbi->s_snapshot_cno = cno; 781 + } 760 782 } 761 783 762 784 err = nilfs_attach_checkpoint(sbi, cno); ··· 823 849 struct the_nilfs *nilfs = sbi->s_nilfs; 824 850 unsigned long old_sb_flags; 825 851 struct nilfs_mount_options old_opts; 826 - int err; 852 + int was_snapshot, err; 827 853 828 854 lock_kernel(); 829 855 ··· 831 857 old_sb_flags = sb->s_flags; 832 858 old_opts.mount_opt = sbi->s_mount_opt; 833 859 old_opts.snapshot_cno = sbi->s_snapshot_cno; 860 + was_snapshot = nilfs_test_opt(sbi, SNAPSHOT); 834 861 835 862 if (!parse_options(data, sb)) { 836 863 err = -EINVAL; ··· 839 864 } 840 865 sb->s_flags = (sb->s_flags & ~MS_POSIXACL); 841 866 842 - if ((*flags & MS_RDONLY) && 843 - sbi->s_snapshot_cno != old_opts.snapshot_cno) { 844 - printk(KERN_WARNING "NILFS (device %s): couldn't " 845 - "remount to a different snapshot.\n", 846 - sb->s_id); 847 - err = -EINVAL; 848 - goto restore_opts; 867 + err = -EINVAL; 868 + if (was_snapshot) { 869 + if (!(*flags & MS_RDONLY)) { 870 + printk(KERN_ERR "NILFS (device %s): cannot remount " 871 + "snapshot read/write.\n", 872 + sb->s_id); 873 + goto restore_opts; 874 + } else if (sbi->s_snapshot_cno != old_opts.snapshot_cno) { 875 + printk(KERN_ERR "NILFS (device %s): cannot " 876 + "remount to a different snapshot.\n", 877 + sb->s_id); 878 + goto restore_opts; 879 + } 880 + } else { 881 + if (nilfs_test_opt(sbi, SNAPSHOT)) { 882 + printk(KERN_ERR "NILFS (device %s): cannot change " 883 + "a regular mount to a snapshot.\n", 884 + sb->s_id); 885 + goto restore_opts; 886 + } 849 887 } 850 888 851 889 if (!nilfs_valid_fs(nilfs)) { 852 890 printk(KERN_WARNING "NILFS (device %s): couldn't " 853 891 "remount because the filesystem is in an " 854 892 "incomplete recovery state.\n", sb->s_id); 855 - err = -EINVAL; 856 893 goto restore_opts; 857 894 } 858 895 ··· 874 887 /* Shutting down the segment constructor */ 875 888 nilfs_detach_segment_constructor(sbi); 876 889 sb->s_flags |= MS_RDONLY; 877 - 878 - sbi->s_snapshot_cno = nilfs_last_cno(nilfs); 879 - /* nilfs_set_opt(sbi, SNAPSHOT); */ 880 890 881 891 /* 882 892 * Remounting a valid RW partition RDONLY, so set ··· 893 909 * store the current valid flag. (It may have been changed 894 910 * by fsck since we originally mounted the partition.) 895 911 */ 896 - if (nilfs->ns_current && nilfs->ns_current != sbi) { 897 - printk(KERN_WARNING "NILFS (device %s): couldn't " 898 - "remount because an RW-mount exists.\n", 899 - sb->s_id); 900 - err = -EBUSY; 901 - goto restore_opts; 902 - } 903 - if (sbi->s_snapshot_cno != nilfs_last_cno(nilfs)) { 904 - printk(KERN_WARNING "NILFS (device %s): couldn't " 905 - "remount because the current RO-mount is not " 906 - "the latest one.\n", 907 - sb->s_id); 908 - err = -EINVAL; 909 - goto restore_opts; 910 - } 911 912 sb->s_flags &= ~MS_RDONLY; 912 - nilfs_clear_opt(sbi, SNAPSHOT); 913 - sbi->s_snapshot_cno = 0; 914 913 915 914 err = nilfs_attach_segment_constructor(sbi); 916 915 if (err) ··· 902 935 down_write(&nilfs->ns_sem); 903 936 nilfs_setup_super(sbi); 904 937 up_write(&nilfs->ns_sem); 905 - 906 - nilfs->ns_current = sbi; 907 938 } 908 939 out: 909 940 up_write(&nilfs->ns_super_sem); ··· 987 1022 { 988 1023 struct nilfs_super_data sd; 989 1024 struct super_block *s; 1025 + fmode_t mode = FMODE_READ; 990 1026 struct the_nilfs *nilfs; 991 1027 int err, need_to_close = 1; 992 1028 993 - sd.bdev = open_bdev_exclusive(dev_name, flags, fs_type); 1029 + if (!(flags & MS_RDONLY)) 1030 + mode |= FMODE_WRITE; 1031 + 1032 + sd.bdev = open_bdev_exclusive(dev_name, mode, fs_type); 994 1033 if (IS_ERR(sd.bdev)) 995 1034 return PTR_ERR(sd.bdev); 996 1035 ··· 1061 1092 1062 1093 /* New superblock instance created */ 1063 1094 s->s_flags = flags; 1095 + s->s_mode = mode; 1064 1096 strlcpy(s->s_id, bdevname(sd.bdev, b), sizeof(s->s_id)); 1065 1097 sb_set_blocksize(s, block_size(sd.bdev)); 1066 1098 1067 - err = nilfs_fill_super(s, data, flags & MS_VERBOSE, nilfs); 1099 + err = nilfs_fill_super(s, data, flags & MS_SILENT ? 1 : 0, 1100 + nilfs); 1068 1101 if (err) 1069 1102 goto cancel_new; 1070 1103 ··· 1077 1106 mutex_unlock(&nilfs->ns_mount_mutex); 1078 1107 put_nilfs(nilfs); 1079 1108 if (need_to_close) 1080 - close_bdev_exclusive(sd.bdev, flags); 1109 + close_bdev_exclusive(sd.bdev, mode); 1081 1110 simple_set_mnt(mnt, s); 1082 1111 return 0; 1083 1112 ··· 1085 1114 mutex_unlock(&nilfs->ns_mount_mutex); 1086 1115 put_nilfs(nilfs); 1087 1116 failed: 1088 - close_bdev_exclusive(sd.bdev, flags); 1117 + close_bdev_exclusive(sd.bdev, mode); 1089 1118 1090 1119 return err; 1091 1120 ··· 1095 1124 put_nilfs(nilfs); 1096 1125 deactivate_locked_super(s); 1097 1126 /* 1098 - * deactivate_super() invokes close_bdev_exclusive(). 1127 + * deactivate_locked_super() invokes close_bdev_exclusive(). 1099 1128 * We must finish all post-cleaning before this call; 1100 1129 * put_nilfs() needs the block device. 1101 1130 */ ··· 1110 1139 .fs_flags = FS_REQUIRES_DEV, 1111 1140 }; 1112 1141 1142 + static void nilfs_inode_init_once(void *obj) 1143 + { 1144 + struct nilfs_inode_info *ii = obj; 1145 + 1146 + INIT_LIST_HEAD(&ii->i_dirty); 1147 + #ifdef CONFIG_NILFS_XATTR 1148 + init_rwsem(&ii->xattr_sem); 1149 + #endif 1150 + nilfs_btnode_cache_init_once(&ii->i_btnode_cache); 1151 + ii->i_bmap = (struct nilfs_bmap *)&ii->i_bmap_union; 1152 + inode_init_once(&ii->vfs_inode); 1153 + } 1154 + 1155 + static void nilfs_segbuf_init_once(void *obj) 1156 + { 1157 + memset(obj, 0, sizeof(struct nilfs_segment_buffer)); 1158 + } 1159 + 1160 + static void nilfs_destroy_cachep(void) 1161 + { 1162 + if (nilfs_inode_cachep) 1163 + kmem_cache_destroy(nilfs_inode_cachep); 1164 + if (nilfs_transaction_cachep) 1165 + kmem_cache_destroy(nilfs_transaction_cachep); 1166 + if (nilfs_segbuf_cachep) 1167 + kmem_cache_destroy(nilfs_segbuf_cachep); 1168 + if (nilfs_btree_path_cache) 1169 + kmem_cache_destroy(nilfs_btree_path_cache); 1170 + } 1171 + 1172 + static int __init nilfs_init_cachep(void) 1173 + { 1174 + nilfs_inode_cachep = kmem_cache_create("nilfs2_inode_cache", 1175 + sizeof(struct nilfs_inode_info), 0, 1176 + SLAB_RECLAIM_ACCOUNT, nilfs_inode_init_once); 1177 + if (!nilfs_inode_cachep) 1178 + goto fail; 1179 + 1180 + nilfs_transaction_cachep = kmem_cache_create("nilfs2_transaction_cache", 1181 + sizeof(struct nilfs_transaction_info), 0, 1182 + SLAB_RECLAIM_ACCOUNT, NULL); 1183 + if (!nilfs_transaction_cachep) 1184 + goto fail; 1185 + 1186 + nilfs_segbuf_cachep = kmem_cache_create("nilfs2_segbuf_cache", 1187 + sizeof(struct nilfs_segment_buffer), 0, 1188 + SLAB_RECLAIM_ACCOUNT, nilfs_segbuf_init_once); 1189 + if (!nilfs_segbuf_cachep) 1190 + goto fail; 1191 + 1192 + nilfs_btree_path_cache = kmem_cache_create("nilfs2_btree_path_cache", 1193 + sizeof(struct nilfs_btree_path) * NILFS_BTREE_LEVEL_MAX, 1194 + 0, 0, NULL); 1195 + if (!nilfs_btree_path_cache) 1196 + goto fail; 1197 + 1198 + return 0; 1199 + 1200 + fail: 1201 + nilfs_destroy_cachep(); 1202 + return -ENOMEM; 1203 + } 1204 + 1113 1205 static int __init init_nilfs_fs(void) 1114 1206 { 1115 1207 int err; 1116 1208 1117 - err = nilfs_init_inode_cache(); 1209 + err = nilfs_init_cachep(); 1118 1210 if (err) 1119 - goto failed; 1120 - 1121 - err = nilfs_init_transaction_cache(); 1122 - if (err) 1123 - goto failed_inode_cache; 1124 - 1125 - err = nilfs_init_segbuf_cache(); 1126 - if (err) 1127 - goto failed_transaction_cache; 1128 - 1129 - err = nilfs_btree_path_cache_init(); 1130 - if (err) 1131 - goto failed_segbuf_cache; 1211 + goto fail; 1132 1212 1133 1213 err = register_filesystem(&nilfs_fs_type); 1134 1214 if (err) 1135 - goto failed_btree_path_cache; 1215 + goto free_cachep; 1136 1216 1217 + printk(KERN_INFO "NILFS version 2 loaded\n"); 1137 1218 return 0; 1138 1219 1139 - failed_btree_path_cache: 1140 - nilfs_btree_path_cache_destroy(); 1141 - 1142 - failed_segbuf_cache: 1143 - nilfs_destroy_segbuf_cache(); 1144 - 1145 - failed_transaction_cache: 1146 - nilfs_destroy_transaction_cache(); 1147 - 1148 - failed_inode_cache: 1149 - nilfs_destroy_inode_cache(); 1150 - 1151 - failed: 1220 + free_cachep: 1221 + nilfs_destroy_cachep(); 1222 + fail: 1152 1223 return err; 1153 1224 } 1154 1225 1155 1226 static void __exit exit_nilfs_fs(void) 1156 1227 { 1157 - nilfs_destroy_segbuf_cache(); 1158 - nilfs_destroy_transaction_cache(); 1159 - nilfs_destroy_inode_cache(); 1160 - nilfs_btree_path_cache_destroy(); 1228 + nilfs_destroy_cachep(); 1161 1229 unregister_filesystem(&nilfs_fs_type); 1162 1230 } 1163 1231
+7 -3
fs/nilfs2/the_nilfs.c
··· 486 486 printk(KERN_WARNING 487 487 "NILFS warning: unable to read secondary superblock\n"); 488 488 489 + /* 490 + * Compare two super blocks and set 1 in swp if the secondary 491 + * super block is valid and newer. Otherwise, set 0 in swp. 492 + */ 489 493 valid[0] = nilfs_valid_sb(sbp[0]); 490 494 valid[1] = nilfs_valid_sb(sbp[1]); 491 - swp = valid[1] && 492 - (!valid[0] || 493 - le64_to_cpu(sbp[1]->s_wtime) > le64_to_cpu(sbp[0]->s_wtime)); 495 + swp = valid[1] && (!valid[0] || 496 + le64_to_cpu(sbp[1]->s_last_cno) > 497 + le64_to_cpu(sbp[0]->s_last_cno)); 494 498 495 499 if (valid[swp] && nilfs_sb2_bad_offset(sbp[swp], sb2off)) { 496 500 brelse(sbh[1]);
+9 -8
include/linux/nilfs2_fs.h
··· 199 199 __le32 s_creator_os; /* OS */ 200 200 __le16 s_def_resuid; /* Default uid for reserved blocks */ 201 201 __le16 s_def_resgid; /* Default gid for reserved blocks */ 202 - __le32 s_first_ino; /* First non-reserved inode */ 202 + __le32 s_first_ino; /* First non-reserved inode */ 203 203 204 - __le16 s_inode_size; /* Size of an inode */ 204 + __le16 s_inode_size; /* Size of an inode */ 205 205 __le16 s_dat_entry_size; /* Size of a dat entry */ 206 206 __le16 s_checkpoint_size; /* Size of a checkpoint */ 207 207 __le16 s_segment_usage_size; /* Size of a segment usage */ 208 208 209 209 __u8 s_uuid[16]; /* 128-bit uuid for volume */ 210 - char s_volume_name[16]; /* volume name */ 211 - char s_last_mounted[64]; /* directory where last mounted */ 210 + char s_volume_name[80]; /* volume name */ 212 211 213 212 __le32 s_c_interval; /* Commit interval of segment */ 214 213 __le32 s_c_block_max; /* Threshold of data amount for ··· 376 377 * @ss_nfinfo: number of finfo structures 377 378 * @ss_sumbytes: total size of segment summary in bytes 378 379 * @ss_pad: padding 380 + * @ss_cno: checkpoint number 379 381 */ 380 382 struct nilfs_segment_summary { 381 383 __le32 ss_datasum; ··· 391 391 __le32 ss_nfinfo; 392 392 __le32 ss_sumbytes; 393 393 __le32 ss_pad; 394 + __le64 ss_cno; 394 395 /* array of finfo structures */ 395 396 }; 396 397 ··· 438 437 439 438 /** 440 439 * struct nilfs_dat_entry - disk address translation entry 441 - * @dt_blocknr: block number 442 - * @dt_start: start checkpoint number 443 - * @dt_end: end checkpoint number 444 - * @dt_rsv: reserved for future use 440 + * @de_blocknr: block number 441 + * @de_start: start checkpoint number 442 + * @de_end: end checkpoint number 443 + * @de_rsv: reserved for future use 445 444 */ 446 445 struct nilfs_dat_entry { 447 446 __le64 de_blocknr;