未验证 提交 a496c0ea 编写于 作者: O openharmony_ci 提交者: Gitee

!1348 optimize mount code

Merge pull request !1348 from cheng_jinsong/optimize
...@@ -61,6 +61,7 @@ static int ExecCommand(int argc, char **argv) ...@@ -61,6 +61,7 @@ static int ExecCommand(int argc, char **argv)
if (argc == 0 || argv == NULL || argv[0] == NULL) { if (argc == 0 || argv == NULL || argv[0] == NULL) {
return -1; return -1;
} }
BEGET_LOGI("Execute %s begin", argv[0]);
pid_t pid = fork(); pid_t pid = fork();
if (pid < 0) { if (pid < 0) {
BEGET_LOGE("Fork new process to format failed: %d", errno); BEGET_LOGE("Fork new process to format failed: %d", errno);
...@@ -75,6 +76,7 @@ static int ExecCommand(int argc, char **argv) ...@@ -75,6 +76,7 @@ static int ExecCommand(int argc, char **argv)
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
BEGET_LOGE("Command %s failed with status %d", argv[0], WEXITSTATUS(status)); BEGET_LOGE("Command %s failed with status %d", argv[0], WEXITSTATUS(status));
} }
BEGET_LOGI("Execute %s end", argv[0]);
return WEXITSTATUS(status); return WEXITSTATUS(status);
} }
...@@ -192,7 +194,6 @@ static int DoResizeF2fs(const char* device, const unsigned long long size) ...@@ -192,7 +194,6 @@ static int DoResizeF2fs(const char* device, const unsigned long long size)
char **argv = (char **)cmd; char **argv = (char **)cmd;
ret = ExecCommand(argc, argv); ret = ExecCommand(argc, argv);
} }
BEGET_LOGI("resize.f2fs is ending.");
return ret; return ret;
} }
...@@ -209,7 +210,6 @@ static int DoFsckF2fs(const char* device) ...@@ -209,7 +210,6 @@ static int DoFsckF2fs(const char* device)
}; };
int argc = ARRAY_LENGTH(cmd); int argc = ARRAY_LENGTH(cmd);
char **argv = (char **)cmd; char **argv = (char **)cmd;
BEGET_LOGI("fsck.f2fs is ending.");
return ExecCommand(argc, argv); return ExecCommand(argc, argv);
} }
...@@ -242,7 +242,6 @@ static int DoResizeExt(const char* device, const unsigned long long size) ...@@ -242,7 +242,6 @@ static int DoResizeExt(const char* device, const unsigned long long size)
char **argv = (char **)cmd; char **argv = (char **)cmd;
ret = ExecCommand(argc, argv); ret = ExecCommand(argc, argv);
} }
BEGET_LOGI("resize2fs is ending.");
return ret; return ret;
} }
...@@ -259,7 +258,6 @@ static int DoFsckExt(const char* device) ...@@ -259,7 +258,6 @@ static int DoFsckExt(const char* device)
}; };
int argc = ARRAY_LENGTH(cmd); int argc = ARRAY_LENGTH(cmd);
char **argv = (char **)cmd; char **argv = (char **)cmd;
BEGET_LOGI("e2fsck is ending.");
return ExecCommand(argc, argv); return ExecCommand(argc, argv);
} }
...@@ -287,15 +285,8 @@ static int Mount(const char *source, const char *target, const char *fsType, ...@@ -287,15 +285,8 @@ static int Mount(const char *source, const char *target, const char *fsType,
} }
} }
errno = 0; errno = 0;
while ((rc = mount(source, target, fsType, flags, data)) != 0) { if ((rc = mount(source, target, fsType, flags, data)) != 0) {
if (errno == EAGAIN) { BEGET_WARNING_CHECK(errno != EBUSY, rc = 0, "Mount %s to %s busy, ignore", source, target);
BEGET_LOGE("Mount %s to %s failed. try again", source, target);
continue;
}
if (errno == EBUSY) {
rc = 0;
}
break;
} }
return rc; return rc;
} }
......
...@@ -34,7 +34,7 @@ public: ...@@ -34,7 +34,7 @@ public:
HWTEST_F(MountUnitTest, TestMountRequriedPartitions, TestSize.Level0) HWTEST_F(MountUnitTest, TestMountRequriedPartitions, TestSize.Level0)
{ {
const char *fstabFiles = "/etc/fstab.required"; const char *fstabFiles = "/data/init_ut/etc/fstab.required";
Fstab *fstab = NULL; Fstab *fstab = NULL;
fstab = ReadFstabFromFile(fstabFiles, false); fstab = ReadFstabFromFile(fstabFiles, false);
if (fstab != NULL) { if (fstab != NULL) {
......
...@@ -218,7 +218,7 @@ HWTEST_F(InnerkitsUnitTest, DoFormat_unittest, TestSize.Level1) ...@@ -218,7 +218,7 @@ HWTEST_F(InnerkitsUnitTest, DoFormat_unittest, TestSize.Level1)
*/ */
HWTEST_F(InnerkitsUnitTest, MountAllWithFstabFile_unittest, TestSize.Level1) HWTEST_F(InnerkitsUnitTest, MountAllWithFstabFile_unittest, TestSize.Level1)
{ {
EXPECT_NE(MountAllWithFstabFile("/etc/fstab.required", 0), 1); EXPECT_NE(MountAllWithFstabFile("/data/init_ut/etc/fstab.required", 0), 1);
} }
HWTEST_F(InnerkitsUnitTest, others_unittest, TestSize.Level1) HWTEST_F(InnerkitsUnitTest, others_unittest, TestSize.Level1)
......
...@@ -207,14 +207,14 @@ static void PrepareInnerKitsCfg() ...@@ -207,14 +207,14 @@ static void PrepareInnerKitsCfg()
"aa aa aa aa\n"; "aa aa aa aa\n";
const char *fstabRequired = "# fstab file.\n" const char *fstabRequired = "# fstab file.\n"
"#<src> <mnt_point> <type> <mnt_flags and options> <fs_mgr_flags>\n" "#<src> <mnt_point> <type> <mnt_flags and options> <fs_mgr_flags>\n"
"/dev/block/platform/fe310000.sdhci/by-name/testsystem /usr ext4 ro,barrier=1 wait,required\n" "/dev/block/platform/fe310000.sdhci/by-name/testsystem /usr ext4 ro,barrier=1 wait,required,nofail\n"
"/dev/block/platform/fe310000.sdhci/by-name/testvendor /vendor ext4 ro,barrier=1 wait,required\n" "/dev/block/platform/fe310000.sdhci/by-name/testvendor /vendor ext4 ro,barrier=1 wait,required\n"
"/dev/block/platform/fe310000.sdhci/by-name/testuserdata1 /data f2fs noatime,nosuid,nodev wait,check,quota\n" "/dev/block/platform/fe310000.sdhci/by-name/testuserdata1 /data f2fs noatime,nosuid,nodev wait,check,quota\n"
"/dev/block/platform/fe310000.sdhci/by-name/testuserdata2 /data ext4 noatime,fscrypt=xxx wait,check,quota\n" "/dev/block/platform/fe310000.sdhci/by-name/testuserdata2 /data ext4 noatime,fscrypt=xxx wait,check,quota\n"
"/dev/block/platform/fe310000.sdhci/by-name/testmisc /misc none none wait,required"; "/dev/block/platform/fe310000.sdhci/by-name/testmisc /misc none none wait,required";
mkdir("/data/init_ut/mount_unitest/", S_IRWXU | S_IRWXG | S_IRWXO); mkdir("/data/init_ut/mount_unitest/", S_IRWXU | S_IRWXG | S_IRWXO);
CreateTestFile("/data/init_ut/mount_unitest/ReadFstabFromFile1.fstable", innerKitsCfg); CreateTestFile("/data/init_ut/mount_unitest/ReadFstabFromFile1.fstable", innerKitsCfg);
CreateTestFile("/etc/fstab.required", fstabRequired); CreateTestFile("/data/init_ut/etc/fstab.required", fstabRequired);
} }
static void PrepareGroupTestCfg() static void PrepareGroupTestCfg()
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册