• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/core


Commit MetaInfo

修订版89003f4358cee5c2ea641b1990e655d450a371de (tree)
时间2016-09-15 04:03:14
作者Jaap Jan Meijer <jjmeijer88@gmai...>
CommiterJaap Jan Meijer

Log Message

init: revert using fsck -a for boot time optimisation

This is causing the data partition to get dirty / damaged very regularly
and make the data partition to be mounted ro.

This is a combination of 2 commits:

Revert "init: Allow devices to opt-out of fsck'ing on power off"

This reverts commit 516d6913dc5acd695581b3999fab0b5192353022.

Revert "Use fsck.f2fs -a instead of -f for faster boot"

This reverts commit 784c22c8388e50db243ac4ca3871747cd3eefadc.

Conflicts:
init/builtins.cpp

更改概述

差异

--- a/fs_mgr/fs_mgr.c
+++ b/fs_mgr/fs_mgr.c
@@ -163,10 +163,10 @@ static void check_fs(char *blk_device, char *fs_type, char *target)
163163 } else if (!strcmp(fs_type, "f2fs")) {
164164 char *f2fs_fsck_argv[] = {
165165 F2FS_FSCK_BIN,
166- "-a",
166+ "-f",
167167 blk_device
168168 };
169- INFO("Running %s -a %s\n", F2FS_FSCK_BIN, blk_device);
169+ INFO("Running %s -f %s\n", F2FS_FSCK_BIN, blk_device);
170170
171171 ret = android_fork_execvp_ext(ARRAY_SIZE(f2fs_fsck_argv), f2fs_fsck_argv,
172172 &status, true, LOG_KLOG | LOG_FILE,
--- a/include/cutils/android_reboot.h
+++ b/include/cutils/android_reboot.h
@@ -17,8 +17,6 @@
1717 #ifndef __CUTILS_ANDROID_REBOOT_H__
1818 #define __CUTILS_ANDROID_REBOOT_H__
1919
20-#include <mntent.h>
21-
2220 __BEGIN_DECLS
2321
2422 /* Commands */
@@ -30,9 +28,6 @@ __BEGIN_DECLS
3028 #define ANDROID_RB_PROPERTY "sys.powerctl"
3129
3230 int android_reboot(int cmd, int flags, const char *arg);
33-int android_reboot_with_callback(
34- int cmd, int flags, const char *arg,
35- void (*cb_on_remount)(const struct mntent*));
3631
3732 __END_DECLS
3833
--- a/init/Android.mk
+++ b/init/Android.mk
@@ -69,10 +69,6 @@ ifneq ($(TARGET_IGNORE_RO_BOOT_REVISION),)
6969 LOCAL_CFLAGS += -DIGNORE_RO_BOOT_REVISION
7070 endif
7171
72-ifneq ($(TARGET_INIT_UMOUNT_AND_FSCK_IS_UNSAFE),)
73-LOCAL_CFLAGS += -DUMOUNT_AND_FSCK_IS_UNSAFE
74-endif
75-
7672 LOCAL_MODULE:= init
7773 LOCAL_C_INCLUDES += \
7874 external/zlib \
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -16,9 +16,7 @@
1616
1717 #include <errno.h>
1818 #include <fcntl.h>
19-#include <mntent.h>
2019 #include <net/if.h>
21-#include <signal.h>
2220 #include <stdio.h>
2321 #include <stdlib.h>
2422 #include <string.h>
@@ -42,7 +40,6 @@
4240 #include <base/stringprintf.h>
4341 #include <cutils/partition_utils.h>
4442 #include <cutils/android_reboot.h>
45-#include <logwrap/logwrap.h>
4643 #include <cutils/probe_module.h>
4744 #include <private/android_filesystem_config.h>
4845
@@ -55,8 +52,6 @@
5552 #include "log.h"
5653
5754 #define chmod DO_NOT_USE_CHMOD_USE_FCHMODAT_SYMLINK_NOFOLLOW
58-#define UNMOUNT_CHECK_MS 5000
59-#define UNMOUNT_CHECK_TIMES 10
6055
6156 int add_environment(const char *name, const char *value);
6257
@@ -117,69 +112,6 @@ static void service_start_if_not_disabled(struct service *svc)
117112 }
118113 }
119114
120-static void unmount_and_fsck(const struct mntent *entry)
121-{
122-#ifndef UMOUNT_AND_FSCK_IS_UNSAFE
123- if (strcmp(entry->mnt_type, "f2fs") && strcmp(entry->mnt_type, "ext4"))
124- return;
125-
126- /* First, lazily unmount the directory. This unmount request finishes when
127- * all processes that open a file or directory in |entry->mnt_dir| exit.
128- */
129- TEMP_FAILURE_RETRY(umount2(entry->mnt_dir, MNT_DETACH));
130-
131- /* Next, kill all processes except init, kthreadd, and kthreadd's
132- * children to finish the lazy unmount. Killing all processes here is okay
133- * because this callback function is only called right before reboot().
134- * It might be cleaner to selectively kill processes that actually use
135- * |entry->mnt_dir| rather than killing all, probably by reusing a function
136- * like killProcessesWithOpenFiles() in vold/, but the selinux policy does
137- * not allow init to scan /proc/<pid> files which the utility function
138- * heavily relies on. The policy does not allow the process to execute
139- * killall/pkill binaries either. Note that some processes might
140- * automatically restart after kill(), but that is not really a problem
141- * because |entry->mnt_dir| is no longer visible to such new processes.
142- */
143- service_for_each(service_stop);
144- TEMP_FAILURE_RETRY(kill(-1, SIGKILL));
145-
146- int count = 0;
147- while (count++ < UNMOUNT_CHECK_TIMES) {
148- int fd = TEMP_FAILURE_RETRY(open(entry->mnt_fsname, O_RDONLY | O_EXCL));
149- if (fd >= 0) {
150- /* |entry->mnt_dir| has sucessfully been unmounted. */
151- close(fd);
152- break;
153- } else if (errno == EBUSY) {
154- /* Some processes using |entry->mnt_dir| are still alive. Wait for a
155- * while then retry.
156- */
157- TEMP_FAILURE_RETRY(
158- usleep(UNMOUNT_CHECK_MS * 1000 / UNMOUNT_CHECK_TIMES));
159- continue;
160- } else {
161- /* Cannot open the device. Give up. */
162- return;
163- }
164- }
165-
166- int st;
167- if (!strcmp(entry->mnt_type, "f2fs")) {
168- const char *f2fs_argv[] = {
169- "/system/bin/fsck.f2fs", "-f", entry->mnt_fsname,
170- };
171- android_fork_execvp_ext(ARRAY_SIZE(f2fs_argv), (char **)f2fs_argv,
172- &st, true, LOG_KLOG, true, NULL);
173- } else if (!strcmp(entry->mnt_type, "ext4")) {
174- const char *ext4_argv[] = {
175- "/system/bin/e2fsck", "-f", "-y", entry->mnt_fsname,
176- };
177- android_fork_execvp_ext(ARRAY_SIZE(ext4_argv), (char **)ext4_argv,
178- &st, true, LOG_KLOG, true, NULL);
179- }
180-#endif
181-}
182-
183115 int do_class_start(int nargs, char **args)
184116 {
185117 char prop[PROP_NAME_MAX];
@@ -705,7 +637,6 @@ int do_powerctl(int nargs, char **args)
705637 int len = 0;
706638 int cmd = 0;
707639 const char *reboot_target;
708- void (*callback_on_ro_remount)(const struct mntent*) = NULL;
709640
710641 res = expand_props(command, args[1], sizeof(command));
711642 if (res) {
@@ -719,7 +650,6 @@ int do_powerctl(int nargs, char **args)
719650 }
720651 cmd = ANDROID_RB_POWEROFF;
721652 len = 8;
722- callback_on_ro_remount = unmount_and_fsck;
723653 } else if (strncmp(command, "reboot", 6) == 0) {
724654 cmd = ANDROID_RB_RESTART2;
725655 len = 6;
@@ -744,8 +674,7 @@ int do_powerctl(int nargs, char **args)
744674 return -EINVAL;
745675 }
746676
747- return android_reboot_with_callback(cmd, 0, reboot_target,
748- callback_on_ro_remount);
677+ return android_reboot(cmd, 0, reboot_target);
749678 }
750679
751680 int do_trigger(int nargs, char **args)
--- a/libcutils/android_reboot.c
+++ b/libcutils/android_reboot.c
@@ -14,108 +14,43 @@
1414 * limitations under the License.
1515 */
1616
17-#include <errno.h>
17+#include <unistd.h>
18+#include <sys/reboot.h>
19+#include <sys/syscall.h>
20+#include <sys/types.h>
21+#include <sys/stat.h>
1822 #include <fcntl.h>
1923 #include <mntent.h>
20-#include <stdbool.h>
2124 #include <stdio.h>
22-#include <stdlib.h>
2325 #include <string.h>
24-#include <sys/cdefs.h>
25-#include <sys/mount.h>
26-#include <sys/reboot.h>
27-#include <sys/stat.h>
28-#include <sys/syscall.h>
29-#include <sys/types.h>
30-#include <unistd.h>
3126
3227 #include <cutils/android_reboot.h>
33-#include <cutils/klog.h>
34-#include <cutils/list.h>
3528
36-#define TAG "android_reboot"
37-#define READONLY_CHECK_MS 5000
38-#define READONLY_CHECK_TIMES 50
29+#define UNUSED __attribute__((unused))
3930
40-typedef struct {
41- struct listnode list;
42- struct mntent entry;
43-} mntent_list;
44-
45-static bool has_mount_option(const char* opts, const char* opt_to_find)
46-{
47- bool ret = false;
48- char* copy = NULL;
49- char* opt;
50- char* rem;
51-
52- while ((opt = strtok_r(copy ? NULL : (copy = strdup(opts)), ",", &rem))) {
53- if (!strcmp(opt, opt_to_find)) {
54- ret = true;
55- break;
56- }
57- }
58-
59- free(copy);
60- return ret;
61-}
62-
63-static bool is_block_device(const char* fsname)
64-{
65- return !strncmp(fsname, "/dev/block", 10);
66-}
67-
68-/* Find all read+write block devices in /proc/mounts and add them to
69- * |rw_entries|.
31+/* Check to see if /proc/mounts contains any writeable filesystems
32+ * backed by a block device.
33+ * Return true if none found, else return false.
7034 */
71-static void find_rw(struct listnode* rw_entries)
35+static int remount_ro_done(void)
7236 {
7337 FILE* fp;
7438 struct mntent* mentry;
39+ int found_rw_fs = 0;
7540
7641 if ((fp = setmntent("/proc/mounts", "r")) == NULL) {
77- KLOG_WARNING(TAG, "Failed to open /proc/mounts.\n");
78- return;
42+ /* If we can't read /proc/mounts, just give up. */
43+ return 1;
7944 }
8045 while ((mentry = getmntent(fp)) != NULL) {
81- if (is_block_device(mentry->mnt_fsname) &&
82- has_mount_option(mentry->mnt_opts, "rw")) {
83- mntent_list* item = (mntent_list*)calloc(1, sizeof(mntent_list));
84- item->entry = *mentry;
85- item->entry.mnt_fsname = strdup(mentry->mnt_fsname);
86- item->entry.mnt_dir = strdup(mentry->mnt_dir);
87- item->entry.mnt_type = strdup(mentry->mnt_type);
88- item->entry.mnt_opts = strdup(mentry->mnt_opts);
89- list_add_tail(rw_entries, &item->list);
46+ if (!strncmp(mentry->mnt_fsname, "/dev/block", 10) && strstr(mentry->mnt_opts, "rw,")) {
47+ found_rw_fs = 1;
48+ break;
9049 }
9150 }
9251 endmntent(fp);
93-}
94-
95-static void free_entries(struct listnode* entries)
96-{
97- struct listnode* node;
98- struct listnode* n;
99- list_for_each_safe(node, n, entries) {
100- mntent_list* item = node_to_item(node, mntent_list, list);
101- free(item->entry.mnt_fsname);
102- free(item->entry.mnt_dir);
103- free(item->entry.mnt_type);
104- free(item->entry.mnt_opts);
105- free(item);
106- }
107-}
10852
109-static mntent_list* find_item(struct listnode* rw_entries, const char* fsname_to_find)
110-{
111- struct listnode* node;
112- list_for_each(node, rw_entries) {
113- mntent_list* item = node_to_item(node, mntent_list, list);
114- if (!strcmp(item->entry.mnt_fsname, fsname_to_find)) {
115- return item;
116- }
117- }
118- return NULL;
53+ return !found_rw_fs;
11954 }
12055
12156 /* Remounting filesystems read-only is difficult when there are files
@@ -129,92 +64,38 @@ static mntent_list* find_item(struct listnode* rw_entries, const char* fsname_to
12964 * repeatedly until there are no more writable filesystems mounted on
13065 * block devices.
13166 */
132-static void remount_ro(void (*cb_on_remount)(const struct mntent*))
67+static void remount_ro(void)
13368 {
134- int fd, cnt;
135- FILE* fp;
136- struct mntent* mentry;
137- struct listnode* node;
138-
139- list_declare(rw_entries);
140- list_declare(ro_entries);
141-
142- sync();
143- find_rw(&rw_entries);
69+ int fd, cnt = 0;
14470
14571 /* Trigger the remount of the filesystems as read-only,
14672 * which also marks them clean.
14773 */
148- fd = TEMP_FAILURE_RETRY(open("/proc/sysrq-trigger", O_WRONLY));
74+ fd = open("/proc/sysrq-trigger", O_WRONLY);
14975 if (fd < 0) {
150- KLOG_WARNING(TAG, "Failed to open sysrq-trigger.\n");
151- /* TODO: Try to remount each rw parition manually in readonly mode.
152- * This may succeed if no process is using the partition.
153- */
154- goto out;
155- }
156- if (TEMP_FAILURE_RETRY(write(fd, "u", 1)) != 1) {
157- close(fd);
158- KLOG_WARNING(TAG, "Failed to write to sysrq-trigger.\n");
159- /* TODO: The same. Manually remount the paritions. */
160- goto out;
76+ return;
16177 }
78+ write(fd, "u", 1);
16279 close(fd);
16380
81+
16482 /* Now poll /proc/mounts till it's done */
165- cnt = 0;
166- while (cnt < READONLY_CHECK_TIMES) {
167- if ((fp = setmntent("/proc/mounts", "r")) == NULL) {
168- /* If we can't read /proc/mounts, just give up. */
169- KLOG_WARNING(TAG, "Failed to open /proc/mounts.\n");
170- goto out;
171- }
172- while ((mentry = getmntent(fp)) != NULL) {
173- if (!is_block_device(mentry->mnt_fsname) ||
174- !has_mount_option(mentry->mnt_opts, "ro")) {
175- continue;
176- }
177- mntent_list* item = find_item(&rw_entries, mentry->mnt_fsname);
178- if (item) {
179- /* |item| has now been ro remounted. */
180- list_remove(&item->list);
181- list_add_tail(&ro_entries, &item->list);
182- }
183- }
184- endmntent(fp);
185- if (list_empty(&rw_entries)) {
186- /* All rw block devices are now readonly. */
187- break;
188- }
189- TEMP_FAILURE_RETRY(
190- usleep(READONLY_CHECK_MS * 1000 / READONLY_CHECK_TIMES));
83+ while (!remount_ro_done() && (cnt < 50)) {
84+ usleep(100000);
19185 cnt++;
19286 }
19387
194- list_for_each(node, &rw_entries) {
195- mntent_list* item = node_to_item(node, mntent_list, list);
196- KLOG_WARNING(TAG, "Failed to remount %s in readonly mode.\n",
197- item->entry.mnt_fsname);
198- }
199-
200- if (cb_on_remount) {
201- list_for_each(node, &ro_entries) {
202- mntent_list* item = node_to_item(node, mntent_list, list);
203- cb_on_remount(&item->entry);
204- }
205- }
206-
207-out:
208- free_entries(&rw_entries);
209- free_entries(&ro_entries);
88+ return;
21089 }
21190
212-int android_reboot_with_callback(
213- int cmd, int flags __unused, const char *arg,
214- void (*cb_on_remount)(const struct mntent*))
91+
92+int android_reboot(int cmd, int flags UNUSED, const char *arg)
21593 {
21694 int ret;
217- remount_ro(cb_on_remount);
95+
96+ sync();
97+ remount_ro();
98+
21899 switch (cmd) {
219100 case ANDROID_RB_RESTART:
220101 ret = reboot(RB_AUTOBOOT);
@@ -236,7 +117,3 @@ int android_reboot_with_callback(
236117 return ret;
237118 }
238119
239-int android_reboot(int cmd, int flags, const char *arg)
240-{
241- return android_reboot_with_callback(cmd, flags, arg, NULL);
242-}
--- a/logwrapper/logwrap.c
+++ b/logwrapper/logwrap.c
@@ -355,8 +355,7 @@ static int parent(const char *tag, int parent_read, pid_t pid,
355355 }
356356
357357 if (poll_fds[0].revents & POLLIN) {
358- sz = TEMP_FAILURE_RETRY(
359- read(parent_read, &buffer[b], sizeof(buffer) - 1 - b));
358+ sz = read(parent_read, &buffer[b], sizeof(buffer) - 1 - b);
360359
361360 sz += b;
362361 // Log one line at a time
@@ -491,7 +490,7 @@ int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int
491490 }
492491
493492 /* Use ptty instead of socketpair so that STDOUT is not buffered */
494- parent_ptty = TEMP_FAILURE_RETRY(open("/dev/ptmx", O_RDWR));
493+ parent_ptty = open("/dev/ptmx", O_RDWR);
495494 if (parent_ptty < 0) {
496495 ERROR("Cannot create parent ptty\n");
497496 rc = -1;
@@ -506,7 +505,7 @@ int android_fork_execvp_ext(int argc, char* argv[], int *status, bool ignore_int
506505 goto err_ptty;
507506 }
508507
509- child_ptty = TEMP_FAILURE_RETRY(open(child_devname, O_RDWR));
508+ child_ptty = open(child_devname, O_RDWR);
510509 if (child_ptty < 0) {
511510 ERROR("Cannot open child_ptty\n");
512511 rc = -1;