static void uwsgi_glusterfs_add_mountpoint(char *arg, size_t arg_len) { char *ugfs_mountpoint = NULL; char *ugfs_server = NULL; char *ugfs_volfile = NULL; char *ugfs_volume = NULL; if (uwsgi_kvlist_parse(arg, arg_len, ',', '=', "mountpoint", &ugfs_mountpoint, "server", &ugfs_server, "servers", &ugfs_server, "volfile", &ugfs_volfile, "volume", &ugfs_volume, NULL)) { uwsgi_log("unable to parse glusterfs mountpoint definition\n"); exit(1); } if (!ugfs_mountpoint || (!ugfs_server && !ugfs_volfile) || !ugfs_volume) { uwsgi_log("[glusterfs] mount requires a mountpoint, a volume and at least one server or volfile\n"); exit(1); } int id = uwsgi_apps_cnt; time_t now = uwsgi_now(); uwsgi_log("[glusterfs] mounting %s ...\n", ugfs_mountpoint); // this should fail only if memory is not available glfs_t *volume = glfs_new(ugfs_volume); if (!volume) { uwsgi_error("unable to initialize glusterfs mountpoint: glfs_new()"); exit(1); } if (ugfs_volfile) { if (glfs_set_volfile(volume, ugfs_volfile)) { uwsgi_error("unable to set glusterfs volfile: glfs_set_volfile\n"); exit(1); } } /* here we pass ugfs_server as the callable field. After fork() if this field is defined we will start trying to connect to each one of the configuratio nodes This is required to have fallback management */ struct uwsgi_app *ua = uwsgi_add_app(id, glusterfs_plugin.modifier1, ugfs_mountpoint, strlen(ugfs_mountpoint), volume, ugfs_server); if (!ua) { uwsgi_log("[glusterfs] unable to mount %s\n", ugfs_mountpoint); exit(1); } ua->started_at = now; ua->startup_time = uwsgi_now() - now; uwsgi_log("GlusterFS app/mountpoint %d (%s) loaded in %d seconds at %p\n", id, ugfs_mountpoint, (int) ua->startup_time, volume); }
int main (int argc, char **argv) { glfs_t *fs; int ret; int meta_fd = (-1); char *meta_buf = NULL; int data_fd = (-1); char *data_buf = NULL; fs = glfs_new ("whocares"); if (!fs) { fprintf (stderr, "glfs_new failed\n"); return EXIT_FAILURE; } if (getenv("RECON_DEBUG")) { ret = glfs_set_logging (fs, "/dev/stderr", 7); } else { ret = glfs_set_logging (fs, "/dev/null", 0); } if (ret != GFAPI_SUCCESS) { fprintf (stderr, "glfs_set_logging failed (%d)\n", errno); return EXIT_FAILURE; } ret = glfs_set_volfile (fs, argv[1]); if (ret != GFAPI_SUCCESS) { fprintf (stderr, "glfs_set_volfile failed (%d)\n", errno); return EXIT_FAILURE; } ret = glfs_init (fs); if (ret != GFAPI_SUCCESS) { fprintf (stderr, "glfs_init failed (%d)\n", errno); return EXIT_FAILURE; } meta_fd = open (argv[2], O_RDONLY); if (meta_fd < 0) { perror ("open"); return EXIT_FAILURE; } /* TBD: get proper length */ meta_buf = mmap (NULL, 1048576, PROT_READ, MAP_PRIVATE, meta_fd, 0); if (meta_buf == MAP_FAILED) { perror ("mmap"); return EXIT_FAILURE; } data_fd = open (argv[3], O_RDONLY); if (data_fd < 0) { perror ("open"); return EXIT_FAILURE; } /* TBD: get proper length */ data_buf = mmap (NULL, 1048576, PROT_READ, MAP_PRIVATE, data_fd, 0); if (data_buf == MAP_FAILED) { perror ("mmap"); return EXIT_FAILURE; } for (;;) { if (!recon_execute(fs,&meta_buf,&data_buf)) { break; } } return EXIT_SUCCESS; }