Skip to contentSkip to conversation

erofs-utils: lib: get rid of global sbi in lib/inode.c

PATCH New Hongzhen Luo 1 participant 2 messages Jul 4, 2024 Library code

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 erofs-utils: lib: get rid of global sbi in lib/inode.c

Get rid of the global sbi when EROFS_MT_ENABLED is defined.

---
v2: Minor cleanup on the patch.
v1: https://lore.kernel.org/all/[email protected]/

---
 lib/inode.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
lib/inode.c +6 -5
index 3e82af7..8d60088 100644
@@ -1800,6 +1800,7 @@ static int erofs_mkfs_build_tree(struct erofs_mkfs_buildtree_ctx *ctx)
 {
 	struct erofs_mkfs_dfops *q;
 	int err, err2;
+	struct erofs_sb_info *sbi = ctx->sbi ? ctx->sbi : ctx->u.root->sbi;
 
 	q = malloc(sizeof(*q));
 	if (!q)
@@ -1818,15 +1819,15 @@ static int erofs_mkfs_build_tree(struct erofs_mkfs_buildtree_ctx *ctx)
 
 	q->head = 0;
 	q->tail = 0;
-	sbi.mkfs_dfops = q;
-	err = pthread_create(&sbi.dfops_worker, NULL,
-			     z_erofs_mt_dfops_worker, &sbi);
+	sbi->mkfs_dfops = q;
+	err = pthread_create(&sbi->dfops_worker, NULL,
+			     z_erofs_mt_dfops_worker, sbi);
 	if (err)
 		goto fail;
 
 	err = __erofs_mkfs_build_tree(ctx);
-	erofs_mkfs_go(&sbi, ~0, NULL, 0);
-	err2 = pthread_join(sbi.dfops_worker, NULL);
+	erofs_mkfs_go(sbi, ~0, NULL, 0);
+	err2 = pthread_join(sbi->dfops_worker, NULL);
 	if (!err)
 		err = err2;
 
Signature · 1 line
2.39.3
#1 lore raw

PATCH v2 2/2 erofs-utils: rename the global sbi to g_sbi

Rename the global sbi to g_sbi to prepare for
the upcoming per-sbi buffer.

It is checked by enabling multi-threadding option.

---
v2: The same as v1.
v1: https://lore.kernel.org/all/[email protected]/

---
 dump/main.c              |  58 +++++++++----------
 fsck/main.c              |  34 +++++------
 fuse/main.c              |  40 ++++++-------
 include/erofs/cache.h    |   6 +-
 include/erofs/internal.h |   2 +-
 lib/cache.c              |  22 +++----
 lib/config.c             |   2 +-
 lib/diskbuf.c            |   6 +-
 lib/rebuild.c            |   4 +-
 mkfs/main.c              | 122 +++++++++++++++++++--------------------
 10 files changed, 148 insertions(+), 148 deletions(-)
dump/main.c +29 -29
index 7c77c92..06ca4d3 100644
@@ -166,10 +166,10 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)
 			usage(argc, argv);
 			exit(0);
 		case 3:
-			err = erofs_blob_open_ro(&sbi, optarg);
+			err = erofs_blob_open_ro(&g_sbi, optarg);
 			if (err)
 				return err;
-			++sbi.extra_devices;
+			++g_sbi.extra_devices;
 			break;
 		case 4:
 			dumpcfg.inode_path = optarg;
@@ -180,7 +180,7 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)
 			dumpcfg.show_subdirectories = true;
 			break;
 		case 6:
