2 * the_nilfs.c - the_nilfs shared structure.
4 * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * Written by Ryusuke Konishi <ryusuke@osrg.net>
24 #include <linux/buffer_head.h>
25 #include <linux/slab.h>
26 #include <linux/blkdev.h>
27 #include <linux/backing-dev.h>
28 #include <linux/crc32.h>
38 static int nilfs_valid_sb(struct nilfs_super_block *sbp);
40 void nilfs_set_last_segment(struct the_nilfs *nilfs,
41 sector_t start_blocknr, u64 seq, __u64 cno)
43 spin_lock(&nilfs->ns_last_segment_lock);
44 nilfs->ns_last_pseg = start_blocknr;
45 nilfs->ns_last_seq = seq;
46 nilfs->ns_last_cno = cno;
48 if (!nilfs_sb_dirty(nilfs)) {
49 if (nilfs->ns_prev_seq == nilfs->ns_last_seq)
52 set_nilfs_sb_dirty(nilfs);
54 nilfs->ns_prev_seq = nilfs->ns_last_seq;
57 spin_unlock(&nilfs->ns_last_segment_lock);
61 * alloc_nilfs - allocate a nilfs object
62 * @bdev: block device to which the_nilfs is related
64 * Return Value: On success, pointer to the_nilfs is returned.
65 * On error, NULL is returned.
67 struct the_nilfs *alloc_nilfs(struct block_device *bdev)
69 struct the_nilfs *nilfs;
71 nilfs = kzalloc(sizeof(*nilfs), GFP_KERNEL);
75 nilfs->ns_bdev = bdev;
76 atomic_set(&nilfs->ns_ndirtyblks, 0);
77 init_rwsem(&nilfs->ns_sem);
78 init_rwsem(&nilfs->ns_writer_sem);
79 INIT_LIST_HEAD(&nilfs->ns_gc_inodes);
80 spin_lock_init(&nilfs->ns_last_segment_lock);
81 nilfs->ns_cptree = RB_ROOT;
82 spin_lock_init(&nilfs->ns_cptree_lock);
83 init_rwsem(&nilfs->ns_segctor_sem);
89 * destroy_nilfs - destroy nilfs object
90 * @nilfs: nilfs object to be released
92 void destroy_nilfs(struct the_nilfs *nilfs)
95 if (nilfs_loaded(nilfs)) {
96 nilfs_mdt_destroy(nilfs->ns_sufile);
97 nilfs_mdt_destroy(nilfs->ns_cpfile);
98 nilfs_mdt_destroy(nilfs->ns_dat);
99 nilfs_mdt_destroy(nilfs->ns_gc_dat);
101 if (nilfs_init(nilfs)) {
102 brelse(nilfs->ns_sbh[0]);
103 brelse(nilfs->ns_sbh[1]);
108 static int nilfs_load_super_root(struct the_nilfs *nilfs, sector_t sr_block)
110 struct buffer_head *bh_sr;
111 struct nilfs_super_root *raw_sr;
112 struct nilfs_super_block **sbp = nilfs->ns_sbp;
113 unsigned dat_entry_size, segment_usage_size, checkpoint_size;
117 err = nilfs_read_super_root_block(nilfs, sr_block, &bh_sr, 1);
121 down_read(&nilfs->ns_sem);
122 dat_entry_size = le16_to_cpu(sbp[0]->s_dat_entry_size);
123 checkpoint_size = le16_to_cpu(sbp[0]->s_checkpoint_size);
124 segment_usage_size = le16_to_cpu(sbp[0]->s_segment_usage_size);
125 up_read(&nilfs->ns_sem);
127 inode_size = nilfs->ns_inode_size;
130 nilfs->ns_dat = nilfs_dat_new(nilfs, dat_entry_size);
131 if (unlikely(!nilfs->ns_dat))
134 nilfs->ns_gc_dat = nilfs_dat_new(nilfs, dat_entry_size);
135 if (unlikely(!nilfs->ns_gc_dat))
138 nilfs->ns_cpfile = nilfs_cpfile_new(nilfs, checkpoint_size);
139 if (unlikely(!nilfs->ns_cpfile))
142 nilfs->ns_sufile = nilfs_sufile_new(nilfs, segment_usage_size);
143 if (unlikely(!nilfs->ns_sufile))
146 nilfs_mdt_set_shadow(nilfs->ns_dat, nilfs->ns_gc_dat);
148 err = nilfs_dat_read(nilfs->ns_dat, (void *)bh_sr->b_data +
149 NILFS_SR_DAT_OFFSET(inode_size));
153 err = nilfs_cpfile_read(nilfs->ns_cpfile, (void *)bh_sr->b_data +
154 NILFS_SR_CPFILE_OFFSET(inode_size));
158 err = nilfs_sufile_read(nilfs->ns_sufile, (void *)bh_sr->b_data +
159 NILFS_SR_SUFILE_OFFSET(inode_size));
163 raw_sr = (struct nilfs_super_root *)bh_sr->b_data;
164 nilfs->ns_nongc_ctime = le64_to_cpu(raw_sr->sr_nongc_ctime);
171 nilfs_mdt_destroy(nilfs->ns_sufile);
174 nilfs_mdt_destroy(nilfs->ns_cpfile);
177 nilfs_mdt_destroy(nilfs->ns_gc_dat);
180 nilfs_mdt_destroy(nilfs->ns_dat);
184 static void nilfs_init_recovery_info(struct nilfs_recovery_info *ri)
186 memset(ri, 0, sizeof(*ri));
187 INIT_LIST_HEAD(&ri->ri_used_segments);
190 static void nilfs_clear_recovery_info(struct nilfs_recovery_info *ri)
192 nilfs_dispose_segment_list(&ri->ri_used_segments);
196 * nilfs_store_log_cursor - load log cursor from a super block
197 * @nilfs: nilfs object
198 * @sbp: buffer storing super block to be read
200 * nilfs_store_log_cursor() reads the last position of the log
201 * containing a super root from a given super block, and initializes
202 * relevant information on the nilfs object preparatory for log
203 * scanning and recovery.
205 static int nilfs_store_log_cursor(struct the_nilfs *nilfs,
206 struct nilfs_super_block *sbp)
210 nilfs->ns_last_pseg = le64_to_cpu(sbp->s_last_pseg);
211 nilfs->ns_last_cno = le64_to_cpu(sbp->s_last_cno);
212 nilfs->ns_last_seq = le64_to_cpu(sbp->s_last_seq);
214 nilfs->ns_prev_seq = nilfs->ns_last_seq;
215 nilfs->ns_seg_seq = nilfs->ns_last_seq;
217 nilfs_get_segnum_of_block(nilfs, nilfs->ns_last_pseg);
218 nilfs->ns_cno = nilfs->ns_last_cno + 1;
219 if (nilfs->ns_segnum >= nilfs->ns_nsegments) {
220 printk(KERN_ERR "NILFS invalid last segment number.\n");
227 * load_nilfs - load and recover the nilfs
228 * @nilfs: the_nilfs structure to be released
229 * @sbi: nilfs_sb_info used to recover past segment
231 * load_nilfs() searches and load the latest super root,
232 * attaches the last segment, and does recovery if needed.
233 * The caller must call this exclusively for simultaneous mounts.
235 int load_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi)
237 struct nilfs_recovery_info ri;
238 unsigned int s_flags = sbi->s_super->s_flags;
239 int really_read_only = bdev_read_only(nilfs->ns_bdev);
240 int valid_fs = nilfs_valid_fs(nilfs);
244 printk(KERN_WARNING "NILFS warning: mounting unchecked fs\n");
245 if (s_flags & MS_RDONLY) {
246 printk(KERN_INFO "NILFS: INFO: recovery "
247 "required for readonly filesystem.\n");
248 printk(KERN_INFO "NILFS: write access will "
249 "be enabled during recovery.\n");
253 nilfs_init_recovery_info(&ri);
255 err = nilfs_search_super_root(nilfs, &ri);
257 struct nilfs_super_block **sbp = nilfs->ns_sbp;
263 if (!nilfs_valid_sb(sbp[1])) {
265 "NILFS warning: unable to fall back to spare"
270 "NILFS: try rollback from an earlier position\n");
273 * restore super block with its spare and reconfigure
274 * relevant states of the nilfs object.
276 memcpy(sbp[0], sbp[1], nilfs->ns_sbsize);
277 nilfs->ns_crc_seed = le32_to_cpu(sbp[0]->s_crc_seed);
278 nilfs->ns_sbwtime = le64_to_cpu(sbp[0]->s_wtime);
280 /* verify consistency between two super blocks */
281 blocksize = BLOCK_SIZE << le32_to_cpu(sbp[0]->s_log_block_size);
282 if (blocksize != nilfs->ns_blocksize) {
284 "NILFS warning: blocksize differs between "
285 "two super blocks (%d != %d)\n",
286 blocksize, nilfs->ns_blocksize);
290 err = nilfs_store_log_cursor(nilfs, sbp[0]);
294 /* drop clean flag to allow roll-forward and recovery */
295 nilfs->ns_mount_state &= ~NILFS_VALID_FS;
298 err = nilfs_search_super_root(nilfs, &ri);
303 err = nilfs_load_super_root(nilfs, ri.ri_super_root);
305 printk(KERN_ERR "NILFS: error loading super root.\n");
312 if (s_flags & MS_RDONLY) {
315 if (nilfs_test_opt(sbi, NORECOVERY)) {
316 printk(KERN_INFO "NILFS: norecovery option specified. "
317 "skipping roll-forward recovery\n");
320 features = le64_to_cpu(nilfs->ns_sbp[0]->s_feature_compat_ro) &
321 ~NILFS_FEATURE_COMPAT_RO_SUPP;
323 printk(KERN_ERR "NILFS: couldn't proceed with "
324 "recovery because of unsupported optional "
326 (unsigned long long)features);
330 if (really_read_only) {
331 printk(KERN_ERR "NILFS: write access "
332 "unavailable, cannot proceed.\n");
336 sbi->s_super->s_flags &= ~MS_RDONLY;
337 } else if (nilfs_test_opt(sbi, NORECOVERY)) {
338 printk(KERN_ERR "NILFS: recovery cancelled because norecovery "
339 "option was specified for a read/write mount\n");
344 err = nilfs_salvage_orphan_logs(nilfs, sbi, &ri);
348 down_write(&nilfs->ns_sem);
349 nilfs->ns_mount_state |= NILFS_VALID_FS; /* set "clean" flag */
350 err = nilfs_cleanup_super(sbi);
351 up_write(&nilfs->ns_sem);
354 printk(KERN_ERR "NILFS: failed to update super block. "
355 "recovery unfinished.\n");
358 printk(KERN_INFO "NILFS: recovery complete.\n");
361 set_nilfs_loaded(nilfs);
362 nilfs_clear_recovery_info(&ri);
363 sbi->s_super->s_flags = s_flags;
367 printk(KERN_ERR "NILFS: error searching super root.\n");
371 nilfs_mdt_destroy(nilfs->ns_cpfile);
372 nilfs_mdt_destroy(nilfs->ns_sufile);
373 nilfs_mdt_destroy(nilfs->ns_dat);
374 nilfs_mdt_destroy(nilfs->ns_gc_dat);
377 nilfs_clear_recovery_info(&ri);
378 sbi->s_super->s_flags = s_flags;
382 static unsigned long long nilfs_max_size(unsigned int blkbits)
384 unsigned int max_bits;
385 unsigned long long res = MAX_LFS_FILESIZE; /* page cache limit */
387 max_bits = blkbits + NILFS_BMAP_KEY_BIT; /* bmap size limit */
389 res = min_t(unsigned long long, res, (1ULL << max_bits) - 1);
393 static int nilfs_store_disk_layout(struct the_nilfs *nilfs,
394 struct nilfs_super_block *sbp)
396 if (le32_to_cpu(sbp->s_rev_level) < NILFS_MIN_SUPP_REV) {
397 printk(KERN_ERR "NILFS: unsupported revision "
398 "(superblock rev.=%d.%d, current rev.=%d.%d). "
399 "Please check the version of mkfs.nilfs.\n",
400 le32_to_cpu(sbp->s_rev_level),
401 le16_to_cpu(sbp->s_minor_rev_level),
402 NILFS_CURRENT_REV, NILFS_MINOR_REV);
405 nilfs->ns_sbsize = le16_to_cpu(sbp->s_bytes);
406 if (nilfs->ns_sbsize > BLOCK_SIZE)
409 nilfs->ns_inode_size = le16_to_cpu(sbp->s_inode_size);
410 nilfs->ns_first_ino = le32_to_cpu(sbp->s_first_ino);
412 nilfs->ns_blocks_per_segment = le32_to_cpu(sbp->s_blocks_per_segment);
413 if (nilfs->ns_blocks_per_segment < NILFS_SEG_MIN_BLOCKS) {
414 printk(KERN_ERR "NILFS: too short segment.\n");
418 nilfs->ns_first_data_block = le64_to_cpu(sbp->s_first_data_block);
419 nilfs->ns_nsegments = le64_to_cpu(sbp->s_nsegments);
420 nilfs->ns_r_segments_percentage =
421 le32_to_cpu(sbp->s_r_segments_percentage);
423 max_t(unsigned long, NILFS_MIN_NRSVSEGS,
424 DIV_ROUND_UP(nilfs->ns_nsegments *
425 nilfs->ns_r_segments_percentage, 100));
426 nilfs->ns_crc_seed = le32_to_cpu(sbp->s_crc_seed);
430 static int nilfs_valid_sb(struct nilfs_super_block *sbp)
432 static unsigned char sum[4];
433 const int sumoff = offsetof(struct nilfs_super_block, s_sum);
437 if (!sbp || le16_to_cpu(sbp->s_magic) != NILFS_SUPER_MAGIC)
439 bytes = le16_to_cpu(sbp->s_bytes);
440 if (bytes > BLOCK_SIZE)
442 crc = crc32_le(le32_to_cpu(sbp->s_crc_seed), (unsigned char *)sbp,
444 crc = crc32_le(crc, sum, 4);
445 crc = crc32_le(crc, (unsigned char *)sbp + sumoff + 4,
447 return crc == le32_to_cpu(sbp->s_sum);
450 static int nilfs_sb2_bad_offset(struct nilfs_super_block *sbp, u64 offset)
452 return offset < ((le64_to_cpu(sbp->s_nsegments) *
453 le32_to_cpu(sbp->s_blocks_per_segment)) <<
454 (le32_to_cpu(sbp->s_log_block_size) + 10));
457 static void nilfs_release_super_block(struct the_nilfs *nilfs)
461 for (i = 0; i < 2; i++) {
462 if (nilfs->ns_sbp[i]) {
463 brelse(nilfs->ns_sbh[i]);
464 nilfs->ns_sbh[i] = NULL;
465 nilfs->ns_sbp[i] = NULL;
470 void nilfs_fall_back_super_block(struct the_nilfs *nilfs)
472 brelse(nilfs->ns_sbh[0]);
473 nilfs->ns_sbh[0] = nilfs->ns_sbh[1];
474 nilfs->ns_sbp[0] = nilfs->ns_sbp[1];
475 nilfs->ns_sbh[1] = NULL;
476 nilfs->ns_sbp[1] = NULL;
479 void nilfs_swap_super_block(struct the_nilfs *nilfs)
481 struct buffer_head *tsbh = nilfs->ns_sbh[0];
482 struct nilfs_super_block *tsbp = nilfs->ns_sbp[0];
484 nilfs->ns_sbh[0] = nilfs->ns_sbh[1];
485 nilfs->ns_sbp[0] = nilfs->ns_sbp[1];
486 nilfs->ns_sbh[1] = tsbh;
487 nilfs->ns_sbp[1] = tsbp;
490 static int nilfs_load_super_block(struct the_nilfs *nilfs,
491 struct super_block *sb, int blocksize,
492 struct nilfs_super_block **sbpp)
494 struct nilfs_super_block **sbp = nilfs->ns_sbp;
495 struct buffer_head **sbh = nilfs->ns_sbh;
496 u64 sb2off = NILFS_SB2_OFFSET_BYTES(nilfs->ns_bdev->bd_inode->i_size);
497 int valid[2], swp = 0;
499 sbp[0] = nilfs_read_super_block(sb, NILFS_SB_OFFSET_BYTES, blocksize,
501 sbp[1] = nilfs_read_super_block(sb, sb2off, blocksize, &sbh[1]);
505 printk(KERN_ERR "NILFS: unable to read superblock\n");
509 "NILFS warning: unable to read primary superblock\n");
512 "NILFS warning: unable to read secondary superblock\n");
515 * Compare two super blocks and set 1 in swp if the secondary
516 * super block is valid and newer. Otherwise, set 0 in swp.
518 valid[0] = nilfs_valid_sb(sbp[0]);
519 valid[1] = nilfs_valid_sb(sbp[1]);
520 swp = valid[1] && (!valid[0] ||
521 le64_to_cpu(sbp[1]->s_last_cno) >
522 le64_to_cpu(sbp[0]->s_last_cno));
524 if (valid[swp] && nilfs_sb2_bad_offset(sbp[swp], sb2off)) {
531 nilfs_release_super_block(nilfs);
532 printk(KERN_ERR "NILFS: Can't find nilfs on dev %s.\n",
538 printk(KERN_WARNING "NILFS warning: broken superblock. "
539 "using spare superblock.\n");
541 nilfs_swap_super_block(nilfs);
543 nilfs->ns_sbwcount = 0;
544 nilfs->ns_sbwtime = le64_to_cpu(sbp[0]->s_wtime);
545 nilfs->ns_prot_seq = le64_to_cpu(sbp[valid[1] & !swp]->s_last_seq);
551 * init_nilfs - initialize a NILFS instance.
552 * @nilfs: the_nilfs structure
553 * @sbi: nilfs_sb_info
555 * @data: mount options
557 * init_nilfs() performs common initialization per block device (e.g.
558 * reading the super block, getting disk layout information, initializing
559 * shared fields in the_nilfs).
561 * Return Value: On success, 0 is returned. On error, a negative error
564 int init_nilfs(struct the_nilfs *nilfs, struct nilfs_sb_info *sbi, char *data)
566 struct super_block *sb = sbi->s_super;
567 struct nilfs_super_block *sbp;
568 struct backing_dev_info *bdi;
572 down_write(&nilfs->ns_sem);
574 blocksize = sb_min_blocksize(sb, NILFS_MIN_BLOCK_SIZE);
576 printk(KERN_ERR "NILFS: unable to set blocksize\n");
580 err = nilfs_load_super_block(nilfs, sb, blocksize, &sbp);
584 err = nilfs_store_magic_and_option(sb, sbp, data);
588 err = nilfs_check_feature_compatibility(sb, sbp);
592 blocksize = BLOCK_SIZE << le32_to_cpu(sbp->s_log_block_size);
593 if (blocksize < NILFS_MIN_BLOCK_SIZE ||
594 blocksize > NILFS_MAX_BLOCK_SIZE) {
595 printk(KERN_ERR "NILFS: couldn't mount because of unsupported "
596 "filesystem blocksize %d\n", blocksize);
600 if (sb->s_blocksize != blocksize) {
601 int hw_blocksize = bdev_logical_block_size(sb->s_bdev);
603 if (blocksize < hw_blocksize) {
605 "NILFS: blocksize %d too small for device "
606 "(sector-size = %d).\n",
607 blocksize, hw_blocksize);
611 nilfs_release_super_block(nilfs);
612 sb_set_blocksize(sb, blocksize);
614 err = nilfs_load_super_block(nilfs, sb, blocksize, &sbp);
617 /* not failed_sbh; sbh is released automatically
618 when reloading fails. */
620 nilfs->ns_blocksize_bits = sb->s_blocksize_bits;
621 nilfs->ns_blocksize = blocksize;
623 err = nilfs_store_disk_layout(nilfs, sbp);
627 sb->s_maxbytes = nilfs_max_size(sb->s_blocksize_bits);
629 nilfs->ns_mount_state = le16_to_cpu(sbp->s_state);
631 bdi = nilfs->ns_bdev->bd_inode->i_mapping->backing_dev_info;
632 nilfs->ns_bdi = bdi ? : &default_backing_dev_info;
634 err = nilfs_store_log_cursor(nilfs, sbp);
638 set_nilfs_init(nilfs);
641 up_write(&nilfs->ns_sem);
645 nilfs_release_super_block(nilfs);
649 int nilfs_discard_segments(struct the_nilfs *nilfs, __u64 *segnump,
652 sector_t seg_start, seg_end;
653 sector_t start = 0, nblocks = 0;
654 unsigned int sects_per_block;
658 sects_per_block = (1 << nilfs->ns_blocksize_bits) /
659 bdev_logical_block_size(nilfs->ns_bdev);
660 for (sn = segnump; sn < segnump + nsegs; sn++) {
661 nilfs_get_segment_range(nilfs, *sn, &seg_start, &seg_end);
665 nblocks = seg_end - seg_start + 1;
666 } else if (start + nblocks == seg_start) {
667 nblocks += seg_end - seg_start + 1;
669 ret = blkdev_issue_discard(nilfs->ns_bdev,
670 start * sects_per_block,
671 nblocks * sects_per_block,
681 ret = blkdev_issue_discard(nilfs->ns_bdev,
682 start * sects_per_block,
683 nblocks * sects_per_block,
685 BLKDEV_IFL_WAIT | BLKDEV_IFL_BARRIER);
689 int nilfs_count_free_blocks(struct the_nilfs *nilfs, sector_t *nblocks)
691 struct inode *dat = nilfs_dat_inode(nilfs);
692 unsigned long ncleansegs;
694 down_read(&NILFS_MDT(dat)->mi_sem); /* XXX */
695 ncleansegs = nilfs_sufile_get_ncleansegs(nilfs->ns_sufile);
696 up_read(&NILFS_MDT(dat)->mi_sem); /* XXX */
697 *nblocks = (sector_t)ncleansegs * nilfs->ns_blocks_per_segment;
701 int nilfs_near_disk_full(struct the_nilfs *nilfs)
703 unsigned long ncleansegs, nincsegs;
705 ncleansegs = nilfs_sufile_get_ncleansegs(nilfs->ns_sufile);
706 nincsegs = atomic_read(&nilfs->ns_ndirtyblks) /
707 nilfs->ns_blocks_per_segment + 1;
709 return ncleansegs <= nilfs->ns_nrsvsegs + nincsegs;
712 struct nilfs_root *nilfs_lookup_root(struct the_nilfs *nilfs, __u64 cno)
715 struct nilfs_root *root;
717 spin_lock(&nilfs->ns_cptree_lock);
718 n = nilfs->ns_cptree.rb_node;
720 root = rb_entry(n, struct nilfs_root, rb_node);
722 if (cno < root->cno) {
724 } else if (cno > root->cno) {
727 atomic_inc(&root->count);
728 spin_unlock(&nilfs->ns_cptree_lock);
732 spin_unlock(&nilfs->ns_cptree_lock);
738 nilfs_find_or_create_root(struct the_nilfs *nilfs, __u64 cno)
740 struct rb_node **p, *parent;
741 struct nilfs_root *root, *new;
743 root = nilfs_lookup_root(nilfs, cno);
747 new = kmalloc(sizeof(*root), GFP_KERNEL);
751 spin_lock(&nilfs->ns_cptree_lock);
753 p = &nilfs->ns_cptree.rb_node;
758 root = rb_entry(parent, struct nilfs_root, rb_node);
760 if (cno < root->cno) {
762 } else if (cno > root->cno) {
765 atomic_inc(&root->count);
766 spin_unlock(&nilfs->ns_cptree_lock);
775 atomic_set(&new->count, 1);
776 atomic_set(&new->inodes_count, 0);
777 atomic_set(&new->blocks_count, 0);
779 rb_link_node(&new->rb_node, parent, p);
780 rb_insert_color(&new->rb_node, &nilfs->ns_cptree);
782 spin_unlock(&nilfs->ns_cptree_lock);
787 void nilfs_put_root(struct nilfs_root *root)
789 if (atomic_dec_and_test(&root->count)) {
790 struct the_nilfs *nilfs = root->nilfs;
792 spin_lock(&nilfs->ns_cptree_lock);
793 rb_erase(&root->rb_node, &nilfs->ns_cptree);
794 spin_unlock(&nilfs->ns_cptree_lock);
796 nilfs_mdt_destroy(root->ifile);
802 int nilfs_checkpoint_is_mounted(struct the_nilfs *nilfs, __u64 cno,
805 struct nilfs_root *root;
808 if (cno < 0 || cno > nilfs->ns_cno)
811 if (cno >= nilfs_last_cno(nilfs))
812 return true; /* protect recent checkpoints */
815 root = nilfs_lookup_root(nilfs, cno);
818 nilfs_put_root(root);