Browse Source

Fall back to checkpointing by stream if GIPC is not installed
Fix a bug in Proc FS (Permission denied at /proc/[PID])

Chia-Che Tsai 9 years ago
parent
commit
29767a2a9f

+ 0 - 4
LibOS/shim/include/shim_checkpoint.h

@@ -519,9 +519,6 @@ ptr_t add_to_migrate_map (void * map, void * obj, ptr_t off,
                                                                             \
             BEGIN_PROFILE_INTERVAL();                                       \
                                                                             \
-            INIT_CP_STORE(store);                                           \
-            SAVE_PROFILE_INTERVAL(checkpoint_init_store);                   \
-                                                                            \
             size = migrate_def_##name((store), NULL, 0, true, ##__VA_ARGS__) \
                    + (preserve);                                            \
             SAVE_PROFILE_INTERVAL(checkpoint_predict_size);                 \
@@ -597,7 +594,6 @@ int restore_gipc (PAL_HANDLE gipc, struct gipc_header * hdr, void * cpdata,
                   long cprebase);
 int send_checkpoint_by_gipc (PAL_HANDLE gipc_store,
                              struct shim_cp_store * cpstore);
-int send_checkpoint_on_stream (PAL_HANDLE stream, void * cpdata, int size);
 int send_handles_on_stream (PAL_HANDLE stream, void * cpdata);
 
 int do_migrate_process (int (*migrate) (struct shim_cp_store *,

+ 1 - 1
LibOS/shim/src/fs/proc/ipc-thread.c

@@ -227,7 +227,7 @@ static int proc_ipc_thread_dir_mode (const char * name, mode_t * mode)
         for (int i = 0 ; i < pid_status_cache->nstatus ; i++)
             if (pid_status_cache->status[i].pid == pid) {
                 unlock(status_lock);
-                *mode = 0400;
+                *mode = 0500;
                 return 0;
             }
 

+ 1 - 1
LibOS/shim/src/fs/proc/thread.c

@@ -470,7 +470,7 @@ static int proc_thread_dir_mode (const char * name, mode_t * mode)
     if (pid < 0)
         return pid;
 
-    *mode = 0400;
+    *mode = 0500;
     return 0;
 }
 

+ 26 - 12
LibOS/shim/src/shim_checkpoint.c

@@ -45,7 +45,6 @@ DEFINE_PROFILE_CATAGORY(migrate_func, );
 DEFINE_PROFILE_CATAGORY(resume_func, );
 
 DEFINE_PROFILE_CATAGORY(checkpoint, );
-DEFINE_PROFILE_INTERVAL(checkpoint_init_store, checkpoint);
 DEFINE_PROFILE_INTERVAL(checkpoint_predict_size, checkpoint);
 DEFINE_PROFILE_INTERVAL(checkpoint_alloc_memory, checkpoint);
 DEFINE_PROFILE_INTERVAL(checkpoint_copy_object, checkpoint);
@@ -740,10 +739,9 @@ int do_migrate_process (int (*migrate) (struct shim_cp_store *,
     PAL_NUM gipc_key;
     PAL_HANDLE gipc_hdl = DkCreatePhysicalMemoryChannel(&gipc_key);
 
-    if (!gipc_hdl) {
-        sys_printf("Failure: require physical memory support\n");
-        return -PAL_ERRNO;
-    }
+    if (!gipc_hdl)
+        sys_printf("WARNING: no physical memory support, process creation "
+                   "will be slow.\n");
 
     debug("created gipc store: gipc:%lu\n", gipc_key);
 
@@ -762,6 +760,8 @@ int do_migrate_process (int (*migrate) (struct shim_cp_store *,
     }
 
     cpstore = __alloca(sizeof(struct shim_cp_store));
+    INIT_CP_STORE(cpstore);
+    cpstore->use_gipc = (gipc_hdl != NULL);
     va_list ap;
     va_start(ap, thread);
     ret = migrate(cpstore, new_process, thread, ap);
@@ -776,11 +776,17 @@ int do_migrate_process (int (*migrate) (struct shim_cp_store *,
 
     hdr.checkpoint.data.cpsize = cpstore->cpsize;
     hdr.checkpoint.data.cpaddr = cpstore->cpaddr;
-    hdr.checkpoint.data.cpoffset = cpstore->cpdata - cpstore->cpaddr ;
-    hdr.checkpoint.gipc.gipc_key = gipc_key;
-    hdr.checkpoint.gipc.gipc_entoffset = cpstore->gipc_entries ?
+    hdr.checkpoint.data.cpoffset = cpstore->cpdata - cpstore->cpaddr;
+    if (gipc_hdl) {
+        hdr.checkpoint.gipc.gipc_key = gipc_key;
+        hdr.checkpoint.gipc.gipc_entoffset = cpstore->gipc_entries ?
                            (void *) cpstore->gipc_entries - cpstore->cpaddr : 0;
-    hdr.checkpoint.gipc.gipc_nentries  = cpstore->gipc_nentries;
+        hdr.checkpoint.gipc.gipc_nentries  = cpstore->gipc_nentries;
+    } else {
+        hdr.checkpoint.gipc.gipc_key = 0;
+        hdr.checkpoint.gipc.gipc_entoffset = 0;
+        hdr.checkpoint.gipc.gipc_nentries  = 0;
+    }
     hdr.failure = 0;
 #ifdef PROFILE
     hdr.begin_create_time  = begin_create_time;
@@ -794,10 +800,18 @@ int do_migrate_process (int (*migrate) (struct shim_cp_store *,
         goto err;
     }
 
-    if ((ret = send_checkpoint_by_gipc(gipc_hdl, cpstore)) < 0)
-        goto err;
+    if (gipc_hdl) {
+        if ((ret = send_checkpoint_by_gipc(gipc_hdl, cpstore)) < 0)
+            goto err;
 
-    DkObjectClose(gipc_hdl);
+        DkObjectClose(gipc_hdl);
+    } else {
+        ret = DkStreamWrite(proc, 0, cpstore->cpsize, cpstore->cpdata, NULL);
+        if (ret < cpstore->cpsize) {
+            ret = -PAL_ERRNO;
+            goto err;
+        }
+    }
 
     if ((ret = send_handles_on_stream(proc, cpstore->cpdata)) < 0)
         goto err;

+ 0 - 1
LibOS/shim/src/sys/shim_fork.c

@@ -63,7 +63,6 @@ static int migrate_fork (struct shim_cp_store * cpstore,
     BEGIN_MIGRATION_DEF(fork, struct shim_process * proc,
                         struct shim_thread * thread)
     {
-        store->use_gipc = true;
         DEFINE_MIGRATE(process, proc, sizeof(struct shim_process), false);
         DEFINE_MIGRATE(all_mounts, NULL, 0, false);
         DEFINE_MIGRATE(all_vmas, NULL, 0, true); /* recusive for the data */

+ 1 - 1
LibOS/shim/src/sys/shim_migrate.c

@@ -232,7 +232,7 @@ static int finish_checkpoint (void)
     struct shim_cp_store cpstore;
 
 again:
-    memset(&cpstore, 0, sizeof(struct shim_cp_store));
+    INIT_CP_STORE(&cpstore);
 
     BEGIN_MIGRATION_DEF(checkpoint)
     {

+ 19 - 6
LibOS/shim/test/native/proc.c

@@ -12,6 +12,19 @@
 
 int main(int argc, char ** argv)
 {
+    struct dirent * dirent;
+    DIR * dir;
+
+    dir = opendir("/proc/1");
+    if (!dir) {
+        perror("opendir /proc/1");
+        exit(1);
+    }
+    while ((dirent = readdir(dir)))
+        printf("/proc/1/%s\n", dirent->d_name);
+    closedir(dir);
+
+
     for (int i = 0 ; i < 3 ; i++) {
         pid_t pid = fork();
 
@@ -26,13 +39,13 @@ int main(int argc, char ** argv)
         }
     }
 
-    struct dirent * dirent;
-
-    DIR * dir = opendir("/proc");
-
+    dir = opendir("/proc");
+    if (!dir) {
+        perror("opendir /proc");
+        exit(1);
+    }
     while ((dirent = readdir(dir)))
-        printf("found %s\n", dirent->d_name);
-
+        printf("/proc/%s\n", dirent->d_name);
     closedir(dir);
 
     return 0;