diff options
author | Shehjar Tikoo <shehjart@zresearch.com> | 2009-05-05 15:59:18 +0530 |
---|---|---|
committer | Anand V. Avati <avati@amp.gluster.com> | 2009-05-05 17:40:08 +0530 |
commit | 313713a254e193623807d019f4c0e17e637ed316 (patch) | |
tree | e9487ccda2fb2c88787966f94e71fe50ce07dec5 | |
parent | 42d5355a6221ea473372c891544e4cc7b265bbe9 (diff) |
booster: Integrate VMP-based mounting
This commit brings into booster the use of VMP based operations
which will allow users of booster to specifiy a VMP and use it
for transparently operating on a glusterfs client context.
Since applications are oblivious to booster's presence, because it is
LD_PRELOAD'ed, we need to specify the VMPs and the corresponding
options like volfile, logfile, loglevel, through a conf file.
By default, this conf file is the /etc/booster.conf. This can be
over-ridden through the GLFS_BOOSTER_CONF environment variable
for the application.
The format of the conf file is very simple for now. Each VMP is
described on a single line with space separated fields.
Format: <Virtual Mount Point> <volfile-path> <log-file> <log-level>
<log-level> takes the string representation of the usual glusterfs
log levels.
Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
-rw-r--r-- | booster/src/booster.c | 112 |
1 files changed, 110 insertions, 2 deletions
diff --git a/booster/src/booster.c b/booster/src/booster.c index c8ba3eae887..ef1dcc8e68a 100644 --- a/booster/src/booster.c +++ b/booster/src/booster.c @@ -38,6 +38,7 @@ #include <string.h> #include <assert.h> #include <errno.h> +#include <ctype.h> #ifndef GF_UNIT_KB #define GF_UNIT_KB 1024 @@ -150,6 +151,88 @@ typedef struct booster_mount_table booster_mount_table_t; static fdtable_t *booster_glfs_fdtable = NULL; static booster_mount_table_t *booster_mount_table = NULL; +#define DEFAULT_BOOSTER_CONF "/etc/booster.conf" + +int +booster_parse_line (char *buf, char **mount_point, + glusterfs_init_params_t *params) +{ + /* Structure of each line in booster config: + * /virtual/mount/point /volume/specification/file volume-name /log/file loglevel cache-timeout + * 0 can be entered for each of volume-name, /log/file, loglevel + * to force default values. + */ + char *inbufptr = NULL; + + if (!buf || !mount_point || !params) { + goto out; + } + memset (params, 0, sizeof (*params)); + inbufptr = strtok (buf, " "); + if (inbufptr == NULL) + goto out; + *mount_point = strdup (inbufptr); + + inbufptr = strtok (NULL, " "); + if (inbufptr == NULL) + goto out; + params->specfile = strdup (inbufptr); + + inbufptr = strtok (NULL, " "); + if (inbufptr == NULL) + goto out; + params->volume_name = strdup (inbufptr); + + inbufptr = strtok (NULL, " "); + if (inbufptr == NULL) + goto out; + params->logfile = strdup (inbufptr); + + inbufptr = strtok (NULL, " "); + if (inbufptr == NULL) + goto out; + params->loglevel = strdup (inbufptr); + + return 0; +out: + return -1; +} + +int +booster_configure (char *confpath) +{ + FILE *fp = NULL; + int ret = -1; + char buf[4096]; + char *mount_point = NULL; + glusterfs_init_params_t params = {0, }; + + fp = fopen (confpath, "r"); + if (fp == NULL) { + goto out; + } + + while (1) { + fgets (buf, 4096, fp); + if (feof (fp)) { + break; + } + + mount_point = NULL; + ret = booster_parse_line (buf, &mount_point, ¶ms); + if (ret == -1) { + goto out; + } + + /* even if this mount fails, lets continue with others */ + glusterfs_mount (mount_point, ¶ms); + } + + ret = 0; +out: + return ret; +} + static int32_t booster_put_handle (booster_mount_table_t *table, dev_t st_dev, @@ -786,7 +869,10 @@ dup2 (int oldfd, int newfd) static int booster_init (void) { - int i = 0; + int i = 0; + char *booster_conf_path = NULL; + int ret = -1; + booster_glfs_fdtable = gf_fd_fdtable_alloc (); if (!booster_glfs_fdtable) { fprintf (stderr, "cannot allocate fdtable: %s\n", @@ -816,6 +902,21 @@ booster_init (void) INIT_LIST_HEAD (&booster_mount_table->mounts[i]); } + /* libglusterfsclient based VMPs should be inited only + * after the file tables are inited so that if the socket + * calls use the fd based syscalls, the fd tables are + * correctly initialized to return a NULL handle, on which the + * socket calls will fall-back to the real API. + */ + booster_conf_path = getenv ("GLFS_BOOSTER_CONF"); + if (booster_conf_path == NULL) + ret = booster_configure (DEFAULT_BOOSTER_CONF); + else + ret = booster_configure (booster_conf_path); + + if (ret == -1) + goto err; + return 0; err: @@ -900,7 +1001,6 @@ fork (void) void _init (void) { - booster_init (); RESOLVE (open); RESOLVE (open64); @@ -925,5 +1025,13 @@ _init (void) RESOLVE (dup2); RESOLVE (fork); + + /* This must be called after resolving real functions + * above so that the socket based IO calls in libglusterfsclient + * can fall back to a non-NULL real_XXX function pointer. + * Calling booster_init before resolving the names above + * results in seg-faults because the function symbols above are NULL. + */ + booster_init (); } |