Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *   Copyright (C) International Business Machines Corp., 2000-2004
0004  *   Portions Copyright (C) Christoph Hellwig, 2001-2002
0005  */
0006 
0007 #include <linux/fs.h>
0008 #include <linux/module.h>
0009 #include <linux/parser.h>
0010 #include <linux/completion.h>
0011 #include <linux/vfs.h>
0012 #include <linux/quotaops.h>
0013 #include <linux/mount.h>
0014 #include <linux/moduleparam.h>
0015 #include <linux/kthread.h>
0016 #include <linux/posix_acl.h>
0017 #include <linux/buffer_head.h>
0018 #include <linux/exportfs.h>
0019 #include <linux/crc32.h>
0020 #include <linux/slab.h>
0021 #include <linux/uaccess.h>
0022 #include <linux/seq_file.h>
0023 #include <linux/blkdev.h>
0024 
0025 #include "jfs_incore.h"
0026 #include "jfs_filsys.h"
0027 #include "jfs_inode.h"
0028 #include "jfs_metapage.h"
0029 #include "jfs_superblock.h"
0030 #include "jfs_dmap.h"
0031 #include "jfs_imap.h"
0032 #include "jfs_acl.h"
0033 #include "jfs_debug.h"
0034 #include "jfs_xattr.h"
0035 #include "jfs_dinode.h"
0036 
0037 MODULE_DESCRIPTION("The Journaled Filesystem (JFS)");
0038 MODULE_AUTHOR("Steve Best/Dave Kleikamp/Barry Arndt, IBM");
0039 MODULE_LICENSE("GPL");
0040 
0041 static struct kmem_cache *jfs_inode_cachep;
0042 
0043 static const struct super_operations jfs_super_operations;
0044 static const struct export_operations jfs_export_operations;
0045 static struct file_system_type jfs_fs_type;
0046 
0047 #define MAX_COMMIT_THREADS 64
0048 static int commit_threads;
0049 module_param(commit_threads, int, 0);
0050 MODULE_PARM_DESC(commit_threads, "Number of commit threads");
0051 
0052 static struct task_struct *jfsCommitThread[MAX_COMMIT_THREADS];
0053 struct task_struct *jfsIOthread;
0054 struct task_struct *jfsSyncThread;
0055 
0056 #ifdef CONFIG_JFS_DEBUG
0057 int jfsloglevel = JFS_LOGLEVEL_WARN;
0058 module_param(jfsloglevel, int, 0644);
0059 MODULE_PARM_DESC(jfsloglevel, "Specify JFS loglevel (0, 1 or 2)");
0060 #endif
0061 
0062 static void jfs_handle_error(struct super_block *sb)
0063 {
0064     struct jfs_sb_info *sbi = JFS_SBI(sb);
0065 
0066     if (sb_rdonly(sb))
0067         return;
0068 
0069     updateSuper(sb, FM_DIRTY);
0070 
0071     if (sbi->flag & JFS_ERR_PANIC)
0072         panic("JFS (device %s): panic forced after error\n",
0073             sb->s_id);
0074     else if (sbi->flag & JFS_ERR_REMOUNT_RO) {
0075         jfs_err("ERROR: (device %s): remounting filesystem as read-only",
0076             sb->s_id);
0077         sb->s_flags |= SB_RDONLY;
0078     }
0079 
0080     /* nothing is done for continue beyond marking the superblock dirty */
0081 }
0082 
0083 void jfs_error(struct super_block *sb, const char *fmt, ...)
0084 {
0085     struct va_format vaf;
0086     va_list args;
0087 
0088     va_start(args, fmt);
0089 
0090     vaf.fmt = fmt;
0091     vaf.va = &args;
0092 
0093     pr_err("ERROR: (device %s): %ps: %pV\n",
0094            sb->s_id, __builtin_return_address(0), &vaf);
0095 
0096     va_end(args);
0097 
0098     jfs_handle_error(sb);
0099 }
0100 
0101 static struct inode *jfs_alloc_inode(struct super_block *sb)
0102 {
0103     struct jfs_inode_info *jfs_inode;
0104 
0105     jfs_inode = alloc_inode_sb(sb, jfs_inode_cachep, GFP_NOFS);
0106     if (!jfs_inode)
0107         return NULL;
0108 #ifdef CONFIG_QUOTA
0109     memset(&jfs_inode->i_dquot, 0, sizeof(jfs_inode->i_dquot));
0110 #endif
0111     return &jfs_inode->vfs_inode;
0112 }
0113 
0114 static void jfs_free_inode(struct inode *inode)
0115 {
0116     kmem_cache_free(jfs_inode_cachep, JFS_IP(inode));
0117 }
0118 
0119 static int jfs_statfs(struct dentry *dentry, struct kstatfs *buf)
0120 {
0121     struct jfs_sb_info *sbi = JFS_SBI(dentry->d_sb);
0122     s64 maxinodes;
0123     struct inomap *imap = JFS_IP(sbi->ipimap)->i_imap;
0124 
0125     jfs_info("In jfs_statfs");
0126     buf->f_type = JFS_SUPER_MAGIC;
0127     buf->f_bsize = sbi->bsize;
0128     buf->f_blocks = sbi->bmap->db_mapsize;
0129     buf->f_bfree = sbi->bmap->db_nfree;
0130     buf->f_bavail = sbi->bmap->db_nfree;
0131     /*
0132      * If we really return the number of allocated & free inodes, some
0133      * applications will fail because they won't see enough free inodes.
0134      * We'll try to calculate some guess as to how many inodes we can
0135      * really allocate
0136      *
0137      * buf->f_files = atomic_read(&imap->im_numinos);
0138      * buf->f_ffree = atomic_read(&imap->im_numfree);
0139      */
0140     maxinodes = min((s64) atomic_read(&imap->im_numinos) +
0141             ((sbi->bmap->db_nfree >> imap->im_l2nbperiext)
0142              << L2INOSPEREXT), (s64) 0xffffffffLL);
0143     buf->f_files = maxinodes;
0144     buf->f_ffree = maxinodes - (atomic_read(&imap->im_numinos) -
0145                     atomic_read(&imap->im_numfree));
0146     buf->f_fsid.val[0] = crc32_le(0, (char *)&sbi->uuid,
0147                       sizeof(sbi->uuid)/2);
0148     buf->f_fsid.val[1] = crc32_le(0,
0149                       (char *)&sbi->uuid + sizeof(sbi->uuid)/2,
0150                       sizeof(sbi->uuid)/2);
0151 
0152     buf->f_namelen = JFS_NAME_MAX;
0153     return 0;
0154 }
0155 
0156 #ifdef CONFIG_QUOTA
0157 static int jfs_quota_off(struct super_block *sb, int type);
0158 static int jfs_quota_on(struct super_block *sb, int type, int format_id,
0159             const struct path *path);
0160 
0161 static void jfs_quota_off_umount(struct super_block *sb)
0162 {
0163     int type;
0164 
0165     for (type = 0; type < MAXQUOTAS; type++)
0166         jfs_quota_off(sb, type);
0167 }
0168 
0169 static const struct quotactl_ops jfs_quotactl_ops = {
0170     .quota_on   = jfs_quota_on,
0171     .quota_off  = jfs_quota_off,
0172     .quota_sync = dquot_quota_sync,
0173     .get_state  = dquot_get_state,
0174     .set_info   = dquot_set_dqinfo,
0175     .get_dqblk  = dquot_get_dqblk,
0176     .set_dqblk  = dquot_set_dqblk,
0177     .get_nextdqblk  = dquot_get_next_dqblk,
0178 };
0179 #else
0180 static inline void jfs_quota_off_umount(struct super_block *sb)
0181 {
0182 }
0183 #endif
0184 
0185 static void jfs_put_super(struct super_block *sb)
0186 {
0187     struct jfs_sb_info *sbi = JFS_SBI(sb);
0188     int rc;
0189 
0190     jfs_info("In jfs_put_super");
0191 
0192     jfs_quota_off_umount(sb);
0193 
0194     rc = jfs_umount(sb);
0195     if (rc)
0196         jfs_err("jfs_umount failed with return code %d", rc);
0197 
0198     unload_nls(sbi->nls_tab);
0199 
0200     truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
0201     iput(sbi->direct_inode);
0202 
0203     kfree(sbi);
0204 }
0205 
0206 enum {
0207     Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize,
0208     Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota,
0209     Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask,
0210     Opt_discard, Opt_nodiscard, Opt_discard_minblk
0211 };
0212 
0213 static const match_table_t tokens = {
0214     {Opt_integrity, "integrity"},
0215     {Opt_nointegrity, "nointegrity"},
0216     {Opt_iocharset, "iocharset=%s"},
0217     {Opt_resize, "resize=%u"},
0218     {Opt_resize_nosize, "resize"},
0219     {Opt_errors, "errors=%s"},
0220     {Opt_ignore, "noquota"},
0221     {Opt_quota, "quota"},
0222     {Opt_usrquota, "usrquota"},
0223     {Opt_grpquota, "grpquota"},
0224     {Opt_uid, "uid=%u"},
0225     {Opt_gid, "gid=%u"},
0226     {Opt_umask, "umask=%u"},
0227     {Opt_discard, "discard"},
0228     {Opt_nodiscard, "nodiscard"},
0229     {Opt_discard_minblk, "discard=%u"},
0230     {Opt_err, NULL}
0231 };
0232 
0233 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
0234              int *flag)
0235 {
0236     void *nls_map = (void *)-1; /* -1: no change;  NULL: none */
0237     char *p;
0238     struct jfs_sb_info *sbi = JFS_SBI(sb);
0239 
0240     *newLVSize = 0;
0241 
0242     if (!options)
0243         return 1;
0244 
0245     while ((p = strsep(&options, ",")) != NULL) {
0246         substring_t args[MAX_OPT_ARGS];
0247         int token;
0248         if (!*p)
0249             continue;
0250 
0251         token = match_token(p, tokens, args);
0252         switch (token) {
0253         case Opt_integrity:
0254             *flag &= ~JFS_NOINTEGRITY;
0255             break;
0256         case Opt_nointegrity:
0257             *flag |= JFS_NOINTEGRITY;
0258             break;
0259         case Opt_ignore:
0260             /* Silently ignore the quota options */
0261             /* Don't do anything ;-) */
0262             break;
0263         case Opt_iocharset:
0264             if (nls_map && nls_map != (void *) -1)
0265                 unload_nls(nls_map);
0266             if (!strcmp(args[0].from, "none"))
0267                 nls_map = NULL;
0268             else {
0269                 nls_map = load_nls(args[0].from);
0270                 if (!nls_map) {
0271                     pr_err("JFS: charset not found\n");
0272                     goto cleanup;
0273                 }
0274             }
0275             break;
0276         case Opt_resize:
0277         {
0278             char *resize = args[0].from;
0279             int rc = kstrtoll(resize, 0, newLVSize);
0280 
0281             if (rc)
0282                 goto cleanup;
0283             break;
0284         }
0285         case Opt_resize_nosize:
0286         {
0287             *newLVSize = sb_bdev_nr_blocks(sb);
0288             if (*newLVSize == 0)
0289                 pr_err("JFS: Cannot determine volume size\n");
0290             break;
0291         }
0292         case Opt_errors:
0293         {
0294             char *errors = args[0].from;
0295             if (!errors || !*errors)
0296                 goto cleanup;
0297             if (!strcmp(errors, "continue")) {
0298                 *flag &= ~JFS_ERR_REMOUNT_RO;
0299                 *flag &= ~JFS_ERR_PANIC;
0300                 *flag |= JFS_ERR_CONTINUE;
0301             } else if (!strcmp(errors, "remount-ro")) {
0302                 *flag &= ~JFS_ERR_CONTINUE;
0303                 *flag &= ~JFS_ERR_PANIC;
0304                 *flag |= JFS_ERR_REMOUNT_RO;
0305             } else if (!strcmp(errors, "panic")) {
0306                 *flag &= ~JFS_ERR_CONTINUE;
0307                 *flag &= ~JFS_ERR_REMOUNT_RO;
0308                 *flag |= JFS_ERR_PANIC;
0309             } else {
0310                 pr_err("JFS: %s is an invalid error handler\n",
0311                        errors);
0312                 goto cleanup;
0313             }
0314             break;
0315         }
0316 
0317 #ifdef CONFIG_QUOTA
0318         case Opt_quota:
0319         case Opt_usrquota:
0320             *flag |= JFS_USRQUOTA;
0321             break;
0322         case Opt_grpquota:
0323             *flag |= JFS_GRPQUOTA;
0324             break;
0325 #else
0326         case Opt_usrquota:
0327         case Opt_grpquota:
0328         case Opt_quota:
0329             pr_err("JFS: quota operations not supported\n");
0330             break;
0331 #endif
0332         case Opt_uid:
0333         {
0334             char *uid = args[0].from;
0335             uid_t val;
0336             int rc = kstrtouint(uid, 0, &val);
0337 
0338             if (rc)
0339                 goto cleanup;
0340             sbi->uid = make_kuid(current_user_ns(), val);
0341             if (!uid_valid(sbi->uid))
0342                 goto cleanup;
0343             break;
0344         }
0345 
0346         case Opt_gid:
0347         {
0348             char *gid = args[0].from;
0349             gid_t val;
0350             int rc = kstrtouint(gid, 0, &val);
0351 
0352             if (rc)
0353                 goto cleanup;
0354             sbi->gid = make_kgid(current_user_ns(), val);
0355             if (!gid_valid(sbi->gid))
0356                 goto cleanup;
0357             break;
0358         }
0359 
0360         case Opt_umask:
0361         {
0362             char *umask = args[0].from;
0363             int rc = kstrtouint(umask, 8, &sbi->umask);
0364 
0365             if (rc)
0366                 goto cleanup;
0367             if (sbi->umask & ~0777) {
0368                 pr_err("JFS: Invalid value of umask\n");
0369                 goto cleanup;
0370             }
0371             break;
0372         }
0373 
0374         case Opt_discard:
0375             /* if set to 1, even copying files will cause
0376              * trimming :O
0377              * -> user has more control over the online trimming
0378              */
0379             sbi->minblks_trim = 64;
0380             if (bdev_max_discard_sectors(sb->s_bdev))
0381                 *flag |= JFS_DISCARD;
0382             else
0383                 pr_err("JFS: discard option not supported on device\n");
0384             break;
0385 
0386         case Opt_nodiscard:
0387             *flag &= ~JFS_DISCARD;
0388             break;
0389 
0390         case Opt_discard_minblk:
0391         {
0392             char *minblks_trim = args[0].from;
0393             int rc;
0394             if (bdev_max_discard_sectors(sb->s_bdev)) {
0395                 *flag |= JFS_DISCARD;
0396                 rc = kstrtouint(minblks_trim, 0,
0397                         &sbi->minblks_trim);
0398                 if (rc)
0399                     goto cleanup;
0400             } else
0401                 pr_err("JFS: discard option not supported on device\n");
0402             break;
0403         }
0404 
0405         default:
0406             printk("jfs: Unrecognized mount option \"%s\" or missing value\n",
0407                    p);
0408             goto cleanup;
0409         }
0410     }
0411 
0412     if (nls_map != (void *) -1) {
0413         /* Discard old (if remount) */
0414         unload_nls(sbi->nls_tab);
0415         sbi->nls_tab = nls_map;
0416     }
0417     return 1;
0418 
0419 cleanup:
0420     if (nls_map && nls_map != (void *) -1)
0421         unload_nls(nls_map);
0422     return 0;
0423 }
0424 
0425 static int jfs_remount(struct super_block *sb, int *flags, char *data)
0426 {
0427     s64 newLVSize = 0;
0428     int rc = 0;
0429     int flag = JFS_SBI(sb)->flag;
0430     int ret;
0431 
0432     sync_filesystem(sb);
0433     if (!parse_options(data, sb, &newLVSize, &flag))
0434         return -EINVAL;
0435 
0436     if (newLVSize) {
0437         if (sb_rdonly(sb)) {
0438             pr_err("JFS: resize requires volume to be mounted read-write\n");
0439             return -EROFS;
0440         }
0441         rc = jfs_extendfs(sb, newLVSize, 0);
0442         if (rc)
0443             return rc;
0444     }
0445 
0446     if (sb_rdonly(sb) && !(*flags & SB_RDONLY)) {
0447         /*
0448          * Invalidate any previously read metadata.  fsck may have
0449          * changed the on-disk data since we mounted r/o
0450          */
0451         truncate_inode_pages(JFS_SBI(sb)->direct_inode->i_mapping, 0);
0452 
0453         JFS_SBI(sb)->flag = flag;
0454         ret = jfs_mount_rw(sb, 1);
0455 
0456         /* mark the fs r/w for quota activity */
0457         sb->s_flags &= ~SB_RDONLY;
0458 
0459         dquot_resume(sb, -1);
0460         return ret;
0461     }
0462     if (!sb_rdonly(sb) && (*flags & SB_RDONLY)) {
0463         rc = dquot_suspend(sb, -1);
0464         if (rc < 0)
0465             return rc;
0466         rc = jfs_umount_rw(sb);
0467         JFS_SBI(sb)->flag = flag;
0468         return rc;
0469     }
0470     if ((JFS_SBI(sb)->flag & JFS_NOINTEGRITY) != (flag & JFS_NOINTEGRITY))
0471         if (!sb_rdonly(sb)) {
0472             rc = jfs_umount_rw(sb);
0473             if (rc)
0474                 return rc;
0475 
0476             JFS_SBI(sb)->flag = flag;
0477             ret = jfs_mount_rw(sb, 1);
0478             return ret;
0479         }
0480     JFS_SBI(sb)->flag = flag;
0481 
0482     return 0;
0483 }
0484 
0485 static int jfs_fill_super(struct super_block *sb, void *data, int silent)
0486 {
0487     struct jfs_sb_info *sbi;
0488     struct inode *inode;
0489     int rc;
0490     s64 newLVSize = 0;
0491     int flag, ret = -EINVAL;
0492 
0493     jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags);
0494 
0495     sbi = kzalloc(sizeof(struct jfs_sb_info), GFP_KERNEL);
0496     if (!sbi)
0497         return -ENOMEM;
0498 
0499     sb->s_fs_info = sbi;
0500     sb->s_max_links = JFS_LINK_MAX;
0501     sb->s_time_min = 0;
0502     sb->s_time_max = U32_MAX;
0503     sbi->sb = sb;
0504     sbi->uid = INVALID_UID;
0505     sbi->gid = INVALID_GID;
0506     sbi->umask = -1;
0507 
0508     /* initialize the mount flag and determine the default error handler */
0509     flag = JFS_ERR_REMOUNT_RO;
0510 
0511     if (!parse_options((char *) data, sb, &newLVSize, &flag))
0512         goto out_kfree;
0513     sbi->flag = flag;
0514 
0515 #ifdef CONFIG_JFS_POSIX_ACL
0516     sb->s_flags |= SB_POSIXACL;
0517 #endif
0518 
0519     if (newLVSize) {
0520         pr_err("resize option for remount only\n");
0521         goto out_kfree;
0522     }
0523 
0524     /*
0525      * Initialize blocksize to 4K.
0526      */
0527     sb_set_blocksize(sb, PSIZE);
0528 
0529     /*
0530      * Set method vectors.
0531      */
0532     sb->s_op = &jfs_super_operations;
0533     sb->s_export_op = &jfs_export_operations;
0534     sb->s_xattr = jfs_xattr_handlers;
0535 #ifdef CONFIG_QUOTA
0536     sb->dq_op = &dquot_operations;
0537     sb->s_qcop = &jfs_quotactl_ops;
0538     sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
0539 #endif
0540 
0541     /*
0542      * Initialize direct-mapping inode/address-space
0543      */
0544     inode = new_inode(sb);
0545     if (inode == NULL) {
0546         ret = -ENOMEM;
0547         goto out_unload;
0548     }
0549     inode->i_size = bdev_nr_bytes(sb->s_bdev);
0550     inode->i_mapping->a_ops = &jfs_metapage_aops;
0551     inode_fake_hash(inode);
0552     mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
0553 
0554     sbi->direct_inode = inode;
0555 
0556     rc = jfs_mount(sb);
0557     if (rc) {
0558         if (!silent)
0559             jfs_err("jfs_mount failed w/return code = %d", rc);
0560         goto out_mount_failed;
0561     }
0562     if (sb_rdonly(sb))
0563         sbi->log = NULL;
0564     else {
0565         rc = jfs_mount_rw(sb, 0);
0566         if (rc) {
0567             if (!silent) {
0568                 jfs_err("jfs_mount_rw failed, return code = %d",
0569                     rc);
0570             }
0571             goto out_no_rw;
0572         }
0573     }
0574 
0575     sb->s_magic = JFS_SUPER_MAGIC;
0576 
0577     if (sbi->mntflag & JFS_OS2)
0578         sb->s_d_op = &jfs_ci_dentry_operations;
0579 
0580     inode = jfs_iget(sb, ROOT_I);
0581     if (IS_ERR(inode)) {
0582         ret = PTR_ERR(inode);
0583         goto out_no_rw;
0584     }
0585     sb->s_root = d_make_root(inode);
0586     if (!sb->s_root)
0587         goto out_no_root;
0588 
0589     /* logical blocks are represented by 40 bits in pxd_t, etc.
0590      * and page cache is indexed by long
0591      */
0592     sb->s_maxbytes = min(((loff_t)sb->s_blocksize) << 40, MAX_LFS_FILESIZE);
0593     sb->s_time_gran = 1;
0594     return 0;
0595 
0596 out_no_root:
0597     jfs_err("jfs_read_super: get root dentry failed");
0598 
0599 out_no_rw:
0600     rc = jfs_umount(sb);
0601     if (rc)
0602         jfs_err("jfs_umount failed with return code %d", rc);
0603 out_mount_failed:
0604     filemap_write_and_wait(sbi->direct_inode->i_mapping);
0605     truncate_inode_pages(sbi->direct_inode->i_mapping, 0);
0606     make_bad_inode(sbi->direct_inode);
0607     iput(sbi->direct_inode);
0608     sbi->direct_inode = NULL;
0609 out_unload:
0610     unload_nls(sbi->nls_tab);
0611 out_kfree:
0612     kfree(sbi);
0613     return ret;
0614 }
0615 
0616 static int jfs_freeze(struct super_block *sb)
0617 {
0618     struct jfs_sb_info *sbi = JFS_SBI(sb);
0619     struct jfs_log *log = sbi->log;
0620     int rc = 0;
0621 
0622     if (!sb_rdonly(sb)) {
0623         txQuiesce(sb);
0624         rc = lmLogShutdown(log);
0625         if (rc) {
0626             jfs_error(sb, "lmLogShutdown failed\n");
0627 
0628             /* let operations fail rather than hang */
0629             txResume(sb);
0630 
0631             return rc;
0632         }
0633         rc = updateSuper(sb, FM_CLEAN);
0634         if (rc) {
0635             jfs_err("jfs_freeze: updateSuper failed");
0636             /*
0637              * Don't fail here. Everything succeeded except
0638              * marking the superblock clean, so there's really
0639              * no harm in leaving it frozen for now.
0640              */
0641         }
0642     }
0643     return 0;
0644 }
0645 
0646 static int jfs_unfreeze(struct super_block *sb)
0647 {
0648     struct jfs_sb_info *sbi = JFS_SBI(sb);
0649     struct jfs_log *log = sbi->log;
0650     int rc = 0;
0651 
0652     if (!sb_rdonly(sb)) {
0653         rc = updateSuper(sb, FM_MOUNT);
0654         if (rc) {
0655             jfs_error(sb, "updateSuper failed\n");
0656             goto out;
0657         }
0658         rc = lmLogInit(log);
0659         if (rc)
0660             jfs_error(sb, "lmLogInit failed\n");
0661 out:
0662         txResume(sb);
0663     }
0664     return rc;
0665 }
0666 
0667 static struct dentry *jfs_do_mount(struct file_system_type *fs_type,
0668     int flags, const char *dev_name, void *data)
0669 {
0670     return mount_bdev(fs_type, flags, dev_name, data, jfs_fill_super);
0671 }
0672 
0673 static int jfs_sync_fs(struct super_block *sb, int wait)
0674 {
0675     struct jfs_log *log = JFS_SBI(sb)->log;
0676 
0677     /* log == NULL indicates read-only mount */
0678     if (log) {
0679         /*
0680          * Write quota structures to quota file, sync_blockdev() will
0681          * write them to disk later
0682          */
0683         dquot_writeback_dquots(sb, -1);
0684         jfs_flush_journal(log, wait);
0685         jfs_syncpt(log, 0);
0686     }
0687 
0688     return 0;
0689 }
0690 
0691 static int jfs_show_options(struct seq_file *seq, struct dentry *root)
0692 {
0693     struct jfs_sb_info *sbi = JFS_SBI(root->d_sb);
0694 
0695     if (uid_valid(sbi->uid))
0696         seq_printf(seq, ",uid=%d", from_kuid(&init_user_ns, sbi->uid));
0697     if (gid_valid(sbi->gid))
0698         seq_printf(seq, ",gid=%d", from_kgid(&init_user_ns, sbi->gid));
0699     if (sbi->umask != -1)
0700         seq_printf(seq, ",umask=%03o", sbi->umask);
0701     if (sbi->flag & JFS_NOINTEGRITY)
0702         seq_puts(seq, ",nointegrity");
0703     if (sbi->flag & JFS_DISCARD)
0704         seq_printf(seq, ",discard=%u", sbi->minblks_trim);
0705     if (sbi->nls_tab)
0706         seq_printf(seq, ",iocharset=%s", sbi->nls_tab->charset);
0707     if (sbi->flag & JFS_ERR_CONTINUE)
0708         seq_printf(seq, ",errors=continue");
0709     if (sbi->flag & JFS_ERR_PANIC)
0710         seq_printf(seq, ",errors=panic");
0711 
0712 #ifdef CONFIG_QUOTA
0713     if (sbi->flag & JFS_USRQUOTA)
0714         seq_puts(seq, ",usrquota");
0715 
0716     if (sbi->flag & JFS_GRPQUOTA)
0717         seq_puts(seq, ",grpquota");
0718 #endif
0719 
0720     return 0;
0721 }
0722 
0723 #ifdef CONFIG_QUOTA
0724 
0725 /* Read data from quotafile - avoid pagecache and such because we cannot afford
0726  * acquiring the locks... As quota files are never truncated and quota code
0727  * itself serializes the operations (and no one else should touch the files)
0728  * we don't have to be afraid of races */
0729 static ssize_t jfs_quota_read(struct super_block *sb, int type, char *data,
0730                   size_t len, loff_t off)
0731 {
0732     struct inode *inode = sb_dqopt(sb)->files[type];
0733     sector_t blk = off >> sb->s_blocksize_bits;
0734     int err = 0;
0735     int offset = off & (sb->s_blocksize - 1);
0736     int tocopy;
0737     size_t toread;
0738     struct buffer_head tmp_bh;
0739     struct buffer_head *bh;
0740     loff_t i_size = i_size_read(inode);
0741 
0742     if (off > i_size)
0743         return 0;
0744     if (off+len > i_size)
0745         len = i_size-off;
0746     toread = len;
0747     while (toread > 0) {
0748         tocopy = sb->s_blocksize - offset < toread ?
0749                 sb->s_blocksize - offset : toread;
0750 
0751         tmp_bh.b_state = 0;
0752         tmp_bh.b_size = i_blocksize(inode);
0753         err = jfs_get_block(inode, blk, &tmp_bh, 0);
0754         if (err)
0755             return err;
0756         if (!buffer_mapped(&tmp_bh))    /* A hole? */
0757             memset(data, 0, tocopy);
0758         else {
0759             bh = sb_bread(sb, tmp_bh.b_blocknr);
0760             if (!bh)
0761                 return -EIO;
0762             memcpy(data, bh->b_data+offset, tocopy);
0763             brelse(bh);
0764         }
0765         offset = 0;
0766         toread -= tocopy;
0767         data += tocopy;
0768         blk++;
0769     }
0770     return len;
0771 }
0772 
0773 /* Write to quotafile */
0774 static ssize_t jfs_quota_write(struct super_block *sb, int type,
0775                    const char *data, size_t len, loff_t off)
0776 {
0777     struct inode *inode = sb_dqopt(sb)->files[type];
0778     sector_t blk = off >> sb->s_blocksize_bits;
0779     int err = 0;
0780     int offset = off & (sb->s_blocksize - 1);
0781     int tocopy;
0782     size_t towrite = len;
0783     struct buffer_head tmp_bh;
0784     struct buffer_head *bh;
0785 
0786     inode_lock(inode);
0787     while (towrite > 0) {
0788         tocopy = sb->s_blocksize - offset < towrite ?
0789                 sb->s_blocksize - offset : towrite;
0790 
0791         tmp_bh.b_state = 0;
0792         tmp_bh.b_size = i_blocksize(inode);
0793         err = jfs_get_block(inode, blk, &tmp_bh, 1);
0794         if (err)
0795             goto out;
0796         if (offset || tocopy != sb->s_blocksize)
0797             bh = sb_bread(sb, tmp_bh.b_blocknr);
0798         else
0799             bh = sb_getblk(sb, tmp_bh.b_blocknr);
0800         if (!bh) {
0801             err = -EIO;
0802             goto out;
0803         }
0804         lock_buffer(bh);
0805         memcpy(bh->b_data+offset, data, tocopy);
0806         flush_dcache_page(bh->b_page);
0807         set_buffer_uptodate(bh);
0808         mark_buffer_dirty(bh);
0809         unlock_buffer(bh);
0810         brelse(bh);
0811         offset = 0;
0812         towrite -= tocopy;
0813         data += tocopy;
0814         blk++;
0815     }
0816 out:
0817     if (len == towrite) {
0818         inode_unlock(inode);
0819         return err;
0820     }
0821     if (inode->i_size < off+len-towrite)
0822         i_size_write(inode, off+len-towrite);
0823     inode->i_mtime = inode->i_ctime = current_time(inode);
0824     mark_inode_dirty(inode);
0825     inode_unlock(inode);
0826     return len - towrite;
0827 }
0828 
0829 static struct dquot **jfs_get_dquots(struct inode *inode)
0830 {
0831     return JFS_IP(inode)->i_dquot;
0832 }
0833 
0834 static int jfs_quota_on(struct super_block *sb, int type, int format_id,
0835             const struct path *path)
0836 {
0837     int err;
0838     struct inode *inode;
0839 
0840     err = dquot_quota_on(sb, type, format_id, path);
0841     if (err)
0842         return err;
0843 
0844     inode = d_inode(path->dentry);
0845     inode_lock(inode);
0846     JFS_IP(inode)->mode2 |= JFS_NOATIME_FL | JFS_IMMUTABLE_FL;
0847     inode_set_flags(inode, S_NOATIME | S_IMMUTABLE,
0848             S_NOATIME | S_IMMUTABLE);
0849     inode_unlock(inode);
0850     mark_inode_dirty(inode);
0851 
0852     return 0;
0853 }
0854 
0855 static int jfs_quota_off(struct super_block *sb, int type)
0856 {
0857     struct inode *inode = sb_dqopt(sb)->files[type];
0858     int err;
0859 
0860     if (!inode || !igrab(inode))
0861         goto out;
0862 
0863     err = dquot_quota_off(sb, type);
0864     if (err)
0865         goto out_put;
0866 
0867     inode_lock(inode);
0868     JFS_IP(inode)->mode2 &= ~(JFS_NOATIME_FL | JFS_IMMUTABLE_FL);
0869     inode_set_flags(inode, 0, S_NOATIME | S_IMMUTABLE);
0870     inode_unlock(inode);
0871     mark_inode_dirty(inode);
0872 out_put:
0873     iput(inode);
0874     return err;
0875 out:
0876     return dquot_quota_off(sb, type);
0877 }
0878 #endif
0879 
0880 static const struct super_operations jfs_super_operations = {
0881     .alloc_inode    = jfs_alloc_inode,
0882     .free_inode = jfs_free_inode,
0883     .dirty_inode    = jfs_dirty_inode,
0884     .write_inode    = jfs_write_inode,
0885     .evict_inode    = jfs_evict_inode,
0886     .put_super  = jfs_put_super,
0887     .sync_fs    = jfs_sync_fs,
0888     .freeze_fs  = jfs_freeze,
0889     .unfreeze_fs    = jfs_unfreeze,
0890     .statfs     = jfs_statfs,
0891     .remount_fs = jfs_remount,
0892     .show_options   = jfs_show_options,
0893 #ifdef CONFIG_QUOTA
0894     .quota_read = jfs_quota_read,
0895     .quota_write    = jfs_quota_write,
0896     .get_dquots = jfs_get_dquots,
0897 #endif
0898 };
0899 
0900 static const struct export_operations jfs_export_operations = {
0901     .fh_to_dentry   = jfs_fh_to_dentry,
0902     .fh_to_parent   = jfs_fh_to_parent,
0903     .get_parent = jfs_get_parent,
0904 };
0905 
0906 static struct file_system_type jfs_fs_type = {
0907     .owner      = THIS_MODULE,
0908     .name       = "jfs",
0909     .mount      = jfs_do_mount,
0910     .kill_sb    = kill_block_super,
0911     .fs_flags   = FS_REQUIRES_DEV,
0912 };
0913 MODULE_ALIAS_FS("jfs");
0914 
0915 static void init_once(void *foo)
0916 {
0917     struct jfs_inode_info *jfs_ip = (struct jfs_inode_info *) foo;
0918 
0919     memset(jfs_ip, 0, sizeof(struct jfs_inode_info));
0920     INIT_LIST_HEAD(&jfs_ip->anon_inode_list);
0921     init_rwsem(&jfs_ip->rdwrlock);
0922     mutex_init(&jfs_ip->commit_mutex);
0923     init_rwsem(&jfs_ip->xattr_sem);
0924     spin_lock_init(&jfs_ip->ag_lock);
0925     jfs_ip->active_ag = -1;
0926     inode_init_once(&jfs_ip->vfs_inode);
0927 }
0928 
0929 static int __init init_jfs_fs(void)
0930 {
0931     int i;
0932     int rc;
0933 
0934     jfs_inode_cachep =
0935         kmem_cache_create_usercopy("jfs_ip", sizeof(struct jfs_inode_info),
0936             0, SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_ACCOUNT,
0937             offsetof(struct jfs_inode_info, i_inline_all),
0938             sizeof_field(struct jfs_inode_info, i_inline_all),
0939             init_once);
0940     if (jfs_inode_cachep == NULL)
0941         return -ENOMEM;
0942 
0943     /*
0944      * Metapage initialization
0945      */
0946     rc = metapage_init();
0947     if (rc) {
0948         jfs_err("metapage_init failed w/rc = %d", rc);
0949         goto free_slab;
0950     }
0951 
0952     /*
0953      * Transaction Manager initialization
0954      */
0955     rc = txInit();
0956     if (rc) {
0957         jfs_err("txInit failed w/rc = %d", rc);
0958         goto free_metapage;
0959     }
0960 
0961     /*
0962      * I/O completion thread (endio)
0963      */
0964     jfsIOthread = kthread_run(jfsIOWait, NULL, "jfsIO");
0965     if (IS_ERR(jfsIOthread)) {
0966         rc = PTR_ERR(jfsIOthread);
0967         jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
0968         goto end_txmngr;
0969     }
0970 
0971     if (commit_threads < 1)
0972         commit_threads = num_online_cpus();
0973     if (commit_threads > MAX_COMMIT_THREADS)
0974         commit_threads = MAX_COMMIT_THREADS;
0975 
0976     for (i = 0; i < commit_threads; i++) {
0977         jfsCommitThread[i] = kthread_run(jfs_lazycommit, NULL,
0978                          "jfsCommit");
0979         if (IS_ERR(jfsCommitThread[i])) {
0980             rc = PTR_ERR(jfsCommitThread[i]);
0981             jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
0982             commit_threads = i;
0983             goto kill_committask;
0984         }
0985     }
0986 
0987     jfsSyncThread = kthread_run(jfs_sync, NULL, "jfsSync");
0988     if (IS_ERR(jfsSyncThread)) {
0989         rc = PTR_ERR(jfsSyncThread);
0990         jfs_err("init_jfs_fs: fork failed w/rc = %d", rc);
0991         goto kill_committask;
0992     }
0993 
0994 #ifdef PROC_FS_JFS
0995     jfs_proc_init();
0996 #endif
0997 
0998     rc = register_filesystem(&jfs_fs_type);
0999     if (!rc)
1000         return 0;
1001 
1002 #ifdef PROC_FS_JFS
1003     jfs_proc_clean();
1004 #endif
1005     kthread_stop(jfsSyncThread);
1006 kill_committask:
1007     for (i = 0; i < commit_threads; i++)
1008         kthread_stop(jfsCommitThread[i]);
1009     kthread_stop(jfsIOthread);
1010 end_txmngr:
1011     txExit();
1012 free_metapage:
1013     metapage_exit();
1014 free_slab:
1015     kmem_cache_destroy(jfs_inode_cachep);
1016     return rc;
1017 }
1018 
1019 static void __exit exit_jfs_fs(void)
1020 {
1021     int i;
1022 
1023     jfs_info("exit_jfs_fs called");
1024 
1025     txExit();
1026     metapage_exit();
1027 
1028     kthread_stop(jfsIOthread);
1029     for (i = 0; i < commit_threads; i++)
1030         kthread_stop(jfsCommitThread[i]);
1031     kthread_stop(jfsSyncThread);
1032 #ifdef PROC_FS_JFS
1033     jfs_proc_clean();
1034 #endif
1035     unregister_filesystem(&jfs_fs_type);
1036 
1037     /*
1038      * Make sure all delayed rcu free inodes are flushed before we
1039      * destroy cache.
1040      */
1041     rcu_barrier();
1042     kmem_cache_destroy(jfs_inode_cachep);
1043 }
1044 
1045 module_init(init_jfs_fs)
1046 module_exit(exit_jfs_fs)