• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

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

system/corennnnn


Commit MetaInfo

修訂31627ba2253cb324d4223e3b1cbe5a7e6acb881a (tree)
時間2016-11-09 00:56:26
作者Chih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

ueventd: defer modules loading if explicitly listed

The patch extends the syntax of /etc/modules.blacklist.
The modules marked as deferred in this file will be loaded
after all other modules are loaded at coldboot stage.

Change Summary

差異

--- a/init/devices.cpp
+++ b/init/devices.cpp
@@ -111,6 +111,7 @@ struct module_alias_node {
111111
112112 struct module_blacklist_node {
113113 char *name;
114+ bool deferred;
114115 struct listnode list;
115116 };
116117
@@ -774,7 +775,7 @@ static void handle_generic_device_event(struct uevent *uevent)
774775 uevent->major, uevent->minor, links);
775776 }
776777
777-static int is_module_blacklisted(const char *name)
778+static int is_module_blacklisted_or_deferred(const char *name, bool need_deferred)
778779 {
779780 struct listnode *blklst_node;
780781 struct module_blacklist_node *blacklist;
@@ -789,7 +790,7 @@ static int is_module_blacklisted(const char *name)
789790 list);
790791 if (!strcmp(name, blacklist->name)) {
791792 INFO("modules %s is blacklisted\n", name);
792- ret = 1;
793+ ret = blacklist->deferred ? (need_deferred ? 2 : 0) : 1;
793794 goto out;
794795 }
795796 }
@@ -798,7 +799,7 @@ out:
798799 return ret;
799800 }
800801
801-static int load_module_by_device_modalias(const char *id)
802+static int load_module_by_device_modalias(const char *id, bool need_deferred)
802803 {
803804 struct listnode *alias_node;
804805 struct module_alias_node *alias;
@@ -811,8 +812,9 @@ static int load_module_by_device_modalias(const char *id)
811812 if (fnmatch(alias->pattern, id, 0) == 0) {
812813 INFO("trying to load module %s due to uevents\n", alias->name);
813814
814- if (!is_module_blacklisted(alias->name)) {
815- if (insmod_by_dep(alias->name, "", NULL, 0, NULL)) {
815+ ret = is_module_blacklisted_or_deferred(alias->name, need_deferred);
816+ if (ret == 0) {
817+ if ((ret = insmod_by_dep(alias->name, "", NULL, 0, NULL))) {
816818 /* cannot load module. try another one since
817819 * there may be another match.
818820 */
@@ -821,8 +823,9 @@ static int load_module_by_device_modalias(const char *id)
821823 } else {
822824 /* loading was successful */
823825 INFO("loaded module %s due to uevents\n", alias->name);
824- ret = 0;
825826 }
827+ } else {
828+ NOTICE("blacklisted module %s: %d\n", alias->name, ret);
826829 }
827830 }
828831 }
@@ -846,7 +849,7 @@ static void handle_deferred_module_loading()
846849
847850 if (alias && alias->pattern) {
848851 INFO("deferred loading of module for %s\n", alias->pattern);
849- load_module_by_device_modalias(alias->pattern);
852+ load_module_by_device_modalias(alias->pattern, false);
850853 free(alias->pattern);
851854 list_remove(node);
852855 free(alias);
@@ -863,7 +866,7 @@ static int module_probe(int argc, char **argv)
863866 }
864867
865868 // is it a modalias?
866- int ret = load_module_by_device_modalias(argv[1]);
869+ int ret = load_module_by_device_modalias(argv[1], false);
867870 if (ret) {
868871 // treat it as a module name
869872 std::string options;
@@ -905,6 +908,11 @@ int modprobe_main(int argc, char **argv)
905908 return module_probe(argc, argv);
906909 }
907910
911+static int is_booting(void)
912+{
913+ return access("/dev/.booting", F_OK) == 0;
914+}
915+
908916 static void handle_module_loading(const char *modalias)
909917 {
910918 struct module_alias_node *node;
@@ -915,13 +923,13 @@ static void handle_module_loading(const char *modalias)
915923 if (list_empty(&modules_aliases_map)) {
916924 if (read_modules_aliases() == 0) {
917925 read_modules_blacklist();
918- handle_deferred_module_loading();
919926 }
920927 }
921928
922929 if (!modalias) return;
923930
924- if (list_empty(&modules_aliases_map)) {
931+ if (list_empty(&modules_aliases_map) ||
932+ load_module_by_device_modalias(modalias, is_booting()) == 2) {
925933 /* if module alias mapping is empty,
926934 * queue it for loading later
927935 */
@@ -938,10 +946,7 @@ static void handle_module_loading(const char *modalias)
938946 } else {
939947 ERROR("failed to allocate memory to store device id for deferred module loading.\n");
940948 }
941- } else {
942- load_module_by_device_modalias(modalias);
943949 }
944-
945950 }
946951
947952 static void handle_device_event(struct uevent *uevent)
@@ -1000,11 +1005,6 @@ static int load_firmware(int fw_fd, int loading_fd, int data_fd)
10001005 return ret;
10011006 }
10021007
1003-static int is_booting(void)
1004-{
1005- return access("/dev/.booting", F_OK) == 0;
1006-}
1007-
10081008 static void process_firmware_event(struct uevent *uevent)
10091009 {
10101010 char *root, *loading, *data;
@@ -1122,6 +1122,7 @@ static void parse_line_module_alias(struct parse_state *state, int nargs, char *
11221122 static void parse_line_module_blacklist(struct parse_state *state, int nargs, char **args)
11231123 {
11241124 struct module_blacklist_node *node;
1125+ bool deferred;
11251126
11261127 if (!args ||
11271128 (nargs != 2) ||
@@ -1130,8 +1131,13 @@ static void parse_line_module_blacklist(struct parse_state *state, int nargs, ch
11301131 return;
11311132 }
11321133
1133- /* this line does not being with "blacklist" */
1134- if (strncmp(args[0], "blacklist", 9)) return;
1134+ /* this line does not being with "blacklist" or "deferred" */
1135+ if (!strncmp(args[0], "blacklist", 9))
1136+ deferred = false;
1137+ else if (!strncmp(args[0], "deferred", 8))
1138+ deferred = true;
1139+ else
1140+ return;
11351141
11361142 node = (module_blacklist_node *) calloc(1, sizeof(*node));
11371143 if (!node) return;
@@ -1141,6 +1147,7 @@ static void parse_line_module_blacklist(struct parse_state *state, int nargs, ch
11411147 free(node);
11421148 return;
11431149 }
1150+ node->deferred = deferred;
11441151
11451152 list_add_tail(&modules_blacklist, &node->list);
11461153 }
@@ -1335,6 +1342,7 @@ void device_init(bool child)
13351342 coldboot("/sys/class");
13361343 coldboot("/sys/block");
13371344 coldboot("/sys/devices");
1345+ handle_deferred_module_loading();
13381346 close(open(COLDBOOT_DONE, O_WRONLY|O_CREAT|O_CLOEXEC, 0000));
13391347 NOTICE("Coldboot took %.2fs.\n", t.duration());
13401348 }