-			sbi.bdev.offset = strtoull(optarg, &endptr, 0);
+			g_sbi.bdev.offset = strtoull(optarg, &endptr, 0);
 			if (*endptr != '\0') {
 				erofs_err("invalid disk offset %s", optarg);
 				return -EINVAL;
@@ -289,9 +289,9 @@ static int erofsdump_read_packed_inode(void)
 {
 	int err;
 	erofs_off_t occupied_size = 0;
-	struct erofs_inode vi = { .sbi = &sbi, .nid = sbi.packed_nid };
+	struct erofs_inode vi = { .sbi = &g_sbi, .nid = g_sbi.packed_nid };
 
-	if (!(erofs_sb_has_fragments(&sbi) && sbi.packed_nid > 0))
+	if (!(erofs_sb_has_fragments(&g_sbi) && g_sbi.packed_nid > 0))
 		return 0;
 
 	err = erofs_read_inode_from_disk(&vi);
@@ -315,7 +315,7 @@ static int erofsdump_readdir(struct erofs_dir_context *ctx)
 {
 	int err;
 	erofs_off_t occupied_size = 0;
-	struct erofs_inode vi = { .sbi = &sbi, .nid = ctx->de_nid };
+	struct erofs_inode vi = { .sbi = &g_sbi, .nid = ctx->de_nid };
 
 	err = erofs_read_inode_from_disk(&vi);
 	if (err) {
@@ -370,7 +370,7 @@ static void erofsdump_show_fileinfo(bool show_extent)
 	int err, i;
 	erofs_off_t size;
 	u16 access_mode;
-	struct erofs_inode inode = { .sbi = &sbi, .nid = dumpcfg.nid };
+	struct erofs_inode inode = { .sbi = &g_sbi, .nid = dumpcfg.nid };
 	char path[PATH_MAX];
 	char access_mode_str[] = "rwxrwxrwx";
 	char timebuf[128] = {0};
@@ -582,7 +582,7 @@ static void erofsdump_print_statistic(void)
 		.pnid = 0,
 		.dir = NULL,
 		.cb = erofsdump_dirent_iter,
-		.de_nid = sbi.root_nid,
+		.de_nid = g_sbi.root_nid,
 		.dname = "",
 		.de_namelen = 0,
 	};
@@ -626,48 +626,48 @@ static void erofsdump_print_supported_compressors(FILE *f, unsigned int mask)
 
 static void erofsdump_show_superblock(void)
 {
-	time_t time = sbi.build_time;
+	time_t time = g_sbi.build_time;
 	char uuid_str[37];
 	int i = 0;
 
 	fprintf(stdout, "Filesystem magic number:                      0x%04X\n",
 			EROFS_SUPER_MAGIC_V1);
 	fprintf(stdout, "Filesystem blocksize:                         %u\n",
-			erofs_blksiz(&sbi));
+			erofs_blksiz(&g_sbi));
 	fprintf(stdout, "Filesystem blocks:                            %llu\n",
-			sbi.total_blocks | 0ULL);
+			g_sbi.total_blocks | 0ULL);
 	fprintf(stdout, "Filesystem inode metadata start block:        %u\n",
-			sbi.meta_blkaddr);
+			g_sbi.meta_blkaddr);
 	fprintf(stdout, "Filesystem shared xattr metadata start block: %u\n",
-			sbi.xattr_blkaddr);
+			g_sbi.xattr_blkaddr);
 	fprintf(stdout, "Filesystem root nid:                          %llu\n",
-			sbi.root_nid | 0ULL);
-	if (erofs_sb_has_fragments(&sbi) && sbi.packed_nid > 0)
+			g_sbi.root_nid | 0ULL);
+	if (erofs_sb_has_fragments(&g_sbi) && g_sbi.packed_nid > 0)
 		fprintf(stdout, "Filesystem packed nid:                        %llu\n",
-			sbi.packed_nid | 0ULL);
-	if (erofs_sb_has_compr_cfgs(&sbi)) {
+			g_sbi.packed_nid | 0ULL);
+	if (erofs_sb_has_compr_cfgs(&g_sbi)) {
 		fprintf(stdout, "Filesystem compr_algs:                        ");
 		erofsdump_print_supported_compressors(stdout,
-			sbi.available_compr_algs);
+			g_sbi.available_compr_algs);
 	} else {
 		fprintf(stdout, "Filesystem lz4_max_distance:                  %u\n",
-			sbi.lz4_max_distance | 0U);
+			g_sbi.lz4_max_distance | 0U);
 	}
 	fprintf(stdout, "Filesystem sb_size:                           %u\n",
-			sbi.sb_size | 0U);
+			g_sbi.sb_size | 0U);
 	fprintf(stdout, "Filesystem inode count:                       %llu\n",
-			sbi.inos | 0ULL);
+			g_sbi.inos | 0ULL);
 	fprintf(stdout, "Filesystem created:                           %s",
 			ctime(&time));
 	fprintf(stdout, "Filesystem features:                          ");
 	for (; i < ARRAY_SIZE(feature_lists); i++) {
 		u32 feat = le32_to_cpu(feature_lists[i].compat ?
-				       sbi.feature_compat :
-				       sbi.feature_incompat);
+				       g_sbi.feature_compat :
+				       g_sbi.feature_incompat);
 		if (feat & feature_lists[i].flag)
 			fprintf(stdout, "%s ", feature_lists[i].name);
 	}
