^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) International Business Machines Corp., 2000-2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Portions Copyright (C) Christoph Hellwig, 2001-2002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/parser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/vfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/quotaops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/posix_acl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/exportfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/crc32.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "jfs_incore.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "jfs_filsys.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "jfs_inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "jfs_metapage.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include "jfs_superblock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include "jfs_dmap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "jfs_imap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "jfs_acl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "jfs_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include "jfs_xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include "jfs_dinode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) MODULE_DESCRIPTION("The Journaled Filesystem (JFS)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) MODULE_AUTHOR("Steve Best/Dave Kleikamp/Barry Arndt, IBM");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static struct kmem_cache *jfs_inode_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static const struct super_operations jfs_super_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) static const struct export_operations jfs_export_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static struct file_system_type jfs_fs_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define MAX_COMMIT_THREADS 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static int commit_threads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) module_param(commit_threads, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) MODULE_PARM_DESC(commit_threads, "Number of commit threads");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) static struct task_struct *jfsCommitThread[MAX_COMMIT_THREADS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct task_struct *jfsIOthread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct task_struct *jfsSyncThread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #ifdef CONFIG_JFS_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) int jfsloglevel = JFS_LOGLEVEL_WARN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) module_param(jfsloglevel, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) MODULE_PARM_DESC(jfsloglevel, "Specify JFS loglevel (0, 1 or 2)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static void jfs_handle_error(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct jfs_sb_info *sbi = JFS_SBI(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) updateSuper(sb, FM_DIRTY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (sbi->flag & JFS_ERR_PANIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) panic("JFS (device %s): panic forced after error\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) sb->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) else if (sbi->flag & JFS_ERR_REMOUNT_RO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) jfs_err("ERROR: (device %s): remounting filesystem as read-only",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) sb->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /* nothing is done for continue beyond marking the superblock dirty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) void jfs_error(struct super_block *sb, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) pr_err("ERROR: (device %s): %ps: %pV\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) sb->s_id, __builtin_return_address(0), &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) jfs_handle_error(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static struct inode *jfs_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct jfs_inode_info *jfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) jfs_inode = kmem_cache_alloc(jfs_inode_cachep, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (!jfs_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) memset(&jfs_inode->i_dquot, 0, sizeof(jfs_inode->i_dquot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return &jfs_inode->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static void jfs_free_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) kmem_cache_free(jfs_inode_cachep, JFS_IP(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static int jfs_statfs(struct dentry *dentry, struct kstatfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct jfs_sb_info *sbi = JFS_SBI(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) s64 maxinodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct inomap *imap = JFS_IP(sbi->ipimap)->i_imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) jfs_info("In jfs_statfs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) buf->f_type = JFS_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) buf->f_bsize = sbi->bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) buf->f_blocks = sbi->bmap->db_mapsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) buf->f_bfree = sbi->bmap->db_nfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) buf->f_bavail = sbi->bmap->db_nfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * If we really return the number of allocated & free inodes, some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * applications will fail because they won't see enough free inodes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * We'll try to calculate some guess as to how many inodes we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * really allocate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * buf->f_files = atomic_read(&imap->im_numinos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * buf->f_ffree = atomic_read(&imap->im_numfree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) maxinodes = min((s64) atomic_read(&imap->im_numinos) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) ((sbi->bmap->db_nfree >> imap->im_l2nbperiext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) << L2INOSPEREXT), (s64) 0xffffffffLL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) buf->f_files = maxinodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) buf->f_ffree = maxinodes - (atomic_read(&imap->im_numinos) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) atomic_read(&imap->im_numfree));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) buf->f_fsid.val[0] = crc32_le(0, (char *)&sbi->uuid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) sizeof(sbi->uuid)/2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) buf->f_fsid.val[1] = crc32_le(0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) (char *)&sbi->uuid + sizeof(sbi->uuid)/2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) sizeof(sbi->uuid)/2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) buf->f_namelen = JFS_NAME_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static int jfs_quota_off(struct super_block *sb, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static int jfs_quota_on(struct super_block *sb, int type, int format_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) const struct path *path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static void jfs_quota_off_umount(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) for (type = 0; type < MAXQUOTAS; type++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) jfs_quota_off(sb, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) static const struct quotactl_ops jfs_quotactl_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) .quota_on = jfs_quota_on,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) .quota_off = jfs_quota_off,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) .quota_sync = dquot_quota_sync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) .get_state = dquot_get_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) .set_info = dquot_set_dqinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) .get_dqblk = dquot_get_dqblk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) .set_dqblk = dquot_set_dqblk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) .get_nextdqblk = dquot_get_next_dqblk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static inline void jfs_quota_off_umount(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static void jfs_put_super(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct jfs_sb_info *sbi = JFS_SBI(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) jfs_info("In jfs_put_super");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) jfs_quota_off_umount(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) rc = jfs_umount(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) jfs_err("jfs_umount failed with return code %d", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) unload_nls(sbi->nls_tab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) iput(sbi->direct_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) kfree(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) Opt_discard, Opt_nodiscard, Opt_discard_minblk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static const match_table_t tokens = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {Opt_integrity, "integrity"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) {Opt_nointegrity, "nointegrity"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {Opt_iocharset, "iocharset=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {Opt_resize, "resize=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {Opt_resize_nosize, "resize"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {Opt_errors, "errors=%s"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {Opt_ignore, "noquota"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {Opt_quota, "quota"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {Opt_usrquota, "usrquota"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {Opt_grpquota, "grpquota"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {Opt_uid, "uid=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {Opt_gid, "gid=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {Opt_umask, "umask=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {Opt_discard, "discard"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) {Opt_nodiscard, "nodiscard"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {Opt_discard_minblk, "discard=%u"},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {Opt_err, NULL}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) int *flag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) void *nls_map = (void *)-1; /* -1: no change; NULL: none */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct jfs_sb_info *sbi = JFS_SBI(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) *newLVSize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) if (!options)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) while ((p = strsep(&options, ",")) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) substring_t args[MAX_OPT_ARGS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) int token;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (!*p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) token = match_token(p, tokens, args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) switch (token) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) case Opt_integrity:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) *flag &= ~JFS_NOINTEGRITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) case Opt_nointegrity:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) *flag |= JFS_NOINTEGRITY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) case Opt_ignore:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) /* Silently ignore the quota options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /* Don't do anything ;-) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) case Opt_iocharset:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (nls_map && nls_map != (void *) -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) unload_nls(nls_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (!strcmp(args[0].from, "none"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) nls_map = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) nls_map = load_nls(args[0].from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (!nls_map) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) pr_err("JFS: charset not found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) case Opt_resize:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) char *resize = args[0].from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) int rc = kstrtoll(resize, 0, newLVSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) case Opt_resize_nosize:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) *newLVSize = i_size_read(sb->s_bdev->bd_inode) >>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) if (*newLVSize == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) pr_err("JFS: Cannot determine volume size\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) case Opt_errors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) char *errors = args[0].from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (!errors || !*errors)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (!strcmp(errors, "continue")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) *flag &= ~JFS_ERR_REMOUNT_RO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) *flag &= ~JFS_ERR_PANIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) *flag |= JFS_ERR_CONTINUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) } else if (!strcmp(errors, "remount-ro")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) *flag &= ~JFS_ERR_CONTINUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) *flag &= ~JFS_ERR_PANIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) *flag |= JFS_ERR_REMOUNT_RO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) } else if (!strcmp(errors, "panic")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) *flag &= ~JFS_ERR_CONTINUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) *flag &= ~JFS_ERR_REMOUNT_RO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) *flag |= JFS_ERR_PANIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) pr_err("JFS: %s is an invalid error handler\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) errors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) case Opt_quota:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) case Opt_usrquota:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) *flag |= JFS_USRQUOTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) case Opt_grpquota:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) *flag |= JFS_GRPQUOTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) case Opt_usrquota:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) case Opt_grpquota:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) case Opt_quota:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) pr_err("JFS: quota operations not supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) case Opt_uid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) char *uid = args[0].from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) uid_t val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) int rc = kstrtouint(uid, 0, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) sbi->uid = make_kuid(current_user_ns(), val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (!uid_valid(sbi->uid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) case Opt_gid:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) char *gid = args[0].from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) gid_t val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) int rc = kstrtouint(gid, 0, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) sbi->gid = make_kgid(current_user_ns(), val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (!gid_valid(sbi->gid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) case Opt_umask:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) char *umask = args[0].from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) int rc = kstrtouint(umask, 8, &sbi->umask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) if (sbi->umask & ~0777) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) pr_err("JFS: Invalid value of umask\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) case Opt_discard:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct request_queue *q = bdev_get_queue(sb->s_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) /* if set to 1, even copying files will cause
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * trimming :O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) * -> user has more control over the online trimming
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) sbi->minblks_trim = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (blk_queue_discard(q))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) *flag |= JFS_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) pr_err("JFS: discard option not supported on device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) case Opt_nodiscard:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) *flag &= ~JFS_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) case Opt_discard_minblk:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) struct request_queue *q = bdev_get_queue(sb->s_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) char *minblks_trim = args[0].from;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) if (blk_queue_discard(q)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) *flag |= JFS_DISCARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) rc = kstrtouint(minblks_trim, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) &sbi->minblks_trim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) pr_err("JFS: discard option not supported on device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) printk("jfs: Unrecognized mount option \"%s\" or missing value\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) goto cleanup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (nls_map != (void *) -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /* Discard old (if remount) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) unload_nls(sbi->nls_tab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) sbi->nls_tab = nls_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) cleanup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (nls_map && nls_map != (void *) -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) unload_nls(nls_map);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static int jfs_remount(struct super_block *sb, int *flags, char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) s64 newLVSize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) int flag = JFS_SBI(sb)->flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) sync_filesystem(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) if (!parse_options(data, sb, &newLVSize, &flag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) if (newLVSize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) pr_err("JFS: resize requires volume to be mounted read-write\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) return -EROFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) rc = jfs_extendfs(sb, newLVSize, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) if (sb_rdonly(sb) && !(*flags & SB_RDONLY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) * Invalidate any previously read metadata. fsck may have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) * changed the on-disk data since we mounted r/o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) truncate_inode_pages(JFS_SBI(sb)->direct_inode->i_mapping, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) JFS_SBI(sb)->flag = flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) ret = jfs_mount_rw(sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) /* mark the fs r/w for quota activity */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) sb->s_flags &= ~SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) dquot_resume(sb, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) if (!sb_rdonly(sb) && (*flags & SB_RDONLY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) rc = dquot_suspend(sb, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) rc = jfs_umount_rw(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) JFS_SBI(sb)->flag = flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if ((JFS_SBI(sb)->flag & JFS_NOINTEGRITY) != (flag & JFS_NOINTEGRITY))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) rc = jfs_umount_rw(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) JFS_SBI(sb)->flag = flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) ret = jfs_mount_rw(sb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) JFS_SBI(sb)->flag = flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) static int jfs_fill_super(struct super_block *sb, void *data, int silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) struct jfs_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) s64 newLVSize = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) int flag, ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) sbi = kzalloc(sizeof(struct jfs_sb_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) if (!sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) sb->s_fs_info = sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) sb->s_max_links = JFS_LINK_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) sb->s_time_min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) sb->s_time_max = U32_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) sbi->sb = sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) sbi->uid = INVALID_UID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) sbi->gid = INVALID_GID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) sbi->umask = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) /* initialize the mount flag and determine the default error handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) flag = JFS_ERR_REMOUNT_RO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) if (!parse_options((char *) data, sb, &newLVSize, &flag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) goto out_kfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) sbi->flag = flag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) #ifdef CONFIG_JFS_POSIX_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) sb->s_flags |= SB_POSIXACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) if (newLVSize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) pr_err("resize option for remount only\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) goto out_kfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) * Initialize blocksize to 4K.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) sb_set_blocksize(sb, PSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) * Set method vectors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) sb->s_op = &jfs_super_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) sb->s_export_op = &jfs_export_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) sb->s_xattr = jfs_xattr_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) sb->dq_op = &dquot_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) sb->s_qcop = &jfs_quotactl_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) * Initialize direct-mapping inode/address-space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) inode = new_inode(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (inode == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) goto out_unload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) inode->i_ino = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) inode->i_size = i_size_read(sb->s_bdev->bd_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) inode->i_mapping->a_ops = &jfs_metapage_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) inode_fake_hash(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) sbi->direct_inode = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) rc = jfs_mount(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) jfs_err("jfs_mount failed w/return code = %d", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) goto out_mount_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) if (sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) sbi->log = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) rc = jfs_mount_rw(sb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) if (!silent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) jfs_err("jfs_mount_rw failed, return code = %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) goto out_no_rw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) sb->s_magic = JFS_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) if (sbi->mntflag & JFS_OS2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) sb->s_d_op = &jfs_ci_dentry_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) inode = jfs_iget(sb, ROOT_I);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) if (IS_ERR(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) ret = PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) goto out_no_rw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) sb->s_root = d_make_root(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if (!sb->s_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) goto out_no_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) /* logical blocks are represented by 40 bits in pxd_t, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) * and page cache is indexed by long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) sb->s_maxbytes = min(((loff_t)sb->s_blocksize) << 40, MAX_LFS_FILESIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) sb->s_time_gran = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) out_no_root:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) jfs_err("jfs_read_super: get root dentry failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) out_no_rw:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) rc = jfs_umount(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) jfs_err("jfs_umount failed with return code %d", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) out_mount_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) filemap_write_and_wait(sbi->direct_inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) make_bad_inode(sbi->direct_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) iput(sbi->direct_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) sbi->direct_inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) out_unload:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) unload_nls(sbi->nls_tab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) out_kfree:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) kfree(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) static int jfs_freeze(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) struct jfs_sb_info *sbi = JFS_SBI(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) struct jfs_log *log = sbi->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) txQuiesce(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) rc = lmLogShutdown(log);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) jfs_error(sb, "lmLogShutdown failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) /* let operations fail rather than hang */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) txResume(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) rc = updateSuper(sb, FM_CLEAN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) jfs_err("jfs_freeze: updateSuper failed");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) * Don't fail here. Everything succeeded except
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) * marking the superblock clean, so there's really
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) * no harm in leaving it frozen for now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) static int jfs_unfreeze(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) struct jfs_sb_info *sbi = JFS_SBI(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) struct jfs_log *log = sbi->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) rc = updateSuper(sb, FM_MOUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) jfs_error(sb, "updateSuper failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) rc = lmLogInit(log);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) jfs_error(sb, "lmLogInit failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) txResume(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) static struct dentry *jfs_do_mount(struct file_system_type *fs_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) int flags, const char *dev_name, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) return mount_bdev(fs_type, flags, dev_name, data, jfs_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) static int jfs_sync_fs(struct super_block *sb, int wait)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) struct jfs_log *log = JFS_SBI(sb)->log;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) /* log == NULL indicates read-only mount */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) if (log) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) * Write quota structures to quota file, sync_blockdev() will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) * write them to disk later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) dquot_writeback_dquots(sb, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) jfs_flush_journal(log, wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) jfs_syncpt(log, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) return 0;
^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) static int jfs_show_options(struct seq_file *seq, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) struct jfs_sb_info *sbi = JFS_SBI(root->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) if (uid_valid(sbi->uid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) seq_printf(seq, ",uid=%d", from_kuid(&init_user_ns, sbi->uid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) if (gid_valid(sbi->gid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) seq_printf(seq, ",gid=%d", from_kgid(&init_user_ns, sbi->gid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) if (sbi->umask != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) seq_printf(seq, ",umask=%03o", sbi->umask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) if (sbi->flag & JFS_NOINTEGRITY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) seq_puts(seq, ",nointegrity");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) if (sbi->flag & JFS_DISCARD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) seq_printf(seq, ",discard=%u", sbi->minblks_trim);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) if (sbi->nls_tab)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) seq_printf(seq, ",iocharset=%s", sbi->nls_tab->charset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) if (sbi->flag & JFS_ERR_CONTINUE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) seq_printf(seq, ",errors=continue");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) if (sbi->flag & JFS_ERR_PANIC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) seq_printf(seq, ",errors=panic");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) if (sbi->flag & JFS_USRQUOTA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) seq_puts(seq, ",usrquota");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) if (sbi->flag & JFS_GRPQUOTA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) seq_puts(seq, ",grpquota");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) /* Read data from quotafile - avoid pagecache and such because we cannot afford
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) * acquiring the locks... As quota files are never truncated and quota code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) * itself serializes the operations (and no one else should touch the files)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) * we don't have to be afraid of races */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) static ssize_t jfs_quota_read(struct super_block *sb, int type, char *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) size_t len, loff_t off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) struct inode *inode = sb_dqopt(sb)->files[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) sector_t blk = off >> sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) int offset = off & (sb->s_blocksize - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) int tocopy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) size_t toread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) struct buffer_head tmp_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) loff_t i_size = i_size_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) if (off > i_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) if (off+len > i_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) len = i_size-off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) toread = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) while (toread > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) tocopy = sb->s_blocksize - offset < toread ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) sb->s_blocksize - offset : toread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) tmp_bh.b_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) tmp_bh.b_size = i_blocksize(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) err = jfs_get_block(inode, blk, &tmp_bh, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) if (!buffer_mapped(&tmp_bh)) /* A hole? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) memset(data, 0, tocopy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) bh = sb_bread(sb, tmp_bh.b_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) memcpy(data, bh->b_data+offset, tocopy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) toread -= tocopy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) data += tocopy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) blk++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) /* Write to quotafile */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) static ssize_t jfs_quota_write(struct super_block *sb, int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) const char *data, size_t len, loff_t off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) struct inode *inode = sb_dqopt(sb)->files[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) sector_t blk = off >> sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) int offset = off & (sb->s_blocksize - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) int tocopy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) size_t towrite = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) struct buffer_head tmp_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) while (towrite > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) tocopy = sb->s_blocksize - offset < towrite ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) sb->s_blocksize - offset : towrite;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) tmp_bh.b_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) tmp_bh.b_size = i_blocksize(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) err = jfs_get_block(inode, blk, &tmp_bh, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) if (offset || tocopy != sb->s_blocksize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) bh = sb_bread(sb, tmp_bh.b_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) bh = sb_getblk(sb, tmp_bh.b_blocknr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) if (!bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) lock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) memcpy(bh->b_data+offset, data, tocopy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) flush_dcache_page(bh->b_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) set_buffer_uptodate(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) mark_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) unlock_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) towrite -= tocopy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) data += tocopy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) blk++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) if (len == towrite) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) if (inode->i_size < off+len-towrite)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) i_size_write(inode, off+len-towrite);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) inode->i_mtime = inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) return len - towrite;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) static struct dquot **jfs_get_dquots(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) return JFS_IP(inode)->i_dquot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) static int jfs_quota_on(struct super_block *sb, int type, int format_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) const struct path *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) err = dquot_quota_on(sb, type, format_id, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) inode = d_inode(path->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) JFS_IP(inode)->mode2 |= JFS_NOATIME_FL | JFS_IMMUTABLE_FL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) inode_set_flags(inode, S_NOATIME | S_IMMUTABLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) S_NOATIME | S_IMMUTABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) static int jfs_quota_off(struct super_block *sb, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) struct inode *inode = sb_dqopt(sb)->files[type];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) if (!inode || !igrab(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) err = dquot_quota_off(sb, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) goto out_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) JFS_IP(inode)->mode2 &= ~(JFS_NOATIME_FL | JFS_IMMUTABLE_FL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) inode_set_flags(inode, 0, S_NOATIME | S_IMMUTABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) out_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) return dquot_quota_off(sb, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) static const struct super_operations jfs_super_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) .alloc_inode = jfs_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) .free_inode = jfs_free_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) .dirty_inode = jfs_dirty_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) .write_inode = jfs_write_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) .evict_inode = jfs_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) .put_super = jfs_put_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) .sync_fs = jfs_sync_fs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) .freeze_fs = jfs_freeze,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) .unfreeze_fs = jfs_unfreeze,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) .statfs = jfs_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) .remount_fs = jfs_remount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) .show_options = jfs_show_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) #ifdef CONFIG_QUOTA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) .quota_read = jfs_quota_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) .quota_write = jfs_quota_write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) .get_dquots = jfs_get_dquots,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) static const struct export_operations jfs_export_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) .fh_to_dentry = jfs_fh_to_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) .fh_to_parent = jfs_fh_to_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) .get_parent = jfs_get_parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) static struct file_system_type jfs_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) .name = "jfs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) .mount = jfs_do_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) .kill_sb = kill_block_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) .fs_flags = FS_REQUIRES_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) MODULE_ALIAS_FS("jfs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) static void init_once(void *foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) struct jfs_inode_info *jfs_ip = (struct jfs_inode_info *) foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) memset(jfs_ip, 0, sizeof(struct jfs_inode_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) INIT_LIST_HEAD(&jfs_ip->anon_inode_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) init_rwsem(&jfs_ip->rdwrlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) mutex_init(&jfs_ip->commit_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) init_rwsem(&jfs_ip->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) spin_lock_init(&jfs_ip->ag_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) jfs_ip->active_ag = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) inode_init_once(&jfs_ip->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) static int __init init_jfs_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) jfs_inode_cachep =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) kmem_cache_create_usercopy("jfs_ip", sizeof(struct jfs_inode_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) 0, SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_ACCOUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) offsetof(struct jfs_inode_info, i_inline), IDATASIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) if (jfs_inode_cachep == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) * Metapage initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) rc = metapage_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) jfs_err("metapage_init failed w/rc = %d", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) goto free_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) * Transaction Manager initialization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) rc = txInit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) jfs_err("txInit failed w/rc = %d", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) goto free_metapage;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) * I/O completion thread (endio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) jfsIOthread = kthread_run(jfsIOWait, NULL, "jfsIO");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) if (IS_ERR(jfsIOthread)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) rc = PTR_ERR(jfsIOthread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) goto end_txmngr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) if (commit_threads < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) commit_threads = num_online_cpus();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) if (commit_threads > MAX_COMMIT_THREADS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) commit_threads = MAX_COMMIT_THREADS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) for (i = 0; i < commit_threads; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) jfsCommitThread[i] = kthread_run(jfs_lazycommit, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) "jfsCommit");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) if (IS_ERR(jfsCommitThread[i])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) rc = PTR_ERR(jfsCommitThread[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) commit_threads = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) goto kill_committask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) }
^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) jfsSyncThread = kthread_run(jfs_sync, NULL, "jfsSync");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) if (IS_ERR(jfsSyncThread)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) rc = PTR_ERR(jfsSyncThread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) goto kill_committask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) #ifdef PROC_FS_JFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) jfs_proc_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) rc = register_filesystem(&jfs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) #ifdef PROC_FS_JFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) jfs_proc_clean();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) kthread_stop(jfsSyncThread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) kill_committask:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) for (i = 0; i < commit_threads; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) kthread_stop(jfsCommitThread[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) kthread_stop(jfsIOthread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) end_txmngr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) txExit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) free_metapage:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) metapage_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) free_slab:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) kmem_cache_destroy(jfs_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) return rc;
^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) static void __exit exit_jfs_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) jfs_info("exit_jfs_fs called");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) txExit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) metapage_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) kthread_stop(jfsIOthread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) for (i = 0; i < commit_threads; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) kthread_stop(jfsCommitThread[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) kthread_stop(jfsSyncThread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) #ifdef PROC_FS_JFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) jfs_proc_clean();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) unregister_filesystem(&jfs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) * Make sure all delayed rcu free inodes are flushed before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) * destroy cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) kmem_cache_destroy(jfs_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) module_init(init_jfs_fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) module_exit(exit_jfs_fs)