aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@google.com>2022-02-03 10:22:49 -0800
committerJaegeuk Kim <jaegeuk@google.com>2022-02-03 10:30:56 -0800
commit802713c6bfad3d417a053251c0dd9da97be5d125 (patch)
treef318bccb638150ca5a882cb1e1f56958d3eeb5c7
parent5e241a4f97504e4ebac27132662a887985f6d5e0 (diff)
parent1de1db84d2a4a0ddfe90362d07dbec1dbc423323 (diff)
downloadf2fs-tools-802713c6bfad3d417a053251c0dd9da97be5d125.tar.gz
Merge remote-tracking branch 'aosp/upstream-master' into aosp/masterandroid-t-preview-1android-s-v2-beta-3android-t-preview-1android-s-v2-beta-3
* aosp/upstream-master: f2fs-tools: add atomic write related options to f2fs_io write command mkfs.f2fs: set required quota types only fsck.f2fs: Add progression feedback Bug: 183020160 Signed-off-by: Jaegeuk Kim <jaegeuk@google.com> Change-Id: I8ebc094f8e2458578473ede1ef2a23ec19e316fe
-rw-r--r--METADATA6
-rw-r--r--fsck/fsck.c15
-rw-r--r--fsck/fsck.h1
-rw-r--r--include/f2fs_fs.h1
-rw-r--r--mkfs/f2fs_format.c37
-rw-r--r--mkfs/f2fs_format_main.c9
-rw-r--r--tools/f2fs_io/f2fs_io.c53
7 files changed, 88 insertions, 34 deletions
diff --git a/METADATA b/METADATA
index a3078fb..d59ae6e 100644
--- a/METADATA
+++ b/METADATA
@@ -11,8 +11,8 @@ third_party {
version: "v1.14.0"
license_type: RESTRICTED
last_upgrade_date {
- year: 2021
- month: 12
- day: 14
+ year: 2022
+ month: 2
+ day: 3
}
}
diff --git a/fsck/fsck.c b/fsck/fsck.c
index ecd87af..ddcede3 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -493,8 +493,23 @@ static int sanity_check_nid(struct f2fs_sb_info *sbi, u32 nid,
ni->blk_addr);
if (f2fs_test_main_bitmap(sbi, ni->blk_addr) == 0) {
+
fsck->chk.valid_blk_cnt++;
fsck->chk.valid_node_cnt++;
+
+ /* Progress report */
+ if (sbi->total_valid_node_count > 1000) {
+ unsigned int p10 = sbi->total_valid_node_count / 10;
+
+ if (sbi->fsck->chk.checked_node_cnt++ % p10)
+ return 0;
+
+ printf("[FSCK] Check node %"PRIu64" / %u (%.2f%%)\n",
+ sbi->fsck->chk.checked_node_cnt,
+ sbi->total_valid_node_count,
+ 10 * (float)sbi->fsck->chk.checked_node_cnt /
+ p10);
+ }
}
return 0;
}
diff --git a/fsck/fsck.h b/fsck/fsck.h
index 11846e1..ce5fffe 100644
--- a/fsck/fsck.h
+++ b/fsck/fsck.h
@@ -91,6 +91,7 @@ struct f2fs_fsck {
struct orphan_info orphani;
struct chk_result {
+ u64 checked_node_cnt;
u64 valid_blk_cnt;
u32 valid_nat_entry_cnt;
u32 valid_node_cnt;
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 9f918ba..d236437 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -504,6 +504,7 @@ struct f2fs_configuration {
int large_nat_bitmap;
int fix_chksum; /* fix old cp.chksum position */
__le32 feature; /* defined features */
+ unsigned int quota_bits; /* quota bits */
time_t fixed_time;
/* mkfs parameters */
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index d6a92f8..864d285 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -38,8 +38,6 @@ struct f2fs_checkpoint *cp;
/* Return time fixed by the user or current time by default */
#define mkfs_time ((c.fixed_time == -1) ? time(NULL) : c.fixed_time)
-static unsigned int quotatype_bits = 0;
-
const char *media_ext_lists[] = {
/* common prefix */
"mp", // Covers mp3, mp4, mpeg, mpg
@@ -513,14 +511,8 @@ static int f2fs_prepare_super_block(void)
set_sb(root_ino, 3);
c.next_free_nid = 4;
- if (c.feature & cpu_to_le32(F2FS_FEATURE_QUOTA_INO)) {
- quotatype_bits = QUOTA_USR_BIT | QUOTA_GRP_BIT;
- if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA))
- quotatype_bits |= QUOTA_PRJ_BIT;
- }
-
for (qtype = 0; qtype < F2FS_MAX_QUOTAS; qtype++) {
- if (!((1 << qtype) & quotatype_bits))
+ if (!((1 << qtype) & c.quota_bits))
continue;
sb->qf_ino[qtype] = cpu_to_le32(c.next_free_nid++);
MSG(0, "Info: add quota type = %u => %u\n",
@@ -867,7 +859,7 @@ static int f2fs_write_check_point_pack(void)
get_cp(cur_node_segno[0]) * c.blks_per_seg);
for (qtype = 0, i = 1; qtype < F2FS_MAX_QUOTAS; qtype++) {
- if (sb->qf_ino[qtype] == 0)
+ if (!((1 << qtype) & c.quota_bits))
continue;
journal->nat_j.entries[i].nid = sb->qf_ino[qtype];
journal->nat_j.entries[i].ne.version = 0;
@@ -958,10 +950,11 @@ static int f2fs_write_check_point_pack(void)
off = 1;
for (qtype = 0; qtype < F2FS_MAX_QUOTAS; qtype++) {
- if (sb->qf_ino[qtype] == 0)
- continue;
int j;
+ if (!((1 << qtype) & c.quota_bits))
+ continue;
+
for (j = 0; j < QUOTA_DATA(qtype); j++) {
(sum_entry + off + j)->nid = sb->qf_ino[qtype];
(sum_entry + off + j)->ofs_in_node = cpu_to_le16(j);
@@ -992,7 +985,7 @@ static int f2fs_write_check_point_pack(void)
sum->entries[0].nid = sb->root_ino;
sum->entries[0].ofs_in_node = 0;
for (qtype = i = 0; qtype < F2FS_MAX_QUOTAS; qtype++) {
- if (sb->qf_ino[qtype] == 0)
+ if (!((1 << qtype) & c.quota_bits))
continue;
sum->entries[1 + i].nid = sb->qf_ino[qtype];
sum->entries[1 + i].ofs_in_node = 0;
@@ -1360,7 +1353,7 @@ static int f2fs_write_default_quota(int qtype, unsigned int blkaddr,
return 0;
}
-static int f2fs_write_qf_inode(int qtype)
+static int f2fs_write_qf_inode(int qtype, int offset)
{
struct f2fs_node *raw_node = NULL;
u_int64_t data_blk_nor;
@@ -1382,11 +1375,9 @@ static int f2fs_write_qf_inode(int qtype)
raw_node->i.i_blocks = cpu_to_le64(1 + QUOTA_DATA(qtype));
data_blk_nor = get_sb(main_blkaddr) +
- c.cur_seg[CURSEG_HOT_DATA] * c.blks_per_seg + 1;
+ c.cur_seg[CURSEG_HOT_DATA] * c.blks_per_seg + 1
+ + offset * QUOTA_DATA(i);
- for (i = 0; i < qtype; i++)
- if (sb->qf_ino[i])
- data_blk_nor += QUOTA_DATA(i);
if (qtype == 0)
raw_id = raw_node->i.i_uid;
else if (qtype == 1)
@@ -1408,7 +1399,7 @@ static int f2fs_write_qf_inode(int qtype)
main_area_node_seg_blk_offset = get_sb(main_blkaddr);
main_area_node_seg_blk_offset += c.cur_seg[CURSEG_HOT_NODE] *
- c.blks_per_seg + qtype + 1;
+ c.blks_per_seg + offset + 1;
DBG(1, "\tWriting quota inode (hot node), %x %x %x at offset 0x%08"PRIu64"\n",
get_sb(main_blkaddr),
@@ -1440,7 +1431,7 @@ static int f2fs_update_nat_root(void)
/* update quota */
for (qtype = i = 0; qtype < F2FS_MAX_QUOTAS; qtype++) {
- if (sb->qf_ino[qtype] == 0)
+ if (!((1 << qtype) & c.quota_bits))
continue;
nat_blk->entries[sb->qf_ino[qtype]].block_addr =
cpu_to_le32(get_sb(main_blkaddr) +
@@ -1678,7 +1669,7 @@ static int f2fs_add_default_dentry_root(void)
static int f2fs_create_root_dir(void)
{
enum quota_type qtype;
- int err = 0;
+ int err = 0, i = 0;
err = f2fs_write_root_inode();
if (err < 0) {
@@ -1687,9 +1678,9 @@ static int f2fs_create_root_dir(void)
}
for (qtype = 0; qtype < F2FS_MAX_QUOTAS; qtype++) {
- if (sb->qf_ino[qtype] == 0)
+ if (!((1 << qtype) & c.quota_bits))
continue;
- err = f2fs_write_qf_inode(qtype);
+ err = f2fs_write_qf_inode(qtype, i++);
if (err < 0) {
MSG(1, "\tError: Failed to write quota inode!!!\n");
goto exit;
diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
index b89efe6..8d4dbe1 100644
--- a/mkfs/f2fs_format_main.c
+++ b/mkfs/f2fs_format_main.c
@@ -28,6 +28,7 @@
#endif
#include "f2fs_fs.h"
+#include "quota.h"
#include "f2fs_format_utils.h"
#ifdef WITH_ANDROID
@@ -127,9 +128,17 @@ static void add_default_options(void)
c.feature |= cpu_to_le32(F2FS_FEATURE_CASEFOLD);
#endif
#ifdef CONF_PROJID
+ c.feature |= cpu_to_le32(F2FS_FEATURE_QUOTA_INO);
c.feature |= cpu_to_le32(F2FS_FEATURE_PRJQUOTA);
c.feature |= cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR);
#endif
+
+ if (c.feature & cpu_to_le32(F2FS_FEATURE_QUOTA_INO))
+ c.quota_bits = QUOTA_USR_BIT | QUOTA_GRP_BIT;
+ if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA)) {
+ c.feature |= cpu_to_le32(F2FS_FEATURE_QUOTA_INO);
+ c.quota_bits |= QUOTA_PRJ_BIT;
+ }
}
static void f2fs_parse_options(int argc, char *argv[])
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index c6847c8..af4a34b 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -496,16 +496,19 @@ static void do_erase(int argc, char **argv, const struct cmd_desc *cmd)
#define write_desc "write data into file"
#define write_help \
-"f2fs_io write [chunk_size in 4kb] [offset in chunk_size] [count] [pattern] [IO] [file_path]\n\n" \
+"f2fs_io write [chunk_size in 4kb] [offset in chunk_size] [count] [pattern] [IO] [file_path] {delay}\n\n" \
"Write given patten data in file_path\n" \
"pattern can be\n" \
-" zero : zeros\n" \
-" inc_num : incrementing numbers\n" \
-" rand : random numbers\n" \
+" zero : zeros\n" \
+" inc_num : incrementing numbers\n" \
+" rand : random numbers\n" \
"IO can be\n" \
-" buffered : buffered IO\n" \
-" dio : direct IO\n" \
-" osync : O_SYNC\n" \
+" buffered : buffered IO\n" \
+" dio : direct IO\n" \
+" osync : O_SYNC\n" \
+" atomic_commit : atomic write & commit\n" \
+" atomic_abort : atomic write & abort\n" \
+"{delay} is in ms unit and optional only for atomic_commit and atomic_abort\n"
static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
{
@@ -516,10 +519,12 @@ static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
int flags = 0;
int fd;
u64 total_time = 0, max_time = 0, max_time_t = 0;
+ bool atomic_commit = false, atomic_abort = false;
+ int useconds = 0;
srand(time(0));
- if (argc != 7) {
+ if (argc < 7 || argc > 8) {
fputs("Excess arguments\n\n", stderr);
fputs(cmd->cmd_help, stderr);
exit(1);
@@ -545,11 +550,26 @@ static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
flags |= O_DIRECT;
else if (!strcmp(argv[5], "osync"))
flags |= O_SYNC;
+ else if (!strcmp(argv[5], "atomic_commit"))
+ atomic_commit = true;
+ else if (!strcmp(argv[5], "atomic_abort"))
+ atomic_abort = true;
else if (strcmp(argv[5], "buffered"))
die("Wrong IO type");
fd = xopen(argv[6], O_CREAT | O_WRONLY | flags, 0755);
+ if (atomic_commit || atomic_abort) {
+ if (argc == 8)
+ useconds = atoi(argv[7]) * 1000;
+
+ ret = ioctl(fd, F2FS_IOC_START_ATOMIC_WRITE);
+ if (ret < 0) {
+ fputs("setting atomic file mode failed\n", stderr);
+ exit(1);
+ }
+ }
+
total_time = get_current_us();
for (i = 0; i < count; i++) {
if (!strcmp(argv[4], "inc_num"))
@@ -568,6 +588,23 @@ static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
written += ret;
}
+ if (useconds)
+ usleep(useconds);
+
+ if (atomic_commit) {
+ ret = ioctl(fd, F2FS_IOC_COMMIT_ATOMIC_WRITE);
+ if (ret < 0) {
+ fputs("committing atomic write failed\n", stderr);
+ exit(1);
+ }
+ } else if (atomic_abort) {
+ ret = ioctl(fd, F2FS_IOC_ABORT_VOLATILE_WRITE);
+ if (ret < 0) {
+ fputs("aborting atomic write failed\n", stderr);
+ exit(1);
+ }
+ }
+
printf("Written %"PRIu64" bytes with pattern=%s, total_time=%"PRIu64" us, max_latency=%"PRIu64" us\n",
written, argv[4],
get_current_us() - total_time,