Fork() and return from the parent back to the shell to ensure remote-cache is run...
authorroot <root@rcn1.VSOFS1.COM>
Sun, 29 Mar 2009 23:04:21 +0000 (10:04 +1100)
committerroot <root@rcn1.VSOFS1.COM>
Sun, 29 Mar 2009 23:04:21 +0000 (10:04 +1100)
Add a handler for SIGUSR2.    Kill -USR2 <pid of migration daemon>
is now the approved was to stop and unmount a remote cache filesystem

migrate/migrate.h
migrate/remote-cache.c
migrate/remote-cached.c

index 5ce35fd60642cd3677aa80ee0086d1ab8aff5ae5..c439adbb65dfa686389fb400eb078366dc3ef294 100644 (file)
@@ -22,6 +22,7 @@
 extern struct tdb_context *migrate_db;
 extern const char *cache;
 extern const char *remote;
+extern const char *export;
 
 extern int this_log_level;
 enum deb_lev { 
index 3925a1b4067f08c613dd9ee790ccbc9fee1dc2f6..2d9e6d718530675787f9eb3a4a8a33f39b15bb5c 100644 (file)
@@ -58,7 +58,7 @@ const char *remote = NULL;
 
 /* this is the directory where we present the cached image and which
    we re-export through our local nfs server to the clients */
-static const char *export = NULL;
+const char *export = NULL;
 
 
 enum deb_lev debug_level = DEBUG_ERR;
@@ -3215,6 +3215,15 @@ int main(int argc, const char *argv[])
                printf("Using BIG_WRITES\n");
        }
 
+       ret = fork();
+       if (ret == -1) {
+               DEBUG(DEBUG_ERR, ("Failed to fork\n"));
+               exit(10);
+       }
+       if (ret != 0) {
+               return 0;
+       }
+
        migpid = start_migration_daemon();
        if (migpid == -1) {
                DEBUG(DEBUG_CRIT,("Failed to spawn migration daemon. Aborting\n"));
@@ -3224,3 +3233,5 @@ int main(int argc, const char *argv[])
        printf("here we go ...\n");
        return fuse_main(num_args, discard_const(fuse_argv), &remote_cache_ops, NULL);
 }
+
+
index 5e94545cbbccb1628794b6a6e10dc73296f38363..7dfccc43b60685387cdb59a45b9ba597c7ea7095 100644 (file)
@@ -193,6 +193,20 @@ static void migd_sigusr1_handler(struct event_context *ev, struct signal_event *
        DEBUG(DEBUG_DEBUG,("No more files to migrate, for now\n"));
 }
 
+static void migd_sigusr2_handler(struct event_context *ev, struct signal_event *se, int signum, int count, void *dont_care, void *private_data)
+{
+       TALLOC_CTX *mem_ctx = talloc_new(NULL);
+       char *cmd;
+       int ret;
+
+       cmd = talloc_asprintf(mem_ctx, "fusermount -u %s\n", export);
+       DEBUG(DEBUG_ERR,("Got SIGUSR2, unmounting fuse filesystem %s\n", export));
+       ret = system(cmd);
+
+       talloc_free(mem_ctx);
+       _exit(10);
+}
+
 int start_migration_daemon(void)
 {
        TALLOC_CTX *migd;
@@ -230,6 +244,10 @@ int start_migration_daemon(void)
                return -1;
        }
 
+       /* make sure we unmount the filesystem when the migration dameon exits */
+       /* set up a handler to pick up sigusr2 */
+       se = event_add_signal(ev, migd, SIGUSR2, 0, migd_sigusr2_handler, migd);
+
        event_loop_wait(ev);
        DEBUG(DEBUG_CRIT,("Returned from event loop. This can not happen\n"));