Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2017-2018 HUAWEI, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *             https://www.huawei.com/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Created by Gao Xiang <gaoxiang25@huawei.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/statfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/parser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/crc32c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/fs_context.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/fs_parser.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/dax.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include "xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define CREATE_TRACE_POINTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <trace/events/erofs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static struct kmem_cache *erofs_inode_cachep __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) void _erofs_err(struct super_block *sb, const char *function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 		const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	pr_err("(device %s): %s: %pV", sb->s_id, function, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) void _erofs_info(struct super_block *sb, const char *function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		 const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	pr_info("(device %s): %pV", sb->s_id, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static int erofs_superblock_csum_verify(struct super_block *sb, void *sbdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	struct erofs_super_block *dsb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	u32 expected_crc, crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	dsb = kmemdup(sbdata + EROFS_SUPER_OFFSET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		      EROFS_BLKSIZ - EROFS_SUPER_OFFSET, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	if (!dsb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	expected_crc = le32_to_cpu(dsb->checksum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	dsb->checksum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	/* to allow for x86 boot sectors and other oddities. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	crc = crc32c(~0, dsb, EROFS_BLKSIZ - EROFS_SUPER_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	kfree(dsb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	if (crc != expected_crc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		erofs_err(sb, "invalid checksum 0x%08x, 0x%08x expected",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 			  crc, expected_crc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return -EBADMSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) static void erofs_inode_init_once(void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct erofs_inode *vi = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	inode_init_once(&vi->vfs_inode);
^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) static struct inode *erofs_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	struct erofs_inode *vi =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		kmem_cache_alloc(erofs_inode_cachep, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (!vi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	/* zero out everything except vfs_inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	memset(vi, 0, offsetof(struct erofs_inode, vfs_inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	return &vi->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static void erofs_free_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	struct erofs_inode *vi = EROFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	/* be careful of RCU symlink path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (inode->i_op == &erofs_fast_symlink_iops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		kfree(inode->i_link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	kfree(vi->xattr_shared_xattrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	kmem_cache_free(erofs_inode_cachep, vi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static bool check_layout_compatibility(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 				       struct erofs_super_block *dsb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	const unsigned int feature = le32_to_cpu(dsb->feature_incompat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	EROFS_SB(sb)->feature_incompat = feature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	/* check if current kernel meets all mandatory requirements */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (feature & (~EROFS_ALL_FEATURE_INCOMPAT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		erofs_err(sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			  "unidentified incompatible feature %x, please upgrade kernel version",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 			   feature & ~EROFS_ALL_FEATURE_INCOMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #ifdef CONFIG_EROFS_FS_ZIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) /* read variable-sized metadata, offset will be aligned by 4-byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static void *erofs_read_metadata(struct super_block *sb, struct page **pagep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 				 erofs_off_t *offset, int *lengthp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	struct page *page = *pagep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	u8 *buffer, *ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	int len, i, cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	erofs_blk_t blk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	*offset = round_up(*offset, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	blk = erofs_blknr(*offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	if (!page || page->index != blk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		if (page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 			put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 		page = erofs_get_meta_page(sb, blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		if (IS_ERR(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			goto err_nullpage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	ptr = kmap(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	len = le16_to_cpu(*(__le16 *)&ptr[erofs_blkoff(*offset)]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (!len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		len = U16_MAX + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	buffer = kmalloc(len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	if (!buffer) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		buffer = ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	*offset += sizeof(__le16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	*lengthp = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	for (i = 0; i < len; i += cnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		cnt = min(EROFS_BLKSIZ - (int)erofs_blkoff(*offset), len - i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		blk = erofs_blknr(*offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		if (!page || page->index != blk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			if (page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 				kunmap(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 				unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 				put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			page = erofs_get_meta_page(sb, blk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 			if (IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 				kfree(buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 				goto err_nullpage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 			ptr = kmap(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 		memcpy(buffer + i, ptr + erofs_blkoff(*offset), cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		*offset += cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	kunmap(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	*pagep = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	return buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) err_nullpage:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	*pagep = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static int erofs_load_compr_cfgs(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 				 struct erofs_super_block *dsb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct erofs_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	unsigned int algs, alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	erofs_off_t offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	int size, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	sbi = EROFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	sbi->available_compr_algs = le16_to_cpu(dsb->u1.available_compr_algs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	if (sbi->available_compr_algs & ~Z_EROFS_ALL_COMPR_ALGS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		erofs_err(sb, "try to load compressed fs with unsupported algorithms %x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			  sbi->available_compr_algs & ~Z_EROFS_ALL_COMPR_ALGS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	offset = EROFS_SUPER_OFFSET + sbi->sb_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	alg = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	for (algs = sbi->available_compr_algs; algs; algs >>= 1, ++alg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		if (!(algs & 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		data = erofs_read_metadata(sb, &page, &offset, &size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		if (IS_ERR(data)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 			ret = PTR_ERR(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		switch (alg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		case Z_EROFS_COMPRESSION_LZ4:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			ret = z_erofs_load_lz4_config(sb, dsb, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			DBG_BUGON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 			ret = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	if (page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static int erofs_load_compr_cfgs(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 				 struct erofs_super_block *dsb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (dsb->u1.available_compr_algs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		erofs_err(sb, "try to load compressed fs when compression is disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static int erofs_read_superblock(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	struct erofs_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	struct erofs_super_block *dsb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	unsigned int blkszbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	page = read_mapping_page(sb->s_bdev->bd_inode->i_mapping, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		erofs_err(sb, "cannot read erofs superblock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		return PTR_ERR(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	sbi = EROFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	data = kmap(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	if (le32_to_cpu(dsb->magic) != EROFS_SUPER_MAGIC_V1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		erofs_err(sb, "cannot find valid erofs superblock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	sbi->feature_compat = le32_to_cpu(dsb->feature_compat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (erofs_sb_has_sb_chksum(sbi)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		ret = erofs_superblock_csum_verify(sb, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	blkszbits = dsb->blkszbits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	/* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	if (blkszbits != LOG_BLOCK_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 		erofs_err(sb, "blkszbits %u isn't supported on this platform",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			  blkszbits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	if (!check_layout_compatibility(sb, dsb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	sbi->sb_size = 128 + dsb->sb_extslots * EROFS_SB_EXTSLOT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	if (sbi->sb_size > EROFS_BLKSIZ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		erofs_err(sb, "invalid sb_extslots %u (more than a fs block)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			  sbi->sb_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	sbi->blocks = le32_to_cpu(dsb->blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	sbi->meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) #ifdef CONFIG_EROFS_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	sbi->xattr_blkaddr = le32_to_cpu(dsb->xattr_blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	sbi->islotbits = ilog2(sizeof(struct erofs_inode_compact));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	sbi->root_nid = le16_to_cpu(dsb->root_nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	sbi->inos = le64_to_cpu(dsb->inos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	sbi->build_time = le64_to_cpu(dsb->build_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	sbi->build_time_nsec = le32_to_cpu(dsb->build_time_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	memcpy(&sb->s_uuid, dsb->uuid, sizeof(dsb->uuid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	ret = strscpy(sbi->volume_name, dsb->volume_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		      sizeof(dsb->volume_name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	if (ret < 0) {	/* -E2BIG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		erofs_err(sb, "bad volume name without NIL terminator");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 		ret = -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	/* parse on-disk compression configurations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	if (erofs_sb_has_compr_cfgs(sbi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 		ret = erofs_load_compr_cfgs(sb, dsb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		ret = z_erofs_load_lz4_config(sb, dsb, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	kunmap(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) /* set up default EROFS parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) static void erofs_default_options(struct erofs_fs_context *ctx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) #ifdef CONFIG_EROFS_FS_ZIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	ctx->cache_strategy = EROFS_ZIP_CACHE_READAROUND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	ctx->max_sync_decompress_pages = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	ctx->readahead_sync_decompress = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) #ifdef CONFIG_EROFS_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	set_opt(ctx, XATTR_USER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) #ifdef CONFIG_EROFS_FS_POSIX_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	set_opt(ctx, POSIX_ACL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	Opt_user_xattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	Opt_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 	Opt_cache_strategy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	Opt_dax,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	Opt_dax_enum,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	Opt_err
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) static const struct constant_table erofs_param_cache_strategy[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	{"disabled",	EROFS_ZIP_CACHE_DISABLED},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	{"readahead",	EROFS_ZIP_CACHE_READAHEAD},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	{"readaround",	EROFS_ZIP_CACHE_READAROUND},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) static const struct constant_table erofs_dax_param_enums[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	{"always",	EROFS_MOUNT_DAX_ALWAYS},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	{"never",	EROFS_MOUNT_DAX_NEVER},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) static const struct fs_parameter_spec erofs_fs_parameters[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	fsparam_flag_no("user_xattr",	Opt_user_xattr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	fsparam_flag_no("acl",		Opt_acl),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	fsparam_enum("cache_strategy",	Opt_cache_strategy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 		     erofs_param_cache_strategy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	fsparam_flag("dax",             Opt_dax),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	fsparam_enum("dax",		Opt_dax_enum, erofs_dax_param_enums),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) static bool erofs_fc_set_dax_mode(struct fs_context *fc, unsigned int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) #ifdef CONFIG_FS_DAX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	struct erofs_fs_context *ctx = fc->fs_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	switch (mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	case EROFS_MOUNT_DAX_ALWAYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 		warnfc(fc, "DAX enabled. Warning: EXPERIMENTAL, use at your own risk");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		set_opt(ctx, DAX_ALWAYS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		clear_opt(ctx, DAX_NEVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 	case EROFS_MOUNT_DAX_NEVER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		set_opt(ctx, DAX_NEVER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		clear_opt(ctx, DAX_ALWAYS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 		DBG_BUGON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	errorfc(fc, "dax options not supported");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) static int erofs_fc_parse_param(struct fs_context *fc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 				struct fs_parameter *param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 	struct erofs_fs_context *ctx __maybe_unused = fc->fs_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	struct fs_parse_result result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	int opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	opt = fs_parse(fc, erofs_fs_parameters, param, &result);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	if (opt < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 		return opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	switch (opt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	case Opt_user_xattr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) #ifdef CONFIG_EROFS_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 		if (result.boolean)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 			set_opt(ctx, XATTR_USER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 			clear_opt(ctx, XATTR_USER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		errorfc(fc, "{,no}user_xattr options not supported");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 	case Opt_acl:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) #ifdef CONFIG_EROFS_FS_POSIX_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 		if (result.boolean)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 			set_opt(ctx, POSIX_ACL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 			clear_opt(ctx, POSIX_ACL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 		errorfc(fc, "{,no}acl options not supported");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	case Opt_cache_strategy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) #ifdef CONFIG_EROFS_FS_ZIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 		ctx->cache_strategy = result.uint_32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 		errorfc(fc, "compression not supported, cache_strategy ignored");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	case Opt_dax:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		if (!erofs_fc_set_dax_mode(fc, EROFS_MOUNT_DAX_ALWAYS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	case Opt_dax_enum:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		if (!erofs_fc_set_dax_mode(fc, result.uint_32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		return -ENOPARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) #ifdef CONFIG_EROFS_FS_ZIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) static const struct address_space_operations managed_cache_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static int erofs_managed_cache_releasepage(struct page *page, gfp_t gfp_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 	int ret = 1;	/* 0 - busy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	struct address_space *const mapping = page->mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	DBG_BUGON(!PageLocked(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 	DBG_BUGON(mapping->a_ops != &managed_cache_aops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 	if (PagePrivate(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		ret = erofs_try_to_free_cached_page(mapping, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) static void erofs_managed_cache_invalidatepage(struct page *page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 					       unsigned int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 					       unsigned int length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 	const unsigned int stop = length + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	DBG_BUGON(!PageLocked(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 	/* Check for potential overflow in debug mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	DBG_BUGON(stop > PAGE_SIZE || stop < length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 	if (offset == 0 && stop == PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 		while (!erofs_managed_cache_releasepage(page, GFP_NOFS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 			cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) static const struct address_space_operations managed_cache_aops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	.releasepage = erofs_managed_cache_releasepage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	.invalidatepage = erofs_managed_cache_invalidatepage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static int erofs_init_managed_cache(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	struct erofs_sb_info *const sbi = EROFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 	struct inode *const inode = new_inode(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	set_nlink(inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	inode->i_size = OFFSET_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	inode->i_mapping->a_ops = &managed_cache_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	mapping_set_gfp_mask(inode->i_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 			     GFP_NOFS | __GFP_HIGHMEM | __GFP_MOVABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	sbi->managed_cache = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) static int erofs_init_managed_cache(struct super_block *sb) { return 0; }
^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) static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	struct erofs_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	struct erofs_fs_context *ctx = fc->fs_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	sb->s_magic = EROFS_SUPER_MAGIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	if (!sb_set_blocksize(sb, EROFS_BLKSIZ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 		erofs_err(sb, "failed to set erofs blksize");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	if (!sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	sb->s_fs_info = sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	sbi->dax_dev = fs_dax_get_by_bdev(sb->s_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	err = erofs_read_superblock(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	if (test_opt(ctx, DAX_ALWAYS) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 	    !bdev_dax_supported(sb->s_bdev, EROFS_BLKSIZ)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 		errorfc(fc, "DAX unsupported by block device. Turning off DAX.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) 		clear_opt(ctx, DAX_ALWAYS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	sb->s_flags |= SB_RDONLY | SB_NOATIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	sb->s_maxbytes = MAX_LFS_FILESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	sb->s_time_gran = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 	sb->s_op = &erofs_sops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	sb->s_xattr = erofs_xattr_handlers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	if (test_opt(ctx, POSIX_ACL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 		sb->s_flags |= SB_POSIXACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 		sb->s_flags &= ~SB_POSIXACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	sbi->ctx = *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) #ifdef CONFIG_EROFS_FS_ZIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 	xa_init(&sbi->managed_pslots);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	/* get the root inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	inode = erofs_iget(sb, ROOT_NID(sbi), true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	if (IS_ERR(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 		return PTR_ERR(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	if (!S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		erofs_err(sb, "rootino(nid %llu) is not a directory(i_mode %o)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 			  ROOT_NID(sbi), inode->i_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	sb->s_root = d_make_root(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	if (!sb->s_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	erofs_shrinker_register(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	/* sb->s_umount is already locked, SB_ACTIVE and SB_BORN are not set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	err = erofs_init_managed_cache(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 	erofs_info(sb, "mounted with root inode @ nid %llu.", ROOT_NID(sbi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) static int erofs_fc_get_tree(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 	return get_tree_bdev(fc, erofs_fc_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) static int erofs_fc_reconfigure(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 	struct super_block *sb = fc->root->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	struct erofs_sb_info *sbi = EROFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	struct erofs_fs_context *ctx = fc->fs_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	DBG_BUGON(!sb_rdonly(sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	if (test_opt(ctx, POSIX_ACL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 		fc->sb_flags |= SB_POSIXACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 		fc->sb_flags &= ~SB_POSIXACL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	sbi->ctx = *ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	fc->sb_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) static void erofs_fc_free(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 	kfree(fc->fs_private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) static const struct fs_context_operations erofs_context_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 	.parse_param	= erofs_fc_parse_param,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 	.get_tree       = erofs_fc_get_tree,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	.reconfigure    = erofs_fc_reconfigure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	.free		= erofs_fc_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) static int erofs_init_fs_context(struct fs_context *fc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	fc->fs_private = kzalloc(sizeof(struct erofs_fs_context), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	if (!fc->fs_private)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	/* set default mount options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	erofs_default_options(fc->fs_private);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 	fc->ops = &erofs_context_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) }
^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)  * could be triggered after deactivate_locked_super()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)  * is called, thus including umount and failed to initialize.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static void erofs_kill_sb(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) 	struct erofs_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	WARN_ON(sb->s_magic != EROFS_SUPER_MAGIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	kill_block_super(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	sbi = EROFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 	if (!sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	fs_put_dax(sbi->dax_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 	kfree(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	sb->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) /* called when ->s_root is non-NULL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static void erofs_put_super(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	struct erofs_sb_info *const sbi = EROFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	DBG_BUGON(!sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	erofs_shrinker_unregister(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) #ifdef CONFIG_EROFS_FS_ZIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	iput(sbi->managed_cache);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	sbi->managed_cache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) static struct file_system_type erofs_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	.owner          = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	.name           = "erofs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	.init_fs_context = erofs_init_fs_context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	.kill_sb        = erofs_kill_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	.fs_flags       = FS_REQUIRES_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) MODULE_ALIAS_FS("erofs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) static int __init erofs_module_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	erofs_check_ondisk_layout_definitions();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) 	erofs_inode_cachep = kmem_cache_create("erofs_inode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) 					       sizeof(struct erofs_inode), 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) 					       SLAB_RECLAIM_ACCOUNT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) 					       erofs_inode_init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) 	if (!erofs_inode_cachep) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) 		goto icache_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) 	err = erofs_init_shrinker();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) 		goto shrinker_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) 	erofs_pcpubuf_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) 	err = z_erofs_init_zip_subsystem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) 		goto zip_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) 	err = register_filesystem(&erofs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) 		goto fs_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) fs_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) 	z_erofs_exit_zip_subsystem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) zip_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) 	erofs_exit_shrinker();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) shrinker_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) 	kmem_cache_destroy(erofs_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) icache_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) static void __exit erofs_module_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) 	unregister_filesystem(&erofs_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) 	z_erofs_exit_zip_subsystem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) 	erofs_exit_shrinker();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) 	/* Ensure all RCU free inodes are safe before cache is destroyed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) 	rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) 	kmem_cache_destroy(erofs_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) 	erofs_pcpubuf_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) /* get filesystem statistics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) 	struct super_block *sb = dentry->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) 	struct erofs_sb_info *sbi = EROFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) 	u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) 	buf->f_type = sb->s_magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) 	buf->f_bsize = EROFS_BLKSIZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) 	buf->f_blocks = sbi->blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) 	buf->f_bfree = buf->f_bavail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) 	buf->f_files = ULLONG_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) 	buf->f_ffree = ULLONG_MAX - sbi->inos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) 	buf->f_namelen = EROFS_NAME_LEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) 	buf->f_fsid    = u64_to_fsid(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) static int erofs_show_options(struct seq_file *seq, struct dentry *root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) 	struct erofs_sb_info *sbi = EROFS_SB(root->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) 	struct erofs_fs_context *ctx = &sbi->ctx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) #ifdef CONFIG_EROFS_FS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) 	if (test_opt(ctx, XATTR_USER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) 		seq_puts(seq, ",user_xattr");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) 		seq_puts(seq, ",nouser_xattr");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) #ifdef CONFIG_EROFS_FS_POSIX_ACL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) 	if (test_opt(ctx, POSIX_ACL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) 		seq_puts(seq, ",acl");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) 		seq_puts(seq, ",noacl");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) #ifdef CONFIG_EROFS_FS_ZIP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) 	if (ctx->cache_strategy == EROFS_ZIP_CACHE_DISABLED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) 		seq_puts(seq, ",cache_strategy=disabled");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) 	else if (ctx->cache_strategy == EROFS_ZIP_CACHE_READAHEAD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) 		seq_puts(seq, ",cache_strategy=readahead");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) 	else if (ctx->cache_strategy == EROFS_ZIP_CACHE_READAROUND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) 		seq_puts(seq, ",cache_strategy=readaround");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) 	if (test_opt(ctx, DAX_ALWAYS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) 		seq_puts(seq, ",dax=always");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) 	if (test_opt(ctx, DAX_NEVER))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) 		seq_puts(seq, ",dax=never");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) const struct super_operations erofs_sops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) 	.put_super = erofs_put_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) 	.alloc_inode = erofs_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) 	.free_inode = erofs_free_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) 	.statfs = erofs_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) 	.show_options = erofs_show_options,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) module_init(erofs_module_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) module_exit(erofs_module_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) MODULE_DESCRIPTION("Enhanced ROM File System");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) MODULE_AUTHOR("Gao Xiang, Chao Yu, Miao Xie, CONSUMER BG, HUAWEI Inc.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811)