-	erofs_uuid_unparse_lower(sbi.uuid, uuid_str);
+	erofs_uuid_unparse_lower(g_sbi.uuid, uuid_str);
 	fprintf(stdout, "\nFilesystem UUID:                              %s\n",
 			uuid_str);
 }
@@ -684,13 +684,13 @@ int main(int argc, char **argv)
 		goto exit;
 	}
 
-	err = erofs_dev_open(&sbi, cfg.c_img_path, O_RDONLY | O_TRUNC);
+	err = erofs_dev_open(&g_sbi, cfg.c_img_path, O_RDONLY | O_TRUNC);
 	if (err) {
 		erofs_err("failed to open image file");
 		goto exit;
 	}
 
-	err = erofs_read_superblock(&sbi);
+	err = erofs_read_superblock(&g_sbi);
 	if (err) {
 		erofs_err("failed to read superblock");
 		goto exit_dev_close;
@@ -715,11 +715,11 @@ int main(int argc, char **argv)
 		erofsdump_show_fileinfo(dumpcfg.show_extent);
 
 exit_put_super:
-	erofs_put_super(&sbi);
+	erofs_put_super(&g_sbi);
 exit_dev_close:
-	erofs_dev_close(&sbi);
+	erofs_dev_close(&g_sbi);
 exit:
-	erofs_blob_closeall(&sbi);
+	erofs_blob_closeall(&g_sbi);
 	erofs_exit_configure();
 	return err;
 }
fsck/main.c +17 -17
index a505e99..8ec9486 100644
@@ -183,10 +183,10 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
 			}
 			break;
 		case 3:
-			ret = erofs_blob_open_ro(&sbi, optarg);
+			ret = erofs_blob_open_ro(&g_sbi, optarg);
 			if (ret)
 				return ret;
-			++sbi.extra_devices;
+			++g_sbi.extra_devices;
 			break;
 		case 4:
 			fsckcfg.force = true;
@@ -219,7 +219,7 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)
 			has_opt_preserve = true;
 			break;
 		case 12:
