40d7a6e23124d8064e69d874b0191aa538a5fb70
[bluesky.git] / nfs3 / nfsd.c
1 /* Blue Sky: File Systems in the Cloud
2  *
3  * Copyright (C) 2009  The Regents of the University of California
4  * Written by Michael Vrable <mvrable@cs.ucsd.edu>
5  *
6  * TODO: Licensing
7  */
8
9 /* Main entry point for an NFSv3 server which will proxy requests to a cloud
10  * filesystem. */
11
12 #include "mount_prot.h"
13 #include "nfs3_prot.h"
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <rpc/pmap_clnt.h>
17 #include <string.h>
18 #include <memory.h>
19 #include <sys/socket.h>
20 #include <netinet/in.h>
21 #include <glib.h>
22
23 #include "bluesky.h"
24
25 void register_rpc();
26
27 BlueSkyFS *fs;
28 BlueSkyStore *store;
29
30 /* A cookie value returned for uncommitted writes and verified by commits; this
31  * should be a unique value each time the server is started. */
32 char nfsd_instance_verf_cookie[NFS3_WRITEVERFSIZE];
33
34 static void shutdown_handler(int num)
35 {
36     g_print("SIGINT caught, shutting down...\n");
37     g_print("Proxy statistics:\n");
38     bluesky_stats_dump_all();
39     exit(1);
40 }
41
42 int main(int argc, char *argv[])
43 {
44     int i;
45
46     signal(SIGPIPE, SIG_IGN);
47     signal(SIGINT, shutdown_handler);
48
49     bluesky_init();
50     g_set_prgname("nfsd");
51
52     const char *target = getenv("BLUESKY_TARGET");
53     if (target == NULL)
54         target = "s3";
55
56     const char *key = getenv("BLUESKY_KEY");
57     if (key == NULL)
58         key = "";
59
60     const char *profile_output = getenv("BLUESKY_PROFILE_OUT");
61     if (profile_output != NULL)
62         bluesky_profile_set_output(fopen(profile_output, "a"));
63
64     store = bluesky_store_new(target);
65     fs = bluesky_init_fs("export", store, key);
66
67     const char *stats_output = getenv("BLUESKY_STATS_OUT");
68     if (stats_output != NULL)
69         bluesky_stats_run_periodic_dump(fopen(stats_output, "a"));
70
71     bluesky_crypt_random_bytes(nfsd_instance_verf_cookie,
72                                sizeof(nfsd_instance_verf_cookie));
73
74     register_rpc();
75
76     svc_run();
77     fprintf(stderr, "%s", "svc_run returned");
78     exit(1);
79 }