char * gfs_pio_open_remote_section(GFS_File gf, char *hostname, int flags) { struct gfs_file_section_context *vc = gf->view_context; char *e, *path_section; struct gfs_connection *gfs_server; /* * We won't use GFARM_FILE_EXCLUSIVE flag for the actual storage * level access (at least for now) to avoid the effect of * remaining junk files. * It's already handled anyway at the metadata level. * * NOTE: Same thing must be done in gfs_pio_local.c. */ int oflags = (gf->open_flags & ~GFARM_FILE_EXCLUSIVE); int fd; struct sockaddr peer_addr; e = gfarm_path_section(gf->pi.pathname, vc->section, &path_section); if (e != NULL) return (e); e = gfarm_host_address_get(hostname, gfarm_spool_server_port, &peer_addr, NULL); if (e != NULL) { free(path_section); return (e); } e = gfs_client_connection(vc->canonical_hostname, &peer_addr, &gfs_server); if (e != NULL) { free(path_section); return (e); } vc->storage_context = gfs_server; e = gfs_client_open(gfs_server, path_section, oflags, gf->pi.status.st_mode & GFARM_S_ALLPERM, &fd); /* FT - the parent directory may be missing */ if (e == GFARM_ERR_NO_SUCH_OBJECT) if (gfs_pio_remote_mkdir_parent_canonical_path( gfs_server, gf->pi.pathname) == NULL) e = gfs_client_open(gfs_server, path_section, oflags, gf->pi.status.st_mode & GFARM_S_ALLPERM, &fd); /* FT - physical file should be missing */ if ((oflags & GFARM_FILE_CREATE) == 0 && e == GFARM_ERR_NO_SUCH_OBJECT) /* Delete the section copy info */ if (gfarm_file_section_copy_info_remove(gf->pi.pathname, vc->section, vc->canonical_hostname) == NULL) e = GFARM_ERR_INCONSISTENT_RECOVERABLE; free(path_section); if (e != NULL) return (e); vc->ops = &gfs_pio_remote_storage_ops; vc->fd = fd; return (NULL); }
static char * replicate_section_to_local_internal( char *pathname, char *section, gfarm_mode_t st_mode, char *local_path, char *path_section, char *peer_hostname) { struct sockaddr peer_addr; struct gfs_connection *peer_conn; int fd, peer_fd, saved_errno; char *e; e = gfarm_host_address_get(peer_hostname, gfarm_spool_server_port, &peer_addr, NULL); if (e != NULL) return (e); e = gfs_client_connection(peer_hostname, &peer_addr, &peer_conn); if (e != NULL) return (e); e = gfs_client_open(peer_conn, path_section, GFARM_FILE_RDONLY, 0, &peer_fd); /* FT - source file should be missing */ if (e == GFARM_ERR_NO_SUCH_OBJECT) /* Delete the section copy info */ if (gfarm_file_section_copy_info_remove(pathname, section, peer_hostname) == NULL) e = GFARM_ERR_INCONSISTENT_RECOVERABLE; if (e != NULL) return (e); fd = open(local_path, O_WRONLY|O_CREAT|O_TRUNC, st_mode); saved_errno = errno; /* FT - the parent directory may be missing */ if (fd == -1 && gfs_proto_error_string(saved_errno) == GFARM_ERR_NO_SUCH_OBJECT) { if (gfs_pio_local_mkdir_parent_canonical_path( pathname) == NULL) { fd = open(local_path, O_WRONLY|O_CREAT|O_TRUNC, st_mode); saved_errno = errno; } } if (fd < 0) { e = gfs_proto_error_string(saved_errno); goto finish_peer_close; } /* XXX FIXME: this should honor sync_rate */ e = gfs_client_copyin(peer_conn, peer_fd, fd, 0); /* XXX - copyin() should return the digest value */ if (e == NULL) e = gfs_pio_set_fragment_info_local(local_path, pathname, section); close(fd); finish_peer_close: gfs_client_close(peer_conn, peer_fd); return (e); }
static char * replicate_section_to_local(GFS_File gf, char *section, char *peer_hostname) { char *e; struct sockaddr peer_addr; struct gfs_connection *peer_conn; char *path_section; char *local_path; int fd, peer_fd; e = gfarm_host_address_get(peer_hostname, gfarm_spool_server_port, &peer_addr, NULL); if (e != NULL) return (e); e = gfs_client_connection(peer_hostname, &peer_addr, &peer_conn); if (e != NULL) return (e); e = gfarm_path_section(gf->pi.pathname, section, &path_section); if (e != NULL) return (e); e = gfs_client_open(peer_conn, path_section, GFARM_FILE_RDONLY, 0, &peer_fd); if (e != NULL) goto finish_free_path_section; e = gfarm_path_localize(path_section, &local_path); if (e != NULL) goto finish_peer_close; fd = open(local_path, O_WRONLY|O_CREAT|O_TRUNC, gf->pi.status.st_mode); if (fd < 0) { e = gfs_proto_error_string(errno); goto finish_free_local_path; } e = gfs_client_copyin(peer_conn, peer_fd, fd); /* XXX - copyin() should return the digest value */ if (e == NULL) e = gfs_pio_set_fragment_info_local(local_path, gf->pi.pathname, section); close(fd); finish_free_local_path: free(local_path); finish_peer_close: gfs_client_close(peer_conn, peer_fd); finish_free_path_section: free(path_section); return (e); }
gfarm_error_t gfs_pio_open_remote_section(GFS_File gf, struct gfs_connection *gfs_server) { gfarm_error_t e; struct gfs_file_section_context *vc = gf->view_context; e = gfs_client_open(gfs_server, gf->fd); if (e != GFARM_ERR_NO_ERROR) return (e); vc->ops = &gfs_pio_remote_storage_ops; vc->storage_context = gfs_server; vc->fd = -1; /* not used */ vc->pid = getpid(); return (GFARM_ERR_NO_ERROR); }
char * gfs_pio_open_remote_section(GFS_File gf, char *hostname, int flags) { struct gfs_file_section_context *vc = gf->view_context; char *e, *path_section; struct gfs_connection *gfs_server; int fd; struct sockaddr peer_addr; e = gfarm_path_section(gf->pi.pathname, vc->section, &path_section); if (e != NULL) return (e); e = gfarm_host_address_get(hostname, gfarm_spool_server_port, &peer_addr, NULL); if (e != NULL) { free(path_section); return (e); } e = gfs_client_connection(vc->canonical_hostname, &peer_addr, &gfs_server); if (e != NULL) { free(path_section); return (e); } e = gfs_client_open(gfs_server, path_section, gf->open_flags, gf->pi.status.st_mode & GFARM_S_ALLPERM, &fd); free(path_section); if (e != NULL) return (e); vc->ops = &gfs_pio_remote_storage_ops; vc->storage_context = gfs_server; vc->fd = fd; return (NULL); }