-			sbi.bdev.offset = strtoull(optarg, &endptr, 0);
+			g_sbi.bdev.offset = strtoull(optarg, &endptr, 0);
 			if (*endptr != '\0') {
 				erofs_err("invalid disk offset %s", optarg);
 				return -EINVAL;
@@ -311,7 +311,7 @@ static int erofs_check_sb_chksum(void)
 	struct erofs_super_block *sb;
 	int ret;
 
-	ret = erofs_blk_read(&sbi, 0, buf, 0, 1);
+	ret = erofs_blk_read(&g_sbi, 0, buf, 0, 1);
 	if (ret) {
 		erofs_err("failed to read superblock to check checksum: %d",
 			  ret);
@@ -321,10 +321,10 @@ static int erofs_check_sb_chksum(void)
 	sb = (struct erofs_super_block *)(buf + EROFS_SUPER_OFFSET);
 	sb->checksum = 0;
 
-	crc = erofs_crc32c(~0, (u8 *)sb, erofs_blksiz(&sbi) - EROFS_SUPER_OFFSET);
-	if (crc != sbi.checksum) {
+	crc = erofs_crc32c(~0, (u8 *)sb, erofs_blksiz(&g_sbi) - EROFS_SUPER_OFFSET);
+	if (crc != g_sbi.checksum) {
 		erofs_err("superblock chksum doesn't match: saved(%08xh) calculated(%08xh)",
-			  sbi.checksum, crc);
+			  g_sbi.checksum, crc);
 		fsckcfg.corrupted = true;
 		return -1;
 	}
@@ -889,7 +889,7 @@ static int erofsfsck_check_inode(erofs_nid_t pnid, erofs_nid_t nid)
 	erofs_dbg("check inode: nid(%llu)", nid | 0ULL);
 
 	inode.nid = nid;
-	inode.sbi = &sbi;
+	inode.sbi = &g_sbi;
 	ret = erofs_read_inode_from_disk(&inode);
 	if (ret) {
 		if (ret == -EIO)
@@ -965,19 +965,19 @@ int main(int argc, char *argv[])
 	cfg.c_dbg_lvl = -1;
 #endif
 
-	err = erofs_dev_open(&sbi, cfg.c_img_path, O_RDONLY);
+	err = erofs_dev_open(&g_sbi, cfg.c_img_path, O_RDONLY);
 	if (err) {
 		erofs_err("failed to open image file");
 		goto exit;
 	}
 
-	err = erofs_read_superblock(&sbi);
+	err = erofs_read_superblock(&g_sbi);
 	if (err) {
 		erofs_err("failed to read superblock");
 		goto exit_dev_close;
 	}
 
-	if (erofs_sb_has_sb_chksum(&sbi) && erofs_check_sb_chksum()) {
+	if (erofs_sb_has_sb_chksum(&g_sbi) && erofs_check_sb_chksum()) {
 		erofs_err("failed to verify superblock checksum");
 		goto exit_put_super;
 	}
@@ -985,15 +985,15 @@ int main(int argc, char *argv[])
 	if (fsckcfg.extract_path)
 		erofsfsck_hardlink_init();
 
-	if (erofs_sb_has_fragments(&sbi) && sbi.packed_nid > 0) {
-		err = erofsfsck_check_inode(sbi.packed_nid, sbi.packed_nid);
+	if (erofs_sb_has_fragments(&g_sbi) && g_sbi.packed_nid > 0) {
+		err = erofsfsck_check_inode(g_sbi.packed_nid, g_sbi.packed_nid);
 		if (err) {
 			erofs_err("failed to verify packed file");
 			goto exit_hardlink;
 		}
 	}
 
-	err = erofsfsck_check_inode(sbi.root_nid, sbi.root_nid);
+	err = erofsfsck_check_inode(g_sbi.root_nid, g_sbi.root_nid);
 	if (fsckcfg.corrupted) {
 		if (!fsckcfg.extract_path)
 			erofs_err("Found some filesystem corruption");
@@ -1019,11 +1019,11 @@ exit_hardlink:
 	if (fsckcfg.extract_path)
 		erofsfsck_hardlink_exit();
 exit_put_super:
-	erofs_put_super(&sbi);
+	erofs_put_super(&g_sbi);
 exit_dev_close:
-	erofs_dev_close(&sbi);
+	erofs_dev_close(&g_sbi);
 exit:
-	erofs_blob_closeall(&sbi);
+	erofs_blob_closeall(&g_sbi);
 	erofs_exit_configure();
 	return err ? 1 : 0;
 }
fuse/main.c +20 -20
index 70e3218..f6c04e8 100644
@@ -41,13 +41,13 @@ struct erofsfuse_lookupdir_context {
 static inline erofs_nid_t erofsfuse_to_nid(fuse_ino_t ino)
 {
 	if (ino == FUSE_ROOT_ID)
-		return sbi.root_nid;
+		return g_sbi.root_nid;
 	return (erofs_nid_t)(ino - FUSE_ROOT_ID);
 }
 
 static inline fuse_ino_t erofsfuse_to_ino(erofs_nid_t nid)
 {
-	if (nid == sbi.root_nid)
+	if (nid == g_sbi.root_nid)
 		return FUSE_ROOT_ID;
 	return (nid + FUSE_ROOT_ID);
 }
@@ -60,7 +60,7 @@ static void erofsfuse_fill_stat(struct erofs_inode *vi, struct stat *stbuf)
 	stbuf->st_mode = vi->i_mode;
 	stbuf->st_nlink = vi->i_nlink;
 	stbuf->st_size = vi->i_size;
-	stbuf->st_blocks = roundup(vi->i_size, erofs_blksiz(&sbi)) >> 9;
+	stbuf->st_blocks = roundup(vi->i_size, erofs_blksiz(&g_sbi)) >> 9;
 	stbuf->st_uid = vi->i_uid;
 	stbuf->st_gid = vi->i_gid;
 	stbuf->st_ctime = vi->i_mtime;
@@ -94,7 +94,7 @@ static int erofsfuse_add_dentry(struct erofs_dir_context *ctx)
 #if FUSE_MAJOR_VERSION >= 3
 		int ret;
 		struct erofs_inode vi = {
-			.sbi = &sbi,
+			.sbi = &g_sbi,
 			.nid = ctx->de_nid
 		};
 
@@ -140,7 +140,7 @@ static int erofsfuse_lookup_dentry(struct erofs_dir_context *ctx)
 	if (!strncmp(lookup_ctx->target_name, ctx->dname, ctx->de_namelen)) {
 		int ret;
 		struct erofs_inode vi = {
-			.sbi = &sbi,
+			.sbi = &g_sbi,
 			.nid = (erofs_nid_t)ctx->de_nid,
 		};
 
@@ -236,7 +236,7 @@ static void erofsfuse_open(fuse_req_t req, fuse_ino_t ino,
 		return;
 	}
 
-	vi->sbi = &sbi;
+	vi->sbi = &g_sbi;
 	vi->nid = erofsfuse_to_nid(ino);
 	ret = erofs_read_inode_from_disk(vi);
 	if (ret < 0) {
@@ -262,7 +262,7 @@ static void erofsfuse_getattr(fuse_req_t req, fuse_ino_t ino,
 {
 	int ret;
 	struct stat stbuf = { 0 };
-	struct erofs_inode vi = { .sbi = &sbi, .nid = erofsfuse_to_nid(ino) };
+	struct erofs_inode vi = { .sbi = &g_sbi, .nid = erofsfuse_to_nid(ino) };
 
 	ret = erofs_read_inode_from_disk(&vi);
 	if (ret < 0)
@@ -286,7 +286,7 @@ static void erofsfuse_opendir(fuse_req_t req, fuse_ino_t ino,
 		return;
 	}
 
-	vi->sbi = &sbi;
+	vi->sbi = &g_sbi;
 	vi->nid = erofsfuse_to_nid(ino);
 	ret = erofs_read_inode_from_disk(vi);
 	if (ret < 0) {
@@ -329,7 +329,7 @@ static void erofsfuse_lookup(fuse_req_t req, fuse_ino_t parent,
 		return;
 	}
 
-	vi->sbi = &sbi;
+	vi->sbi = &g_sbi;
 	vi->nid = erofsfuse_to_nid(parent);
 	ret = erofs_read_inode_from_disk(vi);
 	if (ret < 0) {
@@ -399,7 +399,7 @@ static void erofsfuse_readlink(fuse_req_t req, fuse_ino_t ino)
 {
 	int ret;
 	char *buf = NULL;
-	struct erofs_inode vi = { .sbi = &sbi, .nid = erofsfuse_to_nid(ino) };
+	struct erofs_inode vi = { .sbi = &g_sbi, .nid = erofsfuse_to_nid(ino) };
 
 	ret = erofs_read_inode_from_disk(&vi);
 	if (ret < 0) {
@@ -436,7 +436,7 @@ static void erofsfuse_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name,
 {
 	int ret;
 	char *buf = NULL;
-	struct erofs_inode vi = { .sbi = &sbi, .nid = erofsfuse_to_nid(ino) };
+	struct erofs_inode vi = { .sbi = &g_sbi, .nid = erofsfuse_to_nid(ino) };
 
 	erofs_dbg("getattr(%llu): name = %s, size = %zu", ino | 0ULL, name, size);
 
@@ -469,7 +469,7 @@ static void erofsfuse_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size)
 {
 	int ret;
 	char *buf = NULL;
-	struct erofs_inode vi = { .sbi = &sbi, .nid = erofsfuse_to_nid(ino) };
+	struct erofs_inode vi = { .sbi = &g_sbi, .nid = erofsfuse_to_nid(ino) };
 
 	erofs_dbg("listxattr(%llu): size = %zu", ino | 0ULL, size);
 
@@ -573,10 +573,10 @@ static int optional_opt_func(void *data, const char *arg, int key,
 
 	switch (key) {
 	case 1:
-		ret = erofs_blob_open_ro(&sbi, arg + sizeof("--device=") - 1);
+		ret = erofs_blob_open_ro(&g_sbi, arg + sizeof("--device=") - 1);
 		if (ret)
 			return -1;
-		++sbi.extra_devices;
+		++g_sbi.extra_devices;
 		return 0;
 	case FUSE_OPT_KEY_NONOPT:
 		if (fusecfg.mountpoint)
@@ -675,14 +675,14 @@ int main(int argc, char *argv[])
 	if (fusecfg.odebug && cfg.c_dbg_lvl < EROFS_DBG)
 		cfg.c_dbg_lvl = EROFS_DBG;
 
-	sbi.bdev.offset = fusecfg.offset;
-	ret = erofs_dev_open(&sbi, fusecfg.disk, O_RDONLY);
+	g_sbi.bdev.offset = fusecfg.offset;
+	ret = erofs_dev_open(&g_sbi, fusecfg.disk, O_RDONLY);
 	if (ret) {
 		fprintf(stderr, "failed to open: %s\n", fusecfg.disk);
 		goto err_fuse_free_args;
 	}
 
-	ret = erofs_read_superblock(&sbi);
+	ret = erofs_read_superblock(&g_sbi);
 	if (ret) {
 		fprintf(stderr, "failed to read erofs super block\n");
 		goto err_dev_close;
@@ -744,10 +744,10 @@ int main(int argc, char *argv[])
 #endif
 
 err_super_put:
-	erofs_put_super(&sbi);
+	erofs_put_super(&g_sbi);
 err_dev_close:
-	erofs_blob_closeall(&sbi);
-	erofs_dev_close(&sbi);
+	erofs_blob_closeall(&g_sbi);
+	erofs_dev_close(&g_sbi);
 err_fuse_free_args:
 	free(opts.mountpoint);
 	fuse_opt_free_args(&args);
include/erofs/cache.h +3 -3
index f30fe9f..234185f 100644
@@ -56,14 +56,14 @@ struct erofs_buffer_block {
 static inline const int get_alignsize(int type, int *type_ret)
 {
 	if (type == DATA)
-		return erofs_blksiz(&sbi);
+		return erofs_blksiz(&g_sbi);
 
 	if (type == INODE) {
 		*type_ret = META;
 		return sizeof(struct erofs_inode_compact);
 	} else if (type == DIRA) {
 		*type_ret = META;
-		return erofs_blksiz(&sbi);
+		return erofs_blksiz(&g_sbi);
 	} else if (type == XATTR) {
 		*type_ret = META;
 		return sizeof(struct erofs_xattr_entry);
@@ -87,7 +87,7 @@ static inline erofs_off_t erofs_btell(struct erofs_buffer_head *bh, bool end)
 	if (bb->blkaddr == NULL_ADDR)
 		return NULL_ADDR_UL;
 
-	return erofs_pos(&sbi, bb->blkaddr) +
+	return erofs_pos(&g_sbi, bb->blkaddr) +
 		(end ? list_next_entry(bh, list)->off : bh->off);
 }
 
include/erofs/internal.h +1 -1
index d5c5ce2..5f70570 100644
@@ -48,7 +48,7 @@ typedef u32 erofs_blk_t;
 #define NULL_ADDR_UL	((unsigned long)-1)
 
 /* global sbi */
-extern struct erofs_sb_info sbi;
+extern struct erofs_sb_info g_sbi;
 
 #define erofs_blksiz(sbi)	(1u << (sbi)->blkszbits)
 #define erofs_blknr(sbi, addr)  ((addr) >> (sbi)->blkszbits)
lib/cache.c +11 -11
index 328ca4a..e3dc9de 100644
@@ -56,7 +56,7 @@ static void erofs_bupdate_mapped(struct erofs_buffer_block *bb)
 		return;
 
 	bkt = mapped_buckets[bb->type] +
-		(bb->buffers.off & (erofs_blksiz(&sbi) - 1));
+		(bb->buffers.off & (erofs_blksiz(&g_sbi) - 1));
 	list_del(&bb->mapped_list);
 	list_add_tail(&bb->mapped_list, bkt);
 }
@@ -69,7 +69,7 @@ static int __erofs_battach(struct erofs_buffer_block *bb,
 			   unsigned int extrasize,
 			   bool dryrun)
 {
-	const unsigned int blksiz = erofs_blksiz(&sbi);
+	const unsigned int blksiz = erofs_blksiz(&g_sbi);
 	const unsigned int blkmask = blksiz - 1;
 	erofs_off_t boff = bb->buffers.off;
 	const erofs_off_t alignedoffset = roundup(boff, alignsize);
@@ -86,7 +86,7 @@ static int __erofs_battach(struct erofs_buffer_block *bb,
 		blkaddr = bb->blkaddr;
 		if (blkaddr != NULL_ADDR) {
 			tailupdate = (tail_blkaddr == blkaddr +
-				      BLK_ROUND_UP(&sbi, boff));
+				      BLK_ROUND_UP(&g_sbi, boff));
 			if (oob && !tailupdate)
 				return -EINVAL;
 		}
@@ -102,7 +102,7 @@ static int __erofs_battach(struct erofs_buffer_block *bb,
 		bb->buffers.off = boff;
 		/* need to update the tail_blkaddr */
 		if (tailupdate)
-			tail_blkaddr = blkaddr + BLK_ROUND_UP(&sbi, boff);
+			tail_blkaddr = blkaddr + BLK_ROUND_UP(&g_sbi, boff);
 		erofs_bupdate_mapped(bb);
 	}
 	return ((alignedoffset + incr - 1) & blkmask) + 1;
@@ -125,7 +125,7 @@ static int erofs_bfind_for_attach(int type, erofs_off_t size,
 				  unsigned int alignsize,
 				  struct erofs_buffer_block **bbp)
 {
-	const unsigned int blksiz = erofs_blksiz(&sbi);
+	const unsigned int blksiz = erofs_blksiz(&g_sbi);
 	struct erofs_buffer_block *cur, *bb;
 	unsigned int used0, used_before, usedmax, used;
 	int ret;
@@ -322,7 +322,7 @@ static erofs_blk_t __erofs_mapbh(struct erofs_buffer_block *bb)
 		erofs_bupdate_mapped(bb);
 	}
 
-	blkaddr = bb->blkaddr + BLK_ROUND_UP(&sbi, bb->buffers.off);
+	blkaddr = bb->blkaddr + BLK_ROUND_UP(&g_sbi, bb->buffers.off);
 	if (blkaddr > tail_blkaddr)
 		tail_blkaddr = blkaddr;
 
@@ -360,7 +360,7 @@ static void erofs_bfree(struct erofs_buffer_block *bb)
 
 int erofs_bflush(struct erofs_buffer_block *bb)
 {
-	const unsigned int blksiz = erofs_blksiz(&sbi);
+	const unsigned int blksiz = erofs_blksiz(&g_sbi);
 	struct erofs_buffer_block *p, *n;
 	erofs_blk_t blkaddr;
 
@@ -392,11 +392,11 @@ int erofs_bflush(struct erofs_buffer_block *bb)
 
 		padding = blksiz - (p->buffers.off & (blksiz - 1));
 		if (padding != blksiz)
-			erofs_dev_fillzero(&sbi, erofs_pos(&sbi, blkaddr) - padding,
+			erofs_dev_fillzero(&g_sbi, erofs_pos(&g_sbi, blkaddr) - padding,
 					   padding, true);
 
 		if (p->type != DATA)
-			erofs_metablkcnt += BLK_ROUND_UP(&sbi, p->buffers.off);
+			erofs_metablkcnt += BLK_ROUND_UP(&g_sbi, p->buffers.off);
 		erofs_dbg("block %u to %u flushed", p->blkaddr, blkaddr - 1);
 		erofs_bfree(p);
 	}
@@ -411,7 +411,7 @@ void erofs_bdrop(struct erofs_buffer_head *bh, bool tryrevoke)
 
 	/* tail_blkaddr could be rolled back after revoking all bhs */
 	if (tryrevoke && blkaddr != NULL_ADDR &&
-	    tail_blkaddr == blkaddr + BLK_ROUND_UP(&sbi, bb->buffers.off))
+	    tail_blkaddr == blkaddr + BLK_ROUND_UP(&g_sbi, bb->buffers.off))
 		rollback = true;
 
 	bh->op = &erofs_drop_directly_bhops;
@@ -421,7 +421,7 @@ void erofs_bdrop(struct erofs_buffer_head *bh, bool tryrevoke)
 		return;
 
 	if (!rollback && bb->type != DATA)
-		erofs_metablkcnt += BLK_ROUND_UP(&sbi, bb->buffers.off);
+		erofs_metablkcnt += BLK_ROUND_UP(&g_sbi, bb->buffers.off);
 	erofs_bfree(bb);
 	if (rollback)
 		tail_blkaddr = blkaddr;
lib/config.c +1 -1
index 44f0606..848bc59 100644
@@ -19,7 +19,7 @@
 #endif
 
 struct erofs_configure cfg;
-struct erofs_sb_info sbi;
+struct erofs_sb_info g_sbi;
 bool erofs_stdout_tty;
 
 void erofs_init_configure(void)
lib/diskbuf.c +3 -3
index e5f1f0c..3789654 100644
@@ -104,10 +104,10 @@ int erofs_diskbuf_init(unsigned int nstrms)
 		struct stat st;
 
 		/* try to use the devfd for regfiles on stream 0 */
-		if (strm == dbufstrm && !sbi.bdev.ops) {
+		if (strm == dbufstrm && !g_sbi.bdev.ops) {
 			strm->devpos = 1ULL << 40;
-			if (!ftruncate(sbi.bdev.fd, strm->devpos << 1)) {
-				strm->fd = dup(sbi.bdev.fd);
+			if (!ftruncate(g_sbi.bdev.fd, strm->devpos << 1)) {
+				strm->fd = dup(g_sbi.bdev.fd);
 				if (lseek(strm->fd, strm->devpos,
 					  SEEK_SET) != strm->devpos)
 					return -EIO;
lib/rebuild.c +2 -2
index 0b1a6c6..9e8bf8f 100644
@@ -360,7 +360,7 @@ static int erofs_rebuild_dirent_iter(struct erofs_dir_context *ctx)
 			inode->i_ino[1] = inode->nid;
 			inode->i_nlink = 1;
 
-			ret = erofs_rebuild_update_inode(&sbi, inode,
+			ret = erofs_rebuild_update_inode(&g_sbi, inode,
 							 rctx->datamode);
 			if (ret) {
 				erofs_iput(inode);
@@ -386,7 +386,7 @@ static int erofs_rebuild_dirent_iter(struct erofs_dir_context *ctx)
 	}
 
 	/* reset sbi, nid after subdirs are all loaded for the final dump */
-	inode->sbi = &sbi;
+	inode->sbi = &g_sbi;
 	inode->nid = 0;
 out:
 	free(path);
mkfs/main.c +61 -61

344 lines not on this page · raw message

Signature · 1 line
2.39.3