Let storage tuning options be set via environment variables.
[bluesky.git] / bluesky / init.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 #include <stdint.h>
10 #include <stdlib.h>
11 #include <glib.h>
12 #include <string.h>
13
14 #include "bluesky-private.h"
15
16 BlueSkyOptions bluesky_options;
17
18 /* Environment variables that can be used to initialize settings. */
19 static struct {
20     const char *env;
21     int *option;
22 } option_table[] = {
23     {"BLUESKY_OPT_SYNC_STORES", &bluesky_options.synchronous_stores},
24     {"BLUESKY_OPT_WRITETHROUGH", &bluesky_options.writethrough_cache},
25     {"BLUESKY_OPT_SYNC_INODE_FETCH", &bluesky_options.sync_inode_fetches},
26     {NULL, NULL}
27 };
28
29 /* BlueSky library initialization. */
30
31 void bluesky_store_init_s3(void);
32
33 /* Initialize the BlueSky library and dependent libraries. */
34 void bluesky_init(void)
35 {
36     g_thread_init(NULL);
37     bluesky_crypt_init();
38
39     for (int i = 0; option_table[i].env != NULL; i++) {
40         const char *val = getenv(option_table[i].env);
41         if (val != NULL) {
42             int v = atoi(val);
43             g_print("Option %s set to %d\n", option_table[i].env, v);
44             *option_table[i].option = atoi(val);
45         }
46     }
47
48     bluesky_store_init();
49     bluesky_store_init_s3();
50 }