void cfs_normalize(char url[CHIRP_PATH_MAX]) { char *root = NULL; char *rest = NULL; if(strprfx(url, "chirp:")) { return; } else if(strprfx(url, "hdfs:")) { return; } else if(pattern_match(url, "^confuga://([^?]*)(.*)", &root, &rest) >= 0) { char absolute[PATH_MAX]; path_absolute(root, absolute, 0); debug(D_CHIRP, "normalizing url `%s' as `confuga://%s%s'", url, absolute, rest); snprintf(url, CHIRP_PATH_MAX, "confuga://%s%s", absolute, rest); } else { char absolute[PATH_MAX]; if(strprfx(url, "file:") || strprfx(url, "local:")) path_absolute(strstr(url, ":") + 1, absolute, 0); else path_absolute(url, absolute, 0); debug(D_CHIRP, "normalizing url `%s' as `local://%s'", url, absolute); strcpy(url, "local://"); strcat(url, absolute); } free(root); free(rest); }
struct chirp_filesystem *cfs_lookup(const char *url) { if(strprfx(url, "chirp://")) { return &chirp_fs_chirp; } else if(strprfx(url, "hdfs://")) { return &chirp_fs_hdfs; } else { /* always interpret as a local url */ return &chirp_fs_local; } }
static int chirp_fs_local_init(const char url[CHIRP_PATH_MAX]) { int i; char tmp[CHIRP_PATH_MAX]; if (strprfx(url, "local://") || strprfx(url, "file://")) strcpy(tmp, strstr(url, "//")+2); else strcpy(tmp, url); path_collapse(tmp, local_root, 1); for (i = 0; i < CHIRP_FILESYSTEM_MAXFD; i++) open_files[i].fd = -1; return cfs_create_dir("/", 0711); }
void cfs_normalize(char url[CHIRP_PATH_MAX]) { if(strprfx(url, "chirp:")) { return; } else if(strprfx(url, "hdfs:")) { return; } else { char absolute[PATH_MAX]; if(strprfx(url, "file:") || strprfx(url, "local:")) path_absolute(strstr(url, ":")+1, absolute, 0); else path_absolute(url, absolute, 0); debug(D_CHIRP, "normalizing url `%s' as `local://%s'", url, absolute); strcpy(url, "local://"); strcat(url, absolute); } }
static const char *chirp_fs_local_init(const char *url) { static char root[CHIRP_PATH_MAX]; char tmp[CHIRP_PATH_MAX]; if (strlen(url) >= CHIRP_PATH_MAX) { fatal("root path too long"); } if (strprfx(url, "local://") || strprfx(url, "file://")) strcpy(tmp, strstr(url, "//")+2); else strcpy(tmp, url); path_collapse(tmp, root, 1); return root; }
static int chirp_fs_local_init(const char url[CHIRP_PATH_MAX]) { PREAMBLE("init(`%s')", url); int i; char tmp[CHIRP_PATH_MAX]; for (i = 0; i < CHIRP_FILESYSTEM_MAXFD; i++) open_files[i].fd = -1; if (strprfx(url, "local://") || strprfx(url, "file://")) strcpy(tmp, strstr(url, "//")+2); else strcpy(tmp, url); path_collapse(tmp, local_root, 1); rc = create_dir(local_root, 0711); PROLOGUE }
static int chirp_fs_hdfs_init(const char url[CHIRP_PATH_MAX]) { static const char *groups[] = { "supergroup" }; char *path; if(!hdfs_services) { if (hdfs_library_envinit() == -1) return -1; hdfs_services = hdfs_library_open(); if(!hdfs_services) return -1; } debug(D_CHIRP, "url: %s", url); assert(strprfx(url, "hdfs://")); strcpy(hdfs_host, url+strlen("hdfs://")); path = strchr(hdfs_host, '/'); if (path) { path_collapse(path, hdfs_root, 1); *path = '\0'; /* remove path from hdfs_host */ /* now hdfs_host holds 'host[:port]' */ } else { strcpy(hdfs_root, "/"); } if (strlen(hdfs_host) == 0) { /* use default */ strcpy(hdfs_host, "default"); hdfs_port = 0; } else if (strchr(hdfs_host, ':')) { hdfs_port = atoi(strchr(hdfs_host, ':')+1); *strchr(hdfs_host, ':') = '\0'; } else { hdfs_port = 50070; /* default namenode port */ } debug(D_HDFS, "connecting to hdfs://%s:%u%s as '%s'\n", hdfs_host, hdfs_port, hdfs_root, chirp_owner); assert(fs == NULL); fs = hdfs_services->connect_as_user(hdfs_host, hdfs_port, chirp_owner, groups, 1); if (fs == NULL) { errno = EIO; return -1; } memset(open_files, 0, sizeof(open_files)); return cfs_create_dir("/", 0711); }