^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * super.c - NILFS module and super block management.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Written by Ryusuke Konishi.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * linux/fs/ext2/super.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Copyright (C) 1992, 1993, 1994, 1995
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Remy Card (card@masi.ibp.fr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * Laboratoire MASI - Institut Blaise Pascal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * Universite Pierre et Marie Curie (Paris VI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * linux/fs/minix/inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Copyright (C) 1991, 1992 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * Big-endian to little-endian byte-swapping/bitmaps by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * David S. Miller (davem@caip.rutgers.edu), 1995
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/parser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/crc32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/vfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/writeback.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include "nilfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include "export.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include "mdt.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include "alloc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include "btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include "btnode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include "page.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include "cpfile.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include "sufile.h" /* nilfs_sufile_resize(), nilfs_sufile_set_alloc_range() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include "ifile.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include "dat.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include "segment.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include "segbuf.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) MODULE_AUTHOR("NTT Corp.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) MODULE_DESCRIPTION("A New Implementation of the Log-structured Filesystem "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) "(NILFS)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static struct kmem_cache *nilfs_inode_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct kmem_cache *nilfs_transaction_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct kmem_cache *nilfs_segbuf_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct kmem_cache *nilfs_btree_path_cache;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static int nilfs_setup_super(struct super_block *sb, int is_mount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static int nilfs_remount(struct super_block *sb, int *flags, char *data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) void __nilfs_msg(struct super_block *sb, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) level = printk_get_level(fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) vaf.fmt = printk_skip_level(fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) printk("%c%cNILFS (%s): %pV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) KERN_SOH_ASCII, level, sb->s_id, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) printk("%c%cNILFS: %pV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) KERN_SOH_ASCII, level, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static void nilfs_set_error(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct nilfs_super_block **sbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) down_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (!(nilfs->ns_mount_state & NILFS_ERROR_FS)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) nilfs->ns_mount_state |= NILFS_ERROR_FS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) sbp = nilfs_prepare_super(sb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (likely(sbp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) sbp[0]->s_state |= cpu_to_le16(NILFS_ERROR_FS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (sbp[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) sbp[1]->s_state |= cpu_to_le16(NILFS_ERROR_FS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) nilfs_commit_super(sb, NILFS_SB_COMMIT_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) up_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * __nilfs_error() - report failure condition on a filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * __nilfs_error() sets an ERROR_FS flag on the superblock as well as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * reporting an error message. This function should be called when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * NILFS detects incoherences or defects of meta data on disk.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * This implements the body of nilfs_error() macro. Normally,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * nilfs_error() should be used. As for sustainable errors such as a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * single-shot I/O error, nilfs_err() should be used instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * Callers should not add a trailing newline since this will do it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) void __nilfs_error(struct super_block *sb, const char *function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) printk(KERN_CRIT "NILFS error (device %s): %s: %pV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) sb->s_id, function, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) nilfs_set_error(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (nilfs_test_opt(nilfs, ERRORS_RO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) printk(KERN_CRIT "Remounting filesystem read-only\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (nilfs_test_opt(nilfs, ERRORS_PANIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) panic("NILFS (device %s): panic forced after error\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) sb->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct inode *nilfs_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct nilfs_inode_info *ii;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ii = kmem_cache_alloc(nilfs_inode_cachep, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (!ii)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ii->i_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ii->i_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ii->i_cno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) nilfs_mapping_init(&ii->i_btnode_cache, &ii->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return &ii->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static void nilfs_free_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (nilfs_is_metadata_file_inode(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) nilfs_mdt_destroy(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) kmem_cache_free(nilfs_inode_cachep, NILFS_I(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static int nilfs_sync_super(struct super_block *sb, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) set_buffer_dirty(nilfs->ns_sbh[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) if (nilfs_test_opt(nilfs, BARRIER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) err = __sync_dirty_buffer(nilfs->ns_sbh[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) REQ_SYNC | REQ_PREFLUSH | REQ_FUA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) err = sync_dirty_buffer(nilfs->ns_sbh[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (unlikely(err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) nilfs_err(sb, "unable to write superblock: err=%d", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (err == -EIO && nilfs->ns_sbh[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * sbp[0] points to newer log than sbp[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * so copy sbp[0] to sbp[1] to take over sbp[0].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) memcpy(nilfs->ns_sbp[1], nilfs->ns_sbp[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) nilfs->ns_sbsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) nilfs_fall_back_super_block(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct nilfs_super_block *sbp = nilfs->ns_sbp[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) nilfs->ns_sbwcount++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * The latest segment becomes trailable from the position
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * written in superblock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) clear_nilfs_discontinued(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /* update GC protection for recent segments */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (nilfs->ns_sbh[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (flag == NILFS_SB_COMMIT_ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) set_buffer_dirty(nilfs->ns_sbh[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (sync_dirty_buffer(nilfs->ns_sbh[1]) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (le64_to_cpu(nilfs->ns_sbp[1]->s_last_cno) <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) le64_to_cpu(nilfs->ns_sbp[0]->s_last_cno))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) sbp = nilfs->ns_sbp[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) spin_lock(&nilfs->ns_last_segment_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) nilfs->ns_prot_seq = le64_to_cpu(sbp->s_last_seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) spin_unlock(&nilfs->ns_last_segment_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) void nilfs_set_log_cursor(struct nilfs_super_block *sbp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) struct the_nilfs *nilfs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) sector_t nfreeblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /* nilfs->ns_sem must be locked by the caller. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) nilfs_count_free_blocks(nilfs, &nfreeblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) sbp->s_free_blocks_count = cpu_to_le64(nfreeblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) spin_lock(&nilfs->ns_last_segment_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) sbp->s_last_seq = cpu_to_le64(nilfs->ns_last_seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) sbp->s_last_pseg = cpu_to_le64(nilfs->ns_last_pseg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) sbp->s_last_cno = cpu_to_le64(nilfs->ns_last_cno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) spin_unlock(&nilfs->ns_last_segment_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct nilfs_super_block **nilfs_prepare_super(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) int flip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct nilfs_super_block **sbp = nilfs->ns_sbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* nilfs->ns_sem must be locked by the caller. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (sbp[0]->s_magic != cpu_to_le16(NILFS_SUPER_MAGIC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (sbp[1] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) sbp[1]->s_magic == cpu_to_le16(NILFS_SUPER_MAGIC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) memcpy(sbp[0], sbp[1], nilfs->ns_sbsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) nilfs_crit(sb, "superblock broke");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) } else if (sbp[1] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) sbp[1]->s_magic != cpu_to_le16(NILFS_SUPER_MAGIC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) memcpy(sbp[1], sbp[0], nilfs->ns_sbsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (flip && sbp[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) nilfs_swap_super_block(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) return sbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int nilfs_commit_super(struct super_block *sb, int flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct nilfs_super_block **sbp = nilfs->ns_sbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) time64_t t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /* nilfs->ns_sem must be locked by the caller. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) t = ktime_get_real_seconds();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) nilfs->ns_sbwtime = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) sbp[0]->s_wtime = cpu_to_le64(t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) sbp[0]->s_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) sbp[0]->s_sum = cpu_to_le32(crc32_le(nilfs->ns_crc_seed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) (unsigned char *)sbp[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) nilfs->ns_sbsize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) if (flag == NILFS_SB_COMMIT_ALL && sbp[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) sbp[1]->s_wtime = sbp[0]->s_wtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) sbp[1]->s_sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) sbp[1]->s_sum = cpu_to_le32(crc32_le(nilfs->ns_crc_seed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) (unsigned char *)sbp[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) nilfs->ns_sbsize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) clear_nilfs_sb_dirty(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) nilfs->ns_flushed_device = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /* make sure store to ns_flushed_device cannot be reordered */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) smp_wmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return nilfs_sync_super(sb, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * nilfs_cleanup_super() - write filesystem state for cleanup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * @sb: super block instance to be unmounted or degraded to read-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * This function restores state flags in the on-disk super block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * This will set "clean" flag (i.e. NILFS_VALID_FS) unless the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * filesystem was not clean previously.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) int nilfs_cleanup_super(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct nilfs_super_block **sbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) int flag = NILFS_SB_COMMIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) int ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) sbp = nilfs_prepare_super(sb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (sbp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) sbp[0]->s_state = cpu_to_le16(nilfs->ns_mount_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) nilfs_set_log_cursor(sbp[0], nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (sbp[1] && sbp[0]->s_last_cno == sbp[1]->s_last_cno) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * make the "clean" flag also to the opposite
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * super block if both super blocks point to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * the same checkpoint.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) sbp[1]->s_state = sbp[0]->s_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) flag = NILFS_SB_COMMIT_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) ret = nilfs_commit_super(sb, flag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) * nilfs_move_2nd_super - relocate secondary super block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) * @sb: super block instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) * @sb2off: new offset of the secondary super block (in bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) static int nilfs_move_2nd_super(struct super_block *sb, loff_t sb2off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) struct buffer_head *nsbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) struct nilfs_super_block *nsbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) sector_t blocknr, newblocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) unsigned long offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) int sb2i; /* array index of the secondary superblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /* nilfs->ns_sem must be locked by the caller. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if (nilfs->ns_sbh[1] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) nilfs->ns_sbh[1]->b_blocknr > nilfs->ns_first_data_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) sb2i = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) blocknr = nilfs->ns_sbh[1]->b_blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) } else if (nilfs->ns_sbh[0]->b_blocknr > nilfs->ns_first_data_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) sb2i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) blocknr = nilfs->ns_sbh[0]->b_blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) sb2i = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) blocknr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (sb2i >= 0 && (u64)blocknr << nilfs->ns_blocksize_bits == sb2off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) goto out; /* super block location is unchanged */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) /* Get new super block buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) newblocknr = sb2off >> nilfs->ns_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) offset = sb2off & (nilfs->ns_blocksize - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) nsbh = sb_getblk(sb, newblocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (!nsbh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) nilfs_warn(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) "unable to move secondary superblock to block %llu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) (unsigned long long)newblocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) nsbp = (void *)nsbh->b_data + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) memset(nsbp, 0, nilfs->ns_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (sb2i >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) memcpy(nsbp, nilfs->ns_sbp[sb2i], nilfs->ns_sbsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) brelse(nilfs->ns_sbh[sb2i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) nilfs->ns_sbh[sb2i] = nsbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) nilfs->ns_sbp[sb2i] = nsbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) } else if (nilfs->ns_sbh[0]->b_blocknr < nilfs->ns_first_data_block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) /* secondary super block will be restored to index 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) nilfs->ns_sbh[1] = nsbh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) nilfs->ns_sbp[1] = nsbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) brelse(nsbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * nilfs_resize_fs - resize the filesystem
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * @sb: super block instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) * @newsize: new size of the filesystem (in bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) int nilfs_resize_fs(struct super_block *sb, __u64 newsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct nilfs_super_block **sbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) __u64 devsize, newnsegs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) loff_t sb2off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) ret = -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) devsize = i_size_read(sb->s_bdev->bd_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (newsize > devsize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) * Write lock is required to protect some functions depending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * on the number of segments, the number of reserved segments,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * and so forth.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) down_write(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) sb2off = NILFS_SB2_OFFSET_BYTES(newsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) newnsegs = sb2off >> nilfs->ns_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) do_div(newnsegs, nilfs->ns_blocks_per_segment);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) ret = nilfs_sufile_resize(nilfs->ns_sufile, newnsegs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) up_write(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) ret = nilfs_construct_segment(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) down_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) nilfs_move_2nd_super(sb, sb2off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) ret = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) sbp = nilfs_prepare_super(sb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (likely(sbp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) nilfs_set_log_cursor(sbp[0], nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * Drop NILFS_RESIZE_FS flag for compatibility with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * mount-time resize which may be implemented in a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * future release.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) sbp[0]->s_state = cpu_to_le16(le16_to_cpu(sbp[0]->s_state) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) ~NILFS_RESIZE_FS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) sbp[0]->s_dev_size = cpu_to_le64(newsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) sbp[0]->s_nsegments = cpu_to_le64(nilfs->ns_nsegments);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (sbp[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) memcpy(sbp[1], sbp[0], nilfs->ns_sbsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) ret = nilfs_commit_super(sb, NILFS_SB_COMMIT_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) up_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) * Reset the range of allocatable segments last. This order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) * is important in the case of expansion because the secondary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) * superblock must be protected from log write until migration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * completes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) nilfs_sufile_set_alloc_range(nilfs->ns_sufile, 0, newnsegs - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static void nilfs_put_super(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) nilfs_detach_log_writer(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) down_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) nilfs_cleanup_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) up_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) iput(nilfs->ns_sufile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) iput(nilfs->ns_cpfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) iput(nilfs->ns_dat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) destroy_nilfs(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) sb->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) static int nilfs_sync_fs(struct super_block *sb, int wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) struct nilfs_super_block **sbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) /* This function is called when super block should be written back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) if (wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) err = nilfs_construct_segment(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) down_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (nilfs_sb_dirty(nilfs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) sbp = nilfs_prepare_super(sb, nilfs_sb_will_flip(nilfs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (likely(sbp)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) nilfs_set_log_cursor(sbp[0], nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) nilfs_commit_super(sb, NILFS_SB_COMMIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) up_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) err = nilfs_flush_device(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) int nilfs_attach_checkpoint(struct super_block *sb, __u64 cno, int curr_mnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) struct nilfs_root **rootp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) struct nilfs_root *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) struct nilfs_checkpoint *raw_cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) struct buffer_head *bh_cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) int err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) root = nilfs_find_or_create_root(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) nilfs, curr_mnt ? NILFS_CPTREE_CURRENT_CNO : cno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) if (!root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) if (root->ifile)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) goto reuse; /* already attached checkpoint */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) down_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) err = nilfs_cpfile_get_checkpoint(nilfs->ns_cpfile, cno, 0, &raw_cp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) &bh_cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) up_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (unlikely(err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) if (err == -ENOENT || err == -EINVAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) nilfs_err(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) "Invalid checkpoint (checkpoint number=%llu)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) (unsigned long long)cno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) err = nilfs_ifile_read(sb, root, nilfs->ns_inode_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) &raw_cp->cp_ifile_inode, &root->ifile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) goto failed_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) atomic64_set(&root->inodes_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) le64_to_cpu(raw_cp->cp_inodes_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) atomic64_set(&root->blocks_count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) le64_to_cpu(raw_cp->cp_blocks_count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) nilfs_cpfile_put_checkpoint(nilfs->ns_cpfile, cno, bh_cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) reuse:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) *rootp = root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) failed_bh:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) nilfs_cpfile_put_checkpoint(nilfs->ns_cpfile, cno, bh_cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) nilfs_put_root(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) static int nilfs_freeze(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) /* Mark super block clean */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) down_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) err = nilfs_cleanup_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) up_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) static int nilfs_unfreeze(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) if (sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) down_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) nilfs_setup_super(sb, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) up_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) static int nilfs_statfs(struct dentry *dentry, struct kstatfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) struct super_block *sb = dentry->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) struct nilfs_root *root = NILFS_I(d_inode(dentry))->i_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) struct the_nilfs *nilfs = root->nilfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) unsigned long long blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) unsigned long overhead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) unsigned long nrsvblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) sector_t nfreeblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) u64 nmaxinodes, nfreeinodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) * Compute all of the segment blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) * The blocks before first segment and after last segment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) * are excluded.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) blocks = nilfs->ns_blocks_per_segment * nilfs->ns_nsegments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) - nilfs->ns_first_data_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) nrsvblocks = nilfs->ns_nrsvsegs * nilfs->ns_blocks_per_segment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) * Compute the overhead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) * When distributing meta data blocks outside segment structure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) * We must count them as the overhead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) overhead = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) err = nilfs_count_free_blocks(nilfs, &nfreeblocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) if (unlikely(err))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) err = nilfs_ifile_count_free_inodes(root->ifile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) &nmaxinodes, &nfreeinodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) if (unlikely(err)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) nilfs_warn(sb, "failed to count free inodes: err=%d", err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (err == -ERANGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) * If nilfs_palloc_count_max_entries() returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) * -ERANGE error code then we simply treat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) * curent inodes count as maximum possible and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) * zero as free inodes value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) nmaxinodes = atomic64_read(&root->inodes_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) nfreeinodes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) buf->f_type = NILFS_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) buf->f_bsize = sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) buf->f_blocks = blocks - overhead;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) buf->f_bfree = nfreeblocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) buf->f_bavail = (buf->f_bfree >= nrsvblocks) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) (buf->f_bfree - nrsvblocks) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) buf->f_files = nmaxinodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) buf->f_ffree = nfreeinodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) buf->f_namelen = NILFS_NAME_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) buf->f_fsid = u64_to_fsid(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) static int nilfs_show_options(struct seq_file *seq, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) struct super_block *sb = dentry->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) struct nilfs_root *root = NILFS_I(d_inode(dentry))->i_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) if (!nilfs_test_opt(nilfs, BARRIER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) seq_puts(seq, ",nobarrier");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) if (root->cno != NILFS_CPTREE_CURRENT_CNO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) seq_printf(seq, ",cp=%llu", (unsigned long long)root->cno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) if (nilfs_test_opt(nilfs, ERRORS_PANIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) seq_puts(seq, ",errors=panic");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) if (nilfs_test_opt(nilfs, ERRORS_CONT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) seq_puts(seq, ",errors=continue");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) if (nilfs_test_opt(nilfs, STRICT_ORDER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) seq_puts(seq, ",order=strict");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (nilfs_test_opt(nilfs, NORECOVERY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) seq_puts(seq, ",norecovery");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) if (nilfs_test_opt(nilfs, DISCARD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) seq_puts(seq, ",discard");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) static const struct super_operations nilfs_sops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) .alloc_inode = nilfs_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) .free_inode = nilfs_free_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) .dirty_inode = nilfs_dirty_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) .evict_inode = nilfs_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) .put_super = nilfs_put_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) .sync_fs = nilfs_sync_fs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) .freeze_fs = nilfs_freeze,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) .unfreeze_fs = nilfs_unfreeze,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) .statfs = nilfs_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) .remount_fs = nilfs_remount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) .show_options = nilfs_show_options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) Opt_err_cont, Opt_err_panic, Opt_err_ro,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) Opt_barrier, Opt_nobarrier, Opt_snapshot, Opt_order, Opt_norecovery,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) Opt_discard, Opt_nodiscard, Opt_err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) static match_table_t tokens = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) {Opt_err_cont, "errors=continue"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) {Opt_err_panic, "errors=panic"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) {Opt_err_ro, "errors=remount-ro"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) {Opt_barrier, "barrier"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) {Opt_nobarrier, "nobarrier"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) {Opt_snapshot, "cp=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) {Opt_order, "order=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) {Opt_norecovery, "norecovery"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) {Opt_discard, "discard"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) {Opt_nodiscard, "nodiscard"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) {Opt_err, NULL}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) static int parse_options(char *options, struct super_block *sb, int is_remount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) substring_t args[MAX_OPT_ARGS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (!options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) while ((p = strsep(&options, ",")) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) int token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) if (!*p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) token = match_token(p, tokens, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) switch (token) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) case Opt_barrier:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) nilfs_set_opt(nilfs, BARRIER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) case Opt_nobarrier:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) nilfs_clear_opt(nilfs, BARRIER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) case Opt_order:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) if (strcmp(args[0].from, "relaxed") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) /* Ordered data semantics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) nilfs_clear_opt(nilfs, STRICT_ORDER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) else if (strcmp(args[0].from, "strict") == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) /* Strict in-order semantics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) nilfs_set_opt(nilfs, STRICT_ORDER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) case Opt_err_panic:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) nilfs_write_opt(nilfs, ERROR_MODE, ERRORS_PANIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) case Opt_err_ro:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) nilfs_write_opt(nilfs, ERROR_MODE, ERRORS_RO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) case Opt_err_cont:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) nilfs_write_opt(nilfs, ERROR_MODE, ERRORS_CONT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) case Opt_snapshot:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) if (is_remount) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) nilfs_err(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) "\"%s\" option is invalid for remount",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) case Opt_norecovery:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) nilfs_set_opt(nilfs, NORECOVERY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) case Opt_discard:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) nilfs_set_opt(nilfs, DISCARD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) case Opt_nodiscard:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) nilfs_clear_opt(nilfs, DISCARD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) nilfs_err(sb, "unrecognized mount option \"%s\"", p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) static inline void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) nilfs_set_default_options(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) struct nilfs_super_block *sbp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) nilfs->ns_mount_opt =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) NILFS_MOUNT_ERRORS_RO | NILFS_MOUNT_BARRIER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) static int nilfs_setup_super(struct super_block *sb, int is_mount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) struct nilfs_super_block **sbp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) int max_mnt_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) int mnt_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) /* nilfs->ns_sem must be locked by the caller. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) sbp = nilfs_prepare_super(sb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) if (!sbp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) if (!is_mount)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) goto skip_mount_setup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) max_mnt_count = le16_to_cpu(sbp[0]->s_max_mnt_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) mnt_count = le16_to_cpu(sbp[0]->s_mnt_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) if (nilfs->ns_mount_state & NILFS_ERROR_FS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) nilfs_warn(sb, "mounting fs with errors");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) } else if (max_mnt_count >= 0 && mnt_count >= max_mnt_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) nilfs_warn(sb, "maximal mount count reached");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) if (!max_mnt_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) sbp[0]->s_max_mnt_count = cpu_to_le16(NILFS_DFL_MAX_MNT_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) sbp[0]->s_mnt_count = cpu_to_le16(mnt_count + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) sbp[0]->s_mtime = cpu_to_le64(ktime_get_real_seconds());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) skip_mount_setup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) sbp[0]->s_state =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) cpu_to_le16(le16_to_cpu(sbp[0]->s_state) & ~NILFS_VALID_FS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) /* synchronize sbp[1] with sbp[0] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (sbp[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) memcpy(sbp[1], sbp[0], nilfs->ns_sbsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) return nilfs_commit_super(sb, NILFS_SB_COMMIT_ALL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) struct nilfs_super_block *nilfs_read_super_block(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) u64 pos, int blocksize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) struct buffer_head **pbh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) unsigned long long sb_index = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) unsigned long offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) offset = do_div(sb_index, blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) *pbh = sb_bread(sb, sb_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) if (!*pbh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) return (struct nilfs_super_block *)((char *)(*pbh)->b_data + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) int nilfs_store_magic_and_option(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) struct nilfs_super_block *sbp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) sb->s_magic = le16_to_cpu(sbp->s_magic);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) /* FS independent flags */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) #ifdef NILFS_ATIME_DISABLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) sb->s_flags |= SB_NOATIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) nilfs_set_default_options(sb, sbp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) nilfs->ns_resuid = le16_to_cpu(sbp->s_def_resuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) nilfs->ns_resgid = le16_to_cpu(sbp->s_def_resgid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) nilfs->ns_interval = le32_to_cpu(sbp->s_c_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) nilfs->ns_watermark = le32_to_cpu(sbp->s_c_block_max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) return !parse_options(data, sb, 0) ? -EINVAL : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) int nilfs_check_feature_compatibility(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) struct nilfs_super_block *sbp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) __u64 features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) features = le64_to_cpu(sbp->s_feature_incompat) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) ~NILFS_FEATURE_INCOMPAT_SUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) if (features) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) nilfs_err(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) "couldn't mount because of unsupported optional features (%llx)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) (unsigned long long)features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) features = le64_to_cpu(sbp->s_feature_compat_ro) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) ~NILFS_FEATURE_COMPAT_RO_SUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) if (!sb_rdonly(sb) && features) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) nilfs_err(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) "couldn't mount RDWR because of unsupported optional features (%llx)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) (unsigned long long)features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) static int nilfs_get_root_dentry(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) struct nilfs_root *root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) struct dentry **root_dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) inode = nilfs_iget(sb, root, NILFS_ROOT_INO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) ret = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) nilfs_err(sb, "error %d getting root inode", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) if (!S_ISDIR(inode->i_mode) || !inode->i_blocks || !inode->i_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) nilfs_err(sb, "corrupt root inode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) if (root->cno == NILFS_CPTREE_CURRENT_CNO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) dentry = d_find_alias(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) if (!dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) dentry = d_make_root(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) if (!dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) goto failed_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) dentry = d_obtain_root(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) if (IS_ERR(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) ret = PTR_ERR(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) goto failed_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) *root_dentry = dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) failed_dentry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) nilfs_err(sb, "error %d getting root dentry", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) static int nilfs_attach_snapshot(struct super_block *s, __u64 cno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) struct dentry **root_dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) struct the_nilfs *nilfs = s->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) struct nilfs_root *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) mutex_lock(&nilfs->ns_snapshot_mount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) down_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) ret = nilfs_cpfile_is_snapshot(nilfs->ns_cpfile, cno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) up_read(&nilfs->ns_segctor_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) ret = (ret == -ENOENT) ? -EINVAL : ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) } else if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) nilfs_err(s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) "The specified checkpoint is not a snapshot (checkpoint number=%llu)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) (unsigned long long)cno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) ret = nilfs_attach_checkpoint(s, cno, false, &root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) nilfs_err(s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) "error %d while loading snapshot (checkpoint number=%llu)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) ret, (unsigned long long)cno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) ret = nilfs_get_root_dentry(s, root, root_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) nilfs_put_root(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) mutex_unlock(&nilfs->ns_snapshot_mount_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) * nilfs_tree_is_busy() - try to shrink dentries of a checkpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) * @root_dentry: root dentry of the tree to be shrunk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) * This function returns true if the tree was in-use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) static bool nilfs_tree_is_busy(struct dentry *root_dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) shrink_dcache_parent(root_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) return d_count(root_dentry) > 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) int nilfs_checkpoint_is_mounted(struct super_block *sb, __u64 cno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) struct nilfs_root *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) if (cno > nilfs->ns_cno)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) if (cno >= nilfs_last_cno(nilfs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) return true; /* protect recent checkpoints */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) root = nilfs_lookup_root(nilfs, cno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) if (root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) inode = nilfs_ilookup(sb, root, NILFS_ROOT_INO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) if (inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) dentry = d_find_alias(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) if (dentry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) ret = nilfs_tree_is_busy(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) dput(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) nilfs_put_root(root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) * nilfs_fill_super() - initialize a super block instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) * @sb: super_block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) * @data: mount options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) * @silent: silent mode flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) * This function is called exclusively by nilfs->ns_mount_mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) * So, the recovery process is protected from other simultaneous mounts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) nilfs_fill_super(struct super_block *sb, void *data, int silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) struct the_nilfs *nilfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) struct nilfs_root *fsroot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) __u64 cno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) nilfs = alloc_nilfs(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) if (!nilfs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) sb->s_fs_info = nilfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) err = init_nilfs(nilfs, sb, (char *)data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) goto failed_nilfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) sb->s_op = &nilfs_sops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) sb->s_export_op = &nilfs_export_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) sb->s_root = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) sb->s_time_gran = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) sb->s_max_links = NILFS_LINK_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) sb->s_bdi = bdi_get(sb->s_bdev->bd_bdi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) err = load_nilfs(nilfs, sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) goto failed_nilfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) cno = nilfs_last_cno(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) err = nilfs_attach_checkpoint(sb, cno, true, &fsroot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) nilfs_err(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) "error %d while loading last checkpoint (checkpoint number=%llu)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) err, (unsigned long long)cno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) goto failed_unload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) err = nilfs_attach_log_writer(sb, fsroot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) goto failed_checkpoint;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) err = nilfs_get_root_dentry(sb, fsroot, &sb->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) goto failed_segctor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) nilfs_put_root(fsroot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) down_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) nilfs_setup_super(sb, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) up_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) failed_segctor:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) nilfs_detach_log_writer(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) failed_checkpoint:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) nilfs_put_root(fsroot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) failed_unload:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) iput(nilfs->ns_sufile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) iput(nilfs->ns_cpfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) iput(nilfs->ns_dat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) failed_nilfs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) destroy_nilfs(nilfs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) static int nilfs_remount(struct super_block *sb, int *flags, char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) struct the_nilfs *nilfs = sb->s_fs_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) unsigned long old_sb_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) unsigned long old_mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) sync_filesystem(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) old_sb_flags = sb->s_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) old_mount_opt = nilfs->ns_mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) if (!parse_options(data, sb, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) sb->s_flags = (sb->s_flags & ~SB_POSIXACL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) if (!nilfs_valid_fs(nilfs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) nilfs_warn(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) "couldn't remount because the filesystem is in an incomplete recovery state");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) if (*flags & SB_RDONLY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) /* Shutting down log writer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) nilfs_detach_log_writer(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) * Remounting a valid RW partition RDONLY, so set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) * the RDONLY flag and then mark the partition as valid again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) down_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) nilfs_cleanup_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) up_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) __u64 features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) struct nilfs_root *root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) * Mounting a RDONLY partition read-write, so reread and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) * store the current valid flag. (It may have been changed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) * by fsck since we originally mounted the partition.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) down_read(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) features = le64_to_cpu(nilfs->ns_sbp[0]->s_feature_compat_ro) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) ~NILFS_FEATURE_COMPAT_RO_SUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) up_read(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) if (features) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) nilfs_warn(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) "couldn't remount RDWR because of unsupported optional features (%llx)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) (unsigned long long)features);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) err = -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) sb->s_flags &= ~SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) root = NILFS_I(d_inode(sb->s_root))->i_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) err = nilfs_attach_log_writer(sb, root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) goto restore_opts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) down_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) nilfs_setup_super(sb, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) up_write(&nilfs->ns_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) restore_opts:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) sb->s_flags = old_sb_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) nilfs->ns_mount_opt = old_mount_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) struct nilfs_super_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) struct block_device *bdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) __u64 cno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) static int nilfs_parse_snapshot_option(const char *option,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) const substring_t *arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) struct nilfs_super_data *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) unsigned long long val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) const char *msg = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) if (!(sd->flags & SB_RDONLY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) msg = "read-only option is not specified";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) goto parse_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) err = kstrtoull(arg->from, 0, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) if (err == -ERANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) msg = "too large checkpoint number";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) msg = "malformed argument";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) goto parse_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) } else if (val == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) msg = "invalid checkpoint number 0";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) goto parse_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) sd->cno = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) parse_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) nilfs_err(NULL, "invalid option \"%s\": %s", option, msg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) * nilfs_identify - pre-read mount options needed to identify mount instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) * @data: mount options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) * @sd: nilfs_super_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) static int nilfs_identify(char *data, struct nilfs_super_data *sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) char *p, *options = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) substring_t args[MAX_OPT_ARGS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) int token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) p = strsep(&options, ",");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) if (p != NULL && *p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) token = match_token(p, tokens, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) if (token == Opt_snapshot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) ret = nilfs_parse_snapshot_option(p, &args[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) sd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) if (!options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) BUG_ON(options == data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) *(options - 1) = ',';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) } while (!ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) static int nilfs_set_bdev_super(struct super_block *s, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) s->s_bdev = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) s->s_dev = s->s_bdev->bd_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) static int nilfs_test_bdev_super(struct super_block *s, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) return (void *)s->s_bdev == data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) static struct dentry *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) nilfs_mount(struct file_system_type *fs_type, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) const char *dev_name, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) struct nilfs_super_data sd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) struct super_block *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) fmode_t mode = FMODE_READ | FMODE_EXCL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) struct dentry *root_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) int err, s_new = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) if (!(flags & SB_RDONLY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) mode |= FMODE_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) sd.bdev = blkdev_get_by_path(dev_name, mode, fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) if (IS_ERR(sd.bdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) return ERR_CAST(sd.bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) sd.cno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) sd.flags = flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) if (nilfs_identify((char *)data, &sd)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) * once the super is inserted into the list by sget, s_umount
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) * will protect the lockfs code from trying to start a snapshot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) * while we are mounting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) mutex_lock(&sd.bdev->bd_fsfreeze_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) if (sd.bdev->bd_fsfreeze_count > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) mutex_unlock(&sd.bdev->bd_fsfreeze_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) s = sget(fs_type, nilfs_test_bdev_super, nilfs_set_bdev_super, flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) sd.bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) mutex_unlock(&sd.bdev->bd_fsfreeze_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) if (IS_ERR(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) err = PTR_ERR(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) if (!s->s_root) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) s_new = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) /* New superblock instance created */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) s->s_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) snprintf(s->s_id, sizeof(s->s_id), "%pg", sd.bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) sb_set_blocksize(s, block_size(sd.bdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) err = nilfs_fill_super(s, data, flags & SB_SILENT ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) goto failed_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) s->s_flags |= SB_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) } else if (!sd.cno) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) if (nilfs_tree_is_busy(s->s_root)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) if ((flags ^ s->s_flags) & SB_RDONLY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) nilfs_err(s,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) "the device already has a %s mount.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) sb_rdonly(s) ? "read-only" : "read/write");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) err = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) goto failed_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) * Try remount to setup mount states if the current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) * tree is not mounted and only snapshots use this sb.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) err = nilfs_remount(s, &flags, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) goto failed_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) if (sd.cno) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) err = nilfs_attach_snapshot(s, sd.cno, &root_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) goto failed_super;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) root_dentry = dget(s->s_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) if (!s_new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) blkdev_put(sd.bdev, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) return root_dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) failed_super:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) deactivate_locked_super(s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) if (!s_new)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) blkdev_put(sd.bdev, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) struct file_system_type nilfs_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) .name = "nilfs2",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) .mount = nilfs_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) .kill_sb = kill_block_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) .fs_flags = FS_REQUIRES_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) MODULE_ALIAS_FS("nilfs2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) static void nilfs_inode_init_once(void *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) struct nilfs_inode_info *ii = obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) INIT_LIST_HEAD(&ii->i_dirty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) #ifdef CONFIG_NILFS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) init_rwsem(&ii->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) address_space_init_once(&ii->i_btnode_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) ii->i_bmap = &ii->i_bmap_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) inode_init_once(&ii->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) static void nilfs_segbuf_init_once(void *obj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) memset(obj, 0, sizeof(struct nilfs_segment_buffer));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) static void nilfs_destroy_cachep(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) * Make sure all delayed rcu free inodes are flushed before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) * destroy cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) kmem_cache_destroy(nilfs_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) kmem_cache_destroy(nilfs_transaction_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) kmem_cache_destroy(nilfs_segbuf_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) kmem_cache_destroy(nilfs_btree_path_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) static int __init nilfs_init_cachep(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) nilfs_inode_cachep = kmem_cache_create("nilfs2_inode_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) sizeof(struct nilfs_inode_info), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) SLAB_RECLAIM_ACCOUNT|SLAB_ACCOUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) nilfs_inode_init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) if (!nilfs_inode_cachep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) nilfs_transaction_cachep = kmem_cache_create("nilfs2_transaction_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) sizeof(struct nilfs_transaction_info), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) SLAB_RECLAIM_ACCOUNT, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) if (!nilfs_transaction_cachep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) nilfs_segbuf_cachep = kmem_cache_create("nilfs2_segbuf_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) sizeof(struct nilfs_segment_buffer), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) SLAB_RECLAIM_ACCOUNT, nilfs_segbuf_init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) if (!nilfs_segbuf_cachep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) nilfs_btree_path_cache = kmem_cache_create("nilfs2_btree_path_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) sizeof(struct nilfs_btree_path) * NILFS_BTREE_LEVEL_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 0, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) if (!nilfs_btree_path_cache)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) nilfs_destroy_cachep();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) static int __init init_nilfs_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) err = nilfs_init_cachep();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) err = nilfs_sysfs_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) goto free_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) err = register_filesystem(&nilfs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) goto deinit_sysfs_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) printk(KERN_INFO "NILFS version 2 loaded\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) deinit_sysfs_entry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) nilfs_sysfs_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) free_cachep:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) nilfs_destroy_cachep();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) static void __exit exit_nilfs_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) nilfs_destroy_cachep();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) nilfs_sysfs_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) unregister_filesystem(&nilfs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) module_init(init_nilfs_fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) module_exit(exit_nilfs_fs)