Add proper per-file copyright notices/licenses and top-level license.
[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  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the University nor the names of its contributors
15  *    may be used to endorse or promote products derived from this software
16  *    without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30
31 /* Main entry point for an NFSv3 server which will proxy requests to a cloud
32  * filesystem. */
33
34 #include "mount_prot.h"
35 #include "nfs3_prot.h"
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <rpc/pmap_clnt.h>
39 #include <string.h>
40 #include <memory.h>
41 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #include <glib.h>
44
45 #include "bluesky.h"
46
47 void register_rpc();
48
49 BlueSkyFS *fs;
50 BlueSkyStore *store;
51
52 /* A cookie value returned for uncommitted writes and verified by commits; this
53  * should be a unique value each time the server is started. */
54 char nfsd_instance_verf_cookie[NFS3_WRITEVERFSIZE];
55
56 static void shutdown_handler(int num)
57 {
58     g_print("SIGINT caught, shutting down...\n");
59     g_print("Proxy statistics:\n");
60     bluesky_stats_dump_all();
61     exit(1);
62 }
63
64 int main(int argc, char *argv[])
65 {
66     int i;
67
68     signal(SIGPIPE, SIG_IGN);
69     signal(SIGINT, shutdown_handler);
70
71     bluesky_init();
72     g_set_prgname("nfsd");
73
74     const char *target = getenv("BLUESKY_TARGET");
75     if (target == NULL)
76         target = "s3";
77
78     const char *key = getenv("BLUESKY_KEY");
79     if (key == NULL)
80         key = "";
81
82     const char *profile_output = getenv("BLUESKY_PROFILE_OUT");
83     if (profile_output != NULL)
84         bluesky_profile_set_output(fopen(profile_output, "a"));
85
86     store = bluesky_store_new(target);
87     fs = bluesky_init_fs("export", store, key);
88
89     const char *stats_output = getenv("BLUESKY_STATS_OUT");
90     if (stats_output != NULL)
91         bluesky_stats_run_periodic_dump(fopen(stats_output, "a"));
92
93     bluesky_crypt_random_bytes(nfsd_instance_verf_cookie,
94                                sizeof(nfsd_instance_verf_cookie));
95
96     register_rpc();
97
98     svc_run();
99     fprintf(stderr, "%s", "svc_run returned");
100     exit(1);
101 }