Krishna iResearch Intelligent Cloud Platform - VIRtual Generic Os - VIRGO - Linux kernel extensions for cloud
 All Classes
main.c
1 /*
2  * linux/init/main.c
3  *
4  * Copyright (C) 1991, 1992 Linus Torvalds
5  *
6  * GK 2/5/95 - Changed to support mounting root fs via NFS
7  * Added initrd & change_root: Werner Almesberger & Hans Lermen, Feb '96
8  * Moan early if gcc is old, avoiding bogus kernels - Paul Gortmaker, May '96
9  * Simplified starting of init: Michael A. Griffith <grif@acm.org>
10  */
11 
12 #include <linux/types.h>
13 #include <linux/module.h>
14 #include <linux/proc_fs.h>
15 #include <linux/kernel.h>
16 #include <linux/syscalls.h>
17 #include <linux/stackprotector.h>
18 #include <linux/string.h>
19 #include <linux/ctype.h>
20 #include <linux/delay.h>
21 #include <linux/ioport.h>
22 #include <linux/init.h>
23 #include <linux/initrd.h>
24 #include <linux/bootmem.h>
25 #include <linux/acpi.h>
26 #include <linux/tty.h>
27 #include <linux/percpu.h>
28 #include <linux/kmod.h>
29 #include <linux/vmalloc.h>
30 #include <linux/kernel_stat.h>
31 #include <linux/start_kernel.h>
32 #include <linux/security.h>
33 #include <linux/smp.h>
34 #include <linux/profile.h>
35 #include <linux/rcupdate.h>
36 #include <linux/moduleparam.h>
37 #include <linux/kallsyms.h>
38 #include <linux/writeback.h>
39 #include <linux/cpu.h>
40 #include <linux/cpuset.h>
41 #include <linux/cgroup.h>
42 #include <linux/efi.h>
43 #include <linux/tick.h>
44 #include <linux/interrupt.h>
45 #include <linux/taskstats_kern.h>
46 #include <linux/delayacct.h>
47 #include <linux/unistd.h>
48 #include <linux/rmap.h>
49 #include <linux/mempolicy.h>
50 #include <linux/key.h>
51 #include <linux/buffer_head.h>
52 #include <linux/page_cgroup.h>
53 #include <linux/debug_locks.h>
54 #include <linux/debugobjects.h>
55 #include <linux/lockdep.h>
56 #include <linux/kmemleak.h>
57 #include <linux/pid_namespace.h>
58 #include <linux/device.h>
59 #include <linux/kthread.h>
60 #include <linux/sched.h>
61 #include <linux/signal.h>
62 #include <linux/idr.h>
63 #include <linux/kgdb.h>
64 #include <linux/ftrace.h>
65 #include <linux/async.h>
66 #include <linux/kmemcheck.h>
67 #include <linux/sfi.h>
68 #include <linux/shmem_fs.h>
69 #include <linux/slab.h>
70 #include <linux/perf_event.h>
71 #include <linux/file.h>
72 #include <linux/ptrace.h>
73 
74 
75 /*
76 #include <linux/virgocloudexecsvc.h>
77 */
78 
79 #include <asm/io.h>
80 #include <asm/bugs.h>
81 #include <asm/setup.h>
82 #include <asm/sections.h>
83 #include <asm/cacheflush.h>
84 #include <linux/virgo_config.h>
85 
86 
87 int num_cloud_nodes=2;
88 EXPORT_SYMBOL(num_cloud_nodes);
89 
90 char* node_ip_addrs_in_cloud[3000]={"127.0.0.1","127.0.0.1",NULL,};
91 EXPORT_SYMBOL(node_ip_addrs_in_cloud);
92 
93 
94 
95 #ifdef CONFIG_X86_LOCAL_APIC
96 #include <asm/smp.h>
97 #endif
98 
99 void do_virgo_cloud_init(void);
100 
101 void read_virgo_clone_config(void);
102 
103 static int kernel_init(void *);
104 
105 extern void init_IRQ(void);
106 extern void fork_init(unsigned long);
107 extern void mca_init(void);
108 extern void sbus_init(void);
109 extern void radix_tree_init(void);
110 #ifndef CONFIG_DEBUG_RODATA
111 static inline void mark_rodata_ro(void) { }
112 #endif
113 
114 #ifdef CONFIG_TC
115 extern void tc_init(void);
116 #endif
117 
118 /*
119  * Debug helper: via this flag we know that we are in 'early bootup code'
120  * where only the boot processor is running with IRQ disabled. This means
121  * two things - IRQ must not be enabled before the flag is cleared and some
122  * operations which are not allowed with IRQ disabled are allowed while the
123  * flag is set.
124  */
125 bool early_boot_irqs_disabled __read_mostly;
126 
127 enum system_states system_state __read_mostly;
128 EXPORT_SYMBOL(system_state);
129 
130 /*
131  * Boot command-line arguments
132  */
133 #define MAX_INIT_ARGS CONFIG_INIT_ENV_ARG_LIMIT
134 #define MAX_INIT_ENVS CONFIG_INIT_ENV_ARG_LIMIT
135 
136 extern void time_init(void);
137 /* Default late time init is NULL. archs can override this later. */
138 void (*__initdata late_time_init)(void);
139 extern void softirq_init(void);
140 
141 /* Untouched command line saved by arch-specific code. */
142 char __initdata boot_command_line[COMMAND_LINE_SIZE];
143 /* Untouched saved command line (eg. for /proc) */
144 char *saved_command_line;
145 /* Command line for parameter parsing */
146 static char *static_command_line;
147 
148 static char *execute_command;
149 static char *ramdisk_execute_command;
150 
151 /*
152  * If set, this is an indication to the drivers that reset the underlying
153  * device before going ahead with the initialization otherwise driver might
154  * rely on the BIOS and skip the reset operation.
155  *
156  * This is useful if kernel is booting in an unreliable environment.
157  * For ex. kdump situaiton where previous kernel has crashed, BIOS has been
158  * skipped and devices will be in unknown state.
159  */
160 unsigned int reset_devices;
161 EXPORT_SYMBOL(reset_devices);
162 
163 static int __init set_reset_devices(char *str)
164 {
165  reset_devices = 1;
166  return 1;
167 }
168 
169 __setup("reset_devices", set_reset_devices);
170 
171 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
172 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
173 static const char *panic_later, *panic_param;
174 
175 extern const struct obs_kernel_param __setup_start[], __setup_end[];
176 
177 static int __init obsolete_checksetup(char *line)
178 {
179  const struct obs_kernel_param *p;
180  int had_early_param = 0;
181 
182  p = __setup_start;
183  do {
184  int n = strlen(p->str);
185  if (parameqn(line, p->str, n)) {
186  if (p->early) {
187  /* Already done in parse_early_param?
188  * (Needs exact match on param part).
189  * Keep iterating, as we can have early
190  * params and __setups of same names 8( */
191  if (line[n] == '\0' || line[n] == '=')
192  had_early_param = 1;
193  } else if (!p->setup_func) {
194  printk(KERN_WARNING "Parameter %s is obsolete,"
195  " ignored\n", p->str);
196  return 1;
197  } else if (p->setup_func(line + n))
198  return 1;
199  }
200  p++;
201  } while (p < __setup_end);
202 
203  return had_early_param;
204 }
205 
206 /*
207  * This should be approx 2 Bo*oMips to start (note initial shift), and will
208  * still work even if initially too large, it will just take slightly longer
209  */
210 unsigned long loops_per_jiffy = (1<<12);
211 
212 EXPORT_SYMBOL(loops_per_jiffy);
213 
214 static int __init debug_kernel(char *str)
215 {
216  console_loglevel = 10;
217  return 0;
218 }
219 
220 static int __init quiet_kernel(char *str)
221 {
222  console_loglevel = 4;
223  return 0;
224 }
225 
226 early_param("debug", debug_kernel);
227 early_param("quiet", quiet_kernel);
228 
229 static int __init loglevel(char *str)
230 {
231  int newlevel;
232 
233  /*
234  * Only update loglevel value when a correct setting was passed,
235  * to prevent blind crashes (when loglevel being set to 0) that
236  * are quite hard to debug
237  */
238  if (get_option(&str, &newlevel)) {
239  console_loglevel = newlevel;
240  return 0;
241  }
242 
243  return -EINVAL;
244 }
245 
246 early_param("loglevel", loglevel);
247 
248 /* Change NUL term back to "=", to make "param" the whole string. */
249 static int __init repair_env_string(char *param, char *val, const char *unused)
250 {
251  if (val) {
252  /* param=val or param="val"? */
253  if (val == param+strlen(param)+1)
254  val[-1] = '=';
255  else if (val == param+strlen(param)+2) {
256  val[-2] = '=';
257  memmove(val-1, val, strlen(val)+1);
258  val--;
259  } else
260  BUG();
261  }
262  return 0;
263 }
264 
265 /*
266  * Unknown boot options get handed to init, unless they look like
267  * unused parameters (modprobe will find them in /proc/cmdline).
268  */
269 static int __init unknown_bootoption(char *param, char *val, const char *unused)
270 {
271  repair_env_string(param, val, unused);
272 
273  /* Handle obsolete-style parameters */
274  if (obsolete_checksetup(param))
275  return 0;
276 
277  /* Unused module parameter. */
278  if (strchr(param, '.') && (!val || strchr(param, '.') < val))
279  return 0;
280 
281  if (panic_later)
282  return 0;
283 
284  if (val) {
285  /* Environment option */
286  unsigned int i;
287  for (i = 0; envp_init[i]; i++) {
288  if (i == MAX_INIT_ENVS) {
289  panic_later = "Too many boot env vars at `%s'";
290  panic_param = param;
291  }
292  if (!strncmp(param, envp_init[i], val - param))
293  break;
294  }
295  envp_init[i] = param;
296  } else {
297  /* Command line option */
298  unsigned int i;
299  for (i = 0; argv_init[i]; i++) {
300  if (i == MAX_INIT_ARGS) {
301  panic_later = "Too many boot init vars at `%s'";
302  panic_param = param;
303  }
304  }
305  argv_init[i] = param;
306  }
307  return 0;
308 }
309 
310 static int __init init_setup(char *str)
311 {
312  unsigned int i;
313 
314  execute_command = str;
315  /*
316  * In case LILO is going to boot us with default command line,
317  * it prepends "auto" before the whole cmdline which makes
318  * the shell think it should execute a script with such name.
319  * So we ignore all arguments entered _before_ init=... [MJ]
320  */
321  for (i = 1; i < MAX_INIT_ARGS; i++)
322  argv_init[i] = NULL;
323  return 1;
324 }
325 __setup("init=", init_setup);
326 
327 static int __init rdinit_setup(char *str)
328 {
329  unsigned int i;
330 
331  ramdisk_execute_command = str;
332  /* See "auto" comment in init_setup */
333  for (i = 1; i < MAX_INIT_ARGS; i++)
334  argv_init[i] = NULL;
335  return 1;
336 }
337 __setup("rdinit=", rdinit_setup);
338 
339 #ifndef CONFIG_SMP
340 static const unsigned int setup_max_cpus = NR_CPUS;
341 #ifdef CONFIG_X86_LOCAL_APIC
342 static void __init smp_init(void)
343 {
344  APIC_init_uniprocessor();
345 }
346 #else
347 #define smp_init() do { } while (0)
348 #endif
349 
350 static inline void setup_nr_cpu_ids(void) { }
351 static inline void smp_prepare_cpus(unsigned int maxcpus) { }
352 #endif
353 
354 /*
355  * We need to store the untouched command line for future reference.
356  * We also need to store the touched command line since the parameter
357  * parsing is performed in place, and we should allow a component to
358  * store reference of name/value for future reference.
359  */
360 static void __init setup_command_line(char *command_line)
361 {
362  saved_command_line = alloc_bootmem(strlen (boot_command_line)+1);
363  static_command_line = alloc_bootmem(strlen (command_line)+1);
364  strcpy (saved_command_line, boot_command_line);
365  strcpy (static_command_line, command_line);
366 }
367 
368 /*
369  * We need to finalize in a non-__init function or else race conditions
370  * between the root thread and the init thread may cause start_kernel to
371  * be reaped by free_initmem before the root thread has proceeded to
372  * cpu_idle.
373  *
374  * gcc-3.4 accidentally inlines this function, so use noinline.
375  */
376 
377 static __initdata DECLARE_COMPLETION(kthreadd_done);
378 
379 static noinline void __init_refok rest_init(void)
380 {
381  int pid;
382 
383  rcu_scheduler_starting();
384  /*
385  * We need to spawn init first so that it obtains pid 1, however
386  * the init task will end up wanting to create kthreads, which, if
387  * we schedule it before we create kthreadd, will OOPS.
388  */
389  kernel_thread(kernel_init, NULL, CLONE_FS | CLONE_SIGHAND);
390  numa_default_policy();
391  pid = kernel_thread(kthreadd, NULL, CLONE_FS | CLONE_FILES);
392  rcu_read_lock();
393  kthreadd_task = find_task_by_pid_ns(pid, &init_pid_ns);
394  rcu_read_unlock();
395  complete(&kthreadd_done);
396 
397  /*
398  * The boot idle thread must execute schedule()
399  * at least once to get things moving:
400  */
401  init_idle_bootup_task(current);
402  schedule_preempt_disabled();
403  /* Call into cpu_idle with preempt disabled */
404  cpu_idle();
405 }
406 
407 /* Check for early params. */
408 static int __init do_early_param(char *param, char *val, const char *unused)
409 {
410  const struct obs_kernel_param *p;
411 
412  for (p = __setup_start; p < __setup_end; p++) {
413  if ((p->early && parameq(param, p->str)) ||
414  (strcmp(param, "console") == 0 &&
415  strcmp(p->str, "earlycon") == 0)
416  ) {
417  if (p->setup_func(val) != 0)
418  printk(KERN_WARNING
419  "Malformed early option '%s'\n", param);
420  }
421  }
422  /* We accept everything at this stage. */
423  return 0;
424 }
425 
426 void __init parse_early_options(char *cmdline)
427 {
428  parse_args("early options", cmdline, NULL, 0, 0, 0, do_early_param);
429 }
430 
431 /* Arch code calls this early on, or if not, just before other parsing. */
432 void __init parse_early_param(void)
433 {
434  static __initdata int done = 0;
435  static __initdata char tmp_cmdline[COMMAND_LINE_SIZE];
436 
437  if (done)
438  return;
439 
440  /* All fall through to do_early_param. */
441  strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
442  parse_early_options(tmp_cmdline);
443  done = 1;
444 }
445 
446 /*
447  * Activate the first processor.
448  */
449 
450 static void __init boot_cpu_init(void)
451 {
452  int cpu = smp_processor_id();
453  /* Mark the boot cpu "present", "online" etc for SMP and UP case */
454  set_cpu_online(cpu, true);
455  set_cpu_active(cpu, true);
456  set_cpu_present(cpu, true);
457  set_cpu_possible(cpu, true);
458 }
459 
460 void __init __weak smp_setup_processor_id(void)
461 {
462 }
463 
464 # if THREAD_SIZE >= PAGE_SIZE
465 void __init __weak thread_info_cache_init(void)
466 {
467 }
468 #endif
469 
470 /*
471  * Set up kernel memory allocators
472  */
473 static void __init mm_init(void)
474 {
475  /*
476  * page_cgroup requires contiguous pages,
477  * bigger than MAX_ORDER unless SPARSEMEM.
478  */
479  page_cgroup_init_flatmem();
480  mem_init();
481  kmem_cache_init();
482  percpu_init_late();
483  pgtable_cache_init();
484  vmalloc_init();
485 }
486 
487 asmlinkage void __init start_kernel(void)
488 {
489  char * command_line;
490  extern const struct kernel_param __start___param[], __stop___param[];
491 
492  /*
493  * Need to run as early as possible, to initialize the
494  * lockdep hash:
495  */
496  lockdep_init();
497  smp_setup_processor_id();
498  debug_objects_early_init();
499 
500  /*
501  * Set up the the initial canary ASAP:
502  */
503  boot_init_stack_canary();
504 
505  cgroup_init_early();
506 
507  local_irq_disable();
508  early_boot_irqs_disabled = true;
509 
510 /*
511  * Interrupts are still disabled. Do necessary setups, then
512  * enable them
513  */
514  tick_init();
515  boot_cpu_init();
516  page_address_init();
517  printk(KERN_NOTICE "%s", linux_banner);
518  setup_arch(&command_line);
519  mm_init_owner(&init_mm, &init_task);
520  mm_init_cpumask(&init_mm);
521  setup_command_line(command_line);
522  setup_nr_cpu_ids();
523  setup_per_cpu_areas();
524  smp_prepare_boot_cpu(); /* arch-specific boot-cpu hooks */
525 
526  build_all_zonelists(NULL, NULL);
527  page_alloc_init();
528 
529  printk(KERN_NOTICE "Kernel command line: %s\n", boot_command_line);
530  parse_early_param();
531  parse_args("Booting kernel", static_command_line, __start___param,
532  __stop___param - __start___param,
533  -1, -1, &unknown_bootoption);
534 
535  jump_label_init();
536 
537  /*
538  * These use large bootmem allocations and must precede
539  * kmem_cache_init()
540  */
541  setup_log_buf(0);
542  pidhash_init();
543  vfs_caches_init_early();
544  sort_main_extable();
545  trap_init();
546  mm_init();
547 
548  /*
549  * Set up the scheduler prior starting any interrupts (such as the
550  * timer interrupt). Full topology setup happens at smp_init()
551  * time - but meanwhile we still have a functioning scheduler.
552  */
553  sched_init();
554  /*
555  * Disable preemption - early bootup scheduling is extremely
556  * fragile until we cpu_idle() for the first time.
557  */
558  preempt_disable();
559  if (!irqs_disabled()) {
560  printk(KERN_WARNING "start_kernel(): bug: interrupts were "
561  "enabled *very* early, fixing it\n");
562  local_irq_disable();
563  }
564  idr_init_cache();
565  perf_event_init();
566  rcu_init();
567  radix_tree_init();
568  /* init some links before init_ISA_irqs() */
569  early_irq_init();
570  init_IRQ();
571  init_timers();
572  hrtimers_init();
573  softirq_init();
574  timekeeping_init();
575  time_init();
576  profile_init();
577  call_function_init();
578  if (!irqs_disabled())
579  printk(KERN_CRIT "start_kernel(): bug: interrupts were "
580  "enabled early\n");
581  early_boot_irqs_disabled = false;
582  local_irq_enable();
583 
584  kmem_cache_init_late();
585 
586  /*
587  * HACK ALERT! This is early. We're enabling the console before
588  * we've done PCI setups etc, and console_init() must be aware of
589  * this. But we do want output early, in case something goes wrong.
590  */
591  console_init();
592  if (panic_later)
593  panic(panic_later, panic_param);
594 
595  lockdep_info();
596 
597  /*
598  * Need to run this when irqs are enabled, because it wants
599  * to self-test [hard/soft]-irqs on/off lock inversion bugs
600  * too:
601  */
602  locking_selftest();
603 
604 #ifdef CONFIG_BLK_DEV_INITRD
605  if (initrd_start && !initrd_below_start_ok &&
606  page_to_pfn(virt_to_page((void *)initrd_start)) < min_low_pfn) {
607  printk(KERN_CRIT "initrd overwritten (0x%08lx < 0x%08lx) - "
608  "disabling it.\n",
609  page_to_pfn(virt_to_page((void *)initrd_start)),
610  min_low_pfn);
611  initrd_start = 0;
612  }
613 #endif
614  page_cgroup_init();
615  debug_objects_mem_init();
616  kmemleak_init();
617  setup_per_cpu_pageset();
618  numa_policy_init();
619  if (late_time_init)
620  late_time_init();
621  sched_clock_init();
622  calibrate_delay();
623  pidmap_init();
624  anon_vma_init();
625 #ifdef CONFIG_X86
626  if (efi_enabled(EFI_RUNTIME_SERVICES))
627  efi_enter_virtual_mode();
628 #endif
629  thread_info_cache_init();
630  cred_init();
631  fork_init(totalram_pages);
632  proc_caches_init();
633  buffer_init();
634  key_init();
635  security_init();
636  dbg_late_init();
637  vfs_caches_init(totalram_pages);
638  signals_init();
639  /* rootfs populating might need page-writeback */
640  page_writeback_init();
641 #ifdef CONFIG_PROC_FS
642  proc_root_init();
643 #endif
644  cgroup_init();
645  cpuset_init();
646  taskstats_init_early();
647  delayacct_init();
648 
649  check_bugs();
650 
651  acpi_early_init(); /* before LAPIC and SMP init */
652  sfi_init_late();
653 
654  if (efi_enabled(EFI_RUNTIME_SERVICES)) {
655  efi_late_init();
656  efi_free_boot_services();
657  }
658 
659  ftrace_init();
660 
661  /* Do the rest non-__init'ed, we're now alive */
662  rest_init();
663 }
664 
665 /* Call all constructor functions linked into the kernel. */
666 static void __init do_ctors(void)
667 {
668 #ifdef CONFIG_CONSTRUCTORS
669  ctor_fn_t *fn = (ctor_fn_t *) __ctors_start;
670 
671  for (; fn < (ctor_fn_t *) __ctors_end; fn++)
672  (*fn)();
673 #endif
674 }
675 
676 bool initcall_debug;
677 core_param(initcall_debug, initcall_debug, bool, 0644);
678 
679 static char msgbuf[64];
680 
681 static int __init_or_module do_one_initcall_debug(initcall_t fn)
682 {
683  ktime_t calltime, delta, rettime;
684  unsigned long long duration;
685  int ret;
686 
687  printk(KERN_DEBUG "calling %pF @ %i\n", fn, task_pid_nr(current));
688  calltime = ktime_get();
689  ret = fn();
690  rettime = ktime_get();
691  delta = ktime_sub(rettime, calltime);
692  duration = (unsigned long long) ktime_to_ns(delta) >> 10;
693  printk(KERN_DEBUG "initcall %pF returned %d after %lld usecs\n", fn,
694  ret, duration);
695 
696  return ret;
697 }
698 
699 int __init_or_module do_one_initcall(initcall_t fn)
700 {
701  int count = preempt_count();
702  int ret;
703 
704  if (initcall_debug)
705  ret = do_one_initcall_debug(fn);
706  else
707  ret = fn();
708 
709  msgbuf[0] = 0;
710 
711  if (ret && ret != -ENODEV && initcall_debug)
712  sprintf(msgbuf, "error code %d ", ret);
713 
714  if (preempt_count() != count) {
715  strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
716  preempt_count() = count;
717  }
718  if (irqs_disabled()) {
719  strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
720  local_irq_enable();
721  }
722  if (msgbuf[0]) {
723  printk("initcall %pF returned with %s\n", fn, msgbuf);
724  }
725 
726  return ret;
727 }
728 
729 
730 extern initcall_t __initcall_start[];
731 extern initcall_t __initcall0_start[];
732 extern initcall_t __initcall1_start[];
733 extern initcall_t __initcall2_start[];
734 extern initcall_t __initcall3_start[];
735 extern initcall_t __initcall4_start[];
736 extern initcall_t __initcall5_start[];
737 extern initcall_t __initcall6_start[];
738 extern initcall_t __initcall7_start[];
739 extern initcall_t __initcall_end[];
740 
741 static initcall_t *initcall_levels[] __initdata = {
742  __initcall0_start,
743  __initcall1_start,
744  __initcall2_start,
745  __initcall3_start,
746  __initcall4_start,
747  __initcall5_start,
748  __initcall6_start,
749  __initcall7_start,
750  __initcall_end,
751 };
752 
753 /* Keep these in sync with initcalls in include/linux/init.h */
754 static char *initcall_level_names[] __initdata = {
755  "early",
756  "core",
757  "postcore",
758  "arch",
759  "subsys",
760  "fs",
761  "device",
762  "late",
763 };
764 
765 static void __init do_initcall_level(int level)
766 {
767  extern const struct kernel_param __start___param[], __stop___param[];
768  initcall_t *fn;
769 
770  strcpy(static_command_line, saved_command_line);
771  parse_args(initcall_level_names[level],
772  static_command_line, __start___param,
773  __stop___param - __start___param,
774  level, level,
775  &repair_env_string);
776 
777  for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
778  do_one_initcall(*fn);
779 }
780 
781 static void __init do_initcalls(void)
782 {
783  int level;
784 
785  for (level = 0; level < ARRAY_SIZE(initcall_levels) - 1; level++)
786  do_initcall_level(level);
787 }
788 
789 /*
790  * Ok, the machine is now initialized. None of the devices
791  * have been touched yet, but the CPU subsystem is up and
792  * running, and memory and process management works.
793  *
794  * Now we can finally start doing some real work..
795  */
796 static void __init do_basic_setup(void)
797 {
798  cpuset_init_smp();
799  usermodehelper_init();
800  shmem_init();
801  driver_init();
802  init_irq_proc();
803  do_ctors();
804  usermodehelper_enable();
805  do_initcalls();
806 
807  /*
808  * VIRGO cloudexec service kernel thread initialization
809  * - Ka.Shrinivaasan 3May2013
810 
811  do_virgocloudexec_init();
812  */
813 
814  /*
815  VIRGO cloudexec - cloud initialization from virgo_cloud.conf file
816  - Ka.Shrinivaasan 3 July 2013
817  do_virgo_cloud_init();
818  */
819 }
820 
821 /*
822  VIRGO clone and cloudexec - cloud initialization from virgo_cloud.conf file
823  - Ka.Shrinivaasan 3 July 2013
824  - Ka.Shrinivaasan 16 July 2013
825 */
826 void do_virgo_cloud_init()
827 {
828  read_virgo_clone_config();
829 }
830 
831 void read_virgo_clone_config()
832 {
833  /*
834  virgo_cloud.conf contains a string of comma separated list of IP addresses in the virgo cloud .Read and strtok() it.
835  For the timebeing /etc/virgo_cloud.conf contains configurations for both virgo_clone() and virgo_cloudexec
836  If necessary , two config tiles can be used - one for virgo_clone() client and kernel service side each.
837  - Ka.Shrinivaasan 16 July 2013
838  */
839 
840  loff_t bytesread=0;
841  loff_t pos=0;
842  mm_segment_t fs;
843 
844  /*
845  * It is redundant to use kallsyms_lookup for exported symbols for virgo cloud initialization.
846  * kallsyms_lookup is for non-exported symbols.
847  *
848  * - Ka.Shrinivaasan 10 July 2013
849  *
850 
851  node_ip_addrs_in_cloud=(char**)kallsyms_lookup_name("node_ip_addrs_in_cloud");
852  num_cloud_nodes=kallsyms_lookup_name("num_cloud_nodes");
853 
854  printk(KERN_INFO "virgo kernel service: read_virgo_config(): virgo_cloud config being read... \n");
855  printk(KERN_INFO "virgo kernel service: read_virgo_config(): num_cloud_nodes=%d #### node_ip_addrs_in_cloud=%s\n", num_cloud_nodes,node_ip_addrs_in_cloud);
856  */
857 
858  fs=get_fs();
859  /*set_fs(get_ds());*/
860  set_fs(KERNEL_DS);
861  struct file* f=NULL;
862  f=filp_open("/etc/virgo_cloud.conf", O_RDONLY, 0);
863 
864  char buf[256];
865  int i=0;
866 
867  int k=0;
868  for(k=0;k<256;k++)
869  buf[k]=0;
870 
871  /*
872  for(k=0; k < num_cloud_nodes; k++)
873  printk(KERN_INFO "read_virgo_clone_config(): before reading virgo_cloud.conf - virgo_cloud ip address - %d: %s\n", k+1, node_ip_addrs_in_cloud[k]);
874 
875  printk(KERN_INFO "read_virgo_clone_config(): virgo_cloud config file being read \n");
876  */
877 
878 
879  if(f !=NULL)
880  {
881  /*f->f_op->read(f, buf, sizeof(buf), &f->f_pos);*/
882  bytesread=vfs_read(f, buf, 256, &pos);
883  /*strcpy(node_ip_addrs_in_cloud[i],buf);*/
884  /*printk(KERN_INFO "read_virgo_clone_config(): virgo_cloud config file string of comma separated IPs : %s \n",buf);*/
885  /*printk(KERN_INFO "do_virgo_cloud_init(): virgo_cloud config file line %d \n",i);*/
886  pos=pos+bytesread;
887  }
888  /*num_cloud_nodes=tokenize_list_of_ip_addrs(buf);*/
889  char* delim=",";
890  char* token=NULL;
891  char* bufdup=kstrdup(buf,GFP_ATOMIC);
892  /*printk(KERN_INFO "read_virgo_clone_config(): tokenize_list_of_ip_addrs(): bufdup = %s\n",bufdup);*/
893  while(bufdup != NULL)
894  {
895  token=strsep(&bufdup, delim);
896  /*printk(KERN_INFO "read_virgo_clone_config(): tokenize_list_of_ip_addrs(): %s\n",token);*/
897  node_ip_addrs_in_cloud[i]=kstrdup(token,GFP_ATOMIC);
898  /*printk(KERN_INFO "read_virgo_clone_config(): tokenize_list_of_ip_addrs(): node_ip_addrs_in_cloud[%d] = %s\n",i,node_ip_addrs_in_cloud[i]);*/
899  i++;
900  }
901  num_cloud_nodes=i;
902  set_fs(fs);
903  filp_close(f,NULL);
904 }
905 
906 /*
907 * VIRGO cloudexec service kernel thread initialization
908 * - Ka.Shrinivaasan 3May2013
909 void do_virgocloudexec_init()
910 {
911  struct task_struct* task;
912  task=kthread_create(virgo_cloudexec_service, (void*)args, "Virgo Cloudexec Service Kernel Thread");
913 }
914 
915 */
916 
917 static void __init do_pre_smp_initcalls(void)
918 {
919  initcall_t *fn;
920 
921  for (fn = __initcall_start; fn < __initcall0_start; fn++)
922  do_one_initcall(*fn);
923 }
924 
925 static int run_init_process(const char *init_filename)
926 {
927  argv_init[0] = init_filename;
928  return kernel_execve(init_filename, argv_init, envp_init);
929 }
930 
931 static noinline void __init kernel_init_freeable(void);
932 
933 static int __ref kernel_init(void *unused)
934 {
935  kernel_init_freeable();
936  /* need to finish all async __init code before freeing the memory */
937  async_synchronize_full();
938  free_initmem();
939  mark_rodata_ro();
940  system_state = SYSTEM_RUNNING;
941  numa_default_policy();
942 
943  current->signal->flags |= SIGNAL_UNKILLABLE;
944  flush_delayed_fput();
945 
946  if (ramdisk_execute_command) {
947  if (!run_init_process(ramdisk_execute_command))
948  return 0;
949  printk(KERN_WARNING "Failed to execute %s\n",
950  ramdisk_execute_command);
951  }
952 
953  /*
954  * We try each of these until one succeeds.
955  *
956  * The Bourne shell can be used instead of init if we are
957  * trying to recover a really broken machine.
958  */
959  if (execute_command) {
960  if (!run_init_process(execute_command))
961  return 0;
962  printk(KERN_WARNING "Failed to execute %s. Attempting "
963  "defaults...\n", execute_command);
964  }
965  if (!run_init_process("/sbin/init") ||
966  !run_init_process("/etc/init") ||
967  !run_init_process("/bin/init") ||
968  !run_init_process("/bin/sh"))
969  return 0;
970 
971  panic("No init found. Try passing init= option to kernel. "
972  "See Linux Documentation/init.txt for guidance.");
973 }
974 
975 static noinline void __init kernel_init_freeable(void)
976 {
977  /*
978  * Wait until kthreadd is all set-up.
979  */
980  wait_for_completion(&kthreadd_done);
981 
982  /* Now the scheduler is fully set up and can do blocking allocations */
983  gfp_allowed_mask = __GFP_BITS_MASK;
984 
985  /*
986  * init can allocate pages on any node
987  */
988  set_mems_allowed(node_states[N_HIGH_MEMORY]);
989  /*
990  * init can run on any cpu.
991  */
992  set_cpus_allowed_ptr(current, cpu_all_mask);
993 
994  cad_pid = task_pid(current);
995 
996  smp_prepare_cpus(setup_max_cpus);
997 
998  do_pre_smp_initcalls();
999  lockup_detector_init();
1000 
1001  smp_init();
1002  sched_init_smp();
1003 
1004  do_basic_setup();
1005 
1006  /* Open the /dev/console on the rootfs, this should never fail */
1007  if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
1008  printk(KERN_WARNING "Warning: unable to open an initial console.\n");
1009 
1010  (void) sys_dup(0);
1011  (void) sys_dup(0);
1012  /*
1013  * check if there is an early userspace init. If yes, let it do all
1014  * the work
1015  */
1016 
1017  if (!ramdisk_execute_command)
1018  ramdisk_execute_command = "/init";
1019 
1020  if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
1021  ramdisk_execute_command = NULL;
1022  prepare_namespace();
1023  }
1024 
1025  /*
1026  * Ok, we have completed the initial bootup, and
1027  * we're essentially up and running. Get rid of the
1028  * initmem segments and start the user-mode stuff..
1029  */
1030 }